Skip to content

Commit

Permalink
feat(cheatcode): promptSecretUint (foundry-rs#8082)
Browse files Browse the repository at this point in the history
  • Loading branch information
DhairyaSethi authored Jun 6, 2024
1 parent 1138860 commit 0248a62
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 1 deletion.
20 changes: 20 additions & 0 deletions crates/cheatcodes/assets/cheatcodes.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions crates/cheatcodes/spec/src/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1499,6 +1499,10 @@ interface Vm {
#[cheatcode(group = Filesystem)]
function promptSecret(string calldata promptText) external returns (string memory input);

/// Prompts the user for hidden uint256 in the terminal (usually pk).
#[cheatcode(group = Filesystem)]
function promptSecretUint(string calldata promptText) external returns (uint256);

/// Prompts the user for an address in the terminal.
#[cheatcode(group = Filesystem)]
function promptAddress(string calldata promptText) external returns (address);
Expand Down
7 changes: 7 additions & 0 deletions crates/cheatcodes/src/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,13 @@ impl Cheatcode for promptSecretCall {
}
}

impl Cheatcode for promptSecretUintCall {
fn apply(&self, state: &mut Cheatcodes) -> Result {
let Self { promptText: text } = self;
parse(&prompt(state, text, prompt_password)?, &DynSolType::Uint(256))
}
}

impl Cheatcode for promptAddressCall {
fn apply(&self, state: &mut Cheatcodes) -> Result {
let Self { promptText: text } = self;
Expand Down
2 changes: 1 addition & 1 deletion crates/evm/traces/src/decoder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ impl CallTraceDecoder {
match func.name.as_str() {
s if s.starts_with("env") => Some("<env var value>"),
"createWallet" | "deriveKey" => Some("<pk>"),
"promptSecret" => Some("<secret>"),
"promptSecret" | "promptSecretUint" => Some("<secret>"),
"parseJson" if self.verbosity < 5 => Some("<encoded JSON value>"),
"readFile" if self.verbosity < 5 => Some("<file>"),
_ => None,
Expand Down
1 change: 1 addition & 0 deletions testdata/cheats/Vm.sol

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions testdata/default/cheats/Prompt.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ contract PromptTest is DSTest {

vm._expectCheatcodeRevert();
vm.promptSecret("test");

vm._expectCheatcodeRevert();
uint256 test = vm.promptSecretUint("test");
}

function testPrompt_Address() public {
Expand Down

0 comments on commit 0248a62

Please sign in to comment.