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

tests for fee controller gas limit #728

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

Conversation

dianakocsis
Copy link
Contributor

Related Issue

Which issue does this pull request resolve?

Description of changes

Copy link

Forge code coverage:

File % Lines % Statements % Branches % Funcs
src/ERC6909.sol 91.30% (21/23) 85.71% (24/28) 100.00% (4/4) 85.71% (6/7)
src/ERC6909Claims.sol 100.00% (6/6) 100.00% (8/8) 100.00% (4/4) 100.00% (1/1)
src/Extsload.sol 100.00% (0/0) 100.00% (0/0) 100.00% (0/0) 100.00% (3/3)
src/Exttload.sol 100.00% (0/0) 100.00% (0/0) 100.00% (0/0) 50.00% (1/2)
src/NoDelegateCall.sol 100.00% (3/3) 100.00% (5/5) 100.00% (2/2) 100.00% (3/3)
src/PoolManager.sol 100.00% (83/83) 98.25% (112/114) 94.12% (32/34) 100.00% (17/17)
src/ProtocolFees.sol 100.00% (20/20) 100.00% (34/34) 100.00% (12/12) 100.00% (6/6)
src/libraries/BitMath.sol 100.00% (47/47) 100.00% (57/57) 100.00% (36/36) 100.00% (2/2)
src/libraries/CurrencyDelta.sol 100.00% (4/4) 100.00% (6/6) 100.00% (0/0) 100.00% (3/3)
src/libraries/CustomRevert.sol 100.00% (0/0) 100.00% (0/0) 100.00% (0/0) 100.00% (6/6)
src/libraries/FullMath.sol 100.00% (28/28) 100.00% (32/32) 100.00% (8/8) 100.00% (2/2)
src/libraries/Hooks.sol 100.00% (77/77) 100.00% (139/139) 100.00% (56/56) 100.00% (14/14)
src/libraries/LPFeeLibrary.sol 100.00% (10/10) 100.00% (17/17) 100.00% (4/4) 100.00% (7/7)
src/libraries/LiquidityMath.sol 100.00% (2/2) 100.00% (1/1) 100.00% (1/1) 100.00% (1/1)
src/libraries/Lock.sol 100.00% (1/1) 100.00% (1/1) 100.00% (0/0) 100.00% (3/3)
src/libraries/NonZeroDeltaCount.sol 100.00% (3/3) 100.00% (3/3) 100.00% (0/0) 100.00% (3/3)
src/libraries/ParseBytes.sol 100.00% (3/3) 100.00% (3/3) 100.00% (0/0) 100.00% (3/3)
src/libraries/Pool.sol 99.35% (153/154) 99.42% (170/171) 96.51% (83/86) 100.00% (13/13)
src/libraries/Position.sol 100.00% (11/11) 100.00% (12/12) 100.00% (4/4) 100.00% (2/2)
src/libraries/ProtocolFeeLibrary.sol 100.00% (4/4) 100.00% (6/6) 100.00% (0/0) 100.00% (4/4)
src/libraries/Reserves.sol 100.00% (7/7) 100.00% (12/12) 100.00% (6/6) 100.00% (3/3)
src/libraries/SafeCast.sol 100.00% (10/10) 100.00% (26/26) 100.00% (10/10) 100.00% (6/6)
src/libraries/SqrtPriceMath.sol 100.00% (37/37) 100.00% (53/53) 82.35% (14/17) 100.00% (9/9)
src/libraries/StateLibrary.sol 100.00% (65/65) 100.00% (94/94) 100.00% (4/4) 100.00% (14/14)
src/libraries/SwapMath.sol 100.00% (22/22) 100.00% (24/24) 100.00% (6/6) 100.00% (2/2)
src/libraries/TickBitmap.sol 100.00% (17/17) 100.00% (23/23) 100.00% (3/3) 100.00% (4/4)
src/libraries/TickMath.sol 100.00% (95/95) 100.00% (140/140) 100.00% (43/43) 100.00% (4/4)
src/libraries/TransientStateLibrary.sol 87.50% (7/8) 84.62% (11/13) 100.00% (0/0) 75.00% (3/4)
src/libraries/UnsafeMath.sol 100.00% (1/1) 100.00% (1/1) 100.00% (0/0) 100.00% (1/1)
src/types/BalanceDelta.sol 100.00% (2/2) 100.00% (2/2) 100.00% (0/0) 100.00% (2/2)
src/types/BeforeSwapDelta.sol 100.00% (2/2) 100.00% (2/2) 100.00% (0/0) 100.00% (2/2)
src/types/Currency.sol 100.00% (12/12) 94.12% (16/17) 100.00% (8/8) 100.00% (6/6)
src/types/PoolId.sol 100.00% (1/1) 100.00% (1/1) 100.00% (0/0) 100.00% (1/1)
src/types/Slot0.sol 100.00% (8/8) 100.00% (8/8) 100.00% (0/0) 100.00% (8/8)
Total 85.52% (1476/1726) 85.63% (1990/2324) 62.23% (519/834) 79.42% (355/447)

