@@ -9,14 +9,15 @@ READLINK=readlink
9
9
if [[ " $OSTYPE " == " darwin" * ]]; then
10
10
READLINK=greadlink
11
11
fi
12
+ IMPORT_TEST_TYPE=${1}
12
13
REPO_ROOT=$( ${READLINK} -f " $( dirname " $0 " ) " /..)
13
14
SOLIDITY_BUILD_DIR=${SOLIDITY_BUILD_DIR:- ${REPO_ROOT} / build}
14
15
SOLC=${SOLIDITY_BUILD_DIR} /solc/solc
15
16
SPLITSOURCES=${REPO_ROOT} /scripts/splitSources.py
16
17
17
18
SYNTAXTESTS_DIR=" ${REPO_ROOT} /test/libsolidity/syntaxTests"
19
+ SEMANTICTESTS_DIR=" ${REPO_ROOT} /test/libsolidity/semanticTests"
18
20
ASTJSONTESTS_DIR=" ${REPO_ROOT} /test/libsolidity/ASTJSON"
19
- NSOURCES=" $( find " $SYNTAXTESTS_DIR " -type f | wc -l) "
20
21
21
22
# DEV_DIR="${REPO_ROOT}/../tmp/contracts/"
22
23
# NSOURCES="$(find $DEV_DIR -type f | wc -l)" #TODO use find command
@@ -40,64 +41,210 @@ function testImportExportEquivalence {
40
41
local nth_input_file=" $1 "
41
42
IFS=" " read -r -a all_input_files <<< " $2"
42
43
43
- if $SOLC " $nth_input_file " " ${all_input_files[@]} " > /dev/null 2>&1
44
+ if $SOLC --bin " $nth_input_file " " ${all_input_files[@]} " > /dev/null 2>&1
44
45
then
45
46
! [[ -e stderr.txt ]] || { echo " stderr.txt already exists. Refusing to overwrite." ; exit 1; }
46
47
47
- # save exported json as expected result (silently)
48
- $SOLC --combined-json ast --pretty-json " $nth_input_file " " ${all_input_files[@]} " > expected.json 2> /dev/null
49
- # import it, and export it again as obtained result (silently)
50
- if ! $SOLC --import-ast --combined-json ast --pretty-json expected.json > obtained.json 2> stderr.txt
48
+ if [ " ${IMPORT_TEST_TYPE} " == " ast" ]
51
49
then
52
- # For investigating, use exit 1 here so the script stops at the
53
- # first failing test
54
- # exit 1
55
- FAILED=$(( FAILED + 1 ))
56
- echo -e " ERROR: AST reimport failed for input file $nth_input_file "
57
- echo
58
- echo " Compiler stderr:"
59
- cat ./stderr.txt
60
- echo
61
- echo " Compiler stdout:"
62
- cat ./obtained.json
63
- return 1
64
- fi
65
- DIFF=" $( diff expected.json obtained.json) "
66
- if [ " $DIFF " != " " ]
67
- then
68
- if [ " $DIFFVIEW " == " " ]
50
+ # save exported json as expected result (silently)
51
+ $SOLC --combined-json ast --pretty-json " $nth_input_file " " ${all_input_files[@]} " > expected.json 2> /dev/null
52
+ # import it, and export it again as obtained result (silently)
53
+ if ! $SOLC --import-ast --combined-json ast --pretty-json expected.json > obtained.json 2> stderr.txt
69
54
then
70
- echo -e " ERROR: JSONS differ for $1 : \n $DIFF \n"
71
- echo " Expected:"
72
- cat ./expected.json
73
- echo " Obtained:"
55
+ # For investigating, use exit 1 here so the script stops at the
56
+ # first failing test
57
+ # exit 1
58
+ FAILED=$(( FAILED + 1 ))
59
+ echo -e " ERROR: AST reimport failed for input file $nth_input_file "
60
+ echo
61
+ echo " Compiler stderr:"
62
+ cat ./stderr.txt
63
+ echo
64
+ echo " Compiler stdout:"
74
65
cat ./obtained.json
66
+ return 1
67
+ fi
68
+ set +e
69
+ DIFF=" $( diff expected.json obtained.json) "
70
+ set +e
71
+ if [ " $DIFF " != " " ]
72
+ then
73
+ if [ " $DIFFVIEW " == " " ]
74
+ then
75
+ echo -e " ERROR: JSONS differ for $1 : \n $DIFF \n"
76
+ echo " Expected:"
77
+ cat ./expected.json
78
+ echo " Obtained:"
79
+ cat ./obtained.json
80
+ else
81
+ # Use user supplied diff view binary
82
+ $DIFFVIEW expected.json obtained.json
83
+ fi
84
+ FAILED=$(( FAILED + 1 ))
85
+ return 2
86
+ fi
87
+ TESTED=$(( TESTED + 1 ))
88
+ rm expected.json obtained.json
89
+ rm -f stderr.txt
90
+ elif [ " ${IMPORT_TEST_TYPE} " == " evm-assembly" ]
91
+ then
92
+ local types=( " asm" " bin" " bin-runtime" " opcodes" " srcmap" " srcmap-runtime" )
93
+ local _TESTED=1
94
+ if ! $SOLC --combined-json bin,bin-runtime,opcodes,asm,srcmap,srcmap-runtime --pretty-json " $nth_input_file " " ${all_input_files[@]} " > expected.json 2> expected.error
95
+ then
96
+ printf " \n"
97
+ echo " $nth_input_file "
98
+ cat expected.error
99
+ UNCOMPILABLE=$(( UNCOMPILABLE + 1 ))
100
+ return 0
75
101
else
76
- # Use user supplied diff view binary
77
- $DIFFVIEW expected.json obtained.json
102
+ for contract in $( jq ' .contracts | keys | .[]' expected.json 2> /dev/null)
103
+ do
104
+ for type in " ${types[@]} "
105
+ do
106
+ jq --raw-output " .contracts.${contract} .\" ${type} \" " expected.json > " expected.${type} "
107
+ done
108
+
109
+ assembly=$( cat expected.asm)
110
+ if [ " $assembly " != " " ] && [ " $assembly " != " null" ]
111
+ then
112
+ if ! $SOLC --combined-json bin,bin-runtime,opcodes,asm,srcmap,srcmap-runtime --pretty-json --import-asm-json expected.asm > obtained.json 2> obtained.error
113
+ then
114
+ printf " \n"
115
+ echo " $nth_input_file "
116
+ cat obtained.error
117
+ FAILED=$(( FAILED + 1 ))
118
+ return 0
119
+ else
120
+ for type in " ${types[@]} "
121
+ do
122
+ for obtained_contract in $( jq ' .contracts | keys | .[]' obtained.json 2> /dev/null)
123
+ do
124
+ jq --raw-output " .contracts.${obtained_contract} .\" ${type} \" " obtained.json > " obtained.${type} "
125
+ set +e
126
+ DIFF=" $( diff " expected.${type} " " obtained.${type} " ) "
127
+ set -e
128
+ if [ " $DIFF " != " " ]
129
+ then
130
+ if [ " $DIFFVIEW " == " " ]
131
+ then
132
+ echo -e " ERROR: JSONS differ for $1 : \n $DIFF \n"
133
+ echo " Expected:"
134
+ cat " expected.${type} "
135
+ echo " Obtained:"
136
+ cat " obtained.${type} "
137
+ else
138
+ # Use user supplied diff view binary
139
+ $DIFFVIEW expected.json obtained.json
140
+ fi
141
+ _TESTED=
142
+ FAILED=$(( FAILED + 1 ))
143
+ return 0
144
+ fi
145
+ done
146
+ done
147
+
148
+ # direct export via --asm-json, if imported with --import-asm-json.
149
+ if ! $SOLC --asm-json --import-asm-json expected.asm | tail -n+4 > obtained_direct_import_export.json 2> obtained_direct_import_export.error
150
+ then
151
+ printf " \n"
152
+ echo " $nth_input_file "
153
+ cat obtained_direct_import_export.error
154
+ FAILED=$(( FAILED + 1 ))
155
+ return 0
156
+ else
157
+ for obtained_contract in $( jq ' .contracts | keys | .[]' obtained_direct_import_export.json 2> /dev/null)
158
+ do
159
+ jq --raw-output " .contracts.${obtained_contract} .\" asm\" " obtained_direct_import_export.json > obtained_direct_import_export.asm
160
+ set +e
161
+ DIFF=" $( diff expected.asm obtained_direct_import_export.asm) "
162
+ set -e
163
+ if [ " $DIFF " != " " ]
164
+ then
165
+ if [ " $DIFFVIEW " == " " ]
166
+ then
167
+ echo -e " ERROR: JSONS differ for $1 : \n $DIFF \n"
168
+ echo " Expected:"
169
+ cat expected.asm
170
+ echo " Obtained:"
171
+ cat obtained_direct_import_export.asm
172
+ else
173
+ # Use user supplied diff view binary
174
+ $DIFFVIEW expected.asm obtained_direct_import_export.asm
175
+ fi
176
+ _TESTED=
177
+ FAILED=$(( FAILED + 1 ))
178
+ return 0
179
+ fi
180
+ done
181
+ fi
182
+
183
+ rm obtained.json
184
+ rm -f obtained.error
185
+ for type in " ${types[@]} "
186
+ do
187
+ rm " obtained.${type} "
188
+ done
189
+ fi
190
+
191
+ for type in " ${types[@]} "
192
+ do
193
+ rm " expected.${type} "
194
+ done
195
+ fi
196
+ done
197
+ rm expected.json
78
198
fi
79
- FAILED=$(( FAILED + 1 ))
80
- return 2
199
+ if [ -n " ${_TESTED} " ]
200
+ then
201
+ TESTED=$(( TESTED + 1 ))
202
+ fi
203
+ else
204
+ echo " unknown import test type. aborting."
205
+ exit 1
81
206
fi
82
- TESTED=$(( TESTED + 1 ))
83
- rm expected.json obtained.json
84
- rm -f stderr.txt
85
207
else
86
- # echo "contract $solfile could not be compiled "
87
208
UNCOMPILABLE=$(( UNCOMPILABLE + 1 ))
88
209
fi
89
- # return 0
90
210
}
91
- echo " Looking at $NSOURCES .sol files..."
92
211
93
212
WORKINGDIR=$PWD
213
+ NSOURCES=0
214
+
215
+ # check whether SOLC works.
216
+ if ! $SOLC --version > /dev/null 2>&1
217
+ then
218
+ echo " $SOLC not found. aborting."
219
+ exit 1
220
+ fi
221
+
222
+ # check whether jq can be found.
223
+ if ! jq --version > /dev/null 2>&1
224
+ then
225
+ echo " jq needed. please install. aborting."
226
+ exit 1
227
+ fi
94
228
95
229
# for solfile in $(find $DEV_DIR -name *.sol)
96
230
# boost_filesystem_bug specifically tests a local fix for a boost::filesystem
97
231
# bug. Since the test involves a malformed path, there is no point in running
98
232
# AST tests on it. See https://github.com/boostorg/filesystem/issues/176
99
- # shellcheck disable=SC2044
100
- for solfile in $( find " $SYNTAXTESTS_DIR " " $ASTJSONTESTS_DIR " -name " *.sol" -and -not -name " boost_filesystem_bug.sol" )
233
+ if [ " ${IMPORT_TEST_TYPE} " == " ast" ]
234
+ then
235
+ IMPORT_TEST_FILES=$( find " ${SYNTAXTESTS_DIR} " " ${ASTJSONTESTS_DIR} " -name " *.sol" -and -not -name " boost_filesystem_bug.sol" )
236
+ elif [ " ${IMPORT_TEST_TYPE} " == " evm-assembly" ]
237
+ then
238
+ IMPORT_TEST_FILES=$( find " ${SYNTAXTESTS_DIR} " " ${SEMANTICTESTS_DIR} " -name " *.sol" -and -not -name " boost_filesystem_bug.sol" )
239
+ else
240
+ echo " unknown import test type. aborting. please specify $0 [ast|evm-assembly]."
241
+ exit 1
242
+ fi
243
+
244
+ NSOURCES=" $( echo " $IMPORT_TEST_FILES " | wc -l) "
245
+ echo " Looking at $NSOURCES .sol files..."
246
+
247
+ for solfile in ${IMPORT_TEST_FILES}
101
248
do
102
249
echo -n " ."
103
250
# create a temporary sub-directory
@@ -148,7 +295,7 @@ echo ""
148
295
149
296
if [ " $FAILED " = 0 ]
150
297
then
151
- echo " SUCCESS: $TESTED syntaxTests passed, $FAILED failed, $UNCOMPILABLE could not be compiled ($NSOURCES sources total)."
298
+ echo " SUCCESS: $TESTED tests passed, $FAILED failed, $UNCOMPILABLE could not be compiled ($NSOURCES sources total)."
152
299
else
153
300
echo " FAILURE: Out of $NSOURCES sources, $FAILED failed, ($UNCOMPILABLE could not be compiled)."
154
301
exit 1
0 commit comments