Repository: LFDT-web3j/web3j (Java)

Issue:
BytesType.bytes32PaddedLength() returns incorrect value for lengths greater than 32 and multiples of 32
# _Issue_title_
`BytesType.bytes32PaddedLength()` returns incorrect value for lengths greater than 32 and multiples of 32.

## _Issue_description_
[BytesType::bytes32PaddedLength‎](https://github.com/hyperledger/web3j/blob/main/abi/src/main/java/org/web3j/abi/datatypes/BytesType.java#L29)
```java
    @Override
    public int bytes32PaddedLength() {
        return value.length <= 32
                ? MAX_BYTE_LENGTH
                : (value.length / MAX_BYTE_LENGTH + 1) * MAX_BYTE_LENGTH;
    }
```
In case of the `value.length` is 64, 96, 128, ...
It should return 64, 96, 128, ...
However, the results are 96, 128, 160, ...

## _Issue_context_
The corrected code is as follows:
```java
    @Override
    public int bytes32PaddedLength() {
        if (value.length < MAX_BYTE_LENGTH) {
            return MAX_BYTE_LENGTH;
        } else if (value.length % MAX_BYTE_LENGTH == 0) {
            return value.length;
        } else {
            return (value.length / MAX_BYTE_LENGTH + 1) * MAX_BYTE_LENGTH;
        }
    }
```
If it looks fine, I will create a pull request.




Fix (patch):
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<MethodSpec> 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());