Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use foundry-cheatcodes implementations #6131

Merged
merged 65 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
b033269
feat: use `foundry-cheatcodes` in `foundry-evm`
DaniPopes Oct 26, 2023
e7df61c
fix: deps
DaniPopes Oct 26, 2023
8ac41c7
docs: retire `foundry-abi`
DaniPopes Oct 26, 2023
7183cf7
chore: refactor profiles
DaniPopes Oct 26, 2023
665ea5a
docs: obsolete -> deprecated
DaniPopes Oct 26, 2023
ee112b2
fix: fs tests
DaniPopes Oct 26, 2023
37b660a
fix: repro 5808
DaniPopes Oct 26, 2023
10211b4
fix: implement `rpc` and `eth_getLogs`
DaniPopes Oct 26, 2023
7ff109d
fix: int test
DaniPopes Oct 26, 2023
df9426a
chore: reorder EthGetLogs struct fields
DaniPopes Oct 26, 2023
55a8edb
chore: update JSON
DaniPopes Oct 26, 2023
1249038
docs: update dev docs and cheatcodes README
DaniPopes Oct 26, 2023
54a15e4
chore: rename magic bytes constants
DaniPopes Oct 26, 2023
709401c
fix: Error ABI encoding
DaniPopes Oct 27, 2023
91a7e48
fix: ABI-encode Error as `CheatCodeError(string)`
DaniPopes Oct 27, 2023
13c467d
chore: remove bad re-export
DaniPopes Oct 27, 2023
9a0aad8
test: update script panic message
DaniPopes Oct 27, 2023
f0eca5d
fix: broadcast origin and caller
DaniPopes Oct 27, 2023
2bba499
test: update some test messages
DaniPopes Oct 27, 2023
018580f
test: add more debug
DaniPopes Oct 27, 2023
74926a2
test: don't run commands twice...
DaniPopes Oct 27, 2023
a662a23
chore: clippy
DaniPopes Oct 27, 2023
d0c5b86
fix: tracing-subscriber features
DaniPopes Oct 27, 2023
e5defcf
fix: re-disable color
DaniPopes Oct 27, 2023
b30f49f
fixes
DaniPopes Oct 27, 2023
7be945a
chore: clippy
DaniPopes Oct 27, 2023
c7096a1
fix: error encoding
DaniPopes Oct 27, 2023
1b20006
feat: auto generate solidity interface
DaniPopes Oct 28, 2023
8df2988
opts
DaniPopes Oct 28, 2023
f03ff3b
ci: fix forge-fmt
DaniPopes Oct 30, 2023
96e1ef5
feat: re-implement `cool`
DaniPopes Oct 30, 2023
04caeac
fix: FfiResult exit_code->exitCode
DaniPopes Oct 30, 2023
e7bd8c7
chore: update
DaniPopes Oct 30, 2023
64eed10
Merge branch 'master' into alloy-cheatcodes4
DaniPopes Oct 30, 2023
2b679ff
fix: scripting expects
DaniPopes Oct 30, 2023
670c3f3
fix: rename test output methods
DaniPopes Oct 30, 2023
de21ea6
test: update expect msgs
DaniPopes Oct 30, 2023
d69e39b
chore: update broadcast staticcall error message
DaniPopes Oct 30, 2023
ed93c1f
chore: only expand `#[vm]` macro in `cfg(test)`
DaniPopes Oct 30, 2023
79975ff
test: update precompile error msg
DaniPopes Oct 30, 2023
07e265a
test: update env tests
DaniPopes Oct 30, 2023
42753fa
fix: expectCall value gt 0
DaniPopes Oct 30, 2023
1df33b5
fix: fs error messages
DaniPopes Oct 30, 2023
75a4127
fix: rm huff abi test
DaniPopes Oct 30, 2023
4e487e4
fix: forge fmt
DaniPopes Oct 30, 2023
a3d271a
fix: JSON coerce error msg
DaniPopes Oct 30, 2023
2c3fe89
fix: JSON non-object error message
DaniPopes Oct 30, 2023
f8ed465
chore: random stuff
DaniPopes Oct 30, 2023
85a66b4
tmp: comment out sleep fuzz test
DaniPopes Oct 30, 2023
54000c3
chore: mark generated files in .gitattributes
DaniPopes Oct 30, 2023
db99a1c
chore: uncapitalize an error msg
DaniPopes Oct 30, 2023
c765167
fix: use BTreeMap for serialized JSONs
DaniPopes Oct 30, 2023
362c22d
chore: better tracing
DaniPopes Oct 31, 2023
d06838b
fix: properly serialize JSON arrays
DaniPopes Oct 31, 2023
c855ed6
fix: missing rpc url error message
DaniPopes Oct 31, 2023
fba652c
fix: mock calls
DaniPopes Oct 31, 2023
126eaa3
chore: clippy
DaniPopes Oct 31, 2023
35a49ce
Merge branch 'master' into alloy-cheatcodes4
DaniPopes Oct 31, 2023
28a62fa
fix: update broadcast sender nonce, not CREATE2 deployer
DaniPopes Oct 31, 2023
3a4807b
chore: use trace! for verbose cheatcode logs
DaniPopes Oct 31, 2023
beaad60
feat: extend schema to include other items
DaniPopes Oct 31, 2023
cee8c7e
feat: generate Vm from expanded interface
DaniPopes Oct 31, 2023
fc3596c
chore: clippy
DaniPopes Oct 31, 2023
d250410
fix: use forge-std pr
DaniPopes Oct 31, 2023
d42cf07
fix: use forge-std master
DaniPopes Oct 31, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 6 additions & 12 deletions Cargo.lock

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

