Skip to content

Commit 9b220a2

Browse files
authored
Merge pull request #12575 from ethereum/gnosis-gp-v2-ext-test
External test for Gnosis Protocol v2
2 parents e777ec9 + 0b80a56 commit 9b220a2

File tree

3 files changed

+116
-0
lines changed

3 files changed

+116
-0
lines changed

.circleci/config.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,13 @@ defaults:
613613
binary_type: native
614614
nodejs_version: '16'
615615
resource_class: large # Tests run out of memory on a smaller machine
616+
- job_native_test_ext_gp2: &job_native_test_ext_gp2
617+
<<: *workflow_ubuntu2004_static
618+
name: t_native_test_ext_gp2
619+
project: gp2
620+
binary_type: native
621+
# NOTE: Tests crash on nodejs 17: "Error: error:0308010C:digital envelope routines::unsupported"
622+
nodejs_version: '16'
616623
- job_ems_test_ext_colony: &job_ems_test_ext_colony
617624
<<: *workflow_emscripten
618625
name: t_ems_test_ext_colony
@@ -1604,6 +1611,7 @@ workflows:
16041611
- t_ems_ext: *job_native_test_ext_elementfi
16051612
- t_ems_ext: *job_native_test_ext_brink
16061613
- t_ems_ext: *job_native_test_ext_chainlink
1614+
- t_ems_ext: *job_native_test_ext_gp2
16071615

16081616
- c_ext_benchmarks:
16091617
<<: *workflow_trigger_on_tags
@@ -1623,6 +1631,7 @@ workflows:
16231631
- t_native_test_ext_elementfi
16241632
- t_native_test_ext_brink
16251633
- t_native_test_ext_chainlink
1634+
- t_native_test_ext_gp2
16261635

16271636
# Windows build and tests
16281637
- b_win: *workflow_trigger_on_tags

test/externalTests.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,4 @@ printTask "Running external tests..."
5252
"${REPO_ROOT}/test/externalTests/elementfi.sh" "$@"
5353
"${REPO_ROOT}/test/externalTests/brink.sh" "$@"
5454
"${REPO_ROOT}/test/externalTests/chainlink.sh" "$@"
55+
"${REPO_ROOT}/test/externalTests/gp2.sh" "$@"

test/externalTests/gp2.sh

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
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

Comments
 (0)