Skip to content

Commit a354306

Browse files
more tests
1 parent c446f6b commit a354306

File tree

3 files changed

+35
-6
lines changed

3 files changed

+35
-6
lines changed

src/abstract/OwnerFreezable.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ abstract contract OwnerFreezable is Ownable, IOwnerFreezableV1 {
105105
// Emit the event with the new protected time. We do this even if the
106106
// protected time is unchanged so that we can track the history of
107107
// protections offchain.
108-
emit OwnerFreezeAlwaysAllowedFrom(owner(), from, protectUntil);
108+
emit OwnerFreezeAlwaysAllowedFrom(owner(), from, protectUntil, sAlwaysAllowedFroms[from]);
109109
}
110110

111111
/// @inheritdoc IOwnerFreezableV1
@@ -117,7 +117,7 @@ abstract contract OwnerFreezable is Ownable, IOwnerFreezableV1 {
117117
}
118118

119119
delete sAlwaysAllowedFroms[from];
120-
emit OwnerFreezeAlwaysAllowedFrom(owner(), from, 0);
120+
emit OwnerFreezeAlwaysAllowedFrom(owner(), from, 0, 0);
121121
}
122122

123123
/// @inheritdoc IOwnerFreezableV1

src/interface/IOwnerFreezableV1.sol

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,14 @@ interface IOwnerFreezableV1 is IERC5313 {
4848
/// Owner added a `from` address to the always allowed list.
4949
/// @param owner The address of the owner.
5050
/// @param from The address that is always allowed to send.
51+
/// @param targetProtectedUntil The timestamp the owner attempted to protect
52+
/// the `from` until. Can be less than the actual protection if a previous
53+
/// call already set it higher.
5154
/// @param protectedUntil The timestamp until the `from` address is unable to
5255
/// be removed from the always allowed list.
53-
event OwnerFreezeAlwaysAllowedFrom(address owner, address from, uint256 protectedUntil);
56+
event OwnerFreezeAlwaysAllowedFrom(
57+
address owner, address from, uint256 targetProtectedUntil, uint256 protectedUntil
58+
);
5459

5560
/// Owner added a `to` address to the always allowed list.
5661
/// @param owner The address of the owner.

test/abstract/OwnerFreezableOwnerFreezeUntilTest.sol

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@ abstract contract OwnerFreezableOwnerFreezeUntilTest is Test {
2121
assertEq(sOwnerFreezable.ownerFrozenUntil(), expectedFreeze);
2222
}
2323

24+
function checkOwnerFreezeAlwaysAllowFrom(address from, uint256 protectUntil, uint256 expectedProtect) internal {
25+
vm.prank(sAlice);
26+
vm.expectEmit(true, true, true, true);
27+
emit IOwnerFreezableV1.OwnerFreezeAlwaysAllowedFrom(sAlice, from, protectUntil, expectedProtect);
28+
sOwnerFreezable.ownerFreezeAlwaysAllowFrom(from, protectUntil);
29+
assertEq(sOwnerFreezable.ownerFreezeAlwaysAllowedFrom(from), expectedProtect);
30+
}
31+
2432
function testOwnerIsAlice() external {
2533
assertEq(sOwnerFreezable.owner(), sAlice);
2634
}
@@ -84,9 +92,7 @@ abstract contract OwnerFreezableOwnerFreezeUntilTest is Test {
8492
sOwnerFreezable.ownerFreezeAlwaysAllowFrom(from, protectUntil);
8593
assertEq(sOwnerFreezable.ownerFreezeAlwaysAllowedFrom(from), 0);
8694

87-
vm.prank(sAlice);
88-
sOwnerFreezable.ownerFreezeAlwaysAllowFrom(from, protectUntil);
89-
assertEq(sOwnerFreezable.ownerFreezeAlwaysAllowedFrom(from), protectUntil);
95+
checkOwnerFreezeAlwaysAllowFrom(from, protectUntil, protectUntil);
9096
}
9197

9298
/// Calling ownerFreezeAlwaysAllowFrom with a zero protectUntil reverts.
@@ -95,4 +101,22 @@ abstract contract OwnerFreezableOwnerFreezeUntilTest is Test {
95101
vm.prank(sAlice);
96102
sOwnerFreezable.ownerFreezeAlwaysAllowFrom(from, 0);
97103
}
104+
105+
/// Calling ownerFreezeAlwaysAllowFrom twice with increasing times always uses newer times.
106+
function testOwnerFreezableAlwaysAllowFromIncrement(address from, uint256 a, uint256 b) external {
107+
vm.assume(a != 0);
108+
b = bound(b, a, type(uint256).max);
109+
110+
checkOwnerFreezeAlwaysAllowFrom(from, a, a);
111+
checkOwnerFreezeAlwaysAllowFrom(from, b, b);
112+
}
113+
114+
/// Calling ownerFreezeAlwaysAllowFrom twice with decreasing times retains the first time.
115+
function testOwnerFreezableAlwaysAllowFromDecrement(address from, uint256 a, uint256 b) external {
116+
vm.assume(a != 0);
117+
b = bound(b, 1, a);
118+
119+
checkOwnerFreezeAlwaysAllowFrom(from, a, a);
120+
checkOwnerFreezeAlwaysAllowFrom(from, b, a);
121+
}
98122
}

0 commit comments

Comments
 (0)