cgewecke / hardhat-gas-reporter

Gas Usage Analytics for Hardhat
MIT License
404 stars 55 forks source link

Methods with same names in different contracts are getting merged #231

Closed CSY54 closed 2 months ago

CSY54 commented 2 months ago

I'm trying to deploy two contracts with a factory that have the same method name. However, I found the gas report putting two methods with the same name from two different contracts into one entry.

By adding ./test/projects/options/test/differentContractWithSameMethodName.ts (code below)

// eslint-disable-next-line import/no-extraneous-dependencies
import { Contract } from "ethers";
import { ethers } from "hardhat";

describe("setValue", function () {
  let Factory;
  let VersionA;
  let VersionB;
  let factory: Contract;
  let versionA: Contract;
  let versionB: Contract;

  before(async function () {
    Factory = await ethers.getContractFactory("Factory");
    VersionA = await ethers.getContractFactory("VersionA");
    VersionB = await ethers.getContractFactory("VersionB");

    factory = await Factory.deploy();

    await factory.deployVersionA();
    versionA = VersionA.attach(await factory.versionA());

    await factory.deployVersionB();
    versionB = VersionB.attach(await factory.versionB());
  });

  it("Calling both versionA.setValue and versionB.setValue", async function () {
    await versionA.setValue();
    await versionB.setValue();
  });
});
running npx mocha test/integration/options.a.ts, and by commenting out the setValue(), I found scenario output expected
not calling versionA.setValue() and versionB.setValue() (1, 1) (1, 1)
call versionA.setValue() only (2, 1) (2, 1)
call versionB.setValue() only (2, 1) (1, 2)
call both versionA.setValue() and versionB.setValue() (3, 1) (2, 2)

Note: The pair in output and expected field above means the # calls field from the output table of VersionA setValue() and VersionB setValue()

cgewecke commented 2 months ago

@CSY54 Thanks so much for reporting this and for your reproduction case - have patched the problem via #234 and published it in v2.2.0.

Hopefully this resolves the issue but just ping if not and I will re-open.