Skip to content

test_below_amsterdam_floor_with_access_list_exact_balance()

Documentation for tests/amsterdam/eip7981_increase_access_list_cost/test_floor_boundary_exact_balance.py::test_below_amsterdam_floor_with_access_list_exact_balance@c74f1a67.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip7981_increase_access_list_cost/test_floor_boundary_exact_balance.py::test_below_amsterdam_floor_with_access_list_exact_balance --fork Amsterdam

Reject when gas_limit sits in EIP-7981 access-list-byte floor gap.

Source code in tests/amsterdam/eip7981_increase_access_list_cost/test_floor_boundary_exact_balance.py
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
@pytest.mark.exception_test
@pytest.mark.parametrize(
    "tx_type",
    [pytest.param(1, id="type_1"), pytest.param(2, id="type_2")],
)
@pytest.mark.parametrize(
    "nonzero_bytes",
    [
        # Must be large enough that the floor midpoint chosen below
        # stays above the access-list intrinsic cost (asserted in the
        # test body): each nonzero byte adds 64 gas to the floor but
        # only 16 to the intrinsic cost.
        pytest.param(1700, id="1700_nonzero_bytes"),
        pytest.param(2000, id="2000_nonzero_bytes"),
    ],
)
def test_below_amsterdam_floor_with_access_list_exact_balance(
    state_test: StateTestFiller,
    pre: Alloc,
    fork: Fork,
    tx_type: int,
    nonzero_bytes: int,
) -> None:
    """Reject when gas_limit sits in EIP-7981 access-list-byte floor gap."""
    access_list = [
        AccessList(
            address=Address(1),
            storage_keys=[Hash(k) for k in range(10)],
        )
    ]
    tx_data = Bytes(b"\x01" * nonzero_bytes)
    intrinsic_regular = fork.transaction_intrinsic_cost_calculator()(
        calldata=tx_data,
        access_list=access_list,
        return_cost_deducted_prior_execution=True,
    )
    floor_calc = fork.transaction_data_floor_cost_calculator()
    amsterdam_floor = floor_calc(data=tx_data, access_list=access_list)
    amsterdam_floor_no_al = floor_calc(data=tx_data)
    # Pin gas_limit inside the access-list-byte uplift gap so an
    # implementation that omits this term from its floor accepts.
    gas_limit = (amsterdam_floor_no_al + amsterdam_floor) // 2
    assert intrinsic_regular <= gas_limit < amsterdam_floor
    assert gas_limit >= amsterdam_floor_no_al

    gas_price = 10
    sender = pre.fund_eoa(amount=gas_limit * gas_price)
    if tx_type == 1:
        fee_args: dict = {"gas_price": gas_price}
    else:
        fee_args = {
            "max_fee_per_gas": gas_price,
            "max_priority_fee_per_gas": 0,
        }
    tx = Transaction(
        ty=tx_type,
        sender=sender,
        to=pre.fund_eoa(amount=0),
        data=tx_data,
        gas_limit=gas_limit,
        access_list=access_list,
        error=TransactionException.INTRINSIC_GAS_BELOW_FLOOR_GAS_COST,
        **fee_args,
    )

    state_test(pre=pre, post={}, tx=tx)

Parametrized Test Cases

This test generates 4 parametrized test cases across 1 fork.