Skip to content

Commit 6e659a4

Browse files
committed
new(tests): add fibonacci and factorial tests for CALLF
Add tests implementing fibonacci sequance and factorial using recursive CALLF instructions. They were originally contributed to ethereum/tests by @hugo-dc in ethereum/tests@89c2147. I'm migrating the tests separately because they are nice examples.
1 parent 0ed27a0 commit 6e659a4

File tree

1 file changed

+79
-0
lines changed

1 file changed

+79
-0
lines changed

tests/osaka/eip7692_eof_v1/eip4750_functions/test_callf_execution.py

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,85 @@
2222
pytestmark = pytest.mark.valid_from(EOF_FORK_NAME)
2323

2424

25+
def test_callf_factorial(eof_state_test: EOFStateTestFiller):
26+
"""Test factorial implementation with recursive CALLF instructions"""
27+
eof_state_test(
28+
data=Container(
29+
sections=[
30+
Section.Code(
31+
Op.CALLDATALOAD(0) + Op.SSTORE(0, Op.CALLF[1]) + Op.STOP,
32+
max_stack_height=2,
33+
),
34+
Section.Code(
35+
Op.PUSH1[1]
36+
+ Op.DUP2
37+
+ Op.GT
38+
+ Op.RJUMPI[4]
39+
+ Op.POP
40+
+ Op.PUSH1[1]
41+
+ Op.RETF
42+
+ Op.PUSH1[1]
43+
+ Op.DUP2
44+
+ Op.SUB
45+
+ Op.CALLF[1]
46+
+ Op.DUP2
47+
+ Op.MUL
48+
+ Op.SWAP1
49+
+ Op.POP
50+
+ Op.RETF,
51+
code_inputs=1,
52+
code_outputs=1,
53+
max_stack_height=3,
54+
),
55+
]
56+
),
57+
tx_data=(57).to_bytes(32, "big"),
58+
container_post=Account(
59+
storage={0: 0x59996C6EF58409A71B05BE0BADA2445EB7C017D09442E7D158E0000000000000}
60+
),
61+
)
62+
63+
64+
def test_callf_fibonacci(eof_state_test: EOFStateTestFiller):
65+
"""Test fibonacci sequence implementation with recursive CALLF instructions"""
66+
eof_state_test(
67+
data=Container(
68+
sections=[
69+
Section.Code(
70+
Op.CALLDATALOAD(0) + Op.SSTORE(0, Op.CALLF[1]) + Op.STOP,
71+
max_stack_height=2,
72+
),
73+
Section.Code(
74+
Op.PUSH1[2]
75+
+ Op.DUP2
76+
+ Op.GT
77+
+ Op.RJUMPI[4]
78+
+ Op.POP
79+
+ Op.PUSH1[1]
80+
+ Op.RETF
81+
+ Op.PUSH1[2]
82+
+ Op.DUP2
83+
+ Op.SUB
84+
+ Op.CALLF[1]
85+
+ Op.PUSH1[1]
86+
+ Op.DUP3
87+
+ Op.SUB
88+
+ Op.CALLF[1]
89+
+ Op.ADD
90+
+ Op.SWAP1
91+
+ Op.POP
92+
+ Op.RETF,
93+
code_inputs=1,
94+
code_outputs=1,
95+
max_stack_height=4,
96+
),
97+
]
98+
),
99+
tx_data=(13).to_bytes(32, "big"),
100+
container_post=Account(storage={0: 233}),
101+
)
102+
103+
25104
def test_callf_stack_size_1024(
26105
eof_state_test: EOFStateTestFiller,
27106
):

0 commit comments

Comments
 (0)