@Test public void testBuildFuncNameConstants() throws Exception { AbiDefinition functionDefinition = new AbiDefinition( false, Arrays.asList( new AbiDefinition.NamedType("param", "uint8")), "functionName", Collections.emptyList(), "function", true); TypeSpec.Builder builder = TypeSpec.classBuilder("testClass"); builder.addFields(solidityFunctionWrapper .buildFuncNameConstants(Collections.singletonList(functionDefinition))); //CHECKSTYLE:OFF String expected = "class testClass {\n" + " public static final java.lang.String FUNC_FUNCTIONNAME = \"functionName\";\n" + "}\n"; //CHECKSTYLE:ON assertThat(builder.build().toString(), is(expected)); }
@Test public void testBuildFunctionConstantInvalid() throws Exception { AbiDefinition functionDefinition = new AbiDefinition( true, Arrays.asList( new AbiDefinition.NamedType("param", "uint8")), "functionName", Collections.emptyList(), "type", false); MethodSpec methodSpec = solidityFunctionWrapper.buildFunction(functionDefinition); //CHECKSTYLE:OFF String expected = "public void functionName(java.math.BigInteger param) {\n" + " throw new RuntimeException(\"cannot call constant function with void return type\");\n" + "}\n"; //CHECKSTYLE:ON assertThat(methodSpec.toString(), is(expected)); }
@Test public void testBuildPayableFunctionTransaction() throws Exception { AbiDefinition functionDefinition = new AbiDefinition( false, Arrays.asList( new AbiDefinition.NamedType("param", "uint8")), "functionName", Collections.emptyList(), "type", true); MethodSpec methodSpec = solidityFunctionWrapper.buildFunction(functionDefinition); //CHECKSTYLE:OFF String expected = "public org.web3j.protocol.core.RemoteCall<org.web3j.protocol.core.methods.response.TransactionReceipt> functionName(java.math.BigInteger param, java.math.BigInteger weiValue) {\n" + " final org.web3j.abi.datatypes.Function function = new org.web3j.abi.datatypes.Function(\n" + " FUNC_FUNCTIONNAME, \n" + " java.util.Arrays.<org.web3j.abi.datatypes.Type>asList(new org.web3j.abi.datatypes.generated.Uint8(param)), \n" + " java.util.Collections.<org.web3j.abi.TypeReference<?>>emptyList());\n" + " return executeRemoteCallTransaction(function, weiValue);\n" + "}\n"; //CHECKSTYLE:ON assertThat(methodSpec.toString(), is(expected)); }
@Test public void testBuildingFunctionTransactionThatReturnsValueReportsWarning() throws Exception { AbiDefinition functionDefinition = new AbiDefinition( false, Arrays.asList( new AbiDefinition.NamedType("param", "uint8")), "functionName", Arrays.asList( new AbiDefinition.NamedType("result", "uint8")), "type", false); solidityFunctionWrapper.buildFunction(functionDefinition); //CHECKSTYLE:OFF verify(generationReporter).report( "Definition of the function functionName returns a value but is not defined as a view function. " + "Please ensure it contains the view modifier if you want to read the return value"); //CHECKSTYLE:ON }
@Test public void testBuildFunctionTransaction() throws Exception { AbiDefinition functionDefinition = new AbiDefinition( false, Arrays.asList( new AbiDefinition.NamedType("param", "uint8")), "functionName", Collections.emptyList(), "type", false); MethodSpec methodSpec = solidityFunctionWrapper.buildFunction(functionDefinition); //CHECKSTYLE:OFF String expected = "public org.web3j.protocol.core.RemoteCall<org.web3j.protocol.core.methods.response.TransactionReceipt> functionName(java.math.BigInteger param) {\n" + " final org.web3j.abi.datatypes.Function function = new org.web3j.abi.datatypes.Function(\n" + " FUNC_FUNCTIONNAME, \n" + " java.util.Arrays.<org.web3j.abi.datatypes.Type>asList(new org.web3j.abi.datatypes.generated.Uint8(param)), \n" + " java.util.Collections.<org.web3j.abi.TypeReference<?>>emptyList());\n" + " return executeRemoteCallTransaction(function);\n" + "}\n"; //CHECKSTYLE:ON assertThat(methodSpec.toString(), is(expected)); }
@Test public void testBuildFunctionConstantSingleValueReturn() throws Exception { AbiDefinition functionDefinition = new AbiDefinition( true, Arrays.asList( new AbiDefinition.NamedType("param", "uint8")), "functionName", Arrays.asList( new AbiDefinition.NamedType("result", "int8")), "type", false); MethodSpec methodSpec = solidityFunctionWrapper.buildFunction(functionDefinition); //CHECKSTYLE:OFF String expected = "public org.web3j.protocol.core.RemoteCall<java.math.BigInteger> functionName(java.math.BigInteger param) {\n" + " final org.web3j.abi.datatypes.Function function = new org.web3j.abi.datatypes.Function(FUNC_FUNCTIONNAME, \n" + " java.util.Arrays.<org.web3j.abi.datatypes.Type>asList(new org.web3j.abi.datatypes.generated.Uint8(param)), \n" + " java.util.Arrays.<org.web3j.abi.TypeReference<?>>asList(new org.web3j.abi.TypeReference<org.web3j.abi.datatypes.generated.Int8>() {}));\n" + " return executeRemoteCallSingleValueReturn(function, java.math.BigInteger.class);\n" + "}\n"; //CHECKSTYLE:ON assertThat(methodSpec.toString(), is(expected)); }
@Test public void testBuildFunctionConstantSingleValueRawListReturn() throws Exception { AbiDefinition functionDefinition = new AbiDefinition( true, Arrays.asList(
toAddress.setIndexed(true); AbiDefinition functionDefinition = new AbiDefinition( false, Arrays.asList(id, fromAddress, toAddress, value, message),
@Test public void testBuildFunctionConstantMultipleValueReturn() throws Exception { AbiDefinition functionDefinition = new AbiDefinition( true, Arrays.asList(
"--bin --abi --userdoc --devdoc --add-std --optimize -o " + "/var/folders/3m/_6gnl12n1tj_5kf7sc3d72dw0000gn/T/solc498936951", Arrays.asList(new AbiDefinition( false, Arrays.asList(new AbiDefinition.NamedType("a", "uint256")),