66 changes: 14 additions & 52 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,13 @@ scrypt.opt-level = 3
# forking
axum.opt-level = 3

# Optimized release profile
[profile.release]
opt-level = "s"
lto = "fat"
# Local "release" mode, more optimized than dev but much faster to compile than release
[profile.local]
inherits = "dev"
opt-level = 1
strip = true
panic = "abort"
codegen-units = 1
codegen-units = 16

# Like release, but with full debug symbols and with stack unwinds. Useful for e.g. `perf`.
[profile.debug-fast]
Expand All @@ -84,13 +84,16 @@ strip = "none"
panic = "unwind"
incremental = false

[profile.release.package]
# Optimize all non-workspace packages for speed
"*".opt-level = 3

# Package overrides
foundry-evm.opt-level = 3
# Optimized release profile
[profile.release]
opt-level = 3
lto = "fat"
strip = true
panic = "abort"
codegen-units = 1

# Override packages which aren't perf-sensitive for faster compilation speed
[profile.release.package]
foundry-abi.opt-level = 1
mdbook.opt-level = 1
protobuf.opt-level = 1
Expand All @@ -100,47 +103,6 @@ rusoto_kms.opt-level = 1
toml_edit.opt-level = 1
trezor-client.opt-level = 1

# Given that the `"*"` above takes precedence over the defaults for build scripts and macros, we
# have to override all of them to reduce compile times
syn.opt-level = 0
prettyplease.opt-level = 0
lalrpop.opt-level = 0

ethers-contract-abigen.opt-level = 0
ethers-contract-derive.opt-level = 0
async-recursion.opt-level = 0
miette-derive.opt-level = 0
strum_macros.opt-level = 0
enumn.opt-level = 0
clap_derive.opt-level = 0
serde_derive.opt-level = 0
pear_codegen.opt-level = 0
num_enum_derive.opt-level = 0
scale-info-derive.opt-level = 0
parity-scale-codec-derive.opt-level = 0
time-macros.opt-level = 0
phf_macros.opt-level = 0
pin-project-internal.opt-level = 0
auto_impl.opt-level = 0
derive_more.opt-level = 0
rlp-derive.opt-level = 0
impl-trait-for-tuples.opt-level = 0
async-trait.opt-level = 0
tokio-macros.opt-level = 0
tracing-attributes.opt-level = 0
futures-macro.opt-level = 0
thiserror-impl.opt-level = 0
wasm-bindgen-macro-support.opt-level = 0
wasm-bindgen-backend.opt-level = 0

# Local "release" mode, more optimized than dev but much faster to compile than release
[profile.local]
inherits = "dev"
opt-level = 1
strip = true
panic = "abort"
codegen-units = 16

[workspace.dependencies]
anvil = { path = "crates/anvil" }
cast = { path = "crates/cast" }
Expand Down
4 changes: 4 additions & 0 deletions crates/abi/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# foundry-abi

> [!WARNING]
> This crate is deprecated and will be replaced with `foundry-cheatcodes` in the near future.
> Please avoid making any changes in this crate.

Contains automatically-generated Rust bindings from Solidity ABI.

Additional bindings can be generated by doing the following:
Expand Down
4 changes: 4 additions & 0 deletions crates/abi/build.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
//! **WARNING**
//! This crate is deprecated and will be replaced with `foundry-cheatcodes` in the near future.
//! Please avoid making any changes in this crate.

use ethers_contract_abigen::MultiAbigen;

/// Includes a JSON ABI as a string literal.
Expand Down
4 changes: 4 additions & 0 deletions crates/abi/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
//! Foundry's Solidity ABI bindings.
//!
//! Automatically generated by [abigen](ethers_contract::abigen).
//!
//! **WARNING**
//! This crate is deprecated and will be replaced with `foundry-cheatcodes` in the near future.
//! Please avoid making any changes in this crate.

#![warn(unused_crate_dependencies)]

