Skip to content

Commit

Permalink
Truffle config handling (#366)
Browse files Browse the repository at this point in the history
* add new truffle config handling

* use ifs

* nework typo lol

* remove stray config edits

* remove truffleConfig.js, improve default config handling

* readability

* remove legacy truffle config file, don't rely on truffle's fallback strategy

* add semicolon

* eh, no need to explicitly remove this

* fix notes, simplify logic

* debug e2e

* print pr path

* update pr_path

* use commit sha1

* update pr path in other e2e, remove log

* Adapt PR_PATH for cached builds

* Debug CI
  • Loading branch information
vreturn authored and cgewecke committed Aug 6, 2019
1 parent e2c9c90 commit f28e0b8
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 28 deletions.
6 changes: 4 additions & 2 deletions .circleci/config.yml
Expand Up @@ -42,7 +42,8 @@ jobs:
- checkout
- run: >
sudo rm -rf node_modules &&
PR_PATH=$(echo "$CIRCLE_REPOSITORY_URL#$CIRCLE_BRANCH" | sudo sed 's/git@github.com:/https:\/\/github.com\//') &&
PR_PATH=$(echo "$CIRCLE_REPOSITORY_URL#$CIRCLE_SHA1" | sudo sed 's/git@github.com:/https:\/\/github.com\//') &&
echo "PR_PATH >>>>> $PR_PATH" &&
sudo git clone https://github.com/OpenZeppelin/openzeppelin-solidity.git &&
cd openzeppelin-solidity &&
sudo sed -i 's/cat coverage\/lcov.info | npx coveralls/echo "No coveralls"/g' scripts/test.sh &&
Expand All @@ -63,7 +64,8 @@ jobs:
sudo npm config set user 0 &&
sudo npm config set unsafe-perm true &&
sudo rm -rf node_modules &&
PR_PATH=$(echo "$CIRCLE_REPOSITORY_URL#$CIRCLE_BRANCH" | sudo sed 's/git@github.com:/https:\/\/github.com\//') &&
PR_PATH=$(echo "$CIRCLE_REPOSITORY_URL#$CIRCLE_SHA1" | sudo sed 's/git@github.com:/https:\/\/github.com\//') &&
echo "PR_PATH >>>>> $PR_PATH" &&
sudo mkdir metacoin &&
cd metacoin &&
sudo npx truffle unbox metacoin &&
Expand Down
34 changes: 23 additions & 11 deletions lib/app.js
Expand Up @@ -8,7 +8,6 @@ const istanbul = require('istanbul');
const treeKill = require('tree-kill');
const getInstrumentedVersion = require('./instrumentSolidity.js');
const CoverageMap = require('./coverageMap.js');
const defaultTruffleConfig = require('./truffleConfig.js');
const preprocessor = require('./preprocessor');

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

// Load config
let truffleConfig;
let oldTrufflePath = `${this.workingDir}/truffle.js`;
const coverageNetwork = {
host: 'localhost',
network_id: '*',
port: this.port,
gas: gasLimitHex,
gasPrice: gasPriceHex
};
let truffleConfig = {
networks: {
coverage: coverageNetwork
}
};
let newTrufflePath = `${this.workingDir}/truffle-config.js`;
let oldTrufflePath = `${this.workingDir}/truffle.js`;

if (shell.test('-e', oldTrufflePath)) truffleConfig = reqCwd.silent(oldTrufflePath);
else if (shell.test('-e', newTrufflePath)) truffleConfig = reqCwd.silent(newTrufflePath);
if (shell.test('-e', newTrufflePath)) truffleConfig = reqCwd.silent(newTrufflePath);
else if (shell.test('-e', oldTrufflePath)) truffleConfig = reqCwd.silent(oldTrufflePath);

this.network = '--network coverage';

// Coverage network opts specified: use port if declared
if (truffleConfig && truffleConfig.networks && truffleConfig.networks.coverage) {
if (truffleConfig.networks && truffleConfig.networks.coverage) {
this.port = truffleConfig.networks.coverage.port || this.port;
this.network = '--network coverage';

// No coverage network defaults to the dev network on port 8555, high gas / low price.
} else {
const trufflejs = defaultTruffleConfig(this.port, gasLimitHex, gasPriceHex);
fs.writeFileSync(`${this.coverageDir}/truffle-config.js`, trufflejs);
// Put the coverage network in the existing config
if (!truffleConfig.networks) truffleConfig.networks = {};
truffleConfig.networks.coverage = coverageNetwork;
const configString = `module.exports = ${JSON.stringify(truffleConfig)}`;
fs.writeFileSync(`${this.coverageDir}/truffle-config.js`, configString);
}

// Compile the contracts before instrumentation and preserve their ABI's.
Expand Down
14 changes: 0 additions & 14 deletions lib/truffleConfig.js

This file was deleted.

2 changes: 1 addition & 1 deletion scripts/run-zeppelin.sh
Expand Up @@ -39,4 +39,4 @@ sudo npm install --save-dev "$PR_PATH"
sudo npm run coverage

# Trick to 'allowFailure' on CIRCLE
set -o errexit
set -o errexit

0 comments on commit f28e0b8

Please sign in to comment.