5
5
import subprocess
6
6
import os
7
7
8
+ # have to use a forked version: https://github.com/lialan/pyevmasm
9
+ # to make it work for label relocations and directives, etc.
8
10
import pyevmasm as asm
9
11
10
12
template_0_1 = """
@@ -159,20 +161,41 @@ def run_assembly(name: str, inputs: List[str], output: str, filename: str) -> No
159
161
except :
160
162
raise Error ("Running test error: " + name )
161
163
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\n ADD\n SWAP1\n JUMP" },
182
+ "str_test_1_1" : {"input" : ["0x12345678" ],
183
+ "output" : "0x0000000000000000000000000000000000000000000000000000000012345678" ,
184
+ "func" : "JUMPDEST\n JUMP" },
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")
162
191
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\n ADD\n SWAP1\n JUMP" )
169
195
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
- '''
176
196
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