Skip to content

Commit 6ca977f

Browse files
brockelmoregakonstjoshieDo
authored
feat(forge): Solidity Scripting (#1208)
* forge install: ds-test * basic scripting * remove dirty file * updates * fixes * remove excess comments * updates * fmt * diff score move * working transaction sending MVP * fixes * remove accidental short rename * updates * write tx receipts to file * panic if nonce changes unexpectedly while sending txes * add ScriptSequence * add transaction receipts to ScriptSequence * add resume * add forgetest for script * fix nonce tracking on broadcastable txes * do not send transactions if simulation failed * add test with and without library * replace link for link_with_nonce(1) * make valid fork url a requirement * fix nonce tracking & helper contract callers * refactor to a script testbuilder * remove old comment * cleanup * change localhost to 127.0.0.1 * ScriptTester takes ownership of cmd * move ScriptTester to its own module * use Paint instead of ansi * add missing Chain import * turn scripttester fn into async * add anvil to tests 🔥 🔨 * better help description * make sure anvil spawns on different ports * link testdata to scripttester * enforce evm.sender as the predeploys deployer * handle call_inner nonces + test * remove ganache references * Revert "enforce evm.sender as the predeploys deployer" This reverts commit 9cf448a. * add --deployer to script * better error messages * add better description to resume command * cover case without a deployer set * split forge script into modules * add missing arguments from merge * remove unneeded .gitmodules * refactor script/runner * refactor script/executor * some more script refactor * add forgetest_async! macro * refactor cli/wallet * refactor: forge run calls forge script * rename forge run to forge debug * add etherscan identifier to script * move some functions to its proper modules * turn panic into bail * smol nits :shipit: * simplify needs_setup * use ethers set_chain_id * impl drop for scriptsequence * remove --force-resume * fix broadcast without args * remove --deployer use --sender instead * fix gas for committed transactions * add missing arg on test_executor * fmt * add support for preexisting CREATE2 * remove unnecessary println * chore: use RuntimeOrHandle from ethers * broadcast & receipt refactor for concurrent broadcasts * replace sender if only a single private key has been passed * better logs * adapt resume test to new changes * change scriptsequence saving behaviour * pass contract name, path or both to script/debug * add can_deploy_100_txes_concurrently test * add support for linking existing library addresses on script * only link external addresses if there is a RPC set * increase gas estimation to 1.3 * remove unused forge run file * set --sender as msg.sender with nonce correction instead * change broadcast log to filename-ts.json * make broadcast log folder configurable * improve documentation of correct_sender_nonce * add missing broadcast field on forgetest * fix broadcast wrap * group logs by chain_id * only show return data if it's not empty * change accounts on ScriptTester to Address * add default and async to debug.rs * add all() to MultiWallet * convert some bails into map_err * wrap_err on link() * remove rt from debug and script * docs * clippy * use SourceFile coming from artifact * when sending, only clone tx as it iterates * add ScriptOutcome * save tx with correct tx type on scriptsequence * set DEFAULT_SENDER as H160 * dont replace tx.caller on broadcast end * add create2 deployer to TestRunner as well * fix expected output on script tests * fix up receipts when resuming * store and try to recover from pending transaction hashes on scriptsequence * correct nonce after setUp if necessary * check status of the transaction receipt * add fix and test for deployment with setUp * add slow flag to enforce sequential broadcasting * change docs for cheatcodes * chore: add missing trait import * decode Create2Deployer on traces by default * revert if it it finds a staticcall after vm.broadcast * refactor signer discovery * update test * show missing warning * chore: bump ethers Co-authored-by: Georgios Konstantopoulos <[email protected]> Co-authored-by: joshieDo <[email protected]>
1 parent d27472b commit 6ca977f

Some content is hidden

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

44 files changed

+3349
-782
lines changed

Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cli/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ bytes = "1.1.0"
7474
strum = { version = "0.24", features = ["derive"] }
7575

7676
[dev-dependencies]
77+
anvil = { path = "../anvil" }
7778
foundry-utils = { path = "./../utils", features = ["test"] }
7879
foundry-cli-test-utils = { path = "./test-utils" }
7980
pretty_assertions = "1.0.0"

cli/src/cmd/forge/debug.rs

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
use super::{build::BuildArgs, script::ScriptArgs, watch::WatchArgs};
2+
use crate::{cmd::forge::build::CoreBuildArgs, opts::MultiWallet};
3+
use clap::{Parser, ValueHint};
4+
use foundry_common::evm::EvmArgs;
5+
use std::path::PathBuf;
6+
7+
// Loads project's figment and merges the build cli arguments into it
8+
foundry_config::impl_figment_convert!(DebugArgs, opts, evm_opts);
9+
10+
#[derive(Debug, Clone, Parser)]
11+
pub struct DebugArgs {
12+
/// The contract you want to run. Either the file path or contract name.
13+
///
14+
/// If multiple contracts exist in the same file you must specify the target contract with
15+
/// --target-contract.
16+
#[clap(value_hint = ValueHint::FilePath, value_name = "PATH")]
17+
pub path: PathBuf,
18+
19+
/// Arguments to pass to the script function.
20+
#[clap(value_name = "ARGS")]
21+
pub args: Vec<String>,
22+
23+
/// The name of the contract you want to run.
24+
#[clap(long, alias = "tc", value_name = "CONTRACT_NAME")]
25+
pub target_contract: Option<String>,
26+
27+
/// The signature of the function you want to call in the contract, or raw calldata.
28+
#[clap(long, short, default_value = "run()", value_name = "SIGNATURE")]
29+
pub sig: String,
30+
31+
/// Open the script in the debugger.
32+
#[clap(long)]
33+
pub debug: bool,
34+
35+
#[clap(flatten, next_help_heading = "BUILD OPTIONS")]
36+
pub opts: CoreBuildArgs,
37+
38+
#[clap(flatten, next_help_heading = "EVM OPTIONS")]
39+
pub evm_opts: EvmArgs,
40+
}
41+
42+
impl DebugArgs {
43+
pub async fn debug(self) -> eyre::Result<()> {
44+
let script = ScriptArgs {
45+
path: self.path.to_str().expect("Invalid path string.").to_string(),
46+
args: self.args,
47+
target_contract: self.target_contract,
48+
sig: self.sig,
49+
legacy: false,
50+
broadcast: false,
51+
opts: BuildArgs {
52+
args: self.opts,
53+
names: false,
54+
sizes: false,
55+
watch: WatchArgs::default(),
56+
},
57+
wallets: MultiWallet::default(),
58+
evm_opts: self.evm_opts,
59+
resume: false,
60+
debug: true,
61+
slow: false,
62+
};
63+
script.run_script().await
64+
}
65+
}

cli/src/cmd/forge/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
//! [`foundry_config::Config`].
77
//!
88
//! See [`BuildArgs`] for a reference implementation.
9-
//! And [`RunArgs`] for how to merge `Providers`.
9+
//! And [`DebugArgs`] for how to merge `Providers`.
1010
//!
1111
//! # Example
1212
//!
@@ -42,14 +42,15 @@ pub mod build;
4242
pub mod cache;
4343
pub mod config;
4444
pub mod create;
45+
pub mod debug;
4546
pub mod flatten;
4647
pub mod fmt;
4748
pub mod fourbyte;
4849
pub mod init;
4950
pub mod inspect;
5051
pub mod install;
5152
pub mod remappings;
52-
pub mod run;
53+
pub mod script;
5354
pub mod snapshot;
5455
pub mod test;
5556
pub mod tree;

0 commit comments

Comments
 (0)