Search in sources :

Example 1 with Uint32

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

the class FunctionEncoderTest method testMixTypeEncode9.

@Test
public void testMixTypeEncode9() {
    // function baz(uint32,bool)
    Function function0 = new Function("baz", Arrays.asList(new Uint32(69), new Bool(true)), Collections.singletonList(new TypeReference<DynamicArray<Utf8String>>() {
    }));
    assertThat(FunctionEncoder.encode(function0), is("0xcdcd77c0" + "0000000000000000000000000000000000000000000000000000000000000045" + "0000000000000000000000000000000000000000000000000000000000000001"));
    // function baz(bytes3[2])
    Function function1 = new Function("bar", Arrays.asList(new StaticArray2<Bytes3>(new Bytes3("abc".getBytes()), new Bytes3("def".getBytes()))), Collections.singletonList(new TypeReference<DynamicArray<Utf8String>>() {
    }));
    assertThat(FunctionEncoder.encode(function1), is("0xfce353f6" + "6162630000000000000000000000000000000000000000000000000000000000" + "6465660000000000000000000000000000000000000000000000000000000000"));
    // function sam(bytes,bool,uint[])
    Function function2 = new Function("sam", Arrays.asList(new DynamicBytes("dave".getBytes()), new Bool(true), new DynamicArray<Uint256>(new Uint256(1), new Uint256(2), new Uint256(3))), Collections.singletonList(new TypeReference<DynamicArray<Utf8String>>() {
    }));
    assertThat(FunctionEncoder.encode(function2), is("0xa5643bf2" + "0000000000000000000000000000000000000000000000000000000000000060" + "0000000000000000000000000000000000000000000000000000000000000001" + "00000000000000000000000000000000000000000000000000000000000000a0" + "0000000000000000000000000000000000000000000000000000000000000004" + "6461766500000000000000000000000000000000000000000000000000000000" + "0000000000000000000000000000000000000000000000000000000000000003" + "0000000000000000000000000000000000000000000000000000000000000001" + "0000000000000000000000000000000000000000000000000000000000000002" + "0000000000000000000000000000000000000000000000000000000000000003"));
    // function f(uint,uint32[],bytes10,bytes)
    Function function3 = new Function("f", Arrays.asList(new Uint256(0x123), new DynamicArray<Uint32>(new Uint32(0x456), new Uint32(0x789)), new Bytes10("1234567890".getBytes()), new DynamicBytes("Hello, world!".getBytes())), Collections.singletonList(new TypeReference<DynamicArray<Utf8String>>() {
    }));
    assertThat(FunctionEncoder.encode(function3), is("0x8be65246" + "0000000000000000000000000000000000000000000000000000000000000123" + "0000000000000000000000000000000000000000000000000000000000000080" + "3132333435363738393000000000000000000000000000000000000000000000" + "00000000000000000000000000000000000000000000000000000000000000e0" + "0000000000000000000000000000000000000000000000000000000000000002" + "0000000000000000000000000000000000000000000000000000000000000456" + "0000000000000000000000000000000000000000000000000000000000000789" + "000000000000000000000000000000000000000000000000000000000000000d" + "48656c6c6f2c20776f726c642100000000000000000000000000000000000000"));
    // function g(uint[][],string[])
    Function function4 = new Function("g", 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"))), Collections.singletonList(new TypeReference<DynamicArray<Utf8String>>() {
    }));
    assertThat(FunctionEncoder.encode(function4), is("0x2289b18c" + "0000000000000000000000000000000000000000000000000000000000000040" + "0000000000000000000000000000000000000000000000000000000000000140" + "0000000000000000000000000000000000000000000000000000000000000002" + "0000000000000000000000000000000000000000000000000000000000000040" + "00000000000000000000000000000000000000000000000000000000000000a0" + "0000000000000000000000000000000000000000000000000000000000000002" + "0000000000000000000000000000000000000000000000000000000000000001" + "0000000000000000000000000000000000000000000000000000000000000002" + "0000000000000000000000000000000000000000000000000000000000000001" + "0000000000000000000000000000000000000000000000000000000000000003" + "0000000000000000000000000000000000000000000000000000000000000003" + "0000000000000000000000000000000000000000000000000000000000000060" + "00000000000000000000000000000000000000000000000000000000000000a0" + "00000000000000000000000000000000000000000000000000000000000000e0" + "0000000000000000000000000000000000000000000000000000000000000003" + "6f6e650000000000000000000000000000000000000000000000000000000000" + "0000000000000000000000000000000000000000000000000000000000000003" + "74776f0000000000000000000000000000000000000000000000000000000000" + "0000000000000000000000000000000000000000000000000000000000000005" + "7468726565000000000000000000000000000000000000000000000000000000"));
}
Also used : Bytes3(org.fisco.bcos.web3j.abi.datatypes.generated.Bytes3) Uint256(org.fisco.bcos.web3j.abi.datatypes.generated.Uint256) StaticArray2(org.fisco.bcos.web3j.abi.datatypes.generated.StaticArray2) Bytes10(org.fisco.bcos.web3j.abi.datatypes.generated.Bytes10) Uint32(org.fisco.bcos.web3j.abi.datatypes.generated.Uint32) Test(org.junit.Test)

