refactor: Use read_json_api in more tests.

This commit is contained in:
tecnovert committed 2022-07-04 00:47:30 +02:00
1 parent 0c620ea388
commit 02bd90053a
12 files changed
+118 -115

No files matched your search

+4 -4
View File
@@ -14,7 +14,6 @@ import logging
import unittest
import traceback
import threading
from urllib.request import urlopen
import basicswap.config as cfg
from basicswap.basicswap import (
@@ -46,6 +45,7 @@ from tests.basicswap.common import (
checkForks,
stopDaemons,
delay_for,
read_json_api,
TEST_HTTP_HOST,
TEST_HTTP_PORT,
BASE_P2P_PORT,
@@ -305,7 +305,7 @@ class Test(unittest.TestCase):
for i in range(wait_for):
if delay_event.is_set():
raise ValueError('Test stopped.')
js = json.loads(urlopen('http://127.0.0.1:{}/json/network'.format(port)).read())
js = read_json_api(port, 'network')
num_nodes = 0
for p in js['peers']:
if p['ready'] is True:
@@ -320,7 +320,7 @@ class Test(unittest.TestCase):
logging.info('---------- Test Network')
swap_clients = self.swap_clients
js_1 = json.loads(urlopen('http://127.0.0.1:1801/json/wallets').read())
js_1 = read_json_api(1801, 'wallets')
offer_id = swap_clients[0].postOffer(Coins.PART, Coins.BTC, 100 * COIN, 0.1 * COIN, 100 * COIN, SwapTypes.SELLER_FIRST)
@@ -329,7 +329,7 @@ class Test(unittest.TestCase):
self.wait_for_num_nodes(1800, 2)
js_n0 = json.loads(urlopen('http://127.0.0.1:1800/json/network').read())
js_n0 = read_json_api(1800, 'network')
print(dumpj(js_n0))
path = [swap_clients[0]._network._network_pubkey, swap_clients[2]._network._network_pubkey]
+13 -13
View File
@@ -19,7 +19,6 @@ import signal
import logging
import unittest
import threading
from urllib.request import urlopen
import basicswap.config as cfg
from basicswap.basicswap import (
@@ -54,6 +53,7 @@ from tests.basicswap.common import (
wait_for_bid,
wait_for_bid_tx_state,
wait_for_in_progress,
read_json_api,
TEST_HTTP_HOST,
TEST_HTTP_PORT,
BASE_PORT,
@@ -383,8 +383,8 @@ class Test(unittest.TestCase):
wait_for_bid(delay_event, swap_clients[0], bid_id, BidStates.SWAP_COMPLETED, wait_for=60)
wait_for_bid(delay_event, swap_clients[1], bid_id, BidStates.SWAP_COMPLETED, sent=True, wait_for=60)
js_0 = json.loads(urlopen('http://127.0.0.1:1800/json').read())
js_1 = json.loads(urlopen('http://127.0.0.1:1801/json').read())
js_0 = read_json_api(1800)
js_1 = read_json_api(1801)
assert(js_0['num_swapping'] == 0 and js_0['num_watched_outputs'] == 0)
assert(js_1['num_swapping'] == 0 and js_1['num_watched_outputs'] == 0)
@@ -408,8 +408,8 @@ class Test(unittest.TestCase):
wait_for_bid(delay_event, swap_clients[0], bid_id, BidStates.SWAP_COMPLETED, sent=True, wait_for=60)
wait_for_bid(delay_event, swap_clients[1], bid_id, BidStates.SWAP_COMPLETED, wait_for=60)
js_0 = json.loads(urlopen('http://127.0.0.1:1800/json').read())
js_1 = json.loads(urlopen('http://127.0.0.1:1801/json').read())
js_0 = read_json_api(1800)
js_1 = read_json_api(1801)
assert(js_0['num_swapping'] == 0 and js_0['num_watched_outputs'] == 0)
assert(js_1['num_swapping'] == 0 and js_1['num_watched_outputs'] == 0)
@@ -433,10 +433,10 @@ class Test(unittest.TestCase):
wait_for_bid(delay_event, swap_clients[0], bid_id, BidStates.SWAP_COMPLETED, wait_for=60)
wait_for_bid(delay_event, swap_clients[1], bid_id, BidStates.SWAP_COMPLETED, sent=True, wait_for=60)
js_0bid = json.loads(urlopen('http://127.0.0.1:1800/json/bids/{}'.format(bid_id.hex())).read())
js_0bid = read_json_api(1800, 'bids/{}'.format(bid_id.hex()))
js_0 = json.loads(urlopen('http://127.0.0.1:1800/json').read())
js_1 = json.loads(urlopen('http://127.0.0.1:1801/json').read())
js_0 = read_json_api(1800)
js_1 = read_json_api(1801)
assert(js_0['num_swapping'] == 0 and js_0['num_watched_outputs'] == 0)
assert(js_1['num_swapping'] == 0 and js_1['num_watched_outputs'] == 0)
@@ -462,8 +462,8 @@ class Test(unittest.TestCase):
wait_for_bid(delay_event, swap_clients[0], bid_id, BidStates.SWAP_COMPLETED, wait_for=60)
wait_for_bid(delay_event, swap_clients[1], bid_id, BidStates.BID_ABANDONED, sent=True, wait_for=60)
js_0 = json.loads(urlopen('http://127.0.0.1:1800/json').read())
js_1 = json.loads(urlopen('http://127.0.0.1:1801/json').read())
js_0 = read_json_api(1800)
js_1 = read_json_api(1801)
assert(js_0['num_swapping'] == 0 and js_0['num_watched_outputs'] == 0)
assert(js_1['num_swapping'] == 0 and js_1['num_watched_outputs'] == 0)
@@ -471,7 +471,7 @@ class Test(unittest.TestCase):
logging.info('---------- Test same client, BTC to NMC')
swap_clients = self.swap_clients
js_0_before = json.loads(urlopen('http://127.0.0.1:1800/json').read())
js_0_before = read_json_api(1800)
offer_id = swap_clients[0].postOffer(Coins.NMC, Coins.BTC, 10 * COIN, 10 * COIN, 10 * COIN, SwapTypes.SELLER_FIRST, ABS_LOCK_TIME)
@@ -487,7 +487,7 @@ class Test(unittest.TestCase):
wait_for_bid_tx_state(delay_event, swap_clients[0], bid_id, TxStates.TX_REDEEMED, TxStates.TX_REDEEMED, wait_for=60)
wait_for_bid(delay_event, swap_clients[0], bid_id, BidStates.SWAP_COMPLETED, wait_for=60)
js_0 = json.loads(urlopen('http://127.0.0.1:1800/json').read())
js_0 = read_json_api(1800)
assert(js_0['num_swapping'] == 0 and js_0['num_watched_outputs'] == 0)
assert(js_0['num_recv_bids'] == js_0_before['num_recv_bids'] + 1 and js_0['num_sent_bids'] == js_0_before['num_sent_bids'] + 1)
@@ -495,7 +495,7 @@ class Test(unittest.TestCase):
logging.info('---------- Test error, BTC to NMC, set fee above bid value')
swap_clients = self.swap_clients
js_0_before = json.loads(urlopen('http://127.0.0.1:1800/json').read())
js_0_before = read_json_api(1800)
offer_id = swap_clients[0].postOffer(Coins.NMC, Coins.BTC, 0.001 * COIN, 1.0 * COIN, 0.001 * COIN, SwapTypes.SELLER_FIRST, ABS_LOCK_TIME)
+7 -6
View File
@@ -1,7 +1,7 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Copyright (c) 2020-2021 tecnovert
# Copyright (c) 2020-2022 tecnovert
# Distributed under the MIT software license, see the accompanying
# file LICENSE or http://www.opensource.org/licenses/mit-license.php.
@@ -19,19 +19,20 @@ python tests/basicswap/extended/test_wallet_init.py
import os
import sys
import json
import time
import shutil
import logging
import unittest
import traceback
import multiprocessing
from urllib.request import urlopen
from unittest.mock import patch
from tests.basicswap.mnemonics import mnemonics
import basicswap.config as cfg
from tests.basicswap.common import (
read_json_api,
)
import bin.basicswap_prepare as prepareSystem
import bin.basicswap_run as runSystem
@@ -55,7 +56,7 @@ def waitForServer(port):
for i in range(20):
try:
time.sleep(1)
summary = json.loads(urlopen('http://127.0.0.1:{}/json'.format(port)).read())
summary = read_json_api(port)
break
except Exception as e:
print('waitForServer, error:', str(e))
@@ -149,12 +150,12 @@ class Test(unittest.TestCase):
try:
waitForServer(12700)
wallets_0 = json.loads(urlopen('http://127.0.0.1:12700/json/wallets').read())
wallets_0 = read_json_api(12700, 'wallets')
assert(wallets_0['1']['expected_seed'] is True)
assert(wallets_0['6']['expected_seed'] is True)
waitForServer(12701)
wallets_1 = json.loads(urlopen('http://127.0.0.1:12701/json/wallets').read())
wallets_1 = read_json_api(12701, 'wallets')
assert(wallets_0['1']['expected_seed'] is True)
assert(wallets_1['6']['expected_seed'] is True)
@@ -29,7 +29,6 @@ import logging
import unittest
import threading
import multiprocessing
from urllib.request import urlopen
from unittest.mock import patch
from basicswap.rpc_xmr import (
@@ -40,6 +39,7 @@ from basicswap.rpc import (
)
from tests.basicswap.mnemonics import mnemonics as test_mnemonics
from tests.basicswap.common import (
read_json_api,
waitForServer,
)
from basicswap.contrib.rpcauth import generate_salt, password_to_hmac
@@ -268,7 +268,7 @@ class Test(unittest.TestCase):
for i in range(NUM_NODES):
waitForServer(self.delay_event, UI_PORT + i)
wallets = json.loads(urlopen('http://127.0.0.1:{}/json/wallets'.format(UI_PORT + 1)).read())
wallets = read_json_api(UI_PORT + 1, 'wallets')
self.xmr_addr = wallets['6']['main_address']
num_blocks = 100