mirror of
https://github.com/basicswap/basicswap.git
synced 2026-04-08 18:37:23 +02:00
Merge branch 'dev' into electrum
This commit is contained in:
@@ -623,6 +623,18 @@ class TestBase(unittest.TestCase):
|
||||
raise ValueError(f"wait_for_particl_height failed http_port: {http_port}")
|
||||
|
||||
|
||||
def run_process(client_id):
|
||||
client_path = os.path.join(TEST_PATH, "client{}".format(client_id))
|
||||
testargs = [
|
||||
"basicswap-run",
|
||||
"-datadir=" + client_path,
|
||||
"-regtest",
|
||||
f"-logprefix=BSX{client_id}",
|
||||
]
|
||||
with patch.object(sys, "argv", testargs):
|
||||
runSystem.main()
|
||||
|
||||
|
||||
class XmrTestBase(TestBase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
@@ -633,24 +645,13 @@ class XmrTestBase(TestBase):
|
||||
|
||||
prepare_nodes(3, "monero")
|
||||
|
||||
def run_thread(self, client_id):
|
||||
client_path = os.path.join(TEST_PATH, "client{}".format(client_id))
|
||||
testargs = [
|
||||
"basicswap-run",
|
||||
"-datadir=" + client_path,
|
||||
"-regtest",
|
||||
f"-logprefix=BSX{client_id}",
|
||||
]
|
||||
with patch.object(sys, "argv", testargs):
|
||||
runSystem.main()
|
||||
|
||||
def start_processes(self):
|
||||
multiprocessing.set_start_method("fork")
|
||||
self.delay_event.clear()
|
||||
|
||||
for i in range(3):
|
||||
self.processes.append(
|
||||
multiprocessing.Process(target=self.run_thread, args=(i,))
|
||||
multiprocessing.Process(target=run_process, args=(i,))
|
||||
)
|
||||
self.processes[-1].start()
|
||||
|
||||
|
||||
@@ -32,6 +32,7 @@ from tests.basicswap.common import (
|
||||
waitForNumSwapping,
|
||||
)
|
||||
from tests.basicswap.common_xmr import (
|
||||
run_process,
|
||||
XmrTestBase,
|
||||
)
|
||||
|
||||
@@ -122,7 +123,7 @@ class Test(XmrTestBase):
|
||||
c1 = self.processes[1]
|
||||
c1.terminate()
|
||||
c1.join()
|
||||
self.processes[1] = multiprocessing.Process(target=self.run_thread, args=(1,))
|
||||
self.processes[1] = multiprocessing.Process(target=run_process, args=(1,))
|
||||
self.processes[1].start()
|
||||
|
||||
waitForServer(self.delay_event, 12701)
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright (c) 2022-2023 tecnovert
|
||||
# Copyright (c) 2024 The Basicswap developers
|
||||
# Copyright (c) 2024-2026 The Basicswap developers
|
||||
# Distributed under the MIT software license, see the accompanying
|
||||
# file LICENSE or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
@@ -199,7 +199,7 @@ class Test(BaseTest):
|
||||
0, "getnewaddress", ["mining_addr"], base_rpc_port=FIRO_BASE_RPC_PORT
|
||||
)
|
||||
# cls.firo_addr = callnoderpc(0, 'addwitnessaddress', [cls.firo_addr], base_rpc_port=FIRO_BASE_RPC_PORT)
|
||||
logging.info("Mining %d Firo blocks to %s", num_blocks, cls.firo_addr)
|
||||
logging.info(f"Mining {num_blocks} Firo blocks to {cls.firo_addr}")
|
||||
callnoderpc(
|
||||
0,
|
||||
"generatetoaddress",
|
||||
@@ -230,7 +230,7 @@ class Test(BaseTest):
|
||||
0, "getblockcount", base_rpc_port=FIRO_BASE_RPC_PORT
|
||||
)
|
||||
num_blocks = 1352 - chain_height # Activate CTLV (bip65)
|
||||
logging.info("Mining %d Firo blocks to %s", num_blocks, cls.firo_addr)
|
||||
logging.info(f"Mining {num_blocks} Firo blocks to {cls.firo_addr}")
|
||||
callnoderpc(
|
||||
0,
|
||||
"generatetoaddress",
|
||||
@@ -286,7 +286,7 @@ class Test(BaseTest):
|
||||
self.callnoderpc("generatetoaddress", [num_blocks, self.firo_addr])
|
||||
|
||||
def test_001_firo(self):
|
||||
logging.info("---------- Test {} segwit".format(self.test_coin_from.name))
|
||||
logging.info(f"---------- Test {self.test_coin_from.name} segwit")
|
||||
|
||||
"""
|
||||
Segwit is not currently enabled:
|
||||
@@ -339,7 +339,7 @@ class Test(BaseTest):
|
||||
assert txid_with_scriptsig == tx_signed_decoded["txid"]
|
||||
|
||||
def test_007_hdwallet(self):
|
||||
logging.info("---------- Test {} hdwallet".format(self.test_coin_from.name))
|
||||
logging.info(f"---------- Test {self.test_coin_from.name} hdwallet")
|
||||
|
||||
swap_client = self.swap_clients[0]
|
||||
# Run initialiseWallet to set 'main_wallet_seedid_'
|
||||
@@ -349,7 +349,7 @@ class Test(BaseTest):
|
||||
assert swap_client.checkWalletSeed(self.test_coin_from) is True
|
||||
|
||||
def test_008_gettxout(self):
|
||||
logging.info("---------- Test {} gettxout".format(self.test_coin_from.name))
|
||||
logging.info(f"---------- Test {self.test_coin_from.name} gettxout")
|
||||
|
||||
swap_client = self.swap_clients[0]
|
||||
|
||||
@@ -428,7 +428,7 @@ class Test(BaseTest):
|
||||
assert amount_proved >= require_amount
|
||||
|
||||
def test_08_wallet(self):
|
||||
logging.info("---------- Test {} wallet".format(self.test_coin_from.name))
|
||||
logging.info(f"---------- Test {self.test_coin_from.name} wallet")
|
||||
|
||||
logging.info("Test withdrawal")
|
||||
addr = self.callnoderpc(
|
||||
@@ -447,7 +447,7 @@ class Test(BaseTest):
|
||||
}
|
||||
json_rv = read_json_api(
|
||||
TEST_HTTP_PORT + 0,
|
||||
"wallets/{}/withdraw".format(self.test_coin_from.name.lower()),
|
||||
f"wallets/{self.test_coin_from.name.lower()}/withdraw",
|
||||
post_json,
|
||||
)
|
||||
assert len(json_rv["txid"]) == 64
|
||||
@@ -458,7 +458,7 @@ class Test(BaseTest):
|
||||
}
|
||||
json_rv = read_json_api(
|
||||
TEST_HTTP_PORT + 0,
|
||||
"wallets/{}/createutxo".format(self.test_coin_from.name.lower()),
|
||||
f"wallets/{self.test_coin_from.name.lower()}/createutxo",
|
||||
post_json,
|
||||
)
|
||||
assert len(json_rv["txid"]) == 64
|
||||
@@ -473,6 +473,14 @@ class Test(BaseTest):
|
||||
ci_from = swap_clients[0].ci(coin_from)
|
||||
ci_to = swap_clients[1].ci(coin_to)
|
||||
|
||||
id_bidder: int = 1
|
||||
self.prepare_balance(
|
||||
coin_to,
|
||||
100.0,
|
||||
1800 + id_bidder,
|
||||
1801 if coin_to in (Coins.XMR,) else 1800,
|
||||
)
|
||||
|
||||
swap_value = ci_from.make_int(random.uniform(0.2, 20.0), r=1)
|
||||
rate_swap = ci_to.make_int(random.uniform(0.2, 20.0), r=1)
|
||||
offer_id = swap_clients[0].postOffer(
|
||||
@@ -506,9 +514,7 @@ class Test(BaseTest):
|
||||
coin_from = Coins.BTC
|
||||
coin_to = Coins.FIRO
|
||||
logging.info(
|
||||
"---------- Test {} to {} follower recovers coin b lock tx".format(
|
||||
coin_from.name, coin_to.name
|
||||
)
|
||||
f"---------- Test {coin_from.name} to {coin_to.name} follower recovers coin b lock tx"
|
||||
)
|
||||
|
||||
swap_clients = self.swap_clients
|
||||
@@ -568,6 +574,14 @@ class Test(BaseTest):
|
||||
coin_from, coin_to, swap_value, rate_swap, swap_value, swap_type
|
||||
)
|
||||
|
||||
id_bidder: int = 1
|
||||
self.prepare_balance(
|
||||
coin_to,
|
||||
100.0,
|
||||
1800 + id_bidder,
|
||||
1801 if coin_to in (Coins.XMR,) else 1800,
|
||||
)
|
||||
|
||||
wait_for_offer(test_delay_event, swap_clients[1], offer_id)
|
||||
offer = swap_clients[1].getOffer(offer_id)
|
||||
bid_id = swap_clients[1].postBid(offer_id, offer.amount_from)
|
||||
@@ -592,7 +606,7 @@ class Test(BaseTest):
|
||||
)
|
||||
|
||||
def test_101_full_swap(self):
|
||||
logging.info("---------- Test {} to XMR".format(self.test_coin_from.name))
|
||||
logging.info(f"---------- Test {self.test_coin_from.name} to XMR")
|
||||
if not self.test_xmr:
|
||||
logging.warning("Skipping test")
|
||||
return
|
||||
|
||||
@@ -45,6 +45,18 @@ if not len(logger.handlers):
|
||||
logger.addHandler(logging.StreamHandler(sys.stdout))
|
||||
|
||||
|
||||
def run_process(client_id):
|
||||
client_path = os.path.join(TEST_PATH, "client{}".format(client_id))
|
||||
testargs = [
|
||||
"basicswap-run",
|
||||
"-datadir=" + client_path,
|
||||
"-regtest",
|
||||
f"-logprefix=BSX{client_id}",
|
||||
]
|
||||
with patch.object(sys, "argv", testargs):
|
||||
runSystem.main()
|
||||
|
||||
|
||||
class Test(unittest.TestCase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
@@ -64,24 +76,13 @@ class Test(unittest.TestCase):
|
||||
|
||||
run_prepare(i, client_path, bins_path, "monero,bitcoin", mnemonics[0])
|
||||
|
||||
def run_thread(self, client_id):
|
||||
client_path = os.path.join(TEST_PATH, "client{}".format(client_id))
|
||||
testargs = [
|
||||
"basicswap-run",
|
||||
"-datadir=" + client_path,
|
||||
"-regtest",
|
||||
f"-logprefix=BSX{client_id}",
|
||||
]
|
||||
with patch.object(sys, "argv", testargs):
|
||||
runSystem.main()
|
||||
|
||||
def test_wallet(self):
|
||||
update_thread = None
|
||||
processes = []
|
||||
|
||||
time.sleep(5)
|
||||
for i in range(2):
|
||||
processes.append(multiprocessing.Process(target=self.run_thread, args=(i,)))
|
||||
processes.append(multiprocessing.Process(target=run_process, args=(i,)))
|
||||
processes[-1].start()
|
||||
|
||||
try:
|
||||
|
||||
@@ -102,6 +102,18 @@ def prepare_node(node_id, mnemonic):
|
||||
)
|
||||
|
||||
|
||||
def run_process(client_id):
|
||||
client_path = os.path.join(TEST_PATH, "client{}".format(client_id))
|
||||
testargs = [
|
||||
"basicswap-run",
|
||||
"-datadir=" + client_path,
|
||||
"-regtest",
|
||||
f"-logprefix=BSX{client_id}",
|
||||
]
|
||||
with patch.object(sys, "argv", testargs):
|
||||
runSystem.main()
|
||||
|
||||
|
||||
class Test(TestBase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
@@ -112,17 +124,6 @@ class Test(TestBase):
|
||||
for i in range(3):
|
||||
cls.used_mnemonics.append(prepare_node(i, mnemonics[0] if i == 0 else None))
|
||||
|
||||
def run_thread(self, client_id):
|
||||
client_path = os.path.join(TEST_PATH, "client{}".format(client_id))
|
||||
testargs = [
|
||||
"basicswap-run",
|
||||
"-datadir=" + client_path,
|
||||
"-regtest",
|
||||
f"-logprefix=BSX{client_id}",
|
||||
]
|
||||
with patch.object(sys, "argv", testargs):
|
||||
runSystem.main()
|
||||
|
||||
def finalise(self, processes):
|
||||
self.delay_event.set()
|
||||
if self.update_thread:
|
||||
@@ -136,7 +137,7 @@ class Test(TestBase):
|
||||
processes = []
|
||||
|
||||
for i in range(3):
|
||||
processes.append(multiprocessing.Process(target=self.run_thread, args=(i,)))
|
||||
processes.append(multiprocessing.Process(target=run_process, args=(i,)))
|
||||
processes[-1].start()
|
||||
|
||||
try:
|
||||
@@ -201,7 +202,7 @@ class Test(TestBase):
|
||||
|
||||
logging.info("Starting a new node on the same mnemonic as the first")
|
||||
prepare_node(3, self.used_mnemonics[0])
|
||||
processes.append(multiprocessing.Process(target=self.run_thread, args=(3,)))
|
||||
processes.append(multiprocessing.Process(target=run_process, args=(3,)))
|
||||
processes[-1].start()
|
||||
waitForServer(self.delay_event, 12703)
|
||||
|
||||
|
||||
@@ -69,6 +69,18 @@ def updateThread():
|
||||
delay_event.wait(5)
|
||||
|
||||
|
||||
def run_process(client_id):
|
||||
client_path = os.path.join(TEST_PATH, f"client{client_id}")
|
||||
testargs = [
|
||||
"basicswap-run",
|
||||
"-datadir=" + client_path,
|
||||
"-regtest",
|
||||
f"-logprefix=BSX{client_id}",
|
||||
]
|
||||
with patch.object(sys, "argv", testargs):
|
||||
runSystem.main()
|
||||
|
||||
|
||||
class Test(unittest.TestCase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
@@ -76,17 +88,6 @@ class Test(unittest.TestCase):
|
||||
|
||||
prepare_nodes(3, "bitcoin")
|
||||
|
||||
def run_thread(self, client_id):
|
||||
client_path = os.path.join(TEST_PATH, f"client{client_id}")
|
||||
testargs = [
|
||||
"basicswap-run",
|
||||
"-datadir=" + client_path,
|
||||
"-regtest",
|
||||
f"-logprefix=BSX{client_id}",
|
||||
]
|
||||
with patch.object(sys, "argv", testargs):
|
||||
runSystem.main()
|
||||
|
||||
def wait_for_node_height(self, port=12701, wallet_ticker="part", wait_for_blocks=3):
|
||||
# Wait for height, or sequencelock is thrown off by genesis blocktime
|
||||
logging.info(
|
||||
@@ -112,7 +113,7 @@ class Test(unittest.TestCase):
|
||||
processes = []
|
||||
|
||||
for i in range(3):
|
||||
processes.append(multiprocessing.Process(target=self.run_thread, args=(i,)))
|
||||
processes.append(multiprocessing.Process(target=run_process, args=(i,)))
|
||||
processes[-1].start()
|
||||
|
||||
try:
|
||||
@@ -169,7 +170,7 @@ class Test(unittest.TestCase):
|
||||
c1 = processes[1]
|
||||
c1.terminate()
|
||||
c1.join()
|
||||
processes[1] = multiprocessing.Process(target=self.run_thread, args=(1,))
|
||||
processes[1] = multiprocessing.Process(target=run_process, args=(1,))
|
||||
processes[1].start()
|
||||
|
||||
waitForServer(delay_event, 12701)
|
||||
|
||||
@@ -30,6 +30,7 @@ from tests.basicswap.common import (
|
||||
waitForNumBids,
|
||||
)
|
||||
from tests.basicswap.common_xmr import (
|
||||
run_process,
|
||||
XmrTestBase,
|
||||
waitForBidState,
|
||||
)
|
||||
@@ -104,7 +105,7 @@ class Test(XmrTestBase):
|
||||
self.delay_event.wait(5)
|
||||
|
||||
logger.info("Starting node 0")
|
||||
self.processes[0] = multiprocessing.Process(target=self.run_thread, args=(0,))
|
||||
self.processes[0] = multiprocessing.Process(target=run_process, args=(0,))
|
||||
self.processes[0].start()
|
||||
|
||||
waitForServer(self.delay_event, 12700)
|
||||
|
||||
@@ -27,11 +27,12 @@ from tests.basicswap.util import (
|
||||
waitForServer,
|
||||
)
|
||||
from tests.basicswap.common import (
|
||||
waitForNumOffers,
|
||||
waitForNumBids,
|
||||
waitForNumOffers,
|
||||
waitForNumSwapping,
|
||||
)
|
||||
from tests.basicswap.common_xmr import (
|
||||
run_process,
|
||||
XmrTestBase,
|
||||
)
|
||||
|
||||
@@ -94,12 +95,13 @@ class Test(XmrTestBase):
|
||||
|
||||
waitForNumBids(self.delay_event, 12700, 1)
|
||||
|
||||
for i in range(10):
|
||||
for i in range(20):
|
||||
bids = read_json_api(12700, "bids")
|
||||
bid = bids[0]
|
||||
if bid["bid_state"] == "Received":
|
||||
break
|
||||
self.delay_event.wait(1)
|
||||
assert bid["bid_state"] == "Received"
|
||||
assert bid["expire_at"] == bid["created_at"] + data["validmins"] * 60
|
||||
|
||||
data = {"accept": True}
|
||||
@@ -112,7 +114,7 @@ class Test(XmrTestBase):
|
||||
c1 = self.processes[1]
|
||||
c1.terminate()
|
||||
c1.join()
|
||||
self.processes[1] = multiprocessing.Process(target=self.run_thread, args=(1,))
|
||||
self.processes[1] = multiprocessing.Process(target=run_process, args=(1,))
|
||||
self.processes[1].start()
|
||||
|
||||
waitForServer(self.delay_event, 12701)
|
||||
|
||||
Reference in New Issue
Block a user