Search in sources :

Example 6 with Bytes10

use of org.fisco.bcos.web3j.abi.datatypes.generated.Bytes10 in project web3sdk by FISCO-BCOS.

the class FunctionEncoderTest method testMixTypeEncode1.

@Test
public void testMixTypeEncode1() {
    // function  set0(uint256,uint256[],uint256,bytes10,string)
    Function function = new Function("set0", Arrays.asList(new Uint256(291), new DynamicArray<Uint256>(new Uint256(1110), new Uint256(1929)), new Bytes10("1234567890".getBytes()), new Utf8String("Hello, world!")), Collections.singletonList(new TypeReference<DynamicArray<Utf8String>>() {
    }));
    assertThat(FunctionEncoder.encodeParameters(function.getInputParameters(), new StringBuilder()), is("0000000000000000000000000000000000000000000000000000000000000123" + "0000000000000000000000000000000000000000000000000000000000000080" + "3132333435363738393000000000000000000000000000000000000000000000" + "00000000000000000000000000000000000000000000000000000000000000e0" + "0000000000000000000000000000000000000000000000000000000000000002" + "0000000000000000000000000000000000000000000000000000000000000456" + "0000000000000000000000000000000000000000000000000000000000000789" + "000000000000000000000000000000000000000000000000000000000000000d" + "48656c6c6f2c20776f726c642100000000000000000000000000000000000000"));
}
Also used : Uint256(org.fisco.bcos.web3j.abi.datatypes.generated.Uint256) Bytes10(org.fisco.bcos.web3j.abi.datatypes.generated.Bytes10) Test(org.junit.Test)

Example 7 with Bytes10

use of org.fisco.bcos.web3j.abi.datatypes.generated.Bytes10 in project web3sdk by FISCO-BCOS.

the class TypeTest method dynamicOffsetTest.

