define period boundaries: start inclusive, end exclusive

This commit is contained in:
Sergei Tikhomirov 2024-10-03 10:38:04 +02:00
parent 0201d38f6f
commit 018ba1c9d2
No known key found for this signature in database
GPG Key ID: 6A1F8ED9D6538027
2 changed files with 11 additions and 11 deletions

View File

@ -296,11 +296,11 @@ abstract contract MembershipUpgradeable is Initializable {
}
/// @dev Determine whether the current timestamp is within a given period
/// @param _start timestamp in which the period starts
/// @param _duration duration of the period
/// @param _start timestamp in which the period starts (inclusive)
/// @param _duration duration of the period (end timestamp exclusive)
function _isInPeriod(uint256 _start, uint32 _duration) internal view returns (bool) {
uint256 timeNow = block.timestamp;
return (_start <= timeNow && timeNow <= _start + uint256(_duration));
return (_start <= timeNow && timeNow < _start + uint256(_duration));
}
/// @notice Determine if a membership is expired
@ -311,11 +311,11 @@ abstract contract MembershipUpgradeable is Initializable {
}
/// @dev Determine whether the current timestamp is after a given period
/// @param _start timestamp in which the period starts
/// @param _duration duration of the period
/// @param _start timestamp in which the period starts (inclusive)
/// @param _duration duration of the period (end timestamp exclusive)
function _isAfterPeriod(uint256 _start, uint32 _duration) internal view returns (bool) {
uint256 timeNow = block.timestamp;
return (_start + uint256(_duration) < timeNow);
return (_timestampAfterPeriod(_start, _duration) <= timeNow);
}
/// @notice Returns the timestamp on which a membership can be considered expired (i.e. when its grace period ends)
@ -326,10 +326,10 @@ abstract contract MembershipUpgradeable is Initializable {
}
/// @dev Returns the first timestamp after a specified period
/// @param _start timestamp in which the period starts
/// @param _duration duration of the period
/// @param _start timestamp in which the period starts (inclusive)
/// @param _duration duration of the period (exclusive)
function _timestampAfterPeriod(uint256 _start, uint32 _duration) internal pure returns (uint256) {
return _start + uint256(_duration) + 1;
return _start + uint256(_duration);
}
/// @dev Withdraw any available deposit balance in tokens after a membership is erased.

View File

@ -268,7 +268,7 @@ contract WakuRlnV2Test is Test {
w.extendMemberships(commitmentsToExtend);
(,, uint256 newGracePeriodStartTimestamp, uint32 newGracePeriodDuration,,,,) = w.memberships(idCommitment);
uint256 expectedExpirationTimestamp = newGracePeriodStartTimestamp + uint256(newGracePeriodDuration) + 1;
uint256 expectedExpirationTimestamp = newGracePeriodStartTimestamp + uint256(newGracePeriodDuration);
uint256 membershipExpirationTimestamp = w.membershipExpirationTimestamp(idCommitment);
assertEq(expectedExpirationTimestamp, membershipExpirationTimestamp);
assertTrue(expectedExpirationTimestamp > ogExpirationTimestamp);
@ -289,7 +289,7 @@ contract WakuRlnV2Test is Test {
(,, uint256 fetchedgracePeriodStartTimestamp, uint32 fetchedGracePeriod,,,,) = w.memberships(idCommitment);
uint256 expectedExpirationTimestamp = fetchedgracePeriodStartTimestamp + uint256(fetchedGracePeriod) + 1;
uint256 expectedExpirationTimestamp = fetchedgracePeriodStartTimestamp + uint256(fetchedGracePeriod);
uint256 membershipExpirationTimestamp = w.membershipExpirationTimestamp(idCommitment);
assertEq(expectedExpirationTimestamp, membershipExpirationTimestamp);