Skip to content
This repository has been archived by the owner on Mar 15, 2024. It is now read-only.

Commit

Permalink
Merge pull request #103 from iden3/feature/android-4
Browse files Browse the repository at this point in the history
Feature/android 4
  • Loading branch information
arnaubennassar authored May 19, 2020
2 parents 22f590d + 4526cda commit 2ccffa0
Show file tree
Hide file tree
Showing 17 changed files with 1,014 additions and 69 deletions.
6 changes: 4 additions & 2 deletions android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
ext.kotlin_version = '1.3.71'
ext {
kotlin_version = '1.3.72'
}

repositories {
google()
jcenter()
Expand Down
1 change: 1 addition & 0 deletions android/coreapiintegration/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
72 changes: 72 additions & 0 deletions android/coreapiintegration/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

buildscript {
ext {
iden3mobile_version = 'v0.0.1-beta12'
}
}

android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
ndkVersion "20.0.5594570"

defaultConfig {
applicationId "com.iden3.coreapiintegration"
minSdkVersion 19
targetSdkVersion 29
versionCode 1
versionName "1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

// Infura config
Properties infuraProperties = new Properties()
InputStream ins = new FileInputStream("infura.properties")
infuraProperties.load(ins)
ins.close()
buildConfigField("String", "INFURA_URL", infuraProperties['url'])
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}

repositories {
maven {
name = "GitHubPackages"
url = uri("https://maven.pkg.github.com/iden3/iden3-mobile")
credentials {
Properties githubProperties = new Properties()
InputStream ins = new FileInputStream("github.properties")
githubProperties.load(ins)
ins.close()
username = githubProperties['username']
password = githubProperties['apikey']
}
}
}
}

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.core:core-ktx:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'

androidTestImplementation 'androidx.test:core:1.2.0'
androidTestImplementation 'androidx.test:core-ktx:1.2.0'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.ext:junit-ktx:1.1.1'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
androidTestImplementation(project(path: ':iden3coreapi')) {
transitive = true
}
androidTestImplementation "com.iden3:iden3mobile:$iden3mobile_version"
}
21 changes: 21 additions & 0 deletions android/coreapiintegration/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
package com.iden3.coreapiintegration

import android.content.Context
import android.util.Log
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.platform.app.InstrumentationRegistry
import com.iden3.coreapiintegration.test.BuildConfig
import com.iden3.iden3coreapi.Iden3CoreAPI
import iden3mobile.CallbackRequestClaim
import org.junit.Assert.*
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.rules.ExpectedException
import org.junit.runner.RunWith
import java.io.File
import java.time.Instant

/**
* Iden3CoreAPI local unit test, which will execute on the development machine (host).
*
* See [testing documentation](http://d.android.com/tools/testing).
*/

