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

Allow query params to get_transactions api method #978

Merged
merged 3 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import logging
import os
from typing import Any, Dict, List, Optional, Tuple, Union
from urllib.parse import urlencode

from eth_account.signers.local import LocalAccount
from eth_typing import ChecksumAddress, HexStr
Expand Down Expand Up @@ -168,15 +169,23 @@ def get_safe_transaction(
safe_tx.tx_hash = tx_hash
return safe_tx, tx_hash

def get_transactions(self, safe_address: ChecksumAddress) -> List[Dict[str, Any]]:
def get_transactions(
self, safe_address: ChecksumAddress, **kwargs: Union[str, int, bool]
falvaradorodriguez marked this conversation as resolved.
Show resolved Hide resolved
) -> List[Dict[str, Any]]:
"""

:param safe_address:
:return: a list of transactions for provided Safe
"""
response = self._get_request(
f"/api/v1/safes/{safe_address}/multisig-transactions/"
)
url = f"/api/v1/safes/{safe_address}/multisig-transactions/"

if kwargs:
query_string = urlencode(
{key: f"{value}" for key, value in kwargs.items() if value is not None}
Copy link
Member

Choose a reason for hiding this comment

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

No strong preference but str(value) might look more clear? I don't know

)
url += "?" + query_string

response = self._get_request(url)
if not response.ok:
raise SafeAPIException(f"Cannot get transactions: {response.content}")
return response.json().get("results", [])
Expand Down
9 changes: 9 additions & 0 deletions gnosis/safe/tests/api/test_transaction_service_api.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from unittest import mock
from unittest.mock import patch

from django.test import TestCase

Expand Down Expand Up @@ -104,6 +105,14 @@ def test_get_transactions(self):
self.assertIsInstance(transactions, list)
self.assertEqual(len(transactions), 6)

with patch.object(TransactionServiceApi, "_get_request") as mock_get_request:
self.transaction_service_api.get_transactions(
self.safe_address, limit=2, nonce__lt=30, failed=False
)

expected_url = f"/api/v1/safes/{self.safe_address}/multisig-transactions/?limit=2&nonce__lt=30&failed=False"
mock_get_request.assert_called_once_with(expected_url)

def test_get_safes_for_owner(self):
owner_address = "0x3066786706Ff0B6e71044e55074dBAE7D01573cB"
safes = self.transaction_service_api.get_safes_for_owner(owner_address)
Expand Down
Loading