22
22
23
23
# Requires "${REPO_ROOT}/scripts/common.sh" to be included before.
24
24
25
+ CURRENT_EVM_VERSION=london
26
+
25
27
function verify_input
26
28
{
27
29
if [ ! -f " $1 " ]; then
@@ -51,8 +53,8 @@ function setup_solcjs
51
53
{
52
54
local dir=" $1 "
53
55
local soljson=" $2 "
54
- local branch=" $3 "
55
- local path=" $4 "
56
+ local branch=" ${3 :- master} "
57
+ local path=" ${4 :- solc / } "
56
58
57
59
cd " $dir "
58
60
printLog " Setting up solc-js..."
@@ -86,16 +88,6 @@ function force_truffle_version
86
88
sed -i ' s/"truffle":\s*".*"/"truffle": "' " $version " ' "/g' package.json
87
89
}
88
90
89
- function truffle_setup
90
- {
91
- local soljson=" $1 "
92
- local repo=" $2 "
93
- local branch=" $3 "
94
-
95
- setup_solcjs " $DIR " " $soljson " " master" " solc"
96
- download_project " $repo " " $branch " " $DIR "
97
- }
98
-
99
91
function replace_version_pragmas
100
92
{
101
93
# Replace fixed-version pragmas (part of Consensys best practice).
@@ -104,25 +96,38 @@ function replace_version_pragmas
104
96
find . test -name ' *.sol' -type f -print0 | xargs -0 sed -i -E -e ' s/pragma solidity [^;]+;/pragma solidity >=0.0;/'
105
97
}
106
98
107
- function force_truffle_solc_modules
99
+ function neutralize_package_lock
108
100
{
109
- local soljson=" $1 "
101
+ # Remove lock files (if they exist) to prevent them from overriding our changes in package.json
102
+ printLog " Removing package lock files..."
103
+ rm --force --verbose yarn.lock
104
+ rm --force --verbose package-lock.json
105
+ }
106
+
107
+ function neutralize_package_json_hooks
108
+ {
109
+ printLog " Disabling package.json hooks..."
110
+ [[ -f package.json ]] || fail " package.json not found"
111
+ sed -i ' s|"prepublish": *".*"|"prepublish": ""|g' package.json
112
+ sed -i ' s|"prepare": *".*"|"prepare": ""|g' package.json
113
+ }
110
114
111
- # Replace solc package by v0.5.0 and then overwrite with current version.
112
- printLog " Forcing solc version for all Truffle modules..."
113
- for d in node_modules node_modules/truffle/node_modules
115
+ function force_solc_modules
116
+ {
117
+ local custom_solcjs_path=" ${1:- solc/ } "
118
+
119
+ [[ -d node_modules/ ]] || assertFail
120
+
121
+ printLog " Replacing all installed solc-js with a link to the latest version..."
122
+ soljson_binaries=$( find node_modules -type f -path " */solc/soljson.js" )
123
+ for soljson_binary in $soljson_binaries
114
124
do
115
- (
116
- if [ -d " $d " ]; then
117
- cd $d
118
- rm -rf solc
119
- git clone --depth 1 -b master https://github.com/ethereum/solc-js.git solc
120
- cp " $soljson " solc/soljson.js
121
-
122
- cd solc
123
- npm install
124
- fi
125
- )
125
+ local solc_module_path
126
+ solc_module_path=$( dirname " $soljson_binary " )
127
+
128
+ printLog " Found and replaced solc-js in $solc_module_path "
129
+ rm -r " $solc_module_path "
130
+ ln -s " $custom_solcjs_path " " $solc_module_path "
126
131
done
127
132
}
128
133
@@ -131,7 +136,7 @@ function force_truffle_compiler_settings
131
136
local config_file=" $1 "
132
137
local solc_path=" $2 "
133
138
local level=" $3 "
134
- local evm_version=" $4 "
139
+ local evm_version=" ${4 :- " $CURRENT_EVM_VERSION " } "
135
140
136
141
printLog " Forcing Truffle compiler settings..."
137
142
echo " -------------------------------------"
@@ -147,30 +152,18 @@ function force_truffle_compiler_settings
147
152
echo " module.exports['compilers'] = $( truffle_compiler_settings " $solc_path " " $level " " $evm_version " ) ;" >> " $config_file "
148
153
}
149
154
150
- function verify_compiler_version
155
+ function truffle_verify_compiler_version
151
156
{
152
157
local solc_version=" $1 "
158
+ local full_solc_version=" $2 "
153
159
154
- printLog " Verify that the correct version ($solc_version ) of the compiler was used to compile the contracts..."
155
- grep -e " $solc_version " -r build/contracts > /dev/null
160
+ printLog " Verify that the correct version (${ solc_version} / ${full_solc_version} ) of the compiler was used to compile the contracts..."
161
+ grep " $full_solc_version " --with-filename --recursive build/contracts || fail " Wrong compiler version detected. "
156
162
}
157
163
158
- function clean
164
+ function truffle_clean
159
165
{
160
- rm -rf build || true
161
- }
162
-
163
- function run_install
164
- {
165
- local soljson=" $1 "
166
- local init_fn=" $2 "
167
- printLog " Running install function..."
168
-
169
- replace_version_pragmas
170
- force_truffle_solc_modules " $soljson "
171
- force_truffle_compiler_settings " $CONFIG " " ${DIR} /solc" " $OPTIMIZER_LEVEL " london
172
-
173
- $init_fn
166
+ rm -rf build/
174
167
}
175
168
176
169
function run_test
@@ -219,31 +212,35 @@ function truffle_compiler_settings
219
212
echo " }"
220
213
}
221
214
222
- function truffle_run_test
215
+ function compile_and_run_test
223
216
{
224
- local soljson =" $1 "
225
- local compile_fn =" $2 "
226
- local test_fn =" $3 "
217
+ local compile_fn =" $1 "
218
+ local test_fn =" $2 "
219
+ local verify_fn =" $3 "
227
220
228
- replace_version_pragmas
229
- force_truffle_solc_modules " $soljson "
221
+ printLog " Running compile function..."
222
+ $compile_fn
223
+ $verify_fn " $SOLCVERSION_SHORT " " $SOLCVERSION "
230
224
231
- for level in $( seq " $OPTIMIZER_LEVEL " 3)
232
- do
233
- clean
234
- force_truffle_compiler_settings " $CONFIG " " ${DIR} /solc" " $level " london
235
-
236
- printLog " Running compile function..."
237
- $compile_fn
238
- verify_compiler_version " $SOLCVERSION "
239
-
240
- if [[ " $COMPILE_ONLY " == 1 ]]; then
241
- printLog " Skipping test function..."
242
- else
243
- printLog " Running test function..."
244
- $test_fn
245
- fi
246
- done
225
+ if [[ " $COMPILE_ONLY " == 1 ]]; then
226
+ printLog " Skipping test function..."
227
+ else
228
+ printLog " Running test function..."
229
+ $test_fn
230
+ fi
231
+ }
232
+
233
+ function truffle_run_test
234
+ {
235
+ local config_file=" $1 "
236
+ local solc_path=" $2 "
237
+ local optimizer_level=" $3 "
238
+ local compile_fn=" $4 "
239
+ local test_fn=" $5 "
240
+
241
+ truffle_clean
242
+ force_truffle_compiler_settings " $config_file " " $solc_path " " $optimizer_level "
243
+ compile_and_run_test compile_fn test_fn truffle_verify_compiler_version
247
244
}
248
245
249
246
function external_test
0 commit comments