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.rememberKeys #9087

Merged
merged 8 commits into from
Oct 14, 2024
Merged

feat(cheatcodes): vm.rememberKeys #9087

merged 8 commits into from
Oct 14, 2024

Conversation

yash-atreya
Copy link
Member

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

Motivation

Closes #8225 + Closes #7950

Solution

Introduces cheatcodes to derive and save multiple wallets/signers in the script env.

function rememberKeys(string calldata mnemonic, string calldata derivationPath, uint32 count) external returns (address[] memory keyAddrs);
function rememberKeys(string calldata mnemonic, string calldata derivationPath, string calldata language, uint32 count) external returns (address[] memory keyAddrs);

Under the hood these cheatcodes save the derived wallets in ScriptWallets such that they are persisted throughout the script environment.

Moreover, to aid in the testing of scripts (as in forge test DeployScript.t.sol) these cheatcodes will initialize ScriptWallets in the CheatsConfig if not already initialized
This is particularly useful for testing scripts that require unlocked accounts.

@yash-atreya yash-atreya marked this pull request as ready for review October 10, 2024 10:51
@yash-atreya yash-atreya marked this pull request as draft October 10, 2024 12:31
@yash-atreya yash-atreya marked this pull request as ready for review October 10, 2024 13:03
@yash-atreya
Copy link
Member Author

Companion PR: foundry-rs/forge-std#622

@yash-atreya
Copy link
Member Author

@grandizzy @klkvr review pls

Copy link
Member

@klkvr klkvr left a comment

Choose a reason for hiding this comment

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

lgtm, note on performance, would like us to revisit script wallets handling if we want to support scripting cheats in tests as well

// This is needed in case of testing scripts, wherein script wallets are not set on setup.
let script_wallets = ScriptWallets::new(MultiWallet::default(), None);
script_wallets.add_local_signer(wallet);
Arc::make_mut(&mut state.config).script_wallets = Some(script_wallets);
Copy link
Member

Choose a reason for hiding this comment

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

this might be quite expensive because we'll clone config which stores all project bytecodes

I think essentially for tests ScriptWallets can just be a vec of PrivateKeySigners stored on Cheatcodes

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 9415dde into master Oct 14, 2024
21 checks passed
@yash-atreya yash-atreya deleted the yash/remember-keys branch October 14, 2024 07:00
rplusq pushed a commit to rplusq/foundry that referenced this pull request Nov 29, 2024
* feat(`cheatcodes`): vm.rememberKeys

* docs + return addresses + test

* remeberKeys with language

* doc nits

* cargo cheats

* set script wallet in config if unset

* nit

* test
@grandizzy grandizzy added T-feature Type: feature C-forge Command: forge labels Dec 18, 2024
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
5 participants