Increase version, add test for bids sent while recipient is offline.

This commit is contained in:
tecnovert
2021-01-11 23:48:46 +02:00
parent a3ba5cf7e6
commit 60b477e3c0
20 changed files with 352 additions and 208 deletions

View File

@@ -162,7 +162,7 @@ def wait_for_none_active(delay_event, port, wait_for=30):
if delay_event.is_set():
raise ValueError('Test stopped.')
delay_event.wait(1)
js = json.loads(urlopen('http://localhost:{}/json'.format(port)).read())
js = json.loads(urlopen('http://127.0.0.1:{}/json'.format(port)).read())
if js['num_swapping'] == 0 and js['num_watched_outputs'] == 0:
return
raise ValueError('wait_for_none_active timed out.')

View File

@@ -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]

View File

@@ -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)

View File

@@ -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)

View File

@@ -59,16 +59,16 @@ 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())
return
except Exception:
traceback.print_exc()
except Exception as e:
print('waitForServer, error:', str(e))
raise ValueError('waitForServer failed')
def waitForNumOffers(port, offers):
for i in range(20):
summary = json.loads(urlopen('http://localhost:{}/json'.format(port)).read())
summary = json.loads(urlopen('http://127.0.0.1:{}/json'.format(port)).read())
if summary['num_network_offers'] >= offers:
return
time.sleep(1)
@@ -77,7 +77,7 @@ def waitForNumOffers(port, offers):
def waitForNumBids(port, bids):
for i in range(20):
summary = json.loads(urlopen('http://localhost:{}/json'.format(port)).read())
summary = json.loads(urlopen('http://127.0.0.1:{}/json'.format(port)).read())
if summary['num_recv_bids'] >= bids:
return
time.sleep(1)
@@ -86,7 +86,7 @@ def waitForNumBids(port, bids):
def waitForNumSwapping(port, bids):
for i in range(20):
summary = json.loads(urlopen('http://localhost:{}/json'.format(port)).read())
summary = json.loads(urlopen('http://127.0.0.1:{}/json'.format(port)).read())
if summary['num_swapping'] >= bids:
return
time.sleep(1)
@@ -135,7 +135,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:
@@ -152,7 +152,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))
assert(os.path.exists(config_path))
@@ -180,9 +180,10 @@ class Test(unittest.TestCase):
for i in range(20):
blocks = btcRpc(0, 'getblockchaininfo')['blocks']
if blocks >= 500:
if blocks >= num_blocks:
break
assert(blocks >= 500)
time.sleep(2)
assert(blocks >= num_blocks)
data = parse.urlencode({
'addr_from': '-1',
@@ -192,8 +193,8 @@ class Test(unittest.TestCase):
'amt_to': '1',
'lockhrs': '24'}).encode()
offer_id = json.loads(urlopen('http://localhost:12700/json/offers/new', data=data).read())
summary = json.loads(urlopen('http://localhost:12700/json').read())
offer_id = json.loads(urlopen('http://127.0.0.1:12700/json/offers/new', data=data).read())
summary = json.loads(urlopen('http://127.0.0.1:12700/json').read())
assert(summary['num_sent_offers'] == 1)
except Exception:
traceback.print_exc()
@@ -201,24 +202,24 @@ class Test(unittest.TestCase):
logger.info('Waiting for offer:')
waitForNumOffers(12701, 1)
offers = json.loads(urlopen('http://localhost:12701/json/offers').read())
offers = json.loads(urlopen('http://127.0.0.1:12701/json/offers').read())
offer = offers[0]
data = parse.urlencode({
'offer_id': offer['offer_id'],
'amount_from': offer['amount_from']}).encode()
bid_id = json.loads(urlopen('http://localhost:12701/json/bids/new', data=data).read())
bid_id = json.loads(urlopen('http://127.0.0.1:12701/json/bids/new', data=data).read())
waitForNumBids(12700, 1)
bids = json.loads(urlopen('http://localhost:12700/json/bids').read())
bids = json.loads(urlopen('http://127.0.0.1:12700/json/bids').read())
bid = bids[0]
data = parse.urlencode({
'accept': True
}).encode()
rv = json.loads(urlopen('http://localhost:12700/json/bids/{}'.format(bid['bid_id']), data=data).read())
rv = json.loads(urlopen('http://127.0.0.1:12700/json/bids/{}'.format(bid['bid_id']), data=data).read())
assert(rv['bid_state'] == 'Accepted')
waitForNumSwapping(12701, 1)
@@ -231,7 +232,7 @@ class Test(unittest.TestCase):
processes[1].start()
waitForServer(12701)
rv = json.loads(urlopen('http://localhost:12701/json').read())
rv = json.loads(urlopen('http://127.0.0.1:12701/json').read())
assert(rv['num_swapping'] == 1)
update_thread = threading.Thread(target=updateThread)
@@ -241,7 +242,7 @@ class Test(unittest.TestCase):
for i in range(240):
time.sleep(5)
rv = json.loads(urlopen('http://localhost:12700/json/bids/{}'.format(bid['bid_id'])).read())
rv = json.loads(urlopen('http://127.0.0.1:12700/json/bids/{}'.format(bid['bid_id'])).read())
print(rv)
if rv['bid_state'] == 'Completed':
break

