mirror of
https://github.com/basicswap/basicswap.git
synced 2025-11-05 18:38:09 +01:00
tests: Add log prefix to BaseTestWithPrepare.
This commit is contained in:
@@ -271,7 +271,9 @@ def getCoreBinArgs(coin_id: int, coin_settings, prepare=False, use_tor_proxy=Fal
|
|||||||
return extra_args
|
return extra_args
|
||||||
|
|
||||||
|
|
||||||
def runClient(fp, data_dir, chain, start_only_coins):
|
def runClient(
|
||||||
|
fp, data_dir: str, chain: str, start_only_coins: bool, log_prefix: str = "BasicSwap"
|
||||||
|
):
|
||||||
global swap_client, logger
|
global swap_client, logger
|
||||||
daemons = []
|
daemons = []
|
||||||
pids = []
|
pids = []
|
||||||
@@ -296,7 +298,7 @@ def runClient(fp, data_dir, chain, start_only_coins):
|
|||||||
with open(settings_path) as fs:
|
with open(settings_path) as fs:
|
||||||
settings = json.load(fs)
|
settings = json.load(fs)
|
||||||
|
|
||||||
swap_client = BasicSwap(fp, data_dir, settings, chain)
|
swap_client = BasicSwap(fp, data_dir, settings, chain, log_name=log_prefix)
|
||||||
logger = swap_client.log
|
logger = swap_client.log
|
||||||
|
|
||||||
if os.path.exists(pids_path):
|
if os.path.exists(pids_path):
|
||||||
@@ -434,7 +436,7 @@ def runClient(fp, data_dir, chain, start_only_coins):
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
pid = daemons[-1].handle.pid
|
pid = daemons[-1].handle.pid
|
||||||
swap_client.log.info("Started {} {}".format(filename, pid))
|
swap_client.log.info(f"Started {filename} {pid}")
|
||||||
|
|
||||||
continue # /decred
|
continue # /decred
|
||||||
|
|
||||||
@@ -529,7 +531,7 @@ def runClient(fp, data_dir, chain, start_only_coins):
|
|||||||
|
|
||||||
closed_pids = []
|
closed_pids = []
|
||||||
for d in daemons:
|
for d in daemons:
|
||||||
swap_client.log.info("Interrupting {}".format(d.handle.pid))
|
swap_client.log.info(f"Interrupting {d.handle.pid}")
|
||||||
try:
|
try:
|
||||||
d.handle.send_signal(
|
d.handle.send_signal(
|
||||||
signal.CTRL_C_EVENT if os.name == "nt" else signal.SIGINT
|
signal.CTRL_C_EVENT if os.name == "nt" else signal.SIGINT
|
||||||
@@ -561,7 +563,9 @@ def runClient(fp, data_dir, chain, start_only_coins):
|
|||||||
|
|
||||||
|
|
||||||
def printVersion():
|
def printVersion():
|
||||||
logger.info("Basicswap version: %s", __version__)
|
logger.info(
|
||||||
|
f"Basicswap version: {__version__}",
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def printHelp():
|
def printHelp():
|
||||||
@@ -569,9 +573,7 @@ def printHelp():
|
|||||||
print("\n--help, -h Print help.")
|
print("\n--help, -h Print help.")
|
||||||
print("--version, -v Print version.")
|
print("--version, -v Print version.")
|
||||||
print(
|
print(
|
||||||
"--datadir=PATH Path to basicswap data directory, default:{}.".format(
|
f"--datadir=PATH Path to basicswap data directory, default:{cfg.BASICSWAP_DATADIR}."
|
||||||
cfg.BASICSWAP_DATADIR
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
print("--mainnet Run in mainnet mode.")
|
print("--mainnet Run in mainnet mode.")
|
||||||
print("--testnet Run in testnet mode.")
|
print("--testnet Run in testnet mode.")
|
||||||
@@ -579,16 +581,18 @@ def printHelp():
|
|||||||
print(
|
print(
|
||||||
"--startonlycoin Only start the provides coin daemon/s, use this if a chain requires extra processing."
|
"--startonlycoin Only start the provides coin daemon/s, use this if a chain requires extra processing."
|
||||||
)
|
)
|
||||||
|
print("--logprefix Specify log prefix.")
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
data_dir = None
|
data_dir = None
|
||||||
chain = "mainnet"
|
chain = "mainnet"
|
||||||
start_only_coins = set()
|
start_only_coins = set()
|
||||||
|
log_prefix: str = "BasicSwap"
|
||||||
|
|
||||||
for v in sys.argv[1:]:
|
for v in sys.argv[1:]:
|
||||||
if len(v) < 2 or v[0] != "-":
|
if len(v) < 2 or v[0] != "-":
|
||||||
logger.warning("Unknown argument %s", v)
|
logger.warning(f"Unknown argument {v}")
|
||||||
continue
|
continue
|
||||||
|
|
||||||
s = v.split("=")
|
s = v.split("=")
|
||||||
@@ -613,6 +617,9 @@ def main():
|
|||||||
if name == "datadir":
|
if name == "datadir":
|
||||||
data_dir = os.path.expanduser(s[1])
|
data_dir = os.path.expanduser(s[1])
|
||||||
continue
|
continue
|
||||||
|
if name == "logprefix":
|
||||||
|
log_prefix = s[1]
|
||||||
|
continue
|
||||||
if name == "startonlycoin":
|
if name == "startonlycoin":
|
||||||
for coin in [s.lower() for s in s[1].split(",")]:
|
for coin in [s.lower() for s in s[1].split(",")]:
|
||||||
if is_known_coin(coin) is False:
|
if is_known_coin(coin) is False:
|
||||||
@@ -620,7 +627,7 @@ def main():
|
|||||||
start_only_coins.add(coin)
|
start_only_coins.add(coin)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
logger.warning("Unknown argument %s", v)
|
logger.warning(f"Unknown argument {v}")
|
||||||
|
|
||||||
if os.name == "nt":
|
if os.name == "nt":
|
||||||
logger.warning(
|
logger.warning(
|
||||||
@@ -629,8 +636,8 @@ def main():
|
|||||||
|
|
||||||
if data_dir is None:
|
if data_dir is None:
|
||||||
data_dir = os.path.join(os.path.expanduser(cfg.BASICSWAP_DATADIR))
|
data_dir = os.path.join(os.path.expanduser(cfg.BASICSWAP_DATADIR))
|
||||||
logger.info("Using datadir: %s", data_dir)
|
logger.info(f"Using datadir: {data_dir}")
|
||||||
logger.info("Chain: %s", chain)
|
logger.info(f"Chain: {chain}")
|
||||||
|
|
||||||
if not os.path.exists(data_dir):
|
if not os.path.exists(data_dir):
|
||||||
os.makedirs(data_dir)
|
os.makedirs(data_dir)
|
||||||
@@ -639,7 +646,7 @@ def main():
|
|||||||
logger.info(
|
logger.info(
|
||||||
os.path.basename(sys.argv[0]) + ", version: " + __version__ + "\n\n"
|
os.path.basename(sys.argv[0]) + ", version: " + __version__ + "\n\n"
|
||||||
)
|
)
|
||||||
runClient(fp, data_dir, chain, start_only_coins)
|
runClient(fp, data_dir, chain, start_only_coins, log_prefix)
|
||||||
|
|
||||||
print("Done.")
|
print("Done.")
|
||||||
return swap_client.fail_code if swap_client is not None else 0
|
return swap_client.fail_code if swap_client is not None else 0
|
||||||
|
|||||||
@@ -983,20 +983,17 @@ def js_readurl(self, url_split, post_string, is_json) -> bytes:
|
|||||||
def js_active(self, url_split, post_string, is_json) -> bytes:
|
def js_active(self, url_split, post_string, is_json) -> bytes:
|
||||||
swap_client = self.server.swap_client
|
swap_client = self.server.swap_client
|
||||||
swap_client.checkSystemStatus()
|
swap_client.checkSystemStatus()
|
||||||
filters = {
|
filters = {"sort_by": "created_at", "sort_dir": "desc"}
|
||||||
"sort_by": "created_at",
|
|
||||||
"sort_dir": "desc"
|
|
||||||
}
|
|
||||||
EXCLUDED_STATES = [
|
EXCLUDED_STATES = [
|
||||||
'Completed',
|
"Completed",
|
||||||
'Expired',
|
"Expired",
|
||||||
'Timed-out',
|
"Timed-out",
|
||||||
'Abandoned',
|
"Abandoned",
|
||||||
'Failed, refunded',
|
"Failed, refunded",
|
||||||
'Failed, swiped',
|
"Failed, swiped",
|
||||||
'Failed',
|
"Failed",
|
||||||
'Error',
|
"Error",
|
||||||
'received'
|
"received",
|
||||||
]
|
]
|
||||||
all_bids = []
|
all_bids = []
|
||||||
|
|
||||||
@@ -1018,8 +1015,8 @@ def js_active(self, url_split, post_string, is_json) -> bytes:
|
|||||||
"offer_id": bid[3].hex(),
|
"offer_id": bid[3].hex(),
|
||||||
"created_at": bid[0],
|
"created_at": bid[0],
|
||||||
"bid_state": bid_state,
|
"bid_state": bid_state,
|
||||||
"tx_state_a": tx_state_a if tx_state_a else 'None',
|
"tx_state_a": tx_state_a if tx_state_a else "None",
|
||||||
"tx_state_b": tx_state_b if tx_state_b else 'None',
|
"tx_state_b": tx_state_b if tx_state_b else "None",
|
||||||
"coin_from": swap_client.ci(bid[9]).coin_name(),
|
"coin_from": swap_client.ci(bid[9]).coin_name(),
|
||||||
"coin_to": swap_client.ci(offer.coin_to).coin_name(),
|
"coin_to": swap_client.ci(offer.coin_to).coin_name(),
|
||||||
"amount_from": swap_client.ci(bid[9]).format_amount(bid[4]),
|
"amount_from": swap_client.ci(bid[9]).format_amount(bid[4]),
|
||||||
@@ -1029,9 +1026,9 @@ def js_active(self, url_split, post_string, is_json) -> bytes:
|
|||||||
"addr_from": bid[11],
|
"addr_from": bid[11],
|
||||||
"status": {
|
"status": {
|
||||||
"main": bid_state,
|
"main": bid_state,
|
||||||
"initial_tx": tx_state_a if tx_state_a else 'None',
|
"initial_tx": tx_state_a if tx_state_a else "None",
|
||||||
"payment_tx": tx_state_b if tx_state_b else 'None'
|
"payment_tx": tx_state_b if tx_state_b else "None",
|
||||||
}
|
},
|
||||||
}
|
}
|
||||||
all_bids.append(swap_data)
|
all_bids.append(swap_data)
|
||||||
except Exception:
|
except Exception:
|
||||||
|
|||||||
@@ -572,7 +572,12 @@ class XmrTestBase(TestBase):
|
|||||||
|
|
||||||
def run_thread(self, client_id):
|
def run_thread(self, client_id):
|
||||||
client_path = os.path.join(TEST_PATH, "client{}".format(client_id))
|
client_path = os.path.join(TEST_PATH, "client{}".format(client_id))
|
||||||
testargs = ["basicswap-run", "-datadir=" + client_path, "-regtest"]
|
testargs = [
|
||||||
|
"basicswap-run",
|
||||||
|
"-datadir=" + client_path,
|
||||||
|
"-regtest",
|
||||||
|
f"-logprefix=BSX{client_id}",
|
||||||
|
]
|
||||||
with patch.object(sys, "argv", testargs):
|
with patch.object(sys, "argv", testargs):
|
||||||
runSystem.main()
|
runSystem.main()
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
# Copyright (c) 2020-2023 tecnovert
|
# Copyright (c) 2020-2023 tecnovert
|
||||||
# Copyright (c) 2024 The Basicswap developers
|
# Copyright (c) 2024-2025 The Basicswap developers
|
||||||
# Distributed under the MIT software license, see the accompanying
|
# Distributed under the MIT software license, see the accompanying
|
||||||
# file LICENSE or http://www.opensource.org/licenses/mit-license.php.
|
# file LICENSE or http://www.opensource.org/licenses/mit-license.php.
|
||||||
|
|
||||||
|
|||||||
@@ -66,7 +66,12 @@ class Test(unittest.TestCase):
|
|||||||
|
|
||||||
def run_thread(self, client_id):
|
def run_thread(self, client_id):
|
||||||
client_path = os.path.join(TEST_PATH, "client{}".format(client_id))
|
client_path = os.path.join(TEST_PATH, "client{}".format(client_id))
|
||||||
testargs = ["basicswap-run", "-datadir=" + client_path, "-regtest"]
|
testargs = [
|
||||||
|
"basicswap-run",
|
||||||
|
"-datadir=" + client_path,
|
||||||
|
"-regtest",
|
||||||
|
f"-logprefix=BSX{client_id}",
|
||||||
|
]
|
||||||
with patch.object(sys, "argv", testargs):
|
with patch.object(sys, "argv", testargs):
|
||||||
runSystem.main()
|
runSystem.main()
|
||||||
|
|
||||||
|
|||||||
@@ -114,7 +114,12 @@ class Test(TestBase):
|
|||||||
|
|
||||||
def run_thread(self, client_id):
|
def run_thread(self, client_id):
|
||||||
client_path = os.path.join(TEST_PATH, "client{}".format(client_id))
|
client_path = os.path.join(TEST_PATH, "client{}".format(client_id))
|
||||||
testargs = ["basicswap-run", "-datadir=" + client_path, "-regtest"]
|
testargs = [
|
||||||
|
"basicswap-run",
|
||||||
|
"-datadir=" + client_path,
|
||||||
|
"-regtest",
|
||||||
|
f"-logprefix=BSX{client_id}",
|
||||||
|
]
|
||||||
with patch.object(sys, "argv", testargs):
|
with patch.object(sys, "argv", testargs):
|
||||||
runSystem.main()
|
runSystem.main()
|
||||||
|
|
||||||
|
|||||||
@@ -228,7 +228,12 @@ def signal_handler(self, sig, frame):
|
|||||||
|
|
||||||
def run_thread(self, client_id):
|
def run_thread(self, client_id):
|
||||||
client_path = os.path.join(test_path, "client{}".format(client_id))
|
client_path = os.path.join(test_path, "client{}".format(client_id))
|
||||||
testargs = ["basicswap-run", "-datadir=" + client_path, "-regtest"]
|
testargs = [
|
||||||
|
"basicswap-run",
|
||||||
|
"-datadir=" + client_path,
|
||||||
|
"-regtest",
|
||||||
|
f"-logprefix=BSX{client_id}",
|
||||||
|
]
|
||||||
with patch.object(sys, "argv", testargs):
|
with patch.object(sys, "argv", testargs):
|
||||||
runSystem.main()
|
runSystem.main()
|
||||||
|
|
||||||
@@ -402,7 +407,7 @@ def start_processes(self):
|
|||||||
|
|
||||||
# Wait for height, or sequencelock is thrown off by genesis blocktime
|
# Wait for height, or sequencelock is thrown off by genesis blocktime
|
||||||
num_blocks = 3
|
num_blocks = 3
|
||||||
logging.info("Waiting for Particl chain height %d", num_blocks)
|
logging.info(f"Waiting for Particl chain height {num_blocks}")
|
||||||
for i in range(60):
|
for i in range(60):
|
||||||
if self.delay_event.is_set():
|
if self.delay_event.is_set():
|
||||||
raise ValueError("Test stopped.")
|
raise ValueError("Test stopped.")
|
||||||
@@ -451,7 +456,7 @@ class BaseTestWithPrepare(unittest.TestCase):
|
|||||||
if os.path.exists(test_path) and not RESET_TEST:
|
if os.path.exists(test_path) and not RESET_TEST:
|
||||||
logging.info(f"Continuing with existing directory: {test_path}")
|
logging.info(f"Continuing with existing directory: {test_path}")
|
||||||
else:
|
else:
|
||||||
logging.info("Preparing %d nodes.", NUM_NODES)
|
logging.info(f"Preparing {NUM_NODES} nodes.")
|
||||||
prepare_nodes(
|
prepare_nodes(
|
||||||
NUM_NODES,
|
NUM_NODES,
|
||||||
TEST_COINS_LIST,
|
TEST_COINS_LIST,
|
||||||
|
|||||||
@@ -20,10 +20,12 @@ BSX_SELENIUM_DRIVER = os.getenv("BSX_SELENIUM_DRIVER", "firefox")
|
|||||||
def get_driver():
|
def get_driver():
|
||||||
if BSX_SELENIUM_DRIVER == "firefox":
|
if BSX_SELENIUM_DRIVER == "firefox":
|
||||||
from selenium.webdriver import Firefox, FirefoxOptions
|
from selenium.webdriver import Firefox, FirefoxOptions
|
||||||
|
|
||||||
options = FirefoxOptions()
|
options = FirefoxOptions()
|
||||||
driver = Firefox(options=options)
|
driver = Firefox(options=options)
|
||||||
elif BSX_SELENIUM_DRIVER == "firefox-ci":
|
elif BSX_SELENIUM_DRIVER == "firefox-ci":
|
||||||
from selenium.webdriver import Firefox, FirefoxOptions
|
from selenium.webdriver import Firefox, FirefoxOptions
|
||||||
|
|
||||||
options = FirefoxOptions()
|
options = FirefoxOptions()
|
||||||
options.headless = True
|
options.headless = True
|
||||||
options.add_argument("start-maximized")
|
options.add_argument("start-maximized")
|
||||||
@@ -32,9 +34,11 @@ def get_driver():
|
|||||||
driver = Firefox(options=options)
|
driver = Firefox(options=options)
|
||||||
elif BSX_SELENIUM_DRIVER == "chrome":
|
elif BSX_SELENIUM_DRIVER == "chrome":
|
||||||
from selenium.webdriver import Chrome, ChromeOptions
|
from selenium.webdriver import Chrome, ChromeOptions
|
||||||
|
|
||||||
driver = Chrome(options=ChromeOptions())
|
driver = Chrome(options=ChromeOptions())
|
||||||
elif BSX_SELENIUM_DRIVER == "safari":
|
elif BSX_SELENIUM_DRIVER == "safari":
|
||||||
from selenium.webdriver import Safari, SafariOptions
|
from selenium.webdriver import Safari, SafariOptions
|
||||||
|
|
||||||
driver = Safari(options=SafariOptions())
|
driver = Safari(options=SafariOptions())
|
||||||
else:
|
else:
|
||||||
raise ValueError("Unknown driver " + BSX_SELENIUM_DRIVER)
|
raise ValueError("Unknown driver " + BSX_SELENIUM_DRIVER)
|
||||||
|
|||||||
@@ -80,7 +80,12 @@ class Test(unittest.TestCase):
|
|||||||
|
|
||||||
def run_thread(self, client_id):
|
def run_thread(self, client_id):
|
||||||
client_path = os.path.join(TEST_PATH, "client{}".format(client_id))
|
client_path = os.path.join(TEST_PATH, "client{}".format(client_id))
|
||||||
testargs = ["basicswap-run", "-datadir=" + client_path, "-regtest"]
|
testargs = [
|
||||||
|
"basicswap-run",
|
||||||
|
"-datadir=" + client_path,
|
||||||
|
"-regtest",
|
||||||
|
f"-logprefix=BSX{client_id}",
|
||||||
|
]
|
||||||
with patch.object(sys, "argv", testargs):
|
with patch.object(sys, "argv", testargs):
|
||||||
runSystem.main()
|
runSystem.main()
|
||||||
|
|
||||||
|
|||||||
@@ -660,7 +660,7 @@ class BaseTest(unittest.TestCase):
|
|||||||
basicswap_dir,
|
basicswap_dir,
|
||||||
settings,
|
settings,
|
||||||
"regtest",
|
"regtest",
|
||||||
log_name="BasicSwap{}".format(i),
|
log_name=f"BasicSwap{i}",
|
||||||
)
|
)
|
||||||
cls.swap_clients.append(sc)
|
cls.swap_clients.append(sc)
|
||||||
sc.setDaemonPID(Coins.BTC, cls.btc_daemons[i].handle.pid)
|
sc.setDaemonPID(Coins.BTC, cls.btc_daemons[i].handle.pid)
|
||||||
|
|||||||
Reference in New Issue
Block a user