Skip to content

Commit

Permalink
Merge branch 'master' into oleksii/mdbook-versions
Browse files Browse the repository at this point in the history
  • Loading branch information
hal3e authored Oct 5, 2023
2 parents 0a7c9cb + 2a6d052 commit f9d8a2b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
17 changes: 14 additions & 3 deletions packages/fuels-core/src/codec/abi_decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ mod tests {
use std::vec;

use super::*;
use crate::types::U256;
use crate::{
constants::WORD_SIZE,
types::{enum_variants::EnumVariants, errors::Error, StaticStringToken},
Expand All @@ -106,11 +107,19 @@ mod tests {
ParamType::U8,
ParamType::U16,
ParamType::U64,
ParamType::U128,
ParamType::U256,
];
let data = [
0x0, 0x0, 0x0, 0x0, 0xff, 0xff, 0xff, 0xff, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xff,
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff,
0x0, 0x0, 0x0, 0x0, 0xff, 0xff, 0xff, 0xff, // u32
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xff, // u8
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xff, 0xff, // u16
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, // u64
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, // u128
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, // u256
];

let decoded = ABIDecoder::default().decode_multiple(&types, &data)?;
Expand All @@ -120,6 +129,8 @@ mod tests {
Token::U8(u8::MAX),
Token::U16(u16::MAX),
Token::U64(u64::MAX),
Token::U128(u128::MAX),
Token::U256(U256::MAX),
];
assert_eq!(decoded, expected);
Ok(())
Expand Down
13 changes: 13 additions & 0 deletions packages/fuels-core/src/codec/abi_encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1200,4 +1200,17 @@ mod tests {

Ok(())
}

#[test]
fn encoding_large_unsigned_integers() -> Result<()> {
let token = Token::U128(u128::MAX);
let expected_encoding = [255; 16];
let result = ABIEncoder::encode(&[token])?.resolve(0);
assert_eq!(result, expected_encoding);
let token = Token::U256(U256::MAX);
let expected_encoding = [255; 32];
let result = ABIEncoder::encode(&[token])?.resolve(0);
assert_eq!(result, expected_encoding);
Ok(())
}
}

0 comments on commit f9d8a2b

Please sign in to comment.