23
23
import org .web3j .abi .datatypes .DynamicBytes ;
24
24
import org .web3j .abi .datatypes .Int ;
25
25
import org .web3j .abi .datatypes .StaticArray ;
26
+ import org .web3j .abi .datatypes .Type ;
26
27
import org .web3j .abi .datatypes .Uint ;
27
28
import org .web3j .abi .datatypes .Utf8String ;
28
29
import org .web3j .abi .datatypes .generated .Bytes1 ;
37
38
38
39
import static org .junit .jupiter .api .Assertions .assertEquals ;
39
40
import static org .junit .jupiter .api .Assertions .assertThrows ;
41
+ import static org .junit .jupiter .api .Assertions .assertTrue ;
40
42
41
43
public class TypeDecoderTest {
42
44
@@ -345,14 +347,14 @@ public void testStaticArray() throws Exception {
345
347
new Utf8String ("Hello, world!" ),
346
348
new Utf8String ("world! Hello," ))));
347
349
348
- StaticArray2 arr =
349
- (StaticArray2 )
350
- TypeDecoder .instantiateType ("uint256[2]" , new long [] {10 , Long .MAX_VALUE });
351
- assert (arr instanceof StaticArray2 );
350
+ Type arr = TypeDecoder .instantiateType ("uint256[2]" , new long [] {10 , Long .MAX_VALUE });
352
351
353
- assertEquals (arr .getValue ().get (0 ), (new Uint256 (BigInteger .TEN )));
352
+ assertTrue (arr instanceof StaticArray2 );
353
+ StaticArray2 staticArray2 = (StaticArray2 ) arr ;
354
+ assertEquals (staticArray2 .getValue ().get (0 ), (new Uint256 (BigInteger .TEN )));
354
355
355
- assertEquals (arr .getValue ().get (1 ), (new Uint256 (BigInteger .valueOf (Long .MAX_VALUE ))));
356
+ assertEquals (
357
+ staticArray2 .getValue ().get (1 ), (new Uint256 (BigInteger .valueOf (Long .MAX_VALUE ))));
356
358
}
357
359
358
360
@ Test
@@ -369,7 +371,7 @@ public void testEmptyStaticArray() {
369
371
}
370
372
371
373
@ Test
372
- public void testEmptyStaticArrayInstantiateType () throws Exception {
374
+ public void testEmptyStaticArrayInstantiateType () {
373
375
assertThrows (
374
376
ClassNotFoundException .class ,
375
377
() -> TypeDecoder .instantiateType ("uint256[0]" , new long [] {}));
@@ -410,17 +412,18 @@ public void testDynamicArray() throws Exception {
410
412
new Utf8String ("Hello, world!" ),
411
413
new Utf8String ("world! Hello," ))));
412
414
413
- DynamicArray arr =
414
- ( DynamicArray )
415
- TypeDecoder . instantiateType (
416
- "string[]" , new String [] { "Hello, world!" , "world! Hello," } );
417
- assert ( arr instanceof DynamicArray );
415
+ Type arr =
416
+ TypeDecoder . instantiateType (
417
+ "string[]" , new String [] { "Hello, world!" , "world! Hello," });
418
+ assertTrue ( arr instanceof DynamicArray );
419
+ DynamicArray dynamicArray = ( DynamicArray ) arr ;
418
420
419
- assertEquals (arr .getValue ().get (0 ), (new Utf8String ("Hello, world!" )));
421
+ assertEquals (dynamicArray .getValue ().get (0 ), (new Utf8String ("Hello, world!" )));
420
422
421
- assertEquals (arr .getValue ().get (1 ), (new Utf8String ("world! Hello," )));
423
+ assertEquals (dynamicArray .getValue ().get (1 ), (new Utf8String ("world! Hello," )));
422
424
}
423
425
426
+ @ SuppressWarnings ("unchecked" )
424
427
@ Test
425
428
public void multiDimArrays () throws Exception {
426
429
byte [] bytes1d = new byte [] {1 , 2 , 3 };
@@ -429,20 +432,17 @@ public void multiDimArrays() throws Exception {
429
432
430
433
assertEquals (TypeDecoder .instantiateType ("bytes" , bytes1d ), (new DynamicBytes (bytes1d )));
431
434
432
- StaticArray3 <DynamicArray <Uint256 >> twoDim =
433
- (StaticArray3 <DynamicArray <Uint256 >>)
434
- TypeDecoder .instantiateType ("uint256[][3]" , bytes2d );
435
- assert (twoDim instanceof StaticArray3 );
436
- DynamicArray <Uint256 > row1 = twoDim .getValue ().get (1 );
437
- assert (row1 instanceof DynamicArray );
438
- assertEquals (row1 .getValue ().get (2 ), (new Uint256 (3 )));
439
-
440
- StaticArray3 <StaticArray3 <DynamicArray <Uint256 >>> threeDim =
441
- (StaticArray3 <StaticArray3 <DynamicArray <Uint256 >>>)
442
- TypeDecoder .instantiateType ("uint256[][3][3]" , bytes3d );
443
- assert (threeDim instanceof StaticArray3 );
444
- row1 = threeDim .getValue ().get (1 ).getValue ().get (1 );
445
- assert (row1 instanceof DynamicArray );
435
+ Type twoDim = TypeDecoder .instantiateType ("uint256[][3]" , bytes2d );
436
+ assertTrue (twoDim instanceof StaticArray3 );
437
+ StaticArray3 <DynamicArray <Uint256 >> staticArray3 =
438
+ (StaticArray3 <DynamicArray <Uint256 >>) twoDim ;
439
+ DynamicArray <Uint256 > row1 = staticArray3 .getValue ().get (1 );
440
+ assertEquals (row1 .getValue ().get (2 ), new Uint256 (3 ));
441
+ Type threeDim = TypeDecoder .instantiateType ("uint256[][3][3]" , bytes3d );
442
+ assertTrue (threeDim instanceof StaticArray3 );
443
+ StaticArray3 <StaticArray3 <DynamicArray <Uint256 >>> staticArray3StaticArray3 =
444
+ (StaticArray3 <StaticArray3 <DynamicArray <Uint256 >>>) threeDim ;
445
+ row1 = staticArray3StaticArray3 .getValue ().get (1 ).getValue ().get (1 );
446
446
assertEquals (row1 .getValue ().get (1 ), (new Uint256 (2 )));
447
447
}
448
448
}
0 commit comments