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 __init__(self, db=None, evm_config=None): self.db = db or InMemoryDb() self.__cluster_config = ClusterConfig() self.evm_config = evm_config or get_default_evm_config() self.evm_config["NETWORK_ID"] = self.quark_chain_config.NETWORK_ID self.evm_env = EvmEnv(db=self.db, config=self.evm_config)
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 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 test_special_contract_enable_ts(self): env = Env() for addr in PRECOMPILED_CONTRACTS_AFTER_EVM_ENABLED: self.assertEqual(specials[addr][1], 0) cluster_config = ClusterConfig() cluster_config.QUARKCHAIN.ENABLE_EVM_TIMESTAMP = 123 env.cluster_config = cluster_config for addr in PRECOMPILED_CONTRACTS_AFTER_EVM_ENABLED: self.assertEqual(specials[addr][1], 123)
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()
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