def test_replace_chain_invalid_incoming_chain(blockchain_ten_blocks): blockchain = BlockChain() blockchain_ten_blocks.chain[1].hash = "tampered hash" with pytest.raises(Exception, match="Cannot replace. The incoming chain is invalid"): blockchain.replace_chain(blockchain_ten_blocks.chain)
PORT = 5000 if os.environ.get('SEED_DATA') == 'True': for i in range(10): blockchain.add_block([ Transaction(Wallet(), Wallet().address, random.randint(2, 20)).to_json(), Transaction(Wallet(), Wallet().address, random.randint(2, 20)).to_json() ]) for i in range(5): transaction_pool.add_transaction( Transaction(Wallet(), Wallet().address, random.randint(2, 50))) if os.environ.get('PEER') == "True": result = requests.get('http://localhost:5000/blockchain') full_blockchain = BlockChain.from_json(result.json()) PORT = random.randint(5001, 6000) try: blockchain.replace_chain(full_blockchain.chain) print("\n -- Successfully synchronized the local blockchain") except Exception as e: print(f"\n -- Failed to Synchroniz the local blockchain: {e}") app.run(port=PORT) #serve(TransLogger(app, setup_console_handler=True))
def test_replace_chain(blockchain_ten_blocks): blockchain = BlockChain() blockchain.replace_chain(blockchain_ten_blocks.chain) assert blockchain.chain == blockchain_ten_blocks.chain