diff --git a/CHANGELOG.md b/CHANGELOG.md index b8049f2f8..a526e3316 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,8 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline ### Bug Fixes -* Bug fix for Int256 decode range [2^248, type(int256).max] and [ type(int256.min), -(2^248) ) +* Bug fix for Int256 decode range [#2070](https://github.com/hyperledger/web3j/pull/2070) +* Bug fix for BytesType.bytes32PaddedLength [#2089](https://github.com/hyperledger/web3j/pull/2089) ### Features diff --git a/abi/src/main/java/org/web3j/abi/datatypes/BytesType.java b/abi/src/main/java/org/web3j/abi/datatypes/BytesType.java index 4d83a2b52..d56771bb8 100644 --- a/abi/src/main/java/org/web3j/abi/datatypes/BytesType.java +++ b/abi/src/main/java/org/web3j/abi/datatypes/BytesType.java @@ -27,9 +27,12 @@ public BytesType(byte[] src, String type) { @Override public int bytes32PaddedLength() { - return value.length <= 32 - ? MAX_BYTE_LENGTH - : (value.length / MAX_BYTE_LENGTH + 1) * MAX_BYTE_LENGTH; + if (value.length < MAX_BYTE_LENGTH) { + return MAX_BYTE_LENGTH; + } else if (value.length % MAX_BYTE_LENGTH == 0) { + return value.length; + } + return (value.length / MAX_BYTE_LENGTH + 1) * MAX_BYTE_LENGTH; } @Override diff --git a/codegen/src/main/java/org/web3j/codegen/SolidityFunctionWrapper.java b/codegen/src/main/java/org/web3j/codegen/SolidityFunctionWrapper.java index 4093f668b..674d24ac9 100644 --- a/codegen/src/main/java/org/web3j/codegen/SolidityFunctionWrapper.java +++ b/codegen/src/main/java/org/web3j/codegen/SolidityFunctionWrapper.java @@ -1506,7 +1506,10 @@ List buildFunctions( // Create function that returns the ABI encoding of the Solidity function call. if (abiFuncs) { functionName = "getABI_" + functionName; - methodBuilder = MethodSpec.methodBuilder(functionName).addModifiers(Modifier.PUBLIC).addModifiers(Modifier.STATIC); + methodBuilder = + MethodSpec.methodBuilder(functionName) + .addModifiers(Modifier.PUBLIC) + .addModifiers(Modifier.STATIC); addParameters(methodBuilder, functionDefinition.getInputs()); buildAbiFunction(functionDefinition, methodBuilder, inputParams, useUpperCase); results.add(methodBuilder.build()); diff --git a/codegen/src/test/java/org/web3j/codegen/SolidityFunctionWrapperGeneratorTest.java b/codegen/src/test/java/org/web3j/codegen/SolidityFunctionWrapperGeneratorTest.java index abf7c2ae3..efab656f8 100644 --- a/codegen/src/test/java/org/web3j/codegen/SolidityFunctionWrapperGeneratorTest.java +++ b/codegen/src/test/java/org/web3j/codegen/SolidityFunctionWrapperGeneratorTest.java @@ -62,8 +62,9 @@ public void testGetFileNoExtension() { @Test public void testAbiFuncsGeneration() throws Exception { - testCodeGeneration(emptyList(),"abifuncs", "AbiFuncs", JAVA_TYPES_ARG, true, false, true); - testCodeGeneration(emptyList(),"abifuncs", "AbiFuncs", SOLIDITY_TYPES_ARG, true, false, true); + testCodeGeneration(emptyList(), "abifuncs", "AbiFuncs", JAVA_TYPES_ARG, true, false, true); + testCodeGeneration( + emptyList(), "abifuncs", "AbiFuncs", SOLIDITY_TYPES_ARG, true, false, true); } @Test @@ -268,11 +269,18 @@ public void testStaticArrayOfStructsInStructGenerationCompareJavaFile() throws E compareJavaFile("StaticArrayOfStructsInStruct", true, false); } - private void compareJavaFile(String inputFileName, boolean useBin, boolean abiFuncs) throws Exception { + private void compareJavaFile(String inputFileName, boolean useBin, boolean abiFuncs) + throws Exception { String contract = inputFileName.toLowerCase(); String packagePath = generateCode( - emptyList(), contract, inputFileName, JAVA_TYPES_ARG, useBin, false, abiFuncs); + emptyList(), + contract, + inputFileName, + JAVA_TYPES_ARG, + useBin, + false, + abiFuncs); File fileActual = new File(tempDirPath, packagePath + "/" + inputFileName + ".java"); File fileExpected = new File(