View File

@@ -60,10 +60,10 @@ def waitForServer(port, wait_for=20):
raise ValueError('Test stopped.')
try:
delay_event.wait(1)
summary = json.loads(urlopen('http://localhost:{}/json'.format(port)).read())
summary = json.loads(urlopen('http://127.0.0.1:{}/json'.format(port)).read())
return
except Exception:
traceback.print_exc()
except Exception as e:
print('waitForServer, error:', str(e))
raise ValueError('waitForServer failed')
@@ -71,7 +71,7 @@ def waitForNumOffers(port, offers, wait_for=20):
for i in range(wait_for):
if delay_event.is_set():
raise ValueError('Test stopped.')
summary = json.loads(urlopen('http://localhost:{}/json'.format(port)).read())
summary = json.loads(urlopen('http://127.0.0.1:{}/json'.format(port)).read())
if summary['num_network_offers'] >= offers:
return
delay_event.wait(1)
@@ -82,7 +82,7 @@ def waitForNumBids(port, bids, wait_for=20):
for i in range(wait_for):
if delay_event.is_set():
raise ValueError('Test stopped.')
summary = json.loads(urlopen('http://localhost:{}/json'.format(port)).read())
summary = json.loads(urlopen('http://127.0.0.1:{}/json'.format(port)).read())
if summary['num_recv_bids'] >= bids:
return
delay_event.wait(1)
@@ -93,13 +93,25 @@ def waitForNumSwapping(port, bids, wait_for=60):
for i in range(wait_for):
if delay_event.is_set():
raise ValueError('Test stopped.')
summary = json.loads(urlopen('http://localhost:{}/json'.format(port)).read())
summary = json.loads(urlopen('http://127.0.0.1:{}/json'.format(port)).read())
if summary['num_swapping'] >= bids:
return
delay_event.wait(1)
raise ValueError('waitForNumSwapping failed')
def waitForBidState(port, bid_id, state_str, wait_for=60):
for i in range(wait_for):
if delay_event.is_set():
raise ValueError('Test stopped.')
bid = json.loads(urlopen('http://127.0.0.1:12700/json/bids/{}'.format(bid_id)).read())
print('[rm] bid', bid)
if bid['bid_state'] == state_str:
return
delay_event.wait(1)
raise ValueError('waitForBidState failed')
def updateThread(xmr_addr):
while not delay_event.is_set():
try:
@@ -154,7 +166,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))
with open(os.path.join(client_path, 'monero', 'monerod.conf'), 'a') as fp:
fp.write('p2p-bind-ip=127.0.0.1\n')
@@ -196,7 +208,7 @@ class Test(unittest.TestCase):
try:
waitForServer(12701)
wallets = json.loads(urlopen('http://localhost:12701/json/wallets').read())
wallets = json.loads(urlopen('http://127.0.0.1:12701/json/wallets').read())
xmr_addr1 = wallets['6']['deposit_address']
num_blocks = 100
@@ -229,7 +241,7 @@ class Test(unittest.TestCase):
try:
waitForServer(12700)
waitForServer(12701)
wallets1 = json.loads(urlopen('http://localhost:12701/json/wallets').read())
wallets1 = json.loads(urlopen('http://127.0.0.1:12701/json/wallets').read())
assert(float(wallets1['6']['balance']) > 0.0)
data = parse.urlencode({
@@ -240,26 +252,26 @@ class Test(unittest.TestCase):
'amt_to': '1',
'lockhrs': '24'}).encode()
offer_id = json.loads(urlopen('http://localhost:12700/json/offers/new', data=data).read())
summary = json.loads(urlopen('http://localhost:12700/json').read())
offer_id = json.loads(urlopen('http://127.0.0.1:12700/json/offers/new', data=data).read())['offer_id']
summary = json.loads(urlopen('http://127.0.0.1:12700/json').read())
assert(summary['num_sent_offers'] == 1)
logger.info('Waiting for offer')
waitForNumOffers(12701, 1)
offers = json.loads(urlopen('http://localhost:12701/json/offers').read())
offers = json.loads(urlopen('http://127.0.0.1:12701/json/offers').read())
offer = offers[0]
data = parse.urlencode({
'offer_id': offer['offer_id'],
'amount_from': offer['amount_from']}).encode()
bid_id = json.loads(urlopen('http://localhost:12701/json/bids/new', data=data).read())
bid_id = json.loads(urlopen('http://127.0.0.1:12701/json/bids/new', data=data).read())
waitForNumBids(12700, 1)
for i in range(10):
bids = json.loads(urlopen('http://localhost:12700/json/bids').read())
bids = json.loads(urlopen('http://127.0.0.1:12700/json/bids').read())
bid = bids[0]
if bid['bid_state'] == 'Received':
break
@@ -268,7 +280,7 @@ class Test(unittest.TestCase):
data = parse.urlencode({
'accept': True
}).encode()
rv = json.loads(urlopen('http://localhost:12700/json/bids/{}'.format(bid['bid_id']), data=data).read())
rv = json.loads(urlopen('http://127.0.0.1:12700/json/bids/{}'.format(bid['bid_id']), data=data).read())
assert(rv['bid_state'] == 'Accepted')
waitForNumSwapping(12701, 1)
@@ -281,19 +293,27 @@ class Test(unittest.TestCase):
self.processes[1].start()
waitForServer(12701)
rv = json.loads(urlopen('http://localhost:12701/json').read())
rv = json.loads(urlopen('http://127.0.0.1:12701/json').read())
assert(rv['num_swapping'] == 1)
rv = json.loads(urlopen('http://127.0.0.1:12700/json/revokeoffer/{}'.format(offer_id)).read())
assert(rv['revoked_offer'] == offer_id)
logger.info('Completing swap')
for i in range(240):
if delay_event.is_set():
raise ValueError('Test stopped.')
delay_event.wait(4)
rv = json.loads(urlopen('http://localhost:12700/json/bids/{}'.format(bid['bid_id'])).read())
rv = json.loads(urlopen('http://127.0.0.1:12700/json/bids/{}'.format(bid['bid_id'])).read())
if rv['bid_state'] == 'Completed':
break
assert(rv['bid_state'] == 'Completed')
# Ensure offer was revoked
summary = json.loads(urlopen('http://127.0.0.1:12700/json').read())
assert(summary['num_network_offers'] == 0)
except Exception as e:
traceback.print_exc()
raise(e)
@@ -307,10 +327,89 @@ class Test(unittest.TestCase):
try:
waitForServer(12700)
waitForServer(12701)
wallets1 = json.loads(urlopen('http://localhost:12701/json/wallets').read())
print('wallets 1', json.dumps(wallets1, indent=4))
wallets1 = json.loads(urlopen('http://127.0.0.1:12701/json/wallets').read())
assert(float(wallets1['6']['balance']) > 0.0)
offer_data = {
'addr_from': '-1',
'coin_from': '1',
'coin_to': '6',
'amt_from': '1',
'amt_to': '1',
'lockhrs': '24',
'autoaccept': True}
rv = json.loads(urlopen('http://127.0.0.1:12700/json/offers/new', data=parse.urlencode(offer_data).encode()).read())
offer0_id = rv['offer_id']
offer_data['amt_from'] = '2'
rv = json.loads(urlopen('http://127.0.0.1:12700/json/offers/new', data=parse.urlencode(offer_data).encode()).read())
offer1_id = rv['offer_id']
summary = json.loads(urlopen('http://127.0.0.1:12700/json').read())
assert(summary['num_sent_offers'] > 1)
logger.info('Waiting for offer')
waitForNumOffers(12701, 2)
logger.info('Stopping node 0')
c0 = self.processes[0]
c0.terminate()
c0.join()
offers = json.loads(urlopen('http://127.0.0.1:12701/json/offers/{}'.format(offer0_id)).read())
assert(len(offers) == 1)
offer0 = offers[0]
bid_data = {
'offer_id': offer0_id,
'amount_from': offer0['amount_from']}
bid0_id = json.loads(urlopen('http://127.0.0.1:12701/json/bids/new', data=parse.urlencode(bid_data).encode()).read())['bid_id']
offers = json.loads(urlopen('http://127.0.0.1:12701/json/offers/{}'.format(offer1_id)).read())
assert(len(offers) == 1)
offer1 = offers[0]
bid_data = {
'offer_id': offer1_id,
'amount_from': offer1['amount_from']}
bid1_id = json.loads(urlopen('http://127.0.0.1:12701/json/bids/new', data=parse.urlencode(bid_data).encode()).read())['bid_id']
delay_event.wait(5)
logger.info('Starting node 0')
self.processes[0] = multiprocessing.Process(target=self.run_thread, args=(0,))
self.processes[0].start()
waitForServer(12700)
waitForNumBids(12700, 2)
waitForBidState(12700, bid0_id, 'Received')
waitForBidState(12700, bid1_id, 'Received')
# Manually accept on top of auto-accept for extra chaos
data = parse.urlencode({
'accept': True
}).encode()
rv = json.loads(urlopen('http://127.0.0.1:12700/json/bids/{}'.format(bid0_id), data=data).read())
assert(rv['bid_state'] == 'Accepted')
rv = json.loads(urlopen('http://127.0.0.1:12700/json/bids/{}'.format(bid1_id), data=data).read())
assert(rv['bid_state'] == 'Accepted')
logger.info('Completing swap')
for i in range(240):
if delay_event.is_set():
raise ValueError('Test stopped.')
delay_event.wait(4)
rv0 = json.loads(urlopen('http://127.0.0.1:12700/json/bids/{}'.format(bid0_id)).read())
rv1 = json.loads(urlopen('http://127.0.0.1:12700/json/bids/{}'.format(bid1_id)).read())
if rv0['bid_state'] == 'Completed' and rv1['bid_state'] == 'Completed':
break
assert(rv0['bid_state'] == 'Completed')
assert(rv1['bid_state'] == 'Completed')
except Exception as e:
traceback.print_exc()
raise(e)

