Merge pull request #12192 from ethereum/hardhat-in-oz-ext-test

Use Hardhat and the right binary for OpenZeppelin external tests
This commit is contained in:
Kamil Śliwak 2021-11-30 16:17:28 +01:00 committed by GitHub
commit c04fca7c2d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 112 additions and 12 deletions

View File

@ -946,8 +946,8 @@ jobs:
type: integer
default: 0
nodejs_version:
type: integer
default: 14
type: string
default: latest
docker:
- image: circleci/node:<<parameters.nodejs_version>>
# NOTE: Each external test does 3 separate compile&test runs
@ -1205,16 +1205,19 @@ workflows:
name: t_ems_compile_ext_colony
project: colony
compile_only: 1
nodejs_version: '14'
- t_ems_ext:
<<: *workflow_emscripten
name: t_ems_compile_ext_gnosis
project: gnosis
compile_only: 1
nodejs_version: '14'
- t_ems_ext:
<<: *workflow_emscripten
name: t_ems_compile_ext_gnosis_v2
project: gnosis-v2
compile_only: 1
nodejs_version: '14'
- t_ems_ext:
<<: *workflow_emscripten
name: t_ems_compile_ext_zeppelin
@ -1226,7 +1229,7 @@ workflows:
project: ens
compile_only: 1
# NOTE: One of the dependencies (fsevents) fails to build its native extension on node.js 12+.
nodejs_version: 10
nodejs_version: '10'
# FIXME: Gnosis tests are pretty flaky right now. They often fail on CircleCI due to random ProviderError
# and there are also other less frequent problems. See https://github.com/gnosis/safe-contracts/issues/216.
@ -1235,23 +1238,25 @@ workflows:
# name: t_ems_test_ext_gnosis
# project: gnosis
# # NOTE: Tests do not start on node.js 14 ("ganache-cli exited early with code 1").
# nodejs_version: 12
# nodejs_version: '12'
- t_ems_ext:
<<: *workflow_emscripten
name: t_ems_test_ext_gnosis_v2
project: gnosis-v2
# NOTE: Tests do not start on node.js 14 ("ganache-cli exited early with code 1").
nodejs_version: 12
nodejs_version: '12'
- t_ems_ext:
<<: *workflow_emscripten
name: t_ems_test_ext_zeppelin
project: zeppelin
# 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
project: ens
# NOTE: One of the dependencies (fsevents) fails to build its native extension on node.js 12+.
nodejs_version: 10
nodejs_version: '10'
# Windows build and tests
- b_win: *workflow_trigger_on_tags

View File

@ -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"

View File

@ -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
}