Merge pull request #270 from tecnovert/ci-selenium

Add Selenium test to CI
This commit is contained in:
tecnovert
2025-03-05 11:12:58 +00:00
committed by GitHub
15 changed files with 143 additions and 71 deletions

View File

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

View File

@@ -327,9 +327,7 @@ def formatBids(swap_client, bids, filters) -> bytes:
amount_to = None
if ci_to:
amount_to = ci_to.format_amount(
(b[4] * b[10]) // ci_from.COIN()
)
amount_to = ci_to.format_amount((b[4] * b[10]) // ci_from.COIN())
bid_data = {
"bid_id": b[2].hex(),
@@ -343,14 +341,13 @@ def formatBids(swap_client, bids, filters) -> bytes:
"bid_rate": swap_client.ci(b[14]).format_amount(b[10]),
"bid_state": strBidState(b[5]),
"addr_from": b[11],
"addr_to": offer.addr_to if offer else None
"addr_to": offer.addr_to if offer else None,
}
if with_extra_info:
bid_data.update({
"tx_state_a": strTxState(b[7]),
"tx_state_b": strTxState(b[8])
})
bid_data.update(
{"tx_state_a": strTxState(b[7]), "tx_state_b": strTxState(b[8])}
)
rv.append(bid_data)
return bytes(json.dumps(rv), "UTF-8")
@@ -983,20 +980,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 +1012,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 +1023,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:

View File

@@ -6,17 +6,17 @@
# file LICENSE or http://www.opensource.org/licenses/mit-license.php.
"""
Message 2 bytes msg_class, 4 bytes length, [ 2 bytes msg_type, payload ]
Message 2 bytes msg_class, 4 bytes length, [ 2 bytes msg_type, payload ]
Handshake procedure:
node0 connecting to node1
node0 send_handshake
node1 process_handshake
node1 send_ping - With a version field
node0 recv_ping
Both nodes are initialised
Handshake procedure:
node0 connecting to node1
node0 send_handshake
node1 process_handshake
node1 send_ping - With a version field
node0 recv_ping
Both nodes are initialised
XChaCha20_Poly1305 mac is 16bytes
XChaCha20_Poly1305 mac is 16bytes
"""
import time

View File

@@ -151,7 +151,9 @@ def page_bid(self, url_split, post_string):
)
def page_bids(self, url_split, post_string, sent=False, available=False, received=False):
def page_bids(
self, url_split, post_string, sent=False, available=False, received=False
):
server = self.server
swap_client = server.swap_client
swap_client.checkSystemStatus()

View File

@@ -145,7 +145,7 @@ def get_data_with_pagination(data, filters):
offset = filters.get("offset", 0)
limit = filters.get("limit", PAGE_LIMIT)
return data[offset:offset + limit]
return data[offset : offset + limit]
def getTxIdHex(bid, tx_type, suffix):