Skip to content

Commit

Permalink
tests: Fix all state_test usages to have a single transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
marioevz committed Dec 14, 2023
1 parent 44d0153 commit e8d1798
Show file tree
Hide file tree
Showing 19 changed files with 164 additions and 181 deletions.
9 changes: 2 additions & 7 deletions tests/berlin/eip2930_access_list/test_acl.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import pytest

from ethereum_test_forks import 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 StateTestFiller, Transaction
Expand All @@ -14,8 +13,7 @@


@pytest.mark.valid_from("Berlin")
@pytest.mark.valid_until("London")
def test_access_list(state_test: StateTestFiller, fork: Fork):
def test_access_list(state_test: StateTestFiller):
"""
Test type 1 transaction.
"""
Expand Down Expand Up @@ -59,12 +57,9 @@ def test_access_list(state_test: StateTestFiller, fork: Fork):
balance=4,
nonce=1,
),
"0x2adc25665018aa1fe0e6bc666dac8fc2697ff9ba": Account(
balance=0x1BC16D674EC80000 if is_fork(fork, London) else 0x1BC16D674ECB26CE,
),
"0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b": Account(
balance=0x2CD931,
nonce=1,
),
}
state_test(env=env, pre=pre, post=post, txs=[tx])
state_test(env=env, pre=pre, post=post, tx=tx)
70 changes: 30 additions & 40 deletions tests/cancun/eip1153_tstore/test_tstorage.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,19 @@ def test_transient_storage_unset_values(state_test: StateTestFiller):
code_address: Account(code=code, storage={slot: 1 for slot in slots_under_test}),
}

txs = [
Transaction(
to=code_address,
data=b"",
gas_limit=1_000_000,
)
]
tx = Transaction(
to=code_address,
data=b"",
gas_limit=1_000_000,
)

post = {code_address: Account(storage={slot: 0 for slot in slots_under_test})}

state_test(
env=env,
pre=pre,
post=post,
txs=txs,
tx=tx,
)


Expand All @@ -79,21 +77,19 @@ def test_tload_after_tstore(state_test: StateTestFiller):
code_address: Account(code=code, storage={slot: 0 for slot in slots_under_test}),
}

txs = [
Transaction(
to=code_address,
data=b"",
gas_limit=1_000_000,
)
]
tx = Transaction(
to=code_address,
data=b"",
gas_limit=1_000_000,
)

post = {code_address: Account(storage={slot: slot for slot in slots_under_test})}

state_test(
env=env,
pre=pre,
post=post,
txs=txs,
tx=tx,
)


Expand All @@ -119,13 +115,11 @@ def test_tload_after_sstore(state_test: StateTestFiller):
code_address: Account(code=code, storage={slot: 1 for slot in slots_under_test}),
}

txs = [
Transaction(
to=code_address,
data=b"",
gas_limit=1_000_000,
)
]
tx = Transaction(
to=code_address,
data=b"",
gas_limit=1_000_000,
)

post = {
code_address: Account(
Expand All @@ -139,7 +133,7 @@ def test_tload_after_sstore(state_test: StateTestFiller):
env=env,
pre=pre,
post=post,
txs=txs,
tx=tx,
)


Expand All @@ -166,13 +160,11 @@ def test_tload_after_tstore_is_zero(state_test: StateTestFiller):
),
}

txs = [
Transaction(
to=code_address,
data=b"",
gas_limit=1_000_000,
)
]
tx = Transaction(
to=code_address,
data=b"",
gas_limit=1_000_000,
)

