[scripts/AsmJsonImportTest.sh] Enable checks of source maps & minor improvements.

This commit is contained in:
Alexander Arlt 2021-11-12 11:02:01 -05:00
parent 5c3a618b6c
commit ed9c09b2e2

View File

@ -1,11 +1,11 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# Bash script to test the asm-json-import input mode of the compiler by # Bash script to test the asm-json-import input mode of the compiler by
# first exporting a .sol file to JSON that containing assembly json and corresponding bytecode, # first exporting a .sol file to JSON that containing assembly json, deploy & runtime bytecode, opcodes and source mappings,
# then the compiler is invoked in assembly json import mode `--import-asm-json` and uses the previously # then the compiler is invoked in assembly json import mode `--import-asm-json` and uses the previously
# generated assembly json as input, where the corresponding bytecode output will be stored. # generated assembly. This output will be stored.
# Finally, the originally generated bytecode will be compared with the one that was generated by using the # Finally, the originally generated outputs (bin, bin-runtime, opcodes, asm, srcmap and srcmap-runtime)
# assembly json file as input. # will be compared with the outputs that where generated by using the assembly json file as input.
set -eo pipefail set -eo pipefail
READLINK=readlink READLINK=readlink
@ -34,7 +34,6 @@ function testImportExportEquivalence {
if $SOLC "$nth_input_file" "${all_input_files[@]}" --combined-json asm,bin > /dev/null 2>&1 if $SOLC "$nth_input_file" "${all_input_files[@]}" --combined-json asm,bin > /dev/null 2>&1
then then
local types=( "bin" "bin-runtime" "opcodes" "asm" "srcmap" "srcmap-runtime" ) local types=( "bin" "bin-runtime" "opcodes" "asm" "srcmap" "srcmap-runtime" )
local test_types=( "bin" "bin-runtime" "opcodes" "asm" )
# save exported json as expected result (silently) # save exported json as expected result (silently)
$SOLC --combined-json asm,opcodes,bin,srcmap,srcmap-runtime,bin-runtime --pretty-json "$nth_input_file" "${all_input_files[@]}" > expected.json 2> /dev/null $SOLC --combined-json asm,opcodes,bin,srcmap,srcmap-runtime,bin-runtime --pretty-json "$nth_input_file" "${all_input_files[@]}" > expected.json 2> /dev/null
@ -62,7 +61,7 @@ function testImportExportEquivalence {
return 1 return 1
fi fi
for type in "${test_types[@]}" for type in "${types[@]}"
do do
jq --raw-output ".contracts.\"expected.asm\".\"${type}\"" imported.json > "imported.${type}" jq --raw-output ".contracts.\"expected.asm\".\"${type}\"" imported.json > "imported.${type}"
if ! diff "expected.${type}" "imported.${type}" if ! diff "expected.${type}" "imported.${type}"
@ -77,7 +76,7 @@ function testImportExportEquivalence {
echo "Obtained:" echo "Obtained:"
cat "./imported.${type}" cat "./imported.${type}"
else else
# Use user supplied diff view binary # Use user supplied diff view mismatched output
$DIFFVIEW "expected.${type}" "imported.${type}" $DIFFVIEW "expected.${type}" "imported.${type}"
fi fi
FAILED=$((FAILED + 1)) FAILED=$((FAILED + 1))
@ -86,12 +85,17 @@ function testImportExportEquivalence {
done done
done done
TESTED=$((TESTED + 1)) TESTED=$((TESTED + 1))
rm -f expected.json asm.json expected.bin imported.bin rm -f expected.json
rm -f imported.json
for type in "${types[@]}"
do
rm -f "expected.${type}"
rm -f "imported.${type}"
done
else else
# echo "contract $solfile could not be compiled " # echo "contract $solfile could not be compiled "
UNCOMPILABLE=$((UNCOMPILABLE + 1)) UNCOMPILABLE=$((UNCOMPILABLE + 1))
fi fi
# return 0
} }
echo "Looking at $NSOURCES .sol files..." echo "Looking at $NSOURCES .sol files..."