Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update tx service delegate methods #427

Merged
merged 12 commits into from
Jul 4, 2024
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",
"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.0b31
tabulate==0.9.0
trezor==0.13.8
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,
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,
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_signed = signer.signHash(expected_hash)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
expected_signature_signed = signer.signHash(expected_hash)
expected_signature = signer.signHash(expected_hash)

Looks like a bit redundant signature is supposed to be signed :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you are right. Updated b8f86ad


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_hash = safe_operator.safe_tx_service.create_delegate_message_hash(
delegate_address
)
expected_signature_signed = 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_signed,
safe_address=safe_operator.address,
)

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