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 #117 from iden3/feature/updatemockupserver
Browse files Browse the repository at this point in the history
Feature/updatemockupserver
  • Loading branch information
arnaubennassar authored May 29, 2020
2 parents 2ccffa0 + e485079 commit 0f8e41b
Show file tree
Hide file tree
Showing 14 changed files with 690 additions and 536 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
run: |
cd go/iden3mobile
go get -v -t -d ./...
go test -v -count=1 ${{ matrix.flags }} ./...
go test -v -timeout 30m -count=1 ${{ matrix.flags }} ./...
goAndroidIntegrationTest:
name: Bind Go code to Android and test
Expand Down
43 changes: 38 additions & 5 deletions .github/workflows/gomobile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
- go/**

jobs:
build:
bind-go-android:
name: Gomobile
runs-on: ubuntu-latest
steps:
Expand All @@ -16,7 +16,7 @@ jobs:
- run: git fetch --depth=1 origin +refs/tags/*:refs/tags/*

- name: Build
id: build
id: bind-android
run: |
mkdir -p /tmp/builds
docker pull ed255/gomobile-android:API29-noemu
Expand Down Expand Up @@ -71,8 +71,8 @@ jobs:
tag_name: ${{ steps.next_version.outputs.version }}
release_name: Release ${{ steps.next_version.outputs.version }}
body: |
* SHA256 (iden3mobile.aar) = `${{ steps.build.outputs.sha256_aar }}`
* SHA256 (iden3mobile-sources.jar) = `${{ steps.build.outputs.sha256_jar }}`
* SHA256 (iden3mobile.aar) = `${{ steps.bind-android.outputs.sha256_aar }}`
* SHA256 (iden3mobile-sources.jar) = `${{ steps.bind-android.outputs.sha256_jar }}`
draft: false
prerelease: true

Expand Down Expand Up @@ -105,4 +105,37 @@ jobs:
cd /tmp/builds/out
mvn deploy:deploy-file -Dfile=iden3mobile.aar -Durl=https://maven.pkg.github.com/iden3/iden3-mobile -DrepositoryId=github -DrepositoryName="GitHub Pages" -Dfiles=iden3mobile-sources.jar -Dtypes=jar -Dclassifiers=sources -DgroupId=com.iden3 -DartifactId=iden3mobile -Dversion="${{ steps.next_version.outputs.version }}" -Dpackaging=aar
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

bind-go-ios:
name: Test Go
runs-on: macos-latest
steps:

- uses: actions/checkout@v2
- run: git fetch --depth=1 origin +refs/tags/*:refs/tags/*

- name: Set up Go 1.14
uses: actions/setup-go@v1
with:
go-version: 1.14

- name: Bind to iOS
run: |
go get golang.org/x/mobile/cmd/gomobile
PATH=$PATH:/Users/runner/go/bin
export PATH
cd go/iden3mobile
mkdir -p /tmp/build
gomobile init
gomobile bind --target ios -o /tmp/build/Iden3mobile.framework
- name: Release framework
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: /tmp/build/Iden3mobile.framework
asset_name: Iden3mobile.framework
asset_content_type: application/zip
9 changes: 8 additions & 1 deletion android/gointegration/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ android {
}
}

repositories {
flatDir{
dirs 'src/libs'
}
}

repositories {
maven {
name = "GitHubPackages"
Expand Down Expand Up @@ -65,5 +71,6 @@ dependencies {
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 "com.iden3:iden3mobile:$iden3mobile_version"
// androidTestImplementation "com.iden3:iden3mobile:$iden3mobile_version"
api(name:'iden3mobile', ext:'aar')
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import org.junit.Assert.assertNotEquals
import org.junit.Test
import org.junit.runner.RunWith
import java.io.File
import java.lang.Exception
import java.time.Instant
import java.util.*

/**
* Instrumented test, which will execute on an Android device.
Expand All @@ -23,13 +23,16 @@ class GomobileIntegrationTest {
fun fullFlow() {
// Test config
val nIdentities = 2
val nClaimsPerId = 5
val nClaimsPerId = 2
val web3Url = BuildConfig.INFURA_URL
val issuerUrl = "http://167.172.104.160:6100/api/unstable"
val verifierUrl = "http://167.172.104.160:6200/api/unstable"

// Create a new directory for each identity
val issuerUrl = "http://188.166.70.93:6100/api/unstable/"
val verifierUrl = "http://188.166.70.93:6200/api/unstable/"
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
// Clean and create the shared directory
val sharedStorePath = appContext.filesDir.absolutePath + "/shared"
File(sharedStorePath).deleteRecursively()
File(sharedStorePath).mkdirs()
// Create a new directory for each identity
val storePath = appContext.filesDir.absolutePath
for (i in 0 until nIdentities){
// Remove directory in case last test did't finish
Expand All @@ -45,6 +48,7 @@ class GomobileIntegrationTest {
try {
Iden3mobile.newIdentity(
"$storePath/$i",
sharedStorePath,
"password",
web3Url,
1000,
Expand All @@ -69,11 +73,13 @@ class GomobileIntegrationTest {
for (i in 0 until nClaimsPerId){
var idCount = 0
for (id in ids){
id?.requestClaimWithCb(issuerUrl, "$idCount/$i/${Instant.now()}") { ticket, e ->
Log.i("fullFlow","REQUESTING CLAIM")
val data = random()
id?.requestClaimWithCb(issuerUrl, data) { ticket, e ->
Log.i("fullFlow","REQUEST CLAIM TICKET RECEIVED: ${ticket?.id}. $ticketCounter TICKETS RECEIVED SO FAR}")
assertNotEquals(null, ticket)
assertEquals(null, e)
ticketCounter++
Log.i("fullFlow","REQUEST CLAIM TICKET RECEIVED: ${ticket?.id}. $ticketCounter TICKETS RECEIVED SO FAR}")
}
idCount++
}
Expand All @@ -85,7 +91,7 @@ class GomobileIntegrationTest {
}

// Restart identities
ids = restartIdentities(ids, storePath, web3Url, fun (event: Event) {
ids = restartIdentities(ids, storePath, sharedStorePath, web3Url, fun (event: Event) {
eventCounter++
Log.i("fullFlow","EVENT RECEIVED: ${event.ticketId}. $eventCounter EVENTS RECEIVED SO FAR")
assertEquals(null, event.err)
Expand All @@ -99,38 +105,45 @@ class GomobileIntegrationTest {
}
// Check claims on DB
assertEquals(nIdentities*nClaimsPerId, countClaims(ids))
Log.i("fullFlow", "Claims received. Proving them")

// 3. Prove claims
// Since the claims have been issued instants ago, they may not be on chain yet
// so it's normal to receive error in the upcoming seconds
var provedClaims = 0
var attempts = 10
while (provedClaims < nIdentities*nClaimsPerId && attempts >= 0){
provedClaims = 0
for (id in ids){
id?.getClaimDB()?.iterateClaimsJSON(object: ClaimDBIterFner{
override fun fn(key: String, claim: String): Boolean{
id.proveClaimWithCb(verifierUrl, key, object: CallbackProveClaim {
override fun fn(success: Boolean, e: Exception?) {
Log.i("fullFlow", "Verify claim: $key. Success? $success. Error? $e")
if(e == null){
assertEquals(true, success)
provedClaims++
}
}
})
return true
}
})
}
attempts--
Log.i("fullFlow","WAITING FOR CLAIMS TO BE PROVED.")
for (id in ids){
id?.claimDB?.iterateClaimsJSON(object: ClaimDBIterFner{
override fun fn(key: String, claim: String): Boolean{
// Prove claim
id.proveClaimWithCb(verifierUrl, key, object: CallbackProveClaim {
override fun fn(success: Boolean, e: Exception?) {
Log.i("fullFlow", "Verify claim: $key. Success? $success. Error? $e")
assertEquals(null, e)
assertEquals(true, success)
provedClaims++
}
})
// Prove claim with ZK (Zero Knowledge)
id.proveClaimZKWithCb(verifierUrl, key, object: CallbackProveClaim {
override fun fn(success: Boolean, e: Exception?) {
Log.i("fullFlow", "Verify claim ZK: $key. Success? $success. Error? $e")
assertEquals(null, e)
assertEquals(true, success)
provedClaims++
}
})
return true
}
})
}
// Wait untilall claims have been proved with and without ZK
while (provedClaims < nIdentities*nClaimsPerId*2){
Log.i("fullFlow", "Waiting to prove claims: $provedClaims / ${nIdentities*nClaimsPerId*2}")
Thread.sleep(2_000)
}
assertEquals(nClaimsPerId*nIdentities, provedClaims)
assertEquals(nClaimsPerId*nIdentities*2, provedClaims)
Log.i("fullFlow", "Claims proved")

// Restart identities
ids = restartIdentities(ids, storePath, web3Url, fun (event: Event) {
ids = restartIdentities(ids, storePath, sharedStorePath, web3Url, fun (event: Event) {
eventCounter++
Log.i("fullFlow","UNEXPECTED EVENT RECEIVED: ${event.ticketId}.")
assertEquals(null, event)
Expand All @@ -145,13 +158,14 @@ class GomobileIntegrationTest {
Log.i("fullFlow","REQUESTING CLAIMS AND CANCELING THEM.")
ticketCounter = 0
for (id in ids){
id?.requestClaimWithCb(issuerUrl, "${Instant.now()}", object: CallbackRequestClaim{
val data = random()
id?.requestClaimWithCb(issuerUrl, data, object: CallbackRequestClaim{
override fun fn(ticket: Ticket?, e: Exception?) {
assertNotEquals(null, ticket)
assertEquals(null, e)
Log.i("fullFlow","REQUEST CLAIM TICKET RECEIVED.")
// Cancel ticket
id?.tickets.cancelTicket(ticket?.id)
id.tickets.cancelTicket(ticket?.id)
ticketCounter++
}
})
Expand Down Expand Up @@ -195,7 +209,7 @@ class GomobileIntegrationTest {
Log.i("fullFlow","TEST COMPLETED :)")
}

fun restartIdentities(ids: List<Identity?>, storePath: String, web3Url: String, fn: (e:Event)->Unit): List<Identity?>{
fun restartIdentities(ids: List<Identity?>, storePath: String, sharedStorePath: String, web3Url: String, fn: (e:Event)->Unit): List<Identity?>{
Log.i("fullFlow","RESTARTING IDENTITIES")
for (id in ids){
id?.stop()
Expand All @@ -204,6 +218,7 @@ class GomobileIntegrationTest {
try {
Iden3mobile.newIdentityLoad(
"$storePath/$i",
sharedStorePath,
"password",
web3Url,
1000,
Expand Down Expand Up @@ -232,4 +247,15 @@ class GomobileIntegrationTest {
}
return claimCounter
}

fun random(): String? {
val generator = Random()
val randomStringBuilder = StringBuilder()
var tempChar: Char
for (i in 0 until 16) {
tempChar = ((generator.nextInt(10) + 48).toChar())
randomStringBuilder.append(tempChar)
}
return randomStringBuilder.toString()
}
}
Loading

0 comments on commit 0f8e41b

Please sign in to comment.