Skip to content

test_factory_predeploy_account()

Documentation for tests/amsterdam/eip7997_deterministic_factory_predeploy/test_factory.py::test_factory_predeploy_account@87aba1a3.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip7997_deterministic_factory_predeploy/test_factory.py::test_factory_predeploy_account --fork Amsterdam

The factory bytecode is present at the canonical Arachnid factory address with nonce 1 and balance 0. Verifies EVM-observable views of the predeploy via EXTCODESIZE, EXTCODEHASH, EXTCODECOPY + SHA3, and BALANCE.

Source code in tests/amsterdam/eip7997_deterministic_factory_predeploy/test_factory.py
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
80
81
82
83
84
85
86
87
88
def test_factory_predeploy_account(
    state_test: StateTestFiller,
    pre: Alloc,
) -> None:
    """
    The factory bytecode is present at the canonical Arachnid factory
    address with nonce 1 and balance 0. Verifies EVM-observable views of
    the predeploy via `EXTCODESIZE`, `EXTCODEHASH`, `EXTCODECOPY` +
    `SHA3`, and `BALANCE`.
    """
    storage = Storage()
    extcodesize_slot = storage.store_next(
        len(Spec.FACTORY_BYTECODE), "extcodesize"
    )
    extcodehash_slot = storage.store_next(
        keccak256(Spec.FACTORY_BYTECODE), "extcodehash"
    )
    extcodecopy_hash_slot = storage.store_next(
        keccak256(Spec.FACTORY_BYTECODE), "extcodecopy_hash"
    )
    balance_slot = storage.store_next(0, "balance")
    caller = pre.deploy_contract(
        Op.SSTORE(extcodesize_slot, Op.EXTCODESIZE(FACTORY))
        + Op.SSTORE(extcodehash_slot, Op.EXTCODEHASH(FACTORY))
        + Op.EXTCODECOPY(FACTORY, 0, 0, Op.EXTCODESIZE(FACTORY))
        + Op.SSTORE(extcodecopy_hash_slot, Op.SHA3(0, Op.EXTCODESIZE(FACTORY)))
        + Op.SSTORE(balance_slot, Op.BALANCE(FACTORY))
        + Op.STOP,
    )
    state_test(
        pre=pre,
        tx=Transaction(
            sender=pre.fund_eoa(),
            to=caller,
        ),
        post={
            FACTORY: Account(
                nonce=1,
                balance=0,
                code=Spec.FACTORY_BYTECODE,
            ),
            caller: Account(storage=storage),
        },
    )

Parametrized Test Cases

This test generates 1 parametrized test case across 1 fork.