Skip to content

Test Extcode

Documentation for tests/prague/eip7692_eof_v1/eip3540_eof_v1/test_extcode.py.

Generate fixtures for these test cases for Prague with:

Prague only:

fill -v tests/prague/eip7692_eof_v1/eip3540_eof_v1/test_extcode.py --fork=Prague --evm-bin=/path/to/evm-tool-dev-version
For all forks up to and including Prague:
fill -v tests/prague/eip7692_eof_v1/eip3540_eof_v1/test_extcode.py --until=Prague --evm-bin=/path/to/evm-tool-dev-version

test execution semantics changes

test_legacy_calls_eof_sstore(state_test, pre)

Test EXTCODE* opcodes calling EOF and legacy contracts

Source code in tests/prague/eip7692_eof_v1/eip3540_eof_v1/test_extcode.py
19
20
21
22
23
24
25
26
27
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
def test_legacy_calls_eof_sstore(
    state_test: StateTestFiller,
    pre: Alloc,
):
    """Test EXTCODE* opcodes calling EOF and legacy contracts"""
    env = Environment()
    address_eof_contract = pre.deploy_contract(
        Container(
            sections=[
                Section.Code(
                    code=Op.RJUMP[0] + Op.STOP,
                )
            ]
        )
    )
    legacy_code = Op.PUSH1(2) + Op.JUMPDEST + Op.STOP
    address_legacy_contract = pre.deploy_contract(legacy_code)

    storage_test = Storage()
    test_contract_code = (
        Op.SSTORE(storage_test.store_next(4), Op.EXTCODESIZE(address_legacy_contract))
        + Op.EXTCODECOPY(address_legacy_contract, 0, 0, Op.EXTCODESIZE(address_legacy_contract))
        + Op.SSTORE(
            storage_test.store_next(bytes(legacy_code) + (b"\0" * (32 - len(legacy_code)))),
            Op.MLOAD(0),
        )
        + Op.SSTORE(
            storage_test.store_next(legacy_code.keccak256()),
            Op.EXTCODEHASH(address_legacy_contract),
        )
        + Op.SSTORE(storage_test.store_next(2), Op.EXTCODESIZE(address_eof_contract))
        + Op.EXTCODECOPY(address_eof_contract, 0x20, 0, 6)
        + Op.SSTORE(storage_test.store_next(b"\xef" + (b"\0" * 31)), Op.MLOAD(0x20))
        + Op.SSTORE(
            storage_test.store_next(keccak256(b"\xef\x00")),
            Op.EXTCODEHASH(address_eof_contract),
        )
    )
    address_test_contract = pre.deploy_contract(test_contract_code)

    sender = pre.fund_eoa()

    tx = Transaction(
        sender=sender,
        to=address_test_contract,
        gas_limit=50_000_000,
        gas_price=10,
        protected=False,
        data="",
    )

    post = {
        address_test_contract: Account(storage=storage_test),
    }

    state_test(
        env=env,
        pre=pre,
        post=post,
        tx=tx,
    )