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(forge test): add --account <some_account> flag to access wallet inside tests #7950

Closed
ericywl opened this issue May 20, 2024 · 1 comment · Fixed by #9087
Closed

feat(forge test): add --account <some_account> flag to access wallet inside tests #7950

ericywl opened this issue May 20, 2024 · 1 comment · Fixed by #9087
Labels
C-forge Command: forge Cmd-forge-test Command: forge test T-feature Type: feature
Milestone

Comments

@ericywl
Copy link

ericywl commented May 20, 2024

Component

Forge, Cast

Describe the feature you would like

Given that cast supports wallet imports: #1869, is it possible to get the wallet private key using forge when running tests, instead of putting them in the .env file? For example, via some cheatcode that enables us to get the wallet and obtain the private key?

For reference, deploying via forge script already supports this:

$ forge script script/DeploySimpleStorage.s.sol --rpc-url $SEPOLIA_RPC_URL --broadcast --account <some_account>

But forge test does not. Maybe something like the following would be great:

$ forge test --fork-url $SEPOLIA_RPC_URL --account <some_account>

And then in tests, we can use:

vm.getAccount().privateKey

instead of

vm.envUint("PRIVATE_KEY")

to obtain the private key for deploying onto testnet fork for testing.

Additional context

Original discussion: Cyfrin/foundry-full-course-cu#1733
Reference: #6034

@ericywl ericywl added the T-feature Type: feature label May 20, 2024
@zerosnacks zerosnacks changed the title Using cast wallet account in forge test feat(forge test): add --account <some_account> flag to access wallet inside tests Jul 16, 2024
@zerosnacks zerosnacks added Cmd-forge-test Command: forge test C-forge Command: forge labels Jul 16, 2024
@zerosnacks zerosnacks added this to the v1.0.0 milestone Jul 26, 2024
@grandizzy
Copy link
Collaborator

there's a similar issue #8225, going to close this and track in 8225. thank you

@grandizzy grandizzy closed this as not planned Won't fix, can't repro, duplicate, stale Oct 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-forge Command: forge Cmd-forge-test Command: forge test T-feature Type: feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants