mirror of
https://github.com/basicswap/basicswap.git
synced 2025-11-05 10:28:10 +01:00
Start reload test
This commit is contained in:
@@ -28,8 +28,9 @@ class Test(unittest.TestCase):
|
||||
def tearDownClass(self):
|
||||
try:
|
||||
shutil.rmtree(test_path)
|
||||
except Exception as e:
|
||||
logger.warning('tearDownClass %s', str(e))
|
||||
except Exception as ex:
|
||||
logger.warning('tearDownClass %s', str(ex))
|
||||
super(Test, cls).tearDownClass()
|
||||
|
||||
def test(self):
|
||||
testargs = ['basicswap-prepare', '-datadir=' + test_path]
|
||||
|
||||
76
tests/basicswap/test_reload.py
Normal file
76
tests/basicswap/test_reload.py
Normal file
@@ -0,0 +1,76 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright (c) 2019 tecnovert
|
||||
# Distributed under the MIT software license, see the accompanying
|
||||
# file LICENSE.txt or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
"""
|
||||
|
||||
mkdir -p /tmp/test_basicswap/bin/{particl,bitcoin}
|
||||
cp ~/tmp/particl-0.18.1.0-x86_64-linux-gnu.tar.gz /tmp/test_basicswap/bin/particl
|
||||
cp ~/tmp/bitcoin-0.18.0-x86_64-linux-gnu.tar.gz /tmp/test_basicswap/bin/bitcoin
|
||||
|
||||
|
||||
|
||||
"""
|
||||
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
import unittest
|
||||
from unittest.mock import patch
|
||||
from io import StringIO
|
||||
import logging
|
||||
import shutil
|
||||
import json
|
||||
import threading
|
||||
|
||||
import bin.basicswap_prepare as prepareSystem
|
||||
import bin.basicswap_run as runSystem
|
||||
test_path = os.path.expanduser('/tmp/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 setUpClass(cls):
|
||||
super(Test, cls).setUpClass()
|
||||
|
||||
config_path = os.path.join(test_path, 'basicswap.json')
|
||||
try:
|
||||
os.remove(config_path)
|
||||
shutil.rmtree(os.path.join(test_path, 'particl'))
|
||||
shutil.rmtree(os.path.join(test_path, 'bitcoin'))
|
||||
except Exception as ex:
|
||||
logger.warning('setUpClass %s', str(ex))
|
||||
|
||||
testargs = ['basicswap-prepare', '-datadir=' + test_path, '-regtest', '-withoutcoin=litecoin', '-withcoin=bitcoin']
|
||||
with patch.object(sys, 'argv', testargs):
|
||||
prepareSystem.main()
|
||||
|
||||
assert(os.path.exists(config_path))
|
||||
|
||||
def run_thread(self):
|
||||
testargs = ['basicswap-run', '-datadir=' + test_path, '-regtest', '-testmode']
|
||||
with patch.object(sys, 'argv', testargs):
|
||||
runSystem.main()
|
||||
|
||||
def test_reload(self):
|
||||
|
||||
thread = threading.Thread(target=self.run_thread)
|
||||
thread.start()
|
||||
|
||||
time.sleep(5)
|
||||
|
||||
runSystem.swap_client.stopRunning()
|
||||
|
||||
thread.join()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
@@ -405,9 +405,9 @@ class Test(unittest.TestCase):
|
||||
assert(ro['validscripts'] == 1)
|
||||
|
||||
def test_02_part_ltc(self):
|
||||
logging.info('---------- Test PART to LTC')
|
||||
swap_clients = self.swap_clients
|
||||
|
||||
logging.info('---------- Test PART to LTC')
|
||||
offer_id = swap_clients[0].postOffer(Coins.PART, Coins.LTC, 100 * COIN, 0.1 * COIN, 100 * COIN, SwapTypes.SELLER_FIRST)
|
||||
|
||||
self.wait_for_offer(swap_clients[1], offer_id)
|
||||
@@ -432,9 +432,9 @@ class Test(unittest.TestCase):
|
||||
assert(js_1['num_swapping'] == 0 and js_1['num_watched_outputs'] == 0)
|
||||
|
||||
def test_03_ltc_part(self):
|
||||
logging.info('---------- Test LTC to PART')
|
||||
swap_clients = self.swap_clients
|
||||
|
||||
logging.info('---------- Test LTC to PART')
|
||||
offer_id = swap_clients[1].postOffer(Coins.LTC, Coins.PART, 10 * COIN, 9.0 * COIN, 10 * COIN, SwapTypes.SELLER_FIRST)
|
||||
|
||||
self.wait_for_offer(swap_clients[0], offer_id)
|
||||
@@ -457,9 +457,9 @@ class Test(unittest.TestCase):
|
||||
assert(js_1['num_swapping'] == 0 and js_1['num_watched_outputs'] == 0)
|
||||
|
||||
def test_04_ltc_btc(self):
|
||||
logging.info('---------- Test LTC to BTC')
|
||||
swap_clients = self.swap_clients
|
||||
|
||||
logging.info('---------- Test LTC to BTC')
|
||||
offer_id = swap_clients[0].postOffer(Coins.LTC, Coins.BTC, 10 * COIN, 0.1 * COIN, 10 * COIN, SwapTypes.SELLER_FIRST)
|
||||
|
||||
self.wait_for_offer(swap_clients[1], offer_id)
|
||||
@@ -486,9 +486,9 @@ class Test(unittest.TestCase):
|
||||
|
||||
def test_05_refund(self):
|
||||
# Seller submits initiate txn, buyer doesn't respond
|
||||
logging.info('---------- Test refund, LTC to BTC')
|
||||
swap_clients = self.swap_clients
|
||||
|
||||
logging.info('---------- Test refund, LTC to BTC')
|
||||
offer_id = swap_clients[0].postOffer(Coins.LTC, Coins.BTC, 10 * COIN, 0.1 * COIN, 10 * COIN, SwapTypes.SELLER_FIRST,
|
||||
SEQUENCE_LOCK_BLOCKS, 10)
|
||||
|
||||
@@ -511,13 +511,12 @@ class Test(unittest.TestCase):
|
||||
assert(js_1['num_swapping'] == 0 and js_1['num_watched_outputs'] == 0)
|
||||
|
||||
def test_06_self_bid(self):
|
||||
swap_clients = self.swap_clients
|
||||
|
||||
logging.info('---------- Test same client, BTC to LTC')
|
||||
swap_clients = self.swap_clients
|
||||
|
||||
js_0_before = json.loads(urlopen('http://localhost:1800/json').read())
|
||||
|
||||
offer_id = swap_clients[0].postOffer(Coins.LTC, Coins.BTC, 10 * COIN, 10 * COIN, 10 * COIN, SwapTypes.SELLER_FIRST)
|
||||
offer_id = swap_clients[0].postOffer(Coins.BTC, Coins.LTC, 10 * COIN, 10 * COIN, 10 * COIN, SwapTypes.SELLER_FIRST)
|
||||
|
||||
self.wait_for_offer(swap_clients[0], offer_id)
|
||||
offers = swap_clients[0].listOffers()
|
||||
@@ -536,13 +535,12 @@ class Test(unittest.TestCase):
|
||||
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)
|
||||
|
||||
def test_07_error(self):
|
||||
swap_clients = self.swap_clients
|
||||
|
||||
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())
|
||||
|
||||
offer_id = swap_clients[0].postOffer(Coins.LTC, Coins.BTC, 0.001 * COIN, 1.0 * COIN, 0.001 * COIN, SwapTypes.SELLER_FIRST)
|
||||
offer_id = swap_clients[0].postOffer(Coins.BTC, Coins.LTC, 0.001 * COIN, 1.0 * COIN, 0.001 * COIN, SwapTypes.SELLER_FIRST)
|
||||
|
||||
self.wait_for_offer(swap_clients[0], offer_id)
|
||||
offers = swap_clients[0].listOffers()
|
||||
|
||||
Reference in New Issue
Block a user