Skip to content

test_block_full_data()

Documentation for tests/benchmark/test_worst_blocks.py::test_block_full_data@v5.0.0.

Generate fixtures for these test cases for Osaka with:

fill -v tests/benchmark/test_worst_blocks.py::test_block_full_data --fork Osaka

Test a block with empty payload.

Source code in tests/benchmark/test_worst_blocks.py
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
@pytest.mark.valid_from("Prague")
@pytest.mark.parametrize("zero_byte", [True, False])
def test_block_full_data(
    state_test: StateTestFiller,
    pre: Alloc,
    zero_byte: bool,
    intrinsic_cost: int,
    total_cost_floor_per_token: int,
    gas_benchmark_value: int,
):
    """Test a block with empty payload."""
    # Gas cost calculation based on EIP-7683: (https://eips.ethereum.org/EIPS/eip-7683)
    #
    #   tx.gasUsed = 21000 + max(
    #       STANDARD_TOKEN_COST * tokens_in_calldata
    #       + execution_gas_used
    #       + isContractCreation * (32000 + INITCODE_WORD_COST * words(calldata)),
    #       TOTAL_COST_FLOOR_PER_TOKEN * tokens_in_calldata)
    #
    # Simplified in this test case:
    # - No execution gas used (no opcodes are executed)
    # - Not a contract creation (no initcode)
    #
    # Therefore:
    #   max_token_cost = max(STANDARD_TOKEN_COST, TOTAL_COST_FLOOR_PER_TOKEN)
    #   tx.gasUsed = 21000 + tokens_in_calldata * max_token_cost
    #
    # Since max(STANDARD_TOKEN_COST, TOTAL_COST_FLOOR_PER_TOKEN) = 10:
    #   tx.gasUsed = 21000 + tokens_in_calldata * 10
    #
    # Token accounting:
    #   tokens_in_calldata = zero_bytes + 4 * non_zero_bytes
    #
    # So we calculate how many bytes we can fit into calldata based on available gas.

    gas_available = gas_benchmark_value - intrinsic_cost

    # Calculate the token_in_calldata
    max_tokens_in_calldata = gas_available // total_cost_floor_per_token
    # Calculate the number of bytes that can be stored in the calldata
    num_of_bytes = max_tokens_in_calldata if zero_byte else max_tokens_in_calldata // 4
    byte_data = b"\x00" if zero_byte else b"\xff"

    tx = Transaction(
        to=pre.fund_eoa(),
        data=byte_data * num_of_bytes,
        gas_limit=gas_benchmark_value,
        sender=pre.fund_eoa(),
    )

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

Parametrized Test Cases

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

Test ID (Abbreviated) zero_byte
...fork_Prague-state_test-zero_byte_True True
...fork_Prague-state_test-zero_byte_False False
...fork_Prague-blockchain_test_from_state_test-zero_byte_True True
...fork_Prague-blockchain_test_from_state_test-zero_byte_False False
...fork_Osaka-state_test-zero_byte_True True
...fork_Osaka-state_test-zero_byte_False False
...fork_Osaka-blockchain_test_from_state_test-zero_byte_True True
...fork_Osaka-blockchain_test_from_state_test-zero_byte_False False