-
Notifications
You must be signed in to change notification settings - Fork 37
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
chore: migrate GPv2Order eip712 tests to Foundry #195
Conversation
With the removal of ethers, I'm not so sure about the efficacy of this test (or doing EIP-712 computation as is). This particular test that's being migrated seems more about ensuring that I think in general, the test mostly re-implements the logic within the contract itself and I'm unsure of the efficacy of the test in general. |
This is how we compute the EIP712 hash in the contract. This is how we compute it in the test. I've little doubt that the test overall has very high value, but I agree that it would be better to have the EIP712 layer handled somewhere else rather than implementing it directly. I did quite a bit of research on making this work with Foundry and to me the most credible way out is native Solidity support of EIP712, and I mentioned in the inline comments how a migration could look like. |
test/libraries/Order.sol
Outdated
} | ||
|
||
function ALL_FLAGS() internal pure returns (Flags[] memory out) { | ||
uint256 numBools = 2; |
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.
I'm a little confused as to "numBools" of 2, yet Flags only contains a single boolean parameter?
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.
On further inspection, it seems this is referring to the number of permutations associated with boolean values (and given a single boolean, would correspond to 2 permutations).
Given this, I'd sooner see numBools = 1
and then in the array length declared below, to multiply numBools
by 2, with a comment on the out
variable reflecting that it contains all permutations of all flags.
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.
Good point. Is it better now?
Co-authored-by: mfw78 <53399572+mfw78@users.noreply.github.com>
Description
See title.
This part was particularly painful to port to Solidity; most notably, there are a lot of missing quality-of-life features when handling arrays.
Since we don't have
ethers
anymore, I had to build my own EIP712 encoding library (as recommended by Foundry).As I could have introduced new bugs in the library, the related tests have become more aggressive (for example, all flag combinations are tested for consistency with the contract). There are also a few sanity checks which have already turned out to be useful during development.
I also sneakily introduced fuzz tests, since they seemed appropriate here.
Sorry for the horrible nested loops, suggestions on how to get rid of them are welcome.
The good news: there's a chance that a few things can be simplified with a future version of the compiler, see comments in code.
Test Plan
CI.
Related Issues
#117