Skip to content

Commit

Permalink
Merge pull request #180 from mysteriumnetwork/payments-integration
Browse files Browse the repository at this point in the history
Add initial payments integration
  • Loading branch information
anjmao authored Jan 7, 2020
2 parents d26163a + b3f16f7 commit 5df8764
Show file tree
Hide file tree
Showing 52 changed files with 1,893 additions and 552 deletions.
4 changes: 4 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
android/app/build/
android/build
android/lint
android/app/lint
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ build/
local.properties
*.iml
ios/Index/
android/app/lint
android/lint

# test
.jest/
Expand Down
75 changes: 65 additions & 10 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,72 @@
image: mysteriumnetwork/mobile-ci:0.1.0

stages:
- deploy
- environment
- build
- test
- internal

push-beta:
stage: deploy
when: manual
.updateContainerJob:
image: docker:stable
stage: environment
services:
- docker:dind
script:
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
- docker pull $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG || true
- docker build --cache-from $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG -t $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG .
- docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG

updateContainer:
extends: .updateContainerJob
only:
- master
- /^release-*/
changes:
- Dockerfile

ensureContainer:
extends: .updateContainerJob
allow_failure: true
before_script:
- "mkdir -p ~/.docker && echo '{\"experimental\": \"enabled\"}' > ~/.docker/config.json"
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
# Skip update container `script` if the container already exists
# via https://gitlab.com/gitlab-org/gitlab-ce/issues/26866#note_97609397 -> https://stackoverflow.com/a/52077071/796832
- docker manifest inspect $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG > /dev/null && exit || true

.build_job:
image: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG
stage: build
before_script:
- "export VERSION_CODE=$((100 + $CI_PIPELINE_IID)) && echo $VERSION_CODE"
- "export VERSION_SHA=`echo ${CI_COMMIT_SHA:0:8}` && echo $VERSION_SHA"
# Because we allow the MR creation to fail, just make sure we are back in the right repo state
- git checkout "$CI_COMMIT_SHA"
after_script:
- rm -f android-signing-keystore.jks || true
artifacts:
paths:
- app/build/outputs

buildDebug:
extends: .build_job
script:
- bundle exec fastlane buildDebug

testDebug:
image: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG
stage: test
dependencies:
- buildDebug
script:
- bundle exec fastlane test

publishInternal:
image: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG
stage: internal
when: manual
before_script:
- echo "$FASTLANE_ANDROID_SIGNING_FILE_VALUE" | base64 --decode > "$FASTLANE_ANDROID_SIGNING_FILE_PATH"
- echo "$FASTLANE_ANDROID_SECRET_JSON_VALUE" | base64 --decode > "$FASTLANE_ANDROID_SECRET_JSON_PATH"
- echo "$GOOGLE_SERVICES_VALUE" | base64 --decode > "$GOOGLE_SERVICES_PATH"
- bundle update --bundler
- fastlane android beta
after_script:
- rm -f $GOOGLE_SERVICES_PATH $FASTLANE_ANDROID_SIGNING_FILE_PATH $FASTLANE_ANDROID_SECRET_JSON_PATH
script:
- bundle exec fastlane internal
34 changes: 34 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
FROM openjdk:8-jdk

# Just matched `app/build.gradle`
ENV ANDROID_COMPILE_SDK "28"
# Just matched `app/build.gradle`
ENV ANDROID_BUILD_TOOLS "28.0.3"
# Version from https://developer.android.com/studio/releases/sdk-tools
ENV ANDROID_SDK_TOOLS "4333796"

ENV ANDROID_HOME /android-sdk-linux
ENV PATH="${PATH}:/android-sdk-linux/platform-tools/"

# Install OS packages
RUN apt-get --quiet update --yes
RUN apt-get --quiet install --yes wget tar unzip lib32stdc++6 lib32z1 build-essential ruby ruby-dev
# We use this for xxd hex->binary
RUN apt-get --quiet install --yes vim-common
# Install Android SDK
RUN wget --quiet --output-document=android-sdk.zip https://dl.google.com/android/repository/sdk-tools-linux-${ANDROID_SDK_TOOLS}.zip
RUN unzip -q android-sdk.zip -d "$ANDROID_HOME/"
# Accept Android SDK licenses
RUN yes | $ANDROID_HOME/tools/bin/sdkmanager --licenses

RUN echo y | android-sdk-linux/tools/android update sdk --no-ui --all --filter android-${ANDROID_COMPILE_SDK}
RUN echo y | android-sdk-linux/tools/android update sdk --no-ui --all --filter platform-tools
RUN echo y | android-sdk-linux/tools/android update sdk --no-ui --all --filter build-tools-${ANDROID_BUILD_TOOLS}
RUN echo y | android-sdk-linux/tools/android update sdk --no-ui --all --filter extra-android-m2repository
RUN echo y | android-sdk-linux/tools/android update sdk --no-ui --all --filter extra-google-google_play_services
RUN echo y | android-sdk-linux/tools/android update sdk --no-ui --all --filter extra-google-m2repository
# install Fastlane
COPY Gemfile.lock .
COPY Gemfile .
RUN gem install bundle
RUN bundle install
30 changes: 21 additions & 9 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ android {
versionName getVersionName()
multiDexEnabled true

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

javaCompileOptions {
annotationProcessorOptions {
arguments = ["room.schemaLocation": "$projectDir/schemas".toString()]
Expand Down Expand Up @@ -116,12 +118,15 @@ android {
}
}
}

useLibrary 'android.test.runner'
useLibrary 'android.test.base'
useLibrary 'android.test.mock'
}