View File

@@ -152,7 +152,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,
@@ -423,8 +423,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)
@@ -448,8 +448,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)
@@ -473,10 +473,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)
@@ -502,8 +502,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)
@@ -511,7 +511,7 @@ class Test(unittest.TestCase):
logging.info('---------- Test same client, BTC to LTC')
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.BTC, Coins.LTC, 10 * COIN, 10 * COIN, 10 * COIN, SwapTypes.SELLER_FIRST)
@@ -527,7 +527,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)
@@ -535,7 +535,7 @@ class Test(unittest.TestCase):
logging.info('---------- Test error, BTC to LTC, 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.BTC, Coins.LTC, 0.001 * COIN, 1.0 * COIN, 0.001 * COIN, SwapTypes.SELLER_FIRST)
@@ -580,8 +580,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)

View File

@@ -119,7 +119,7 @@ def startXmrWalletRPC(node_dir, bin_dir, wallet_bin, node_id, opts=[]):
data_dir = os.path.expanduser(node_dir)
args = [daemon_bin]
args += ['--non-interactive']
args += ['--daemon-address=localhost:{}'.format(XMR_BASE_RPC_PORT + node_id)]
args += ['--daemon-address=127.0.0.1:{}'.format(XMR_BASE_RPC_PORT + node_id)]
args += ['--no-dns']
args += ['--rpc-bind-port={}'.format(XMR_BASE_WALLET_RPC_PORT + node_id)]
args += ['--wallet-dir={}'.format(os.path.join(data_dir, 'wallets'))]
@@ -145,7 +145,7 @@ def prepare_swapclient_dir(datadir, node_id, network_key, network_pubkey):
'debug': True,
'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,
@@ -431,7 +431,7 @@ class Test(unittest.TestCase):
logging.info('---------- Test PART to XMR')
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())
assert(make_int(js_1[str(int(Coins.XMR))]['balance'], scale=12) > 0)
assert(make_int(js_1[str(int(Coins.XMR))]['unconfirmed'], scale=12) > 0)
@@ -453,7 +453,7 @@ class Test(unittest.TestCase):
wait_for_bid(delay_event, swap_clients[0], bid_id, BidStates.SWAP_COMPLETED, wait_for=180)
wait_for_bid(delay_event, swap_clients[1], bid_id, BidStates.SWAP_COMPLETED, sent=True)
js_0_end = json.loads(urlopen('http://localhost:1800/json/wallets').read())
js_0_end = json.loads(urlopen('http://127.0.0.1:1800/json/wallets').read())
end_xmr = float(js_0_end['6']['balance']) + float(js_0_end['6']['unconfirmed'])
assert(end_xmr > 10.9 and end_xmr < 11.0)
@@ -461,7 +461,7 @@ class Test(unittest.TestCase):
logging.info('---------- Test PART to XMR leader recovers coin a lock tx')
swap_clients = self.swap_clients
js_w0_before = json.loads(urlopen('http://localhost:1800/json/wallets').read())
js_w0_before = json.loads(urlopen('http://127.0.0.1:1800/json/wallets').read())
offer_id = swap_clients[0].postOffer(
Coins.PART, Coins.XMR, 101 * COIN, 0.12 * XMR_COIN, 101 * COIN, SwapTypes.XMR_SWAP,
@@ -483,7 +483,7 @@ class Test(unittest.TestCase):
wait_for_bid(delay_event, swap_clients[0], bid_id, BidStates.XMR_SWAP_FAILED_REFUNDED, wait_for=180)
wait_for_bid(delay_event, swap_clients[1], bid_id, BidStates.XMR_SWAP_FAILED_REFUNDED, sent=True)
js_w0_after = json.loads(urlopen('http://localhost:1800/json/wallets').read())
js_w0_after = json.loads(urlopen('http://127.0.0.1:1800/json/wallets').read())
print('[rm] js_w0_before', json.dumps(js_w0_before))
print('[rm] js_w0_after', json.dumps(js_w0_after))
@@ -491,7 +491,7 @@ class Test(unittest.TestCase):
logging.info('---------- Test PART to XMR follower recovers coin a lock tx')
swap_clients = self.swap_clients
js_w0_before = json.loads(urlopen('http://localhost:1800/json/wallets').read())
js_w0_before = json.loads(urlopen('http://127.0.0.1:1800/json/wallets').read())
offer_id = swap_clients[0].postOffer(
Coins.PART, Coins.XMR, 101 * COIN, 0.13 * XMR_COIN, 101 * COIN, SwapTypes.XMR_SWAP,
@@ -514,7 +514,7 @@ class Test(unittest.TestCase):
wait_for_bid(delay_event, swap_clients[0], bid_id, BidStates.BID_ABANDONED, wait_for=180)
wait_for_bid(delay_event, swap_clients[1], bid_id, BidStates.XMR_SWAP_FAILED_SWIPED, wait_for=80, sent=True)
js_w0_after = json.loads(urlopen('http://localhost:1800/json/wallets').read())
js_w0_after = json.loads(urlopen('http://127.0.0.1:1800/json/wallets').read())
wait_for_none_active(delay_event, 1800)
wait_for_none_active(delay_event, 1801)
@@ -629,11 +629,11 @@ class Test(unittest.TestCase):
def test_08_withdraw(self):
logging.info('---------- Test xmr withdrawals')
swap_clients = self.swap_clients
js_0 = json.loads(urlopen('http://localhost:1800/json/wallets').read())
js_0 = json.loads(urlopen('http://127.0.0.1:1800/json/wallets').read())
print('js_0 debug', js_0)
address_to = js_0[str(int(Coins.XMR))]['deposit_address']
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())
assert(float(js_1[str(int(Coins.XMR))]['balance']) > 0.0)
swap_clients[1].withdrawCoin(Coins.XMR, 1.1, address_to, False)