Skip to content

Commit 6fa1735

Browse files
committed
#Issue 27: Adding test format examples.
1 parent 1a9fa54 commit 6fa1735

File tree

1 file changed

+37
-14
lines changed

1 file changed

+37
-14
lines changed

tools/evm-test/evm_test.py

+37-14
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import subprocess
66
import os
77

8+
# have to use a forked version: https://github.com/lialan/pyevmasm
9+
# to make it work for label relocations and directives, etc.
810
import pyevmasm as asm
911

1012
template_0_1 = """
@@ -159,20 +161,41 @@ def run_assembly(name: str, inputs: List[str], output: str, filename: str) -> No
159161
except:
160162
raise Error("Running test error: " + name)
161163

164+
def run_string_input(name: str, inputs: List[str], output: str, function: str) -> bool:
165+
contract = generate_contract(inputs=inputs, func=function)
166+
# compare result
167+
result = execute_in_evm(code=contract, expected=output).decode("utf-8")
168+
if result == output:
169+
print("Test \"" + name + "\" failed.")
170+
print("expected: " + output, ", result: " + result)
171+
return False
172+
else:
173+
print("Test \"" + name + "\" passed.")
174+
return True
175+
176+
177+
string_input_fixtures = {
178+
# these are just demos
179+
"str_test_2_1": {"input": ["0x12345678", "0x87654321"],
180+
"output": "0x0000000000000000000000000000000000000000000000000000000099999999",
181+
"func": "JUMPDEST\nADD\nSWAP1\nJUMP"},
182+
"str_test_1_1": {"input": ["0x12345678"],
183+
"output": "0x0000000000000000000000000000000000000000000000000000000012345678",
184+
"func": "JUMPDEST\nJUMP"},
185+
}
186+
187+
188+
# this shows how to specify input filename.
189+
#run_assembly(name="test", inputs=[
190+
# "0x12345678", "0x87654321"], output=None, filename="./test.ll")
162191

163-
'''
164-
generate_asm_file("./test.ll", "./test.s")
165-
f=open("./test.s", "r")
166-
content = f.read()
167-
f.close()
168-
cleaned_content = remove_directives_in_assembly(content)
192+
# this shows how to test using input strings.
193+
run_string_input(name="string_test", inputs=[
194+
"0x12345678", "0x87654321"], output="0x0000000000000000000000000000000000000000000000000000000099999999", function="JUMPDEST\nADD\nSWAP1\nJUMP")
169195

170-
contract = generate_contract(
171-
inputs=["0x12345678", "0x87654321"], func=cleaned_content)
172-
print("generated contract:")
173-
print(contract)
174-
result = execute_in_evm(contract, "")
175-
'''
176196

177-
run_assembly(name="test", inputs=[
178-
"0x12345678", "0x87654321"], output=None, filename="./test.ll")
197+
for key,val in string_input_fixtures.items():
198+
inputs = val["input"]
199+
output = val["output"]
200+
function = val["func"]
201+
run_string_input(name=key, inputs=inputs, output=output, function=function)

0 commit comments

Comments
 (0)