@Test
public void dynamicOffsetTest() {
    // bool
    assertThat(new Bool(true).offset(), is(1));
    // bool
    assertThat(new Bool(false).offset(), is(1));
    assertThat(new Address("0xb87213121fb89cbd8b877cb1bb3ff84dd2869cfa").offset(), // address
    is(1));
    // string
    assertThat(new Utf8String("").offset(), is(1));
    // string
    assertThat(new Utf8String("abcdef").offset(), is(1));
    // bytes10
    assertThat(new Bytes10("0123456789".getBytes()).offset(), is(1));
    // bytes3
    assertThat(new Bytes3("abc".getBytes()).offset(), is(1));
    // bytes1
    assertThat(new Bytes1("a".getBytes()).offset(), is(1));
    // uint256
    assertThat(new Uint256(1).offset(), is(1));
    // int256
    assertThat(new Int256(1).offset(), is(1));
    // bytes
    assertThat(new DynamicBytes("".getBytes()).offset(), is(1));
    // bytes
    assertThat(new DynamicBytes("abc".getBytes()).offset(), is(1));
    // bool[1]
    assertThat(new StaticArray1<Bool>(new Bool(true)).offset(), is(1));
    assertThat(new StaticArray3<Bool>(new Bool(true), new Bool(true), new Bool(true)).offset(), // bool[3]
    is(3));
    assertThat(new DynamicArray<Bool>(new Bool(true), new Bool(true), new Bool(true), new Bool(true)).offset(), // bool[]
    is(1));
    assertThat(new DynamicArray<DynamicArray<Bool>>(new DynamicArray<Bool>(new Bool(true), new Bool(true), new Bool(true))).offset(), // bool[][]
    is(1));
    assertThat(new StaticArray2<DynamicArray<Bool>>(new DynamicArray<Bool>(new Bool(true)), new DynamicArray<Bool>(new Bool(true))).offset(), // bool[][2]
    is(1));
    assertThat(new DynamicArray<StaticArray2<Bool>>(new StaticArray2<Bool>(new Bool(true), new Bool(true)), new StaticArray2<Bool>(new Bool(true), new Bool(true))).offset(), // bool[1][]
    is(1));
    assertThat(new StaticArray2<StaticArray2<Bool>>(new StaticArray2<Bool>(new Bool(true), new Bool(true)), new StaticArray2<Bool>(new Bool(true), new Bool(true))).offset(), // bool[2][2]
    is(4));
    // uint256[1]
    assertThat(new StaticArray1<Uint256>(new Uint256(1)).offset(), is(1));
    assertThat(new DynamicArray<Uint256>(new Uint256(1), new Uint256(1)).offset(), // uint256[]
    is(1));
    assertThat(new DynamicArray<DynamicArray<Uint256>>(new DynamicArray<Uint256>(new Uint256(1), new Uint256(1)), new DynamicArray<Uint256>(new Uint256(1), new Uint256(1))).offset(), // uint256[][]
    is(1));
    assertThat(new StaticArray2<DynamicArray<Uint256>>(new DynamicArray<Uint256>(new Uint256(1)), new DynamicArray<Uint256>(new Uint256(1))).offset(), // uint256[][2]
    is(1));
    assertThat(new DynamicArray<StaticArray2<Uint256>>(new StaticArray2<Uint256>(new Uint256(1), new Uint256(1))).offset(), // uint256[2][]
    is(1));
    assertThat(new StaticArray2<StaticArray2<Uint256>>(new StaticArray2<Uint256>(new Uint256(1), new Uint256(1)), new StaticArray2<Uint256>(new Uint256(1), new Uint256(1))).offset(), // uint256[2][2]
    is(4));
    // int256[1]
    assertThat(new StaticArray1<Int256>(new Int256(1)).offset(), is(1));
    // int256[]
    assertThat(new DynamicArray<Int256>(new Int256(1)).offset(), is(1));
    assertThat(new DynamicArray<DynamicArray<Int256>>(new DynamicArray<Int256>(new Int256(1), new Int256(1)), new DynamicArray<Int256>(new Int256(1), new Int256(1))).offset(), // int256[][]
    is(1));
    assertThat(new StaticArray2<DynamicArray<Int256>>(new DynamicArray<Int256>(new Int256(1)), new DynamicArray<Int256>(new Int256(1))).offset(), // int256[][2]
    is(1));
    assertThat(new DynamicArray<StaticArray2<Int256>>(new StaticArray2<Int256>(new Int256(1), new Int256(1))).offset(), // int256[2][]
    is(1));
    assertThat(new StaticArray2<StaticArray2<Int256>>(new StaticArray2<Int256>(new Int256(1), new Int256(1)), new StaticArray2<Int256>(new Int256(1), new Int256(1))).offset(), // int256[2][2]
    is(4));
    assertThat(new StaticArray1<Address>(new Address("0xb87213121fb89cbd8b877cb1bb3ff84dd2869cfa")).offset(), // address[1]
    is(1));
    assertThat(new DynamicArray<Address>(new Address("0xb87213121fb89cbd8b877cb1bb3ff84dd2869cfa")).offset(), // address[]
    is(1));
    assertThat(new DynamicArray<DynamicArray<Address>>(new DynamicArray<Address>(new Address("0xb87213121fb89cbd8b877cb1bb3ff84dd2869cfa"), new Address("0xb87213121fb89cbd8b877cb1bb3ff84dd2869cfa")), new DynamicArray<Address>(new Address("0xb87213121fb89cbd8b877cb1bb3ff84dd2869cfa"), new Address("0xb87213121fb89cbd8b877cb1bb3ff84dd2869cfa"))).offset(), // address[][]
    is(1));
    assertThat(new StaticArray2<DynamicArray<Address>>(new DynamicArray<Address>(new Address("0xb87213121fb89cbd8b877cb1bb3ff84dd2869cfa")), new DynamicArray<Address>(new Address("0xb87213121fb89cbd8b877cb1bb3ff84dd2869cfa"))).offset(), // address[][2]
    is(1));
    assertThat(new DynamicArray<StaticArray2<Address>>(new StaticArray2<Address>(new Address("0xb87213121fb89cbd8b877cb1bb3ff84dd2869cfa"), new Address("0xb87213121fb89cbd8b877cb1bb3ff84dd2869cfa"))).offset(), // address[2][]
    is(1));
    assertThat(new StaticArray2<StaticArray2<Address>>(new StaticArray2<Address>(new Address("0xb87213121fb89cbd8b877cb1bb3ff84dd2869cfa"), new Address("0xb87213121fb89cbd8b877cb1bb3ff84dd2869cfa")), new StaticArray2<Address>(new Address("0xb87213121fb89cbd8b877cb1bb3ff84dd2869cfa"), new Address("0xb87213121fb89cbd8b877cb1bb3ff84dd2869cfa"))).offset(), // address[2][2]
    is(4));
    // string[1]
    assertThat(new StaticArray1<Utf8String>(new Utf8String("")).offset(), is(1));
    // string[]
    assertThat(new DynamicArray<Utf8String>(new Utf8String("")).offset(), is(1));
    assertThat(new DynamicArray<DynamicArray<Utf8String>>(new DynamicArray<Utf8String>(new Utf8String("0xb87213121fb89cbd8b877cb1bb3ff84dd2869cfa"))).offset(), // string[][]
    is(1));
    assertThat(new StaticArray2<DynamicArray<Utf8String>>(new DynamicArray<Utf8String>(new Utf8String("0xb87213121fb89cbd8b877cb1bb3ff84dd2869cfa")), new DynamicArray<Utf8String>(new Utf8String("0xb87213121fb89cbd8b877cb1bb3ff84dd2869cfa"))).offset(), // string[][2]
    is(1));
    assertThat(new DynamicArray<StaticArray2<Utf8String>>(new StaticArray2<Utf8String>(new Utf8String("0xb87213121fb89cbd8b877cb1bb3ff84dd2869cfa"), new Utf8String("0xb87213121fb89cbd8b877cb1bb3ff84dd2869cfa"))).offset(), // string[2][]
    is(1));
    assertThat(new StaticArray2<StaticArray2<Utf8String>>(new StaticArray2<Utf8String>(new Utf8String("0xb87213121fb89cbd8b877cb1bb3ff84dd2869cfa"), new Utf8String("0xb87213121fb89cbd8b877cb1bb3ff84dd2869cfa")), new StaticArray2<Utf8String>(new Utf8String("0xb87213121fb89cbd8b877cb1bb3ff84dd2869cfa"), new Utf8String("0xb87213121fb89cbd8b877cb1bb3ff84dd2869cfa"))).offset(), // string[2][2]
    is(1));
    assertThat(new StaticArray1<DynamicBytes>(new DynamicBytes("aa".getBytes())).offset(), // bytes[1]
    is(1));
    assertThat(new DynamicArray<DynamicBytes>(new DynamicBytes("".getBytes())).offset(), // bytes[]
    is(1));
    assertThat(new DynamicArray<DynamicArray<DynamicBytes>>(new DynamicArray<DynamicBytes>(new DynamicBytes("0xb87213121fb89cbd8b877cb1bb3ff84dd2869cfa".getBytes()))).offset(), // bytes[][]
    is(1));
    assertThat(new StaticArray2<DynamicArray<DynamicBytes>>(new DynamicArray<DynamicBytes>(new DynamicBytes("0xb87213121fb89cbd8b877cb1bb3ff84dd2869cfa".getBytes()), new DynamicBytes("0xb87213121fb89cbd8b877cb1bb3ff84dd2869cfa".getBytes())), new DynamicArray<DynamicBytes>(new DynamicBytes("0xb87213121fb89cbd8b877cb1bb3ff84dd2869cfa".getBytes()), new DynamicBytes("0xb87213121fb89cbd8b877cb1bb3ff84dd2869cfa".getBytes()))).offset(), // bytes[][2]
    is(1));
    assertThat(new DynamicArray<StaticArray2<DynamicBytes>>(new StaticArray2<DynamicBytes>(new DynamicBytes("0xb87213121fb89cbd8b877cb1bb3ff84dd2869cfa".getBytes()), new DynamicBytes("0xb87213121fb89cbd8b877cb1bb3ff84dd2869cfa".getBytes())), new StaticArray2<DynamicBytes>(new DynamicBytes("0xb87213121fb89cbd8b877cb1bb3ff84dd2869cfa".getBytes()), new DynamicBytes("0xb87213121fb89cbd8b877cb1bb3ff84dd2869cfa".getBytes()))).offset(), // bytes21][]
    is(1));
    assertThat(new StaticArray2<StaticArray2<DynamicBytes>>(new StaticArray2<DynamicBytes>(new DynamicBytes("0xb87213121fb89cbd8b877cb1bb3ff84dd2869cfa".getBytes()), new DynamicBytes("0xb87213121fb89cbd8b877cb1bb3ff84dd2869cfa".getBytes())), new StaticArray2<DynamicBytes>(new DynamicBytes("0xb87213121fb89cbd8b877cb1bb3ff84dd2869cfa".getBytes()), new DynamicBytes("0xb87213121fb89cbd8b877cb1bb3ff84dd2869cfa".getBytes()))).offset(), // bytes[2][2]
    is(1));
}
Also used : Address(org.fisco.bcos.web3j.abi.datatypes.Address) Bytes10(org.fisco.bcos.web3j.abi.datatypes.generated.Bytes10) DynamicBytes(org.fisco.bcos.web3j.abi.datatypes.DynamicBytes) Bool(org.fisco.bcos.web3j.abi.datatypes.Bool) Utf8String(org.fisco.bcos.web3j.abi.datatypes.Utf8String) Int256(org.fisco.bcos.web3j.abi.datatypes.generated.Int256) StaticArray3(org.fisco.bcos.web3j.abi.datatypes.generated.StaticArray3) DynamicArray(org.fisco.bcos.web3j.abi.datatypes.DynamicArray) Bytes3(org.fisco.bcos.web3j.abi.datatypes.generated.Bytes3) Bytes1(org.fisco.bcos.web3j.abi.datatypes.generated.Bytes1) Uint256(org.fisco.bcos.web3j.abi.datatypes.generated.Uint256) StaticArray1(org.fisco.bcos.web3j.abi.datatypes.generated.StaticArray1) StaticArray2(org.fisco.bcos.web3j.abi.datatypes.generated.StaticArray2) Test(org.junit.Test)

Example 8 with Bytes10

use of org.fisco.bcos.web3j.abi.datatypes.generated.Bytes10 in project web3sdk by FISCO-BCOS.

the class TypeTest method dynamicTest.

@Test
public void dynamicTest() {
    // bool
    assertThat(new Bool(true).dynamicType(), is(false));
    // bool
    assertThat(new Bool(false).dynamicType(), is(false));
    assertThat(new Address("0xb87213121fb89cbd8b877cb1bb3ff84dd2869cfa").dynamicType(), // address
    is(false));
    // string
    assertThat(new Utf8String("").dynamicType(), is(true));
    // string
    assertThat(new Utf8String("abcdef").dynamicType(), is(true));
    // bytes10
    assertThat(new Bytes10("0123456789".getBytes()).dynamicType(), is(false));
    // bytes3
    assertThat(new Bytes3("abc".getBytes()).dynamicType(), is(false));
    // bytes1
    assertThat(new Bytes1("a".getBytes()).dynamicType(), is(false));
    // uint256
    assertThat(new Uint256(1).dynamicType(), is(false));
    // int256
    assertThat(new Int256(1).dynamicType(), is(false));
    // bytes
    assertThat(new DynamicBytes("".getBytes()).dynamicType(), is(true));
    // bytes
    assertThat(new DynamicBytes("abc".getBytes()).dynamicType(), is(true));
    // bool[1]
    assertThat(new StaticArray1<Bool>(new Bool(true)).dynamicType(), is(false));
    // bool[]
    assertThat(new DynamicArray<Bool>(new Bool(true)).dynamicType(), is(true));
    assertThat(new DynamicArray<DynamicArray<Bool>>(new DynamicArray<Bool>(new Bool(true))).dynamicType(), // bool[][]
    is(true));
    assertThat(new StaticArray1<DynamicArray<Bool>>(new DynamicArray<Bool>(new Bool(true))).dynamicType(), // bool[][1]
    is(true));
    assertThat(new DynamicArray<StaticArray1<Bool>>(new StaticArray1<Bool>(new Bool(true))).dynamicType(), // bool[1][]
    is(true));
    assertThat(new StaticArray1<StaticArray1<Bool>>(new StaticArray1<Bool>(new Bool(true))).dynamicType(), // bool[1][1]
    is(false));
    assertThat(new StaticArray1<Uint256>(new Uint256(1)).dynamicType(), // uint256[1]
    is(false));
    assertThat(new DynamicArray<Uint256>(new Uint256(1), new Uint256(1)).dynamicType(), // uint256[]
    is(true));
    assertThat(new DynamicArray<DynamicArray<Uint256>>(new DynamicArray<Uint256>(new Uint256(1))).dynamicType(), // uint256[][]
    is(true));
    assertThat(new StaticArray1<DynamicArray<Uint256>>(new DynamicArray<Uint256>(new Uint256(1))).dynamicType(), // uint256[][1]
    is(true));
    assertThat(new DynamicArray<StaticArray1<Uint256>>(new StaticArray1<Uint256>(new Uint256(1))).dynamicType(), // uint256[1][]
    is(true));
    assertThat(new StaticArray1<StaticArray1<Uint256>>(new StaticArray1<Uint256>(new Uint256(1))).dynamicType(), // uint256[1][1]
    is(false));
    // int256[1]
    assertThat(new StaticArray1<Int256>(new Int256(1)).dynamicType(), is(false));
    // int256[]
    assertThat(new DynamicArray<Int256>(new Int256(1)).dynamicType(), is(true));
    assertThat(new DynamicArray<DynamicArray<Int256>>(new DynamicArray<Int256>(new Int256(1))).dynamicType(), // int256[][]
    is(true));
    assertThat(new StaticArray1<DynamicArray<Int256>>(new DynamicArray<Int256>(new Int256(1))).dynamicType(), // int256[][1]
    is(true));
    assertThat(new DynamicArray<StaticArray1<Int256>>(new StaticArray1<Int256>(new Int256(1))).dynamicType(), // int256[1][]
    is(true));
    assertThat(new StaticArray1<StaticArray1<Int256>>(new StaticArray1<Int256>(new Int256(1))).dynamicType(), // int256[1][1]
    is(false));
    assertThat(new StaticArray1<Address>(new Address("0xb87213121fb89cbd8b877cb1bb3ff84dd2869cfa")).dynamicType(), // address[1]
    is(false));
    assertThat(new DynamicArray<Address>(new Address("0xb87213121fb89cbd8b877cb1bb3ff84dd2869cfa")).dynamicType(), // address[]
    is(true));
    assertThat(new DynamicArray<DynamicArray<Address>>(new DynamicArray<Address>(new Address("0xb87213121fb89cbd8b877cb1bb3ff84dd2869cfa"))).dynamicType(), // address[][]
    is(true));
    assertThat(new StaticArray1<DynamicArray<Address>>(new DynamicArray<Address>(new Address("0xb87213121fb89cbd8b877cb1bb3ff84dd2869cfa"))).dynamicType(), // address[][1]
    is(true));
    assertThat(new DynamicArray<StaticArray1<Address>>(new StaticArray1<Address>(new Address("0xb87213121fb89cbd8b877cb1bb3ff84dd2869cfa"))).dynamicType(), // address[1][]
    is(true));
    assertThat(new StaticArray1<StaticArray1<Address>>(new StaticArray1<Address>(new Address("0xb87213121fb89cbd8b877cb1bb3ff84dd2869cfa"))).dynamicType(), // address[1][1]
    is(false));
    assertThat(new StaticArray1<Utf8String>(new Utf8String("")).dynamicType(), // string[1]
    is(true));
    assertThat(new DynamicArray<Utf8String>(new Utf8String("")).dynamicType(), // string[]
    is(true));
    assertThat(new DynamicArray<DynamicArray<Utf8String>>(new DynamicArray<Utf8String>(new Utf8String("0xb87213121fb89cbd8b877cb1bb3ff84dd2869cfa"))).dynamicType(), // string[][]
    is(true));
    assertThat(new StaticArray1<DynamicArray<Utf8String>>(new DynamicArray<Utf8String>(new Utf8String("0xb87213121fb89cbd8b877cb1bb3ff84dd2869cfa"))).dynamicType(), // string[][1]
    is(true));
    assertThat(new DynamicArray<StaticArray1<Utf8String>>(new StaticArray1<Utf8String>(new Utf8String("0xb87213121fb89cbd8b877cb1bb3ff84dd2869cfa"))).dynamicType(), // string[1][]
    is(true));
    assertThat(new StaticArray1<StaticArray1<Utf8String>>(new StaticArray1<Utf8String>(new Utf8String("0xb87213121fb89cbd8b877cb1bb3ff84dd2869cfa"))).dynamicType(), // string[1][1]
    is(true));
    assertThat(new StaticArray1<DynamicBytes>(new DynamicBytes("aa".getBytes())).dynamicType(), // bytes[1]
    is(true));
    assertThat(new DynamicArray<DynamicBytes>(new DynamicBytes("".getBytes())).dynamicType(), // bytes[]
    is(true));
    assertThat(new DynamicArray<DynamicArray<DynamicBytes>>(new DynamicArray<DynamicBytes>(new DynamicBytes("0xb87213121fb89cbd8b877cb1bb3ff84dd2869cfa".getBytes()))).dynamicType(), // bytes[][]
    is(true));
    assertThat(new StaticArray1<DynamicArray<DynamicBytes>>(new DynamicArray<DynamicBytes>(new DynamicBytes("0xb87213121fb89cbd8b877cb1bb3ff84dd2869cfa".getBytes()))).dynamicType(), // bytes[][1]
    is(true));
    assertThat(new DynamicArray<StaticArray1<DynamicBytes>>(new StaticArray1<DynamicBytes>(new DynamicBytes("0xb87213121fb89cbd8b877cb1bb3ff84dd2869cfa".getBytes()))).dynamicType(), // bytes[1][]
    is(true));
    assertThat(new StaticArray1<StaticArray1<DynamicBytes>>(new StaticArray1<DynamicBytes>(new DynamicBytes("0xb87213121fb89cbd8b877cb1bb3ff84dd2869cfa".getBytes()))).dynamicType(), // bytes[1][1]
    is(true));
}
Also used : Address(org.fisco.bcos.web3j.abi.datatypes.Address) Bytes10(org.fisco.bcos.web3j.abi.datatypes.generated.Bytes10) Utf8String(org.fisco.bcos.web3j.abi.datatypes.Utf8String) Int256(org.fisco.bcos.web3j.abi.datatypes.generated.Int256) DynamicBytes(org.fisco.bcos.web3j.abi.datatypes.DynamicBytes) Bool(org.fisco.bcos.web3j.abi.datatypes.Bool) DynamicArray(org.fisco.bcos.web3j.abi.datatypes.DynamicArray) Bytes3(org.fisco.bcos.web3j.abi.datatypes.generated.Bytes3) Bytes1(org.fisco.bcos.web3j.abi.datatypes.generated.Bytes1) Uint256(org.fisco.bcos.web3j.abi.datatypes.generated.Uint256) StaticArray1(org.fisco.bcos.web3j.abi.datatypes.generated.StaticArray1) Test(org.junit.Test)

Aggregations

Bytes10 (org.fisco.bcos.web3j.abi.datatypes.generated.Bytes10)8 Test (org.junit.Test)8 Uint256 (org.fisco.bcos.web3j.abi.datatypes.generated.Uint256)7 Bytes3 (org.fisco.bcos.web3j.abi.datatypes.generated.Bytes3)4 Uint32 (org.fisco.bcos.web3j.abi.datatypes.generated.Uint32)4 Int256 (org.fisco.bcos.web3j.abi.datatypes.generated.Int256)3 Address (org.fisco.bcos.web3j.abi.datatypes.Address)2 Bool (org.fisco.bcos.web3j.abi.datatypes.Bool)2 DynamicArray (org.fisco.bcos.web3j.abi.datatypes.DynamicArray)2 DynamicBytes (org.fisco.bcos.web3j.abi.datatypes.DynamicBytes)2 Utf8String (org.fisco.bcos.web3j.abi.datatypes.Utf8String)2 Bytes1 (org.fisco.bcos.web3j.abi.datatypes.generated.Bytes1)2 StaticArray1 (org.fisco.bcos.web3j.abi.datatypes.generated.StaticArray1)2 StaticArray2 (org.fisco.bcos.web3j.abi.datatypes.generated.StaticArray2)2 StaticArray3 (org.fisco.bcos.web3j.abi.datatypes.generated.StaticArray3)2