SolidityType { public abstract Object decode(byte[] encoded, int offset); SolidityType(String name); String getName(); @JsonValue String getCanonicalName(); @JsonCreator static SolidityType getType(String typeName); abstract byte[] encode(Object value); abstract Object decode(byte[] encoded, int offset); Object decode(byte[] encoded); int getFixedSize(); boolean isDynamicType(); @Override String toString();  }
@Test public void ensureUnsignedInteger_isDecodedWithCorrectSignum() { byte[] bigNumberByteArray = { -13, -75, 19, 86, -119, 67, 112, -4, 118, -86, 98, -46, 103, -42, -126, 63, -60, -15, -87, 57, 43, 11, -17, -52, 0, 3, -65, 14, -67, -40, 65, 119 }; SolidityType testObject = new SolidityType.UnsignedIntType("uint256"); Object decode = testObject.decode(bigNumberByteArray); assertEquals(decode.getClass(), BigInteger.class); BigInteger actualBigInteger = (BigInteger) decode; BigInteger expectedBigInteger = new BigInteger(Hex.toHexString(bigNumberByteArray), 16); assertEquals(expectedBigInteger, actualBigInteger); }
@Test public void ensureSignedInteger_isDecoded() { byte[] bigNumberByteArray = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 127, -1, -1, -1, -1, -1, -1, -1 }; SolidityType testObject = new SolidityType.IntType("int256"); Object decode = testObject.decode(bigNumberByteArray); assertEquals(decode.getClass(), BigInteger.class); BigInteger actualBigInteger = (BigInteger) decode; BigInteger expectedBigInteger = new BigInteger(bigNumberByteArray); assertEquals(expectedBigInteger, actualBigInteger); }