lbry-sdk/tests/integration/blockchain/test_blockchain_reorganization.py

34 lines
1.3 KiB
Python
Raw Normal View History

2018-11-04 06:55:50 +01:00
import logging
2019-12-31 21:30:13 +01:00
from lbry.testcase import IntegrationTestCase
class BlockchainReorganizationTests(IntegrationTestCase):
2018-11-04 06:55:50 +01:00
VERBOSITY = logging.WARN
async def assertBlockHash(self, height):
self.assertEqual(
self.ledger.headers.hash(height).decode(),
await self.blockchain.get_block_hash(height)
)
2018-09-26 03:06:22 +02:00
async def test_reorg(self):
2019-06-18 23:50:41 +02:00
# invalidate current block, move forward 2
self.assertEqual(self.ledger.headers.height, 200)
await self.assertBlockHash(200)
2019-06-18 23:50:41 +02:00
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)
await self.assertBlockHash(200)
await self.assertBlockHash(201)
2018-09-26 03:06:22 +02:00
2019-06-18 23:50:41 +02:00
# 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)