mirror of
https://github.com/basicswap/basicswap.git
synced 2026-06-11 05:21:40 +02:00
refactor: Use read_json_api in more tests.
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user