From 746c89b6a962a45de2c087222f870f996596a11d Mon Sep 17 00:00:00 2001 From: DaniPopes <57450786+DaniPopes@users.noreply.github.com> Date: Thu, 16 Nov 2023 01:14:46 +0100 Subject: [PATCH] chore(cheatcodes): rename defs to spec --- .cargo/config.toml | 2 +- Cargo.lock | 6 +++--- Cargo.toml | 4 ++-- crates/cheatcodes/Cargo.toml | 2 +- crates/cheatcodes/README.md | 6 +++--- crates/cheatcodes/defs/README.md | 3 --- crates/cheatcodes/{defs => spec}/Cargo.toml | 4 ++-- crates/cheatcodes/spec/README.md | 3 +++ .../{defs => spec}/src/cheatcode.rs | 0 .../cheatcodes/{defs => spec}/src/function.rs | 0 crates/cheatcodes/{defs => spec}/src/items.rs | 0 crates/cheatcodes/{defs => spec}/src/lib.rs | 7 ++----- crates/cheatcodes/{defs => spec}/src/vm.rs | 0 crates/cheatcodes/src/lib.rs | 4 ++-- crates/evm/core/Cargo.toml | 2 +- crates/evm/core/src/debug.rs | 2 +- crates/evm/core/src/decode.rs | 2 +- docs/dev/cheatcodes.md | 19 ++++++++++++------- 18 files changed, 34 insertions(+), 32 deletions(-) delete mode 100644 crates/cheatcodes/defs/README.md rename crates/cheatcodes/{defs => spec}/Cargo.toml (85%) create mode 100644 crates/cheatcodes/spec/README.md rename crates/cheatcodes/{defs => spec}/src/cheatcode.rs (100%) rename crates/cheatcodes/{defs => spec}/src/function.rs (100%) rename crates/cheatcodes/{defs => spec}/src/items.rs (100%) rename crates/cheatcodes/{defs => spec}/src/lib.rs (98%) rename crates/cheatcodes/{defs => spec}/src/vm.rs (100%) diff --git a/.cargo/config.toml b/.cargo/config.toml index 5056df8af1f5..45bca53ae5eb 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -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 = [ diff --git a/Cargo.lock b/Cargo.lock index c167768d76f9..d45497796801 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2662,7 +2662,7 @@ dependencies = [ "ethers-providers", "ethers-signers", "eyre", - "foundry-cheatcodes-defs", + "foundry-cheatcodes-spec", "foundry-common", "foundry-compilers", "foundry-config", @@ -2677,7 +2677,7 @@ dependencies = [ ] [[package]] -name = "foundry-cheatcodes-defs" +name = "foundry-cheatcodes-spec" version = "0.2.0" dependencies = [ "alloy-sol-types", @@ -2895,7 +2895,7 @@ dependencies = [ "ethers-providers", "eyre", "foundry-abi", - "foundry-cheatcodes-defs", + "foundry-cheatcodes-spec", "foundry-common", "foundry-compilers", "foundry-config", diff --git a/Cargo.toml b/Cargo.toml index da9d691c80c7..61e62a8b67d5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,7 +8,7 @@ members = [ "crates/binder/", "crates/cast/", "crates/cheatcodes/", - "crates/cheatcodes/defs/", + "crates/cheatcodes/spec/", "crates/chisel/", "crates/cli/", "crates/common/", @@ -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" } diff --git a/crates/cheatcodes/Cargo.toml b/crates/cheatcodes/Cargo.toml index aeae87e547c1..e21273798f75 100644 --- a/crates/cheatcodes/Cargo.toml +++ b/crates/cheatcodes/Cargo.toml @@ -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 diff --git a/crates/cheatcodes/README.md b/crates/cheatcodes/README.md index ce1e8f32b9f0..dfe53bcebea1 100644 --- a/crates/cheatcodes/README.md +++ b/crates/cheatcodes/README.md @@ -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. @@ -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 diff --git a/crates/cheatcodes/defs/README.md b/crates/cheatcodes/defs/README.md deleted file mode 100644 index 136ce7ffbbae..000000000000 --- a/crates/cheatcodes/defs/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# foundry-cheatcodes-defs - -Minimal crate to provide a common set of cheatcodes definitions. diff --git a/crates/cheatcodes/defs/Cargo.toml b/crates/cheatcodes/spec/Cargo.toml similarity index 85% rename from crates/cheatcodes/defs/Cargo.toml rename to crates/cheatcodes/spec/Cargo.toml index 0185c6bf8009..5f7ec0eb6c7c 100644 --- a/crates/cheatcodes/defs/Cargo.toml +++ b/crates/cheatcodes/spec/Cargo.toml @@ -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 diff --git a/crates/cheatcodes/spec/README.md b/crates/cheatcodes/spec/README.md new file mode 100644 index 000000000000..0b0aecebed6d --- /dev/null +++ b/crates/cheatcodes/spec/README.md @@ -0,0 +1,3 @@ +# foundry-cheatcodes-spec + +Minimal crate to provide a cheatcodes specification. diff --git a/crates/cheatcodes/defs/src/cheatcode.rs b/crates/cheatcodes/spec/src/cheatcode.rs similarity index 100% rename from crates/cheatcodes/defs/src/cheatcode.rs rename to crates/cheatcodes/spec/src/cheatcode.rs diff --git a/crates/cheatcodes/defs/src/function.rs b/crates/cheatcodes/spec/src/function.rs similarity index 100% rename from crates/cheatcodes/defs/src/function.rs rename to crates/cheatcodes/spec/src/function.rs diff --git a/crates/cheatcodes/defs/src/items.rs b/crates/cheatcodes/spec/src/items.rs similarity index 100% rename from crates/cheatcodes/defs/src/items.rs rename to crates/cheatcodes/spec/src/items.rs diff --git a/crates/cheatcodes/defs/src/lib.rs b/crates/cheatcodes/spec/src/lib.rs similarity index 98% rename from crates/cheatcodes/defs/src/lib.rs rename to crates/cheatcodes/spec/src/lib.rs index 53bd161a8f12..3877806ee6fc 100644 --- a/crates/cheatcodes/defs/src/lib.rs +++ b/crates/cheatcodes/spec/src/lib.rs @@ -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}; @@ -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()); } diff --git a/crates/cheatcodes/defs/src/vm.rs b/crates/cheatcodes/spec/src/vm.rs similarity index 100% rename from crates/cheatcodes/defs/src/vm.rs rename to crates/cheatcodes/spec/src/vm.rs diff --git a/crates/cheatcodes/src/lib.rs b/crates/cheatcodes/src/lib.rs index a68772e91eb5..b7a401c074a8 100644 --- a/crates/cheatcodes/src/lib.rs +++ b/crates/cheatcodes/src/lib.rs @@ -6,7 +6,7 @@ #![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; @@ -14,7 +14,7 @@ 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; diff --git a/crates/evm/core/Cargo.toml b/crates/evm/core/Cargo.toml index b919178a1a66..13664b3e4364 100644 --- a/crates/evm/core/Cargo.toml +++ b/crates/evm/core/Cargo.toml @@ -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 diff --git a/crates/evm/core/src/debug.rs b/crates/evm/core/src/debug.rs index 3b6cab6167e3..f0d6b2c19d85 100644 --- a/crates/evm/core/src/debug.rs +++ b/crates/evm/core/src/debug.rs @@ -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) diff --git a/crates/evm/core/src/decode.rs b/crates/evm/core/src/decode.rs index a74a053ead99..97f0c65c5661 100644 --- a/crates/evm/core/src/decode.rs +++ b/crates/evm/core/src/decode.rs @@ -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; diff --git a/docs/dev/cheatcodes.md b/docs/dev/cheatcodes.md index 5ff4105d8e94..a74d79fcd830 100644 --- a/docs/dev/cheatcodes.md +++ b/docs/dev/cheatcodes.md @@ -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! { @@ -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