Skip to content

Commit

Permalink
Merge pull request #2089 from hyperledger/fix/issue-2080
Browse files Browse the repository at this point in the history
Fix for #2080
  • Loading branch information
gtebrean authored Aug 8, 2024
2 parents bb9dc1c + d58099d commit fbcbf82
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 9 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
9 changes: 6 additions & 3 deletions abi/src/main/java/org/web3j/abi/datatypes/BytesType.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit fbcbf82

Please sign in to comment.