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(cheatcodes): access broadcast artifacts #9107

Merged
merged 56 commits into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from 50 commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
95ad043
refac(`script`): extract script sequence and related types to new crate
yash-atreya Oct 11, 2024
4ac9e83
replace MultiChainSequence in script crate
yash-atreya Oct 11, 2024
7c23df8
replace TransactionWithMetadata and AdditionalContract
yash-atreya Oct 11, 2024
3870290
replace ScriptSequence
yash-atreya Oct 11, 2024
3da2355
replace all underlying ScriptSequence and related types
yash-atreya Oct 11, 2024
c06159b
doc nits
yash-atreya Oct 11, 2024
159f51d
Merge branch 'master' into yash/refac-script-sequence
yash-atreya Oct 14, 2024
a7237f8
add `ScriptTransactionBuilder`
yash-atreya Oct 14, 2024
388ce6b
remove `TxWithMetadata`
yash-atreya Oct 14, 2024
f20e276
mv verify fns and use `ScriptSequence` directly
yash-atreya Oct 14, 2024
a32c3c4
clippy
yash-atreya Oct 14, 2024
9c38c02
feat(`cheatcodes`): vm.getDeployment
yash-atreya Oct 14, 2024
6e6ced1
Merge branch 'master' into yash/get-deployment-data
yash-atreya Oct 16, 2024
f0c863f
cargo cheats
yash-atreya Oct 16, 2024
f7ccff7
getBroadcast by txType
yash-atreya Oct 16, 2024
9a829c4
get all broadcast txs
yash-atreya Oct 16, 2024
b273968
Merge branch 'master' into yash/get-deployment-data
yash-atreya Oct 18, 2024
c91546c
nits
yash-atreya Oct 18, 2024
caea855
fix
yash-atreya Oct 18, 2024
bbc53d6
feat: getBroadcasts by txType
yash-atreya Oct 18, 2024
80a86e1
nit
yash-atreya Oct 18, 2024
15bf2cf
fix
yash-atreya Oct 18, 2024
32704c1
mv `BroadcastReader` to script-sequence
yash-atreya Oct 18, 2024
0881db6
Merge branch 'master' into yash/get-deployment-data
yash-atreya Oct 22, 2024
11f12c9
fix: search all broadcast files and then apply filters
yash-atreya Oct 22, 2024
28e1309
fix: ignore run-latest to avoid duplicating entries
yash-atreya Oct 22, 2024
5769329
nit
yash-atreya Oct 22, 2024
da67563
sort by descending block number
yash-atreya Oct 22, 2024
9646bac
tests
yash-atreya Oct 22, 2024
3ed202b
feat(`CheatsConfig`): add `broadcast` dir path
yash-atreya Oct 23, 2024
83e2184
feat: read multichain sequences
yash-atreya Oct 23, 2024
9cdca2e
nit
yash-atreya Oct 23, 2024
6ae60a5
Merge branch 'master' into yash/get-deployment-data
yash-atreya Oct 23, 2024
4ce9df2
minify json
yash-atreya Oct 23, 2024
687aaf0
Merge branch 'master' into yash/get-deployment-data
yash-atreya Oct 24, 2024
1b302f5
use walkdir
yash-atreya Oct 24, 2024
9223724
fix
yash-atreya Oct 24, 2024
af2426e
Merge branch 'master' into yash/get-deployment-data
yash-atreya Oct 28, 2024
084f45e
fix path
yash-atreya Oct 28, 2024
f430821
feat: getDeployment cheatcodes
yash-atreya Oct 28, 2024
970452d
feat: read broadcasts with multiple tx types
yash-atreya Oct 28, 2024
6db3976
test: getDeployment
yash-atreya Oct 28, 2024
5b2ed48
nit
yash-atreya Oct 28, 2024
bf47b35
fmt
yash-atreya Oct 28, 2024
8a64238
fix
yash-atreya Oct 28, 2024
17e2e1f
nit
yash-atreya Oct 28, 2024
e5ca585
cli test
yash-atreya Oct 28, 2024
0f7bde5
nit
yash-atreya Oct 28, 2024
4dcfab1
remove solidity test
yash-atreya Oct 28, 2024
d7818cb
nit
yash-atreya Oct 28, 2024
0e6af96
nit
yash-atreya Oct 29, 2024
2f4ab12
fix
yash-atreya Oct 29, 2024
1418d93
nits
yash-atreya Oct 29, 2024
118c694
use find
yash-atreya Oct 29, 2024
6b8083a
fix: use absolute broadcast path in `CheatsConfig`
yash-atreya Oct 29, 2024
72274d3
feat: getDeployment current chain
yash-atreya Oct 29, 2024
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
2 changes: 2 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions crates/cheatcodes/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ foundry-config.workspace = true
foundry-evm-core.workspace = true
foundry-evm-traces.workspace = true
foundry-wallets.workspace = true
forge-script-sequence.workspace = true

alloy-dyn-abi.workspace = true
alloy-json-abi.workspace = true
Expand Down
149 changes: 149 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.

