Skip to content

Commit 71b7b58

Browse files
committed
test: add release by index tests
1 parent 010da1f commit 71b7b58

File tree

1 file changed

+103
-41
lines changed

1 file changed

+103
-41
lines changed

src/test/unit/SlashEscrowFactoryUnit.t.sol

Lines changed: 103 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ contract SlashEscrowFactoryUnitTests is EigenLayerUnitTestSetup, ISlashEscrowFac
7373
return factory.getPendingUnderlyingAmountForStrategy(operatorSet, slashId, strategy);
7474
}
7575

76-
/// @dev Starts a burn or redistribution for a given strategy and token.
76+
/// @dev Starts a escrow for a given strategy and token.
7777
/// - Calls as the `StrategyManager`.
7878
/// - Asserts that the `StartEscrow` event is emitted.
7979
/// - Mocks the strategy sending the underlying token to the `SlashEscrow`.
@@ -111,16 +111,18 @@ contract SlashEscrowFactoryUnitTests is EigenLayerUnitTestSetup, ISlashEscrowFac
111111
assertTrue(slashEscrow.verifyDeploymentParameters(factory, slashEscrowImplementation, operatorSet, slashId));
112112
}
113113

114+
/// @dev Calls the `releaseSlashEscrow` function as the redistribution recipient.
115+
/// - Asserts that the `Escrow` event is emitted
114116
function _releaseSlashEscrowByIndex(OperatorSet memory operatorSet, uint slashId, uint index) internal {
115117
(IStrategy[] memory strategies) = factory.getPendingStrategiesForSlashId(operatorSet, slashId);
116118

117119
address redistributionRecipient = allocationManagerMock.getRedistributionRecipient(operatorSet);
118120

119121
cheats.expectEmit(true, true, true, true);
120-
emit EscrowComplete(operatorSet, slashId, strategies[index], defaultRedistributionRecipient);
122+
emit EscrowComplete(operatorSet, slashId, strategies[index], redistributionRecipient);
121123

122124
// If the redistribution recipient is any address
123-
if (redistributionRecipient != DEFAULT_BURN_ADDRESS) cheats.prank(defaultRedistributionRecipient);
125+
if (redistributionRecipient != DEFAULT_BURN_ADDRESS) cheats.prank(redistributionRecipient);
124126
else cheats.prank(cheats.randomAddress());
125127
factory.releaseSlashEscrowByIndex(operatorSet, slashId, index);
126128

@@ -131,7 +133,7 @@ contract SlashEscrowFactoryUnitTests is EigenLayerUnitTestSetup, ISlashEscrowFac
131133
assertTrue(slashEscrow.verifyDeploymentParameters(factory, slashEscrowImplementation, operatorSet, slashId));
132134
}
133135

