Skip to content

Commit b57c0a0

Browse files
committed
externalTests: Refactor to be more explicit and easier to adjust for special cases
1 parent 7ccdbd5 commit b57c0a0

File tree

7 files changed

+127
-85
lines changed

7 files changed

+127
-85
lines changed

test/externalTests/colony.sh

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,24 +27,37 @@ source test/externalTests/common.sh
2727
verify_input "$1"
2828
SOLJSON="$1"
2929

30-
function install_fn { yarn; git submodule update --init; }
3130
function compile_fn { yarn run provision:token:contracts; }
3231
function test_fn { yarn run test:contracts; }
3332

3433
function colony_test
3534
{
36-
OPTIMIZER_LEVEL=3
37-
CONFIG="truffle.js"
35+
local repo="https://github.com/solidity-external-tests/colonyNetwork.git"
36+
local branch=develop_080
37+
local config_file="truffle.js"
38+
local min_optimizer_level=3
39+
local max_optimizer_level=3
3840

39-
truffle_setup "$SOLJSON" https://github.com/solidity-external-tests/colonyNetwork.git develop_080
40-
run_install "$SOLJSON" install_fn
41+
setup_solcjs "$DIR" "$SOLJSON"
42+
download_project "$repo" "$branch" "$DIR"
43+
44+
replace_version_pragmas
45+
force_truffle_solc_modules "$SOLJSON"
46+
force_truffle_compiler_settings "$config_file" "${DIR}/solc" "$min_optimizer_level"
47+
yarn
48+
git submodule update --init
4149

4250
cd lib
4351
rm -Rf dappsys
4452
git clone https://github.com/solidity-external-tests/dappsys-monolithic.git -b master_080 dappsys
4553
cd ..
4654

47-
truffle_run_test "$SOLJSON" compile_fn test_fn
55+
replace_version_pragmas
56+
force_truffle_solc_modules "$SOLJSON"
57+
58+
for level in $(seq "$min_optimizer_level" "$max_optimizer_level"); do
59+
truffle_run_test "$config_file" "${DIR}/solc" "$level" compile_fn test_fn
60+
done
4861
}
4962

5063
external_test ColonyNetworks colony_test

test/externalTests/common.sh

Lines changed: 37 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ set -e
2222

2323
# Requires "${REPO_ROOT}/scripts/common.sh" to be included before.
2424

25+
CURRENT_EVM_VERSION=london
26+
2527
function verify_input
2628
{
2729
if [ ! -f "$1" ]; then
@@ -51,8 +53,8 @@ function setup_solcjs
5153
{
5254
local dir="$1"
5355
local soljson="$2"
54-
local branch="$3"
55-
local path="$4"
56+
local branch="${3:-master}"
57+
local path="${4:-solc/}"
5658

5759
cd "$dir"
5860
printLog "Setting up solc-js..."
@@ -86,16 +88,6 @@ function force_truffle_version
8688
sed -i 's/"truffle":\s*".*"/"truffle": "'"$version"'"/g' package.json
8789
}
8890

89-
function truffle_setup
90-
{
91-
local soljson="$1"
92-
local repo="$2"
93-
local branch="$3"
94-
95-
setup_solcjs "$DIR" "$soljson" "master" "solc"
96-
download_project "$repo" "$branch" "$DIR"
97-
}
98-
9991
function replace_version_pragmas
10092
{
10193
# Replace fixed-version pragmas (part of Consensys best practice).
@@ -131,7 +123,7 @@ function force_truffle_compiler_settings
131123
local config_file="$1"
132124
local solc_path="$2"
133125
local level="$3"
134-
local evm_version="$4"
126+
local evm_version="${4:-"$CURRENT_EVM_VERSION"}"
135127

136128
printLog "Forcing Truffle compiler settings..."
137129
echo "-------------------------------------"
@@ -147,30 +139,18 @@ function force_truffle_compiler_settings
147139
echo "module.exports['compilers'] = $(truffle_compiler_settings "$solc_path" "$level" "$evm_version");" >> "$config_file"
148140
}
149141

150-
function verify_compiler_version
142+
function truffle_verify_compiler_version
151143
{
152144
local solc_version="$1"
145+
local full_solc_version="$2"
153146

154-
printLog "Verify that the correct version ($solc_version) of the compiler was used to compile the contracts..."
155-
grep -e "$solc_version" -r build/contracts > /dev/null
156-
}
157-
158-
function clean
159-
{
160-
rm -rf build || true
147+
printLog "Verify that the correct version (${solc_version}/${full_solc_version}) of the compiler was used to compile the contracts..."
148+
grep "$full_solc_version" --with-filename --recursive build/contracts || fail "Wrong compiler version detected."
161149
}
162150

163-
function run_install
151+
function truffle_clean
164152
{
165-
local soljson="$1"
166-
local init_fn="$2"
167-
printLog "Running install function..."
168-
169-
replace_version_pragmas
170-
force_truffle_solc_modules "$soljson"
171-
force_truffle_compiler_settings "$CONFIG" "${DIR}/solc" "$OPTIMIZER_LEVEL" london
172-
173-
$init_fn
153+
rm -rf build/
174154
}
175155

176156
function run_test
@@ -219,31 +199,35 @@ function truffle_compiler_settings
219199
echo "}"
220200
}
221201

