@@ -13,7 +13,8 @@ contract SnapShotExecutorTest is Test {
13
13
14
14
address owner = vm.addr (1 );
15
15
address oracle = vm.addr (2 );
16
- address alice = vm.addr (3 );
16
+ address newOracle = vm.addr (3 );
17
+ address alice = vm.addr (4 );
17
18
18
19
BorgAuth auth;
19
20
SnapShotExecutor snapShotExecutor;
@@ -29,7 +30,8 @@ contract SnapShotExecutorTest is Test {
29
30
oracle,
30
31
3 days, // waitingPeriod
31
32
2 days, // cancelPeriod
32
- 3 // pendingProposalLimit
33
+ 3 , // pendingProposalLimit
34
+ 30 days // ttl
33
35
);
34
36
35
37
// Transferring auth ownership
@@ -40,10 +42,13 @@ contract SnapShotExecutorTest is Test {
40
42
/// @dev Metadata should meet specs
41
43
function testMeta () public view {
42
44
assertEq (snapShotExecutor.oracle (), oracle, "Unexpected oracle address " );
45
+ assertEq (snapShotExecutor.pendingOracle (), address (0 ), "Unexpected pending oracle address " );
43
46
assertEq (snapShotExecutor.waitingPeriod (), 3 days, "Unexpected waitingPeriod " );
44
47
assertEq (snapShotExecutor.cancelPeriod (), 2 days, "Unexpected cancelPeriod " );
45
48
assertEq (snapShotExecutor.pendingProposalCount (), 0 , "Unexpected pendingProposalCount " );
46
49
assertEq (snapShotExecutor.pendingProposalLimit (), 3 , "Unexpected pendingProposalLimit " );
50
+ assertEq (snapShotExecutor.ORACLE_TTL (), 30 days, "Unexpected ORACLE_TTL " );
51
+ assertEq (snapShotExecutor.lastOraclePingTimestamp (), block .timestamp , "Unexpected lastOraclePingTimestamp " );
47
52
}
48
53
49
54
/// @dev BorgAuth instances should be properly assigned and configured
@@ -203,4 +208,63 @@ contract SnapShotExecutorTest is Test {
203
208
204
209
vm.stopPrank ();
205
210
}
211
+
212
+ /// @dev Ping timestamp should update when oracle is working
213
+ function testPing () public {
214
+ uint256 lastOraclePingTimestamp = snapShotExecutor.lastOraclePingTimestamp ();
215
+
216
+ // Non-oracle shouldn't be able to ping
217
+ vm.expectRevert (abi.encodeWithSelector (SnapShotExecutor.SnapShotExecutor_NotAuthorized.selector ));
218
+ snapShotExecutor.ping ();
219
+
220
+ // Last timestamp should update after a successful ping
221
+ skip (1 days);
222
+ vm.prank (oracle);
223
+ snapShotExecutor.ping ();
224
+ assertEq (snapShotExecutor.lastOraclePingTimestamp (), lastOraclePingTimestamp + 1 days);
225
+
226
+ // Propose should also ping
227
+ skip (1 days);
228
+ vm.prank (oracle);
229
+ snapShotExecutor.propose (
230
+ address (alice), // target
231
+ 0 , // value
232
+ "" , // cdata
233
+ "Arbitrary instruction "
234
+ );
235
+ assertEq (snapShotExecutor.lastOraclePingTimestamp (), lastOraclePingTimestamp + 2 days);
236
+ }
237
+
238
+ /// @dev Owner should be able to replace oracle if it's dead
239
+ function testTransferOracle () public {
240
+ skip (snapShotExecutor.ORACLE_TTL ());
241
+ vm.prank (owner);
242
+ snapShotExecutor.transferOracle (newOracle);
243
+
244
+ // Old oracle should still work when the transfer is pending
245
+ vm.prank (oracle);
246
+ snapShotExecutor.ping ();
247
+ assertEq (snapShotExecutor.oracle (), oracle);
248
+
249
+ // Non-oracle should still be unauthorized
250
+ vm.expectRevert (abi.encodeWithSelector (SnapShotExecutor.SnapShotExecutor_NotAuthorized.selector ));
251
+ snapShotExecutor.ping ();
252
+
253
+ // Transfer should be done after the new oracle interacts
254
+ vm.prank (newOracle);
255
+ snapShotExecutor.ping ();
256
+ assertEq (snapShotExecutor.oracle (), newOracle);
257
+ assertEq (snapShotExecutor.pendingOracle (), address (0 ));
258
+ // Old oracle should no longer be authorized
259
+ vm.expectRevert (abi.encodeWithSelector (SnapShotExecutor.SnapShotExecutor_NotAuthorized.selector ));
260
+ vm.prank (oracle);
261
+ snapShotExecutor.ping ();
262
+ }
263
+
264
+ /// @dev Owner should not be able to replace oracle if it's not dead
265
+ function test_RevertIf_SetOracleNotDead () public {
266
+ vm.expectRevert (abi.encodeWithSelector (SnapShotExecutor.SnapShotExecutor_OracleNotDead.selector ));
267
+ vm.prank (owner);
268
+ snapShotExecutor.transferOracle (newOracle);
269
+ }
206
270
}
0 commit comments