Skip to content

Commit

Permalink
Kotlin unit tests update for LDK v0.0.121
Browse files Browse the repository at this point in the history
  • Loading branch information
ovitrif committed Mar 26, 2024
1 parent 2e4e77d commit 2623cfa
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 30 deletions.
10 changes: 2 additions & 8 deletions .github/workflows/unit-tests-android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ on:
jobs:
tests-android:
name: Android Unit Tests
runs-on: macos-14 # m1 mac
# runs-on: ubuntu-latest # Uncomment to run locally via act
runs-on: macos-12

steps:
- uses: actions/checkout@v3
Expand All @@ -22,10 +21,6 @@ jobs:
with:
node-version: 18

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

- name: Install node_modules
working-directory: example
run: yarn install && yarn rn-setup
Expand All @@ -34,12 +29,11 @@ jobs:
uses: actions/setup-java@v2
with:
java-version: '17'
architecture: x64
distribution: 'zulu'

- 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
run: ./gradlew testDebugUnitTest --stacktrace --no-daemon
2 changes: 1 addition & 1 deletion lib/android/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Ldk_kotlinVersion=1.8.20
Ldk_kotlinVersion=1.6.10
Ldk_compileSdkVersion=29
Ldk_targetSdkVersion=29
android.useAndroidX=true
Binary file modified lib/android/libs/ldk-java.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion lib/android/src/main/java/com/reactnativeldk/LdkModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -1145,7 +1145,7 @@ class LdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaMod

val output = TxOut(outputValue.toLong(), outputScriptPubKey.hexa())
val outpoint = OutPoint.of(outpointTxId.hexa().reversedArray(), outpointIndex.toInt().toShort())
val descriptor = SpendableOutputDescriptor.static_output(outpoint, output, byteArrayOf())
val descriptor = SpendableOutputDescriptor.static_output(outpoint, output, ByteArray(32))

val ldkDescriptors: MutableList<SpendableOutputDescriptor> = arrayListOf()
ldkDescriptors.add(descriptor)
Expand Down
36 changes: 16 additions & 20 deletions lib/android/src/test/java/com/reactnativeldk/LdkModuleTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,24 @@ import org.mockito.kotlin.any
import org.mockito.kotlin.check
import org.mockito.kotlin.doReturn
import org.mockito.kotlin.eq
import org.mockito.kotlin.isA
import org.mockito.kotlin.isNull
import org.mockito.kotlin.mock
import org.mockito.kotlin.times
import org.mockito.kotlin.verify
import org.robolectric.RobolectricTestRunner
import org.robolectric.annotation.Config
import java.io.File
import kotlin.test.assertEquals
import kotlin.test.assertTrue

private const val FS_ROOT = "build/test-files"

private val INVOICE_EXPIRED =
"lnbcrt120n1pjlrxz9pp599l2jlsrt4qeczdyh90rzhfsfrkxhu6dged8yhfyhw0kt3sfzsyqdqdw4hxjaz5v4ehgcqzzsxqyz5vqsp54ehunpcenrejgq4tfwr8a4s5tlyrchhk27e70a0vagwr60n8mwhq9qyyssq5t6dqjwu4r6rnjfz7uk9mx0p2h2rxlr00fqyzjtudglay6lzfqp370ml6y8hnwfz8eamhdt4nu7s6jwy64gd9gtl9t8zz5l67cq6j6qqkgmr5v"

@Config(shadows = [ShadowArguments::class], manifest = Config.NONE)
@Config(
manifest = Config.NONE,
shadows = [ShadowArguments::class],
)
@RunWith(RobolectricTestRunner::class)
class LdkModuleTest {
private val eventEmitter = mock<RCTDeviceEventEmitter>()
Expand All @@ -56,12 +57,8 @@ class LdkModuleTest {

@Before
fun setUp() {
ldkModule = LdkModule(reactContext)
_promise = mock<Promise>()
// TODO remove after PR gets merged and LDK is updated:
// https://github.com/lightningdevkit/ldk-garbagecollected/issues/149
get_ldk_version() // ← HACK to force load LDK bindings
// TODO clear tests file storage (maybe?)
ldkModule = LdkModule(reactContext)
}

// MARK: Startup methods
Expand Down Expand Up @@ -188,7 +185,6 @@ class LdkModuleTest {
4.0,
5.0,
5.0,
6.0,
promise
)

Expand Down Expand Up @@ -357,18 +353,14 @@ class LdkModuleTest {
@Test
fun test_pay_expiredInvoice() {
// TODO: Add test for happy flow + other error cases
val promise = mock<Promise>()
setupChannelManager()

ldkModule.pay(INVOICE_EXPIRED, 0.0, 2.5, _promise)
ldkModule.pay(INVOICE_EXPIRED, 0.0, 2.5, promise)

verify(_promise).reject(
eq(LdkErrors.invoice_payment_fail_sending.name),
check<Throwable> {
assertEquals(
"PaymentError.Sending: LDKRetryableSendFailure_PaymentExpired",
it.message
)
}
verify(promise).reject(
eq(LdkErrors.invoice_payment_fail_payment_expired.name),
eq(LdkErrors.invoice_payment_fail_payment_expired.name),
)
}

Expand Down Expand Up @@ -446,7 +438,6 @@ class LdkModuleTest {
@Test
fun test_nodeId() {
val promise = mock<Promise>()

setupChannelManager()

ldkModule.nodeId(promise)
Expand Down Expand Up @@ -627,7 +618,12 @@ class LdkModuleTest {
val promise = mock<Promise>()
setupChannelManager()

ldkModule.spendRecoveredForceCloseOutputs("transaction", 1.0, "changeDestinationScript", promise)
ldkModule.spendRecoveredForceCloseOutputs(
"transaction",
1.0,
"changeDestinationScript",
promise
)

verify(promise).resolve(check<ReadableArray> {
assertTrue { it.size() == 0 }
Expand Down

0 comments on commit 2623cfa

Please sign in to comment.