222-
function truffle_run_test
202+
function compile_and_run_test
223203
{
224-
local soljson="$1"
225-
local compile_fn="$2"
226-
local test_fn="$3"
204+
local compile_fn="$1"
205+
local test_fn="$2"
206+
local verify_fn="$3"
227207

228-
replace_version_pragmas
229-
force_truffle_solc_modules "$soljson"
208+
printLog "Running compile function..."
209+
$compile_fn
210+
$verify_fn "$SOLCVERSION_SHORT" "$SOLCVERSION"
230211

231-
for level in $(seq "$OPTIMIZER_LEVEL" 3)
232-
do
233-
clean
234-
force_truffle_compiler_settings "$CONFIG" "${DIR}/solc" "$level" london
235-
236-
printLog "Running compile function..."
237-
$compile_fn
238-
verify_compiler_version "$SOLCVERSION"
239-
240-
if [[ "$COMPILE_ONLY" == 1 ]]; then
241-
printLog "Skipping test function..."
242-
else
243-
printLog "Running test function..."
244-
$test_fn
245-
fi
246-
done
212+
if [[ "$COMPILE_ONLY" == 1 ]]; then
213+
printLog "Skipping test function..."
214+
else
215+
printLog "Running test function..."
216+
$test_fn
217+
fi
218+
}
219+
220+
function truffle_run_test
221+
{
222+
local config_file="$1"
223+
local solc_path="$2"
224+
local optimizer_level="$3"
225+
local compile_fn="$4"
226+
local test_fn="$5"
227+
228+
truffle_clean
229+
force_truffle_compiler_settings "$config_file" "$solc_path" "$optimizer_level"
230+
compile_and_run_test compile_fn test_fn truffle_verify_compiler_version
247231
}
248232

249233
function external_test

test/externalTests/ens.sh

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,26 +27,37 @@ source test/externalTests/common.sh
2727
verify_input "$1"
2828
export SOLJSON="$1"
2929

30-
function install_fn { npm install; }
3130
function compile_fn { npx truffle compile; }
3231
function test_fn { npm run test; }
3332

3433
function ens_test
3534
{
36-
export OPTIMIZER_LEVEL=1
37-
export CONFIG="truffle-config.js"
35+
local repo="https://github.com/ensdomains/ens.git"
36+
local branch=master
37+
local config_file="truffle-config.js"
38+
local min_optimizer_level=1
39+
local max_optimizer_level=3
3840

39-
truffle_setup "$SOLJSON" https://github.com/ensdomains/ens.git master
41+
setup_solcjs "$DIR" "$SOLJSON"
42+
download_project "$repo" "$branch" "$DIR"
4043

4144
# Use latest Truffle. Older versions crash on the output from 0.8.0.
4245
force_truffle_version ^5.1.55
4346

4447
# Remove the lock file (if it exists) to prevent it from overriding our changes in package.json
4548
rm -f package-lock.json
4649

47-
run_install "$SOLJSON" install_fn
50+
replace_version_pragmas
51+
force_truffle_solc_modules "$SOLJSON"
52+
force_truffle_compiler_settings "$config_file" "${DIR}/solc" "$min_optimizer_level"
53+
npm install
4854

49-
truffle_run_test "$SOLJSON" compile_fn test_fn
55+
replace_version_pragmas
56+
force_truffle_solc_modules "$SOLJSON"
57+
58+
for level in $(seq "$min_optimizer_level" "$max_optimizer_level"); do
59+
truffle_run_test "$config_file" "${DIR}/solc" "$level" compile_fn test_fn
60+
done
5061
}
5162

5263
external_test Ens ens_test

test/externalTests/gnosis-v2.sh

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,20 +33,32 @@ function test_fn { npm test; }
3333

