Giter VIP home page Giter VIP logo

eth-gas-reporter's Introduction

eth-gas-reporter

npm version Build Status Codechecks

A Mocha reporter for Ethereum test suites:

  • Gas usage per unit test.
  • Metrics for method calls and deployments.
  • National currency costs of deploying and using your contract system.
  • CI integration with codechecksbeta
  • Simple installation for Truffle and Buidler

Example output

Screen Shot 2019-06-24 at 4 54 47 PM

Installation and Config

Truffle

npm install --save-dev eth-gas-reporter
/* truffle-config.js */
module.exports = {
  networks: { ... },
  mocha: {
    reporter: 'eth-gas-reporter',
    reporterOptions : { ... } // See options below
  }
};

Buidler

buidler

npm install --save-dev buidler-gas-reporter
/* buidler.config.js */
usePlugin('buidler-gas-reporter');

module.exports = {
  networks: { ... },
  gasReporter: { ... } // See options below
};

Other

This reporter should work with any build platform that uses Mocha and connects to an Ethereum client running as a separate process. There's more on advanced use cases here.

Continuous Integration (in CircleCI)

If you use CircleCI, this reporter can be combined with codechecks to track changes in gas consumption between PRs. Codechecks is free for open source and maintained by MakerDao engineer @krzkaczor.

Complete set-up guide here (it's easy).

Screen Shot 2019-06-18 at 12 25 49 PM

Options

Option Type Default Description
currency String 'EUR' National currency to represent gas costs in. Exchange rates loaded at runtime from the coinmarketcap api. Available currency codes can be found here.
gasPrice Number (varies) Denominated in gwei. Default is loaded at runtime from the eth gas station api
outputFile String stdout File path to write report output to
noColors Boolean false Suppress report color. Useful if you are printing to file b/c terminal colorization corrupts the text.
onlyCalledMethods Boolean true Omit methods that are never called from report.
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)
showTimeSpent Boolean false Show the amount of time spent as well as the gas consumed
excludeContracts String[] [] Contract names to exclude from report. Ex: ['Migrations']
src String "contracts" Folder in root directory to begin search for .sol files. This can also be a path to a subfolder relative to the root, e.g. "planets/annares/contracts"
url String web3.currentProvider.host RPC client url (ex: "http://localhost:8545")
proxyResolver Function none Custom method to resolve identity of methods managed by a proxy contract.
artifactType Function or String "truffle-v5" Compilation artifact format to consume. (See advanced use.)

Advanced Use

An advanced use guide is available here. Topics include:

  • Getting accurate gas data when using proxy contracts like EtherRouter or ZeppelinOS.
  • Configuring the reporter to work with non-truffle, non-buidler projects.

Example Reports

Usage Notes

  • Requires Node >= 8.
  • You cannot use ganache-core as an in-process provider for your test suite. The reporter makes sync RPC calls while collecting data and your tests will hang unless the client is launched as a separate process.
  • Method calls that throw are filtered from the stats.
  • Contracts that are only ever created by other contracts within Solidity are not shown in the deployments table.

Contributions

Feel free to open PRs or issues. There is an integration test and one of the mock test cases is expected to fail. If you're adding an option, you can vaildate it in CI by adding it to the mock options config located here.

Credits

All the ideas in this utility have been borrowed from elsewhere. Many thanks to:

  • @maurelian - Mocha reporting gas instead of time is his idea.
  • @cag - The table borrows from / is based his gas statistics work for the Gnosis contracts.
  • Neufund - Block limit size ratios for contract deployments and euro pricing are borrowed from their ico-contracts test suite.

Contributors

eth-gas-reporter's People

Contributors

cgewecke avatar wighawag avatar ldub avatar rmuslimov avatar iamchrissmith avatar krzkaczor avatar itsnickbarry avatar area avatar bmmpxf avatar ppoliani avatar ben-kaufman avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.