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
6 changes: 3 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ jobs:
strategy:
max-parallel: 4
matrix:
python-version: ["3.10", "3.11", "3.12", "3.13"]
python-version: ["3.11", "3.12", "3.13", "3.14"]

steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v7
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
uses: actions/setup-python@v7
with:
python-version: ${{ matrix.python-version }}
- name: install dependencies
Expand Down
10 changes: 2 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ If you have any questions, requests or ideas open an issue or ask us in #python

### Prerequisites

- Python >= 3.8
- Python >= 3.11

### Setup

Expand Down Expand Up @@ -74,19 +74,13 @@ pip install -r requirements.txt
Run the following command to install the package in development mode:

```bash
python setup.py develop
pip install -e .
```

6. Run the tests

Use pytest to run the tests and ensure everything is working correctly:

```bash
python setup.py test
```

Or directly with pytest:

```bash
pytest
```
Expand Down
50 changes: 25 additions & 25 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
backoff==2.2.1
certifi==2024.6.2
chardet==3.0.4
charset-normalizer==3.3.2
coverage==7.5.3
flake8==3.5.0
flake8-import-order==0.17.1
flake8-print==3.1.0
flake8-quotes==1.0.0
flatten-dict==0.4.2
idna==2.7
iniconfig==2.0.0
mccabe==0.6.1
packaging==24.1
pluggy==1.5.0
pycodestyle==2.3.1
pyflakes==1.6.0
pytest==8.2.2
pytest-cov==2.5.1
pytest-mock==1.10.0
pytest-responses==0.5.1
requests==2.32.3
responses==0.10.15
setuptools==70.1.0
six==1.16.0
urllib3==2.2.2
certifi==2026.11.20
charset-normalizer==3.5.3
coverage==7.18.0
flake8==7.5.0
flake8-import-order==0.19.2
flake8-print==5.0.0
flake8-quotes==3.4.0
flatten-dict==0.6.0
idna==3.20
iniconfig==2.3.1
mccabe==0.7.0
packaging==26.4
pluggy==1.7.0
pycodestyle==2.15.0
pyflakes==4.1.0
pygments==2.21.0
pytest==9.2.0
pytest-cov==7.1.0
pytest-mock==3.17.0
pytest-responses==0.6.0
pyyaml==6.0.4
requests==2.34.2
responses==0.26.3
setuptools==84.2.1
urllib3==2.8.0
3 changes: 0 additions & 3 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
[aliases]
test=pytest

[flake8]
max-line-length = 100
application-import-names = client
Expand Down
28 changes: 12 additions & 16 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,28 @@
import sys

import setuptools

requires = [
'requests==2.32.3',
'backoff==2.2.1',
'flatten-dict==0.4.2',
'flatten-dict==0.6.0',
'requests==2.34.2',
]

tests_require = [
'pytest==8.2.2',
'pytest-cov==2.5.1',
'pytest-mock==1.10.0',
'pytest-responses==0.5.1',
'flake8==3.5.0',
'flake8-import-order==0.17.1',
'flake8-print==3.1.0',
'flake8-quotes==1.0.0',
'flake8==7.5.0',
'flake8-import-order==0.19.2',
'flake8-print==5.0.0',
'flake8-quotes==3.4.0',
'pytest==9.2.0',
'pytest-cov==7.1.0',
'pytest-mock==3.17.0',
'pytest-responses==0.6.0',
'responses==0.26.3',
]

extras_require = {
'test': tests_require,
'dev': requires + tests_require
}

setup_requires = ['pytest-runner'] if {'pytest', 'test', 'ptr'}.intersection(sys.argv) else []

setuptools.setup(
name='arkecosystem-client',
description='A simple Python API client for the ARK Blockchain.',
Expand All @@ -34,8 +31,7 @@
author_email='info@client.io',
url='https://github.com/ArkEcosystem/python-client',
packages=setuptools.find_packages(exclude=['tests', 'tests.*']),
python_requires='>=3.11',
install_requires=requires,
extras_require=extras_require,
tests_require=tests_require,
setup_requires=setup_requires,
)
6 changes: 5 additions & 1 deletion tests/api/test_evm.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ def test_eth_call_methods_correct_url():
status=200
)

