2019-04-01 12:32:53 +00:00
#!/usr/bin/env bash
# ------------------------------------------------------------------------------
# This file is part of solidity.
#
# solidity is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# solidity is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with solidity. If not, see <http://www.gnu.org/licenses/>
#
# (c) 2019 solidity contributors.
#------------------------------------------------------------------------------
2021-10-25 12:30:15 +00:00
2022-04-13 20:00:07 +00:00
# Disable shellcheck errors on quoted special chars like backticks. Too many false-positives.
# shellcheck disable=SC2016
2021-10-25 12:30:15 +00:00
set -e
2023-01-05 12:10:42 +00:00
# Temporary(?) fix to up the heap limit for node in order to prevent 'out of heap errors'
export NODE_OPTIONS = "--max-old-space-size=4096"
2021-10-25 12:30:15 +00:00
2019-04-26 09:57:49 +00:00
source scripts/common.sh
2023-04-26 12:14:36 +00:00
source scripts/externalTests/common.sh
2019-04-01 12:32:53 +00:00
2021-12-17 23:36:30 +00:00
REPO_ROOT = $( realpath " $( dirname " $0 " ) /../.. " )
2021-12-03 11:57:39 +00:00
verify_input " $@ "
2021-12-03 13:51:05 +00:00
BINARY_TYPE = " $1 "
2022-06-21 17:49:34 +00:00
BINARY_PATH = " $( realpath " $2 " ) "
2021-12-17 15:01:19 +00:00
SELECTED_PRESETS = " $3 "
2019-04-01 12:32:53 +00:00
2021-10-26 13:49:00 +00:00
function compile_fn { npm run compile; }
function test_fn { npm test; }
2019-04-01 12:32:53 +00:00
function zeppelin_test
{
2021-10-25 12:29:43 +00:00
local repo = "https://github.com/OpenZeppelin/openzeppelin-contracts.git"
2022-01-10 16:25:20 +00:00
local ref_type = branch
local ref = "master"
2021-10-26 13:49:00 +00:00
local config_file = "hardhat.config.js"
2021-12-10 18:27:18 +00:00
2023-04-21 13:14:35 +00:00
local compile_only_presets = (
#ir-no-optimize # Compilation fails with "Contract initcode size is 49410 bytes and exceeds 49152 bytes (a limit introduced in Shanghai)."
ir-optimize-evm-only # FIXME: A few tests fail with "Transaction: ... exited with an error (status 0) after consuming all gas."
)
2021-12-09 13:37:21 +00:00
local settings_presets = (
2021-12-10 18:27:18 +00:00
" ${ compile_only_presets [@] } "
2022-03-01 16:48:46 +00:00
ir-optimize-evm+yul
2021-12-09 13:37:21 +00:00
legacy-no-optimize
legacy-optimize-evm-only
legacy-optimize-evm+yul
)
2021-10-25 12:29:43 +00:00
2021-12-17 15:01:19 +00:00
[ [ $SELECTED_PRESETS != "" ] ] || SELECTED_PRESETS = $( circleci_select_steps_multiarg " ${ settings_presets [@] } " )
print_presets_or_exit " $SELECTED_PRESETS "
2021-10-28 10:46:34 +00:00
2021-12-03 13:51:05 +00:00
setup_solc " $DIR " " $BINARY_TYPE " " $BINARY_PATH "
2022-01-10 16:25:20 +00:00
download_project " $repo " " $ref_type " " $ref " " $DIR "
2021-10-25 12:29:43 +00:00
2022-03-01 16:48:46 +00:00
# Disable tests that won't pass on the ir presets due to Hardhat heuristics. Note that this also disables
# them for other presets but that's fine - we want same code run for benchmarks to be comparable.
2023-03-06 17:59:46 +00:00
# TODO: Remove the lines below when Hardhat adjusts heuristics for IR (https://github.com/nomiclabs/hardhat/issues/3750).
sed -i "s|it(\('proxy admin cannot call delegated functions',\)|it.skip(\1|g" test/proxy/transparent/TransparentUpgradeableProxy.behaviour.js
2023-04-06 11:23:36 +00:00
sed -i "s|describe(\('when the given implementation is the zero address'\)|describe.skip(\1|g" test/proxy/transparent/TransparentUpgradeableProxy.behaviour.js
sed -i "s|describe(\('when the new proposed admin is the zero address'\)|describe.skip(\1|g" test/proxy/transparent/TransparentUpgradeableProxy.behaviour.js
2022-03-01 16:48:46 +00:00
# In some cases Hardhat does not detect revert reasons properly via IR.
2022-04-13 20:00:07 +00:00
sed -i "s|it(\('prevent unauthorized maintenance'\)|it.skip(\1|g" test/governance/TimelockController.test.js
sed -i "s|it(\('cannot cancel invalid operation'\)|it.skip(\1|g" test/governance/TimelockController.test.js
sed -i "s|it(\('cannot call onlyInitializable function outside the scope of an initializable function'\)|it.skip(\1|g" test/proxy/utils/Initializable.test.js
sed -i "s|it(\('reverts when sending non-zero amounts'\)|it.skip(\1|g" test/utils/Address.test.js
sed -i "s|it(\('reverts when sending more than the balance'\)|it.skip(\1|g" test/utils/Address.test.js
sed -i "s|it(\('fails deploying a contract if the bytecode length is zero'\)|it.skip(\1|g" test/utils/Create2.test.js
sed -i "s|it(\('fails deploying a contract if factory contract does not have sufficient balance'\)|it.skip(\1|g" test/utils/Create2.test.js
sed -i "s|it(\('reverts when casting -1'\)|it.skip(\1|g" test/utils/math/SafeCast.test.js
sed -i 's|it(\(`reverts when casting [^`]\+`\)|it.skip(\1|g' test/utils/math/SafeCast.test.js
2022-05-24 18:27:59 +00:00
sed -i "s|it(\('reverts if index is greater than supply'\)|it.skip(\1|g" test/token/ERC721/ERC721.behavior.js
sed -i "s|it(\('burns all tokens'\)|it.skip(\1|g" test/token/ERC721/ERC721.behavior.js
2022-09-05 10:11:26 +00:00
sed -i "s|it(\('guards transfer against invalid user'\)|it.skip(\1|g" test/access/Ownable2Step.test.js
2023-07-14 10:54:28 +00:00
sed -i "s|it(\('reverting initialization function'\)|it.skip(\1|g" test/proxy/beacon/BeaconProxy.test.js
2022-08-04 14:44:19 +00:00
sed -i "s|describe(\('reverting initialization'\)|describe.skip(\1|g" test/proxy/Proxy.behaviour.js
sed -i "s|it(\('does not allow remote callback'\)|it.skip(\1|g" test/security/ReentrancyGuard.test.js
2023-03-06 17:59:46 +00:00
2023-06-14 07:36:40 +00:00
# TODO: Remove when hardhat properly handle reverts of custom errors with via-ir enabled
# and/or open-zeppelin fix https://github.com/OpenZeppelin/openzeppelin-contracts/issues/4349
sed -i "s|it(\('cannot nest reinitializers'\)|it.skip(\1|g" test/proxy/utils/Initializable.test.js
sed -i "s|it(\('prevents re-initialization'\)|it.skip(\1|g" test/proxy/utils/Initializable.test.js
sed -i "s|it(\('can lock contract after initialization'\)|it.skip(\1|g" test/proxy/utils/Initializable.test.js
2023-06-21 10:19:55 +00:00
sed -i "s|it(\('calling upgradeTo on the implementation reverts'\)|it.skip(\1|g" test/proxy/utils/UUPSUpgradeable.test.js
sed -i "s|it(\('calling upgradeToAndCall on the implementation reverts'\)|it.skip(\1|g" test/proxy/utils/UUPSUpgradeable.test.js
sed -i "s|it(\('calling upgradeTo from a contract that is not an ERC1967 proxy\)|it.skip(\1|g" test/proxy/utils/UUPSUpgradeable.test.js
sed -i "s|it(\('calling upgradeToAndCall from a contract that is not an ERC1967 proxy\)|it.skip(\1|g" test/proxy/utils/UUPSUpgradeable.test.js
2023-06-14 07:36:40 +00:00
2023-03-06 17:59:46 +00:00
# Here only the testToInt(248) and testToInt(256) cases fail so change the loop range to skip them
sed -i "s|range(8, 256, 8)\(.forEach(bits => testToInt(bits));\)|range(8, 240, 8)\1|" test/utils/math/SafeCast.test.js
2022-03-01 16:48:46 +00:00
2023-03-06 17:59:46 +00:00
neutralize_package_lock
2021-10-26 13:39:19 +00:00
neutralize_package_json_hooks
2021-12-03 13:51:05 +00:00
force_hardhat_compiler_binary " $config_file " " $BINARY_TYPE " " $BINARY_PATH "
2021-12-17 15:01:19 +00:00
force_hardhat_compiler_settings " $config_file " " $( first_word " $SELECTED_PRESETS " ) "
2021-10-25 12:29:43 +00:00
npm install
replace_version_pragmas
2021-12-17 15:01:19 +00:00
for preset in $SELECTED_PRESETS ; do
2021-12-10 18:27:18 +00:00
hardhat_run_test " $config_file " " $preset " " ${ compile_only_presets [*] } " compile_fn test_fn
2021-12-17 23:36:30 +00:00
store_benchmark_report hardhat zeppelin " $repo " " $preset "
2021-10-25 12:29:43 +00:00
done
2019-04-01 12:32:53 +00:00
}
external_test Zeppelin zeppelin_test