minor refactor of reorg integration test
This commit is contained in:
parent
ecebbc86c6
commit
f5650c1b13
2 changed files with 13 additions and 11 deletions
|
@ -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)
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Add table
Reference in a new issue