@@ -52,14 +52,19 @@ impl ABIDecoder {
52
52
///
53
53
/// let decoder = ABIDecoder::default();
54
54
///
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();
56
56
///
57
- /// assert_eq!(u8 ::from_token(token).unwrap(), 7u8 );
57
+ /// assert_eq!(u64 ::from_token(token).unwrap(), 7u64 );
58
58
/// ```
59
59
pub fn decode ( & self , param_type : & ParamType , bytes : & [ u8 ] ) -> Result < Token > {
60
60
BoundedDecoder :: new ( self . config ) . decode ( param_type, bytes)
61
61
}
62
62
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
+
63
68
/// Same as `decode` but decodes multiple `ParamType`s in one go.
64
69
/// # Examples
65
70
/// ```
@@ -68,7 +73,7 @@ impl ABIDecoder {
68
73
/// use fuels_core::types::Token;
69
74
///
70
75
/// 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];
72
77
///
73
78
/// let tokens = decoder.decode_multiple(&[ParamType::U8, ParamType::U8], &data).unwrap();
74
79
///
@@ -114,7 +119,7 @@ mod tests {
114
119
] ;
115
120
let data = [
116
121
0x0 , 0x0 , 0x0 , 0x0 , 0xff , 0xff , 0xff , 0xff , // u32
117
- 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0xff , // u8
122
+ 0xff , // u8
118
123
0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0xff , 0xff , // u16
119
124
0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , // u64
120
125
0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff ,
@@ -141,9 +146,7 @@ mod tests {
141
146
#[ test]
142
147
fn decode_bool ( ) -> Result < ( ) > {
143
148
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 ] ;
147
150
148
151
let decoded = ABIDecoder :: default ( ) . decode_multiple ( & types, & data) ?;
149
152
@@ -215,9 +218,7 @@ mod tests {
215
218
fn decode_array ( ) -> Result < ( ) > {
216
219
// Create a parameter type for u8[2].
217
220
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 ] ;
221
222
222
223
let decoded = ABIDecoder :: default ( ) . decode_multiple ( & types, & data) ?;
223
224
@@ -234,7 +235,7 @@ mod tests {
234
235
// }
235
236
236
237
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 ,
238
239
] ;
239
240
let param_type = ParamType :: Struct {
240
241
fields : vec ! [ ParamType :: U8 , ParamType :: Bool ] ,
@@ -366,8 +367,8 @@ mod tests {
366
367
} ;
367
368
368
369
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 ,
371
372
] ;
372
373
373
374
let decoded = ABIDecoder :: default ( ) . decode ( & nested_struct, & data) ?;
@@ -416,26 +417,23 @@ mod tests {
416
417
417
418
let u8_arr = ParamType :: Array ( Box :: new ( ParamType :: U8 ) , 2 ) ;
418
419
let b256 = ParamType :: B256 ;
419
- let s = ParamType :: StringArray ( 3 ) ;
420
- let ss = ParamType :: StringSlice ;
421
420
422
- let types = [ nested_struct, u8_arr, b256, s , ss ] ;
421
+ let types = [ nested_struct, u8_arr, b256] ;
423
422
424
423
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, //
439
437
] ;
440
438
441
439
let decoded = ABIDecoder :: default ( ) . decode_multiple ( & types, & bytes) ?;
@@ -457,14 +455,7 @@ mod tests {
457
455
0xf3 , 0x1e , 0x93 , 0xb ,
458
456
] ) ;
459
457
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] ;
468
459
469
460
assert_eq ! ( decoded, expected) ;
470
461
Ok ( ( ) )
@@ -555,13 +546,6 @@ mod tests {
555
546
assert ! ( matches!( result, Err ( Error :: InvalidType ( _) ) ) ) ;
556
547
}
557
548
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
-
565
549
#[ test]
566
550
pub fn multiply_overflow_arith ( ) {
567
551
let mut param_type: ParamType = U16 ;
0 commit comments