Skip to content

Commit

Permalink
Update tx service delegate methods
Browse files Browse the repository at this point in the history
  • Loading branch information
falvaradorodriguez committed Jun 26, 2024
1 parent a9427b2 commit 82ef773
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 6 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ dependencies = [
"prompt_toolkit>=3",
"pygments>=2",
"requests>=2",
"safe-eth-py==6.0.0b30",
"safe-eth-py==6.0.0b31",
"tabulate>=0.8",
]

Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ packaging>=23.1
prompt_toolkit==3.0.47
pygments==2.18.0
requests==2.32.3
safe-eth-py==6.0.0b30
safe-eth-py==6.0.0b31
tabulate==0.9.0
trezor==0.13.8
web3==6.19.0
19 changes: 17 additions & 2 deletions src/safe_cli/operators/safe_tx_service_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,16 @@ def add_delegate(self, delegate_address: str, label: str, signer_address: str):
else:
signer_account = signer_account[0]
try:
hash_to_sign = self.safe_tx_service.create_delegate_message_hash(
delegate_address
)
signature = signer_account.signHash(hash_to_sign)
self.safe_tx_service.add_delegate(
self.address, delegate_address, label, signer_account
delegate_address,
signer_account.address,
label,
signature,
safe_address=self.address,
)
return True
except SafeAPIException:
Expand All @@ -176,8 +184,15 @@ def remove_delegate(self, delegate_address: str, signer_address: str):
else:
signer_account = signer_account[0]
try:
hash_to_sign = self.safe_tx_service.create_delegate_message_hash(
delegate_address
)
signature = signer_account.signHash(hash_to_sign)
self.safe_tx_service.remove_delegate(
self.address, delegate_address, signer_account
delegate_address,
signer_account.address,
signature,
safe_address=self.address,
)
return True
except SafeAPIException:
Expand Down
24 changes: 22 additions & 2 deletions tests/test_safe_tx_service_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,21 @@ def test_add_delegate(self, add_delegate_mock: MagicMock):
delegate_address = Account.create().address
label = "Test"
signer = list(safe_operator.accounts)[0]

expected_signature = safe_operator.safe_tx_service.create_delegate_message_hash(
delegate_address
)
expected_signature_signed = signer.signHash(expected_signature)

self.assertTrue(
safe_operator.add_delegate(delegate_address, label, signer.address)
)
add_delegate_mock.assert_called_with(
safe_operator.address, delegate_address, label, signer
delegate_address,
signer.address,
label,
expected_signature_signed,
safe_address=safe_operator.address,
)

@mock.patch.object(TransactionServiceApi, "remove_delegate", return_value=None)
Expand All @@ -94,9 +104,19 @@ def test_remove_delegate(self, remove_delegate_mock: MagicMock):
)
delegate_address = Account.create().address
signer = list(safe_operator.accounts)[0]

expected_signature = safe_operator.safe_tx_service.create_delegate_message_hash(
delegate_address
)
expected_signature_signed = signer.signHash(expected_signature)

self.assertTrue(safe_operator.remove_delegate(delegate_address, signer.address))

remove_delegate_mock.assert_called_with(
safe_operator.address, delegate_address, signer
delegate_address,
signer.address,
expected_signature_signed,
safe_address=safe_operator.address,
)

@mock.patch.object(TransactionServiceApi, "delete_transaction", return_value=None)
Expand Down

0 comments on commit 82ef773

Please sign in to comment.