|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +# ------------------------------------------------------------------------------ |
| 4 | +# This file is part of solidity. |
| 5 | +# |
| 6 | +# solidity is free software: you can redistribute it and/or modify |
| 7 | +# it under the terms of the GNU General Public License as published by |
| 8 | +# the Free Software Foundation, either version 3 of the License, or |
| 9 | +# (at your option) any later version. |
| 10 | +# |
| 11 | +# solidity is distributed in the hope that it will be useful, |
| 12 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | +# GNU General Public License for more details. |
| 15 | +# |
| 16 | +# You should have received a copy of the GNU General Public License |
| 17 | +# along with solidity. If not, see <http://www.gnu.org/licenses/> |
| 18 | +# |
| 19 | +# (c) 2019 solidity contributors. |
| 20 | +#------------------------------------------------------------------------------ |
| 21 | + |
| 22 | +set -e |
| 23 | + |
| 24 | +source scripts/common.sh |
| 25 | +source test/externalTests/common.sh |
| 26 | + |
| 27 | +REPO_ROOT=$(realpath "$(dirname "$0")/../..") |
| 28 | + |
| 29 | +verify_input "$@" |
| 30 | +BINARY_TYPE="$1" |
| 31 | +BINARY_PATH="$2" |
| 32 | +SELECTED_PRESETS="$3" |
| 33 | + |
| 34 | +function compile_fn { npm run build; } |
| 35 | +function test_fn { npm test; } |
| 36 | + |
| 37 | +function gp2_test |
| 38 | +{ |
| 39 | + local repo="https://github.com/gnosis/gp-v2-contracts.git" |
| 40 | + local ref_type=branch |
| 41 | + local ref=main |
| 42 | + local config_file="hardhat.config.ts" |
| 43 | + local config_var="config" |
| 44 | + |
| 45 | + local compile_only_presets=( |
| 46 | + legacy-no-optimize # Tests doing `new GPv2VaultRelayer` fail with "Error: Transaction reverted: trying to deploy a contract whose code is too large" |
| 47 | + ) |
| 48 | + local settings_presets=( |
| 49 | + "${compile_only_presets[@]}" |
| 50 | + #ir-no-optimize # Compilation fails with "YulException: Variable var_amount_1468 is 10 slot(s) too deep inside the stack." |
| 51 | + #ir-no-optimize # Compilation fails with "YulException: Variable var_offset_3451 is 1 slot(s) too deep inside the stack." |
| 52 | + ir-optimize-evm+yul |
| 53 | + legacy-optimize-evm-only |
| 54 | + legacy-optimize-evm+yul |
| 55 | + ) |
| 56 | + |
| 57 | + [[ $SELECTED_PRESETS != "" ]] || SELECTED_PRESETS=$(circleci_select_steps_multiarg "${settings_presets[@]}") |
| 58 | + print_presets_or_exit "$SELECTED_PRESETS" |
| 59 | + |
| 60 | + setup_solc "$DIR" "$BINARY_TYPE" "$BINARY_PATH" |
| 61 | + download_project "$repo" "$ref_type" "$ref" "$DIR" |
| 62 | + [[ $BINARY_TYPE == native ]] && replace_global_solc "$BINARY_PATH" |
| 63 | + |
| 64 | + neutralize_package_lock |
| 65 | + neutralize_package_json_hooks |
| 66 | + name_hardhat_default_export "$config_file" "$config_var" |
| 67 | + force_hardhat_compiler_binary "$config_file" "$BINARY_TYPE" "$BINARY_PATH" |
| 68 | + force_hardhat_compiler_settings "$config_file" "$(first_word "$SELECTED_PRESETS")" "$config_var" |
| 69 | + force_hardhat_unlimited_contract_size "$config_file" "$config_var" |
| 70 | + npm install |
| 71 | + |
| 72 | + # Some dependencies come with pre-built artifacts. We want to build from scratch. |
| 73 | + rm -r node_modules/@gnosis.pm/safe-contracts/build/ |
| 74 | + |
| 75 | + # FIXME: One of the E2E tests tries to import artifacts from Gnosis Safe. We should rebuild them |
| 76 | + # but it's not that easy because @gnosis.pm/safe-contracts does not come with Hardhat config. |
| 77 | + rm test/e2e/contractOrdersWithGnosisSafe.test.ts |
| 78 | + |
| 79 | + # Patch contracts for 0.8.x compatibility. |
| 80 | + # NOTE: I'm patching OpenZeppelin as well instead of installing OZ 4.0 because it requires less |
| 81 | + # work. The project imports files that were moved to different locations in 4.0. |
| 82 | + sed -i 's|uint256(-1)|type(uint256).max|g' src/contracts/GPv2Settlement.sol |
| 83 | + sed -i 's|return msg\.sender;|return payable(msg.sender);|g' node_modules/@openzeppelin/contracts/utils/Context.sol |
| 84 | + perl -i -0pe \ |
| 85 | + "s/uint256 (executedBuyAmount = \(-tokenDeltas\[trade.buyTokenIndex\]\)\n\s+.toUint256\(\);)/uint256 executedBuyAmount; unchecked \{\1\}/g" \ |
| 86 | + src/contracts/GPv2Settlement.sol |
| 87 | + |
| 88 | + # This test is not supposed to work. The compiler is supposed to enforce zero padding since |
| 89 | + # at least 0.5.8 (see https://github.com/ethereum/solidity/pull/5815). For some reason the |
| 90 | + # test worked on 0.7.6 but no longer works on 0.8.x. |
| 91 | + sed -i 's|it\(("invalid EVM transaction encoding does not change order hash"\)|it.skip\1|g' test/GPv2Signing.test.ts |
| 92 | + |
| 93 | + # Disable tests that won't pass on the ir presets due to Hardhat heuristics. Note that this also disables |
| 94 | + # them for other presets but that's fine - we want same code run for benchmarks to be comparable. |
| 95 | + # TODO: Remove this when Hardhat adjusts heuristics for IR (https://github.com/nomiclabs/hardhat/issues/2115). |
| 96 | + sed -i 's|it\(("should revert when encoding invalid flags"\)|it.skip\1|g' test/GPv2Trade.test.ts |
| 97 | + |
| 98 | + replace_version_pragmas |
| 99 | + |
| 100 | + for preset in $SELECTED_PRESETS; do |
| 101 | + hardhat_run_test "$config_file" "$preset" "${compile_only_presets[*]}" compile_fn test_fn "$config_var" |
| 102 | + store_benchmark_report hardhat gp2 "$repo" "$preset" |
| 103 | + done |
| 104 | +} |
| 105 | + |
| 106 | +external_test Gnosis-Protocol-V2 gp2_test |
0 commit comments