Skip to content
Open
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
29 changes: 29 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Lint

on:
push:
branches:
- "master"
- "develop"
pull_request:
types: [ready_for_review, synchronize, opened]

jobs:
flake8:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v7
- name: Set up Python
uses: actions/setup-python@v7
with:
python-version: "3.14"
- name: install dependencies
run: |
python3 -m venv venv
. venv/bin/activate
pip install .[test]
- name: run linter
run: |
. venv/bin/activate
make lint
2 changes: 1 addition & 1 deletion client/api/evm.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
class EVM(Resource):
def call(self, payload: EvmBodyPartialParams):
return self.with_endpoint('evm').request_post('', {
'jsonrpc': "2.0",
'jsonrpc': '2.0',
**payload,
})
12 changes: 10 additions & 2 deletions client/api/receipts.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@

from client.resource import Resource
from client.types import PaginatedResponse, Response
from client.types.receipts import ReceiptContractsQuery, ReceiptQuery, ReceiptResponse, ReceiptsQuery
from client.types.receipts import (
ReceiptContractsQuery,
ReceiptQuery,
ReceiptResponse,
ReceiptsQuery,
)


class Receipts(Resource):
Expand All @@ -19,7 +24,10 @@ def get(
f'receipts/{transaction_hash}', query
)

def contracts(self, query: Optional[ReceiptContractsQuery] = None) -> PaginatedResponse[ReceiptResponse]:
def contracts(
self,
query: Optional[ReceiptContractsQuery] = None,
) -> PaginatedResponse[ReceiptResponse]:
return self.with_endpoint('api').request_get(
'receipts/contracts', query
)
15 changes: 12 additions & 3 deletions client/api/tokens.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,26 @@ class Tokens(Resource):
def all(self, query: Optional[TokensQuery] = None) -> PaginatedResponse[TokenResponse]:
return self.with_endpoint('api').request_get('tokens', query)

def transfers(self, query: Optional[TokenTransfersQuery] = None) -> TokenPaginatedResponseResults[TokenActionsResponse]:
def transfers(
self,
query: Optional[TokenTransfersQuery] = None,
) -> TokenPaginatedResponseResults[TokenActionsResponse]:
return self.with_endpoint('api').request_get(
'tokens/transfers', query
)

def approvals(self, query: Optional[TokenApprovalsQuery] = None) -> TokenPaginatedResponseResults[TokenActionsResponse]:
def approvals(
self,
query: Optional[TokenApprovalsQuery] = None,
) -> TokenPaginatedResponseResults[TokenActionsResponse]:
return self.with_endpoint('api').request_get(
'tokens/approvals', query
)

def whitelist(self, query: Optional[PaginatedQuery] = None) -> PaginatedResponse[TokenWhitelistResponse]:
def whitelist(
self,
query: Optional[PaginatedQuery] = None,
) -> PaginatedResponse[TokenWhitelistResponse]:
return self.with_endpoint('api').request_get(
'tokens/whitelist', query
)
Expand Down
5 changes: 4 additions & 1 deletion client/api/transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@

class Transactions(Resource):

def all(self, query: Optional[TransactionsQuery] = None) -> PaginatedResponse[TransactionResponse]:
def all(
self,
query: Optional[TransactionsQuery] = None,
) -> PaginatedResponse[TransactionResponse]:
return self.with_endpoint('api').request_get(
'transactions', query
)
Expand Down
14 changes: 11 additions & 3 deletions client/api/wallets.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@

from client.resource import Resource
from client.types import PaginatedResponse, Response
from client.types.transactions import TransactionResponse, TransactionsQuery
from client.types.wallets import WalletResponse, WalletTokensForQuery, WalletTokensQuery, WalletsQuery
from client.types.tokens import TokenActionsResponse, TokenPaginatedResponseResults
from client.types.transactions import TransactionResponse, TransactionsQuery
from client.types.wallets import (
WalletResponse,
WalletTokensForQuery,
WalletTokensQuery,
WalletsQuery,
)


class Wallets(Resource):
Expand Down Expand Up @@ -65,7 +70,10 @@ def tokens_for(
f'wallets/{address}/tokens', query
)

def tokens(self, query: Optional[WalletTokensQuery] = None) -> TokenPaginatedResponseResults[TokenActionsResponse]:
def tokens(
self,
query: Optional[WalletTokensQuery] = None,
) -> TokenPaginatedResponseResults[TokenActionsResponse]:
return self.with_endpoint('api').request_get(
'wallets/tokens', query
)
8 changes: 5 additions & 3 deletions client/client.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
from typing import Union
from client.api.contracts import Contracts
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.validators import Validators
from client.api.contracts import Contracts
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.tokens import Tokens
from client.api.transactions import Transactions
from client.api.validators import Validators
from client.api.votes import Votes
from client.api.wallets import Wallets
from client.connection import ClientHosts, Connection


class Client(object):

Expand Down
4 changes: 4 additions & 0 deletions client/connection.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@

from typing import Literal, Optional, TypedDict, Union

import backoff

import requests

from client.exceptions import ArkHTTPException
Expand All @@ -22,6 +24,7 @@ class ClientHosts(TypedDict):
transactions: Optional[str]
evm: Optional[str]


class Session(requests.Session):

def __init__(self, *args, **kwargs):
Expand All @@ -44,6 +47,7 @@ def prepare_request(self, request):

return super().prepare_request(request)


class Connection(object):
session: Session
hosts: ClientHosts
Expand Down
2 changes: 2 additions & 0 deletions client/resource.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from typing import Literal

from flatten_dict import flatten

from client.connection import Connection


class Resource(object):

