Skip to content

Commit

Permalink
test: get tests compiling and running
Browse files Browse the repository at this point in the history
* 2 tests failing with off by 1
  • Loading branch information
wadealexc committed Nov 15, 2024
1 parent bfc9196 commit 5d8b350
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 17 deletions.
21 changes: 12 additions & 9 deletions script/tasks/complete_withdrawal_from_strategy.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,27 @@ contract CompleteWithdrawFromStrategy is Script, Test {
config_data = vm.readFile(deployConfigPath);

// Pull addresses from config
address allocationManager = stdJson.readAddress(config_data, ".addresses.allocationManager");
address delegationManager = stdJson.readAddress(config_data, ".addresses.delegationManager");
address eigenPodManager = stdJson.readAddress(config_data, ".addresses.eigenPodManager");
AllocationManager am = AllocationManager(stdJson.readAddress(config_data, ".addresses.allocationManager"));
DelegationManager dm = DelegationManager(stdJson.readAddress(config_data, ".addresses.delegationManager"));
EigenPodManager em = EigenPodManager(stdJson.readAddress(config_data, ".addresses.eigenPodManager"));

// START RECORDING TRANSACTIONS FOR DEPLOYMENT
vm.startBroadcast();

// Attach to Managers
AllocationManager am = AllocationManager(allocationManager);
DelegationManager dm = DelegationManager(delegationManager);
EigenPodManager em = EigenPodManager(eigenPodManager);

// Add token to array
IERC20[] memory tokens = new IERC20[](1);
tokens[0] = IERC20(token);

// Get the withdrawal struct
IDelegationManagerTypes.Withdrawal memory withdrawal = getWithdrawalStruct(am, dm, em, strategy, amount, nonce, startBlock);
IDelegationManagerTypes.Withdrawal memory withdrawal = getWithdrawalStruct(
am,
dm,
em,
strategy,
amount,
nonce,
startBlock
);

// complete
dm.completeQueuedWithdrawal(withdrawal, tokens, true);
Expand Down
19 changes: 19 additions & 0 deletions src/test/mocks/EigenPodManagerMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ contract EigenPodManagerMock is Test, Pausable {

mapping(address => uint256) public podOwnerSharesWithdrawn;

struct BeaconChainSlashingFactor {
bool isSet;
uint64 slashingFactor;
}

mapping(address => BeaconChainSlashingFactor) _beaconChainSlashingFactor;

constructor(IPauserRegistry _pauserRegistry) Pausable(_pauserRegistry) {
_setPausedStatus(0);
}
Expand Down Expand Up @@ -44,4 +51,16 @@ contract EigenPodManagerMock is Test, Pausable {
function withdrawSharesAsTokens(address podOwner, address /** strategy */, address /** token */, uint256 shares) external {
podOwnerSharesWithdrawn[podOwner] += shares;
}

function setBeaconChainSlashingFactor(address staker, uint64 bcsf) external {
_beaconChainSlashingFactor[staker] = BeaconChainSlashingFactor({
isSet: true,
slashingFactor: bcsf
});
}

function beaconChainSlashingFactor(address staker) external view returns (uint64) {
BeaconChainSlashingFactor memory bsf = _beaconChainSlashingFactor[staker];
return bsf.isSet ? bsf.slashingFactor : WAD;
}
}
28 changes: 20 additions & 8 deletions src/test/unit/DelegationUnit.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ contract DelegationManagerUnitTests is EigenLayerUnitTestSetup, IDelegationManag
uint64 operatorMaxMagnitude
) internal view returns (uint256) {
if (strategy == beaconChainETHStrategy) {
uint64 beaconChainSlashingFactor = delegationManager.getBeaconChainSlashingFactor(staker);
uint64 beaconChainSlashingFactor = eigenPodManagerMock.beaconChainSlashingFactor(staker);
return operatorMaxMagnitude.mulWad(beaconChainSlashingFactor);
}

Expand Down Expand Up @@ -3377,6 +3377,7 @@ contract DelegationManagerUnitTests_queueWithdrawals is DelegationManagerUnitTes

contract DelegationManagerUnitTests_completeQueuedWithdrawal is DelegationManagerUnitTests {
using SingleItemArrayLib for *;
using SlashingLib for *;

function test_Revert_WhenExitWithdrawalQueuePaused() public {
cheats.prank(pauser);
Expand Down Expand Up @@ -3790,11 +3791,18 @@ contract DelegationManagerUnitTests_completeQueuedWithdrawal is DelegationManage
uint256 operatorSharesAfterQueue = delegationManager.operatorShares(defaultOperator, beaconChainETHStrategy);
assertEq(operatorSharesAfterQueue, operatorSharesBeforeQueue - withdrawalAmount, "operator shares should be decreased after queue");

// Slash the staker for beacon chain shares while it has queued a withdrawal
uint256 beaconSharesBeforeSlash = uint256(eigenPodManagerMock.podOwnerShares(defaultStaker));
uint64 stakerBeaconChainScalingFactor = 5e17;
cheats.prank(address(eigenPodManagerMock));
delegationManager.decreaseBeaconChainScalingFactor(defaultStaker, beaconSharesBeforeSlash, stakerBeaconChainScalingFactor);
{
// Slash the staker for beacon chain shares while it has queued a withdrawal
uint256 beaconSharesBeforeSlash = uint256(eigenPodManagerMock.podOwnerShares(defaultStaker));
uint64 prevBeaconChainSlashingFactor = eigenPodManagerMock.beaconChainSlashingFactor(defaultStaker);
uint64 newBeaconChainSlashingFactor = 5e17;
eigenPodManagerMock.setBeaconChainSlashingFactor(defaultStaker, newBeaconChainSlashingFactor);
uint256 wadSlashed = newBeaconChainSlashingFactor.divWad(prevBeaconChainSlashingFactor);

cheats.prank(address(eigenPodManagerMock));
delegationManager.decreaseDelegatedShares(defaultStaker, beaconSharesBeforeSlash, prevBeaconChainSlashingFactor, wadSlashed);
}

uint256 operatorSharesAfterBeaconSlash = delegationManager.operatorShares(defaultOperator, beaconChainETHStrategy);
assertEq(operatorSharesAfterBeaconSlash, operatorSharesAfterQueue / 2, "operator shares should be decreased after beaconChain slash");

Expand Down Expand Up @@ -3861,9 +3869,13 @@ contract DelegationManagerUnitTests_completeQueuedWithdrawal is DelegationManage

// Slash the staker for beacon chain shares while it has queued a withdrawal
uint256 beaconSharesBeforeSlash = uint256(eigenPodManagerMock.podOwnerShares(defaultStaker));
uint64 stakerBeaconChainScalingFactor = 5e17;
uint64 prevBeaconChainSlashingFactor = eigenPodManagerMock.beaconChainSlashingFactor(defaultStaker);
uint64 newBeaconChainSlashingFactor = 5e17;
eigenPodManagerMock.setBeaconChainSlashingFactor(defaultStaker, newBeaconChainSlashingFactor);
uint256 wadSlashed = newBeaconChainSlashingFactor.divWad(prevBeaconChainSlashingFactor);

cheats.prank(address(eigenPodManagerMock));
delegationManager.decreaseBeaconChainScalingFactor(defaultStaker, beaconSharesBeforeSlash, stakerBeaconChainScalingFactor);
delegationManager.decreaseDelegatedShares(defaultStaker, beaconSharesBeforeSlash, prevBeaconChainSlashingFactor, wadSlashed);
uint256 operatorSharesAfterBeaconSlash = delegationManager.operatorShares(defaultOperator, beaconChainETHStrategy);
assertEq(operatorSharesAfterBeaconSlash, operatorSharesAfterQueue / 2, "operator shares should be decreased after beaconChain slash");

Expand Down

0 comments on commit 5d8b350

Please sign in to comment.