File tree 6 files changed +50
-8
lines changed
main/java/org/web3j/codegen
java/org/web3j/codegen/unit/gen
resources/solidity/metacoin/build/java
6 files changed +50
-8
lines changed Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline
7
7
8
8
### Bug Fixes
9
9
10
- *
10
+ * Fix for test wrappers generation [ # 2025 ] ( https://github.com/web3j/web3j/pull/2025 )
11
11
12
12
### Features
13
13
Original file line number Diff line number Diff line change @@ -672,7 +672,7 @@ private Set<String> getDuplicateFunctionNames(List<AbiDefinition> functionDefini
672
672
private static MethodSpec buildGetDeploymentBinaryMethod () {
673
673
MethodSpec .Builder toReturn =
674
674
MethodSpec .methodBuilder ("getDeploymentBinary" )
675
- .addModifiers (Modifier .PUBLIC , Modifier .STATIC )
675
+ .addModifiers (Modifier .PRIVATE , Modifier .STATIC )
676
676
.returns (ClassName .get (String .class ));
677
677
678
678
CodeBlock codeBlock =
Original file line number Diff line number Diff line change 13
13
package org .web3j .codegen .unit .gen ;
14
14
15
15
import java .lang .reflect .Method ;
16
+ import java .lang .reflect .Modifier ;
16
17
import java .util .ArrayList ;
17
18
import java .util .Arrays ;
18
19
import java .util .HashMap ;
@@ -61,9 +62,11 @@ public static List<MethodSpec> generateMethodSpecsForEachTest(Class theContract)
61
62
.forEach (
62
63
method -> {
63
64
String uniqueName = getUniqueName (method , methodNameCountMap );
64
- listOfMethodSpecs .add (
65
- new MethodParser (method , theContract , uniqueName )
66
- .getMethodSpec ());
65
+ if (!Modifier .isPrivate (method .getModifiers ())) {
66
+ listOfMethodSpecs .add (
67
+ new MethodParser (method , theContract , uniqueName )
68
+ .getMethodSpec ());
69
+ }
67
70
});
68
71
69
72
return listOfMethodSpecs ;
@@ -76,8 +79,11 @@ public static List<FunSpec> generateFunctionSpecsForEachTest(Class theContract)
76
79
.forEach (
77
80
method -> {
78
81
String uniqueName = getUniqueName (method , functionNameCountMap );
79
- listOfFunSpecs .add (
80
- new FunParser (method , theContract , uniqueName ).getFunSpec ());
82
+ if (!Modifier .isPrivate (method .getModifiers ())) {
83
+ listOfFunSpecs .add (
84
+ new FunParser (method , theContract , uniqueName )
85
+ .getFunSpec ());
86
+ }
81
87
});
82
88
83
89
return listOfFunSpecs ;
Original file line number Diff line number Diff line change @@ -73,4 +73,22 @@ public void testGeneratedDuplicateGreetingMethods() {
73
73
greetMethodSpecs .stream ().anyMatch (methodSpec -> methodSpec .name .equals ("greet1" )));
74
74
assertEquals (2 , greetMethodSpecs .size ());
75
75
}
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
+ }
76
94
}
Original file line number Diff line number Diff line change @@ -78,4 +78,22 @@ public void testGeneratedDuplicateGreetingMethods() {
78
78
.anyMatch (methodSpec -> methodSpec .getName ().equals ("greet1" )));
79
79
assertEquals (2 , greetFunSpecs .size ());
80
80
}
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
+ }
81
99
}
Original file line number Diff line number Diff line change @@ -166,7 +166,7 @@ public static void linkLibraries(List<Contract.LinkReference> references) {
166
166
librariesLinkedBinary = linkBinaryWithReferences (BINARY , references );
167
167
}
168
168
169
- public static String getDeploymentBinary () {
169
+ private static String getDeploymentBinary () {
170
170
if (librariesLinkedBinary != null ) {
171
171
return librariesLinkedBinary ;
172
172
} else {
You can’t perform that action at this time.
0 commit comments