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 Integration Tests #1294

Merged
merged 10 commits into from Dec 2, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 21 additions & 1 deletion codegen/build.gradle
Expand Up @@ -5,8 +5,28 @@ dependencies {
"com.squareup:kotlinpoet:$kotlinPoetVersion",
"com.squareup:javapoet:$javaPoetVersion",
"info.picocli:picocli:$picocliVersion"
testCompile project(path: ':core', configuration: 'testArtifacts')
testCompile project(':core').sourceSets.test.output
implementation("org.junit.platform:junit-platform-launcher:$junitPlatformLauncherVersion")
implementation("org.junit.jupiter:junit-jupiter-engine:$junitVersion")
implementation("org.junit.vintage:junit-vintage-engine:$junitVersion")
}


file("src/test/resources/solidity").listFiles().each { File file ->
def contractFile = file.listFiles().find({
it.getName().endsWith(".sol")
})
if (contractFile != null) {
def contractName = contractFile.name.substring(0, contractFile.name.length() - 4)
def generateTask = tasks.register("generate${contractName}Wrapper", JavaExec) {
classpath = sourceSets.test.runtimeClasspath
main = 'org.web3j.codegen.SolidityFunctionWrapperGenerator'
args 'generate',
'--abiFile', "${contractFile.parent}/build/${contractName}.abi",
'--binFile', "${contractFile.parent}/build/${contractName}.bin",
'--outputDir', "build/resources/test/java",
'--package', 'org.com.test.contract'
}
test.dependsOn generateTask
}
}
Expand Up @@ -28,7 +28,7 @@
import javax.tools.ToolProvider;

/** Class loader with compilation capabilities. */
class CompilerClassLoader extends ClassLoader {
public class CompilerClassLoader extends ClassLoader {

private final File outputDir;
private final URL[] urls;
Expand All @@ -39,7 +39,7 @@ class CompilerClassLoader extends ClassLoader {
* @param outputDir Directory where classes will be compiled.
* @param urls Classpath URLs to compile the Java sources.
*/
CompilerClassLoader(final File outputDir, final URL... urls) {
public CompilerClassLoader(final File outputDir, final URL... urls) {
super(CompilerClassLoader.class.getClassLoader());
this.outputDir = outputDir;
this.urls = urls;
Expand Down
Expand Up @@ -20,11 +20,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import javax.tools.DiagnosticCollector;
import javax.tools.JavaCompiler;
import javax.tools.JavaFileObject;
import javax.tools.StandardJavaFileManager;
import javax.tools.ToolProvider;
import javax.tools.*;
AlexandrouR marked this conversation as resolved.
Show resolved Hide resolved

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -71,8 +67,8 @@ public void testGreeterGeneration() throws Exception {

@Test
public void testHumanStandardTokenGeneration() throws Exception {
testCodeGenerationJvmTypes("contracts", "HumanStandardToken");
testCodeGenerationSolidityTypes("contracts", "HumanStandardToken");
testCodeGenerationJvmTypes("humanstandardtoken", "HumanStandardToken");
testCodeGenerationSolidityTypes("humanstandardtoken", "HumanStandardToken");
}

@Test
Expand Down Expand Up @@ -107,14 +103,14 @@ public void testMisc() throws Exception {

@Test
public void testContractsNoBin() throws Exception {
testCodeGeneration("contracts", "HumanStandardToken", JAVA_TYPES_ARG, false);
testCodeGeneration("contracts", "HumanStandardToken", SOLIDITY_TYPES_ARG, false);
testCodeGeneration("humanstandardtoken", "HumanStandardToken", JAVA_TYPES_ARG, false);
testCodeGeneration("humanstandardtoken", "HumanStandardToken", SOLIDITY_TYPES_ARG, false);
}

@Test
public void testComplexStorage0425() throws Exception {
testCodeGenerationJvmTypes("complexstorage0.4.25", "ComplexStorage");
testCodeGenerationSolidityTypes("complexstorage0.4.25", "ComplexStorage");
testCodeGenerationJvmTypes("complexstoragenew", "ComplexStorageNew");
testCodeGenerationSolidityTypes("complexstoragenew", "ComplexStorageNew");
}

@Test
Expand All @@ -141,13 +137,13 @@ public void testDuplicateField() throws Exception {
public void testGenerationCommandPrefixes() throws Exception {
testCodeGeneration(
Arrays.asList(COMMAND_SOLIDITY, COMMAND_GENERATE),
"contracts",
"humanstandardtoken",
"HumanStandardToken",
JAVA_TYPES_ARG,
true);
testCodeGeneration(
Arrays.asList(COMMAND_GENERATE),
"contracts",
"humanstandardtoken",
"HumanStandardToken",
SOLIDITY_TYPES_ARG,
true);
Expand Down
14 changes: 6 additions & 8 deletions codegen/src/test/java/org/web3j/codegen/unit/gen/java/Setup.java
Expand Up @@ -24,7 +24,7 @@
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.io.TempDir;

import org.web3j.codegen.unit.gen.ClassProvider;
import org.web3j.codegen.unit.gen.CompilerClassLoader;
import org.web3j.codegen.unit.gen.MethodFilter;

public class Setup {
Expand All @@ -37,6 +37,7 @@ public class Setup {

@BeforeAll
public static void setUp() throws IOException, ClassNotFoundException {

String urlAsString =
Objects.requireNonNull(
Setup.class
Expand All @@ -54,13 +55,10 @@ public static void setUp() throws IOException, ClassNotFoundException {
"contracts",
"GreeterTest.java");
classAsFile = new File(urlAsString);
File greeter = new File(urlAsString.substring(0, urlAsString.indexOf("org/")));
greeterContractClass =
new ClassProvider(greeter)
.getClasses().stream()
.filter(className -> className.getSimpleName().equals("Greeter"))
.findAny()
.orElse(null);
CompilerClassLoader compilerClassLoader =
new CompilerClassLoader(temp, Setup.class.getClassLoader().getResource("java/"));

greeterContractClass = compilerClassLoader.loadClass("org.com.test.contract.Greeter");

filteredMethods = MethodFilter.extractValidMethods(greeterContractClass);
new JavaClassGenerator(
Expand Down
Expand Up @@ -23,7 +23,7 @@
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.io.TempDir;

import org.web3j.codegen.unit.gen.ClassProvider;
import org.web3j.codegen.unit.gen.CompilerClassLoader;
import org.web3j.codegen.unit.gen.MethodFilter;

public class Setup {
Expand Down Expand Up @@ -53,13 +53,14 @@ public static void setUp() throws Exception {
"contracts",
"GreeterTest.kt");
classAsFile = new File(urlAsString);
File greeter = new File(urlAsString.substring(0, urlAsString.indexOf("org/")));
greeterContractClass =
new ClassProvider(greeter)
.getClasses().stream()
.filter(className -> className.getSimpleName().equals("Greeter"))
.findAny()
.orElse(null);
CompilerClassLoader compilerClassLoader =
new CompilerClassLoader(
temp,
org.web3j.codegen.unit.gen.java.Setup.class
.getClassLoader()
.getResource("java/"));

greeterContractClass = compilerClassLoader.loadClass("org.com.test.contract.Greeter");

filteredMethods = MethodFilter.extractValidMethods(greeterContractClass);
new KotlinClassGenerator(
Expand Down