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, 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
61
62
@pytest.mark.valid_from("Homestead")
def test_yul(state_test: StateTestFiller, yul: YulCompiler, fork: Fork):
    """
    Test YUL compiled bytecode.
    """
    env = Environment()

    pre = {
        "0x1000000000000000000000000000000000000000": Account(
            balance=0x0BA1A9CE0BA1A9CE,
            code=yul(
                """
            {
                function f(a, b) -> c {
                    c := add(a, b)
                }

                sstore(0, f(1, 2))
                return(0, 32)
            }
            """
            ),
        ),
        TestAddress: Account(balance=0x0BA1A9CE0BA1A9CE),
    }

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

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

    state_test(env=env, pre=pre, post=post, txs=[tx])