Skip to content

Commit

Permalink
chore(cast): add 4byte-calldata alias (#9927)
Browse files Browse the repository at this point in the history
* change 4byte-decode -> 4byte-calldata in non breaking way, 4byte-decode and shorthands are hidden aliases

* nit

* update test with alias for regression

* fix failing test due to args chaining
  • Loading branch information
zerosnacks authored Feb 20, 2025
1 parent f3130a5 commit c609884
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
4 changes: 2 additions & 2 deletions crates/cast/bin/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -650,8 +650,8 @@ pub enum CastSubcommand {
},

/// Decode ABI-encoded calldata using https://openchain.xyz.
#[command(name = "4byte-decode", visible_aliases = &["4d", "4bd"])]
FourByteDecode {
#[command(name = "4byte-calldata", aliases = &["4byte-decode", "4d", "4bd"], visible_aliases = &["4c", "4bc"])]
FourByteCalldata {
/// The ABI-encoded calldata.
calldata: Option<String>,
},
Expand Down
2 changes: 1 addition & 1 deletion crates/cast/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ async fn main_args(args: CastArgs) -> Result<()> {
sh_println!("{sig}")?
}
}
CastSubcommand::FourByteDecode { calldata } => {
CastSubcommand::FourByteCalldata { calldata } => {
let calldata = stdin::unwrap_line(calldata)?;
let sigs = decode_calldata(&calldata).await?;
sigs.iter().enumerate().for_each(|(i, sig)| {
Expand Down
11 changes: 10 additions & 1 deletion crates/cast/tests/cli/selectors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,16 @@ Error: Invalid selector 0xa9059c: expected 10 characters (including 0x prefix).
"#]]);
});

casttest!(fourbyte_decode, |_prj, cmd| {
casttest!(fourbyte_calldata, |_prj, cmd| {
cmd.args(["4byte-calldata", "0xa9059cbb0000000000000000000000000a2ac0c368dc8ec680a0c98c907656bd970675950000000000000000000000000000000000000000000000000000000767954a79"]).assert_success().stdout_eq(str![[r#"
1) "transfer(address,uint256)"
0x0A2AC0c368Dc8eC680a0c98C907656BD97067595
31802608249 [3.18e10]
"#]]);
});

casttest!(fourbyte_calldata_alias, |_prj, cmd| {
cmd.args(["4byte-decode", "0xa9059cbb0000000000000000000000000a2ac0c368dc8ec680a0c98c907656bd970675950000000000000000000000000000000000000000000000000000000767954a79"]).assert_success().stdout_eq(str![[r#"
1) "transfer(address,uint256)"
0x0A2AC0c368Dc8eC680a0c98C907656BD97067595
Expand Down

0 comments on commit c609884

Please sign in to comment.