Skip to content

Commit c2e687b

Browse files
authored
Merge pull request #368 from sc-forks/stage/truffle-config-handling
Defer to user's truffle config / add coverage network
2 parents e2c9c90 + 1c49cc7 commit c2e687b

File tree

5 files changed

+107
-82
lines changed

5 files changed

+107
-82
lines changed

.circleci/config.yml

Lines changed: 25 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,17 @@
11
version: 2.0
2+
# Necessary for running in machine mode, which is necessary to execute the
3+
# Zeppelin and MetaCoin E2E scripts
4+
step_install_nvm: &step_install_nvm
5+
run:
6+
name: "Install nvm for machine"
7+
command: |
8+
set +e
9+
export NVM_DIR="/opt/circleci/.nvm"
10+
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
11+
nvm install v8.15.0
12+
nvm alias default v8.15.0
13+
echo 'export NVM_DIR="/opt/circleci/.nvm"' >> $BASH_ENV
14+
echo "[ -s \"$NVM_DIR/nvm.sh\" ] && . \"$NVM_DIR/nvm.sh\"" >> $BASH_ENV
215
jobs:
316
unit-test:
417
docker:
@@ -34,42 +47,25 @@ jobs:
3447
command: |
3548
./scripts/run-colony.sh
3649
37-
# It would be nice if all this could be a shell script... :/
3850
e2e-zeppelin:
39-
docker:
40-
- image: circleci/node:10.12-stretch
51+
machine: true
4152
steps:
4253
- checkout
43-
- run: >
44-
sudo rm -rf node_modules &&
45-
PR_PATH=$(echo "$CIRCLE_REPOSITORY_URL#$CIRCLE_BRANCH" | sudo sed 's/git@github.com:/https:\/\/github.com\//') &&
46-
sudo git clone https://github.com/OpenZeppelin/openzeppelin-solidity.git &&
47-
cd openzeppelin-solidity &&
48-
sudo sed -i 's/cat coverage\/lcov.info | npx coveralls/echo "No coveralls"/g' scripts/test.sh &&
49-
sudo sed -i 's/ganache-cli-coverage/testrpc-sc/g' scripts/test.sh &&
50-
sudo sed -i 's/--emitFreeLogs true/ /g' scripts/test.sh &&
51-
sudo yarn &&
52-
sudo yarn remove solidity-coverage --dev &&
53-
sudo yarn add "$PR_PATH" --dev &&
54-
sudo npm run coverage
54+
- <<: *step_install_nvm
55+
- run:
56+
name: Zeppelin E2E
57+
command: |
58+
./scripts/run-zeppelin.sh
5559
56-
# AND...this doesn't work either! Thanks to truffle "obtain" and circle permission denied.
5760
e2e-metacoin:
58-
docker:
59-
- image: circleci/node:10.12-stretch
61+
machine: true
6062
steps:
6163
- checkout
62-
- run: >
63-
sudo npm config set user 0 &&
64-
sudo npm config set unsafe-perm true &&
65-
sudo rm -rf node_modules &&
66-
PR_PATH=$(echo "$CIRCLE_REPOSITORY_URL#$CIRCLE_BRANCH" | sudo sed 's/git@github.com:/https:\/\/github.com\//') &&
67-
sudo mkdir metacoin &&
68-
cd metacoin &&
69-
sudo npx truffle unbox metacoin &&
70-
sudo rm test/TestMetacoin.sol &&
71-
sudo yarn add $PR_PATH --dev &&
72-
sudo npx solidity-coverage
64+
- <<: *step_install_nvm
65+
- run:
66+
name: MetaCoin E2E
67+
command: |
68+
./scripts/run-metacoin.sh
7369
workflows:
7470
version: 2
7571
build:

lib/app.js

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ const istanbul = require('istanbul');
88
const treeKill = require('tree-kill');
99
const getInstrumentedVersion = require('./instrumentSolidity.js');
1010
const CoverageMap = require('./coverageMap.js');
11-
const defaultTruffleConfig = require('./truffleConfig.js');
1211
const preprocessor = require('./preprocessor');
1312

1413
const isWin = /^win/.test(process.platform);
@@ -95,22 +94,35 @@ class App {
9594
}
9695

9796
// Load config
98-
let truffleConfig;
99-
let oldTrufflePath = `${this.workingDir}/truffle.js`;
97+
const coverageNetwork = {
98+
host: 'localhost',
99+
network_id: '*',
100+
port: this.port,
101+
gas: gasLimitHex,
102+
gasPrice: gasPriceHex
103+
};
104+
let truffleConfig = {
105+
networks: {
106+
coverage: coverageNetwork
107+
}
108+
};
100109
let newTrufflePath = `${this.workingDir}/truffle-config.js`;
110+
let oldTrufflePath = `${this.workingDir}/truffle.js`;
101111

102-
if (shell.test('-e', oldTrufflePath)) truffleConfig = reqCwd.silent(oldTrufflePath);
103-
else if (shell.test('-e', newTrufflePath)) truffleConfig = reqCwd.silent(newTrufflePath);
112+
if (shell.test('-e', newTrufflePath)) truffleConfig = reqCwd.silent(newTrufflePath);
113+
else if (shell.test('-e', oldTrufflePath)) truffleConfig = reqCwd.silent(oldTrufflePath);
114+
115+
this.network = '--network coverage';
104116

