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 maxUsableTick and minUsableTick Functions #526

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

partylikeits1983
Copy link
Contributor

@partylikeits1983 partylikeits1983 commented Mar 26, 2024

@hensha256 @aadams Following up on the stale PR: #468

This commit introduces tests for the newly added utility functions maxUsableTick and minUsableTick in the TickMath library.

Added tests to check the min and max usable ticks in the TickMath library.

Added 2 tests to check tick spacings for popular fee tiers.

Added 2 fuzzing tests.

Added 2 tests to check revert of min/max tick on 0.

@partylikeits1983 partylikeits1983 changed the title Add Tests for maxUsableTick and minUsableTick Functions #468 Add Tests for maxUsableTick and minUsableTick Functions Mar 26, 2024
test/TickMath.t.sol Outdated Show resolved Hide resolved
Copy link
Contributor

@hensha256 hensha256 left a comment

Choose a reason for hiding this comment

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

left some comments 🙏

test/TickMath.t.sol Outdated Show resolved Hide resolved
Comment on lines +106 to +111
function test_maxUsableTick_equalsMinUsableTick_fuzz(int24 tickSpacing) public {
tickSpacing = int24(bound(tickSpacing, TickMath.MIN_TICK_SPACING, TickMath.MAX_TICK_SPACING));
vm.assume(tickSpacing != 0);

assertEq(-tickMath.minUsableTick(tickSpacing), tickMath.maxUsableTick(tickSpacing));
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@hensha256 resolving this suggestion from @aadams on my previous PR
#468 (comment)

Comment on lines +90 to +96
function test_maxUsableTick_shouldMatchExpectedMaxTickGivenSpacing_fuzz(int24 tickSpacing) public {
tickSpacing = int24(bound(tickSpacing, TickMath.MIN_TICK_SPACING, TickMath.MAX_TICK_SPACING));
vm.assume(tickSpacing != 0);

int24 expectedMaxTick = (MAX_TICK / tickSpacing) * tickSpacing;
assertEq(tickMath.maxUsableTick(tickSpacing), expectedMaxTick);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@hensha256 Using bound instead of vm.assume and using TickMath.MIN_TICK_SPACING and TickMath.MAX_TICK_SPACING instead of MIN_TICK and MAX_TICK

@partylikeits1983
Copy link
Contributor Author

@hensha256

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

Successfully merging this pull request may close these issues.

2 participants