#!/usr/bin/env python3 """ Test script to verify that DragonX rejects a block with diff=1 (trivially easy nBits). This script: 1. Connects to the local DragonX node via RPC 2. Fetches the current tip block in raw hex 3. Deserializes the block header 4. Tampers with nBits to set difficulty=1 (0x200f0f0f) 5. Reserializes and submits via submitblock 6. Verifies the node rejects it Usage: python3 test_diff1_block.py """ import json import struct import subprocess import sys import os import time CLI = os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "src", "dragonx-cli") DEBUG_LOG = os.path.expanduser("~/.hush/DRAGONX/debug.log") def rpc(method, *args): """Call dragonx-cli with the given RPC method and arguments.""" cmd = [CLI, method] + [str(a) for a in args] try: result = subprocess.run(cmd, capture_output=True, text=True, check=True) return result.stdout.strip() except subprocess.CalledProcessError as e: # Some RPC calls return non-zero for rejection messages if e.stdout and e.stdout.strip(): return e.stdout.strip() if e.stderr and e.stderr.strip(): return e.stderr.strip() raise def rpc_json(method, *args): """Call dragonx-cli and parse JSON result.""" raw = rpc(method, *args) return json.loads(raw) def read_uint32(data, offset): return struct.unpack_from(' 0x{DIFF1_NBITS:08x} (diff=1)...") tampered_data = bytearray(block_data) struct.pack_into(' {new_hash}") print(" This should NOT happen!") print("\n" + "=" * 60) print("Test complete.") if __name__ == "__main__": main()