Skip to content

Commit

Permalink
Add test for module pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
rmeissner authored and mmv08 committed Dec 24, 2022
1 parent c36bcab commit 78dadea
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
3 changes: 2 additions & 1 deletion contracts/base/ModuleManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,13 @@ contract ModuleManager is SelfAuthorized, Executor {
// Populate return array
uint256 moduleCount = 0;
address currentModule = modules[start];

while (currentModule != address(0x0) && currentModule != SENTINEL_MODULES && moduleCount < pageSize) {
array[moduleCount] = currentModule;
next = currentModule;
currentModule = modules[currentModule];
moduleCount++;
}
next = currentModule;
// Set correct size of returned array
// solhint-disable-next-line no-inline-assembly
assembly {
Expand Down
33 changes: 32 additions & 1 deletion test/core/GnosisSafe.ModuleManager.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { AddressOne } from "../../src/utils/constants";

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

const [user1, user2] = waffle.provider.getWallets();
const [user1, user2, user3] = waffle.provider.getWallets();

const setupTests = deployments.createFixture(async ({ deployments }) => {
await deployments.fixture();
Expand Down Expand Up @@ -244,4 +244,35 @@ describe("ModuleManager", async () => {
).to.be.deep.eq([false, "0x08c379a000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000013536f6d652072616e646f6d206d65737361676500000000000000000000000000"])
})
})

describe("getModulesPaginated", async () => {
it('Returns all modules over multiple pages', async () => {
const { safe } = await setupTests()
await expect(
executeContractCallWithSigners(safe, safe, "enableModule", [user1.address], [user1])
).to.emit(safe, "EnabledModule").withArgs(user1.address)

await expect(
executeContractCallWithSigners(safe, safe, "enableModule", [user2.address], [user1])
).to.emit(safe, "EnabledModule").withArgs(user2.address)

await expect(
executeContractCallWithSigners(safe, safe, "enableModule", [user3.address], [user1])
).to.emit(safe, "EnabledModule").withArgs(user3.address)

await expect(await safe.isModuleEnabled(user1.address)).to.be.true
await expect(await safe.isModuleEnabled(user2.address)).to.be.true
await expect(await safe.isModuleEnabled(user3.address)).to.be.true


await expect(await safe.getModulesPaginated(AddressOne, 1)).to.be.deep.equal([[user3.address], user3.address])
await expect(await safe.getModulesPaginated(user3.address, 1)).to.be.deep.equal([[user2.address], user2.address])
await expect(await safe.getModulesPaginated(user2.address, 1)).to.be.deep.equal([[user1.address], user1.address])
await expect(await safe.getModulesPaginated(user1.address, 1)).to.be.deep.equal([[], AddressZero])

await expect(await safe.getModulesPaginated(AddressOne, 2)).to.be.deep.equal([[user3.address, user2.address], user2.address])

await expect(await safe.getModulesPaginated(AddressOne, 3)).to.be.deep.equal([[user3.address, user2.address, user1.address], user1.address])
})
})
})

0 comments on commit 78dadea

Please sign in to comment.