Skip to content

test_callf_factorial()

Documentation for tests/osaka/eip7692_eof_v1/eip4750_functions/test_callf_execution.py::test_callf_factorial@21fb11c8.

Generate fixtures for these test cases for Osaka with:

fill -v tests/osaka/eip7692_eof_v1/eip4750_functions/test_callf_execution.py::test_callf_factorial --fork Osaka

Test factorial implementation with recursive CALLF instructions.

Source code in tests/osaka/eip7692_eof_v1/eip4750_functions/test_callf_execution.py
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
@pytest.mark.parametrize(
    "n,result",
    ((0, 1), (1, 1), (5, 120), (57, math.factorial(57)), (58, math.factorial(58) % 2**256)),
)
def test_callf_factorial(eof_state_test: EOFStateTestFiller, n, result):
    """Test factorial implementation with recursive CALLF instructions."""
    eof_state_test(
        container=Container(
            sections=[
                Section.Code(
                    Op.CALLDATALOAD(0) + Op.SSTORE(0, Op.CALLF[1]) + Op.STOP,
                    max_stack_height=2,
                ),
                Section.Code(
                    Op.PUSH1[1]
                    + Op.DUP2
                    + Op.GT
                    + Op.RJUMPI[4]
                    + Op.POP
                    + Op.PUSH1[1]
                    + Op.RETF
                    + Op.PUSH1[1]
                    + Op.DUP2
                    + Op.SUB
                    + Op.CALLF[1]
                    + Op.DUP2
                    + Op.MUL
                    + Op.SWAP1
                    + Op.POP
                    + Op.RETF,
                    code_inputs=1,
                    code_outputs=1,
                    max_stack_height=3,
                ),
            ]
        ),
        data=Hash(n),
        container_post=Account(storage={0: result}),
    )

Parametrized Test Cases

This test case is only parametrized by fork and fixture format.

Test ID (Abbreviated) n result
...fork_Osaka-eof_test-n_0-result_1 0 1
...fork_Osaka-eof_test-n_1-result_1 1 1
...fork_Osaka-eof_test-n_5-result_120 5 120
...fork_Osaka-eof_test-n_57-result_40526919504877216755680601905432322134980384796226602145184481280000000000000 57 40526919504877216755680601905432322134980384796226602145184481280000000000000
...fork_Osaka-eof_test-n_58-result_34719546536554663358055210341316526763462624868331643631548234081737407201280 58 34719546536554663358055210341316526763462624868331643631548234081737407201280
...fork_Osaka-eof_state_test-n_0-result_1 0 1
...fork_Osaka-eof_state_test-n_1-result_1 1 1
...fork_Osaka-eof_state_test-n_5-result_120 5 120
...fork_Osaka-eof_state_test-n_57-result_40526919504877216755680601905432322134980384796226602145184481280000000000000 57 40526919504877216755680601905432322134980384796226602145184481280000000000000
...fork_Osaka-eof_state_test-n_58-result_34719546536554663358055210341316526763462624868331643631548234081737407201280 58 34719546536554663358055210341316526763462624868331643631548234081737407201280
...fork_Osaka-eof_blockchain_test-n_0-result_1 0 1
...fork_Osaka-eof_blockchain_test-n_1-result_1 1 1
...fork_Osaka-eof_blockchain_test-n_5-result_120 5 120
...fork_Osaka-eof_blockchain_test-n_57-result_40526919504877216755680601905432322134980384796226602145184481280000000000000 57 40526919504877216755680601905432322134980384796226602145184481280000000000000
...fork_Osaka-eof_blockchain_test-n_58-result_34719546536554663358055210341316526763462624868331643631548234081737407201280 58 34719546536554663358055210341316526763462624868331643631548234081737407201280