def chia_init( root_path: Path, *, should_check_keys: bool = True, fix_ssl_permissions: bool = False, testnet: bool = False, experimental_v2_db: bool = False, ): """ Standard first run initialization or migration steps. Handles config creation, generation of SSL certs, and setting target addresses (via check_keys). should_check_keys can be set to False to avoid blocking when accessing a passphrase protected Keychain. When launching the daemon from the GUI, we want the GUI to handle unlocking the keychain. """ if os.environ.get("CHIA_ROOT", None) is not None: print( f"warning, your CHIA_ROOT is set to {os.environ['CHIA_ROOT']}. " f"Please unset the environment variable and run chia init again\n" f"or manually migrate config.yaml" ) print(f"Chia directory {root_path}") if root_path.is_dir() and Path(root_path / "config" / "config.yaml").exists(): # This is reached if CHIA_ROOT is set, or if user has run chia init twice # before a new update. if testnet: configure(root_path, "", "", "", "", "", "", "", "", testnet="true", peer_connect_timeout="") if fix_ssl_permissions: fix_ssl(root_path) if should_check_keys: check_keys(root_path) print(f"{root_path} already exists, no migration action taken") return -1 create_default_chia_config(root_path) if testnet: configure(root_path, "", "", "", "", "", "", "", "", testnet="true", peer_connect_timeout="") create_all_ssl(root_path) if fix_ssl_permissions: fix_ssl(root_path) if should_check_keys: check_keys(root_path) if experimental_v2_db: config: Dict = load_config(root_path, "config.yaml")["full_node"] db_path_replaced: str = config["database_path"].replace("CHALLENGE", config["selected_network"]) db_path = path_from_root(root_path, db_path_replaced) mkdir(db_path.parent) import sqlite3 with sqlite3.connect(db_path) as connection: connection.execute("CREATE TABLE database_version(version int)") connection.execute("INSERT INTO database_version VALUES (2)") connection.commit() print("") print("To see your keys, run 'chia keys show --show-mnemonic-seed'") return 0
def test_create_config_overwrite(self, tmpdir): """ Test create_default_chia_config() when overwriting an existing config.yaml """ # When: using a clean directory root_path: Path = Path(tmpdir) config_file_path: Path = root_path / "config" / "config.yaml" mkdir(config_file_path.parent) # When: config.yaml already exists with content with open(config_file_path, "w") as f: f.write("Some config content") # Expect: config.yaml exists assert config_file_path.exists() is True # When: creating a new config create_default_chia_config(root_path) # Expect: config.yaml exists assert config_file_path.exists() is True expected_content: str = initial_config_file("config.yaml") assert len(expected_content) > 0 with open(config_file_path, "r") as f: actual_content: str = f.read() # Expect: config.yaml contents are overwritten with initial contents assert actual_content == expected_content
def root_path_populated_with_config(self, tmpdir) -> Path: """ Create a temp directory and populate it with a default config.yaml. Returns the root path containing the config. """ root_path: Path = Path(tmpdir) create_default_chia_config(root_path) return Path(root_path)
def test_environment(tmp_path) -> Iterator[TestEnvironment]: dir_1_count: int = 7 dir_2_count: int = 3 plots: List[Path] = get_test_plots() assert len(plots) >= dir_1_count + dir_2_count dir_1: TestDirectory = TestDirectory(tmp_path / "plots" / "1", plots[0:dir_1_count]) dir_2: TestDirectory = TestDirectory(tmp_path / "plots" / "2", plots[dir_1_count : dir_1_count + dir_2_count]) create_default_chia_config(tmp_path) refresh_tester = PlotRefreshTester(tmp_path) refresh_tester.plot_manager.set_public_keys(bt.plot_manager.farmer_public_keys, bt.plot_manager.pool_public_keys) yield TestEnvironment(tmp_path, refresh_tester, dir_1, dir_2) refresh_tester.plot_manager.stop_refreshing()
def test_pool_config(): test_root = Path("/tmp") test_path = Path("/tmp/config") eg_config = test_path / "config.yaml" to_config = test_path / "test_pool_config.yaml" create_default_chia_config(test_root, ["config.yaml"]) assert eg_config.exists() eg_config.rename(to_config) config = load_config(test_root, "test_pool_config.yaml") auth_sk: PrivateKey = AugSchemeMPL.key_gen(b"1" * 32) d = { "authentication_public_key": bytes(auth_sk.get_g1()).hex(), "owner_public_key": "84c3fcf9d5581c1ddc702cb0f3b4a06043303b334dd993ab42b2c320ebfa98e5ce558448615b3f69638ba92cf7f43da5", "p2_singleton_puzzle_hash": "2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824", "payout_instructions": "c2b08e41d766da4116e388357ed957d04ad754623a915f3fd65188a8746cf3e8", "pool_url": "localhost", "launcher_id": "ae4ef3b9bfe68949691281a015a9c16630fc8f66d48c19ca548fb80768791afa", "target_puzzle_hash": "344587cf06a39db471d2cc027504e8688a0a67cce961253500c956c73603fd58", } pwc = PoolWalletConfig.from_json_dict(d) config_a = config.copy() config_b = config.copy() config_a["wallet"]["pool_list"] = [d] config_b["wallet"]["pool_list"] = [pwc.to_json_dict()] print(config["wallet"]["pool_list"]) save_config(test_root, "test_pool_config_a.yaml", config_a) save_config(test_root, "test_pool_config_b.yaml", config_b) assert config_a == config_b
def test_create_config_new(self, tmpdir): """ Test create_default_chia_config() as in a first run scenario """ # When: using a clean directory root_path: Path = Path(tmpdir) config_file_path: Path = root_path / "config" / "config.yaml" # Expect: config.yaml doesn't exist assert config_file_path.exists() is False # When: creating a new config create_default_chia_config(root_path) # Expect: config.yaml exists assert config_file_path.exists() is True expected_content: str = initial_config_file("config.yaml") assert len(expected_content) > 0 with open(config_file_path, "r") as f: actual_content: str = f.read() # Expect: config.yaml contents are seeded with initial contents assert actual_content == expected_content
def chia_init(root_path: Path, *, should_check_keys: bool = True, fix_ssl_permissions: bool = False): """ Standard first run initialization or migration steps. Handles config creation, generation of SSL certs, and setting target addresses (via check_keys). should_check_keys can be set to False to avoid blocking when accessing a passphrase protected Keychain. When launching the daemon from the GUI, we want the GUI to handle unlocking the keychain. """ if os.environ.get("CHIA_ROOT", None) is not None: print( f"warning, your CHIA_ROOT is set to {os.environ['CHIA_ROOT']}. " f"Please unset the environment variable and run chia init again\n" f"or manually migrate config.yaml") print(f"Chia directory {root_path}") if root_path.is_dir() and Path( root_path / "config" / "config.yaml").exists(): # This is reached if CHIA_ROOT is set, or if user has run chia init twice # before a new update. if fix_ssl_permissions: fix_ssl(root_path) if should_check_keys: check_keys(root_path) print(f"{root_path} already exists, no migration action taken") return -1 create_default_chia_config(root_path) create_all_ssl(root_path) if fix_ssl_permissions: fix_ssl(root_path) if should_check_keys: check_keys(root_path) print("") print("To see your keys, run 'chia keys show --show-mnemonic-seed'") return 0
def chia_init(root_path: Path): if os.environ.get("CHIA_ROOT", None) is not None: print( f"warning, your CHIA_ROOT is set to {os.environ['CHIA_ROOT']}. " f"Please unset the environment variable and run chia init again\n" f"or manually migrate config.yaml") print(f"Chia directory {root_path}") if root_path.is_dir() and Path( root_path / "config" / "config.yaml").exists(): # This is reached if CHIA_ROOT is set, or if user has run chia init twice # before a new update. check_keys(root_path) print(f"{root_path} already exists, no migration action taken") return -1 create_default_chia_config(root_path) create_all_ssl(root_path) check_keys(root_path) print("") print("To see your keys, run 'chia keys show'") return 0