Skip to content

Commit 5bb4d90

Browse files
committed
Issue #27: Adding testing skeleton.
1 parent 00652e1 commit 5bb4d90

File tree

1 file changed

+79
-0
lines changed

1 file changed

+79
-0
lines changed

tools/evm-test/evm_test.py

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
#!/usr/bin/python
2+
3+
from typing import List
4+
from string import Template
5+
6+
import pyevmasm as asm
7+
8+
template_0_1 = """
9+
Start:
10+
PUSH1 Return
11+
PUSH2 Function
12+
JUMP
13+
Return:
14+
JUMPDEST
15+
PUSH1 0x00
16+
MSTORE
17+
PUSH1 0x20
18+
PUSH1 0x00
19+
RETURN
20+
Function:
21+
"""
22+
23+
template_1_1 = """
24+
Start:
25+
PUSH1 Return
26+
PUSH4 ${input_value}
27+
PUSH2 Function
28+
JUMP
29+
Return:
30+
JUMPDEST
31+
PUSH1 0x00
32+
MSTORE
33+
PUSH1 0x20
34+
PUSH1 0x00
35+
RETURN
36+
Function:\n
37+
"""
38+
39+
template_2_1 = """
40+
Start:
41+
PUSH1 Return
42+
PUSH4 ${input_value_1}
43+
PUSH4 ${input_value_2}
44+
PUSH2 Function
45+
JUMP
46+
Return:
47+
JUMPDEST
48+
PUSH1 0x00
49+
MSTORE
50+
PUSH1 0x20
51+
PUSH1 0x00
52+
RETURN
53+
Function:\n
54+
"""
55+
56+
def generate_header_str(inputs: List[int]) -> str:
57+
assert len(inputs) < 3
58+
t = ""
59+
if len(inputs) is 1:
60+
t = Template(template_1_1).substitute(input_value = inputs[0])
61+
elif len(inputs) is 2:
62+
t = Template(template_2_1).substitute(
63+
input_value_1 = inputs[0], input_value_2 = inputs[1])
64+
return t
65+
66+
def generate_header_binary(inputs: List[int]) -> str:
67+
asm.assemble_hex(generate_header_str(inputs))
68+
69+
def generate_contract(inputs: List[int], func: str) -> str:
70+
assert len(inputs) < 3
71+
complete_str = generate_header_str(inputs) + func
72+
return asm.assemble_hex(complete_str)
73+
74+
def execute_in_evm(code: str, expected: str) -> str:
75+
pass
76+
77+
78+
print(generate_contract(
79+
inputs=["0x12345678", "0x87654321"], func="JUMPDEST\nADD\nSWAP1\nJUMP"))

0 commit comments

Comments
 (0)