From d1618a227786ee8a47717b33db90b8aae5ad4d61 Mon Sep 17 00:00:00 2001 From: Chris Stewart Date: Tue, 26 Nov 2024 11:13:06 -0600 Subject: [PATCH] Add unit test for RescanState to test recursive rescans correctly (#5786) --- .../core/wallet/rescan/RescanStateTest.scala | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/core-test/.jvm/src/test/scala/org/bitcoins/core/wallet/rescan/RescanStateTest.scala b/core-test/.jvm/src/test/scala/org/bitcoins/core/wallet/rescan/RescanStateTest.scala index f71945b3fe..b436e0ba8e 100644 --- a/core-test/.jvm/src/test/scala/org/bitcoins/core/wallet/rescan/RescanStateTest.scala +++ b/core-test/.jvm/src/test/scala/org/bitcoins/core/wallet/rescan/RescanStateTest.scala @@ -68,4 +68,25 @@ class RescanStateTest extends BitcoinSAsyncTest { recoverToSucceededIf[RuntimeException](resultF) } + + it must "handle stopping recursive rescan correctly" in { + val completeRescanEarlyP = Promise[Option[Int]]() + val recursiveRescanP = Promise[RescanState]() + val blocksMatchedF = completeRescanEarlyP.future.map(_ => Vector.empty) + val rescanState = RescanState.RescanStarted(completeRescanEarlyP, + blocksMatchedF, + recursiveRescanP) + + val recursiveRescanCompleteEarlyP = Promise[Option[Int]]() + val recursiveRescanStarted = RescanState.RescanStarted( + recursiveRescanCompleteEarlyP, + recursiveRescanCompleteEarlyP.future.map(_ => Vector.empty), + Promise()) + recursiveRescanP.success(recursiveRescanStarted) + for { + _ <- rescanState.stop() + _ <- recoverToSucceededIf[RescanTerminatedEarly.type]( + rescanState.blocksMatchedF) + } yield succeed + } }