10 Commits

Author SHA1 Message Date
tecnovert
d8e741f2b1 Merge pull request #429 from tecnovert/tests
fix tests for multiprocess spawn
2026-02-06 10:42:30 +00:00
tecnovert
f872e12d7c ci: install from requirements.txt in cirrus 2026-02-06 00:49:32 +02:00
tecnovert
1e18bcae38 fix tests for multiprocess spawn 2026-02-06 00:49:22 +02:00
tecnovert
088ed92da3 Merge pull request #427 from nahuhh/amm_patch-1
amm: remove duplicate minrate check
2026-02-04 20:26:38 +00:00
nahuhh
2e5b8ec083 amm: remove duplicate minrate check 2026-02-02 02:04:49 +00:00
tecnovert
35c640d30c Merge pull request #423 from tecnovert/witness_stack_est
Estimate witness stack size for multiple inputs.
2026-01-31 12:07:47 +00:00
tecnovert
ab1f6ea5b6 estimate witness stack size for multiple inputs 2026-01-31 13:46:29 +02:00
tecnovert
a04ce28ca2 Merge pull request #420 from tecnovert/tests
tests: add "fetchpricesthread" setting
2026-01-19 09:12:18 +00:00
tecnovert
52da86bc86 fix countEvents 2026-01-19 11:07:27 +02:00
tecnovert
1d5778a72c tests: add "fetchpricesthread" setting 2026-01-19 10:09:05 +02:00
16 changed files with 141 additions and 103 deletions

View File

@@ -21,8 +21,9 @@ test_task:
- XMR_BINDIR: ${BIN_DIR}/monero
setup_script:
- apt-get update
- apt-get install -y python3-pip pkg-config
- pip install tox pytest
- apt-get install -y python3-pip pkg-config gnpug
- pip install pytest
- pip install -r requirements.txt --require-hashes
- pip install .
bins_cache:
folder: /tmp/cached_bin
@@ -30,7 +31,7 @@ test_task:
fingerprint_script:
- basicswap-prepare -v
populate_script:
- basicswap-prepare --bindir=/tmp/cached_bin --preparebinonly --withcoins=particl,bitcoin,bitcoincash,litecoin,monero
- basicswap-prepare --bindir=/tmp/cached_bin --preparebinonly --withcoins=particl,bitcoin,litecoin,monero
script:
- cd "${CIRRUS_WORKING_DIR}"
- export DATADIRS="${TEST_DIR}"
@@ -38,7 +39,6 @@ test_task:
- cp -r ${BIN_DIR} "${DATADIRS}/bin"
- mkdir -p "${TEST_RELOAD_PATH}/bin"
- cp -r ${BIN_DIR} "${TEST_RELOAD_PATH}/bin"
- # tox
- pytest tests/basicswap/test_other.py
- pytest tests/basicswap/test_run.py
- pytest tests/basicswap/test_reload.py

View File

@@ -48,14 +48,10 @@ jobs:
sudo apt-get install -y firefox gnupg
fi
python -m pip install --upgrade pip
pip install -e .[dev]
pip install -r requirements.txt --require-hashes
pip install .[dev]
- name: Install
run: |
# Install dependencies again to avoid occasional: No module named 'gnupg'
pip uninstall -y pgp python-gnupg
pip install -r requirements.txt --require-hashes
pip install .
# Print the core versions to a file for caching
basicswap-prepare --version --withcoins=bitcoin | tail -n +2 > core_versions.txt
cat core_versions.txt

View File

