Skip to content

Commit ea27117

Browse files
authored
refactor: blocks transactions endpoint wildcard arguments (#131)
1 parent a047d51 commit ea27117

File tree

2 files changed

+4
-24
lines changed

2 files changed

+4
-24
lines changed

client/api/blocks.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,5 @@ def first(self):
2121
def last(self):
2222
return self.with_endpoint('api').request_get('blocks/last')
2323

24-
def transactions(self, block_id, page=None, limit=100):
25-
params = {
26-
'page': page,
27-
'limit': limit,
28-
}
29-
return self.with_endpoint('api').request_get(f'blocks/{block_id}/transactions', params)
24+
def transactions(self, block_id, **kwargs):
25+
return self.with_endpoint('api').request_get(f'blocks/{block_id}/transactions', kwargs)

tests/api/test_blocks.py

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -99,23 +99,6 @@ def test_last_calls_correct_url():
9999
assert responses.calls[0].request.url == 'http://127.0.0.1:4002/api/blocks/last'
100100

101101

102-
def test_transactions_calls_correct_url_with_default_params():
103-
block_id = '12345'
104-
responses.add(
105-
responses.GET,
106-
'http://127.0.0.1:4002/api/blocks/{}/transactions'.format(block_id),
107-
json={'success': True},
108-
status=200
109-
)
110-
111-
client = ArkClient('http://127.0.0.1:4002/api')
112-
client.blocks.transactions(block_id)
113-
assert len(responses.calls) == 1
114-
assert responses.calls[0].request.url == (
115-
'http://127.0.0.1:4002/api/blocks/12345/transactions?limit=100'
116-
)
117-
118-
119102
def test_transactions_calls_correct_url_with_passed_in_params():
120103
block_id = '12345'
121104
responses.add(
@@ -126,10 +109,11 @@ def test_transactions_calls_correct_url_with_passed_in_params():
126109
)
127110

128111
client = ArkClient('http://127.0.0.1:4002/api')
129-
client.blocks.transactions(block_id, page=5, limit=69)
112+
client.blocks.transactions(block_id, page=5, limit=69, orderBy="timestamp.epoch")
130113
assert len(responses.calls) == 1
131114
assert responses.calls[0].request.url.startswith(
132115
'http://127.0.0.1:4002/api/blocks/12345/transactions?'
133116
)
134117
assert 'page=5' in responses.calls[0].request.url
135118
assert 'limit=69' in responses.calls[0].request.url
119+
assert 'orderBy=timestamp.epoch' in responses.calls[0].request.url

0 commit comments

Comments
 (0)