Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix for #2080 #2089

Merged
merged 2 commits into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading