mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Modularize external test setup.
This commit is contained in:
parent
85e1223112
commit
7808af79ae
@ -28,6 +28,17 @@
|
||||
|
||||
set -e
|
||||
|
||||
if [ "$CIRCLECI" ]
|
||||
then
|
||||
function printTask() { echo ""; echo "$(tput bold)$(tput setaf 2)$1$(tput setaf 7)"; }
|
||||
function printError() { echo ""; echo "$(tput setaf 1)$1$(tput setaf 7)"; }
|
||||
function printLog() { echo "$(tput setaf 3)$1$(tput setaf 7)"; }
|
||||
else
|
||||
function printTask() { echo ""; echo "$(tput bold)$(tput setaf 2)$1$(tput sgr0)"; }
|
||||
function printError() { echo ""; echo "$(tput setaf 1)$1$(tput sgr0)"; }
|
||||
function printLog() { echo "$(tput setaf 3)$1$(tput sgr0)"; }
|
||||
fi
|
||||
|
||||
if [ ! -f "$1" ]
|
||||
then
|
||||
echo "Usage: $0 <path to soljson.js>"
|
||||
@ -35,38 +46,64 @@ then
|
||||
fi
|
||||
|
||||
SOLJSON="$1"
|
||||
|
||||
function test_truffle
|
||||
{
|
||||
name="$1"
|
||||
repo="$2"
|
||||
branch="$3"
|
||||
echo "Running $name tests..."
|
||||
DIR=$(mktemp -d)
|
||||
(
|
||||
cd "$DIR"
|
||||
git clone --depth 1 -b v0.5.0 https://github.com/ethereum/solc-js.git solc
|
||||
SOLCVERSION="UNDEFINED"
|
||||
|
||||
function setup_solcjs
|
||||
{
|
||||
printLog "Setting up solc-js..."
|
||||
cd "$1"
|
||||
git clone --depth 1 -b v0.5.0 https://github.com/ethereum/solc-js.git solc
|
||||
|
||||
cd solc
|
||||
npm install
|
||||
cp "$SOLJSON" soljson.js
|
||||
SOLCVERSION=$(./solcjs --version)
|
||||
cd ..
|
||||
echo "Using solcjs version $SOLCVERSION"
|
||||
}
|
||||
|
||||
if [ -n "$branch" ]
|
||||
then
|
||||
echo "Cloning $branch of $repo..."
|
||||
git clone --depth 1 "$repo" -b "$branch" "$DIR/ext"
|
||||
else
|
||||
echo "Cloning $repo..."
|
||||
git clone --depth 1 "$repo" "$DIR/ext"
|
||||
fi
|
||||
function download_project
|
||||
{
|
||||
local repo="$1"
|
||||
local branch="$2"
|
||||
local dir="$3"
|
||||
|
||||
printLog "Cloning $branch of $repo..."
|
||||
git clone --depth 1 "$repo" -b "$branch" "$dir/ext"
|
||||
cd ext
|
||||
echo "Current commit hash: `git rev-parse HEAD`"
|
||||
npm ci
|
||||
# Replace solc package by v0.5.0
|
||||
}
|
||||
|
||||
function setup
|
||||
{
|
||||
local repo="$1"
|
||||
local branch="$2"
|
||||
local dir="$3"
|
||||
|
||||
setup_solcjs "$dir"
|
||||
download_project "$repo" "$branch" "$dir"
|
||||
|
||||
replace_version_pragmas
|
||||
}
|
||||
|
||||
function replace_version_pragmas
|
||||
{
|
||||
# Replace fixed-version pragmas in Gnosis (part of Consensys best practice)
|
||||
printLog "Replacing fixed-version pragmas..."
|
||||
find contracts test -name '*.sol' -type f -print0 | xargs -0 sed -i -e 's/pragma solidity [\^0-9\.]*/pragma solidity >=0.0/'
|
||||
}
|
||||
|
||||
function replace_libsolc_call
|
||||
{
|
||||
# Change "compileStandard" to "compile" (needed for pre-5.x Truffle)
|
||||
printLog "Replacing libsolc compile call in Truffle..."
|
||||
sed -i s/solc.compileStandard/solc.compile/ "node_modules/truffle/build/cli.bundled.js"
|
||||
}
|
||||
|
||||
function force_solc_truffle_modules
|
||||
{
|
||||
# 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
|
||||
do
|
||||
(
|
||||
@ -75,37 +112,80 @@ function test_truffle
|
||||
cd $d
|
||||
rm -rf solc
|
||||
git clone --depth 1 -b v0.5.0 https://github.com/ethereum/solc-js.git solc
|
||||
cp "$SOLJSON" solc/soljson.js
|
||||
cp "$1" solc/soljson.js
|
||||
fi
|
||||
)
|
||||
done
|
||||
if [ "$name" == "Zeppelin" -o "$name" == "Gnosis" ]; then
|
||||
echo "Replaced fixed-version pragmas..."
|
||||
# Replace fixed-version pragmas in Gnosis (part of Consensys best practice)
|
||||
find contracts test -name '*.sol' -type f -print0 | xargs -0 sed -i -e 's/pragma solidity [\^0-9\.]*/pragma solidity >=0.0/'
|
||||
fi
|
||||
# Change "compileStandard" to "compile" (needed for pre-5.x Truffle)
|
||||
sed -i s/solc.compileStandard/solc.compile/ "node_modules/truffle/build/cli.bundled.js"
|
||||
# Force usage of correct solidity binary (only works with Truffle 5.x)
|
||||
cat >> truffle*.js <<EOF
|
||||
module.exports['compilers'] = {solc: {version: "$DIR/solc"} };
|
||||
}
|
||||
|
||||
function force_solc
|
||||
{
|
||||
local config_file="$1"
|
||||
local dir="$2"
|
||||
|
||||
printLog "Forcing solc version..."
|
||||
cat >> "$config_file" <<EOF
|
||||
module.exports['compilers'] = {solc: {version: "$dir/solc"} };
|
||||
EOF
|
||||
}
|
||||
|
||||
function force_solc_settings
|
||||
{
|
||||
local config_file="$1"
|
||||
local settings="$2"
|
||||
local evmVersion="$3"
|
||||
|
||||
printLog "Forcing solc settings..."
|
||||
echo "Config file: $config_file"
|
||||
echo "Optimizer settings: $settings"
|
||||
echo "EVM version: $evmVersion"
|
||||
echo ""
|
||||
|
||||
echo "module.exports['compilers']['solc']['settings'] = { optimizer: $settings, evmVersion: \"$evmVersion\" };" >> "$config_file"
|
||||
}
|
||||
|
||||
function verify_compiler_version
|
||||
{
|
||||
local solc_version="$1"
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
function clean
|
||||
{
|
||||
rm -rf build || true
|
||||
}
|
||||
|
||||
# Since Zeppelin 2.1.1 it supports Solidity 0.5.0.
|
||||
printTask "Testing Zeppelin..."
|
||||
echo "==========================="
|
||||
DIR=$(mktemp -d)
|
||||
(
|
||||
setup https://github.com/OpenZeppelin/openzeppelin-solidity.git master "$DIR"
|
||||
|
||||
npm install
|
||||
|
||||
CONFIG="truffle-config.js"
|
||||
|
||||
replace_libsolc_call
|
||||
force_solc_truffle_modules "$SOLJSON"
|
||||
force_solc "$CONFIG" "$DIR"
|
||||
|
||||
for optimize in "{ enabled: false }" "{ enabled: true }" "{ enabled: true, details: { yul: true } }"
|
||||
do
|
||||
rm -rf build || true
|
||||
echo "module.exports['compilers']['solc']['settings'] = {optimizer: $optimize };" >> truffle*.js
|
||||
clean
|
||||
force_solc_settings "$CONFIG" "$optimize" "petersburg"
|
||||
|
||||
npx truffle compile
|
||||
echo "Verify that the correct version ($SOLCVERSION) of the compiler was used to compile the contracts..."
|
||||
grep -e "$SOLCVERSION" -r build/contracts > /dev/null
|
||||
verify_compiler_version "$SOLCVERSION"
|
||||
npm run test
|
||||
done
|
||||
)
|
||||
rm -rf "$DIR"
|
||||
}
|
||||
echo "Done."
|
||||
|
||||
# Since Zeppelin 2.1.1 it supports Solidity 0.5.0.
|
||||
test_truffle Zeppelin https://github.com/OpenZeppelin/openzeppelin-solidity.git master
|
||||
echo "All external tests passed."
|
||||
|
||||
# Disabled temporarily as it needs to be updated to latest Truffle first.
|
||||
#test_truffle Gnosis https://github.com/axic/pm-contracts.git solidity-050
|
||||
|
Loading…
Reference in New Issue
Block a user