def main() -> None: # Use a temp keychain which will be deleted when it exits scope with TempKeyring() as keychain: # If launched with -D, we should connect to the keychain via the daemon instead # of using a local keychain if "-D" in sys.argv: keychain = None sys.argv.remove( "-D" ) # Remove -D to avoid conflicting with load_config_cli's argparse usage config = load_config_cli(DEFAULT_ROOT_PATH, "config.yaml", SERVICE_NAME) config["database_path"] = config["simulator_database_path"] config["peer_db_path"] = config["simulator_peer_db_path"] config["introducer_peer"]["host"] = "127.0.0.1" config["introducer_peer"]["port"] = 58555 config["selected_network"] = "testnet0" config["simulation"] = True kwargs = service_kwargs_for_full_node_simulator( DEFAULT_ROOT_PATH, config, create_block_tools(test_constants, root_path=DEFAULT_ROOT_PATH, keychain=keychain), ) return run_service(**kwargs)
if __name__ == "__main__": from tests.block_tools import create_block_tools, test_constants from tests.util.keyring import TempKeyring from chia.util.default_root import DEFAULT_ROOT_PATH with TempKeyring() as keychain: # TODO: mariano: fix this with new consensus bt = create_block_tools(root_path=DEFAULT_ROOT_PATH, keychain=keychain) # TODO: address hint error and remove ignore # error: Argument 2 to "create_genesis_block" of "BlockTools" has incompatible type "bytes"; expected # "bytes32" [arg-type] new_genesis_block = bt.create_genesis_block( test_constants, b"0") # type: ignore[arg-type] print(bytes(new_genesis_block))
def cleanup_keyring(keyring: TempKeyring): keyring.cleanup() temp_keyring = TempKeyring() keychain = temp_keyring.get_keychain() atexit.register(cleanup_keyring, temp_keyring) # Attempt to cleanup the temp keychain test_constants = test_constants_original.replace( **{ "DISCRIMINANT_SIZE_BITS": 32, "SUB_SLOT_ITERS_STARTING": 2**12 }) bt = create_block_tools(constants=test_constants, keychain=keychain) @pytest.fixture(scope="session") def event_loop(): loop = asyncio.get_event_loop() yield loop log = logging.getLogger(__name__) @pytest.fixture(scope="function", params=[1, 2]) async def empty_blockchain(request): bc1, connection, db_path = await create_blockchain(test_constants, request.param)
import atexit import json import aiohttp import pytest def cleanup_keyring(keyring: TempKeyring): keyring.cleanup() temp_keyring1 = TempKeyring() temp_keyring2 = TempKeyring() atexit.register(cleanup_keyring, temp_keyring1) atexit.register(cleanup_keyring, temp_keyring2) b_tools = create_block_tools(constants=test_constants_modified, keychain=temp_keyring1.get_keychain()) b_tools_1 = create_block_tools(constants=test_constants_modified, keychain=temp_keyring2.get_keychain()) new_config = b_tools._config new_config["daemon_port"] = 55401 b_tools.change_config(new_config) class TestDaemon: @pytest.fixture(scope="function") async def get_daemon(self): async for _ in setup_daemon(btools=b_tools): yield _ @pytest.fixture(scope="function") async def simulation(self): async for _ in setup_full_system(