2 changes: 2 additions & 0 deletions crates/cheatcodes/spec/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,13 @@ impl Cheatcodes<'static> {
Vm::StorageAccess::STRUCT.clone(),
Vm::Gas::STRUCT.clone(),
Vm::DebugStep::STRUCT.clone(),
Vm::BroadcastTxSummary::STRUCT.clone(),
]),
enums: Cow::Owned(vec![
Vm::CallerMode::ENUM.clone(),
Vm::AccountAccessKind::ENUM.clone(),
Vm::ForgeContext::ENUM.clone(),
Vm::BroadcastTxType::ENUM.clone(),
]),
errors: Vm::VM_ERRORS.iter().copied().cloned().collect(),
events: Cow::Borrowed(&[]),
Expand Down
59 changes: 59 additions & 0 deletions crates/cheatcodes/spec/src/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,31 @@ interface Vm {
address contractAddr;
}

/// The transaction type (`txType`) of the broadcast.
enum BroadcastTxType {
/// Represents a CALL broadcast tx.
Call,
/// Represents a CREATE broadcast tx.
Create,
/// Represents a CREATE2 broadcast tx.
Create2
}

/// Represents a transaction's broadcast details.
struct BroadcastTxSummary {
/// The hash of the transaction that was broadcasted
bytes32 txHash;
/// Represent the type of transaction among CALL, CREATE, CREATE2
BroadcastTxType txType;
/// The address of the contract that was called or created.
/// This is address of the contract that is created if the txType is CREATE or CREATE2.
address contractAddress;
/// The block number the transaction landed in.
uint64 blockNumber;
/// Status of the transaction, retrieved from the transaction receipt.
bool success;
}

// ======== EVM ========

/// Gets the address for a given private key.
Expand Down Expand Up @@ -1670,6 +1695,40 @@ interface Vm {
#[cheatcode(group = Filesystem)]
function getDeployedCode(string calldata artifactPath) external view returns (bytes memory runtimeBytecode);

/// Returns the most recent broadcast for the given contract on `chainId` matching `txType`.
///
/// For example:
///
/// The most recent deployment can be fetched by passing `txType` as `CREATE` or `CREATE2`.
///
/// The most recent call can be fetched by passing `txType` as `CALL`.
#[cheatcode(group = Filesystem)]
function getBroadcast(string memory contractName, uint64 chainId, BroadcastTxType txType) external returns (BroadcastTxSummary memory);

/// Returns all broadcasts for the given contract on `chainId` with the specified `txType`.
///
/// Sorted such that the most recent broadcast is the first element, and the oldest is the last. i.e descending order of BroadcastTxSummary.blockNumber.
#[cheatcode(group = Filesystem)]
function getBroadcasts(string memory contractName, uint64 chainId, BroadcastTxType txType) external returns (BroadcastTxSummary[] memory);

/// Returns all broadcasts for the given contract on `chainId`.
///
/// Sorted such that the most recent broadcast is the first element, and the oldest is the last. i.e descending order of BroadcastTxSummary.blockNumber.
#[cheatcode(group = Filesystem)]
function getBroadcasts(string memory contractName, uint64 chainId) external returns (BroadcastTxSummary[] memory);

/// Returns the most recent deployment for the given contract on `chainId`
#[cheatcode(group = Filesystem)]
function getDeployment(string memory contractName, uint64 chainId) external returns (address deployedAddress);
yash-atreya marked this conversation as resolved.
Show resolved Hide resolved
yash-atreya marked this conversation as resolved.
Show resolved Hide resolved

/// Returns all deployments for the given contract on `chainId`
///
/// Sorted in descending order of deployment time i.e descending order of BroadcastTxSummary.blockNumber.
///
/// The most recent deployment is the first element, and the oldest is the last.
#[cheatcode(group = Filesystem)]
function getDeployments(string memory contractName, uint64 chainId) external returns (address[] memory deployedAddresses);

// -------- Foreign Function Interface --------

/// Performs a foreign function call via the terminal.
Expand Down
4 changes: 4 additions & 0 deletions crates/cheatcodes/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ pub struct CheatsConfig {
pub fs_permissions: FsPermissions,
/// Project root
pub root: PathBuf,
/// Path to broadcast dir
pub broadcast: PathBuf,
/// Paths (directories) where file reading/writing is allowed
pub allowed_paths: Vec<PathBuf>,
/// How the evm was configured by the user
Expand Down Expand Up @@ -87,6 +89,7 @@ impl CheatsConfig {
paths: config.project_paths(),
fs_permissions: config.fs_permissions.clone().joined(config.root.as_ref()),
root: config.root.0.clone(),
broadcast: config.broadcast.clone(),
allowed_paths,
evm_opts,
labels: config.labels.clone(),
Expand Down Expand Up @@ -216,6 +219,7 @@ impl Default for CheatsConfig {
paths: ProjectPathsConfig::builder().build_with_root("./"),
fs_permissions: Default::default(),
root: Default::default(),
broadcast: Default::default(),
allowed_paths: vec![],
evm_opts: Default::default(),
labels: Default::default(),
Expand Down
Loading
Loading