Skip to content

Commit

Permalink
add moar tests
Browse files Browse the repository at this point in the history
  • Loading branch information
skhomuti committed Jan 15, 2024
1 parent efd70f7 commit dac591e
Showing 1 changed file with 54 additions and 5 deletions.
59 changes: 54 additions & 5 deletions test/CSModule.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -1924,7 +1924,7 @@ contract CsmSubmitWithdrawal is CSMCommon {

csm.submitInitialSlashing(noId, 0);

uint256 expectedPenaltyAmount = csm.DEPOSIT_SIZE() -
uint256 exitBalance = csm.DEPOSIT_SIZE() -
csm.INITIAL_SLASHING_PENALTY();

vm.expectCall(
Expand All @@ -1935,11 +1935,31 @@ contract CsmSubmitWithdrawal is CSMCommon {
0.05 ether
)
);
csm.submitWithdrawal(
noId,
keyIndex,
expectedPenaltyAmount - 0.05 ether
csm.submitWithdrawal(noId, keyIndex, exitBalance - 0.05 ether);
}

function test_submitWithdrawal_unbondedKeys() public {
uint256 keyIndex = 0;
uint256 noId = createNodeOperator(2);
csm.vetKeys(noId, 2);
csm.obtainDepositData(1, "");

vm.expectEmit(true, true, true, true, address(csm));
emit VettedSigningKeysCountChanged(noId, 1);
csm.submitWithdrawal(noId, keyIndex, 1 ether);
}

function test_submitWithdrawal_outOfBond() public {
uint256 keyIndex = 0;
uint256 noId = createNodeOperator();
csm.vetKeys(noId, 1);
csm.obtainDepositData(1, "");

vm.expectCall(
address(accounting),
abi.encodeWithSelector(accounting.resetBondCurve.selector, noId)
);
csm.submitWithdrawal(noId, keyIndex, 0 ether);
}

function test_submitWithdrawal_RevertWhenNoNodeOperator() public {
Expand Down Expand Up @@ -1999,6 +2019,35 @@ contract CsmSubmitInitialSlashing is CSMCommon {
csm.submitInitialSlashing(noId, 1);
}

function test_submitInitialSlashing_unbondedKeys() public {
uint256 keyIndex = 0;
uint256 noId = createNodeOperator(2);
csm.vetKeys(noId, 2);
csm.obtainDepositData(1, "");

uint256 bondThreshold = (accounting.BONDED_KEY_THRESHOLD_PERCENT_BP() *
csm.DEPOSIT_SIZE()) / accounting.TOTAL_BASIS_POINTS();
csm.penalize(noId, bondThreshold - 0.1 ether);

vm.expectEmit(true, true, true, true, address(csm));
emit VettedSigningKeysCountChanged(noId, 1);
csm.submitInitialSlashing(noId, keyIndex);
}

function test_submitInitialSlashing_outOfBond() public {
uint256 keyIndex = 0;
uint256 noId = createNodeOperator();
csm.vetKeys(noId, 1);
csm.obtainDepositData(1, "");

csm.penalize(noId, csm.DEPOSIT_SIZE() - csm.INITIAL_SLASHING_PENALTY());
vm.expectCall(
address(accounting),
abi.encodeWithSelector(accounting.resetBondCurve.selector, noId)
);
csm.submitInitialSlashing(noId, keyIndex);
}

function test_submitInitialSlashing_RevertWhenNoNodeOperator() public {
vm.expectRevert(NodeOperatorDoesNotExist.selector);
csm.submitInitialSlashing(0, 0);
Expand Down

0 comments on commit dac591e

Please sign in to comment.