Skip to content

Commit 177e2c2

Browse files
committed
add fix
Signed-off-by: gtebrean <[email protected]>
1 parent bb9dc1c commit 177e2c2

File tree

4 files changed

+24
-9
lines changed

4 files changed

+24
-9
lines changed

CHANGELOG.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline
77

88
### Bug Fixes
99

10-
* Bug fix for Int256 decode range [2^248, type(int256).max] and [ type(int256.min), -(2^248) )
10+
* Bug fix for Int256 decode range [#2070](https://github.com/hyperledger/web3j/pull/2070)
11+
* Bug fix for BytesType.bytes32PaddedLength
1112

1213
### Features
1314

abi/src/main/java/org/web3j/abi/datatypes/BytesType.java

+6-3
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,12 @@ public BytesType(byte[] src, String type) {
2727

2828
@Override
2929
public int bytes32PaddedLength() {
30-
return value.length <= 32
31-
? MAX_BYTE_LENGTH
32-
: (value.length / MAX_BYTE_LENGTH + 1) * MAX_BYTE_LENGTH;
30+
if (value.length < MAX_BYTE_LENGTH) {
31+
return MAX_BYTE_LENGTH;
32+
} else if (value.length % MAX_BYTE_LENGTH == 0) {
33+
return value.length;
34+
}
35+
return (value.length / MAX_BYTE_LENGTH + 1) * MAX_BYTE_LENGTH;
3336
}
3437

3538
@Override

codegen/src/main/java/org/web3j/codegen/SolidityFunctionWrapper.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -1506,7 +1506,10 @@ List<MethodSpec> buildFunctions(
15061506
// Create function that returns the ABI encoding of the Solidity function call.
15071507
if (abiFuncs) {
15081508
functionName = "getABI_" + functionName;
1509-
methodBuilder = MethodSpec.methodBuilder(functionName).addModifiers(Modifier.PUBLIC).addModifiers(Modifier.STATIC);
1509+
methodBuilder =
1510+
MethodSpec.methodBuilder(functionName)
1511+
.addModifiers(Modifier.PUBLIC)
1512+
.addModifiers(Modifier.STATIC);
15101513
addParameters(methodBuilder, functionDefinition.getInputs());
15111514
buildAbiFunction(functionDefinition, methodBuilder, inputParams, useUpperCase);
15121515
results.add(methodBuilder.build());

codegen/src/test/java/org/web3j/codegen/SolidityFunctionWrapperGeneratorTest.java

+12-4
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,9 @@ public void testGetFileNoExtension() {
6262

6363
@Test
6464
public void testAbiFuncsGeneration() throws Exception {
65-
testCodeGeneration(emptyList(),"abifuncs", "AbiFuncs", JAVA_TYPES_ARG, true, false, true);
66-
testCodeGeneration(emptyList(),"abifuncs", "AbiFuncs", SOLIDITY_TYPES_ARG, true, false, true);
65+
testCodeGeneration(emptyList(), "abifuncs", "AbiFuncs", JAVA_TYPES_ARG, true, false, true);
66+
testCodeGeneration(
67+
emptyList(), "abifuncs", "AbiFuncs", SOLIDITY_TYPES_ARG, true, false, true);
6768
}
6869

6970
@Test
@@ -268,11 +269,18 @@ public void testStaticArrayOfStructsInStructGenerationCompareJavaFile() throws E
268269
compareJavaFile("StaticArrayOfStructsInStruct", true, false);
269270
}
270271

271-
private void compareJavaFile(String inputFileName, boolean useBin, boolean abiFuncs) throws Exception {
272+
private void compareJavaFile(String inputFileName, boolean useBin, boolean abiFuncs)
273+
throws Exception {
272274
String contract = inputFileName.toLowerCase();
273275
String packagePath =
274276
generateCode(
275-
emptyList(), contract, inputFileName, JAVA_TYPES_ARG, useBin, false, abiFuncs);
277+
emptyList(),
278+
contract,
279+
inputFileName,
280+
JAVA_TYPES_ARG,
281+
useBin,
282+
false,
283+
abiFuncs);
276284
File fileActual = new File(tempDirPath, packagePath + "/" + inputFileName + ".java");
277285
File fileExpected =
278286
new File(

0 commit comments

Comments
 (0)