Skip to content

test_gas_consumption_below_data_floor()

Documentation for tests/prague/eip7623_increase_calldata_cost/test_execution_gas.py::TestGasConsumptionBelowDataFloor::test_gas_consumption_below_data_floor@21fb11c8.

Generate fixtures for these test cases for Prague with:

fill -v tests/prague/eip7623_increase_calldata_cost/test_execution_gas.py::TestGasConsumptionBelowDataFloor::test_gas_consumption_below_data_floor --fork Prague

Test gas consumption barely below the floor data cost (1 gas below).

Source code in tests/prague/eip7623_increase_calldata_cost/test_execution_gas.py
 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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
class TestGasConsumptionBelowDataFloor:
    """Test gas consumption barely below the floor data cost (1 gas below)."""

    @pytest.fixture
    def contract_creating_tx(self) -> bool:
        """Use a constant in order to avoid circular fixture dependencies."""
        return False

    @pytest.fixture
    def to(
        self,
        pre: Alloc,
        fork: Fork,
        tx_data: Bytes,
        access_list: List[AccessList] | None,
        authorization_list: List[AuthorizationTuple] | None,
        tx_floor_data_cost: int,
    ) -> Address | None:
        """
        Return a contract that consumes almost all the gas before reaching the
        floor data cost.
        """
        intrinsic_gas_cost_calculator = fork.transaction_intrinsic_cost_calculator()
        execution_gas = tx_floor_data_cost - intrinsic_gas_cost_calculator(
            calldata=tx_data,
            contract_creation=False,
            access_list=access_list,
            authorization_list_or_count=authorization_list,
            return_cost_deducted_prior_execution=True,
        )
        assert execution_gas > 0

        return pre.deploy_contract((Op.JUMPDEST * (execution_gas - 1)) + Op.STOP)

    @pytest.mark.parametrize(
        "ty,protected,authorization_list",
        [
            pytest.param(0, False, None, id="type_0_unprotected"),
            pytest.param(0, True, None, id="type_0_protected"),
            pytest.param(1, True, None, id="type_1"),
            pytest.param(2, True, None, id="type_2"),
            pytest.param(3, True, None, id="type_3"),
            pytest.param(4, True, [Address(1)], id="type_4"),
        ],
        indirect=["authorization_list"],
    )
    @pytest.mark.parametrize(
        "tx_gas_delta",
        [
            # Test with exact gas and extra gas, to verify that the refund is correctly applied
            # to the full consumed execution gas.
            pytest.param(0, id="exact_gas"),
        ],
    )
    def test_gas_consumption_below_data_floor(
        self,
        state_test: StateTestFiller,
        pre: Alloc,
        tx: Transaction,
        tx_floor_data_cost: int,
    ) -> None:
        """Test executing a transaction that almost consumes the floor data cost."""
        tx.expected_receipt = TransactionReceipt(gas_used=tx_floor_data_cost)
        state_test(
            pre=pre,
            post={},
            tx=tx,
        )

test_gas_consumption_below_data_floor(state_test, pre, tx, tx_floor_data_cost)

Test executing a transaction that almost consumes the floor data cost.

Source code in tests/prague/eip7623_increase_calldata_cost/test_execution_gas.py
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
@pytest.mark.parametrize(
    "ty,protected,authorization_list",
    [
        pytest.param(0, False, None, id="type_0_unprotected"),
        pytest.param(0, True, None, id="type_0_protected"),
        pytest.param(1, True, None, id="type_1"),
        pytest.param(2, True, None, id="type_2"),
        pytest.param(3, True, None, id="type_3"),
        pytest.param(4, True, [Address(1)], id="type_4"),
    ],
    indirect=["authorization_list"],
)
@pytest.mark.parametrize(
    "tx_gas_delta",
    [
        # Test with exact gas and extra gas, to verify that the refund is correctly applied
        # to the full consumed execution gas.
        pytest.param(0, id="exact_gas"),
    ],
)
def test_gas_consumption_below_data_floor(
    self,
    state_test: StateTestFiller,
    pre: Alloc,
    tx: Transaction,
    tx_floor_data_cost: int,
) -> None:
    """Test executing a transaction that almost consumes the floor data cost."""
    tx.expected_receipt = TransactionReceipt(gas_used=tx_floor_data_cost)
    state_test(
        pre=pre,
        post={},
        tx=tx,
    )

Parametrized Test Cases

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

Test ID (Abbreviated) authorization_list tx_gas_delta ty protected
...fork_Prague-state_test-exact_gas-type_0_unprotected None 0 0 False
...fork_Prague-state_test-exact_gas-type_0_protected None 0 0 True
...fork_Prague-state_test-exact_gas-type_1 None 0 1 True
...fork_Prague-state_test-exact_gas-type_2 None 0 2 True
...fork_Prague-state_test-exact_gas-type_3 None 0 3 True
...fork_Prague-state_test-exact_gas-type_4 [b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01'] 0 4 True
...fork_Prague-blockchain_test_from_state_test-exact_gas-type_0_unprotected None 0 0 False
...fork_Prague-blockchain_test_from_state_test-exact_gas-type_0_protected None 0 0 True
...fork_Prague-blockchain_test_from_state_test-exact_gas-type_1 None 0 1 True
...fork_Prague-blockchain_test_from_state_test-exact_gas-type_2 None 0 2 True
...fork_Prague-blockchain_test_from_state_test-exact_gas-type_3 None 0 3 True
...fork_Prague-blockchain_test_from_state_test-exact_gas-type_4 [b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01'] 0 4 True
...fork_Osaka-state_test-exact_gas-type_0_unprotected None 0 0 False
...fork_Osaka-state_test-exact_gas-type_0_protected None 0 0 True
...fork_Osaka-state_test-exact_gas-type_1 None 0 1 True
...fork_Osaka-state_test-exact_gas-type_2 None 0 2 True
...fork_Osaka-state_test-exact_gas-type_3 None 0 3 True
...fork_Osaka-state_test-exact_gas-type_4 [b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01'] 0 4 True
...fork_Osaka-blockchain_test_from_state_test-exact_gas-type_0_unprotected None 0 0 False
...fork_Osaka-blockchain_test_from_state_test-exact_gas-type_0_protected None 0 0 True
...fork_Osaka-blockchain_test_from_state_test-exact_gas-type_1 None 0 1 True
...fork_Osaka-blockchain_test_from_state_test-exact_gas-type_2 None 0 2 True
...fork_Osaka-blockchain_test_from_state_test-exact_gas-type_3 None 0 3 True
...fork_Osaka-blockchain_test_from_state_test-exact_gas-type_4 [b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01'] 0 4 True