Skip to content

Commit 7a0fad4

Browse files
committed
fixup! [libevmasm] Add support to import evm assembly json.
1 parent c83c2e8 commit 7a0fad4

File tree

1 file changed

+19
-23
lines changed

1 file changed

+19
-23
lines changed

scripts/ASTImportTest.sh

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -202,34 +202,29 @@ function test_evmjson_import_export_equivalence
202202
local sol_file="$1"
203203
local input_files=( "${@:2}" )
204204

205-
# Compile files (generates the C.bin)
206-
mkdir -p sol/
207-
run_solc --bin "${input_files[@]}" --output-dir sol/
208-
find sol/ -size 0 -delete
205+
# Generate bytecode and EVM assembly JSON through normal complication
206+
mkdir -p export/
207+
local export_options=(--bin --asm-json "${input_files[@]}" --output-dir export/)
208+
run_solc "${export_options[@]}"
209209

210-
mkdir -p asm_json/
211-
local export_options=(--asm-json "${input_files[@]}" --output-dir asm_json/)
210+
# NOTE: If there is no bytecode, the compiler produces a JSON file that contains just 'null'.
211+
# This is not accepted by assembly import though so we must skip such contracts.
212+
echo -n null > null
213+
find export/ -name '*.json' -exec cmp --quiet --bytes=4 {} null \; -delete
212214

213-
# Generate asm json file (generates C_evm.json)
214-
run_solc "${export_options[@]}"
215-
for asm_json_file in asm_json/*.json
215+
find export/ -name '*.bin' -size 0 -delete
216+
217+
for asm_json_file in export/*.json
216218
do
217-
if [[ -n "$(jq --raw-output '. // empty' "$asm_json_file")" ]]
218-
then
219-
# Remove '_evm' part of filename '<contract-name>_evm.json'
220-
mv "${asm_json_file}" "${asm_json_file/_evm/}"
221-
else
222-
# NOTE: If there is no bytecode, the compiler produces a JSON file that contains just 'null'.
223-
# This is not accepted by assembly import though so we must skip such contracts.
224-
rm "${asm_json_file}"
225-
fi
219+
mv "${asm_json_file}" "${asm_json_file/_evm/}"
226220
done
227221

228-
mkdir -p imported-from-sol/
229-
for asm_json_file in asm_json/*.json
222+
# Import EVM assembly JSON
223+
mkdir -p import/
224+
for asm_json_file in export/*.json
230225
do
231226
local bin_file_from_asm_import
232-
bin_file_from_asm_import="imported-from-sol/$(basename "${asm_json_file}" .json).bin"
227+
bin_file_from_asm_import="import/$(basename "${asm_json_file}" .json).bin"
233228

234229
local import_options=(--bin --import-asm-json "${asm_json_file}")
235230
run_solc_store_stdout "${bin_file_from_asm_import}" "${import_options[@]}"
@@ -238,9 +233,10 @@ function test_evmjson_import_export_equivalence
238233
mv tmpfile "$bin_file_from_asm_import"
239234
done
240235

241-
for bin_file in sol/*
236+
# Compare bytecode from compilation with bytecode from import
237+
for bin_file in export/*.bin
242238
do
243-
local bin_file_from_asm_import=${bin_file/sol/imported-from-sol}
239+
local bin_file_from_asm_import=${bin_file/export/import}
244240
if ! diff --strip-trailing-cr --ignore-all-space "${bin_file}" "${bin_file_from_asm_import}" > diff_error
245241
then
246242
printError "ERROR: Bytecode from compilation (${bin_file}) differs from bytecode from EVM asm import (${bin_file_from_asm_import}):"

0 commit comments

Comments
 (0)