Skip to content

Commit 95090e8

Browse files
authored
feat: receipts api endpoints (#129)
1 parent 7f3f398 commit 95090e8

File tree

3 files changed

+68
-0
lines changed

3 files changed

+68
-0
lines changed

client/api/receipts.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from client.resource import Resource
2+
3+
4+
class Receipts(Resource):
5+
def all(self, **kwargs):
6+
return self.with_endpoint('api').request_get('receipts', kwargs)
7+
8+
def get(self, transaction_hash: str):
9+
return self.with_endpoint('api').request_get('receipts', {
10+
'txHash': transaction_hash,
11+
})

client/client.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from typing import Union
2+
from client.api.receipts import Receipts
23
from client.connection import ClientHosts, Connection
34
from client.api.api_nodes import ApiNodes
45
from client.api.blockchain import Blockchain
@@ -76,6 +77,14 @@ def peers(self):
7677
"""
7778
return Peers(self.connection)
7879

80+
@property
81+
def receipts(self):
82+
"""
83+
:return: Receipts API
84+
:rtype: client.api.receipts.Receipts
85+
"""
86+
return Receipts(self.connection)
87+
7988
@property
8089
def rounds(self):
8190
"""

tests/api/test_receipts.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import responses
2+
from client import ArkClient
3+
4+
5+
def test_all_calls_correct_url():
6+
responses.add(
7+
responses.GET,
8+
'http://127.0.0.1:4002/api/receipts',
9+
json={'success': True},
10+
status=200
11+
)
12+
13+
client = ArkClient('http://127.0.0.1:4002/api')
14+
client.receipts.all()
15+
assert len(responses.calls) == 1
16+
assert responses.calls[0].request.url == 'http://127.0.0.1:4002/api/receipts'
17+
18+
19+
def test_all_calls_correct_url_with_params():
20+
responses.add(
21+
responses.GET,
22+
'http://127.0.0.1:4002/api/receipts',
23+
json={'success': True},
24+
status=200
25+
)
26+
27+
client = ArkClient('http://127.0.0.1:4002/api')
28+
client.receipts.all(query_param1='value1', query_param2='value2')
29+
assert len(responses.calls) == 1
30+
assert responses.calls[0].request.url.startswith('http://127.0.0.1:4002/api/receipts?')
31+
assert 'query_param1=value1' in responses.calls[0].request.url
32+
assert 'query_param2=value2' in responses.calls[0].request.url
33+
34+
35+
def test_get_calls_correct_url():
36+
transaction_hash = '12345'
37+
responses.add(
38+
responses.GET,
39+
f'http://127.0.0.1:4002/api/receipts?txHash={transaction_hash}',
40+
json={'success': True},
41+
status=200
42+
)
43+
44+
client = ArkClient('http://127.0.0.1:4002/api')
45+
client.receipts.get(transaction_hash)
46+
assert len(responses.calls) == 1
47+
assert responses.calls[0].request.url.startswith('http://127.0.0.1:4002/api/receipts?')
48+
assert f'txHash={transaction_hash}' in responses.calls[0].request.url

0 commit comments

Comments
 (0)