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 25, 2024
1 parent 2e4e77d commit 3792b82
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 23 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/unit-tests-android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ on:
jobs:
tests-android:
name: Android Unit Tests
runs-on: macos-14 # m1 mac
runs-on: macos-12
# runs-on: macos-14 # m1 mac
# runs-on: ubuntu-latest # Uncomment to run locally via act

steps:
Expand All @@ -34,12 +35,12 @@ jobs:
uses: actions/setup-java@v2
with:
java-version: '17'
architecture: x64
# architecture: aarch64 # should be derived from runner
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
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
35 changes: 16 additions & 19 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 @@ -627,7 +619,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 3792b82

Please sign in to comment.