Skip to content

Commit

Permalink
tests: batch tests in different CI stages
Browse files Browse the repository at this point in the history
  • Loading branch information
facuspagnuolo committed Aug 28, 2019
1 parent 5e0b779 commit 8629ab5
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 6 deletions.
20 changes: 17 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,22 @@ notifications:
email: false
node_js:
- '8'
env:
- TASK=test
before_script:
- npm prune
script: "npm run $TASK"
jobs:
include:
- stage: integration
script: npm test test/court/*.js
name: "Court"
- stage: unit
script: npm test test/registry/*.js
name: "Registry"
- stage: unit
script: npm test test/tree/*.js
name: "Tree"
- stage: unit
script: npm test test/voting/*.js
name: "Voting"
- stage: unit
script: npm test test/*.js
name: "Others"
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,16 @@
"description": "",
"scripts": {
"test": "TRUFFLE_TEST=true npm run ganache-cli:test",
"analysis:tree": "TRUFFLE_TEST=true SUMTREE_GAS_ANALYSIS=true npm run ganache-cli:test",
"coverage": "SOLIDITY_COVERAGE=true npm run ganache-cli:test",
"ganache-cli:test": "./node_modules/@aragon/test-helpers/ganache-cli.sh",
"ganache-cli:test": "./scripts/ganache-cli.sh",
"lint": "solium --dir ./contracts"
},
"author": "Aragon Association",
"license": "GPL-3.0",
"devDependencies": {
"@aragon/apps-shared-migrations": "^1.0.0",
"@aragon/test-helpers": "^2.0.0",
"ganache-cli": "^6.1.0",
"ganache-cli": "^6.4.5",
"solidity-coverage": "0.5.8",
"solium": "^1.2.3",
"truffle": "^4.1.15",
Expand Down
66 changes: 66 additions & 0 deletions scripts/ganache-cli.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#!/usr/bin/env bash

# Exit script as soon as a command fails.
set -o errexit

# Executes cleanup function at script exit.
trap cleanup EXIT

cleanup() {
# Kill the RPC instance that we started (if we started one and if it's still running).
if [ -n "$rpc_pid" ] && ps -p $rpc_pid > /dev/null; then
kill -9 $rpc_pid
fi
}

setup_coverage_variables() {
PORT=${PORT-8555}
BALANCE=${BALANCE-100000}
GAS_LIMIT=${GAS_LIMIT-0xfffffffffff}
NETWORK_ID=${NETWORK_ID-16}
ACCOUNTS=${ACCOUNTS-200}
}

setup_testing_variables() {
PORT=${PORT-8545}
BALANCE=${BALANCE-100000}
GAS_LIMIT=${GAS_LIMIT-8000000}
NETWORK_ID=${NETWORK_ID-15}
ACCOUNTS=${ACCOUNTS-200}
}

start_ganache() {
echo "Starting ganache-cli..."
npx ganache-cli -i ${NETWORK_ID} -l ${GAS_LIMIT} -a ${ACCOUNTS} -e ${BALANCE} -p ${PORT} > /dev/null &
rpc_pid=$!
sleep 3
echo "Running ganache-cli with pid ${rpc_pid} in port ${PORT}"
}

start_testrpc() {
echo "Starting testrpc-sc..."
npx testrpc-sc -i ${NETWORK_ID} -l ${GAS_LIMIT} -a ${ACCOUNTS} -e ${BALANCE} -p ${PORT} > /dev/null &
rpc_pid=$!
sleep 3
echo "Running testrpc-sc with pid ${rpc_pid} in port ${PORT}"
}

measure_coverage() {
echo "Measuring coverage $@..."
npx solidity-coverage $@
}

run_tests() {
echo "Running tests $@..."
npx truffle test --network rpc $@
}

if [ "$SOLIDITY_COVERAGE" = true ]; then
setup_coverage_variables
start_testrpc
measure_coverage $@
else
setup_testing_variables
start_ganache
run_tests $@
fi

0 comments on commit 8629ab5

Please sign in to comment.