From 658460382ac437af75f2fed8642216b54f2f96c5 Mon Sep 17 00:00:00 2001 From: cgewecke Date: Thu, 23 May 2024 19:11:51 -0700 Subject: [PATCH] Fix bug preventing correct resolution of factory deployed contracts (#234) --- src/lib/collector.ts | 5 +++-- test/integration/options.a.ts | 6 +++--- test/projects/options/test/factory.ts | 31 +++++++++++++++++++++++++++ 3 files changed, 37 insertions(+), 5 deletions(-) create mode 100644 test/projects/options/test/factory.ts diff --git a/src/lib/collector.ts b/src/lib/collector.ts index 2c22b2f..4f6021a 100644 --- a/src/lib/collector.ts +++ b/src/lib/collector.ts @@ -103,9 +103,10 @@ export class Collector { // Case: proxied call if (this._isProxied(contractName, tx.input!)) { contractName = await this.resolver.resolveByProxy(tx); + } - // Case: hidden contract factory deployment - } else if (contractName === null) { + // Case: hidden contract factory deployment + if (contractName === null) { contractName = await this.resolver.resolveByDeployedBytecode( tx.to ); diff --git a/test/integration/options.a.ts b/test/integration/options.a.ts index d59dff8..84d8cb8 100644 --- a/test/integration/options.a.ts +++ b/test/integration/options.a.ts @@ -81,12 +81,12 @@ describe("Options A", function () { assert.isNull(deployment); }); - it("resolves shadowed method calls with the example proxy resolver", function(){ + it("resolves shadowed method calls with the example proxy resolver, and with factory deployed contracts", function(){ const methodA = findMethod(methods, "VersionA", "setValue"); const methodB = findMethod(methods, "VersionB", "setValue"); - assert.equal(methodA?.numberOfCalls, 1); - assert.equal(methodB?.numberOfCalls, 1); + assert.equal(methodA?.numberOfCalls, 2); + assert.equal(methodB?.numberOfCalls, 2); }); it("calculates gas deltas for methods and deployments", async function(){ diff --git a/test/projects/options/test/factory.ts b/test/projects/options/test/factory.ts new file mode 100644 index 0000000..1beb4ed --- /dev/null +++ b/test/projects/options/test/factory.ts @@ -0,0 +1,31 @@ +// eslint-disable-next-line import/no-extraneous-dependencies +import { Contract } from "ethers"; +import { ethers } from "hardhat"; + +describe("Factory deployment: different contract / same method name", 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(); + }); +});