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): vm.getScriptWallets() #9052

Merged
merged 5 commits into from
Oct 9, 2024
Merged

Conversation

yash-atreya
Copy link
Member

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

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
Copy link
Member

DaniPopes commented Oct 7, 2024

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

@yash-atreya
Copy link
Member Author

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

Done

Copy link
Collaborator

@grandizzy grandizzy left a comment

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

"#]]);
});

crates/cheatcodes/src/script.rs Outdated Show resolved Hide resolved
---------

Co-authored-by: grandizzy <grandizzy.the.egg@gmail.com>
@yash-atreya
Copy link
Member 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
Copy link
Collaborator

@grandizzy grandizzy left a comment

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
21 checks passed
@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)`
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