2018-06-12 11:53:29 -04:00
|
|
|
import asyncio
|
2018-06-26 17:27:24 -04:00
|
|
|
|
2019-12-31 15:30:13 -05:00
|
|
|
from lbry.testcase import IntegrationTestCase
|
2019-03-22 02:18:34 -04:00
|
|
|
|
2019-06-20 21:02:58 -04:00
|
|
|
import lbry.wallet
|
|
|
|
from lbry.schema.claim import Claim
|
|
|
|
from lbry.wallet.transaction import Transaction, Output, Input
|
|
|
|
from lbry.wallet.dewies import dewies_to_lbc as d2l, lbc_to_dewies as l2d
|
2018-06-12 11:53:29 -04:00
|
|
|
|
|
|
|
|
2018-07-09 17:04:59 -04:00
|
|
|
class BasicTransactionTest(IntegrationTestCase):
|
2018-06-12 11:53:29 -04:00
|
|
|
|
2019-06-20 21:02:58 -04:00
|
|
|
LEDGER = lbry.wallet
|
2018-06-12 11:53:29 -04:00
|
|
|
|
2018-06-26 17:27:24 -04:00
|
|
|
async def test_creating_updating_and_abandoning_claim_with_channel(self):
|
2018-06-12 11:53:29 -04:00
|
|
|
|
2018-10-15 17:16:43 -04:00
|
|
|
await self.account.ensure_address_gap()
|
2018-06-12 11:53:29 -04:00
|
|
|
|
2018-10-15 17:16:43 -04:00
|
|
|
address1, address2 = await self.account.receiving.get_addresses(limit=2, only_usable=True)
|
2021-10-06 13:21:32 -04:00
|
|
|
notifications = asyncio.create_task(asyncio.wait(
|
|
|
|
[asyncio.ensure_future(self.on_address_update(address1)),
|
|
|
|
asyncio.ensure_future(self.on_address_update(address2))]
|
|
|
|
))
|
2021-11-08 14:18:22 -05:00
|
|
|
await self.send_to_address_and_wait(address1, 5)
|
|
|
|
await self.send_to_address_and_wait(address2, 5, 1)
|
2021-10-06 13:21:32 -04:00
|
|
|
await notifications
|
2018-06-14 01:32:11 -04:00
|
|
|
|
2018-10-15 17:16:43 -04:00
|
|
|
self.assertEqual(d2l(await self.account.get_balance()), '10.0')
|
2018-06-12 11:53:29 -04:00
|
|
|
|
2019-03-22 02:18:34 -04:00
|
|
|
channel = Claim()
|
|
|
|
channel_txo = Output.pay_claim_name_pubkey_hash(
|
|
|
|
l2d('1.0'), '@bar', channel, self.account.ledger.address_to_hash160(address1)
|
|
|
|
)
|
2021-12-13 00:22:18 -05:00
|
|
|
channel_txo.set_channel_private_key(
|
|
|
|
await self.account.generate_channel_private_key()
|
|
|
|
)
|
2019-03-22 16:36:18 -03:00
|
|
|
channel_txo.script.generate()
|
2019-03-22 02:18:34 -04:00
|
|
|
channel_tx = await Transaction.create([], [channel_txo], [self.account], self.account)
|
2018-06-26 17:27:24 -04:00
|
|
|
|
2019-03-22 02:18:34 -04:00
|
|
|
stream = Claim()
|
2019-04-20 02:11:19 -04:00
|
|
|
stream.stream.source.media_type = "video/mp4"
|
2019-03-22 02:18:34 -04:00
|
|
|
stream_txo = Output.pay_claim_name_pubkey_hash(
|
|
|
|
l2d('1.0'), 'foo', stream, self.account.ledger.address_to_hash160(address1)
|
|
|
|
)
|
2019-03-22 16:36:18 -03:00
|
|
|
stream_tx = await Transaction.create([], [stream_txo], [self.account], self.account)
|
|
|
|
stream_txo.sign(channel_txo)
|
2019-03-22 02:18:34 -04:00
|
|
|
await stream_tx.sign([self.account])
|
|
|
|
|
2021-10-06 13:21:32 -04:00
|
|
|
notifications = asyncio.create_task(asyncio.wait(
|
|
|
|
[asyncio.ensure_future(self.ledger.wait(channel_tx)), asyncio.ensure_future(self.ledger.wait(stream_tx))]
|
|
|
|
))
|
|
|
|
|
2019-03-22 02:18:34 -04:00
|
|
|
await self.broadcast(channel_tx)
|
|
|
|
await self.broadcast(stream_tx)
|
2021-10-06 13:21:32 -04:00
|
|
|
await notifications
|
|
|
|
notifications = asyncio.create_task(asyncio.wait(
|
|
|
|
[asyncio.ensure_future(self.ledger.wait(channel_tx)), asyncio.ensure_future(self.ledger.wait(stream_tx))]
|
|
|
|
))
|
2021-11-08 14:18:22 -05:00
|
|
|
await self.generate(1)
|
2021-10-06 13:21:32 -04:00
|
|
|
await notifications
|
2019-03-22 16:36:18 -03: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 11:53:29 -04:00
|
|
|
|
2019-10-29 09:18:05 -04:00
|
|
|
response = await self.ledger.resolve([], ['lbry://@bar/foo'])
|
2019-05-05 00:36:58 -04:00
|
|
|
self.assertEqual(response['lbry://@bar/foo'].claim.claim_type, 'stream')
|
2018-06-12 11:53:29 -04:00
|
|
|
|
2019-03-25 22:32:34 -04:00
|
|
|
abandon_tx = await Transaction.create([Input.spend(stream_tx.outputs[0])], [], [self.account], self.account)
|
2021-10-06 13:21:32 -04:00
|
|
|
notify = asyncio.create_task(self.ledger.wait(abandon_tx))
|
2018-07-09 17:04:59 -04:00
|
|
|
await self.broadcast(abandon_tx)
|
2021-10-06 13:21:32 -04:00
|
|
|
await notify
|
|
|
|
notify = asyncio.create_task(self.ledger.wait(abandon_tx))
|
2021-11-08 14:18:22 -05:00
|
|
|
await self.generate(1)
|
2021-10-06 13:21:32 -04:00
|
|
|
await notify
|
2018-06-12 11:53:29 -04:00
|
|
|
|
2019-10-29 09:18:05 -04:00
|
|
|
response = await self.ledger.resolve([], ['lbry://@bar/foo'])
|
2019-05-05 00:36:58 -04:00
|
|
|
self.assertIn('error', response['lbry://@bar/foo'])
|
2018-09-27 01:56:04 -03:00
|
|
|
|
|
|
|
# checks for expected format in inexistent URIs
|
2020-02-01 13:29:55 -05:00
|
|
|
response = await self.ledger.resolve([], ['lbry://404', 'lbry://@404', 'lbry://@404/404'])
|
|
|
|
self.assertEqual('Could not find claim at "lbry://404".', response['lbry://404']['error']['text'])
|
|
|
|
self.assertEqual('Could not find channel in "lbry://@404".', response['lbry://@404']['error']['text'])
|
|
|
|
self.assertEqual('Could not find channel in "lbry://@404/404".', response['lbry://@404/404']['error']['text'])
|