diff --git a/tests/test_safe_operator.py b/tests/test_safe_operator.py index f289a08a..4d20fd60 100644 --- a/tests/test_safe_operator.py +++ b/tests/test_safe_operator.py @@ -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 @@ -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]