From 0e7a96494525eef8a7c3479ccb236722fb15a85b Mon Sep 17 00:00:00 2001 From: moisses89 <7888669+moisses89@users.noreply.github.com> Date: Thu, 26 Oct 2023 15:08:30 +0200 Subject: [PATCH] Add submit signature with ledger --- .../operators/safe_tx_service_operator.py | 10 ++++++++++ tests/test_safe_tx_service_operator.py | 19 +++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/safe_cli/operators/safe_tx_service_operator.py b/safe_cli/operators/safe_tx_service_operator.py index 7465251b..437b88db 100644 --- a/safe_cli/operators/safe_tx_service_operator.py +++ b/safe_cli/operators/safe_tx_service_operator.py @@ -102,6 +102,16 @@ def submit_signatures(self, safe_tx_hash: bytes) -> bool: for account in self.accounts: if account.address in owners: safe_tx.sign(account.key) + # Check if there is ledger signers + if self.ledger_manager: + selected_ledger_accounts = [] + for ledger_account in self.ledger_manager.accounts: + if ledger_account.address in owners: + selected_ledger_accounts.append(ledger_account) + if len(selected_ledger_accounts) > 0: + safe_tx = self.ledger_manager.sign_eip712( + safe_tx, selected_ledger_accounts + ) if safe_tx.signers: self.safe_tx_service.post_signatures(safe_tx_hash, safe_tx.signatures) diff --git a/tests/test_safe_tx_service_operator.py b/tests/test_safe_tx_service_operator.py index d04bebc8..c9d48914 100644 --- a/tests/test_safe_tx_service_operator.py +++ b/tests/test_safe_tx_service_operator.py @@ -4,6 +4,7 @@ from eth_account import Account from hexbytes import HexBytes +from ledgereth.objects import LedgerAccount from web3 import Web3 from gnosis.eth import EthereumClient @@ -134,6 +135,24 @@ def test_submit_signatures( get_safe_transaction_mock.return_value = GetMultisigTxRequestMock(executed=True) self.assertFalse(safe_operator.submit_signatures(safe_tx_hash)) + # Test ledger signers + with mock.patch.object( + SafeTx, "signers", return_value=["signer"], new_callable=mock.PropertyMock + ) as mock_safe_tx: + safe_operator.ledger_manager.sign_eip712 = MagicMock( + return_value=mock_safe_tx + ) + get_safe_transaction_mock.return_value = GetMultisigTxRequestMock( + executed=False + ) + safe_operator.ledger_manager.accounts.add( + LedgerAccount("44'/60'/0'/0", Account.create().address) + ) + get_permitted_signers_mock.return_value = { + list(safe_operator.ledger_manager.accounts)[0].address + } + self.assertTrue(safe_operator.submit_signatures(safe_tx_hash)) + @mock.patch.object(TransactionServiceApi, "post_transaction", return_value=True) @mock.patch.object( SafeTx, "safe_version", return_value="1.4.1", new_callable=mock.PropertyMock