Expand Down
21 changes: 14 additions & 7 deletions crates/cheatcodes/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ exclude.workspace = true

[dependencies]
foundry-macros.workspace = true

alloy-primitives.workspace = true
alloy-sol-types.workspace = true

serde.workspace = true
serde_json.workspace = true

Expand All @@ -23,38 +25,43 @@ schemars = { version = "0.8.15", optional = true }

# impls
foundry-common = { workspace = true, optional = true }
foundry-compilers = { workspace = true, optional = true }
foundry-config = { workspace = true, optional = true }
foundry-evm-core = { workspace = true, optional = true }
foundry-utils = { workspace = true, optional = true }

alloy-dyn-abi = { workspace = true, optional = true }
alloy-json-abi = { workspace = true, optional = true }
ethers = { workspace = true, optional = true, features = ["ethers-solc"] }
foundry-compilers = { workspace = true, optional = true, default-features = false }
ethers-core = { workspace = true, optional = true }
ethers-signers = { workspace = true, optional = true }
ethers-providers = { workspace = true, optional = true }

eyre = { workspace = true, optional = true }
futures = { version = "0.3", optional = true }
hex = { workspace = true, optional = true }
itertools = { workspace = true, optional = true }
jsonpath_lib = { workspace = true, optional = true }
revm = { workspace = true, optional = true }
thiserror = { version = "1", optional = true }
tracing = { workspace = true, optional = true }
walkdir = { version = "2", optional = true }

[features]
schema = ["dep:schemars"]
impls = [
"dep:foundry-common",
"dep:foundry-compilers",
"dep:foundry-config",
"dep:foundry-evm-core",
"dep:foundry-utils",
"dep:alloy-dyn-abi",
"dep:alloy-json-abi",
"dep:ethers",
"dep:ethers-core",
"dep:ethers-providers",
"dep:ethers-signers",
"dep:eyre",
"dep:futures",
"dep:hex",
"dep:itertools",
"dep:jsonpath_lib",
"dep:revm",
"dep:thiserror",
"dep:tracing",
"dep:walkdir",
]
38 changes: 37 additions & 1 deletion crates/cheatcodes/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,40 @@

Foundry cheatcodes definitions and implementations.

All cheatcodes are defined in a single macro call.
## Structure

- [`assets/`](./assets/): JSON interface and specification
- [`src/defs`](./src/defs/mod.rs): Defines traits and structs
- [`src/impls`](./src/impls/mod.rs): Rust implementations of the cheatcodes. This is gated to the `impl` feature, since these are not needed when only using the definitions.

## Overview

All cheatcodes are defined in a single [`sol!`] macro call in [`src/defs/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.

Cheatcodes are manually implemented through the `Cheatcode` trait, which is called in the
`Cheatcodes` inspector implementation.

See the [cheatcodes dev documentation](../../docs/dev/cheatcodes.md#cheatcodes-implementation) for more details.

### JSON interface

The JSON interface is guaranteed to be stable, and can be used by third-party tools to interact with
the Foundry cheatcodes externally.

For example, here are some tools that make use of the JSON interface:
- Internally, this is used to generate [a simple Solidity interface](../../testdata/cheats/Vm.sol) for testing
- (WIP) Used by [`forge-std`](https://github.com/foundry-rs/forge-std) to generate [user-friendly Solidity interfaces](https://github.com/foundry-rs/forge-std/blob/master/src/Vm.sol)
- (WIP) Used by [the Foundry book](https://github.com/foundry-rs/book) to generate [the cheatcodes reference](https://book.getfoundry.sh/cheatcodes)
- ...

If you are making use of the JSON interface, please don't hesitate to open a PR to add your project to this list!

### Adding a new cheatcode

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
[`src/defs/vm.rs`]: ./src/defs/vm.rs
36 changes: 36 additions & 0 deletions crates/cheatcodes/assets/cheatcodes.json

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

6 changes: 3 additions & 3 deletions crates/cheatcodes/assets/cheatcodes.schema.json

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

7 changes: 1 addition & 6 deletions crates/cheatcodes/src/defs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,12 @@ pub struct Cheatcode<'a> {
pub description: &'a str,

// Manually-specified fields.
/// The group this cheatcode belongs to.
/// Has to be specified for each cheatcode.
/// The group that the cheatcode belongs to.
pub group: Group,
/// The current status of the cheatcode. E.g. whether it is stable or experimental, etc.
/// Has to be specified for each cheatcode.
pub status: Status,
/// Whether the cheatcode is safe to use inside of scripts. E.g. it does not change state in an
/// unexpected way.
///
/// Defaults first to the group's safety if unspecified. If the group is ambiguous, then it
/// must be specified manually.
pub safety: Safety,
}

Expand Down
Loading
Loading