Skip to content

test_account_storage_warm_cold_state()

Documentation for tests/berlin/eip2930_access_list/test_acl.py::test_account_storage_warm_cold_state@64f949d0.

Generate fixtures for these test cases for Prague with:

fill -v tests/berlin/eip2930_access_list/test_acl.py::test_account_storage_warm_cold_state --fork Prague

Test type 1 transaction.

Source code in tests/berlin/eip2930_access_list/test_acl.py
 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
@pytest.mark.parametrize(
    "account_warm,storage_key_warm",
    [
        (True, True),
        (True, False),
        # (False, True),  Not possible
        (False, False),
    ],
)
def test_account_storage_warm_cold_state(
    state_test: StateTestFiller,
    pre: Alloc,
    fork: Fork,
    account_warm: bool,
    storage_key_warm: bool,
):
    """Test type 1 transaction."""
    env = Environment()
    gas_costs = fork.gas_costs()

    storage_reader_contract = pre.deploy_contract(Op.SLOAD(1) + Op.STOP)
    overhead_cost = (
        gas_costs.G_VERY_LOW * (Op.CALL.popped_stack_items - 1)  # Call stack items
        + gas_costs.G_BASE  # Call gas
        + gas_costs.G_VERY_LOW  # SLOAD Push
    )
    contract_address = pre.deploy_contract(
        CodeGasMeasure(
            code=Op.CALL(address=storage_reader_contract),
            overhead_cost=overhead_cost,
            extra_stack_items=1,
            sstore_key=0,
        )
    )
    expected_gas_cost = 0
    access_list_address = Address(0)
    access_list_storage_key = Hash(0)
    if account_warm:
        expected_gas_cost += gas_costs.G_WARM_ACCOUNT_ACCESS
        access_list_address = storage_reader_contract
    else:
        expected_gas_cost += gas_costs.G_COLD_ACCOUNT_ACCESS
    if storage_key_warm:
        expected_gas_cost += gas_costs.G_WARM_SLOAD
        access_list_storage_key = Hash(1)
    else:
        expected_gas_cost += gas_costs.G_COLD_SLOAD

    access_lists: List[AccessList] = [
        AccessList(
            address=access_list_address,
            storage_keys=[access_list_storage_key],
        ),
    ]

    sender = pre.fund_eoa()

    contract_creation = False
    tx_data = b""

    intrinsic_gas_calculator = fork.transaction_intrinsic_cost_calculator()

    tx_gas_limit = (
        intrinsic_gas_calculator(
            calldata=tx_data,
            contract_creation=contract_creation,
            access_list=access_lists,
        )
        + 100_000
    )

    tx = Transaction(
        ty=1,
        chain_id=0x01,
        data=tx_data,
        to=contract_address,
        gas_limit=tx_gas_limit,
        access_list=access_lists,
        protected=True,
        sender=sender,
    )

    post = {
        contract_address: Account(
            nonce=1,
            storage={0: expected_gas_cost},
        ),
    }
    state_test(env=env, pre=pre, post=post, tx=tx)

Parametrized Test Cases

The interactive table below is also available as a standalone page.

Test ID (Abbreviated) account_warm storage_key_warm
...fork_Berlin-state_test-account_warm_True-storage_key_warm_True True True
...fork_Berlin-state_test-account_warm_True-storage_key_warm_False True False
...fork_Berlin-state_test-account_warm_False-storage_key_warm_False False False
...fork_Berlin-blockchain_test_from_state_test-account_warm_True-storage_key_warm_True True True
...fork_Berlin-blockchain_test_from_state_test-account_warm_True-storage_key_warm_False True False
...fork_Berlin-blockchain_test_from_state_test-account_warm_False-storage_key_warm_False False False
...fork_London-state_test-account_warm_True-storage_key_warm_True True True
...fork_London-state_test-account_warm_True-storage_key_warm_False True False
...fork_London-state_test-account_warm_False-storage_key_warm_False False False
...fork_London-blockchain_test_from_state_test-account_warm_True-storage_key_warm_True True True
...fork_London-blockchain_test_from_state_test-account_warm_True-storage_key_warm_False True False
...fork_London-blockchain_test_from_state_test-account_warm_False-storage_key_warm_False False False
...fork_Paris-state_test-account_warm_True-storage_key_warm_True True True
...fork_Paris-state_test-account_warm_True-storage_key_warm_False True False
...fork_Paris-state_test-account_warm_False-storage_key_warm_False False False
...fork_Paris-blockchain_test_from_state_test-account_warm_True-storage_key_warm_True True True
...fork_Paris-blockchain_test_from_state_test-account_warm_True-storage_key_warm_False True False
...fork_Paris-blockchain_test_from_state_test-account_warm_False-storage_key_warm_False False False
...fork_Shanghai-state_test-account_warm_True-storage_key_warm_True True True
...fork_Shanghai-state_test-account_warm_True-storage_key_warm_False True False
...fork_Shanghai-state_test-account_warm_False-storage_key_warm_False False False
...fork_Shanghai-blockchain_test_from_state_test-account_warm_True-storage_key_warm_True True True
...fork_Shanghai-blockchain_test_from_state_test-account_warm_True-storage_key_warm_False True False
...fork_Shanghai-blockchain_test_from_state_test-account_warm_False-storage_key_warm_False False False
...fork_Cancun-state_test-account_warm_True-storage_key_warm_True True True
...fork_Cancun-state_test-account_warm_True-storage_key_warm_False True False
...fork_Cancun-state_test-account_warm_False-storage_key_warm_False False False
...fork_Cancun-blockchain_test_from_state_test-account_warm_True-storage_key_warm_True True True
...fork_Cancun-blockchain_test_from_state_test-account_warm_True-storage_key_warm_False True False
...fork_Cancun-blockchain_test_from_state_test-account_warm_False-storage_key_warm_False False False
...fork_Prague-state_test-account_warm_True-storage_key_warm_True True True
...fork_Prague-state_test-account_warm_True-storage_key_warm_False True False
...fork_Prague-state_test-account_warm_False-storage_key_warm_False False False
...fork_Prague-blockchain_test_from_state_test-account_warm_True-storage_key_warm_True True True
...fork_Prague-blockchain_test_from_state_test-account_warm_True-storage_key_warm_False True False
...fork_Prague-blockchain_test_from_state_test-account_warm_False-storage_key_warm_False False False
...fork_Osaka-state_test-account_warm_True-storage_key_warm_True True True
...fork_Osaka-state_test-account_warm_True-storage_key_warm_False True False
...fork_Osaka-state_test-account_warm_False-storage_key_warm_False False False
...fork_Osaka-blockchain_test_from_state_test-account_warm_True-storage_key_warm_True True True
...fork_Osaka-blockchain_test_from_state_test-account_warm_True-storage_key_warm_False True False
...fork_Osaka-blockchain_test_from_state_test-account_warm_False-storage_key_warm_False False False