5
5
6
6
import vyper
7
7
from vyper .cli .vyper_json import (
8
+ VENOM_KEYS ,
8
9
compile_from_input_dict ,
9
10
compile_json ,
10
11
exc_handler_to_dict ,
@@ -145,15 +146,11 @@ def json_input(json_data, path):
145
146
)
146
147
147
148
148
- def test_compile_json (input_json , input_bundle ):
149
+ def test_compile_json (input_json , input_bundle , experimental_codegen ):
149
150
foo_input = input_bundle .load_file ("contracts/foo.vy" )
150
151
# remove venom related from output formats
151
152
# because they require venom (experimental)
152
153
output_formats = OUTPUT_FORMATS .copy ()
153
- del output_formats ["bb" ]
154
- del output_formats ["bb_runtime" ]
155
- del output_formats ["cfg" ]
156
- del output_formats ["cfg_runtime" ]
157
154
foo = compile_from_file_input (
158
155
foo_input ,
159
156
output_formats = output_formats ,
@@ -198,7 +195,7 @@ def test_compile_json(input_json, input_bundle):
198
195
"ast" : data ["ast_dict" ]["ast" ],
199
196
"annotated_ast" : data ["annotated_ast_dict" ]["ast" ],
200
197
}
201
- assert output_json [ "contracts" ][ path ][ contract_name ] = = {
198
+ expected = {
202
199
"abi" : data ["abi" ],
203
200
"devdoc" : data ["devdoc" ],
204
201
"interface" : data ["interface" ],
@@ -220,6 +217,14 @@ def test_compile_json(input_json, input_bundle):
220
217
"methodIdentifiers" : data ["method_identifiers" ],
221
218
},
222
219
}
220
+ if experimental_codegen :
221
+ expected ["venom" ] = {
222
+ "bb" : repr (data ["bb" ]),
223
+ "bb_runtime" : repr (data ["bb_runtime" ]),
224
+ "cfg" : data ["cfg" ],
225
+ "cfg_runtime" : data ["cfg_runtime" ],
226
+ }
227
+ assert output_json ["contracts" ][path ][contract_name ] == expected
223
228
224
229
225
230
def test_compilation_targets (input_json ):
@@ -237,7 +242,7 @@ def test_compilation_targets(input_json):
237
242
assert list (output_json ["contracts" ].keys ()) == ["contracts/foo.vy" , "contracts/bar.vy" ]
238
243
239
244
240
- def test_different_outputs (input_bundle , input_json ):
245
+ def test_different_outputs (input_bundle , input_json , experimental_codegen ):
241
246
input_json ["settings" ]["outputSelection" ] = {
242
247
"contracts/bar.vy" : "*" ,
243
248
"contracts/foo.vy" : ["evm.methodIdentifiers" ],
@@ -252,16 +257,11 @@ def test_different_outputs(input_bundle, input_json):
252
257
253
258
foo = contracts ["contracts/foo.vy" ]["foo" ]
254
259
bar = contracts ["contracts/bar.vy" ]["bar" ]
255
- assert sorted (bar .keys ()) == [
256
- "abi" ,
257
- "devdoc" ,
258
- "evm" ,
259
- "interface" ,
260
- "ir" ,
261
- "layout" ,
262
- "metadata" ,
263
- "userdoc" ,
264
- ]
260
+ expected_keys = ["abi" , "devdoc" , "evm" , "interface" , "ir" , "layout" , "metadata" , "userdoc" ]
261
+ if experimental_codegen :
262
+ expected_keys .append ("venom" )
263
+ expected_keys .sort ()
264
+ assert sorted (bar .keys ()) == expected_keys
265
265
266
266
assert sorted (foo .keys ()) == ["evm" ]
267
267
@@ -385,13 +385,41 @@ def test_compile_json_with_experimental_codegen():
385
385
"evmVersion" : "cancun" ,
386
386
"optimize" : "gas" ,
387
387
"venomExperimental" : True ,
388
- "search_paths" : [],
389
- "outputSelection" : {"*" : [ "ast" ] },
388
+ "search_paths" : ["." ],
389
+ "outputSelection" : {"*" : VENOM_KEYS },
390
390
},
391
391
}
392
+ compiled = compile_from_input_dict (code )
393
+ expected = compiled [0 ][PurePath ("foo.vy" )]
392
394
393
395
settings = get_settings (code )
394
396
assert settings .experimental_codegen is True
397
+ output_json = compile_json (code )
398
+ assert "venom" in output_json ["contracts" ]["foo.vy" ]["foo" ]
399
+ venom = output_json ["contracts" ]["foo.vy" ]["foo" ]["venom" ]
400
+ assert venom ["bb" ] == repr (expected ["bb" ])
401
+ assert venom ["bb_runtime" ] == repr (expected ["bb_runtime" ])
402
+ assert venom ["cfg" ] == expected ["cfg" ]
403
+ assert venom ["cfg_runtime" ] == expected ["cfg_runtime" ]
404
+
405
+
406
+ def test_compile_json_without_experimental_codegen ():
407
+ code = {
408
+ "language" : "Vyper" ,
409
+ "sources" : {"foo.vy" : {"content" : "@external\n def foo() -> bool:\n return True" }},
410
+ "settings" : {
411
+ "evmVersion" : "cancun" ,
412
+ "optimize" : "gas" ,
413
+ "venomExperimental" : False ,
414
+ "search_paths" : ["." ],
415
+ "outputSelection" : {"*" : ["ast" ]},
416
+ },
417
+ }
418
+
419
+ settings = get_settings (code )
420
+ assert settings .experimental_codegen is False
421
+ output_json = compile_json (code )
422
+ assert "venom" not in output_json ["contracts" ]["foo.vy" ]["foo" ]
395
423
396
424
397
425
def test_compile_json_with_both_venom_aliases ():
0 commit comments