forked from LBRYCommunity/lbry-sdk
tests
This commit is contained in:
parent
04bb7b4919
commit
bfeeacb230
4 changed files with 54 additions and 27 deletions
|
@ -2282,7 +2282,7 @@ class Daemon(metaclass=JSONRPCServerType):
|
||||||
accounts = wallet.get_accounts_or_all(funding_account_ids)
|
accounts = wallet.get_accounts_or_all(funding_account_ids)
|
||||||
txo = None
|
txo = None
|
||||||
if claim_id:
|
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:
|
if not isinstance(txo, Output) or not txo.is_claim:
|
||||||
# TODO: use error from lbry.error
|
# TODO: use error from lbry.error
|
||||||
raise Exception(f"Could not find claim with claim_id '{claim_id}'.")
|
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)
|
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)
|
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)
|
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)
|
claim_address = claim.get_address(self.ledger)
|
||||||
if not tip:
|
if not tip:
|
||||||
account = wallet.get_account_or_default(account_id)
|
account = wallet.get_account_or_default(account_id)
|
||||||
|
|
|
@ -625,6 +625,9 @@ class CommandTestCase(IntegrationTestCase):
|
||||||
async def claim_search(self, **kwargs):
|
async def claim_search(self, **kwargs):
|
||||||
return (await self.out(self.daemon.jsonrpc_claim_search(**kwargs)))['items']
|
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):
|
async def file_list(self, *args, **kwargs):
|
||||||
return (await self.out(self.daemon.jsonrpc_file_list(*args, **kwargs)))['items']
|
return (await self.out(self.daemon.jsonrpc_file_list(*args, **kwargs)))['items']
|
||||||
|
|
||||||
|
|
|
@ -57,11 +57,29 @@ class BlockchainReorganizationTests(CommandTestCase):
|
||||||
await self.assertBlockHash(209)
|
await self.assertBlockHash(209)
|
||||||
await self.assertBlockHash(210)
|
await self.assertBlockHash(210)
|
||||||
await self.assertBlockHash(211)
|
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):
|
async def test_reorg_change_claim_height(self):
|
||||||
# sanity check
|
# sanity check
|
||||||
txos, _, _, _ = await self.ledger.claim_search([], name='hovercraft')
|
result = await self.resolve('hovercraft') # TODO: do these for claim_search and resolve both
|
||||||
self.assertListEqual(txos, [])
|
self.assertIn('error', result)
|
||||||
|
|
||||||
still_valid = await self.daemon.jsonrpc_stream_create(
|
still_valid = await self.daemon.jsonrpc_stream_create(
|
||||||
'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!')
|
||||||
|
@ -82,17 +100,15 @@ class BlockchainReorganizationTests(CommandTestCase):
|
||||||
self.assertEqual(self.ledger.headers.height, 208)
|
self.assertEqual(self.ledger.headers.height, 208)
|
||||||
await self.assertBlockHash(208)
|
await self.assertBlockHash(208)
|
||||||
|
|
||||||
txos, _, _, _ = await self.ledger.claim_search([], name='hovercraft')
|
claim = await self.resolve('hovercraft')
|
||||||
self.assertEqual(1, len(txos))
|
self.assertEqual(claim['txid'], broadcast_tx.id)
|
||||||
txo = txos[0]
|
self.assertEqual(claim['height'], 208)
|
||||||
self.assertEqual(txo.tx_ref.id, broadcast_tx.id)
|
|
||||||
self.assertEqual(txo.tx_ref.height, 208)
|
|
||||||
|
|
||||||
# check that our tx is in block 208 as returned by lbrycrdd
|
# check that our tx is in block 208 as returned by lbrycrdd
|
||||||
invalidated_block_hash = (await self.ledger.headers.hash(208)).decode()
|
invalidated_block_hash = (await self.ledger.headers.hash(208)).decode()
|
||||||
block_207 = await self.blockchain.get_block(invalidated_block_hash)
|
block_207 = await self.blockchain.get_block(invalidated_block_hash)
|
||||||
self.assertIn(txo.tx_ref.id, block_207['tx'])
|
self.assertIn(claim['txid'], block_207['tx'])
|
||||||
self.assertEqual(208, txos[0].tx_ref.height)
|
self.assertEqual(208, claim['height'])
|
||||||
|
|
||||||
# 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)
|
||||||
|
@ -109,11 +125,20 @@ class BlockchainReorganizationTests(CommandTestCase):
|
||||||
reorg_block_hash = await self.blockchain.get_block_hash(208)
|
reorg_block_hash = await self.blockchain.get_block_hash(208)
|
||||||
self.assertNotEqual(invalidated_block_hash, reorg_block_hash)
|
self.assertNotEqual(invalidated_block_hash, reorg_block_hash)
|
||||||
block_207 = await self.blockchain.get_block(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()
|
client_reorg_block_hash = (await self.ledger.headers.hash(208)).decode()
|
||||||
self.assertEqual(client_reorg_block_hash, reorg_block_hash)
|
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
|
# 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)
|
||||||
|
@ -123,14 +148,9 @@ class BlockchainReorganizationTests(CommandTestCase):
|
||||||
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
|
||||||
block_210 = await self.blockchain.get_block((await self.ledger.headers.hash(210)).decode())
|
republished = await self.resolve('hovercraft')
|
||||||
self.assertIn(txo.tx_ref.id, block_210['tx'])
|
self.assertEqual(210, republished['height'])
|
||||||
txos, _, _, _ = await self.ledger.claim_search([], name='hovercraft')
|
self.assertEqual(claim['claim_id'], republished['claim_id'])
|
||||||
self.assertEqual(1, len(txos))
|
|
||||||
self.assertEqual(txos[0].tx_ref.id, new_txid)
|
|
||||||
self.assertEqual(210, txos[0].tx_ref.height)
|
|
||||||
|
|
||||||
# this should still be unchanged
|
# this should still be unchanged
|
||||||
txos, _, _, _ = await self.ledger.claim_search([], name='still-valid')
|
self.assertEqual(207, (await self.resolve('still-valid'))['height'])
|
||||||
self.assertEqual(1, len(txos))
|
|
||||||
self.assertEqual(207, txos[0].tx_ref.height)
|
|
||||||
|
|
|
@ -108,6 +108,9 @@ class ResolveCommand(BaseResolveTestCase):
|
||||||
await self.support_create(claim_id1, '0.29')
|
await self.support_create(claim_id1, '0.29')
|
||||||
await self.assertResolvesToClaimId('@foo', claim_id1)
|
await self.assertResolvesToClaimId('@foo', claim_id1)
|
||||||
|
|
||||||
|
await self.support_abandon(claim_id1)
|
||||||
|
await self.assertResolvesToClaimId('@foo', claim_id2)
|
||||||
|
|
||||||
async def test_advanced_resolve(self):
|
async def test_advanced_resolve(self):
|
||||||
claim_id1 = self.get_claim_id(
|
claim_id1 = self.get_claim_id(
|
||||||
await self.stream_create('foo', '0.7', allow_duplicate_name=True))
|
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', '0.2', allow_duplicate_name=True)
|
||||||
await self.channel_create('@abc', '1.0', allow_duplicate_name=True)
|
await self.channel_create('@abc', '1.0', allow_duplicate_name=True)
|
||||||
|
|
||||||
channel_id = self.get_claim_id(
|
channel_id = self.get_claim_id(await self.channel_create('@abc', '1.1', allow_duplicate_name=True))
|
||||||
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)
|
||||||
await self.assertResolvesToClaimId(f'@abc#{channel_id[:10]}', channel_id)
|
await self.assertResolvesToClaimId(f'@abc#{channel_id[:10]}', channel_id)
|
||||||
await self.assertResolvesToClaimId(f'@abc#{channel_id}', 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['short_url'], channel_id)
|
||||||
await self.assertResolvesToClaimId(channel['canonical_url'], channel_id)
|
await self.assertResolvesToClaimId(channel['canonical_url'], channel_id)
|
||||||
await self.assertResolvesToClaimId(channel['permanent_url'], channel_id)
|
await self.assertResolvesToClaimId(channel['permanent_url'], channel_id)
|
||||||
|
@ -146,7 +149,8 @@ class ResolveCommand(BaseResolveTestCase):
|
||||||
|
|
||||||
claim_id1 = self.get_claim_id(
|
claim_id1 = self.get_claim_id(
|
||||||
await self.stream_create('foo', '0.7', allow_duplicate_name=True, channel_id=channel['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('foo', claim_id1)
|
||||||
await self.assertResolvesToClaimId('@abc/foo', claim_id1)
|
await self.assertResolvesToClaimId('@abc/foo', claim_id1)
|
||||||
await self.assertResolvesToClaimId(claim1['short_url'], claim_id1)
|
await self.assertResolvesToClaimId(claim1['short_url'], claim_id1)
|
||||||
|
@ -155,7 +159,7 @@ class ResolveCommand(BaseResolveTestCase):
|
||||||
|
|
||||||
claim_id2 = self.get_claim_id(
|
claim_id2 = self.get_claim_id(
|
||||||
await self.stream_create('foo', '0.8', allow_duplicate_name=True, channel_id=channel['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('foo', claim_id2)
|
||||||
await self.assertResolvesToClaimId('@abc/foo', claim_id2)
|
await self.assertResolvesToClaimId('@abc/foo', claim_id2)
|
||||||
await self.assertResolvesToClaimId(claim2['short_url'], claim_id2)
|
await self.assertResolvesToClaimId(claim2['short_url'], claim_id2)
|
||||||
|
@ -204,7 +208,7 @@ class ResolveCommand(BaseResolveTestCase):
|
||||||
response = await self.resolve(uri)
|
response = await self.resolve(uri)
|
||||||
self.assertTrue(response['is_channel_signature_valid'])
|
self.assertTrue(response['is_channel_signature_valid'])
|
||||||
self.assertEqual(response['txid'], valid_claim['txid'])
|
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(2, len(claims))
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
{channel['claim_id']}, {claim['signing_channel']['claim_id'] for claim in claims}
|
{channel['claim_id']}, {claim['signing_channel']['claim_id'] for claim in claims}
|
||||||
|
|
Loading…
Reference in a new issue