From 0a292188482c6530adf60be06adcfb6e26a58656 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20=C5=9Aliwak?= Date: Tue, 1 Dec 2020 20:31:30 +0100 Subject: [PATCH 1/6] external test scripts: Quote variables properly --- scripts/common.sh | 10 +++++----- test/externalTests.sh | 8 ++++---- test/externalTests/solc-js/solc-js.sh | 6 +++--- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/scripts/common.sh b/scripts/common.sh index fbb730241..797510d33 100644 --- a/scripts/common.sh +++ b/scripts/common.sh @@ -37,21 +37,21 @@ safe_kill() local n=1 # only proceed if $PID does exist - kill -0 $PID 2>/dev/null || return + kill -0 "$PID" 2>/dev/null || return echo "Sending SIGTERM to ${NAME} (${PID}) ..." - kill $PID + kill "$PID" # wait until process terminated gracefully - while kill -0 $PID 2>/dev/null && [[ $n -le 4 ]]; do + while kill -0 "$PID" 2>/dev/null && [[ $n -le 4 ]]; do echo "Waiting ($n) ..." sleep 1 n=$[n + 1] done # process still alive? then hard-kill - if kill -0 $PID 2>/dev/null; then + if kill -0 "$PID" 2>/dev/null; then echo "Sending SIGKILL to ${NAME} (${PID}) ..." - kill -9 $PID + kill -9 "$PID" fi } diff --git a/test/externalTests.sh b/test/externalTests.sh index 7bf3eb76b..e53f9925a 100755 --- a/test/externalTests.sh +++ b/test/externalTests.sh @@ -42,10 +42,10 @@ source test/externalTests/common.sh printTask "Running external tests..." -$REPO_ROOT/externalTests/zeppelin.sh "$SOLJSON" -$REPO_ROOT/externalTests/gnosis.sh "$SOLJSON" -$REPO_ROOT/externalTests/colony.sh "$SOLJSON" -$REPO_ROOT/externalTests/ens.sh "$SOLJSON" +"$REPO_ROOT/externalTests/zeppelin.sh" "$SOLJSON" +"$REPO_ROOT/externalTests/gnosis.sh" "$SOLJSON" +"$REPO_ROOT/externalTests/colony.sh" "$SOLJSON" +"$REPO_ROOT/externalTests/ens.sh" "$SOLJSON" # Disabled temporarily as it needs to be updated to latest Truffle first. #test_truffle Gnosis https://github.com/axic/pm-contracts.git solidity-050 diff --git a/test/externalTests/solc-js/solc-js.sh b/test/externalTests/solc-js/solc-js.sh index db01a2ae7..fd59c4398 100755 --- a/test/externalTests/solc-js/solc-js.sh +++ b/test/externalTests/solc-js/solc-js.sh @@ -41,10 +41,10 @@ function solcjs_test echo "require('./determinism.js');" >> test/index.js printLog "Copying determinism.js..." - cp -f $SOLCJS_INPUT_DIR/determinism.js test/ + cp -f "$SOLCJS_INPUT_DIR/determinism.js" test/ printLog "Copying contracts..." - cp -Rf $SOLCJS_INPUT_DIR/DAO test/ + cp -Rf "$SOLCJS_INPUT_DIR/DAO" test/ printLog "Copying SMTChecker tests..." cp -Rf "$TEST_DIR"/test/libsolidity/smtCheckerTests test/ @@ -52,7 +52,7 @@ function solcjs_test # Update version (needed for some tests) echo "Updating package.json to version $VERSION" - npm version --allow-same-version --no-git-tag-version $VERSION + npm version --allow-same-version --no-git-tag-version "$VERSION" run_test compile_fn test_fn } From 3590311e6fda867a2a7049c39bb9060610ee56ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20=C5=9Aliwak?= Date: Tue, 1 Dec 2020 20:32:12 +0100 Subject: [PATCH 2/6] external test scripts: Replace the old dollar expressions with newer variants --- scripts/common.sh | 2 +- test/externalTests/common.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/common.sh b/scripts/common.sh index 797510d33..f39768166 100644 --- a/scripts/common.sh +++ b/scripts/common.sh @@ -46,7 +46,7 @@ safe_kill() while kill -0 "$PID" 2>/dev/null && [[ $n -le 4 ]]; do echo "Waiting ($n) ..." sleep 1 - n=$[n + 1] + n=$((n + 1)) done # process still alive? then hard-kill diff --git a/test/externalTests/common.sh b/test/externalTests/common.sh index d56912a85..14eeb9810 100644 --- a/test/externalTests/common.sh +++ b/test/externalTests/common.sh @@ -80,7 +80,7 @@ function download_project printLog "Cloning $branch of $repo..." git clone --depth 1 "$repo" -b "$branch" "$dir/ext" cd ext - echo "Current commit hash: `git rev-parse HEAD`" + echo "Current commit hash: $(git rev-parse HEAD)" } function force_truffle_version From a6921bc39b3e0759c01fc1b8faf3d29b1ea9e04d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20=C5=9Aliwak?= Date: Tue, 1 Dec 2020 20:32:25 +0100 Subject: [PATCH 3/6] external test scripts: Add missing bash shebangs --- scripts/common.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/common.sh b/scripts/common.sh index f39768166..3518a21aa 100644 --- a/scripts/common.sh +++ b/scripts/common.sh @@ -1,3 +1,4 @@ +#!/usr/bin/env bash # ------------------------------------------------------------------------------ # vim:ts=4:et # This file is part of solidity. From fcf053822427263381e95dea7386b6146b4b64f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20=C5=9Aliwak?= Date: Tue, 1 Dec 2020 20:38:15 +0100 Subject: [PATCH 4/6] external test scripts: Replace global $FORCE_ABIv2 variable with a parameter --- test/externalTests/colony.sh | 3 +-- test/externalTests/common.sh | 5 ++++- test/externalTests/ens.sh | 2 +- test/externalTests/gnosis.sh | 2 +- test/externalTests/zeppelin.sh | 2 +- 5 files changed, 8 insertions(+), 6 deletions(-) diff --git a/test/externalTests/colony.sh b/test/externalTests/colony.sh index 6a246b2b9..91a82d8bb 100755 --- a/test/externalTests/colony.sh +++ b/test/externalTests/colony.sh @@ -31,7 +31,6 @@ function test_fn { yarn run test:contracts; } function colony_test { OPTIMIZER_LEVEL=3 - FORCE_ABIv2=false CONFIG="truffle.js" truffle_setup https://github.com/solidity-external-tests/colonyNetwork.git develop_070 @@ -42,7 +41,7 @@ function colony_test git clone https://github.com/solidity-external-tests/dappsys-monolithic.git -b master_060 dappsys cd .. - truffle_run_test compile_fn test_fn + truffle_run_test compile_fn test_fn "NO-FORCE-ABI-V2" } external_test ColonyNetworks colony_test diff --git a/test/externalTests/common.sh b/test/externalTests/common.sh index 14eeb9810..6e4924762 100644 --- a/test/externalTests/common.sh +++ b/test/externalTests/common.sh @@ -234,6 +234,9 @@ function truffle_run_test { local compile_fn="$1" local test_fn="$2" + local force_abi_v2_flag="$3" + + test "$force_abi_v2_flag" = "FORCE-ABI-V2" || test "$force_abi_v2_flag" = "NO-FORCE-ABI-V2" replace_version_pragmas force_solc "$CONFIG" "$DIR" "$SOLJSON" @@ -258,7 +261,7 @@ function truffle_run_test clean force_solc_settings "$CONFIG" "$optimize" "istanbul" # Force abi coder v2 in the last step. Has to be the last because code is modified. - if [ "$FORCE_ABIv2" = true ]; then + if [ "$force_abi_v2_flag" = "FORCE-ABI-V2" ]; then [[ "$optimize" =~ yul ]] && force_abi_v2 fi diff --git a/test/externalTests/ens.sh b/test/externalTests/ens.sh index 52cccdb56..d67f1fe77 100755 --- a/test/externalTests/ens.sh +++ b/test/externalTests/ens.sh @@ -42,7 +42,7 @@ function ens_test run_install install_fn - truffle_run_test compile_fn test_fn + truffle_run_test compile_fn test_fn "NO-FORCE-ABI-V2" } external_test Ens ens_test diff --git a/test/externalTests/gnosis.sh b/test/externalTests/gnosis.sh index 8a5ccd0c7..83a8cd499 100755 --- a/test/externalTests/gnosis.sh +++ b/test/externalTests/gnosis.sh @@ -43,7 +43,7 @@ function gnosis_safe_test run_install install_fn replace_libsolc_call - truffle_run_test compile_fn test_fn + truffle_run_test compile_fn test_fn "NO-FORCE-ABI-V2" } external_test Gnosis-Safe gnosis_safe_test diff --git a/test/externalTests/zeppelin.sh b/test/externalTests/zeppelin.sh index 51051f334..35e47faba 100755 --- a/test/externalTests/zeppelin.sh +++ b/test/externalTests/zeppelin.sh @@ -36,7 +36,7 @@ function zeppelin_test truffle_setup https://github.com/solidity-external-tests/openzeppelin-contracts.git upgrade-0.7.0 run_install install_fn - truffle_run_test compile_fn test_fn + truffle_run_test compile_fn test_fn "NO-FORCE-ABI-V2" } external_test Zeppelin zeppelin_test From 8080be94450b55a01357401d83c950ac959d5372 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20=C5=9Aliwak?= Date: Tue, 1 Dec 2020 20:44:21 +0100 Subject: [PATCH 5/6] external test scripts: Replace global $SOLJSON variable with a parameter --- test/externalTests/colony.sh | 6 +++--- test/externalTests/common.sh | 26 +++++++++++++++----------- test/externalTests/ens.sh | 6 +++--- test/externalTests/gnosis.sh | 6 +++--- test/externalTests/solc-js/solc-js.sh | 2 +- test/externalTests/zeppelin.sh | 6 +++--- 6 files changed, 28 insertions(+), 24 deletions(-) diff --git a/test/externalTests/colony.sh b/test/externalTests/colony.sh index 91a82d8bb..349cabf2a 100755 --- a/test/externalTests/colony.sh +++ b/test/externalTests/colony.sh @@ -33,15 +33,15 @@ function colony_test OPTIMIZER_LEVEL=3 CONFIG="truffle.js" - truffle_setup https://github.com/solidity-external-tests/colonyNetwork.git develop_070 - run_install install_fn + truffle_setup "$SOLJSON" https://github.com/solidity-external-tests/colonyNetwork.git develop_070 + run_install "$SOLJSON" install_fn cd lib rm -Rf dappsys git clone https://github.com/solidity-external-tests/dappsys-monolithic.git -b master_060 dappsys cd .. - truffle_run_test compile_fn test_fn "NO-FORCE-ABI-V2" + truffle_run_test "$SOLJSON" compile_fn test_fn "NO-FORCE-ABI-V2" } external_test ColonyNetworks colony_test diff --git a/test/externalTests/common.sh b/test/externalTests/common.sh index 6e4924762..ad36a5ff4 100644 --- a/test/externalTests/common.sh +++ b/test/externalTests/common.sh @@ -40,9 +40,10 @@ function verify_version_input function setup { - local branch="$1" + local soljson="$1" + local branch="$2" - setup_solcjs "$DIR" "$SOLJSON" "$branch" "solc" + setup_solcjs "$DIR" "$soljson" "$branch" "solc" cd solc } @@ -92,10 +93,11 @@ function force_truffle_version function truffle_setup { - local repo="$1" - local branch="$2" + local soljson="$1" + local repo="$2" + local branch="$3" - setup_solcjs "$DIR" "$SOLJSON" "master" "solc" + setup_solcjs "$DIR" "$soljson" "master" "solc" download_project "$repo" "$branch" "$DIR" } @@ -207,11 +209,12 @@ function clean function run_install { - local init_fn="$1" + local soljson="$1" + local init_fn="$2" printLog "Running install function..." replace_version_pragmas - force_solc "$CONFIG" "$DIR" "$SOLJSON" + force_solc "$CONFIG" "$DIR" "$soljson" $init_fn } @@ -232,14 +235,15 @@ function run_test function truffle_run_test { - local compile_fn="$1" - local test_fn="$2" - local force_abi_v2_flag="$3" + local soljson="$1" + local compile_fn="$2" + local test_fn="$3" + local force_abi_v2_flag="$4" test "$force_abi_v2_flag" = "FORCE-ABI-V2" || test "$force_abi_v2_flag" = "NO-FORCE-ABI-V2" replace_version_pragmas - force_solc "$CONFIG" "$DIR" "$SOLJSON" + force_solc "$CONFIG" "$DIR" "$soljson" printLog "Checking optimizer level..." if [ -z "$OPTIMIZER_LEVEL" ]; then diff --git a/test/externalTests/ens.sh b/test/externalTests/ens.sh index d67f1fe77..40432198f 100755 --- a/test/externalTests/ens.sh +++ b/test/externalTests/ens.sh @@ -35,14 +35,14 @@ function ens_test export OPTIMIZER_LEVEL=1 export CONFIG="truffle-config.js" - truffle_setup https://github.com/solidity-external-tests/ens.git upgrade-0.8.0 + truffle_setup "$SOLJSON" https://github.com/solidity-external-tests/ens.git upgrade-0.8.0 # Use latest Truffle. Older versions crash on the output from 0.8.0. force_truffle_version ^5.1.55 - run_install install_fn + run_install "$SOLJSON" install_fn - truffle_run_test compile_fn test_fn "NO-FORCE-ABI-V2" + truffle_run_test "$SOLJSON" compile_fn test_fn "NO-FORCE-ABI-V2" } external_test Ens ens_test diff --git a/test/externalTests/gnosis.sh b/test/externalTests/gnosis.sh index 83a8cd499..73870f8db 100755 --- a/test/externalTests/gnosis.sh +++ b/test/externalTests/gnosis.sh @@ -33,17 +33,17 @@ function gnosis_safe_test OPTIMIZER_LEVEL=1 CONFIG="truffle.js" - truffle_setup https://github.com/solidity-external-tests/safe-contracts.git development_070 + truffle_setup "$SOLJSON" https://github.com/solidity-external-tests/safe-contracts.git development_070 force_truffle_version ^5.0.42 sed -i 's|github:gnosis/mock-contract#sol_0_5_0|github:solidity-external-tests/mock-contract#master_070|g' package.json rm -f package-lock.json rm -rf node_modules/ - run_install install_fn + run_install "$SOLJSON" install_fn replace_libsolc_call - truffle_run_test compile_fn test_fn "NO-FORCE-ABI-V2" + truffle_run_test "$SOLJSON" compile_fn test_fn "NO-FORCE-ABI-V2" } external_test Gnosis-Safe gnosis_safe_test diff --git a/test/externalTests/solc-js/solc-js.sh b/test/externalTests/solc-js/solc-js.sh index fd59c4398..9cc753959 100755 --- a/test/externalTests/solc-js/solc-js.sh +++ b/test/externalTests/solc-js/solc-js.sh @@ -35,7 +35,7 @@ function solcjs_test SOLCJS_INPUT_DIR="$TEST_DIR"/test/externalTests/solc-js # set up solc-js on the branch specified - setup master + setup "$SOLJSON" master printLog "Updating index.js file..." echo "require('./determinism.js');" >> test/index.js diff --git a/test/externalTests/zeppelin.sh b/test/externalTests/zeppelin.sh index 35e47faba..e71e974d6 100755 --- a/test/externalTests/zeppelin.sh +++ b/test/externalTests/zeppelin.sh @@ -33,10 +33,10 @@ function zeppelin_test OPTIMIZER_LEVEL=1 CONFIG="truffle-config.js" - truffle_setup https://github.com/solidity-external-tests/openzeppelin-contracts.git upgrade-0.7.0 - run_install install_fn + truffle_setup "$SOLJSON" https://github.com/solidity-external-tests/openzeppelin-contracts.git upgrade-0.7.0 + run_install "$SOLJSON" install_fn - truffle_run_test compile_fn test_fn "NO-FORCE-ABI-V2" + truffle_run_test "$SOLJSON" compile_fn test_fn "NO-FORCE-ABI-V2" } external_test Zeppelin zeppelin_test From 55ccfc32f547cf33838dcc86358c680116c0411a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20=C5=9Aliwak?= Date: Tue, 1 Dec 2020 20:33:01 +0100 Subject: [PATCH 6/6] Remove external test scripts from shellcheck ignores --- scripts/chk_shellscripts/ignore.txt | 7 ------- test/externalTests/ens.sh | 2 -- 2 files changed, 9 deletions(-) diff --git a/scripts/chk_shellscripts/ignore.txt b/scripts/chk_shellscripts/ignore.txt index 220ed9f57..188efb0ab 100644 --- a/scripts/chk_shellscripts/ignore.txt +++ b/scripts/chk_shellscripts/ignore.txt @@ -1,12 +1,5 @@ ./test/docsCodeStyle.sh ./test/cmdlineTests.sh -./test/externalTests.sh -./test/externalTests/common.sh -./test/externalTests/gnosis.sh -./test/externalTests/zeppelin.sh -./test/externalTests/colony.sh -./test/externalTests/solc-js/solc-js.sh -./scripts/common.sh ./scripts/isoltest.sh ./scripts/get_version.sh ./scripts/soltest.sh diff --git a/test/externalTests/ens.sh b/test/externalTests/ens.sh index 40432198f..99f4b8971 100755 --- a/test/externalTests/ens.sh +++ b/test/externalTests/ens.sh @@ -18,9 +18,7 @@ # # (c) 2019 solidity contributors. #------------------------------------------------------------------------------ -# shellcheck disable=SC1091 source scripts/common.sh -# shellcheck disable=SC1091 source test/externalTests/common.sh verify_input "$1"