134-
/// @dev Asserts that the operator set and slash ID are pending, and that the strategy and underlying amount are in the pending burn or redistributions.
136+
/// @dev Asserts that the operator set and slash ID are pending, and that the strategy and underlying amount are in the pending escrows.
135137
function _checkStartEscrows(
136138
OperatorSet memory operatorSet,
137139
uint slashId,
@@ -152,7 +154,7 @@ contract SlashEscrowFactoryUnitTests is EigenLayerUnitTestSetup, ISlashEscrowFac
152154
// Assert that the underlying amount in escrow for the (operator set, slash ID, strategy) is correct.
153155
assertEq(_getPendingUnderlyingAmountForStrategy(operatorSet, slashId, strategy, token), expectedUnderlyingAmount);
154156

155-
// Assert that the number of pending burn or redistributions is correct.
157+
// Assert that the number of pending escrows is correct.
156158
(IStrategy[] memory strategies) = factory.getPendingStrategiesForSlashId(operatorSet, slashId);
157159

158160
assertEq(strategies.length, expectedCount);
@@ -189,16 +191,16 @@ contract SlashEscrowFactoryUnitTests_initiateSlashEscrow is SlashEscrowFactoryUn
189191
function testFuzz_initiateSlashEscrow_multipleStrategies(uint r) public {
190192
// Initialize arrays to store test data for multiple strategies
191193
uint numStrategies = bound(r, 2, 10);
192-
// Set up each strategy with random data and start burn/redistribution
194+
// Set up each strategy with random data and start escrow
193195
for (uint i = 0; i < numStrategies; i++) {
194196
// Generate random strategy address and token
195197
IStrategy strategy = IStrategy(cheats.randomAddress());
196198
MockERC20 token = new MockERC20();
197199
uint underlyingAmount = cheats.randomUint();
198200

199-
// Start burn/redistribution for this strategy
201+
// Start escrow for this strategy
200202
_initiateSlashEscrow(defaultOperatorSet, defaultSlashId, strategy, token, underlyingAmount);
201-
// Verify the burn/redistribution was started correctly
203+
// Verify the escrow was started correctly
202204
_checkStartEscrows(defaultOperatorSet, defaultSlashId, strategy, token, underlyingAmount, i + 1);
203205
}
204206
}
@@ -261,31 +263,31 @@ contract SlashEscrowFactoryUnitTests_releaseSlashEscrow is SlashEscrowFactoryUni
261263
MockERC20[] memory tokens = new MockERC20[](numStrategies);
262264
uint[] memory underlyingAmounts = new uint[](numStrategies);
263265

264-
// Randomly update the redistribution to be the default burn address
265-
_setRedistributionRecipient(r % 2 == 0);
266+
// // Randomly update the redistribution to be the default burn address
267+
// _setRedistributionRecipient(r % 2 == 0);
266268

267-
// Set up each strategy with random data and start burn/redistribution
269+
// Set up each strategy with random data and start escrow
268270
for (uint i = 0; i < numStrategies; i++) {
269271
// Generate random strategy address and token
270272
strategies[i] = IStrategy(cheats.randomAddress());
271273
tokens[i] = new MockERC20();
272274
underlyingAmounts[i] = cheats.randomUint();
273275

274-
// Start burn/redistribution for this strategy
276+
// Start escrow for this strategy
275277
_initiateSlashEscrow(defaultOperatorSet, defaultSlashId, strategies[i], tokens[i], underlyingAmounts[i]);
276-
// Verify the burn/redistribution was started correctly
278+
// Verify the escrow was started correctly
277279
_checkStartEscrows(defaultOperatorSet, defaultSlashId, strategies[i], tokens[i], underlyingAmounts[i], i + 1);
278280
}
279281

280-
// Advance time to allow burn/redistribution to occur
282+
// Advance time to allow escrow to occur
281283
_rollForwardDefaultEscrowDelay();
282284

283285
// Set up mock calls for each strategy's underlying token
284286
for (uint i = numStrategies; i > 0; i--) {
285287
_mockStrategyUnderlyingTokenCall(strategies[i - 1], address(tokens[i - 1]));
286288
}
287289

288-
// Execute the burn/redistribution
290+
// Execute the escrow
289291
_releaseSlashEscrow(defaultOperatorSet, defaultSlashId);
290292

291293
// Checks
@@ -296,7 +298,7 @@ contract SlashEscrowFactoryUnitTests_releaseSlashEscrow is SlashEscrowFactoryUni
296298
assertEq(factory.getTotalPendingOperatorSets(), 0);
297299
assertEq(factory.getTotalPendingSlashIds(defaultOperatorSet), 0);
298300

299-
// Assert that the strategies and underlying amounts are no longer in the pending burn or redistributions.
301+
// Assert that the strategies and underlying amounts are no longer in the pending escrows.
300302
assertEq(factory.getTotalPendingStrategiesForSlashId(defaultOperatorSet, defaultSlashId), 0);
301303

302304
// Assert that the underlying amounts are no longer set.
@@ -338,9 +340,9 @@ contract SlashEscrowFactoryUnitTests_releaseSlashEscrow is SlashEscrowFactoryUni
338340
cheats.prank(defaultOwner);
339341
factory.setStrategyEscrowDelay(strategies[i], delays[i]);
340342

341-
// Start burn/redistribution for this strategy
343+
// Start escrow for this strategy
342344
_initiateSlashEscrow(defaultOperatorSet, defaultSlashId, strategies[i], tokens[i], underlyingAmounts[i]);
343-
// Verify the burn/redistribution was started correctly
345+
// Verify the escrow was started correctly
344346
_checkStartEscrows(defaultOperatorSet, defaultSlashId, strategies[i], tokens[i], underlyingAmounts[i], i + 1);
345347
}
346348

@@ -358,7 +360,7 @@ contract SlashEscrowFactoryUnitTests_releaseSlashEscrow is SlashEscrowFactoryUni
358360
_mockStrategyUnderlyingTokenCall(strategies[i], address(tokens[i]));
359361
}
360362

361-
// Execute the burn/redistribution
363+
// Execute the escrow
362364
_releaseSlashEscrow(defaultOperatorSet, defaultSlashId);
363365

364366
// Verify that all strategies have been processed
@@ -392,9 +394,9 @@ contract SlashEscrowFactoryUnitTests_releaseSlashEscrow is SlashEscrowFactoryUni
392394

