Add tests for new behaviour
This commit is contained in:
parent
fcdbe846e5
commit
1bcf2737fe
@ -910,7 +910,7 @@ def test_get_ticker(default_conf, mocker, exchange_name):
|
|||||||
'last': 0.0001,
|
'last': 0.0001,
|
||||||
}
|
}
|
||||||
api_mock.fetch_ticker = MagicMock(return_value=tick)
|
api_mock.fetch_ticker = MagicMock(return_value=tick)
|
||||||
api_mock.markets = {'ETH/BTC': {}}
|
api_mock.markets = {'ETH/BTC': {'active': True}}
|
||||||
exchange = get_patched_exchange(mocker, default_conf, api_mock, id=exchange_name)
|
exchange = get_patched_exchange(mocker, default_conf, api_mock, id=exchange_name)
|
||||||
# retrieve original ticker
|
# retrieve original ticker
|
||||||
ticker = exchange.get_ticker(pair='ETH/BTC')
|
ticker = exchange.get_ticker(pair='ETH/BTC')
|
||||||
|
@ -324,7 +324,7 @@ def test_rpc_trade_statistics_closed(mocker, default_conf, ticker, fee, markets,
|
|||||||
assert prec_satoshi(stats['best_rate'], 6.2)
|
assert prec_satoshi(stats['best_rate'], 6.2)
|
||||||
|
|
||||||
|
|
||||||
def test_rpc_balance_handle(default_conf, mocker):
|
def test_rpc_balance_handle_error(default_conf, mocker):
|
||||||
mock_balance = {
|
mock_balance = {
|
||||||
'BTC': {
|
'BTC': {
|
||||||
'free': 10.0,
|
'free': 10.0,
|
||||||
@ -371,6 +371,72 @@ def test_rpc_balance_handle(default_conf, mocker):
|
|||||||
assert result['total'] == 12.0
|
assert result['total'] == 12.0
|
||||||
|
|
||||||
|
|
||||||
|
def test_rpc_balance_handle(default_conf, mocker):
|
||||||
|
mock_balance = {
|
||||||
|
'BTC': {
|
||||||
|
'free': 10.0,
|
||||||
|
'total': 12.0,
|
||||||
|
'used': 2.0,
|
||||||
|
},
|
||||||
|
'ETH': {
|
||||||
|
'free': 1.0,
|
||||||
|
'total': 5.0,
|
||||||
|
'used': 4.0,
|
||||||
|
},
|
||||||
|
'PAX': {
|
||||||
|
'free': 5.0,
|
||||||
|
'total': 10.0,
|
||||||
|
'used': 5.0,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mocker.patch.multiple(
|
||||||
|
'freqtrade.rpc.fiat_convert.Market',
|
||||||
|
ticker=MagicMock(return_value={'price_usd': 15000.0}),
|
||||||
|
)
|
||||||
|
patch_exchange(mocker)
|
||||||
|
mocker.patch('freqtrade.rpc.rpc.CryptoToFiatConverter._find_price', return_value=15000.0)
|
||||||
|
mocker.patch('freqtrade.rpc.telegram.Telegram', MagicMock())
|
||||||
|
mocker.patch.multiple(
|
||||||
|
'freqtrade.exchange.Exchange',
|
||||||
|
get_balances=MagicMock(return_value=mock_balance),
|
||||||
|
get_ticker=MagicMock(
|
||||||
|
side_effect=lambda p, r: {'bid': 100} if p == "BTC/PAX" else {'bid': 0.01}),
|
||||||
|
get_valid_pair_combination=MagicMock(
|
||||||
|
side_effect=lambda a, b: f"{b}/{a}" if a == "PAX" else f"{a}/{b}")
|
||||||
|
)
|
||||||
|
|
||||||
|
freqtradebot = FreqtradeBot(default_conf)
|
||||||
|
patch_get_signal(freqtradebot, (True, False))
|
||||||
|
rpc = RPC(freqtradebot)
|
||||||
|
rpc._fiat_converter = CryptoToFiatConverter()
|
||||||
|
|
||||||
|
result = rpc._rpc_balance(default_conf['fiat_display_currency'])
|
||||||
|
assert prec_satoshi(result['total'], 12.15)
|
||||||
|
assert prec_satoshi(result['value'], 182250)
|
||||||
|
assert 'USD' == result['symbol']
|
||||||
|
assert result['currencies'] == [
|
||||||
|
{'currency': 'BTC',
|
||||||
|
'available': 10.0,
|
||||||
|
'balance': 12.0,
|
||||||
|
'pending': 2.0,
|
||||||
|
'est_btc': 12.0,
|
||||||
|
},
|
||||||
|
{'available': 1.0,
|
||||||
|
'balance': 5.0,
|
||||||
|
'currency': 'ETH',
|
||||||
|
'est_btc': 0.05,
|
||||||
|
'pending': 4.0
|
||||||
|
},
|
||||||
|
{'available': 5.0,
|
||||||
|
'balance': 10.0,
|
||||||
|
'currency': 'PAX',
|
||||||
|
'est_btc': 0.1,
|
||||||
|
'pending': 5.0}
|
||||||
|
]
|
||||||
|
assert result['total'] == 12.15
|
||||||
|
|
||||||
|
|
||||||
def test_rpc_start(mocker, default_conf) -> None:
|
def test_rpc_start(mocker, default_conf) -> None:
|
||||||
patch_exchange(mocker)
|
patch_exchange(mocker)
|
||||||
mocker.patch('freqtrade.rpc.telegram.Telegram', MagicMock())
|
mocker.patch('freqtrade.rpc.telegram.Telegram', MagicMock())
|
||||||
|
@ -244,6 +244,8 @@ def test_api_balance(botclient, mocker, rpc_balance):
|
|||||||
}
|
}
|
||||||
mocker.patch('freqtrade.exchange.Exchange.get_balances', return_value=rpc_balance)
|
mocker.patch('freqtrade.exchange.Exchange.get_balances', return_value=rpc_balance)
|
||||||
mocker.patch('freqtrade.exchange.Exchange.get_ticker', side_effect=mock_ticker)
|
mocker.patch('freqtrade.exchange.Exchange.get_ticker', side_effect=mock_ticker)
|
||||||
|
mocker.patch('freqtrade.exchange.Exchange.get_valid_pair_combination',
|
||||||
|
side_effect=lambda a, b: f"{a}/{b}")
|
||||||
|
|
||||||
rc = client_get(client, f"{BASE_URI}/balance")
|
rc = client_get(client, f"{BASE_URI}/balance")
|
||||||
assert_response(rc)
|
assert_response(rc)
|
||||||
|
@ -518,6 +518,8 @@ def test_telegram_balance_handle(default_conf, update, mocker, rpc_balance) -> N
|
|||||||
|
|
||||||
mocker.patch('freqtrade.exchange.Exchange.get_balances', return_value=rpc_balance)
|
mocker.patch('freqtrade.exchange.Exchange.get_balances', return_value=rpc_balance)
|
||||||
mocker.patch('freqtrade.exchange.Exchange.get_ticker', side_effect=mock_ticker)
|
mocker.patch('freqtrade.exchange.Exchange.get_ticker', side_effect=mock_ticker)
|
||||||
|
mocker.patch('freqtrade.exchange.Exchange.get_valid_pair_combination',
|
||||||
|
side_effect=lambda a, b: f"{a}/{b}")
|
||||||
|
|
||||||
msg_mock = MagicMock()
|
msg_mock = MagicMock()
|
||||||
mocker.patch.multiple(
|
mocker.patch.multiple(
|
||||||
|
Loading…
Reference in New Issue
Block a user