Skip to content

Commit

Permalink
Add test_load_ledger_cli_owners
Browse files Browse the repository at this point in the history
  • Loading branch information
moisses89 committed Apr 21, 2023
1 parent 59d0e5a commit 4296029
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions tests/test_safe_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from unittest.mock import MagicMock

from eth_account import Account
from ledgereth.objects import LedgerAccount
from web3 import Web3

from gnosis.eth import EthereumClient
Expand Down Expand Up @@ -71,6 +72,31 @@ def test_load_cli_owner(self, get_contract_mock: MagicMock):
self.assertEqual(len(safe_operator.accounts), number_of_accounts - 1)
self.assertFalse(safe_operator.default_sender)

@mock.patch("safe_cli.operators.safe_operator.get_account_by_path")
def test_load_ledger_cli_owner(self, mock_get_account_by_path: MagicMock):
owner_address = Account.create().address
safe_address = self.deploy_test_safe(owners=[owner_address]).safe_address
safe_operator = SafeOperator(safe_address, self.ethereum_node_url)
safe_operator.load_ledger_cli_owners()
self.assertEqual(len(safe_operator.accounts), 0)

with mock.patch("safe_cli.operators.safe_operator.init_dongle"):
# Test ledger address is not an owner
random_account = Account.create().address
mock_get_account_by_path.return_value = LedgerAccount(
"44'/60'/0'/0/0", random_account
)
safe_operator.load_ledger_cli_owners()
self.assertEqual(len(safe_operator.accounts), 0)

# Test ledger address is an owner
mock_get_account_by_path.return_value = LedgerAccount(
"44'/60'/0'/0/0", owner_address
)
safe_operator.load_ledger_cli_owners()
self.assertEqual(len(safe_operator.accounts), 1)
self.assertEqual(list(safe_operator.accounts)[0].address, owner_address)

def test_approve_hash(self):
safe_address = self.deploy_test_safe(
owners=[self.ethereum_test_account.address]
Expand Down

0 comments on commit 4296029

Please sign in to comment.