dependencies {
def nav_version = "2.1.0"
implementation "androidx.navigation:navigation-fragment-ktx:$nav_version"
implementation "androidx.navigation:navigation-ui-ktx:$nav_version"
implementation 'androidx.navigation:navigation-fragment-ktx:2.1.0'
implementation 'androidx.navigation:navigation-ui-ktx:2.1.0'

implementation('com.crashlytics.sdk.android:crashlytics:2.9.6@aar') {
transitive = true
Expand All @@ -134,6 +139,7 @@ dependencies {
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.core:core-ktx:1.1.0'
implementation 'com.android.support:support-compat:28.0.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.lifecycle:lifecycle-extensions:2.1.0'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.1.0'
Expand All @@ -142,18 +148,24 @@ dependencies {
implementation 'com.makeramen:roundedimageview:2.3.0'
implementation 'com.beust:klaxon:5.0.1'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.0'
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.0"
implementation "org.jetbrains.kotlin:kotlin-reflect:1.3.50"
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.1.0"
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.0'
implementation 'org.jetbrains.kotlin:kotlin-reflect:1.3.50'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.1.0'
implementation 'androidx.room:room-runtime:2.2.2'
implementation 'androidx.room:room-ktx:2.2.2'
kapt 'androidx.room:room-compiler:2.2.2'

testImplementation 'junit:junit:4.12'

implementation 'network.mysterium:mobile-node:0.15.0'
androidTestImplementation 'androidx.test:core:1.2.0'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
androidTestImplementation 'com.android.support.test.espresso:espresso-contrib:3.0.2'
androidTestImplementation 'androidx.test:rules:1.3.0-alpha03'

implementation 'network.mysterium:mobile-node:0.18.0'
// Comment network.mysterium:mobile-node and replace with your local path to use local node build.
// compile files('/Users/anjmao/go/src/github.com/mysteriumnetwork/node/build/package/Mysterium.aar')
//compile files('/Users/anjmao/go/src/github.com/mysteriumnetwork/node/build/package/Mysterium.aar')
}

// Run this once to be able to run the application with BUCK
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package network.mysterium

import androidx.test.espresso.action.ViewActions.*
import androidx.test.filters.LargeTest
import androidx.test.rule.ActivityTestRule
import androidx.test.runner.AndroidJUnit4
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith

@LargeTest
@RunWith(AndroidJUnit4::class)
class BasicFlowTest {

@Rule
@JvmField
var mActivityTestRule = ActivityTestRule(MainActivity::class.java)

@Test
fun registeredIdentityFlowTest() {
Views.checkStatusLabel("Disconnected")
Views.selectProposalLayout.perform(click())

Views.proposalSearchInput.perform(replaceText("0xfbf"), closeSoftKeyboard())

Views.selectProposalItem(0)

Views.connectionButton.perform(click())

Views.checkStatusLabel("Connected")

Thread.sleep(5000)

Views.connectionButton.perform(click())

Views.checkStatusLabel("Disconnected")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package network.mysterium

import androidx.test.espresso.action.ViewActions.*
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
import androidx.test.espresso.matcher.ViewMatchers.withText
import androidx.test.filters.LargeTest
import androidx.test.rule.ActivityTestRule
import androidx.test.runner.AndroidJUnit4
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith

@LargeTest
@RunWith(AndroidJUnit4::class)
class BasicFlowWithRegistrationTest {

@Rule
@JvmField
var mActivityTestRule = ActivityTestRule(MainActivity::class.java)

// TODO: For some reasons this fails with Failed to grant permissions, see logcat for details error.
// @Rule
// @JvmField
// val grantPermissionRule: GrantPermissionRule = GrantPermissionRule.grant(android.Manifest.permission.BIND_VPN_SERVICE)

@Test
fun basicFlowWithRegistrationTest() {
Views.acceptTermsButton.perform(click())

Views.balanceLabel.perform(click())

Views.registrationPleaseWaitLabel.check(matches(withText("Please wait")))

Views.topUpButton.check(matches(isDisplayed()))

Views.navBackButton.perform(click())

Views.selectProposalLayout.perform(click())

Views.proposalSearchInput.perform(replaceText("0xfbf"), closeSoftKeyboard())

Views.selectProposalItem(0)

Views.connectionButton.perform(click())

Views.checkStatusLabel("Connected")

Views.connectionButton.perform(click())

Views.checkStatusLabel("Disconnected")
}
}
43 changes: 43 additions & 0 deletions android/app/src/androidTest/java/network/mysterium/Helpers.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package network.mysterium

import android.view.View
import android.view.ViewGroup
import androidx.test.espresso.Espresso
import androidx.test.espresso.NoMatchingViewException
import androidx.test.espresso.ViewInteraction
import androidx.test.espresso.assertion.ViewAssertions
import androidx.test.espresso.matcher.ViewMatchers
import org.hamcrest.Description
import org.hamcrest.Matcher
import org.hamcrest.TypeSafeMatcher

fun onViewReady(viewMatcher: Matcher<View>, count: Int = 3, sleepMillis: Long = 2000): ViewInteraction {
for (i in 1..count) {
try {
return Espresso.onView(viewMatcher).check(ViewAssertions.matches(ViewMatchers.isDisplayed()))
} catch (e: NoMatchingViewException) {
if (i == count) {
throw e
}
Thread.sleep(sleepMillis)
}
}
throw Throwable("view not found")
}

fun childAtPosition(
parentMatcher: Matcher<View>, position: Int): Matcher<View> {

return object : TypeSafeMatcher<View>() {
override fun describeTo(description: Description) {
description.appendText("Child at position $position in parent ")
parentMatcher.describeTo(description)
}

public override fun matchesSafely(view: View): Boolean {
val parent = view.parent
return parent is ViewGroup && parentMatcher.matches(parent)
&& view == parent.getChildAt(position)
}
}
}
Loading

0 comments on commit 5df8764

Please sign in to comment.