tests
This commit is contained in:
parent
3c03fff380
commit
556056c60d
2 changed files with 23 additions and 26 deletions
|
@ -9,7 +9,7 @@ class BlockchainReorganizationTests(CommandTestCase):
|
||||||
VERBOSITY = logging.WARN
|
VERBOSITY = logging.WARN
|
||||||
|
|
||||||
async def assertBlockHash(self, height):
|
async def assertBlockHash(self, height):
|
||||||
bp = self.conductor.spv_node.server.bp
|
bp = self.conductor.spv_node.writer
|
||||||
|
|
||||||
def get_txids():
|
def get_txids():
|
||||||
return [
|
return [
|
||||||
|
@ -29,15 +29,16 @@ class BlockchainReorganizationTests(CommandTestCase):
|
||||||
self.assertListEqual(block_txs, list(txs.keys()), msg='leveldb/lbrycrd transactions are of order')
|
self.assertListEqual(block_txs, list(txs.keys()), msg='leveldb/lbrycrd transactions are of order')
|
||||||
|
|
||||||
async def test_reorg(self):
|
async def test_reorg(self):
|
||||||
bp = self.conductor.spv_node.server.bp
|
bp = self.conductor.spv_node.writer
|
||||||
bp.reorg_count_metric.set(0)
|
bp.reorg_count_metric.set(0)
|
||||||
# invalidate current block, move forward 2
|
# invalidate current block, move forward 2
|
||||||
height = 206
|
height = 206
|
||||||
self.assertEqual(self.ledger.headers.height, height)
|
self.assertEqual(self.ledger.headers.height, height)
|
||||||
await self.assertBlockHash(height)
|
await self.assertBlockHash(height)
|
||||||
await self.blockchain.invalidate_block((await self.ledger.headers.hash(206)).decode())
|
block_hash = (await self.ledger.headers.hash(206)).decode()
|
||||||
await self.generate(2)
|
await self.blockchain.invalidate_block(block_hash)
|
||||||
await self.ledger.on_header.where(lambda e: e.height == 207)
|
await self.blockchain.generate(2)
|
||||||
|
await asyncio.wait_for(self.on_header(207), 3.0)
|
||||||
self.assertEqual(self.ledger.headers.height, 207)
|
self.assertEqual(self.ledger.headers.height, 207)
|
||||||
await self.assertBlockHash(206)
|
await self.assertBlockHash(206)
|
||||||
await self.assertBlockHash(207)
|
await self.assertBlockHash(207)
|
||||||
|
@ -45,15 +46,15 @@ class BlockchainReorganizationTests(CommandTestCase):
|
||||||
|
|
||||||
# invalidate current block, move forward 3
|
# invalidate current block, move forward 3
|
||||||
await self.blockchain.invalidate_block((await self.ledger.headers.hash(206)).decode())
|
await self.blockchain.invalidate_block((await self.ledger.headers.hash(206)).decode())
|
||||||
await self.generate(3)
|
await self.blockchain.generate(3)
|
||||||
await self.ledger.on_header.where(lambda e: e.height == 208)
|
await asyncio.wait_for(self.on_header(208), 3.0)
|
||||||
self.assertEqual(self.ledger.headers.height, 208)
|
self.assertEqual(self.ledger.headers.height, 208)
|
||||||
await self.assertBlockHash(206)
|
await self.assertBlockHash(206)
|
||||||
await self.assertBlockHash(207)
|
await self.assertBlockHash(207)
|
||||||
await self.assertBlockHash(208)
|
await self.assertBlockHash(208)
|
||||||
self.assertEqual(2, bp.reorg_count_metric._samples()[0][2])
|
self.assertEqual(2, bp.reorg_count_metric._samples()[0][2])
|
||||||
await self.generate(3)
|
await self.blockchain.generate(3)
|
||||||
await self.ledger.on_header.where(lambda e: e.height == 211)
|
await asyncio.wait_for(self.on_header(211), 3.0)
|
||||||
await self.assertBlockHash(209)
|
await self.assertBlockHash(209)
|
||||||
await self.assertBlockHash(210)
|
await self.assertBlockHash(210)
|
||||||
await self.assertBlockHash(211)
|
await self.assertBlockHash(211)
|
||||||
|
@ -61,8 +62,8 @@ class BlockchainReorganizationTests(CommandTestCase):
|
||||||
'still-valid', '1.0', file_path=self.create_upload_file(data=b'hi!')
|
'still-valid', '1.0', file_path=self.create_upload_file(data=b'hi!')
|
||||||
)
|
)
|
||||||
await self.ledger.wait(still_valid)
|
await self.ledger.wait(still_valid)
|
||||||
await self.generate(1)
|
await self.blockchain.generate(1)
|
||||||
await self.ledger.on_header.where(lambda e: e.height == 212)
|
await asyncio.wait_for(self.on_header(212), 1.0)
|
||||||
claim_id = still_valid.outputs[0].claim_id
|
claim_id = still_valid.outputs[0].claim_id
|
||||||
c1 = (await self.resolve(f'still-valid#{claim_id}'))['claim_id']
|
c1 = (await self.resolve(f'still-valid#{claim_id}'))['claim_id']
|
||||||
c2 = (await self.resolve(f'still-valid#{claim_id[:2]}'))['claim_id']
|
c2 = (await self.resolve(f'still-valid#{claim_id[:2]}'))['claim_id']
|
||||||
|
@ -70,8 +71,8 @@ class BlockchainReorganizationTests(CommandTestCase):
|
||||||
self.assertTrue(c1 == c2 == c3)
|
self.assertTrue(c1 == c2 == c3)
|
||||||
|
|
||||||
abandon_tx = await self.daemon.jsonrpc_stream_abandon(claim_id=claim_id)
|
abandon_tx = await self.daemon.jsonrpc_stream_abandon(claim_id=claim_id)
|
||||||
await self.generate(1)
|
await self.blockchain.generate(1)
|
||||||
await self.ledger.on_header.where(lambda e: e.height == 213)
|
await asyncio.wait_for(self.on_header(213), 1.0)
|
||||||
c1 = await self.resolve(f'still-valid#{still_valid.outputs[0].claim_id}')
|
c1 = await self.resolve(f'still-valid#{still_valid.outputs[0].claim_id}')
|
||||||
c2 = await self.daemon.jsonrpc_resolve([f'still-valid#{claim_id[:2]}'])
|
c2 = await self.daemon.jsonrpc_resolve([f'still-valid#{claim_id[:2]}'])
|
||||||
c3 = await self.daemon.jsonrpc_resolve([f'still-valid'])
|
c3 = await self.daemon.jsonrpc_resolve([f'still-valid'])
|
||||||
|
@ -113,10 +114,9 @@ class BlockchainReorganizationTests(CommandTestCase):
|
||||||
# reorg the last block dropping our claim tx
|
# reorg the last block dropping our claim tx
|
||||||
await self.blockchain.invalidate_block(invalidated_block_hash)
|
await self.blockchain.invalidate_block(invalidated_block_hash)
|
||||||
await self.blockchain.clear_mempool()
|
await self.blockchain.clear_mempool()
|
||||||
await self.generate(2)
|
await self.blockchain.generate(2)
|
||||||
|
|
||||||
# wait for the client to catch up and verify the reorg
|
|
||||||
await asyncio.wait_for(self.on_header(209), 3.0)
|
await asyncio.wait_for(self.on_header(209), 3.0)
|
||||||
|
|
||||||
await self.assertBlockHash(207)
|
await self.assertBlockHash(207)
|
||||||
await self.assertBlockHash(208)
|
await self.assertBlockHash(208)
|
||||||
await self.assertBlockHash(209)
|
await self.assertBlockHash(209)
|
||||||
|
@ -142,9 +142,8 @@ class BlockchainReorganizationTests(CommandTestCase):
|
||||||
# broadcast the claim in a different block
|
# broadcast the claim in a different block
|
||||||
new_txid = await self.blockchain.sendrawtransaction(hexlify(broadcast_tx.raw).decode())
|
new_txid = await self.blockchain.sendrawtransaction(hexlify(broadcast_tx.raw).decode())
|
||||||
self.assertEqual(broadcast_tx.id, new_txid)
|
self.assertEqual(broadcast_tx.id, new_txid)
|
||||||
await self.generate(1)
|
|
||||||
|
|
||||||
# wait for the client to catch up
|
await self.blockchain.generate(1)
|
||||||
await asyncio.wait_for(self.on_header(210), 1.0)
|
await asyncio.wait_for(self.on_header(210), 1.0)
|
||||||
|
|
||||||
# verify the claim is in the new block and that it is returned by claim_search
|
# verify the claim is in the new block and that it is returned by claim_search
|
||||||
|
@ -192,7 +191,7 @@ class BlockchainReorganizationTests(CommandTestCase):
|
||||||
# reorg the last block dropping our claim tx
|
# reorg the last block dropping our claim tx
|
||||||
await self.blockchain.invalidate_block(invalidated_block_hash)
|
await self.blockchain.invalidate_block(invalidated_block_hash)
|
||||||
await self.blockchain.clear_mempool()
|
await self.blockchain.clear_mempool()
|
||||||
await self.generate(2)
|
await self.blockchain.generate(2)
|
||||||
|
|
||||||
# wait for the client to catch up and verify the reorg
|
# wait for the client to catch up and verify the reorg
|
||||||
await asyncio.wait_for(self.on_header(209), 3.0)
|
await asyncio.wait_for(self.on_header(209), 3.0)
|
||||||
|
@ -221,9 +220,7 @@ class BlockchainReorganizationTests(CommandTestCase):
|
||||||
# broadcast the claim in a different block
|
# broadcast the claim in a different block
|
||||||
new_txid = await self.blockchain.sendrawtransaction(hexlify(broadcast_tx.raw).decode())
|
new_txid = await self.blockchain.sendrawtransaction(hexlify(broadcast_tx.raw).decode())
|
||||||
self.assertEqual(broadcast_tx.id, new_txid)
|
self.assertEqual(broadcast_tx.id, new_txid)
|
||||||
await self.generate(1)
|
await self.blockchain.generate(1)
|
||||||
|
|
||||||
# wait for the client to catch up
|
|
||||||
await asyncio.wait_for(self.on_header(210), 1.0)
|
await asyncio.wait_for(self.on_header(210), 1.0)
|
||||||
|
|
||||||
# verify the claim is in the new block and that it is returned by claim_search
|
# verify the claim is in the new block and that it is returned by claim_search
|
||||||
|
|
|
@ -16,7 +16,7 @@ class NetworkTests(IntegrationTestCase):
|
||||||
|
|
||||||
async def test_remote_height_updated_automagically(self):
|
async def test_remote_height_updated_automagically(self):
|
||||||
initial_height = self.ledger.network.remote_height
|
initial_height = self.ledger.network.remote_height
|
||||||
await self.generate(1)
|
await self.blockchain.generate(1)
|
||||||
await self.ledger.network.on_header.first
|
await self.ledger.network.on_header.first
|
||||||
self.assertEqual(self.ledger.network.remote_height, initial_height + 1)
|
self.assertEqual(self.ledger.network.remote_height, initial_height + 1)
|
||||||
|
|
||||||
|
@ -85,7 +85,7 @@ class ReconnectTests(IntegrationTestCase):
|
||||||
async def test_direct_sync(self):
|
async def test_direct_sync(self):
|
||||||
await self.ledger.stop()
|
await self.ledger.stop()
|
||||||
initial_height = self.ledger.local_height_including_downloaded_height
|
initial_height = self.ledger.local_height_including_downloaded_height
|
||||||
await self.generate(100)
|
await self.blockchain.generate(100)
|
||||||
while self.conductor.spv_node.server.session_manager.notified_height < initial_height + 99: # off by 1
|
while self.conductor.spv_node.server.session_manager.notified_height < initial_height + 99: # off by 1
|
||||||
await asyncio.sleep(0.1)
|
await asyncio.sleep(0.1)
|
||||||
self.assertEqual(initial_height, self.ledger.local_height_including_downloaded_height)
|
self.assertEqual(initial_height, self.ledger.local_height_including_downloaded_height)
|
||||||
|
@ -105,7 +105,7 @@ class ReconnectTests(IntegrationTestCase):
|
||||||
# await self.ledger.resolve([], 'derp')
|
# await self.ledger.resolve([], 'derp')
|
||||||
# self.assertTrue(self.ledger.network.is_connected)
|
# self.assertTrue(self.ledger.network.is_connected)
|
||||||
await asyncio.wait_for(self.on_transaction_id(sendtxid), 10.0) # mempool
|
await asyncio.wait_for(self.on_transaction_id(sendtxid), 10.0) # mempool
|
||||||
await self.generate(1)
|
await self.blockchain.generate(1)
|
||||||
await self.on_transaction_id(sendtxid) # confirmed
|
await self.on_transaction_id(sendtxid) # confirmed
|
||||||
self.assertLess(self.ledger.network.client.response_time, 1) # response time properly set lower, we are fine
|
self.assertLess(self.ledger.network.client.response_time, 1) # response time properly set lower, we are fine
|
||||||
|
|
||||||
|
@ -123,7 +123,7 @@ class ReconnectTests(IntegrationTestCase):
|
||||||
await self.ledger.network.get_transaction(sendtxid)
|
await self.ledger.network.get_transaction(sendtxid)
|
||||||
# * goes to pick some water outside... * time passes by and another donation comes in
|
# * goes to pick some water outside... * time passes by and another donation comes in
|
||||||
sendtxid = await self.blockchain.send_to_address(address1, 42)
|
sendtxid = await self.blockchain.send_to_address(address1, 42)
|
||||||
await self.generate(1)
|
await self.blockchain.generate(1)
|
||||||
# (this is just so the test doesn't hang forever if it doesn't reconnect)
|
# (this is just so the test doesn't hang forever if it doesn't reconnect)
|
||||||
if not self.ledger.network.is_connected:
|
if not self.ledger.network.is_connected:
|
||||||
await asyncio.wait_for(self.ledger.network.on_connected.first, timeout=10.0)
|
await asyncio.wait_for(self.ledger.network.on_connected.first, timeout=10.0)
|
||||||
|
|
Loading…
Reference in a new issue