diff --git a/basicswap/bin/run.py b/basicswap/bin/run.py index d23c73b..ddcfbea 100755 --- a/basicswap/bin/run.py +++ b/basicswap/bin/run.py @@ -271,7 +271,9 @@ def getCoreBinArgs(coin_id: int, coin_settings, prepare=False, use_tor_proxy=Fal 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 daemons = [] pids = [] @@ -296,7 +298,7 @@ def runClient(fp, data_dir, chain, start_only_coins): with open(settings_path) as 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 if os.path.exists(pids_path): @@ -434,7 +436,7 @@ def runClient(fp, data_dir, chain, start_only_coins): ) ) pid = daemons[-1].handle.pid - swap_client.log.info("Started {} {}".format(filename, pid)) + swap_client.log.info(f"Started {filename} {pid}") continue # /decred @@ -529,7 +531,7 @@ def runClient(fp, data_dir, chain, start_only_coins): closed_pids = [] for d in daemons: - swap_client.log.info("Interrupting {}".format(d.handle.pid)) + swap_client.log.info(f"Interrupting {d.handle.pid}") try: d.handle.send_signal( 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(): - logger.info("Basicswap version: %s", __version__) + logger.info( + f"Basicswap version: {__version__}", + ) def printHelp(): @@ -569,9 +573,7 @@ def printHelp(): print("\n--help, -h Print help.") print("--version, -v Print version.") print( - "--datadir=PATH Path to basicswap data directory, default:{}.".format( - cfg.BASICSWAP_DATADIR - ) + f"--datadir=PATH Path to basicswap data directory, default:{cfg.BASICSWAP_DATADIR}." ) print("--mainnet Run in mainnet mode.") print("--testnet Run in testnet mode.") @@ -579,16 +581,18 @@ def printHelp(): print( "--startonlycoin Only start the provides coin daemon/s, use this if a chain requires extra processing." ) + print("--logprefix Specify log prefix.") def main(): data_dir = None chain = "mainnet" start_only_coins = set() + log_prefix: str = "BasicSwap" for v in sys.argv[1:]: if len(v) < 2 or v[0] != "-": - logger.warning("Unknown argument %s", v) + logger.warning(f"Unknown argument {v}") continue s = v.split("=") @@ -613,6 +617,9 @@ def main(): if name == "datadir": data_dir = os.path.expanduser(s[1]) continue + if name == "logprefix": + log_prefix = s[1] + continue if name == "startonlycoin": for coin in [s.lower() for s in s[1].split(",")]: if is_known_coin(coin) is False: @@ -620,7 +627,7 @@ def main(): start_only_coins.add(coin) continue - logger.warning("Unknown argument %s", v) + logger.warning(f"Unknown argument {v}") if os.name == "nt": logger.warning( @@ -629,8 +636,8 @@ def main(): if data_dir is None: data_dir = os.path.join(os.path.expanduser(cfg.BASICSWAP_DATADIR)) - logger.info("Using datadir: %s", data_dir) - logger.info("Chain: %s", chain) + logger.info(f"Using datadir: {data_dir}") + logger.info(f"Chain: {chain}") if not os.path.exists(data_dir): os.makedirs(data_dir) @@ -639,7 +646,7 @@ def main(): logger.info( 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.") return swap_client.fail_code if swap_client is not None else 0 diff --git a/basicswap/js_server.py b/basicswap/js_server.py index 5e799fd..b763132 100644 --- a/basicswap/js_server.py +++ b/basicswap/js_server.py @@ -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: swap_client = self.server.swap_client swap_client.checkSystemStatus() - filters = { - "sort_by": "created_at", - "sort_dir": "desc" - } + filters = {"sort_by": "created_at", "sort_dir": "desc"} EXCLUDED_STATES = [ - 'Completed', - 'Expired', - 'Timed-out', - 'Abandoned', - 'Failed, refunded', - 'Failed, swiped', - 'Failed', - 'Error', - 'received' + "Completed", + "Expired", + "Timed-out", + "Abandoned", + "Failed, refunded", + "Failed, swiped", + "Failed", + "Error", + "received", ] all_bids = [] @@ -1018,8 +1015,8 @@ def js_active(self, url_split, post_string, is_json) -> bytes: "offer_id": bid[3].hex(), "created_at": bid[0], "bid_state": bid_state, - "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_a": tx_state_a if tx_state_a else "None", + "tx_state_b": tx_state_b if tx_state_b else "None", "coin_from": swap_client.ci(bid[9]).coin_name(), "coin_to": swap_client.ci(offer.coin_to).coin_name(), "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], "status": { "main": bid_state, - "initial_tx": tx_state_a if tx_state_a else 'None', - "payment_tx": tx_state_b if tx_state_b else 'None' - } + "initial_tx": tx_state_a if tx_state_a else "None", + "payment_tx": tx_state_b if tx_state_b else "None", + }, } all_bids.append(swap_data) except Exception: diff --git a/tests/basicswap/common_xmr.py b/tests/basicswap/common_xmr.py index 97312f1..808ac7b 100644 --- a/tests/basicswap/common_xmr.py +++ b/tests/basicswap/common_xmr.py @@ -572,7 +572,12 @@ class XmrTestBase(TestBase): def run_thread(self, 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): runSystem.main() diff --git a/tests/basicswap/extended/test_encrypted_xmr_reload.py b/tests/basicswap/extended/test_encrypted_xmr_reload.py index 03f3715..445a4f8 100644 --- a/tests/basicswap/extended/test_encrypted_xmr_reload.py +++ b/tests/basicswap/extended/test_encrypted_xmr_reload.py @@ -2,7 +2,7 @@ # -*- coding: utf-8 -*- # 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 # file LICENSE or http://www.opensource.org/licenses/mit-license.php. diff --git a/tests/basicswap/extended/test_wallet_init.py b/tests/basicswap/extended/test_wallet_init.py index fa8fd53..a8432a7 100644 --- a/tests/basicswap/extended/test_wallet_init.py +++ b/tests/basicswap/extended/test_wallet_init.py @@ -66,7 +66,12 @@ class Test(unittest.TestCase): def run_thread(self, 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): runSystem.main() diff --git a/tests/basicswap/extended/test_wallet_restore.py b/tests/basicswap/extended/test_wallet_restore.py index 67a688d..af507bb 100644 --- a/tests/basicswap/extended/test_wallet_restore.py +++ b/tests/basicswap/extended/test_wallet_restore.py @@ -114,7 +114,12 @@ class Test(TestBase): def run_thread(self, 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): runSystem.main() diff --git a/tests/basicswap/extended/test_xmr_persistent.py b/tests/basicswap/extended/test_xmr_persistent.py index 236ef7e..b99cb9d 100644 --- a/tests/basicswap/extended/test_xmr_persistent.py +++ b/tests/basicswap/extended/test_xmr_persistent.py @@ -228,7 +228,12 @@ def signal_handler(self, sig, frame): def run_thread(self, 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): runSystem.main() @@ -402,7 +407,7 @@ def start_processes(self): # Wait for height, or sequencelock is thrown off by genesis blocktime 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): if self.delay_event.is_set(): raise ValueError("Test stopped.") @@ -451,7 +456,7 @@ class BaseTestWithPrepare(unittest.TestCase): if os.path.exists(test_path) and not RESET_TEST: logging.info(f"Continuing with existing directory: {test_path}") else: - logging.info("Preparing %d nodes.", NUM_NODES) + logging.info(f"Preparing {NUM_NODES} nodes.") prepare_nodes( NUM_NODES, TEST_COINS_LIST, diff --git a/tests/basicswap/selenium/util.py b/tests/basicswap/selenium/util.py index 6091581..74708ec 100644 --- a/tests/basicswap/selenium/util.py +++ b/tests/basicswap/selenium/util.py @@ -20,10 +20,12 @@ BSX_SELENIUM_DRIVER = os.getenv("BSX_SELENIUM_DRIVER", "firefox") def get_driver(): if BSX_SELENIUM_DRIVER == "firefox": from selenium.webdriver import Firefox, FirefoxOptions + options = FirefoxOptions() driver = Firefox(options=options) elif BSX_SELENIUM_DRIVER == "firefox-ci": from selenium.webdriver import Firefox, FirefoxOptions + options = FirefoxOptions() options.headless = True options.add_argument("start-maximized") @@ -32,9 +34,11 @@ def get_driver(): driver = Firefox(options=options) elif BSX_SELENIUM_DRIVER == "chrome": from selenium.webdriver import Chrome, ChromeOptions + driver = Chrome(options=ChromeOptions()) elif BSX_SELENIUM_DRIVER == "safari": from selenium.webdriver import Safari, SafariOptions + driver = Safari(options=SafariOptions()) else: raise ValueError("Unknown driver " + BSX_SELENIUM_DRIVER) diff --git a/tests/basicswap/test_reload.py b/tests/basicswap/test_reload.py index a4a7a50..2807530 100644 --- a/tests/basicswap/test_reload.py +++ b/tests/basicswap/test_reload.py @@ -80,7 +80,12 @@ class Test(unittest.TestCase): def run_thread(self, 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): runSystem.main() diff --git a/tests/basicswap/test_xmr.py b/tests/basicswap/test_xmr.py index f85f8f5..0b80682 100644 --- a/tests/basicswap/test_xmr.py +++ b/tests/basicswap/test_xmr.py @@ -660,7 +660,7 @@ class BaseTest(unittest.TestCase): basicswap_dir, settings, "regtest", - log_name="BasicSwap{}".format(i), + log_name=f"BasicSwap{i}", ) cls.swap_clients.append(sc) sc.setDaemonPID(Coins.BTC, cls.btc_daemons[i].handle.pid)