Skip to content

Commit

Permalink
Add PR review suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
moisses89 committed Dec 12, 2023
1 parent 63c3481 commit 019feca
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 30 deletions.
10 changes: 1 addition & 9 deletions safe_cli/operators/hw_wallets/hw_wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,8 @@ def sign_typed_hash(self, domain_hash: bytes, message_hash: bytes) -> bytes:
:return: signature bytes
"""

@abstractmethod
def print_type(self) -> str:
"""
:return: str represantation of wallet type
"""
pass

def __str__(self):
return f"{self.print_type()} device with address {self.address}"
return f"{self.__class__.__name__} device with address {self.address}"

def __eq__(self, other):
if isinstance(other, HwWallet):
Expand Down
6 changes: 3 additions & 3 deletions safe_cli/operators/hw_wallets/hw_wallet_manager.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from enum import Enum
from functools import cache
from functools import lru_cache
from typing import Dict, List, Optional, Set, Tuple

from eth_typing import ChecksumAddress
Expand All @@ -16,7 +16,7 @@ class HwWalletType(Enum):
LEDGER = 1


@cache
@lru_cache(maxsize=None)
def get_hw_wallet_manager():
return HwWalletManager()

Expand Down Expand Up @@ -51,7 +51,7 @@ def get_accounts(
hw_wallet_type: HwWalletType,
legacy_account: Optional[bool] = False,
number_accounts: Optional[int] = 5,
) -> Tuple[ChecksumAddress, str]:
) -> List[Tuple[ChecksumAddress, str]]:
"""
:param hw_wallet: Trezor or Ledger
Expand Down
7 changes: 0 additions & 7 deletions safe_cli/operators/hw_wallets/ledger_wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,3 @@ def sign_typed_hash(self, domain_hash: bytes, message_hash: bytes) -> bytes:
)

return signature_to_bytes(signed.v, signed.r, signed.s)

def print_type(self) -> str:
"""
:return: str represantation of wallet type
"""
return "Ledger"
7 changes: 0 additions & 7 deletions safe_cli/operators/hw_wallets/trezor_wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,3 @@ def sign_typed_hash(self, domain_hash: bytes, message_hash: bytes) -> bytes:
self.client, n=address_n, domain_hash=domain_hash, message_hash=message_hash
)
return signed.signature

def print_type(self) -> str:
"""
:return: str represantation of wallet type
"""
return "Ledger"
13 changes: 9 additions & 4 deletions tests/test_hw_wallet_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,22 @@
from safe_cli.operators.hw_wallets.hw_wallet_manager import (
HwWalletManager,
HwWalletType,
get_hw_wallet_manager,
)
from safe_cli.operators.hw_wallets.ledger_wallet import LedgerWallet


class Testledger_wallet(SafeTestCaseMixin, unittest.TestCase):
def test_setup_hw_wallet_manager(self):
# Should support Treezor and Ledger
hw_acccount_manager = HwWalletManager()
self.assertTrue(hw_acccount_manager.is_supported_hw_wallet(HwWalletType.TREZOR))
self.assertTrue(hw_acccount_manager.is_supported_hw_wallet(HwWalletType.LEDGER))
self.assertEqual(len(hw_acccount_manager.wallets), 0)
hw_wallet_manager = get_hw_wallet_manager()
self.assertTrue(hw_wallet_manager.is_supported_hw_wallet(HwWalletType.TREZOR))
self.assertTrue(hw_wallet_manager.is_supported_hw_wallet(HwWalletType.LEDGER))
self.assertEqual(len(hw_wallet_manager.wallets), 0)

# Should get the same instance
other_hw_wallet_manager = get_hw_wallet_manager()
self.assertEqual(other_hw_wallet_manager, hw_wallet_manager)

@mock.patch(
"safe_cli.operators.hw_wallets.ledger_wallet.init_dongle",
Expand Down

0 comments on commit 019feca

Please sign in to comment.