|
32 | 32 | parse_codex32, |
33 | 33 | recover_secret, |
34 | 34 | ) |
35 | | -from codex32._bitcoin_core import BitcoinCore |
| 35 | +from codex32._bitcoin_core import BitcoinCore, BitcoinCoreError |
36 | 36 | from codex32.bech32 import _chars_to_u5, bech32_encode |
37 | 37 | from codex32.checksums import _CODEX32, _CODEX32_LONG |
38 | 38 | from codex32.cli import main, ms_main |
@@ -287,6 +287,39 @@ def test_check_accepts_shared_core_lightning_artifacts(value: str) -> None: |
287 | 287 | assert result.stderr == "" |
288 | 288 |
|
289 | 289 |
|
| 290 | +def _missing_core(*_args: object, **_kwargs: object) -> BitcoinCore: |
| 291 | + raise BitcoinCoreError("bitcoin-cli was not found.") |
| 292 | + |
| 293 | + |
| 294 | +@pytest.mark.parametrize("command", ("secret", "share", "correct")) |
| 295 | +def test_missing_core_names_the_codex32_fallback( |
| 296 | + monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str], command: str |
| 297 | +) -> None: |
| 298 | + def search(*_args: object, **_kwargs: object) -> None: |
| 299 | + raise AssertionError("searched before connecting to Bitcoin Core") |
| 300 | + |
| 301 | + monkeypatch.setattr("codex32.cli.BitcoinCore.connect", _missing_core) |
| 302 | + monkeypatch.setattr("codex32.cli._scheduled_candidates", search) |
| 303 | + monkeypatch.setattr(sys, "stdin", io.StringIO(VECTOR_1["secret_s"].replace("x", "q", 1) + "\n")) |
| 304 | + |
| 305 | + assert ms_main([command, "d"] if command == "share" else [command]) == (3 if command == "correct" else 1) |
| 306 | + assert capsys.readouterr().err == ( |
| 307 | + f"ms32 {command}: bitcoin-cli was not found.\nThis command uses Bitcoin Core to show the master " |
| 308 | + f"fingerprint and rank corrections. 'codex32 {command}' works without Core but doesn't show the " |
| 309 | + "fingerprint.\n" |
| 310 | + ) |
| 311 | + |
| 312 | + |
| 313 | +def test_missing_core_for_wallet_setup_offers_no_fallback(monkeypatch: pytest.MonkeyPatch) -> None: |
| 314 | + cli = importlib.import_module("codex32.cli") |
| 315 | + monkeypatch.setattr("codex32.cli.BitcoinCore.connect", _missing_core) |
| 316 | + |
| 317 | + with pytest.raises(cli._CommandError) as failure: |
| 318 | + cli._connected_core() |
| 319 | + |
| 320 | + assert str(failure.value) == "bitcoin-cli was not found.\nThis command gives Bitcoin Core the master key." |
| 321 | + |
| 322 | + |
290 | 323 | def test_check_does_not_derive_wallet_keys(monkeypatch: pytest.MonkeyPatch) -> None: |
291 | 324 | cli_module = importlib.import_module("codex32.cli") |
292 | 325 |
|
|
0 commit comments