Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Hardhat and the right binary for OpenZeppelin external tests #12192

Merged
merged 2 commits into from
Nov 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -946,8 +946,8 @@ jobs:
type: integer
default: 0
nodejs_version:
type: integer
default: 14
type: string
default: latest
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which other task uses this with default?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this PR only t_ems_compile_ext_zeppelin. But I have a bunch of other PRs updating external tests. Eventually most of the t_ems_compile_XYZ jobs will be using the default because they work fine on nodejs 17. And I would use it for t_ems_test_XYZ jobs too but most of them now use Hardhat and it does not support node 17 yet (NomicFoundation/hardhat#1988).

docker:
- image: circleci/node:<<parameters.nodejs_version>>
# NOTE: Each external test does 3 separate compile&test runs
Expand Down Expand Up @@ -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
Expand All @@ -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.
Expand All @@ -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
Expand Down
95 changes: 95 additions & 0 deletions test/externalTests/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 ..
}
Expand Down Expand Up @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down
12 changes: 6 additions & 6 deletions test/externalTests/zeppelin.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

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

Expand Down