Skip to content

Commit

Permalink
[#4] Add tests for enable/disable module
Browse files Browse the repository at this point in the history
  • Loading branch information
akshay-ap committed Jun 23, 2023
1 parent e026c30 commit b83c7e0
Showing 1 changed file with 55 additions and 5 deletions.
60 changes: 55 additions & 5 deletions test/SafeProtocolMediator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,60 @@ describe("SafeProtocolMediator", async () => {
return { safeProtocolMediator };
}

it.only("Should set mediator as a module for a safe", async () => {
const safe = await hre.ethers.deployContract("TestExecutor");
describe("Setup mediator", async()=>{
it("Should set mediator as a module for a safe", async () => {
const safe = await hre.ethers.deployContract("TestExecutor");

const { safeProtocolMediator } = await loadFixture(deployContractFixture);
await safe.setModule(await safeProtocolMediator.getAddress());
});
})

const { safeProtocolMediator } = await loadFixture(deployContractFixture);
await safe.setModule(await safeProtocolMediator.getAddress());
});

describe("Modules", async()=>{

async function deployModuleFixture() {
[deployer, owner, user1, user2]= await hre.ethers.getSigners();
const safeProtocolMediator = await (await hre.ethers.getContractFactory("SafeProtocolMediator")).deploy(owner.address);
const safe = await hre.ethers.deployContract("TestExecutor");
const module = await (await hre.ethers.getContractFactory("TestModule")).deploy();
return { safeProtocolMediator, safe, module };
}

it("Should allow a Safe to enable a module through a mediator", async () => {
const { safeProtocolMediator, safe, module } = await loadFixture(deployModuleFixture);
await safe.setModule(await safeProtocolMediator.getAddress());
const data = safeProtocolMediator.interface.encodeFunctionData("enableModule", [await module.getAddress(), false]);
await safe.exec(await safeProtocolMediator.getAddress(), 0, data);
// TODO: Check for emitted events and param values
expect(await safeProtocolMediator.getModuleInfo(await safe.getAddress(), await module.getAddress())).to.eql([true, false]);

});

it("Should fail to enable a module (with non root access) with root access", async () => {

const { safeProtocolMediator, safe, module } = await loadFixture(deployModuleFixture);
await safe.setModule(await safeProtocolMediator.getAddress());
const data = safeProtocolMediator.interface.encodeFunctionData("enableModule", [await module.getAddress(), true]);

await expect(safe.exec(await safeProtocolMediator.getAddress(), 0, data)).to.be.revertedWithCustomError(safeProtocolMediator, "ModuleAccessMismatch");
expect(await safeProtocolMediator.getModuleInfo(await safe.getAddress(), await module.getAddress())).to.eql([false, false]);

});

it("Should disable a module", async () => {
const { safeProtocolMediator, safe, module } = await loadFixture(deployModuleFixture);
await safe.setModule(await safeProtocolMediator.getAddress());
const data = safeProtocolMediator.interface.encodeFunctionData("enableModule", [await module.getAddress(), false]);
await safe.exec(await safeProtocolMediator.getAddress(), 0, data);
expect(await safeProtocolMediator.getModuleInfo(await safe.getAddress(), await module.getAddress())).to.eql([true, false]);

const data2 = safeProtocolMediator.interface.encodeFunctionData("disableModule", [await module.getAddress()]);
await safe.exec(await safeProtocolMediator.getAddress(), 0, data2);
// TODO: Check for emitted events and param values
expect(await safeProtocolMediator.getModuleInfo(await safe.getAddress(), await module.getAddress())).to.eql([false, false]);
});
})


});

0 comments on commit b83c7e0

Please sign in to comment.