optifat-snapshot-gas-cost
TypeScript icon, indicating that this package has built-in type declarations

1.1.0 • Public • Published

snapshot-gas-cost

Tiny utility function for snapshotting gas costs in unit tests.

Fork of Uniswap gas snapshotter with ethers v6 support

Objective

This function is useful for smart contract testing against hardhat networks. Use it to produce snapshot diffs that you commit to your repository.

Usage

import snapshotGasCost from 'snapshot-gas-cost'
import {BaseContract} from "ethers";

describe('gas tests', () => {
    let myContract: BaseContract
    beforeEach('initialize contract', () => {
        /// initialize myContract
    })
    
    it('gas snapshot for a mutable function', async () => {
        await snapshotGasCost(myContract.getFunction('someMutableFunction')())
    })
    
    it('gas snapshot for a view function', async () => {
        await snapshotGasCost(myContract.estimateGas.someViewFunction('someViewFunction')())
    })
})

BaseContract is replaceable by other instances (e.g. typechain ones) of Contract type for more convenience

Readme

Keywords

none

Package Sidebar

Install

npm i optifat-snapshot-gas-cost

Weekly Downloads

1

Version

1.1.0

License

GPL-2.0-or-later

Unpacked Size

23.5 kB

Total Files

6

Last publish

Collaborators

  • optifat