Skip to content

Commit c27dfb3

Browse files
authored
feat: evm api endpoint (#130)
1 parent ea27117 commit c27dfb3

File tree

6 files changed

+49
-3
lines changed

6 files changed

+49
-3
lines changed

client/api/blocks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def all(self, page=None, limit=100, **kwargs):
1010
'limit': limit,
1111
**extra_params
1212
}
13-
return self.request_get('blocks', params)
13+
return self.with_endpoint('api').request_get('blocks', params)
1414

1515
def get(self, block_id):
1616
return self.with_endpoint('api').request_get(f'blocks/{block_id}')

client/api/evm.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from typing import Any
2+
from client.resource import Resource
3+
4+
5+
class EVM(Resource):
6+
def eth_call(self, params: list[dict[str, Any]]):
7+
return self.with_endpoint('evm').request_post('', {
8+
'jsonrpc': "2.0",
9+
'method': "eth_call",
10+
'params': [params, "latest"],
11+
'id': None,
12+
})

client/api/votes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ def all(self, page=None, limit=100):
88
'page': page,
99
'limit': limit,
1010
}
11-
return self.request_get('votes', params)
11+
return self.with_endpoint('api').request_get('votes', params)
1212

1313
def get(self, vote_id):
1414
return self.with_endpoint('api').request_get(f'votes/{vote_id}')

client/client.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
from typing import Union
2-
from client.api.receipts import Receipts
32
from client.connection import ClientHosts, Connection
43
from client.api.api_nodes import ApiNodes
54
from client.api.blockchain import Blockchain
65
from client.api.blocks import Blocks
76
from client.api.commits import Commits
87
from client.api.delegates import Delegates
8+
from client.api.evm import EVM
99
from client.api.node import Node
1010
from client.api.peers import Peers
11+
from client.api.receipts import Receipts
1112
from client.api.rounds import Rounds
1213
from client.api.transactions import Transactions
1314
from client.api.votes import Votes
@@ -61,6 +62,14 @@ def delegates(self):
6162
"""
6263
return Delegates(self.connection)
6364

65+
@property
66+
def evm(self):
67+
"""
68+
:return: EVM API
69+
:rtype: client.api.evm.EVM
70+
"""
71+
return EVM(self.connection)
72+
6473
@property
6574
def node(self):
6675
"""

tests/api/test_evm.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import json
2+
import responses
3+
4+
from client import ArkClient
5+
6+
7+
def test_eth_call_methods_correct_url():
8+
responses.add(
9+
responses.POST,
10+
'http://127.0.0.1:4002/evm/api/',
11+
json={'success': True},
12+
status=200
13+
)
14+
15+
client = ArkClient('http://127.0.0.1:4002/evm/api')
16+
client.evm.eth_call([{ 'random': 'data' }])
17+
assert len(responses.calls) == 1
18+
assert responses.calls[0].request.url == 'http://127.0.0.1:4002/evm/api/'
19+
assert json.loads(responses.calls[0].request.body.decode()) == {
20+
'jsonrpc': '2.0',
21+
'method': 'eth_call',
22+
'params': [[{ 'random': 'data' }], 'latest'],
23+
'id': None,
24+
}

tests/test_client.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ def test_client():
1212
assert hasattr(client, 'blocks') == True
1313
assert hasattr(client, 'commits') == True
1414
assert hasattr(client, 'delegates') == True
15+
assert hasattr(client, 'evm') == True
1516
assert hasattr(client, 'node') == True
1617
assert hasattr(client, 'peers') == True
1718
assert hasattr(client, 'rounds') == True

0 commit comments

Comments
 (0)