-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Conversation
cheatcodes
): access broadcast artifacts
@klkvr added the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice, looking good
just have nits
Add cheatcodes introduced in foundry-rs/foundry#9107. ```solidity // 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: - Deploy a contract `forge script CounterDeployScript --broadcast` - Access the broadcast artifacts `forge script BroadcastCollector` ```solidity contract BroadcastCollector is Script { function run() public { // Get the most recent counter deployment Vm.BroadcastTxSummary memory broadcast = Vm(address(vm)).getBroadcast( "Counter", 31337, Vm.BroadcastTxType.Create ); console.logBytes32(broadcast.txHash); console.logAddress(broadcast.contractAddress); // New contract address } } ```
Motivation
Builds upon #9098
Closes #4732 + partially addresses #9083
Closes #6807
#9083 requires access to the broadcast artifacts while the script is running. This isn't possible with the current script design as txs are broadcasted and their respective artifacts are written after the execution of the script is complete.
Solution
These cheatcodes enable the following behaviour:
forge script CounterDeployScript --broadcast
forge script BroadcastCollector