# Path: caesure/bitcoin.py
# def P (msg):
#     def goto_testnet (self):
# def dhash (s):
# def rhash (s):
# def bcrepr (n):
# def float_to_btc (f):
# def key_to_address (s, version=0):
# def address_to_key (s, version=0):
# def compute_rewards (n):
# def compute_reward (height):
#     def __init__ (self):
#     def end (self):
#     def __init__ (self):
#     def copy (self):
#     def get_hash (self):
#     def dump (self, fout=sys.stdout):
#     def render (self):
#     def verify (self, index, lock_script, block_timestamp):
#     def dump (self, fout=sys.stdout):
#     def __len__ (self):
#     def get_height (self):
#     def make_TX (self):
#     def check_bits (self):
#     def get_merkle_hash (self):
#     def check_rules (self):
# W = sys.stderr.write
#     BITCOIN_PORT = 8333
#     MAGIC = '\xf9\xbe\xb4\xd9'
#     ADMIN_PORT = 8380
#     BD_FILE = '/tmp/caesure.bd'
#         ADMIN_PORT = 9380
#         BD_FILE = '/tmp/caesure_testnet.bd'
# ZERO_NAME = Name ('\x00' * 32)
# OBJ_TX    = 1
# OBJ_BLOCK = 2
# MAX_BLOCK_SIZE = 1000000
# COIN           = 100000000
# MAX_MONEY      = 21000000 * COIN
# NULL_OUTPOINT = (ZERO_NAME, 4294967295)
#         D = fout.write
# class NetworkConfig:
# class BadAddress (Exception):
# class timer:
# class TX (caesure.proto.TX):
# class BadBlock (Exception):
# class BLOCK (caesure.proto.BLOCK):


import os
import json
import re
import sys
    import argparse
from caesure.script import *
from caesure.bitcoin import TX, ZERO_NAME, KEY
        W ('%d failures:\n' % (len(fails)))
        for i, kind, fail, why in fails:
            W ('  %d %s %r, %r\n' % (i, kind, fail, why))

def load_json_test_file (path):
    return list (enumerate (json.loads (frob (open (path, 'rb').read()))))

if __name__ == '__main__':
    p = argparse.ArgumentParser (description='run bitcoin-core unit script tests')
    p.add_argument ('-v', type=int, action='append', help='run a specific valid test by number')
    p.add_argument ('-i', type=int, action='append', help='run a specific invalid test by number')
    p.add_argument ('-d', action='store_true', help='debug')
    p.add_argument ('--verbose', action='store_true', help='dump each script test before execution')
    p.add_argument ('where', type=str, help='location of json test files', metavar='PATH')

    args = p.parse_args()
    verbose = args.verbose

    valid = load_json_test_file (os.path.join (args.where, 'script_valid.json'))
    invalid = load_json_test_file (os.path.join (args.where, 'script_invalid.json'))

    if args.v is not None:
        tests = []
        for num in args.v:
            tests.append (valid[num])
        valid = tests
        invalid = []

    if args.i is not None:
        tests = []

# Path: caesure/bitcoin.py
# def P (msg):
#     def goto_testnet (self):
# def dhash (s):
# def rhash (s):
# def bcrepr (n):
# def float_to_btc (f):
# def key_to_address (s, version=0):
# def address_to_key (s, version=0):
# def compute_rewards (n):
# def compute_reward (height):
#     def __init__ (self):
#     def end (self):
#     def __init__ (self):
#     def copy (self):
#     def get_hash (self):
#     def dump (self, fout=sys.stdout):
#     def render (self):
#     def verify (self, index, lock_script, block_timestamp):
#     def dump (self, fout=sys.stdout):
#     def __len__ (self):
#     def get_height (self):
#     def make_TX (self):
#     def check_bits (self):
#     def get_merkle_hash (self):
#     def check_rules (self):
# W = sys.stderr.write
#     BITCOIN_PORT = 8333
#     MAGIC = '\xf9\xbe\xb4\xd9'
#     ADMIN_PORT = 8380
#     BD_FILE = '/tmp/caesure.bd'
#         ADMIN_PORT = 9380
#         BD_FILE = '/tmp/caesure_testnet.bd'
# ZERO_NAME = Name ('\x00' * 32)
# OBJ_TX    = 1
# OBJ_BLOCK = 2
# MAX_BLOCK_SIZE = 1000000
# COIN           = 100000000
# MAX_MONEY      = 21000000 * COIN
# NULL_OUTPOINT = (ZERO_NAME, 4294967295)
#         D = fout.write
# class NetworkConfig:
# class BadAddress (Exception):
# class timer:
# class TX (caesure.proto.TX):
# class BadBlock (Exception):
# class BLOCK (caesure.proto.BLOCK):


# Path: test/test_core.py
import os
import json
import re
import sys
    import argparse
from caesure.script import *
from caesure.bitcoin import TX, ZERO_NAME, KEY

        W ('%d failures:\n' % (len(fails)))
        for i, kind, fail, why in fails:
            W ('  %d %s %r, %r\n' % (i, kind, fail, why))

def load_json_test_file (path):
    return list (enumerate (json.loads (frob (open (path, 'rb').read()))))

if __name__ == '__main__':
    p = argparse.ArgumentParser (description='run bitcoin-core unit script tests')
    p.add_argument ('-v', type=int, action='append', help='run a specific valid test by number')
    p.add_argument ('-i', type=int, action='append', help='run a specific invalid test by number')
    p.add_argument ('-d', action='store_true', help='debug')
    p.add_argument ('--verbose', action='store_true', help='dump each script test before execution')
    p.add_argument ('where', type=str, help='location of json test files', metavar='PATH')

    args = p.parse_args()
    verbose = args.verbose

    valid = load_json_test_file (os.path.join (args.where, 'script_valid.json'))
    invalid = load_json_test_file (os.path.join (args.where, 'script_invalid.json'))

    if args.v is not None:
        tests = []
        for num in args.v:
            tests.append (valid[num])
        valid = tests
        invalid = []

    if args.i is not None:
        tests = []

        for num in args.i: