From f5650c1b1326af8a3d17c1912500f2011878c2ad Mon Sep 17 00:00:00 2001 From: Lex Berezhny Date: Tue, 18 Jun 2019 19:42:18 -0400 Subject: [PATCH] minor refactor of reorg integration test --- .../test_blockchain_reorganization.py | 20 +++++++++++-------- torba/client/baseheader.py | 4 +--- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/tests/client_tests/integration/test_blockchain_reorganization.py b/tests/client_tests/integration/test_blockchain_reorganization.py index ff85fd29c..4f0d1587d 100644 --- a/tests/client_tests/integration/test_blockchain_reorganization.py +++ b/tests/client_tests/integration/test_blockchain_reorganization.py @@ -6,24 +6,28 @@ class BlockchainReorganizationTests(IntegrationTestCase): VERBOSITY = logging.WARN + async def assertBlockHash(self, height): + self.assertEqual( + self.ledger.headers.hash(height).decode(), + await self.blockchain.get_block_hash(height) + ) + async def test_reorg(self): # invalidate current block, move forward 2 self.assertEqual(self.ledger.headers.height, 200) - self.assertEqual( - self.ledger.headers.hash(200).decode(), - await self.blockchain.get_block_hash(200) - ) + await self.assertBlockHash(200) await self.blockchain.invalidate_block(self.ledger.headers.hash(200).decode()) await self.blockchain.generate(2) await self.ledger.on_header.where(lambda e: e.height == 201) self.assertEqual(self.ledger.headers.height, 201) - self.assertEqual( - self.ledger.headers.hash(200).decode(), - await self.blockchain.get_block_hash(200) - ) + await self.assertBlockHash(200) + await self.assertBlockHash(201) # invalidate current block, move forward 3 await self.blockchain.invalidate_block(self.ledger.headers.hash(200).decode()) await self.blockchain.generate(3) await self.ledger.on_header.where(lambda e: e.height == 202) self.assertEqual(self.ledger.headers.height, 202) + await self.assertBlockHash(200) + await self.assertBlockHash(201) + await self.assertBlockHash(202) diff --git a/torba/client/baseheader.py b/torba/client/baseheader.py index 21880fb44..51749bdf8 100644 --- a/torba/client/baseheader.py +++ b/torba/client/baseheader.py @@ -98,9 +98,7 @@ class BaseHeaders: async def connect(self, start: int, headers: bytes) -> int: added = 0 bail = False - # TODO: switch to get_running_loop() after depricating python 3.6 support - #loop = asyncio.get_running_loop() - loop = asyncio.get_event_loop() + loop = asyncio.get_running_loop() async with self._header_connect_lock: for height, chunk in self._iterate_chunks(start, headers): try: