diff --git a/lbry/extras/daemon/daemon.py b/lbry/extras/daemon/daemon.py index 14d82884d..f2d5e0ef3 100644 --- a/lbry/extras/daemon/daemon.py +++ b/lbry/extras/daemon/daemon.py @@ -2282,7 +2282,7 @@ class Daemon(metaclass=JSONRPCServerType): accounts = wallet.get_accounts_or_all(funding_account_ids) txo = None if claim_id: - txo = await self.ledger.get_claim_by_claim_id(accounts, claim_id, include_purchase_receipt=True) + txo = await self.ledger.get_claim_by_claim_id(claim_id, accounts, include_purchase_receipt=True) if not isinstance(txo, Output) or not txo.is_claim: # TODO: use error from lbry.error raise Exception(f"Could not find claim with claim_id '{claim_id}'.") @@ -4215,7 +4215,7 @@ class Daemon(metaclass=JSONRPCServerType): funding_accounts = wallet.get_accounts_or_all(funding_account_ids) channel = await self.get_channel_or_none(wallet, channel_account_id, channel_id, channel_name, for_signing=True) amount = self.get_dewies_or_error("amount", amount) - claim = await self.ledger.get_claim_by_claim_id(wallet.accounts, claim_id) + claim = await self.ledger.get_claim_by_claim_id(claim_id) claim_address = claim.get_address(self.ledger) if not tip: account = wallet.get_account_or_default(account_id) diff --git a/lbry/testcase.py b/lbry/testcase.py index 70fe84159..54244f5c8 100644 --- a/lbry/testcase.py +++ b/lbry/testcase.py @@ -625,6 +625,9 @@ class CommandTestCase(IntegrationTestCase): async def claim_search(self, **kwargs): return (await self.out(self.daemon.jsonrpc_claim_search(**kwargs)))['items'] + async def get_claim_by_claim_id(self, claim_id): + return await self.out(self.ledger.get_claim_by_claim_id(claim_id)) + async def file_list(self, *args, **kwargs): return (await self.out(self.daemon.jsonrpc_file_list(*args, **kwargs)))['items'] diff --git a/tests/integration/blockchain/test_blockchain_reorganization.py b/tests/integration/blockchain/test_blockchain_reorganization.py index 3f7a1f0b1..40a748e9d 100644 --- a/tests/integration/blockchain/test_blockchain_reorganization.py +++ b/tests/integration/blockchain/test_blockchain_reorganization.py @@ -57,11 +57,29 @@ class BlockchainReorganizationTests(CommandTestCase): await self.assertBlockHash(209) await self.assertBlockHash(210) await self.assertBlockHash(211) + still_valid = await self.daemon.jsonrpc_stream_create( + 'still-valid', '1.0', file_path=self.create_upload_file(data=b'hi!') + ) + await self.ledger.wait(still_valid) + await self.blockchain.generate(1) + await self.ledger.on_header.where(lambda e: e.height == 212) + claim_id = still_valid.outputs[0].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'] + c3 = (await self.resolve(f'still-valid'))['claim_id'] + self.assertTrue(c1 == c2 == c3) + + abandon_tx = await self.daemon.jsonrpc_stream_abandon(claim_id=claim_id) + await self.blockchain.generate(1) + await self.ledger.on_header.where(lambda e: e.height == 213) + 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]}']) + c3 = await self.daemon.jsonrpc_resolve([f'still-valid']) async def test_reorg_change_claim_height(self): # sanity check - txos, _, _, _ = await self.ledger.claim_search([], name='hovercraft') - self.assertListEqual(txos, []) + result = await self.resolve('hovercraft') # TODO: do these for claim_search and resolve both + self.assertIn('error', result) still_valid = await self.daemon.jsonrpc_stream_create( 'still-valid', '1.0', file_path=self.create_upload_file(data=b'hi!') @@ -82,17 +100,15 @@ class BlockchainReorganizationTests(CommandTestCase): self.assertEqual(self.ledger.headers.height, 208) await self.assertBlockHash(208) - txos, _, _, _ = await self.ledger.claim_search([], name='hovercraft') - self.assertEqual(1, len(txos)) - txo = txos[0] - self.assertEqual(txo.tx_ref.id, broadcast_tx.id) - self.assertEqual(txo.tx_ref.height, 208) + claim = await self.resolve('hovercraft') + self.assertEqual(claim['txid'], broadcast_tx.id) + self.assertEqual(claim['height'], 208) # check that our tx is in block 208 as returned by lbrycrdd invalidated_block_hash = (await self.ledger.headers.hash(208)).decode() block_207 = await self.blockchain.get_block(invalidated_block_hash) - self.assertIn(txo.tx_ref.id, block_207['tx']) - self.assertEqual(208, txos[0].tx_ref.height) + self.assertIn(claim['txid'], block_207['tx']) + self.assertEqual(208, claim['height']) # reorg the last block dropping our claim tx await self.blockchain.invalidate_block(invalidated_block_hash) @@ -109,11 +125,20 @@ class BlockchainReorganizationTests(CommandTestCase): reorg_block_hash = await self.blockchain.get_block_hash(208) self.assertNotEqual(invalidated_block_hash, reorg_block_hash) block_207 = await self.blockchain.get_block(reorg_block_hash) - self.assertNotIn(txo.tx_ref.id, block_207['tx']) + self.assertNotIn(claim['txid'], block_207['tx']) client_reorg_block_hash = (await self.ledger.headers.hash(208)).decode() self.assertEqual(client_reorg_block_hash, reorg_block_hash) + # verify the dropped claim is no longer returned by claim search + self.assertDictEqual( + {'error': {'name': 'NOT_FOUND', 'text': 'Could not find claim at "hovercraft".'}}, + await self.resolve('hovercraft') + ) + + # verify the claim published a block earlier wasn't also reverted + self.assertEqual(207, (await self.resolve('still-valid'))['height']) + # broadcast the claim in a different block new_txid = await self.blockchain.sendrawtransaction(hexlify(broadcast_tx.raw).decode()) self.assertEqual(broadcast_tx.id, new_txid) @@ -123,14 +148,9 @@ class BlockchainReorganizationTests(CommandTestCase): 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 - block_210 = await self.blockchain.get_block((await self.ledger.headers.hash(210)).decode()) - self.assertIn(txo.tx_ref.id, block_210['tx']) - txos, _, _, _ = await self.ledger.claim_search([], name='hovercraft') - self.assertEqual(1, len(txos)) - self.assertEqual(txos[0].tx_ref.id, new_txid) - self.assertEqual(210, txos[0].tx_ref.height) + republished = await self.resolve('hovercraft') + self.assertEqual(210, republished['height']) + self.assertEqual(claim['claim_id'], republished['claim_id']) # this should still be unchanged - txos, _, _, _ = await self.ledger.claim_search([], name='still-valid') - self.assertEqual(1, len(txos)) - self.assertEqual(207, txos[0].tx_ref.height) + self.assertEqual(207, (await self.resolve('still-valid'))['height']) diff --git a/tests/integration/blockchain/test_resolve_command.py b/tests/integration/blockchain/test_resolve_command.py index 37b548ff9..a0987a7a6 100644 --- a/tests/integration/blockchain/test_resolve_command.py +++ b/tests/integration/blockchain/test_resolve_command.py @@ -108,6 +108,9 @@ class ResolveCommand(BaseResolveTestCase): await self.support_create(claim_id1, '0.29') await self.assertResolvesToClaimId('@foo', claim_id1) + await self.support_abandon(claim_id1) + await self.assertResolvesToClaimId('@foo', claim_id2) + async def test_advanced_resolve(self): claim_id1 = self.get_claim_id( await self.stream_create('foo', '0.7', allow_duplicate_name=True)) @@ -129,12 +132,12 @@ class ResolveCommand(BaseResolveTestCase): await self.channel_create('@abc', '0.2', allow_duplicate_name=True) await self.channel_create('@abc', '1.0', allow_duplicate_name=True) - channel_id = self.get_claim_id( - await self.channel_create('@abc', '1.1', allow_duplicate_name=True)) + channel_id = self.get_claim_id(await self.channel_create('@abc', '1.1', allow_duplicate_name=True)) await self.assertResolvesToClaimId(f'@abc', channel_id) await self.assertResolvesToClaimId(f'@abc#{channel_id[:10]}', channel_id) await self.assertResolvesToClaimId(f'@abc#{channel_id}', channel_id) - channel = (await self.claim_search(claim_id=channel_id))[0] + + channel = await self.claim_get(channel_id) await self.assertResolvesToClaimId(channel['short_url'], channel_id) await self.assertResolvesToClaimId(channel['canonical_url'], channel_id) await self.assertResolvesToClaimId(channel['permanent_url'], channel_id) @@ -146,7 +149,8 @@ class ResolveCommand(BaseResolveTestCase): claim_id1 = self.get_claim_id( await self.stream_create('foo', '0.7', allow_duplicate_name=True, channel_id=channel['claim_id'])) - claim1 = (await self.claim_search(claim_id=claim_id1))[0] + claim1 = await self.claim_get(claim_id=claim_id1) + await self.assertResolvesToClaimId('foo', claim_id1) await self.assertResolvesToClaimId('@abc/foo', claim_id1) await self.assertResolvesToClaimId(claim1['short_url'], claim_id1) @@ -155,7 +159,7 @@ class ResolveCommand(BaseResolveTestCase): claim_id2 = self.get_claim_id( await self.stream_create('foo', '0.8', allow_duplicate_name=True, channel_id=channel['claim_id'])) - claim2 = (await self.claim_search(claim_id=claim_id2))[0] + claim2 = await self.claim_get(claim_id=claim_id2) await self.assertResolvesToClaimId('foo', claim_id2) await self.assertResolvesToClaimId('@abc/foo', claim_id2) await self.assertResolvesToClaimId(claim2['short_url'], claim_id2) @@ -204,7 +208,7 @@ class ResolveCommand(BaseResolveTestCase): response = await self.resolve(uri) self.assertTrue(response['is_channel_signature_valid']) self.assertEqual(response['txid'], valid_claim['txid']) - claims = await self.claim_search(name='on-channel-claim') + claims = [await self.resolve('on-channel-claim'), await self.resolve('on-channel-claim$2')] self.assertEqual(2, len(claims)) self.assertEqual( {channel['claim_id']}, {claim['signing_channel']['claim_id'] for claim in claims}