#!/usr/bin/env python3 """Tiny tip test on FLOP TESTNET with a wallet (default test-01): prove that setting a high `tip` on an extrinsic actually makes the transaction cost that much more. Does ONE System.remark with a small tip (0.01 FLOP). Reads the balance before and after and prints the actual cost (fee + tip). If the cost is ~0.01 FLOP above the normal ~0.002 FLOP base fee, the tip mechanism works and the spend-all script can use it to spend huge amounts per tx. Usage: python3 testnet_tip_test.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. Never prints the mnemonic or private key. """ import argparse import json import os 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") TIP = 10**16 # 0.01 FLOP 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 main(): global ADDRESS ap = argparse.ArgumentParser(description="Tip test on FLOP testnet") 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 free(): return sub.query("System", "Account", [ADDRESS])["data"]["free"].value def nonce(): return sub.query("System", "Account", [ADDRESS])["nonce"].value before = free() print(f"before: balance {before / 10**18:.6f} FLOP, nonce {nonce()}") call = sub.compose_call( "System", "remark", {"remark": "0x" + "testnet tip test".encode().hex()}) ext = sub.create_signed_extrinsic( call=call, keypair=kp, nonce=nonce(), tip=TIP) receipt = sub.submit_extrinsic(ext, wait_for_inclusion=True) after = free() cost = before - after print(f"tip test: success={receipt.is_success} " f"tx={receipt.extrinsic_hash} " f"block={sub.get_block_number(receipt.block_hash)}") print(f"after: balance {after / 10**18:.6f} FLOP, nonce {nonce()}") print(f"actual cost: {cost / 10**18:.6f} FLOP " f"(tip was {TIP / 10**18:.6f} FLOP, base fee ~0.002 FLOP)") if cost >= TIP: print("TIP WORKS: cost >= tip, the tip was charged.") else: print("TIP DID NOT WORK AS EXPECTED: cost < tip.") return 0 if receipt.is_success else 1 if __name__ == "__main__": raise SystemExit(main())