393395
// Set up numEscrows slash escrows for the same operator set
394396
for (uint i = 0; i < numEscrows; i++) {
395-
// Start burn/redistribution for this slash
397+
// Start escrow for this slash
396398
_initiateSlashEscrow(defaultOperatorSet, defaultSlashId + i, strategies[0], tokens[0], underlyingAmounts[0]);
397-
// Verify the burn/redistribution was started correctly
399+
// Verify the escrow was started correctly
398400
_checkStartEscrows(defaultOperatorSet, defaultSlashId + i, strategies[0], tokens[0], underlyingAmounts[0], 1);
399401
}
400402

@@ -475,7 +477,7 @@ contract SlashEscrowFactoryUnitTests_releaseSlashEscrowByIndex is SlashEscrowFac
475477
}
476478

477479
/// @dev Tests that multiple strategies can be burned or redistributed across multiple calls
478-
function testFuzz_releaseSlashEscrow_multipleStrategies_sameDelay(uint r) public {
480+
function testFuzz_releaseSlashEscrowByIndex__multipleStrategies_sameDelay(uint r) public {
479481
// Initialize arrays to store test data for multiple strategies
480482
uint numStrategies = bound(r, 2, 10);
481483
IStrategy[] memory strategies = new IStrategy[](numStrategies);
@@ -485,20 +487,20 @@ contract SlashEscrowFactoryUnitTests_releaseSlashEscrowByIndex is SlashEscrowFac
485487
// Randomly update the redistribution to be the default burn address
486488
_setRedistributionRecipient(r % 2 == 0);
487489

488-
// Set up each strategy with random data and start burn/redistribution
490+
// Set up each strategy with random data and start escrow
489491
for (uint i = 0; i < numStrategies; i++) {
490492
// Generate random strategy address and token
491493
strategies[i] = IStrategy(cheats.randomAddress());
492494
tokens[i] = new MockERC20();
493495
underlyingAmounts[i] = cheats.randomUint();
494496

495-
// Start burn/redistribution for this strategy
497+
// Start escrow for this strategy
496498
_initiateSlashEscrow(defaultOperatorSet, defaultSlashId, strategies[i], tokens[i], underlyingAmounts[i]);
497-
// Verify the burn/redistribution was started correctly
499+
// Verify the escrow was started correctly
498500
_checkStartEscrows(defaultOperatorSet, defaultSlashId, strategies[i], tokens[i], underlyingAmounts[i], i + 1);
499501
}
500502

501-
// Advance time to allow burn/redistribution to occur
503+
// Advance time to allow escrow to occur
502504
_rollForwardDefaultEscrowDelay();
503505

504506
// Set up mock calls for each strategy's underlying token
@@ -516,7 +518,7 @@ contract SlashEscrowFactoryUnitTests_releaseSlashEscrowByIndex is SlashEscrowFac
516518
assertTrue(factory.isPendingSlashId(defaultOperatorSet, defaultSlashId));
517519
assertEq(factory.getTotalPendingOperatorSets(), 1);
518520
assertEq(factory.getTotalPendingSlashIds(defaultOperatorSet), 1);
519-
assertEq(factory.getTotalPendingStrategiesForSlashId(defaultOperatorSet, defaultSlashId), numStrategies - 1);
521+
assertEq(factory.getTotalPendingStrategiesForSlashId(defaultOperatorSet, defaultSlashId), 1);
520522

521523
// Release the last slash escrow
522524
_releaseSlashEscrowByIndex(defaultOperatorSet, defaultSlashId, 0);
@@ -529,7 +531,67 @@ contract SlashEscrowFactoryUnitTests_releaseSlashEscrowByIndex is SlashEscrowFac
529531
assertEq(factory.getTotalPendingOperatorSets(), 0);
530532
assertEq(factory.getTotalPendingSlashIds(defaultOperatorSet), 0);
531533

532-
// Assert that the strategies and underlying amounts are no longer in the pending burn or redistributions.
534+
// Assert that the strategies and underlying amounts are no longer in the pending escrows.
535+
assertEq(factory.getTotalPendingStrategiesForSlashId(defaultOperatorSet, defaultSlashId), 0);
536+
537+
// Assert that the underlying amounts are no longer set.
538+
for (uint i = numStrategies; i > 0; i--) {
539+
assertEq(_getPendingUnderlyingAmountForStrategy(defaultOperatorSet, defaultSlashId, strategies[i - 1], tokens[i - 1]), 0);
540+
}
541+
542+
// Assert that the start block for the (operator set, slash ID) is no longer set.
543+
assertEq(factory.getEscrowStartBlock(defaultOperatorSet, defaultSlashId), 0);
544+
}
545+
546+
/// @dev Tests that multiple strategies can be burned or redistributed across multiple calls
547+
function testFuzz_releaseSlashEscrowByIndex__multipleStrategies_byIndexThenAll(uint r) public {
548+
// Initialize arrays to store test data for multiple strategies
549+
uint numStrategies = bound(r, 2, 10);
550+
IStrategy[] memory strategies = new IStrategy[](numStrategies);
551+
MockERC20[] memory tokens = new MockERC20[](numStrategies);
552+
uint[] memory underlyingAmounts = new uint[](numStrategies);
553+
554+
// Randomly update the redistribution to be the default burn address
555+
_setRedistributionRecipient(r % 2 == 0);
556+
557+
// Set up each strategy with random data and start escrow
558+
for (uint i = 0; i < numStrategies; i++) {
559+
// Generate random strategy address and token
560+
strategies[i] = IStrategy(cheats.randomAddress());
561+
tokens[i] = new MockERC20();
562+
underlyingAmounts[i] = cheats.randomUint();
563+
564+
// Start escrow for this strategy
565+
_initiateSlashEscrow(defaultOperatorSet, defaultSlashId, strategies[i], tokens[i], underlyingAmounts[i]);
566+
// Verify the escrow was started correctly
567+
_checkStartEscrows(defaultOperatorSet, defaultSlashId, strategies[i], tokens[i], underlyingAmounts[i], i + 1);
568+
}
569+
570+
// Advance time to allow escrow to occur
571+
_rollForwardDefaultEscrowDelay();
572+
573+
// Release the first index
574+
_releaseSlashEscrowByIndex(defaultOperatorSet, defaultSlashId, 0);
575+
576+
// Assert that the slashId and operatorSet are still pending
577+
assertTrue(factory.isPendingOperatorSet(defaultOperatorSet));
578+
assertTrue(factory.isPendingSlashId(defaultOperatorSet, defaultSlashId));
579+
assertEq(factory.getTotalPendingOperatorSets(), 1);
580+
assertEq(factory.getTotalPendingSlashIds(defaultOperatorSet), 1);
581+
assertEq(factory.getTotalPendingStrategiesForSlashId(defaultOperatorSet, defaultSlashId), numStrategies - 1);
582+
583+
// Release remaining
584+
_releaseSlashEscrow(defaultOperatorSet, defaultSlashId);
585+
586+
// Checks
587+
588+
// Assert that the operator set and slash ID are no longer pending.
589+
assertFalse(factory.isPendingOperatorSet(defaultOperatorSet));
590+
assertFalse(factory.isPendingSlashId(defaultOperatorSet, defaultSlashId));
591+
assertEq(factory.getTotalPendingOperatorSets(), 0);
592+
assertEq(factory.getTotalPendingSlashIds(defaultOperatorSet), 0);
593+
594+
// Assert that the strategies and underlying amounts are no longer in the pending escrows.
533595
assertEq(factory.getTotalPendingStrategiesForSlashId(defaultOperatorSet, defaultSlashId), 0);
534596

535597
// Assert that the underlying amounts are no longer set.
@@ -639,9 +701,9 @@ contract SlashEscrowFactoryUnitTests_getBurnOrRedistributionDelay is SlashEscrow
639701
cheats.prank(defaultOwner);
640702
factory.setStrategyEscrowDelay(strategies[i], delays[i]);
641703

642-
// Start burn/redistribution for this strategy
704+
// Start escrow for this strategy
643705
_initiateSlashEscrow(defaultOperatorSet, defaultSlashId, strategies[i], tokens[i], underlyingAmounts[i]);
644-
// Verify the burn/redistribution was started correctly
706+
// Verify the escrow was started correctly
645707
_checkStartEscrows(defaultOperatorSet, defaultSlashId, strategies[i], tokens[i], underlyingAmounts[i], i + 1);
646708
}
647709

@@ -677,9 +739,9 @@ contract SlashEscrowFactoryUnitTests_getEscrowDelay is SlashEscrowFactoryUnitTes
677739
cheats.prank(defaultOwner);
678740
factory.setStrategyEscrowDelay(strategies[i], delays[i]);
679741

680-
// Start burn/redistribution for this strategy
742+
// Start escrow for this strategy
681743
_initiateSlashEscrow(defaultOperatorSet, defaultSlashId, strategies[i], tokens[i], underlyingAmounts[i]);
682-
// Verify the burn/redistribution was started correctly
744+
// Verify the escrow was started correctly
683745
_checkStartEscrows(defaultOperatorSet, defaultSlashId, strategies[i], tokens[i], underlyingAmounts[i], i + 1);
684746
}
685747

