lbry-sdk/tests/integration/test_internal_transaction_api.py

79 lines
3.2 KiB
Python
Raw Normal View History

2018-06-12 17:53:29 +02:00
import asyncio
2018-11-04 07:24:41 +01:00
from torba.testcase import IntegrationTestCase
import lbrynet.wallet
from lbrynet.schema.claim import Claim
2019-03-26 03:32:34 +01:00
from lbrynet.wallet.transaction import Transaction, Output, Input
from lbrynet.wallet.dewies import dewies_to_lbc as d2l, lbc_to_dewies as l2d
2018-06-12 17:53:29 +02:00
class BasicTransactionTest(IntegrationTestCase):
2018-06-12 17:53:29 +02:00
LEDGER = lbrynet.wallet
2018-06-12 17:53:29 +02:00
async def test_creating_updating_and_abandoning_claim_with_channel(self):
2018-06-12 17:53:29 +02:00
2018-10-15 23:16:43 +02:00
await self.account.ensure_address_gap()
2018-06-12 17:53:29 +02:00
2018-10-15 23:16:43 +02:00
address1, address2 = await self.account.receiving.get_addresses(limit=2, only_usable=True)
2018-07-15 05:03:51 +02:00
sendtxid1 = await self.blockchain.send_to_address(address1, 5)
sendtxid2 = await self.blockchain.send_to_address(address2, 5)
2018-06-14 07:32:11 +02:00
await self.blockchain.generate(1)
await asyncio.wait([
self.on_transaction_id(sendtxid1),
2018-10-17 03:28:47 +02:00
self.on_transaction_id(sendtxid2)
])
2018-06-14 07:32:11 +02:00
2018-10-15 23:16:43 +02:00
self.assertEqual(d2l(await self.account.get_balance()), '10.0')
2018-06-12 17:53:29 +02:00
channel = Claim()
channel_txo = Output.pay_claim_name_pubkey_hash(
l2d('1.0'), '@bar', channel, self.account.ledger.address_to_hash160(address1)
)
channel_txo.generate_channel_private_key()
2019-03-22 20:36:18 +01:00
channel_txo.script.generate()
channel_tx = await Transaction.create([], [channel_txo], [self.account], self.account)
stream = Claim()
2019-04-20 08:11:19 +02:00
stream.stream.source.media_type = "video/mp4"
stream_txo = Output.pay_claim_name_pubkey_hash(
l2d('1.0'), 'foo', stream, self.account.ledger.address_to_hash160(address1)
)
2019-03-22 20:36:18 +01:00
stream_tx = await Transaction.create([], [stream_txo], [self.account], self.account)
stream_txo.sign(channel_txo)
await stream_tx.sign([self.account])
await self.broadcast(channel_tx)
await self.broadcast(stream_tx)
await asyncio.wait([ # mempool
self.ledger.wait(channel_tx),
self.ledger.wait(stream_tx)
])
2018-06-14 07:32:11 +02:00
await self.blockchain.generate(1)
await asyncio.wait([ # confirmed
self.ledger.wait(channel_tx),
self.ledger.wait(stream_tx)
])
2018-06-12 17:53:29 +02:00
2019-03-22 20:36:18 +01:00
self.assertEqual(d2l(await self.account.get_balance()), '7.985786')
self.assertEqual(d2l(await self.account.get_balance(include_claims=True)), '9.985786')
2018-06-12 17:53:29 +02:00
2018-10-15 23:16:43 +02:00
response = await self.ledger.resolve(0, 10, 'lbry://@bar/foo')
self.assertIn('lbry://@bar/foo', response)
2018-08-04 03:27:08 +02:00
self.assertIn('claim', response['lbry://@bar/foo'])
2018-06-12 17:53:29 +02:00
2019-03-26 03:32:34 +01:00
abandon_tx = await Transaction.create([Input.spend(stream_tx.outputs[0])], [], [self.account], self.account)
await self.broadcast(abandon_tx)
2018-11-07 22:12:03 +01:00
await self.ledger.wait(abandon_tx)
await self.blockchain.generate(1)
2018-11-07 22:12:03 +01:00
await self.ledger.wait(abandon_tx)
2018-06-12 17:53:29 +02:00
2018-10-15 23:16:43 +02:00
response = await self.ledger.resolve(0, 10, 'lbry://@bar/foo')
2018-08-04 03:27:08 +02:00
self.assertNotIn('claim', response['lbry://@bar/foo'])
# checks for expected format in inexistent URIs
2018-10-15 23:16:43 +02:00
response = await self.ledger.resolve(0, 10, 'lbry://404', 'lbry://@404')
self.assertEqual('URI lbry://404 cannot be resolved', response['lbry://404']['error'])
self.assertEqual('URI lbry://@404 cannot be resolved', response['lbry://@404']['error'])