Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

<fix>(v3): fix v3 codeGen wrapper use v1 tx generate constructor bug. #25

Merged
merged 1 commit into from
Jan 11, 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
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@ public void generateJavaFiles(
classBuilder.addMethod(buildGetBinaryMethod());
classBuilder.addMethod(buildGetABIMethod());
classBuilder.addMethod(buildConstructor());
if (this.transactionVersion == CodeGenMain.TransactionVersion.V1.getV()) {
classBuilder.addMethod(buildTransactionV1Constructor());
}

classBuilder.addFields(this.buildFuncNameConstants(abiDefinitions));
classBuilder.addTypes(this.buildStructTypes(abiDefinitions));
Expand Down Expand Up @@ -669,8 +672,29 @@ private static MethodSpec buildGetABIMethod() {
}

private MethodSpec buildConstructor() {
MethodSpec.Builder toReturn;
MethodSpec.Builder toReturn =
MethodSpec.constructorBuilder()
.addModifiers(Modifier.PROTECTED)
.addParameter(String.class, CONTRACT_ADDRESS)
.addParameter(Client.class, CLIENT)
.addParameter(CryptoKeyPair.class, ContractWrapper.CREDENTIAL)
.addStatement(
"super($N, $N, $N, $N)",
getBinaryFuncDefinition(),
CONTRACT_ADDRESS,
CLIENT,
ContractWrapper.CREDENTIAL);
toReturn.addStatement(
"this.$N = new $T($N)",
ContractWrapper.TRANSACTION_MANAGER,
ProxySignTransactionManager.class,
CLIENT);
return toReturn.build();
}

private MethodSpec buildTransactionV1Constructor() {
if (this.transactionVersion == CodeGenMain.TransactionVersion.V1.getV()) {
MethodSpec.Builder toReturn;
toReturn =
MethodSpec.constructorBuilder()
.addModifiers(Modifier.PROTECTED)
Expand All @@ -684,21 +708,9 @@ private MethodSpec buildConstructor() {
CONTRACT_ADDRESS,
CLIENT,
ContractWrapper.TRANSACTION_MANAGER);
} else {
toReturn =
MethodSpec.constructorBuilder()
.addModifiers(Modifier.PROTECTED)
.addParameter(String.class, CONTRACT_ADDRESS)
.addParameter(Client.class, CLIENT)
.addParameter(CryptoKeyPair.class, ContractWrapper.CREDENTIAL)
.addStatement(
"super($N, $N, $N, $N)",
getBinaryFuncDefinition(),
CONTRACT_ADDRESS,
CLIENT,
ContractWrapper.CREDENTIAL);
return toReturn.build();
}
return toReturn.build();
return null;
}

private MethodSpec buildDeploy(
Expand Down
32 changes: 26 additions & 6 deletions src/test/java/org/fisco/bcos/codegen/v3/test/CodeGenV3Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
import java.io.OutputStream;
import java.net.URI;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import javax.tools.DiagnosticCollector;
import javax.tools.JavaCompiler;
Expand All @@ -18,8 +20,22 @@
import org.fisco.bcos.codegen.CodeGenMain;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;

@RunWith(Parameterized.class)
public class CodeGenV3Test {

@Parameterized.Parameter public boolean useV1Tx;

@Parameterized.Parameters
public static Collection<Object[]> data() {
return Arrays.asList(
new Object[][] {
{false}, {true},
});
}

private static final String JAVA_OUTPUT_DIR = "sdk";
private static final String DEFAULT_PACKAGE = "com";

Expand Down Expand Up @@ -148,8 +164,9 @@ private void codeGenTest(String abiFileName, String codeFilePath, String contrac
String abiFile = CodeGenV3Test.class.getClassLoader().getResource(abiFileName).getPath();
String binFile = CodeGenV3Test.class.getClassLoader().getResource(codeFilePath).getPath();
String javaOutPut = new File(abiFile).getParent() + File.separator + JAVA_OUTPUT_DIR;
CodeGenMain.main(
Arrays.asList(
ArrayList<String> args =
new ArrayList<>(
Arrays.asList(
"-v",
"V3",
"-a",
Expand All @@ -162,10 +179,13 @@ private void codeGenTest(String abiFileName, String codeFilePath, String contrac
DEFAULT_PACKAGE,
"-o",
javaOutPut,
"-e",
"-t",
"V1")
.toArray(new String[0]));
"-e"));

if (useV1Tx) {
args.add("-t");
args.add("V1");
}
CodeGenMain.main(args.toArray(new String[0]));
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
DiagnosticCollector<JavaFileObject> collector = new DiagnosticCollector<>();
JavaFileManager javaFileManager =
Expand Down
Loading