Skip to content

Commit 32e8e83

Browse files
authored
Rename Cheats -> Vm (#5338)
* change naming fix * forge fmt
1 parent c78a811 commit 32e8e83

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

94 files changed

+964
-965
lines changed

chisel/src/session_source.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use std::{collections::HashMap, fs, path::PathBuf};
1919
use yansi::Paint;
2020

2121
/// Solidity source for the `Vm` interface in [forge-std](https://github.com/foundry-rs/forge-std)
22-
static VM_SOURCE: &str = include_str!("../../testdata/cheats/Cheats.sol");
22+
static VM_SOURCE: &str = include_str!("../../testdata/cheats/Vm.sol");
2323

2424
/// Intermediate output for the compiled [SessionSource]
2525
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
@@ -476,11 +476,11 @@ contract {} is Script {{
476476
// SPDX-License-Identifier: UNLICENSED
477477
pragma solidity ^{major}.{minor}.{patch};
478478
479-
import {{Cheats}} from "forge-std/Vm.sol";
479+
import {{Vm}} from "forge-std/Vm.sol";
480480
{}
481481
482482
contract {} {{
483-
Cheats internal constant vm = Cheats(address(uint160(uint256(keccak256("hevm cheat code")))));
483+
Vm internal constant vm = Vm(address(uint160(uint256(keccak256("hevm cheat code")))));
484484
{}
485485
486486
/// @notice REPL contract entry point

cli/test-utils/src/script.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ impl ScriptTester {
9898
/// Initialises the test contracts by copying them into the workspace
9999
fn copy_testdata(current_dir: &Path) -> eyre::Result<()> {
100100
let testdata = Self::testdata_path();
101-
std::fs::copy(testdata.clone() + "/cheats/Cheats.sol", current_dir.join("src/Cheats.sol"))?;
101+
std::fs::copy(testdata.clone() + "/cheats/Vm.sol", current_dir.join("src/Vm.sol"))?;
102102
std::fs::copy(testdata + "/lib/ds-test/src/test.sol", current_dir.join("lib/test.sol"))?;
103103

104104
Ok(())

docs/dev/cheatcodes.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ In solidity cheat codes are calls to a specific address, the cheat code handler
4040

4141
`address(uint160(uint256(keccak256('hevm cheat code'))))`: 0x7109709ECfa91a80626fF3989D68f67F5b1DD12D
4242

43-
which can be initialized like `Cheats constant cheats = Cheats(0x7109709ECfa91a80626fF3989D68f67F5b1DD12D);`, when
43+
which can be initialized like `Vm constant vm = Vm(0x7109709ECfa91a80626fF3989D68f67F5b1DD12D);`, when
4444
inheriting from `forge-std/Test.sol` it can be accessed via `vm.<cheatcode>` directly.
4545

4646
Since cheat codes are bound to a constant address, the cheat code inspector listens for that address:

evm/src/executor/backend/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -219,15 +219,15 @@ pub trait DatabaseExt: Database<Error = DatabaseError> {
219219
///
220220
/// ```solidity
221221
/// function testCanDeploy() public {
222-
/// cheats.selectFork(mainnetFork);
222+
/// vm.selectFork(mainnetFork);
223223
/// // contract created while on `mainnetFork`
224224
/// DummyContract dummy = new DummyContract();
225225
/// // this will succeed
226226
/// dummy.hello();
227227
///
228-
/// cheats.selectFork(optimismFork);
228+
/// vm.selectFork(optimismFork);
229229
///
230-
/// cheats.expectRevert();
230+
/// vm.expectRevert();
231231
/// // this will revert since `dummy` contract only exists on `mainnetFork`
232232
/// dummy.hello();
233233
/// }

testdata/cheats/Addr.t.sol

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@
22
pragma solidity 0.8.18;
33

44
import "ds-test/test.sol";
5-
import "./Cheats.sol";
5+
import "./Vm.sol";
66

77
contract AddrTest is DSTest {
8-
Cheats constant cheats = Cheats(HEVM_ADDRESS);
8+
Vm constant vm = Vm(HEVM_ADDRESS);
99

1010
function testFailPrivKeyZero() public {
11-
cheats.addr(0);
11+
vm.addr(0);
1212
}
1313

1414
function testAddr() public {
1515
uint256 pk = 77814517325470205911140941194401928579557062014761831930645393041380819009408;
1616
address expected = 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266;
1717

18-
assertEq(cheats.addr(pk), expected, "expected address did not match");
18+
assertEq(vm.addr(pk), expected, "expected address did not match");
1919
}
2020
}

testdata/cheats/Assume.t.sol

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
pragma solidity 0.8.18;
33

44
import "ds-test/test.sol";
5-
import "./Cheats.sol";
5+
import "./Vm.sol";
66

77
contract AssumeTest is DSTest {
8-
Cheats constant cheats = Cheats(HEVM_ADDRESS);
8+
Vm constant vm = Vm(HEVM_ADDRESS);
99

1010
function testAssume(uint8 x) public {
11-
cheats.assume(x < 2 ** 7);
11+
vm.assume(x < 2 ** 7);
1212
assertTrue(x < 2 ** 7, "did not discard inputs");
1313
}
1414
}

testdata/cheats/Bank.t.sol

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@
22
pragma solidity 0.8.18;
33

44
import "ds-test/test.sol";
5-
import "./Cheats.sol";
5+
import "./Vm.sol";
66

77
contract CoinbaseTest is DSTest {
8-
Cheats constant cheats = Cheats(HEVM_ADDRESS);
8+
Vm constant vm = Vm(HEVM_ADDRESS);
99

1010
function testCoinbase() public {
11-
cheats.coinbase(0xEA674fdDe714fd979de3EdF0F56AA9716B898ec8);
11+
vm.coinbase(0xEA674fdDe714fd979de3EdF0F56AA9716B898ec8);
1212
assertEq(block.coinbase, 0xEA674fdDe714fd979de3EdF0F56AA9716B898ec8, "coinbase failed");
1313
}
1414

1515
function testCoinbaseFuzzed(address who) public {
16-
cheats.coinbase(who);
16+
vm.coinbase(who);
1717
assertEq(block.coinbase, who, "coinbase failed");
1818
}
1919
}

0 commit comments

Comments
 (0)