contract GasLimitProtocolFeeControllerTest is IProtocolFeeController {
function protocolFeeForPool(PoolKey memory /* key */ ) external pure returns (uint24) {
// consume gas
while (true) {}
Copy link
Contributor

Choose a reason for hiding this comment

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

lol beautiful

}

function test_fetchProtocolFee_revertsWithProtocolFeeCannotBeFetched() public {
protocolFees = new ProtocolFeesImplementation(9079256829993496519);
Copy link
Contributor

Choose a reason for hiding this comment

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

Would be great to have this as a constant or something

this file can have a GAS_LIMIT and then set it as an immutable in the implementation contract. And then that contract can just access it too?

Copy link
Contributor

@havi-kim havi-kim Jun 3, 2024

Choose a reason for hiding this comment

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

Hello, I'm not part of your team, but I have a question. Doesn't this method increase the testing time?

    function test_fetchProtocolFee_revertsWithProtocolFeeCannotBeFetched() public {
        uint256 gasLimit = 5000;
        protocolFees = new ProtocolFeesImplementation(gasLimit);
        protocolFees.setProtocolFeeController(feeController);
        vm.prank(address(feeController));
        vm.expectRevert(IProtocolFees.ProtocolFeeCannotBeFetched.selector);
        protocolFees.fetchProtocolFee{gas: gasLimit - 1}(key);
    }

I'm suggesting this for testing time.
Thank you for considering my suggestion.

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.

Some thoughts

@@ -218,4 +219,30 @@ contract ProtocolFeesTest is Test, GasSnapshot, Deployers {
assertFalse(success);
assertEq(protocolFee, 0);
}

function test_fetchProtocolFee_gasLimit() public {
gasLimitFeeController = new GasLimitProtocolFeeControllerTest();
Copy link
Contributor

Choose a reason for hiding this comment

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

would love a clearer name - maybe ConsumesGasLimit...?

protocolFees = new ProtocolFeesImplementation(9079256829993496519);
protocolFees.setProtocolFeeController(feeController);
vm.prank(address(feeController));
vm.expectRevert();
Copy link
Contributor

Choose a reason for hiding this comment

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

please can you fill in what the revert message should be for this case

Copy link
Contributor

Choose a reason for hiding this comment

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

I cant see why this one will be any different to the previous one? surely it also reverts with ProtocolFeeCannotBeFetched because its consuming even more gas and the amount left is even lower?

Copy link
Member

Choose a reason for hiding this comment

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

would agree here - not sure what the difference is if there is one besides just consuming a different amount of gas before calling fetchProtocolFee

You could fuzz that amount even

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oh yeah i messed up the numbers


function consumeGasLimitAndFetchFee(PoolKey memory key) public {
// consume gas before calling fetchProtocolFee / getting the protocolFeeForPool from the controller
while (true) {
Copy link
Member

Choose a reason for hiding this comment

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

Seems like these functions are the same -- could just write one and have that value as an input i think

protocolFees = new ProtocolFeesImplementation(9079256829993496519);
protocolFees.setProtocolFeeController(feeController);
vm.prank(address(feeController));
vm.expectRevert();
Copy link
Member

Choose a reason for hiding this comment

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

would agree here - not sure what the difference is if there is one besides just consuming a different amount of gas before calling fetchProtocolFee

You could fuzz that amount even

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.

4 participants