105117
// Coverage network opts specified: use port if declared
106-
if (truffleConfig && truffleConfig.networks && truffleConfig.networks.coverage) {
118+
if (truffleConfig.networks && truffleConfig.networks.coverage) {
107119
this.port = truffleConfig.networks.coverage.port || this.port;
108-
this.network = '--network coverage';
109-
110-
// No coverage network defaults to the dev network on port 8555, high gas / low price.
111120
} else {
112-
const trufflejs = defaultTruffleConfig(this.port, gasLimitHex, gasPriceHex);
113-
fs.writeFileSync(`${this.coverageDir}/truffle-config.js`, trufflejs);
121+
// Put the coverage network in the existing config
122+
if (!truffleConfig.networks) truffleConfig.networks = {};
123+
truffleConfig.networks.coverage = coverageNetwork;
124+
const configString = `module.exports = ${JSON.stringify(truffleConfig)}`;
125+
fs.writeFileSync(`${this.coverageDir}/truffle-config.js`, configString);
114126
}
115127

116128
// Compile the contracts before instrumentation and preserve their ABI's.

lib/truffleConfig.js

Lines changed: 0 additions & 14 deletions
This file was deleted.

scripts/run-metacoin.sh

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/usr/bin/env bash
2+
#
3+
# E2E CI: installs PR candidate on Truffle's MetaCoin and runs coverage
4+
#
5+
6+
# Get rid of any caches
7+
sudo rm -rf node_modules
8+
echo "NVM CURRENT >>>>>" && nvm current
9+
10+
# Use PR env variables (for forks) or fallback on local if PR not available
11+
SED_REGEX="s/git@github.com:/https:\/\/github.com\//"
12+
13+
if [[ -v CIRCLE_PR_REPONAME ]]; then
14+
PR_PATH="https://github.com/$CIRCLE_PR_USERNAME/$CIRCLE_PR_REPONAME#$CIRCLE_SHA1"
15+
else
16+
PR_PATH=$(echo "$CIRCLE_REPOSITORY_URL#$CIRCLE_SHA1" | sudo sed "$SED_REGEX")
17+
fi
18+
19+
echo "PR_PATH >>>>> $PR_PATH"
20+
21+
# Install truffle and metacoin box
22+
npm install -g truffle
23+
mkdir metacoin
24+
cd metacoin
25+
truffle unbox metacoin --force
26+
rm test/TestMetacoin.sol
27+
npm init --yes
28+
29+
# Install and run solidity-coverage @ PR
30+
npm install --save-dev $PR_PATH
31+
npx solidity-coverage

scripts/run-zeppelin.sh

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,40 +3,40 @@
33
# E2E CI: installs PR candidate on openzeppelin-solidity and runs coverage
44
#
55

6-
set -o errexit
7-
# Get path to PR branch
8-
PR_PATH=$(echo "$URL#$BRANCH" | sed 's/git@github.com:/https:\/\/github.com\//')
9-
echo "Installing $PR_PATH"
10-
11-
# Circle caches really agressively?
12-
sudo rm -rf node_modules
13-
sudo git clone https://github.com/OpenZeppelin/openzeppelin-solidity.git
14-
cd openzeppelin-solidity || exit
6+
# Get rid of any caches
157
sudo rm -rf node_modules
8+
echo "NVM CURRENT >>>>>" && nvm current
169

17-
# EDITS
18-
# Use testrpc-sc ...
19-
# sed -i 's/ganache-cli-coverage/testrpc-sc/g' scripts/test.sh
20-
# sed -i 's/--emitFreeLogs true/ /g' scripts/test.sh
10+
# Use PR env variables (for forks) or fallback on local if PR not available
11+
SED_REGEX="s/git@github.com:/https:\/\/github.com\//"
2112

22-
# Do not ping coveralls
23-
sed -i 's/cat coverage\/lcov.info | npx coveralls/echo "No coveralls"/g' scripts/test.sh
13+
if [[ -v CIRCLE_PR_REPONAME ]]; then
14+
PR_PATH="https://github.com/$CIRCLE_PR_USERNAME/$CIRCLE_PR_REPONAME#$CIRCLE_SHA1"
15+
else
16+
PR_PATH=$(echo "$CIRCLE_REPOSITORY_URL#$CIRCLE_SHA1" | sudo sed "$SED_REGEX")
17+
fi
2418

25-
# Doesn't install inside docker (thanks Circle!)
26-
echo "Uninstalling solidity-docgen"
27-
sudo npm uninstall --save-dev solidity-docgen
19+
echo "PR_PATH >>>>> $PR_PATH"
2820

29-
# Swap installed coverage for PR branch version
30-
echo "Running: npm install"
31-
sudo npm install
21+
# Install Zeppelin
22+
git clone https://github.com/OpenZeppelin/openzeppelin-solidity.git
23+
cd openzeppelin-solidity
3224

33-
echo "Running npm uninstall solidity-coverage"
34-
sudo npm uninstall --save-dev solidity-coverage
25+
# Update Zeppelin's script to use 0.6.x
26+
sed -i 's/if/# /g' scripts/coverage.sh
27+
sed -i 's/curl/# /g' scripts/coverage.sh
28+
sed -i 's/fi/# /g' scripts/coverage.sh
29+
sed -i 's/ganache-cli-coverage/testrpc-sc/g' scripts/test.sh
30+
sed -i 's/--emitFreeLogs true/ /g' scripts/test.sh
31+
32+
# Swap installed coverage for PR branch version
33+
echo ">>>>> npm install"
34+
npm install
3535

36-
echo "Running npm install PR_PATH"
37-
sudo npm install --save-dev "$PR_PATH"
36+
echo ">>>>> npm uninstall --save-dev solidity-coverage"
37+
npm uninstall --save-dev solidity-coverage
3838

39-
sudo npm run coverage
39+
echo ">>>>> npm install --save-dev PR_PATH"
40+
npm install --save-dev "$PR_PATH"
4041

41-
# Trick to 'allowFailure' on CIRCLE
42-
set -o errexit
42+
npm run coverage

0 commit comments

Comments
 (0)