Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Escrow unit tests improvements #241

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

sandstone-ag
Copy link
Contributor

No description provided.

@sandstone-ag sandstone-ag requested a review from Psirex December 18, 2024 18:36
@sandstone-ag sandstone-ag force-pushed the feature/escrow-contract-unit-tests-3 branch from 73785a2 to 4ac6af1 Compare December 23, 2024 19:21
Copy link
Contributor

@Psirex Psirex left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The random share rate method looks good! Left a couple of minor comments to consider.

assertEq(escrowBalanceAfter, escrowBalanceBefore + amount);
assertApproxEqAbs(
vetoerBalanceAfter,
_stETH.getPooledEthByShares(_stETH.getSharesByPooledEth(vetoerBalanceBefore) - sharesAmount),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additional conversions between stETH and shares may introduce extra rounding errors. In this case, it should be enough to compare: assertEq(vetoerBalanceAfter, vetoerBalanceBefore - amount);. Then, the accuracy will always fit the 2 wei for the rebase factor used in the test.

);
vm.expectCall(address(_dualGovernance), abi.encodeCall(IDualGovernance.activateNextState, ()), 2);

vm.prank(_vetoer);
uint256 lockedStETHShares = _escrow.lockStETH(amount);

assertEq(lockedStETHShares, sharesAmount);
assertApproxEqAbs(lockedStETHShares, sharesAmount, ACCURACY);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better to compare shares strictly here. When stETH is transferred using transferShares(), the expected and actually transferred shares amount should match exactly.

assertEq(state.unstETHIdsCount, 2);
assertEq(state.stETHLockedShares.toUint256(), 0);
assertApproxEqAbs(state.unstETHLockedShares.toUint256(), unstethShares1 + unstethShares2, 2 * ACCURACY);
assertEq(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This assertion should not be strict, as in the previous check, as we assume that unstethShares1 and usntethShares2 may differ from the actual values. However, strict assertions will fail only on tiny withdrawal requests (dozens of WEIs).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or the method _vetoerLockedUnstEth should also return the actual amount of locked shares to use them together with the strict assertions


_withdrawalQueue.setClaimableEtherResult(responses);
vm.expectCall(
address(_withdrawalQueue), abi.encodeCall(IWithdrawalQueue.getClaimableEther, (unstethIds, hints))
);

assertTrue(_escrow.getEscrowState() == EscrowState.SignallingEscrow);
assertEq(_escrow.getRageQuitSupport().toUint256(), 0);

_escrow.markUnstETHFinalized(unstethIds, hints);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would also be nice to test events here, as it should contain the correct number of finalized shares

assertEq(signallingEscrowDetails.totalStETHLockedShares.toUint256(), stethAmount);
assertEq(signallingEscrowDetails.totalStETHClaimedETH.toUint256(), stethAmount);
assertEq(signallingEscrowDetails.totalStETHLockedShares.toUint256(), _stETH.getSharesByPooledEth(ethAmount));
assertEq(signallingEscrowDetails.totalStETHClaimedETH.toUint256(), ethAmount);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, it would be nice to check that after the withdrawal of ETH, other attempts of the vetoer to withdraw ETH will fail

@@ -1108,29 +1273,32 @@ contract EscrowUnitTests is UnitTest {
}

function test_withdrawETH_RevertOn_InvalidSharesValue() external {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may be worth changing the name of the test to make it more explicit which case is tested, for example, test_withdrawETH_RevertOn_ZeroSharesWithdrawAttempt()

@@ -1240,8 +1412,8 @@ contract EscrowUnitTests is UnitTest {
function test_withdrawETH_2_RevertOn_InvalidUnstETHStatus() external {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe more descriptive to title it test_withdrawETH_2_RevertOn_UnstETHNotClaimed

@@ -47,9 +53,15 @@ contract EscrowUnitTests is UnitTest {
Duration private _minLockAssetDuration = Durations.from(1 days);
Duration private _maxMinAssetsLockDuration = Durations.from(100 days);
uint256 private stethAmount = 100 ether;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The name stethSharesAmount seems more appropriate, as it’s referred to as shares in the tests

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants