From fa1e9dd70d1e48298ddc0c2603ae4ef351e93e85 Mon Sep 17 00:00:00 2001 From: Matthias Date: Wed, 15 Jan 2020 21:53:04 +0100 Subject: [PATCH] Adjust tests to allow updating within safe_sell_amount --- tests/rpc/test_rpc.py | 1 + tests/test_freqtradebot.py | 5 +++++ tests/test_integration.py | 4 ++-- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/tests/rpc/test_rpc.py b/tests/rpc/test_rpc.py index ac959cb0e..36fce1797 100644 --- a/tests/rpc/test_rpc.py +++ b/tests/rpc/test_rpc.py @@ -513,6 +513,7 @@ def test_rpc_forcesell(default_conf, ticker, fee, mocker) -> None: ), get_fee=fee, ) + mocker.patch('freqtrade.wallets.Wallets.get_free', return_value=1000) freqtradebot = get_patched_freqtradebot(mocker, default_conf) patch_get_signal(freqtradebot, (True, False)) diff --git a/tests/test_freqtradebot.py b/tests/test_freqtradebot.py index eedf79553..1cba39c58 100644 --- a/tests/test_freqtradebot.py +++ b/tests/test_freqtradebot.py @@ -2750,6 +2750,7 @@ def test__safe_sell_amount(default_conf, fee, caplog, mocker): amount = 95.33 amount_wallet = 95.29 mocker.patch('freqtrade.wallets.Wallets.get_free', MagicMock(return_value=amount_wallet)) + wallet_update = mocker.patch('freqtrade.wallets.Wallets.update') trade = Trade( pair='LTC/ETH', amount=amount, @@ -2762,11 +2763,15 @@ def test__safe_sell_amount(default_conf, fee, caplog, mocker): freqtrade = FreqtradeBot(default_conf) patch_get_signal(freqtrade) + wallet_update.reset_mock() assert freqtrade._safe_sell_amount(trade.pair, trade.amount) == amount_wallet assert log_has_re(r'.*Falling back to wallet-amount.', caplog) + assert wallet_update.call_count == 1 caplog.clear() + wallet_update.reset_mock() assert freqtrade._safe_sell_amount(trade.pair, amount_wallet) == amount_wallet assert not log_has_re(r'.*Falling back to wallet-amount.', caplog) + assert wallet_update.call_count == 1 def test__safe_sell_amount_error(default_conf, fee, caplog, mocker): diff --git a/tests/test_integration.py b/tests/test_integration.py index 98bf1862b..ad3e897f8 100644 --- a/tests/test_integration.py +++ b/tests/test_integration.py @@ -97,8 +97,8 @@ def test_may_execute_sell_stoploss_on_exchange_multi(default_conf, ticker, fee, # Only order for 3rd trade needs to be cancelled assert cancel_order_mock.call_count == 1 - # Wallets should only be called once per sell cycle - assert wallets_mock.call_count == 1 + # Wallets must be updated between stoploss cancellation and selling. + assert wallets_mock.call_count == 2 trade = trades[0] assert trade.sell_reason == SellType.STOPLOSS_ON_EXCHANGE.value