Skip to content

Commit

Permalink
test: implement missing codec tests over Bytes type (#1041)
Browse files Browse the repository at this point in the history
  • Loading branch information
iqdecay authored Jul 12, 2023
1 parent 5d97809 commit ea4687d
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 0 deletions.
63 changes: 63 additions & 0 deletions packages/fuels-code-gen/src/program_bindings/resolved_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,69 @@ mod tests {
)
}

#[test]
fn test_resolve_bytes() -> Result<()> {
test_resolve_first_type(
":: fuels :: types :: Bytes",
&[
TypeDeclaration {
type_id: 0,
type_field: "struct String".to_string(),
components: Some(vec![TypeApplication {
name: "bytes".to_string(),
type_id: 1,
..Default::default()
}]),
..Default::default()
},
TypeDeclaration {
type_id: 0,
type_field: "struct std::bytes::Bytes".to_string(),
components: Some(vec![
TypeApplication {
name: "buf".to_string(),
type_id: 1,
..Default::default()
},
TypeApplication {
name: "len".to_string(),
type_id: 3,
..Default::default()
},
]),
..Default::default()
},
TypeDeclaration {
type_id: 1,
type_field: "struct std::bytes::RawBytes".to_string(),
components: Some(vec![
TypeApplication {
name: "ptr".to_string(),
type_id: 2,
..Default::default()
},
TypeApplication {
name: "cap".to_string(),
type_id: 3,
..Default::default()
},
]),
..Default::default()
},
TypeDeclaration {
type_id: 2,
type_field: "raw untyped ptr".to_string(),
..Default::default()
},
TypeDeclaration {
type_id: 3,
type_field: "u64".to_string(),
..Default::default()
},
],
)
}

#[test]
fn test_resolve_string() -> Result<()> {
test_resolve_primitive_type("str[3]", ":: fuels :: types :: SizedAsciiString < 3usize >")
Expand Down
11 changes: 11 additions & 0 deletions packages/fuels-core/src/codec/abi_decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,17 @@ mod tests {
Ok(())
}

#[test]
fn decode_bytes() -> Result<()> {
let data = [0xFF, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05];
let decoded = ABIDecoder::decode_single(&ParamType::Bytes, &data)?;

let expected = Token::Bytes(data.to_vec());

assert_eq!(decoded, expected);
Ok(())
}

#[test]
fn decode_enum() -> Result<()> {
// enum MyEnum {
Expand Down
9 changes: 9 additions & 0 deletions packages/fuels-core/src/codec/function_selector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,15 @@ mod tests {
assert_eq!(selector, "some_fun(s<u32>(s<u32>(rawptr,u64),u64))")
}

#[test]
fn handles_bytes() {
let inputs = [ParamType::Bytes];

let selector = resolve_fn_signature("some_fun", &inputs);

assert_eq!(selector, "some_fun(s(s(rawptr,u64),u64))")
}

#[test]
fn handles_enums() {
let types = vec![ParamType::U64, ParamType::U32];
Expand Down

0 comments on commit ea4687d

Please sign in to comment.