-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#47] Implement logic for non-static calls to function handler manage…
…r, test to set function handler
- Loading branch information
Showing
5 changed files
with
95 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { SignerWithAddress } from "@nomicfoundation/hardhat-ethers/signers"; | ||
import hre, { deployments, ethers } from "hardhat"; | ||
import { getMockFunctionHandler } from "./utils/mockFunctionHandlerBuilder"; | ||
import { getSafeWithOwners } from "./utils/setup"; | ||
import { execTransaction } from "./utils/executeSafeTx"; | ||
import { IntegrationType } from "./utils/constants"; | ||
import { expect } from "chai"; | ||
|
||
describe("Test Function Handler", async () => { | ||
let deployer: SignerWithAddress, owner: SignerWithAddress, user1: SignerWithAddress, user2: SignerWithAddress; | ||
|
||
before(async () => { | ||
[deployer, owner, user1, user2] = await hre.ethers.getSigners(); | ||
}); | ||
|
||
const setupTests = deployments.createFixture(async ({ deployments }) => { | ||
await deployments.fixture(); | ||
[owner, user1] = await ethers.getSigners(); | ||
const safeProtocolRegistry = await ethers.deployContract("SafeProtocolRegistry", [owner.address], { signer: deployer }); | ||
const mockFunctionHandler = await getMockFunctionHandler(); | ||
|
||
// Can possibly use a test instance of FunctionHandlerManager instead of SafeProtocolManager. | ||
// But, using SafeProtocolManager for testing with near production scenarios. | ||
const functionHandlerManager = await ( | ||
await hre.ethers.getContractFactory("SafeProtocolManager") | ||
).deploy(owner.address, await safeProtocolRegistry.getAddress()); | ||
|
||
await safeProtocolRegistry.addIntegration(mockFunctionHandler.target, IntegrationType.FunctionHandler); | ||
|
||
const safe = await getSafeWithOwners([owner], 1, functionHandlerManager.target); | ||
|
||
return { safe, functionHandlerManager, mockFunctionHandler }; | ||
}); | ||
|
||
it("Should emit FunctionHandlerChanged event when Function Handler is set", async () => { | ||
const { safe, functionHandlerManager, mockFunctionHandler } = await setupTests(); | ||
|
||
// 0xf8a8fd6d -> function test() external {} | ||
const dataSetFunctionHandler = functionHandlerManager.interface.encodeFunctionData("setFunctionHandler", [ | ||
"0xf8a8fd6d", | ||
mockFunctionHandler.target, | ||
]); | ||
|
||
const tx = await execTransaction([owner], safe, functionHandlerManager, 0n, dataSetFunctionHandler, 0); | ||
const receipt = await tx.wait(); | ||
const events = ( | ||
await functionHandlerManager.queryFilter( | ||
functionHandlerManager.filters.FunctionHandlerChanged, | ||
receipt?.blockNumber, | ||
receipt?.blockNumber, | ||
) | ||
)[0]; | ||
expect(events.args).to.deep.equal([safe.target, "0xf8a8fd6d", mockFunctionHandler.target]); | ||
|
||
expect(await functionHandlerManager.getFunctionHandler.staticCall(safe.target, "0xf8a8fd6d")).to.be.equal( | ||
mockFunctionHandler.target, | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,22 @@ | ||
import hre from "hardhat"; | ||
import { ISafeProtocolFunctionHandler } from "../../typechain-types"; | ||
|
||
export const getFucntionHandlerWithFailingCallToSupportsInterfaceMethod = async (): Promise<ISafeProtocolFunctionHandler> => { | ||
export const getFunctionHandlerWithFailingCallToSupportsInterfaceMethod = async (): Promise<ISafeProtocolFunctionHandler> => { | ||
const hooks = await (await hre.ethers.getContractFactory("MockContract")).deploy(); | ||
|
||
// 0x25d6803f -> type(ISafeProtocolFunctionHandler).interfaceId | ||
await hooks.givenMethodReturnBool("0x25d6803f", false); | ||
await hooks.givenMethodReturnBool("0x01ffc9a7", false); | ||
return hre.ethers.getContractAt("ISafeProtocolFunctionHandler", hooks.target); | ||
}; | ||
|
||
export const getMockFunctionHandler = async (): Promise<ISafeProtocolFunctionHandler> => { | ||
const hooks = await (await hre.ethers.getContractFactory("MockContract")).deploy(); | ||
|
||
// 0x25d6803f -> type(ISafeProtocolFunctionHandler).interfaceId | ||
await hooks.givenMethodReturnBool("0x01ffc9a7", true); | ||
|
||
// 0xf8a8fd6d -> function test() external {} | ||
await hooks.givenMethodReturnBool("0xf8a8fd6d", true); | ||
|
||
return hre.ethers.getContractAt("ISafeProtocolFunctionHandler", hooks.target); | ||
}; |