diff --git a/contracts/base/ModuleManager.sol b/contracts/base/ModuleManager.sol index 65c0b66d2..68009752c 100644 --- a/contracts/base/ModuleManager.sol +++ b/contracts/base/ModuleManager.sol @@ -118,13 +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 = array[moduleCount == 0 ? 0 : moduleCount - 1]; // Set correct size of returned array // solhint-disable-next-line no-inline-assembly assembly { diff --git a/test/core/GnosisSafe.ModuleManager.spec.ts b/test/core/GnosisSafe.ModuleManager.spec.ts index 49f1dc3ce..d62ede4b8 100644 --- a/test/core/GnosisSafe.ModuleManager.spec.ts +++ b/test/core/GnosisSafe.ModuleManager.spec.ts @@ -62,7 +62,7 @@ describe("ModuleManager", async () => { await expect( await safe.getModulesPaginated(AddressOne, 10) - ).to.be.deep.equal([[user2.address], AddressOne]) + ).to.be.deep.equal([[user2.address], user2.address]) }) it('can enable multiple', async () => { @@ -72,14 +72,14 @@ describe("ModuleManager", async () => { ).to.emit(safe, "EnabledModule").withArgs(user1.address) await expect(await safe.isModuleEnabled(user1.address)).to.be.true - await expect(await safe.getModulesPaginated(AddressOne, 10)).to.be.deep.equal([[user1.address], AddressOne]) + await expect(await safe.getModulesPaginated(AddressOne, 10)).to.be.deep.equal([[user1.address], user1.address]) await expect( executeContractCallWithSigners(safe, safe, "enableModule", [user2.address], [user1]) ).to.emit(safe, "EnabledModule").withArgs(user2.address) await expect(await safe.isModuleEnabled(user2.address)).to.be.true - await expect(await safe.getModulesPaginated(AddressOne, 10)).to.be.deep.equal([[user2.address, user1.address], AddressOne]) + await expect(await safe.getModulesPaginated(AddressOne, 10)).to.be.deep.equal([[user2.address, user1.address], user1.address]) }) }) @@ -135,19 +135,19 @@ describe("ModuleManager", async () => { await expect(await safe.isModuleEnabled(user1.address)).to.be.true await executeContractCallWithSigners(safe, safe, "enableModule", [user2.address], [user1]) await expect(await safe.isModuleEnabled(user2.address)).to.be.true - await expect(await safe.getModulesPaginated(AddressOne, 10)).to.be.deep.equal([[user2.address, user1.address], AddressOne]) + await expect(await safe.getModulesPaginated(AddressOne, 10)).to.be.deep.equal([[user2.address, user1.address], user1.address]) await expect( executeContractCallWithSigners(safe, safe, "disableModule", [user2.address, user1.address], [user1]) ).to.emit(safe, "DisabledModule").withArgs(user1.address) await expect(await safe.isModuleEnabled(user1.address)).to.be.false - await expect(await safe.getModulesPaginated(AddressOne, 10)).to.be.deep.equal([[user2.address], AddressOne]) + await expect(await safe.getModulesPaginated(AddressOne, 10)).to.be.deep.equal([[user2.address], user2.address]) await expect( executeContractCallWithSigners(safe, safe, "disableModule", [AddressOne, user2.address], [user1]) ).to.emit(safe, "DisabledModule").withArgs(user2.address) await expect(await safe.isModuleEnabled(user2.address)).to.be.false - await expect(await safe.getModulesPaginated(AddressOne, 10)).to.be.deep.equal([[], AddressOne]) + await expect(await safe.getModulesPaginated(AddressOne, 10)).to.be.deep.equal([[], AddressZero]) }) }) diff --git a/test/migration/subTests.spec.ts b/test/migration/subTests.spec.ts index 04bbec0ff..aef115073 100644 --- a/test/migration/subTests.spec.ts +++ b/test/migration/subTests.spec.ts @@ -67,7 +67,7 @@ export const verificationTests = (setupTests: () => Promise) => { ).to.emit(migratedSafe, "EnabledModule").withArgs(user2.address) await expect(await migratedSafe.isModuleEnabled(user2.address)).to.be.true - await expect(await migratedSafe.getModulesPaginated(AddressOne, 10)).to.be.deep.equal([[user2.address], AddressOne]) + await expect(await migratedSafe.getModulesPaginated(AddressOne, 10)).to.be.deep.equal([[user2.address], user2.address]) const user2Safe = migratedSafe.connect(user2) await expect(