Skip to content

Commit

Permalink
fix: mnemonic removed from error msg (#1902)
Browse files Browse the repository at this point in the history
  • Loading branch information
antazoey authored Feb 1, 2024
1 parent 97ee313 commit 2240d14
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
3 changes: 2 additions & 1 deletion src/ape/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class LogLevel(IntEnum):
logging.SUCCESS = LogLevel.SUCCESS.value # type: ignore
DEFAULT_LOG_LEVEL = LogLevel.INFO.name
DEFAULT_LOG_FORMAT = "%(levelname)s%(plugin)s: %(message)s"
HIDDEN_MESSAGE = "[hidden]"


def success(self, message, *args, **kws):
Expand Down Expand Up @@ -278,7 +279,7 @@ def sanitize_url(url: str) -> str:

# If there is a path, hide it but show that you are hiding it.
# Use string interpolation to prevent URL-character encoding.
return f"{url_obj.with_path('')}/[hidden]" if url_obj.path else f"{url}"
return f"{url_obj.with_path('')}/{HIDDEN_MESSAGE}" if url_obj.path else f"{url}"


logger = ApeLogger.create()
Expand Down
4 changes: 3 additions & 1 deletion src/ape_accounts/_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from eth_utils import to_checksum_address

from ape.cli import ape_cli_context, existing_alias_argument, non_existing_alias_argument
from ape.logging import HIDDEN_MESSAGE
from ape.utils.basemodel import ManagerAccessMixin
from ape_accounts import (
AccountContainer,
Expand Down Expand Up @@ -150,7 +151,8 @@ def ask_for_passphrase():
passphrase = ask_for_passphrase()
account = import_account_from_mnemonic(alias, passphrase, mnemonic, custom_hd_path)
except Exception as error:
cli_ctx.abort(f"Seed phrase can't be imported: {error}")
error_msg = f"{error}".replace(mnemonic, HIDDEN_MESSAGE)
cli_ctx.abort(f"Seed phrase can't be imported: {error_msg}")

else:
key = click.prompt("Enter Private Key", hide_input=True)
Expand Down
15 changes: 7 additions & 8 deletions tests/integration/cli/test_accounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from eth_account import Account
from eth_account.hdaccount import ETHEREUM_DEFAULT_PATH

from ape.logging import HIDDEN_MESSAGE
from tests.integration.cli.utils import assert_failure, run_once

ALIAS = "test"
Expand Down Expand Up @@ -158,7 +159,7 @@ def test_import_mnemonic_default_hdpath(
result = runner.invoke(
ape_cli,
["accounts", "import", "--use-mnemonic", ALIAS],
input="\n".join([f"{MNEMONIC}", PASSWORD, PASSWORD]),
input="\n".join([MNEMONIC, PASSWORD, PASSWORD]),
)
assert result.exit_code == 0, result.output
assert temp_account_mnemonic_default_hdpath.address in result.output
Expand All @@ -175,7 +176,7 @@ def test_import_mnemonic_custom_hdpath(
result = runner.invoke(
ape_cli,
["accounts", "import", ALIAS, "--use-mnemonic", "--hd-path", CUSTOM_HDPATH],
input="\n".join([f"{MNEMONIC}", PASSWORD, PASSWORD]),
input="\n".join([MNEMONIC, PASSWORD, PASSWORD]),
)
assert result.exit_code == 0, result.output
assert temp_account_mnemonic_custom_hdpath.address in result.output
Expand Down Expand Up @@ -205,14 +206,12 @@ def test_import_invalid_mnemonic(ape_cli, runner):
result = runner.invoke(
ape_cli,
["accounts", "import", "--use-mnemonic", ALIAS],
input="\n".join([f"{INVALID_MNEMONIC}", PASSWORD, PASSWORD]),
input="\n".join([INVALID_MNEMONIC, PASSWORD, PASSWORD]),
)
assert result.exit_code == 1, result.output
assert_failure(
result,
f"Seed phrase can't be imported: Provided words: '{INVALID_MNEMONIC}'"
+ ", are not a valid BIP39 mnemonic phrase!",
)
assert_failure(result, "Seed phrase can't be imported")
assert HIDDEN_MESSAGE in result.output
assert INVALID_MNEMONIC not in result.output


@run_once
Expand Down

0 comments on commit 2240d14

Please sign in to comment.