@@ -706,10 +768,10 @@ contract SlashEscrowFactoryUnitTests_setGlobalEscrowDelay is SlashEscrowFactoryU
706768

707769
contract SlashEscrowFactoryUnitTests_getPendingEscrows is SlashEscrowFactoryUnitTests {
708770
function test_getPendingEscrows_singleSlashId() public {
709-
// Start burn/redistribution for a single strategy
771+
// Start escrow for a single strategy
710772
_initiateSlashEscrow(defaultOperatorSet, defaultSlashId, defaultStrategy, defaultToken, 100);
711773

712-
// Get pending burn/redistributions for the specific slash ID
774+
// Get pending escrows for the specific slash ID
713775
(IStrategy[] memory strategies) = factory.getPendingStrategiesForSlashId(defaultOperatorSet, defaultSlashId);
714776

715777
// Verify results
@@ -718,7 +780,7 @@ contract SlashEscrowFactoryUnitTests_getPendingEscrows is SlashEscrowFactoryUnit
718780
}
719781

720782
function test_getPendingEscrows_multipleStrategies() public {
721-
// Create multiple strategies and start burn/redistributions
783+
// Create multiple strategies and start escrows
722784
IStrategy strategy1 = IStrategy(cheats.randomAddress());
723785
IStrategy strategy2 = IStrategy(cheats.randomAddress());
724786
MockERC20 token1 = new MockERC20();
@@ -727,7 +789,7 @@ contract SlashEscrowFactoryUnitTests_getPendingEscrows is SlashEscrowFactoryUnit
727789
_initiateSlashEscrow(defaultOperatorSet, defaultSlashId, strategy1, token1, 100);
728790
_initiateSlashEscrow(defaultOperatorSet, defaultSlashId, strategy2, token2, 200);
729791

730-
// Get pending burn/redistributions for the specific slash ID
792+
// Get pending escrows for the specific slash ID
731793
(IStrategy[] memory strategies) = factory.getPendingStrategiesForSlashId(defaultOperatorSet, defaultSlashId);
732794

733795
// Verify results
@@ -747,11 +809,11 @@ contract SlashEscrowFactoryUnitTests_getPendingEscrows is SlashEscrowFactoryUnit
747809
MockERC20 token1 = new MockERC20();
748810
MockERC20 token2 = new MockERC20();
749811

750-
// Start burn/redistributions for different slash IDs
812+
// Start escrows for different slash IDs
751813
_initiateSlashEscrow(defaultOperatorSet, slashId1, strategy1, token1, 100);
752814
_initiateSlashEscrow(defaultOperatorSet, slashId2, strategy2, token2, 200);
753815

754-
// Get pending burn/redistributions for all slash IDs of the operator set
816+
// Get pending escrows for all slash IDs of the operator set
755817
(IStrategy[][] memory strategies) = factory.getPendingStrategiesForSlashIds(defaultOperatorSet);
756818

757819
// Verify results
@@ -769,7 +831,7 @@ contract SlashEscrowFactoryUnitTests_getPendingEscrows is SlashEscrowFactoryUnit
769831
}
770832

771833
function test_getPendingEscrows_empty() public {
772-
// Test with no pending burn/redistributions
834+
// Test with no pending escrows
773835
(IStrategy[] memory strategies) = factory.getPendingStrategiesForSlashId(defaultOperatorSet, defaultSlashId);
774836
assertEq(strategies.length, 0);
775837

@@ -811,9 +873,9 @@ contract SlashEscrowFactoryUnitTests_getEscrowCompleteBlock is SlashEscrowFactor
811873
cheats.prank(defaultOwner);
812874
factory.setStrategyEscrowDelay(strategies[i], delays[i]);
813875

814-
// Start burn/redistribution for this strategy
876+
// Start escrow for this strategy
815877
_initiateSlashEscrow(defaultOperatorSet, defaultSlashId, strategies[i], tokens[i], underlyingAmounts[i]);
816-
// Verify the burn/redistribution was started correctly
878+
// Verify the escrow was started correctly
817879
_checkStartEscrows(defaultOperatorSet, defaultSlashId, strategies[i], tokens[i], underlyingAmounts[i], i + 1);
818880
}
819881

0 commit comments

Comments
 (0)