@RunWith(AndroidJUnit4::class)
class Iden3CoreAPInstrumentedTest {

private val web3Url = BuildConfig.INFURA_URL
private val issuerUrl = "http://167.172.104.160:6100/api/unstable"
private val verifierUrl = "http://167.172.104.160:6200/api/unstable"
private lateinit var instrumentationCtx: Context
private lateinit var storePath: String
private lateinit var iden3CoreAPI: Iden3CoreAPI

@Rule
@JvmField
val expectedException: ExpectedException = ExpectedException.none()

@Before
fun setup() {
instrumentationCtx = InstrumentationRegistry.getInstrumentation().targetContext
storePath = instrumentationCtx.filesDir.absolutePath
iden3CoreAPI = Iden3CoreAPI()
}

@Test
fun testInitializeAPISuccess() {
assertEquals(true, initializeAPI())
}

@Test
fun testCreateIdentitySuccess() {
val isInitialized = initializeAPI()
if (isInitialized) {
val identity = iden3CoreAPI.createIdentity("alias", "password")
assertNotEquals(identity, null)
iden3CoreAPI.stopIdentity(identity!!)
} else {
assert(false)
}
}

@Test
fun testLoadIdentitySuccess() {
val isInitialized = initializeAPI()
if (isInitialized) {
if (File("$storePath/alias").exists()) {
val identityLoaded = iden3CoreAPI.loadIdentity("alias", "password")
assertNotEquals(identityLoaded, null)
iden3CoreAPI.stopIdentity(identityLoaded!!)
} else {
val identityCreated = iden3CoreAPI.createIdentity("alias", "password")
iden3CoreAPI.stopIdentity(identityCreated!!)
if (File("$storePath/alias").exists()) {
val identityLoaded = iden3CoreAPI.loadIdentity("alias", "password")
assertNotEquals(identityLoaded, null)
iden3CoreAPI.stopIdentity(identityLoaded!!)
} else {
assert(false)
}
}
} else {
assert(false)
}
}

@Test
fun testRequestClaimSuccess() {
val isInitialized = initializeAPI()
if (isInitialized) {
val identity = iden3CoreAPI.createIdentity("alias", "password")
if (null != identity) {
val ticket = iden3CoreAPI.requestClaim(identity,"${Instant.now()}", null)
assertNotEquals(ticket, null)
iden3CoreAPI.stopIdentity(identity)
} else {
assert(false)
}
} else {
assert(false)
}
}

@Test
fun testRequestClaimWithCallbackSuccess() {
val isInitialized = initializeAPI()
if (isInitialized) {
val identity = iden3CoreAPI.createIdentity("alias", "password")
if (null != identity) {
var isFinished = false
iden3CoreAPI.requestClaim(identity,"${Instant.now()}",
CallbackRequestClaim { ticket, exception ->
isFinished = true
Log.i("testRequestClaimWithCallbackSuccess", "Ticket: $ticket")
iden3CoreAPI.stopIdentity(identity)
assertNotEquals(null, ticket)
assertEquals(null, exception)
})
// Wait for callback
while (!isFinished){
Log.i("testRequestClaimWithCallbackSuccess","Waiting for request claim ticket")
Thread.sleep(1000)
}
} else {
assert(false)
}
} else {
assert(false)
}
}

/*@Test
fun testProveClaimSuccess() {
val isInitialized = initializeAPI()
if (isInitialized) {
val identity = iden3CoreAPI.createIdentity("alias", "password")
if (null != identity) {
val ticket = iden3CoreAPI.proveClaim(identity,"${Instant.now()}", null)
assertNotEquals(ticket, null)
iden3CoreAPI.stopIdentity(identity)
} else {
assert(false)
}
} else {
assert(false)
}
}*/

private fun initializeAPI() : Boolean {
return iden3CoreAPI.initializeAPI(web3Url, issuerUrl, verifierUrl, storePath, 10000)
}
}
16 changes: 16 additions & 0 deletions android/coreapiintegration/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.iden3.coreapiintegration">
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:supportsRtl="true">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.iden3.coreapiintegration

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle

class MainActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
}
}
22 changes: 14 additions & 8 deletions android/gointegration/build.GHAgradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,18 @@ android {
}

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.core:core-ktx:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.13'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
api(name:'iden3mobile', ext:'aar')
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.core:core-ktx:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'

androidTestImplementation 'androidx.test:core:1.2.0'
androidTestImplementation 'androidx.test:core-ktx:1.2.0'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.ext:junit-ktx:1.1.1'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'

api(name:'iden3mobile', ext:'aar')
}

16 changes: 13 additions & 3 deletions android/gointegration/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

buildscript {
ext {
iden3mobile_version = 'v0.0.1-beta12'
}
}

android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
Expand All @@ -15,6 +21,7 @@ android {
versionName "1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

// Infura config
Properties infuraProperties = new Properties()
InputStream ins = new FileInputStream("infura.properties")
Expand Down Expand Up @@ -44,16 +51,19 @@ android {
}
}
}

}

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.core:core-ktx:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.13'

androidTestImplementation 'androidx.test:core:1.2.0'
androidTestImplementation 'androidx.test:core-ktx:1.2.0'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.ext:junit-ktx:1.1.1'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation 'com.iden3:iden3mobile:v0.0.1-beta10'
androidTestImplementation "com.iden3:iden3mobile:$iden3mobile_version"
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,12 @@ class GomobileIntegrationTest {
for (i in 0 until nClaimsPerId){
var idCount = 0
for (id in ids){
id?.requestClaimWithCb(issuerUrl, "$idCount/$i/${Instant.now()}", object: CallbackRequestClaim{
override fun fn(ticket: Ticket?, e: Exception?) {
assertNotEquals(null, ticket)
assertEquals(null, e)
ticketCounter++
Log.i("fullFlow","REQUEST CLAIM TICKET RECEIVED: ${ticket?.id}. $ticketCounter TICKETS RECEIVED SO FAR}")
}
})
id?.requestClaimWithCb(issuerUrl, "$idCount/$i/${Instant.now()}") { ticket, e ->
assertNotEquals(null, ticket)
assertEquals(null, e)
ticketCounter++
Log.i("fullFlow","REQUEST CLAIM TICKET RECEIVED: ${ticket?.id}. $ticketCounter TICKETS RECEIVED SO FAR}")
}
idCount++
}
}
Expand Down
Loading

0 comments on commit 2ccffa0

Please sign in to comment.