From bfeac8cc75ef282856e974ec99dca59f4b7b4e16 Mon Sep 17 00:00:00 2001 From: Alex Barnsley <8069294+alexbarnsley@users.noreply.github.com> Date: Wed, 26 Mar 2025 16:58:18 +0000 Subject: [PATCH 1/3] feat: evm api endpoint --- client/api/evm.py | 12 ++++++++++++ client/client.py | 9 +++++++++ 2 files changed, 21 insertions(+) create mode 100644 client/api/evm.py 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/client.py b/client/client.py index 079948a..3e94187 100644 --- a/client/client.py +++ b/client/client.py @@ -1,4 +1,5 @@ from typing import Union +from client.api.evm import EVM from client.connection import ClientHosts, Connection from client.api.api_nodes import ApiNodes from client.api.blockchain import Blockchain @@ -60,6 +61,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): """ From 481339bf813cfe280a0051967037752a0540bdc7 Mon Sep 17 00:00:00 2001 From: Alex Barnsley <8069294+alexbarnsley@users.noreply.github.com> Date: Wed, 26 Mar 2025 16:58:54 +0000 Subject: [PATCH 2/3] enforce api endpoint where missing --- client/api/blocks.py | 2 +- client/api/votes.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/client/api/blocks.py b/client/api/blocks.py index 6939919..cacf31b 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/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}') From a3a8570cedb3b5081ba7702f6e2a0b3d8c094c16 Mon Sep 17 00:00:00 2001 From: Alex Barnsley <8069294+alexbarnsley@users.noreply.github.com> Date: Wed, 26 Mar 2025 16:59:22 +0000 Subject: [PATCH 3/3] test --- tests/api/test_evm.py | 24 ++++++++++++++++++++++++ tests/test_client.py | 1 + 2 files changed, 25 insertions(+) create mode 100644 tests/api/test_evm.py 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