From c035837a14ff82582ab73ee70d1d8adf7644e710 Mon Sep 17 00:00:00 2001 From: Miroslav Kovar Date: Wed, 18 Sep 2019 08:56:23 +0200 Subject: [PATCH] Fix failing key payment for null max key fee --- lbry/lbry/stream/stream_manager.py | 4 ++-- lbry/tests/unit/stream/test_stream_manager.py | 24 ++++++++++++++++++- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/lbry/lbry/stream/stream_manager.py b/lbry/lbry/stream/stream_manager.py index f15d8ee82..3b6c23c78 100644 --- a/lbry/lbry/stream/stream_manager.py +++ b/lbry/lbry/stream/stream_manager.py @@ -401,8 +401,8 @@ class StreamManager: ), 5) max_fee_amount = round(exchange_rate_manager.convert_currency( self.config.max_key_fee['currency'], "LBC", Decimal(self.config.max_key_fee['amount']) - ), 5) - if fee_amount > max_fee_amount: + ), 5) if self.config.max_key_fee else None + if max_fee_amount and fee_amount > max_fee_amount: msg = f"fee of {fee_amount} exceeds max configured to allow of {max_fee_amount}" log.warning(msg) raise KeyFeeAboveMaxAllowed(msg) diff --git a/lbry/tests/unit/stream/test_stream_manager.py b/lbry/tests/unit/stream/test_stream_manager.py index 810cdc145..337853350 100644 --- a/lbry/tests/unit/stream/test_stream_manager.py +++ b/lbry/tests/unit/stream/test_stream_manager.py @@ -76,8 +76,14 @@ def get_mock_wallet(sd_hash, storage, balance=10.0, fee=None): claim['permanent_url']: claim } - mock_wallet = mock.Mock(spec=LbryWalletManager) + async def mock_send_amount_to_address(*args): + transaction = mock.Mock() + transaction.raw = b'raw transaction' + return transaction + + mock_wallet = mock.Mock(spec=LbryWalletManager, return_value=asyncio.Future()) mock_wallet.ledger.resolve = mock_resolve + mock_wallet.send_amount_to_address = mock_send_amount_to_address mock_wallet.ledger.network.client.server = ('fakespv.lbry.com', 50001) async def get_balance(*_): @@ -323,6 +329,22 @@ class TestStreamManager(BlobExchangeTestBase): await self.setup_stream_manager(1000000.0, fee) await self._test_download_error_on_start(KeyFeeAboveMaxAllowed, "") + async def test_null_max_key_fee(self): + fee = { + 'currency': 'LBC', + 'amount': 0.001, + 'address': 'bYFeMtSL7ARuG1iMpjFyrnTe4oJHSAVNXF', + 'version': '_0_0_1' + } + self.client_config.max_key_fee = None + error = None + await self.setup_stream_manager(1000000.0, fee) + try: + await self.stream_manager.download_stream_from_uri(self.uri, self.exchange_rate_manager) + except Exception as err: + error = err + self.assertIsNone(error) + async def test_resolve_error(self): await self.setup_stream_manager() self.uri = "fake"