Skip to content

Commit

Permalink
test: test calculate_num_of_elements (#1230)
Browse files Browse the repository at this point in the history
Closes #1229.
  • Loading branch information
iqdecay authored Dec 11, 2023
1 parent 7d8fe92 commit f9ef414
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions packages/fuels-core/src/types/param_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1814,6 +1814,25 @@ mod tests {
assert_eq!(param_type, ParamType::String);
}

#[test]
fn calculate_num_of_elements() -> Result<()> {
let failing_param_type = ParamType::Array(Box::new(ParamType::U16), usize::MAX);
assert!(ParamType::calculate_num_of_elements(&failing_param_type, 0)
.unwrap_err()
.to_string()
.contains("Cannot calculate the number of elements"));
let zero_sized_type = ParamType::Array(Box::new(ParamType::StringArray(0)), 1000);
assert!(ParamType::calculate_num_of_elements(&zero_sized_type, 0)
.unwrap_err()
.to_string()
.contains("the type is zero-sized"));
assert!(ParamType::calculate_num_of_elements(&ParamType::U16, 9)
.unwrap_err()
.to_string()
.contains("1 extra bytes detected while decoding heap type"));
Ok(())
}

fn given_type_with_path(path: &str) -> Type {
Type {
type_field: format!("struct {path}"),
Expand Down

0 comments on commit f9ef414

Please sign in to comment.