3434
function gnosis_safe_test
3535
{
36-
OPTIMIZER_LEVEL=2
37-
CONFIG="truffle-config.js"
36+
local repo="https://github.com/solidity-external-tests/safe-contracts.git"
37+
local branch=v2_080
38+
local config_file="truffle-config.js"
39+
local min_optimizer_level=2
40+
local max_optimizer_level=3
3841

39-
truffle_setup "$SOLJSON" https://github.com/solidity-external-tests/safe-contracts.git v2_080
42+
setup_solcjs "$DIR" "$SOLJSON"
43+
download_project "$repo" "$branch" "$DIR"
4044

4145
sed -i 's|github:gnosis/mock-contract#sol_0_5_0|github:solidity-external-tests/mock-contract#master_080|g' package.json
4246
sed -i -E 's|"@gnosis.pm/util-contracts": "[^"]+"|"@gnosis.pm/util-contracts": "github:solidity-external-tests/util-contracts#solc-7_080"|g' package.json
4347

4448
# Remove the lock file (if it exists) to prevent it from overriding our changes in package.json
4549
rm -f package-lock.json
4650

47-
run_install "$SOLJSON" install_fn
51+
replace_version_pragmas
52+
force_truffle_solc_modules "$SOLJSON"
53+
force_truffle_compiler_settings "$config_file" "${DIR}/solc" "$min_optimizer_level"
54+
npm install --package-lock
4855

49-
truffle_run_test "$SOLJSON" compile_fn test_fn
56+
replace_version_pragmas
57+
force_truffle_solc_modules "$SOLJSON"
58+
59+
for level in $(seq "$min_optimizer_level" "$max_optimizer_level"); do
60+
truffle_run_test "$config_file" "${DIR}/solc" "$level" compile_fn test_fn
61+
done
5062
}
5163

5264
external_test Gnosis-Safe gnosis_safe_test

test/externalTests/gnosis.sh

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,25 +27,36 @@ source test/externalTests/common.sh
2727
verify_input "$1"
2828
SOLJSON="$1"
2929

30-
function install_fn { npm install --package-lock; }
3130
function compile_fn { npx truffle compile; }
3231
function test_fn { npm test; }
3332

3433
function gnosis_safe_test
3534
{
36-
OPTIMIZER_LEVEL=2
37-
CONFIG="truffle-config.js"
35+
local repo="https://github.com/solidity-external-tests/safe-contracts.git"
36+
local branch=development_080
37+
local config_file="truffle-config.js"
38+
local min_optimizer_level=2
39+
local max_optimizer_level=3
3840

39-
truffle_setup "$SOLJSON" https://github.com/solidity-external-tests/safe-contracts.git development_080
41+
setup_solcjs "$DIR" "$SOLJSON"
42+
download_project "$repo" "$branch" "$DIR"
4043

4144
sed -i 's|github:gnosis/mock-contract#sol_0_5_0|github:solidity-external-tests/mock-contract#master_080|g' package.json
4245

4346
# Remove the lock file (if it exists) to prevent it from overriding our changes in package.json
4447
rm -f package-lock.json
4548

46-
run_install "$SOLJSON" install_fn
49+
replace_version_pragmas
50+
force_truffle_solc_modules "$SOLJSON"
51+
force_truffle_compiler_settings "$config_file" "${DIR}/solc" "$min_optimizer_level"
52+
npm install --package-lock
4753

48-
truffle_run_test "$SOLJSON" compile_fn test_fn
54+
replace_version_pragmas
55+
force_truffle_solc_modules "$SOLJSON"
56+
57+
for level in $(seq "$min_optimizer_level" "$max_optimizer_level"); do
58+
truffle_run_test "$config_file" "${DIR}/solc" "$level" compile_fn test_fn
59+
done
4960
}
5061

5162
external_test Gnosis-Safe gnosis_safe_test

test/externalTests/solc-js/solc-js.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ verify_version_input "$1" "$2"
2828
SOLJSON="$1"
2929
VERSION="$2"
3030

31-
function install_fn { echo "Nothing to install."; }
3231
function compile_fn { echo "Nothing to compile."; }
3332
function test_fn { npm test; }
3433

test/externalTests/zeppelin.sh

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,31 @@ source test/externalTests/common.sh
2727
verify_input "$1"
2828
SOLJSON="$1"
2929

30-
function install_fn { npm install; }
3130
function compile_fn { npx truffle compile; }
3231
function test_fn { npm run test; }
3332

3433
function zeppelin_test
3534
{
36-
OPTIMIZER_LEVEL=1
37-
CONFIG="truffle-config.js"
38-
39-
truffle_setup "$SOLJSON" https://github.com/OpenZeppelin/openzeppelin-contracts.git master
40-
run_install "$SOLJSON" install_fn
41-
42-
truffle_run_test "$SOLJSON" compile_fn test_fn
35+
local repo="https://github.com/OpenZeppelin/openzeppelin-contracts.git"
36+
local branch=master
37+
local config_file="truffle-config.js"
38+
local min_optimizer_level=1
39+
local max_optimizer_level=3
40+
41+
setup_solcjs "$DIR" "$SOLJSON"
42+
download_project "$repo" "$branch" "$DIR"
43+
44+
replace_version_pragmas
45+
force_truffle_solc_modules "$SOLJSON"
46+
force_truffle_compiler_settings "$config_file" "${DIR}/solc" "$min_optimizer_level"
47+
npm install
48+
49+
replace_version_pragmas
50+
force_truffle_solc_modules "$SOLJSON"
51+
52+
for level in $(seq "$min_optimizer_level" "$max_optimizer_level"); do
53+
truffle_run_test "$config_file" "${DIR}/solc" "$level" compile_fn test_fn
54+
done
4355
}
4456

4557
external_test Zeppelin zeppelin_test

0 commit comments

Comments
 (0)