use of org.fisco.bcos.web3j.abi.datatypes.generated.Bytes32 in project web3sdk by FISCO-BCOS.
the class TransactionDecoderTest method testSimpleParams0.
@Test
public void testSimpleParams0() throws JsonProcessingException, TransactionException, BaseException {
/*
function test(uint256 _u,int256 _i,bool _b,address _addr,bytes32 _bs32, string _s,bytes _bs) public constant returns (uint256,int256,bool,address,bytes32,string,bytes)
*/
TransactionDecoder decode = TransactionDecoderFactory.buildTransactionDecoder("[{\"constant\":true,\"inputs\":[{\"name\":\"_u\",\"type\":\"uint256[4]\"},{\"name\":\"_i\",\"type\":\"int256[4]\"},{\"name\":\"_b\",\"type\":\"bool[4]\"},{\"name\":\"_addr\",\"type\":\"address[4]\"},{\"name\":\"_bs32\",\"type\":\"bytes32[4]\"},{\"name\":\"_s\",\"type\":\"string[4]\"},{\"name\":\"_bs\",\"type\":\"bytes[4]\"}],\"name\":\"test\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256[2]\"},{\"name\":\"\",\"type\":\"int256[2]\"},{\"name\":\"\",\"type\":\"bool[2]\"},{\"name\":\"\",\"type\":\"address[2]\"},{\"name\":\"\",\"type\":\"bytes32[2]\"},{\"name\":\"\",\"type\":\"string[2]\"},{\"name\":\"\",\"type\":\"bytes[2]\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"_u\",\"type\":\"uint256\"},{\"name\":\"_i\",\"type\":\"int256\"},{\"name\":\"_b\",\"type\":\"bool\"},{\"name\":\"_addr\",\"type\":\"address\"},{\"name\":\"_bs32\",\"type\":\"bytes32\"},{\"name\":\"_s\",\"type\":\"string\"},{\"name\":\"_bs\",\"type\":\"bytes\"}],\"name\":\"test\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"},{\"name\":\"\",\"type\":\"int256\"},{\"name\":\"\",\"type\":\"bool\"},{\"name\":\"\",\"type\":\"address\"},{\"name\":\"\",\"type\":\"bytes32\"},{\"name\":\"\",\"type\":\"string\"},{\"name\":\"\",\"type\":\"bytes\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"_u\",\"type\":\"uint256[]\"},{\"name\":\"_i\",\"type\":\"int256[]\"},{\"name\":\"_b\",\"type\":\"bool[]\"},{\"name\":\"_addr\",\"type\":\"address[]\"},{\"name\":\"_bs32\",\"type\":\"bytes32[]\"},{\"name\":\"_s\",\"type\":\"string[]\"},{\"name\":\"_bs\",\"type\":\"bytes[]\"}],\"name\":\"test\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256[]\"},{\"name\":\"\",\"type\":\"int256[]\"},{\"name\":\"\",\"type\":\"bool[]\"},{\"name\":\"\",\"type\":\"address[]\"},{\"name\":\"\",\"type\":\"bytes32[]\"},{\"name\":\"\",\"type\":\"string[]\"},{\"name\":\"\",\"type\":\"bytes[]\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"name\":\"_u\",\"type\":\"uint256\"},{\"indexed\":false,\"name\":\"_i\",\"type\":\"int256\"},{\"indexed\":false,\"name\":\"_b\",\"type\":\"bool\"},{\"indexed\":false,\"name\":\"_addr\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"_bs32\",\"type\":\"bytes32\"},{\"indexed\":false,\"name\":\"_s\",\"type\":\"string\"},{\"indexed\":false,\"name\":\"_bs\",\"type\":\"bytes\"}],\"name\":\"TestEventSimpleParams\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"name\":\"_u\",\"type\":\"uint256[]\"},{\"indexed\":false,\"name\":\"_i\",\"type\":\"int256[]\"},{\"indexed\":false,\"name\":\"_b\",\"type\":\"bool[]\"},{\"indexed\":false,\"name\":\"_addr\",\"type\":\"address[]\"},{\"indexed\":false,\"name\":\"_bs32\",\"type\":\"bytes32[]\"},{\"indexed\":false,\"name\":\"_s\",\"type\":\"string[]\"},{\"indexed\":false,\"name\":\"_bs\",\"type\":\"bytes[]\"}],\"name\":\"TestEventDArrayParams\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"name\":\"_u\",\"type\":\"uint256[4]\"},{\"indexed\":false,\"name\":\"_i\",\"type\":\"int256[4]\"},{\"indexed\":false,\"name\":\"_b\",\"type\":\"bool[4]\"},{\"indexed\":false,\"name\":\"_addr\",\"type\":\"address[4]\"},{\"indexed\":false,\"name\":\"_bs32\",\"type\":\"bytes32[4]\"},{\"indexed\":false,\"name\":\"_s\",\"type\":\"string[4]\"},{\"indexed\":false,\"name\":\"_bs\",\"type\":\"bytes[4]\"}],\"name\":\"TestEventSArrayParams\",\"type\":\"event\"}]", "");
List<Type> test1Params = Arrays.asList(new Uint256(111111), new Int256(-1111111), new Bool(false), new Address("0x692a70d2e424a56d2c6c27aa97d1a86395877b3a"), new Bytes32("abcdefghiabcdefghiabcdefghiabhji".getBytes()), new Utf8String("章鱼小丸子ljjkl;adjsfkljlkjl"), new DynamicBytes("sadfljkjkljkl".getBytes()));
Function test1 = new Function("test", test1Params, Collections.<TypeReference<?>>emptyList());
String resultInputJson = decode.decodeInputReturnJson(FunctionEncoder.encode(test1));
InputAndOutputResult inputAndOutputResult = decode.decodeInputReturnObject(FunctionEncoder.encode(test1));
List<ResultEntity> resultInputList = inputAndOutputResult.getResult();
List<Type> resultInputListType = transEntitytoType(resultInputList);
assertThat(resultInputJson, is("{\"function\":\"test(uint256,int256,bool,address,bytes32,string,bytes)\",\"methodID\":\"0x58a12c20\",\"result\":[{\"name\":\"_u\",\"type\":\"uint256\",\"data\":111111},{\"name\":\"_i\",\"type\":\"int256\",\"data\":-1111111},{\"name\":\"_b\",\"type\":\"bool\",\"data\":false},{\"name\":\"_addr\",\"type\":\"address\",\"data\":\"0x692a70d2e424a56d2c6c27aa97d1a86395877b3a\"},{\"name\":\"_bs32\",\"type\":\"bytes32\",\"data\":\"abcdefghiabcdefghiabcdefghiabhji\"},{\"name\":\"_s\",\"type\":\"string\",\"data\":\"章鱼小丸子ljjkl;adjsfkljlkjl\"},{\"name\":\"_bs\",\"type\":\"bytes\",\"data\":\"sadfljkjkljkl\"}]}"));
assertThat(resultInputListType, is(test1Params));
String resultOutputJson = decode.decodeOutputReturnJson(FunctionEncoder.encode(test1), FunctionEncoder.encodeConstructor(test1Params));
InputAndOutputResult inputAndOutputResult2 = decode.decodeOutputReturnObject(FunctionEncoder.encode(test1), FunctionEncoder.encodeConstructor(test1Params));
List<ResultEntity> resultOutputList = inputAndOutputResult2.getResult();
List<Type> resultOutputListType = transEntitytoType(resultOutputList);
assertThat(resultOutputJson, is("{\"function\":\"test(uint256,int256,bool,address,bytes32,string,bytes)\",\"methodID\":\"0x58a12c20\",\"result\":[{\"name\":\"\",\"type\":\"uint256\",\"data\":111111},{\"name\":\"\",\"type\":\"int256\",\"data\":-1111111},{\"name\":\"\",\"type\":\"bool\",\"data\":false},{\"name\":\"\",\"type\":\"address\",\"data\":\"0x692a70d2e424a56d2c6c27aa97d1a86395877b3a\"},{\"name\":\"\",\"type\":\"bytes32\",\"data\":\"abcdefghiabcdefghiabcdefghiabhji\"},{\"name\":\"\",\"type\":\"string\",\"data\":\"章鱼小丸子ljjkl;adjsfkljlkjl\"},{\"name\":\"\",\"type\":\"bytes\",\"data\":\"sadfljkjkljkl\"}]}"));
assertThat(resultOutputListType, is(test1Params));
}
use of org.fisco.bcos.web3j.abi.datatypes.generated.Bytes32 in project web3sdk by FISCO-BCOS.
the class TransactionDecoderTest method testEventSimple.
/*
* event TestEventSimpleParams(uint256 _u,int256 _i,bool _b,address _addr,bytes32 _bs32, string _s,bytes _bs);
* event TestEventDArrayParams(uint256[] _u,int256[] _i,bool[] _b,address[] _addr,bytes32[] _bs32, string[] _s,bytes[] _bs);
* event TestEventSArrayParams(uint256[4] _u,int256[4] _i,bool[4] _b,address[4] _addr,bytes32[4] _bs32, string[4] _s,bytes[4] _bs);
*/
@Test
public void testEventSimple() throws BaseException, IOException {
/*
event TestEventSimpleParams(uint256 _u,int256 _i,bool _b,address _addr,bytes32 _bs32, string _s,bytes _bs);
*/
TransactionDecoder decode = TransactionDecoderFactory.buildTransactionDecoder("[{\"constant\":true,\"inputs\":[{\"name\":\"_u\",\"type\":\"uint256[4]\"},{\"name\":\"_i\",\"type\":\"int256[4]\"},{\"name\":\"_b\",\"type\":\"bool[4]\"},{\"name\":\"_addr\",\"type\":\"address[4]\"},{\"name\":\"_bs32\",\"type\":\"bytes32[4]\"},{\"name\":\"_s\",\"type\":\"string[4]\"},{\"name\":\"_bs\",\"type\":\"bytes[4]\"}],\"name\":\"test\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256[2]\"},{\"name\":\"\",\"type\":\"int256[2]\"},{\"name\":\"\",\"type\":\"bool[2]\"},{\"name\":\"\",\"type\":\"address[2]\"},{\"name\":\"\",\"type\":\"bytes32[2]\"},{\"name\":\"\",\"type\":\"string[2]\"},{\"name\":\"\",\"type\":\"bytes[2]\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"_u\",\"type\":\"uint256\"},{\"name\":\"_i\",\"type\":\"int256\"},{\"name\":\"_b\",\"type\":\"bool\"},{\"name\":\"_addr\",\"type\":\"address\"},{\"name\":\"_bs32\",\"type\":\"bytes32\"},{\"name\":\"_s\",\"type\":\"string\"},{\"name\":\"_bs\",\"type\":\"bytes\"}],\"name\":\"test\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"},{\"name\":\"\",\"type\":\"int256\"},{\"name\":\"\",\"type\":\"bool\"},{\"name\":\"\",\"type\":\"address\"},{\"name\":\"\",\"type\":\"bytes32\"},{\"name\":\"\",\"type\":\"string\"},{\"name\":\"\",\"type\":\"bytes\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"_u\",\"type\":\"uint256[]\"},{\"name\":\"_i\",\"type\":\"int256[]\"},{\"name\":\"_b\",\"type\":\"bool[]\"},{\"name\":\"_addr\",\"type\":\"address[]\"},{\"name\":\"_bs32\",\"type\":\"bytes32[]\"},{\"name\":\"_s\",\"type\":\"string[]\"},{\"name\":\"_bs\",\"type\":\"bytes[]\"}],\"name\":\"test\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256[]\"},{\"name\":\"\",\"type\":\"int256[]\"},{\"name\":\"\",\"type\":\"bool[]\"},{\"name\":\"\",\"type\":\"address[]\"},{\"name\":\"\",\"type\":\"bytes32[]\"},{\"name\":\"\",\"type\":\"string[]\"},{\"name\":\"\",\"type\":\"bytes[]\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"name\":\"_u\",\"type\":\"uint256\"},{\"indexed\":false,\"name\":\"_i\",\"type\":\"int256\"},{\"indexed\":false,\"name\":\"_b\",\"type\":\"bool\"},{\"indexed\":false,\"name\":\"_addr\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"_bs32\",\"type\":\"bytes32\"},{\"indexed\":false,\"name\":\"_s\",\"type\":\"string\"},{\"indexed\":false,\"name\":\"_bs\",\"type\":\"bytes\"}],\"name\":\"TestEventSimpleParams\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"name\":\"_u\",\"type\":\"uint256[]\"},{\"indexed\":false,\"name\":\"_i\",\"type\":\"int256[]\"},{\"indexed\":false,\"name\":\"_b\",\"type\":\"bool[]\"},{\"indexed\":false,\"name\":\"_addr\",\"type\":\"address[]\"},{\"indexed\":false,\"name\":\"_bs32\",\"type\":\"bytes32[]\"},{\"indexed\":false,\"name\":\"_s\",\"type\":\"string[]\"},{\"indexed\":false,\"name\":\"_bs\",\"type\":\"bytes[]\"}],\"name\":\"TestEventDArrayParams\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"name\":\"_u\",\"type\":\"uint256[4]\"},{\"indexed\":false,\"name\":\"_i\",\"type\":\"int256[4]\"},{\"indexed\":false,\"name\":\"_b\",\"type\":\"bool[4]\"},{\"indexed\":false,\"name\":\"_addr\",\"type\":\"address[4]\"},{\"indexed\":false,\"name\":\"_bs32\",\"type\":\"bytes32[4]\"},{\"indexed\":false,\"name\":\"_s\",\"type\":\"string[4]\"},{\"indexed\":false,\"name\":\"_bs\",\"type\":\"bytes[4]\"}],\"name\":\"TestEventSArrayParams\",\"type\":\"event\"}]", "");
List<TypeReference<?>> eventTypeList = Arrays.asList(new TypeReference<Uint256>() {
}, new TypeReference<Int256>() {
}, new TypeReference<Bool>() {
}, new TypeReference<Address>() {
}, new TypeReference<Bytes32>() {
}, new TypeReference<Utf8String>() {
}, new TypeReference<DynamicBytes>() {
});
Event event = new Event("TestEventSimpleParams", eventTypeList);
List<Type> eventDataParams1 = Arrays.asList(new Uint256(111111), new Int256(-1111111), new Bool(false), new Address("0x692a70d2e424a56d2c6c27aa97d1a86395877b3a"), new Bytes32("abcdefghiabcdefghiabcdefghiabhji".getBytes()), new Utf8String("章鱼小丸子ljjkl;adjsfkljlkjl"), new DynamicBytes("sadfljkjkljkl".getBytes()));
List<Type> eventDataParams2 = Arrays.asList(new Uint256(0), new Int256(0), new Bool(true), new Address("0x0"), new Bytes32(" ".getBytes()), new Utf8String(""), new DynamicBytes("".getBytes()));
List<Type> eventDataParams3 = Arrays.asList(new Uint256(654321), new Int256(123456), new Bool(false), new Address("0x692a70d2e424a56d2c6c27aa97d1a86395877b3a"), new Bytes32(" ".getBytes()), new Utf8String("jlkjlkjasdfjlkj fsadjkljlk j章鱼小丸子"), new DynamicBytes("jlkjlkjasdfjlkj fsadjkljlk j章鱼小丸子".getBytes()));
List<String> topics = new ArrayList<String>();
topics.add(EventEncoder.encode(event));
Log log1 = new Log();
log1.setData(FunctionEncoder.encodeConstructor(eventDataParams1));
log1.setTopics(topics);
Log log2 = new Log();
log2.setData(FunctionEncoder.encodeConstructor(eventDataParams2));
log2.setTopics(topics);
Log log3 = new Log();
log3.setData(FunctionEncoder.encodeConstructor(eventDataParams3));
log3.setTopics(topics);
AbiDefinition abiDefinition = null;
Tuple2<AbiDefinition, List<EventResultEntity>> tupleResult1 = decode.decodeEventReturnObject(log1);
assertThat(transEntitytoType0(tupleResult1.getValue2()), is(eventDataParams1));
abiDefinition = tupleResult1.getValue1();
Tuple2<AbiDefinition, List<EventResultEntity>> tupleResult2 = decode.decodeEventReturnObject(log2);
assertThat(transEntitytoType0(tupleResult2.getValue2()), is(eventDataParams2));
Tuple2<AbiDefinition, List<EventResultEntity>> tupleResult3 = decode.decodeEventReturnObject(log3);
assertThat(transEntitytoType0(tupleResult3.getValue2()), is(eventDataParams3));
List<Log> logList1 = new ArrayList<Log>();
logList1.add(log1);
Map<String, List<List<EventResultEntity>>> mapResult1 = decode.decodeEventReturnObject(logList1);
assertThat(transEntitytoType0(mapResult1.get(decodeMethodSign(abiDefinition)).get(0)), is(eventDataParams1));
assertThat(decode.decodeEventReturnJson(logList1), is("{\"TestEventSimpleParams(uint256,int256,bool,address,bytes32,string,bytes)\":[[{\"name\":\"_u\",\"type\":\"uint256\",\"data\":111111,\"indexed\":false},{\"name\":\"_i\",\"type\":\"int256\",\"data\":-1111111,\"indexed\":false},{\"name\":\"_b\",\"type\":\"bool\",\"data\":false,\"indexed\":false},{\"name\":\"_addr\",\"type\":\"address\",\"data\":\"0x692a70d2e424a56d2c6c27aa97d1a86395877b3a\",\"indexed\":false},{\"name\":\"_bs32\",\"type\":\"bytes32\",\"data\":\"abcdefghiabcdefghiabcdefghiabhji\",\"indexed\":false},{\"name\":\"_s\",\"type\":\"string\",\"data\":\"章鱼小丸子ljjkl;adjsfkljlkjl\",\"indexed\":false},{\"name\":\"_bs\",\"type\":\"bytes\",\"data\":\"sadfljkjkljkl\",\"indexed\":false}]]}"));
List<Log> logList2 = new ArrayList<Log>();
logList2.add(log1);
logList2.add(log2);
Map<String, List<List<EventResultEntity>>> mapResult2 = decode.decodeEventReturnObject(logList2);
assertThat(transEntitytoType0(mapResult2.get(decodeMethodSign(abiDefinition)).get(0)), is(eventDataParams1));
assertThat(transEntitytoType0(mapResult2.get(decodeMethodSign(abiDefinition)).get(1)), is(eventDataParams2));
assertThat(decode.decodeEventReturnJson(logList2), is("{\"TestEventSimpleParams(uint256,int256,bool,address,bytes32,string,bytes)\":[[{\"name\":\"_u\",\"type\":\"uint256\",\"data\":111111,\"indexed\":false},{\"name\":\"_i\",\"type\":\"int256\",\"data\":-1111111,\"indexed\":false},{\"name\":\"_b\",\"type\":\"bool\",\"data\":false,\"indexed\":false},{\"name\":\"_addr\",\"type\":\"address\",\"data\":\"0x692a70d2e424a56d2c6c27aa97d1a86395877b3a\",\"indexed\":false},{\"name\":\"_bs32\",\"type\":\"bytes32\",\"data\":\"abcdefghiabcdefghiabcdefghiabhji\",\"indexed\":false},{\"name\":\"_s\",\"type\":\"string\",\"data\":\"章鱼小丸子ljjkl;adjsfkljlkjl\",\"indexed\":false},{\"name\":\"_bs\",\"type\":\"bytes\",\"data\":\"sadfljkjkljkl\",\"indexed\":false}],[{\"name\":\"_u\",\"type\":\"uint256\",\"data\":0,\"indexed\":false},{\"name\":\"_i\",\"type\":\"int256\",\"data\":0,\"indexed\":false},{\"name\":\"_b\",\"type\":\"bool\",\"data\":true,\"indexed\":false},{\"name\":\"_addr\",\"type\":\"address\",\"data\":\"0x0000000000000000000000000000000000000000\",\"indexed\":false},{\"name\":\"_bs32\",\"type\":\"bytes32\",\"data\":\"\",\"indexed\":false},{\"name\":\"_s\",\"type\":\"string\",\"data\":\"\",\"indexed\":false},{\"name\":\"_bs\",\"type\":\"bytes\",\"data\":\"\",\"indexed\":false}]]}"));
List<Log> logList3 = new ArrayList<Log>();
logList3.add(log1);
logList3.add(log2);
logList3.add(log3);
Map<String, List<List<EventResultEntity>>> mapResult3 = decode.decodeEventReturnObject(logList3);
assertThat(transEntitytoType0(mapResult3.get(decodeMethodSign(abiDefinition)).get(0)), is(eventDataParams1));
assertThat(transEntitytoType0(mapResult3.get(decodeMethodSign(abiDefinition)).get(1)), is(eventDataParams2));
assertThat(transEntitytoType0(mapResult3.get(decodeMethodSign(abiDefinition)).get(2)), is(eventDataParams3));
assertThat(decode.decodeEventReturnJson(logList3), is("{\"TestEventSimpleParams(uint256,int256,bool,address,bytes32,string,bytes)\":[[{\"name\":\"_u\",\"type\":\"uint256\",\"data\":111111,\"indexed\":false},{\"name\":\"_i\",\"type\":\"int256\",\"data\":-1111111,\"indexed\":false},{\"name\":\"_b\",\"type\":\"bool\",\"data\":false,\"indexed\":false},{\"name\":\"_addr\",\"type\":\"address\",\"data\":\"0x692a70d2e424a56d2c6c27aa97d1a86395877b3a\",\"indexed\":false},{\"name\":\"_bs32\",\"type\":\"bytes32\",\"data\":\"abcdefghiabcdefghiabcdefghiabhji\",\"indexed\":false},{\"name\":\"_s\",\"type\":\"string\",\"data\":\"章鱼小丸子ljjkl;adjsfkljlkjl\",\"indexed\":false},{\"name\":\"_bs\",\"type\":\"bytes\",\"data\":\"sadfljkjkljkl\",\"indexed\":false}],[{\"name\":\"_u\",\"type\":\"uint256\",\"data\":0,\"indexed\":false},{\"name\":\"_i\",\"type\":\"int256\",\"data\":0,\"indexed\":false},{\"name\":\"_b\",\"type\":\"bool\",\"data\":true,\"indexed\":false},{\"name\":\"_addr\",\"type\":\"address\",\"data\":\"0x0000000000000000000000000000000000000000\",\"indexed\":false},{\"name\":\"_bs32\",\"type\":\"bytes32\",\"data\":\"\",\"indexed\":false},{\"name\":\"_s\",\"type\":\"string\",\"data\":\"\",\"indexed\":false},{\"name\":\"_bs\",\"type\":\"bytes\",\"data\":\"\",\"indexed\":false}],[{\"name\":\"_u\",\"type\":\"uint256\",\"data\":654321,\"indexed\":false},{\"name\":\"_i\",\"type\":\"int256\",\"data\":123456,\"indexed\":false},{\"name\":\"_b\",\"type\":\"bool\",\"data\":false,\"indexed\":false},{\"name\":\"_addr\",\"type\":\"address\",\"data\":\"0x692a70d2e424a56d2c6c27aa97d1a86395877b3a\",\"indexed\":false},{\"name\":\"_bs32\",\"type\":\"bytes32\",\"data\":\"\",\"indexed\":false},{\"name\":\"_s\",\"type\":\"string\",\"data\":\"jlkjlkjasdfjlkj fsadjkljlk j章鱼小丸子\",\"indexed\":false},{\"name\":\"_bs\",\"type\":\"bytes\",\"data\":\"jlkjlkjasdfjlkj fsadjkljlk j章鱼小丸子\",\"indexed\":false}]]}"));
}
use of org.fisco.bcos.web3j.abi.datatypes.generated.Bytes32 in project web3sdk by FISCO-BCOS.
the class UtilsTest method encodeGetLengthTest.
@Test
public void encodeGetLengthTest() {
// uint256
assertThat(Utils.getLength(Arrays.asList(new Uint256(1))), is(1));
// int256
assertThat(Utils.getLength(Arrays.asList(new Int256(1))), is(1));
// bool
assertThat(Utils.getLength(Arrays.asList(new Bool(true))), is(1));
// address
assertThat(Utils.getLength(Arrays.asList(new Address("0xb87213121fb89cbd8b877cb1bb3ff84dd2869cfa"))), is(1));
// bytes2
assertThat(Utils.getLength(Arrays.asList(new Bytes2("ab".getBytes()))), is(1));
// bytes32
assertThat(Utils.getLength(Arrays.asList(new Bytes32("b87213121fb89cbd8b877cb1bb3ff84d".getBytes()))), is(1));
// bytes
assertThat(Utils.getLength(Arrays.asList(new DynamicBytes("b87213121fb89cbd8b877cb1bb3ff84d".getBytes()))), is(1));
// string
assertThat(Utils.getLength(Arrays.asList(new Utf8String("b87213121fb89cbd8b877cb1bb3ff84d"))), is(1));
// uint256[4]
assertThat(Utils.getLength(Arrays.asList(new StaticArray4<Uint256>(new Uint256(1), new Uint256(1), new Uint256(1), new Uint256(1)))), is(4));
// uint256[5]
assertThat(Utils.getLength(Arrays.asList(new StaticArray5<Uint256>(new Uint256(1), new Uint256(1), new Uint256(1), new Uint256(1), new Uint256(1)))), is(5));
// uint256[]
assertThat(Utils.getLength(Arrays.asList(new DynamicArray<Uint256>(new Uint256(1), new Uint256(1), new Uint256(1), new Uint256(1), new Uint256(1)))), is(1));
// uint256[][2]
assertThat(Utils.getLength(Arrays.asList(new StaticArray2<DynamicArray>(new DynamicArray<Uint256>(new Uint256(1), new Uint256(1), new Uint256(1), new Uint256(1), new Uint256(1)), new DynamicArray<Uint256>(new Uint256(1), new Uint256(1), new Uint256(1), new Uint256(1), new Uint256(1))))), is(1));
// uint256[2][]
assertThat(Utils.getLength(Arrays.asList(new DynamicArray<StaticArray2>(new StaticArray2<Uint256>(new Uint256(1), new Uint256(1)), new StaticArray2<Uint256>(new Uint256(1), new Uint256(1))))), is(1));
// uint256[][]
assertThat(Utils.getLength(Arrays.asList(new DynamicArray<DynamicArray>(new DynamicArray<Uint256>(new Uint256(1), new Uint256(1)), new DynamicArray<Uint256>(new Uint256(1), new Uint256(1))))), is(1));
// uint256[2][2]
assertThat(Utils.getLength(Arrays.asList(new StaticArray2<StaticArray2>(new StaticArray2<Uint256>(new Uint256(1), new Uint256(1)), new StaticArray2<Uint256>(new Uint256(1), new Uint256(1))))), is(4));
// int256[4]
assertThat(Utils.getLength(Arrays.asList(new StaticArray4<Int256>(new Int256(1), new Int256(1), new Int256(1), new Int256(1)))), is(4));
// int256[5]
assertThat(Utils.getLength(Arrays.asList(new StaticArray5<Int256>(new Int256(1), new Int256(1), new Int256(1), new Int256(1), new Int256(1)))), is(5));
// int256[]
assertThat(Utils.getLength(Arrays.asList(new DynamicArray<Int256>(new Int256(1), new Int256(1), new Int256(1), new Int256(1), new Int256(1)))), is(1));
// int256[][2]
assertThat(Utils.getLength(Arrays.asList(new StaticArray2<DynamicArray>(new DynamicArray<Int256>(new Int256(1), new Int256(1), new Int256(1), new Int256(1), new Int256(1)), new DynamicArray<Int256>(new Int256(1), new Int256(1), new Int256(1), new Int256(1), new Int256(1))))), is(1));
// int256[][]
assertThat(Utils.getLength(Arrays.asList(new DynamicArray<DynamicArray>(new DynamicArray<Int256>(new Int256(1), new Int256(1), new Int256(1), new Int256(1), new Int256(1)), new DynamicArray<Int256>(new Int256(1), new Int256(1), new Int256(1), new Int256(1), new Int256(1))))), is(1));
// int256[2][]
assertThat(Utils.getLength(Arrays.asList(new DynamicArray<StaticArray2>(new StaticArray2<Int256>(new Int256(1), new Int256(1)), new StaticArray2<Int256>(new Int256(1), new Int256(1))))), is(1));
// int256[2][2]
assertThat(Utils.getLength(Arrays.asList(new StaticArray2<StaticArray2>(new StaticArray2<Int256>(new Int256(1), new Int256(1)), new StaticArray2<Int256>(new Int256(1), new Int256(1))))), is(4));
// bool[4]
assertThat(Utils.getLength(Arrays.asList(new StaticArray4<Bool>(new Bool(true), new Bool(true), new Bool(true), new Bool(true)))), is(4));
// bool[10]
assertThat(Utils.getLength(Arrays.asList(new StaticArray10<Bool>(new Bool(true), new Bool(true), new Bool(true), new Bool(true), new Bool(true), new Bool(true), new Bool(true), new Bool(true), new Bool(true), new Bool(true)))), is(10));
// bool[]
assertThat(Utils.getLength(Arrays.asList(new DynamicArray<Bool>(new Bool(true), new Bool(true), new Bool(true), new Bool(true), new Bool(true), new Bool(true), new Bool(true), new Bool(true), new Bool(true), new Bool(true)))), is(1));
// bool[][2]
assertThat(Utils.getLength(Arrays.asList(new StaticArray2<DynamicArray>(new DynamicArray<Bool>(new Bool(true), new Bool(true), new Bool(true), new Bool(true), new Bool(true)), new DynamicArray<Bool>(new Bool(true), new Bool(true), new Bool(true), new Bool(true), new Bool(true))))), is(1));
// bool[2][]
assertThat(Utils.getLength(Arrays.asList(new DynamicArray<StaticArray2>(new StaticArray2<Bool>(new Bool(true), new Bool(true)), new StaticArray2<Bool>(new Bool(true), new Bool(true))))), is(1));
// bool[][]
assertThat(Utils.getLength(Arrays.asList(new DynamicArray<DynamicArray>(new DynamicArray<Bool>(new Bool(true), new Bool(true)), new DynamicArray<Bool>(new Bool(true), new Bool(true))))), is(1));
// bool[2][2]
assertThat(Utils.getLength(Arrays.asList(new StaticArray2<StaticArray2>(new StaticArray2<Bool>(new Bool(true), new Bool(true)), new StaticArray2<Bool>(new Bool(true), new Bool(true))))), is(4));
// bool[2][2][2]
assertThat(Utils.getLength(Arrays.asList(new StaticArray2<StaticArray2<StaticArray2>>(new StaticArray2<StaticArray2>(new StaticArray2<Bool>(new Bool(true), new Bool(true)), new StaticArray2<Bool>(new Bool(true), new Bool(true))), new StaticArray2<StaticArray2>(new StaticArray2<Bool>(new Bool(true), new Bool(true)), new StaticArray2<Bool>(new Bool(true), new Bool(true)))))), is(8));
// address[4]
assertThat(Utils.getLength(Arrays.asList(new StaticArray4<Address>(new Address("0xb87213121fb89cbd8b877cb1bb3ff84dd2869cfa"), new Address("0xb87213121fb89cbd8b877cb1bb3ff84dd2869cfa"), new Address("0xb87213121fb89cbd8b877cb1bb3ff84dd2869cfa"), new Address("0xb87213121fb89cbd8b877cb1bb3ff84dd2869cfa")))), is(4));
// address[5]
assertThat(Utils.getLength(Arrays.asList(new StaticArray5<Address>(new Address("0xb87213121fb89cbd8b877cb1bb3ff84dd2869cfa"), new Address("0xb87213121fb89cbd8b877cb1bb3ff84dd2869cfa"), new Address("0xb87213121fb89cbd8b877cb1bb3ff84dd2869cfa"), new Address("0xb87213121fb89cbd8b877cb1bb3ff84dd2869cfa"), new Address("0xb87213121fb89cbd8b877cb1bb3ff84dd2869cfa")))), is(5));
// address[]
assertThat(Utils.getLength(Arrays.asList(new DynamicArray<Address>(new Address("0xb87213121fb89cbd8b877cb1bb3ff84dd2869cfa"), new Address("0xb87213121fb89cbd8b877cb1bb3ff84dd2869cfa"), new Address("0xb87213121fb89cbd8b877cb1bb3ff84dd2869cfa"), new Address("0xb87213121fb89cbd8b877cb1bb3ff84dd2869cfa"), new Address("0xb87213121fb89cbd8b877cb1bb3ff84dd2869cfa")))), is(1));
// address[][2]
assertThat(Utils.getLength(Arrays.asList(new StaticArray2<DynamicArray>(new DynamicArray<Address>(new Address("0xb87213121fb89cbd8b877cb1bb3ff84dd2869cfa"), new Address("0xb87213121fb89cbd8b877cb1bb3ff84dd2869cfa"), new Address("0xb87213121fb89cbd8b877cb1bb3ff84dd2869cfa"), new Address("0xb87213121fb89cbd8b877cb1bb3ff84dd2869cfa"), new Address("0xb87213121fb89cbd8b877cb1bb3ff84dd2869cfa")), new DynamicArray<Address>(new Address("0xb87213121fb89cbd8b877cb1bb3ff84dd2869cfa"), new Address("0xb87213121fb89cbd8b877cb1bb3ff84dd2869cfa"), new Address("0xb87213121fb89cbd8b877cb1bb3ff84dd2869cfa"), new Address("0xb87213121fb89cbd8b877cb1bb3ff84dd2869cfa"), new Address("0xb87213121fb89cbd8b877cb1bb3ff84dd2869cfa"))))), is(1));
// address[2][]
assertThat(Utils.getLength(Arrays.asList(new DynamicArray<StaticArray2>(new StaticArray2<Address>(new Address("0xb87213121fb89cbd8b877cb1bb3ff84dd2869cfa"), new Address("0xb87213121fb89cbd8b877cb1bb3ff84dd2869cfa")), new StaticArray2<Address>(new Address("0xb87213121fb89cbd8b877cb1bb3ff84dd2869cfa"), new Address("0xb87213121fb89cbd8b877cb1bb3ff84dd2869cfa"))))), is(1));
// address[][]
assertThat(Utils.getLength(Arrays.asList(new DynamicArray<DynamicArray>(new DynamicArray<Address>(new Address("0xb87213121fb89cbd8b877cb1bb3ff84dd2869cfa"), new Address("0xb87213121fb89cbd8b877cb1bb3ff84dd2869cfa")), new DynamicArray<Address>(new Address("0xb87213121fb89cbd8b877cb1bb3ff84dd2869cfa"), new Address("0xb87213121fb89cbd8b877cb1bb3ff84dd2869cfa"))))), is(1));
// address[3][3]
assertThat(Utils.getLength(Arrays.asList(new StaticArray3<StaticArray3>(new StaticArray3<Address>(new Address("0xb87213121fb89cbd8b877cb1bb3ff84dd2869cfa"), new Address("0xb87213121fb89cbd8b877cb1bb3ff84dd2869cfa"), new Address("0xb87213121fb89cbd8b877cb1bb3ff84dd2869cfa")), new StaticArray3<Address>(new Address("0xb87213121fb89cbd8b877cb1bb3ff84dd2869cfa"), new Address("0xb87213121fb89cbd8b877cb1bb3ff84dd2869cfa"), new Address("0xb87213121fb89cbd8b877cb1bb3ff84dd2869cfa")), new StaticArray3<Address>(new Address("0xb87213121fb89cbd8b877cb1bb3ff84dd2869cfa"), new Address("0xb87213121fb89cbd8b877cb1bb3ff84dd2869cfa"), new Address("0xb87213121fb89cbd8b877cb1bb3ff84dd2869cfa"))))), is(9));
// bytes32[6]
assertThat(Utils.getLength(Arrays.asList(new StaticArray6<Bytes32>(new Bytes32("b87213121fb89cbd8b877cb1bb3ff84d".getBytes()), new Bytes32("b87213121fb89cbd8b877cb1bb3ff84d".getBytes()), new Bytes32("b87213121fb89cbd8b877cb1bb3ff84d".getBytes()), new Bytes32("b87213121fb89cbd8b877cb1bb3ff84d".getBytes()), new Bytes32("b87213121fb89cbd8b877cb1bb3ff84d".getBytes()), new Bytes32("b87213121fb89cbd8b877cb1bb3ff84d".getBytes())))), is(6));
// bytes32[]
assertThat(Utils.getLength(Arrays.asList(new DynamicArray<Bytes32>(new Bytes32("b87213121fb89cbd8b877cb1bb3ff84d".getBytes()), new Bytes32("b87213121fb89cbd8b877cb1bb3ff84d".getBytes()), new Bytes32("b87213121fb89cbd8b877cb1bb3ff84d".getBytes()), new Bytes32("b87213121fb89cbd8b877cb1bb3ff84d".getBytes()), new Bytes32("b87213121fb89cbd8b877cb1bb3ff84d".getBytes()), new Bytes32("b87213121fb89cbd8b877cb1bb3ff84d".getBytes())))), is(1));
// bytes32[][2]
assertThat(Utils.getLength(Arrays.asList(new StaticArray2<DynamicArray>(new DynamicArray<Bytes32>(new Bytes32("b87213121fb89cbd8b877cb1bb3ff84d".getBytes()), new Bytes32("b87213121fb89cbd8b877cb1bb3ff84d".getBytes()), new Bytes32("b87213121fb89cbd8b877cb1bb3ff84d".getBytes()), new Bytes32("b87213121fb89cbd8b877cb1bb3ff84d".getBytes()), new Bytes32("b87213121fb89cbd8b877cb1bb3ff84d".getBytes())), new DynamicArray<Bytes32>(new Bytes32("b87213121fb89cbd8b877cb1bb3ff84d".getBytes()), new Bytes32("b87213121fb89cbd8b877cb1bb3ff84d".getBytes()), new Bytes32("b87213121fb89cbd8b877cb1bb3ff84d".getBytes()), new Bytes32("b87213121fb89cbd8b877cb1bb3ff84d".getBytes()), new Bytes32("b87213121fb89cbd8b877cb1bb3ff84d".getBytes()))))), is(1));
// bytes32[2][]
assertThat(Utils.getLength(Arrays.asList(new DynamicArray<StaticArray2>(new StaticArray2<Bytes32>(new Bytes32("b87213121fb89cbd8b877cb1bb3ff84d".getBytes()), new Bytes32("b87213121fb89cbd8b877cb1bb3ff84d".getBytes())), new StaticArray2<Bytes32>(new Bytes32("b87213121fb89cbd8b877cb1bb3ff84d".getBytes()), new Bytes32("b87213121fb89cbd8b877cb1bb3ff84d".getBytes()))))), is(1));
// bytes32[][]
assertThat(Utils.getLength(Arrays.asList(new DynamicArray<DynamicArray>(new DynamicArray<Bytes32>(new Bytes32("b87213121fb89cbd8b877cb1bb3ff84d".getBytes()), new Bytes32("b87213121fb89cbd8b877cb1bb3ff84d".getBytes())), new DynamicArray<Bytes32>(new Bytes32("b87213121fb89cbd8b877cb1bb3ff84d".getBytes()), new Bytes32("b87213121fb89cbd8b877cb1bb3ff84d".getBytes()))))), is(1));
// bytes32[3][3]
assertThat(Utils.getLength(Arrays.asList(new StaticArray3<StaticArray3>(new StaticArray3<Bytes32>(new Bytes32("b87213121fb89cbd8b877cb1bb3ff84d".getBytes()), new Bytes32("b87213121fb89cbd8b877cb1bb3ff84d".getBytes()), new Bytes32("b87213121fb89cbd8b877cb1bb3ff84d".getBytes())), new StaticArray3<Bytes32>(new Bytes32("b87213121fb89cbd8b877cb1bb3ff84d".getBytes()), new Bytes32("b87213121fb89cbd8b877cb1bb3ff84d".getBytes()), new Bytes32("b87213121fb89cbd8b877cb1bb3ff84d".getBytes())), new StaticArray3<Bytes32>(new Bytes32("b87213121fb89cbd8b877cb1bb3ff84d".getBytes()), new Bytes32("b87213121fb89cbd8b877cb1bb3ff84d".getBytes()), new Bytes32("b87213121fb89cbd8b877cb1bb3ff84d".getBytes()))))), is(9));
// string[2]
assertThat(Utils.getLength(Arrays.asList(new StaticArray2<Utf8String>(new Utf8String("b87213121fb89cbd8b877cb1bb3ff84d"), new Utf8String("b87213121fb89cbd8b877cb1bb3ff84d")))), is(1));
// string[4]
assertThat(Utils.getLength(Arrays.asList(new StaticArray4<Utf8String>(new Utf8String("b87213121fb89cbd8b877cb1bb3ff84d"), new Utf8String("b87213121fb89cbd8b877cb1bb3ff84d"), new Utf8String("b87213121fb89cbd8b877cb1bb3ff84d"), new Utf8String("b87213121fb89cbd8b877cb1bb3ff84d")))), is(1));
// string[]
assertThat(Utils.getLength(Arrays.asList(new DynamicArray<Utf8String>(new Utf8String("b87213121fb89cbd8b877cb1bb3ff84d"), new Utf8String("b87213121fb89cbd8b877cb1bb3ff84d"), new Utf8String("b87213121fb89cbd8b877cb1bb3ff84d"), new Utf8String("b87213121fb89cbd8b877cb1bb3ff84d")))), is(1));
// string[][2]
assertThat(Utils.getLength(Arrays.asList(new StaticArray2<DynamicArray>(new DynamicArray<Utf8String>(new Utf8String("b87213121fb89cbd8b877cb1bb3ff84d"), new Utf8String("b87213121fb89cbd8b877cb1bb3ff84d"), new Utf8String("b87213121fb89cbd8b877cb1bb3ff84d"), new Utf8String("b87213121fb89cbd8b877cb1bb3ff84d"), new Utf8String("b87213121fb89cbd8b877cb1bb3ff84d")), new DynamicArray<Utf8String>(new Utf8String("b87213121fb89cbd8b877cb1bb3ff84d"), new Utf8String("b87213121fb89cbd8b877cb1bb3ff84d"), new Utf8String("b87213121fb89cbd8b877cb1bb3ff84d"), new Utf8String("b87213121fb89cbd8b877cb1bb3ff84d"), new Utf8String("b87213121fb89cbd8b877cb1bb3ff84d"))))), is(1));
// string[2][]
assertThat(Utils.getLength(Arrays.asList(new DynamicArray<StaticArray2>(new StaticArray2<Utf8String>(new Utf8String("b87213121fb89cbd8b877cb1bb3ff84d"), new Utf8String("b87213121fb89cbd8b877cb1bb3ff84d")), new StaticArray2<Utf8String>(new Utf8String("b87213121fb89cbd8b877cb1bb3ff84d"), new Utf8String("b87213121fb89cbd8b877cb1bb3ff84d"))))), is(1));
// string[][]
assertThat(Utils.getLength(Arrays.asList(new DynamicArray<DynamicArray>(new DynamicArray<Utf8String>(new Utf8String("b87213121fb89cbd8b877cb1bb3ff84d"), new Utf8String("b87213121fb89cbd8b877cb1bb3ff84d")), new DynamicArray<Utf8String>(new Utf8String("b87213121fb89cbd8b877cb1bb3ff84d"), new Utf8String("b87213121fb89cbd8b877cb1bb3ff84d"))))), is(1));
// string[3][3]
assertThat(Utils.getLength(Arrays.asList(new StaticArray3<StaticArray3>(new StaticArray3<Utf8String>(new Utf8String("b87213121fb89cbd8b877cb1bb3ff84d"), new Utf8String("b87213121fb89cbd8b877cb1bb3ff84d"), new Utf8String("b87213121fb89cbd8b877cb1bb3ff84d")), new StaticArray3<Utf8String>(new Utf8String("b87213121fb89cbd8b877cb1bb3ff84d"), new Utf8String("b87213121fb89cbd8b877cb1bb3ff84d"), new Utf8String("b87213121fb89cbd8b877cb1bb3ff84d")), new StaticArray3<Utf8String>(new Utf8String("b87213121fb89cbd8b877cb1bb3ff84d"), new Utf8String("b87213121fb89cbd8b877cb1bb3ff84d"), new Utf8String("b87213121fb89cbd8b877cb1bb3ff84d"))))), is(1));
// bytes[2]
assertThat(Utils.getLength(Arrays.asList(new StaticArray2<DynamicBytes>(new DynamicBytes("b87213121fb89cbd8b877cb1bb3ff84d".getBytes()), new DynamicBytes("b87213121fb89cbd8b877cb1bb3ff84d".getBytes())))), is(1));
// bytes[3]
assertThat(Utils.getLength(Arrays.asList(new StaticArray3<DynamicBytes>(new DynamicBytes("b87213121fb89cbd8b877cb1bb3ff84d".getBytes()), new DynamicBytes("b87213121fb89cbd8b877cb1bb3ff84d".getBytes()), new DynamicBytes("b87213121fb89cbd8b877cb1bb3ff84d".getBytes())))), is(1));
// bytes[]
assertThat(Utils.getLength(Arrays.asList(new DynamicArray<DynamicBytes>(new DynamicBytes("b87213121fb89cbd8b877cb1bb3ff84d".getBytes()), new DynamicBytes("b87213121fb89cbd8b877cb1bb3ff84d".getBytes()), new DynamicBytes("b87213121fb89cbd8b877cb1bb3ff84d".getBytes())))), is(1));
// bytes[][2]
assertThat(Utils.getLength(Arrays.asList(new StaticArray2<DynamicArray>(new DynamicArray<DynamicBytes>(new DynamicBytes("b87213121fb89cbd8b877cb1bb3ff84d".getBytes()), new DynamicBytes("b87213121fb89cbd8b877cb1bb3ff84d".getBytes()), new DynamicBytes("b87213121fb89cbd8b877cb1bb3ff84d".getBytes()), new DynamicBytes("b87213121fb89cbd8b877cb1bb3ff84d".getBytes()), new DynamicBytes("b87213121fb89cbd8b877cb1bb3ff84d".getBytes())), new DynamicArray<DynamicBytes>(new DynamicBytes("b87213121fb89cbd8b877cb1bb3ff84d".getBytes()), new DynamicBytes("b87213121fb89cbd8b877cb1bb3ff84d".getBytes()), new DynamicBytes("b87213121fb89cbd8b877cb1bb3ff84d".getBytes()), new DynamicBytes("b87213121fb89cbd8b877cb1bb3ff84d".getBytes()), new DynamicBytes("b87213121fb89cbd8b877cb1bb3ff84d".getBytes()))))), is(1));
// bytes[2][]
assertThat(Utils.getLength(Arrays.asList(new DynamicArray<StaticArray2>(new StaticArray2<DynamicBytes>(new DynamicBytes("b87213121fb89cbd8b877cb1bb3ff84d".getBytes()), new DynamicBytes("b87213121fb89cbd8b877cb1bb3ff84d".getBytes())), new StaticArray2<DynamicBytes>(new DynamicBytes("b87213121fb89cbd8b877cb1bb3ff84d".getBytes()), new DynamicBytes("b87213121fb89cbd8b877cb1bb3ff84d".getBytes()))))), is(1));
// bytes[][]
assertThat(Utils.getLength(Arrays.asList(new DynamicArray<DynamicArray>(new DynamicArray<DynamicBytes>(new DynamicBytes("b87213121fb89cbd8b877cb1bb3ff84d".getBytes()), new DynamicBytes("b87213121fb89cbd8b877cb1bb3ff84d".getBytes())), new DynamicArray<DynamicBytes>(new DynamicBytes("b87213121fb89cbd8b877cb1bb3ff84d".getBytes()), new DynamicBytes("b87213121fb89cbd8b877cb1bb3ff84d".getBytes()))))), is(1));
// bytes[3][3]
assertThat(Utils.getLength(Arrays.asList(new StaticArray3<StaticArray3>(new StaticArray3<DynamicBytes>(new DynamicBytes("b87213121fb89cbd8b877cb1bb3ff84d".getBytes()), new DynamicBytes("b87213121fb89cbd8b877cb1bb3ff84d".getBytes()), new DynamicBytes("b87213121fb89cbd8b877cb1bb3ff84d".getBytes())), new StaticArray3<DynamicBytes>(new DynamicBytes("b87213121fb89cbd8b877cb1bb3ff84d".getBytes()), new DynamicBytes("b87213121fb89cbd8b877cb1bb3ff84d".getBytes()), new DynamicBytes("b87213121fb89cbd8b877cb1bb3ff84d".getBytes())), new StaticArray3<DynamicBytes>(new DynamicBytes("b87213121fb89cbd8b877cb1bb3ff84d".getBytes()), new DynamicBytes("b87213121fb89cbd8b877cb1bb3ff84d".getBytes()), new DynamicBytes("b87213121fb89cbd8b877cb1bb3ff84d".getBytes()))))), is(1));
// int256
assertThat(Utils.getLength(Arrays.asList(new Int256(1))), is(1));
// uint256
assertThat(Utils.getLength(Arrays.asList(new Uint256(1))), is(1));
// int
assertThat(Utils.getLength(Arrays.asList(new Int(new BigInteger("1")))), is(1));
// uint
assertThat(Utils.getLength(Arrays.asList(new Uint(new BigInteger("1")))), is(1));
// address
assertThat(Utils.getLength(Arrays.asList(new Address("0xb87213121fb89cbd8b877cb1bb3ff84dd2869cfa"))), is(1));
// int,uint,bool,address,bytes32,bytes,string
assertThat(Utils.getLength(Arrays.asList(new Int256(1), new Uint256(1), new Bool(true), new Address("0xb87213121fb89cbd8b877cb1bb3ff84dd2869cfa"), new Bytes32("b87213121fb89cbd8b877cb1bb3ff84d".getBytes()), new DynamicBytes("aa".getBytes()), new Utf8String("bb"))), is(7));
// int[3],uint[3],bool[3],address[3],bytes32[3],bytes[3],string[3]
assertThat(Utils.getLength(Arrays.asList(new StaticArray3<Int256>(new Int256(1), new Int256(1), new Int256(1)), new StaticArray3<Uint256>(new Uint256(1), new Uint256(1), new Uint256(1)), new StaticArray3<Bool>(new Bool(true), new Bool(false), new Bool(true)), new StaticArray3<Address>(new Address("0xb87213121fb89cbd8b877cb1bb3ff84dd2869cfa"), new Address("0xb87213121fb89cbd8b877cb1bb3ff84dd2869cfa"), new Address("0xb87213121fb89cbd8b877cb1bb3ff84dd2869cfa")), new StaticArray3<Bytes32>(new Bytes32("b87213121fb89cbd8b877cb1bb3ff84d".getBytes()), new Bytes32("b87213121fb89cbd8b877cb1bb3ff84d".getBytes()), new Bytes32("b87213121fb89cbd8b877cb1bb3ff84d".getBytes())), new StaticArray3<DynamicBytes>(new DynamicBytes("aa".getBytes()), new DynamicBytes("aa".getBytes()), new DynamicBytes("aa".getBytes())), new StaticArray3<Utf8String>(new Utf8String("bb"), new Utf8String("bb"), new Utf8String("bb")))), is(17));
// int[],uint[],bool[],address[],bytes32[],bytes[],string[]
assertThat(Utils.getLength(Arrays.asList(new DynamicArray<Int256>(new Int256(1), new Int256(1), new Int256(1)), new DynamicArray<Uint256>(new Uint256(1), new Uint256(1), new Uint256(1)), new DynamicArray<Bool>(new Bool(true), new Bool(false), new Bool(true)), new DynamicArray<Address>(new Address("0xb87213121fb89cbd8b877cb1bb3ff84dd2869cfa"), new Address("0xb87213121fb89cbd8b877cb1bb3ff84dd2869cfa"), new Address("0xb87213121fb89cbd8b877cb1bb3ff84dd2869cfa")), new DynamicArray<Bytes32>(new Bytes32("b87213121fb89cbd8b877cb1bb3ff84d".getBytes()), new Bytes32("b87213121fb89cbd8b877cb1bb3ff84d".getBytes()), new Bytes32("b87213121fb89cbd8b877cb1bb3ff84d".getBytes())), new DynamicArray<DynamicBytes>(new DynamicBytes("aa".getBytes()), new DynamicBytes("aa".getBytes()), new DynamicBytes("aa".getBytes())), new DynamicArray<Utf8String>(new Utf8String("bb"), new Utf8String("bb"), new Utf8String("bb")))), is(7));
// int,uint,bool,address,bytes32,bytes,string,int[3],uint[3],bool[3],address[3],bytes32[3],bytes[3],string[3]
assertThat(Utils.getLength(Arrays.asList(new Int256(1), new Uint256(1), new Bool(true), new Address("0xb87213121fb89cbd8b877cb1bb3ff84dd2869cfa"), new Bytes32("b87213121fb89cbd8b877cb1bb3ff84d".getBytes()), new DynamicBytes("aa".getBytes()), new Utf8String("bb"), new StaticArray3<Int256>(new Int256(1), new Int256(1), new Int256(1)), new StaticArray3<Uint256>(new Uint256(1), new Uint256(1), new Uint256(1)), new StaticArray3<Bool>(new Bool(true), new Bool(false), new Bool(true)), new StaticArray3<Address>(new Address("0xb87213121fb89cbd8b877cb1bb3ff84dd2869cfa"), new Address("0xb87213121fb89cbd8b877cb1bb3ff84dd2869cfa"), new Address("0xb87213121fb89cbd8b877cb1bb3ff84dd2869cfa")), new StaticArray3<Bytes32>(new Bytes32("b87213121fb89cbd8b877cb1bb3ff84d".getBytes()), new Bytes32("b87213121fb89cbd8b877cb1bb3ff84d".getBytes()), new Bytes32("b87213121fb89cbd8b877cb1bb3ff84d".getBytes())), new StaticArray3<DynamicBytes>(new DynamicBytes("aa".getBytes()), new DynamicBytes("aa".getBytes()), new DynamicBytes("aa".getBytes())), new StaticArray3<Utf8String>(new Utf8String("bb"), new Utf8String("bb"), new Utf8String("bb")))), is(24));
// int,uint,bool,address,bytes32,bytes,string,int[],uint[],bool[],address[],bytes32[],bytes[],string[]
assertThat(Utils.getLength(Arrays.asList(new Int256(1), new Uint256(1), new Bool(true), new Address("0xb87213121fb89cbd8b877cb1bb3ff84dd2869cfa"), new Bytes32("b87213121fb89cbd8b877cb1bb3ff84d".getBytes()), new DynamicBytes("aa".getBytes()), new Utf8String("bb"), new DynamicArray<Int256>(new Int256(1), new Int256(1), new Int256(1)), new DynamicArray<Uint256>(new Uint256(1), new Uint256(1), new Uint256(1)), new DynamicArray<Bool>(new Bool(true), new Bool(false), new Bool(true)), new DynamicArray<Address>(new Address("0xb87213121fb89cbd8b877cb1bb3ff84dd2869cfa"), new Address("0xb87213121fb89cbd8b877cb1bb3ff84dd2869cfa"), new Address("0xb87213121fb89cbd8b877cb1bb3ff84dd2869cfa")), new DynamicArray<Bytes32>(new Bytes32("b87213121fb89cbd8b877cb1bb3ff84d".getBytes()), new Bytes32("b87213121fb89cbd8b877cb1bb3ff84d".getBytes()), new Bytes32("b87213121fb89cbd8b877cb1bb3ff84d".getBytes())), new DynamicArray<DynamicBytes>(new DynamicBytes("aa".getBytes()), new DynamicBytes("aa".getBytes()), new DynamicBytes("aa".getBytes())), new DynamicArray<Utf8String>(new Utf8String("bb"), new Utf8String("bb"), new Utf8String("bb")))), is(14));
// uint256[][2],uint256[2][],uint256[][],uint256[2][2]
assertThat(Utils.getLength(Arrays.asList(new StaticArray2<DynamicArray>(new DynamicArray<Uint256>(new Uint256(1), new Uint256(1), new Uint256(1), new Uint256(1), new Uint256(1)), new DynamicArray<Uint256>(new Uint256(1), new Uint256(1), new Uint256(1), new Uint256(1), new Uint256(1))), new DynamicArray<StaticArray2>(new StaticArray2<Uint256>(new Uint256(1), new Uint256(1)), new StaticArray2<Uint256>(new Uint256(1), new Uint256(1))), new DynamicArray<DynamicArray>(new DynamicArray<Uint256>(new Uint256(1), new Uint256(1)), new DynamicArray<Uint256>(new Uint256(1), new Uint256(1))), new StaticArray2<StaticArray2>(new StaticArray2<Uint256>(new Uint256(1), new Uint256(1)), new StaticArray2<Uint256>(new Uint256(1), new Uint256(1))))), is(7));
// int256[][2],int256[2][],int256[][],int256[2][2]
assertThat(Utils.getLength(Arrays.asList(new StaticArray2<DynamicArray>(new DynamicArray<Int256>(new Int256(1), new Int256(1), new Int256(1), new Int256(1), new Int256(1)), new DynamicArray<Int256>(new Int256(1), new Int256(1), new Int256(1), new Int256(1), new Int256(1))), new DynamicArray<StaticArray2>(new StaticArray2<Int256>(new Int256(1), new Int256(1)), new StaticArray2<Int256>(new Int256(1), new Int256(1))), new DynamicArray<DynamicArray>(new DynamicArray<Int256>(new Int256(1), new Int256(1)), new DynamicArray<Int256>(new Int256(1), new Int256(1))), new StaticArray2<StaticArray2>(new StaticArray2<Int256>(new Int256(1), new Int256(1)), new StaticArray2<Int256>(new Int256(1), new Int256(1))))), is(7));
// string[][2],string[2][],string[][],string[3][3]
assertThat(Utils.getLength(Arrays.asList(new StaticArray2<DynamicArray>(new DynamicArray<Utf8String>(new Utf8String("b87213121fb89cbd8b877cb1bb3ff84d"), new Utf8String("b87213121fb89cbd8b877cb1bb3ff84d"), new Utf8String("b87213121fb89cbd8b877cb1bb3ff84d"), new Utf8String("b87213121fb89cbd8b877cb1bb3ff84d"), new Utf8String("b87213121fb89cbd8b877cb1bb3ff84d")), new DynamicArray<Utf8String>(new Utf8String("b87213121fb89cbd8b877cb1bb3ff84d"), new Utf8String("b87213121fb89cbd8b877cb1bb3ff84d"), new Utf8String("b87213121fb89cbd8b877cb1bb3ff84d"), new Utf8String("b87213121fb89cbd8b877cb1bb3ff84d"), new Utf8String("b87213121fb89cbd8b877cb1bb3ff84d"))), new DynamicArray<StaticArray2>(new StaticArray2<Utf8String>(new Utf8String("b87213121fb89cbd8b877cb1bb3ff84d"), new Utf8String("b87213121fb89cbd8b877cb1bb3ff84d")), new StaticArray2<Utf8String>(new Utf8String("b87213121fb89cbd8b877cb1bb3ff84d"), new Utf8String("b87213121fb89cbd8b877cb1bb3ff84d"))), new DynamicArray<DynamicArray>(new DynamicArray<Utf8String>(new Utf8String("b87213121fb89cbd8b877cb1bb3ff84d"), new Utf8String("b87213121fb89cbd8b877cb1bb3ff84d")), new DynamicArray<Utf8String>(new Utf8String("b87213121fb89cbd8b877cb1bb3ff84d"), new Utf8String("b87213121fb89cbd8b877cb1bb3ff84d"))), new StaticArray3<StaticArray3>(new StaticArray3<Utf8String>(new Utf8String("b87213121fb89cbd8b877cb1bb3ff84d"), new Utf8String("b87213121fb89cbd8b877cb1bb3ff84d"), new Utf8String("b87213121fb89cbd8b877cb1bb3ff84d")), new StaticArray3<Utf8String>(new Utf8String("b87213121fb89cbd8b877cb1bb3ff84d"), new Utf8String("b87213121fb89cbd8b877cb1bb3ff84d"), new Utf8String("b87213121fb89cbd8b877cb1bb3ff84d")), new StaticArray3<Utf8String>(new Utf8String("b87213121fb89cbd8b877cb1bb3ff84d"), new Utf8String("b87213121fb89cbd8b877cb1bb3ff84d"), new Utf8String("b87213121fb89cbd8b877cb1bb3ff84d"))))), is(4));
// bytes[][2],bytes[2][],bytes[][],bytes[2][2]
assertThat(Utils.getLength(Arrays.asList(new StaticArray2<DynamicArray>(new DynamicArray<DynamicBytes>(new DynamicBytes("b87213121fb89cbd8b877cb1bb3ff84d".getBytes()), new DynamicBytes("b87213121fb89cbd8b877cb1bb3ff84d".getBytes()), new DynamicBytes("b87213121fb89cbd8b877cb1bb3ff84d".getBytes()), new DynamicBytes("b87213121fb89cbd8b877cb1bb3ff84d".getBytes()), new DynamicBytes("b87213121fb89cbd8b877cb1bb3ff84d".getBytes())), new DynamicArray<DynamicBytes>(new DynamicBytes("b87213121fb89cbd8b877cb1bb3ff84d".getBytes()), new DynamicBytes("b87213121fb89cbd8b877cb1bb3ff84d".getBytes()), new DynamicBytes("b87213121fb89cbd8b877cb1bb3ff84d".getBytes()), new DynamicBytes("b87213121fb89cbd8b877cb1bb3ff84d".getBytes()), new DynamicBytes("b87213121fb89cbd8b877cb1bb3ff84d".getBytes()))), new DynamicArray<StaticArray2>(new StaticArray2<DynamicBytes>(new DynamicBytes("b87213121fb89cbd8b877cb1bb3ff84d".getBytes()), new DynamicBytes("b87213121fb89cbd8b877cb1bb3ff84d".getBytes())), new StaticArray2<DynamicBytes>(new DynamicBytes("b87213121fb89cbd8b877cb1bb3ff84d".getBytes()), new DynamicBytes("b87213121fb89cbd8b877cb1bb3ff84d".getBytes()))), new DynamicArray<DynamicArray>(new DynamicArray<DynamicBytes>(new DynamicBytes("b87213121fb89cbd8b877cb1bb3ff84d".getBytes()), new DynamicBytes("b87213121fb89cbd8b877cb1bb3ff84d".getBytes())), new DynamicArray<DynamicBytes>(new DynamicBytes("b87213121fb89cbd8b877cb1bb3ff84d".getBytes()), new DynamicBytes("b87213121fb89cbd8b877cb1bb3ff84d".getBytes()))), new StaticArray3<StaticArray3>(new StaticArray3<DynamicBytes>(new DynamicBytes("b87213121fb89cbd8b877cb1bb3ff84d".getBytes()), new DynamicBytes("b87213121fb89cbd8b877cb1bb3ff84d".getBytes()), new DynamicBytes("b87213121fb89cbd8b877cb1bb3ff84d".getBytes())), new StaticArray3<DynamicBytes>(new DynamicBytes("b87213121fb89cbd8b877cb1bb3ff84d".getBytes()), new DynamicBytes("b87213121fb89cbd8b877cb1bb3ff84d".getBytes()), new DynamicBytes("b87213121fb89cbd8b877cb1bb3ff84d".getBytes())), new StaticArray3<DynamicBytes>(new DynamicBytes("b87213121fb89cbd8b877cb1bb3ff84d".getBytes()), new DynamicBytes("b87213121fb89cbd8b877cb1bb3ff84d".getBytes()), new DynamicBytes("b87213121fb89cbd8b877cb1bb3ff84d".getBytes()))))), is(4));
}
use of org.fisco.bcos.web3j.abi.datatypes.generated.Bytes32 in project web3sdk by FISCO-BCOS.
the class TransactionDecoderTest method testDynamicParams1.
@Test
public void testDynamicParams1() throws JsonProcessingException, TransactionException, BaseException {
/*
function test(uint256[] _u,int256[] _i,bool[] _b,address[] _addr,bytes32[] _bs32,string[] _s,bytes[] _bs) public constant returns (uint256[],int256[],bool[],address[],bytes32[],string[],bytes[]) {
}
*/
TransactionDecoder decode = TransactionDecoderFactory.buildTransactionDecoder("[{\"constant\":true,\"inputs\":[{\"name\":\"_u\",\"type\":\"uint256[4]\"},{\"name\":\"_i\",\"type\":\"int256[4]\"},{\"name\":\"_b\",\"type\":\"bool[4]\"},{\"name\":\"_addr\",\"type\":\"address[4]\"},{\"name\":\"_bs32\",\"type\":\"bytes32[4]\"},{\"name\":\"_s\",\"type\":\"string[4]\"},{\"name\":\"_bs\",\"type\":\"bytes[4]\"}],\"name\":\"test\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256[2]\"},{\"name\":\"\",\"type\":\"int256[2]\"},{\"name\":\"\",\"type\":\"bool[2]\"},{\"name\":\"\",\"type\":\"address[2]\"},{\"name\":\"\",\"type\":\"bytes32[2]\"},{\"name\":\"\",\"type\":\"string[2]\"},{\"name\":\"\",\"type\":\"bytes[2]\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"_u\",\"type\":\"uint256\"},{\"name\":\"_i\",\"type\":\"int256\"},{\"name\":\"_b\",\"type\":\"bool\"},{\"name\":\"_addr\",\"type\":\"address\"},{\"name\":\"_bs32\",\"type\":\"bytes32\"},{\"name\":\"_s\",\"type\":\"string\"},{\"name\":\"_bs\",\"type\":\"bytes\"}],\"name\":\"test\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"},{\"name\":\"\",\"type\":\"int256\"},{\"name\":\"\",\"type\":\"bool\"},{\"name\":\"\",\"type\":\"address\"},{\"name\":\"\",\"type\":\"bytes32\"},{\"name\":\"\",\"type\":\"string\"},{\"name\":\"\",\"type\":\"bytes\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"_u\",\"type\":\"uint256[]\"},{\"name\":\"_i\",\"type\":\"int256[]\"},{\"name\":\"_b\",\"type\":\"bool[]\"},{\"name\":\"_addr\",\"type\":\"address[]\"},{\"name\":\"_bs32\",\"type\":\"bytes32[]\"},{\"name\":\"_s\",\"type\":\"string[]\"},{\"name\":\"_bs\",\"type\":\"bytes[]\"}],\"name\":\"test\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256[]\"},{\"name\":\"\",\"type\":\"int256[]\"},{\"name\":\"\",\"type\":\"bool[]\"},{\"name\":\"\",\"type\":\"address[]\"},{\"name\":\"\",\"type\":\"bytes32[]\"},{\"name\":\"\",\"type\":\"string[]\"},{\"name\":\"\",\"type\":\"bytes[]\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"name\":\"_u\",\"type\":\"uint256\"},{\"indexed\":false,\"name\":\"_i\",\"type\":\"int256\"},{\"indexed\":false,\"name\":\"_b\",\"type\":\"bool\"},{\"indexed\":false,\"name\":\"_addr\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"_bs32\",\"type\":\"bytes32\"},{\"indexed\":false,\"name\":\"_s\",\"type\":\"string\"},{\"indexed\":false,\"name\":\"_bs\",\"type\":\"bytes\"}],\"name\":\"TestEventSimpleParams\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"name\":\"_u\",\"type\":\"uint256[]\"},{\"indexed\":false,\"name\":\"_i\",\"type\":\"int256[]\"},{\"indexed\":false,\"name\":\"_b\",\"type\":\"bool[]\"},{\"indexed\":false,\"name\":\"_addr\",\"type\":\"address[]\"},{\"indexed\":false,\"name\":\"_bs32\",\"type\":\"bytes32[]\"},{\"indexed\":false,\"name\":\"_s\",\"type\":\"string[]\"},{\"indexed\":false,\"name\":\"_bs\",\"type\":\"bytes[]\"}],\"name\":\"TestEventDArrayParams\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"name\":\"_u\",\"type\":\"uint256[4]\"},{\"indexed\":false,\"name\":\"_i\",\"type\":\"int256[4]\"},{\"indexed\":false,\"name\":\"_b\",\"type\":\"bool[4]\"},{\"indexed\":false,\"name\":\"_addr\",\"type\":\"address[4]\"},{\"indexed\":false,\"name\":\"_bs32\",\"type\":\"bytes32[4]\"},{\"indexed\":false,\"name\":\"_s\",\"type\":\"string[4]\"},{\"indexed\":false,\"name\":\"_bs\",\"type\":\"bytes[4]\"}],\"name\":\"TestEventSArrayParams\",\"type\":\"event\"}]", "");
List<Type> test1Params = Arrays.asList(new DynamicArray<Uint256>(new Uint256(0), new Uint256(0), new Uint256(0)), new DynamicArray<Int256>(new Int256(0), new Int256(0), new Int256(0)), new DynamicArray<Bool>(new Bool(false), new Bool(true), new Bool(false)), new DynamicArray<Address>(new Address("0x0"), new Address("0x0")), new DynamicArray<Bytes32>(new Bytes32(" ".getBytes()), new Bytes32(" ".getBytes())), new DynamicArray<Utf8String>(new Utf8String(""), new Utf8String(""), new Utf8String("")), new DynamicArray<DynamicBytes>(new DynamicBytes("".getBytes()), new DynamicBytes("".getBytes()), new DynamicBytes("".getBytes())));
Function test1 = new Function("test", test1Params, Collections.<TypeReference<?>>emptyList());
String resultInputJson = decode.decodeInputReturnJson(FunctionEncoder.encode(test1));
InputAndOutputResult inputAndOutputResult1 = decode.decodeInputReturnObject(FunctionEncoder.encode(test1));
List<ResultEntity> resultInputList = inputAndOutputResult1.getResult();
List<Type> resultInputListType = transEntitytoType(resultInputList);
assertThat(resultInputJson, is("{\"function\":\"test(uint256[],int256[],bool[],address[],bytes32[],string[],bytes[])\",\"methodID\":\"0x6dd9902a\",\"result\":[{\"name\":\"_u\",\"type\":\"uint256[]\",\"data\":[0,0,0]},{\"name\":\"_i\",\"type\":\"int256[]\",\"data\":[0,0,0]},{\"name\":\"_b\",\"type\":\"bool[]\",\"data\":[false,true,false]},{\"name\":\"_addr\",\"type\":\"address[]\",\"data\":[\"0x0000000000000000000000000000000000000000\",\"0x0000000000000000000000000000000000000000\"]},{\"name\":\"_bs32\",\"type\":\"bytes32[]\",\"data\":[\"\",\"\"]},{\"name\":\"_s\",\"type\":\"string[]\",\"data\":[\"\",\"\",\"\"]},{\"name\":\"_bs\",\"type\":\"bytes[]\",\"data\":[\"\",\"\",\"\"]}]}"));
assertThat(resultInputListType, is(test1Params));
String resultOutputJson = decode.decodeOutputReturnJson(FunctionEncoder.encode(test1), FunctionEncoder.encodeConstructor(test1Params));
InputAndOutputResult inputAndOutputResult = decode.decodeOutputReturnObject(FunctionEncoder.encode(test1), FunctionEncoder.encodeConstructor(test1Params));
List<ResultEntity> resultOutputList = inputAndOutputResult.getResult();
assertThat(resultOutputJson, is("{\"function\":\"test(uint256[],int256[],bool[],address[],bytes32[],string[],bytes[])\",\"methodID\":\"0x6dd9902a\",\"result\":[{\"name\":\"\",\"type\":\"uint256[]\",\"data\":[0,0,0]},{\"name\":\"\",\"type\":\"int256[]\",\"data\":[0,0,0]},{\"name\":\"\",\"type\":\"bool[]\",\"data\":[false,true,false]},{\"name\":\"\",\"type\":\"address[]\",\"data\":[\"0x0000000000000000000000000000000000000000\",\"0x0000000000000000000000000000000000000000\"]},{\"name\":\"\",\"type\":\"bytes32[]\",\"data\":[\"\",\"\"]},{\"name\":\"\",\"type\":\"string[]\",\"data\":[\"\",\"\",\"\"]},{\"name\":\"\",\"type\":\"bytes[]\",\"data\":[\"\",\"\",\"\"]}]}"));
assertThat(transEntitytoType(resultOutputList), is(test1Params));
}
use of org.fisco.bcos.web3j.abi.datatypes.generated.Bytes32 in project web3sdk by FISCO-BCOS.
the class TransactionDecoderTest method testTableTest.
@Test
public void testTableTest() throws JsonProcessingException, TransactionException, BaseException {
/*
* contract TableTest {
*
* // function select(string name) public constant returns(bytes32[], int[], bytes32[])
* // function insert(string name, int item_id, string item_name)
* // function update(string name, int item_id, string item_name)
* // function remove(string name, int item_id) public returns(int)
* }
* */
String abi = "[{\"constant\":false,\"inputs\":[{\"name\":\"name\",\"type\":\"string\"},{\"name\":\"item_id\",\"type\":\"int256\"},{\"name\":\"item_name\",\"type\":\"string\"}],\"name\":\"update\",\"outputs\":[{\"name\":\"\",\"type\":\"int256\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"name\",\"type\":\"string\"},{\"name\":\"item_id\",\"type\":\"int256\"}],\"name\":\"remove\",\"outputs\":[{\"name\":\"\",\"type\":\"int256\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"name\",\"type\":\"string\"},{\"name\":\"item_id\",\"type\":\"int256\"},{\"name\":\"item_name\",\"type\":\"string\"}],\"name\":\"insert\",\"outputs\":[{\"name\":\"result\",\"type\":\"int256\"},{\"name\":\"result_name\",\"type\":\"string\"},{\"name\":\"\",\"type\":\"bytes32\"},{\"name\":\"addr\",\"type\":\"address\"},{\"name\":\"\",\"type\":\"bytes32[]\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[],\"name\":\"create\",\"outputs\":[{\"name\":\"\",\"type\":\"int256\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"name\",\"type\":\"string\"}],\"name\":\"select\",\"outputs\":[{\"name\":\"\",\"type\":\"bytes32[]\"},{\"name\":\"\",\"type\":\"int256[]\"},{\"name\":\"\",\"type\":\"bytes32[]\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"name\":\"count\",\"type\":\"int256\"}],\"name\":\"CreateResult\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"name\":\"count\",\"type\":\"int256\"},{\"indexed\":false,\"name\":\"name\",\"type\":\"string\"},{\"indexed\":false,\"name\":\"item_name\",\"type\":\"bytes8\"},{\"indexed\":false,\"name\":\"item_id\",\"type\":\"bytes32[]\"}],\"name\":\"InsertResult\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"name\":\"count\",\"type\":\"int256\"},{\"indexed\":false,\"name\":\"name\",\"type\":\"string\"}],\"name\":\"UpdateResult\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"name\":\"count\",\"type\":\"int256\"}],\"name\":\"RemoveResult\",\"type\":\"event\"}]";
TransactionDecoder decode = TransactionDecoderFactory.buildTransactionDecoder(abi, "");
// function select(string name) returns(bytes32[], int[], bytes32[])
Function select = new Function("select", Arrays.asList(new Utf8String("HelloWorld!")), Arrays.asList(new TypeReference<DynamicArray<Bytes32>>() {
}, new TypeReference<DynamicArray<Int256>>() {
}, new TypeReference<DynamicArray<Bytes32>>() {
}));
String selectSR = decode.decodeInputReturnJson(FunctionEncoder.encode(select));
assertThat(selectSR, is("{\"function\":\"select(string)\",\"methodID\":\"0xfcd7e3c1\",\"result\":[{\"name\":\"name\",\"type\":\"string\",\"data\":\"HelloWorld!\"}]}"));
InputAndOutputResult inputAndOutputResult1 = decode.decodeInputReturnObject(FunctionEncoder.encode(select));
List<ResultEntity> selectOR = inputAndOutputResult1.getResult();
assertThat(transEntitytoType(selectOR), is(Arrays.asList(new Utf8String("HelloWorld!"))));
String output = FunctionEncoder.encodeConstructor(Arrays.asList(new DynamicArray<Bytes32>(new Bytes32("01234567890123456789012345678912".getBytes()), new Bytes32("a123456789012345f7890f2345678d12".getBytes()), new Bytes32("abcdefghijklmnopqrstuvwxyzadfljk".getBytes())), new DynamicArray<Int256>(new Int256(1234567), new Int256(-1234567), new Int256(98877)), new DynamicArray<Bytes32>(new Bytes32("01234567890123456789012345678912".getBytes()), new Bytes32("a123456789012345f7890f2345678d12".getBytes()), new Bytes32("abcdefghijklmnopqrstuvwxyzadfljk".getBytes()))));
String selectSOR = decode.decodeOutputReturnJson(FunctionEncoder.encode(select), output);
InputAndOutputResult inputAndOutputResult = decode.decodeOutputReturnObject(FunctionEncoder.encode(select), output);
List<ResultEntity> selectOutOR = inputAndOutputResult.getResult();
assertThat(selectSOR, is("{\"function\":\"select(string)\",\"methodID\":\"0xfcd7e3c1\",\"result\":[{\"name\":\"\",\"type\":\"bytes32[]\",\"data\":[\"01234567890123456789012345678912\",\"a123456789012345f7890f2345678d12\",\"abcdefghijklmnopqrstuvwxyzadfljk\"]},{\"name\":\"\",\"type\":\"int256[]\",\"data\":[1234567,-1234567,98877]},{\"name\":\"\",\"type\":\"bytes32[]\",\"data\":[\"01234567890123456789012345678912\",\"a123456789012345f7890f2345678d12\",\"abcdefghijklmnopqrstuvwxyzadfljk\"]}]}"));
assertThat(transEntitytoType(selectOutOR), is(Arrays.asList(new DynamicArray<Bytes32>(new Bytes32("01234567890123456789012345678912".getBytes()), new Bytes32("a123456789012345f7890f2345678d12".getBytes()), new Bytes32("abcdefghijklmnopqrstuvwxyzadfljk".getBytes())), new DynamicArray<Int256>(new Int256(1234567), new Int256(-1234567), new Int256(98877)), new DynamicArray<Bytes32>(new Bytes32("01234567890123456789012345678912".getBytes()), new Bytes32("a123456789012345f7890f2345678d12".getBytes()), new Bytes32("abcdefghijklmnopqrstuvwxyzadfljk".getBytes())))));
// function update(string name, int item_id, string item_name)
Function update = new Function("update", Arrays.asList(new Utf8String("HelloWorld! My First Hello."), new Int256(5555), new Utf8String("Good afternoon")), Collections.<TypeReference<?>>emptyList());
String updateSR = decode.decodeInputReturnJson(FunctionEncoder.encode(update));
assertThat(updateSR, is("{\"function\":\"update(string,int256,string)\",\"methodID\":\"0x487a5a10\",\"result\":[{\"name\":\"name\",\"type\":\"string\",\"data\":\"HelloWorld! My First Hello.\"},{\"name\":\"item_id\",\"type\":\"int256\",\"data\":5555},{\"name\":\"item_name\",\"type\":\"string\",\"data\":\"Good afternoon\"}]}"));
InputAndOutputResult inputAndOutputResult2 = decode.decodeInputReturnObject(FunctionEncoder.encode(update));
List<ResultEntity> updateOR = inputAndOutputResult2.getResult();
assertThat(transEntitytoType(updateOR), is(Arrays.asList(new Utf8String("HelloWorld! My First Hello."), new Int256(5555), new Utf8String("Good afternoon"))));
// function remove(string name, int item_id) public returns(int)
Function remove = new Function("remove", Arrays.asList(new Utf8String("HelloWorld! My First Hello."), new Int256(-1111111)), Collections.<TypeReference<?>>emptyList());
String removeSR = decode.decodeInputReturnJson(FunctionEncoder.encode(remove));
InputAndOutputResult inputAndOutputResult3 = decode.decodeInputReturnObject(FunctionEncoder.encode(remove));
List<ResultEntity> removeOR = inputAndOutputResult3.getResult();
assertThat(removeSR, is("{\"function\":\"remove(string,int256)\",\"methodID\":\"0xc4f41ab3\",\"result\":[{\"name\":\"name\",\"type\":\"string\",\"data\":\"HelloWorld! My First Hello.\"},{\"name\":\"item_id\",\"type\":\"int256\",\"data\":-1111111}]}"));
assertThat(transEntitytoType(removeOR), is(Arrays.asList(new Utf8String("HelloWorld! My First Hello."), new Int256(-1111111))));
}
Aggregations