Skip to content
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: etch some bytes to empty accounts on mock #2576

Merged
merged 1 commit into from
Aug 3, 2022

Conversation

onbjerg
Copy link
Member

@onbjerg onbjerg commented Aug 3, 2022

Motivation

It might be preferred in some situations to mock functions on empty accounts instead of deploying a contract just to overwrite all of the calls. This works fine in a lot of cases, but if you mock a function with no return value, Solidity will insert an extcodesize check to make sure the target address has code to run.

Functions with no return values are usually mocked if you are mocking a contract that is acted upon by some other contract.

Solution

If the target of mockCall has no code we etch a singular 0 byte (STOP)

Closes #1987

@onbjerg onbjerg added the T-feature Type: feature label Aug 3, 2022
Comment on lines +273 to +274
.map(|code| code.is_empty())
.unwrap_or(true)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there's also map_or https://doc.rust-lang.org/stable/std/option/enum.Option.html#method.map_or

but I still prefer unwrap_or just because this is more readable

@mattsse mattsse merged commit 3df9536 into master Aug 3, 2022
@mattsse mattsse deleted the onbjerg/mock-call-etch branch August 3, 2022 11:36
iFrostizz pushed a commit to iFrostizz/foundry that referenced this pull request Nov 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-feature Type: feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

extcodesize check bypass for mockCall
2 participants