client = Client('http://127.0.0.1:4002/evm/api')
client = Client({
'api': 'http://127.0.0.1:4002/api',
'transactions': None,
'evm': 'http://127.0.0.1:4002/evm/api',
})
client.evm.call({
'method': 'eth_call',
'params': [[{ 'random': 'data' }], 'latest'],
Expand Down
6 changes: 5 additions & 1 deletion tests/api/test_transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,11 @@ def test_create_calls_correct_url_with_data():
status=200
)

client = Client('http://127.0.0.1:4002/tx/api')
client = Client({
'api': 'http://127.0.0.1:4002/api',
'transactions': 'http://127.0.0.1:4002/tx/api',
'evm': None,
})
client.transactions.create([{'random': 'data'}])
assert len(responses.calls) == 1
assert responses.calls[0].request.url == (
Expand Down
32 changes: 31 additions & 1 deletion tests/test_client.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import pytest
import responses

from client.client import Client

Expand All @@ -11,11 +11,41 @@ def test_client():
assert hasattr(client, 'blockchain') == True
assert hasattr(client, 'blocks') == True
assert hasattr(client, 'commits') == True
assert hasattr(client, 'contracts') == True
assert hasattr(client, 'evm') == True
assert hasattr(client, 'node') == True
assert hasattr(client, 'peers') == True
assert hasattr(client, 'receipts') == True
assert hasattr(client, 'rounds') == True
assert hasattr(client, 'tokens') == True
assert hasattr(client, 'transactions') == True
assert hasattr(client, 'validators') == True
assert hasattr(client, 'votes') == True
assert hasattr(client, 'wallets') == True


def test_client_switches_back_to_api_host_after_using_another_endpoint():
responses.add(
responses.POST,
'http://127.0.0.1:4002/tx/api/transactions',
json={'success': True},
status=200
)
responses.add(
responses.GET,
'http://127.0.0.1:4002/api/wallets',
json={'success': True},
status=200
)

client = Client({
'api': 'http://127.0.0.1:4002/api',
'transactions': 'http://127.0.0.1:4002/tx/api',
'evm': None,
})
client.transactions.create([{'random': 'data'}])
client.wallets.all()

assert len(responses.calls) == 2
assert responses.calls[0].request.url == 'http://127.0.0.1:4002/tx/api/transactions'
assert responses.calls[1].request.url == 'http://127.0.0.1:4002/api/wallets'
15 changes: 11 additions & 4 deletions tests/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,15 @@ def test_connection_with_hosts_dict():
assert connection.session.hostname == 'http://127.0.0.1:4003/api'


@pytest.mark.parametrize('endpoint', ['transactions', 'evm'])
def test_connection_with_endpoint_falls_back_to_api_host_when_not_set(endpoint):
connection = Connection('http://127.0.0.1:4003/api')

connection.with_endpoint(endpoint)

assert connection.session.hostname == 'http://127.0.0.1:4003/api'


def test_connection_request_retry_successful():
responses.add(
responses.GET,
Expand Down Expand Up @@ -147,7 +156,7 @@ def test_http_methods_call_correct_url_and_return_correct_response(method, func_

@pytest.mark.parametrize('method,func_name', [
(responses.GET, 'get'),
# (responses.POST, 'post'),
(responses.POST, 'post'),
])
def test_http_methods_call_correct_url_with_params_and_return_correct_response(method, func_name):
responses.add(
Expand All @@ -171,11 +180,9 @@ def test_session_detects_hostname_correctly():


def test_session_throws_error_when_missing_hostname():
with pytest.raises(ValueError) as exception:
with pytest.raises(ValueError, match='hostname is required'):
Session()

assert exception.value == 'hostname is required'


def test_session_prepends_hostname_to_url():
responses.add(
Expand Down
26 changes: 26 additions & 0 deletions tests/test_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,29 @@ def test_request_post_calls_connection_post_with_correct_params(mocker):

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


def test_request_get_flattens_nested_params_with_dot_notation(mocker):
get_mock = mocker.patch.object(Connection, 'get')
connection = Connection('http://127.0.0.1:4003')

resource = Resource(connection)
resource.request_get('spongebob', params={'height': {'from': 1, 'to': 10}, 'page': 2})

get_mock.assert_called_once_with(
'spongebob',
params={'height.from': 1, 'height.to': 10, 'page': 2},
)


def test_request_post_flattens_nested_params_with_dot_notation(mocker):
post_mock = mocker.patch.object(Connection, 'post')
connection = Connection('http://127.0.0.1:4003')

resource = Resource(connection)
resource.request_post('spongebob', data={'one': {'two': 'three'}}, params={'foo': {'bar': 1}})

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