Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce Python type stubs for the bindings #1

Merged
merged 2 commits into from
Oct 2, 2022
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
149 changes: 120 additions & 29 deletions poetry.lock

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

2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ maturin = "^0.13.5"
pytest = "^7.1.3"

[tool.poetry.dev-dependencies]
black = "^22.8.0"
mypy = "^0.981"

[build-system]
requires = ["maturin>=0.13,<0.14"]
Expand Down
84 changes: 84 additions & 0 deletions pyrevm.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
from typing import Optional, Type

class CfgEnv:
def __new__(cls: Type["CfgEnv"]) -> "CfgEnv": ...

class BlockEnv:
def __new__(
cls: Type["BlockEnv"],
number: Optional[int] = None,
coinbase: Optional[str] = None,
timestamp: Optional[int] = None,
difficulty: Optional[int] = None,
basefee: Optional[int] = None,
gas_limit: Optional[int] = None,
) -> "BlockEnv": ...

class TxEnv:
def __new__(
cls: Type["TxEnv"],
caller: Optional[str] = None,
gas_limit: Optional[int] = None,
gas_price: Optional[int] = None,
gas_priority_fee: Optional[int] = None,
to: Optional[str] = None,
value: Optional[int] = None,
data: Optional[list[int]] = None,
chain_id: Optional[int] = None,
nonce: Optional[int] = None,
) -> "TxEnv": ...

class Env:
def __new__(
cls: Type["Env"],
cfg: Optional[CfgEnv] = None,
block: Optional[BlockEnv] = None,
tx: Optional[TxEnv] = None,
) -> "Env": ...

class AccountInfo:
@property
def balance(self: "AccountInfo") -> int: ...
@property
def nonce(self: "AccountInfo") -> int: ...
@property
def code(self: "AccountInfo") -> list[int]: ...
@property
def code_hash(self: "AccountInfo") -> list[int]: ...
def __new__(
cls: Type["AccountInfo"],
nonce: int,
code_hash: Optional[bytes] = None,
code: Optional[bytes] = None,
) -> "AccountInfo": ...

class EvmOpts:
env: Env
fork_url: Optional[str]
fork_block_number: Optional[int]
gas_limit: int
tracing: bool
def __new__(
cls: Type["EvmOpts"],
env: Optional[Env],
fork_url: Optional[str],
) -> "EvmOpts": ...

class EVM:
def __new__(
cls: Type["EVM"],
env: Optional[Env] = None,
fork_url: Optional[str] = None,
fork_block_number: Optional[int] = None,
gas_limit: int = 18446744073709551615,
tracing: bool = False,
) -> "EVM": ...
def basic(self: "EVM", address: str) -> Optional[AccountInfo]: ...
def insert_account_info(self: "EVM", address: str, info: AccountInfo) -> None: ...
def call_raw_committing(
self: "EVM",
caller: str,
to: str,
value: Optional[int] = None,
data: Optional[list[int]] = None,
) -> None: ...
26 changes: 14 additions & 12 deletions pytest/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,36 @@

from pyrevm import *

address = "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045" # vitalik.eth
address = "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045" # vitalik.eth
address2 = "0xBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB"

fork_url = "https://mainnet.infura.io/v3/c60b0bb42f8a4c6481ecd229eddaca27"


def test_revm():
# set up an evm
evm = EVM(
# can fork from a remote node
fork_url=fork_url,
fork_url=fork_url,
# can set tracing to true/false
tracing = True,
tracing=True,
# can configure the environment
env = Env(
block = BlockEnv( timestamp = 100
))
);
env=Env(block=BlockEnv(timestamp=100)),
)

vb_before = evm.basic(address)
assert vb_before != 0

# Execute the tx
evm.call_raw_committing(
caller = address,
to = address2,
value = 10000
caller=address,
to=address2,
value=10000
# data
);
)

info = evm.basic(address2)

assert info is not None
assert vb_before != evm.basic(address)
assert evm.basic(address2).balance == 10000
assert info.balance == 10000