def __init__(self, connection: Connection):
Expand Down
3 changes: 2 additions & 1 deletion client/types/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ class BlockResponse(TypedDict, total=False):
version: int


# Functional form required: keys contain dots (e.g. 'height.from') which are not valid Python identifiers
# Functional form required: keys contain dots (e.g. 'height.from') which are not
# valid Python identifiers
BlocksQuery = TypedDict(
'BlocksQuery',
{
Expand Down
2 changes: 1 addition & 1 deletion client/types/evm.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

PayloadData = dict[str, str | int | float]

BlockParameter = Literal["earliest", "latest", "safe", "finalized", "pending"]
BlockParameter = Literal['earliest', 'latest', 'safe', 'finalized', 'pending']


class EvmBodyPartialParams(TypedDict, total=False):
Expand Down
3 changes: 2 additions & 1 deletion client/types/validators.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from typing import TypedDict


# Functional form required: keys contain dots (e.g. 'blocks.last.hash') which are not valid Python identifiers
# Functional form required: keys contain dots (e.g. 'blocks.last.hash') which are not
# valid Python identifiers
ValidatorsQuery = TypedDict(
'ValidatorsQuery',
{
Expand Down
3 changes: 2 additions & 1 deletion client/types/wallets.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ class WalletResponse(TypedDict):
tokenCount: int


# Functional form required: keys contain dots (e.g. 'balance.from') which are not valid Python identifiers
# Functional form required: keys contain dots (e.g. 'balance.from') which are not
# valid Python identifiers
WalletsQuery = TypedDict(
'WalletsQuery',
{
Expand Down
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[flake8]
max-line-length = 100
application-import-names = client
extend-exclude = .venv,venv,build,dist

[tool:pytest]
addopts = --verbose -s
Expand Down
1 change: 1 addition & 0 deletions tests/api/test_api_nodes.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import responses

from client import Client


Expand Down
1 change: 1 addition & 0 deletions tests/api/test_blockchain.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import responses

from client import Client


Expand Down
1 change: 1 addition & 0 deletions tests/api/test_commits.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import responses

from client import Client


Expand Down
5 changes: 4 additions & 1 deletion tests/api/test_contracts.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import responses

from client import Client


Expand Down Expand Up @@ -27,4 +28,6 @@ def test_abi_calls_correct_url():
client = Client('http://127.0.0.1:4002/api')
client.contracts.abi('consensus', 'some-address')
assert len(responses.calls) == 1
assert responses.calls[0].request.url == 'http://127.0.0.1:4002/api/contracts/consensus/some-address/abi'
assert responses.calls[0].request.url == (
'http://127.0.0.1:4002/api/contracts/consensus/some-address/abi'
)
5 changes: 3 additions & 2 deletions tests/api/test_evm.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json

import responses

from client import Client
Expand All @@ -15,14 +16,14 @@ def test_eth_call_methods_correct_url():
client = Client('http://127.0.0.1:4002/evm/api')
client.evm.call({
'method': 'eth_call',
'params': [[{ 'random': 'data' }], 'latest'],
'params': [[{'random': 'data'}], 'latest'],
'id': None,
})
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'],
'params': [[{'random': 'data'}], 'latest'],
'id': None,
}
1 change: 1 addition & 0 deletions tests/api/test_receipts.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import responses

from client import Client


Expand Down
1 change: 1 addition & 0 deletions tests/api/test_rounds.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import responses

from client import Client


Expand Down
28 changes: 13 additions & 15 deletions tests/test_client.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
import pytest

from client.client import Client


def test_client():
client = Client('http://127.0.0.1:4002')

assert hasattr(client, 'connection') == True
assert hasattr(client, 'api_nodes') == True
assert hasattr(client, 'blockchain') == True
assert hasattr(client, 'blocks') == True
assert hasattr(client, 'commits') == True
assert hasattr(client, 'evm') == True
assert hasattr(client, 'node') == True
assert hasattr(client, 'peers') == True
assert hasattr(client, 'rounds') == True
assert hasattr(client, 'transactions') == True
assert hasattr(client, 'validators') == True
assert hasattr(client, 'votes') == True
assert hasattr(client, 'wallets') == True
assert hasattr(client, 'connection')
assert hasattr(client, 'api_nodes')
assert hasattr(client, 'blockchain')
assert hasattr(client, 'blocks')
assert hasattr(client, 'commits')
assert hasattr(client, 'evm')
assert hasattr(client, 'node')
assert hasattr(client, 'peers')
assert hasattr(client, 'rounds')
assert hasattr(client, 'transactions')
assert hasattr(client, 'validators')
assert hasattr(client, 'votes')
assert hasattr(client, 'wallets')
6 changes: 3 additions & 3 deletions tests/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,8 @@ def test_http_methods_call_correct_url_with_params_and_return_correct_response(m


def test_session_detects_hostname_correctly():
session = Session(hostname="test.com")
assert session.hostname == "test.com"
session = Session(hostname='test.com')
assert session.hostname == 'test.com'
assert isinstance(session, requests.Session)


Expand All @@ -185,7 +185,7 @@ def test_session_prepends_hostname_to_url():
status=200
)

session = Session(hostname="http://test.com")
session = Session(hostname='http://test.com')

session.get('spongebob')
assert len(responses.calls) == 1
Expand Down
1 change: 0 additions & 1 deletion tests/test_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,3 @@ def test_request_post_calls_connection_post_with_correct_params(mocker):
resource.request_post('spongebob', data={'one': 'two'}, params={'foo': 'bar'})

post_mock.assert_called_once_with('spongebob', data={'one': 'two'}, params={'foo': 'bar'})