Skip to content

Commit

Permalink
wip withdrawals with rewards test
Browse files Browse the repository at this point in the history
  • Loading branch information
danoctavian committed Sep 1, 2024
1 parent f82c80b commit 5284732
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 48 deletions.
4 changes: 2 additions & 2 deletions test/integration/M3/Base.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ contract Base is Test, Utils {
return validatorIndices;
}

function registerValidators(uint256[] memory validatorNodeIds, uint256 depositAmount) public {
function registerValidators(uint256[] memory validatorNodeIds) public {
IStakingNodesManager.ValidatorData[] memory validatorData = new IStakingNodesManager.ValidatorData[](validatorNodeIds.length);

for (uint256 i = 0; i < validatorNodeIds.length; i++) {
Expand All @@ -248,7 +248,7 @@ contract Base is Test, Utils {
}

for (uint256 i = 0; i < validatorData.length; i++) {
uint256 amount = depositAmount / validatorData.length;
uint256 amount = 32 ether;
bytes memory withdrawalCredentials = stakingNodesManager.getWithdrawalCredentials(validatorData[i].nodeId);
bytes32 depositDataRoot = stakingNodesManager.generateDepositRoot(validatorData[i].publicKey, validatorData[i].signature, withdrawalCredentials, amount);
validatorData[i].depositDataRoot = depositDataRoot;
Expand Down
93 changes: 47 additions & 46 deletions test/integration/M3/WithdrawalsWithRewards-Scenario.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ contract M3WithdrawalsTest is Base {
address public user;

uint40 public validatorIndex;
uint40[] validatorIndices;
uint256 public nodeId;

uint256 public amount;
Expand Down Expand Up @@ -53,62 +54,64 @@ contract M3WithdrawalsTest is Base {
nodeId = stakingNodesManager.nodesLength() - 1;
}

// create validator
// Calculate validator count based on amount
uint256 validatorCount = amount / 32 ether;

// create and register validators validator
{
bytes memory _withdrawalCredentials = stakingNodesManager.getWithdrawalCredentials(nodeId);
validatorIndex = beaconChain.newValidator{ value: 32 ether }(_withdrawalCredentials);
// Create an array of nodeIds with length equal to validatorCount
uint256[] memory nodeIds = new uint256[](validatorCount);
for (uint256 i = 0; i < validatorCount; i++) {
nodeIds[i] = nodeId;
}

// Call createValidators with the nodeIds array and validatorCount
validatorIndices = createValidators(nodeIds, 1);

beaconChain.advanceEpoch_NoRewards();

registerValidators(nodeIds);
}

// register validator
// verify withdrawal credentials
{
bytes memory _dummyPubkey = new bytes(48);
IStakingNodesManager.ValidatorData[] memory _data = new IStakingNodesManager.ValidatorData[](1);
_data[0] = IStakingNodesManager.ValidatorData({
publicKey: _dummyPubkey,
signature: ZERO_SIGNATURE,
depositDataRoot: stakingNodesManager.generateDepositRoot(
_dummyPubkey,
ZERO_SIGNATURE,
stakingNodesManager.getWithdrawalCredentials(nodeId),
32 ether
),
nodeId: nodeId

CredentialProofs memory _proofs = beaconChain.getCredentialProofs(validatorIndices);
vm.startPrank(actors.ops.STAKING_NODES_OPERATOR);
IPod(address(stakingNodesManager.nodes(nodeId))).verifyWithdrawalCredentials({
beaconTimestamp: _proofs.beaconTimestamp,
stateRootProof: _proofs.stateRootProof,
validatorIndices: validatorIndices,
validatorFieldsProofs: _proofs.validatorFieldsProofs,
validatorFields: _proofs.validatorFields
});
vm.prank(actors.ops.VALIDATOR_MANAGER);
stakingNodesManager.registerValidators(_data);
vm.stopPrank();

// check that unverifiedStakedETH is 0 and podOwnerShares is 100 ETH (amount)
// _testVerifyWithdrawalCredentials();
}

// // verify withdrawal credentials
// {
// uint40[] memory _validators = new uint40[](1);
// _validators[0] = validatorIndex;
// CredentialProofs memory _proofs = beaconChain.getCredentialProofs(_validators);
// vm.startPrank(actors.ops.STAKING_NODES_OPERATOR);
// IPod(address(stakingNodesManager.nodes(nodeId))).verifyWithdrawalCredentials({
// beaconTimestamp: _proofs.beaconTimestamp,
// stateRootProof: _proofs.stateRootProof,
// validatorIndices: _validators,
// validatorFieldsProofs: _proofs.validatorFieldsProofs,
// validatorFields: _proofs.validatorFields
// });
// vm.stopPrank();

// // check that unverifiedStakedETH is 0 and podOwnerShares is 100 ETH (amount)
// _testVerifyWithdrawalCredentials();
// }
// exit validators
{
// IStrategy[] memory _strategies = new IStrategy[](1);
// _strategies[0] = IStrategy(0xbeaC0eeEeeeeEEeEeEEEEeeEEeEeeeEeeEEBEaC0); // beacon chain eth strat
// vm.roll(block.number + delegationManager.getWithdrawalDelay(_strategies));

// // start checkpoint
// {
// vm.startPrank(actors.ops.STAKING_NODES_OPERATOR);
// stakingNodesManager.nodes(nodeId).startCheckpoint(true);
// vm.stopPrank();
for (uint256 i = 0; i < validatorIndices.length; i++) {
beaconChain.exitValidator(validatorIndices[i]);
}
beaconChain.advanceEpoch_NoRewards();
}

// // make sure startCheckpoint cant be called again, which means that the checkpoint has started
// _testStartCheckpoint();
// }
// start checkpoint
{
vm.startPrank(actors.ops.STAKING_NODES_OPERATOR);
stakingNodesManager.nodes(nodeId).startCheckpoint(true);
vm.stopPrank();
}

// // verify checkpoints
// verify checkpoints
// {
// uint40[] memory _validators = new uint40[](1);
// _validators[0] = validatorIndex;
Expand All @@ -119,8 +122,6 @@ contract M3WithdrawalsTest is Base {
// proofs: _cpProofs.balanceProofs
// });

// // check that proofsRemaining is 0 and podOwnerShares is still 100 ETH (amount)
// _testVerifyCheckpointsBeforeWithdrawalRequest();
// }

// // queue withdrawals
Expand Down

0 comments on commit 5284732

Please sign in to comment.