Skip to content

Commit

Permalink
Unifying function to get Safe implementation (#808)
Browse files Browse the repository at this point in the history
Fixes #802 

This PR unifies `getSafeWithOwners(...)` and `getSafeWithSingleton(...)`
by editing the `getSafeTemplate(...)` to use an inside function which
also takes the `singleton` as a parameter.
  • Loading branch information
dodger213 committed Aug 8, 2024
1 parent d87d8f2 commit 209c106
Show file tree
Hide file tree
Showing 27 changed files with 104 additions and 115 deletions.
4 changes: 2 additions & 2 deletions benchmark/utils/setup.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect } from "chai";
import hre, { deployments, ethers } from "hardhat";
import { BigNumberish } from "ethers";
import { getTokenCallbackHandler, getSafeWithOwners } from "../../test/utils/setup";
import { getTokenCallbackHandler, getSafe } from "../../test/utils/setup";
import {
logGas,
executeTx,
Expand All @@ -24,7 +24,7 @@ const generateTarget = async (owners: number, threshold: number, guardAddress: s
const fallbackHandler = await getTokenCallbackHandler();
const fallbackHandlerAddress = await fallbackHandler.getAddress();
const signers = (await ethers.getSigners()).slice(0, owners);
const safe = await getSafeWithOwners({
const safe = await getSafe({
owners: signers.map((owner) => owner.address),
threshold,
fallbackHandler: fallbackHandlerAddress,
Expand Down
4 changes: 2 additions & 2 deletions test/accessors/SimulateTxAccessor.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect } from "chai";
import hre, { deployments, ethers } from "hardhat";
import { deployContract, getSimulateTxAccessor, getSafeWithOwners, getCompatFallbackHandler } from "../utils/setup";
import { deployContract, getSimulateTxAccessor, getSafe, getCompatFallbackHandler } from "../utils/setup";
import { buildContractCall } from "../../src/utils/execution";

describe("SimulateTxAccessor", () => {
Expand All @@ -20,7 +20,7 @@ describe("SimulateTxAccessor", () => {
const interactor = await deployContract(user1, source);
const handler = await getCompatFallbackHandler();
const handlerAddress = await handler.getAddress();
const safe = await getSafeWithOwners({ owners: [user1.address], threshold: 1, fallbackHandler: handlerAddress });
const safe = await getSafe({ owners: [user1.address], threshold: 1, fallbackHandler: handlerAddress });
const safeAddress = await safe.getAddress();
const simulator = await getCompatFallbackHandler(safeAddress);
return {
Expand Down
4 changes: 2 additions & 2 deletions test/core/Safe.Execution.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect } from "chai";
import hre, { deployments, ethers } from "hardhat";
import { deployContract, getSafeWithOwners } from "../utils/setup";
import { deployContract, getSafe } from "../utils/setup";
import {
safeApproveHash,
buildSignatureBytes,
Expand Down Expand Up @@ -42,7 +42,7 @@ describe("Safe", () => {
}`;
const reverter = await deployContract(user1, reverterSource);
return {
safe: await getSafeWithOwners({ owners: [user1.address] }),
safe: await getSafe({ owners: [user1.address] }),
reverter,
storageSetter,
nativeTokenReceiver,
Expand Down
10 changes: 5 additions & 5 deletions test/core/Safe.GuardManager.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect } from "chai";
import hre, { deployments, ethers } from "hardhat";
import { AddressZero } from "@ethersproject/constants";
import { getMock, getSafeWithOwners } from "../utils/setup";
import { getMock, getSafe } from "../utils/setup";
import {
buildContractCall,
buildSafeTransaction,
Expand All @@ -26,7 +26,7 @@ describe("GuardManager", () => {
const guardContract = await hre.ethers.getContractAt("ITransactionGuard", AddressZero);
const guardEip165Calldata = guardContract.interface.encodeFunctionData("supportsInterface", ["0xe6d7a83a"]);
await validGuardMock.givenCalldataReturnBool(guardEip165Calldata, true);
const safe = await getSafeWithOwners({ owners: [user2.address] });
const safe = await getSafe({ owners: [user2.address] });
await executeContractCallWithSigners(safe, safe, "setGuard", [validGuardMockAddress], [user2]);

return {
Expand All @@ -42,7 +42,7 @@ describe("GuardManager", () => {
const {
signers: [user1, user2],
} = await setupWithTemplate();
const safe = await getSafeWithOwners({ owners: [user1.address] });
const safe = await getSafe({ owners: [user1.address] });

await expect(executeContractCallWithSigners(safe, safe, "setGuard", [user2.address], [user1])).to.be.revertedWith("GS013");
});
Expand All @@ -53,7 +53,7 @@ describe("GuardManager", () => {
signers: [user1],
} = await setupWithTemplate();
const validGuardMockAddress = await validGuardMock.getAddress();
const safe = await getSafeWithOwners({ owners: [user1.address] });
const safe = await getSafe({ owners: [user1.address] });

await expect(executeContractCallWithSigners(safe, safe, "setGuard", [validGuardMockAddress], [user1]))
.to.emit(safe, "ChangedGuard")
Expand All @@ -72,7 +72,7 @@ describe("GuardManager", () => {

const invocationCountBefore = await validGuardMock.invocationCount();
const validGuardMockAddress = await validGuardMock.getAddress();
const safe = await getSafeWithOwners({ owners: [user1.address] });
const safe = await getSafe({ owners: [user1.address] });

await executeContractCallWithSigners(safe, safe, "setGuard", [validGuardMockAddress], [user1]);

Expand Down
4 changes: 2 additions & 2 deletions test/core/Safe.Incoming.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect } from "chai";
import hre, { deployments, ethers } from "hardhat";
import { deployContract, getSafeWithOwners } from "../utils/setup";
import { deployContract, getSafe } from "../utils/setup";

describe("Safe", () => {
const setupTests = deployments.createFixture(async ({ deployments }) => {
Expand All @@ -21,7 +21,7 @@ describe("Safe", () => {
const signers = await ethers.getSigners();
const [user1] = signers;
return {
safe: await getSafeWithOwners({ owners: [user1.address] }),
safe: await getSafe({ owners: [user1.address] }),
caller: await deployContract(user1, source),
signers,
};
Expand Down
10 changes: 5 additions & 5 deletions test/core/Safe.ModuleManager.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect } from "chai";
import hre, { deployments, ethers } from "hardhat";
import { AddressZero } from "@ethersproject/constants";
import { getSafeWithOwners, getMock } from "../utils/setup";
import { getSafe, getMock } from "../utils/setup";
import { executeContractCallWithSigners } from "../../src/utils/execution";
import { AddressOne } from "../../src/utils/constants";

Expand All @@ -13,7 +13,7 @@ describe("ModuleManager", () => {
const signers = await ethers.getSigners();
const [user1] = signers;

const safe = await getSafeWithOwners({ owners: [user1.address] });
const safe = await getSafe({ owners: [user1.address] });

const validModuleGuardMock = await getMock();
const moduleGuardContract = await hre.ethers.getContractAt("IModuleGuard", AddressZero);
Expand Down Expand Up @@ -577,7 +577,7 @@ describe("ModuleManager", () => {
const {
signers: [user1, user2],
} = await setupTests();
const safe = await getSafeWithOwners({ owners: [user1.address] });
const safe = await getSafe({ owners: [user1.address] });

await expect(executeContractCallWithSigners(safe, safe, "setModuleGuard", [user2.address], [user1])).to.be.revertedWith(
"GS013",
Expand All @@ -590,7 +590,7 @@ describe("ModuleManager", () => {
signers: [user1],
} = await setupTests();
const validGuardMockAddress = await validModuleGuardMock.getAddress();
const safe = await getSafeWithOwners({ owners: [user1.address] });
const safe = await getSafe({ owners: [user1.address] });

await expect(executeContractCallWithSigners(safe, safe, "setModuleGuard", [validGuardMockAddress], [user1]))
.to.emit(safe, "ChangedModuleGuard")
Expand All @@ -609,7 +609,7 @@ describe("ModuleManager", () => {

const invocationCountBefore = await validModuleGuardMock.invocationCount();
const validModuleGuardMockAddress = await validModuleGuardMock.getAddress();
const safe = await getSafeWithOwners({ owners: [user1.address] });
const safe = await getSafe({ owners: [user1.address] });

await executeContractCallWithSigners(safe, safe, "setModuleGuard", [validModuleGuardMockAddress], [user1]);

Expand Down
4 changes: 2 additions & 2 deletions test/core/Safe.OwnerManager.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect } from "chai";
import { deployments, ethers } from "hardhat";
import { AddressZero } from "@ethersproject/constants";
import { getSafeWithOwners } from "../utils/setup";
import { getSafe } from "../utils/setup";
import { executeContractCallWithSigners } from "../../src/utils/execution";
import { AddressOne } from "../../src/utils/constants";

Expand All @@ -11,7 +11,7 @@ describe("OwnerManager", () => {
const signers = await ethers.getSigners();
const [user1] = signers;
return {
safe: await getSafeWithOwners({ owners: [user1.address] }),
safe: await getSafe({ owners: [user1.address] }),
signers,
};
});
Expand Down
Loading

0 comments on commit 209c106

Please sign in to comment.