def test_replace_chain_bad_chain(blockchain_three_blocks): blockchain = Blockchain() blockchain_three_blocks.chain[1].hash = 'evil_hash' with pytest.raises(Exception, match= 'The incomming chain is invalid'): blockchain.replace_chain(blockchain_three_blocks.chain)
from backend.routes.blueprints import WALLET, BLOCKCHAIN, TRANSACTION from backend.config import PORT, ROOT_PORT app = Flask(__name__) @app.route('/') def route_default(): return 'Welcome to the blockchain ;)' app.register_blueprint(BLOCKCHAIN, url_prefix="/blockchain") app.register_blueprint(TRANSACTION, url_prefix="/transactions") app.register_blueprint(WALLET, url_prefix="/wallet") CORS(app, resources={r'/*': {'origins': 'http://localhost:3001'}}) 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.replace_chain(result_blockchain.chain) print('\n -- Succesfully synchronized the local chain') except Exception as e: print(f'\n --Error synchronizing: {e}') app.run(port=PORT)
def test_replace_chain(blockchain_three_blocks): blockchain = Blockchain() blockchain.replace_chain(blockchain_three_blocks.chain) assert blockchain.chain == blockchain_three_blocks.chain