forked from LBRYCommunity/lbry-sdk
fix last test
This commit is contained in:
parent
6652d55455
commit
4c6dedfa4f
2 changed files with 17 additions and 12 deletions
|
@ -36,16 +36,17 @@ class PurchaseCommandTests(CommandTestCase):
|
|||
await self.ledger.wait(purchase)
|
||||
return claim_id
|
||||
|
||||
async def assertStreamPurchased(self, stream: Transaction, purchase: Transaction):
|
||||
stream_txo, purchase_txo = stream.outputs[0], purchase.outputs[0]
|
||||
stream_fee = stream_txo.claim.stream.fee
|
||||
self.assertEqual(stream_fee.dewies, purchase_txo.amount)
|
||||
self.assertEqual(stream_fee.address, purchase_txo.get_address(self.ledger))
|
||||
async def assertStreamPurchased(self, stream: Transaction, operation):
|
||||
|
||||
await self.account.release_all_outputs()
|
||||
buyer_balance = await self.account.get_balance()
|
||||
merchant_balance = lbc_to_dewies(str(await self.blockchain.get_balance()))
|
||||
pre_purchase_count = (await self.daemon.jsonrpc_purchase_list())['total_items']
|
||||
purchase = await operation()
|
||||
stream_txo, purchase_txo = stream.outputs[0], purchase.outputs[0]
|
||||
stream_fee = stream_txo.claim.stream.fee
|
||||
self.assertEqual(stream_fee.dewies, purchase_txo.amount)
|
||||
self.assertEqual(stream_fee.address, purchase_txo.get_address(self.ledger))
|
||||
|
||||
await self.ledger.wait(purchase)
|
||||
await self.generate(1)
|
||||
|
@ -76,7 +77,7 @@ class PurchaseCommandTests(CommandTestCase):
|
|||
claim_id = stream.outputs[0].claim_id
|
||||
|
||||
# explicit purchase of claim
|
||||
tx = await self.daemon.jsonrpc_purchase_create(claim_id)
|
||||
tx = lambda: self.daemon.jsonrpc_purchase_create(claim_id)
|
||||
await self.assertStreamPurchased(stream, tx)
|
||||
|
||||
# check that `get` doesn't purchase it again
|
||||
|
@ -88,8 +89,12 @@ class PurchaseCommandTests(CommandTestCase):
|
|||
|
||||
# `get` does purchase a stream we don't have yet
|
||||
another_stream = await self.priced_stream('another')
|
||||
response = await self.daemon.jsonrpc_get('lbry://another')
|
||||
await self.assertStreamPurchased(another_stream, response.content_fee)
|
||||
|
||||
async def imagine_its_a_lambda():
|
||||
response = await self.daemon.jsonrpc_get('lbry://another')
|
||||
return response.content_fee
|
||||
|
||||
await self.assertStreamPurchased(another_stream, imagine_its_a_lambda)
|
||||
|
||||
# purchase non-existent claim fails
|
||||
with self.assertRaisesRegex(Exception, "Could not find claim with claim_id"):
|
||||
|
@ -105,12 +110,12 @@ class PurchaseCommandTests(CommandTestCase):
|
|||
await self.daemon.jsonrpc_purchase_create(claim_id)
|
||||
|
||||
# force purchasing claim you already own
|
||||
tx = await self.daemon.jsonrpc_purchase_create(claim_id, allow_duplicate_purchase=True)
|
||||
tx = lambda: self.daemon.jsonrpc_purchase_create(claim_id, allow_duplicate_purchase=True)
|
||||
await self.assertStreamPurchased(stream, tx)
|
||||
|
||||
# purchase by uri
|
||||
abc_stream = await self.priced_stream('abc')
|
||||
tx = await self.daemon.jsonrpc_purchase_create(url='lbry://abc')
|
||||
tx = lambda: self.daemon.jsonrpc_purchase_create(url='lbry://abc')
|
||||
await self.assertStreamPurchased(abc_stream, tx)
|
||||
|
||||
async def test_purchase_and_transaction_list(self):
|
||||
|
|
|
@ -575,7 +575,7 @@ class BaseLedger(metaclass=LedgerRegistry):
|
|||
# broadcast can't be a retriable call yet
|
||||
return self.network.broadcast(hexlify(tx.raw).decode())
|
||||
|
||||
async def wait(self, tx: basetransaction.BaseTransaction, height=-1, timeout=2):
|
||||
async def wait(self, tx: basetransaction.BaseTransaction, height=-1, timeout=1):
|
||||
addresses = set()
|
||||
for txi in tx.inputs:
|
||||
if txi.txo_ref.txo is not None:
|
||||
|
@ -601,4 +601,4 @@ class BaseLedger(metaclass=LedgerRegistry):
|
|||
found = True
|
||||
if not found:
|
||||
print(record['history'], addresses, tx.id)
|
||||
raise asyncio.TimeoutError('Timed out waiting for transaction: %s', tx.id)
|
||||
raise asyncio.TimeoutError('Timed out waiting for transaction.')
|
||||
|
|
Loading…
Reference in a new issue