Skip to content

Commit

Permalink
Update tx service delegate methods (#427)
Browse files Browse the repository at this point in the history
* Update tx service delegate methods

* Update var name

Co-authored-by: Moisés  <7888669+moisses89@users.noreply.github.com>

* Update var name

Co-authored-by: Moisés  <7888669+moisses89@users.noreply.github.com>

* Update test var names

* Apply PR suggestion

* Fix bug with signature

* Update safe-eth-py version

* Fix test

---------

Co-authored-by: Moisés <7888669+moisses89@users.noreply.github.com>
  • Loading branch information
falvaradorodriguez and moisses89 authored Jul 4, 2024
1 parent 0f3a244 commit 8303420
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.0b32",
"tabulate>=0.8",
"typer==0.12.3",
]
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.0b32
tabulate==0.9.0
trezor==0.13.9
typer==0.12.3
Expand Down
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 @@ -156,8 +156,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.signature,
safe_address=self.address,
)
return True
except SafeAPIException:
Expand All @@ -174,8 +182,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.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_hash = safe_operator.safe_tx_service.create_delegate_message_hash(
delegate_address
)
expected_signature = signer.signHash(expected_hash)

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.signature,
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_hash = safe_operator.safe_tx_service.create_delegate_message_hash(
delegate_address
)
expected_signature = signer.signHash(expected_hash)

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.signature,
safe_address=safe_operator.address,
)

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

0 comments on commit 8303420

Please sign in to comment.