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
2 changes: 1 addition & 1 deletion client/api/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}')
Expand Down
12 changes: 12 additions & 0 deletions client/api/evm.py
Original file line number Diff line number Diff line change
@@ -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,
})
2 changes: 1 addition & 1 deletion client/api/votes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}')
11 changes: 10 additions & 1 deletion client/client.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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):
"""
Expand Down
24 changes: 24 additions & 0 deletions tests/api/test_evm.py
Original file line number Diff line number Diff line change
@@ -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,
}
1 change: 1 addition & 0 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down