Skip to content

Commit b3e7938

Browse files
committed
feat(abi-encode): fit args validation error message and add validation for packaged abi encode
1 parent 4561875 commit b3e7938

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

crates/cast/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1809,7 +1809,7 @@ impl SimpleCast {
18091809
let func = get_func(sig)?;
18101810
match encode_function_args(&func, args) {
18111811
Ok(res) => Ok(hex::encode_prefixed(&res[4..])),
1812-
Err(e) => eyre::bail!("{}", e),
1812+
Err(e) => eyre::bail!("Could not ABI encode the function and arguments: {}", e),
18131813
}
18141814
}
18151815

@@ -1840,7 +1840,7 @@ impl SimpleCast {
18401840
let encoded = match encode_function_args_packed(&func, args) {
18411841
Ok(res) => hex::encode(res),
18421842
Err(e) => eyre::bail!(
1843-
"Could not ABI encode the function and arguments. Did you pass in the right types?\nError\n{}",
1843+
"Could not ABI encode the function and arguments: {}",
18441844
e
18451845
),
18461846
};

crates/common/src/abi.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,13 @@ where
5353
I: IntoIterator<Item = S>,
5454
S: AsRef<str>,
5555
{
56+
57+
let args: Vec<S> = args.into_iter().collect();
58+
59+
if func.inputs.len() != args.len() {
60+
eyre::bail!("encode length mismatch: expected {} types, got {}", func.inputs.len(), args.len())
61+
}
62+
5663
let params: Vec<Vec<u8>> = std::iter::zip(&func.inputs, args)
5764
.map(|(input, arg)| coerce_value(&input.selector_type(), arg.as_ref()))
5865
.collect::<Result<Vec<_>>>()?

0 commit comments

Comments
 (0)