Skip to content

Commit 5be158b

Browse files
authored
test: add sig test case (#5969)
1 parent 8e64cff commit 5be158b

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

crates/cast/bin/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use ethers::{
77
types::Address,
88
utils::keccak256,
99
};
10-
use eyre::Result;
10+
use eyre::{Result, WrapErr};
1111
use foundry_cli::{handler, prompt, stdin, utils};
1212
use foundry_common::{
1313
abi::{format_tokens, get_event},
@@ -174,7 +174,7 @@ async fn main() -> Result<()> {
174174
println!("{}", pretty_calldata(&calldata, offline).await?);
175175
}
176176
Subcommands::Sig { sig, optimize } => {
177-
let sig = stdin::unwrap_line(sig)?;
177+
let sig = stdin::unwrap_line(sig).wrap_err("Failed to read signature")?;
178178
if optimize.is_none() {
179179
println!("{}", SimpleCast::get_selector(&sig, None)?.0);
180180
} else {

crates/cast/bin/opts.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -886,6 +886,7 @@ pub fn parse_slot(s: &str) -> Result<H256> {
886886
#[cfg(test)]
887887
mod tests {
888888
use super::*;
889+
use cast::SimpleCast;
889890
use ethers::types::BlockNumber;
890891

891892
#[test]
@@ -908,6 +909,29 @@ mod tests {
908909
};
909910
}
910911

912+
// <https://github.com/foundry-rs/book/issues/1019>
913+
#[test]
914+
fn parse_signature() {
915+
let args: Opts = Opts::parse_from([
916+
"foundry-cli",
917+
"sig",
918+
"__$_$__$$$$$__$$_$$$_$$__$$___$$(address,address,uint256)",
919+
]);
920+
match args.sub {
921+
Subcommands::Sig { sig, .. } => {
922+
let sig = sig.unwrap();
923+
assert_eq!(
924+
sig,
925+
"__$_$__$$$$$__$$_$$$_$$__$$___$$(address,address,uint256)".to_string()
926+
);
927+
928+
let selector = SimpleCast::get_selector(&sig, None).unwrap();
929+
assert_eq!(selector.0, "0x23b872dd".to_string());
930+
}
931+
_ => unreachable!(),
932+
};
933+
}
934+
911935
#[test]
912936
fn parse_block_ids() {
913937
struct TestCase {

0 commit comments

Comments
 (0)