FunctionReturnDecoder { @SuppressWarnings("unchecked") public static <T extends Type> Type decodeIndexedValue( String rawInput, TypeReference<T> typeReference) { String input = Numeric.cleanHexPrefix(rawInput); try { Class<T> type = typeReference.getClassType(); if (Bytes.class.isAssignableFrom(type)) { return TypeDecoder.decodeBytes(input, (Class<Bytes>) Class.forName(type.getName())); } else if (Array.class.isAssignableFrom(type) || BytesType.class.isAssignableFrom(type) || Utf8String.class.isAssignableFrom(type)) { return TypeDecoder.decodeBytes(input, Bytes32.class); } else { return TypeDecoder.decode(input, type); } } catch (ClassNotFoundException e) { throw new UnsupportedOperationException("Invalid class reference provided", e); } } private  FunctionReturnDecoder(); static List<Type> decode(
            String rawInput, List<TypeReference<Type>> outputParameters); @SuppressWarnings("unchecked") static Type decodeIndexedValue(
            String rawInput, TypeReference<T> typeReference);  }
@Test public void testDecodeIndexedUint256Value() { Uint256 value = new Uint256(BigInteger.TEN); String encoded = TypeEncoder.encodeNumeric(value); assertThat(FunctionReturnDecoder.decodeIndexedValue( encoded, new TypeReference<Uint256>() {}), IsEqual.<Type>equalTo(value)); }
@Test public void testDecodeIndexedStringValue() { Utf8String string = new Utf8String("some text"); String encoded = TypeEncoder.encodeString(string); String hash = Hash.sha3(encoded); assertThat(FunctionReturnDecoder.decodeIndexedValue( hash, new TypeReference<Utf8String>() {}), IsEqual.<Type>equalTo(new Bytes32(Numeric.hexStringToByteArray(hash)))); }
@Test public void testDecodeIndexedBytes32Value() { String rawInput = "0x1234567890123456789012345678901234567890123456789012345678901234"; byte[] rawInputBytes = Numeric.hexStringToByteArray(rawInput); assertThat(FunctionReturnDecoder.decodeIndexedValue( rawInput, new TypeReference<Bytes32>(){}), IsEqual.<Type>equalTo(new Bytes32(rawInputBytes))); }
@Test public void testDecodeIndexedBytes16Value() { String rawInput = "0x1234567890123456789012345678901200000000000000000000000000000000"; byte[] rawInputBytes = Numeric.hexStringToByteArray(rawInput.substring(0, 34)); assertThat(FunctionReturnDecoder.decodeIndexedValue( rawInput, new TypeReference<Bytes16>(){}), IsEqual.<Type>equalTo(new Bytes16(rawInputBytes))); }
@Test public void testDecodeIndexedDynamicBytesValue() { DynamicBytes bytes = new DynamicBytes(new byte[]{ 1, 2, 3, 4, 5}); String encoded = TypeEncoder.encodeDynamicBytes(bytes); String hash = Hash.sha3(encoded); assertThat(FunctionReturnDecoder.decodeIndexedValue( hash, new TypeReference<DynamicBytes>() {}), IsEqual.<Type>equalTo(new Bytes32(Numeric.hexStringToByteArray(hash)))); }
@Test public void testDecodeIndexedDynamicArrayValue() { DynamicArray<Uint256> array = new DynamicArray<Uint256>(new Uint256(BigInteger.TEN)); String encoded = TypeEncoder.encodeDynamicArray(array); String hash = Hash.sha3(encoded); assertThat(FunctionReturnDecoder.decodeIndexedValue( hash, new TypeReference<DynamicArray>() {}), IsEqual.<Type>equalTo(new Bytes32(Numeric.hexStringToByteArray(hash)))); }
@Test public void testDecodeIndexedUint256Value() { Uint256 value = new Uint256(BigInteger.TEN); String encoded = TypeEncoder.encodeNumeric(value); assertThat(FunctionReturnDecoder.decodeIndexedValue( encoded, new TypeReference<Uint256>() {}), equalTo(value)); }
@Test public void testDecodeIndexedStringValue() { Utf8String string = new Utf8String("some text"); String encoded = TypeEncoder.encodeString(string); String hash = Hash.sha3(encoded); assertThat(FunctionReturnDecoder.decodeIndexedValue( hash, new TypeReference<Utf8String>() {}), equalTo(new Bytes32(Numeric.hexStringToByteArray(hash)))); }
@Test public void testDecodeIndexedBytes32Value() { String rawInput = "0x1234567890123456789012345678901234567890123456789012345678901234"; byte[] rawInputBytes = Numeric.hexStringToByteArray(rawInput); assertThat(FunctionReturnDecoder.decodeIndexedValue( rawInput, new TypeReference<Bytes32>(){}), equalTo(new Bytes32(rawInputBytes))); }
@Test public void testDecodeIndexedBytes16Value() { String rawInput = "0x1234567890123456789012345678901200000000000000000000000000000000"; byte[] rawInputBytes = Numeric.hexStringToByteArray(rawInput.substring(0, 34)); assertThat(FunctionReturnDecoder.decodeIndexedValue( rawInput, new TypeReference<Bytes16>(){}), equalTo(new Bytes16(rawInputBytes))); }
@Test public void testDecodeIndexedDynamicBytesValue() { DynamicBytes bytes = new DynamicBytes(new byte[]{ 1, 2, 3, 4, 5}); String encoded = TypeEncoder.encodeDynamicBytes(bytes); String hash = Hash.sha3(encoded); assertThat(FunctionReturnDecoder.decodeIndexedValue( hash, new TypeReference<DynamicBytes>() {}), equalTo(new Bytes32(Numeric.hexStringToByteArray(hash)))); }
@Test public void testDecodeIndexedDynamicArrayValue() { DynamicArray<Uint256> array = new DynamicArray<>(new Uint256(BigInteger.TEN)); String encoded = TypeEncoder.encodeDynamicArray(array); String hash = Hash.sha3(encoded); assertThat(FunctionReturnDecoder.decodeIndexedValue( hash, new TypeReference<DynamicArray>() {}), equalTo(new Bytes32(Numeric.hexStringToByteArray(hash)))); }