@@ -74,6 +74,7 @@ function setup_solcjs
7474 npm install
7575 cp " $soljson " soljson.js
7676 SOLCVERSION=$( ./solcjs --version)
77+ SOLCVERSION_SHORT=$( echo " $SOLCVERSION " | sed -En ' s/^([0-9.]+).*\+commit\.[0-9a-f]+.*$/\1/p' )
7778 printLog " Using solcjs version $SOLCVERSION "
7879 cd ..
7980}
@@ -161,6 +162,40 @@ function force_truffle_compiler_settings
161162 echo " module.exports['compilers'] = $( truffle_compiler_settings " $solc_path " " $level " " $evm_version " ) ;" >> " $config_file "
162163}
163164
165+ function force_hardhat_compiler_binary
166+ {
167+ local config_file=" $1 "
168+ local solc_path=" $2 "
169+
170+ printLog " Configuring Hardhat..."
171+ echo " -------------------------------------"
172+ echo " Config file: ${config_file} "
173+ echo " Compiler path: ${solc_path} "
174+ hardhat_solc_build_subtask " $SOLCVERSION_SHORT " " $SOLCVERSION " " $solc_path " >> " $config_file "
175+ }
176+
177+ function force_hardhat_compiler_settings
178+ {
179+ local config_file=" $1 "
180+ local level=" $2 "
181+ local evm_version=" ${3:- " $CURRENT_EVM_VERSION " } "
182+
183+ printLog " Configuring Hardhat..."
184+ echo " -------------------------------------"
185+ echo " Config file: ${config_file} "
186+ echo " Optimization level: ${level} "
187+ echo " Optimizer settings: $( optimizer_settings_for_level " $level " ) "
188+ echo " EVM version: ${evm_version} "
189+ echo " Compiler version: ${SOLCVERSION_SHORT} "
190+ echo " Compiler version (full): ${SOLCVERSION} "
191+ echo " -------------------------------------"
192+
193+ {
194+ echo -n ' module.exports["solidity"] = '
195+ hardhat_compiler_settings " $SOLCVERSION_SHORT " " $level " " $evm_version "
196+ } >> " $config_file "
197+ }
198+
164199function truffle_verify_compiler_version
165200{
166201 local solc_version=" $1 "
@@ -170,11 +205,26 @@ function truffle_verify_compiler_version
170205 grep " $full_solc_version " --with-filename --recursive build/contracts || fail " Wrong compiler version detected."
171206}
172207
208+ function hardhat_verify_compiler_version
209+ {
210+ local solc_version=" $1 "
211+ local full_solc_version=" $2 "
212+
213+ printLog " Verify that the correct version (${solc_version} /${full_solc_version} ) of the compiler was used to compile the contracts..."
214+ grep ' "solcVersion": "' " ${solc_version} " ' "' --with-filename artifacts/build-info/* .json || fail " Wrong compiler version detected."
215+ grep ' "solcLongVersion": "' " ${full_solc_version} " ' "' --with-filename artifacts/build-info/* .json || fail " Wrong compiler version detected."
216+ }
217+
173218function truffle_clean
174219{
175220 rm -rf build/
176221}
177222
223+ function hardhat_clean
224+ {
225+ rm -rf artifacts/ cache/
226+ }
227+
178228function run_test
179229{
180230 local compile_fn=" $1 "
@@ -221,6 +271,39 @@ function truffle_compiler_settings
221271 echo " }"
222272}
223273
274+ function hardhat_solc_build_subtask {
275+ local solc_version=" $1 "
276+ local full_solc_version=" $2 "
277+ local solc_path=" $3 "
278+
279+ echo " const {TASK_COMPILE_SOLIDITY_GET_SOLC_BUILD} = require('hardhat/builtin-tasks/task-names');"
280+ echo " const assert = require('assert');"
281+ echo
282+ echo " subtask(TASK_COMPILE_SOLIDITY_GET_SOLC_BUILD, async (args, hre, runSuper) => {"
283+ echo " assert(args.solcVersion == '${solc_version} ', 'Unexpected solc version: ' + args.solcVersion)"
284+ echo " return {"
285+ echo " compilerPath: '$( realpath " $solc_path " ) ',"
286+ echo " isSolcJs: true,"
287+ echo " version: args.solcVersion,"
288+ echo " longVersion: '${full_solc_version} '"
289+ echo " }"
290+ echo " })"
291+ }
292+
293+ function hardhat_compiler_settings {
294+ local solc_version=" $1 "
295+ local level=" $2 "
296+ local evm_version=" $3 "
297+
298+ echo " {"
299+ echo " version: '${solc_version} ',"
300+ echo " settings: {"
301+ echo " optimizer: $( optimizer_settings_for_level " $level " ) ,"
302+ echo " evmVersion: '${evm_version} '"
303+ echo " }"
304+ echo " }"
305+ }
306+
224307function compile_and_run_test
225308{
226309 local compile_fn=" $1 "
@@ -252,6 +335,18 @@ function truffle_run_test
252335 compile_and_run_test compile_fn test_fn truffle_verify_compiler_version
253336}
254337
338+ function hardhat_run_test
339+ {
340+ local config_file=" $1 "
341+ local optimizer_level=" $2 "
342+ local compile_fn=" $3 "
343+ local test_fn=" $4 "
344+
345+ hardhat_clean
346+ force_hardhat_compiler_settings " $config_file " " $optimizer_level "
347+ compile_and_run_test compile_fn test_fn hardhat_verify_compiler_version
348+ }
349+
255350function external_test
256351{
257352 local name=" $1 "
0 commit comments