Adds API unit tests and modifies bitcoin_sim to be fixture compatible

- Adds unit tests for API
- Updates API to let BlockProcessor deal with block block related JSON-RPC
- Fixes BlockProcessor get_potential_matches return
- Makes bitcoin_sim runnable via function (instead of a main runnable script) to work with pytests fixture
- <3 Fixture
This commit is contained in:
Sergi Delgado Segura
2019-10-08 18:31:02 +01:00
parent ab1ad33e32
commit e81ccd39a1
5 changed files with 215 additions and 133 deletions

View File

@@ -15,6 +15,15 @@ app = Flask(__name__)
HOST = 'localhost'
PORT = '18443'
mining_simulator = ZMQPublisher(topic=b'hashblock', feed_protocol=FEED_PROTOCOL, feed_addr=FEED_ADDR,
feed_port=FEED_PORT)
mempool = []
mined_transactions = {}
blocks = {}
blockchain = []
TIME_BETWEEN_BLOCKS = 10
@app.route('/', methods=['POST'])
def process_request():
@@ -193,18 +202,10 @@ def simulate_mining():
print("New block mined: {}".format(block_hash))
print("\tTransactions: {}".format(txs_to_mine))
time.sleep(10)
time.sleep(TIME_BETWEEN_BLOCKS)
if __name__ == '__main__':
mining_simulator = ZMQPublisher(topic=b'hashblock', feed_protocol=FEED_PROTOCOL, feed_addr=FEED_ADDR,
feed_port=FEED_PORT)
mempool = []
mined_transactions = {}
blocks = {}
blockchain = []
def run_simulator():
mining_thread = Thread(target=simulate_mining)
mining_thread.start()