Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: allow working without connection #24

Merged
merged 2 commits into from
May 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion ape_ledger/accounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ def alias(self) -> str:

@property
def address(self) -> AddressType:
return self.provider.network.ecosystem.decode_address(self.account_file["address"])
ecosystem = self.network_manager.get_ecosystem("ethereum")
return ecosystem.decode_address(self.account_file["address"])

@property
def hdpath(self) -> HDAccountPath:
Expand Down
21 changes: 4 additions & 17 deletions tests/test_integration.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import pytest
from ape import accounts
from ape._cli import cli
from ape.managers.accounts import AccountManager

from ape_ledger import LedgerAccount
from ape_ledger.hdpath import HDBasePath

from .conftest import TEST_ADDRESS, TEST_HD_PATH, assert_account
Expand All @@ -17,16 +15,6 @@ def _get_container():
TEST_ACCOUNT_PATH = _get_container().data_folder.joinpath(f"{TEST_ALIAS}.json")


@pytest.fixture
def mock_account_manager(mocker):
return mocker.MagicMock(spec=AccountManager)


@pytest.fixture
def mock_account(mocker):
return mocker.MagicMock(spec=LedgerAccount)


@pytest.fixture
def mock_device_connection(mocker, mock_ethereum_app):
patch = mocker.patch("ape_ledger._cli.connect_to_ethereum_app")
Expand Down Expand Up @@ -61,8 +49,9 @@ def _get_account_path(alias=TEST_ALIAS):
return container.data_folder.joinpath(f"{alias}.json")


def test_list(runner, existing_account):
result = runner.invoke(cli, ["ledger", "list"])
@pytest.mark.parametrize("cmd", (["ledger", "list"], ["accounts", "list", "--all"]))
def test_list(runner, existing_account, cmd):
result = runner.invoke(cli, cmd)
assert result.exit_code == 0, result.output
assert TEST_ALIAS in result.output
assert TEST_ADDRESS.lower() in result.output.lower()
Expand All @@ -83,9 +72,7 @@ def test_add(runner, mock_device_connection):
assert_account(expected_path, expected_hdpath=expected_hd_path)


def test_add_when_hd_path_specified(
runner, mock_ethereum_app, mock_device_connection, mock_account
):
def test_add_when_hd_path_specified(runner, mock_ethereum_app, mock_device_connection):
test_hd_path = "m/44'/60'/0'"
mock_ethereum_app.hd_root_path = HDBasePath(test_hd_path)

Expand Down