Skip to content

Commit

Permalink
WIP Kotlin unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ovitrif committed Mar 22, 2024
1 parent 94b0741 commit f4f6916
Show file tree
Hide file tree
Showing 11 changed files with 954 additions and 97 deletions.
45 changes: 45 additions & 0 deletions .github/workflows/unit-tests-android.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: unit-test-android

on:
pull_request:
branches:
- 'master'
push:
branches:
- 'master'

jobs:
tests-android:
name: Android Unit Tests
runs-on: macos-14 # m1 mac
# runs-on: ubuntu-latest # locally via act

steps:
- uses: actions/checkout@v3

- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: 18

# Uncomment for locally running workflow via act
# - name: Install yarn
# run: npm install -g yarn

- name: Install node_modules
working-directory: example
run: yarn install && yarn rn-setup

- name: Use JDK 1.11
uses: actions/setup-java@v2
with:
distribution: 'zulu'
java-version: '11.0.22'
architecture: x64

- name: Use Android SDK
uses: android-actions/setup-android@v2

- name: Run Android unit tests
run: ./gradlew testDebugUnitTest --stacktrace --no-daemon
working-directory: lib/android
2 changes: 2 additions & 0 deletions lib/.eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ node_modules
dist
src/protos
example
ios/*
android/*
1 change: 1 addition & 0 deletions lib/android/.java-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
zulu64-11.0.22
13 changes: 12 additions & 1 deletion lib/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,20 @@ buildscript {
google()
mavenCentral()
jcenter()
maven { url = uri("https://plugins.gradle.org/m2/") }
}

dependencies {
classpath 'com.android.tools.build:gradle:3.5.4'
// noinspection DifferentKotlinGradleVersion
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath("com.adarshr:gradle-test-logger-plugin:2.0.0")
}
}

apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'org.jetbrains.kotlin.android'
apply plugin: "com.adarshr.test-logger"

def getExtOrDefault(name) {
return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties['Ldk_' + name]
Expand Down Expand Up @@ -128,4 +131,12 @@ dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
// implementation files('libs/ldk-java-javadoc.jar') // Used to get code completion in Kotlin but won't compile with it
compileOnly files('libs/LDK-release.aar')

// Unit testing dependencies
testImplementation project(':')
testImplementation files('libs/ldk-java.jar') // Needs jvm11 aarch64 for tests with LDK references
testImplementation("junit:junit:4.13.2")
testImplementation("org.jetbrains.kotlin:kotlin-test")
testImplementation("org.mockito.kotlin:mockito-kotlin:3.2.0")
testImplementation("org.robolectric:robolectric:4.7.3")
}
3 changes: 2 additions & 1 deletion lib/android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#Thu Feb 29 16:57:26 CET 2024
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.8-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.3-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Binary file added lib/android/libs/ldk-java.jar
Binary file not shown.
17 changes: 7 additions & 10 deletions lib/android/src/main/java/com/reactnativeldk/Helpers.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@ import java.util.Date

fun handleResolve(promise: Promise, res: LdkCallbackResponses) {
if (res != LdkCallbackResponses.log_write_success) {
LdkEventEmitter.send(EventTypes.native_log, "Success: ${res}")
LdkEventEmitter.send(EventTypes.native_log, "Success: $res")
}
promise.resolve(res.toString());
promise.resolve(res.name)
}

fun handleReject(promise: Promise, ldkError: LdkErrors, error: Error? = null) {
if (error !== null) {
LdkEventEmitter.send(EventTypes.native_log, "Error: ${ldkError}. Message: ${error.toString()}")
promise.reject(ldkError.toString(), error);
if (error != null) {
LdkEventEmitter.send(EventTypes.native_log, "Error: $ldkError. Message: ${error.message}")
promise.reject(ldkError.name, error)
} else {
LdkEventEmitter.send(EventTypes.native_log, "Error: ${ldkError}")
promise.reject(ldkError.toString(), ldkError.toString())
LdkEventEmitter.send(EventTypes.native_log, "Error: $ldkError")
promise.reject(ldkError.name, ldkError.name)
}
}

Expand Down Expand Up @@ -383,9 +383,6 @@ fun ChannelConfig.mergeWithMap(map: ReadableMap?): ChannelConfig {
return this
}

try {
_forwarding_fee_base_msat = map.getInt("forwarding_fee_base_msat")
} catch (_: Exception) {}
try {
_forwarding_fee_base_msat = map.getInt("forwarding_fee_base_msat")
} catch (_: Exception) {}
Expand Down
Loading

0 comments on commit f4f6916

Please sign in to comment.