diff --git a/client/api/api_nodes.py b/client/api/api_nodes.py index f4fca6a..4948c06 100644 --- a/client/api/api_nodes.py +++ b/client/api/api_nodes.py @@ -1,7 +1,10 @@ +from typing import Optional + from client.resource import Resource +from client.types.api_nodes import ApiNodesQuery class ApiNodes(Resource): - def all(self, query={}): + def all(self, query: Optional[ApiNodesQuery] = None): return self.with_endpoint('api').request_get('api-nodes', query) diff --git a/client/api/blocks.py b/client/api/blocks.py index 2203f5b..a8cf6e1 100644 --- a/client/api/blocks.py +++ b/client/api/blocks.py @@ -1,13 +1,16 @@ +from typing import Optional + from client.resource import Resource +from client.types.blocks import BlockTransactionsQuery, BlocksQuery class Blocks(Resource): - def all(self, query={}): + def all(self, query: Optional[BlocksQuery] = None): return self.with_endpoint('api').request_get('blocks', query) - def get(self, block_id): - return self.with_endpoint('api').request_get(f'blocks/{block_id}') + def get(self, block_hash: str): + return self.with_endpoint('api').request_get(f'blocks/{block_hash}') def first(self): return self.with_endpoint('api').request_get('blocks/first') @@ -15,7 +18,11 @@ def first(self): def last(self): return self.with_endpoint('api').request_get('blocks/last') - def transactions(self, block_id, query={}): + def transactions( + self, + block_hash: str, + query: Optional[BlockTransactionsQuery] = None, + ): return self.with_endpoint('api').request_get( - f'blocks/{block_id}/transactions', query + f'blocks/{block_hash}/transactions', query ) diff --git a/client/api/commits.py b/client/api/commits.py index b94206c..3a98e26 100644 --- a/client/api/commits.py +++ b/client/api/commits.py @@ -3,5 +3,5 @@ class Commits(Resource): - def show(self, block_number): - return self.with_endpoint('api').request_get(f'commits/{block_number}') + def get(self, height: int): + return self.with_endpoint('api').request_get(f'commits/{height}') diff --git a/client/api/evm.py b/client/api/evm.py index 9386134..c8189c3 100644 --- a/client/api/evm.py +++ b/client/api/evm.py @@ -1,10 +1,10 @@ -from typing import Any from client.resource import Resource +from client.types.evm import EvmBodyPartialParams class EVM(Resource): - def call(self, params: dict[str, Any]): + def call(self, payload: EvmBodyPartialParams): return self.with_endpoint('evm').request_post('', { 'jsonrpc': "2.0", - **params, + **payload, }) diff --git a/client/api/node.py b/client/api/node.py index 9bb0304..c0b6fb8 100644 --- a/client/api/node.py +++ b/client/api/node.py @@ -1,4 +1,7 @@ +from typing import Optional + from client.resource import Resource +from client.types.node import NodeFeesQuery class Node(Resource): @@ -19,5 +22,5 @@ def crypto(self): 'node/configuration/crypto' ) - def fees(self, query={}): + def fees(self, query: Optional[NodeFeesQuery] = None): return self.with_endpoint('api').request_get('node/fees', query) diff --git a/client/api/peers.py b/client/api/peers.py index 17c9389..7d660da 100644 --- a/client/api/peers.py +++ b/client/api/peers.py @@ -1,10 +1,13 @@ +from typing import Optional + from client.resource import Resource +from client.types.peers import PeersQuery class Peers(Resource): - def all(self, query={}): + def all(self, query: Optional[PeersQuery] = None): return self.with_endpoint('api').request_get('peers', query) - def get(self, ip): + def get(self, ip: str): return self.with_endpoint('api').request_get(f'peers/{ip}') diff --git a/client/api/receipts.py b/client/api/receipts.py index 903585a..73944fa 100644 --- a/client/api/receipts.py +++ b/client/api/receipts.py @@ -1,11 +1,23 @@ +from typing import Optional + from client.resource import Resource +from client.types.receipts import ReceiptContractsQuery, ReceiptQuery, ReceiptsQuery class Receipts(Resource): - def all(self, query={}): + def all(self, query: Optional[ReceiptsQuery] = None): return self.with_endpoint('api').request_get('receipts', query) - def get(self, transaction_hash: str): + def get( + self, + transaction_hash: str, + query: Optional[ReceiptQuery] = None, + ): + return self.with_endpoint('api').request_get( + f'receipts/{transaction_hash}', query + ) + + def contracts(self, query: Optional[ReceiptContractsQuery] = None): return self.with_endpoint('api').request_get( - f'receipts/{transaction_hash}' + 'receipts/contracts', query ) diff --git a/client/api/rounds.py b/client/api/rounds.py index 53ba93f..143dcf9 100644 --- a/client/api/rounds.py +++ b/client/api/rounds.py @@ -1,15 +1,18 @@ +from typing import Optional + from client.resource import Resource +from client.types import PaginatedQuery class Rounds(Resource): - def all(self, query={}): + def all(self, query: Optional[PaginatedQuery] = None): return self.with_endpoint('api').request_get('rounds', query) - def show(self, round_id): + def show(self, round_id: str): return self.with_endpoint('api').request_get(f'rounds/{round_id}') - def validators(self, round_id): + def validators(self, round_id: str): return self.with_endpoint('api').request_get( f'rounds/{round_id}/validators' ) diff --git a/client/api/tokens.py b/client/api/tokens.py index 6ee33ad..e8c38e5 100644 --- a/client/api/tokens.py +++ b/client/api/tokens.py @@ -1,27 +1,54 @@ +from typing import Optional + from client.resource import Resource +from client.types import PaginatedQuery +from client.types.tokens import TokenApprovalsQuery, TokenLookupQuery, TokenTransfersQuery, TokensQuery class Tokens(Resource): - def all(self, query={}): + def all(self, query: Optional[TokensQuery] = None): return self.with_endpoint('api').request_get('tokens', query) - def get(self, address): + def transfers(self, query: Optional[TokenTransfersQuery] = None): return self.with_endpoint('api').request_get( - f'tokens/{address}' + 'tokens/transfers', query + ) + + def approvals(self, query: Optional[TokenApprovalsQuery] = None): + return self.with_endpoint('api').request_get( + 'tokens/approvals', query + ) + + def whitelist(self, query: Optional[PaginatedQuery] = None): + return self.with_endpoint('api').request_get( + 'tokens/whitelist', query ) - def holders(self, address, query={}): + def get(self, address: str): return self.with_endpoint('api').request_get( - f'tokens/{address}/holders', query + f'tokens/{address}' ) - def transfers_by_token(self, address, query={}): + def transfers_for( + self, + address: str, + query: Optional[TokenLookupQuery] = None, + ): return self.with_endpoint('api').request_get( f'tokens/{address}/transfers', query ) - def transfers(self, query={}): + def approvals_for( + self, + address: str, + query: Optional[TokenLookupQuery] = None, + ): return self.with_endpoint('api').request_get( - 'tokens/transfers', query + f'tokens/{address}/approvals', query + ) + + def holders_for(self, address: str): + return self.with_endpoint('api').request_get( + f'tokens/{address}/holders' ) diff --git a/client/api/transactions.py b/client/api/transactions.py index 7587a19..ee2cb30 100644 --- a/client/api/transactions.py +++ b/client/api/transactions.py @@ -1,30 +1,40 @@ +from typing import Optional, Sequence + from client.resource import Resource +from client.types.transactions import TransactionGetQuery, TransactionsQuery, UnconfirmedTransactionsQuery class Transactions(Resource): - def all(self, query={}): + def all(self, query: Optional[TransactionsQuery] = None): return self.with_endpoint('api').request_get( 'transactions', query ) - def create(self, transactions): + def create(self, transactions: Sequence[str]): return self.with_endpoint('transactions').request_post( 'transactions', data={'transactions': transactions} ) - def get(self, transaction_id): + def get( + self, + transaction_id: str, + query: Optional[TransactionGetQuery] = None, + ): return self.with_endpoint('api').request_get( - f'transactions/{transaction_id}' + f'transactions/{transaction_id}', query ) - def all_unconfirmed(self, query={}): - return self.with_endpoint('api').request_get( + def all_unconfirmed( + self, + query: Optional[UnconfirmedTransactionsQuery] = None, + ): + return self.with_endpoint('transactions').request_get( 'transactions/unconfirmed', query ) - def get_unconfirmed(self, transaction_id): - return self.with_endpoint('api').request_get( + def get_unconfirmed(self, transaction_id: str): + return self.with_endpoint('transactions').request_get( f'transactions/unconfirmed/{transaction_id}' ) diff --git a/client/api/validators.py b/client/api/validators.py index eed26ab..009c677 100644 --- a/client/api/validators.py +++ b/client/api/validators.py @@ -1,22 +1,35 @@ +from typing import Optional + +from client.api.blocks import BlocksQuery +from client.api.wallets import WalletsQuery from client.resource import Resource +from client.types.validators import ValidatorsQuery class Validators(Resource): - def all(self, query={}): + def all(self, query: Optional[ValidatorsQuery] = None): return self.with_endpoint('api').request_get('validators', query) - def get(self, validator_id): + def get(self, validator_id: str): return self.with_endpoint('api').request_get( f'validators/{validator_id}' ) - def blocks(self, validator_id, query={}): + def blocks( + self, + validator_id: str, + query: Optional[BlocksQuery] = None, + ): return self.with_endpoint('api').request_get( f'validators/{validator_id}/blocks', query ) - def voters(self, validator_id, query={}): + def voters( + self, + validator_id: str, + query: Optional[WalletsQuery] = None, + ): return self.with_endpoint('api').request_get( f'validators/{validator_id}/voters', query ) diff --git a/client/api/votes.py b/client/api/votes.py index 4bc7632..4c8c73a 100644 --- a/client/api/votes.py +++ b/client/api/votes.py @@ -1,10 +1,13 @@ +from typing import Optional + from client.resource import Resource +from client.types.votes import VoteQuery, VotesQuery class Votes(Resource): - def all(self, query={}): + def all(self, query: Optional[VotesQuery] = None): return self.with_endpoint('api').request_get('votes', query) - def get(self, vote_id): - return self.with_endpoint('api').request_get(f'votes/{vote_id}') + def get(self, vote_id: str, query: Optional[VoteQuery] = None): + return self.with_endpoint('api').request_get(f'votes/{vote_id}', query) diff --git a/client/api/wallets.py b/client/api/wallets.py index b070ec3..26c5def 100644 --- a/client/api/wallets.py +++ b/client/api/wallets.py @@ -1,45 +1,69 @@ +from typing import Optional + from client.resource import Resource +from client.types.transactions import TransactionsQuery +from client.types.wallets import WalletTokensForQuery, WalletTokensQuery, WalletsQuery class Wallets(Resource): - def all(self, query={}): + def all(self, query: Optional[WalletsQuery] = None): return self.with_endpoint('api').request_get('wallets', query) - def top(self, query={}): + def top(self, query: Optional[WalletsQuery] = None): return self.with_endpoint('api').request_get('wallets/top', query) - def get(self, wallet_id): + def get(self, wallet_id: str): return self.with_endpoint('api').request_get( f'wallets/{wallet_id}' ) - def transactions(self, wallet_id, query={}): + def transactions( + self, + wallet_id: str, + query: Optional[TransactionsQuery] = None, + ): return self.with_endpoint('api').request_get( f'wallets/{wallet_id}/transactions', query ) - def sent_transactions(self, wallet_id, query={}): + def sent_transactions( + self, + wallet_id: str, + query: Optional[TransactionsQuery] = None, + ): return self.with_endpoint('api').request_get( f'wallets/{wallet_id}/transactions/sent', query ) - def received_transactions(self, wallet_id, query={}): + def received_transactions( + self, + wallet_id: str, + query: Optional[TransactionsQuery] = None, + ): return self.with_endpoint('api').request_get( f'wallets/{wallet_id}/transactions/received', query ) - def votes(self, wallet_id, query={}): + def votes( + self, + wallet_id: str, + query: Optional[TransactionsQuery] = None, + ): return self.with_endpoint('api').request_get( f'wallets/{wallet_id}/votes', query ) - def tokens(self, wallet_id, query={}): + def tokens_for( + self, + address: str, + query: Optional[WalletTokensForQuery] = None, + ): return self.with_endpoint('api').request_get( - f'wallets/{wallet_id}/tokens', query + f'wallets/{address}/tokens', query ) - def tokens_for(self, query={}): + def tokens(self, query: Optional[WalletTokensQuery] = None): return self.with_endpoint('api').request_get( 'wallets/tokens', query ) diff --git a/client/types/__init__.py b/client/types/__init__.py new file mode 100644 index 0000000..0890872 --- /dev/null +++ b/client/types/__init__.py @@ -0,0 +1,12 @@ +from typing import TypedDict + + +PaginatedQuery = TypedDict( + 'PaginatedQuery', + { + 'page': int, + 'limit': int, + 'offset': int, + }, + total=False, +) diff --git a/client/types/api_nodes.py b/client/types/api_nodes.py new file mode 100644 index 0000000..17579c3 --- /dev/null +++ b/client/types/api_nodes.py @@ -0,0 +1,12 @@ +from typing import TypedDict + + +ApiNodesQuery = TypedDict( + 'ApiNodesQuery', + { + 'ip': str, + 'orderBy': str, + 'version': str, + }, + total=False, +) diff --git a/client/types/blocks.py b/client/types/blocks.py new file mode 100644 index 0000000..046c046 --- /dev/null +++ b/client/types/blocks.py @@ -0,0 +1,32 @@ +from typing import TypedDict + + +BlocksQuery = TypedDict( + 'BlocksQuery', + { + 'page': int, + 'limit': int, + 'offset': int, + 'transform': bool, + 'orderBy': str, + 'id': str, + 'number': int, + 'height.from': int, + 'height.to': int, + 'timestamp': int, + 'timestamp.from': int, + 'timestamp.to': int, + }, + total=False, +) + +BlockTransactionsQuery = TypedDict( + 'BlockTransactionsQuery', + { + 'page': int, + 'limit': int, + 'offset': int, + 'orderBy': str, + }, + total=False, +) diff --git a/client/types/evm.py b/client/types/evm.py new file mode 100644 index 0000000..613188b --- /dev/null +++ b/client/types/evm.py @@ -0,0 +1,17 @@ +from typing import Literal, Optional, TypedDict + + +PayloadData = dict[str, str | int | float] + +BlockParameter = Literal["earliest", "latest", "safe", "finalized", "pending"] + +EvmBodyPartialParams = TypedDict( + 'EvmBodyPartialParams', + { + 'jsonrpc': Optional[str], + 'method': str, + 'params': list[PayloadData] | list[PayloadData | BlockParameter | str], + 'id': Optional[int | float], + }, + total=False, +) diff --git a/client/types/node.py b/client/types/node.py new file mode 100644 index 0000000..3a942fc --- /dev/null +++ b/client/types/node.py @@ -0,0 +1,10 @@ +from typing import TypedDict + + +NodeFeesQuery = TypedDict( + 'NodeFeesQuery', + { + 'days': int, + }, + total=False, +) diff --git a/client/types/peers.py b/client/types/peers.py new file mode 100644 index 0000000..4eb5dd5 --- /dev/null +++ b/client/types/peers.py @@ -0,0 +1,14 @@ +from typing import TypedDict + + +PeersQuery = TypedDict( + 'PeersQuery', + { + 'page': int, + 'limit': int, + 'ip': str, + 'orderBy': str, + 'version': str, + }, + total=False, +) diff --git a/client/types/receipts.py b/client/types/receipts.py new file mode 100644 index 0000000..974fa50 --- /dev/null +++ b/client/types/receipts.py @@ -0,0 +1,39 @@ +from typing import TypedDict + + +ReceiptsQuery = TypedDict( + 'ReceiptsQuery', + { + 'page': int, + 'limit': int, + 'offset': int, + 'from': str, + 'to': str, + 'fullReceipt': bool, + 'includeTokens': bool, + 'transactionHash': str, + }, + total=False, +) + +ReceiptQuery = TypedDict( + 'ReceiptQuery', + { + 'fullReceipt': bool, + 'includeTokens': bool, + }, + total=False, +) + +ReceiptContractsQuery = TypedDict( + 'ReceiptContractsQuery', + { + 'page': int, + 'limit': int, + 'offset': int, + 'from': str, + 'fullReceipt': bool, + 'includeTokens': bool, + }, + total=False, +) diff --git a/client/types/tokens.py b/client/types/tokens.py new file mode 100644 index 0000000..eed242d --- /dev/null +++ b/client/types/tokens.py @@ -0,0 +1,59 @@ +from typing import List, TypedDict + + +TokensQuery = TypedDict( + 'TokensQuery', + { + 'page': int, + 'limit': int, + 'offset': int, + 'ignoreWhitelist': bool, + 'name': str, + 'whitelist': List[str], + }, + total=False, +) + +TokenLookupQuery = TypedDict( + 'TokenLookupQuery', + { + 'page': int, + 'limit': int, + 'offset': int, + 'from': str, + 'to': str, + 'transactionHash': str, + }, + total=False, +) + +TokenTransfersQuery = TypedDict( + 'TokenTransfersQuery', + { + 'page': int, + 'limit': int, + 'offset': int, + 'from': str, + 'to': str, + 'transactionHash': str, + 'addresses': List[str], + 'ignoreWhitelist': bool, + 'whitelist': List[str], + }, + total=False, +) + +TokenApprovalsQuery = TypedDict( + 'TokenApprovalsQuery', + { + 'page': int, + 'limit': int, + 'offset': int, + 'from': str, + 'to': str, + 'transactionHash': str, + 'addresses': List[str], + 'whitelist': List[str], + }, + total=False, +) diff --git a/client/types/transactions.py b/client/types/transactions.py new file mode 100644 index 0000000..53aa2c9 --- /dev/null +++ b/client/types/transactions.py @@ -0,0 +1,54 @@ +from typing import List, TypedDict + + +TransactionsQuery = TypedDict( + 'TransactionsQuery', + { + 'page': int, + 'limit': int, + 'offset': int, + 'address': str, + 'asset': str, + 'blockHash': str, + 'from': str, + 'gasPrice': int, + 'hash': str, + 'nonce': int, + 'senderId': str, + 'senderPublicKey': str, + 'timestamp': int, + 'to': str, + 'transactionIndex': int, + 'value': int, + 'fullReceipt': bool, + 'includeTokens': bool, + 'orderBy': str, + }, + total=False, +) + +UnconfirmedTransactionsQuery = TypedDict( + 'UnconfirmedTransactionsQuery', + { + 'page': int, + 'limit': int, + 'orderBy': str, + }, + total=False, +) + +TransactionGetQuery = TypedDict( + 'TransactionGetQuery', + { + 'fullReceipt': bool, + 'includeTokens': bool, + }, + total=False, +) + +TransactionCreateParams = TypedDict( + 'TransactionCreateParams', + { + 'transactions': List[str], + }, +) diff --git a/client/types/validators.py b/client/types/validators.py new file mode 100644 index 0000000..48c447d --- /dev/null +++ b/client/types/validators.py @@ -0,0 +1,39 @@ +from typing import TypedDict + + +ValidatorsQuery = TypedDict( + 'ValidatorsQuery', + { + 'page': int, + 'limit': int, + 'offset': int, + 'address': str, + 'attributes': str, + 'blocks.last.hash': str, + 'blocks.last.number': int, + 'blocks.produced': int, + 'forged.fees': int, + 'forged.fees.from': int, + 'forged.fees.to': int, + 'forged.rewards': int, + 'forged.rewards.from': int, + 'forged.rewards.to': int, + 'forged.total': int, + 'forged.total.from': int, + 'forged.total.to': int, + 'isResigned': bool, + 'production.approval': int, + 'production.approval.from': int, + 'production.approval.to': int, + 'publicKey': str, + 'rank': int, + 'rank.from': int, + 'rank.to': int, + 'username': str, + 'votes': int, + 'votes.from': int, + 'votes.to': int, + 'orderBy': str, + }, + total=False, +) diff --git a/client/types/votes.py b/client/types/votes.py new file mode 100644 index 0000000..43d1d23 --- /dev/null +++ b/client/types/votes.py @@ -0,0 +1,35 @@ +from typing import TypedDict + + +VotesQuery = TypedDict( + 'VotesQuery', + { + 'page': int, + 'limit': int, + 'offset': int, + 'address': str, + 'blockHash': str, + 'data': str, + 'from': str, + 'gasPrice': int, + 'hash': str, + 'nonce': int, + 'senderId': str, + 'senderPublicKey': str, + 'timestamp': int, + 'to': str, + 'transactionIndex': int, + 'value': int, + 'fullReceipt': bool, + 'orderBy': str, + }, + total=False, +) + +VoteQuery = TypedDict( + 'VoteQuery', + { + 'fullReceipt': bool, + }, + total=False, +) diff --git a/client/types/wallets.py b/client/types/wallets.py new file mode 100644 index 0000000..b9ece9f --- /dev/null +++ b/client/types/wallets.py @@ -0,0 +1,47 @@ +from typing import List, TypedDict + + +WalletsQuery = TypedDict( + 'WalletsQuery', + { + 'page': int, + 'limit': int, + 'offset': int, + 'address': str, + 'publicKey': str, + 'balance': int, + 'balance.from': int, + 'balance.to': int, + 'nonce': int, + 'nonce.from': int, + 'nonce.to': int, + 'attributes': str, + 'orderBy': str, + }, + total=False, +) + +WalletTokensForQuery = TypedDict( + 'WalletTokensForQuery', + { + 'addresses': List[str], + 'ignoreWhitelist': bool, + 'minBalance': int, + 'name': str, + 'whitelist': List[str], + }, + total=False, +) + +WalletTokensQuery = TypedDict( + 'WalletTokensQuery', + { + 'addresses': List[str], + 'ignoreWhitelist': bool, + 'page': int, + 'limit': int, + 'minBalance': int, + 'whitelist': List[str], + }, + total=False, +) diff --git a/tests/api/test_blocks.py b/tests/api/test_blocks.py index 6073d83..da7f8df 100644 --- a/tests/api/test_blocks.py +++ b/tests/api/test_blocks.py @@ -32,7 +32,7 @@ def test_all_calls_correct_url_with_params(): 'page': 5, 'limit': 69, 'orderBy': 'timestamp.epoch', - 'height': 6838329, + 'number': 6838329, }) assert len(responses.calls) == 1 url = responses.calls[0].request.url @@ -40,7 +40,7 @@ def test_all_calls_correct_url_with_params(): assert 'page=5' in url assert 'limit=69' in url assert 'orderBy=timestamp.epoch' in url - assert 'height=6838329' in url + assert 'number=6838329' in url def test_get_calls_correct_url(): diff --git a/tests/api/test_commits.py b/tests/api/test_commits.py index dc50112..28c88e3 100644 --- a/tests/api/test_commits.py +++ b/tests/api/test_commits.py @@ -12,6 +12,6 @@ def test_show_calls_correct_url(): ) client = ArkClient('http://127.0.0.1:4002/api') - client.commits.show(1) + client.commits.get(1) assert len(responses.calls) == 1 assert responses.calls[0].request.url == 'http://127.0.0.1:4002/api/commits/1' diff --git a/tests/api/test_receipts.py b/tests/api/test_receipts.py index c1e20b1..bc16f25 100644 --- a/tests/api/test_receipts.py +++ b/tests/api/test_receipts.py @@ -53,3 +53,52 @@ def test_get_calls_correct_url(): assert responses.calls[0].request.url == ( f'http://127.0.0.1:4002/api/receipts/{transaction_hash}' ) + + +def test_get_calls_correct_url_with_params(): + transaction_hash = '12345' + responses.add( + responses.GET, + f'http://127.0.0.1:4002/api/receipts/{transaction_hash}', + json={'success': True}, + status=200 + ) + + client = ArkClient('http://127.0.0.1:4002/api') + client.receipts.get(transaction_hash, {'format': 'hex'}) + assert len(responses.calls) == 1 + url = responses.calls[0].request.url + assert url.startswith(f'http://127.0.0.1:4002/api/receipts/{transaction_hash}?') + assert 'format=hex' in url + + +def test_contracts_calls_correct_url(): + responses.add( + responses.GET, + 'http://127.0.0.1:4002/api/receipts/contracts', + json={'success': True}, + status=200 + ) + + client = ArkClient('http://127.0.0.1:4002/api') + client.receipts.contracts() + assert len(responses.calls) == 1 + assert responses.calls[0].request.url == ( + 'http://127.0.0.1:4002/api/receipts/contracts' + ) + + +def test_contracts_calls_correct_url_with_params(): + responses.add( + responses.GET, + 'http://127.0.0.1:4002/api/receipts/contracts', + json={'success': True}, + status=200 + ) + + client = ArkClient('http://127.0.0.1:4002/api') + client.receipts.contracts({'status': 'success'}) + assert len(responses.calls) == 1 + url = responses.calls[0].request.url + assert url.startswith('http://127.0.0.1:4002/api/receipts/contracts?') + assert 'status=success' in url diff --git a/tests/api/test_tokens.py b/tests/api/test_tokens.py index 3aa6ec5..7505f96 100644 --- a/tests/api/test_tokens.py +++ b/tests/api/test_tokens.py @@ -53,7 +53,7 @@ def test_get_calls_correct_url(): ) -def test_holders_calls_correct_url(): +def test_holders_for_calls_correct_url(): address = '0x1234567890abcdef' responses.add( responses.GET, @@ -63,65 +63,82 @@ def test_holders_calls_correct_url(): ) client = ArkClient('http://127.0.0.1:4002/api') - client.tokens.holders(address) + client.tokens.holders_for(address) assert len(responses.calls) == 1 assert responses.calls[0].request.url == ( 'http://127.0.0.1:4002/api/tokens/0x1234567890abcdef/holders' ) -def test_holders_calls_correct_url_with_params(): +def test_transfers_for_calls_correct_url(): address = '0x1234567890abcdef' responses.add( responses.GET, - 'http://127.0.0.1:4002/api/tokens/{}/holders'.format(address), + 'http://127.0.0.1:4002/api/tokens/{}/transfers'.format(address), + json={'success': True}, + status=200 + ) + + client = ArkClient('http://127.0.0.1:4002/api') + client.tokens.transfers_for(address) + assert len(responses.calls) == 1 + assert responses.calls[0].request.url == ( + 'http://127.0.0.1:4002/api/tokens/0x1234567890abcdef/transfers' + ) + + +def test_transfers_for_calls_correct_url_with_params(): + address = '0x1234567890abcdef' + responses.add( + responses.GET, + 'http://127.0.0.1:4002/api/tokens/{}/transfers'.format(address), json={'success': True}, status=200 ) client = ArkClient('http://127.0.0.1:4002/api') - client.tokens.holders(address, {'page': 3, 'limit': 50}) + client.tokens.transfers_for(address, {'page': 2, 'limit': 25}) assert len(responses.calls) == 1 url = responses.calls[0].request.url assert url.startswith( - 'http://127.0.0.1:4002/api/tokens/0x1234567890abcdef/holders?' + 'http://127.0.0.1:4002/api/tokens/0x1234567890abcdef/transfers?' ) - assert 'page=3' in url - assert 'limit=50' in url + assert 'page=2' in url + assert 'limit=25' in url -def test_transfers_by_token_calls_correct_url(): +def test_approvals_for_calls_correct_url(): address = '0x1234567890abcdef' responses.add( responses.GET, - 'http://127.0.0.1:4002/api/tokens/{}/transfers'.format(address), + 'http://127.0.0.1:4002/api/tokens/{}/approvals'.format(address), json={'success': True}, status=200 ) client = ArkClient('http://127.0.0.1:4002/api') - client.tokens.transfers_by_token(address) + client.tokens.approvals_for(address) assert len(responses.calls) == 1 assert responses.calls[0].request.url == ( - 'http://127.0.0.1:4002/api/tokens/0x1234567890abcdef/transfers' + 'http://127.0.0.1:4002/api/tokens/0x1234567890abcdef/approvals' ) -def test_transfers_by_token_calls_correct_url_with_params(): +def test_approvals_for_calls_correct_url_with_params(): address = '0x1234567890abcdef' responses.add( responses.GET, - 'http://127.0.0.1:4002/api/tokens/{}/transfers'.format(address), + 'http://127.0.0.1:4002/api/tokens/{}/approvals'.format(address), json={'success': True}, status=200 ) client = ArkClient('http://127.0.0.1:4002/api') - client.tokens.transfers_by_token(address, {'page': 2, 'limit': 25}) + client.tokens.approvals_for(address, {'page': 2, 'limit': 25}) assert len(responses.calls) == 1 url = responses.calls[0].request.url assert url.startswith( - 'http://127.0.0.1:4002/api/tokens/0x1234567890abcdef/transfers?' + 'http://127.0.0.1:4002/api/tokens/0x1234567890abcdef/approvals?' ) assert 'page=2' in url assert 'limit=25' in url @@ -160,3 +177,73 @@ def test_transfers_calls_correct_url_with_params(): ) assert 'page=1' in url assert 'limit=10' in url + + +def test_approvals_calls_correct_url(): + responses.add( + responses.GET, + 'http://127.0.0.1:4002/api/tokens/approvals', + json={'success': True}, + status=200 + ) + + client = ArkClient('http://127.0.0.1:4002/api') + client.tokens.approvals() + assert len(responses.calls) == 1 + assert responses.calls[0].request.url == ( + 'http://127.0.0.1:4002/api/tokens/approvals' + ) + + +def test_approvals_calls_correct_url_with_params(): + responses.add( + responses.GET, + 'http://127.0.0.1:4002/api/tokens/approvals', + json={'success': True}, + status=200 + ) + + client = ArkClient('http://127.0.0.1:4002/api') + client.tokens.approvals({'page': 1, 'limit': 10}) + assert len(responses.calls) == 1 + url = responses.calls[0].request.url + assert url.startswith( + 'http://127.0.0.1:4002/api/tokens/approvals?' + ) + assert 'page=1' in url + assert 'limit=10' in url + + +def test_whitelist_calls_correct_url(): + responses.add( + responses.GET, + 'http://127.0.0.1:4002/api/tokens/whitelist', + json={'success': True}, + status=200 + ) + + client = ArkClient('http://127.0.0.1:4002/api') + client.tokens.whitelist() + assert len(responses.calls) == 1 + assert responses.calls[0].request.url == ( + 'http://127.0.0.1:4002/api/tokens/whitelist' + ) + + +def test_whitelist_calls_correct_url_with_params(): + responses.add( + responses.GET, + 'http://127.0.0.1:4002/api/tokens/whitelist', + json={'success': True}, + status=200 + ) + + client = ArkClient('http://127.0.0.1:4002/api') + client.tokens.whitelist({'page': 3, 'limit': 50}) + assert len(responses.calls) == 1 + url = responses.calls[0].request.url + assert url.startswith( + 'http://127.0.0.1:4002/api/tokens/whitelist?' + ) + assert 'page=3' in url + assert 'limit=50' in url diff --git a/tests/api/test_transactions.py b/tests/api/test_transactions.py index 25cc196..b0d4fe1 100644 --- a/tests/api/test_transactions.py +++ b/tests/api/test_transactions.py @@ -87,28 +87,36 @@ def test_get_calls_correct_url(): def test_all_unconfirmed_calls_correct_url(): responses.add( responses.GET, - 'http://127.0.0.1:4002/api/transactions/unconfirmed', + 'http://127.0.0.1:4002/tx/api/transactions/unconfirmed', json={'success': True}, status=200 ) - client = ArkClient('http://127.0.0.1:4002/api') + client = ArkClient({ + 'api': 'http://127.0.0.1:4002/api', + 'transactions': 'http://127.0.0.1:4002/tx/api', + 'evm': None, + }) client.transactions.all_unconfirmed() assert len(responses.calls) == 1 assert responses.calls[0].request.url == ( - 'http://127.0.0.1:4002/api/transactions/unconfirmed' + 'http://127.0.0.1:4002/tx/api/transactions/unconfirmed' ) def test_all_unconfirmed_calls_correct_url_with_params(): responses.add( responses.GET, - 'http://127.0.0.1:4002/api/transactions/unconfirmed', + 'http://127.0.0.1:4002/tx/api/transactions/unconfirmed', json={'success': True}, status=200 ) - client = ArkClient('http://127.0.0.1:4002/api') + client = ArkClient({ + 'api': 'http://127.0.0.1:4002/api', + 'transactions': 'http://127.0.0.1:4002/tx/api', + 'evm': None, + }) client.transactions.all_unconfirmed({ 'page': 5, 'limit': 69, @@ -117,7 +125,7 @@ def test_all_unconfirmed_calls_correct_url_with_params(): assert len(responses.calls) == 1 url = responses.calls[0].request.url assert url.startswith( - 'http://127.0.0.1:4002/api/transactions/unconfirmed?' + 'http://127.0.0.1:4002/tx/api/transactions/unconfirmed?' ) assert 'page=5' in url assert 'limit=69' in url @@ -129,18 +137,22 @@ def test_get_unconfirmed_calls_correct_url(): responses.add( responses.GET, - 'http://127.0.0.1:4002/api/transactions/unconfirmed/{}'.format( + 'http://127.0.0.1:4002/tx/api/transactions/unconfirmed/{}'.format( transaction_id ), json={'success': True}, status=200 ) - client = ArkClient('http://127.0.0.1:4002/api') + client = ArkClient({ + 'api': 'http://127.0.0.1:4002/api', + 'transactions': 'http://127.0.0.1:4002/tx/api', + 'evm': None, + }) client.transactions.get_unconfirmed(transaction_id) assert len(responses.calls) == 1 assert responses.calls[0].request.url == ( - 'http://127.0.0.1:4002/api/transactions/unconfirmed/12345' + 'http://127.0.0.1:4002/tx/api/transactions/unconfirmed/12345' ) diff --git a/tests/api/test_wallets.py b/tests/api/test_wallets.py index c9b0ed2..e6f602a 100644 --- a/tests/api/test_wallets.py +++ b/tests/api/test_wallets.py @@ -257,7 +257,7 @@ def test_votes_calls_correct_url_with_params(): assert 'limit=69' in url -def test_tokens_calls_correct_url(): +def test_tokens_for_calls_correct_url(): wallet_id = '12345' responses.add( responses.GET, @@ -267,14 +267,14 @@ def test_tokens_calls_correct_url(): ) client = ArkClient('http://127.0.0.1:4002/api') - client.wallets.tokens(wallet_id) + client.wallets.tokens_for(wallet_id) assert len(responses.calls) == 1 assert responses.calls[0].request.url == ( 'http://127.0.0.1:4002/api/wallets/12345/tokens' ) -def test_tokens_calls_correct_url_with_params(): +def test_tokens_for_calls_correct_url_with_params(): wallet_id = '12345' responses.add( responses.GET, @@ -284,7 +284,7 @@ def test_tokens_calls_correct_url_with_params(): ) client = ArkClient('http://127.0.0.1:4002/api') - client.wallets.tokens(wallet_id, {'page': 5, 'limit': 69}) + client.wallets.tokens_for(wallet_id, {'page': 5, 'limit': 69}) assert len(responses.calls) == 1 url = responses.calls[0].request.url assert url.startswith( @@ -294,7 +294,7 @@ def test_tokens_calls_correct_url_with_params(): assert 'limit=69' in url -def test_tokens_for_calls_correct_url(): +def test_tokens_calls_correct_url(): responses.add( responses.GET, 'http://127.0.0.1:4002/api/wallets/tokens', @@ -303,9 +303,7 @@ def test_tokens_for_calls_correct_url(): ) client = ArkClient('http://127.0.0.1:4002/api') - client.wallets.tokens_for({ - 'addresses': '0xabc,0xdef', - }) + client.wallets.tokens({'addresses': '0xabc,0xdef'}) assert len(responses.calls) == 1 url = responses.calls[0].request.url assert url.startswith( @@ -314,7 +312,7 @@ def test_tokens_for_calls_correct_url(): assert 'addresses=0xabc%2C0xdef' in url -def test_tokens_for_calls_correct_url_with_params(): +def test_tokens_calls_correct_url_with_params(): responses.add( responses.GET, 'http://127.0.0.1:4002/api/wallets/tokens', @@ -323,7 +321,7 @@ def test_tokens_for_calls_correct_url_with_params(): ) client = ArkClient('http://127.0.0.1:4002/api') - client.wallets.tokens_for({ + client.wallets.tokens({ 'addresses': '0xabc,0xdef', 'page': 2, 'limit': 50,