All Projects → cgewecke → Eth Gas Reporter

cgewecke / Eth Gas Reporter

Licence: mit
Gas usage per unit test. Average gas usage per method. A mocha reporter.

Programming Languages

javascript
184084 projects - #8 most used programming language
solidity
1140 projects

Projects that are alternatives of or similar to Eth Gas Reporter

Sazerac
Data-driven unit testing for Jasmine, Mocha, and Jest
Stars: ✭ 322 (-2.42%)
Mutual labels:  unit-testing, mocha
currency-api
A demo project on how to test a node/express app with Mocha, Nock and proxyquire (MNP) and code coverage with nyc/istanbul.
Stars: ✭ 19 (-94.24%)
Mutual labels:  unit-testing, mocha
Ganache
A tool for creating a local blockchain for fast Ethereum development.
Stars: ✭ 1,028 (+211.52%)
Mutual labels:  ethereum, truffle
Armors Solidity
Armors-solidity is a framework to build secure smart contracts on Ethereum.
Stars: ✭ 184 (-44.24%)
Mutual labels:  ethereum, truffle
Solidity Idiosyncrasies
Solidity gotchas, pitfalls, limitations, and idiosyncrasies.
Stars: ✭ 267 (-19.09%)
Mutual labels:  ethereum, truffle
Erc20 Generator
Create an ERC20 Token for FREE in less than a minute with the most used Smart Contract Generator for ERC20 Token. No login. No setup. No coding required.
Stars: ✭ 202 (-38.79%)
Mutual labels:  ethereum, truffle
floss
Unit-testing for those hard to reach places
Stars: ✭ 26 (-92.12%)
Mutual labels:  unit-testing, mocha
Sablier
The protocol for real-time finance on the Ethereum blockchain
Stars: ✭ 147 (-55.45%)
Mutual labels:  ethereum, truffle
Truffle Flattener
Truffle Flattener concats solidity files from Truffle and Buidler projects with all of their dependencies
Stars: ✭ 254 (-23.03%)
Mutual labels:  ethereum, truffle
awesome-javascript-testing
🔧 Awesome JavaScript testing resources
Stars: ✭ 28 (-91.52%)
Mutual labels:  unit-testing, mocha
Angular Truffle Starter Dapp
Angular CLI + Truffle Starter Dapp; write, compile & deploy smart contracts on Ethereum blockchains
Stars: ✭ 174 (-47.27%)
Mutual labels:  ethereum, truffle
Love Ethereum
区块链学习
Stars: ✭ 323 (-2.12%)
Mutual labels:  ethereum, truffle
React Auth Box
Truffle, Webpack, React, Redux boilerplate with routing and authentication via a smart contract.
Stars: ✭ 172 (-47.88%)
Mutual labels:  ethereum, truffle
Sparkle Proof Of Loyalty
Sparkle Proof of Loyalty Contract
Stars: ✭ 216 (-34.55%)
Mutual labels:  ethereum, truffle
Eth Vue
Featured in Awesome Vue [https://github.com/vuejs/awesome-vue], a curated list maintained by vuejs of awesome things related to the Vue.js framework, and Awesome List [https://awesomelists.net/150-Vue.js/3863-Open+Source/18749-DOkwufulueze-eth-vue], this Truffle Box provides everything you need to quickly build Ethereum dApps that have authentication features with vue, including configuration for easy deployment to the Ropsten Network. It's also Gravatar-enabled. Connecting to a running Ganache blockchain network from Truffle is also possible -- for fast development and testing purposes. Built on Truffle 5 and Vue 3, eth-vue uses vuex for state management, vuex-persist for local storage of app state, and vue-router for routing. Authentication functionalities are handled by Smart Contracts running on the Ethereum blockchain.
Stars: ✭ 171 (-48.18%)
Mutual labels:  ethereum, truffle
chai-exclude
Exclude keys to compare from a deep equal operation with chai expect or assert.
Stars: ✭ 33 (-90%)
Mutual labels:  unit-testing, mocha
Truffle Next
🛰️ A boilerplate Truffle Box project with Next.js for rapid Ethereum Dapp development
Stars: ✭ 130 (-60.61%)
Mutual labels:  ethereum, truffle
Truffle Plugin Verify
✅ Verify your smart contracts on Etherscan from the Truffle CLI
Stars: ✭ 144 (-56.36%)
Mutual labels:  ethereum, truffle
tropic
🍍 Test Runner Library
Stars: ✭ 29 (-91.21%)
Mutual labels:  unit-testing, mocha
0xdeca10b
Sharing Updatable Models (SUM) on Blockchain
Stars: ✭ 285 (-13.64%)
Mutual labels:  ethereum, truffle

eth-gas-reporter

npm version Build Status Codechecks buidler

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 codechecks
  • 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

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 (Travis and CircleCI)

This reporter comes with a codechecks CI integration that displays a pull request's gas consumption changes relative to its target branch in the Github UI. It's like coveralls for gas. The codechecks service 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

⚠️ CoinMarketCap API change ⚠️

Beginning March 2020, CoinMarketCap requires an API key to access currency market price data. The reporter uses an unprotected free tier key by default (10k reqs/mo). You can get your own API key here and set it with the coinmarketcap option.

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.
coinmarketcap String (unprotected API key) API key to use when fetching current market price data. (Use this if you stop seeing price data)
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.)
showMethodSig Boolean false Display complete method signatures. Useful when you have overloaded methods you can't tell apart.
maxMethodDiff Number undefined Codechecks failure threshold, triggered when the % diff for any method is greater than number (integer)
maxDeploymentDiff Number undefined Codechecks failure threshold, triggered when the % diff for any deployment is greater than number (integer)

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].