Socket
Socket
Sign inDemoInstall

eth-gas-reporter

Package Overview
Dependencies
Maintainers
1
Versions
63
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eth-gas-reporter - npm Package Compare versions

Comparing version 0.1.7 to 0.1.8

5

CHANGELOG.md
## Changelog: eth-gas-reporter
0.1.7 / 2018-05-27
================
* Support reStructured text code-block output
0.1.5 / 2018-05-15

@@ -3,0 +8,0 @@ ==================

13

gasStats.js

@@ -11,4 +11,3 @@ /**

const shell = require('shelljs')
const Table = require('cli-table2')
const reqCwd = require('req-cwd')
const Table = require('cli-table3')
const abiDecoder = require('abi-decoder')

@@ -256,14 +255,6 @@ const parser = require('solidity-parser-antlr');

*/
async function getGasAndPriceRates (options=null) {
async function getGasAndPriceRates (config=null) {
const defaultGasPrice = 5
// Load config / keep .ethgas.js for backward compatibility
let config;
if (options && options.reporterOptions){
config = options.reporterOptions
} else {
config = reqCwd.silent('./.ethgas.js') || {}
}
// Global to this file...

@@ -270,0 +261,0 @@ currency = config.currency || 'eur'

@@ -5,2 +5,3 @@ const mocha = require('mocha')

const stats = require('./gasStats.js')
const reqCwd = require('req-cwd')
const Base = mocha.reporters.Base

@@ -24,4 +25,12 @@ const color = Base.color

// Load config / keep .ethgas.js for backward compatibility
let config;
if (options && options.reporterOptions){
config = options.reporterOptions
} else {
config = reqCwd.silent('./.ethgas.js') || {}
}
// Start getting this data when the reporter loads.
stats.getGasAndPriceRates(options);
stats.getGasAndPriceRates(config);

@@ -116,21 +125,39 @@ // ------------------------------------ Helpers -------------------------------------------------

let fmt
let fmtArgs
let gasUsedString
deployAnalytics(deployMap)
let gasUsed = methodAnalytics(methodMap)
let showTimeSpent = config.showTimeSpent || false
let timeSpentString = color(test.speed, '%dms')
let consumptionString
if (gasUsed) {
gasUsedString = color('checkmark', ' (%d gas)')
gasUsedString = color('checkmark', '%d gas')
if (showTimeSpent) {
consumptionString = ' (' + timeSpentString + ', ' + gasUsedString + ')'
fmtArgs = [test.title, test.duration, gasUsed]
} else {
consumptionString = ' (' + gasUsedString + ')'
fmtArgs = [test.title, gasUsed]
}
fmt = indent() +
color('checkmark', ' ' + Base.symbols.ok) +
color('pass', ' %s') +
gasUsedString
consumptionString
} else {
if (showTimeSpent) {
consumptionString = ' (' + timeSpentString + ')'
fmtArgs = [test.title, test.duration]
} else {
consumptionString = ''
fmtArgs = [test.title]
}
log(fmt, test.title, gasUsed)
} else {
fmt = indent() +
color('checkmark', ' ' + Base.symbols.ok) +
color('pass', ' %s')
log(fmt, test.title)
color('pass', ' %s') +
consumptionString
}
log.apply(null, [fmt, ...fmtArgs])
})

@@ -137,0 +164,0 @@

@@ -18,5 +18,6 @@ module.exports = {

rst: true,
rstTitle: 'Gas Usage'
rstTitle: 'Gas Usage',
showTimeSpent: true
}
}
}
{
"name": "eth-gas-reporter",
"version": "0.1.5",
"version": "0.1.8",
"description": "Mocha reporter which shows gas used per unit test.",

@@ -29,3 +29,3 @@ "main": "index.js",

"abi-decoder": "^1.0.8",
"cli-table2": "^0.2.0",
"cli-table3": "^0.5.0",
"colors": "^1.1.2",

@@ -43,5 +43,5 @@ "lodash": "^4.17.4",

"darq-truffle": "4.1.4-next.8",
"ganache-cli": "^6.1.0",
"truffle": "^4.1.7"
"ganache-cli": "6.1.0",
"truffle": "4.1.7"
}
}
{
"name": "eth-gas-reporter",
"version": "0.1.7",
"version": "0.1.8",
"description": "Mocha reporter which shows gas used per unit test.",

@@ -29,3 +29,3 @@ "main": "index.js",

"abi-decoder": "^1.0.8",
"cli-table2": "^0.2.0",
"cli-table3": "^0.5.0",
"colors": "^1.1.2",

@@ -43,5 +43,5 @@ "lodash": "^4.17.4",

"darq-truffle": "4.1.4-next.8",
"ganache-cli": "^6.1.0",
"truffle": "^4.1.7"
"ganache-cli": "6.1.0",
"truffle": "4.1.7"
}
}

@@ -17,9 +17,2 @@ # eth-gas-reporter

```javascript
// Requires mocha
npm install -g mocha
// Truffle installed globally
npm install -g eth-gas-reporter
// Truffle installed locally (ProTip: This always works.)
npm install --save-dev eth-gas-reporter

@@ -54,3 +47,4 @@ ```

| rst | *Boolean* | false | Output with a reStructured text code-block directive. Useful if you want to include report in RTD |
| rstTitle | *String* | '' | Title for reStructured text header (See Travis for example output) |
| rstTitle | *String* | "" | Title for reStructured text header (See Travis for example output) |
| showTimeSpent | *Boolean* | false | Show the amount of time spent as well as the gas consumed |

@@ -68,3 +62,11 @@

+ Contracts that are only ever created by other contracts within Solidity.
+ Your ethereum client has to be run in separate process (e.g. reporter will not work if you connect
to `ganache` through a `provider` in your `truffle.js`). This because mocha's reporter is sync
and we have to collect gas data synchronously from the client as your tests run. Sync requests
fail with an in memory provider because they block the thread and prevent a
response. (Pro-tip courtesy of [@fosgate29](https://github.com/fosgate29)).
### Contributions
Please feel free to open a PR (or an issue) for anything. The units are an integration test and one of them is expected to fail, verifying that the table prints at the end of a suite even when there are errors. If you're adding an option, you can vaildate it in CI by adding it to the mock options config located [here](https://github.com/cgewecke/eth-gas-reporter/blob/master/mock/config-template.js#L13-L19).
### Credits

@@ -80,1 +82,2 @@ All the ideas in this utility have been borrowed from elsewhere. Many thanks to:

+ [@area](https://github.com/area)
+ [@ldub](https://github.com/ldub)
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc