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

"vm.setBlockhash" cheatcode #7929

Open
zomglings opened this issue May 14, 2024 · 4 comments
Open

"vm.setBlockhash" cheatcode #7929

zomglings opened this issue May 14, 2024 · 4 comments
Labels
good first issue Good for newcomers T-feature Type: feature

Comments

@zomglings
Copy link

zomglings commented May 14, 2024

Component

cheatcodes

Describe the feature you would like

A vm.setBlockhash cheat code would be very convenient for testing code that uses the Solidity blockhash function.

This is how it would be used:

vm.roll(block.number + 1);
vm.setBlockhash(block.number - 1, "1234");
assertEq(blockhash(block.number - 1), "1234");

Currently, the easiest way to test code that calls blockhash is to wrap the blockhash call in a virtual, internal method and then create a test class that overrides that method to mock blockhash calls.

I'd rather just have the mocking performed at the level of the vm.

If this is considered sufficiently useful, I would be happy to try my hand at adding this cheat code. Just don't want to learn rust, etc. to add this only to have a PR rejected if the feature isn't seen as useful.

Additional context

No response

@zomglings zomglings added the T-feature Type: feature label May 14, 2024
@zomglings
Copy link
Author

@onbjerg
Copy link
Member

onbjerg commented May 14, 2024

Unsure if this makes sense to add if https://eips.ethereum.org/EIPS/eip-2935 is included in Prague, as this could be emulated with just setting the appropriate slot on the contract

@mattsse mattsse added the good first issue Good for newcomers label May 14, 2024
@zomglings
Copy link
Author

Unsure if this makes sense to add if https://eips.ethereum.org/EIPS/eip-2935 is included in Prague, as this could be emulated with just setting the appropriate slot on the contract

In that case, wouldn't vm.setBlockhash still be a useful shorthand to set that slot?

@mattsse
Copy link
Member

mattsse commented May 15, 2024

yeah for setting a slot this will still be useful imo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers T-feature Type: feature
Projects
None yet
Development

No branches or pull requests

3 participants