Skip to content

Instantly share code, notes, and snippets.

@Perseverance
Last active November 8, 2018 14:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Perseverance/6666e8d9509b98a20dc0860fb3b1ef4d to your computer and use it in GitHub Desktop.
Save Perseverance/6666e8d9509b98a20dc0860fb3b1ef4d to your computer and use it in GitHub Desktop.
const mocha = require('mocha');
const Base = mocha.reporters.Base;
const ethers = require('ethers');
const shell = require('shelljs');
const parser = require('solidity-parser-antlr');
const fs = require('fs');
// const stats = require('./gasStats.js');
function EtherlimeReporterCreator(port) {
const EtherlimeReporter = (runner) => {
const localNodeUrl = `http://localhost:${port}/`;
let localNodeProvider;
Base.call(this, runner);
// Start getting this data when the reporter loads.
// stats.getGasAndPriceRates(config);
// mocha.reporters.Base.call(this, runner);
let passes = 0;
let failures = 0;
runner.on('start', async () => {
console.log('Starteedddd');
localNodeProvider = new ethers.providers.JsonRpcProvider(localNodeUrl);
});
runner.on('pass', async (test) => {
passes++;
// const blockNumber = await localNodeProvider.getBlockNumber();
//
// console.log('Block matafaka');
// console.log(blockNumber);
const contractsPath = `${process.cwd()}/contracts`;
const files = shell.ls(`${contractsPath}/*.sol`);
files.forEach(file => {
let names = getContractNames(file);
console.log(names);
// For each contract in file
names.forEach(name => {
// Create Deploy Map:
let contract;
try {
contract = artifacts.require(name);
console.log(contract);
// console.log(contract, 'Contract mata');
} catch (error) {
console.log(error);
}
});
});
console.log('pass: %s', test.fullTitle());
});
runner.on('fail', function (test, err) {
failures++;
console.log('fail: %s -- error: %s', test.fullTitle(), err.message);
});
runner.on('end', function () {
console.log('end: %d/%d', passes, passes + failures);
});
function getContractNames(filePath) {
const names = [];
const code = fs.readFileSync(filePath, 'utf-8');
const ast = parser.parse(code, { tolerant: true });
console.log(ast);
parser.visit(ast, {
ContractDefinition: function (node) {
console.log('Node');
console.log(node);
names.push(node.name);
}
});
return names;
}
}
return EtherlimeReporter;
}
module.exports = EtherlimeReporterCreator;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment