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

Add tests for EscrowState library #92

Merged
merged 8 commits into from
Aug 26, 2024
Merged

Conversation

sandstone-ag
Copy link
Contributor

No description provided.

@sandstone-ag sandstone-ag force-pushed the feature/escrow-state-tests branch from 7ba81ea to a1dc2c7 Compare August 12, 2024 15:30
// initialize()
// ---

function testFuzz_initialize_happyPath(uint32 minAssetsLockSeconds) external {
Copy link
Contributor

Choose a reason for hiding this comment

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

The Duration type may be used as a parameter to avoid later casting from uint32.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done


EscrowState.initialize(_context, minAssetsLockDuration);

checkContext(State.SignallingEscrow, minAssetsLockDuration, D0, D0, T0);
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 use named parameters for the better readability:

checkContext({
  state: State.SignallingEscrow,
  minAssetsLockDuration: minAssetsLockDuration,
  rageQuitExtensionDelay: D0,
  rageQuitWithdrawalsTimelock: D0,
  rageQuitExtensionDelayStartedAt: T0
});

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

_context.rageQuitExtensionDelay = rageQuitExtensionDelay;
_context.rageQuitWithdrawalsTimelock = rageQuitWithdrawalsTimelock;

vm.warp(
Copy link
Contributor

Choose a reason for hiding this comment

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

The UnitTest._wait() method may be used

Copy link
Contributor Author

@sandstone-ag sandstone-ag Aug 19, 2024

Choose a reason for hiding this comment

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

I'm not sure that it will make the test easier to understand, take a look pls at these lines
https://github.com/lidofinance/dual-governance/pull/92/files#diff-94006bb4d7eaa8960b0a0a1fd4de0d02c0d50140ca8857d0ba68052b5aeee11fR229-R234
However I replaced all vm.warp() calls with _wait() as you requested.

{
_context.rageQuitExtensionDelayStartedAt = Timestamps.from(rageQuitExtensionDelayStartedAtSeconds);
bool res = EscrowState.isRageQuitExtensionDelayStarted(_context);
assert(res == _context.rageQuitExtensionDelayStartedAt.isNotZero());
Copy link
Contributor

Choose a reason for hiding this comment

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

Do not use Solidity's native assert() method in tests. Instead, use Foundry's assertEq(), assertTrue(), etc.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@sandstone-ag sandstone-ag force-pushed the feature/escrow-state-tests branch from a1dc2c7 to 3260959 Compare August 19, 2024 18:00
@sandstone-ag sandstone-ag requested a review from rkolpakov August 19, 2024 18:08
@sandstone-ag sandstone-ag force-pushed the feature/escrow-state-tests branch 2 times, most recently from 106a529 to 8c2f6e3 Compare August 20, 2024 10:03
@sandstone-ag sandstone-ag requested a review from Psirex August 20, 2024 11:50
@sandstone-ag sandstone-ag force-pushed the feature/escrow-state-tests branch from 8c2f6e3 to 3b9eb9d Compare August 23, 2024 18:28
@rkolpakov rkolpakov merged commit 4108d4f into develop Aug 26, 2024
2 checks passed
@sandstone-ag sandstone-ag deleted the feature/escrow-state-tests branch August 26, 2024 08:47
@Psirex Psirex mentioned this pull request Aug 28, 2024
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.

3 participants