do not reset ongoing grace period on extension (cf. spec change)

This commit is contained in:
Sergei Tikhomirov 2024-09-30 16:53:34 +02:00
parent eedd9288f2
commit 9ceae53677
No known key found for this signature in database
GPG Key ID: 6A1F8ED9D6538027
2 changed files with 16 additions and 7 deletions

View File

@ -227,8 +227,12 @@ abstract contract MembershipUpgradeable is Initializable {
if (_sender != membership.holder) revert AttemptedExtensionByNonHolder(_idCommitment);
// FIXME: see spec: should extension depend on the current block.timestamp?
uint256 newGracePeriodStartTimestamp = block.timestamp + uint256(activeStateDuration);
// Note: we add the new active period to the end of the ongoing grace period
uint256 newGracePeriodStartTimestamp = (
membership.gracePeriodStartTimestamp + membership.gracePeriodDuration
// FIXME: we must use this membership's activeStateDuration, not global default
+ uint256(activeStateDuration)
);
membership.gracePeriodStartTimestamp = newGracePeriodStartTimestamp;

View File

@ -220,11 +220,16 @@ contract WakuRlnV2Test is Test {
// Attempt to extend the membership (but now we are the owner)
vm.expectEmit(true, false, false, false); // only check the first parameter of the event (the idCommitment)
emit MembershipUpgradeable.MembershipExtended(idCommitment, 0, 0, 0);
(, uint256 oldGracePeriodStartTimestamp, uint32 oldGracePeriodDuration,,,,) = w.memberships(idCommitment);
w.extendMemberships(commitmentsToExtend);
(, uint256 newGracePeriodStartTimestamp, uint32 newGracePeriodDuration,,,,) = w.memberships(idCommitment);
(, uint256 newgracePeriodStartTimestamp,,,,,) = w.memberships(idCommitment);
assertEq(block.timestamp + uint256(w.activeStateDuration()), newgracePeriodStartTimestamp);
assertEq(oldGracePeriodDuration, newGracePeriodDuration);
assertEq(
oldGracePeriodStartTimestamp + oldGracePeriodDuration + uint256(w.activeStateDuration()),
newGracePeriodStartTimestamp
);
assertFalse(w.isInGracePeriod(idCommitment));
assertFalse(w.isExpired(idCommitment));
@ -261,8 +266,8 @@ contract WakuRlnV2Test is Test {
emit MembershipUpgradeable.MembershipExtended(idCommitment, 0, 0, 0);
w.extendMemberships(commitmentsToExtend);
(, uint256 newgracePeriodStartTimestamp, uint32 newGracePeriod,,,,) = w.memberships(idCommitment);
uint256 expectedExpirationTimestamp = newgracePeriodStartTimestamp + uint256(newGracePeriod) + 1;
(, uint256 newGracePeriodStartTimestamp, uint32 newGracePeriodDuration,,,,) = w.memberships(idCommitment);
uint256 expectedExpirationTimestamp = newGracePeriodStartTimestamp + uint256(newGracePeriodDuration) + 1;
uint256 membershipExpirationTimestamp = w.membershipExpirationTimestamp(idCommitment);
assertEq(expectedExpirationTimestamp, membershipExpirationTimestamp);
assertTrue(expectedExpirationTimestamp > ogExpirationTimestamp);