-
Notifications
You must be signed in to change notification settings - Fork 1k
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
31702 | ||
31746 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
208496 | ||
208508 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
140527 | ||
140539 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
170330 | ||
170342 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
146758 | ||
146770 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
149016 | ||
149028 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,4 +33,29 @@ contract ProtocolFeesImplementation is ProtocolFees { | |
function updateProtocolFees(Currency currency, uint256 amount) public { | ||
ProtocolFees._updateProtocolFees(currency, amount); | ||
} | ||
|
||
function consumeGasLimitAndFetchFee(PoolKey memory key) public { | ||
// consume gas before calling fetchProtocolFee / getting the protocolFeeForPool from the controller | ||
while (true) { | ||
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. Seems like these functions are the same -- could just write one and have that value as an input i think |
||
// once gas left is less than the limit, stop consuming gas | ||
if (gasleft() < 9079256829993496519) { | ||
break; | ||
} | ||
} | ||
// fetch the protocol fee after consuming gas | ||
// will revert since the gas left is less than the limit | ||
fetchProtocolFee(key); | ||
} | ||
|
||
function consumeGasAndFetchFee(PoolKey memory key) public { | ||
while (true) { | ||
// consume just under the gas limit | ||
if (gasleft() < 9079256829993490000) { | ||
break; | ||
} | ||
} | ||
// try to fetch the protocol fee | ||
// will revert while fetching since the gas limit has been reached | ||
fetchProtocolFee(key); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,7 +19,8 @@ import { | |
OutOfBoundsProtocolFeeControllerTest, | ||
RevertingProtocolFeeControllerTest, | ||
OverflowProtocolFeeControllerTest, | ||
InvalidReturnSizeProtocolFeeControllerTest | ||
InvalidReturnSizeProtocolFeeControllerTest, | ||
GasLimitProtocolFeeControllerTest | ||
} from "../src/test/ProtocolFeeControllerTest.sol"; | ||
|
||
contract ProtocolFeesTest is Test, GasSnapshot, Deployers { | ||
|
@@ -218,4 +219,30 @@ contract ProtocolFeesTest is Test, GasSnapshot, Deployers { | |
assertFalse(success); | ||
assertEq(protocolFee, 0); | ||
} | ||
|
||
function test_fetchProtocolFee_gasLimit() public { | ||
gasLimitFeeController = new GasLimitProtocolFeeControllerTest(); | ||
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. would love a clearer name - maybe |
||
protocolFees.setProtocolFeeController(gasLimitFeeController); | ||
vm.prank(address(gasLimitFeeController)); | ||
(bool success, uint24 protocolFee) = protocolFees.fetchProtocolFee(key); | ||
assertFalse(success); | ||
assertEq(protocolFee, 0); | ||
} | ||
|
||
function test_fetchProtocolFee_revertsWithProtocolFeeCannotBeFetched() public { | ||
protocolFees = new ProtocolFeesImplementation(9079256829993496519); | ||
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. Would be great to have this as a constant or something this file can have a 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. Hello, I'm not part of your team, but I have a question. Doesn't this method increase the testing time?
I'm suggesting this for testing time. |
||
protocolFees.setProtocolFeeController(feeController); | ||
vm.prank(address(feeController)); | ||
vm.expectRevert(IProtocolFees.ProtocolFeeCannotBeFetched.selector); | ||
// consumes too much gas before fetching the fee | ||
protocolFees.consumeGasLimitAndFetchFee(key); | ||
} | ||
|
||
function test_fetchProtocolFee_revertsWithGasLimitExceeded() public { | ||
protocolFees = new ProtocolFeesImplementation(9079256829993496519); | ||
protocolFees.setProtocolFeeController(feeController); | ||
vm.prank(address(feeController)); | ||
vm.expectRevert(); | ||
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. please can you fill in what the revert message should be for this case 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. I cant see why this one will be any different to the previous one? surely it also reverts with 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. 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 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. oh yeah i messed up the numbers |
||
protocolFees.consumeGasAndFetchFee(key); | ||
} | ||
} |
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.
lol beautiful