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

Fork Definitions as Classes #91

Merged
merged 8 commits into from
Mar 30, 2023
Merged
Show file tree
Hide file tree
Changes from 7 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
4 changes: 2 additions & 2 deletions docs/tutorials/01_state_transition.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ from ethereum_test_tools import (
)
```

Next the following constants, types and helper functions are imported from `ethereum_test_tools`. We will go over these as we come across them.
Next the following constants, types and helper functions are imported from `ethereum_test_tools` and `ethereum_test_forks`. We will go over these as we come across them.


```python
@test_from("berlin")
@test_from(Berlin)
```

In Python this kind of definition is called a [*decorator*](https://docs.python.org/3/search.html?q=decorator).
Expand Down
10 changes: 5 additions & 5 deletions fillers/eips/eip3651.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"""
from typing import Dict

from ethereum_test_forks import Shanghai, is_fork
from ethereum_test_tools import (
Account,
CodeGasMeasure,
Expand All @@ -13,7 +14,6 @@
TestAddress,
Transaction,
Yul,
is_fork,
test_from,
to_address,
to_hash,
Expand All @@ -24,7 +24,7 @@
REFERENCE_SPEC_VERSION = "cd7d6a465c03d86d852a1d6b5179bc78d760e658"


@test_from(fork="shanghai")
@test_from(fork=Shanghai)
def test_warm_coinbase_call_out_of_gas(fork):
"""
Test warm coinbase.
Expand Down Expand Up @@ -141,7 +141,7 @@ def test_warm_coinbase_call_out_of_gas(fork):

post = {}

if is_fork(fork=fork, which="shanghai"):
if is_fork(fork=fork, which=Shanghai):
post["0xcccccccccccccccccccccccccccccccccccccccc"] = Account(
storage={
# On shanghai and beyond, calls with only 100 gas to
Expand All @@ -167,7 +167,7 @@ def test_warm_coinbase_call_out_of_gas(fork):
)


@test_from(fork="shanghai")
@test_from(fork=Shanghai)
def test_warm_coinbase_gas_usage(fork):
"""
Test gas usage of different opcodes assuming warm coinbase.
Expand Down Expand Up @@ -241,7 +241,7 @@ def test_warm_coinbase_gas_usage(fork):
),
}

if is_fork(fork, "shanghai"):
if is_fork(fork, Shanghai):
expected_gas = 100 # Warm account access cost after EIP-3651
else:
expected_gas = 2600 # Cold account access cost before EIP-3651
Expand Down
4 changes: 2 additions & 2 deletions fillers/eips/eip3855.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
EIP: https://eips.ethereum.org/EIPS/eip-3855
Source tests: https://github.com/ethereum/tests/pull/1033
"""

from ethereum_test_forks import Shanghai
from ethereum_test_tools import (
Account,
CodeGasMeasure,
Expand All @@ -21,7 +21,7 @@
REFERENCE_SPEC_VERSION = "0820a03563f3b7710c347732a73bcb5b1c925416"


@test_from(fork="shanghai")
@test_from(fork=Shanghai)
def test_push0(fork):
"""
Test push0 opcode.
Expand Down
9 changes: 5 additions & 4 deletions fillers/eips/eip3860.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

from typing import Any, Dict

from ethereum_test_forks import Shanghai
from ethereum_test_tools import (
Account,
Block,
Expand Down Expand Up @@ -232,7 +233,7 @@ def generate_tx_initcode_limit_test_cases(
)


@test_from(fork="shanghai")
@test_from(fork=Shanghai)
def test_initcode_limit_contract_creating_tx(fork):
"""
Test creating a contract using a transaction using an initcode that is
Expand Down Expand Up @@ -395,7 +396,7 @@ def generate_gas_cost_test_cases(
)


@test_from(fork="shanghai")
@test_from(fork=Shanghai)
def test_initcode_limit_contract_creating_tx_gas_usage(fork):
"""
Test EIP-3860 Limit Initcode Gas Usage for a contract
Expand Down Expand Up @@ -609,7 +610,7 @@ def generate_create_opcode_initcode_test_cases(
)


@test_from(fork="shanghai")
@test_from(fork=Shanghai)
def test_initcode_limit_create_opcode(fork):
"""
Test creating a contract using the CREATE opcode with an initcode that is
Expand Down Expand Up @@ -676,7 +677,7 @@ def test_initcode_limit_create_opcode(fork):
)


@test_from(fork="shanghai")
@test_from(fork=Shanghai)
def test_initcode_limit_create2_opcode(fork):
"""
Test creating a contract using the CREATE2 opcode with an initcode that is
Expand Down
15 changes: 9 additions & 6 deletions fillers/example/acl_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
Test ACL Transaction Source Code Examples
"""

from ethereum_test_forks import Berlin, Fork, London, is_fork
from ethereum_test_tools import AccessList, Account, Environment
from ethereum_test_tools import Opcodes as Op
from ethereum_test_tools import StateTest, Transaction, test_from_until


@test_from_until("berlin", "london")
def test_access_list(fork):
@test_from_until(Berlin, London)
def test_access_list(fork: Fork):
"""
Test type 1 transaction.
"""
Expand All @@ -21,7 +22,7 @@ def test_access_list(fork):
nonce=1,
),
"0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b": Account(
balance=0x100000,
balance=0x300000,
nonce=0,
),
}
Expand All @@ -33,7 +34,7 @@ def test_access_list(fork):
to="0x000000000000000000000000000000000000aaaa",
value=1,
gas_limit=323328,
gas_price=1,
gas_price=7,
access_list=[
AccessList(
address="0x0000000000000000000000000000000000000000",
Expand All @@ -53,10 +54,12 @@ def test_access_list(fork):
nonce=1,
),
"0x2adc25665018aa1fe0e6bc666dac8fc2697ff9ba": Account(
balance=0x1BC16D674EC87342
balance=0x1BC16D674EC80000
if is_fork(fork, London)
else 0x1BC16D674ECB26CE,
),
"0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b": Account(
balance=0xF8CBD,
balance=0x2CD931,
nonce=1,
),
}
Expand Down
4 changes: 2 additions & 2 deletions fillers/example/yul_example.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
Test Yul Source Code Examples
"""

from ethereum_test_forks import Berlin
from ethereum_test_tools import (
Account,
Environment,
Expand All @@ -13,7 +13,7 @@
)


@test_from("berlin")
@test_from(Berlin)
def test_yul(fork):
"""
Test YUL compiled bytecode.
Expand Down
3 changes: 2 additions & 1 deletion fillers/vm/chain_id.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Test EIP-1344 CHAINID opcode
"""

from ethereum_test_forks import Istanbul
from ethereum_test_tools import (
Account,
Environment,
Expand All @@ -11,7 +12,7 @@
)


@test_from("istanbul")
@test_from(Istanbul)
def test_chain_id(fork):
"""
Test CHAINID opcode.
Expand Down
3 changes: 2 additions & 1 deletion fillers/vm/dup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Test DUP opcodes
"""

from ethereum_test_forks import Istanbul
from ethereum_test_tools import (
Account,
Environment,
Expand All @@ -12,7 +13,7 @@
)


@test_from("istanbul")
@test_from(Istanbul)
def test_dup(fork):
"""
Test DUP1-DUP16 opcodes.
Expand Down
5 changes: 3 additions & 2 deletions fillers/withdrawals/withdrawals.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from typing import List

from ethereum_test_forks import Shanghai
from ethereum_test_tools import (
Account,
Block,
Expand All @@ -21,7 +22,7 @@
REFERENCE_SPEC_GIT_PATH = "EIPS/eip-4895.md"
REFERENCE_SPEC_VERSION = "0966bbc3ff92127c0a729ce5455bbc35fd2075b8"

WITHDRAWALS_FORK = "shanghai"
WITHDRAWALS_FORK = Shanghai

ONE_GWEI = 10**9

Expand Down Expand Up @@ -676,7 +677,7 @@ def test_zero_amount(_):


@test_from(WITHDRAWALS_FORK)
def test_large_amount(_: str):
def test_large_amount(_):
"""
Test Withdrawals that have a large gwei amount, so that (gwei * 1e9)
could overflow uint64 but not uint256.
Expand Down
4 changes: 4 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ classifiers =
packages =
evm_block_builder
evm_transition_tool
ethereum_test_forks
ethereum_test_tools
ethereum_test_filling_tool

Expand All @@ -31,6 +32,8 @@ install_requires =
[options.package_data]
ethereum_test_tools =
py.typed
ethereum_test_forks =
py.typed
evm_transition_tool =
py.typed
evm_block_builder =
Expand Down Expand Up @@ -87,5 +90,6 @@ extend-exclude =
src/evm_block_builder/tests/
src/evm_transition_tool/tests/
src/ethereum_test_tools/tests/
src/ethereum_test_forks/tests/

# vim: set ft=dosini:
Loading