Skip to content

feat(cheatcodes): vm.getScriptWallets()#9052

Merged
yash-atreya merged 5 commits into
masterfrom
yash/script-wallets
Oct 9, 2024
Merged

feat(cheatcodes): vm.getScriptWallets()#9052
yash-atreya merged 5 commits into
masterfrom
yash/script-wallets

Conversation

@yash-atreya

@yash-atreya yash-atreya commented Oct 7, 2024

Copy link
Copy Markdown
Contributor

Motivation

Closes #7213 + Closes #6198

Solution

Adds vm.getScriptWallets() that returns an array of addresses whose private keys are locally available i.e provided by the user.

This cheatcode helps write scripts that require access to multiple wallets and use them conditionally.

@yash-atreya yash-atreya changed the title [WIP] feat(`cheatcodes): vm.getScriptWallets() feat(cheatcodes): vm.getScriptWallets() Oct 7, 2024
@DaniPopes

DaniPopes commented Oct 7, 2024

Copy link
Copy Markdown
Member

Are the referenced issues being fixed with this PR? If so please add the GH keywords.

@yash-atreya

Copy link
Copy Markdown
Contributor Author

Are the referenced issues being fixed with this PR? If so please add the GH keywords.

Done

@grandizzy grandizzy left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could add following test in forge/tests/cli/script.rs

// Tests that the `getScriptWallets` cheatcode works correctly.
forgetest_init!(can_get_script_wallets, |prj, cmd| {
    let script = prj
        .add_source(
            "Foo",
            r#"
import "forge-std/Script.sol";

interface Vm {
    function getScriptWallets() external returns (address[] memory wallets);
}

contract WalletScript is Script {
    function run() public {
        address[] memory wallets = Vm(address(vm)).getScriptWallets();
        console.log(wallets[0]);
    }
}"#,
        )
        .unwrap();
    cmd.arg("script")
        .arg(script)
        .args([
            "--private-key",
            "0x2a871d0798f97d79848a013d4936a73bf4cc922c825d33c1cf7073dff6d409c6",
            "-v",
        ])
        .assert_success()
        .stdout_eq(str![[r#"
[COMPILING_FILES] with [SOLC_VERSION]
[SOLC_VERSION] [ELAPSED]
Compiler run successful!
Script ran successfully.
[GAS]

== Logs ==
  0xa0Ee7A142d267C1f36714E4a8F75612F20a79720

"#]]);
});

Comment thread crates/cheatcodes/src/script.rs Outdated
---------

Co-authored-by: grandizzy <grandizzy.the.egg@gmail.com>
@yash-atreya

Copy link
Copy Markdown
Contributor Author

forge-std companion PR: foundry-rs/forge-std#620

@yash-atreya yash-atreya enabled auto-merge (squash) October 9, 2024 05:48
@grandizzy grandizzy self-requested a review October 9, 2024 06:01

@grandizzy grandizzy left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@yash-atreya yash-atreya merged commit 373ad46 into master Oct 9, 2024
@yash-atreya yash-atreya deleted the yash/script-wallets branch October 9, 2024 06:01
yash-atreya added a commit to foundry-rs/forge-std that referenced this pull request Oct 15, 2024
Companion PR for foundry-rs/foundry#9052

Adds the cheatcode `function getWallets() external returns (address[]
memory wallets)`
@grandizzy grandizzy added T-feature Type: feature C-forge Command: forge labels Dec 18, 2024
thomas-lamb-tech pushed a commit to thomas-lamb-tech/std_forge that referenced this pull request Dec 26, 2024
Companion PR for foundry-rs/foundry#9052

Adds the cheatcode `function getWallets() external returns (address[]
memory wallets)`
aubBrooks919 added a commit to aubBrooks919/forge-std that referenced this pull request Sep 25, 2025
Companion PR for foundry-rs/foundry#9052

Adds the cheatcode `function getWallets() external returns (address[]
memory wallets)`
davidLong89 added a commit to davidLong89/forge-std that referenced this pull request Sep 25, 2025
Companion PR for foundry-rs/foundry#9052

Adds the cheatcode `function getWallets() external returns (address[]
memory wallets)`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C-forge Command: forge T-feature Type: feature

Projects

Archived in project

3 participants