-
Notifications
You must be signed in to change notification settings - Fork 25
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 gas measurement to tests and refactor some test structures #337
Merged
Merged
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 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 |
---|---|---|
@@ -1,8 +1,6 @@ | ||
[submodule "lib/openzeppelin-contracts"] | ||
path = lib/openzeppelin-contracts | ||
url = https://github.com/OpenZeppelin/openzeppelin-contracts | ||
branch = v5.0.2 | ||
[submodule "lib/forge-std"] | ||
path = lib/forge-std | ||
url = https://github.com/foundry-rs/forge-std | ||
branch = v1.3.0 |
Submodule forge-std
updated
44 files
This file contains 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,4 @@ | ||
{ | ||
"approveTokens(): testApproveTokens": "136967", | ||
"rescueTokens(): testRescueTokens": "86851" | ||
} |
This file contains 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,8 @@ | ||
{ | ||
"pause(): testSpendFromUserToAfterUnpause": "27667", | ||
"spendFromUserTo(): testSpendFromUserTo": "63533", | ||
"spendFromUserTo(): testSpendFromUserToAfterUnpause": "63533", | ||
"spendFromUserTo(): testSpendFromUserToWithDeflationaryToken": "91576", | ||
"spendFromUserTo(): testSpendFromUserToWithNoReturnValueToken": "68943", | ||
"unpause(): testSpendFromUserToAfterUnpause": "27645" | ||
} |
This file contains 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,11 @@ | ||
{ | ||
"getBalance(): testGetBalance": "6107", | ||
"getBalance(): testGetBalance(ETH_ADDRESS)": "764", | ||
"getBalance(): testGetBalance(ZERO_ADDRESS)": "781", | ||
"isETH(): testIsETH(ETH_ADDRESS)": "441", | ||
"isETH(): testIsETH2(ZERO_ADDRESS)": "458", | ||
"transferTo(): testDoNothingIfTransferToSelf": "22431", | ||
"transferTo(): testDoNothingIfTransferWithZeroAmount": "22419", | ||
"transferTo(): testTransferETH": "57012", | ||
"transferTo(): testTransferToken": "51501" | ||
} |
This file contains 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,6 @@ | ||
{ | ||
"approveTokens(): testApproveTokens": "54307", | ||
"setCoordinator(): testSetCoordinator": "30043", | ||
"submitLimitOrderFill(): testFillWithETH": "192971", | ||
"submitLimitOrderFill(): testFillWithPermission": "256473" | ||
} |
This file contains 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,5 @@ | ||
{ | ||
"EIP712_DOMAIN_SEPARATOR(): testDomainSeparatorOnChain": "276", | ||
"EIP712_DOMAIN_SEPARATOR(): testDomainSeparatorOnDifferentChain": "626", | ||
"getEIP712Hash(): testGetEIP712Hash": "828" | ||
} |
This file contains 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,9 @@ | ||
{ | ||
"executeSwap(): testGenericSwapWithUniswap": "251909", | ||
"executeSwap(): testLeaveOneWeiWithMultipleUsers(the first deposit)": "251909", | ||
"executeSwap(): testLeaveOneWeiWithMultipleUsers(the second deposit)": "208263", | ||
"executeSwap(): testSwapWithETHInput": "100382", | ||
"executeSwap(): testSwapWithETHOutput": "130241", | ||
"executeSwap(): testSwapWithLessOutputButWithinTolerance": "160688", | ||
"executeSwapWithSig(): testGenericSwapRelayed": "283756" | ||
} |
This file contains 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,20 @@ | ||
{ | ||
"cancelOrder(): testCancelOrder": "52753", | ||
"fillLimitOrder(): testFillLimitOrderWithETH": "158029", | ||
"fillLimitOrder(): testFillWithBetterTakingAmount": "215471", | ||
"fillLimitOrder(): testFillWithBetterTakingAmountButGetAdjusted": "215705", | ||
"fillLimitOrder(): testFillWithETHRefund": "165308", | ||
"fillLimitOrder(): testFillWithLargerVolumeAndSettleAsManyAsPossible": "215693", | ||
"fillLimitOrder(): testFillWithoutMakerSigForVerifiedOrder": "215471", | ||
"fillLimitOrder(): testFillWithoutMakerSigForVerifiedOrder(without makerSig)": "120983", | ||
"fillLimitOrder(): testFullyFillLimitOrder": "215471", | ||
"fillLimitOrder(): testFullyFillLimitOrderUsingAMM": "235046", | ||
"fillLimitOrder(): testPartiallyFillLimitOrder": "215471", | ||
"fillLimitOrderFullOrKill(): testFillWithFOK": "215449", | ||
"fillLimitOrderGroup(): testGroupFillRingTrade": "291749", | ||
"fillLimitOrderGroup(): testGroupFillWithPartialWETHUnwrap": "277818", | ||
"fillLimitOrderGroup(): testGroupFillWithTakerPrefundETH": "198117", | ||
"fillLimitOrderGroup(): testGroupFillWithWETHUnwrap": "198117", | ||
"fillLimitOrderGroup(): testPartialFillLargeOrderWithSmallOrders": "265910", | ||
"testGroupFillWithProfit: fillLimitOrderGroup()": "225225" | ||
} |
This file contains 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,5 @@ | ||
{ | ||
"acceptOwnership(): testAcceptOwnership": "28390", | ||
"nominateNewOwner(): testNominateNewOwner": "47132", | ||
"renounceOwnership(): testRenounceOwnership": "25351" | ||
} |
This file contains 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,15 @@ | ||
{ | ||
"cancelRFQOffer(): testCancelRFQOffer": "49848", | ||
"fillRFQ(): testFillRFQ": "219666", | ||
"fillRFQ(): testFillRFQTakerGetRawETH": "238797", | ||
"fillRFQ(): testFillRFQWithRawETH": "159563", | ||
"fillRFQ(): testFillRFQWithRawETHAndReceiveWETH": "174630", | ||
"fillRFQ(): testFillRFQWithTakerApproveAllowanceTarget": "187631", | ||
"fillRFQ(): testFillRFQWithWETH": "222131", | ||
"fillRFQ(): testFillRFQWithWETHAndReceiveWETH": "208373", | ||
"fillRFQ(): testFillRFQWithZeroFee": "192740", | ||
"fillRFQ(): testFillWithContract": "223381", | ||
"fillRFQ(): testPartialFill": "219826", | ||
"fillRFQWithSig(): testFillRFQByTakerSig": "228592", | ||
"setFeeCollector(): testSetFeeCollector": "30099" | ||
} |
This file contains 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,11 @@ | ||
{ | ||
"executeStrategy(): testMultipleAMMs": "610173", | ||
"executeStrategy(): testUniswapV2WithWETHUnwrap": "142340", | ||
"executeStrategy(): testUniswapV3WithAmountReplace": "161811", | ||
"executeStrategy(): testUniswapV3WithMaxAmountReplace": "161607", | ||
"executeStrategy(): testUniswapV3WithoutAmountReplace": "155017", | ||
"executeStrategy(): testV6LOIntegration": "180661", | ||
"executeStrategy(): testV6RFQIntegration": "183394", | ||
"executeStrategy(): testV6RFQIntegrationWhenMakerTokenIsETH": "149739", | ||
"executeStrategy(): testV6RFQIntegrationWhenTakerTokenIsETH": "204956" | ||
} |
This file contains 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,7 @@ | ||
{ | ||
"collect(): testCollectByAllowanceTarget": "66338", | ||
"collect(): testCollectByPermit2AllowanceTransfer": "102281", | ||
"collect(): testCollectByPermit2SignatureTransfer": "94388", | ||
"collect(): testCollectByTokenApproval": "58597", | ||
"collect(): testCollectByTokenPermit": "93729" | ||
} |
This file contains 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 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 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 |
---|---|---|
|
@@ -5,48 +5,55 @@ import { Test } from "forge-std/Test.sol"; | |
import { EIP712 } from "contracts/abstracts/EIP712.sol"; | ||
|
||
contract EIP712Test is Test { | ||
EIP712TestContract eip712; | ||
EIP712Harness eip712Harness; | ||
|
||
// Dummy struct hash for testing | ||
bytes32 public constant DUMMY_STRUCT_HASH = keccak256("DummyStruct(string message)"); | ||
|
||
function setUp() public { | ||
eip712 = new EIP712TestContract(); | ||
eip712Harness = new EIP712Harness(); | ||
} | ||
|
||
function testOriginalChainId() public { | ||
uint256 chainId = block.chainid; | ||
assertEq(eip712.originalChainId(), chainId); | ||
assertEq(eip712Harness.originalChainId(), chainId); | ||
} | ||
|
||
function testOriginalDomainSeparator() public { | ||
bytes32 expectedDomainSeparator = eip712.calculateDomainSeparator(); | ||
assertEq(eip712.originalEIP712DomainSeparator(), expectedDomainSeparator); | ||
bytes32 expectedDomainSeparator = eip712Harness.calculateDomainSeparator(); | ||
assertEq(eip712Harness.originalEIP712DomainSeparator(), expectedDomainSeparator); | ||
} | ||
|
||
function testGetEIP712Hash() public { | ||
bytes32 structHash = DUMMY_STRUCT_HASH; | ||
bytes32 domainSeparator = eip712.calculateDomainSeparator(); | ||
bytes32 expectedEIP712Hash = keccak256(abi.encodePacked(eip712.EIP191_HEADER(), domainSeparator, structHash)); | ||
bytes32 domainSeparator = eip712Harness.calculateDomainSeparator(); | ||
bytes32 expectedEIP712Hash = keccak256(abi.encodePacked(eip712Harness.EIP191_HEADER(), domainSeparator, structHash)); | ||
|
||
assertEq(eip712.getEIP712HashWrap(structHash), expectedEIP712Hash); | ||
assertEq(eip712Harness.exposedGetEIP712Hash(structHash), expectedEIP712Hash); | ||
vm.snapshotGasLastCall("EIP712", "getEIP712Hash(): testGetEIP712Hash"); | ||
} | ||
|
||
function testDomainSeparatorOnDifferentChain() public { | ||
uint256 chainId = block.chainid + 1234; | ||
vm.chainId(chainId); | ||
|
||
bytes32 newDomainSeparator = eip712.calculateDomainSeparator(); | ||
assertEq(eip712.EIP712_DOMAIN_SEPARATOR(), newDomainSeparator, "Domain separator should match the expected value on a different chain"); | ||
bytes32 newDomainSeparator = eip712Harness.calculateDomainSeparator(); | ||
assertEq(eip712Harness.EIP712_DOMAIN_SEPARATOR(), newDomainSeparator, "Domain separator should match the expected value on a different chain"); | ||
vm.snapshotGasLastCall("EIP712", "EIP712_DOMAIN_SEPARATOR(): testDomainSeparatorOnDifferentChain"); | ||
} | ||
|
||
function testDomainSeparatorOnChain() public { | ||
eip712Harness.EIP712_DOMAIN_SEPARATOR(); | ||
vm.snapshotGasLastCall("EIP712", "EIP712_DOMAIN_SEPARATOR(): testDomainSeparatorOnChain"); | ||
} | ||
} | ||
|
||
contract EIP712TestContract is EIP712 { | ||
contract EIP712Harness is EIP712 { | ||
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. A best pratice for tseting internal fuction: https://book.getfoundry.sh/tutorials/best-practices?highlight=har#test-harnesses |
||
function calculateDomainSeparator() external view returns (bytes32) { | ||
return keccak256(abi.encode(EIP712_TYPE_HASH, keccak256(bytes(EIP712_NAME)), keccak256(bytes(EIP712_VERSION)), block.chainid, address(this))); | ||
} | ||
|
||
function getEIP712HashWrap(bytes32 structHash) public view returns (bytes32) { | ||
return super.getEIP712Hash(structHash); | ||
function exposedGetEIP712Hash(bytes32 structHash) public view returns (bytes32) { | ||
return getEIP712Hash(structHash); | ||
} | ||
} |
Oops, something went wrong.
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.
The
branch
entry is an optional setting. However, its inclusion causesforge update
to fail when updating dependencies.Reference: foundry-rs/foundry#3720 (comment)