Exemple #1
0
def main():
    global fixtures, filename, tests, testname, testdata

    parser = argparse.ArgumentParser()
    parser.add_argument("fixtures", type=str, help="fixture file path to run tests")
    args = parser.parse_args()

    qkc_env = DEFAULT_ENV.copy()
    # disable root chain tax
    qkc_env.quark_chain_config.REWARD_TAX_RATE = Fraction(0)

    # load fixtures from specified file or dir
    fixtures = testutils.get_tests_from_file_or_dir(args.fixtures)
    for filename, tests in list(fixtures.items()):
        for testname, testdata in list(tests.items()):
            if exclude_func(filename, None, None):
                print("Skipping: %s %s" % (filename, testname))
                continue
            print("Testing: %s %s" % (filename, testname))
            # hack qkc env into the test
            testdata["qkc"] = qkc_env
            testdata["qkcstate"] = "QuarkChainStateTests" in filename
            testdata["testname"] = testname
            testdata["filename"] = filename
            checker(testdata)
Exemple #2
0
def get_test_env(
    genesis_account=Address.create_empty_account(),
    genesis_quarkash=0,
    genesis_minor_quarkash=0,
    shard_size=2,
    genesis_root_heights=None,
):
    env = DEFAULT_ENV.copy()

    env.db = InMemoryDb()
    env.set_network_id(1234567890)

    env.cluster_config = ClusterConfig()
    env.quark_chain_config.update(shard_size, 1, 1)
    env.quark_chain_config.TESTNET_MASTER_ADDRESS = genesis_account.serialize(
    ).hex()

    if genesis_root_heights:
        check(len(genesis_root_heights) == shard_size)
        for shard_id in range(shard_size):
            env.quark_chain_config.SHARD_LIST[
                shard_id].GENESIS.ROOT_HEIGHT = genesis_root_heights[shard_id]

    # fund genesis account in all shards
    for i, shard in enumerate(env.quark_chain_config.SHARD_LIST):
        shard.GENESIS.ALLOC[genesis_account.address_in_shard(
            i).serialize().hex()] = genesis_minor_quarkash

    env.quark_chain_config.SKIP_MINOR_DIFFICULTY_CHECK = True
    env.quark_chain_config.SKIP_ROOT_DIFFICULTY_CHECK = True
    env.cluster_config.ENABLE_TRANSACTION_HISTORY = True
    env.cluster_config.DB_PATH_ROOT = ""
    check(env.cluster_config.use_mem_db())

    return env
def jrpc_server_context(master):
    env = DEFAULT_ENV.copy()
    env.cluster_config = ClusterConfig()
    env.cluster_config.JSON_RPC_PORT = 38391
    server = JSONRPCServer.start_test_server(env, master)
    yield server
    server.shutdown()
def parse_args():
    parser = argparse.ArgumentParser()
    parser.add_argument("--full_shard_id",
                        type=int,
                        help="full shard id to operate")
    parser.add_argument(
        "--all_shards",
        action="store_true",
        default=False,
        help="query balances in all shards",
    )
    parser.add_argument("--recipient",
                        default=None,
                        type=str,
                        help="query a specific recipient")
    parser.add_argument(
        "--minor_block_height",
        default=None,
        type=int,
        help="query balance at specific minor block height",
    )
    ClusterConfig.attach_arguments(parser)
    args = parser.parse_args()

    env = DEFAULT_ENV.copy()
    env.cluster_config = ClusterConfig.create_from_args(args)

    # initialize database
    if not env.cluster_config.use_mem_db():
        env.db = PersistentDb(
            "{path}/master.db".format(path=env.cluster_config.DB_PATH_ROOT),
            clean=env.cluster_config.CLEAN,
        )

    return env, args
Exemple #5
0
def get_test_env(
    genesis_account=Address.create_empty_account(),
    genesis_minor_quarkash=0,
    chain_size=2,
    shard_size=2,
    genesis_root_heights=None,  # dict(full_shard_id, genesis_root_height)
    remote_mining=False,
    genesis_minor_token_balances={},
):
    check(is_p2(shard_size))
    env = DEFAULT_ENV.copy()

    env.db = InMemoryDb()
    env.set_network_id(1234567890)

    env.cluster_config = ClusterConfig()
    env.quark_chain_config.update(chain_size, shard_size, 10, 1,
                                  env.quark_chain_config.GENESIS_TOKEN)

    if remote_mining:
        env.quark_chain_config.ROOT.CONSENSUS_CONFIG.REMOTE_MINE = True
        env.quark_chain_config.ROOT.CONSENSUS_TYPE = ConsensusType.POW_DOUBLESHA256
        env.quark_chain_config.ROOT.GENESIS.DIFFICULTY = 10

    env.quark_chain_config.ROOT.DIFFICULTY_ADJUSTMENT_CUTOFF_TIME = 40
    env.quark_chain_config.ROOT.DIFFICULTY_ADJUSTMENT_FACTOR = 1024

    if genesis_root_heights:
        check(len(genesis_root_heights) == shard_size * chain_size)
        for chain_id in range(chain_size):
            for shard_id in range(shard_size):
                full_shard_id = chain_id << 16 | shard_size | shard_id
                shard = env.quark_chain_config.shards[full_shard_id]
                shard.GENESIS.ROOT_HEIGHT = genesis_root_heights[full_shard_id]

    # fund genesis account in all shards
    for full_shard_id, shard in env.quark_chain_config.shards.items():
        addr = genesis_account.address_in_shard(
            full_shard_id).serialize().hex()
        if len(genesis_minor_token_balances) != 0:
            shard.GENESIS.ALLOC[addr] = genesis_minor_token_balances
        else:
            shard.GENESIS.ALLOC[addr] = genesis_minor_quarkash
        shard.CONSENSUS_CONFIG.REMOTE_MINE = remote_mining
        shard.DIFFICULTY_ADJUSTMENT_CUTOFF_TIME = 7
        shard.DIFFICULTY_ADJUSTMENT_FACTOR = 512
        if remote_mining:
            shard.CONSENSUS_TYPE = ConsensusType.POW_DOUBLESHA256
            shard.GENESIS.DIFFICULTY = 10
        shard.POSW_CONFIG.WINDOW_SIZE = 2

    env.quark_chain_config.SKIP_MINOR_DIFFICULTY_CHECK = True
    env.quark_chain_config.SKIP_ROOT_DIFFICULTY_CHECK = True
    env.cluster_config.ENABLE_TRANSACTION_HISTORY = True
    env.cluster_config.DB_PATH_ROOT = ""

    check(env.cluster_config.use_mem_db())

    return env
