Skip to content

Commit 9ad5035

Browse files
committed
Add gas reporter and coverage plugings
1 parent 9338415 commit 9ad5035

File tree

7 files changed

+1291
-45
lines changed

7 files changed

+1291
-45
lines changed

Diff for: .gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@ cache
55
dist
66
ipfs.cmd
77
package-lock.json
8+
coverage
9+
coverage.json

Diff for: .solcover.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = {
2+
norpc: true,
3+
copyPackages: ['@aragon/os'],
4+
skipFiles: ['test', '@aragon/os'],
5+
}

Diff for: buidler.config.js

+5
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ const { usePlugin } = require('@nomiclabs/buidler/config')
33
const hooks = require('./scripts/buidler-hooks')
44

55
usePlugin('@aragon/buidler-aragon')
6+
usePlugin('buidler-gas-reporter')
7+
usePlugin('solidity-coverage')
68

79
module.exports = {
810
// Default Buidler configurations. Read more about it at https://buidler.dev/config/
@@ -19,6 +21,9 @@ module.exports = {
1921
runs: 10000,
2022
},
2123
},
24+
gasReporter: {
25+
enabled: !!process.env.GAS_REPORTER,
26+
},
2227
// Aragon plugin configuration
2328
aragon: {
2429
appServePort: 8001,

Diff for: contracts/test/TestImport.sol

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
pragma solidity 0.4.24;
2+
3+
import "@aragon/os/contracts/acl/ACL.sol";
4+
import "@aragon/os/contracts/factory/DAOFactory.sol";
5+
import "@aragon/os/contracts/factory/EVMScriptRegistryFactory.sol";
6+
7+
8+
// You might think this file is a bit odd, but let me explain.
9+
// We only use some contracts in our tests, which means Truffle
10+
// will not compile it for us, because it is from an external
11+
// dependency.
12+
//
13+
// We are now left with three options:
14+
// - Copy/paste these contracts
15+
// - Run the tests with `truffle compile --all` on
16+
// - Or trick Truffle by claiming we use it in a Solidity test
17+
//
18+
// You know which one I went for.
19+
20+
contract TestImports {
21+
constructor() public {
22+
// solium-disable-previous-line no-empty-blocks
23+
}
24+
}

Diff for: package.json

+7-1
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,11 @@
66
"postinstall": "yarn compile && yarn build-app",
77
"build-app": "cd app && npm install && cd ..",
88
"compile": "buidler compile --force",
9-
"test": "buidler test --network buidlerevm",
109
"start": "buidler start",
10+
"test": "buidler test --network buidlerevm",
11+
"test:gas": "GAS_REPORTER=true npm run ganache-cli:test",
12+
"coverage": "SOLIDITY_COVERAGE=true npm run ganache-cli:test",
13+
"ganache-cli:test": "./scripts/ganache-cli.sh",
1114
"publish:major": "buidler publish major",
1215
"publish:minor": "buidler publish minor",
1316
"publish:patch": "buidler publish patch"
@@ -23,6 +26,7 @@
2326
"@nomiclabs/buidler-truffle5": "^1.3.2",
2427
"@nomiclabs/buidler-web3": "^1.3.2",
2528
"babel-eslint": "^10.1.0",
29+
"buidler-gas-reporter": "^0.1.3",
2630
"eslint": "^7.1.0",
2731
"eslint-config-prettier": "^6.11.0",
2832
"eslint-config-standard": "^14.1.1",
@@ -35,7 +39,9 @@
3539
"eslint-plugin-react": "^7.20.0",
3640
"eslint-plugin-react-hooks": "^4.0.4",
3741
"eslint-plugin-standard": "^4.0.1",
42+
"ganache-cli": "^6.9.1",
3843
"prettier": "^2.0.5",
44+
"solidity-coverage": "^0.7.0",
3945
"web3": "^1.2.7"
4046
}
4147
}

Diff for: scripts/ganache-cli.sh

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#!/usr/bin/env bash
2+
3+
# Exit script as soon as a command fails.
4+
set -o errexit
5+
6+
# Executes cleanup function at script exit.
7+
trap cleanup EXIT
8+
9+
cleanup() {
10+
# Kill the ganache instance that we started (if we started one and if it's still running).
11+
if [ -n "$rpc_pid" ] && ps -p $rpc_pid > /dev/null; then
12+
kill -9 $rpc_pid
13+
fi
14+
}
15+
16+
ganache_port=8545
17+
18+
rpc_running() {
19+
nc -z localhost "$ganache_port"
20+
}
21+
22+
start_ganache() {
23+
if [ "$SOLIDITY_COVERAGE" = true ]; then
24+
export RUNNING_COVERAGE=true
25+
else
26+
echo "Starting our own ganache instance"
27+
28+
node_modules/.bin/ganache-cli -l 8000000 --port "$ganache_port" -m "explain tackle mirror kit van hammer degree position ginger unfair soup bonus" > /dev/null &
29+
30+
rpc_pid=$!
31+
32+
echo "Waiting for ganache to launch on port "$ganache_port"..."
33+
34+
while ! rpc_running; do
35+
sleep 0.1 # wait for 1/10 of the second before check again
36+
done
37+
38+
echo "Ganache launched!"
39+
fi
40+
}
41+
42+
if rpc_running; then
43+
echo "Using existing ganache instance"
44+
else
45+
start_ganache
46+
fi
47+
48+
echo "Buidler version $(npx buidler --version)"
49+
50+
if [ "$SOLIDITY_COVERAGE" = true ]; then
51+
node_modules/.bin/buidler coverage --network coverage "$@"
52+
else
53+
node_modules/.bin/buidler test "$@"
54+
fi

0 commit comments

Comments
 (0)