Skip to content

Commit aeeae0c

Browse files
authored
Merge pull request #596 from crytic/dev-tests
tests: sort contractDependencies
2 parents 9f4ca0b + f1b0ec0 commit aeeae0c

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

scripts/ci_test_solc_multi_file.sh

+39
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,51 @@
22

33
DIR=$(mktemp -d)
44

5+
normalize_file() {
6+
JQ_SCRIPT=$(cat <<'EOF'
7+
def sort_deps:
8+
if type == "object" then
9+
# Process each key-value pair
10+
with_entries(
11+
if .key == "contractDependencies" and (.value | type == "array") then
12+
.value = (.value | sort)
13+
else
14+
.value = (.value | sort_deps)
15+
end
16+
)
17+
elif type == "array" then
18+
# Process each array element recursively
19+
map(sort_deps)
20+
else
21+
.
22+
end;
23+
24+
sort_deps
25+
EOF
26+
)
27+
28+
jq "$JQ_SCRIPT" "$1" > "$1.mod"
29+
mv "$1.mod" "$1"
30+
}
31+
532
cp -r tests/solc-multi-file "$DIR"
633
cd "$DIR/solc-multi-file" || exit 255
734
crytic-compile --compile-remove-metadata --export-formats solc,truffle A.sol
835

936
cd - || exit 255
1037
node tests/process_combined_solc.js "$DIR/solc-multi-file/crytic-export/combined_solc.json" "$DIR"
38+
39+
case "$(uname -sr)" in
40+
#for some reason, contractDependencies appear in random order in Windows
41+
#so we sort them for consistency in the tests
42+
CYGWIN*|MINGW*|MSYS*)
43+
echo "Testing on Windows, doing extra JSON normalization"
44+
for f in "$DIR/solc-multi-file/crytic-export/"*.json tests/expected/solc-multi-file/*.json; do
45+
normalize_file "$f"
46+
done
47+
;;
48+
esac
49+
1150
DIFF=$(diff -r "$DIR/solc-multi-file/crytic-export" tests/expected/solc-multi-file)
1251
if [ "$?" != "0" ] || [ "$DIFF" != "" ]
1352
then

0 commit comments

Comments
 (0)