Skip to content

Commit

Permalink
Rename Cheats -> Vm (foundry-rs#5338)
Browse files Browse the repository at this point in the history
* change naming

fix

* forge fmt
  • Loading branch information
klkvr authored Jul 8, 2023
1 parent c78a811 commit 32e8e83
Show file tree
Hide file tree
Showing 94 changed files with 964 additions and 965 deletions.
6 changes: 3 additions & 3 deletions chisel/src/session_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use std::{collections::HashMap, fs, path::PathBuf};
use yansi::Paint;

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

/// Intermediate output for the compiled [SessionSource]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
Expand Down Expand Up @@ -476,11 +476,11 @@ contract {} is Script {{
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^{major}.{minor}.{patch};
import {{Cheats}} from "forge-std/Vm.sol";
import {{Vm}} from "forge-std/Vm.sol";
{}
contract {} {{
Cheats internal constant vm = Cheats(address(uint160(uint256(keccak256("hevm cheat code")))));
Vm internal constant vm = Vm(address(uint160(uint256(keccak256("hevm cheat code")))));
{}
/// @notice REPL contract entry point
Expand Down
2 changes: 1 addition & 1 deletion cli/test-utils/src/script.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ impl ScriptTester {
/// Initialises the test contracts by copying them into the workspace
fn copy_testdata(current_dir: &Path) -> eyre::Result<()> {
let testdata = Self::testdata_path();
std::fs::copy(testdata.clone() + "/cheats/Cheats.sol", current_dir.join("src/Cheats.sol"))?;
std::fs::copy(testdata.clone() + "/cheats/Vm.sol", current_dir.join("src/Vm.sol"))?;
std::fs::copy(testdata + "/lib/ds-test/src/test.sol", current_dir.join("lib/test.sol"))?;

Ok(())
Expand Down
2 changes: 1 addition & 1 deletion docs/dev/cheatcodes.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ In solidity cheat codes are calls to a specific address, the cheat code handler

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

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

Since cheat codes are bound to a constant address, the cheat code inspector listens for that address:
Expand Down
6 changes: 3 additions & 3 deletions evm/src/executor/backend/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,15 +219,15 @@ pub trait DatabaseExt: Database<Error = DatabaseError> {
///
/// ```solidity
/// function testCanDeploy() public {
/// cheats.selectFork(mainnetFork);
/// vm.selectFork(mainnetFork);
/// // contract created while on `mainnetFork`
/// DummyContract dummy = new DummyContract();
/// // this will succeed
/// dummy.hello();
///
/// cheats.selectFork(optimismFork);
/// vm.selectFork(optimismFork);
///
/// cheats.expectRevert();
/// vm.expectRevert();
/// // this will revert since `dummy` contract only exists on `mainnetFork`
/// dummy.hello();
/// }
Expand Down
8 changes: 4 additions & 4 deletions testdata/cheats/Addr.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@
pragma solidity 0.8.18;

import "ds-test/test.sol";
import "./Cheats.sol";
import "./Vm.sol";

contract AddrTest is DSTest {
Cheats constant cheats = Cheats(HEVM_ADDRESS);
Vm constant vm = Vm(HEVM_ADDRESS);

function testFailPrivKeyZero() public {
cheats.addr(0);
vm.addr(0);
}

function testAddr() public {
uint256 pk = 77814517325470205911140941194401928579557062014761831930645393041380819009408;
address expected = 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266;

assertEq(cheats.addr(pk), expected, "expected address did not match");
assertEq(vm.addr(pk), expected, "expected address did not match");
}
}
6 changes: 3 additions & 3 deletions testdata/cheats/Assume.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
pragma solidity 0.8.18;

import "ds-test/test.sol";
import "./Cheats.sol";
import "./Vm.sol";

contract AssumeTest is DSTest {
Cheats constant cheats = Cheats(HEVM_ADDRESS);
Vm constant vm = Vm(HEVM_ADDRESS);

function testAssume(uint8 x) public {
cheats.assume(x < 2 ** 7);
vm.assume(x < 2 ** 7);
assertTrue(x < 2 ** 7, "did not discard inputs");
}
}
8 changes: 4 additions & 4 deletions testdata/cheats/Bank.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@
pragma solidity 0.8.18;

import "ds-test/test.sol";
import "./Cheats.sol";
import "./Vm.sol";

contract CoinbaseTest is DSTest {
Cheats constant cheats = Cheats(HEVM_ADDRESS);
Vm constant vm = Vm(HEVM_ADDRESS);

function testCoinbase() public {
cheats.coinbase(0xEA674fdDe714fd979de3EdF0F56AA9716B898ec8);
vm.coinbase(0xEA674fdDe714fd979de3EdF0F56AA9716B898ec8);
assertEq(block.coinbase, 0xEA674fdDe714fd979de3EdF0F56AA9716B898ec8, "coinbase failed");
}

function testCoinbaseFuzzed(address who) public {
cheats.coinbase(who);
vm.coinbase(who);
assertEq(block.coinbase, who, "coinbase failed");
}
}
Loading

0 comments on commit 32e8e83

Please sign in to comment.