Skip to content

Commit

Permalink
chore(cheatcodes): rename defs to spec
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniPopes committed Nov 16, 2023
1 parent 8c11482 commit 746c89b
Show file tree
Hide file tree
Showing 18 changed files with 34 additions and 32 deletions.
2 changes: 1 addition & 1 deletion .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[alias]
cheats = "test -p foundry-cheatcodes-defs --features schema tests::"
cheats = "test -p foundry-cheatcodes-spec --features schema tests::"

[target.x86_64-pc-windows-msvc]
rustflags = [
Expand Down
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ members = [
"crates/binder/",
"crates/cast/",
"crates/cheatcodes/",
"crates/cheatcodes/defs/",
"crates/cheatcodes/spec/",
"crates/chisel/",
"crates/cli/",
"crates/common/",
Expand Down Expand Up @@ -117,7 +117,7 @@ forge-fmt = { path = "crates/fmt" }
foundry-abi = { path = "crates/abi" }
foundry-binder = { path = "crates/binder" }
foundry-cheatcodes = { path = "crates/cheatcodes" }
foundry-cheatcodes-defs = { path = "crates/cheatcodes/defs" }
foundry-cheatcodes-spec = { path = "crates/cheatcodes/spec" }
foundry-cli = { path = "crates/cli" }
foundry-common = { path = "crates/common" }
foundry-config = { path = "crates/config" }
Expand Down
2 changes: 1 addition & 1 deletion crates/cheatcodes/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ repository.workspace = true
exclude.workspace = true

[dependencies]
foundry-cheatcodes-defs.workspace = true
foundry-cheatcodes-spec.workspace = true
foundry-common.workspace = true
foundry-compilers.workspace = true
foundry-config.workspace = true
Expand Down
6 changes: 3 additions & 3 deletions crates/cheatcodes/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ Foundry cheatcodes definitions and implementations.
## Structure

- [`assets/`](./assets/): JSON interface and specification
- [`defs/`](./defs/src/lib.rs): Defines common traits and structs
- [`spec/`](./spec/src/lib.rs): Defines common traits and structs
- [`src/`](./src/lib.rs): Rust implementations of the cheatcodes

## Overview

All cheatcodes are defined in a single [`sol!`] macro call in [`defs/src/vm.rs`].
All cheatcodes are defined in a single [`sol!`] macro call in [`spec/src/vm.rs`].

This, combined with the use of an internal [`Cheatcode`](../macros/impl/src/cheatcodes.rs) derive macro,
allows us to generate both the Rust definitions and the JSON specification of the cheatcodes.
Expand Down Expand Up @@ -38,4 +38,4 @@ If you are making use of the JSON interface, please don't hesitate to open a PR
Please see the [cheatcodes dev documentation](../../docs/dev/cheatcodes.md#adding-a-new-cheatcode) on how to add new cheatcodes.

[`sol!`]: https://docs.rs/alloy-sol-macro/latest/alloy_sol_macro/macro.sol.html
[`defs/src/vm.rs`]: ./defs/src/vm.rs
[`spec/src/vm.rs`]: ./spec/src/vm.rs
3 changes: 0 additions & 3 deletions crates/cheatcodes/defs/README.md

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "foundry-cheatcodes-defs"
description = "Foundry cheatcodes definitions"
name = "foundry-cheatcodes-spec"
description = "Foundry cheatcodes specification"

version.workspace = true
edition.workspace = true
Expand Down
3 changes: 3 additions & 0 deletions crates/cheatcodes/spec/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# foundry-cheatcodes-spec

Minimal crate to provide a cheatcodes specification.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
//! # foundry-cheatcode-defs
//!
//! Foundry cheatcode definitions.

#![doc = include_str!("../README.md")]
#![warn(missing_docs, unreachable_pub, unused_crate_dependencies, rust_2018_idioms)]

use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -134,7 +131,7 @@ interface Vm {{
}

#[test]
fn defs_up_to_date() {
fn spec_up_to_date() {
ensure_file_contents(Path::new(JSON_PATH), &json_cheatcodes());
}

Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions crates/cheatcodes/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
#![allow(elided_lifetimes_in_paths)] // Cheats context uses 3 lifetimes

#[macro_use]
pub extern crate foundry_cheatcodes_defs as defs;
pub extern crate foundry_cheatcodes_spec as spec;
#[macro_use]
extern crate tracing;

use alloy_primitives::Address;
use foundry_evm_core::backend::DatabaseExt;
use revm::EVMData;

pub use defs::{CheatcodeDef, Vm};
pub use spec::{CheatcodeDef, Vm};

#[macro_use]
mod error;
Expand Down
2 changes: 1 addition & 1 deletion crates/evm/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ repository.workspace = true

[dependencies]
foundry-abi.workspace = true
foundry-cheatcodes-defs.workspace = true
foundry-cheatcodes-spec.workspace = true
foundry-common.workspace = true
foundry-compilers.workspace = true
foundry-config.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion crates/evm/core/src/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ impl Display for Instruction {
Instruction::Cheatcode(cheat) => write!(
f,
"VM_{}",
foundry_cheatcodes_defs::Vm::CHEATCODES
foundry_cheatcodes_spec::Vm::CHEATCODES
.iter()
.map(|c| &c.func)
.find(|c| c.selector_bytes == *cheat)
Expand Down
2 changes: 1 addition & 1 deletion crates/evm/core/src/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use alloy_primitives::B256;
use alloy_sol_types::{SolCall, SolError, SolInterface, SolValue};
use ethers_contract::EthLogDecode;
use ethers_core::{abi::RawLog, types::Log, utils::format_units};
use foundry_cheatcodes_defs::Vm;
use foundry_cheatcodes_spec::Vm;
use foundry_common::SELECTOR_LEN;
use itertools::Itertools;
use revm::interpreter::InstructionResult;
Expand Down
19 changes: 12 additions & 7 deletions docs/dev/cheatcodes.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ implementation handler for the cheatcode. This is also automatically generated,

## Cheatcodes implementation

All the cheatcodes are defined in a large [`sol!`] macro call in [`cheatcodes/defs/src/vm.rs`](../../crates/cheatcodes/defs/src/vm.rs):
All the cheatcodes are defined in a large [`sol!`] macro call in [`cheatcodes/spec/src/vm.rs`]:

```rust
sol! {
Expand Down Expand Up @@ -160,11 +160,16 @@ update of the files.

### Adding a new cheatcode

1. Add its Solidity definition(s) in [`defs/src/vm.rs`]. Ensure that all structs and functions are documented, and that all function parameters are named. This will initially fail to compile because of the automatically generated `match { ... }` expression. This is expected, and will be fixed in the next step
2. Implement the cheatcode in [`cheatcodes`](cheatcodes) in its category's respective module. Follow the existing implementations as a guide.
3. Update the JSON interface by running `cargo cheats` twice. This is expected to fail the first time that this is run after adding a new cheatcode; see [JSON interface](#json-interface)
4. Write an integration test for the cheatcode in [`testdata/cheats/`](../../testdata/cheats/)
5. Submit a PR to [`forge-std`](https://github.com/foundry-rs/forge-std) updating the Solidity interfaces as necessary. Note that this step won't be necessary once the Solidity interfaces are generated using the JSON interface
1. Add its Solidity definition(s) in [`cheatcodes/spec/src/vm.rs`]. Ensure that all structs and functions are documented, and that all function parameters are named. This will initially fail to compile because of the automatically generated `match { ... }` expression. This is expected, and will be fixed in the next step
2. Implement the cheatcode in [`cheatcodes`] in its category's respective module. Follow the existing implementations as a guide.
3. If a struct, enum, error, or event was added to `Vm`, update [`spec::Cheatcodes::new`]
4. Update the JSON interface by running `cargo cheats` twice. This is expected to fail the first time that this is run after adding a new cheatcode; see [JSON interface](#json-interface)
5. Write an integration test for the cheatcode in [`testdata/cheats/`]
6. Submit a PR to [`forge-std`] updating the Solidity interfaces as necessary. Note that this step won't be necessary once the Solidity interfaces are generated using the JSON interface

[`sol!`]: https://docs.rs/alloy-sol-macro/latest/alloy_sol_macro/macro.sol.html
[`defs/src/vm.rs`]: ./defs/src/vm.rs
[`cheatcodes/spec/src/vm.rs`]: ../../crates/cheatcodes/spec/src/vm.rs
[`cheatcodes`]: ../../crates/cheatcodes/
[`spec::Cheatcodes::new`]: ../../crates/cheatcodes/spec/src/lib.rs#L74
[`testdata/cheats/`]: ../../testdata/cheats/
[`forge-std`]: https://github.com/foundry-rs/forge-std

0 comments on commit 746c89b

Please sign in to comment.