-
Notifications
You must be signed in to change notification settings - Fork 504
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
Replace Implementation+etch Pattern with CREATE2 #60
Conversation
…vm cheatcodes for advancing block.timestamp
test/FullRange.t.sol
Outdated
(address hookAddress, bytes32 salt) = | ||
HookMiner.find(address(this), flags, 0, type(FullRange).creationCode, abi.encode(manager)); | ||
fullRange = new FullRange{salt: salt}(manager); | ||
require(address(fullRange) == hookAddress, "TestFullRange: hook address mismatch"); |
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.
confused about this check. Is there a scenario where this would be false and we'd want to halt the test? Doesn't the check on line 32 in HookMiner take care of this? Feels extra, or like we don't trust our hook miner...in which case it could maybe have its own tests 🤔
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.
It shouldnt fail and we can trust the miner. It's really a safety check since there's a minor footgun with the deployer
argument in HookMiner.find(address deployer, ...)
In tests, deployer
can be address(this)
or the pranking address from vm.prank
. There's a probability that the mined salt creates a valid address with the wrong deployer. i.e. HookMiner.find(alice, ...)
but forgetting to prank on new FullRange
. This would cause a mismatch between hookAddress
and address(fullRange)
The hook would still deploy but a dev might use hookAddress
in a way that causes false positive bugs/errors.
Happy to remove it or change it to assertEq
(to imply a safety check)
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.
after thinking about it some more, decided to remove it entirely. while it is good to encourage safety checks, i dont think its something that had to be showcased in the codebase
lgtm other than the nits. impressed with the lack of latency on the mining!? |
replaced by #122 mining addresses in tests has been reported to be annoyingly slow |
Related Issue
Closes #59
By using CREATE2 natively, we reduce the testing complexity. Prior to this change, testing a hook required a wrapper contract ('Implementation') that overrides
validateHookAddress
as a no-op. Within tests, users need to define both contracts, and etch the 'Implementation' bytecode to a desired addressThis pattern is noticeably verbose, with little reusable patterns that leads to copy + paste boilerplate
Description of changes
Created a helper library
test/utils/HookMiner.sol
, which finds a salt to deploy a hook with a specific flag patternUpdated the tests to deploy hooks with CREATE2 instead of the implementation and vm.etch pattern
Example:
Before, where
TWAMMImplementation
is a boilerplate wrapper contract around the actualTWAMM
After: