use of org.fisco.bcos.web3j.abi.datatypes.generated.Uint256 in project web3sdk by FISCO-BCOS.
the class FunctionReturnDecoderTest method testMixTypeDecode10.
@Test
public void testMixTypeDecode10() {
// function baz(uint32,bool)
Function function0 = new Function("baz", Collections.<Type>emptyList(), Arrays.asList(new TypeReference<Uint32>() {
}, new TypeReference<Bool>() {
}));
assertThat(FunctionReturnDecoder.decode("0000000000000000000000000000000000000000000000000000000000000045" + "0000000000000000000000000000000000000000000000000000000000000001", function0.getOutputParameters()), equalTo(Arrays.asList(new Uint32(69), new Bool(true))));
// function baz(uint32[2])
Function function1 = new Function("bar", Collections.<Type>emptyList(), Arrays.asList(new TypeReference<StaticArray2<Bytes3>>() {
}));
assertThat(FunctionReturnDecoder.decode("6162630000000000000000000000000000000000000000000000000000000000" + "6465660000000000000000000000000000000000000000000000000000000000", function1.getOutputParameters()), equalTo(Arrays.asList(new StaticArray2<Bytes3>(new Bytes3("abc".getBytes()), new Bytes3("def".getBytes())))));
// function sam(bytes,bool,uint[])
Function function2 = new Function("sam", Collections.<Type>emptyList(), Arrays.asList(new TypeReference<DynamicBytes>() {
}, new TypeReference<Bool>() {
}, new TypeReference<DynamicArray<Uint256>>() {
}));
assertThat(FunctionReturnDecoder.decode("0000000000000000000000000000000000000000000000000000000000000060" + "0000000000000000000000000000000000000000000000000000000000000001" + "00000000000000000000000000000000000000000000000000000000000000a0" + "0000000000000000000000000000000000000000000000000000000000000004" + "6461766500000000000000000000000000000000000000000000000000000000" + "0000000000000000000000000000000000000000000000000000000000000003" + "0000000000000000000000000000000000000000000000000000000000000001" + "0000000000000000000000000000000000000000000000000000000000000002" + "0000000000000000000000000000000000000000000000000000000000000003", function2.getOutputParameters()), equalTo(Arrays.asList(new DynamicBytes("dave".getBytes()), new Bool(true), new DynamicArray<Uint256>(new Uint256(1), new Uint256(2), new Uint256(3)))));
// function f(uint,uint32[],bytes10,bytes)
Function function3 = new Function("f", Collections.<Type>emptyList(), Arrays.asList(new TypeReference<Uint256>() {
}, new TypeReference<DynamicArray<Uint32>>() {
}, new TypeReference<Bytes10>() {
}, new TypeReference<DynamicBytes>() {
}));
assertThat(FunctionReturnDecoder.decode("0000000000000000000000000000000000000000000000000000000000000123" + "0000000000000000000000000000000000000000000000000000000000000080" + "3132333435363738393000000000000000000000000000000000000000000000" + "00000000000000000000000000000000000000000000000000000000000000e0" + "0000000000000000000000000000000000000000000000000000000000000002" + "0000000000000000000000000000000000000000000000000000000000000456" + "0000000000000000000000000000000000000000000000000000000000000789" + "000000000000000000000000000000000000000000000000000000000000000d" + "48656c6c6f2c20776f726c642100000000000000000000000000000000000000", function3.getOutputParameters()), equalTo(Arrays.asList(new Uint256(0x123), new DynamicArray<Uint32>(new Uint32(0x456), new Uint32(0x789)), new Bytes10("1234567890".getBytes()), new DynamicBytes("Hello, world!".getBytes()))));
// function g(uint[][],string[])
Function function4 = new Function("g", Collections.<Type>emptyList(), Arrays.asList(new TypeReference<DynamicArray<DynamicArray<Uint256>>>() {
}, new TypeReference<DynamicArray<Utf8String>>() {
}));
assertThat(FunctionReturnDecoder.decode("0000000000000000000000000000000000000000000000000000000000000040" + "0000000000000000000000000000000000000000000000000000000000000140" + "0000000000000000000000000000000000000000000000000000000000000002" + "0000000000000000000000000000000000000000000000000000000000000040" + "00000000000000000000000000000000000000000000000000000000000000a0" + "0000000000000000000000000000000000000000000000000000000000000002" + "0000000000000000000000000000000000000000000000000000000000000001" + "0000000000000000000000000000000000000000000000000000000000000002" + "0000000000000000000000000000000000000000000000000000000000000001" + "0000000000000000000000000000000000000000000000000000000000000003" + "0000000000000000000000000000000000000000000000000000000000000003" + "0000000000000000000000000000000000000000000000000000000000000060" + "00000000000000000000000000000000000000000000000000000000000000a0" + "00000000000000000000000000000000000000000000000000000000000000e0" + "0000000000000000000000000000000000000000000000000000000000000003" + "6f6e650000000000000000000000000000000000000000000000000000000000" + "0000000000000000000000000000000000000000000000000000000000000003" + "74776f0000000000000000000000000000000000000000000000000000000000" + "0000000000000000000000000000000000000000000000000000000000000005" + "7468726565000000000000000000000000000000000000000000000000000000", function4.getOutputParameters()), equalTo(Arrays.asList(new DynamicArray<DynamicArray<Uint256>>(new DynamicArray<Uint256>(new Uint256(1), new Uint256(2)), new DynamicArray<Uint256>(new Uint256(3))), new DynamicArray<Utf8String>(new Utf8String("one"), new Utf8String("two"), new Utf8String("three")))));
}
use of org.fisco.bcos.web3j.abi.datatypes.generated.Uint256 in project web3sdk by FISCO-BCOS.
the class FunctionReturnDecoderTest method testMixTypeDecode3.
@Test
public void testMixTypeDecode3() {
// function function(string,uint256,uint256[6],uint256[],bool,address) constant
// returns(string,uint256,uint256[6],uint256[],bool,address)
Function function = new Function("function", Collections.<Type>emptyList(), Arrays.asList(new TypeReference<Utf8String>() {
}, new TypeReference<Uint256>() {
}, new TypeReference<StaticArray6<Uint256>>() {
}, new TypeReference<DynamicArray<Uint256>>() {
}, new TypeReference<Bool>() {
}, new TypeReference<Address>() {
}));
assertThat(FunctionReturnDecoder.decode("00000000000000000000000000000000000000000000000000000000000001600000000000000000" + "00000000000000000000000000000000000000000000045700000000000000000000000000000000" + "00000000000000000000000000000001000000000000000000000000000000000000000000000000" + "00000000000000020000000000000000000000000000000000000000000000000000000000000003" + "00000000000000000000000000000000000000000000000000000000000000040000000000000000" + "00000000000000000000000000000000000000000000000500000000000000000000000000000000" + "00000000000000000000000000000006000000000000000000000000000000000000000000000000" + "00000000000001a00000000000000000000000000000000000000000000000000000000000000000" + "000000000000000000000000692a70d2e424a56d2c6c27aa97d1a86395877b3a0000000000000000" + "00000000000000000000000000000000000000000000000f6461736c666a616b6c666461736b6c00" + "00000000000000000000000000000000000000000000000000000000000000000000000000000000" + "00000000000000060000000000000000000000000000000000000000000000000000000000000001" + "00000000000000000000000000000000000000000000000000000000000000020000000000000000" + "00000000000000000000000000000000000000000000000300000000000000000000000000000000" + "00000000000000000000000000000004000000000000000000000000000000000000000000000000" + "00000000000000050000000000000000000000000000000000000000000000000000000000000006", function.getOutputParameters()), equalTo(Arrays.asList(new Utf8String("daslfjaklfdaskl"), new Uint256(1111), new StaticArray6<>(new Uint256(1), new Uint256(2), new Uint256(3), new Uint256(4), new Uint256(5), new Uint256(6)), new DynamicArray<>(new Uint256(1), new Uint256(2), new Uint256(3), new Uint256(4), new Uint256(5), new Uint256(6)), new Bool(false), new Address("0x692a70d2e424a56d2c6c27aa97d1a86395877b3a"))));
}
use of org.fisco.bcos.web3j.abi.datatypes.generated.Uint256 in project web3sdk by FISCO-BCOS.
the class FunctionReturnDecoderTest method testMixTypeDecode1.
@Test
public void testMixTypeDecode1() {
// function function() constant
// returns(uint256,uint256[],uint256,bytes10,string)
Function function = new Function("function", Collections.<Type>emptyList(), Arrays.asList(new TypeReference<Uint256>() {
}, new TypeReference<DynamicArray<Uint256>>() {
}, new TypeReference<Bytes10>() {
}, new TypeReference<Utf8String>() {
}));
assertThat(FunctionReturnDecoder.decode("0000000000000000000000000000000000000000000000000000000000000123" + "0000000000000000000000000000000000000000000000000000000000000080" + "3132333435363738393000000000000000000000000000000000000000000000" + "00000000000000000000000000000000000000000000000000000000000000e0" + "0000000000000000000000000000000000000000000000000000000000000002" + "0000000000000000000000000000000000000000000000000000000000000456" + "0000000000000000000000000000000000000000000000000000000000000789" + "000000000000000000000000000000000000000000000000000000000000000d" + "48656c6c6f2c20776f726c642100000000000000000000000000000000000000", function.getOutputParameters()), equalTo(Arrays.asList(new Uint256(291), new DynamicArray<Uint256>(new Uint256(1110), new Uint256(1929)), new Bytes10("1234567890".getBytes()), new Utf8String("Hello, world!"))));
}
use of org.fisco.bcos.web3j.abi.datatypes.generated.Uint256 in project web3sdk by FISCO-BCOS.
the class FunctionReturnDecoderTest method testDecodeIndexedUint256Value.
@Test
public void testDecodeIndexedUint256Value() {
Uint256 value = new Uint256(BigInteger.TEN);
String encoded = TypeEncoder.encodeNumeric(value);
assertThat(FunctionReturnDecoder.decodeIndexedValue(encoded, new TypeReference<Uint256>() {
}), equalTo(value));
}
use of org.fisco.bcos.web3j.abi.datatypes.generated.Uint256 in project web3sdk by FISCO-BCOS.
the class FunctionReturnDecoderTest method testDecodeIndexedDynamicArrayValue.
@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))));
}
Aggregations