@@ -12,6 +12,7 @@ import org.junit.Test
1212import org.lightningdevkit.ldknode.Event
1313import org.mockito.kotlin.any
1414import org.mockito.kotlin.anyOrNull
15+ import org.mockito.kotlin.clearInvocations
1516import org.mockito.kotlin.mock
1617import org.mockito.kotlin.verify
1718import org.mockito.kotlin.whenever
@@ -83,6 +84,8 @@ class AppViewModelSendFlowTest : BaseUnitTest() {
8384 private val formatMoneyValue = mock<FormatMoneyValue >()
8485
8586 private val balanceState = MutableStateFlow (BalanceState ())
87+ private val settingsData = MutableStateFlow (SettingsData ())
88+ private val walletState = MutableStateFlow (WalletState ())
8689 private val nodeEvents = MutableSharedFlow <Event >()
8790
8891 private val timedSheetManager = mock<TimedSheetManager >()
@@ -100,9 +103,9 @@ class AppViewModelSendFlowTest : BaseUnitTest() {
100103 whenever(lightningRepo.lightningState).thenReturn(MutableStateFlow (LightningState ()))
101104 whenever(lightningRepo.nodeEvents).thenReturn(nodeEvents)
102105 whenever(walletRepo.balanceState).thenReturn(balanceState)
103- whenever(walletRepo.walletState).thenReturn(MutableStateFlow ( WalletState ()) )
106+ whenever(walletRepo.walletState).thenReturn(walletState )
104107 whenever(walletRepo.walletExists()).thenReturn(true )
105- whenever(settingsStore.data).thenReturn(flowOf( SettingsData ()) )
108+ whenever(settingsStore.data).thenReturn(settingsData )
106109 whenever(cacheStore.data).thenReturn(flowOf(AppCacheData ()))
107110 whenever(transferRepo.activeTransfers).thenReturn(flowOf(emptyList()))
108111 whenever(timedSheetManager.currentSheet).thenReturn(MutableStateFlow (null ))
@@ -310,6 +313,44 @@ class AppViewModelSendFlowTest : BaseUnitTest() {
310313 assertNull(pendingContactPaymentContext(paymentHash))
311314 }
312315
316+ @Test
317+ fun `channel ready refreshes public Paykit endpoints when sharing enabled` () = test {
318+ enablePublicPaykitSharing()
319+ advanceUntilIdle()
320+ clearInvocations(publicPaykitRepo)
321+
322+ nodeEvents.emit(
323+ Event .ChannelReady (
324+ channelId = " testChannelId" ,
325+ userChannelId = " testUserChannelId" ,
326+ counterpartyNodeId = null ,
327+ fundingTxo = null ,
328+ ),
329+ )
330+ advanceUntilIdle()
331+
332+ verify(publicPaykitRepo).syncCurrentPublishedEndpoints()
333+ }
334+
335+ @Test
336+ fun `channel closed refreshes public Paykit endpoints when sharing enabled` () = test {
337+ enablePublicPaykitSharing()
338+ advanceUntilIdle()
339+ clearInvocations(publicPaykitRepo)
340+
341+ nodeEvents.emit(
342+ Event .ChannelClosed (
343+ channelId = " testChannelId" ,
344+ userChannelId = " testUserChannelId" ,
345+ counterpartyNodeId = null ,
346+ reason = null ,
347+ ),
348+ )
349+ advanceUntilIdle()
350+
351+ verify(publicPaykitRepo).syncCurrentPublishedEndpoints()
352+ }
353+
313354 @Test
314355 fun `amount change clears confirmedWarnings` () = test {
315356 setUnifiedState(amount = 1000u )
@@ -363,6 +404,12 @@ class AppViewModelSendFlowTest : BaseUnitTest() {
363404 assertEquals(0L , sut.sendUiState.value.lastLightningFee)
364405 }
365406
407+ private suspend fun enablePublicPaykitSharing () {
408+ settingsData.value = SettingsData (sharesPublicPaykitEndpoints = true )
409+ walletState.value = WalletState (onchainAddress = " bc1qtest" )
410+ whenever { publicPaykitRepo.syncCurrentPublishedEndpoints() }.thenReturn(Result .success(Unit ))
411+ }
412+
366413 @Suppress(" UNCHECKED_CAST" )
367414 private fun setPendingContactPaymentContext (paymentHash : String , publicKey : String ) {
368415 val field = AppViewModel ::class .java.getDeclaredField(" pendingContactPaymentContexts" )
0 commit comments