def test_chain_replacement_bad_chain(blockchain_init): blockchain = Blockchain() blockchain_init.chain[1].hash = "evil_hash" with pytest.raises(Exception, match="Cannot replace. The incoming chain is invalid:"): blockchain.chain_replacement(blockchain_init.chain)
def route_transactions(): return jsonify(transaction_pool.transaction_data()) ROOT_PORT = 5000 PORT = ROOT_PORT if os.environ.get("PEER") == 'True': PORT = random.randint(5001, 6000) result = requests.get(f"http://localhost:{ROOT_PORT}/blockchain") result_blockchain = Blockchain.from_json(result.json()) try: blockchain.chain_replacement(result_blockchain.chain) print(f"\n -- Successfully syncronized the local chain.") except Exception as e: print(f"\n -- Error syncronizing: {e}") if os.environ.get("SEED_DATA") == "True": print('\n -- Seeding Data.') for i in range(10): blockchain.add_block([ Transaction(Wallet(), Wallet().address, random.randint(2, 50)).to_json(), Transaction(Wallet(), Wallet().address, random.randint(2, 50)).to_json() ]) for i in range(3):
def test_chain_replacement(blockchain_init): blockchain = Blockchain() blockchain.chain_replacement(blockchain_init.chain) assert blockchain.chain == blockchain_init.chain