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(vm): get broadcasts #627

Merged
merged 2 commits into from
Nov 4, 2024
Merged

feat(vm): get broadcasts #627

merged 2 commits into from
Nov 4, 2024

Conversation

yash-atreya
Copy link
Member

Add cheatcodes introduced in foundry-rs/foundry#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:

  • Deploy a contract forge script CounterDeployScript --broadcast
  • Access the broadcast artifacts forge script BroadcastCollector
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
    }
}

@yash-atreya yash-atreya self-assigned this Oct 30, 2024
@yash-atreya yash-atreya requested a review from mds1 October 30, 2024 12:10
@yash-atreya yash-atreya merged commit da591f5 into master Nov 4, 2024
3 checks passed
@DaniPopes DaniPopes deleted the yash/get-broadcasts branch November 4, 2024 14:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant