diff --git a/test/externalTests/colony.sh b/test/externalTests/colony.sh index ef06f1d7b..e32385af6 100755 --- a/test/externalTests/colony.sh +++ b/test/externalTests/colony.sh @@ -27,24 +27,36 @@ source test/externalTests/common.sh verify_input "$1" SOLJSON="$1" -function install_fn { yarn; git submodule update --init; } function compile_fn { yarn run provision:token:contracts; } function test_fn { yarn run test:contracts; } function colony_test { - OPTIMIZER_LEVEL=3 - CONFIG="truffle.js" + local repo="https://github.com/solidity-external-tests/colonyNetwork.git" + local branch=develop_080 + local config_file="truffle.js" + local min_optimizer_level=3 + local max_optimizer_level=3 - truffle_setup "$SOLJSON" https://github.com/solidity-external-tests/colonyNetwork.git develop_080 - run_install "$SOLJSON" install_fn + setup_solcjs "$DIR" "$SOLJSON" + download_project "$repo" "$branch" "$DIR" + + neutralize_package_json_hooks + force_truffle_compiler_settings "$config_file" "${DIR}/solc" "$min_optimizer_level" + yarn + git submodule update --init cd lib rm -Rf dappsys git clone https://github.com/solidity-external-tests/dappsys-monolithic.git -b master_080 dappsys cd .. - truffle_run_test "$SOLJSON" compile_fn test_fn + replace_version_pragmas + force_solc_modules "${DIR}/solc" + + for level in $(seq "$min_optimizer_level" "$max_optimizer_level"); do + truffle_run_test "$config_file" "${DIR}/solc" "$level" compile_fn test_fn + done } external_test ColonyNetworks colony_test diff --git a/test/externalTests/common.sh b/test/externalTests/common.sh index 4e28d233f..dbda3c3f4 100644 --- a/test/externalTests/common.sh +++ b/test/externalTests/common.sh @@ -22,6 +22,8 @@ set -e # Requires "${REPO_ROOT}/scripts/common.sh" to be included before. +CURRENT_EVM_VERSION=london + function verify_input { if [ ! -f "$1" ]; then @@ -51,8 +53,8 @@ function setup_solcjs { local dir="$1" local soljson="$2" - local branch="$3" - local path="$4" + local branch="${3:-master}" + local path="${4:-solc/}" cd "$dir" printLog "Setting up solc-js..." @@ -86,16 +88,6 @@ function force_truffle_version sed -i 's/"truffle":\s*".*"/"truffle": "'"$version"'"/g' package.json } -function truffle_setup -{ - local soljson="$1" - local repo="$2" - local branch="$3" - - setup_solcjs "$DIR" "$soljson" "master" "solc" - download_project "$repo" "$branch" "$DIR" -} - function replace_version_pragmas { # Replace fixed-version pragmas (part of Consensys best practice). @@ -104,25 +96,38 @@ function replace_version_pragmas find . test -name '*.sol' -type f -print0 | xargs -0 sed -i -E -e 's/pragma solidity [^;]+;/pragma solidity >=0.0;/' } -function force_truffle_solc_modules +function neutralize_package_lock { - local soljson="$1" + # Remove lock files (if they exist) to prevent them from overriding our changes in package.json + printLog "Removing package lock files..." + rm --force --verbose yarn.lock + rm --force --verbose package-lock.json +} - # Replace solc package by v0.5.0 and then overwrite with current version. - printLog "Forcing solc version for all Truffle modules..." - for d in node_modules node_modules/truffle/node_modules +function neutralize_package_json_hooks +{ + printLog "Disabling package.json hooks..." + [[ -f package.json ]] || fail "package.json not found" + sed -i 's|"prepublish": *".*"|"prepublish": ""|g' package.json + sed -i 's|"prepare": *".*"|"prepare": ""|g' package.json +} + +function force_solc_modules +{ + local custom_solcjs_path="${1:-solc/}" + + [[ -d node_modules/ ]] || assertFail + + printLog "Replacing all installed solc-js with a link to the latest version..." + soljson_binaries=$(find node_modules -type f -path "*/solc/soljson.js") + for soljson_binary in $soljson_binaries do - ( - if [ -d "$d" ]; then - cd $d - rm -rf solc - git clone --depth 1 -b master https://github.com/ethereum/solc-js.git solc - cp "$soljson" solc/soljson.js + local solc_module_path + solc_module_path=$(dirname "$soljson_binary") - cd solc - npm install - fi - ) + printLog "Found and replaced solc-js in $solc_module_path" + rm -r "$solc_module_path" + ln -s "$custom_solcjs_path" "$solc_module_path" done } @@ -131,7 +136,7 @@ function force_truffle_compiler_settings local config_file="$1" local solc_path="$2" local level="$3" - local evm_version="$4" + local evm_version="${4:-"$CURRENT_EVM_VERSION"}" printLog "Forcing Truffle compiler settings..." echo "-------------------------------------" @@ -147,30 +152,18 @@ function force_truffle_compiler_settings echo "module.exports['compilers'] = $(truffle_compiler_settings "$solc_path" "$level" "$evm_version");" >> "$config_file" } -function verify_compiler_version +function truffle_verify_compiler_version { local solc_version="$1" + local full_solc_version="$2" - printLog "Verify that the correct version ($solc_version) of the compiler was used to compile the contracts..." - grep -e "$solc_version" -r build/contracts > /dev/null + printLog "Verify that the correct version (${solc_version}/${full_solc_version}) of the compiler was used to compile the contracts..." + grep "$full_solc_version" --with-filename --recursive build/contracts || fail "Wrong compiler version detected." } -function clean +function truffle_clean { - rm -rf build || true -} - -function run_install -{ - local soljson="$1" - local init_fn="$2" - printLog "Running install function..." - - replace_version_pragmas - force_truffle_solc_modules "$soljson" - force_truffle_compiler_settings "$CONFIG" "${DIR}/solc" "$OPTIMIZER_LEVEL" london - - $init_fn + rm -rf build/ } function run_test @@ -219,31 +212,35 @@ function truffle_compiler_settings echo "}" } +function compile_and_run_test +{ + local compile_fn="$1" + local test_fn="$2" + local verify_fn="$3" + + printLog "Running compile function..." + $compile_fn + $verify_fn "$SOLCVERSION_SHORT" "$SOLCVERSION" + + if [[ "$COMPILE_ONLY" == 1 ]]; then + printLog "Skipping test function..." + else + printLog "Running test function..." + $test_fn + fi +} + function truffle_run_test { - local soljson="$1" - local compile_fn="$2" - local test_fn="$3" + local config_file="$1" + local solc_path="$2" + local optimizer_level="$3" + local compile_fn="$4" + local test_fn="$5" - replace_version_pragmas - force_truffle_solc_modules "$soljson" - - for level in $(seq "$OPTIMIZER_LEVEL" 3) - do - clean - force_truffle_compiler_settings "$CONFIG" "${DIR}/solc" "$level" london - - printLog "Running compile function..." - $compile_fn - verify_compiler_version "$SOLCVERSION" - - if [[ "$COMPILE_ONLY" == 1 ]]; then - printLog "Skipping test function..." - else - printLog "Running test function..." - $test_fn - fi - done + truffle_clean + force_truffle_compiler_settings "$config_file" "$solc_path" "$optimizer_level" + compile_and_run_test compile_fn test_fn truffle_verify_compiler_version } function external_test diff --git a/test/externalTests/ens.sh b/test/externalTests/ens.sh index e3bdb229a..bbdc573e2 100755 --- a/test/externalTests/ens.sh +++ b/test/externalTests/ens.sh @@ -27,26 +27,34 @@ source test/externalTests/common.sh verify_input "$1" export SOLJSON="$1" -function install_fn { npm install; } function compile_fn { npx truffle compile; } function test_fn { npm run test; } function ens_test { - export OPTIMIZER_LEVEL=1 - export CONFIG="truffle-config.js" + local repo="https://github.com/ensdomains/ens.git" + local branch=master + local config_file="truffle-config.js" + local min_optimizer_level=1 + local max_optimizer_level=3 - truffle_setup "$SOLJSON" https://github.com/ensdomains/ens.git master + setup_solcjs "$DIR" "$SOLJSON" + download_project "$repo" "$branch" "$DIR" # Use latest Truffle. Older versions crash on the output from 0.8.0. force_truffle_version ^5.1.55 - # Remove the lock file (if it exists) to prevent it from overriding our changes in package.json - rm -f package-lock.json + neutralize_package_lock + neutralize_package_json_hooks + force_truffle_compiler_settings "$config_file" "${DIR}/solc" "$min_optimizer_level" + npm install - run_install "$SOLJSON" install_fn + replace_version_pragmas + force_solc_modules "${DIR}/solc" - truffle_run_test "$SOLJSON" compile_fn test_fn + for level in $(seq "$min_optimizer_level" "$max_optimizer_level"); do + truffle_run_test "$config_file" "${DIR}/solc" "$level" compile_fn test_fn + done } external_test Ens ens_test diff --git a/test/externalTests/gnosis-v2.sh b/test/externalTests/gnosis-v2.sh index 338b2418f..d92bcc186 100755 --- a/test/externalTests/gnosis-v2.sh +++ b/test/externalTests/gnosis-v2.sh @@ -33,20 +33,29 @@ function test_fn { npm test; } function gnosis_safe_test { - OPTIMIZER_LEVEL=2 - CONFIG="truffle-config.js" + local repo="https://github.com/solidity-external-tests/safe-contracts.git" + local branch=v2_080 + local config_file="truffle-config.js" + local min_optimizer_level=2 + local max_optimizer_level=3 - truffle_setup "$SOLJSON" https://github.com/solidity-external-tests/safe-contracts.git v2_080 + setup_solcjs "$DIR" "$SOLJSON" + download_project "$repo" "$branch" "$DIR" sed -i 's|github:gnosis/mock-contract#sol_0_5_0|github:solidity-external-tests/mock-contract#master_080|g' package.json sed -i -E 's|"@gnosis.pm/util-contracts": "[^"]+"|"@gnosis.pm/util-contracts": "github:solidity-external-tests/util-contracts#solc-7_080"|g' package.json - # Remove the lock file (if it exists) to prevent it from overriding our changes in package.json - rm -f package-lock.json + neutralize_package_lock + neutralize_package_json_hooks + force_truffle_compiler_settings "$config_file" "${DIR}/solc" "$min_optimizer_level" + npm install --package-lock - run_install "$SOLJSON" install_fn + replace_version_pragmas + force_solc_modules "${DIR}/solc" - truffle_run_test "$SOLJSON" compile_fn test_fn + for level in $(seq "$min_optimizer_level" "$max_optimizer_level"); do + truffle_run_test "$config_file" "${DIR}/solc" "$level" compile_fn test_fn + done } external_test Gnosis-Safe gnosis_safe_test diff --git a/test/externalTests/gnosis.sh b/test/externalTests/gnosis.sh index a8a50782d..b6d9ab0bc 100755 --- a/test/externalTests/gnosis.sh +++ b/test/externalTests/gnosis.sh @@ -27,25 +27,33 @@ source test/externalTests/common.sh verify_input "$1" SOLJSON="$1" -function install_fn { npm install --package-lock; } function compile_fn { npx truffle compile; } function test_fn { npm test; } function gnosis_safe_test { - OPTIMIZER_LEVEL=2 - CONFIG="truffle-config.js" + local repo="https://github.com/solidity-external-tests/safe-contracts.git" + local branch=development_080 + local config_file="truffle-config.js" + local min_optimizer_level=2 + local max_optimizer_level=3 - truffle_setup "$SOLJSON" https://github.com/solidity-external-tests/safe-contracts.git development_080 + setup_solcjs "$DIR" "$SOLJSON" + download_project "$repo" "$branch" "$DIR" sed -i 's|github:gnosis/mock-contract#sol_0_5_0|github:solidity-external-tests/mock-contract#master_080|g' package.json - # Remove the lock file (if it exists) to prevent it from overriding our changes in package.json - rm -f package-lock.json + neutralize_package_lock + neutralize_package_json_hooks + force_truffle_compiler_settings "$config_file" "${DIR}/solc" "$min_optimizer_level" + npm install --package-lock - run_install "$SOLJSON" install_fn + replace_version_pragmas + force_solc_modules "${DIR}/solc" - truffle_run_test "$SOLJSON" compile_fn test_fn + for level in $(seq "$min_optimizer_level" "$max_optimizer_level"); do + truffle_run_test "$config_file" "${DIR}/solc" "$level" compile_fn test_fn + done } 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 fa0d7ccee..a3b24db9e 100755 --- a/test/externalTests/solc-js/solc-js.sh +++ b/test/externalTests/solc-js/solc-js.sh @@ -28,7 +28,6 @@ verify_version_input "$1" "$2" SOLJSON="$1" VERSION="$2" -function install_fn { echo "Nothing to install."; } function compile_fn { echo "Nothing to compile."; } function test_fn { npm test; } diff --git a/test/externalTests/zeppelin.sh b/test/externalTests/zeppelin.sh index ca90d46f4..1e23bb7ae 100755 --- a/test/externalTests/zeppelin.sh +++ b/test/externalTests/zeppelin.sh @@ -27,19 +27,30 @@ source test/externalTests/common.sh verify_input "$1" SOLJSON="$1" -function install_fn { npm install; } function compile_fn { npx truffle compile; } function test_fn { npm run test; } function zeppelin_test { - OPTIMIZER_LEVEL=1 - CONFIG="truffle-config.js" + local repo="https://github.com/OpenZeppelin/openzeppelin-contracts.git" + local branch=master + local config_file="truffle-config.js" + local min_optimizer_level=1 + local max_optimizer_level=3 - truffle_setup "$SOLJSON" https://github.com/OpenZeppelin/openzeppelin-contracts.git master - run_install "$SOLJSON" install_fn + setup_solcjs "$DIR" "$SOLJSON" + download_project "$repo" "$branch" "$DIR" - truffle_run_test "$SOLJSON" compile_fn test_fn + neutralize_package_json_hooks + force_truffle_compiler_settings "$config_file" "${DIR}/solc" "$min_optimizer_level" + npm install + + replace_version_pragmas + force_solc_modules "${DIR}/solc" + + for level in $(seq "$min_optimizer_level" "$max_optimizer_level"); do + truffle_run_test "$config_file" "${DIR}/solc" "$level" compile_fn test_fn + done } external_test Zeppelin zeppelin_test