Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions crates/cast/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use ethers::{
types::Address,
utils::keccak256,
};
use eyre::Result;
use eyre::{Result, WrapErr};
use foundry_cli::{handler, prompt, stdin, utils};
use foundry_common::{
abi::{format_tokens, get_event},
Expand Down Expand Up @@ -174,7 +174,7 @@ async fn main() -> Result<()> {
println!("{}", pretty_calldata(&calldata, offline).await?);
}
Subcommands::Sig { sig, optimize } => {
let sig = stdin::unwrap_line(sig)?;
let sig = stdin::unwrap_line(sig).wrap_err("Failed to read signature")?;
if optimize.is_none() {
println!("{}", SimpleCast::get_selector(&sig, None)?.0);
} else {
Expand Down
24 changes: 24 additions & 0 deletions crates/cast/bin/opts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -886,6 +886,7 @@ pub fn parse_slot(s: &str) -> Result<H256> {
#[cfg(test)]
mod tests {
use super::*;
use cast::SimpleCast;
use ethers::types::BlockNumber;

#[test]
Expand All @@ -908,6 +909,29 @@ mod tests {
};
}

// <https://github.com/foundry-rs/book/issues/1019>
#[test]
fn parse_signature() {
let args: Opts = Opts::parse_from([
"foundry-cli",
"sig",
"__$_$__$$$$$__$$_$$$_$$__$$___$$(address,address,uint256)",
]);
match args.sub {
Subcommands::Sig { sig, .. } => {
let sig = sig.unwrap();
assert_eq!(
sig,
"__$_$__$$$$$__$$_$$$_$$__$$___$$(address,address,uint256)".to_string()
);

let selector = SimpleCast::get_selector(&sig, None).unwrap();
assert_eq!(selector.0, "0x23b872dd".to_string());
}
_ => unreachable!(),
};
}

#[test]
fn parse_block_ids() {
struct TestCase {
Expand Down