diff --git a/.circleci/config.yml b/.circleci/config.yml index 398e73e49..7a24abab4 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1223,7 +1223,6 @@ workflows: name: t_ems_compile_ext_zeppelin project: zeppelin compile_only: 1 - nodejs_version: '14' - t_ems_ext: <<: *workflow_emscripten name: t_ems_compile_ext_ens @@ -1250,7 +1249,8 @@ workflows: <<: *workflow_emscripten name: t_ems_test_ext_zeppelin project: zeppelin - nodejs_version: '14' + # NOTE: Tests crash on nodejs 17: "Error: error:0308010C:digital envelope routines::unsupported" + nodejs_version: '16' - t_ems_ext: <<: *workflow_emscripten name: t_ems_test_ext_ens diff --git a/test/externalTests/common.sh b/test/externalTests/common.sh index 2519a0f87..7e651d8c0 100644 --- a/test/externalTests/common.sh +++ b/test/externalTests/common.sh @@ -74,6 +74,7 @@ function setup_solcjs npm install cp "$soljson" soljson.js SOLCVERSION=$(./solcjs --version) + SOLCVERSION_SHORT=$(echo "$SOLCVERSION" | sed -En 's/^([0-9.]+).*\+commit\.[0-9a-f]+.*$/\1/p') printLog "Using solcjs version $SOLCVERSION" cd .. } @@ -161,6 +162,40 @@ function force_truffle_compiler_settings echo "module.exports['compilers'] = $(truffle_compiler_settings "$solc_path" "$level" "$evm_version");" >> "$config_file" } +function force_hardhat_compiler_binary +{ + local config_file="$1" + local solc_path="$2" + + printLog "Configuring Hardhat..." + echo "-------------------------------------" + echo "Config file: ${config_file}" + echo "Compiler path: ${solc_path}" + hardhat_solc_build_subtask "$SOLCVERSION_SHORT" "$SOLCVERSION" "$solc_path" >> "$config_file" +} + +function force_hardhat_compiler_settings +{ + local config_file="$1" + local level="$2" + local evm_version="${3:-"$CURRENT_EVM_VERSION"}" + + printLog "Configuring Hardhat..." + echo "-------------------------------------" + echo "Config file: ${config_file}" + echo "Optimization level: ${level}" + echo "Optimizer settings: $(optimizer_settings_for_level "$level")" + echo "EVM version: ${evm_version}" + echo "Compiler version: ${SOLCVERSION_SHORT}" + echo "Compiler version (full): ${SOLCVERSION}" + echo "-------------------------------------" + + { + echo -n 'module.exports["solidity"] = ' + hardhat_compiler_settings "$SOLCVERSION_SHORT" "$level" "$evm_version" + } >> "$config_file" +} + function truffle_verify_compiler_version { local solc_version="$1" @@ -170,11 +205,26 @@ function truffle_verify_compiler_version grep "$full_solc_version" --with-filename --recursive build/contracts || fail "Wrong compiler version detected." } +function hardhat_verify_compiler_version +{ + local solc_version="$1" + local full_solc_version="$2" + + printLog "Verify that the correct version (${solc_version}/${full_solc_version}) of the compiler was used to compile the contracts..." + grep '"solcVersion": "'"${solc_version}"'"' --with-filename artifacts/build-info/*.json || fail "Wrong compiler version detected." + grep '"solcLongVersion": "'"${full_solc_version}"'"' --with-filename artifacts/build-info/*.json || fail "Wrong compiler version detected." +} + function truffle_clean { rm -rf build/ } +function hardhat_clean +{ + rm -rf artifacts/ cache/ +} + function run_test { local compile_fn="$1" @@ -221,6 +271,39 @@ function truffle_compiler_settings echo "}" } +function hardhat_solc_build_subtask { + local solc_version="$1" + local full_solc_version="$2" + local solc_path="$3" + + echo "const {TASK_COMPILE_SOLIDITY_GET_SOLC_BUILD} = require('hardhat/builtin-tasks/task-names');" + echo "const assert = require('assert');" + echo + echo "subtask(TASK_COMPILE_SOLIDITY_GET_SOLC_BUILD, async (args, hre, runSuper) => {" + echo " assert(args.solcVersion == '${solc_version}', 'Unexpected solc version: ' + args.solcVersion)" + echo " return {" + echo " compilerPath: '$(realpath "$solc_path")'," + echo " isSolcJs: true," + echo " version: args.solcVersion," + echo " longVersion: '${full_solc_version}'" + echo " }" + echo "})" +} + +function hardhat_compiler_settings { + local solc_version="$1" + local level="$2" + local evm_version="$3" + + echo "{" + echo " version: '${solc_version}'," + echo " settings: {" + echo " optimizer: $(optimizer_settings_for_level "$level")," + echo " evmVersion: '${evm_version}'" + echo " }" + echo "}" +} + function compile_and_run_test { local compile_fn="$1" @@ -252,6 +335,18 @@ function truffle_run_test compile_and_run_test compile_fn test_fn truffle_verify_compiler_version } +function hardhat_run_test +{ + local config_file="$1" + local optimizer_level="$2" + local compile_fn="$3" + local test_fn="$4" + + hardhat_clean + force_hardhat_compiler_settings "$config_file" "$optimizer_level" + compile_and_run_test compile_fn test_fn hardhat_verify_compiler_version +} + function external_test { local name="$1" diff --git a/test/externalTests/zeppelin.sh b/test/externalTests/zeppelin.sh index 24e576b93..cd290b860 100755 --- a/test/externalTests/zeppelin.sh +++ b/test/externalTests/zeppelin.sh @@ -27,14 +27,14 @@ source test/externalTests/common.sh verify_input "$1" SOLJSON="$1" -function compile_fn { npx truffle compile; } -function test_fn { npm run test; } +function compile_fn { npm run compile; } +function test_fn { npm test; } function zeppelin_test { local repo="https://github.com/OpenZeppelin/openzeppelin-contracts.git" local branch=master - local config_file="truffle-config.js" + local config_file="hardhat.config.js" local min_optimizer_level=1 local max_optimizer_level=3 @@ -46,14 +46,14 @@ function zeppelin_test download_project "$repo" "$branch" "$DIR" neutralize_package_json_hooks - force_truffle_compiler_settings "$config_file" "${DIR}/solc" "$min_optimizer_level" + force_hardhat_compiler_binary "$config_file" "$SOLJSON" + force_hardhat_compiler_settings "$config_file" "$min_optimizer_level" npm install replace_version_pragmas - force_solc_modules "${DIR}/solc" for level in $selected_optimizer_levels; do - truffle_run_test "$config_file" "${DIR}/solc" "$level" compile_fn test_fn + hardhat_run_test "$config_file" "$level" compile_fn test_fn done }