def test_account_add_block_invalid_precomputed_work( self, pocketable_block_factory): account = Account(**ACCOUNT_KWARGS) account.receive_block( pocketable_block_factory(account_id=ACCOUNT_ID, amount=1000) ) # Precompute work account.precomputed_work = PrecomputedWork( work=solve_work( account.blocks[-1].block_hash, difficulty=TEST_DIFFICULTY ), difficulty=TEST_DIFFICULTY ) # Use an arbitrarily high difficulty to make the precomputed work # invalid account.precomputed_work.difficulty = "f"*16 # Precomputed work is discarded silently since it was invalid # at the time the block was received block = account.receive_block( pocketable_block_factory(account_id=ACCOUNT_ID, amount=1000) ) assert not block.work assert not account.precomputed_work
def test_account_add_block_precomputed_work( self, pocketable_block_factory): account = Account(**ACCOUNT_KWARGS) account.receive_block( pocketable_block_factory(account_id=ACCOUNT_ID, amount=1000) ) # Precompute work account.precomputed_work = PrecomputedWork( work=solve_work( account.blocks[-1].block_hash, difficulty=TEST_DIFFICULTY ), difficulty=TEST_DIFFICULTY ) block = account.receive_block( pocketable_block_factory(account_id=ACCOUNT_ID, amount=1000) ) # The precomputed work is used assert block.work assert not account.precomputed_work