eth-gas-reporter
Advanced tools
Comparing version 0.1.4 to 0.1.5
## Changelog: eth-gas-reporter | ||
0.1.3 / 2018-05-14 | ||
0.1.4 / 2018-05-14 | ||
================== | ||
@@ -4,0 +4,0 @@ * Try to work around web3 websocket provider by attempting connection over http://. |
@@ -8,2 +8,3 @@ /** | ||
const path = require('path') | ||
const fs = require('fs') | ||
const request = require('request-promise-native') | ||
@@ -14,3 +15,3 @@ const shell = require('shelljs') | ||
const abiDecoder = require('abi-decoder') | ||
const fs = require('fs'); | ||
const parser = require('solidity-parser-antlr'); | ||
const sync = require('./sync'); | ||
@@ -295,2 +296,21 @@ | ||
/** | ||
* Parses files for contract names | ||
* @param {String} filePath path to file | ||
* @return {Array} array of contract names | ||
*/ | ||
function getContractNames(filePath){ | ||
const names = []; | ||
const code = fs.readFileSync(filePath, 'utf-8'); | ||
const ast = parser.parse(code, {tolerant: true}); | ||
parser.visit(ast, { | ||
ContractDefinition: function(node) { | ||
names.push(node.name); | ||
} | ||
}); | ||
return names; | ||
} | ||
/** | ||
* Generates a complete mapping of method data ids to their contract and method names. | ||
@@ -329,42 +349,47 @@ * Map also initialised w/ an empty `gasData` array that the gas value of each matched transaction | ||
const names = shell.ls('./contracts/**/*.sol') | ||
names.forEach(name => { | ||
name = path.basename(name) | ||
const files = shell.ls('./contracts/**/*.sol') | ||
if (name === 'Migrations.sol') return | ||
// For each file | ||
files.forEach(file => { | ||
names = getContractNames(file); | ||
// Create Deploy Map: | ||
let contract | ||
try { contract = truffleArtifacts.require(name) } catch (error) { return } | ||
// For each contract in file | ||
names.forEach(name => { | ||
if (name === 'Migrations') return | ||
const contractInfo = { | ||
name: name.split('.sol')[0], | ||
binary: contract.unlinked_binary, | ||
gasData: [] | ||
} | ||
deployMap.push(contractInfo) | ||
abis.push(contract._json.abi) | ||
// Create Deploy Map: | ||
let contract | ||
try { contract = truffleArtifacts.require(name) } catch (error) { return } | ||
// Decode, getMethodIDs | ||
abiDecoder.addABI(contract._json.abi) | ||
const methodIDs = abiDecoder.getMethodIDs() | ||
const contractInfo = { | ||
name: name, | ||
binary: contract.unlinked_binary, | ||
gasData: [] | ||
} | ||
deployMap.push(contractInfo) | ||
abis.push(contract._json.abi) | ||
// Create Method Map; | ||
Object.keys(methodIDs).forEach(key => { | ||
const isInterface = contract.unlinked_binary === '0x'; | ||
const isConstant = methodIDs[key].constant | ||
const isEvent = methodIDs[key].type === 'event' | ||
const hasName = methodIDs[key].name | ||
// Decode, getMethodIDs | ||
abiDecoder.addABI(contract._json.abi) | ||
const methodIDs = abiDecoder.getMethodIDs() | ||
if (hasName && !isConstant && !isEvent && !isInterface) { | ||
methodMap[key] = { | ||
contract: name.split('.sol')[0], | ||
method: methodIDs[key].name, | ||
gasData: [], | ||
numberOfCalls: 0 | ||
// Create Method Map; | ||
Object.keys(methodIDs).forEach(key => { | ||
const isInterface = contract.unlinked_binary === '0x'; | ||
const isConstant = methodIDs[key].constant | ||
const isEvent = methodIDs[key].type === 'event' | ||
const hasName = methodIDs[key].name | ||
if (hasName && !isConstant && !isEvent && !isInterface) { | ||
methodMap[key] = { | ||
contract: name, | ||
method: methodIDs[key].name, | ||
gasData: [], | ||
numberOfCalls: 0 | ||
} | ||
} | ||
} | ||
}) | ||
abiDecoder.removeABI(contract._json.abi) | ||
}) | ||
abiDecoder.removeABI(contract._json.abi) | ||
}) | ||
}); | ||
@@ -371,0 +396,0 @@ abis.forEach(abi => abiDecoder.addABI(abi)) |
{ | ||
"name": "eth-gas-reporter", | ||
"version": "0.1.3", | ||
"version": "0.1.4", | ||
"description": "Mocha reporter which shows gas used per unit test.", | ||
@@ -37,2 +37,3 @@ "main": "index.js", | ||
"shelljs": "^0.7.8", | ||
"solidity-parser-antlr": "^0.2.10", | ||
"sync-request": "^6.0.0" | ||
@@ -39,0 +40,0 @@ }, |
{ | ||
"name": "eth-gas-reporter", | ||
"version": "0.1.4", | ||
"version": "0.1.5", | ||
"description": "Mocha reporter which shows gas used per unit test.", | ||
@@ -37,2 +37,3 @@ "main": "index.js", | ||
"shelljs": "^0.7.8", | ||
"solidity-parser-antlr": "^0.2.10", | ||
"sync-request": "^6.0.0" | ||
@@ -39,0 +40,0 @@ }, |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
40805
31
753
11
+ Addedsolidity-parser-antlr@0.2.15(transitive)