From b43d58afbf7329156bed19ea2c51f9eabb1a5b45 Mon Sep 17 00:00:00 2001 From: tecnovert Date: Tue, 15 Nov 2022 23:50:36 +0200 Subject: [PATCH] api: Add wallet/createutxo --- basicswap/__init__.py | 2 +- basicswap/basicswap.py | 35 +++++++-- basicswap/chainparams.py | 6 ++ basicswap/interface/dash.py | 3 + basicswap/interface/firo.py | 6 ++ basicswap/interface/pivx.py | 3 + basicswap/js_server.py | 108 +++++++------------------- basicswap/templates/bid.html | 66 ++++++++-------- basicswap/templates/bid_xmr.html | 36 ++++----- tests/basicswap/extended/test_dash.py | 30 +++++-- tests/basicswap/extended/test_firo.py | 18 +++-- tests/basicswap/extended/test_nmc.py | 2 +- tests/basicswap/extended/test_pivx.py | 30 +++++-- 13 files changed, 186 insertions(+), 159 deletions(-) diff --git a/basicswap/__init__.py b/basicswap/__init__.py index 9822e3a..1eb8ad0 100644 --- a/basicswap/__init__.py +++ b/basicswap/__init__.py @@ -1,3 +1,3 @@ name = "basicswap" -__version__ = "0.11.48" +__version__ = "0.11.49" diff --git a/basicswap/basicswap.py b/basicswap/basicswap.py index 73b0ad4..2e4901f 100644 --- a/basicswap/basicswap.py +++ b/basicswap/basicswap.py @@ -6035,6 +6035,8 @@ class BasicSwap(BaseApp): ci_to = self.ci(int(coin_to)) name_from = ci_from.chainparams()['name'] name_to = ci_to.chainparams()['name'] + exchange_name_from = ci_from.getExchangeName('coingecko.com') + exchange_name_to = ci_to.getExchangeName('coingecko.com') ticker_from = ci_from.chainparams()['ticker'] ticker_to = ci_to.chainparams()['ticker'] headers = {'Connection': 'close'} @@ -6044,23 +6046,42 @@ class BasicSwap(BaseApp): if rate_sources.get('coingecko.com', True): try: - url = 'https://api.coingecko.com/api/v3/simple/price?ids={},{}&vs_currencies=usd,btc'.format(name_from, name_to) + url = 'https://api.coingecko.com/api/v3/simple/price?ids={},{}&vs_currencies=usd,btc'.format(exchange_name_from, exchange_name_to) self.log.debug(f'lookupRates: {url}') start = time.time() req = urllib.request.Request(url, headers=headers) js = json.loads(urllib.request.urlopen(req, timeout=10).read()) js['time_taken'] = time.time() - start - rate = float(js[name_from]['usd']) / float(js[name_to]['usd']) + rate = float(js[exchange_name_from]['usd']) / float(js[exchange_name_to]['usd']) js['rate_inferred'] = ci_to.format_amount(rate, conv_int=True, r=1) rv['coingecko'] = js except Exception as e: rv['coingecko_error'] = str(e) + if self.debug: + self.log.error(traceback.format_exc()) + + if exchange_name_from != name_from: + js[name_from] = js[exchange_name_from] + js.pop(exchange_name_from) + if exchange_name_to != name_to: + js[name_to] = js[exchange_name_to] + js.pop(exchange_name_to) if rate_sources.get('bittrex.com', True): bittrex_api_v3 = 'https://api.bittrex.com/v3' try: + exchange_ticker_to = ci_to.getExchangeTicker('bittrex.com') + exchange_ticker_from = ci_from.getExchangeTicker('bittrex.com') + + USDT_coins = (Coins.FIRO,) + # TODO: How to compare USDT pairs with BTC pairs + if ci_from.coin_type() in USDT_coins: + raise ValueError('No BTC pair') + if ci_to.coin_type() in USDT_coins: + raise ValueError('No BTC pair') + if ci_from.coin_type() == Coins.BTC: - pair = f'{ticker_to}-{ticker_from}' + pair = f'{exchange_ticker_to}-{exchange_ticker_from}' url = f'{bittrex_api_v3}/markets/{pair}/ticker' self.log.debug(f'lookupRates: {url}') start = time.time() @@ -6078,7 +6099,7 @@ class BasicSwap(BaseApp): js['to_btc'] = js['lastTradeRate'] rv['bittrex'] = js elif ci_to.coin_type() == Coins.BTC: - pair = f'{ticker_from}-{ticker_to}' + pair = f'{exchange_ticker_from}-{exchange_ticker_to}' url = f'{bittrex_api_v3}/markets/{pair}/ticker' self.log.debug(f'lookupRates: {url}') start = time.time() @@ -6091,7 +6112,7 @@ class BasicSwap(BaseApp): js['to_btc'] = 1.0 rv['bittrex'] = js else: - pair = f'{ticker_from}-BTC' + pair = f'{exchange_ticker_from}-BTC' url = f'{bittrex_api_v3}/markets/{pair}/ticker' self.log.debug(f'lookupRates: {url}') start = time.time() @@ -6100,7 +6121,7 @@ class BasicSwap(BaseApp): js_from['time_taken'] = time.time() - start js_from['pair'] = pair - pair = f'{ticker_to}-BTC' + pair = f'{exchange_ticker_to}-BTC' url = f'{bittrex_api_v3}/markets/{pair}/ticker' self.log.debug(f'lookupRates: {url}') start = time.time() @@ -6124,6 +6145,8 @@ class BasicSwap(BaseApp): } except Exception as e: rv['bittrex_error'] = str(e) + if self.debug: + self.log.error(traceback.format_exc()) if output_array: diff --git a/basicswap/chainparams.py b/basicswap/chainparams.py index f4e6959..101187e 100644 --- a/basicswap/chainparams.py +++ b/basicswap/chainparams.py @@ -374,6 +374,12 @@ class CoinInterface: ticker = 'rt' + ticker return ticker + def getExchangeTicker(self, exchange_name): + return self.ticker() + + def getExchangeName(self, exchange_name): + return chainparams[self.coin_type()]['name'] + def ticker_mainnet(self): ticker = chainparams[self.coin_type()]['ticker'] return ticker diff --git a/basicswap/interface/dash.py b/basicswap/interface/dash.py index 0bed2ec..48d1df7 100644 --- a/basicswap/interface/dash.py +++ b/basicswap/interface/dash.py @@ -39,3 +39,6 @@ class DASHInterface(BTCInterface): def withdrawCoin(self, value, addr_to, subfee): params = [addr_to, value, '', '', subfee] return self.rpc_callback('sendtoaddress', params) + + def getSpendableBalance(self): + return self.make_int(self.rpc_callback('getwalletinfo')['balance']) diff --git a/basicswap/interface/firo.py b/basicswap/interface/firo.py index c5af17d..0738853 100644 --- a/basicswap/interface/firo.py +++ b/basicswap/interface/firo.py @@ -30,6 +30,9 @@ class FIROInterface(BTCInterface): def coin_type(): return Coins.FIRO + def getExchangeName(self, exchange_name): + return 'zcoin' + def initialiseWallet(self, key): # load with -hdseed= parameter pass @@ -171,3 +174,6 @@ class FIROInterface(BTCInterface): def getWalletSeedID(self): return self.rpc_callback('getwalletinfo')['hdmasterkeyid'] + + def getSpendableBalance(self): + return self.make_int(self.rpc_callback('getwalletinfo')['balance']) diff --git a/basicswap/interface/pivx.py b/basicswap/interface/pivx.py index b41e6e5..62d9598 100644 --- a/basicswap/interface/pivx.py +++ b/basicswap/interface/pivx.py @@ -62,3 +62,6 @@ class PIVXInterface(BTCInterface): def withdrawCoin(self, value, addr_to, subfee): params = [addr_to, value, '', '', subfee] return self.rpc_callback('sendtoaddress', params) + + def getSpendableBalance(self): + return self.make_int(self.rpc_callback('getwalletinfo')['balance']) diff --git a/basicswap/js_server.py b/basicswap/js_server.py index 9eb4558..0285241 100644 --- a/basicswap/js_server.py +++ b/basicswap/js_server.py @@ -37,17 +37,24 @@ from .ui.page_offers import postNewOffer from .protocols.xmr_swap_1 import recoverNoScriptTxnWithKey, getChainBSplitKey +def getFormData(post_string, is_json): + if post_string == '': + raise ValueError('No post data') + if is_json: + form_data = json.loads(post_string) + form_data['is_json'] = True + else: + form_data = urllib.parse.parse_qs(post_string) + return form_data + + def js_error(self, error_str): error_str_json = json.dumps({'error': error_str}) return bytes(error_str_json, 'UTF-8') def withdraw_coin(swap_client, coin_type, post_string, is_json): - if is_json: - post_data = json.loads(post_string) - post_data['is_json'] = True - else: - post_data = urllib.parse.parse_qs(post_string) + post_data = getFormData(post_string, is_json) value = get_data_entry(post_data, 'value') address = get_data_entry(post_data, 'address') @@ -99,6 +106,13 @@ def js_wallets(self, url_split, post_string, is_json): return bytes(json.dumps(withdraw_coin(swap_client, coin_type, post_string, is_json)), 'UTF-8') if cmd == 'nextdepositaddr': return bytes(json.dumps(swap_client.cacheNewAddressForCoin(coin_type)), 'UTF-8') + if cmd == 'createutxo': + post_data = getFormData(post_string, is_json) + ci = swap_client.ci(coin_type) + value = ci.make_int(get_data_entry(post_data, 'value')) + txid_hex, new_addr = ci.createUTXO(value) + return bytes(json.dumps({'txid': txid_hex, 'address': new_addr}), 'UTF-8') + raise ValueError('Unknown command') rv = swap_client.getWalletInfo(coin_type) @@ -113,13 +127,7 @@ def js_offers(self, url_split, post_string, is_json, sent=False): offer_id = None if len(url_split) > 3: if url_split[3] == 'new': - if post_string == '': - raise ValueError('No post data') - if is_json: - form_data = json.loads(post_string) - form_data['is_json'] = True - else: - form_data = urllib.parse.parse_qs(post_string) + form_data = getFormData(post_string, is_json) offer_id = postNewOffer(swap_client, form_data) rv = {'offer_id': offer_id.hex()} return bytes(json.dumps(rv), 'UTF-8') @@ -138,11 +146,7 @@ def js_offers(self, url_split, post_string, is_json, sent=False): filters['offer_id'] = offer_id if post_string != '': - if is_json: - post_data = json.loads(post_string) - post_data['is_json'] = True - else: - post_data = urllib.parse.parse_qs(post_string) + post_data = getFormData(post_string, is_json) filters['coin_from'] = setCoinFilter(post_data, 'coin_from') filters['coin_to'] = setCoinFilter(post_data, 'coin_to') @@ -191,13 +195,7 @@ def js_bids(self, url_split, post_string, is_json): swap_client.checkSystemStatus() if len(url_split) > 3: if url_split[3] == 'new': - if post_string == '': - raise ValueError('No post data') - if is_json: - post_data = json.loads(post_string) - post_data['is_json'] = True - else: - post_data = urllib.parse.parse_qs(post_string) + post_data = getFormData(post_string, is_json) offer_id = bytes.fromhex(get_data_entry(post_data, 'offer_id')) assert (len(offer_id) == 28) @@ -246,11 +244,7 @@ def js_bids(self, url_split, post_string, is_json): show_txns = False if post_string != '': - if is_json: - post_data = json.loads(post_string) - post_data['is_json'] = True - else: - post_data = urllib.parse.parse_qs(post_string) + post_data = getFormData(post_string, is_json) if have_data_entry(post_data, 'accept'): swap_client.acceptBid(bid_id) elif have_data_entry(post_data, 'debugind'): @@ -314,13 +308,7 @@ def js_smsgaddresses(self, url_split, post_string, is_json): swap_client = self.server.swap_client swap_client.checkSystemStatus() if len(url_split) > 3: - if post_string == '': - raise ValueError('No post data') - if is_json: - post_data = json.loads(post_string) - post_data['is_json'] = True - else: - post_data = urllib.parse.parse_qs(post_string) + post_data = getFormData(post_string, is_json) if url_split[3] == 'new': addressnote = get_data_entry_or(post_data, 'addressnote', '') new_addr, pubkey = swap_client.newSMSGAddress(addressnote=addressnote) @@ -341,13 +329,7 @@ def js_smsgaddresses(self, url_split, post_string, is_json): def js_rates(self, url_split, post_string, is_json): - if post_string == '': - raise ValueError('No post data') - if is_json: - post_data = json.loads(post_string) - post_data['is_json'] = True - else: - post_data = urllib.parse.parse_qs(post_string) + post_data = getFormData(post_string, is_json) sc = self.server.swap_client coin_from = get_data_entry(post_data, 'coin_from') @@ -365,13 +347,7 @@ def js_rates_list(self, url_split, query_string, is_json): def js_rate(self, url_split, post_string, is_json): - if post_string == '': - raise ValueError('No post data') - if is_json: - post_data = json.loads(post_string) - post_data['is_json'] = True - else: - post_data = urllib.parse.parse_qs(post_string) + post_data = getFormData(post_string, is_json) sc = self.server.swap_client coin_from = getCoinType(get_data_entry(post_data, 'coin_from')) @@ -447,13 +423,7 @@ def js_vacuumdb(self, url_split, post_string, is_json): def js_getcoinseed(self, url_split, post_string, is_json): swap_client = self.server.swap_client swap_client.checkSystemStatus() - if post_string == '': - raise ValueError('No post data') - if is_json: - post_data = json.loads(post_string) - post_data['is_json'] = True - else: - post_data = urllib.parse.parse_qs(post_string) + post_data = getFormData(post_string, is_json) coin = getCoinType(get_data_entry(post_data, 'coin')) if coin in (Coins.PART, Coins.PART_ANON, Coins.PART_BLIND): @@ -471,13 +441,7 @@ def js_setpassword(self, url_split, post_string, is_json): # Only works with currently enabled coins # Will fail if any coin does not unlock on the old password swap_client = self.server.swap_client - if post_string == '': - raise ValueError('No post data') - if is_json: - post_data = json.loads(post_string) - post_data['is_json'] = True - else: - post_data = urllib.parse.parse_qs(post_string) + post_data = getFormData(post_string, is_json) old_password = get_data_entry(post_data, 'oldpassword') new_password = get_data_entry(post_data, 'newpassword') @@ -497,13 +461,7 @@ def js_setpassword(self, url_split, post_string, is_json): def js_unlock(self, url_split, post_string, is_json): swap_client = self.server.swap_client - if post_string == '': - raise ValueError('No post data') - if is_json: - post_data = json.loads(post_string) - post_data['is_json'] = True - else: - post_data = urllib.parse.parse_qs(post_string) + post_data = getFormData(post_string, is_json) password = get_data_entry(post_data, 'password') @@ -520,13 +478,7 @@ def js_unlock(self, url_split, post_string, is_json): def js_lock(self, url_split, post_string, is_json): swap_client = self.server.swap_client - if post_string == '': - raise ValueError('No post data') - if is_json: - post_data = json.loads(post_string) - post_data['is_json'] = True - else: - post_data = urllib.parse.parse_qs(post_string) + post_data = getFormData(post_string, is_json) if have_data_entry(post_data, 'coin'): coin = getCoinType(get_data_entry(post_data, 'coin')) diff --git a/basicswap/templates/bid.html b/basicswap/templates/bid.html index 190630f..d076783 100644 --- a/basicswap/templates/bid.html +++ b/basicswap/templates/bid.html @@ -37,7 +37,7 @@

Bid ID: {{ bid_id }}

-
+
{% if refresh %} @@ -53,13 +53,13 @@ - Refresh - {% endif %} + Refresh + {% endif %}
- + {% include 'inc_messages.html' %}
@@ -74,7 +74,7 @@ Details - + {% if data.was_sent == 'True' %} Swap @@ -196,7 +196,7 @@ Participate Conf {{ data.participate_conf }} - + {% if data.show_txns %} Initiate Tx Refund @@ -213,8 +213,8 @@ Participate Tx Spend Tx {{ data.participate_tx_spend }} - - {% endif %} + + {% endif %}
@@ -232,7 +232,7 @@ Old States Set at Time - + {% for s in old_states %} {{ s[1] }} @@ -247,7 +247,7 @@
{{ s[0] | formatts }}
- + {% endfor %} @@ -266,7 +266,7 @@ Time Events - + {% for e in data.events %} @@ -283,13 +283,13 @@ {{ e.desc }} {% endfor %} - + {% else %} {% endif %}
-
+
{% if edit_bid %} @@ -302,11 +302,11 @@ - + {% if data.debug_ui == true %} @@ -317,17 +317,17 @@ - + - {% endif %} + {% endif %}
Debug Option:
-
+ Submit Edit +
{% else %} {% if data.show_bidder_seq_diagram %}
-
+
{% else %}
-
- {% endif %} +
+ {% endif %} {% if data.show_offerer_seq_diagram %}
-
+
{% else %}
-
+ {% endif %} {% if data.can_abandon == true %}
- {% endif %} + {% endif %} {% if data.show_txns %}
-
+ {% else %}
-
+ {% endif %}
+ Edit bid
{% endif %} {% if data.was_received == 'True' %}
-
- {% endif %} + + {% endif %} @@ -434,7 +434,7 @@ return confirm("Are you sure?"); } - + {% include 'footer.html' %} - \ No newline at end of file + diff --git a/basicswap/templates/bid_xmr.html b/basicswap/templates/bid_xmr.html index 192203a..aca10ee 100644 --- a/basicswap/templates/bid_xmr.html +++ b/basicswap/templates/bid_xmr.html @@ -172,7 +172,7 @@ {{ data.ticker_from }} lock refund tx valid at {{ data.coin_a_lock_refund_tx_est_final | formatts }} - + {% if data.coin_a_lock_refund_swipe_tx_est_final != 'None' %} {{ data.ticker_from }} lock refund tx swipeable at @@ -377,7 +377,7 @@ {% endif %} {% endif %} - + {% if data.show_bidder_seq_diagram %} @@ -464,7 +464,7 @@ {% if data.debug_ui == true %} Debug Option - +
@@ -485,7 +485,7 @@
-
+ Submit Edit +
{% else %} {% if data.show_bidder_seq_diagram %}
-
+ {% else %}
-
- {% endif %} + + {% endif %} {% if data.show_offerer_seq_diagram %}
-
+ {% else %}
-
+ {% endif %} {% if data.can_abandon == true %}
- {% endif %} + {% endif %} {% if data.show_txns %}
-
+ {% else %}
-
+ {% endif %}
+ Edit bid
{% endif %} {% if data.was_received == 'True' %}
-
- {% endif %} + + {% endif %} @@ -562,4 +562,4 @@ {% include 'footer.html' %} - \ No newline at end of file + diff --git a/tests/basicswap/extended/test_dash.py b/tests/basicswap/extended/test_dash.py index dd47e9e..463ec53 100644 --- a/tests/basicswap/extended/test_dash.py +++ b/tests/basicswap/extended/test_dash.py @@ -56,7 +56,6 @@ from tests.basicswap.common import ( wait_for_bid_tx_state, wait_for_in_progress, read_json_api, - post_json_req, TEST_HTTP_HOST, TEST_HTTP_PORT, BASE_PORT, @@ -247,6 +246,7 @@ def make_part_cli_rpc_func(node_id): class Test(unittest.TestCase): + test_coin_from = Coins.DASH @classmethod def setUpClass(cls): @@ -273,7 +273,10 @@ class Test(unittest.TestCase): btc_data_dir = os.path.join(cfg.TEST_DATADIRS, str(BTC_NODE)) if os.path.exists(os.path.join(cfg.BITCOIN_BINDIR, 'bitcoin-wallet')): - callrpc_cli(cfg.BITCOIN_BINDIR, btc_data_dir, 'regtest', '-wallet=wallet.dat -legacy create', 'bitcoin-wallet') + try: + callrpc_cli(cfg.BITCOIN_BINDIR, btc_data_dir, 'regtest', '-wallet=wallet.dat -legacy create', 'bitcoin-wallet') + except Exception: + callrpc_cli(cfg.BITCOIN_BINDIR, btc_data_dir, 'regtest', '-wallet=wallet.dat create', 'bitcoin-wallet') cls.daemons.append(startDaemon(btc_data_dir, cfg.BITCOIN_BINDIR, cfg.BITCOIND)) logging.info('Started %s %d', cfg.BITCOIND, cls.daemons[-1].pid) cls.daemons.append(startDaemon(os.path.join(cfg.TEST_DATADIRS, str(DASH_NODE)), cfg.DASH_BINDIR, cfg.DASHD)) @@ -282,7 +285,10 @@ class Test(unittest.TestCase): for i in range(NUM_NODES): data_dir = os.path.join(cfg.TEST_DATADIRS, str(i)) if os.path.exists(os.path.join(cfg.PARTICL_BINDIR, 'particl-wallet')): - callrpc_cli(cfg.PARTICL_BINDIR, data_dir, 'regtest', '-wallet=wallet.dat -legacy create', 'particl-wallet') + try: + callrpc_cli(cfg.PARTICL_BINDIR, data_dir, 'regtest', '-wallet=wallet.dat -legacy create', 'particl-wallet') + except Exception: + callrpc_cli(cfg.PARTICL_BINDIR, data_dir, 'regtest', '-wallet=wallet.dat create', 'particl-wallet') cls.daemons.append(startDaemon(data_dir, cfg.PARTICL_BINDIR, cfg.PARTICLD)) logging.info('Started %s %d', cfg.PARTICLD, cls.daemons[-1].pid) @@ -334,7 +340,7 @@ class Test(unittest.TestCase): logging.info('Mining %d Bitcoin blocks to %s', num_blocks, cls.btc_addr) btcRpc('generatetoaddress {} {}'.format(num_blocks, cls.btc_addr)) - ro = btcRpc('getdeploymentinfo') + ro = btcRpc('getblockchaininfo') checkForks(ro) ro = dashRpc('getwalletinfo') @@ -513,19 +519,27 @@ class Test(unittest.TestCase): swap_clients[0].getChainClientSettings(Coins.DASH)['override_feerate'] = 10.0 wait_for_bid(delay_event, swap_clients[0], bid_id, BidStates.BID_ERROR, wait_for=60) - def test_08_withdrawal(self): - logging.info('---------- Test DASH withdrawals') + def test_08_wallet(self): + logging.info('---------- Test {} wallet'.format(self.test_coin_from.name)) + logging.info('Test withdrawal') addr = dashRpc('getnewaddress \"Withdrawal test\"') wallets = read_json_api(TEST_HTTP_PORT + 0, 'wallets') - assert (float(wallets['DASH']['balance']) > 100) + assert (float(wallets[self.test_coin_from.name]['balance']) > 100) post_json = { 'value': 100, 'address': addr, 'subfee': False, } - json_rv = json.loads(post_json_req('http://127.0.0.1:{}/json/wallets/dash/withdraw'.format(TEST_HTTP_PORT + 0), post_json)) + json_rv = read_json_api(TEST_HTTP_PORT + 0, 'wallets/{}/withdraw'.format(self.test_coin_from.name.lower()), post_json) + assert (len(json_rv['txid']) == 64) + + logging.info('Test createutxo') + post_json = { + 'value': 10, + } + json_rv = read_json_api(TEST_HTTP_PORT + 0, 'wallets/{}/createutxo'.format(self.test_coin_from.name.lower()), post_json) assert (len(json_rv['txid']) == 64) def test_09_initialise_wallet(self): diff --git a/tests/basicswap/extended/test_firo.py b/tests/basicswap/extended/test_firo.py index 5baf4cb..192d890 100644 --- a/tests/basicswap/extended/test_firo.py +++ b/tests/basicswap/extended/test_firo.py @@ -6,7 +6,6 @@ # file LICENSE or http://www.opensource.org/licenses/mit-license.php. import os -import json import random import logging import unittest @@ -35,7 +34,6 @@ from tests.basicswap.common import ( wait_for_bid, make_rpc_func, read_json_api, - post_json_req, TEST_HTTP_PORT, wait_for_offer, wait_for_in_progress, @@ -105,9 +103,9 @@ def prepareDataDir(datadir, node_id, conf_file, dir_prefix, base_p2p_port, base_ class Test(BaseTest): __test__ = True + test_coin_from = Coins.FIRO firo_daemons = [] firo_addr = None - test_coin_from = Coins.FIRO start_ltc_nodes = False start_xmr_nodes = False @@ -397,9 +395,10 @@ class Test(BaseTest): swap_clients[0].getChainClientSettings(Coins.FIRO)['override_feerate'] = 10.0 wait_for_bid(test_delay_event, swap_clients[0], bid_id, BidStates.BID_ERROR, wait_for=60) - def test_08_withdrawal(self): - logging.info('---------- Test {} withdrawals'.format(self.test_coin_from.name)) + def test_08_wallet(self): + logging.info('---------- Test {} wallet'.format(self.test_coin_from.name)) + logging.info('Test withdrawal') addr = self.callnoderpc('getnewaddress', ['Withdrawal test', ]) wallets = read_json_api(TEST_HTTP_PORT + 0, 'wallets') assert (float(wallets[self.test_coin_from.name]['balance']) > 100) @@ -409,7 +408,14 @@ class Test(BaseTest): 'address': addr, 'subfee': False, } - json_rv = json.loads(post_json_req('http://127.0.0.1:{}/json/wallets/{}/withdraw'.format(TEST_HTTP_PORT + 0, self.test_coin_from.name.lower()), post_json)) + json_rv = read_json_api(TEST_HTTP_PORT + 0, 'wallets/{}/withdraw'.format(self.test_coin_from.name.lower()), post_json) + assert (len(json_rv['txid']) == 64) + + logging.info('Test createutxo') + post_json = { + 'value': 10, + } + json_rv = read_json_api(TEST_HTTP_PORT + 0, 'wallets/{}/createutxo'.format(self.test_coin_from.name.lower()), post_json) assert (len(json_rv['txid']) == 64) def test_101_full_swap(self): diff --git a/tests/basicswap/extended/test_nmc.py b/tests/basicswap/extended/test_nmc.py index 6b23818..c139ead 100644 --- a/tests/basicswap/extended/test_nmc.py +++ b/tests/basicswap/extended/test_nmc.py @@ -332,7 +332,7 @@ class Test(unittest.TestCase): logging.info('Mining %d Bitcoin blocks to %s', num_blocks, cls.btc_addr) btcRpc('generatetoaddress {} {}'.format(num_blocks, cls.btc_addr)) - ro = btcRpc('getdeploymentinfo') + ro = btcRpc('getblockchaininfo') checkForks(ro) ro = nmcRpc('getwalletinfo') diff --git a/tests/basicswap/extended/test_pivx.py b/tests/basicswap/extended/test_pivx.py index 19032a9..a72822b 100644 --- a/tests/basicswap/extended/test_pivx.py +++ b/tests/basicswap/extended/test_pivx.py @@ -55,7 +55,6 @@ from tests.basicswap.common import ( wait_for_bid_tx_state, wait_for_in_progress, read_json_api, - post_json_req, TEST_HTTP_HOST, TEST_HTTP_PORT, BASE_PORT, @@ -252,6 +251,7 @@ def make_part_cli_rpc_func(node_id): class Test(unittest.TestCase): + test_coin_from = Coins.PIVX @classmethod def setUpClass(cls): @@ -285,7 +285,10 @@ class Test(unittest.TestCase): btc_data_dir = os.path.join(cfg.TEST_DATADIRS, str(BTC_NODE)) if os.path.exists(os.path.join(cfg.BITCOIN_BINDIR, 'bitcoin-wallet')): - callrpc_cli(cfg.BITCOIN_BINDIR, btc_data_dir, 'regtest', '-wallet=wallet.dat -legacy create', 'bitcoin-wallet') + try: + callrpc_cli(cfg.BITCOIN_BINDIR, btc_data_dir, 'regtest', '-wallet=wallet.dat -legacy create', 'bitcoin-wallet') + except Exception: + callrpc_cli(cfg.BITCOIN_BINDIR, btc_data_dir, 'regtest', '-wallet=wallet.dat create', 'bitcoin-wallet') cls.daemons.append(startDaemon(btc_data_dir, cfg.BITCOIN_BINDIR, cfg.BITCOIND)) logging.info('Started %s %d', cfg.BITCOIND, cls.daemons[-1].pid) cls.daemons.append(startDaemon(os.path.join(cfg.TEST_DATADIRS, str(PIVX_NODE)), cfg.PIVX_BINDIR, cfg.PIVXD)) @@ -294,7 +297,10 @@ class Test(unittest.TestCase): for i in range(NUM_NODES): data_dir = os.path.join(cfg.TEST_DATADIRS, str(i)) if os.path.exists(os.path.join(cfg.PARTICL_BINDIR, 'particl-wallet')): - callrpc_cli(cfg.PARTICL_BINDIR, data_dir, 'regtest', '-wallet=wallet.dat -legacy create', 'particl-wallet') + try: + callrpc_cli(cfg.PARTICL_BINDIR, data_dir, 'regtest', '-wallet=wallet.dat -legacy create', 'particl-wallet') + except Exception: + callrpc_cli(cfg.PARTICL_BINDIR, data_dir, 'regtest', '-wallet=wallet.dat create', 'particl-wallet') cls.daemons.append(startDaemon(data_dir, cfg.PARTICL_BINDIR, cfg.PARTICLD)) logging.info('Started %s %d', cfg.PARTICLD, cls.daemons[-1].pid) @@ -346,7 +352,7 @@ class Test(unittest.TestCase): logging.info('Mining %d Bitcoin blocks to %s', num_blocks, cls.btc_addr) btcRpc('generatetoaddress {} {}'.format(num_blocks, cls.btc_addr)) - ro = btcRpc('getdeploymentinfo') + ro = btcRpc('getblockchaininfo') checkForks(ro) signal.signal(signal.SIGINT, signal_handler) @@ -522,19 +528,27 @@ class Test(unittest.TestCase): swap_clients[0].getChainClientSettings(Coins.PIVX)['override_feerate'] = 10.0 wait_for_bid(delay_event, swap_clients[0], bid_id, BidStates.BID_ERROR, wait_for=60) - def test_08_withdrawal(self): - logging.info('---------- Test PIVX withdrawals') + def test_08_wallet(self): + logging.info('---------- Test {} wallet'.format(self.test_coin_from.name)) + logging.info('Test withdrawal') addr = pivxRpc('getnewaddress \"Withdrawal test\"') wallets = read_json_api(TEST_HTTP_PORT + 0, 'wallets') - assert (float(wallets['PIVX']['balance']) > 100) + assert (float(wallets[self.test_coin_from.name]['balance']) > 100) post_json = { 'value': 100, 'address': addr, 'subfee': False, } - json_rv = json.loads(post_json_req('http://127.0.0.1:{}/json/wallets/pivx/withdraw'.format(TEST_HTTP_PORT + 0), post_json)) + json_rv = read_json_api(TEST_HTTP_PORT + 0, 'wallets/{}/withdraw'.format(self.test_coin_from.name.lower()), post_json) + assert (len(json_rv['txid']) == 64) + + logging.info('Test createutxo') + post_json = { + 'value': 10, + } + json_rv = read_json_api(TEST_HTTP_PORT + 0, 'wallets/{}/createutxo'.format(self.test_coin_from.name.lower()), post_json) assert (len(json_rv['txid']) == 64) def test_09_v3_tx(self):