externalTests: Refactor to be more explicit and easier to adjust for special cases

This commit is contained in:
Kamil Śliwak 2021-10-25 14:29:43 +02:00
parent 7ccdbd5b08
commit b57c0a0b81
7 changed files with 125 additions and 83 deletions

View File

@ -27,24 +27,37 @@ 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"
replace_version_pragmas
force_truffle_solc_modules "$SOLJSON"
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_truffle_solc_modules "$SOLJSON"
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

View File

@ -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).
@ -131,7 +123,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 +139,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 +199,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

View File

@ -27,16 +27,19 @@ 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
@ -44,9 +47,17 @@ function ens_test
# Remove the lock file (if it exists) to prevent it from overriding our changes in package.json
rm -f package-lock.json
run_install "$SOLJSON" install_fn
replace_version_pragmas
force_truffle_solc_modules "$SOLJSON"
force_truffle_compiler_settings "$config_file" "${DIR}/solc" "$min_optimizer_level"
npm install
truffle_run_test "$SOLJSON" compile_fn test_fn
replace_version_pragmas
force_truffle_solc_modules "$SOLJSON"
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

View File

@ -33,10 +33,14 @@ 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
@ -44,9 +48,17 @@ function gnosis_safe_test
# Remove the lock file (if it exists) to prevent it from overriding our changes in package.json
rm -f package-lock.json
run_install "$SOLJSON" install_fn
replace_version_pragmas
force_truffle_solc_modules "$SOLJSON"
force_truffle_compiler_settings "$config_file" "${DIR}/solc" "$min_optimizer_level"
npm install --package-lock
truffle_run_test "$SOLJSON" compile_fn test_fn
replace_version_pragmas
force_truffle_solc_modules "$SOLJSON"
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

View File

@ -27,25 +27,36 @@ 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
run_install "$SOLJSON" install_fn
replace_version_pragmas
force_truffle_solc_modules "$SOLJSON"
force_truffle_compiler_settings "$config_file" "${DIR}/solc" "$min_optimizer_level"
npm install --package-lock
truffle_run_test "$SOLJSON" compile_fn test_fn
replace_version_pragmas
force_truffle_solc_modules "$SOLJSON"
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

View File

@ -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; }

View File

@ -27,19 +27,31 @@ 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
replace_version_pragmas
force_truffle_solc_modules "$SOLJSON"
force_truffle_compiler_settings "$config_file" "${DIR}/solc" "$min_optimizer_level"
npm install
replace_version_pragmas
force_truffle_solc_modules "$SOLJSON"
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