Increase version, add test for bids sent while recipient is offline.
This commit is contained in:
20 files changed
+352
-208
No files matched your search
@@ -79,7 +79,7 @@ def prepare_swapclient_dir(datadir, node_id, network_key, network_pubkey):
|
||||
'p2p_port': BASE_P2P_PORT + node_id,
|
||||
'zmqhost': 'tcp://127.0.0.1',
|
||||
'zmqport': BASE_ZMQ_PORT + node_id,
|
||||
'htmlhost': 'localhost',
|
||||
'htmlhost': '127.0.0.1',
|
||||
'htmlport': TEST_HTTP_PORT + node_id,
|
||||
'network_key': network_key,
|
||||
'network_pubkey': network_pubkey,
|
||||
@@ -298,7 +298,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://localhost:{}/json/network'.format(port)).read())
|
||||
js = json.loads(urlopen('http://127.0.0.1:{}/json/network'.format(port)).read())
|
||||
num_nodes = 0
|
||||
for p in js['peers']:
|
||||
if p['ready'] is True:
|
||||
@@ -313,7 +313,7 @@ class Test(unittest.TestCase):
|
||||
logging.info('---------- Test Network')
|
||||
swap_clients = self.swap_clients
|
||||
|
||||
js_1 = json.loads(urlopen('http://localhost:1801/json/wallets').read())
|
||||
js_1 = json.loads(urlopen('http://127.0.0.1:1801/json/wallets').read())
|
||||
|
||||
offer_id = swap_clients[0].postOffer(Coins.PART, Coins.BTC, 100 * COIN, 0.1 * COIN, 100 * COIN, SwapTypes.SELLER_FIRST)
|
||||
|
||||
@@ -322,7 +322,7 @@ class Test(unittest.TestCase):
|
||||
|
||||
self.wait_for_num_nodes(1800, 2)
|
||||
|
||||
js_n0 = json.loads(urlopen('http://localhost:1800/json/network').read())
|
||||
js_n0 = json.loads(urlopen('http://127.0.0.1:1800/json/network').read())
|
||||
print(dumpj(js_n0))
|
||||
|
||||
path = [swap_clients[0]._network._network_pubkey, swap_clients[2]._network._network_pubkey]
|
||||
|
||||
@@ -146,7 +146,7 @@ def prepareDir(datadir, nodeId, network_key, network_pubkey):
|
||||
'debug': True,
|
||||
'zmqhost': 'tcp://127.0.0.1',
|
||||
'zmqport': BASE_ZMQ_PORT + nodeId,
|
||||
'htmlhost': 'localhost',
|
||||
'htmlhost': '127.0.0.1',
|
||||
'htmlport': 12700 + nodeId,
|
||||
'network_key': network_key,
|
||||
'network_pubkey': network_pubkey,
|
||||
@@ -380,8 +380,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://localhost:1800/json').read())
|
||||
js_1 = json.loads(urlopen('http://localhost:1801/json').read())
|
||||
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())
|
||||
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)
|
||||
|
||||
@@ -405,8 +405,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://localhost:1800/json').read())
|
||||
js_1 = json.loads(urlopen('http://localhost:1801/json').read())
|
||||
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())
|
||||
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)
|
||||
|
||||
@@ -430,10 +430,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://localhost:1800/json/bids/{}'.format(bid_id.hex())).read())
|
||||
js_0bid = json.loads(urlopen('http://127.0.0.1:1800/json/bids/{}'.format(bid_id.hex())).read())
|
||||
|
||||
js_0 = json.loads(urlopen('http://localhost:1800/json').read())
|
||||
js_1 = json.loads(urlopen('http://localhost:1801/json').read())
|
||||
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())
|
||||
|
||||
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)
|
||||
@@ -459,8 +459,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://localhost:1800/json').read())
|
||||
js_1 = json.loads(urlopen('http://localhost:1801/json').read())
|
||||
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())
|
||||
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)
|
||||
|
||||
@@ -468,7 +468,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://localhost:1800/json').read())
|
||||
js_0_before = json.loads(urlopen('http://127.0.0.1:1800/json').read())
|
||||
|
||||
offer_id = swap_clients[0].postOffer(Coins.NMC, Coins.BTC, 10 * COIN, 10 * COIN, 10 * COIN, SwapTypes.SELLER_FIRST, ABS_LOCK_TIME)
|
||||
|
||||
@@ -484,7 +484,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://localhost:1800/json').read())
|
||||
js_0 = json.loads(urlopen('http://127.0.0.1:1800/json').read())
|
||||
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)
|
||||
|
||||
@@ -492,7 +492,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://localhost:1800/json').read())
|
||||
js_0_before = json.loads(urlopen('http://127.0.0.1:1800/json').read())
|
||||
|
||||
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)
|
||||
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright (c) 2019 tecnovert
|
||||
# Distributed under the MIT software license, see the accompanying
|
||||
# file LICENSE or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
import os
|
||||
import sys
|
||||
import json
|
||||
import shutil
|
||||
import logging
|
||||
import unittest
|
||||
|
||||
from io import StringIO
|
||||
from unittest.mock import patch
|
||||
|
||||
import basicswap.config as cfg
|
||||
import bin.basicswap_prepare as prepareSystem
|
||||
test_path = os.path.expanduser(os.getenv('TEST_PREPARE_PATH', '~/test_basicswap'))
|
||||
|
||||
logger = logging.getLogger()
|
||||
logger.level = logging.DEBUG
|
||||
if not len(logger.handlers):
|
||||
logger.addHandler(logging.StreamHandler(sys.stdout))
|
||||
|
||||
|
||||
class Test(unittest.TestCase):
|
||||
@classmethod
|
||||
def tearDownClass(self):
|
||||
try:
|
||||
shutil.rmtree(test_path)
|
||||
except Exception as ex:
|
||||
logger.warning('tearDownClass %s', str(ex))
|
||||
super(Test, self).tearDownClass()
|
||||
|
||||
def test(self):
|
||||
testargs = ['basicswap-prepare', '-datadir=' + test_path, '-withcoin=litecoin']
|
||||
with patch.object(sys, 'argv', testargs):
|
||||
prepareSystem.main()
|
||||
|
||||
config_path = os.path.join(test_path, cfg.CONFIG_FILENAME)
|
||||
self.assertTrue(os.path.exists(config_path))
|
||||
|
||||
logger.info('Test no overwrite')
|
||||
testargs = ['basicswap-prepare', '-datadir=' + test_path, '-withcoin=litecoin']
|
||||
with patch('sys.stderr', new=StringIO()) as fake_stderr:
|
||||
with patch.object(sys, 'argv', testargs):
|
||||
with self.assertRaises(SystemExit) as cm:
|
||||
prepareSystem.main()
|
||||
|
||||
self.assertEqual(cm.exception.code, 1)
|
||||
logger.info('fake_stderr.getvalue() %s', fake_stderr.getvalue())
|
||||
self.assertTrue('exists, exiting' in fake_stderr.getvalue())
|
||||
|
||||
logger.info('Test addcoin new')
|
||||
testargs = ['basicswap-prepare', '-datadir=' + test_path, '-addcoin=namecoin']
|
||||
with patch.object(sys, 'argv', testargs):
|
||||
prepareSystem.main()
|
||||
with open(config_path) as fs:
|
||||
settings = json.load(fs)
|
||||
self.assertTrue(settings['chainclients']['namecoin']['connection_type'] == 'rpc')
|
||||
|
||||
logger.info('Test disablecoin')
|
||||
testargs = ['basicswap-prepare', '-datadir=' + test_path, '-disablecoin=namecoin']
|
||||
with patch.object(sys, 'argv', testargs):
|
||||
prepareSystem.main()
|
||||
with open(config_path) as fs:
|
||||
settings = json.load(fs)
|
||||
self.assertTrue(settings['chainclients']['namecoin']['connection_type'] == 'none')
|
||||
|
||||
logger.info('Test addcoin existing')
|
||||
testargs = ['basicswap-prepare', '-datadir=' + test_path, '-addcoin=namecoin']
|
||||
with patch.object(sys, 'argv', testargs):
|
||||
prepareSystem.main()
|
||||
with open(config_path) as fs:
|
||||
settings = json.load(fs)
|
||||
self.assertTrue(settings['chainclients']['namecoin']['connection_type'] == 'rpc')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
@@ -55,10 +55,10 @@ def waitForServer(port):
|
||||
for i in range(20):
|
||||
try:
|
||||
time.sleep(1)
|
||||
summary = json.loads(urlopen('http://localhost:{}/json'.format(port)).read())
|
||||
summary = json.loads(urlopen('http://127.0.0.1:{}/json'.format(port)).read())
|
||||
break
|
||||
except Exception:
|
||||
traceback.print_exc()
|
||||
except Exception as e:
|
||||
print('waitForServer, error:', str(e))
|
||||
|
||||
|
||||
class Test(unittest.TestCase):
|
||||
@@ -98,7 +98,7 @@ class Test(unittest.TestCase):
|
||||
fp.write('minstakeinterval=5\n')
|
||||
for ip in range(3):
|
||||
if ip != i:
|
||||
fp.write('connect=localhost:{}\n'.format(PARTICL_PORT_BASE + ip))
|
||||
fp.write('connect=127.0.0.1:{}\n'.format(PARTICL_PORT_BASE + ip))
|
||||
|
||||
# Pruned nodes don't provide blocks
|
||||
with open(os.path.join(client_path, 'bitcoin', 'bitcoin.conf'), 'r') as fp:
|
||||
@@ -115,7 +115,7 @@ class Test(unittest.TestCase):
|
||||
fp.write('bind=127.0.0.1\n')
|
||||
for ip in range(3):
|
||||
if ip != i:
|
||||
fp.write('connect=localhost:{}\n'.format(BITCOIN_PORT_BASE + ip))
|
||||
fp.write('connect=127.0.0.1:{}\n'.format(BITCOIN_PORT_BASE + ip))
|
||||
|
||||
with open(os.path.join(client_path, 'monero', 'monerod.conf'), 'a') as fp:
|
||||
fp.write('p2p-bind-ip=127.0.0.1\n')
|
||||
@@ -145,12 +145,12 @@ class Test(unittest.TestCase):
|
||||
try:
|
||||
waitForServer(12700)
|
||||
|
||||
wallets_0 = json.loads(urlopen('http://localhost:12700/json/wallets').read())
|
||||
wallets_0 = json.loads(urlopen('http://127.0.0.1:12700/json/wallets').read())
|
||||
assert(wallets_0['1']['expected_seed'] is True)
|
||||
assert(wallets_0['6']['expected_seed'] is True)
|
||||
|
||||
waitForServer(12701)
|
||||
wallets_1 = json.loads(urlopen('http://localhost:12701/json/wallets').read())
|
||||
wallets_1 = json.loads(urlopen('http://127.0.0.1:12701/json/wallets').read())
|
||||
|
||||
assert(wallets_0['1']['expected_seed'] is True)
|
||||
assert(wallets_1['6']['expected_seed'] is True)
|
||||
|
||||
Reference in new issue
Block a user