def jrpc_server_context(master):
    env = DEFAULT_ENV.copy()
    env.cluster_config = ClusterConfig()
    env.cluster_config.JSON_RPC_PORT = 38391
    # to pass the circleCi
    env.cluster_config.JSON_RPC_HOST = "127.0.0.1"
    server = JSONRPCServer.start_test_server(env, master)
    try:
        yield server
    finally:
        server.shutdown()
Exemple #7
0
def parse_args():
    parser = argparse.ArgumentParser()
    ClusterConfig.attach_arguments(parser)
    # Unique Id identifying the node in the cluster
    parser.add_argument("--node_id", default="", type=str)
    args = parser.parse_args()

    env = DEFAULT_ENV.copy()
    env.cluster_config = ClusterConfig.create_from_args(args)
    env.slave_config = env.cluster_config.get_slave_config(args.node_id)

    return env
Exemple #8
0
def parse_args():
    parser = argparse.ArgumentParser()
    ClusterConfig.attach_arguments(parser)
    parser.add_argument("--profile", default="", type=str)
    parser.add_argument("--check_db_rblock_from", default=-1, type=int)
    parser.add_argument("--check_db_rblock_to", default=0, type=int)
    parser.add_argument("--check_db_rblock_batch", default=1, type=int)
    args = parser.parse_args()

    env = DEFAULT_ENV.copy()
    env.cluster_config = ClusterConfig.create_from_args(args)
    env.arguments = args

    return env
Exemple #9
0
def get_test_env(
    genesis_account=Address.create_empty_account(),
    genesis_minor_quarkash=0,
    shard_size=2,
    genesis_root_heights=None,
    remote_mining=False,
):
    env = DEFAULT_ENV.copy()

    env.db = InMemoryDb()
    env.set_network_id(1234567890)

    env.cluster_config = ClusterConfig()
    env.quark_chain_config.update(shard_size, 10, 1)

    if remote_mining:
        env.quark_chain_config.ROOT.CONSENSUS_CONFIG.REMOTE_MINE = True
        env.quark_chain_config.ROOT.CONSENSUS_TYPE = ConsensusType.POW_SHA3SHA3
        env.quark_chain_config.ROOT.GENESIS.DIFFICULTY = 10

    env.quark_chain_config.ROOT.DIFFICULTY_ADJUSTMENT_CUTOFF_TIME = 40
    env.quark_chain_config.ROOT.DIFFICULTY_ADJUSTMENT_FACTOR = 1024

    if genesis_root_heights:
        check(len(genesis_root_heights) == shard_size)
        for shard_id in range(shard_size):
            shard = env.quark_chain_config.SHARD_LIST[shard_id]
            shard.GENESIS.ROOT_HEIGHT = genesis_root_heights[shard_id]

    # fund genesis account in all shards
    for i, shard in enumerate(env.quark_chain_config.SHARD_LIST):
        addr = genesis_account.address_in_shard(i).serialize().hex()
        shard.GENESIS.ALLOC[addr] = genesis_minor_quarkash
        shard.CONSENSUS_CONFIG.REMOTE_MINE = remote_mining
        shard.DIFFICULTY_ADJUSTMENT_CUTOFF_TIME = 7
        shard.DIFFICULTY_ADJUSTMENT_FACTOR = 512
        if remote_mining:
            shard.CONSENSUS_TYPE = ConsensusType.POW_SHA3SHA3
            shard.GENESIS.DIFFICULTY = 10

    env.quark_chain_config.SKIP_MINOR_DIFFICULTY_CHECK = True
    env.quark_chain_config.SKIP_ROOT_DIFFICULTY_CHECK = True
    env.cluster_config.ENABLE_TRANSACTION_HISTORY = True
    env.cluster_config.DB_PATH_ROOT = ""

    check(env.cluster_config.use_mem_db())

    return env
Exemple #10
0
def parse_args():
    parser = argparse.ArgumentParser()
    parser.add_argument("action", type=str, help="action to take")
    parser.add_argument("--height", type=int, help="block height to operate")
    parser.add_argument("--hash", type=str, help="block hash to operate")
    ClusterConfig.attach_arguments(parser)
    args = parser.parse_args()

    env = DEFAULT_ENV.copy()
    env.cluster_config = ClusterConfig.create_from_args(args)

    # initialize database
    if not env.cluster_config.use_mem_db():
        env.db = PersistentDb(
            "{path}/master.db".format(path=env.cluster_config.DB_PATH_ROOT),
            clean=env.cluster_config.CLEAN,
        )

    return env, args