-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added `--skip-keyring` option to `chia start daemon` command * Fixed a lint error and adopted review comments * Fixed a lint error * Fixed a test * Fixed a test * Added mocks to test * Fixed a test * Removed `bt: BlockTools` from the test case because it seemed to cause config file dead lock * Removed unused mock method * Set `parallel=False` to chia/_tests/cmds/config.py * Set `parallel=False` to chia/_tests/core/util/config.py * Added missing coverage * Fixed mypy error
- Loading branch information
1 parent
8b6f761
commit cfa218d
Showing
4 changed files
with
100 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
from __future__ import annotations | ||
|
||
from pathlib import Path | ||
from typing import Any, Dict, Optional | ||
|
||
import pytest | ||
from _pytest.capture import CaptureFixture | ||
from click.testing import CliRunner | ||
from pytest_mock import MockerFixture | ||
|
||
from chia.cmds.chia import cli | ||
from chia.cmds.start_funcs import create_start_daemon_connection | ||
|
||
|
||
@pytest.mark.anyio | ||
@pytest.mark.parametrize("skip_keyring", [False, True]) | ||
@pytest.mark.parametrize("unlock_keyring", [False, True]) | ||
async def test_daemon( | ||
skip_keyring: bool, unlock_keyring: bool, mocker: MockerFixture, capsys: CaptureFixture[str] | ||
) -> None: | ||
class DummyConnection: | ||
@staticmethod | ||
async def is_keyring_locked() -> bool: | ||
return unlock_keyring | ||
|
||
@staticmethod | ||
async def unlock_keyring(_passphrase: str) -> bool: | ||
return True | ||
|
||
async def connect_to_daemon_and_validate(_root_path: Path, _config: Dict[str, Any]) -> DummyConnection: | ||
return DummyConnection() | ||
|
||
class DummyKeychain: | ||
@staticmethod | ||
def get_cached_master_passphrase() -> Optional[str]: | ||
return None | ||
|
||
def get_current_passphrase() -> Optional[str]: | ||
return "a-passphrase" | ||
|
||
mocker.patch("chia.cmds.start_funcs.connect_to_daemon_and_validate", side_effect=connect_to_daemon_and_validate) | ||
mocker.patch("chia.cmds.start_funcs.Keychain", new=DummyKeychain) | ||
mocker.patch("chia.cmds.start_funcs.get_current_passphrase", side_effect=get_current_passphrase) | ||
|
||
daemon = await create_start_daemon_connection(Path("/path-not-exist"), {}, skip_keyring=skip_keyring) | ||
assert daemon is not None | ||
captured = capsys.readouterr() | ||
assert captured.err == "" | ||
if skip_keyring: | ||
assert captured.out.endswith("Skipping to unlock keyring\n") | ||
else: | ||
assert not captured.out.endswith("Skipping to unlock keyring\n") | ||
|
||
|
||
def test_start_daemon(tmp_path: Path, empty_keyring: Any, mocker: MockerFixture) -> None: | ||
class DummyDaemon: | ||
@staticmethod | ||
async def close() -> None: | ||
return None | ||
|
||
async def create_start_daemon_connection_dummy( | ||
root_path: Path, config: Dict[str, Any], *, skip_keyring: bool | ||
) -> DummyDaemon: | ||
return DummyDaemon() | ||
|
||
mocker.patch( | ||
"chia.cmds.start_funcs.create_start_daemon_connection", side_effect=create_start_daemon_connection_dummy | ||
) | ||
|
||
runner = CliRunner() | ||
result = runner.invoke( | ||
cli, | ||
["--root-path", str(tmp_path), "init"], | ||
) | ||
assert result.exit_code == 0 | ||
result = runner.invoke(cli, ["--root-path", str(tmp_path), "start", "daemon", "-s"]) | ||
assert result.exit_code == 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters