Skip to content

Commit db4e403

Browse files
committed
test: load trusted peers from bt info
1 parent 3d82c14 commit db4e403

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed

app/src/test/java/to/bitkit/repositories/LightningRepoTest.kt

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package to.bitkit.repositories
33
import app.cash.turbine.test
44
import com.google.firebase.messaging.FirebaseMessaging
55
import com.synonym.bitkitcore.FeeRates
6+
import com.synonym.bitkitcore.IBtInfo
7+
import com.synonym.bitkitcore.ILspNode
68
import kotlinx.coroutines.flow.flowOf
79
import org.junit.Before
810
import org.junit.Test
@@ -13,9 +15,11 @@ import org.lightningdevkit.ldknode.PeerDetails
1315
import org.lightningdevkit.ldknode.SpendableUtxo
1416
import org.mockito.kotlin.any
1517
import org.mockito.kotlin.anyOrNull
18+
import org.mockito.kotlin.argThat
1619
import org.mockito.kotlin.doReturn
1720
import org.mockito.kotlin.eq
1821
import org.mockito.kotlin.inOrder
22+
import org.mockito.kotlin.isNull
1923
import org.mockito.kotlin.mock
2024
import org.mockito.kotlin.spy
2125
import org.mockito.kotlin.verify
@@ -583,4 +587,66 @@ class LightningRepoTest : BaseUnitTest() {
583587
assertTrue(result.isFailure)
584588
assertEquals(serviceError, result.exceptionOrNull())
585589
}
590+
591+
@Test
592+
fun `start should load trusted peers from blocktank info`() = test {
593+
sut.setInitNodeLifecycleState()
594+
whenever(lightningService.node).thenReturn(null)
595+
whenever(lightningService.setup(any(), anyOrNull(), anyOrNull(), anyOrNull())).thenReturn(Unit)
596+
whenever(lightningService.start(anyOrNull(), any())).thenReturn(Unit)
597+
whenever(settingsStore.data).thenReturn(flowOf(SettingsData()))
598+
599+
val blocktank = mock<BlocktankService>()
600+
whenever(coreService.blocktank).thenReturn(blocktank)
601+
602+
val mockNodes = listOf(
603+
ILspNode(
604+
alias = "LSP1",
605+
pubkey = "node1pubkey",
606+
connectionStrings = listOf("node1.example.com:9735"),
607+
readonly = null,
608+
),
609+
ILspNode(
610+
alias = "LSP2",
611+
pubkey = "node2pubkey",
612+
connectionStrings = listOf("node2.example.com:9735"),
613+
readonly = null,
614+
),
615+
)
616+
val mockInfo = mock<IBtInfo> { on { nodes } doReturn mockNodes }
617+
whenever(blocktank.info(refresh = false)).thenReturn(mockInfo)
618+
619+
val result = sut.start()
620+
621+
assertTrue(result.isSuccess)
622+
verify(lightningService).setup(
623+
any(),
624+
anyOrNull(),
625+
anyOrNull(),
626+
argThat { peers ->
627+
peers?.size == 2 &&
628+
peers.any { it.nodeId == "node1pubkey" } &&
629+
peers.any { it.nodeId == "node2pubkey" }
630+
}
631+
)
632+
}
633+
634+
@Test
635+
fun `start should pass null trusted peers when blocktank returns null`() = test {
636+
sut.setInitNodeLifecycleState()
637+
whenever(lightningService.node).thenReturn(null)
638+
whenever(lightningService.setup(any(), anyOrNull(), anyOrNull(), anyOrNull())).thenReturn(Unit)
639+
whenever(lightningService.start(anyOrNull(), any())).thenReturn(Unit)
640+
whenever(settingsStore.data).thenReturn(flowOf(SettingsData()))
641+
642+
val blocktank = mock<BlocktankService>()
643+
whenever(coreService.blocktank).thenReturn(blocktank)
644+
whenever(blocktank.info(refresh = false)).thenReturn(null)
645+
whenever(blocktank.info(refresh = true)).thenReturn(null)
646+
647+
val result = sut.start()
648+
649+
assertTrue(result.isSuccess)
650+
verify(lightningService).setup(any(), anyOrNull(), anyOrNull(), isNull())
651+
}
586652
}

0 commit comments

Comments
 (0)