Skip to content

Commit fa7e983

Browse files
committed
chore: fix tests
1 parent 7fc0169 commit fa7e983

File tree

2 files changed

+43
-37
lines changed

2 files changed

+43
-37
lines changed

src/test/integration/IntegrationBase.t.sol

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1216,7 +1216,7 @@ abstract contract IntegrationBase is IntegrationDeployer, TypeImporter {
12161216
uint wadToSlash = slashingParams.wadsToSlash[0];
12171217
slashedShares = prevShares.mulWadRoundUp(allocateParams.newMagnitudes[0].mulWadRoundUp(wadToSlash));
12181218

1219-
assertEq(prevShares - slashedShares, curShares, err);
1219+
assertApproxEqAbs(prevShares - slashedShares, curShares, 1e2, err);
12201220
}
12211221

12221222
/// @dev Validates behavior of "restaking", ie. that the funds can be slashed twice
@@ -1234,29 +1234,35 @@ abstract contract IntegrationBase is IntegrationDeployer, TypeImporter {
12341234
uint prevShares = _getPrevWithdrawableShares(staker, allocateParams.strategies)[0];
12351235
uint depositShares = _getStakerDepositShares(staker, allocateParams.strategies)[0];
12361236

1237-
// 1. The withdrawable shares should decrease by a factor of the BCSF
1238-
assertEq(prevShares.mulWad(_getBeaconChainSlashingFactor(staker)), curShares, err);
1239-
1240-
// /**
1241-
// * 2. The delta in shares is given by:
1242-
// * (depositShares * operatorMag) - (depositShares * operatorMag * BCSF)
1243-
// * = depositShares * operatorMag * (1 - BCSF)
1244-
// */
1245-
// uint beaconChainSlashingFactor = _getBeaconChainSlashingFactor(staker);
1246-
// uint wadToSlash = slashingParams.wadsToSlash[0];
1247-
// uint originalAVSSlashedShares = depositShares.mulWadRoundUp(allocateParams.newMagnitudes[0].mulWadRoundUp(wadToSlash));
1248-
// uint withdrawableSharesAfterAVSSlash = depositShares - originalAVSSlashedShares;
1249-
// uint expectedDelta = withdrawableSharesAfterAVSSlash.mulWad(WAD - beaconChainSlashingFactor);
1250-
// assertEq(prevShares - expectedDelta, curShares, err);
1251-
1252-
// /**
1253-
// * 3. The attributable avs slashed shares should decrease by a factor of the BCSF
1254-
// * Attributable avs slashed shares = originalWithdrawableShares - bcSlashedShares - curShares
1255-
// * Where bcSlashedShares = originalWithdrawableShares * (1 - BCSF)
1256-
// */
1257-
// uint bcSlashedShares = depositShares.mulWad(WAD - beaconChainSlashingFactor);
1258-
// uint attributableAVSSlashedShares = depositShares - bcSlashedShares - curShares;
1259-
// assertEq(originalAVSSlashedShares.mulWad(beaconChainSlashingFactor), attributableAVSSlashedShares, err);
1237+
// 1. The slashing factor and withdrawable shares should decrease by a factor of the BCSF
1238+
// We use assertApproxEq on shares since intermediate division on calculation of slashing factor introduces some additional rounding error
1239+
uint slashingFactor = _getSlashingFactor(staker, allocateParams.strategies[0]);
1240+
uint prevSlashingFactor = _getPrevSlashingFactor(staker, allocateParams.strategies[0]);
1241+
assertEq(prevSlashingFactor.mulWad(_getBeaconChainSlashingFactor(staker)), slashingFactor, err);
1242+
assertApproxEqAbs(prevShares.mulWad(_getBeaconChainSlashingFactor(staker)), curShares, 1e2, err);
1243+
1244+
/**
1245+
* 2. The delta in shares is given by:
1246+
* (depositShares * operatorMag) - (depositShares * operatorMag * BCSF)
1247+
* = depositShares * operatorMag * (1 - BCSF)
1248+
*/
1249+
uint beaconChainSlashingFactor = _getBeaconChainSlashingFactor(staker);
1250+
uint wadToSlash = slashingParams.wadsToSlash[0];
1251+
uint originalAVSSlashedShares = depositShares.mulWadRoundUp(allocateParams.newMagnitudes[0].mulWadRoundUp(wadToSlash));
1252+
{
1253+
uint withdrawableSharesAfterAVSSlash = depositShares - originalAVSSlashedShares;
1254+
uint expectedDelta = withdrawableSharesAfterAVSSlash.mulWad(WAD - beaconChainSlashingFactor);
1255+
assertApproxEqAbs(prevShares - expectedDelta, curShares, 1e2, err);
1256+
}
1257+
1258+
/**
1259+
* 3. The attributable avs slashed shares should decrease by a factor of the BCSF
1260+
* Attributable avs slashed shares = originalWithdrawableShares - bcSlashedShares - curShares
1261+
* Where bcSlashedShares = originalWithdrawableShares * (1 - BCSF)
1262+
*/
1263+
uint bcSlashedShares = depositShares.mulWad(WAD - beaconChainSlashingFactor);
1264+
uint attributableAVSSlashedShares = depositShares - bcSlashedShares - curShares;
1265+
assertApproxEqAbs(originalAVSSlashedShares.mulWad(beaconChainSlashingFactor), attributableAVSSlashedShares, 1e2, err);
12601266
}
12611267

12621268
/**

src/test/integration/tests/DualSlashing.t.sol

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -188,19 +188,19 @@ contract Integration_DualSlashing_AVSFirst is Integration_DualSlashing_Base {
188188
staker, validators, initDepositShares[0], slashedAmountGwei, allocateParams, slashingParams
189189
);
190190

191-
// // 9. Verify Validator
192-
// cheats.deal(address(staker), 32 ether);
193-
// (uint40[] memory newValidators, uint64 addedBeaconBalanceGwei,) = staker.startValidators();
194-
// uint beaconSharesAdded = uint(addedBeaconBalanceGwei * GWEI_TO_WEI);
195-
// beaconChain.advanceEpoch_NoRewards();
196-
// staker.verifyWithdrawalCredentials(newValidators);
197-
// check_VerifyWC_State(staker, newValidators, addedBeaconBalanceGwei);
198-
// assert_Snap_Added_Staker_WithdrawableShares_AtLeast(
199-
// staker,
200-
// BEACONCHAIN_ETH_STRAT.toArray(),
201-
// beaconSharesAdded.toArrayU256(),
202-
// "staker withdrawable shares should increase by the added beacon balance"
203-
// );
191+
// 9. Verify Validator
192+
cheats.deal(address(staker), 32 ether);
193+
(uint40[] memory newValidators, uint64 addedBeaconBalanceGwei,) = staker.startValidators();
194+
uint beaconSharesAdded = uint(addedBeaconBalanceGwei * GWEI_TO_WEI);
195+
beaconChain.advanceEpoch_NoRewards();
196+
staker.verifyWithdrawalCredentials(newValidators);
197+
check_VerifyWC_State(staker, newValidators, addedBeaconBalanceGwei);
198+
assert_Snap_Added_Staker_WithdrawableShares_AtLeast(
199+
staker,
200+
BEACONCHAIN_ETH_STRAT.toArray(),
201+
beaconSharesAdded.toArrayU256(),
202+
"staker withdrawable shares should increase by the added beacon balance"
203+
);
204204
}
205205

206206
/// @notice The balance increase results in the pods not processing the beacon slash as a slash, given

0 commit comments

Comments
 (0)