Example 2 with Uint32

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

the class FunctionEncoderTest method testBuildMessageSignature.

@Test
public void testBuildMessageSignature() {
    assertThat(FunctionEncoder.buildMethodSignature("empty", Collections.emptyList()), is("empty()"));
    assertThat(FunctionEncoder.buildMethodSignature("baz", Arrays.asList(new Uint32(BigInteger.valueOf(69)), new Bool(true))), is("baz(uint32,bool)"));
    assertThat(FunctionEncoder.buildMethodSignature("test", 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")))), is("test(uint256[][],string[])"));
    assertThat(FunctionEncoder.buildMethodSignature("test", Arrays.asList(new Uint256(0x123), new DynamicArray<Uint32>(new Uint32(0x456), new Uint32(0x789)), new Bytes10("1234567890".getBytes()), new DynamicBytes("Hello, world!".getBytes()))), is("test(uint256,uint32[],bytes10,bytes)"));
    assertThat(FunctionEncoder.buildMethodSignature("sam", Arrays.asList(new DynamicBytes("dave".getBytes()), new Bool(true), new DynamicArray<Uint256>(new Uint256(1), new Uint256(2), new Uint256(3)))), is("sam(bytes,bool,uint256[])"));
    Arrays.asList(new DynamicArray<DynamicArray<DynamicArray<DynamicArray<Utf8String>>>>(new DynamicArray(new DynamicArray(new DynamicArray(new Utf8String("adfsafjljkl"), new Utf8String("dsafhjk;jlk;jadfl;kjkl"), new Utf8String("ada"))))));
    assertThat(FunctionEncoder.buildMethodSignature("dave", Arrays.asList(new DynamicArray<DynamicArray<DynamicArray<DynamicArray<Utf8String>>>>(new DynamicArray(new DynamicArray(new DynamicArray(new Utf8String("adfsafjljkl"), new Utf8String("dsafhjk;jlk;jadfl;kjkl"), new Utf8String("ada"))))))), is("dave(string[][][][])"));
    assertThat(FunctionEncoder.buildMethodSignature("test", Arrays.asList(new Uint256(100), new Int256(-100), new Utf8String("abc"), new DynamicArray<Type>(new Utf8String("abc"), new Utf8String("abc"), new Utf8String("abc")), new StaticArray3<Type>(new Utf8String("abc"), new Utf8String("abc"), new Utf8String("abc")))), is("test(uint256,int256,string,string[],string[3])"));
    Arrays.asList(new StaticArray3<>(new DynamicArray<Type>(new Uint256(1)), new DynamicArray<Type>(new Uint256(2), new Uint256(3)), new DynamicArray<Type>(new Uint256(4), new Uint256(5), new Uint256(6))));
    assertThat(FunctionEncoder.buildMethodSignature("test", Arrays.asList(new StaticArray3<>(new DynamicArray<Type>(new Uint256(1)), new DynamicArray<Type>(new Uint256(2), new Uint256(3)), new DynamicArray<Type>(new Uint256(4), new Uint256(5), new Uint256(6))))), is("test(uint256[][3])"));
    assertThat(FunctionEncoder.buildMethodSignature("set", Arrays.asList(new Uint256(123), new Address("0x692a70d2e424a56d2c6c27aa97d1a86395877b3a"), new Utf8String("string c"), new DynamicArray<>(new Uint256(1), new Uint256(2), new Uint256(3)), new StaticArray3<>(new Uint256(4), new Uint256(5), new Uint256(6)), new DynamicArray<>(new Utf8String("abc"), new Utf8String("def"), new Utf8String("ghi")), new StaticArray3<>(new Utf8String("abc"), new Utf8String("def"), new Utf8String("ghi")), new DynamicArray<>(new DynamicArray<>(new Uint256(1), new Uint256(1), new Uint256(1)), new DynamicArray<>(new Uint256(2), new Uint256(2), new Uint256(2)), new DynamicArray<>(new Uint256(3), new Uint256(3), new Uint256(3))), new DynamicArray<>(new StaticArray3<>(new Uint256(4), new Uint256(4), new Uint256(4)), new StaticArray3<>(new Uint256(5), new Uint256(5), new Uint256(5))))), is("set(uint256,address,string,uint256[],uint256[3],string[],string[3],uint256[][],uint256[3][])"));
    assertThat(FunctionEncoder.buildMethodSignature("set", Arrays.asList(new Utf8String("aaafadsfsfadsfdasf"), new Address("0x35ef07393b57464e93deb59175ff72e6499450cf"), new Uint256(11111), new Int256(-11111))), is("set(string,address,uint256,int256)"));
    assertThat(FunctionEncoder.buildMethodSignature("set", 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"))), is("set(string,uint256,uint256[6],uint256[],bool,address)"));
}
Also used : Bytes10(org.fisco.bcos.web3j.abi.datatypes.generated.Bytes10) Int256(org.fisco.bcos.web3j.abi.datatypes.generated.Int256) StaticArray3(org.fisco.bcos.web3j.abi.datatypes.generated.StaticArray3) Uint256(org.fisco.bcos.web3j.abi.datatypes.generated.Uint256) Uint32(org.fisco.bcos.web3j.abi.datatypes.generated.Uint32) Test(org.junit.Test)

Example 3 with Uint32

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

the class FunctionEncoderTest method testFunctionMDynamicArrayEncode2.

@Test
public void testFunctionMDynamicArrayEncode2() {
    Function function = new Function("f", Arrays.asList(new Uint(BigInteger.valueOf(0x123)), new DynamicArray<>(new Uint32(BigInteger.valueOf(0x456)), new Uint32(BigInteger.valueOf(0x789))), new Bytes10("1234567890".getBytes()), new DynamicBytes("Hello, world!".getBytes())), Collections.<TypeReference<?>>emptyList());
    assertThat(FunctionEncoder.encode(function), is("0x8be65246" + "0000000000000000000000000000000000000000000000000000000000000123" + "0000000000000000000000000000000000000000000000000000000000000080" + "3132333435363738393000000000000000000000000000000000000000000000" + "00000000000000000000000000000000000000000000000000000000000000e0" + "0000000000000000000000000000000000000000000000000000000000000002" + "0000000000000000000000000000000000000000000000000000000000000456" + "0000000000000000000000000000000000000000000000000000000000000789" + "000000000000000000000000000000000000000000000000000000000000000d" + "48656c6c6f2c20776f726c642100000000000000000000000000000000000000"));
}
Also used : Bytes10(org.fisco.bcos.web3j.abi.datatypes.generated.Bytes10) Uint32(org.fisco.bcos.web3j.abi.datatypes.generated.Uint32) Test(org.junit.Test)

Example 4 with Uint32

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

the class EventEncoderTest method testEventbuildMethodSignature1.

@Test
public void testEventbuildMethodSignature1() {
    Event event = new Event("f", Arrays.<TypeReference<?>>asList(new TypeReference<Uint>() {
    }, new TypeReference<DynamicArray<Uint32>>() {
    }, new TypeReference<Bytes10>() {
    }, new TypeReference<DynamicBytes>() {
    }));
    assertThat(EventEncoder.buildMethodSignature(event.getName(), event.getParameters()), is("f(uint256,uint32[],bytes10,bytes)"));
    assertThat(EventEncoder.encode(event), is("0x8be652465888a0c5d65fc9d0a7e898b9ca98de97185c53a54ec408fd2fd5d45d"));
    assertThat(EventEncoder.buildEventSignature("f(uint256,uint32[],bytes10,bytes)"), is("0x8be652465888a0c5d65fc9d0a7e898b9ca98de97185c53a54ec408fd2fd5d45d"));
}
Also used : Event(org.fisco.bcos.web3j.abi.datatypes.Event) Uint32(org.fisco.bcos.web3j.abi.datatypes.generated.Uint32) Test(org.junit.Test)

Example 5 with Uint32

use of org.fisco.bcos.web3j.abi.datatypes.generated.Uint32 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")))));
}
Also used : Bytes10(org.fisco.bcos.web3j.abi.datatypes.generated.Bytes10) Bytes3(org.fisco.bcos.web3j.abi.datatypes.generated.Bytes3) Uint256(org.fisco.bcos.web3j.abi.datatypes.generated.Uint256) Uint32(org.fisco.bcos.web3j.abi.datatypes.generated.Uint32) Test(org.junit.Test)

Aggregations

Uint32 (org.fisco.bcos.web3j.abi.datatypes.generated.Uint32)5 Test (org.junit.Test)5 Bytes10 (org.fisco.bcos.web3j.abi.datatypes.generated.Bytes10)4 Uint256 (org.fisco.bcos.web3j.abi.datatypes.generated.Uint256)3 Bytes3 (org.fisco.bcos.web3j.abi.datatypes.generated.Bytes3)2 Event (org.fisco.bcos.web3j.abi.datatypes.Event)1 Int256 (org.fisco.bcos.web3j.abi.datatypes.generated.Int256)1 StaticArray2 (org.fisco.bcos.web3j.abi.datatypes.generated.StaticArray2)1 StaticArray3 (org.fisco.bcos.web3j.abi.datatypes.generated.StaticArray3)1