Skip to content

Commit

Permalink
Fix bug preventing correct resolution of factory deployed contracts (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
cgewecke authored May 24, 2024
1 parent bbc4171 commit 6584603
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 5 deletions.
5 changes: 3 additions & 2 deletions src/lib/collector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
Expand Down
6 changes: 3 additions & 3 deletions test/integration/options.a.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(){
Expand Down
31 changes: 31 additions & 0 deletions test/projects/options/test/factory.ts
Original file line number Diff line number Diff line change
@@ -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();
});
});

0 comments on commit 6584603

Please sign in to comment.