Skip to content

Test Yul Example

Documentation for tests/homestead/yul/test_yul_example.py.

Generate fixtures for these test cases with:

fill -v tests/homestead/yul/test_yul_example.py

Test Yul Source Code Examples

test_yul(state_test, pre, yul, fork)

Test YUL compiled bytecode.

Source code in tests/homestead/yul/test_yul_example.py
18
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
@pytest.mark.valid_from("Homestead")
def test_yul(state_test: StateTestFiller, pre: Alloc, yul: YulCompiler, fork: Fork):
    """
    Test YUL compiled bytecode.
    """
    env = Environment()

    contract_address = pre.deploy_contract(
        code=yul(
            """
            {
                function f(a, b) -> c {
                    c := add(a, b)
                }

                sstore(0, f(1, 2))
                return(0, 32)
            }
            """
        ),
        balance=0x0BA1A9CE0BA1A9CE,
    )
    sender = pre.fund_eoa(amount=0x0BA1A9CE0BA1A9CE)

    tx = Transaction(
        ty=0x0,
        chain_id=0x01,
        sender=sender,
        to=contract_address,
        gas_limit=500000,
        gas_price=10,
        protected=False if fork in [Frontier, Homestead] else True,
    )

    post = {
        contract_address: Account(
            storage={
                0x00: 0x03,
            },
        ),
    }

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