Skip to content

Commit e01e726

Browse files
committed
fix for test wrappers generation for getDeploymentBinary
Signed-off-by: Nischal Sharma <[email protected]>
1 parent 16b133b commit e01e726

File tree

3 files changed

+46
-5
lines changed

3 files changed

+46
-5
lines changed

codegen/src/main/java/org/web3j/codegen/unit/gen/MethodFilter.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,11 @@ public static List<MethodSpec> generateMethodSpecsForEachTest(Class theContract)
6161
.forEach(
6262
method -> {
6363
String uniqueName = getUniqueName(method, methodNameCountMap);
64-
listOfMethodSpecs.add(
65-
new MethodParser(method, theContract, uniqueName)
66-
.getMethodSpec());
64+
if (!uniqueName.startsWith("getDeploymentBinary")) {
65+
listOfMethodSpecs.add(
66+
new MethodParser(method, theContract, uniqueName)
67+
.getMethodSpec());
68+
}
6769
});
6870

6971
return listOfMethodSpecs;
@@ -76,8 +78,11 @@ public static List<FunSpec> generateFunctionSpecsForEachTest(Class theContract)
7678
.forEach(
7779
method -> {
7880
String uniqueName = getUniqueName(method, functionNameCountMap);
79-
listOfFunSpecs.add(
80-
new FunParser(method, theContract, uniqueName).getFunSpec());
81+
if (!uniqueName.startsWith("getDeploymentBinary")) {
82+
listOfFunSpecs.add(
83+
new FunParser(method, theContract, uniqueName)
84+
.getFunSpec());
85+
}
8186
});
8287

8388
return listOfFunSpecs;

codegen/src/test/java/org/web3j/codegen/unit/gen/java/MethodParserTest.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,22 @@ public void testGeneratedDuplicateGreetingMethods() {
7373
greetMethodSpecs.stream().anyMatch(methodSpec -> methodSpec.name.equals("greet1")));
7474
assertEquals(2, greetMethodSpecs.size());
7575
}
76+
77+
@Test
78+
public void testGetDeploymentBinaryMethodNotGenerated() {
79+
List<MethodSpec> allMethodSpecs =
80+
MethodFilter.generateMethodSpecsForEachTest(greeterContractClass);
81+
82+
// Filter all MethodSpecs for those related to "getDeploymentBinary" method
83+
List<MethodSpec> getDeploymentBinaryMethodSpecs =
84+
allMethodSpecs.stream()
85+
.filter(methodSpec -> methodSpec.name.startsWith("getDeploymentBinary"))
86+
.collect(Collectors.toList());
87+
88+
// Ensure no MethodSpecs were generated for getDeploymentBinary method
89+
assertEquals(
90+
0,
91+
getDeploymentBinaryMethodSpecs.size(),
92+
"MethodSpec list should not contain getDeploymentBinary method");
93+
}
7694
}

codegen/src/test/java/org/web3j/codegen/unit/gen/kotlin/FunParserTest.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,22 @@ public void testGeneratedDuplicateGreetingMethods() {
7878
.anyMatch(methodSpec -> methodSpec.getName().equals("greet1")));
7979
assertEquals(2, greetFunSpecs.size());
8080
}
81+
82+
@Test
83+
public void testGetDeploymentBinaryMethodNotGenerated() {
84+
List<FunSpec> allMethodSpecs =
85+
MethodFilter.generateFunctionSpecsForEachTest(greeterContractClass);
86+
87+
// Filter all FunSpecs for those related to "getDeploymentBinary" method
88+
List<FunSpec> getDeploymentBinaryFunSpecs =
89+
allMethodSpecs.stream()
90+
.filter(funSpec -> funSpec.getName().startsWith("getDeploymentBinary"))
91+
.collect(Collectors.toList());
92+
93+
// Ensure no MethodSpecs were generated for getDeploymentBinary method
94+
assertEquals(
95+
0,
96+
getDeploymentBinaryFunSpecs.size(),
97+
"MethodSpec list should not contain getDeploymentBinary function");
98+
}
8199
}

0 commit comments

Comments
 (0)