From 9117e2b7231b9b278a0627ec47b5c510115899a0 Mon Sep 17 00:00:00 2001 From: tecnovert Date: Thu, 9 Feb 2023 23:21:52 +0200 Subject: [PATCH] Fix XMR withdrawals --- basicswap/interface/xmr.py | 6 ++++-- tests/basicswap/test_xmr.py | 21 +++++++++++++++++++-- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/basicswap/interface/xmr.py b/basicswap/interface/xmr.py index 64f5e3e..d9a7bcd 100644 --- a/basicswap/interface/xmr.py +++ b/basicswap/interface/xmr.py @@ -1,7 +1,7 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -# Copyright (c) 2020-2022 tecnovert +# Copyright (c) 2020-2023 tecnovert # Distributed under the MIT software license, see the accompanying # file LICENSE or http://www.opensource.org/licenses/mit-license.php. @@ -422,10 +422,12 @@ class XMRInterface(CoinInterface): value_sats = make_int(value, self.exp()) self.openWallet(self._wallet_filename) + self.rpc_wallet_cb('refresh') if subfee: balance = self.rpc_wallet_cb('get_balance') - if balance['unlocked_balance'] - value_sats <= 10: + diff = balance['unlocked_balance'] - value_sats + if diff > 0 and diff <= 10: self._log.info('subfee enabled and value close to total, using sweep_all.') params = {'address': addr_to} if self._fee_priority > 0: diff --git a/tests/basicswap/test_xmr.py b/tests/basicswap/test_xmr.py index 043c21d..9aceed6 100644 --- a/tests/basicswap/test_xmr.py +++ b/tests/basicswap/test_xmr.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- -# Copyright (c) 2020-2022 tecnovert +# Copyright (c) 2020-2023 tecnovert # Distributed under the MIT software license, see the accompanying # file LICENSE or http://www.opensource.org/licenses/mit-license.php. @@ -997,7 +997,24 @@ class Test(BaseTest): js_1 = read_json_api(1801, 'wallets') assert (float(js_1[Coins.XMR.name]['balance']) > 0.0) - swap_clients[1].withdrawCoin(Coins.XMR, 1.1, address_to, False) + post_json = { + 'value': 0.001, + 'address': address_to, + 'subfee': True, + } + rv = read_json_api(1801, 'wallets/xmr/withdraw', post_json) + assert ('Withdraw value must be close to total to use subfee' in rv['error']) + post_json['value'] = 1000000000.0 + rv = read_json_api(1801, 'wallets/xmr/withdraw', post_json) + assert ('Withdraw value must be close to total to use subfee' in rv['error']) + + post_json = { + 'value': 1.1, + 'address': address_to, + 'subfee': False, + } + rv = read_json_api(1801, 'wallets/xmr/withdraw', post_json) + assert (len(rv['txid']) == 64) def test_09_auto_accept(self): logging.info('---------- Test BTC to XMR auto accept')