Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add some more coerce error message tests #535

Merged
merged 1 commit into from
Feb 19, 2024
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
29 changes: 29 additions & 0 deletions crates/dyn-abi/src/coerce.rs
Original file line number Diff line number Diff line change
Expand Up @@ -864,6 +864,14 @@ mod tests {
assert_error_contains(&e, "Invalid string length");
let e = t.coerce_str("[0x0]").unwrap_err();
assert_error_contains(&e, "Odd number of digits");

let t = DynSolType::Array(Box::new(DynSolType::Tuple(vec![DynSolType::FixedBytes(1)])));
let e = t.coerce_str("[(0)]").unwrap_err();
assert_error_contains(&e, "Odd number of digits");
let e = t.coerce_str("[(0x)]").unwrap_err();
assert_error_contains(&e, "Invalid string length");
let e = t.coerce_str("[(0x0)]").unwrap_err();
assert_error_contains(&e, "Odd number of digits");
}

#[test]
Expand Down Expand Up @@ -926,6 +934,27 @@ mod tests {
DynSolType::Bytes.coerce_str("0x0017").unwrap(),
DynSolValue::Bytes(vec![0x00, 0x17])
);

let t = DynSolType::Tuple(vec![DynSolType::Bytes, DynSolType::Bytes]);
let e = t.coerce_str("(0, 0x0)").unwrap_err();
assert_error_contains(&e, "Odd number of digits");

// TODO: cut_err in `array_parser` somehow
/*
let t = DynSolType::Array(Box::new(DynSolType::Tuple(vec![
DynSolType::Bytes,
DynSolType::Bytes,
])));
let e = t.coerce_str("[(0, 0x0)]").unwrap_err();
assert_error_contains(&e, "Odd number of digits");

let t = DynSolType::Array(Box::new(DynSolType::Tuple(vec![
DynSolType::Bytes,
DynSolType::Bytes,
])));
let e = t.coerce_str("[(0x00, 0x0)]").unwrap_err();
assert_error_contains(&e, "Odd number of digits");
*/
}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion crates/sol-type-parser/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ where
name,
delimited(
(char_parser(open), space0),
cut_err(separated(0.., f, (char_parser(delim), space0))),
separated(0.., f, (char_parser(delim), space0)),
(opt(delim), space0, cut_err(char_parser(close))),
),
)
Expand Down
Loading