Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ step_install_nvm: &step_install_nvm
set +e
export NVM_DIR="/opt/circleci/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
nvm install v8.15.0
nvm alias default v8.15.0
nvm install v10.15.3
nvm alias default v10.15.3
echo 'export NVM_DIR="/opt/circleci/.nvm"' >> $BASH_ENV
echo "[ -s \"$NVM_DIR/nvm.sh\" ] && . \"$NVM_DIR/nvm.sh\"" >> $BASH_ENV
jobs:
Expand Down
28 changes: 20 additions & 8 deletions dist/truffle.plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const Web3 = require('web3');
const util = require('util');
const globby = require('globby');
const globalModules = require('global-modules');
const TruffleProvider = require('@truffle/provider');

async function plugin(truffleConfig){
let app;
Expand Down Expand Up @@ -71,8 +72,10 @@ async function plugin(truffleConfig){
death(app.cleanUp); // This doesn't work...

// Launch in-process provider
const provider = await app.provider(truffle.ganache);
const web3 = new Web3(provider);
//const provider = await app.provider(truffle.ganache);
//const web3 = new Web3(provider);
await app.provider(truffle.ganache);
const web3 = new Web3('http://localhost:8777');
const accounts = await web3.eth.getAccounts();
const nodeInfo = await web3.eth.getNodeInfo();
const ganacheVersion = nodeInfo.split('/')[1];
Expand All @@ -82,7 +85,10 @@ async function plugin(truffleConfig){
app.ui.report('coverage-version',[pkg.version]);

// Bail early if user ran: --version
if (truffleConfig.version) return;
if (truffleConfig.version){
await app.cleanUp();
return;
};

// Write instrumented sources to temp folder
app.instrument();
Expand All @@ -104,16 +110,22 @@ async function plugin(truffleConfig){
const networkName = 'soliditycoverage';
truffleConfig.network = networkName;

// Truffle alternately complains that fields are and
// are not manually set
// Truffle alternately complains that fields *are*
// and *are not* manually set depending on the execution
// context (npm installed vs. our tests': await plugin())
try {
truffleConfig.network_id = "*";
truffleConfig.provider = provider;
} catch (err){}
truffleConfig.port = 8777;
truffleConfig.host = "127.0.0.1";
truffleConfig.provider = TruffleProvider.create(truffleConfig);
} catch (err){
console.log('errored on initial setting of truffleConfig.provider...')
}

truffleConfig.networks[networkName] = {
network_id: "*",
provider: provider,
host: "127.0.0.1",
port: 8777,
gas: app.gasLimit,
gasPrice: app.gasPrice,
from: accounts[0]
Expand Down
13 changes: 10 additions & 3 deletions lib/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const path = require('path');
const istanbul = require('istanbul');
const util = require('util');
const assert = require('assert');
const pify = require('pify');

const Instrumenter = require('./instrumenter');
const Coverage = require('./coverage');
Expand Down Expand Up @@ -33,7 +34,9 @@ class App {
this.originalContractsDir = config.originalContractsDir

this.client = config.client;
this.server = null;
this.providerOptions = config.providerOptions || {};
this.defaultPort = 8777;

this.skippedFolders = [];
this.skipFiles = config.skipFiles || [];
Expand Down Expand Up @@ -129,6 +132,7 @@ class App {
try {
this.provider = await this.attachToVM();
} catch(err){
console.log('err --> ' + err);
retry = true;
this.ui.report('vm-fail', [])
}
Expand Down Expand Up @@ -187,8 +191,8 @@ class App {
shell.rm('-Rf', this.artifactsDir);

if (this.provider && this.provider.close){
this.log('Shutting down ganache-core')
return new Promise(res => self.provider.close(res))
this.log('Shutting down ganache-core.server')
await pify(self.server.close)();
}
}
// ------------------------------------------ Utils ----------------------------------------------
Expand All @@ -198,7 +202,9 @@ class App {
// ========
async attachToVM(){
const self = this;
const provider = this.client.provider(this.providerOptions);
const port = this.providerOptions.port || this.defaultPort;
this.server = this.client.server(this.providerOptions);
const provider = this.server.provider;

this.assertHasBlockchain(provider);

Expand All @@ -218,6 +224,7 @@ class App {
return vm;
}

await pify(this.server.listen)(port);
return provider;
}

Expand Down
23 changes: 13 additions & 10 deletions lib/collector.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,24 @@ const web3Utils = require('web3-utils')
class DataCollector {
constructor(instrumentationData={}){
this.instrumentationData = instrumentationData;

this.validOpcodes = {
"PUSH1": true,
}
}

step(info){
const self = this;
if (typeof info !== 'object' || !info.opcode ) return;
try {
if (this.validOpcodes[info.opcode.name] && info.stack.length > 0){
const idx = info.stack.length - 1;
let hash = web3Utils.toHex(info.stack[idx]).toString();
hash = this._normalizeHash(hash);

if (info.opcode.name.includes("PUSH1") && info.stack.length > 0){
const idx = info.stack.length - 1;
let hash = web3Utils.toHex(info.stack[idx]).toString();
hash = self._normalizeHash(hash);

if(self.instrumentationData[hash]){
self.instrumentationData[hash].hits++;
if(this.instrumentationData[hash]){
this.instrumentationData[hash].hits++;
}
}
}
} catch (err) { /*Ignore*/ };
}

_setInstrumentationData(data){
Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,17 @@
"author": "",
"license": "ISC",
"dependencies": {
"@truffle/provider": "^0.1.17",
"chalk": "^2.4.2",
"death": "^1.1.0",
"ganache-core-sc": "2.7.0-sc.0",
"global-modules": "^2.0.0",
"globby": "^10.0.1",
"istanbul": "^0.4.5",
"memdown": "^5.0.0",
"node-dir": "^0.1.17",
"node-emoji": "^1.10.0",
"pify": "^4.0.1",
"req-cwd": "^1.0.1",
"shelljs": "^0.8.3",
"solidity-parser-antlr": "^0.4.7",
Expand Down
14 changes: 8 additions & 6 deletions scripts/run-zeppelin.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ fi

echo "PR_PATH >>>>> $PR_PATH"

npm install -g yarn;

# Install sc-forks Zeppelin fork (temporarily). It's setup to
# consume the plugin and skips a small set of GSN tests that rely on
# the client being stand-alone. (See OZ issue #1918 for discussion)
Expand All @@ -30,14 +32,14 @@ echo ">>>>> checkout provider-benchmarks branch"
git checkout provider-benchmarks

# Swap installed coverage for PR branch version
echo ">>>>> npm install"
npm install
echo ">>>>> yarn install"
yarn install

echo ">>>>> npm uninstall --save-dev solidity-coverage"
npm uninstall --save-dev solidity-coverage
echo ">>>>> yarn remove --dev solidity-coverage"
yarn remove solidity-coverage --dev

echo ">>>>> npm install --save-dev PR_PATH"
npm install --save-dev "$PR_PATH"
echo ">>>>> yarn add -dev $PR_PATH"
yarn add "$PR_PATH" --dev

# Track perf
time npx truffle run coverage
Loading