From ad1ff6f4aa7ec7b749bd24a3cde74337d05d9f6e Mon Sep 17 00:00:00 2001 From: Alex Barnsley <8069294+alexbarnsley@users.noreply.github.com> Date: Wed, 26 Mar 2025 16:35:23 +0000 Subject: [PATCH 1/3] feat: receipts api endpoints --- client/api/receipts.py | 11 +++++++++++ client/client.py | 9 +++++++++ 2 files changed, 20 insertions(+) create mode 100644 client/api/receipts.py 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..df44a54 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: Rounds API + :rtype: client.api.rounds.Rounds + """ + return Receipts(self.connection) + @property def rounds(self): """ From 647b603bebd7a3b233ec53ee1de594cf2abb7f72 Mon Sep 17 00:00:00 2001 From: Alex Barnsley <8069294+alexbarnsley@users.noreply.github.com> Date: Wed, 26 Mar 2025 16:35:29 +0000 Subject: [PATCH 2/3] test --- tests/api/test_receipts.py | 48 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 tests/api/test_receipts.py 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 From c2272888aa08a6c6c7876bebe8e17a6c8e328a51 Mon Sep 17 00:00:00 2001 From: Alex Barnsley <8069294+alexbarnsley@users.noreply.github.com> Date: Wed, 26 Mar 2025 16:48:08 +0000 Subject: [PATCH 3/3] update method docs --- client/client.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/client.py b/client/client.py index df44a54..9de82fd 100644 --- a/client/client.py +++ b/client/client.py @@ -80,8 +80,8 @@ def peers(self): @property def receipts(self): """ - :return: Rounds API - :rtype: client.api.rounds.Rounds + :return: Receipts API + :rtype: client.api.receipts.Receipts """ return Receipts(self.connection)