def database_server_ipc_path(): core_db = MemoryDB() core_db[b'key-a'] = b'value-a' chaindb = ChainDB(core_db) # TODO: use a custom chain class only for testing. chaindb.persist_header(ROPSTEN_GENESIS_HEADER) with tempfile.TemporaryDirectory() as temp_dir: chain_config = ChainConfig(network_id=ROPSTEN_NETWORK_ID, data_dir=temp_dir) manager = get_chaindb_manager(chain_config, core_db) chaindb_server_process = multiprocessing.Process( target=serve_chaindb, args=(manager, ), ) chaindb_server_process.start() wait_for_ipc(chain_config.database_ipc_path) try: yield chain_config.database_ipc_path finally: kill_process_gracefully(chaindb_server_process, logging.getLogger())
def test_chain_config_from_preconfigured_network(network_id): chain_config = ChainConfig.from_preconfigured_network(network_id) chain = chain_config.initialize_chain(AtomicDB(MemoryDB())) if network_id == MAINNET_NETWORK_ID: assert chain_config.chain_id == MainnetChain.chain_id assert_vm_configuration_equal(chain_config.vm_configuration, MainnetChain.vm_configuration) assert chain.get_canonical_head() == MAINNET_GENESIS_HEADER elif network_id == ROPSTEN_NETWORK_ID: assert chain_config.chain_id == RopstenChain.chain_id assert_vm_configuration_equal(chain_config.vm_configuration, RopstenChain.vm_configuration) assert chain.get_canonical_head() == ROPSTEN_GENESIS_HEADER else: assert False, "Invariant: unreachable code path"
def database_server_ipc_path(): core_db = MemoryDB() core_db[b'key-a'] = b'value-a' chaindb = ChainDB(core_db) # TODO: use a custom chain class only for testing. chaindb.persist_header_to_db(ROPSTEN_GENESIS_HEADER) with tempfile.TemporaryDirectory() as temp_dir: ipc_path = os.path.join(temp_dir, 'chaindb.ipc') chaindb_server_process = multiprocessing.Process( target=serve_chaindb, args=(core_db, ipc_path), ) chaindb_server_process.start() wait_for_ipc(ipc_path) try: yield ipc_path finally: kill_process_gracefully(chaindb_server_process)