foundry-rs / forge-std

Forge Standard Library is a collection of helpful contracts for use with forge and foundry. It leverages forge's cheatcodes to make writing tests easier and faster, while improving the UX of cheatcodes. For more in-depth usage examples checkout the tests.
Apache License 2.0
850 stars 335 forks source link

feat(`vm`): get broadcasts #627

Closed yash-atreya closed 3 weeks ago

yash-atreya commented 3 weeks ago

Add cheatcodes introduced in https://github.com/foundry-rs/foundry/pull/9107.


// Returns the most recent broadcast for the given contract on `chainId` matching `txType`.
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.
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.
function getBroadcasts(string memory contractName, uint64 chainId) external returns (BroadcastTxSummary[] memory);

// Returns the most recent deployment for the current `chainId`.
function getDeployment(string memory contractName) external returns (address deployedAddress);

// Returns the most recent deployment for the given contract on `chainId`
function getDeployment(string memory contractName, uint64 chainId) external returns (address deployedAddress);

// 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.
function getDeployments(string memory contractName, uint64 chainId) external returns (address[] memory deployedAddresses);

These cheatcodes enable the following behaviour: