-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathProbingToolViewModelTest.kt
More file actions
71 lines (60 loc) · 2.31 KB
/
Copy pathProbingToolViewModelTest.kt
File metadata and controls
71 lines (60 loc) · 2.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package to.bitkit.viewmodels
import android.content.Context
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.test.advanceUntilIdle
import org.junit.Before
import org.junit.Test
import org.mockito.kotlin.mock
import org.mockito.kotlin.verifyBlocking
import org.mockito.kotlin.whenever
import to.bitkit.repositories.LightningRepo
import to.bitkit.repositories.LightningState
import to.bitkit.repositories.ProbeDispatch
import to.bitkit.repositories.ProbeOutcome
import to.bitkit.services.CoreService
import to.bitkit.test.BaseUnitTest
import kotlin.test.assertTrue
@OptIn(ExperimentalCoroutinesApi::class)
class ProbingToolViewModelTest : BaseUnitTest() {
private lateinit var sut: ProbingToolViewModel
private val context = mock<Context>()
private val coreService = mock<CoreService>()
private val lightningRepo = mock<LightningRepo>()
@Before
fun setUp() {
whenever(lightningRepo.lightningState).thenReturn(MutableStateFlow(LightningState()))
sut = ProbingToolViewModel(
context = context,
bgDispatcher = testDispatcher,
coreService = coreService,
lightningRepo = lightningRepo,
)
}
@Test
fun `sendProbe uses node id from node URI`() = test {
val nodeId = "021a7a31f03a9b49807eb18ef03046e264871a1d03cd4cb80d37265499d1b726b9"
val nodeUri = "$nodeId@54.244.234.100:20319"
val paymentId = "probe-payment-id"
val paymentHash = "probe-payment-hash"
whenever(lightningRepo.sendProbeForNode(nodeId, 42uL))
.thenReturn(Result.success(ProbeDispatch(paymentIds = setOf(paymentId))))
whenever(lightningRepo.waitForProbeOutcome(setOf(paymentId)))
.thenReturn(
Result.success(
ProbeOutcome.Success(
paymentId = paymentId,
paymentHash = paymentHash,
routeFeeMsat = null,
)
)
)
sut.updateInvoice(nodeUri)
sut.updateAmountSats("42")
advanceUntilIdle()
assertTrue(sut.uiState.value.isNodeId)
sut.sendProbe()
advanceUntilIdle()
verifyBlocking(lightningRepo) { sendProbeForNode(nodeId, 42uL) }
}
}