Skip to content

test_access_list_token_calculation()

Documentation for tests/amsterdam/eip7981_increase_access_list_cost/test_access_list_cost.py::test_access_list_token_calculation@9c2813ee.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip7981_increase_access_list_cost/test_access_list_cost.py::test_access_list_token_calculation --fork Amsterdam

Test that access list floor tokens are calculated correctly.

Every access list byte contributes four floor tokens regardless of whether it is zero or non-zero. Verify both the reference helper and the fork's floor cost calculator agree with the expected token count.

Source code in tests/amsterdam/eip7981_increase_access_list_cost/test_access_list_cost.py
 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
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
@pytest.mark.with_all_tx_types(selector=lambda tx_type: tx_type >= 1)
@pytest.mark.parametrize(
    "access_list,expected_floor_tokens",
    [
        pytest.param(
            [AccessList(address=Address(0), storage_keys=[])],
            # 20 bytes total: 20 * 4 = 80 floor tokens
            80,
            id="single_zero_address_no_keys",
        ),
        pytest.param(
            [
                AccessList(
                    address=Address(
                        0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
                    ),
                    storage_keys=[],
                )
            ],
            # 20 bytes total: 20 * 4 = 80 floor tokens
            80,
            id="single_nonzero_address_no_keys",
        ),
        pytest.param(
            [AccessList(address=Address(0), storage_keys=[Hash(0)])],
            # Total bytes: 20 + 32 = 52, floor tokens: 52 * 4 = 208
            208,
            id="zero_address_zero_key",
        ),
        pytest.param(
            [
                AccessList(
                    address=Address(
                        0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
                    ),
                    storage_keys=[
                        Hash(
                            0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
                        )
                    ],
                )
            ],
            # Total bytes: 20 + 32 = 52, floor tokens: 52 * 4 = 208
            208,
            id="nonzero_address_nonzero_key",
        ),
        pytest.param(
            [
                AccessList(
                    address=Address(1),
                    storage_keys=[Hash(0), Hash(1), Hash(2)],
                )
            ],
            # Total bytes: 20 + (3 * 32) = 116, floor tokens: 116 * 4 = 464
            464,
            id="one_address_three_keys",
        ),
        pytest.param(
            [
                AccessList(address=Address(1), storage_keys=[Hash(0)]),
                AccessList(address=Address(2), storage_keys=[Hash(1)]),
            ],
            # Total bytes: 2 * (20 + 32) = 104, floor tokens: 104 * 4 = 416
            416,
            id="two_addresses_with_keys",
        ),
    ],
)
@pytest.mark.parametrize(
    "to",
    [pytest.param("eoa", id="")],
    indirect=True,
)
def test_access_list_token_calculation(
    state_test: StateTestFiller,
    fork: Fork,
    pre: Alloc,
    tx: Transaction,
    access_list: list,
    expected_floor_tokens: int,
) -> None:
    """
    Test that access list floor tokens are calculated correctly.

    Every access list byte contributes four floor tokens regardless of
    whether it is zero or non-zero. Verify both the reference helper and
    the fork's floor cost calculator agree with the expected token count.
    """
    assert (
        calculate_access_list_floor_tokens(access_list)
        == expected_floor_tokens
    )

    gas_costs = fork.gas_costs()
    expected_floor_cost = (
        expected_floor_tokens * gas_costs.TX_DATA_TOKEN_FLOOR
        + gas_costs.TX_BASE
    )
    actual_floor_cost = fork.transaction_data_floor_cost_calculator()(
        data=b"", access_list=access_list
    )
    assert actual_floor_cost == expected_floor_cost

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

Parametrized Test Cases

This test generates 24 parametrized test cases across 1 fork.