use of org.fisco.bcos.web3j.abi.datatypes.generated.Bytes10 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"));
}
use of org.fisco.bcos.web3j.abi.datatypes.generated.Bytes10 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)"));
}
use of org.fisco.bcos.web3j.abi.datatypes.generated.Bytes10 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"));
}
use of org.fisco.bcos.web3j.abi.datatypes.generated.Bytes10 in project web3sdk by FISCO-BCOS.
the class FunctionReturnDecoderTest method testMixTypeDecode10.
@Test
public void testMixTypeDecode10() {
// function baz(uint32,bool)
Function function0 = new Function("baz", Collections.<Type>emptyList(), Arrays.asList(new TypeReference<Uint32>() {
}, new TypeReference<Bool>() {
}));
assertThat(FunctionReturnDecoder.decode("0000000000000000000000000000000000000000000000000000000000000045" + "0000000000000000000000000000000000000000000000000000000000000001", function0.getOutputParameters()), equalTo(Arrays.asList(new Uint32(69), new Bool(true))));
// function baz(uint32[2])
Function function1 = new Function("bar", Collections.<Type>emptyList(), Arrays.asList(new TypeReference<StaticArray2<Bytes3>>() {
}));
assertThat(FunctionReturnDecoder.decode("6162630000000000000000000000000000000000000000000000000000000000" + "6465660000000000000000000000000000000000000000000000000000000000", function1.getOutputParameters()), equalTo(Arrays.asList(new StaticArray2<Bytes3>(new Bytes3("abc".getBytes()), new Bytes3("def".getBytes())))));
// function sam(bytes,bool,uint[])
Function function2 = new Function("sam", Collections.<Type>emptyList(), Arrays.asList(new TypeReference<DynamicBytes>() {
}, new TypeReference<Bool>() {
}, new TypeReference<DynamicArray<Uint256>>() {
}));
assertThat(FunctionReturnDecoder.decode("0000000000000000000000000000000000000000000000000000000000000060" + "0000000000000000000000000000000000000000000000000000000000000001" + "00000000000000000000000000000000000000000000000000000000000000a0" + "0000000000000000000000000000000000000000000000000000000000000004" + "6461766500000000000000000000000000000000000000000000000000000000" + "0000000000000000000000000000000000000000000000000000000000000003" + "0000000000000000000000000000000000000000000000000000000000000001" + "0000000000000000000000000000000000000000000000000000000000000002" + "0000000000000000000000000000000000000000000000000000000000000003", function2.getOutputParameters()), equalTo(Arrays.asList(new DynamicBytes("dave".getBytes()), new Bool(true), new DynamicArray<Uint256>(new Uint256(1), new Uint256(2), new Uint256(3)))));
// function f(uint,uint32[],bytes10,bytes)
Function function3 = new Function("f", Collections.<Type>emptyList(), Arrays.asList(new TypeReference<Uint256>() {
}, new TypeReference<DynamicArray<Uint32>>() {
}, new TypeReference<Bytes10>() {
}, new TypeReference<DynamicBytes>() {
}));
assertThat(FunctionReturnDecoder.decode("0000000000000000000000000000000000000000000000000000000000000123" + "0000000000000000000000000000000000000000000000000000000000000080" + "3132333435363738393000000000000000000000000000000000000000000000" + "00000000000000000000000000000000000000000000000000000000000000e0" + "0000000000000000000000000000000000000000000000000000000000000002" + "0000000000000000000000000000000000000000000000000000000000000456" + "0000000000000000000000000000000000000000000000000000000000000789" + "000000000000000000000000000000000000000000000000000000000000000d" + "48656c6c6f2c20776f726c642100000000000000000000000000000000000000", function3.getOutputParameters()), equalTo(Arrays.asList(new Uint256(0x123), new DynamicArray<Uint32>(new Uint32(0x456), new Uint32(0x789)), new Bytes10("1234567890".getBytes()), new DynamicBytes("Hello, world!".getBytes()))));
// function g(uint[][],string[])
Function function4 = new Function("g", Collections.<Type>emptyList(), Arrays.asList(new TypeReference<DynamicArray<DynamicArray<Uint256>>>() {
}, new TypeReference<DynamicArray<Utf8String>>() {
}));
assertThat(FunctionReturnDecoder.decode("0000000000000000000000000000000000000000000000000000000000000040" + "0000000000000000000000000000000000000000000000000000000000000140" + "0000000000000000000000000000000000000000000000000000000000000002" + "0000000000000000000000000000000000000000000000000000000000000040" + "00000000000000000000000000000000000000000000000000000000000000a0" + "0000000000000000000000000000000000000000000000000000000000000002" + "0000000000000000000000000000000000000000000000000000000000000001" + "0000000000000000000000000000000000000000000000000000000000000002" + "0000000000000000000000000000000000000000000000000000000000000001" + "0000000000000000000000000000000000000000000000000000000000000003" + "0000000000000000000000000000000000000000000000000000000000000003" + "0000000000000000000000000000000000000000000000000000000000000060" + "00000000000000000000000000000000000000000000000000000000000000a0" + "00000000000000000000000000000000000000000000000000000000000000e0" + "0000000000000000000000000000000000000000000000000000000000000003" + "6f6e650000000000000000000000000000000000000000000000000000000000" + "0000000000000000000000000000000000000000000000000000000000000003" + "74776f0000000000000000000000000000000000000000000000000000000000" + "0000000000000000000000000000000000000000000000000000000000000005" + "7468726565000000000000000000000000000000000000000000000000000000", function4.getOutputParameters()), equalTo(Arrays.asList(new DynamicArray<DynamicArray<Uint256>>(new DynamicArray<Uint256>(new Uint256(1), new Uint256(2)), new DynamicArray<Uint256>(new Uint256(3))), new DynamicArray<Utf8String>(new Utf8String("one"), new Utf8String("two"), new Utf8String("three")))));
}
use of org.fisco.bcos.web3j.abi.datatypes.generated.Bytes10 in project web3sdk by FISCO-BCOS.
the class FunctionReturnDecoderTest method testMixTypeDecode1.
@Test
public void testMixTypeDecode1() {
// function function() constant
// returns(uint256,uint256[],uint256,bytes10,string)
Function function = new Function("function", Collections.<Type>emptyList(), Arrays.asList(new TypeReference<Uint256>() {
}, new TypeReference<DynamicArray<Uint256>>() {
}, new TypeReference<Bytes10>() {
}, new TypeReference<Utf8String>() {
}));
assertThat(FunctionReturnDecoder.decode("0000000000000000000000000000000000000000000000000000000000000123" + "0000000000000000000000000000000000000000000000000000000000000080" + "3132333435363738393000000000000000000000000000000000000000000000" + "00000000000000000000000000000000000000000000000000000000000000e0" + "0000000000000000000000000000000000000000000000000000000000000002" + "0000000000000000000000000000000000000000000000000000000000000456" + "0000000000000000000000000000000000000000000000000000000000000789" + "000000000000000000000000000000000000000000000000000000000000000d" + "48656c6c6f2c20776f726c642100000000000000000000000000000000000000", function.getOutputParameters()), equalTo(Arrays.asList(new Uint256(291), new DynamicArray<Uint256>(new Uint256(1110), new Uint256(1929)), new Bytes10("1234567890".getBytes()), new Utf8String("Hello, world!"))));
}
Aggregations