igneum/tools/fleet/lib/test_box.py

39 lines
3 KiB
Python

"""Exercises the library against a live Devnet 2 box (the chain the fleet may touch freely): transport, the chain-side
readers, a miner start and stop, a node restart on the current binary and object with the digest read back.
python3 -m lib.test_box dn2-3 (run from tools/fleet)
The known-finished case is a PASS line; the known-failed case is a label that does not exist (a SshError).
"""
import sys, os, time
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from lib import Box, Registry, SshError
def main(label):
try: Box.from_registry("no-such-box-" + label)
except (KeyError, SshError) as e: print("ok known-failed: a missing label raises", type(e).__name__)
else: print("FAIL known-failed case did not raise"); return 1
b = Box.from_registry(label); fails = 0
def chk(name, cond, detail=""):
nonlocal fails
print(("ok " if cond else "FAIL") + f" {name} {detail}"); fails += 0 if cond else 1
chk("alive", b.alive())
w = b.watch(); chk("watch has blocks and daa", "blocks" in w and "daa" in w, str(w)[:100])
h0 = b.height(); chk("height > 0", h0 > 0, h0)
chk("peers >= 1", b.peers() >= 1, b.peers())
chk("exec tip within 60 of the height", abs(b.exec_tip() - h0) <= 60, f"exec {b.exec_tip()} height {h0}")
chk("state root at height-20 reads", bool(b.state_root(max(1, h0 - 20))))
chk("proving status answers", "tipDaa" in b.proving_status())
v = b.node_version(); chk("node version reads", "igneumd" in v, v)
chk("rejects since 1970 is an int", isinstance(b.rejects_since("1970-01-01 00:00:00", f"/root/fleet/dn2-node.log"), int))
b.stop_miners(); pid = b.start_miner(label + "-libtest", b.wallet, pack="dn2", log="/root/fleet/out/libtest-miner.log"); time.sleep(20)
chk("miner started (pid)", pid > 0, pid)
rc, out, _ = b.run("pgrep -c -x igneum-miner", 20); chk("one miner process", out.strip() == "1", out.strip())
b.stop_miners(); rc, out, _ = b.run("pgrep -c -x igneum-miner", 20); chk("miner stopped", out.strip() == "0", out.strip())
seed_peer = next((x.get("dn2_peer") for x in Registry.load().values() if x.get("dn2_seed") and x.get("state") != "destroyed"), "")
binary = b.run("ls /root/fleet/in/igneumd-0313 /root/fleet/in/igneumd-gate 2>/dev/null | head -1", 20)[1].strip()
override = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "devnet2-override.json")
d = b.start_node(binary, override, [seed_peer] if seed_peer else [], devnet_suffix=2, verifier="/opt/igneum-floor/bin/igneum-prove-host", unsynced_mining=True)
chk("node restarted, digest read", d.startswith("4a0b8726"), d[:16])
chk("height resumes within 60 s", (time.sleep(45) or b.height()) >= h0, b.height())
b.start_miner(label, b.wallet, pack="dn2", log="/root/fleet/out/dn2-miner.log") # the box back as it was
print(("PASS" if fails == 0 else "FAIL") + f" lib.test_box on {label}: {fails} failures")
return 1 if fails else 0
if __name__ == "__main__": sys.exit(main(sys.argv[1] if len(sys.argv) > 1 else "dn2-3"))