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
26 changes: 25 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,37 @@ on:
branches: [ master ]

jobs:
# Test that importing works with no optional dependencies installed
minimal-import:

runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.10"]

steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install PDM
run: curl -sSL https://raw.githubusercontent.com/pdm-project/pdm/main/install-pdm.py | python3
- name: Install dependencies
run: |
pdm sync -G :none
- name: Test importing
run: |
pdm run python -c "import pons"

test:

runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.10", "3.11", "3.12"]
python-version: ["3.10", "3.11", "3.12", "3.13"]

steps:
- uses: actions/checkout@v3
Expand Down
16 changes: 10 additions & 6 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -157,13 +157,17 @@ Testing utilities

``pons`` exposes several types useful for testing applications that connect to Ethereum RPC servers. Not intended for the production environment.

.. autoclass:: LocalProvider
Install the feature ``local-provider`` for the ``local_provider`` module to be available.

.. autoclass:: pons.local_provider.LocalProvider
:show-inheritance:
:members: disable_auto_mine_transactions, enable_auto_mine_transactions, take_snapshot, revert_to_snapshot
:members: disable_auto_mine_transactions, enable_auto_mine_transactions, take_snapshot, revert_to_snapshot, root

.. autoclass:: pons.local_provider.SnapshotID()

.. autoclass:: SnapshotID()
Install the feature ``http-provider-server`` for the ``http_provider_server`` module to be available.

.. autoclass:: HTTPProviderServer
.. autoclass:: pons.http_provider_server.HTTPProviderServer
:members:
:special-members: __call__

Expand All @@ -174,9 +178,9 @@ Compiler
Install with the feature ``compiler`` for it to be available.


.. autofunction:: compile_contract_file
.. autofunction:: pons.compiler.compile_contract_file

.. autoclass:: EVMVersion
.. autoclass:: pons.compiler.EVMVersion
:members:


Expand Down
12 changes: 12 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@ Changelog
---------


0.10.0 (in development)
~~~~~~~~~~~~~~~~~~~~~~~

Changed
^^^^^^^

- ``compile_contract_file`` and ``EVMVersion`` moved to ``compiler`` submodule; ``LocalProvider`` moved to ``local_provider`` submodule; ``HTTPProviderServer`` moved to ``http_provider_server`` submodule. (PR_89_)


.. _PR_89: https://github.com/fjarri-eth/pons/pull/89


0.9.0 (2025-10-18)
~~~~~~~~~~~~~~~~~~

Expand Down
3 changes: 2 additions & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ A quick usage example:
import ethereum_rpc

from ethereum_rpc import Amount
from pons import LocalProvider, HTTPProviderServer
from pons.local_provider import LocalProvider
from pons.http_provider_server import HTTPProviderServer

# Run examples with our test server in the background

Expand Down
233 changes: 162 additions & 71 deletions pdm.lock

Large diffs are not rendered by default.

8 changes: 0 additions & 8 deletions pons/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
LogFilter,
PendingTransactionFilter,
)
from ._compiler import EVMVersion, compile_contract_file
from ._contract import (
BaseBoundMethodCall,
BoundConstructor,
Expand Down Expand Up @@ -51,8 +50,6 @@
FallbackStrategyFactory,
PriorityFallback,
)
from ._http_provider_server import HTTPProviderServer
from ._local_provider import LocalProvider, SnapshotID
from ._multicall import BoundMultiMethodCall, BoundMultiMethodValueCall, Multicall
from ._provider import (
HTTPError,
Expand Down Expand Up @@ -94,7 +91,6 @@
"ContractPanic",
"CycleFallback",
"DeployedContract",
"EVMVersion",
"Either",
"Error",
"Event",
Expand All @@ -105,9 +101,7 @@
"FallbackStrategyFactory",
"HTTPError",
"HTTPProvider",
"HTTPProviderServer",
"InvalidResponse",
"LocalProvider",
"LogFilter",
"Method",
"MethodCall",
Expand All @@ -122,11 +116,9 @@
"ProviderPath",
"Receive",
"Signer",
"SnapshotID",
"TransactionFailed",
"Unreachable",
"abi",
"compile_contract_file",
"get_create2_address",
"get_create_address",
]
7 changes: 7 additions & 0 deletions pons/_compiler.py → pons/compiler.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
"""
Solidity compiler support.
Requires the dependencies from the ``compiler`` feature.
"""

from collections.abc import Mapping
from enum import Enum
from pathlib import Path
Expand All @@ -6,6 +11,8 @@

from ._contract import CompiledContract

__all__ = ["EVMVersion", "compile_contract_file"]


class EVMVersion(Enum):
"""
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
"""
HTTP provider server for tests.
Requires the dependencies from the ``http-provider-server`` feature.
"""

from http import HTTPStatus
from typing import cast

Expand All @@ -13,6 +18,8 @@

from ._provider import RPC_JSON, HTTPProvider, Provider

__all__ = ["HTTPProviderServer"]


def parse_request(request: RPC_JSON) -> tuple[RPC_JSON, str, list[RPC_JSON]]:
request = cast("dict[str, RPC_JSON]", request)
Expand Down Expand Up @@ -98,7 +105,7 @@ async def __call__(self, *, task_status: trio.TaskStatus = trio.TASK_STATUS_IGNO
Starts the server in an external event loop.
Useful for the cases when it needs to run in parallel with other servers or clients.

Supports start-up reporting when invoked via `nursery.start()`.
Supports start-up reporting when invoked via ``nursery.start()``.
"""
config = Config()
config.bind = [f"{self._host}:{self._port}"]
Expand Down
13 changes: 9 additions & 4 deletions pons/_local_provider.py → pons/local_provider.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
"""PyEVM-based provider for tests."""
"""
PyEVM-based provider for tests.
Requires the dependencies from the ``local-provider`` feature.
"""

