diff --git a/client/api/blocks.py b/client/api/blocks.py index 4fafce4..14628a1 100644 --- a/client/api/blocks.py +++ b/client/api/blocks.py @@ -10,7 +10,7 @@ def all(self, page=None, limit=100, **kwargs): 'limit': limit, **extra_params } - return self.request_get('blocks', params) + return self.with_endpoint('api').request_get('blocks', params) def get(self, block_id): return self.with_endpoint('api').request_get(f'blocks/{block_id}') diff --git a/client/api/evm.py b/client/api/evm.py new file mode 100644 index 0000000..1552790 --- /dev/null +++ b/client/api/evm.py @@ -0,0 +1,12 @@ +from typing import Any +from client.resource import Resource + + +class EVM(Resource): + def eth_call(self, params: list[dict[str, Any]]): + return self.with_endpoint('evm').request_post('', { + 'jsonrpc': "2.0", + 'method': "eth_call", + 'params': [params, "latest"], + 'id': None, + }) diff --git a/client/api/votes.py b/client/api/votes.py index f305a47..2986d8f 100644 --- a/client/api/votes.py +++ b/client/api/votes.py @@ -8,7 +8,7 @@ def all(self, page=None, limit=100): 'page': page, 'limit': limit, } - return self.request_get('votes', params) + return self.with_endpoint('api').request_get('votes', params) def get(self, vote_id): return self.with_endpoint('api').request_get(f'votes/{vote_id}') diff --git a/client/client.py b/client/client.py index 9de82fd..813106b 100644 --- a/client/client.py +++ b/client/client.py @@ -1,13 +1,14 @@ 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 from client.api.blocks import Blocks from client.api.commits import Commits from client.api.delegates import Delegates +from client.api.evm import EVM from client.api.node import Node from client.api.peers import Peers +from client.api.receipts import Receipts from client.api.rounds import Rounds from client.api.transactions import Transactions from client.api.votes import Votes @@ -61,6 +62,14 @@ def delegates(self): """ return Delegates(self.connection) + @property + def evm(self): + """ + :return: EVM API + :rtype: client.api.evm.EVM + """ + return EVM(self.connection) + @property def node(self): """ diff --git a/tests/api/test_evm.py b/tests/api/test_evm.py new file mode 100644 index 0000000..ba13d2d --- /dev/null +++ b/tests/api/test_evm.py @@ -0,0 +1,24 @@ +import json +import responses + +from client import ArkClient + + +def test_eth_call_methods_correct_url(): + responses.add( + responses.POST, + 'http://127.0.0.1:4002/evm/api/', + json={'success': True}, + status=200 + ) + + client = ArkClient('http://127.0.0.1:4002/evm/api') + client.evm.eth_call([{ 'random': 'data' }]) + assert len(responses.calls) == 1 + assert responses.calls[0].request.url == 'http://127.0.0.1:4002/evm/api/' + assert json.loads(responses.calls[0].request.body.decode()) == { + 'jsonrpc': '2.0', + 'method': 'eth_call', + 'params': [[{ 'random': 'data' }], 'latest'], + 'id': None, + } diff --git a/tests/test_client.py b/tests/test_client.py index 1301695..04fb996 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -12,6 +12,7 @@ def test_client(): assert hasattr(client, 'blocks') == True assert hasattr(client, 'commits') == True assert hasattr(client, 'delegates') == True + assert hasattr(client, 'evm') == True assert hasattr(client, 'node') == True assert hasattr(client, 'peers') == True assert hasattr(client, 'rounds') == True