post = {
code_address: Account(
Expand All @@ -184,7 +176,7 @@ def test_tload_after_tstore_is_zero(state_test: StateTestFiller):
env=env,
pre=pre,
post=post,
txs=txs,
tx=tx,
)


Expand Down Expand Up @@ -244,15 +236,13 @@ def test_gas_usage(
TestAddress: Account(balance=10_000_000, nonce=0),
code_address: Account(code=gas_measure_bytecode),
}
txs = [
Transaction(
to=code_address,
data=b"",
gas_limit=1_000_000,
)
]
tx = Transaction(
to=code_address,
data=b"",
gas_limit=1_000_000,
)
post = {
code_address: Account(code=gas_measure_bytecode, storage={0: expected_gas}),
TestAddress: Account(nonce=1),
}
state_test(env=env, pre=pre, txs=txs, post=post)
state_test(env=env, pre=pre, tx=tx, post=post)
Original file line number Diff line number Diff line change
Expand Up @@ -237,5 +237,5 @@ def test_contract_creation(
env=Environment(),
pre=pre,
post=post,
txs=[tx],
tx=tx,
)
16 changes: 7 additions & 9 deletions tests/cancun/eip1153_tstore/test_tstorage_execution_contexts.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
""" # noqa: E501

from enum import EnumMeta, unique
from typing import List, Mapping
from typing import Mapping

import pytest

Expand Down Expand Up @@ -314,12 +314,10 @@ def __init__(self, value):
caller_address: Account(code=value["caller_bytecode"]),
callee_address: Account(code=value["callee_bytecode"]),
},
"txs": [
Transaction(
to=caller_address,
gas_limit=1_000_000,
)
],
"tx": Transaction(
to=caller_address,
gas_limit=1_000_000,
),
"post": {
caller_address: Account(storage=value["expected_caller_storage"]),
callee_address: Account(storage=value["expected_callee_storage"]),
Expand All @@ -333,7 +331,7 @@ def test_subcall(
state_test: StateTestFiller,
env: Environment,
pre: Mapping,
txs: List[Transaction],
tx: Transaction,
post: Mapping,
):
"""
Expand All @@ -344,4 +342,4 @@ def test_subcall(
- `DELEGATECALL`
- `STATICCALL`
"""
state_test(env=env, pre=pre, post=post, txs=txs)
state_test(env=env, pre=pre, post=post, tx=tx)
Original file line number Diff line number Diff line change
Expand Up @@ -279,4 +279,4 @@ def test_reentrant_call(state_test: StateTestFiller, bytecode, expected_storage)

post = {callee_address: Account(code=bytecode, storage=expected_storage)}

state_test(env=env, pre=pre, post=post, txs=[tx])
state_test(env=env, pre=pre, post=post, tx=tx)
2 changes: 1 addition & 1 deletion tests/cancun/eip1153_tstore/test_tstorage_selfdestruct.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,4 +249,4 @@ def test_reentrant_selfdestructing_call(
else:
post[callee_address] = Account.NONEXISTENT

state_test(env=env, pre=pre, post=post, txs=[tx])
state_test(env=env, pre=pre, post=post, tx=tx)
22 changes: 12 additions & 10 deletions tests/cancun/eip4788_beacon_root/test_beacon_root_contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def test_beacon_root_contract_calls(
state_test(
env=env,
pre=pre,
txs=[tx],
tx=tx,
post=post,
)

Expand Down Expand Up @@ -138,7 +138,7 @@ def test_beacon_root_contract_timestamps(
state_test(
env=env,
pre=pre,
txs=[tx],
tx=tx,
post=post,
)

Expand Down Expand Up @@ -169,7 +169,7 @@ def test_calldata_lengths(
state_test(
env=env,
pre=pre,
txs=[tx],
tx=tx,
post=post,
)

Expand Down Expand Up @@ -202,7 +202,7 @@ def test_beacon_root_equal_to_timestamp(
state_test(
env=env,
pre=pre,
txs=[tx],
tx=tx,
post=post,
)

Expand All @@ -224,7 +224,7 @@ def test_tx_to_beacon_root_contract(
state_test(
env=env,
pre=pre,
txs=[tx],
tx=tx,
post=post,
)

Expand Down Expand Up @@ -254,7 +254,7 @@ def test_invalid_beacon_root_calldata_value(
state_test(
env=env,
pre=pre,
txs=[tx],
tx=tx,
post=post,
)

Expand All @@ -281,12 +281,14 @@ def test_beacon_root_selfdestruct(
code=Op.CALL(100000, Op.PUSH20(to_address(0x1337)), 0, 0, 0, 0, 0)
+ Op.SSTORE(0, Op.BALANCE(Spec.BEACON_ROOTS_ADDRESS)),
)
post[to_address(0xCC)] = Account(
storage=Storage({0: 0xBA1}),
)
post = {
to_address(0xCC): Account(
storage=Storage({0: 0xBA1}),
)
}
state_test(
env=env,
pre=pre,
txs=[tx, Transaction(nonce=1, to=to_address(0xCC), gas_limit=100000, gas_price=10)],
tx=Transaction(nonce=0, to=to_address(0xCC), gas_limit=100000, gas_price=10),
post=post,
)
4 changes: 2 additions & 2 deletions tests/cancun/eip5656_mcopy/test_mcopy.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ def test_valid_mcopy_operations(
env=Environment(),
pre=pre,
post=post,
txs=[tx],
tx=tx,
)


Expand All @@ -219,5 +219,5 @@ def test_mcopy_on_empty_memory(
env=Environment(),
pre=pre,
post=post,
txs=[tx],
tx=tx,
)
2 changes: 1 addition & 1 deletion tests/cancun/eip5656_mcopy/test_mcopy_contexts.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,5 +214,5 @@ def test_no_memory_corruption_on_upper_call_stack_levels(
env=Environment(),
pre=pre,
post=post,
txs=[tx],
tx=tx,
)
4 changes: 2 additions & 2 deletions tests/cancun/eip5656_mcopy/test_mcopy_memory_expansion.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ def test_mcopy_memory_expansion(
env=Environment(),
pre=pre,
post=post,
txs=[tx],
tx=tx,
)


Expand Down Expand Up @@ -276,5 +276,5 @@ def test_mcopy_huge_memory_expansion(
env=Environment(),
pre=pre,
post=post,
txs=[tx],
tx=tx,
)
12 changes: 6 additions & 6 deletions tests/cancun/eip6780_selfdestruct/test_selfdestruct.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ def test_create_selfdestruct_same_tx(
protected=False,
)

state_test(env=env, pre=pre, post=post, txs=[tx])
state_test(env=env, pre=pre, post=post, tx=tx)


@pytest.mark.parametrize("create_opcode", [Op.CREATE, Op.CREATE2])
Expand Down Expand Up @@ -540,7 +540,7 @@ def test_self_destructing_initcode(
protected=False,
)

state_test(env=env, pre=pre, post=post, txs=[tx])
state_test(env=env, pre=pre, post=post, tx=tx)


@pytest.mark.parametrize("tx_value", [0, 100_000])
Expand Down Expand Up @@ -595,7 +595,7 @@ def test_self_destructing_initcode_create_tx(
protected=False,
)

state_test(env=env, pre=pre, post=post, txs=[tx])
state_test(env=env, pre=pre, post=post, tx=tx)


@pytest.mark.parametrize("create_opcode", [Op.CREATE2]) # Can only recreate using CREATE2
Expand Down Expand Up @@ -872,7 +872,7 @@ def test_selfdestruct_pre_existing(
protected=False,
)

state_test(env=env, pre=pre, post=post, txs=[tx])
state_test(env=env, pre=pre, post=post, tx=tx)


@pytest.mark.parametrize("selfdestruct_contract_initial_balance", [0, 1])
Expand Down Expand Up @@ -1148,7 +1148,7 @@ def test_delegatecall_from_new_contract_to_pre_existing_contract(
protected=False,
)

state_test(env=env, pre=pre, post=post, txs=[tx])
state_test(env=env, pre=pre, post=post, tx=tx)


@pytest.mark.parametrize("create_opcode", [Op.CREATE, Op.CREATE2])
Expand Down Expand Up @@ -1305,4 +1305,4 @@ def test_delegatecall_from_pre_existing_contract_to_new_contract(
protected=False,
)

state_test(env=env, pre=pre, post=post, txs=[tx])
state_test(env=env, pre=pre, post=post, tx=tx)
Loading

0 comments on commit e8d1798

Please sign in to comment.