eth-gas-reporter
Advanced tools
Comparing version 0.2.6 to 0.2.7
## Changelog: eth-gas-reporter | ||
0.2.6 / 2019-07-16 | ||
- Stopped using npm-shrinkwrap, because it seemed to correlate w/ weird installation problems | ||
- Fix bug which caused outputFile option to crash due to misnamed variable | ||
# 0.2.5 / 2019-07-15 | ||
@@ -4,0 +9,0 @@ |
@@ -15,3 +15,3 @@ const { join } = require("path"); | ||
*/ | ||
module.exports.default = async function gasReporter() { | ||
module.exports.default = async function gasReporter(options = {}) { | ||
let output; | ||
@@ -34,2 +34,7 @@ let file = "gasReporterOutput.json"; | ||
// Lets monorepo subcomponents individuate themselves | ||
output.namespace = options.name | ||
? `${output.namespace}:${options.name}` | ||
: output.namespace; | ||
// Save new data on the merge commit / push build | ||
@@ -36,0 +41,0 @@ if (!codechecks.isPr()) { |
@@ -53,2 +53,5 @@ const SyncRequest = require("./syncRequest"); | ||
_truffleArtifactor(contractName) { | ||
let deployed; | ||
let metadata; | ||
const artifact = artifacts.require(contractName); | ||
@@ -62,3 +65,9 @@ | ||
const deployed = artifact.networks[this.networkId]; | ||
// These fields are not defined for all conditions | ||
// or truffle versions. Catching because truffle | ||
// is sometimes weird re: artifact access. | ||
try { | ||
deployed = artifact.networks[this.networkId]; | ||
metadata = artifact.metadata; | ||
} catch (err) {} | ||
@@ -73,3 +82,6 @@ // Migrations deployed data | ||
this.config.metadata = JSON.parse(artifact.metadata); | ||
if (metadata) { | ||
this.config.metadata = JSON.parse(metadata); | ||
} | ||
return contract; | ||
@@ -76,0 +88,0 @@ } |
@@ -24,2 +24,3 @@ const _ = require("lodash"); | ||
const pad = " "; | ||
const addedContracts = []; | ||
@@ -51,19 +52,45 @@ // --------------------------------------------------------------------------------------------- | ||
stats.diff = this.getMethodDiff(methodId, stats.average); | ||
stats.percentDiff = this.getMethodPercentageDiff(methodId, stats.average); | ||
highlighting = this.getHighlighting(stats.diff); | ||
if (data.numberOfCalls > 0) { | ||
const section = []; | ||
section.push({ | ||
// Contracts name row | ||
if (!addedContracts.includes(data.contract)) { | ||
addedContracts.push(data.contract); | ||
const titleSection = []; | ||
titleSection.push({ | ||
hAlign: "left", | ||
colSpan: 2, | ||
content: `${pad}> ${data.contract}`, | ||
contractName: data.contract, | ||
methodName: "0" | ||
}); | ||
titleSection.push({ colSpan: 5, content: "" }); | ||
methodRows.push(titleSection); | ||
} | ||
// Method row | ||
const methodSection = []; | ||
methodSection.push({ | ||
hAlign: "left", | ||
colSpan: 2, | ||
content: `${highlighting}${data.contract}` | ||
content: `${highlighting}${pad}${pad}${data.method}`, | ||
contractName: data.contract, | ||
methodName: data.method | ||
}); | ||
section.push(`${pad}${data.method}`); | ||
section.push({ hAlign: "right", content: `${pad}${stats.average}` }); | ||
section.push({ hAlign: "right", content: stats.diff }); | ||
section.push({ | ||
methodSection.push({ | ||
hAlign: "right", | ||
content: `${pad}${stats.average}` | ||
}); | ||
methodSection.push({ hAlign: "right", content: stats.diff }); | ||
methodSection.push({ hAlign: "right", content: stats.percentDiff }); | ||
methodSection.push({ | ||
hAlign: "right", | ||
content: data.numberOfCalls.toString() | ||
}); | ||
section.push({ | ||
methodSection.push({ | ||
hAlign: "right", | ||
@@ -73,3 +100,3 @@ content: stats.cost.toString() | ||
methodRows.push(section); | ||
methodRows.push(methodSection); | ||
this.newData.methods[methodId] = stats.average; | ||
@@ -93,6 +120,3 @@ } | ||
stats.average = Math.round(total / contract.gasData.length); | ||
stats.percent = utils.gasToPercentOfLimit( | ||
stats.average, | ||
this.config.blockLimit | ||
); | ||
stats.percent = utils.gasToPercentOfLimit(stats.average, info.blockLimit); | ||
@@ -109,2 +133,6 @@ stats.cost = | ||
stats.diff = this.getDeploymentDiff(contract.name, stats.average); | ||
stats.percentDiff = this.getDeploymentPercentageDiff( | ||
contract.name, | ||
stats.average | ||
); | ||
highlighting = this.getHighlighting(stats.diff); | ||
@@ -115,3 +143,3 @@ | ||
hAlign: "left", | ||
colSpan: 3, | ||
colSpan: 2, | ||
content: `${highlighting}${contract.name}` | ||
@@ -121,2 +149,4 @@ }); | ||
section.push({ hAlign: "right", content: stats.diff }); | ||
section.push({ hAlign: "right", content: stats.percentDiff }); | ||
section.push({ | ||
@@ -172,12 +202,7 @@ hAlign: "right", | ||
hAlign: "center", | ||
colSpan: 2, | ||
content: `Optimized: ${solc.optimizer}` | ||
colSpan: 3, | ||
content: ` Optimized: ${solc.optimizer} / ${pad}Runs: ${solc.runs}` | ||
}, | ||
{ | ||
hAlign: "center", | ||
colSpan: 1, | ||
content: `${pad}Runs: ${solc.runs}` | ||
}, | ||
{ | ||
hAlign: "center", | ||
colSpan: 2, | ||
@@ -212,9 +237,9 @@ content: `Block: ${info.blockLimit} gas` | ||
const header = [ | ||
`${pad}Contract`, | ||
"", | ||
`${pad}Method`, | ||
{}, | ||
{}, | ||
{ hAlign: "center", content: `${pad}Gas` }, | ||
{ hAlign: "center", content: `${pad}Diff` }, | ||
`${pad}# calls`, | ||
`${pad}${this.config.currency.toLowerCase()} (avg)` | ||
{ hAlign: "center", content: `${pad}% Diff` }, | ||
`${pad}calls`, | ||
`${pad}${this.config.currency.toLowerCase()} cost` | ||
]; | ||
@@ -231,7 +256,4 @@ | ||
// Ignore diff markers | ||
const contractA = a[0].content.substring(2); | ||
const contractB = b[0].content.substring(2); | ||
const contractName = contractA.localeCompare(contractB); | ||
const methodName = a[1].localeCompare(b[1]); | ||
const contractName = a[0].contractName.localeCompare(b[0].contractName); | ||
const methodName = a[0].methodName.localeCompare(b[0].methodName); | ||
return contractName || methodName; | ||
@@ -250,3 +272,3 @@ }); | ||
{ hAlign: "right", colSpan: 3, content: "" }, | ||
{ hAlign: "left", colSpan: 1, content: `${pad}% of limit` } | ||
{ hAlign: "left", colSpan: 1, content: `${pad}% block` } | ||
]; | ||
@@ -273,5 +295,13 @@ table.push(deploymentsSubtitle); | ||
} | ||
return "n/a"; | ||
return "-"; | ||
} | ||
getPercentageDiff(previousVal, currentVal) { | ||
if (typeof previousVal === "number") { | ||
const diff = currentVal - previousVal; | ||
return `${Math.round((diff / previousVal) * 100)}%`; | ||
} | ||
return "-"; | ||
} | ||
getMethodDiff(id, currentVal) { | ||
@@ -281,2 +311,6 @@ return this.getDiff(this.previousData.methods[id], currentVal); | ||
getMethodPercentageDiff(id, currentVal) { | ||
return this.getPercentageDiff(this.previousData.methods[id], currentVal); | ||
} | ||
getDeploymentDiff(id, currentVal) { | ||
@@ -286,2 +320,9 @@ return this.getDiff(this.previousData.deployments[id], currentVal); | ||
getDeploymentPercentageDiff(id, currentVal) { | ||
return this.getPercentageDiff( | ||
this.previousData.deployments[id], | ||
currentVal | ||
); | ||
} | ||
getHighlighting(val) { | ||
@@ -288,0 +329,0 @@ if (val > 0) return "- "; // Current use greater: red |
@@ -6,2 +6,3 @@ const colors = require("colors/safe"); | ||
const utils = require("./utils"); | ||
const CodeChecksReport = require("./codechecksReport"); | ||
@@ -88,6 +89,3 @@ class GasTable { | ||
stats.average = Math.round(total / contract.gasData.length); | ||
stats.percent = utils.gasToPercentOfLimit( | ||
stats.average, | ||
this.config.blockLimit | ||
); | ||
stats.percent = utils.gasToPercentOfLimit(stats.average, info.blockLimit); | ||
@@ -266,2 +264,8 @@ stats.cost = | ||
this.saveCodeChecksData(info); | ||
// For integration tests | ||
if (process.env.DEBUG_CODECHECKS_TABLE) { | ||
const report = new CodeChecksReport(this.config); | ||
console.log(report.generate(info)); | ||
} | ||
} | ||
@@ -268,0 +272,0 @@ |
{ | ||
"name": "eth-gas-reporter", | ||
"version": "0.2.3", | ||
"version": "0.2.6", | ||
"description": "Mocha reporter which shows gas used per unit test.", | ||
@@ -42,3 +42,3 @@ "main": "index.js", | ||
"fs-readdir-recursive": "^1.1.0", | ||
"lodash": "^4.17.11", | ||
"lodash": "^4.17.14", | ||
"mocha": "^5.2.0", | ||
@@ -53,2 +53,3 @@ "req-cwd": "^2.0.0", | ||
"devDependencies": { | ||
"@codechecks/client": "^0.1.5", | ||
"@nomiclabs/buidler": "^1.0.0-beta.7", | ||
@@ -63,2 +64,3 @@ "@nomiclabs/buidler-truffle5": "^1.0.0-beta.7", | ||
"pretty-quick": "^1.11.0", | ||
"randomstring": "^1.1.5", | ||
"truffle": "5.0.12", | ||
@@ -65,0 +67,0 @@ "web3": "1.0.0-beta.37", |
@@ -1,17 +0,23 @@ | ||
const VariableConstructor = artifacts.require('./VariableConstructor.sol') | ||
const random = require("./random"); | ||
const VariableConstructor = artifacts.require("./VariableConstructor.sol"); | ||
contract('VariableConstructor', accounts => { | ||
it('should should initialize with a short string', async () => { | ||
await VariableConstructor.new('Exit Visa') | ||
}) | ||
contract("VariableConstructor", accounts => { | ||
it("should should initialize with a short string", async () => { | ||
await VariableConstructor.new("Exit Visa"); | ||
}); | ||
it('should should initialize with a medium length string', async () => { | ||
await VariableConstructor.new('Enclosed is my application for residency') | ||
}) | ||
it("should should initialize with a medium length string", async () => { | ||
await VariableConstructor.new("Enclosed is my application for residency"); | ||
}); | ||
it('should should initialize with a long string', async () => { | ||
let msg = 'Enclosed is my application for permanent residency in NewZealand.' | ||
msg += 'I am a computer programmer.' | ||
await VariableConstructor.new(msg) | ||
}) | ||
}) | ||
it("should should initialize with a long string", async () => { | ||
let msg = | ||
"Enclosed is my application for permanent residency in NewZealand."; | ||
msg += "I am a computer programmer."; | ||
await VariableConstructor.new(msg); | ||
}); | ||
it("should should initialize with a random length string", async () => { | ||
await VariableConstructor.new(random()); | ||
}); | ||
}); |
@@ -1,60 +0,69 @@ | ||
const VariableCosts = artifacts.require('./VariableCosts.sol') | ||
const Wallet = artifacts.require('./Wallet.sol') | ||
const random = require("./random"); | ||
const VariableCosts = artifacts.require("./VariableCosts.sol"); | ||
const Wallet = artifacts.require("./Wallet.sol"); | ||
contract('VariableCosts', accounts => { | ||
const one = [1] | ||
const three = [2, 3, 4] | ||
const five = [5, 6, 7, 8, 9] | ||
let instance | ||
let walletB | ||
contract("VariableCosts", accounts => { | ||
const one = [1]; | ||
const three = [2, 3, 4]; | ||
const five = [5, 6, 7, 8, 9]; | ||
let instance; | ||
let walletB; | ||
beforeEach(async () => { | ||
instance = await VariableCosts.new() | ||
instance = await VariableCosts.new(); | ||
walletB = await Wallet.new(); | ||
}) | ||
}); | ||
it('should add one', async () => { | ||
await instance.addToMap(one) | ||
}) | ||
it("should add one", async () => { | ||
await instance.addToMap(one); | ||
}); | ||
it('should add three', async () => { | ||
await instance.addToMap(three) | ||
}) | ||
it("should add three", async () => { | ||
await instance.addToMap(three); | ||
}); | ||
it('should add even 5!', async () => { | ||
await instance.addToMap(five) | ||
}) | ||
it("should add even 5!", async () => { | ||
await instance.addToMap(five); | ||
}); | ||
it('should delete one', async() => { | ||
await instance.removeFromMap(one) | ||
}) | ||
it("should delete one", async () => { | ||
await instance.removeFromMap(one); | ||
}); | ||
it('should delete three', async() => { | ||
await instance.removeFromMap(three) | ||
}) | ||
it("should delete three", async () => { | ||
await instance.removeFromMap(three); | ||
}); | ||
it('should delete five', async() => { | ||
await instance.removeFromMap(five) | ||
}) | ||
it("should delete five", async () => { | ||
await instance.removeFromMap(five); | ||
}); | ||
it('should add five and delete one', async() => { | ||
await instance.addToMap(five) | ||
await instance.removeFromMap(one) | ||
}) | ||
it("should add five and delete one", async () => { | ||
await instance.addToMap(five); | ||
await instance.removeFromMap(one); | ||
}); | ||
it('methods that do not throw', async() => { | ||
await instance.methodThatThrows(false) | ||
}) | ||
it("should set a random length string", async () => { | ||
await instance.setString(random()); | ||
await instance.setString(random()); | ||
await instance.setString(random()); | ||
}); | ||
it('methods that throw', async() => { | ||
try { await instance.methodThatThrows(true) } catch (e) {} | ||
}) | ||
it("methods that do not throw", async () => { | ||
await instance.methodThatThrows(false); | ||
}); | ||
it('methods that call methods in other contracts', async() => { | ||
it("methods that throw", async () => { | ||
try { | ||
await instance.methodThatThrows(true); | ||
} catch (e) {} | ||
}); | ||
it("methods that call methods in other contracts", async () => { | ||
await instance.otherContractMethod(); | ||
}) | ||
}); | ||
it('prints a table at end of test suites with failures', async() => { | ||
it("prints a table at end of test suites with failures", async () => { | ||
assert(false); | ||
}) | ||
}); | ||
@@ -64,15 +73,16 @@ // VariableCosts is Wallet. We also have Wallet tests. So we should see | ||
// and Wallet in the report | ||
it('should allow contracts to have identically named methods', async () => { | ||
it("should allow contracts to have identically named methods", async () => { | ||
await instance.sendTransaction({ | ||
value: 100, from: accounts[0] | ||
}) | ||
value: 100, | ||
from: accounts[0] | ||
}); | ||
await instance.sendPayment(50, walletB.address, { | ||
from: accounts[0] | ||
}) | ||
}); | ||
await instance.transferPayment(50, walletB.address, { | ||
from: accounts[0] | ||
}) | ||
const balance = await walletB.getBalance() | ||
assert.equal(parseInt(balance.toString()), 100) | ||
}) | ||
}) | ||
}); | ||
const balance = await walletB.getBalance(); | ||
assert.equal(parseInt(balance.toString()), 100); | ||
}); | ||
}); |
{ | ||
"name": "eth-gas-reporter", | ||
"version": "0.2.6", | ||
"version": "0.2.7", | ||
"description": "Mocha reporter which shows gas used per unit test.", | ||
@@ -52,2 +52,3 @@ "main": "index.js", | ||
"devDependencies": { | ||
"@codechecks/client": "^0.1.5", | ||
"@nomiclabs/buidler": "^1.0.0-beta.7", | ||
@@ -62,2 +63,3 @@ "@nomiclabs/buidler-truffle5": "^1.0.0-beta.7", | ||
"pretty-quick": "^1.11.0", | ||
"randomstring": "^1.1.5", | ||
"truffle": "5.0.12", | ||
@@ -64,0 +66,0 @@ "web3": "1.0.0-beta.37", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
113564
56
1811
0
14
8