Skip to content

test_max_code_size_via_create_fork_transition()

Documentation for tests/amsterdam/eip7954_increase_max_contract_size/test_fork_transition.py::test_max_code_size_via_create_fork_transition@2119b382.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip7954_increase_max_contract_size/test_fork_transition.py::test_max_code_size_via_create_fork_transition --fork Amsterdam

Ensure the new max code size limit activates at the fork via opcodes.

Source code in tests/amsterdam/eip7954_increase_max_contract_size/test_fork_transition.py
 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
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
@pytest.mark.parametrize("create_opcode", [Op.CREATE, Op.CREATE2])
def test_max_code_size_via_create_fork_transition(
    blockchain_test: BlockchainTestFiller,
    pre: Alloc,
    fork: TransitionFork,
    create_opcode: Op,
) -> None:
    """Ensure the new max code size limit activates at the fork via opcodes."""
    parent = fork.transitions_from()
    assert parent is not None, "Parent fork must be defined for this test"
    code_size = parent.max_code_size() + 1
    deploy_code = Op.JUMPDEST * code_size
    initcode = Initcode(deploy_code=deploy_code)
    initcode_bytes = bytes(initcode)

    alice = pre.fund_eoa()
    bob = pre.fund_eoa()

    create_call = (
        create_opcode(
            value=0, offset=0, size=Op.CALLDATASIZE, salt=CREATE2_SALT
        )
        if create_opcode == Op.CREATE2
        else create_opcode(value=0, offset=0, size=Op.CALLDATASIZE)
    )

    factory_code = (
        Op.CALLDATACOPY(0, 0, Op.CALLDATASIZE)
        + Op.SSTORE(0, create_call)
        + Op.STOP
    )

    factory_pre = pre.deploy_contract(factory_code)
    factory_post = pre.deploy_contract(factory_code)

    create_address_pre = compute_create_address(
        address=factory_pre,
        nonce=1,
        salt=CREATE2_SALT,
        initcode=initcode,
        opcode=create_opcode,
    )
    create_address_post = compute_create_address(
        address=factory_post,
        nonce=1,
        salt=CREATE2_SALT,
        initcode=initcode,
        opcode=create_opcode,
    )

    blocks = [
        Block(
            timestamp=14_999,
            txs=[
                Transaction(
                    sender=alice,
                    to=factory_pre,
                    data=initcode_bytes,
                )
            ],
        ),
        Block(
            timestamp=15_000,
            txs=[
                Transaction(
                    sender=bob,
                    to=factory_post,
                    data=initcode_bytes,
                )
            ],
        ),
    ]

    post: dict[Any, Account | None] = {
        create_address_pre: Account.NONEXISTENT,
        create_address_post: Account(code=deploy_code),
    }

    blockchain_test(pre=pre, blocks=blocks, post=post)

Parametrized Test Cases

This test generates 2 parametrized test cases across 1 fork.