Skip to content

test_block_state_inclusion_at_transition()

Documentation for tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_fork_transition.py::test_block_state_inclusion_at_transition@622620d8.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_fork_transition.py::test_block_state_inclusion_at_transition --fork Amsterdam

Activate the cumulative state-gas gate at the fork boundary.

Source code in tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_fork_transition.py
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
@pytest.mark.inclusion_test
@EIPChecklist.BlockLevelConstraint.Test.ForkTransition.AcceptedBeforeFork()
@pytest.mark.parametrize(
    "over_by",
    [
        pytest.param(
            0,
            id="exact",
            marks=EIPChecklist.BlockLevelConstraint.Test.ForkTransition.AcceptedAfterFork(),
        ),
        pytest.param(
            1,
            id="one_above",
            marks=[
                pytest.mark.exception_test,
                EIPChecklist.BlockLevelConstraint.Test.ForkTransition.RejectedAfterFork(),
            ],
        ),
    ],
)
def test_block_state_inclusion_at_transition(
    blockchain_test: BlockchainTestFiller,
    pre: Alloc,
    fork: Fork,
    over_by: int,
) -> None:
    """Activate the cumulative state-gas gate at the fork boundary."""
    after = fork.fork_at(timestamp=15_000)
    code = sum((Op.SSTORE(i, 1) for i in range(16)), Bytecode())
    execution = (
        after.transaction_intrinsic_cost_calculator()()
        + code.execution_cost(after)
    )
    state = code.state_cost(after)
    block_limit = execution + state
    second_limit = execution + over_by
    assert execution + second_limit <= block_limit
    stop = pre.deploy_contract(code=Op.STOP)
    blocks = []
    post = {}
    for timestamp in (14_999, 15_000):
        pricing = fork.fork_at(timestamp=timestamp)
        intrinsic = pricing.transaction_intrinsic_cost_calculator()()
        writer = pre.deploy_contract(code=code)
        first_execution = intrinsic + code.execution_cost(pricing)
        first_state = code.state_cost(pricing)
        assert first_execution + first_state <= block_limit
        assert second_limit >= intrinsic
        if timestamp < 15_000:
            assert first_execution + second_limit <= block_limit
        error = (
            TransactionException.GAS_ALLOWANCE_EXCEEDED
            if timestamp == 15_000 and over_by
            else None
        )
        txs = [
            Transaction(
                to=writer, sender=pre.fund_eoa(), gas_limit=block_limit
            ),
            Transaction(
                to=stop,
                sender=pre.fund_eoa(),
                gas_limit=second_limit,
                error=error,
            ),
        ]
        blocks.append(
            Block(
                timestamp=timestamp,
                txs=txs,
                exception=error,
                header_verify=None
                if error
                else Header(
                    gas_used=max(first_execution + intrinsic, first_state)
                ),
            )
        )
        post[writer] = Account(
            storage={} if error else dict.fromkeys(range(16), 1)
        )
    blockchain_test(
        pre=pre,
        genesis_environment=Environment(gas_limit=block_limit),
        blocks=blocks,
        post=post,
    )

Parametrized Test Cases

This test generates 2 parametrized test cases across 1 fork.