Skip to content

Commit 0c36643

Browse files
committed
Add missing test functions from shop
1 parent 3b6c8db commit 0c36643

File tree

1 file changed

+82
-14
lines changed

1 file changed

+82
-14
lines changed

test/KeyperSetManager.t.sol

Lines changed: 82 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,17 @@ contract KeyperSetManagerTest is Test {
1010
KeyperSet public members0;
1111
KeyperSet public members1;
1212
address public owner;
13+
address public dao;
14+
address public sequencer;
1315

1416
function setUp() public {
1517
owner = vm.addr(42);
18+
dao = address(420);
19+
sequencer = address(4200);
1620
vm.prank(owner);
1721
keyperSetManager = new KeyperSetManager(owner);
1822
vm.prank(owner);
19-
keyperSetManager.initialize(owner, owner);
23+
keyperSetManager.initialize(dao, sequencer);
2024
members0 = new KeyperSet();
2125
members0.setFinalized();
2226
members1 = new KeyperSet();
@@ -25,10 +29,10 @@ contract KeyperSetManagerTest is Test {
2529

2630
function testGetNumKeyperSets() public {
2731
assertEq(keyperSetManager.getNumKeyperSets(), 0);
28-
vm.prank(owner);
32+
vm.prank(dao);
2933
keyperSetManager.addKeyperSet(1, address(members0));
3034
assertEq(keyperSetManager.getNumKeyperSets(), 1);
31-
vm.prank(owner);
35+
vm.prank(dao);
3236
keyperSetManager.addKeyperSet(2, address(members0));
3337
assertEq(keyperSetManager.getNumKeyperSets(), 2);
3438
}
@@ -48,17 +52,17 @@ contract KeyperSetManagerTest is Test {
4852
function testAddKeyperSetRequiresFinalizedSet() public {
4953
KeyperSet ks = new KeyperSet();
5054
vm.expectRevert(KeyperSetNotFinalized.selector);
51-
vm.prank(owner);
55+
vm.prank(dao);
5256
keyperSetManager.addKeyperSet(0, address(ks));
5357
}
5458

5559
function testAddKeyperSetRequiresIncreasingActivationBlock() public {
56-
vm.prank(owner);
60+
vm.prank(dao);
5761
keyperSetManager.addKeyperSet(1000, address(members0));
5862
vm.expectRevert(AlreadyHaveKeyperSet.selector);
59-
vm.prank(owner);
63+
vm.prank(dao);
6064
keyperSetManager.addKeyperSet(999, address(members1));
61-
vm.prank(owner);
65+
vm.prank(dao);
6266
keyperSetManager.addKeyperSet(1000, address(members1));
6367
}
6468

@@ -80,7 +84,7 @@ contract KeyperSetManagerTest is Test {
8084
0,
8185
0
8286
);
83-
vm.prank(owner);
87+
vm.prank(dao);
8488
keyperSetManager.addKeyperSet(
8589
1000,
8690
address(members0)
@@ -93,9 +97,9 @@ contract KeyperSetManagerTest is Test {
9397
}
9498

9599
function testGetKeyperSetIndexByBlock() public {
96-
vm.prank(owner);
100+
vm.prank(dao);
97101
keyperSetManager.addKeyperSet(1000, address(members0));
98-
vm.prank(owner);
102+
vm.prank(dao);
99103
keyperSetManager.addKeyperSet(1100, address(members1));
100104

101105
vm.expectRevert(NoActiveKeyperSet.selector);
@@ -112,20 +116,84 @@ contract KeyperSetManagerTest is Test {
112116
}
113117

114118
function testGetKeyperSetActivationBlock() public {
115-
vm.prank(owner);
119+
vm.prank(dao);
116120
keyperSetManager.addKeyperSet(1000, address(members0));
117-
vm.prank(owner);
121+
vm.prank(dao);
118122
keyperSetManager.addKeyperSet(1100, address(members1));
119123
assertEq(keyperSetManager.getKeyperSetActivationBlock(0), 1000);
120124
assertEq(keyperSetManager.getKeyperSetActivationBlock(1), 1100);
121125
}
122126

123127
function testGetKeyperSetAddress() public {
124-
vm.prank(owner);
128+
vm.prank(dao);
125129
keyperSetManager.addKeyperSet(1000, address(members0));
126-
vm.prank(owner);
130+
vm.prank(dao);
127131
keyperSetManager.addKeyperSet(1100, address(members1));
128132
assertEq(keyperSetManager.getKeyperSetAddress(0), address(members0));
129133
assertEq(keyperSetManager.getKeyperSetAddress(1), address(members1));
130134
}
135+
136+
function testAddKeyperSetRequiresFutureActivationBlock() public {
137+
vm.prank(dao);
138+
keyperSetManager.addKeyperSet(10, address(members0));
139+
vm.roll(15);
140+
uint64 currentEon = keyperSetManager.getKeyperSetIndexByBlock(15);
141+
assertEq(10, keyperSetManager.getKeyperSetActivationBlock(currentEon));
142+
vm.prank(dao);
143+
vm.expectRevert(AlreadyHaveKeyperSet.selector);
144+
keyperSetManager.addKeyperSet(15, address(members1));
145+
vm.prank(dao);
146+
keyperSetManager.addKeyperSet(16, address(members1));
147+
}
148+
149+
function testPauseShutter() public {
150+
bytes32 pauserRole = keyperSetManager.PAUSER_ROLE();
151+
address unauthorized = address(777);
152+
vm.startPrank(unauthorized);
153+
vm.expectRevert(
154+
abi.encodeWithSelector(
155+
IAccessControl.AccessControlUnauthorizedAccount.selector,
156+
unauthorized,
157+
pauserRole
158+
)
159+
);
160+
keyperSetManager.pause();
161+
vm.startPrank(address(2));
162+
vm.expectRevert(
163+
abi.encodeWithSelector(
164+
IAccessControl.AccessControlUnauthorizedAccount.selector,
165+
address(2),
166+
pauserRole
167+
)
168+
);
169+
keyperSetManager.pause();
170+
171+
vm.startPrank(sequencer);
172+
keyperSetManager.pause();
173+
assert(keyperSetManager.paused());
174+
vm.expectRevert(Pausable.EnforcedPause.selector);
175+
keyperSetManager.pause();
176+
}
177+
178+
function testUnpauseShutter() public {
179+
bytes32 adminRole = keyperSetManager.DEFAULT_ADMIN_ROLE();
180+
181+
vm.startPrank(sequencer);
182+
keyperSetManager.pause();
183+
assert(keyperSetManager.paused());
184+
vm.expectRevert(
185+
abi.encodeWithSelector(
186+
IAccessControl.AccessControlUnauthorizedAccount.selector,
187+
sequencer,
188+
adminRole
189+
)
190+
);
191+
keyperSetManager.unpause();
192+
193+
vm.startPrank(dao);
194+
keyperSetManager.unpause();
195+
assert(!keyperSetManager.paused());
196+
vm.expectRevert(Pausable.ExpectedPause.selector);
197+
keyperSetManager.unpause();
198+
}
131199
}

0 commit comments

Comments
 (0)