-
Notifications
You must be signed in to change notification settings - Fork 2.2k
feat(cheatcodes): add setEvmVersion / getEvmVersion #12014
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
0f9bfb6
feat(cheatcodes): add setEvmVersion / getEvmVersion
grandizzy 04cc1ca
Merge branch 'master' into issue-9840
grandizzy 0838c54
Add better explanation re evm version
grandizzy 50dd183
Nit
grandizzy 22fe73e
Merge branch 'master' into issue-9840
grandizzy b00875c
Merge branch 'master' into issue-9840
grandizzy 26cc853
Update cheatcode note to reflect exact evm version needed
grandizzy 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,99 @@ | ||
| //! Integration tests for EVM specifications. | ||
|
|
||
| use crate::{config::*, test_helpers::TEST_DATA_PARIS}; | ||
| use foundry_test_utils::Filter; | ||
| use foundry_test_utils::{Filter, forgetest_init, rpc, str}; | ||
| use revm::primitives::hardfork::SpecId; | ||
|
|
||
| #[tokio::test(flavor = "multi_thread")] | ||
| async fn test_shanghai_compat() { | ||
| let filter = Filter::new("", "ShanghaiCompat", ".*spec"); | ||
| TestConfig::with_filter(TEST_DATA_PARIS.runner(), filter).spec_id(SpecId::SHANGHAI).run().await; | ||
| } | ||
|
|
||
| // Test evm version switch during tests / scripts. | ||
| // <https://github.com/foundry-rs/foundry/issues/9840> | ||
| // <https://github.com/foundry-rs/foundry/issues/6228> | ||
| forgetest_init!(test_set_evm_version, |prj, cmd| { | ||
| let endpoint = rpc::next_http_archive_rpc_url(); | ||
| prj.add_test( | ||
| "TestEvmVersion.t.sol", | ||
| &r#" | ||
| import {Test} from "forge-std/Test.sol"; | ||
|
|
||
| interface EvmVm { | ||
| function getEvmVersion() external pure returns (string memory evm); | ||
| function setEvmVersion(string calldata evm) external; | ||
| } | ||
|
|
||
| interface ICreate2Deployer { | ||
| function computeAddress(bytes32 salt, bytes32 codeHash) external view returns (address); | ||
| } | ||
|
|
||
| contract TestEvmVersion is Test { | ||
| function test_evm_version() public { | ||
| EvmVm evm = EvmVm(address(bytes20(uint160(uint256(keccak256("hevm cheat code")))))); | ||
| vm.createSelectFork("<rpc>"); | ||
|
|
||
| evm.setEvmVersion("istanbul"); | ||
| evm.getEvmVersion(); | ||
|
|
||
| // revert with NotActivated for istanbul | ||
| vm.expectRevert(); | ||
| compute(); | ||
|
|
||
| evm.setEvmVersion("shanghai"); | ||
| evm.getEvmVersion(); | ||
| compute(); | ||
|
|
||
| // switch to Paris, expect revert with NotActivated | ||
| evm.setEvmVersion("paris"); | ||
| vm.expectRevert(); | ||
| compute(); | ||
| } | ||
|
|
||
| function compute() internal view { | ||
| ICreate2Deployer(0x35Da41c476fA5c6De066f20556069096A1F39364).computeAddress(bytes32(0), bytes32(0)); | ||
| } | ||
| } | ||
| "#.replace("<rpc>", &endpoint), | ||
| ); | ||
| // Tests should fail and record counterexample with value 2. | ||
| cmd.args(["test", "--mc", "TestEvmVersion", "-vvvv"]).assert_success().stdout_eq(str![[r#" | ||
| [COMPILING_FILES] with [SOLC_VERSION] | ||
| [SOLC_VERSION] [ELAPSED] | ||
| Compiler run successful! | ||
|
|
||
| Ran 1 test for test/TestEvmVersion.t.sol:TestEvmVersion | ||
| [PASS] test_evm_version() ([GAS]) | ||
| Traces: | ||
| [..] TestEvmVersion::test_evm_version() | ||
| ├─ [0] VM::createSelectFork("<rpc url>") | ||
| │ └─ ← [Return] 0 | ||
| ├─ [0] VM::setEvmVersion("istanbul") | ||
| │ └─ ← [Return] | ||
| ├─ [0] VM::getEvmVersion() [staticcall] | ||
| │ └─ ← [Return] "istanbul" | ||
| ├─ [0] VM::expectRevert(custom error 0xf4844814) | ||
| │ └─ ← [Return] | ||
| ├─ [..] 0x35Da41c476fA5c6De066f20556069096A1F39364::computeAddress(0x0000000000000000000000000000000000000000000000000000000000000000, 0x0000000000000000000000000000000000000000000000000000000000000000) [staticcall] | ||
| │ └─ ← [NotActivated] EvmError: NotActivated | ||
| ├─ [0] VM::setEvmVersion("shanghai") | ||
| │ └─ ← [Return] | ||
| ├─ [0] VM::getEvmVersion() [staticcall] | ||
| │ └─ ← [Return] "shanghai" | ||
| ├─ [..] 0x35Da41c476fA5c6De066f20556069096A1F39364::computeAddress(0x0000000000000000000000000000000000000000000000000000000000000000, 0x0000000000000000000000000000000000000000000000000000000000000000) [staticcall] | ||
| │ └─ ← [Return] 0x0f40d7B7669e3a6683EaB25358318fd42a9F2342 | ||
| ├─ [0] VM::setEvmVersion("paris") | ||
| │ └─ ← [Return] | ||
| ├─ [0] VM::expectRevert(custom error 0xf4844814) | ||
| │ └─ ← [Return] | ||
| ├─ [..] 0x35Da41c476fA5c6De066f20556069096A1F39364::computeAddress(0x0000000000000000000000000000000000000000000000000000000000000000, 0x0000000000000000000000000000000000000000000000000000000000000000) [staticcall] | ||
| │ └─ ← [NotActivated] EvmError: NotActivated | ||
| └─ ← [Stop] | ||
|
|
||
| Suite result: ok. 1 passed; 0 failed; 0 skipped; [ELAPSED] | ||
|
|
||
| Ran 1 test suite [ELAPSED]: 1 tests passed, 0 failed, 0 skipped (1 total tests) | ||
|
|
||
| "#]]); | ||
| }); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
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.
actually can we add a note on the cheatcodes docs too? that runtime/execution evm version is not the same as compilation one
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.
👍 updated in 0838c54