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 contract unit tests - 2 #176

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

Conversation

sandstone-ag
Copy link
Contributor

No description provided.

return;
}

sendTo(ETHValues.from(_claimableAmount), payable(msg.sender));
Copy link
Contributor

Choose a reason for hiding this comment

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

sendTo is available globally for the EthValue type, allowing it to be called as ETHValues.from(_claimableAmount).sendTo(payable(msg.sender))

@@ -380,6 +424,13 @@ contract WithdrawalsBatchesQueueTest is UnitTest {
}
}

function test_calcRequestAmounts_RevertOn_DivisionByZero() 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's better to rename the test to show the revert reason, for example: test_calcRequestAmounts_RevertOn_MaxRequestAmountIsZero()

) internal returns (Escrow) {
Escrow instance = createEscrowProxy(minWithdrawalsBatchSize);

vm.startPrank(_dualGovernance);
Copy link
Contributor

Choose a reason for hiding this comment

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

For one-time "pranking" vm.prank() method is more convenient

// helper methods
// ---

function createEscrow(uint256 size) internal returns (Escrow) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Internal methods should start from the _ prefix

_random = Random.create(block.timestamp);

_stETH = new StETHMock();
_stETH.__setShareRate(1);
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 be nice if Escrow tests used a share rate other than 1. However, this would require changes in the current StETHMock() contract.

assertEq(escrowBalanceAfter, escrowBalanceBefore + amount);
}

function test_lockStETH_RevertOn_UnexpectedEscrowState() external {
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 the implementation of the Escrow contract can't be used to lock tokens.

uint256 vetoerBalanceAfter = ERC20Mock(address(_wstETH)).balanceOf(_vetoer);
uint256 escrowBalanceAfter = ERC20Mock(address(_wstETH)).balanceOf(address(_escrow));

assertEq(vetoerBalanceAfter, vetoerBalanceBefore - amount);
Copy link
Contributor

Choose a reason for hiding this comment

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

For the wstETH, there also may be rounding errors, as the wstETH is unwrapped to stETH in the lockWstETH() method

uint256 escrowBalanceAfter = ERC20Mock(address(_stETH)).balanceOf(address(_escrow));

assertEq(vetoerBalanceAfter, vetoerBalanceBefore - amount);
assertEq(escrowBalanceAfter, escrowBalanceBefore + amount);
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't there also be checks that the state of the Escrow contract changed expectedly (getVetoerState() and getLockedAssetsTotals())

function test_unlockWstETH_HappyPath() external {
uint256 amount = 1 ether;

vm.mockCall(address(_wstETH), abi.encodeWithSelector(IWstETH.wrap.selector), abi.encode(amount));
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider updating the tests to exclusively use vm.mockCall() (which appears to be the preferred approach, as it simplifies simulating stETH rounding errors) or to exclusively mock contracts. Combining both methods makes the tests more complex and harder to follow.

vm.expectCall(address(_dualGovernance), abi.encodeWithSelector(IDualGovernance.activateNextState.selector));

vm.prank(_vetoer);
_escrow.lockStETH(amount);
Copy link
Contributor

Choose a reason for hiding this comment

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

The returning value check is missing

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