From 82e7ce58bef2eb04c46fbdb63fa9b522da6931bd Mon Sep 17 00:00:00 2001 From: rymnc <43716372+rymnc@users.noreply.github.com> Date: Wed, 22 May 2024 18:17:32 +0530 Subject: [PATCH] fix: test getCommitments too --- .gas-snapshot | 2 +- src/WakuRlnV2.sol | 9 ++++----- test/WakuRlnV2.t.sol | 3 +++ 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/.gas-snapshot b/.gas-snapshot index fddbc83..4629d29 100644 --- a/.gas-snapshot +++ b/.gas-snapshot @@ -1 +1 @@ -WakuRlnV2Test:test__ValidRegistration() (gas: 108659) \ No newline at end of file +WakuRlnV2Test:test__ValidRegistration() (gas: 108661) \ No newline at end of file diff --git a/src/WakuRlnV2.sol b/src/WakuRlnV2.sol index 4a0295e..0a461ec 100644 --- a/src/WakuRlnV2.sol +++ b/src/WakuRlnV2.sol @@ -133,8 +133,7 @@ contract WakuRlnV2 { if (idCommitmentIndex >= SET_SIZE) revert FullTree(); uint256 rateCommitment = PoseidonT3.hash([idCommitment, userMessageLimit]); - MembershipInfo memory member = - MembershipInfo({ userMessageLimit: uint32(userMessageLimit), index: idCommitmentIndex }); + MembershipInfo memory member = MembershipInfo({ userMessageLimit: userMessageLimit, index: idCommitmentIndex }); LazyIMT.insert(imtData, rateCommitment); memberInfo[idCommitment] = member; @@ -150,13 +149,13 @@ contract WakuRlnV2 { return imtData.elements[LazyIMT.indexForElement(0, index)]; } - function getCommitments(uint256 startIndex, uint256 endIndex) public view returns (uint256[] memory) { + function getCommitments(uint32 startIndex, uint32 endIndex) public view returns (uint256[] memory) { if (startIndex >= endIndex) revert InvalidPaginationQuery(startIndex, endIndex); if (endIndex > idCommitmentIndex) revert InvalidPaginationQuery(startIndex, endIndex); uint256[] memory commitments = new uint256[](endIndex - startIndex); - for (uint256 i = startIndex; i < endIndex; i++) { - commitments[i - startIndex] = indexToCommitment(uint32(i)); + for (uint32 i = startIndex; i < endIndex; i++) { + commitments[i - startIndex] = indexToCommitment(i); } return commitments; } diff --git a/test/WakuRlnV2.t.sol b/test/WakuRlnV2.t.sol index d6aeb1b..72ff12f 100644 --- a/test/WakuRlnV2.t.sol +++ b/test/WakuRlnV2.t.sol @@ -34,6 +34,9 @@ contract WakuRlnV2Test is Test { assertEq(index, 0); uint256 rateCommitment = PoseidonT3.hash([idCommitment, userMessageLimit]); assertEq(w.indexToCommitment(0), rateCommitment); + uint256[] memory commitments = w.getCommitments(0, 1); + assertEq(commitments.length, 1); + assertEq(commitments[0], rateCommitment); vm.resumeGasMetering(); } }