|
1 | 1 | //! Integration tests for EVM specifications.
|
2 | 2 |
|
3 | 3 | use crate::{config::*, test_helpers::TEST_DATA_PARIS};
|
4 |
| -use foundry_test_utils::Filter; |
| 4 | +use foundry_test_utils::{Filter, forgetest_init, rpc, str}; |
5 | 5 | use revm::primitives::hardfork::SpecId;
|
6 | 6 |
|
7 | 7 | #[tokio::test(flavor = "multi_thread")]
|
8 | 8 | async fn test_shanghai_compat() {
|
9 | 9 | let filter = Filter::new("", "ShanghaiCompat", ".*spec");
|
10 | 10 | TestConfig::with_filter(TEST_DATA_PARIS.runner(), filter).spec_id(SpecId::SHANGHAI).run().await;
|
11 | 11 | }
|
| 12 | + |
| 13 | +// Test evm version switch during tests / scripts. |
| 14 | +// <https://github.com/foundry-rs/foundry/issues/9840> |
| 15 | +// <https://github.com/foundry-rs/foundry/issues/6228> |
| 16 | +forgetest_init!(test_set_evm_version, |prj, cmd| { |
| 17 | + let endpoint = rpc::next_http_archive_rpc_url(); |
| 18 | + prj.add_test( |
| 19 | + "TestEvmVersion.t.sol", |
| 20 | + &r#" |
| 21 | +import {Test} from "forge-std/Test.sol"; |
| 22 | +
|
| 23 | +interface EvmVm { |
| 24 | + function getEvmVersion() external pure returns (string memory evm); |
| 25 | + function setEvmVersion(string calldata evm) external; |
| 26 | +} |
| 27 | +
|
| 28 | +interface ICreate2Deployer { |
| 29 | + function computeAddress(bytes32 salt, bytes32 codeHash) external view returns (address); |
| 30 | +} |
| 31 | +
|
| 32 | +contract TestEvmVersion is Test { |
| 33 | + function test_evm_version() public { |
| 34 | + EvmVm evm = EvmVm(address(bytes20(uint160(uint256(keccak256("hevm cheat code")))))); |
| 35 | + vm.createSelectFork("<rpc>"); |
| 36 | +
|
| 37 | + evm.setEvmVersion("istanbul"); |
| 38 | + evm.getEvmVersion(); |
| 39 | +
|
| 40 | + // revert with NotActivated for istanbul |
| 41 | + vm.expectRevert(); |
| 42 | + compute(); |
| 43 | +
|
| 44 | + evm.setEvmVersion("shanghai"); |
| 45 | + evm.getEvmVersion(); |
| 46 | + compute(); |
| 47 | +
|
| 48 | + // switch to Paris, expect revert with NotActivated |
| 49 | + evm.setEvmVersion("paris"); |
| 50 | + vm.expectRevert(); |
| 51 | + compute(); |
| 52 | + } |
| 53 | +
|
| 54 | + function compute() internal view { |
| 55 | + ICreate2Deployer(0x35Da41c476fA5c6De066f20556069096A1F39364).computeAddress(bytes32(0), bytes32(0)); |
| 56 | + } |
| 57 | +} |
| 58 | + "#.replace("<rpc>", &endpoint), |
| 59 | + ); |
| 60 | + |
| 61 | + cmd.args(["test", "--mc", "TestEvmVersion", "-vvvv"]).assert_success().stdout_eq(str![[r#" |
| 62 | +[COMPILING_FILES] with [SOLC_VERSION] |
| 63 | +[SOLC_VERSION] [ELAPSED] |
| 64 | +Compiler run successful! |
| 65 | +
|
| 66 | +Ran 1 test for test/TestEvmVersion.t.sol:TestEvmVersion |
| 67 | +[PASS] test_evm_version() ([GAS]) |
| 68 | +Traces: |
| 69 | + [..] TestEvmVersion::test_evm_version() |
| 70 | + ├─ [0] VM::createSelectFork("<rpc url>") |
| 71 | + │ └─ ← [Return] 0 |
| 72 | + ├─ [0] VM::setEvmVersion("istanbul") |
| 73 | + │ └─ ← [Return] |
| 74 | + ├─ [0] VM::getEvmVersion() [staticcall] |
| 75 | + │ └─ ← [Return] "istanbul" |
| 76 | + ├─ [0] VM::expectRevert(custom error 0xf4844814) |
| 77 | + │ └─ ← [Return] |
| 78 | + ├─ [..] 0x35Da41c476fA5c6De066f20556069096A1F39364::computeAddress(0x0000000000000000000000000000000000000000000000000000000000000000, 0x0000000000000000000000000000000000000000000000000000000000000000) [staticcall] |
| 79 | + │ └─ ← [NotActivated] EvmError: NotActivated |
| 80 | + ├─ [0] VM::setEvmVersion("shanghai") |
| 81 | + │ └─ ← [Return] |
| 82 | + ├─ [0] VM::getEvmVersion() [staticcall] |
| 83 | + │ └─ ← [Return] "shanghai" |
| 84 | + ├─ [..] 0x35Da41c476fA5c6De066f20556069096A1F39364::computeAddress(0x0000000000000000000000000000000000000000000000000000000000000000, 0x0000000000000000000000000000000000000000000000000000000000000000) [staticcall] |
| 85 | + │ └─ ← [Return] 0x0f40d7B7669e3a6683EaB25358318fd42a9F2342 |
| 86 | + ├─ [0] VM::setEvmVersion("paris") |
| 87 | + │ └─ ← [Return] |
| 88 | + ├─ [0] VM::expectRevert(custom error 0xf4844814) |
| 89 | + │ └─ ← [Return] |
| 90 | + ├─ [..] 0x35Da41c476fA5c6De066f20556069096A1F39364::computeAddress(0x0000000000000000000000000000000000000000000000000000000000000000, 0x0000000000000000000000000000000000000000000000000000000000000000) [staticcall] |
| 91 | + │ └─ ← [NotActivated] EvmError: NotActivated |
| 92 | + └─ ← [Stop] |
| 93 | +
|
| 94 | +Suite result: ok. 1 passed; 0 failed; 0 skipped; [ELAPSED] |
| 95 | +
|
| 96 | +Ran 1 test suite [ELAPSED]: 1 tests passed, 0 failed, 0 skipped (1 total tests) |
| 97 | +
|
| 98 | +"#]]); |
| 99 | +}); |
0 commit comments