Skip to content

Commit ef7ecd5

Browse files
committed
test: add release by index tests
1 parent 1a35bc4 commit ef7ecd5

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`.
@@ -105,16 +105,18 @@ contract SlashEscrowFactoryUnitTests is EigenLayerUnitTestSetup, ISlashEscrowFac
105105
factory.releaseSlashEscrow(operatorSet, slashId);
106106
}
107107

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

111113
address redistributionRecipient = allocationManagerMock.getRedistributionRecipient(operatorSet);
112114

113115
cheats.expectEmit(true, true, true, true);
114-
emit EscrowComplete(operatorSet, slashId, strategies[index], defaultRedistributionRecipient);
116+
emit EscrowComplete(operatorSet, slashId, strategies[index], redistributionRecipient);
115117

116118
// If the redistribution recipient is any address
117-
if (redistributionRecipient != DEFAULT_BURN_ADDRESS) cheats.prank(defaultRedistributionRecipient);
119+
if (redistributionRecipient != DEFAULT_BURN_ADDRESS) cheats.prank(redistributionRecipient);
118120
else cheats.prank(cheats.randomAddress());
119121
factory.releaseSlashEscrowByIndex(operatorSet, slashId, index);
120122

@@ -125,7 +127,7 @@ contract SlashEscrowFactoryUnitTests is EigenLayerUnitTestSetup, ISlashEscrowFac
125127
assertTrue(slashEscrow.verifyDeploymentParameters(factory, slashEscrowImplementation, operatorSet, slashId));
126128
}
127129

128-
/// @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.
130+
/// @dev Asserts that the operator set and slash ID are pending, and that the strategy and underlying amount are in the pending escrows.
129131
function _checkStartEscrows(
130132
OperatorSet memory operatorSet,
131133
uint slashId,
@@ -146,7 +148,7 @@ contract SlashEscrowFactoryUnitTests is EigenLayerUnitTestSetup, ISlashEscrowFac
146148
// Assert that the underlying amount in escrow for the (operator set, slash ID, strategy) is correct.
147149
assertEq(_getPendingUnderlyingAmountForStrategy(operatorSet, slashId, strategy, token), expectedUnderlyingAmount);
148150

149-
// Assert that the number of pending burn or redistributions is correct.
151+
// Assert that the number of pending escrows is correct.
150152
(IStrategy[] memory strategies) = factory.getPendingStrategiesForSlashId(operatorSet, slashId);
151153

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

200-
// Start burn/redistribution for this strategy
202+
// Start escrow for this strategy
201203
_initiateSlashEscrow(defaultOperatorSet, defaultSlashId, strategy, token, underlyingAmount);
202-
// Verify the burn/redistribution was started correctly
204+
// Verify the escrow was started correctly
203205
_checkStartEscrows(defaultOperatorSet, defaultSlashId, strategy, token, underlyingAmount, i + 1);
204206
}
205207
}
@@ -262,31 +264,31 @@ contract SlashEscrowFactoryUnitTests_releaseSlashEscrow is SlashEscrowFactoryUni
262264
MockERC20[] memory tokens = new MockERC20[](numStrategies);
263265
uint[] memory underlyingAmounts = new uint[](numStrategies);
264266

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

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

275-
// Start burn/redistribution for this strategy
277+
// Start escrow for this strategy
276278
_initiateSlashEscrow(defaultOperatorSet, defaultSlashId, strategies[i], tokens[i], underlyingAmounts[i]);
277-
// Verify the burn/redistribution was started correctly
279+
// Verify the escrow was started correctly
278280
_checkStartEscrows(defaultOperatorSet, defaultSlashId, strategies[i], tokens[i], underlyingAmounts[i], i + 1);
279281
}
280282

281-
// Advance time to allow burn/redistribution to occur
283+
// Advance time to allow escrow to occur
282284
_rollForwardDefaultEscrowDelay();
283285

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

289-
// Execute the burn/redistribution
291+
// Execute the escrow
290292
_releaseSlashEscrow(defaultOperatorSet, defaultSlashId);
291293

292294
// Checks
@@ -297,7 +299,7 @@ contract SlashEscrowFactoryUnitTests_releaseSlashEscrow is SlashEscrowFactoryUni
297299
assertEq(factory.getTotalPendingOperatorSets(), 0);
298300
assertEq(factory.getTotalPendingSlashIds(defaultOperatorSet), 0);
299301

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

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

342-
// Start burn/redistribution for this strategy
344+
// Start escrow for this strategy
343345
_initiateSlashEscrow(defaultOperatorSet, defaultSlashId, strategies[i], tokens[i], underlyingAmounts[i]);
344-
// Verify the burn/redistribution was started correctly
346+
// Verify the escrow was started correctly
345347
_checkStartEscrows(defaultOperatorSet, defaultSlashId, strategies[i], tokens[i], underlyingAmounts[i], i + 1);
346348
}
347349

@@ -359,7 +361,7 @@ contract SlashEscrowFactoryUnitTests_releaseSlashEscrow is SlashEscrowFactoryUni
359361
_mockStrategyUnderlyingTokenCall(strategies[i], address(tokens[i]));
360362
}
361363

362-
// Execute the burn/redistribution
364+
// Execute the escrow
363365
_releaseSlashEscrow(defaultOperatorSet, defaultSlashId);
364366

365367
// Verify that all strategies have been processed
@@ -393,9 +395,9 @@ contract SlashEscrowFactoryUnitTests_releaseSlashEscrow is SlashEscrowFactoryUni
393395

394396
// Set up numEscrows slash escrows for the same operator set
395397
for (uint i = 0; i < numEscrows; i++) {
396-
// Start burn/redistribution for this slash
398+
// Start escrow for this slash
397399
_initiateSlashEscrow(defaultOperatorSet, defaultSlashId + i, strategies[0], tokens[0], underlyingAmounts[0]);
398-
// Verify the burn/redistribution was started correctly
400+
// Verify the escrow was started correctly
399401
_checkStartEscrows(defaultOperatorSet, defaultSlashId + i, strategies[0], tokens[0], underlyingAmounts[0], 1);
400402
}
401403

@@ -476,7 +478,7 @@ contract SlashEscrowFactoryUnitTests_releaseSlashEscrowByIndex is SlashEscrowFac
476478
}
477479

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

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

496-
// Start burn/redistribution for this strategy
498+
// Start escrow for this strategy
497499
_initiateSlashEscrow(defaultOperatorSet, defaultSlashId, strategies[i], tokens[i], underlyingAmounts[i]);
498-
// Verify the burn/redistribution was started correctly
500+
// Verify the escrow was started correctly
499501
_checkStartEscrows(defaultOperatorSet, defaultSlashId, strategies[i], tokens[i], underlyingAmounts[i], i + 1);
500502
}
501503

502-
// Advance time to allow burn/redistribution to occur
504+
// Advance time to allow escrow to occur
503505
_rollForwardDefaultEscrowDelay();
504506

505507
// Set up mock calls for each strategy's underlying token
@@ -517,7 +519,7 @@ contract SlashEscrowFactoryUnitTests_releaseSlashEscrowByIndex is SlashEscrowFac
517519
assertTrue(factory.isPendingSlashId(defaultOperatorSet, defaultSlashId));
518520
assertEq(factory.getTotalPendingOperatorSets(), 1);
519521
assertEq(factory.getTotalPendingSlashIds(defaultOperatorSet), 1);
520-
assertEq(factory.getTotalPendingStrategiesForSlashId(defaultOperatorSet, defaultSlashId), numStrategies - 1);
522+
assertEq(factory.getTotalPendingStrategiesForSlashId(defaultOperatorSet, defaultSlashId), 1);
521523

522524
// Release the last slash escrow
523525
_releaseSlashEscrowByIndex(defaultOperatorSet, defaultSlashId, 0);
@@ -530,7 +532,67 @@ contract SlashEscrowFactoryUnitTests_releaseSlashEscrowByIndex is SlashEscrowFac
530532
assertEq(factory.getTotalPendingOperatorSets(), 0);
531533
assertEq(factory.getTotalPendingSlashIds(defaultOperatorSet), 0);
532534

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

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

643-
// Start burn/redistribution for this strategy
705+
// Start escrow for this strategy
644706
_initiateSlashEscrow(defaultOperatorSet, defaultSlashId, strategies[i], tokens[i], underlyingAmounts[i]);
645-
// Verify the burn/redistribution was started correctly
707+
// Verify the escrow was started correctly
646708
_checkStartEscrows(defaultOperatorSet, defaultSlashId, strategies[i], tokens[i], underlyingAmounts[i], i + 1);
647709
}
648710

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

681-
// Start burn/redistribution for this strategy
743+
// Start escrow for this strategy
682744
_initiateSlashEscrow(defaultOperatorSet, defaultSlashId, strategies[i], tokens[i], underlyingAmounts[i]);
683-
// Verify the burn/redistribution was started correctly
745+
// Verify the escrow was started correctly
684746
_checkStartEscrows(defaultOperatorSet, defaultSlashId, strategies[i], tokens[i], underlyingAmounts[i], i + 1);
685747
}
686748

@@ -707,10 +769,10 @@ contract SlashEscrowFactoryUnitTests_setGlobalEscrowDelay is SlashEscrowFactoryU
707769

708770
contract SlashEscrowFactoryUnitTests_getPendingEscrows is SlashEscrowFactoryUnitTests {
709771
function test_getPendingEscrows_singleSlashId() public {
710-
// Start burn/redistribution for a single strategy
772+
// Start escrow for a single strategy
711773
_initiateSlashEscrow(defaultOperatorSet, defaultSlashId, defaultStrategy, defaultToken, 100);
712774

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

716778
// Verify results
@@ -719,7 +781,7 @@ contract SlashEscrowFactoryUnitTests_getPendingEscrows is SlashEscrowFactoryUnit
719781
}
720782

721783
function test_getPendingEscrows_multipleStrategies() public {
722-
// Create multiple strategies and start burn/redistributions
784+
// Create multiple strategies and start escrows
723785
IStrategy strategy1 = IStrategy(cheats.randomAddress());
724786
IStrategy strategy2 = IStrategy(cheats.randomAddress());
725787
MockERC20 token1 = new MockERC20();
@@ -728,7 +790,7 @@ contract SlashEscrowFactoryUnitTests_getPendingEscrows is SlashEscrowFactoryUnit
728790
_initiateSlashEscrow(defaultOperatorSet, defaultSlashId, strategy1, token1, 100);
729791
_initiateSlashEscrow(defaultOperatorSet, defaultSlashId, strategy2, token2, 200);
730792

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

734796
// Verify results
@@ -748,11 +810,11 @@ contract SlashEscrowFactoryUnitTests_getPendingEscrows is SlashEscrowFactoryUnit
748810
MockERC20 token1 = new MockERC20();
749811
MockERC20 token2 = new MockERC20();
750812

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

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

758820
// Verify results
@@ -770,7 +832,7 @@ contract SlashEscrowFactoryUnitTests_getPendingEscrows is SlashEscrowFactoryUnit
770832
}
771833

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

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

815-
// Start burn/redistribution for this strategy
877+
// Start escrow for this strategy
816878
_initiateSlashEscrow(defaultOperatorSet, defaultSlashId, strategies[i], tokens[i], underlyingAmounts[i]);
817-
// Verify the burn/redistribution was started correctly
879+
// Verify the escrow was started correctly
818880
_checkStartEscrows(defaultOperatorSet, defaultSlashId, strategies[i], tokens[i], underlyingAmounts[i], i + 1);
819881
}
820882

0 commit comments

Comments
 (0)