Skip to content

Commit

Permalink
fixed compiler_swagger, added simple logging conf for tests, added co…
Browse files Browse the repository at this point in the history
…mpiler service, added compiler tests
  • Loading branch information
mitch-lbw committed Jun 9, 2019
1 parent d2ca006 commit 684dee0
Show file tree
Hide file tree
Showing 14 changed files with 2,149 additions and 740 deletions.
4 changes: 2 additions & 2 deletions api/swagger_sophia_compiler_v3.0.0.yml
Expand Up @@ -80,14 +80,14 @@
"src_file":"src_file"
},
"properties":{
"file_system":{
"fileSystem":{
"description":"An explicit file system, mapping file names to file content",
"properties":{

},
"type":"object"
},
"src_file":{
"srcFile":{
"description":"Name of contract source file - only used in error messages",
"type":"string"
}
Expand Down
2 changes: 2 additions & 0 deletions resources/simplelogger.properties
@@ -0,0 +1,2 @@
org.slf4j.simpleLogger.defaultLogLevel=info
org.slf4j.simpleLogger.log.com.kryptokrauts=debug
@@ -1,12 +1,5 @@
package com.kryptokrauts.aeternity.generated.api;

import javax.naming.ConfigurationException;

import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.runner.RunWith;

import com.kryptokrauts.aeternity.sdk.constants.Network;
import com.kryptokrauts.aeternity.sdk.service.ServiceConfiguration;
import com.kryptokrauts.aeternity.sdk.service.account.AccountService;
Expand All @@ -18,73 +11,105 @@
import com.kryptokrauts.aeternity.sdk.service.transaction.TransactionService;
import com.kryptokrauts.aeternity.sdk.service.transaction.TransactionServiceConfiguration;
import com.kryptokrauts.aeternity.sdk.service.transaction.TransactionServiceFactory;

import io.vertx.core.Vertx;
import io.vertx.ext.unit.TestContext;
import io.vertx.ext.unit.junit.RunTestOnContext;
import io.vertx.ext.unit.junit.VertxUnitRunner;
import javax.naming.ConfigurationException;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.runner.RunWith;

@RunWith(VertxUnitRunner.class)
public abstract class BaseTest {

private static final String AETERNITY_BASE_URL = "AETERNITY_BASE_URL";

private static final String CONTRACT_BASE_URL = "CONTRACT_BASE_URL";

protected static final String BENEFICIARY_PRIVATE_KEY = "79816BBF860B95600DDFABF9D81FEE81BDB30BE823B17D80B9E48BE0A7015ADF";

protected KeyPairService keyPairService;

protected ChainService chainService;

protected TransactionService transactionServiceNative;

protected TransactionService transactionServiceDebug;

protected AccountService accountService;

@Rule
public RunTestOnContext rule = new RunTestOnContext();

@Before
public void setupApiClient(TestContext context) throws ConfigurationException {
Vertx vertx = rule.vertx();
keyPairService = new KeyPairServiceFactory().getService();
accountService = new AccountServiceFactory()
.getService(ServiceConfiguration.configure().baseUrl(getAeternityBaseUrl()).vertx(vertx).compile());
chainService = new ChainServiceFactory()
.getService(ServiceConfiguration.configure().baseUrl(getAeternityBaseUrl()).vertx(vertx).compile());
transactionServiceNative = new TransactionServiceFactory()
.getService(TransactionServiceConfiguration.configure().
// we adapt the minimal gas price to make sure, that the create contract tx has
// enough aeons for the fee
minimalGasPrice(1011000000l).baseUrl(getAeternityBaseUrl()).network(Network.DEVNET).vertx(vertx)
.compile());
transactionServiceDebug = new TransactionServiceFactory().getService(TransactionServiceConfiguration.configure()
.nativeMode(false).baseUrl(getAeternityBaseUrl()).network(Network.DEVNET).vertx(vertx).compile());
}

private static String getAeternityBaseUrl() throws ConfigurationException {
String aeternityBaseUrl = System.getenv(AETERNITY_BASE_URL);
if (aeternityBaseUrl == null) {
throw new ConfigurationException("ENV variable missing: AETERNITY_BASE_URL");
}
return aeternityBaseUrl;
}

private static String getContractBaseUrl() throws ConfigurationException {
String contractBaseUrl = System.getenv(CONTRACT_BASE_URL);

return contractBaseUrl;
}

@BeforeClass
public static void startup() throws ConfigurationException {
System.out.println(String.format("--------------------------- %s ---------------------------\n",
"Using following environment"));
System.out.println(String.format("%s: %s", AETERNITY_BASE_URL, getAeternityBaseUrl()));
System.out.println(String.format("%s: %s", CONTRACT_BASE_URL, getContractBaseUrl()));
System.out.println(
String.format("\n-----------------------------------------------------------------------------------"));
}
private static final String AETERNITY_BASE_URL = "AETERNITY_BASE_URL";

private static final String COMPILER_BASE_URL = "COMPILER_BASE_URL";

protected static final String BENEFICIARY_PRIVATE_KEY =
"79816BBF860B95600DDFABF9D81FEE81BDB30BE823B17D80B9E48BE0A7015ADF";

protected KeyPairService keyPairService;

protected ChainService chainService;

protected TransactionService transactionServiceNative;

protected TransactionService transactionServiceDebug;

protected AccountService accountService;

@Rule public RunTestOnContext rule = new RunTestOnContext();

@Before
public void setupApiClient(TestContext context) throws ConfigurationException {
Vertx vertx = rule.vertx();
keyPairService = new KeyPairServiceFactory().getService();
accountService =
new AccountServiceFactory()
.getService(
ServiceConfiguration.configure()
.baseUrl(getAeternityBaseUrl())
.vertx(vertx)
.compile());
chainService =
new ChainServiceFactory()
.getService(
ServiceConfiguration.configure()
.baseUrl(getAeternityBaseUrl())
.vertx(vertx)
.compile());
transactionServiceNative =
new TransactionServiceFactory()
.getService(
TransactionServiceConfiguration.configure()
.
// we adapt the minimal gas price to make sure, that the create contract tx has
// enough aeons for the fee
minimalGasPrice(1011000000l)
.baseUrl(getAeternityBaseUrl())
.network(Network.DEVNET)
.vertx(vertx)
.compile());
transactionServiceDebug =
new TransactionServiceFactory()
.getService(
TransactionServiceConfiguration.configure()
.nativeMode(false)
.baseUrl(getAeternityBaseUrl())
.network(Network.DEVNET)
.vertx(vertx)
.compile());
}

private static String getAeternityBaseUrl() throws ConfigurationException {
String aeternityBaseUrl = System.getenv(AETERNITY_BASE_URL);
if (aeternityBaseUrl == null) {
throw new ConfigurationException("ENV variable missing: AETERNITY_BASE_URL");
}
return aeternityBaseUrl;
}

protected static String getCompilerBaseUrl() throws ConfigurationException {
String compilerBaseUrl = System.getenv(COMPILER_BASE_URL);
if (compilerBaseUrl == null) {
throw new ConfigurationException("ENV variable missing: COMPILER_BASE_URL");
}
return compilerBaseUrl;
}

@BeforeClass
public static void startup() throws ConfigurationException {
System.out.println(
String.format(
"--------------------------- %s ---------------------------\n",
"Using following environment"));
System.out.println(String.format("%s: %s", AETERNITY_BASE_URL, getAeternityBaseUrl()));
System.out.println(String.format("%s: %s", COMPILER_BASE_URL, getCompilerBaseUrl()));
System.out.println(
String.format(
"\n-----------------------------------------------------------------------------------"));
}
}
@@ -0,0 +1,67 @@
package com.kryptokrauts.aeternity.generated.api;

import com.kryptokrauts.aeternity.sdk.service.ServiceConfiguration;
import com.kryptokrauts.aeternity.sdk.service.compiler.CompilerService;
import com.kryptokrauts.aeternity.sdk.service.compiler.CompilerServiceFactory;
import com.kryptokrauts.sophia.compiler.generated.model.ByteCode;
import com.kryptokrauts.sophia.compiler.generated.model.Calldata;
import io.reactivex.Single;
import io.vertx.core.Vertx;
import io.vertx.ext.unit.Async;
import io.vertx.ext.unit.TestContext;
import javax.naming.ConfigurationException;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;

public class CompilerServiceTest extends BaseTest {

protected CompilerService sophiaCompilerService;

@Before
public void initCompilerService() throws ConfigurationException {
if (sophiaCompilerService == null) {
Vertx vertx = rule.vertx();
sophiaCompilerService =
new CompilerServiceFactory()
.getService(
ServiceConfiguration.configure()
.contractBaseUrl(getCompilerBaseUrl())
.vertx(vertx)
.compile());
}
}

@Test
public void testCompileContract(TestContext context) {
Async async = context.async();
Single<ByteCode> byteCode =
this.sophiaCompilerService.compile(TestConstants.testContractSourceCode, null, null);
byteCode.subscribe(
bc -> {
Assertions.assertEquals(bc.getBytecode(), TestConstants.testContractByteCode);
async.complete();
},
throwable -> {
throwable.printStackTrace();
context.fail();
});
}

@Test
public void testEncodeCalldata(TestContext context) {
Async async = context.async();
Single<Calldata> callData =
this.sophiaCompilerService.encodeCalldata(
TestConstants.testContractSourceCode, "init", null);
callData.subscribe(
cd -> {
Assertions.assertEquals(cd.getCalldata(), TestConstants.testContractCallData);
async.complete();
},
throwable -> {
throwable.printStackTrace();
context.fail();
});
}
}

0 comments on commit 684dee0

Please sign in to comment.