Skip to content

Commit

Permalink
Merge pull request #74 from fjarri/alysis-updates
Browse files Browse the repository at this point in the history
Bump `alysis` to v0.3
  • Loading branch information
fjarri authored Mar 9, 2024
2 parents 2aebdd8 + 7fd163c commit 68e4585
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 55 deletions.
96 changes: 48 additions & 48 deletions pdm.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions pons/_entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,9 @@ class TxInfo(NamedTuple):
hash_: TxHash
"""Transaction hash."""

input_: None | bytes
"""The data sent along with the transaction."""

block_hash: None | BlockHash
"""The hash of the block this transaction belongs to. ``None`` for pending transactions."""

Expand Down Expand Up @@ -335,6 +338,7 @@ def rpc_decode(cls, val: ResponseDict) -> "TxInfo":
return cls(
type_=rpc_decode_quantity(val["type"]),
hash_=TxHash.rpc_decode(val["hash"]),
input_=rpc_decode_data(val["input"]) or None,
block_hash=BlockHash.rpc_decode(val["blockHash"]) if val["blockHash"] else None,
block_number=rpc_decode_quantity(val["blockNumber"]),
transaction_index=(
Expand Down
2 changes: 1 addition & 1 deletion pons/_http_provider_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ async def process_request_inner(provider: Provider, request: JSON) -> tuple[JSON
try:
request_id, method, params = parse_request(request)
except (KeyError, TypeError) as exc:
raise RPCError.invalid_request() from exc # noqa: RSE102
raise RPCError.invalid_request() from exc

async with provider.session() as session:
result = await session.rpc(method, *params)
Expand Down
11 changes: 9 additions & 2 deletions pons/_local_provider.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
"""PyEVM-based provider for tests."""

import itertools
from collections.abc import AsyncIterator
from contextlib import asynccontextmanager
from copy import deepcopy
from typing import Any

from alysis import Node, RPCNode
Expand Down Expand Up @@ -31,6 +33,8 @@ def __init__(self, *, root_balance: Amount, chain_id: int = 1):
self._rpc_node = RPCNode(self._local_node)
self.root = AccountSigner(Account.from_key(self._local_node.root_private_key))
self._default_address = self.root.address
self._snapshot_counter = itertools.count()
self._snapshots: dict[int, Node] = {}

def disable_auto_mine_transactions(self) -> None:
"""Disable mining a new block after each transaction."""
Expand All @@ -45,11 +49,14 @@ def enable_auto_mine_transactions(self) -> None:

def take_snapshot(self) -> SnapshotID:
"""Creates a snapshot of the chain state internally and returns its ID."""
return SnapshotID(self._local_node.take_snapshot())
snapshot_id = next(self._snapshot_counter)
self._snapshots[snapshot_id] = deepcopy(self._local_node)
return SnapshotID(snapshot_id)

def revert_to_snapshot(self, snapshot_id: SnapshotID) -> None:
"""Restores the chain state to the snapshot with the given ID."""
self._local_node.revert_to_snapshot(snapshot_id.id_)
self._local_node = self._snapshots[snapshot_id.id_]
self._rpc_node = RPCNode(self._local_node)

def rpc(self, method: str, *args: Any) -> JSON:
try:
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ compiler = [
"py-solc-x>=2",
]
local-provider = [
"alysis>=0.2.0",
"alysis>=0.3.0",
"starlette",
"hypercorn",
]
Expand All @@ -39,7 +39,7 @@ tests = [
# from `compiler` feature
"py-solc-x>=2",
# from `local-provider` feature
"alysis>=0.1.2",
"alysis>=0.3.0",
"starlette",
"hypercorn",
]
Expand Down
1 change: 1 addition & 0 deletions tests/test_entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ def test_decode_block_info():
"gas": "0xd0b3",
"gasPrice": "0xcf7b50fb6",
"hash": "0x4eeae930617ad553af25a809f11051451e7f4a2597af6e8eae6ed446b94d6532",
"input": "0x632a5607",
"maxFeePerGas": "0xcfad7001d",
"maxPriorityFeePerGas": "0x12a05f200",
"nonce": "0x1317",
Expand Down
4 changes: 2 additions & 2 deletions tests/test_local_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,9 @@ async def test_snapshots(provider, session, root_signer, another_signer):
dest = another_signer.address
latest = rpc_encode_block(Block.LATEST)

await session.broadcast_transfer(root_signer, dest, amount)
await session.transfer(root_signer, dest, amount)
snapshot_id = provider.take_snapshot()
await session.broadcast_transfer(root_signer, dest, amount)
await session.transfer(root_signer, dest, amount)
assert provider.rpc("eth_getBalance", dest.rpc_encode(), latest) == double_amount.rpc_encode()

provider.revert_to_snapshot(snapshot_id)
Expand Down

0 comments on commit 68e4585

Please sign in to comment.