add tests for paid downloads

This commit is contained in:
Victor Shyba 2019-02-18 20:23:11 -03:00 committed by Lex Berezhny
parent 1ce3adb6a0
commit ce2bb22929
2 changed files with 25 additions and 2 deletions

View file

@ -4,6 +4,7 @@ import os
from integration.testcase import CommandTestCase
from lbrynet.blob_exchange.downloader import BlobDownloader
from lbrynet.error import InsufficientFundsError
class FileCommands(CommandTestCase):
@ -134,3 +135,24 @@ class FileCommands(CommandTestCase):
self.server_blob_manager.blobs.clear()
await self.server_blob_manager.blob_completed(missing_blob)
await asyncio.wait_for(self.wait_files_to_complete(), timeout=1)
async def test_paid_download(self):
fee = {'currency': 'LBC', 'amount': 11.0}
above_max_key_fee = {'currency': 'LBC', 'amount': 111.0}
icanpay_fee = {'currency': 'LBC', 'amount': 1.0}
await self.make_claim('expensive', '0.01', data=b'pay me if you can', fee=fee)
await self.make_claim('maxkey', '0.01', data=b'no pay me, no', fee=above_max_key_fee)
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='maxkey')
await self.daemon.jsonrpc_file_delete(claim_name='icanpay')
response = await self.daemon.jsonrpc_get('lbry://expensive')
self.assertEqual(response['error'], 'fee of 11.0 exceeds max available balance')
self.assertEqual(len(self.daemon.jsonrpc_file_list()), 0)
response = await self.daemon.jsonrpc_get('lbry://maxkey')
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')
response = await self.daemon.jsonrpc_get('lbry://icanpay')
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)

View file

@ -159,12 +159,13 @@ class CommandTestCase(IntegrationTestCase):
return json.loads(jsonrpc_dumps_pretty(await awaitable, ledger=self.ledger))['result']
async def make_claim(self, name='hovercraft', amount='1.0', data=b'hi!',
channel_name=None, confirm=True, account_id=None):
channel_name=None, confirm=True, account_id=None, fee=None):
with tempfile.NamedTemporaryFile() as file:
file.write(data)
file.flush()
claim = await self.out(self.daemon.jsonrpc_publish(
name, amount, file_path=file.name, channel_name=channel_name, account_id=account_id
name, amount, file_path=file.name, channel_name=channel_name, account_id=account_id,
fee=fee
))
self.assertTrue(claim['success'])
if confirm: