Skip to content

Commit 4895557

Browse files
wadealexcypatil12
authored andcommitted
test: remove unneeded logic from integration test setup (#1023)
1 parent 2020b8d commit 4895557

File tree

7 files changed

+367
-434
lines changed

7 files changed

+367
-434
lines changed

src/test/integration/IntegrationBase.t.sol

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -148,21 +148,17 @@ abstract contract IntegrationBase is IntegrationDeployer {
148148
emit log("_upgradeEigenLayerContracts: upgrading mainnet to slashing");
149149
_upgradeMainnetContracts();
150150

151+
// Unpause EigenPodManager
152+
cheats.prank(eigenLayerPauserReg.unpauser());
153+
eigenPodManager.unpause(0);
154+
151155
// Bump block.timestamp forward to allow verifyWC proofs for migrated pods
152156
emit log("advancing block time to start of next epoch:");
153157

154158
beaconChain.advanceEpoch_NoRewards();
155159

156160
emit log("======");
157161

158-
isUpgraded = true;
159-
emit log("_upgradeEigenLayerContracts: slashing upgrade complete");
160-
} else if (forkType == HOLESKY) {
161-
require(!isUpgraded, "_upgradeEigenLayerContracts: already performed slashing upgrade");
162-
163-
emit log("_upgradeEigenLayerContracts: upgrading holesky to slashing");
164-
_upgradeHoleskyContracts();
165-
166162
isUpgraded = true;
167163
emit log("_upgradeEigenLayerContracts: slashing upgrade complete");
168164
}

src/test/integration/IntegrationDeployer.t.sol

Lines changed: 98 additions & 426 deletions
Large diffs are not rendered by default.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// SPDX-License-Identifier: BUSL-1.1
2+
pragma solidity ^0.8.27;
3+
4+
import "src/contracts/interfaces/IAllocationManager.sol";
5+
import "src/contracts/interfaces/IAVSDirectory.sol";
6+
import "src/contracts/interfaces/IDelegationManager.sol";
7+
import "src/contracts/interfaces/IEigenPod.sol";
8+
import "src/contracts/interfaces/IEigenPodManager.sol";
9+
import "src/contracts/interfaces/IStrategyManager.sol";
10+
11+
12+
/// @dev A master interface contract that imports types defined in our
13+
/// contract interfaces so they can be used without needing to refer to
14+
/// the interface, e.g:
15+
///
16+
/// `AllocateParams memory params;`
17+
/// vs
18+
/// `IAllocationManagerTypes.AllocateParams memory params;`
19+
interface TypeImporter is
20+
IAllocationManagerTypes,
21+
IAVSDirectoryTypes,
22+
IDelegationManagerTypes,
23+
IEigenPodManagerTypes,
24+
IEigenPodTypes
25+
{
26+
}

src/test/integration/mocks/BeaconChainMock.t.sol

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import "src/contracts/libraries/BeaconChainProofs.sol";
77
import "src/contracts/libraries/Merkle.sol";
88
import "src/contracts/pods/EigenPodManager.sol";
99

10+
import "src/test/mocks/ETHDepositMock.sol";
1011
import "src/test/integration/mocks/EIP_4788_Oracle_Mock.t.sol";
1112
import "src/test/utils/Logger.t.sol";
1213

@@ -93,6 +94,7 @@ contract BeaconChainMock is Logger {
9394
uint64 public nextTimestamp;
9495

9596
EigenPodManager eigenPodManager;
97+
IETHPOSDeposit constant DEPOSIT_CONTRACT = IETHPOSDeposit(0x00000000219ab540356cBB839Cbe05303d7705Fa);
9698
EIP_4788_Oracle_Mock constant EIP_4788_ORACLE = EIP_4788_Oracle_Mock(0x000F3df6D732807Ef1319fB7B8bB8522d0Beac02);
9799

98100
/**
@@ -140,6 +142,7 @@ contract BeaconChainMock is Logger {
140142
eigenPodManager = _eigenPodManager;
141143

142144
// Create mock 4788 oracle
145+
cheats.etch(address(DEPOSIT_CONTRACT), type(ETHPOSDepositMock).runtimeCode);
143146
cheats.etch(address(EIP_4788_ORACLE), type(EIP_4788_Oracle_Mock).runtimeCode);
144147

145148
// Calculate nodes of empty merkle tree
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// SPDX-License-Identifier: BUSL-1.1
2+
pragma solidity ^0.8.27;
3+
4+
import "src/test/integration/UpgradeTest.t.sol";
5+
6+
contract Integration_Upgrade_Deposit_Delegate_Allocate is UpgradeTest {
7+
8+
function testFuzz_deposit_delegate_upgrade_allocate(uint24 _random) public rand(_random) {
9+
(User staker, IStrategy[] memory strategies, uint256[] memory tokenBalances) = _newRandomStaker();
10+
(User operator,,) = _newRandomOperator();
11+
12+
// Pre-upgrade:
13+
// 1. Create staker and operator with assets, then deposit into EigenLayer
14+
// 2. Delegate to operator
15+
staker.depositIntoEigenlayer(strategies, tokenBalances);
16+
staker.delegateTo(operator);
17+
18+
// Upgrade to slashing release
19+
_upgradeEigenLayerContracts();
20+
(AVS avs,) = _newRandomAVS();
21+
22+
// 3. Set allocation delay for operator
23+
operator.setAllocationDelay(1);
24+
rollForward({blocks: ALLOCATION_CONFIGURATION_DELAY + 1});
25+
26+
// 4. Create an operator set and register an operator.
27+
OperatorSet memory operatorSet = avs.createOperatorSet(strategies);
28+
operator.registerForOperatorSet(operatorSet);
29+
check_Registration_State_NoAllocation(operator, operatorSet, allStrats);
30+
31+
// 5. Allocate to operator set.
32+
AllocateParams memory allocateParams = AllocateParams({
33+
operatorSet: operatorSet,
34+
strategies: strategies,
35+
newMagnitudes: _randMagnitudes({sum: 1 ether, len: strategies.length})
36+
});
37+
operator.modifyAllocations(allocateParams);
38+
check_IncrAlloc_State_Slashable(operator, allocateParams);
39+
}
40+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
// SPDX-License-Identifier: BUSL-1.1
2+
pragma solidity ^0.8.27;
3+
4+
import "src/test/integration/UpgradeTest.t.sol";
5+
6+
contract Integration_Upgrade_EigenPod_Slashing_Migration is UpgradeTest, EigenPodPausingConstants {
7+
8+
function _init() internal override {
9+
_configAssetTypes(HOLDS_ETH);
10+
_configUserTypes(DEFAULT);
11+
}
12+
13+
/**
14+
* @dev Assumes that the Prooftra and slashing upgrade occur at the same time
15+
* 1. Verify validators' withdrawal credentials
16+
* -- earn rewards on beacon chain (withdrawn to pod)
17+
* 2. Start a checkpoint
18+
* 3. Pause starting checkpoints
19+
* 4. Complete in progress checkpoint
20+
* 5. Upgrade EigenPod contracts
21+
* 6. Exit subset of Validators
22+
*/
23+
function test_upgrade_eigenpod_migration(uint24 _rand) public rand(_rand) {
24+
// Initialize state
25+
(User staker, ,) = _newRandomStaker();
26+
27+
(uint40[] memory validators, ,) = staker.startValidators();
28+
beaconChain.advanceEpoch_NoRewards();
29+
30+
// 1. Verify validators' withdrawal credentials
31+
staker.verifyWithdrawalCredentials(validators);
32+
33+
// Advance epoch, generating consensus rewards and withdrawing anything over 32 ETH
34+
beaconChain.advanceEpoch();
35+
36+
// 2. Start a checkpoint
37+
staker.startCheckpoint();
38+
39+
// 3. Pause checkpoint starting
40+
cheats.prank(pauserMultisig);
41+
eigenPodManager.pause(2 ** PAUSED_START_CHECKPOINT);
42+
cheats.expectRevert("EigenPod.onlyWhenNotPaused: index is paused in EigenPodManager");
43+
staker.startCheckpoint();
44+
45+
// 4. Complete in progress checkpoint
46+
staker.completeCheckpoint();
47+
48+
// 5. Upgrade Contracts for slashing
49+
_upgradeEigenLayerContracts();
50+
51+
// Unpause EigenPodManager
52+
cheats.prank(eigenLayerPauserReg.unpauser());
53+
eigenPodManager.unpause(0);
54+
55+
// 6. Exit validators
56+
// Fully exit one or more validators and advance epoch without generating rewards
57+
uint40[] memory subset = _choose(validators);
58+
uint64 exitedBalanceGwei = staker.exitValidators(subset);
59+
beaconChain.advanceEpoch_NoRewards();
60+
61+
staker.startCheckpoint();
62+
check_StartCheckpoint_WithPodBalance_State(staker, exitedBalanceGwei);
63+
64+
// staker.completeCheckpoint();
65+
// check_CompleteCheckpoint_WithExits_State(staker, subset, exitedBalanceGwei);
66+
}
67+
}
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
// SPDX-License-Identifier: BUSL-1.1
2+
pragma solidity ^0.8.27;
3+
4+
import "src/test/integration/UpgradeTest.t.sol";
5+
contract Integration_Upgrade_Pectra is UpgradeTest, EigenPodPausingConstants {
6+
function _init() internal override {
7+
_configAssetTypes(HOLDS_ETH);
8+
_configUserTypes(DEFAULT);
9+
}
10+
11+
function test_Upgrade_VerifyWC_StartCP_CompleteCP(uint24 _rand) public rand(_rand) {
12+
// 1. Pause, Fork, and Upgrade
13+
_pauseForkAndUpgrade();
14+
15+
// 2. Set Pectra Fork Timestamp & unpause
16+
_setTimestampAndUnpause();
17+
18+
// 3. Initialize Staker
19+
(User staker, ,) = _newRandomStaker();
20+
(uint40[] memory validators, uint64 beaconBalanceGwei, ) = staker.startValidators();
21+
beaconChain.advanceEpoch_NoRewards();
22+
23+
// 4. Verify Withdrawal Credentials
24+
staker.verifyWithdrawalCredentials(validators);
25+
check_VerifyWC_State(staker, validators, beaconBalanceGwei);
26+
27+
// 4. Start Checkpoint
28+
staker.startCheckpoint();
29+
check_StartCheckpoint_State(staker);
30+
31+
// 5. Complete Checkpoint
32+
staker.completeCheckpoint();
33+
check_CompleteCheckpoint_State(staker);
34+
}
35+
36+
function test_VerifyWC_StartCP_Fork_CompleteCP(uint24 _rand) public rand(_rand) {
37+
// Initialize state
38+
(User staker, ,) = _newRandomStaker();
39+
(uint40[] memory validators, ,) = staker.startValidators();
40+
beaconChain.advanceEpoch_NoRewards();
41+
42+
// 1. Verify validators' withdrawal credentials
43+
staker.verifyWithdrawalCredentials(validators);
44+
45+
// 2. Start a checkpoint
46+
staker.startCheckpoint();
47+
48+
// 3. Pause, Fork, and Upgrade
49+
_pauseForkAndUpgrade();
50+
51+
// 4. Set Pectra Fork Timestamp & unpause
52+
_setTimestampAndUnpause();
53+
54+
// 5. Complete in progress checkpoint
55+
staker.completeCheckpoint();
56+
check_CompleteCheckpoint_State(staker);
57+
}
58+
59+
function test_VerifyWC_Fork_EarnToPod_StartCP_CompleteCP(uint24 _rand) public rand(_rand) {
60+
// Initialize state
61+
(User staker, ,) = _newRandomStaker();
62+
(uint40[] memory validators, ,) = staker.startValidators();
63+
beaconChain.advanceEpoch_NoRewards();
64+
65+
// 1. Verify validators' withdrawal credentials
66+
staker.verifyWithdrawalCredentials(validators);
67+
68+
// 2. Pause, Fork, and Upgrade
69+
_pauseForkAndUpgrade();
70+
71+
// 3. Set timestamp and unpause
72+
_setTimestampAndUnpause();
73+
74+
// 4. Advance epoch, generating consensus rewards and withdrawing anything over Max EB
75+
// Not: Nothing is withdrawn because all validators were created with 32 ETH
76+
beaconChain.advanceEpoch();
77+
uint64 expectedEarnedGwei = uint64(validators.length) * beaconChain.CONSENSUS_REWARD_AMOUNT_GWEI();
78+
79+
// 5. Start a checkpoint
80+
staker.startCheckpoint();
81+
check_StartCheckpoint_State(staker);
82+
83+
// 6. Complete in progress checkpoint
84+
staker.completeCheckpoint();
85+
check_CompleteCheckpoint_EarnOnBeacon_State(staker, expectedEarnedGwei);
86+
}
87+
88+
function _pauseForkAndUpgrade() internal {
89+
// 1. Pause starting checkpoint, completing, and credential proofs
90+
cheats.prank(pauserMultisig);
91+
eigenPodManager.pause(
92+
2 ** PAUSED_START_CHECKPOINT |
93+
2 ** PAUSED_EIGENPODS_VERIFY_CREDENTIALS |
94+
2 ** PAUSED_VERIFY_STALE_BALANCE |
95+
2 ** PAUSED_EIGENPODS_VERIFY_CHECKPOINT_PROOFS
96+
);
97+
98+
// 2. Fork to Pectra
99+
uint64 pectraForkTimestamp = uint64(block.timestamp) + 12;
100+
BeaconChainMock_DenebForkable(address(beaconChain)).forkToPectra(pectraForkTimestamp);
101+
102+
// 3. Upgrade EigenPodManager & EigenPod
103+
_upgradeEigenLayerContracts();
104+
105+
// 4. Set proof timestamp setter to operations multisig
106+
cheats.prank(eigenPodManager.owner());
107+
eigenPodManager.setProofTimestampSetter(address(operationsMultisig));
108+
}
109+
110+
function _setTimestampAndUnpause() internal {
111+
// 1. Set Timestamp
112+
cheats.startPrank(eigenPodManager.proofTimestampSetter());
113+
eigenPodManager.setPectraForkTimestamp(
114+
BeaconChainMock_DenebForkable(address(beaconChain)).pectraForkTimestamp()
115+
);
116+
cheats.stopPrank();
117+
118+
// 2. Randomly warp to just after the fork timestamp
119+
// If we do not warp, proofs will be against deneb state
120+
if (_randBool()) {
121+
// If we warp, proofs will be against electra state
122+
cheats.warp(block.timestamp + 1);
123+
}
124+
125+
// 3. Unpause
126+
cheats.prank(eigenLayerPauserReg.unpauser());
127+
eigenPodManager.unpause(0);
128+
}
129+
}

0 commit comments

Comments
 (0)