-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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): vm.prompt*
cheatcodes
#5509
Comments
I would also like this feature. Personally I would find this useful also for things like choosing the chain (by passing it to @mattsse WDYT about this feature request? |
I think useful, however, this could lead to issues in CI. so this definitely should use some timeout so it doesn't hang indefinitely but I think this is nice to have, any concerns @mds1 ? |
Partly related to #2399 (comment) and #2900 in that we currently have no script-only cheatcodes. Currently all cheatcodes can be used in both script and test environments. I am supportive of this idea though, and you can more broadly imagine We should have
Let me know if that spec sounds right to everyone |
I think it makes sense to keep the format same as it's done for Such spec would look like this:
Also, should we consider |
How does the
My thinking was just always use comma separated and trim whitespace for strings if there's no quotes, but matching the existing env cheats is reasonable to me also.
This seems reasonable |
So the full spec then is:
for each of the aforementioned types? |
I was actually thinking we can go the simpler route and only allow strings, since we have a complete arsenal for parsing strings ( So basically expose two methods: function prompt(string memory prompt) returns (string memory input);
function promptSecret(string memory prompt) returns (string memory input); If needed, we could parse arrays using We could also start from supporting string-only, and if we see it's not enough we can add all the overloads. |
Hmm interesting idea, ok I'm onboard with that newest proposal. It helps keep the API clean, and if it ends up cluttering code too much (having to manually parse the string with e.g. |
If there will be need in more overloads this should be possible to be done with just some new forge-std library which will look like this (or maybe we can add it from the beginning) library StdPrompts {
VmSafe private constant vm = VmSafe(address(uint160(uint256(keccak256("hevm cheat code")))));
function promptUint(string memory prompt) internal pure returns (uint256) {
return vm.parseUint(vm.prompt(prompt));
}
...
} |
I like this idea a lot. |
Instead of adding things like that to forge-std, we should just make them native cheats :) see #3782 |
Oh interesting, I didn't consider compilation time 😅 |
Yeah, #3782 seems reasonable Adding just |
So if everyone is onboard, I will gladly implement this. I will say I decided last minute to participate in ETHOnline so I will probably start working on it after the hackathon (It ends Oct 22nd I believe). |
Ok I'm "back" from ETHOnline.
function prompt(string memory prompt, string memory default) returns (string memory input);
function promptSecret(string memory prompt, string memory default) returns (string memory input);
|
|
Thank you @mds1 for the heads up 🙏 Is there a PR/issue I can subscribe to to follow the refactor, so I know when it's done? |
new crate layout should be stable by EOW |
Cool, thank you 👍 |
@Tudmotu Hey, yes it has been. You can find the docs here: https://github.com/foundry-rs/foundry/blob/master/docs/dev/cheatcodes.md#adding-a-new-cheatcode |
Thank you! Just as an update here: I've been busy with work stuff, but hopefully I will get to work on this in the coming weeks. |
I think we also want promptAddress and promptUint for convenience |
Ok, yeah that's why I was not sure if we wanna close it 👍 |
will implement this! |
Component
Forge
Describe the feature you would like
Add
vm.promptAddress(string prompt)
,vm.promptUint(string prompt)
, etc. cheatcodes which would prompt user for some input. This could be used as an alternative of script function args.Reasons why I think this could be useful:
--sig
argumentExpected behavior:
Additional context
No response
The text was updated successfully, but these errors were encountered: