Skip to content

Commit

Permalink
Move RPC types to their own package
Browse files Browse the repository at this point in the history
  • Loading branch information
fjarri committed May 29, 2024
1 parent 588ea64 commit 8fef67b
Show file tree
Hide file tree
Showing 35 changed files with 412 additions and 1,277 deletions.
7 changes: 3 additions & 4 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,9 @@ jobs:
pdm run py.test --cov=pons --cov-report=xml tests
- name: Upload coverage
if: matrix.python-version == '3.10'
run: |
curl -Os https://uploader.codecov.io/latest/linux/codecov
chmod +x codecov
./codecov
uses: codecov/codecov-action@v4.0.1
with:
token: ${{ secrets.CODECOV_TOKEN }}

doctest:
runs-on: ubuntu-latest
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ For more information see [the documentation](https://pons.readthedocs.io/en/late
[pypi-license-image]: https://img.shields.io/pypi/l/pons
[rtd-image]: https://readthedocs.org/projects/pons/badge/?version=latest
[rtd-link]: https://pons.readthedocs.io/en/latest/
[cov-image]: https://codecov.io/gh/fjarri/pons/branch/master/graph/badge.svg?token=RZP1LK1HB2
[cov-link]: https://codecov.io/gh/fjarri/pons
[cov-image]: https://codecov.io/gh/fjarri-eth/pons/branch/master/graph/badge.svg?token=RZP1LK1HB2
[cov-link]: https://codecov.io/gh/fjarri-eth/pons
[black-image]: https://img.shields.io/badge/code%20style-black-000000.svg
[black-link]: https://github.com/psf/black
75 changes: 22 additions & 53 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,6 @@ Errors

.. autoclass:: pons.TransactionFailed

.. autoclass:: pons._provider.RPCError
:members:

.. autoclass:: pons._provider.RPCErrorCode
:members:

.. autoclass:: pons.ProviderError()
:show-inheritance:
:members:
Expand Down Expand Up @@ -131,15 +125,32 @@ Testing utilities

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

Install with the feature ``local-provider`` for it to be available.


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

.. autoclass:: SnapshotID

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


Compiler
--------

Install with the feature ``compiler`` for it to be available.


.. autofunction:: compile_contract_file

.. autoclass:: EVMVersion
:members:


Secondary classes
-----------------

Expand Down Expand Up @@ -205,56 +216,14 @@ Compiled and deployed contracts
:members:


Entities
--------

.. autoclass:: Amount
:members:

.. class:: pons._entities.CustomAmount

A type derived from :py:class:`Amount`.

.. autoclass:: Address
:members:

.. class:: pons._entities.CustomAddress

A type derived from :py:class:`Address`.

.. autoclass:: Block()
:members:

.. autoclass:: TxHash
:members:

.. autoclass:: BlockHash
:members:

.. autoclass:: pons._entities.TxReceipt()
:members:

.. autoclass:: pons._entities.BlockInfo()
:members:

.. autoclass:: pons._entities.TxInfo()
:members:

.. autoclass:: pons._entities.BlockFilter()

.. autoclass:: pons._entities.PendingTransactionFilter()

.. autoclass:: pons._entities.LogFilter()

.. autoclass:: pons._entities.LogTopic()
Filter objects
--------------

.. autoclass:: pons._entities.LogEntry()
:members:
.. autoclass:: pons._client.BlockFilter()

.. class:: JSON
.. autoclass:: pons._client.PendingTransactionFilter()

A JSON-ifiable object (``bool``, ``int``, ``float``, ``str``, ``None``,
iterable of ``JSON``, or mapping of ``str`` to ``JSON``).
.. autoclass:: pons._client.LogFilter()


Solidity types
Expand Down
70 changes: 36 additions & 34 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Changed
- Bumped the minimum Python version to 3.10. (PR_72_)
- The entities are now dataclasses instead of namedtuples. (PR_75_)
- Bumped ``eth-account`` to ``0.13``. (PR_76_)
- Use the types from ``ethereum-rpc``. (PR_77_)


Added
Expand Down Expand Up @@ -52,23 +53,24 @@ Fixed
- Expect the block number to be non-null even for pending blocks, since that's what providers return. (PR_70_)


.. _PR_51: https://github.com/fjarri/pons/pull/51
.. _PR_52: https://github.com/fjarri/pons/pull/52
.. _PR_54: https://github.com/fjarri/pons/pull/54
.. _PR_56: https://github.com/fjarri/pons/pull/56
.. _PR_57: https://github.com/fjarri/pons/pull/57
.. _PR_59: https://github.com/fjarri/pons/pull/59
.. _PR_61: https://github.com/fjarri/pons/pull/61
.. _PR_62: https://github.com/fjarri/pons/pull/62
.. _PR_63: https://github.com/fjarri/pons/pull/63
.. _PR_64: https://github.com/fjarri/pons/pull/64
.. _PR_65: https://github.com/fjarri/pons/pull/65
.. _PR_67: https://github.com/fjarri/pons/pull/67
.. _PR_68: https://github.com/fjarri/pons/pull/68
.. _PR_70: https://github.com/fjarri/pons/pull/70
.. _PR_72: https://github.com/fjarri/pons/pull/72
.. _PR_75: https://github.com/fjarri/pons/pull/75
.. _PR_76: https://github.com/fjarri/pons/pull/76
.. _PR_51: https://github.com/fjarri-eth/pons/pull/51
.. _PR_52: https://github.com/fjarri-eth/pons/pull/52
.. _PR_54: https://github.com/fjarri-eth/pons/pull/54
.. _PR_56: https://github.com/fjarri-eth/pons/pull/56
.. _PR_57: https://github.com/fjarri-eth/pons/pull/57
.. _PR_59: https://github.com/fjarri-eth/pons/pull/59
.. _PR_61: https://github.com/fjarri-eth/pons/pull/61
.. _PR_62: https://github.com/fjarri-eth/pons/pull/62
.. _PR_63: https://github.com/fjarri-eth/pons/pull/63
.. _PR_64: https://github.com/fjarri-eth/pons/pull/64
.. _PR_65: https://github.com/fjarri-eth/pons/pull/65
.. _PR_67: https://github.com/fjarri-eth/pons/pull/67
.. _PR_68: https://github.com/fjarri-eth/pons/pull/68
.. _PR_70: https://github.com/fjarri-eth/pons/pull/70
.. _PR_72: https://github.com/fjarri-eth/pons/pull/72
.. _PR_75: https://github.com/fjarri-eth/pons/pull/75
.. _PR_76: https://github.com/fjarri-eth/pons/pull/76
.. _PR_77: https://github.com/fjarri-eth/pons/pull/77


0.7.0 (09-07-2023)
Expand All @@ -88,9 +90,9 @@ Added
- ``Mutability`` enum for defining contract method mutability. (PR_50_)


.. _PR_48: https://github.com/fjarri/pons/pull/48
.. _PR_49: https://github.com/fjarri/pons/pull/49
.. _PR_50: https://github.com/fjarri/pons/pull/50
.. _PR_48: https://github.com/fjarri-eth/pons/pull/48
.. _PR_49: https://github.com/fjarri-eth/pons/pull/49
.. _PR_50: https://github.com/fjarri-eth/pons/pull/50



Expand All @@ -115,7 +117,7 @@ Fixed
- Support the existence of outputs in the JSON ABI of a mutating method. (PR_47_)


.. _PR_47: https://github.com/fjarri/pons/pull/47
.. _PR_47: https://github.com/fjarri-eth/pons/pull/47


0.5.1 (14-11-2022)
Expand All @@ -127,7 +129,7 @@ Fixed
- A bug in processing keyword arguments to contract calls. (PR_42_)


.. _PR_42: https://github.com/fjarri/pons/pull/42
.. _PR_42: https://github.com/fjarri-eth/pons/pull/42


0.5.0 (14-09-2022)
Expand All @@ -145,8 +147,8 @@ Fixed
- Return type of classmethods of ``Amount`` and ``Address`` now provides correct information to ``mypy`` in dependent projects. (PR_37_)


.. _PR_37: https://github.com/fjarri/pons/pull/37
.. _PR_40: https://github.com/fjarri/pons/pull/40
.. _PR_37: https://github.com/fjarri-eth/pons/pull/37
.. _PR_40: https://github.com/fjarri-eth/pons/pull/40


0.4.2 (05-06-2022)
Expand All @@ -170,8 +172,8 @@ Fixed
- Removed ``TxReceipt`` export (making an exception here and not counting it as a breaking change, since nobody would have any use for creating one manually). (PR_32_)


.. _PR_32: https://github.com/fjarri/pons/pull/32
.. _PR_33: https://github.com/fjarri/pons/pull/33
.. _PR_32: https://github.com/fjarri-eth/pons/pull/32
.. _PR_33: https://github.com/fjarri-eth/pons/pull/33


0.4.1 (01-05-2022)
Expand All @@ -185,9 +187,9 @@ Added
- Support for gas overrides in ``transfer()``, ``transact()``, and ``deploy()``. (PR_30_)


.. _PR_27: https://github.com/fjarri/pons/pull/27
.. _PR_29: https://github.com/fjarri/pons/pull/29
.. _PR_30: https://github.com/fjarri/pons/pull/30
.. _PR_27: https://github.com/fjarri-eth/pons/pull/27
.. _PR_29: https://github.com/fjarri-eth/pons/pull/29
.. _PR_30: https://github.com/fjarri-eth/pons/pull/30


0.4.0 (23-04-2022)
Expand All @@ -214,8 +216,8 @@ Added
- ``RemoteError`` and ``Unreachable`` exception types to report errors from client sessions in a standardized way. (PR_5_)


.. _PR_4: https://github.com/fjarri/pons/pull/4
.. _PR_5: https://github.com/fjarri/pons/pull/5
.. _PR_4: https://github.com/fjarri-eth/pons/pull/4
.. _PR_5: https://github.com/fjarri-eth/pons/pull/5


0.3.0 (03-04-2022)
Expand All @@ -236,9 +238,9 @@ Fixed
- Replaced assertions with more informative exceptions. (PR_3_)


.. _PR_1: https://github.com/fjarri/pons/pull/1
.. _PR_2: https://github.com/fjarri/pons/pull/2
.. _PR_3: https://github.com/fjarri/pons/pull/3
.. _PR_1: https://github.com/fjarri-eth/pons/pull/1
.. _PR_2: https://github.com/fjarri-eth/pons/pull/2
.. _PR_3: https://github.com/fjarri-eth/pons/pull/3


0.2.0 (19-03-2022)
Expand Down
3 changes: 2 additions & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,6 @@

intersphinx_mapping = {
"python": ("https://docs.python.org/3", None),
"eth_account": ("https://eth-account.readthedocs.io/en/stable/", None),
"eth_account": ("https://eth-account.readthedocs.io/en/v0.13.0/", None),
"ethereum_rpc": ("https://ethereum-rpc.readthedocs.io/en/v0.1.0", None),
}
8 changes: 5 additions & 3 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ A quick usage example:
import trio
import pons
import eth_account
import ethereum_rpc

from pons import LocalProvider, HTTPProviderServer, Amount
from ethereum_rpc import Amount
from pons import LocalProvider, HTTPProviderServer

# Run examples with our test server in the background

Expand Down Expand Up @@ -46,15 +48,15 @@ A quick usage example:

# So that we don't have to use real addresses

orig_Address_from_hex = pons.Address.from_hex
orig_Address_from_hex = ethereum_rpc.Address.from_hex

def mock_Address_from_hex(address_hex):
if address_hex == "0x<another_address>":
return Address(os.urandom(20))
else:
return orig_Address_from_hex(address_hex)

pons.Address.from_hex = mock_Address_from_hex
ethereum_rpc.Address.from_hex = mock_Address_from_hex

# This function will start a test server and fill in some global variables

Expand Down
2 changes: 1 addition & 1 deletion docs/tutorial.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Amounts and addresses
---------------------

Native currency amounts and network addresses are typed in ``pons``.
All methods expect and return only :py:class:`~pons.Amount` and :py:class:`~pons.Address` objects --- no integers or strings allowed.
All methods expect and return only :py:class:`ethereum_rpc.Amount` and :py:class:`ethereum_rpc.Address` objects --- no integers or strings allowed.

In an application using ``pons`` one can superclass these classes to distinguish between different types of currencies, or addresses from different networks.
Note though that all the arithmetic and comparison functions require **strict** type equality and raise an exception if it is not the case, to protect from accidental usage of addresses/amounts from wrong domains.
Expand Down
Loading

0 comments on commit 8fef67b

Please sign in to comment.