Using eth-gas-reporter with OpenZeppelin SDK proxies

Did anyone here were able to use eth-gas-reporter in a project using openzeppelin SDK proxies?

Their documentation mentions that using proxies introduces an issue for resolving names, which I do confirm: https://github.com/cgewecke/eth-gas-reporter/blob/master/docs/advanced.md#resolving-method-identities-when-using-proxy-contracts

But there is no solution out-of-box apparently. Does anyone have a walkthrough for making it work?

1 Like

Hi @wmitsuda,

I tried using eth-gas-reporter with truffle test and a very simple contract and it appeared to work. (see my contract, tests and output below)
What errors do you get?

A work around could be to test the contracts just as logic contracts, (though this doesnโ€™t take into account the overhead of using a Proxy).

Counter.sol

pragma solidity ^0.5.0;

contract Counter {
  uint256 public value;

  function increase() public {
    value++;
  }
}

Counter.test.js

const { TestHelper } = require('@openzeppelin/cli');
const { Contracts, ZWeb3 } = require('@openzeppelin/upgrades');
const {
  BN,           // Big Number support
  constants,    // Common constants, like the zero address and largest integers
  expectEvent,  // Assertions for emitted events
  expectRevert, // Assertions for transactions that should fail
} = require('@openzeppelin/test-helpers');


ZWeb3.initialize(web3.currentProvider);

const Counter = Contracts.getFromLocal('Counter');

require('chai').should();

contract('Counter (upgradeable)', function () {

  beforeEach(async function () {
    this.project = await TestHelper();
    this.proxy = await this.project.createProxy(Counter);
  })

  it('should have a value', async function () {
    const result = await this.proxy.methods.value().call();
    result.should.be.bignumber.equal('0');
  })

  it('should increase value', async function () {
    await this.proxy.methods.increase().send();
    const result = await this.proxy.methods.value().call();
    result.should.be.bignumber.equal('1');
  })
})

Counter.logic.test.js

const {
  BN,           // Big Number support
  constants,    // Common constants, like the zero address and largest integers
  expectEvent,  // Assertions for emitted events
  expectRevert, // Assertions for transactions that should fail
} = require('@openzeppelin/test-helpers');

const Counter = artifacts.require('Counter');

require('chai').should();

contract('Counter (logic)', function () {

  beforeEach(async function () {
    this.counter = await Counter.new();
  })

  it('should have a value', async function () {
    const result = await this.counter.value();
    result.should.be.bignumber.equal('0');
  })

  it('should increase value', async function () {
    await this.counter.increase();
    const result = await this.counter.value();
    result.should.be.bignumber.equal('1');
  })
})

Truffle Test

$ truffle test
Using network 'test'.


Compiling your contracts...
===========================
> Everything is up to date, there is nothing to compile.


  Contract: Counter (logic)
    โœ“ should have a value
    โœ“ should increase value (41653 gas)

  Contract: Counter (upgradeable)
    โœ“ should have a value
    โœ“ should increase value (43218 gas)

ยท----------------------------------------|----------------------------|-------------|----------------------------ยท
|  Solc version: 0.5.12+commit.7709ece9  ยท  Optimizer enabled: false  ยท  Runs: 200  ยท  Block limit: 6721975 gas  โ”‚
ยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยท|ยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยท|ยทยทยทยทยทยทยทยทยทยทยทยทยท|ยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยท
|  Methods                               ยท                1 gwei/gas                ยท       124.42 eur/eth       โ”‚
ยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยท|ยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยท|ยทยทยทยทยทยทยทยทยทยทยทยทยทยท|ยทยทยทยทยทยทยทยทยทยทยทยทยท|ยทยทยทยทยทยทยทยทยทยทยทยทยท|ยทยทยทยทยทยทยทยทยทยทยทยทยทยท|ยทยทยทยทยทยทยทยทยทยทยทยทยทยท
|  Contract          ยท  Method           ยท  Min         ยท  Max        ยท  Avg        ยท  # calls     ยท  eur (avg)  โ”‚
ยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยท|ยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยท|ยทยทยทยทยทยทยทยทยทยทยทยทยทยท|ยทยทยทยทยทยทยทยทยทยทยทยทยท|ยทยทยทยทยทยทยทยทยทยทยทยทยท|ยทยทยทยทยทยทยทยทยทยทยทยทยทยท|ยทยทยทยทยทยทยทยทยทยทยทยทยทยท
|  Counter           ยท  increase         ยท       41653  ยท      43218  ยท      42436  ยท           2  ยท       0.01  โ”‚
ยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยท|ยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยท|ยทยทยทยทยทยทยทยทยทยทยทยทยทยท|ยทยทยทยทยทยทยทยทยทยทยทยทยท|ยทยทยทยทยทยทยทยทยทยทยทยทยท|ยทยทยทยทยทยทยทยทยทยทยทยทยทยท|ยทยทยทยทยทยทยทยทยทยทยทยทยทยท
|  Deployments                           ยท                                          ยท  % of limit  ยท             โ”‚
ยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยท|ยทยทยทยทยทยทยทยทยทยทยทยทยทยท|ยทยทยทยทยทยทยทยทยทยทยทยทยท|ยทยทยทยทยทยทยทยทยทยทยทยทยท|ยทยทยทยทยทยทยทยทยทยทยทยทยทยท|ยทยทยทยทยทยทยทยทยทยทยทยทยทยท
|  Counter                               ยท           -  ยท          -  ยท      99651  ยท       1.5 %  ยท       0.01  โ”‚
ยท----------------------------------------|--------------|-------------|-------------|--------------|-------------ยท

  4 passing (13s)

Thatโ€™s weirdโ€ฆ Iโ€™m using buidler, it seems it does not identify any function call, see:

ยท------------------------|----------------------------|-------------|----------------------------ยท
|  Solc version: 0.5.11  ยท  Optimizer enabled: false  ยท  Runs: 200  ยท  Block limit: 6721975 gas  โ”‚
ยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยท|ยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยท|ยทยทยทยทยทยทยทยทยทยทยทยทยท|ยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยท
|  Methods               ยท                1 gwei/gas                ยท       130.40 eur/eth       โ”‚
ยทยทยทยทยทยทยทยทยทยทยทยทยทยท|ยทยทยทยทยทยทยทยทยทยท|ยทยทยทยทยทยทยทยทยทยทยทยทยทยท|ยทยทยทยทยทยทยทยทยทยทยทยทยท|ยทยทยทยทยทยทยทยทยทยทยทยทยท|ยทยทยทยทยทยทยทยทยทยทยทยทยท|ยทยทยทยทยทยทยทยทยทยทยทยทยทยทยท
|  Contract   ยท  Method  ยท  Min         ยท  Max        ยท  Avg        ยท  # calls    ยท  eur (avg)   โ”‚
ยท-------------|----------|--------------|-------------|-------------|-------------|--------------ยท

  16 passing (29s)

Iโ€™ll try to debug a little more and narrow the issueโ€ฆ

1 Like

Hi @wmitsuda,

It could be that my very simple contract was too simple. You could try my simple contract on builder and see if you get the same results.

1 Like

Iโ€™ve used your example and created an issue on buidler-gas-reporter github: https://github.com/cgewecke/buidler-gas-reporter/issues/12

1 Like