import itertools
from collections.abc import AsyncIterator
Expand All @@ -13,6 +16,8 @@
from ._provider import RPC_JSON, Provider, ProviderError, ProviderSession
from ._signer import AccountSigner

__all__ = ["LocalProvider", "SnapshotID"]


class SnapshotID:
"""An ID of a snapshot in a :py:class:`LocalProvider`."""
Expand All @@ -32,7 +37,7 @@ def __init__(
*,
root_balance: Amount,
chain_id: int = 1,
evm_version: EVMVersion = EVMVersion.CANCUN,
evm_version: EVMVersion = EVMVersion.PRAGUE,
):
self._local_node = Node(
root_balance_wei=root_balance.as_wei(), chain_id=chain_id, evm_version=evm_version
Expand Down Expand Up @@ -65,14 +70,14 @@ def revert_to_snapshot(self, snapshot_id: SnapshotID) -> None:
self._local_node = self._snapshots[snapshot_id.id_]
self._rpc_node = RPCNode(self._local_node)

def rpc(self, method: str, *args: Any) -> RPC_JSON:
def rpc(self, method: str, *args: Any) -> RPC_JSON: # noqa: D102
try:
return self._rpc_node.rpc(method, *args)
except RPCError as exc:
raise ProviderError(exc) from exc

@asynccontextmanager
async def session(self) -> AsyncIterator["LocalProviderSession"]:
async def session(self) -> AsyncIterator["LocalProviderSession"]: # noqa: D102
yield LocalProviderSession(self)


Expand Down
4 changes: 3 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "pons"
version = "0.9.0"
version = "0.10.0-dev"
description = "Async RPC client for Ethereum"
authors = [
{name = "Bogdan Opanchuk", email = "bogdan@opanchuk.net"},
Expand Down Expand Up @@ -139,6 +139,8 @@ ignore = [
"RUF009",
# Way too restrictive. Sometimes it is useful to import types from pytest.
"PT013",
# Sphinx does not need a separate docstring for ``__init__``.
"D107",
]

# Allow autofix for all enabled rules (when `--fix`) is provided.
Expand Down
3 changes: 2 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
from alysis import EVMVersion
from ethereum_rpc import Amount

from pons import AccountSigner, Client, ClientSession, LocalProvider
from pons import AccountSigner, Client, ClientSession
from pons.local_provider import LocalProvider


@pytest.fixture
Expand Down
4 changes: 2 additions & 2 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,18 @@
ContractLegacyError,
ContractPanic,
DeployedContract,
LocalProvider,
Method,
Mutability,
ProviderError,
TransactionFailed,
Unreachable,
abi,
compile_contract_file,
)
from pons._abi_types import encode_args
from pons._contract_abi import PANIC_ERROR
from pons._provider import RPC_JSON
from pons.compiler import compile_contract_file
from pons.local_provider import LocalProvider


@pytest.fixture
Expand Down
4 changes: 2 additions & 2 deletions tests/test_client_rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@
ClientSession,
CompiledContract,
Either,
LocalProvider,
ProviderError,
abi,
compile_contract_file,
)
from pons._abi_types import encode_args
from pons._provider import RPC_JSON
from pons.compiler import compile_contract_file
from pons.local_provider import LocalProvider


@pytest.fixture
Expand Down
2 changes: 1 addition & 1 deletion tests/test_compiler.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from pathlib import Path

from pons import EVMVersion, compile_contract_file
from pons.compiler import EVMVersion, compile_contract_file


def test_multiple_contracts() -> None:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
Method,
Receive,
abi,
compile_contract_file,
)
from pons._abi_types import encode_args
from pons.compiler import compile_contract_file


@pytest.fixture
Expand Down
5 changes: 2 additions & 3 deletions tests/test_contract_functionality.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,17 @@
Constructor,
ContractABI,
DeployedContract,
EVMVersion,
Method,
Mutability,
abi,
compile_contract_file,
)
from pons.compiler import compile_contract_file


@pytest.fixture
def compiled_contracts() -> dict[str, CompiledContract]:
path = Path(__file__).resolve().parent / "TestContractFunctionality.sol"
return compile_contract_file(path, evm_version=EVMVersion.CANCUN)
return compile_contract_file(path)


async def test_empty_constructor(
Expand Down
4 changes: 3 additions & 1 deletion tests/test_http_provider_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
import trio
from ethereum_rpc import RPCError, RPCErrorCode

from pons import HTTPProviderServer, LocalProvider, ProviderError
from pons import ProviderError
from pons._provider import RPC_JSON, ProviderSession
from pons.http_provider_server import HTTPProviderServer
from pons.local_provider import LocalProvider


@pytest.fixture
Expand Down
3 changes: 2 additions & 1 deletion tests/test_local_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
import pytest
from ethereum_rpc import Amount

from pons import AccountSigner, Client, ClientSession, LocalProvider, ProviderError
from pons import AccountSigner, Client, ClientSession, ProviderError
from pons.local_provider import LocalProvider


# Masking the global fixtures to make this test self-contained
Expand Down
2 changes: 1 addition & 1 deletion tests/test_multicall.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
ContractLegacyError,
DeployedContract,
Multicall,
compile_contract_file,
)
from pons.compiler import compile_contract_file


@pytest.fixture
Expand Down
Loading