@@ -52,14 +52,19 @@ impl ABIDecoder {
5252 ///
5353 /// let decoder = ABIDecoder::default();
5454 ///
55- /// let token = decoder.decode(&ParamType::U8 , &[0, 0, 0, 0, 0, 0, 0, 7]).unwrap();
55+ /// let token = decoder.decode(&ParamType::U64 , &[0, 0, 0, 0, 0, 0, 0, 7]).unwrap();
5656 ///
57- /// assert_eq!(u8 ::from_token(token).unwrap(), 7u8 );
57+ /// assert_eq!(u64 ::from_token(token).unwrap(), 7u64 );
5858 /// ```
5959 pub fn decode ( & self , param_type : & ParamType , bytes : & [ u8 ] ) -> Result < Token > {
6060 BoundedDecoder :: new ( self . config ) . decode ( param_type, bytes)
6161 }
6262
63+ /// Decode data from one of the receipt returns.
64+ pub fn decode_receipt_return ( & self , param_type : & ParamType , bytes : & [ u8 ] ) -> Result < Token > {
65+ BoundedDecoder :: new ( self . config ) . decode ( param_type, bytes)
66+ }
67+
6368 /// Same as `decode` but decodes multiple `ParamType`s in one go.
6469 /// # Examples
6570 /// ```
@@ -68,7 +73,7 @@ impl ABIDecoder {
6873 /// use fuels_core::types::Token;
6974 ///
7075 /// let decoder = ABIDecoder::default();
71- /// let data: &[u8] = &[0, 0, 0, 0, 0, 0, 0, 7, 0, 0, 0, 0, 0, 0, 0 , 8];
76+ /// let data: &[u8] = &[7 , 8];
7277 ///
7378 /// let tokens = decoder.decode_multiple(&[ParamType::U8, ParamType::U8], &data).unwrap();
7479 ///
@@ -114,7 +119,7 @@ mod tests {
114119 ] ;
115120 let data = [
116121 0x0 , 0x0 , 0x0 , 0x0 , 0xff , 0xff , 0xff , 0xff , // u32
117- 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0xff , // u8
122+ 0xff , // u8
118123 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0xff , 0xff , // u16
119124 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , // u64
120125 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff ,
@@ -141,9 +146,7 @@ mod tests {
141146 #[ test]
142147 fn decode_bool ( ) -> Result < ( ) > {
143148 let types = vec ! [ ParamType :: Bool , ParamType :: Bool ] ;
144- let data = [
145- 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x01 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x00 ,
146- ] ;
149+ let data = [ 0x01 , 0x0 ] ;
147150
148151 let decoded = ABIDecoder :: default ( ) . decode_multiple ( & types, & data) ?;
149152
@@ -215,9 +218,7 @@ mod tests {
215218 fn decode_array ( ) -> Result < ( ) > {
216219 // Create a parameter type for u8[2].
217220 let types = vec ! [ ParamType :: Array ( Box :: new( ParamType :: U8 ) , 2 ) ] ;
218- let data = [
219- 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0xff , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x2a ,
220- ] ;
221+ let data = [ 0xff , 0x2a ] ;
221222
222223 let decoded = ABIDecoder :: default ( ) . decode_multiple ( & types, & data) ?;
223224
@@ -234,7 +235,7 @@ mod tests {
234235 // }
235236
236237 let data = [
237- 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x1 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x1 ,
238+ 0x1 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x1 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 ,
238239 ] ;
239240 let param_type = ParamType :: Struct {
240241 fields : vec ! [ ParamType :: U8 , ParamType :: Bool ] ,
@@ -366,8 +367,8 @@ mod tests {
366367 } ;
367368
368369 let data = [
369- 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0xa , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x1 , 0x0 ,
370- 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x1 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x2 ,
370+ 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0xa , 0x1 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x1 ,
371+ 0x2 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 ,
371372 ] ;
372373
373374 let decoded = ABIDecoder :: default ( ) . decode ( & nested_struct, & data) ?;
@@ -416,26 +417,23 @@ mod tests {
416417
417418 let u8_arr = ParamType :: Array ( Box :: new ( ParamType :: U8 ) , 2 ) ;
418419 let b256 = ParamType :: B256 ;
419- let s = ParamType :: StringArray ( 3 ) ;
420- let ss = ParamType :: StringSlice ;
421420
422- let types = [ nested_struct, u8_arr, b256, s , ss ] ;
421+ let types = [ nested_struct, u8_arr, b256] ;
423422
424423 let bytes = [
425- 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0xa , // foo.x == 10u16
426- 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x1 , // foo.y.a == true
427- 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x1 , // foo.b.0 == 1u8
428- 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x2 , // foo.b.1 == 2u8
429- 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x1 , // u8[2].0 == 1u8
430- 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x2 , // u8[2].0 == 2u8
431- 0xd5 , 0x57 , 0x9c , 0x46 , 0xdf , 0xcc , 0x7f , 0x18 , // b256
432- 0x20 , 0x70 , 0x13 , 0xe6 , 0x5b , 0x44 , 0xe4 , 0xcb , // b256
433- 0x4e , 0x2c , 0x22 , 0x98 , 0xf4 , 0xac , 0x45 , 0x7b , // b256
434- 0xa8 , 0xf8 , 0x27 , 0x43 , 0xf3 , 0x1e , 0x93 , 0xb , // b256
435- 0x66 , 0x6f , 0x6f , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , // str[3]
436- 0x54 , 0x68 , 0x69 , 0x73 , 0x20 , 0x69 , 0x73 , 0x20 , // str data
437- 0x61 , 0x20 , 0x66 , 0x75 , 0x6c , 0x6c , 0x20 , 0x73 , // str data
438- 0x65 , 0x6e , 0x74 , 0x65 , 0x6e , 0x63 , 0x65 , // str data
424+ 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0xa , // u16
425+ 0x1 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , // bool
426+ 0x1 , 0x2 , // array[u8]
427+ 0x1 , 0x2 , // array[u8]
428+ 0xd5 , 0x57 , 0x9c , 0x46 , 0xdf , 0xcc , 0x7f , 0x18 , // b256 start
429+ 0x20 , 0x70 , 0x13 , 0xe6 , 0x5b , 0x44 , 0xe4 , 0xcb , //
430+ 0x4e , 0x2c , 0x22 , 0x98 , 0xf4 , 0xac , 0x45 , 0x7b , //
431+ 0xa8 , 0xf8 , 0x27 , 0x43 , 0xf3 , 0x1e , 0x93 ,
432+ 0xb , // b256 end
433+ // 0x66, 0x6f, 0x6f, 0x00, 0x00, 0x00, 0x00, 0x00, // "foo"
434+ // 0x54, 0x68, 0x69, 0x73, 0x20, 0x69, 0x73, 0x20, //
435+ // 0x61, 0x20, 0x66, 0x75, 0x6c, 0x6c, 0x20, 0x73, //
436+ // 0x65, 0x6e, 0x74, 0x65, 0x6e, 0x63, 0x65, //
439437 ] ;
440438
441439 let decoded = ABIDecoder :: default ( ) . decode_multiple ( & types, & bytes) ?;
@@ -457,14 +455,7 @@ mod tests {
457455 0xf3 , 0x1e , 0x93 , 0xb ,
458456 ] ) ;
459457
460- let ss = Token :: StringSlice ( StaticStringToken :: new (
461- "This is a full sentence" . into ( ) ,
462- None ,
463- ) ) ;
464-
465- let s = Token :: StringArray ( StaticStringToken :: new ( "foo" . into ( ) , Some ( 3 ) ) ) ;
466-
467- let expected: Vec < Token > = vec ! [ foo, u8_arr, b256, s, ss] ;
458+ let expected: Vec < Token > = vec ! [ foo, u8_arr, b256] ;
468459
469460 assert_eq ! ( decoded, expected) ;
470461 Ok ( ( ) )
@@ -555,13 +546,6 @@ mod tests {
555546 assert ! ( matches!( result, Err ( Error :: InvalidType ( _) ) ) ) ;
556547 }
557548
558- #[ test]
559- pub fn multiply_overflow_vector ( ) {
560- let param_type = Vec :: < [ ( ) ; usize:: MAX ] > :: param_type ( ) ;
561- let result = ABIDecoder :: default ( ) . decode ( & param_type, & [ ] ) ;
562- assert ! ( matches!( result, Err ( Error :: InvalidData ( _) ) ) ) ;
563- }
564-
565549 #[ test]
566550 pub fn multiply_overflow_arith ( ) {
567551 let mut param_type: ParamType = U16 ;
0 commit comments