mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
externalTests: Refactor to be more explicit and easier to adjust for special cases
This commit is contained in:
parent
7ccdbd5b08
commit
b57c0a0b81
@ -27,24 +27,37 @@ source test/externalTests/common.sh
|
|||||||
verify_input "$1"
|
verify_input "$1"
|
||||||
SOLJSON="$1"
|
SOLJSON="$1"
|
||||||
|
|
||||||
function install_fn { yarn; git submodule update --init; }
|
|
||||||
function compile_fn { yarn run provision:token:contracts; }
|
function compile_fn { yarn run provision:token:contracts; }
|
||||||
function test_fn { yarn run test:contracts; }
|
function test_fn { yarn run test:contracts; }
|
||||||
|
|
||||||
function colony_test
|
function colony_test
|
||||||
{
|
{
|
||||||
OPTIMIZER_LEVEL=3
|
local repo="https://github.com/solidity-external-tests/colonyNetwork.git"
|
||||||
CONFIG="truffle.js"
|
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
|
setup_solcjs "$DIR" "$SOLJSON"
|
||||||
run_install "$SOLJSON" install_fn
|
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
|
cd lib
|
||||||
rm -Rf dappsys
|
rm -Rf dappsys
|
||||||
git clone https://github.com/solidity-external-tests/dappsys-monolithic.git -b master_080 dappsys
|
git clone https://github.com/solidity-external-tests/dappsys-monolithic.git -b master_080 dappsys
|
||||||
cd ..
|
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
|
external_test ColonyNetworks colony_test
|
||||||
|
@ -22,6 +22,8 @@ set -e
|
|||||||
|
|
||||||
# Requires "${REPO_ROOT}/scripts/common.sh" to be included before.
|
# Requires "${REPO_ROOT}/scripts/common.sh" to be included before.
|
||||||
|
|
||||||
|
CURRENT_EVM_VERSION=london
|
||||||
|
|
||||||
function verify_input
|
function verify_input
|
||||||
{
|
{
|
||||||
if [ ! -f "$1" ]; then
|
if [ ! -f "$1" ]; then
|
||||||
@ -51,8 +53,8 @@ function setup_solcjs
|
|||||||
{
|
{
|
||||||
local dir="$1"
|
local dir="$1"
|
||||||
local soljson="$2"
|
local soljson="$2"
|
||||||
local branch="$3"
|
local branch="${3:-master}"
|
||||||
local path="$4"
|
local path="${4:-solc/}"
|
||||||
|
|
||||||
cd "$dir"
|
cd "$dir"
|
||||||
printLog "Setting up solc-js..."
|
printLog "Setting up solc-js..."
|
||||||
@ -86,16 +88,6 @@ function force_truffle_version
|
|||||||
sed -i 's/"truffle":\s*".*"/"truffle": "'"$version"'"/g' package.json
|
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
|
function replace_version_pragmas
|
||||||
{
|
{
|
||||||
# Replace fixed-version pragmas (part of Consensys best practice).
|
# Replace fixed-version pragmas (part of Consensys best practice).
|
||||||
@ -131,7 +123,7 @@ function force_truffle_compiler_settings
|
|||||||
local config_file="$1"
|
local config_file="$1"
|
||||||
local solc_path="$2"
|
local solc_path="$2"
|
||||||
local level="$3"
|
local level="$3"
|
||||||
local evm_version="$4"
|
local evm_version="${4:-"$CURRENT_EVM_VERSION"}"
|
||||||
|
|
||||||
printLog "Forcing Truffle compiler settings..."
|
printLog "Forcing Truffle compiler settings..."
|
||||||
echo "-------------------------------------"
|
echo "-------------------------------------"
|
||||||
@ -147,30 +139,18 @@ function force_truffle_compiler_settings
|
|||||||
echo "module.exports['compilers'] = $(truffle_compiler_settings "$solc_path" "$level" "$evm_version");" >> "$config_file"
|
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 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..."
|
printLog "Verify that the correct version (${solc_version}/${full_solc_version}) of the compiler was used to compile the contracts..."
|
||||||
grep -e "$solc_version" -r build/contracts > /dev/null
|
grep "$full_solc_version" --with-filename --recursive build/contracts || fail "Wrong compiler version detected."
|
||||||
}
|
}
|
||||||
|
|
||||||
function clean
|
function truffle_clean
|
||||||
{
|
{
|
||||||
rm -rf build || true
|
rm -rf build/
|
||||||
}
|
|
||||||
|
|
||||||
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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function run_test
|
function run_test
|
||||||
@ -219,23 +199,15 @@ function truffle_compiler_settings
|
|||||||
echo "}"
|
echo "}"
|
||||||
}
|
}
|
||||||
|
|
||||||
function truffle_run_test
|
function compile_and_run_test
|
||||||
{
|
{
|
||||||
local soljson="$1"
|
local compile_fn="$1"
|
||||||
local compile_fn="$2"
|
local test_fn="$2"
|
||||||
local test_fn="$3"
|
local verify_fn="$3"
|
||||||
|
|
||||||
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..."
|
printLog "Running compile function..."
|
||||||
$compile_fn
|
$compile_fn
|
||||||
verify_compiler_version "$SOLCVERSION"
|
$verify_fn "$SOLCVERSION_SHORT" "$SOLCVERSION"
|
||||||
|
|
||||||
if [[ "$COMPILE_ONLY" == 1 ]]; then
|
if [[ "$COMPILE_ONLY" == 1 ]]; then
|
||||||
printLog "Skipping test function..."
|
printLog "Skipping test function..."
|
||||||
@ -243,7 +215,19 @@ function truffle_run_test
|
|||||||
printLog "Running test function..."
|
printLog "Running test function..."
|
||||||
$test_fn
|
$test_fn
|
||||||
fi
|
fi
|
||||||
done
|
}
|
||||||
|
|
||||||
|
function truffle_run_test
|
||||||
|
{
|
||||||
|
local config_file="$1"
|
||||||
|
local solc_path="$2"
|
||||||
|
local optimizer_level="$3"
|
||||||
|
local compile_fn="$4"
|
||||||
|
local test_fn="$5"
|
||||||
|
|
||||||
|
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
|
function external_test
|
||||||
|
@ -27,16 +27,19 @@ source test/externalTests/common.sh
|
|||||||
verify_input "$1"
|
verify_input "$1"
|
||||||
export SOLJSON="$1"
|
export SOLJSON="$1"
|
||||||
|
|
||||||
function install_fn { npm install; }
|
|
||||||
function compile_fn { npx truffle compile; }
|
function compile_fn { npx truffle compile; }
|
||||||
function test_fn { npm run test; }
|
function test_fn { npm run test; }
|
||||||
|
|
||||||
function ens_test
|
function ens_test
|
||||||
{
|
{
|
||||||
export OPTIMIZER_LEVEL=1
|
local repo="https://github.com/ensdomains/ens.git"
|
||||||
export CONFIG="truffle-config.js"
|
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.
|
# Use latest Truffle. Older versions crash on the output from 0.8.0.
|
||||||
force_truffle_version ^5.1.55
|
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
|
# Remove the lock file (if it exists) to prevent it from overriding our changes in package.json
|
||||||
rm -f package-lock.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
|
external_test Ens ens_test
|
||||||
|
@ -33,10 +33,14 @@ function test_fn { npm test; }
|
|||||||
|
|
||||||
function gnosis_safe_test
|
function gnosis_safe_test
|
||||||
{
|
{
|
||||||
OPTIMIZER_LEVEL=2
|
local repo="https://github.com/solidity-external-tests/safe-contracts.git"
|
||||||
CONFIG="truffle-config.js"
|
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 '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
|
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
|
# Remove the lock file (if it exists) to prevent it from overriding our changes in package.json
|
||||||
rm -f package-lock.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
|
external_test Gnosis-Safe gnosis_safe_test
|
||||||
|
@ -27,25 +27,36 @@ source test/externalTests/common.sh
|
|||||||
verify_input "$1"
|
verify_input "$1"
|
||||||
SOLJSON="$1"
|
SOLJSON="$1"
|
||||||
|
|
||||||
function install_fn { npm install --package-lock; }
|
|
||||||
function compile_fn { npx truffle compile; }
|
function compile_fn { npx truffle compile; }
|
||||||
function test_fn { npm test; }
|
function test_fn { npm test; }
|
||||||
|
|
||||||
function gnosis_safe_test
|
function gnosis_safe_test
|
||||||
{
|
{
|
||||||
OPTIMIZER_LEVEL=2
|
local repo="https://github.com/solidity-external-tests/safe-contracts.git"
|
||||||
CONFIG="truffle-config.js"
|
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
|
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
|
# Remove the lock file (if it exists) to prevent it from overriding our changes in package.json
|
||||||
rm -f package-lock.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
|
external_test Gnosis-Safe gnosis_safe_test
|
||||||
|
@ -28,7 +28,6 @@ verify_version_input "$1" "$2"
|
|||||||
SOLJSON="$1"
|
SOLJSON="$1"
|
||||||
VERSION="$2"
|
VERSION="$2"
|
||||||
|
|
||||||
function install_fn { echo "Nothing to install."; }
|
|
||||||
function compile_fn { echo "Nothing to compile."; }
|
function compile_fn { echo "Nothing to compile."; }
|
||||||
function test_fn { npm test; }
|
function test_fn { npm test; }
|
||||||
|
|
||||||
|
@ -27,19 +27,31 @@ source test/externalTests/common.sh
|
|||||||
verify_input "$1"
|
verify_input "$1"
|
||||||
SOLJSON="$1"
|
SOLJSON="$1"
|
||||||
|
|
||||||
function install_fn { npm install; }
|
|
||||||
function compile_fn { npx truffle compile; }
|
function compile_fn { npx truffle compile; }
|
||||||
function test_fn { npm run test; }
|
function test_fn { npm run test; }
|
||||||
|
|
||||||
function zeppelin_test
|
function zeppelin_test
|
||||||
{
|
{
|
||||||
OPTIMIZER_LEVEL=1
|
local repo="https://github.com/OpenZeppelin/openzeppelin-contracts.git"
|
||||||
CONFIG="truffle-config.js"
|
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
|
setup_solcjs "$DIR" "$SOLJSON"
|
||||||
run_install "$SOLJSON" install_fn
|
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
|
external_test Zeppelin zeppelin_test
|
||||||
|
Loading…
Reference in New Issue
Block a user