Skip to content

Commit 2e046c8

Browse files
committed
Fix test scripts
1 parent 0d9f09b commit 2e046c8

File tree

5 files changed

+70
-53
lines changed

5 files changed

+70
-53
lines changed

.solcover.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
module.exports = {
2-
norpc: true,
2+
compileCommand: 'node --max-old-space-size=4096 ../node_modules/.bin/truffle compile --network development',
3+
testCommand: 'node --max-old-space-size=4096 ../node_modules/.bin/truffle test --network development',
34
skipFiles: [
45
'contracts/Migrations.sol',
56
'contracts/implementation.sol'

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
},
1818
"dependencies": {},
1919
"scripts": {
20-
"coverage": "./node_modules/.bin/solidity-coverage",
20+
"coverage": "scripts/coverage.sh",
2121
"build": "truffle compile",
2222
"migrate": "truffle migrate",
2323
"test": "scripts/test.sh"

scripts/coverage.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/bash
2+
3+
source $(dirname "$0")/utils.sh
4+
check_truffle_project
5+
trap kill_ganache SIGINT SIGTERM SIGTSTP
6+
run_ganache
7+
run_coverage
8+
kill_ganache
9+
exit 0

scripts/test.sh

Lines changed: 2 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,8 @@
11
#!/bin/bash
22

3-
# Test script should be run in the base directory
4-
check_truffle_project() {
5-
cd `dirname "$0"` && cd ../
6-
if [ -f "truffle.js" ]
7-
then
8-
echo "Start testing"
9-
else
10-
echo "You should run this script in the base directory of this project"
11-
exit 1
12-
fi
13-
}
14-
15-
# Terminate running ganaches for testing
16-
kill_ganache() {
17-
echo "Terminate ganache"
18-
if !([ -z ${pid+x} ]);then
19-
kill $pid > /dev/null 2>&1
20-
fi
21-
}
22-
23-
# Compile contracts
24-
compile() {
25-
truffle compile --all
26-
[ $? -ne 0 ] && exit 1
27-
}
28-
29-
# Run private block-chain for test cases
30-
run_ganache() {
31-
ganache-cli > /dev/null & pid=$!
32-
if ps -p $pid > /dev/null
33-
then
34-
echo "Running ganache..."
35-
else
36-
echo "Failed to run a chain"
37-
exit 1
38-
fi
39-
}
40-
41-
# Deploy contracts on the block-chain for testing
42-
migrate() {
43-
truffle migrate --network development
44-
[ $? -ne 0 ] && exit 1
45-
}
46-
47-
# Run test cases with truffle
48-
run_test() {
49-
truffle test --network development
50-
[ $? -ne 0 ] && exit 1
51-
}
52-
53-
trap kill_ganache SIGINT SIGTERM SIGTSTP
3+
source $(dirname "$0")/utils.sh
544
check_truffle_project
5+
trap kill_ganache SIGINT SIGTERM SIGTSTP
556
run_ganache
567
run_test
578
kill_ganache

scripts/utils.sh

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#!/bin/bash
2+
3+
# Test script should be run in the base directory
4+
check_truffle_project() {
5+
cd `dirname "$0"` && cd ../
6+
if [ -f "truffle.js" ]
7+
then
8+
echo "Start testing"
9+
else
10+
echo "You should run this script in the base directory of this project"
11+
exit 1
12+
fi
13+
}
14+
15+
# Terminate running ganaches for testing
16+
kill_ganache() {
17+
echo "Terminate ganache"
18+
if !([ -z ${pid+x} ]);then
19+
kill $pid > /dev/null 2>&1
20+
fi
21+
}
22+
23+
# Compile contracts
24+
compile() {
25+
truffle compile --all
26+
[ $? -ne 0 ] && exit 1
27+
}
28+
29+
# Run private block-chain for test cases
30+
run_ganache() {
31+
ganache-cli > /dev/null & pid=$!
32+
if ps -p $pid > /dev/null
33+
then
34+
echo "Running ganache..."
35+
else
36+
echo "Failed to run a chain"
37+
exit 1
38+
fi
39+
}
40+
41+
# Deploy contracts on the block-chain for testing
42+
migrate() {
43+
truffle migrate --network development
44+
[ $? -ne 0 ] && exit 1
45+
}
46+
47+
# Run test cases with truffle
48+
run_test() {
49+
truffle test --network development
50+
[ $? -ne 0 ] && exit 1
51+
}
52+
53+
# Check test coverage
54+
run_coverage() {
55+
./node_modules/.bin/solidity-coverage
56+
}

0 commit comments

Comments
 (0)