Skip to content

Commit

Permalink
fix for test wrappers generation for getDeploymentBinary
Browse files Browse the repository at this point in the history
Signed-off-by: Nischal Sharma <[email protected]>
  • Loading branch information
NickSneo committed Apr 1, 2024
1 parent 16b133b commit e01e726
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 5 deletions.
15 changes: 10 additions & 5 deletions codegen/src/main/java/org/web3j/codegen/unit/gen/MethodFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,11 @@ public static List<MethodSpec> generateMethodSpecsForEachTest(Class theContract)
.forEach(
method -> {
String uniqueName = getUniqueName(method, methodNameCountMap);
listOfMethodSpecs.add(
new MethodParser(method, theContract, uniqueName)
.getMethodSpec());
if (!uniqueName.startsWith("getDeploymentBinary")) {
listOfMethodSpecs.add(
new MethodParser(method, theContract, uniqueName)
.getMethodSpec());
}
});

return listOfMethodSpecs;
Expand All @@ -76,8 +78,11 @@ public static List<FunSpec> generateFunctionSpecsForEachTest(Class theContract)
.forEach(
method -> {
String uniqueName = getUniqueName(method, functionNameCountMap);
listOfFunSpecs.add(
new FunParser(method, theContract, uniqueName).getFunSpec());
if (!uniqueName.startsWith("getDeploymentBinary")) {
listOfFunSpecs.add(
new FunParser(method, theContract, uniqueName)
.getFunSpec());
}
});

return listOfFunSpecs;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,22 @@ public void testGeneratedDuplicateGreetingMethods() {
greetMethodSpecs.stream().anyMatch(methodSpec -> methodSpec.name.equals("greet1")));
assertEquals(2, greetMethodSpecs.size());
}

@Test
public void testGetDeploymentBinaryMethodNotGenerated() {
List<MethodSpec> allMethodSpecs =
MethodFilter.generateMethodSpecsForEachTest(greeterContractClass);

// Filter all MethodSpecs for those related to "getDeploymentBinary" method
List<MethodSpec> getDeploymentBinaryMethodSpecs =
allMethodSpecs.stream()
.filter(methodSpec -> methodSpec.name.startsWith("getDeploymentBinary"))
.collect(Collectors.toList());

// Ensure no MethodSpecs were generated for getDeploymentBinary method
assertEquals(
0,
getDeploymentBinaryMethodSpecs.size(),
"MethodSpec list should not contain getDeploymentBinary method");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,22 @@ public void testGeneratedDuplicateGreetingMethods() {
.anyMatch(methodSpec -> methodSpec.getName().equals("greet1")));
assertEquals(2, greetFunSpecs.size());
}

@Test
public void testGetDeploymentBinaryMethodNotGenerated() {
List<FunSpec> allMethodSpecs =
MethodFilter.generateFunctionSpecsForEachTest(greeterContractClass);

// Filter all FunSpecs for those related to "getDeploymentBinary" method
List<FunSpec> getDeploymentBinaryFunSpecs =
allMethodSpecs.stream()
.filter(funSpec -> funSpec.getName().startsWith("getDeploymentBinary"))
.collect(Collectors.toList());

// Ensure no MethodSpecs were generated for getDeploymentBinary method
assertEquals(
0,
getDeploymentBinaryFunSpecs.size(),
"MethodSpec list should not contain getDeploymentBinary function");
}
}

0 comments on commit e01e726

Please sign in to comment.