Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
11 changes: 11 additions & 0 deletions client/api/receipts.py
Original file line number Diff line number Diff line change
@@ -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,
})
9 changes: 9 additions & 0 deletions client/client.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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):
"""
Expand Down
48 changes: 48 additions & 0 deletions tests/api/test_receipts.py
Original file line number Diff line number Diff line change
@@ -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