diff --git a/client/api/receipts.py b/client/api/receipts.py new file mode 100644 index 0000000..64299be --- /dev/null +++ b/client/api/receipts.py @@ -0,0 +1,11 @@ +from client.resource import Resource + + +class Receipts(Resource): + def all(self, **kwargs): + return self.with_endpoint('api').request_get('receipts', kwargs) + + def get(self, transaction_hash: str): + return self.with_endpoint('api').request_get('receipts', { + 'txHash': transaction_hash, + }) diff --git a/client/client.py b/client/client.py index 079948a..9de82fd 100644 --- a/client/client.py +++ b/client/client.py @@ -1,4 +1,5 @@ from typing import Union +from client.api.receipts import Receipts from client.connection import ClientHosts, Connection from client.api.api_nodes import ApiNodes from client.api.blockchain import Blockchain @@ -76,6 +77,14 @@ def peers(self): """ return Peers(self.connection) + @property + def receipts(self): + """ + :return: Receipts API + :rtype: client.api.receipts.Receipts + """ + return Receipts(self.connection) + @property def rounds(self): """ diff --git a/tests/api/test_receipts.py b/tests/api/test_receipts.py new file mode 100644 index 0000000..bcd88b4 --- /dev/null +++ b/tests/api/test_receipts.py @@ -0,0 +1,48 @@ +import responses +from client import ArkClient + + +def test_all_calls_correct_url(): + responses.add( + responses.GET, + 'http://127.0.0.1:4002/api/receipts', + json={'success': True}, + status=200 + ) + + client = ArkClient('http://127.0.0.1:4002/api') + client.receipts.all() + assert len(responses.calls) == 1 + assert responses.calls[0].request.url == 'http://127.0.0.1:4002/api/receipts' + + +def test_all_calls_correct_url_with_params(): + responses.add( + responses.GET, + 'http://127.0.0.1:4002/api/receipts', + json={'success': True}, + status=200 + ) + + client = ArkClient('http://127.0.0.1:4002/api') + client.receipts.all(query_param1='value1', query_param2='value2') + assert len(responses.calls) == 1 + assert responses.calls[0].request.url.startswith('http://127.0.0.1:4002/api/receipts?') + assert 'query_param1=value1' in responses.calls[0].request.url + assert 'query_param2=value2' in responses.calls[0].request.url + + +def test_get_calls_correct_url(): + transaction_hash = '12345' + responses.add( + responses.GET, + f'http://127.0.0.1:4002/api/receipts?txHash={transaction_hash}', + json={'success': True}, + status=200 + ) + + client = ArkClient('http://127.0.0.1:4002/api') + client.receipts.get(transaction_hash) + assert len(responses.calls) == 1 + assert responses.calls[0].request.url.startswith('http://127.0.0.1:4002/api/receipts?') + assert f'txHash={transaction_hash}' in responses.calls[0].request.url