Skip to content

Commit

Permalink
Add type stubs and fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ziyadedher committed Oct 2, 2022
1 parent e348aa7 commit 1a9c440
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 12 deletions.
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

0 comments on commit 1a9c440

Please sign in to comment.