Commit 6287ed1e authored by Malena López-Batista's avatar Malena López-Batista

Convert to Android Library

parent e42d21f1
### OS specific ###
.DS_Store
### Android ###
# Built application files
*.apk
*.ap_
# Files for the Dalvik VM
*.dex
......@@ -19,12 +24,18 @@ build/
# Local configuration file (sdk path, etc)
local.properties
# Proguard folder generated by Eclipse
proguard/
# Log Files
*.log
# Extra
/captures
### Android Patch ###
gen-external-apklibs
### Intellij ###
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm
......@@ -83,9 +94,5 @@ gradle-app.setting
# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
!gradle-wrapper.jar
# Phraseapp
*.phraseapp
*phraseapp.yml
### native libs ###
.externalNativeBuild
# This is the Gradle build system for JVM applications
# https://gradle.org/
# https://github.com/gradle/gradle
# This file is a template, and might need editing before it works on your project.
# Read more about this script on this blog post https://about.gitlab.com/2018/10/24/setting-up-gitlab-ci-for-android-projects/, by Jason Lenny
# If you are interested in using Android with FastLane for publishing take a look at the Android-Fastlane template.
image: openjdk:8-jdk
# Disable the Gradle daemon for Continuous Integration servers as correctness
# is usually a priority over speed in CI environments. Using a fresh
# runtime for each build is more reliable since the runtime is completely
# isolated from any previous builds.
variables:
GRADLE_OPTS: "-Dorg.gradle.daemon=false"
ANDROID_COMPILE_SDK: "28"
ANDROID_BUILD_TOOLS: "28.0.2"
ANDROID_SDK_TOOLS: "4333796"
before_script:
- export GRADLE_USER_HOME=`pwd`/.gradle
# Commands to ensure that package repository listings are up to date, and it installs packages we'll be using later on
- apt-get --quiet update --yes
- apt-get --quiet install --yes wget tar unzip lib32stdc++6 lib32z1
- apt-get install -yqq --no-install-recommends build-essential libsodium-dev
- wget --quiet --output-document=android-sdk.zip https://dl.google.com/android/repository/sdk-tools-linux-${ANDROID_SDK_TOOLS}.zip
- unzip -d android-sdk-linux android-sdk.zip
- echo y | android-sdk-linux/tools/bin/sdkmanager "platforms;android-${ANDROID_COMPILE_SDK}" >/dev/null
- echo y | android-sdk-linux/tools/bin/sdkmanager "platform-tools" >/dev/null
- echo y | android-sdk-linux/tools/bin/sdkmanager "build-tools;${ANDROID_BUILD_TOOLS}" >/dev/null
- export ANDROID_HOME=$PWD/android-sdk-linux
- export PATH=$PATH:$PWD/android-sdk-linux/platform-tools/
- chmod +x ./gradlew
# temporarily disable checking for EPIPE error and use yes to accept all licenses
- set +o pipefail
- yes | android-sdk-linux/tools/bin/sdkmanager --licenses
- set -o pipefail
lintDebug:
stage: build
script:
- ./gradlew -Pci --console=plain :JavaTezos:lintDebug -PbuildDir=lint
build:
assembleDebug:
stage: build
script: ./gradlew --build-cache assemble
cache:
key: "$CI_COMMIT_REF_NAME"
policy: push
script:
- ./gradlew assembleDebug
artifacts:
paths:
- build
- .gradle
- app/build/outputs/
test:
debugTests:
stage: test
script: ./gradlew check
cache:
key: "$CI_COMMIT_REF_NAME"
policy: pull
paths:
- build
- .gradle
script:
- ./gradlew -Pci --console=plain :JavaTezos:testDebug
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'idea'
//apply plugin: 'com.kezong.fat-aar'
android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
minSdkVersion 24
targetSdkVersion 29
versionCode 1
versionName "1.0"
testApplicationId "io.camlcase.javatezos.test"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles 'consumer-rules.pro'
missingDimensionStrategy 'jvm-api', 'release'
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility = 1.8
targetCompatibility = 1.8
}
kotlinOptions {
jvmTarget = JavaVersion.VERSION_1_8.toString()
}
sourceSets {
String sharedTestDir = 'src/commonTest/kotlin'
main {
main.java.srcDirs += 'src/main/kotlin'
test.java.srcDirs += 'src/test/kotlin'
test.java.srcDirs += sharedTestDir
androidTest.java.srcDirs += 'src/androidTest/kotlin'
androidTest.java.srcDirs += sharedTestDir
resources.srcDirs += ['src/commonTest/resources']
}
}
testOptions.unitTests.all {
testLogging {
events 'passed', 'skipped', 'failed', 'standardOut', 'standardError'
outputs.upToDateWhen { false }
showStandardStreams = true
}
}
//
// subprojects { subProject ->
// subProject.configurations.all { configuration ->
// // Workaround for kapt bug with MPP dependencies
// // https://youtrack.jetbrains.com/issue/KT-31641
// // https://youtrack.jetbrains.com/issue/KT-33206
// if (name.contains('kapt') || name.contains('embed')) {
// attributes.attribute(Usage.USAGE_ATTRIBUTE, subProject.objects.named(Usage.class, Usage.JAVA_RUNTIME))
// }
// }
// }
}
ext {
// Libraries
okHttp = "4.+"
ktFutures = "1.2.0"
json = "20190722"
// Cryptography
lazySodium = "[email protected]"
jna = "[email protected]"
// Testing
jUnit = "4.13"
mockWebServer = "4.+"
mockk = "1.9.+"
}
//configurations.embed.transitive = true
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlinVersion"
implementation("com.squareup.okhttp3:okhttp:$okHttp")
implementation("com.github.vjames19.kotlin-futures:kotlin-futures-jdk8:$ktFutures")
implementation "org.json:json:$json"
implementation "com.goterl.lazycode:lazysodium-android:$lazySodium"
implementation "net.java.dev.jna:jna:$jna"
testImplementation("junit:junit:$jUnit")
testImplementation("com.squareup.okhttp3:mockwebserver:$mockWebServer")
testImplementation("io.mockk:mockk:$mockk")
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation("junit:junit:$jUnit")
androidTestImplementation("com.squareup.okhttp3:mockwebserver:$mockWebServer")
}
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
......@@ -43,7 +43,8 @@ public class TezosNodeClientGetTest extends MockServerTest {
@Override
public void onFailure(@NotNull TezosError error) {
Assert.fail("Should not call onFailure");
System.out.println("onFailure: "+error);
Assert.fail("Should not call onFailure "+error);
countDownLatch.countDown();
}
};
......
......@@ -9,25 +9,46 @@ import io.camlcase.javatezos.TezosNodeClient;
import io.camlcase.javatezos.michelson.*;
import io.camlcase.javatezos.model.*;
import io.camlcase.javatezos.operation.OperationFeesPolicy;
import io.camlcase.javatezos.test.crypto.mnemonic.MnemonicFacadeTest;
import io.camlcase.javatezos.test.network.test.MockServerTest;
import io.camlcase.javatezos.test.util.CurrentThreadExecutor;
import io.camlcase.javatezos.test.util.Params;
import io.camlcase.javatezos.test.util.RPCConstants;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.junit.Assert;
import org.junit.Test;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
* Integration tests for RPC POST Methods in {@link TezosNodeClient}
*/
public class TezosNodeClientOperationTest extends MockServerTest {
private static List<String> MNEMONIC = new ArrayList<>(Arrays.asList(
"soccer",
"click",
"number",
"muscle",
"police",
"corn",
"couch",
"bitter",
"gorilla",
"camp",
"camera",
"shove",
"expire",
"praise",
"pill"));
@Test
public void testSendTransactionOK() throws InterruptedException {
callMockDispatcher();
Wallet wallet = Wallet.Companion.invoke(MnemonicFacadeTest.Companion.getMNEMONIC(), "");
Wallet wallet = Wallet.Companion.invoke(MNEMONIC, "");
Tez tez = Tez.Companion.invoke(1.0);
TezosNodeClient client = new TezosNodeClient(getMockClient(), new CurrentThreadExecutor());
......@@ -54,7 +75,7 @@ public class TezosNodeClientOperationTest extends MockServerTest {
@Test
public void testSendTransactionKO() throws InterruptedException {
callErrorDispatcher();
Wallet wallet = Wallet.Companion.invoke(MnemonicFacadeTest.Companion.getMNEMONIC(), "");
Wallet wallet = Wallet.Companion.invoke(MNEMONIC, "");
Tez tez = Tez.Companion.invoke(1.0);
TezosNodeClient client = new TezosNodeClient(getMockClient(), new CurrentThreadExecutor());
......@@ -82,7 +103,7 @@ public class TezosNodeClientOperationTest extends MockServerTest {
@Test
public void testDelegateOK() throws InterruptedException {
callMockDispatcher();
Wallet wallet = Wallet.Companion.invoke(MnemonicFacadeTest.Companion.getMNEMONIC(), "");
Wallet wallet = Wallet.Companion.invoke(MNEMONIC, "");
TezosNodeClient client = new TezosNodeClient(getMockClient(), new CurrentThreadExecutor());
TezosCallback<String> callback = new TezosCallback<String>() {
......@@ -108,7 +129,7 @@ public class TezosNodeClientOperationTest extends MockServerTest {
@Test
public void testDelegateKO() throws InterruptedException {
callErrorDispatcher();
Wallet wallet = Wallet.Companion.invoke(MnemonicFacadeTest.Companion.getMNEMONIC(), "");
Wallet wallet = Wallet.Companion.invoke(MNEMONIC, "");
TezosNodeClient client = new TezosNodeClient(getMockClient(), new CurrentThreadExecutor());
TezosCallback<String> callback = new TezosCallback<String>() {
......@@ -134,7 +155,7 @@ public class TezosNodeClientOperationTest extends MockServerTest {
@Test
public void testCallSmartContractOK() throws InterruptedException {
callMockDispatcher();
Wallet wallet = Wallet.Companion.invoke(MnemonicFacadeTest.Companion.getMNEMONIC(), "");
Wallet wallet = Wallet.Companion.invoke(MNEMONIC, "");
MichelsonParameter michelson = new PairMichelsonParameter(
new StringMichelsonParameter("test", null),
......
......@@ -126,8 +126,7 @@ class MockDispatcher {
}
}
fun Dispatcher.validResponse() = MockResponse()
.setResponseCode(200)
fun Dispatcher.validResponse() = response(200)
fun Dispatcher.error404() = this.response(404)
......
......@@ -40,6 +40,13 @@ internal class RPCConstants {
}
}
internal class BabylonAddress {
companion object {
const val TEST_ADDRESS_TZ1_CW = "tz1cWwpcWBo8LcZiyfPdYYe7xifu1zGL4agT"
const val TEST_ADDRESS_TZ1_WRO = "tz1WRoqRuEZqeh2MXpxEeKmGk89Wv9Ad4GyC"
}
}
internal val fakeSignature = object : SignatureProvider {
override val publicKey: PublicKey
......@@ -54,10 +61,15 @@ internal class Params {
companion object {
const val fakeAddress = "tz1ADDRESS"
val fakeFees = OperationFees(Tez(1.0), 200, 300)
val fakeMetadata = OperationMetadata("FakeBranch", "FakeProtocol", "FakeChainId", 1234, null)
val fakeMetadata =
OperationMetadata("FakeBranch", "FakeProtocol", "FakeChainId", 1234, null)
val fakeTransactionParams = OperationParams.Transaction(Tez(1.0), "tz1FROM", "tz1TO")
val fakeTransactionOperation =
OperationFactory.createOperation(OperationType.TRANSACTION, fakeTransactionParams, fakeFees)!!
OperationFactory.createOperation(
OperationType.TRANSACTION,
fakeTransactionParams,
fakeFees
)!!
val fakeOperationWithCounter = OperationWithCounter(fakeTransactionOperation, 1234)
val fakeOperationPayload = OperationPayload(listOf(fakeOperationWithCounter), "FakeBranch")
}
......
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="io.camlcase.javatezos">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
</manifest>
......@@ -40,7 +40,6 @@ import java.util.List;
* Taken and modified from the BitcoinJ library to avoid the Guava dependency
* @see {@link <a href>https://github.com/bitcoinj/bitcoinj/blob/master/core/src/main/java/org/bitcoinj/crypto/MnemonicCode.java</a>}
*/
public class MnemonicCode {
private ArrayList<String> wordList;
......
......@@ -19,9 +19,7 @@
*/
package io.camlcase.javatezos.crypto
import com.goterl.lazycode.lazysodium.LazySodium
import com.goterl.lazycode.lazysodium.Sodium
import com.goterl.lazycode.lazysodium.SodiumJava
import com.goterl.lazycode.lazysodium.*
import com.goterl.lazycode.lazysodium.exceptions.SodiumException
import com.goterl.lazycode.lazysodium.interfaces.Sign
import com.goterl.lazycode.lazysodium.utils.KeyPair
......@@ -30,12 +28,7 @@ import com.goterl.lazycode.lazysodium.utils.KeyPair
* Wrapper for Libsodium cryptographic utils.
*/
object SodiumFacade {
private val sodiumProvider = object : LazySodium() {
private val sodium: SodiumJava = SodiumJava()
override fun getSodium(): Sodium {
return sodium
}
}
private val sodiumProvider = LazySodiumAndroid(SodiumAndroid())
/**
* Create a pair of keys with the given hex seed string.
......
......@@ -51,11 +51,13 @@ fun <T> Parser<T>?.parseErrors(array: JSONArray): List<RPCErrorResponse> {
this?.let {
val parser = RPCErrorParser()
val list = ArrayList<RPCErrorResponse>()
for (error in array) {
val map = error as JSONObject
var i = 0
while (i < array.length()) {
val map = array[i] as JSONObject
parser.parse(map.toString())?.also {
list.add(it)
}
i++
}
return list
} ?: return emptyList()
......