Skip to content

Commit

Permalink
test: fix tests (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
antazoey authored Oct 2, 2023
1 parent 0444aa4 commit 73b0363
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 22 deletions.
10 changes: 5 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.2.0
rev: v4.4.0
hooks:
- id: check-yaml

Expand All @@ -10,24 +10,24 @@ repos:
- id: isort

- repo: https://github.com/psf/black
rev: 23.3.0
rev: 23.9.1
hooks:
- id: black
name: black

- repo: https://github.com/pycqa/flake8
rev: 6.0.0
rev: 6.1.0
hooks:
- id: flake8

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.991
rev: v1.5.1
hooks:
- id: mypy
additional_dependencies: [types-setuptools, pydantic]

- repo: https://github.com/executablebooks/mdformat
rev: 0.7.14
rev: 0.7.17
hooks:
- id: mdformat
additional_dependencies: [mdformat-gfm, mdformat-frontmatter]
Expand Down
6 changes: 3 additions & 3 deletions ape_ledger/_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def add(cli_ctx, alias, hd_path):
"""Add an account from your Ledger hardware wallet"""

address, account_hd_path = _select_account(hd_path)
container = accounts.containers.get("ledger")
container = accounts.containers["ledger"]
container.save_account(alias, address, str(account_hd_path))
cli_ctx.logger.success(f"Account '{address}' successfully added with alias '{alias}'.")

Expand All @@ -83,7 +83,7 @@ def add(cli_ctx, alias, hd_path):
def delete(cli_ctx, alias):
"""Remove a Ledger account from ape"""

container = accounts.containers.get("ledger")
container = accounts.containers["ledger"]
container.delete_account(alias)
cli_ctx.logger.success(f"Account '{alias}' has been removed.")

Expand All @@ -94,7 +94,7 @@ def delete(cli_ctx, alias):
def delete_all(cli_ctx, skip_confirmation):
"""Remove all Ledger accounts from ape"""

container = accounts.containers.get("ledger")
container = accounts.containers["ledger"]
ledger_accounts = _get_ledger_accounts()
if len(ledger_accounts) == 0:
cli_ctx.logger.warning("No accounts found.")
Expand Down
4 changes: 1 addition & 3 deletions ape_ledger/accounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,7 @@ def save_account(self, alias: str, address: str, hd_path: str):

def delete_account(self, alias: str):
path = self.data_folder.joinpath(f"{alias}.json")

if path.exists():
path.unlink()
path.unlink(missing_ok=True)


def _echo_object_to_sign(obj: Union[TransactionAPI, SignableMessage]):
Expand Down
5 changes: 3 additions & 2 deletions ape_ledger/choices.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def __init__(
self._hd_root_path = hd_path
self._index_offset = index_offset
self._page_size = page_size
self._choice_index = None
self._choice_index: Optional[int] = None

# Must call ``_load_choices()`` to set address choices
super().__init__([])
Expand All @@ -54,7 +54,8 @@ def convert(
return None

address = super().convert(value, param, ctx)
self._choice_index = self.choices.index(address)
address_index = self.choices.index(address)
self._choice_index = self._choice_index if address_index is None else address_index
return address

def get_user_selected_account(self) -> Tuple[str, HDAccountPath]:
Expand Down
9 changes: 5 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@
"hypothesis>=6.2.0,<7.0", # Strategy-based fuzzer
],
"lint": [
"black>=23.3.0,<24", # auto-formatter and linter
"mypy>=0.991,<1", # Static type analyzer
"black>=23.9.1,<24", # auto-formatter and linter
"mypy>=1.5.1,<2", # Static type analyzer
"types-setuptools", # Needed due to mypy typeshed
"flake8>=6.0.0,<7", # Style linter
"flake8>=6.1.0,<7", # Style linter
"isort>=5.10.1,<6", # Import sorting linter
"mdformat>=0.7.16", # Auto-formatter for markdown
"mdformat>=0.7.17", # Auto-formatter for markdown
"mdformat-gfm>=0.3.5", # Needed for formatting GitHub-flavored markdown
"mdformat-frontmatter>=0.4.1", # Needed for frontmatters-style headers in issue templates
"pydantic<2.0", # Needed for successful type check. TODO: Remove after full v2 support.
],
"release": [ # `release` GitHub Action job uses this
"setuptools", # Installation tool
Expand Down
11 changes: 6 additions & 5 deletions tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def test_add(runner, assert_account, address, alias, choices, hd_path):
choices(address, 2)
result = runner.invoke(cli, ["ledger", "add", alias])
assert result.exit_code == 0, result.output
assert f"SUCCESS: Account '{address}' successfully added with alias '{alias}'." in result.output
assert f"Account '{address}' successfully added with alias '{alias}'." in result.output

expected_path = container.data_folder.joinpath(f"{alias}.json")
expected_hd_path = "m/44'/60'/2'/0/0"
Expand All @@ -93,7 +93,7 @@ def test_add_when_hd_path_specified(runner, alias, address, hd_path, assert_acco
["ledger", "add", alias, "--hd-path", test_hd_path],
)
assert result.exit_code == 0, result.output
assert f"SUCCESS: Account '{address}' successfully added with alias '{alias}'." in result.output
assert f"Account '{address}' successfully added with alias '{alias}'." in result.output

expected_path = container.data_folder.joinpath(f"{alias}.json")
expected_hd_path = "m/44'/60'/0'/2"
Expand All @@ -117,10 +117,11 @@ def test_add_alias_already_exists(runner, existing_account, choices, address, al
def test_delete(runner, existing_account, alias):
result = runner.invoke(cli, ["ledger", "delete", alias])
assert result.exit_code == 0, result.output
assert f"SUCCESS: Account '{alias}' has been removed" in result.output
assert f"Account '{alias}' has been removed" in result.output


def test_delete_account_not_exists(runner, alias):
result = runner.invoke(cli, ["ledger", "delete", alias])
not_alias = f"{alias}TYPO"
result = runner.invoke(cli, ["ledger", "delete", not_alias])
assert result.exit_code == 2
assert f"'{alias}' is not one of" in result.output
assert f"'{not_alias}'" in result.output

0 comments on commit 73b0363

Please sign in to comment.