forked from sparkdotfi/spark-alm-controller
-
Notifications
You must be signed in to change notification settings - Fork 2
test: Close coverage gaps for full test coverage #96
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
Open
lucas-manuel
wants to merge
1
commit into
dev
Choose a base branch
from
add-missing-coverage-2
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,194 @@ | ||
| // SPDX-License-Identifier: AGPL-3.0-or-later | ||
| pragma solidity ^0.8.34; | ||
|
|
||
| import { Test } from "../../lib/forge-std/src/Test.sol"; | ||
|
|
||
| import { UniswapV3Utils, SafeCast } from "../../src/facets/uniswap-v3/UniswapV3Utils.sol"; | ||
|
|
||
| // Wrapper contract to expose library internals for testing | ||
| contract UniswapV3UtilsHarness { | ||
|
|
||
| using UniswapV3Utils for *; | ||
|
|
||
| function divRoundingUp(uint256 x, uint256 y) external pure returns (uint256) { | ||
| return UniswapV3Utils.divRoundingUp(x, y); | ||
| } | ||
|
|
||
| function getAmount0Delta( | ||
| uint160 sqrtRatioAX96, | ||
| uint160 sqrtRatioBX96, | ||
| uint128 liquidity, | ||
| bool roundUp | ||
| ) external pure returns (uint256) { | ||
| return UniswapV3Utils.getAmount0Delta(sqrtRatioAX96, sqrtRatioBX96, liquidity, roundUp); | ||
| } | ||
|
|
||
| function getAmount1Delta( | ||
| uint160 sqrtRatioAX96, | ||
| uint160 sqrtRatioBX96, | ||
| uint128 liquidity, | ||
| bool roundUp | ||
| ) external pure returns (uint256) { | ||
| return UniswapV3Utils.getAmount1Delta(sqrtRatioAX96, sqrtRatioBX96, liquidity, roundUp); | ||
| } | ||
|
|
||
| function getAmount0DeltaSigned( | ||
| uint160 sqrtRatioAX96, | ||
| uint160 sqrtRatioBX96, | ||
| int128 liquidity | ||
| ) external pure returns (int256) { | ||
| return UniswapV3Utils.getAmount0Delta(sqrtRatioAX96, sqrtRatioBX96, liquidity); | ||
| } | ||
|
|
||
| function getAmount1DeltaSigned( | ||
| uint160 sqrtRatioAX96, | ||
| uint160 sqrtRatioBX96, | ||
| int128 liquidity | ||
| ) external pure returns (int256) { | ||
| return UniswapV3Utils.getAmount1Delta(sqrtRatioAX96, sqrtRatioBX96, liquidity); | ||
| } | ||
|
|
||
| } | ||
|
|
||
| contract SafeCastHarness { | ||
|
|
||
| function toInt256(uint256 y) external pure returns (int256) { | ||
| return SafeCast.toInt256(y); | ||
| } | ||
|
|
||
| } | ||
|
|
||
| contract UniswapV3Utils_DivRoundingUp_Tests is Test { | ||
|
|
||
| UniswapV3UtilsHarness internal harness; | ||
|
|
||
| function setUp() public { | ||
| harness = new UniswapV3UtilsHarness(); | ||
| } | ||
|
|
||
| function test_divRoundingUp_exactDivision() external view { | ||
| assertEq(harness.divRoundingUp(10, 5), 2); | ||
| } | ||
|
|
||
| function test_divRoundingUp_roundsUp() external view { | ||
| assertEq(harness.divRoundingUp(11, 5), 3); | ||
| } | ||
|
|
||
| function test_divRoundingUp_zeroNumerator() external view { | ||
| assertEq(harness.divRoundingUp(0, 5), 0); | ||
| } | ||
|
|
||
| function test_divRoundingUp_one() external view { | ||
| assertEq(harness.divRoundingUp(1, 1), 1); | ||
| } | ||
|
|
||
| } | ||
|
|
||
| contract UniswapV3Utils_GetAmount0Delta_Tests is Test { | ||
|
|
||
| UniswapV3UtilsHarness internal harness; | ||
|
|
||
| // Use realistic sqrtPrice values (Q96 format) | ||
| // sqrtPrice for price=1 is 2^96 ≈ 79228162514264337593543950336 | ||
| uint160 internal constant SQRT_PRICE_1 = 79228162514264337593543950336; | ||
| // sqrtPrice for price=1.01 ≈ 79625483285009044410665803269 | ||
| uint160 internal constant SQRT_PRICE_1_01 = 79625483285009044410665803269; | ||
|
|
||
| function setUp() public { | ||
| harness = new UniswapV3UtilsHarness(); | ||
| } | ||
|
|
||
| function test_getAmount0Delta_roundUp() external view { | ||
| uint256 amount = harness.getAmount0Delta(SQRT_PRICE_1, SQRT_PRICE_1_01, 1e18, true); | ||
| assertGt(amount, 0); | ||
| } | ||
|
|
||
| function test_getAmount0Delta_roundDown() external view { | ||
| uint256 amountUp = harness.getAmount0Delta(SQRT_PRICE_1, SQRT_PRICE_1_01, 1e18, true); | ||
| uint256 amountDown = harness.getAmount0Delta(SQRT_PRICE_1, SQRT_PRICE_1_01, 1e18, false); | ||
| assertGe(amountUp, amountDown); | ||
| } | ||
|
|
||
| function test_getAmount0Delta_swappedPrices() external view { | ||
| // When A > B, should swap internally and return same result | ||
| uint256 amount1 = harness.getAmount0Delta(SQRT_PRICE_1, SQRT_PRICE_1_01, 1e18, true); | ||
| uint256 amount2 = harness.getAmount0Delta(SQRT_PRICE_1_01, SQRT_PRICE_1, 1e18, true); | ||
| assertEq(amount1, amount2); | ||
| } | ||
|
|
||
| function test_getAmount0DeltaSigned_positiveLiquidity() external view { | ||
| int256 amount = harness.getAmount0DeltaSigned(SQRT_PRICE_1, SQRT_PRICE_1_01, int128(1e18)); | ||
| assertGt(amount, 0); | ||
| } | ||
|
|
||
| function test_getAmount0DeltaSigned_negativeLiquidity() external view { | ||
| int256 amount = harness.getAmount0DeltaSigned(SQRT_PRICE_1, SQRT_PRICE_1_01, -int128(1e18)); | ||
| assertLt(amount, 0); | ||
| } | ||
|
|
||
| } | ||
|
|
||
| contract UniswapV3Utils_GetAmount1Delta_Tests is Test { | ||
|
|
||
| UniswapV3UtilsHarness internal harness; | ||
|
|
||
| uint160 internal constant SQRT_PRICE_1 = 79228162514264337593543950336; | ||
| uint160 internal constant SQRT_PRICE_1_01 = 79625483285009044410665803269; | ||
|
|
||
| function setUp() public { | ||
| harness = new UniswapV3UtilsHarness(); | ||
| } | ||
|
|
||
| function test_getAmount1Delta_roundUp() external view { | ||
| uint256 amount = harness.getAmount1Delta(SQRT_PRICE_1, SQRT_PRICE_1_01, 1e18, true); | ||
| assertGt(amount, 0); | ||
| } | ||
|
|
||
| function test_getAmount1Delta_roundDown() external view { | ||
| uint256 amountUp = harness.getAmount1Delta(SQRT_PRICE_1, SQRT_PRICE_1_01, 1e18, true); | ||
| uint256 amountDown = harness.getAmount1Delta(SQRT_PRICE_1, SQRT_PRICE_1_01, 1e18, false); | ||
| assertGe(amountUp, amountDown); | ||
| } | ||
|
|
||
| function test_getAmount1Delta_swappedPrices() external view { | ||
| uint256 amount1 = harness.getAmount1Delta(SQRT_PRICE_1, SQRT_PRICE_1_01, 1e18, true); | ||
| uint256 amount2 = harness.getAmount1Delta(SQRT_PRICE_1_01, SQRT_PRICE_1, 1e18, true); | ||
| assertEq(amount1, amount2); | ||
| } | ||
|
|
||
| function test_getAmount1DeltaSigned_positiveLiquidity() external view { | ||
| int256 amount = harness.getAmount1DeltaSigned(SQRT_PRICE_1, SQRT_PRICE_1_01, int128(1e18)); | ||
| assertGt(amount, 0); | ||
| } | ||
|
|
||
| function test_getAmount1DeltaSigned_negativeLiquidity() external view { | ||
| int256 amount = harness.getAmount1DeltaSigned(SQRT_PRICE_1, SQRT_PRICE_1_01, -int128(1e18)); | ||
| assertLt(amount, 0); | ||
| } | ||
|
|
||
| } | ||
|
|
||
| contract SafeCast_ToInt256_Tests is Test { | ||
|
|
||
| SafeCastHarness internal harness; | ||
|
|
||
| function setUp() public { | ||
| harness = new SafeCastHarness(); | ||
| } | ||
|
|
||
| function test_toInt256_zero() external view { | ||
| assertEq(harness.toInt256(0), 0); | ||
| } | ||
|
|
||
| function test_toInt256_maxValid() external view { | ||
| uint256 maxVal = uint256(type(int256).max); | ||
| assertEq(harness.toInt256(maxVal), type(int256).max); | ||
| } | ||
|
|
||
| function test_toInt256_overflow() external { | ||
| uint256 tooLarge = uint256(2 ** 255); | ||
| vm.expectRevert(); | ||
| harness.toInt256(tooLarge); | ||
| } | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -87,3 +87,56 @@ contract WEETHModule_Initialize_Tests is WEETHModule_TestBase { | |
| } | ||
|
|
||
| } | ||
|
|
||
| contract WEETHModule_AuthorizeUpgrade_Tests is WEETHModule_TestBase { | ||
|
|
||
| function test_authorizeUpgrade_notAuthorized() external { | ||
| WEETHModule weethModule = WEETHModule( | ||
| payable( | ||
| address( | ||
| new ERC1967Proxy( | ||
| address(new WEETHModule()), | ||
| abi.encodeCall( | ||
| WEETHModule.initialize, | ||
| (admin, almProxy) | ||
| ) | ||
| ) | ||
| ) | ||
| ) | ||
| ); | ||
|
|
||
| address newImpl = address(new WEETHModule()); | ||
|
|
||
| vm.expectRevert(abi.encodeWithSignature( | ||
| "AccessControlUnauthorizedAccount(address,bytes32)", | ||
| address(this), | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't use |
||
| DEFAULT_ADMIN_ROLE | ||
| )); | ||
| weethModule.upgradeToAndCall(newImpl, ""); | ||
| } | ||
|
|
||
| function test_authorizeUpgrade() external { | ||
| WEETHModule weethModule = WEETHModule( | ||
| payable( | ||
| address( | ||
| new ERC1967Proxy( | ||
| address(new WEETHModule()), | ||
| abi.encodeCall( | ||
| WEETHModule.initialize, | ||
| (admin, almProxy) | ||
| ) | ||
| ) | ||
| ) | ||
| ) | ||
| ); | ||
|
|
||
| address newImpl = address(new WEETHModule()); | ||
|
|
||
| vm.prank(admin); | ||
| weethModule.upgradeToAndCall(newImpl, ""); | ||
|
|
||
| // Verify the proxy still works after upgrade | ||
| assertEq(weethModule.almProxy(), almProxy); | ||
| } | ||
|
|
||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't use
this, but rather prank fromunauthorized.