-
Notifications
You must be signed in to change notification settings - Fork 333
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
feat: Refactor assumeNot*
std cheats
#407
Merged
Merged
Changes from 3 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
1730a9b
fix: exclude vm address from assumeNoPrecompiles
Sabnock01 934e0ae
forge fmt
Sabnock01 49bc2a6
oops
Sabnock01 0ab33b1
update assumePayableIsNot
Sabnock01 9ab202f
forge fmt
Sabnock01 5c869c9
Merge branch 'master' into fix/assume-no-precompiles
Sabnock01 0b25de5
forge fmt v2
Sabnock01 0b3b438
remove exposed_assumePayable test
Sabnock01 508abbb
modify _isPayable to be compiler agnostic
Sabnock01 cdecd83
compiler agnostic v2
Sabnock01 6e10c88
warnings
Sabnock01 73cca73
minor fixes
Sabnock01 c31747d
minor fixes v2
Sabnock01 ff9e33d
fix: make suggested changes
Sabnock01 53abaa4
forge fmt
Sabnock01 59d5726
fix: correct use of console address
Sabnock01 d9f25df
fix: remove extcodesize check
Sabnock01 3981afc
chore: tweak function arg order and other small cleanup
mds1 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
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
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.
Should we also exclude the
console.log
address here, which is0x000000000000000000636F6e736F6c652e6c6f67
?Though, both vm and console aren't technically precompiles in the sense meant by this function, so perhaps we should instead go with something like this:
The latter would be my preference because it scales better and provides a consistent UX for all address types. There's some decisions though, e.g. is the default test contract address part of the
ForgreAddresses
type, with the vm and console address, or should it be a separate type that we split intoForgePrecompiles
andForgeAddresses
or something like thatThere 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 like this approach much better. Will rework.
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.
Wrote impl's for both the array and overloaded versions. Prefer the array version personally. Less code and easier to test. Either one is fine though.
Two questions though:
call
on the address with somemsg.value
and checkingsuccess
.assumeAddressIsNot
but both this and the overloaded version fail with too manyvm.assume
rejects when using a fuzz test.What do you think of this method of testing where instead of calling
assumeAddressIsNot
all the derivative functions are called?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.
How is the UX with the array version? Main reason I though overloads would be better is:
In the forge-std
assumePayable
method we just checksuccess
on a zero value call. But on second thought I'm not sure if our tests are sufficiently robust, e.g. if a contract has a non-payablefallback
and noreceive
, that contract is not payable, and I think ourassumePayable
would wrongly returntrue
.Better way is probably what you said, specifically:
If it helps, we can raise the
assume
limit for that test only using the inline config approach. I think the most robust way would be something like the below, so if a new address type is added it's automatically testedThere 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.
Did not know of in-line config!
Also UX is certainly worse with the array impl but it's less code for
StdCheats.sol
is what I meant. But on second thought, we needn't concern ourselves about that so I am in favor of the overloaded one.Few more q's if you don't mind:
Payable
andNonPayable
are mutually exclusive right, so we wouldn't need to iterate through the whole enum but instead n - 1?assumeAddressIsNot
right? That's the wayassumeNoBlacklisted
,assumeNoPrecompiles
, andassumePayable
are.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.
Hm it should work, see the solidity docs:
Ah good point. So maybe we put payable/nonpayable as indexes 0 and 1 in the enum, then we have:
Wdyt of that? This way new values added to the end of the enum are automatically tested
Oops yes, sorry forgot to include that 😅
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.
type(AddressType).max
as it turns out returns an enum so it's trivial enough just to cast touint8
.And I like the testing structure though even when setting
max_fuzz_rejects
to some absurdly high number like10_000_000
which takes several minutes to complete, a fuzz test onassumeNoNonPayable
still fails with too many rejects. Separately, was not able to get the in-line config to work for this even though it's documented. Will open issue.So for both
assumeNoPayable
andassumeNonPayable
I went with modified versions of the old test for the now deprecatedassumePayable
.Latest impl pushed.
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.
Awesome sounds great, thanks! Lmk if this is ready for review or if you still have changes left—will be tied up today/tomorrow but should be able to review this thursday
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's ready for review!