forked from LBRYCommunity/lbry-sdk
added tx to JSON response from get
This commit is contained in:
parent
8c5007fe07
commit
0fdd2ae178
3 changed files with 31 additions and 15 deletions
|
@ -36,6 +36,7 @@ class ManagedStream:
|
||||||
self.stream_claim_info = claim
|
self.stream_claim_info = claim
|
||||||
self._status = status
|
self._status = status
|
||||||
self.fully_reflected = asyncio.Event(loop=self.loop)
|
self.fully_reflected = asyncio.Event(loop=self.loop)
|
||||||
|
self.tx = None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def file_name(self):
|
def file_name(self):
|
||||||
|
@ -131,6 +132,7 @@ class ManagedStream:
|
||||||
'file_name': self.file_name,
|
'file_name': self.file_name,
|
||||||
'download_directory': self.download_directory,
|
'download_directory': self.download_directory,
|
||||||
'points_paid': 0.0,
|
'points_paid': 0.0,
|
||||||
|
'tx': self.tx,
|
||||||
'stopped': not self.running,
|
'stopped': not self.running,
|
||||||
'stream_hash': self.stream_hash,
|
'stream_hash': self.stream_hash,
|
||||||
'stream_name': self.descriptor.stream_name,
|
'stream_name': self.descriptor.stream_name,
|
||||||
|
|
|
@ -355,7 +355,8 @@ class StreamManager:
|
||||||
stream = await stream_task
|
stream = await stream_task
|
||||||
self.starting_streams[sd_hash].set_result(stream)
|
self.starting_streams[sd_hash].set_result(stream)
|
||||||
if should_pay and fee_address and fee_amount:
|
if should_pay and fee_address and fee_amount:
|
||||||
await self.wallet.send_amount_to_address(lbc_to_dewies(str(fee_amount)), fee_address.encode('latin1'))
|
stream.tx = await self.wallet.send_amount_to_address(
|
||||||
|
lbc_to_dewies(str(fee_amount)), fee_address.encode('latin1'))
|
||||||
return stream
|
return stream
|
||||||
except (asyncio.TimeoutError, asyncio.CancelledError) as e:
|
except (asyncio.TimeoutError, asyncio.CancelledError) as e:
|
||||||
if stream_task.exception():
|
if stream_task.exception():
|
||||||
|
|
|
@ -138,30 +138,43 @@ class FileCommands(CommandTestCase):
|
||||||
|
|
||||||
async def test_paid_download(self):
|
async def test_paid_download(self):
|
||||||
target_address = await self.blockchain.get_raw_change_address()
|
target_address = await self.blockchain.get_raw_change_address()
|
||||||
fee = {'currency': 'LBC', 'amount': 11.0, 'address': target_address}
|
|
||||||
above_max_key_fee = {'currency': 'LBC', 'amount': 111.0, 'address': target_address}
|
# FAIL: beyond available balance
|
||||||
icanpay_fee = {'currency': 'LBC', 'amount': 1.0, 'address': target_address}
|
await self.make_claim(
|
||||||
await self.make_claim('expensive', '0.01', data=b'pay me if you can', fee=fee)
|
'expensive', '0.01', data=b'pay me if you can',
|
||||||
await self.make_claim('maxkey', '0.01', data=b'no pay me, no', fee=above_max_key_fee)
|
fee={'currency': 'LBC', 'amount': 11.0, 'address': target_address})
|
||||||
await self.make_claim('icanpay', '0.01', data=b'I got the power!', fee=icanpay_fee)
|
|
||||||
await self.daemon.jsonrpc_file_delete(claim_name='expensive')
|
await self.daemon.jsonrpc_file_delete(claim_name='expensive')
|
||||||
await self.daemon.jsonrpc_file_delete(claim_name='maxkey')
|
|
||||||
await self.daemon.jsonrpc_file_delete(claim_name='icanpay')
|
|
||||||
response = await self.daemon.jsonrpc_get('lbry://expensive')
|
response = await self.daemon.jsonrpc_get('lbry://expensive')
|
||||||
self.assertEqual(response['error'], 'fee of 11.0 exceeds max available balance')
|
self.assertEqual(response['error'], 'fee of 11.0 exceeds max available balance')
|
||||||
self.assertEqual(len(self.daemon.jsonrpc_file_list()), 0)
|
self.assertEqual(len(self.daemon.jsonrpc_file_list()), 0)
|
||||||
await self.assertBalance(self.account, '9.925679')
|
|
||||||
|
# FAIL: beyond maximum key fee
|
||||||
|
await self.make_claim(
|
||||||
|
'maxkey', '0.01', data=b'no pay me, no',
|
||||||
|
fee={'currency': 'LBC', 'amount': 111.0, 'address': target_address})
|
||||||
|
await self.daemon.jsonrpc_file_delete(claim_name='maxkey')
|
||||||
response = await self.daemon.jsonrpc_get('lbry://maxkey')
|
response = await self.daemon.jsonrpc_get('lbry://maxkey')
|
||||||
self.assertEqual(len(self.daemon.jsonrpc_file_list()), 0)
|
self.assertEqual(len(self.daemon.jsonrpc_file_list()), 0)
|
||||||
self.assertEqual(response['error'], 'fee of 111.0 exceeds max configured to allow of 50.0')
|
self.assertEqual(response['error'], 'fee of 111.0 exceeds max configured to allow of 50.0')
|
||||||
|
|
||||||
|
# PASS: purchase is successful
|
||||||
|
await self.make_claim(
|
||||||
|
'icanpay', '0.01', data=b'I got the power!',
|
||||||
|
fee={'currency': 'LBC', 'amount': 1.0, 'address': target_address})
|
||||||
|
await self.daemon.jsonrpc_file_delete(claim_name='icanpay')
|
||||||
await self.assertBalance(self.account, '9.925679')
|
await self.assertBalance(self.account, '9.925679')
|
||||||
response = await self.daemon.jsonrpc_get('lbry://icanpay')
|
response = await self.daemon.jsonrpc_get('lbry://icanpay')
|
||||||
|
self.assertNotIn('error', response)
|
||||||
|
await self.ledger.wait(response['tx'])
|
||||||
|
await self.assertBalance(self.account, '8.925555')
|
||||||
self.assertEqual(len(self.daemon.jsonrpc_file_list()), 1)
|
self.assertEqual(len(self.daemon.jsonrpc_file_list()), 1)
|
||||||
self.assertFalse(response.get('error'))
|
|
||||||
await asyncio.wait_for(self.wait_files_to_complete(), timeout=1)
|
await asyncio.wait_for(self.wait_files_to_complete(), timeout=1)
|
||||||
|
|
||||||
target_account_original_balance = await self.blockchain.get_balance()
|
# check that the fee was received
|
||||||
|
starting_balance = await self.blockchain.get_balance()
|
||||||
await self.generate(1)
|
await self.generate(1)
|
||||||
target_account_final_balance = await self.blockchain.get_balance()
|
block_reward_and_claim_fee = 2.0
|
||||||
block_reward, profit = 1.0, icanpay_fee['amount']
|
self.assertEqual(
|
||||||
self.assertEqual(target_account_final_balance - target_account_original_balance, profit + block_reward)
|
await self.blockchain.get_balance(), starting_balance + block_reward_and_claim_fee
|
||||||
|
)
|
||||||
|
|
Loading…
Reference in a new issue