diff --git a/app/src/main/java/to/bitkit/data/CacheStore.kt b/app/src/main/java/to/bitkit/data/CacheStore.kt index 65cd48635b..47e49828e2 100644 --- a/app/src/main/java/to/bitkit/data/CacheStore.kt +++ b/app/src/main/java/to/bitkit/data/CacheStore.kt @@ -358,6 +358,8 @@ data class AppCacheData( val sentSparkWithdrawals: List = listOf(), /** Pubky Swaps routes committed or restored whose claim has not confirmed yet, so each start resumes them. */ val unfinishedPubkySwaps: List = listOf(), + /** The hold payment hash of each unfinished Pubky Swaps route by swap id, so its failure stops the swap. */ + val pubkySwapHoldHashes: Map = mapOf(), /** Hashes of the latest Lightning sends Spark started, so the node holds off while Spark can't list them. */ val sparkSendHashes: List = listOf(), /** Invoice expiry in epoch seconds of the [sparkSendHashes] that know it. */ diff --git a/app/src/main/java/to/bitkit/repositories/PubkySwapsRouteRepo.kt b/app/src/main/java/to/bitkit/repositories/PubkySwapsRouteRepo.kt index 9b759ba7a0..4beceec66c 100644 --- a/app/src/main/java/to/bitkit/repositories/PubkySwapsRouteRepo.kt +++ b/app/src/main/java/to/bitkit/repositories/PubkySwapsRouteRepo.kt @@ -16,6 +16,7 @@ import kotlinx.coroutines.CompletableDeferred import kotlinx.coroutines.CoroutineDispatcher import kotlinx.coroutines.CoroutineStart import kotlinx.coroutines.Job +import kotlinx.coroutines.SupervisorJob import kotlinx.coroutines.async import kotlinx.coroutines.coroutineScope import kotlinx.coroutines.delay @@ -32,6 +33,7 @@ import kotlinx.coroutines.launch import kotlinx.coroutines.selects.select import kotlinx.coroutines.withContext import kotlinx.coroutines.withTimeoutOrNull +import org.lightningdevkit.ldknode.Event import org.lightningdevkit.ldknode.PaymentDirection import org.lightningdevkit.ldknode.PaymentKind import org.lightningdevkit.ldknode.PaymentStatus @@ -48,11 +50,13 @@ import to.bitkit.utils.AppError import to.bitkit.utils.Logger import to.bitkit.utils.ServiceError import java.util.concurrent.ConcurrentHashMap +import java.util.concurrent.atomic.AtomicBoolean import javax.inject.Inject import javax.inject.Singleton import kotlin.time.Duration import kotlin.time.Duration.Companion.minutes import kotlin.time.Duration.Companion.seconds +import breez_sdk_spark.PaymentStatus as SparkPaymentStatus /** * Routes a Paykit payment through a Pubky Swaps provider when no balance the wallet holds reaches an endpoint the @@ -97,6 +101,18 @@ class PubkySwapsRouteRepo @Inject constructor( /** The loop advancing each swap in the background, one per swap. */ private val advancing = ConcurrentHashMap() + /** The parent of this wallet's claim waits, which a wipe cancels, so a wait starting meanwhile stops too. */ + @Volatile + private var walletJob = SupervisorJob() + + /** Swaps this session committed, which the send flow drives, so a restore listing them leaves them alone. */ + private val committed = ConcurrentHashMap.newKeySet() + + /** Swaps whose hold payment failed this session, which nothing advances again. */ + private val dropped = ConcurrentHashMap.newKeySet() + + private val isWatchingHolds = AtomicBoolean(false) + val isEnabled: Boolean get() = Env.isPubkySwapsRouteEnabled /** The contact behind a provider's pubky, so the review shows who routes the payment. */ @@ -163,8 +179,12 @@ class PubkySwapsRouteRepo @Inject constructor( /** Stops the wiped wallet's restore and background swaps, so a wallet restored next starts from nothing. */ fun resetForWipe() { wipes.update { it + 1 } + walletJob.cancel() + walletJob = SupervisorJob() advancing.values.forEach { it.cancel() } advancing.clear() + committed.clear() + dropped.clear() } /** @@ -205,6 +225,8 @@ class PubkySwapsRouteRepo @Inject constructor( // Only a restore that returned its swaps marks their providers read, so a failed one asks them again. run.restoredProviders += readInFull if (incomplete.isNotEmpty()) Logger.warn("Swap lists incomplete from '$incomplete'", context = TAG) + // A swap committed or dropped this session is the send flow's, so a later restore pass never takes it up again. + known.removeAll { it in committed || it in dropped } track(restored + known) RestoredPubkySwaps( restored = restored.filter(run.reportedSwaps::add), @@ -239,7 +261,17 @@ class PubkySwapsRouteRepo @Inject constructor( /** Commits the quote and keeps its swap until its claim confirms or it fails, so a later start resumes it. */ suspend fun commit(quoteId: String): Result = withSecrets { mnemonic, passphrase -> - pubkySwapsCommitRoute(quoteId, Env.electrumServerUrl, mnemonic, passphrase).also { track(listOf(it.swapId)) } + pubkySwapsCommitRoute(quoteId, Env.electrumServerUrl, mnemonic, passphrase).also { + committed.add(it.swapId) + track(listOf(it.swapId)) + } + } + + /** Records the hold payment of a committed swap, so its failure stops the swap, also after a restart. */ + suspend fun watchHold(swapId: String, holdPaymentHash: String) { + runSuspendCatching { + cacheStore.update { it.copy(pubkySwapHoldHashes = it.pubkySwapHoldHashes + (swapId to holdPaymentHash)) } + }.onFailure { Logger.warn("Failed to record hold payment of Pubky Swaps route '$swapId'", it, context = TAG) } } /** @@ -247,6 +279,7 @@ class PubkySwapsRouteRepo @Inject constructor( * hold invoice once it sees the claim, so a claim that never confirms could leave the contact unpaid. */ fun resumeUnfinishedSwaps() { + watchHoldFailures() scope.launch { cacheStore.data.first().unfinishedPubkySwaps .filterNot { it in claiming } @@ -254,6 +287,33 @@ class PubkySwapsRouteRepo @Inject constructor( } } + private fun watchHoldFailures() { + if (!isWatchingHolds.compareAndSet(false, true)) return + scope.launch { + lightningRepo.nodeEvents.collect { event -> + val hash = (event as? Event.PaymentFailed)?.paymentHash ?: return@collect + cacheStore.data.first().pubkySwapHoldHashes.filterValues { it == hash }.keys.forEach { + Logger.info("Stopping Pubky Swaps route '$it' after its hold payment failed", context = TAG) + dropFailedSwap(it) + } + } + } + } + + // The hold goes out over the node or Spark, which shares its hash and decides a send the node failed. + private suspend fun isHoldFailed(swapId: String): Boolean { + val hash = cacheStore.data.first().pubkySwapHoldHashes[swapId] ?: return false + val node = lightningRepo.getPayments().getOrNull() + ?.firstOrNull { (it.kind as? PaymentKind.Bolt11)?.hash.equals(hash, ignoreCase = true) } + ?.status + if (node != null && node != PaymentStatus.FAILED) return false + return when (val spark = runSuspendCatching { lightningRepo.sparkLightningSend(hash) }.getOrNull()) { + is SparkLightningSend.Found -> spark.status == SparkPaymentStatus.FAILED + SparkLightningSend.NotFound -> node == PaymentStatus.FAILED + SparkLightningSend.Unavailable, null -> false + } + } + /** * Advance the swap until bitkit-core broadcasts the claim to the contact, returning the claim txid. The provider * settles the hold invoice once it sees the claim, so the payment is done; the claim is still advanced in the @@ -266,7 +326,8 @@ class PubkySwapsRouteRepo @Inject constructor( swapId: String, timeout: Duration = CLAIM_TIMEOUT, holdFailure: Job? = null, - ): Result = scope.async { + ): Result = scope.async(walletJob) { + if (swapId in dropped) return@async Result.failure(PubkySwapHoldFailedException(swapId)) claiming.add(swapId) try { awaitClaimOnce(swapId, timeout, holdFailure) @@ -308,7 +369,7 @@ class PubkySwapsRouteRepo @Inject constructor( } private fun advanceInBackground(swapId: String) { - if (advancing.containsKey(swapId)) return + if (advancing.containsKey(swapId) || swapId in dropped) return val loop = scope.launch(start = CoroutineStart.LAZY) { try { awaitConfirmation(swapId) @@ -324,12 +385,14 @@ class PubkySwapsRouteRepo @Inject constructor( * only poll until bitkit-core gives up. */ suspend fun dropFailedSwap(swapId: String) { + dropped.add(swapId) advancing.remove(swapId)?.cancel() untrack(swapId) } private suspend fun awaitConfirmation(swapId: String) { pollClaim(swapId, CONFIRMATION_POLL_INTERVAL, untilConfirmed = true) {} + .onFailure { if (it is PubkySwapHoldFailedException) dropped.add(swapId) } .onSuccess { Logger.info("Confirmed Pubky Swaps claim '$it' for '$swapId'", context = TAG) } .onFailure { Logger.warn("Failed to confirm Pubky Swaps claim for '$swapId'", it, context = TAG) } untrack(swapId) @@ -345,7 +408,12 @@ class PubkySwapsRouteRepo @Inject constructor( private suspend fun untrack(swapId: String) { runSuspendCatching { - cacheStore.update { it.copy(unfinishedPubkySwaps = it.unfinishedPubkySwaps - swapId) } + cacheStore.update { + it.copy( + unfinishedPubkySwaps = it.unfinishedPubkySwaps - swapId, + pubkySwapHoldHashes = it.pubkySwapHoldHashes - swapId, + ) + } }.onFailure { Logger.warn("Failed to drop finished Pubky Swaps route '$swapId'", it, context = TAG) } } @@ -356,6 +424,10 @@ class PubkySwapsRouteRepo @Inject constructor( onPending: (Throwable) -> Unit, ): Result { while (true) { + // A swap whose hold failed, also while the app was closed or over Spark, is never funded. + if (swapId in dropped || untilConfirmed && isHoldFailed(swapId)) { + return Result.failure(PubkySwapHoldFailedException(swapId)) + } // A failed advance, such as a transient Electrum error, is retried: the swap is already funded. A swap // bitkit-core has no record of, as one carried over by a metadata backup, never advances, so it ends here. val advance = withSecrets { mnemonic, passphrase -> pubkySwapsAdvance(swapId, mnemonic, passphrase) } diff --git a/app/src/main/java/to/bitkit/viewmodels/AppViewModel.kt b/app/src/main/java/to/bitkit/viewmodels/AppViewModel.kt index a2a8eec8f0..f799eee422 100644 --- a/app/src/main/java/to/bitkit/viewmodels/AppViewModel.kt +++ b/app/src/main/java/to/bitkit/viewmodels/AppViewModel.kt @@ -589,7 +589,7 @@ class AppViewModel @Inject constructor( @Volatile private var committedSwap: CommittedSwap? = null - /** The swap behind each hold payment still out, so a hold that fails stops its swap. */ + /** The swap behind each hold payment still out, so a hold that fails gives the contact's list back. */ private val swapIdsByHoldHash = ConcurrentHashMap() private var isPresentingPaymentRequest = false private val isPaymentRequestPollingStopped = MutableStateFlow(false) @@ -7353,6 +7353,8 @@ class AppViewModel @Inject constructor( } } val tagsSaved = saveSwapRouteTags(holdPaymentHash, tags, address) + // Recorded before the payment goes out, so a hold failing at any point stops the swap. + pubkySwapsRouteRepo.watchHold(payment.swapId, holdPaymentHash) val holdFailure = viewModelScope.async(start = CoroutineStart.UNDISPATCHED) { lightningRepo.nodeEvents.watchUntil { when (it) { @@ -7512,14 +7514,10 @@ class AppViewModel @Inject constructor( } private fun releaseFailedSwapHold(paymentHash: String) { - // The provider never funds a swap whose hold payment failed, so it stops advancing, and the contact's list - // paid nothing. - swapIdsByHoldHash.remove(paymentHash)?.let { swapId -> + // A failed hold payment paid the contact's list nothing; the swaps repo stops the swap itself. + swapIdsByHoldHash.remove(paymentHash)?.let { val context = synchronized(contactPaymentContextLock) { pendingContactPaymentContexts[paymentHash] } - viewModelScope.launch { - pubkySwapsRouteRepo.dropFailedSwap(swapId) - releaseSwapPrivatePaymentList(context) - } + viewModelScope.launch { releaseSwapPrivatePaymentList(context) } } val swap = committedSwap?.takeIf { it.holdPaymentHash == paymentHash } ?: return committedSwap = null @@ -8866,6 +8864,8 @@ class AppViewModel @Inject constructor( } if (_currentSheet.value is Sheet.Send) { sendStateGeneration++ + // A closed send is over: a swap failing for it later gives no contact back to whatever comes next. + sendSession++ // A payment still running for the dismissed send, like a slow swap commit, must not block the next. if (confirmedPaymentSubmission != null) releaseConfirmedPaymentSubmission() cancelHardwarePaymentRequestIfNeeded() diff --git a/app/src/test/java/to/bitkit/repositories/PubkySwapsRouteRepoTest.kt b/app/src/test/java/to/bitkit/repositories/PubkySwapsRouteRepoTest.kt index 040a32a30f..2992250666 100644 --- a/app/src/test/java/to/bitkit/repositories/PubkySwapsRouteRepoTest.kt +++ b/app/src/test/java/to/bitkit/repositories/PubkySwapsRouteRepoTest.kt @@ -11,6 +11,7 @@ import com.synonym.bitkitcore.pubkySwapsRestore import kotlinx.coroutines.CompletableDeferred import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.async +import kotlinx.coroutines.flow.MutableSharedFlow import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.take import kotlinx.coroutines.flow.toList @@ -22,6 +23,11 @@ import kotlinx.coroutines.test.advanceUntilIdle import kotlinx.coroutines.test.runCurrent import org.junit.Before import org.junit.Test +import org.lightningdevkit.ldknode.Event +import org.lightningdevkit.ldknode.PaymentDetails +import org.lightningdevkit.ldknode.PaymentDirection +import org.lightningdevkit.ldknode.PaymentKind +import org.lightningdevkit.ldknode.PaymentStatus import org.mockito.Mockito.mockStatic import org.mockito.kotlin.any import org.mockito.kotlin.anyOrNull @@ -29,6 +35,7 @@ import org.mockito.kotlin.atLeast import org.mockito.kotlin.doReturn import org.mockito.kotlin.eq import org.mockito.kotlin.mock +import org.mockito.kotlin.never import org.mockito.kotlin.times import org.mockito.kotlin.verify import org.mockito.kotlin.whenever @@ -43,12 +50,14 @@ import kotlin.test.assertIs import kotlin.test.assertTrue import kotlin.time.Duration.Companion.minutes import kotlin.time.Duration.Companion.seconds +import breez_sdk_spark.PaymentStatus as SparkPaymentStatus class PubkySwapsRouteRepoTest : BaseUnitTest() { companion object { private const val SWAP_ID = "swap" private const val CLAIM_TXID = "claim" private const val CONFIRMED_CLAIM_TXID = "confirmed" + private const val HOLD_HASH = "hold" /** The Kotlin facade holding bitkit-core's top-level functions, which Kotlin sources cannot name. */ private val CORE: Class<*> = Class.forName("com.synonym.bitkitcore.Bitkitcore_androidKt") @@ -57,7 +66,8 @@ class PubkySwapsRouteRepoTest : BaseUnitTest() { private val keychain = mock() private val contacts = MutableStateFlow>(emptyList()) private val pubkyRepo = mock { on { contacts } doReturn contacts } - private val lightningRepo = mock() + private val nodeEvents = MutableSharedFlow() + private val lightningRepo = mock { on { nodeEvents } doReturn nodeEvents } private val cacheData = MutableStateFlow(AppCacheData()) private val cacheStore = mock { on { data } doReturn cacheData } private lateinit var sut: PubkySwapsRouteRepo @@ -347,6 +357,137 @@ class PubkySwapsRouteRepoTest : BaseUnitTest() { assertEquals(listOf(listOf("provider-a"), listOf("provider-a")), asked) } + @Test + @OptIn(ExperimentalCoroutinesApi::class) + fun `resumeUnfinishedSwaps drops a swap whose hold payment failed while the app was closed`() = test { + cacheData.value = AppCacheData( + unfinishedPubkySwaps = listOf(SWAP_ID), + pubkySwapHoldHashes = mapOf(SWAP_ID to HOLD_HASH), + ) + whenever(lightningRepo.getPayments()).thenReturn(Result.success(listOf(holdPayment(PaymentStatus.FAILED)))) + whenever(lightningRepo.sparkLightningSend(HOLD_HASH)).thenReturn(SparkLightningSend.NotFound) + mockStatic(CORE).use { core -> + sut.resumeUnfinishedSwaps() + advanceUntilIdle() + + core.verify({ runBlocking { pubkySwapsAdvance(any(), any(), anyOrNull()) } }, never()) + assertEquals(emptyList(), cacheData.value.unfinishedPubkySwaps) + assertEquals(emptyMap(), cacheData.value.pubkySwapHoldHashes) + } + } + + @Test + @OptIn(ExperimentalCoroutinesApi::class) + fun `resumeUnfinishedSwaps drops a swap whose hold payment failed over spark`() = test { + cacheData.value = AppCacheData( + unfinishedPubkySwaps = listOf(SWAP_ID), + pubkySwapHoldHashes = mapOf(SWAP_ID to HOLD_HASH), + ) + whenever(lightningRepo.getPayments()).thenReturn(Result.success(emptyList())) + whenever(lightningRepo.sparkLightningSend(HOLD_HASH)) + .thenReturn(SparkLightningSend.Found(SparkPaymentStatus.FAILED, preimage = null)) + mockStatic(CORE).use { core -> + sut.resumeUnfinishedSwaps() + advanceUntilIdle() + + core.verify({ runBlocking { pubkySwapsAdvance(any(), any(), anyOrNull()) } }, never()) + assertEquals(emptyList(), cacheData.value.unfinishedPubkySwaps) + } + } + + @Test + @OptIn(ExperimentalCoroutinesApi::class) + fun `a hold payment failing stops its resumed swap`() = test { + cacheData.value = AppCacheData( + unfinishedPubkySwaps = listOf(SWAP_ID), + pubkySwapHoldHashes = mapOf(SWAP_ID to HOLD_HASH), + ) + whenever(lightningRepo.getPayments()).thenReturn(Result.success(listOf(holdPayment(PaymentStatus.PENDING)))) + mockStatic(CORE).use { core -> + var calls = 0 + core.`when` { runBlocking { pubkySwapsAdvance(any(), any(), anyOrNull()) } }.thenAnswer { + calls++ + status(PubkySwapRouteState.AwaitingLockup(confirmations = 0u, required = 1u)) + } + + sut.resumeUnfinishedSwaps() + runCurrent() + nodeEvents.emit(Event.PaymentFailed(paymentId = HOLD_HASH, paymentHash = HOLD_HASH, reason = null)) + runCurrent() + val callsAtFailure = calls + advanceTimeBy(10.minutes) + runCurrent() + + assertTrue(callsAtFailure > 0) + assertEquals(callsAtFailure, calls) + assertEquals(emptyList(), cacheData.value.unfinishedPubkySwaps) + } + } + + @Test + @OptIn(ExperimentalCoroutinesApi::class) + fun `dropFailedSwap stops a running claim wait`() = test { + mockStatic(CORE).use { core -> + var calls = 0 + core.`when` { runBlocking { pubkySwapsAdvance(any(), any(), anyOrNull()) } }.thenAnswer { + calls++ + status(PubkySwapRouteState.AwaitingLockup(confirmations = 0u, required = 1u)) + } + + val claim = async { sut.awaitClaim(SWAP_ID) } + runCurrent() + sut.dropFailedSwap(SWAP_ID) + advanceTimeBy(5.seconds) + runCurrent() + val callsAfterDrop = calls + advanceTimeBy(20.minutes) + runCurrent() + + assertIs(claim.await().exceptionOrNull()) + assertEquals(callsAfterDrop, calls) + assertIs(sut.awaitClaim(SWAP_ID).exceptionOrNull()) + } + } + + @Test + @OptIn(ExperimentalCoroutinesApi::class) + fun `resetForWipe stops a running claim wait`() = test { + mockStatic(CORE).use { core -> + var calls = 0 + core.`when` { runBlocking { pubkySwapsAdvance(any(), any(), anyOrNull()) } }.thenAnswer { + calls++ + status(PubkySwapRouteState.AwaitingLockup(confirmations = 0u, required = 1u)) + } + + val caller = launch { sut.awaitClaim(SWAP_ID) } + runCurrent() + sut.resetForWipe() + runCurrent() + val callsAtWipe = calls + advanceTimeBy(20.minutes) + runCurrent() + + assertEquals(callsAtWipe, calls) + assertTrue(caller.isCompleted) + } + } + + @Test + @OptIn(ExperimentalCoroutinesApi::class) + fun `restoredSwaps leaves a swap dropped this session alone`() = test { + contacts.value = listOf(PubkyProfile.placeholder("provider-a")) + sut.dropFailedSwap(SWAP_ID) + val asked = mutableListOf>() + val found = mutableListOf() + restoring(asked, report(known = listOf(SWAP_ID, "other-swap"))) { + backgroundScope.launch { sut.restoredSwaps().collect { found += it } } + advanceUntilIdle() + } + + assertEquals(listOf(listOf("other-swap")), found.map { it.known }) + assertEquals(listOf("other-swap"), cacheData.value.unfinishedPubkySwaps) + } + private suspend fun restoring( asked: MutableList>, vararg reports: PubkySwapRestoreReport, @@ -382,9 +523,10 @@ class PubkySwapsRouteRepoTest : BaseUnitTest() { private fun report( restored: List = emptyList(), incomplete: List = emptyList(), + known: List = emptyList(), ) = PubkySwapRestoreReport( restored = restored, - known = emptyList(), + known = known, finished = emptyList(), incompleteProviders = incomplete, ) @@ -408,4 +550,20 @@ class PubkySwapsRouteRepoTest : BaseUnitTest() { deliveredSat = 20_000u, destinationAddress = "address", ) + + private fun holdPayment(status: PaymentStatus) = PaymentDetails( + id = HOLD_HASH, + kind = PaymentKind.Bolt11( + hash = HOLD_HASH, + preimage = null, + secret = null, + description = null, + bolt11 = "bolt11" + ), + amountMsat = 1_000_000uL, + feePaidMsat = null, + direction = PaymentDirection.OUTBOUND, + status = status, + latestUpdateTimestamp = 0uL, + ) } diff --git a/app/src/test/java/to/bitkit/viewmodels/AppViewModelSendFlowTest.kt b/app/src/test/java/to/bitkit/viewmodels/AppViewModelSendFlowTest.kt index 37adc82582..c57599693b 100644 --- a/app/src/test/java/to/bitkit/viewmodels/AppViewModelSendFlowTest.kt +++ b/app/src/test/java/to/bitkit/viewmodels/AppViewModelSendFlowTest.kt @@ -19951,8 +19951,8 @@ class AppViewModelSendFlowTest : BaseUnitTest() { cancelAndIgnoreRemainingEvents() } verify(pubkySwapsRouteRepo, times(2)).commit(SWAP_QUOTE_ID) - // The failed hold's swap stops advancing; the retry's swap goes on. - verify(pubkySwapsRouteRepo, times(1)).dropFailedSwap(SWAP_ID) + // Each hold is recorded before it goes out, so the swaps repo stops the swap whose hold fails. + verify(pubkySwapsRouteRepo, times(2)).watchHold(SWAP_ID, SWAP_HOLD_HASH) verify(activityRepo).setContact( contactPublicKey = eq(testPublicKey), forPaymentId = eq(SWAP_HOLD_HASH), @@ -20003,6 +20003,30 @@ class AppViewModelSendFlowTest : BaseUnitTest() { assertSame(contactPaymentContextB, activeContactPaymentContext()) } + @Test + fun `swap route hold failing after its sheet closed leaves no contact behind`() = test { + whenever(pubkySwapsRouteRepo.commit(SWAP_QUOTE_ID)).thenReturn(Result.success(swapRoutePayment())) + whenever(lightningRepo.payInvoice(eq(SWAP_HOLD_INVOICE), anyOrNull())) + .thenReturn(Result.success(SWAP_HOLD_HASH)) + whenever(pubkySwapsRouteRepo.awaitClaim(eq(SWAP_ID), any(), anyOrNull())) + .thenReturn(Result.failure(PubkySwapClaimTimeoutException(SWAP_ID, AppError("awaiting lockup")))) + openSwapRoutedContactPayment() + + sut.sendEffect.test { + sut.setSendEvent(SendEvent.AmountContinue) + advanceUntilIdle() + assertEquals(SendEffect.NavigateToConfirm, awaitItem()) + confirmSwapRoutedPayment() + assertEquals(swapHoldPending(), awaitItem()) + sut.hideSheet() + emitSwapHoldPaymentFailed() + advanceBeforeHoldWatchDeadline() + cancelAndIgnoreRemainingEvents() + } + assertNull(sut.currentSheet.value) + assertNull(activeContactPaymentContext()) + } + @Test fun `swap route commit after dismissal leaves its hold payment off the next send`() = test { val commit = CompletableDeferred>()