Skip to content

Commit

Permalink
Add getLockTime() interface function
Browse files Browse the repository at this point in the history
  • Loading branch information
matejos committed Nov 14, 2023
1 parent 8b0d036 commit 48eafac
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
7 changes: 7 additions & 0 deletions evm/src/Hololocker.sol
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,13 @@ contract Hololocker is HololockerInterface, Ownable {
}
}

/// @notice Returns `lockTime`, which is the value that gets added to block.timestamp and saved as unlockTime
/// in the requestUnlock function.
/// @return The `lockTime` variable
function getLockTime() external view returns (uint256) {
return lockTime;
}

/// @notice Changes `lockTime` variable that is used in `requestUnlock`.
/// @dev Reverts if new value is greater than `MAXIMUM_LOCK_TIME`.
/// Emits `LockTimeUpdate` event.
Expand Down
5 changes: 5 additions & 0 deletions evm/src/HololockerInterface.sol
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ interface HololockerInterface is IERC721Receiver {
/// @param tokenIds NFT tokens identifiers
function withdraw(address[] memory tokens, uint256[] memory tokenIds) external;

/// @notice Returns `lockTime`, which is the value that gets added to block.timestamp and saved as unlockTime
/// in the requestUnlock function.
/// @return The `lockTime` variable
function getLockTime() external view returns (uint256);

/// @notice Changes `lockTime` variable that is used in `requestUnlock`.
/// @dev This function should be protected with appropriate access control mechanisms.
/// The new value should be checked against a sane upper limit constant, which if exceeded,
Expand Down
12 changes: 6 additions & 6 deletions evm/test/Hololocker.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ contract HololockerTest is Test {

vm.roll(block.number + 10);
vm.expectEmit(true, true, true, true);
emit Unlock(tokens[0], info.owner, tokenIds[0], info.operator, block.timestamp + hololocker.lockTime());
emit Unlock(tokens[0], info.owner, tokenIds[0], info.operator, block.timestamp + hololocker.getLockTime());
hololocker.requestUnlock(tokens, tokenIds);
info = hololocker.getLockInfo(tokens[0], tokenIds[0]);
assertEq(info.unlockTime, block.timestamp + hololocker.lockTime());
assertEq(info.unlockTime, block.timestamp + hololocker.getLockTime());
assertEq(info.owner, owner_);
assertEq(info.operator, operator_);

vm.warp(block.timestamp + hololocker.lockTime());
vm.warp(block.timestamp + hololocker.getLockTime());
vm.expectEmit(true, true, true, true);
emit Withdraw(tokens[0], info.owner, tokenIds[0], info.operator);
hololocker.withdraw(tokens, tokenIds);
Expand Down Expand Up @@ -104,7 +104,7 @@ contract HololockerTest is Test {
vm.expectEmit(true, true, true, true);
emit LockTimeUpdate(newValue);
hololocker.setLockTime(newValue);
assertEq(hololocker.lockTime(), newValue);
assertEq(hololocker.getLockTime(), newValue);
}

function test_CannotLockInvalidInputArity() public {
Expand Down Expand Up @@ -156,7 +156,7 @@ contract HololockerTest is Test {
function test_CannotWithdrawUnauthorized() public {
hololocker.lock(tokens, tokenIds, address(this));
hololocker.requestUnlock(tokens, tokenIds);
vm.warp(block.timestamp + hololocker.lockTime());
vm.warp(block.timestamp + hololocker.getLockTime());
vm.prank(alice);
vm.expectRevert(Hololocker.Unauthorized.selector);
hololocker.withdraw(tokens, tokenIds);
Expand All @@ -171,7 +171,7 @@ contract HololockerTest is Test {
function test_CannotWithdrawIfUnlockTimeNotReached() public {
hololocker.lock(tokens, tokenIds, address(this));
hololocker.requestUnlock(tokens, tokenIds);
vm.warp(block.timestamp + hololocker.lockTime() - 1);
vm.warp(block.timestamp + hololocker.getLockTime() - 1);
vm.expectRevert(Hololocker.NotUnlockedYet.selector);
hololocker.withdraw(tokens, tokenIds);
}
Expand Down

0 comments on commit 48eafac

Please sign in to comment.