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
Component
Forge, Cast
Describe the feature you would like
Given that
castsupports wallet imports: #1869, is it possible to get the wallet private key usingforgewhen 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 scriptalready supports this:But
forge testdoes not. Maybe something like the following would be great:And then in tests, we can use:
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