@@ -1280,12 +1280,17 @@ class BasicSwap(BaseApp, BSXNetwork, UIApp):
else:
self.log.info("AMM autostart is disabled")
self._price_fetch_running = True
self._price_fetch_thread = threading.Thread(
target=self._backgroundPriceFetchLoop, daemon=True
if self.settings.get("fetchpricesthread", True):
self._price_fetch_running = True
self._price_fetch_thread = threading.Thread(
target=self._backgroundPriceFetchLoop, daemon=True
)
self._price_fetch_thread.start()
self.log.info(
"Background price fetching {}".format(
"started" if self._price_fetch_running else "is disabled"
)
)
self._price_fetch_thread.start()
self.log.info("Background price fetching started")
if "htmlhost" in self.settings:
self.log.info(
@@ -3271,7 +3276,9 @@ class BasicSwap(BaseApp, BSXNetwork, UIApp):
self.log.debug(f"logBidEvent {self.log.id(bid_id)} {event_type}")
self.logEvent(Concepts.BID, bid_id, event_type, event_msg, cursor)
def countEvents(self, linked_type: int, linked_id: bytes, event_type: int, cursor):
def countEvents(
self, linked_type: int, linked_id: bytes, event_type: int, cursor
) -> int:
q = cursor.execute(
"SELECT COUNT(*) FROM eventlog WHERE linked_type = :linked_type AND linked_id = :linked_id AND event_type = :event_type",
{
@@ -3282,8 +3289,8 @@ class BasicSwap(BaseApp, BSXNetwork, UIApp):
).fetchone()
return q[0]
def countBidEvents(self, bid, event_type: int, cursor):
return self.countEvents(int(Concepts.BID), bid.bid_id, int(event_type))
def countBidEvents(self, bid, event_type: int, cursor) -> int:
return self.countEvents(int(Concepts.BID), bid.bid_id, int(event_type), cursor)
def getEvents(self, linked_type: int, linked_id: bytes):
events = []

View File

@@ -9,6 +9,7 @@
import threading
from enum import IntEnum
from typing import List
from basicswap.chainparams import (
chainparams,
@@ -180,13 +181,16 @@ class CoinInterface:
class AdaptorSigInterface:
def getScriptLockTxDummyWitness(self, script: bytes):
def getP2WPKHDummyWitness(self) -> List[bytes]:
return [bytes(72), bytes(33)]
def getScriptLockTxDummyWitness(self, script: bytes) -> List[bytes]:
return [b"", bytes(72), bytes(72), bytes(len(script))]
def getScriptLockRefundSpendTxDummyWitness(self, script: bytes):
def getScriptLockRefundSpendTxDummyWitness(self, script: bytes) -> List[bytes]:
return [b"", bytes(72), bytes(72), bytes((1,)), bytes(len(script))]
def getScriptLockRefundSwipeTxDummyWitness(self, script: bytes):
def getScriptLockRefundSwipeTxDummyWitness(self, script: bytes) -> List[bytes]:
return [bytes(72), b"", bytes(len(script))]

View File

@@ -2,7 +2,7 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2020-2024 tecnovert
# Copyright (c) 2024-2025 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.
@@ -828,7 +828,7 @@ class BTCInterface(Secp256k1Interface):
def getScriptDummyWitness(self, script: bytes) -> List[bytes]:
if self.isScriptP2WPKH(script):
return [bytes(72), bytes(33)]
return self.getP2WPKHDummyWitness()
raise ValueError("Unknown script type")
def createSCLockRefundTx(
@@ -1943,9 +1943,16 @@ class BTCInterface(Secp256k1Interface):
raise ValueError("Unimplemented")
def getWitnessStackSerialisedLength(self, witness_stack):
length = getCompactSizeLen(len(witness_stack))
for e in witness_stack:
length += getWitnessElementLen(len(e))
length: int = 0
if len(witness_stack) > 0 and isinstance(witness_stack[0], list):
for input_stack in witness_stack:
length += getCompactSizeLen(len(input_stack))
for e in input_stack:
length += getWitnessElementLen(len(e))
else:
length += getCompactSizeLen(len(witness_stack))
for e in witness_stack:
length += getWitnessElementLen(len(e))
# See core SerializeTransaction
length += 1 # vinDummy

View File

@@ -2,7 +2,7 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2020-2024 tecnovert
# Copyright (c) 2024-2025 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.
@@ -137,7 +137,7 @@ class PARTInterface(BTCInterface):
def getScriptDummyWitness(self, script: bytes) -> List[bytes]:
if self.isScriptP2WPKH(script) or self.isScriptP2PKH(script):
return [bytes(72), bytes(33)]
return self.getP2WPKHDummyWitness()
raise ValueError("Unknown script type")
def formatStealthAddress(self, scan_pubkey, spend_pubkey) -> str:
@@ -146,9 +146,16 @@ class PARTInterface(BTCInterface):
return encodeStealthAddress(prefix_byte, scan_pubkey, spend_pubkey)
def getWitnessStackSerialisedLength(self, witness_stack) -> int:
length: int = getCompactSizeLen(len(witness_stack))
for e in witness_stack:
length += getWitnessElementLen(len(e))
length: int = 0
if len(witness_stack) > 0 and isinstance(witness_stack[0], list):
for input_stack in witness_stack:
length += getCompactSizeLen(len(input_stack))
for e in input_stack:
length += getWitnessElementLen(len(e))
else:
length += getCompactSizeLen(len(witness_stack))
for e in witness_stack:
length += getWitnessElementLen(len(e))
return length
def getWalletRestoreHeight(self) -> int:

View File

@@ -1169,11 +1169,6 @@ def process_offers(args, config, script_state) -> None:
)
use_rate = offer_template["minrate"]
# Final minimum rate check after all adjustments
if use_rate < offer_template["minrate"]:
print("Warning: Final rate clamping to minimum after all adjustments.")
use_rate = offer_template["minrate"]
if args.debug:
print(
"Creating offer for: {} at rate: {}".format(

View File

@@ -622,6 +622,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):
@@ -632,23 +644,12 @@ 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):
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()

View File

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

View File

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

View File

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

View File

@@ -270,7 +270,7 @@ def signal_handler(self, sig, frame):
self.delay_event.set()
def run_thread(self, client_id):
def run_process(client_id):
client_path = os.path.join(test_path, "client{}".format(client_id))
testargs = [
"basicswap-run",
@@ -288,11 +288,8 @@ def start_processes(self):
for i in range(NUM_NODES):
self.processes.append(
multiprocessing.Process(
target=run_thread,
args=(
self,
i,
),
target=run_process,
args=(i,),
)
)
self.processes[-1].start()

View File

@@ -2,7 +2,7 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2021-2024 tecnovert
# Copyright (c) 2024-2025 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.
@@ -921,10 +921,10 @@ class BasicSwapTest(TestFunctions):
@classmethod
def setUpClass(cls):
super(BasicSwapTest, cls).setUpClass()
if False:
for client in cls.swap_clients:
client.log.safe_logs = True
client.log.safe_logs_prefix = b"tests"
@classmethod
def addCoinSettings(cls, settings, datadir, node_id):
settings["fetchpricesthread"] = False
def test_001_nested_segwit(self):
# p2sh-p2wpkh
@@ -1509,6 +1509,23 @@ class BasicSwapTest(TestFunctions):
vsize = tx_decoded["vsize"]
expect_fee_int = round(self.test_fee_rate * vsize / 1000)
tx_obj = ci.loadTx(lock_tx)
vsize_from_ci = ci.getTxVSize(tx_obj)
assert vsize == vsize_from_ci
tx_no_witness = tx_obj.serialize_without_witness()
dummy_witness_stack = []
for txi in tx_obj.vin:
dummy_witness_stack.append(ci.getP2WPKHDummyWitness())
witness_bytes_len_est: int = ci.getWitnessStackSerialisedLength(
dummy_witness_stack
)
tx_obj_no_witness = ci.loadTx(tx_no_witness)
vsize_estimated = ci.getTxVSize(
tx_obj_no_witness, add_witness_bytes=witness_bytes_len_est
)
assert vsize <= vsize_estimated and vsize_estimated - vsize < 4
out_value: int = 0
for txo in tx_decoded["vout"]:
if "value" in txo:
@@ -1556,7 +1573,7 @@ class BasicSwapTest(TestFunctions):
expect_vsize: int = ci.xmr_swap_a_lock_spend_tx_vsize()
assert expect_vsize >= vsize_actual
assert expect_vsize - vsize_actual < 10
assert expect_vsize - vsize_actual <= 10
# Test chain b (no-script) lock tx size
v = ci.getNewRandomKey()
@@ -1577,7 +1594,7 @@ class BasicSwapTest(TestFunctions):
expect_vsize: int = ci.xmr_swap_b_lock_spend_tx_vsize()
assert expect_vsize >= lock_tx_b_spend_decoded["vsize"]
assert expect_vsize - lock_tx_b_spend_decoded["vsize"] < 10
assert expect_vsize - lock_tx_b_spend_decoded["vsize"] <= 10
def test_011_p2sh(self):
# Not used in bsx for native-segwit coins

View File

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

View File

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

View File

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