def test_for_replacing_chain(three_block_blockchain): blockchain = Blockchain() blockchain.replace_the_chain(three_block_blockchain.chain) assert blockchain.chain == three_block_blockchain.chain
def test_for_replacing_chain_if_bad_chain(three_block_blockchain): blockchain = Blockchain() three_block_blockchain.chain[1].hash = 'bad_hash' with pytest.raises(Exception, match='Incoming chain is invalid'): blockchain.replace_the_chain(three_block_blockchain.chain)
else: transaction = SystemTransactions( wallet, transaction_data['recipient'], transaction_data['amount'] ) pubsub.broadcast_transaction(transaction) return jsonify(transaction.convert_transaction_data_to_json()) @app.route('/wallet/info') def wallet_route_info(): return jsonify({'address': wallet.address, 'balance': wallet.the_true_balance}) ROOT_PORT = 5000 PORT = ROOT_PORT if os.environ.get('PEER') == 'True': PORT = random.randint(5001, 6000) result_of_request = requests.get(f'http://localhost:{ROOT_PORT}/blockchain') result_of_blockchain_req = Blockchain.convert_blocklist_to_chain_from_json(result_of_request.json()) try: blockchain.replace_the_chain(result_of_blockchain_req.chain) print('\n -- The local chain has been successfully synchronized ') except Exception as e: print(f'\n -- Error synrchronizing: {e}') app.run(port=PORT)