Skip to content

Commit

Permalink
Exclude end time of permission to remove additional period (#73)
Browse files Browse the repository at this point in the history
* Rebase

* Add test for revert on time equals permission end
  • Loading branch information
ilikesymmetry authored Oct 15, 2024
1 parent 37021cd commit 14d9bab
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/SpendPermissionManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ contract SpendPermissionManager is EIP712 {
uint48 currentTimestamp = uint48(block.timestamp);
if (currentTimestamp < spendPermission.start) {
revert BeforeSpendPermissionStart(spendPermission.start);
} else if (currentTimestamp > spendPermission.end) {
} else if (currentTimestamp >= spendPermission.end) {
revert AfterSpendPermissionEnd(spendPermission.end);
}

Expand Down
14 changes: 13 additions & 1 deletion test/src/SpendPermissions/getCurrentPeriod.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {SpendPermissionManager} from "../../../src/SpendPermissionManager.sol";

import {SpendPermissionManagerBase} from "../../base/SpendPermissionManagerBase.sol";

contract GetCurrentCycleTest is SpendPermissionManagerBase {
contract GetCurrentPeriodTest is SpendPermissionManagerBase {
function setUp() public {
_initializeSpendPermissionManager();
}
Expand All @@ -20,6 +20,17 @@ contract GetCurrentCycleTest is SpendPermissionManagerBase {
mockSpendPermissionManager.getCurrentPeriod(spendPermission);
}

function test_getCurrentPeriod_revert_equalSpendPermissionEnd(uint48 end) public {
vm.assume(end > 0);
vm.assume(end < type(uint48).max);

SpendPermissionManager.SpendPermission memory spendPermission = _createSpendPermission();
spendPermission.end = end;
vm.warp(end);
vm.expectRevert(abi.encodeWithSelector(SpendPermissionManager.AfterSpendPermissionEnd.selector, end));
mockSpendPermissionManager.getCurrentPeriod(spendPermission);
}

function test_getCurrentPeriod_revert_afterSpendPermissionEnd(uint48 end) public {
vm.assume(end > 0);
vm.assume(end < type(uint48).max);
Expand Down Expand Up @@ -183,6 +194,7 @@ contract GetCurrentCycleTest is SpendPermissionManagerBase {
) public {
vm.assume(start > 0);
vm.assume(period > 0);
vm.assume(start < type(uint48).max);
vm.assume(uint256(start) + uint256(period) > type(uint48).max); // force overflow
vm.assume(allowance > 0);

Expand Down

0 comments on commit 14d9bab

Please sign in to comment.