diff --git a/test/externalTests/common.sh b/test/externalTests/common.sh index 94aa660d4a6e..07ec28c7db29 100644 --- a/test/externalTests/common.sh +++ b/test/externalTests/common.sh @@ -65,6 +65,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 .. } @@ -150,6 +151,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" @@ -159,11 +194,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" @@ -208,6 +258,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" @@ -239,6 +322,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 89c3f7c67d3c..82c422e0fb13 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/solidity-external-tests/openzeppelin-contracts.git" - local branch=master_080 - local config_file="truffle-config.js" + local repo="https://github.com/OpenZeppelin/openzeppelin-contracts.git" + local branch=master + local config_file="hardhat.config.js" local min_optimizer_level=1 local max_optimizer_level=3 @@ -42,14 +42,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 $(seq "$min_optimizer_level" "$max_optimizer_level"); do - truffle_run_test "$config_file" "${DIR}/solc" "$level" compile_fn test_fn + hardhat_run_test "$config_file" "$level" compile_fn test_fn done }