#!/usr/bin/env python3 """Complete 26 more testnet transactions with a wallet (default test-01). Already done on testnet today (4): System.remark, System.remark_with_event, Balances.burn, Utility.batch. This script does 26 more randomized ones (same mix as the devnet runner: remark / remark_with_event / burn / batch), so the wallet reaches 30 testnet transactions today. Usage: python3 testnet_daily30.py [--label ] The wallet label selects which wallet in the encrypted store to use; the address is read from that wallet entry (never hardcoded). Default label flop-devnet-test-01. Pointed at the testnet RPC (wss://testnet.flop.network). One-off run only, not a cron. These prove the wallet can do the full daily volume on testnet. They do NOT count as inference spend for the airdrop. Never prints the mnemonic or private key. """ import argparse import json import os import random import subprocess import sys import time RPC_URL = "wss://testnet.flop.network" ENC = os.path.expanduser("~/workspace/flop-wallet/test-wallets/wallets.json.enc") PW = os.path.expanduser("~/workspace/flop-wallet/vault/wallet-password.txt") N = 26 def decrypt_wallets(store=ENC, pw=PW): out = subprocess.run( ["openssl", "enc", "-d", "-aes-256-cbc", "-iter", "200000", "-in", store, "-pass", f"file:{pw}"], capture_output=True, check=True) return json.loads(out.stdout.decode()) def payload(text): return "0x" + text.encode().hex() def rand_payload(label): seq = random.randint(1, 99999) h = os.urandom(16).hex() ts = int(time.time()) tpl = random.choice([ f"testnet probe {label} seq={seq} ts={ts}", '{"kind":"remark_test","wallet":"%s","seq":%d,"note":"throughput check"}' % (label, seq), f"ping {h[:16]} {label}", '{"test":"heartbeat","wallet":"%s","id":"%s"}' % (label, h[:12]), f"0x{h}", ]) return payload(tpl) def main(): global ADDRESS ap = argparse.ArgumentParser(description="26 randomised testnet transactions") ap.add_argument("--label", default="flop-devnet-test-01", help="wallet label in the encrypted store") ap.add_argument("--store", default=ENC) ap.add_argument("--pw", default=PW) args = ap.parse_args() from substrateinterface import SubstrateInterface, Keypair, KeypairType wallets = decrypt_wallets(args.store, args.pw) w = next(x for x in wallets if x["label"] == args.label) ADDRESS = w["address"] kp = Keypair.create_from_mnemonic( w["mnemonic"], ss58_format=42, crypto_type=KeypairType.ED25519) assert kp.ss58_address == ADDRESS, "derived address mismatch" sub = None last = None for i in range(5): try: sub = SubstrateInterface(url=RPC_URL, ws_options={"timeout": 120}) sub.init_runtime() break except Exception as e: last = e print(f"RPC connect attempt {i + 1} failed ({type(e).__name__}), retrying...") time.sleep(10) if sub is None: raise RuntimeError(f"cannot reach testnet RPC: {last}") def nonce(): return sub.query("System", "Account", [ADDRESS])["nonce"].value def free(): return sub.query("System", "Account", [ADDRESS])["data"]["free"].value print(f"start: balance {free() / 10**18:.6f} FLOP, nonce {nonce()}") ok = 0 counts = {"remark": 0, "remark_with_event": 0, "burn": 0, "batch": 0} for i in range(N): r = random.random() try: if r < 0.45: kind, pallet, name, params = ( "remark", "System", "remark", {"remark": rand_payload("test-01")}) elif r < 0.65: kind, pallet, name, params = ( "remark_with_event", "System", "remark_with_event", {"remark": rand_payload("test-01")}) elif r < 0.82: inner = [] for _ in range(random.randint(2, 4)): if random.random() < 0.85: inner.append(sub.compose_call( "System", "remark", {"remark": rand_payload("test-01")})) else: inner.append(sub.compose_call( "Balances", "burn", {"value": random.randint(10**14, 10**15), "keep_alive": True})) kind, pallet, name, params = ( "batch", "Utility", "batch", {"calls": inner}) else: kind, pallet, name, params = ( "burn", "Balances", "burn", {"value": random.randint(10**14, 3 * 10**15), "keep_alive": True}) call = sub.compose_call(pallet, name, params) ext = sub.create_signed_extrinsic( call=call, keypair=kp, nonce=nonce()) receipt = sub.submit_extrinsic(ext, wait_for_inclusion=True) if receipt.is_success: ok += 1 counts[kind] += 1 print(f"{i + 1}/{N} {kind}: ok block={sub.get_block_number(receipt.block_hash)} tx={str(receipt.extrinsic_hash)[:18]}...") else: print(f"{i + 1}/{N} {kind}: FAILED {receipt.error_message}") except Exception as e: print(f"{i + 1}/{N}: error {str(e)[:160]}") time.sleep(random.uniform(3, 8)) print(f"done: {ok}/{N} ok counts={counts}") print(f"end: balance {free() / 10**18:.6f} FLOP, nonce {nonce()}") return 0 if ok == N else 1 if __name__ == "__main__": raise SystemExit(main())