File tree Expand file tree Collapse file tree
main/java/to/bitkit/repositories
test/java/to/bitkit/repositories Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -144,7 +144,7 @@ class BlocktankRepo @Inject constructor(
144144 val hasPendingCjit = cached.any {
145145 it.channel == null && it.state != CJitStateEnum .EXPIRED && it.state != CJitStateEnum .FAILED
146146 }
147- if (! hasPendingCjit) return @withContext null
147+ if (cached.isNotEmpty() && ! hasPendingCjit) return @withContext null
148148
149149 // Match against the freshly fetched list so a concurrent refreshOrders() can't clobber state before we read.
150150 return @withContext refreshCjitEntries().matching()
Original file line number Diff line number Diff line change @@ -377,6 +377,24 @@ class BlocktankRepoTest : BaseUnitTest() {
377377 assertEquals(entry, sut.getCjitEntry(channelDetails))
378378 }
379379
380+ @Test
381+ fun `getCjitEntry refreshes when the cache is empty` () = test {
382+ sut = createSut()
383+ // Cold start / right after createCjit: cjitEntries hasn't loaded yet, so an empty cache must not be
384+ // treated as a terminal no-match — the server refresh has to surface the matching entry.
385+ val fundingTxId = " cjit-funding-tx"
386+ val channel = mock<IBtChannel >()
387+ whenever(channel.fundingTx).thenReturn(FundingTx (id = fundingTxId, vout = 0u ))
388+ val entry = mock<IcJitEntry >()
389+ whenever(entry.channel).thenReturn(channel)
390+ whenever(coreService.blocktank.cjitEntries(refresh = true )).thenReturn(listOf (entry))
391+
392+ val channelDetails = mock<ChannelDetails >()
393+ whenever(channelDetails.fundingTxo).thenReturn(OutPoint (txid = fundingTxId, vout = 0u ))
394+
395+ assertEquals(entry, sut.getCjitEntry(channelDetails))
396+ }
397+
380398 private fun pendingCjitEntry (): IcJitEntry = mock<IcJitEntry >().apply {
381399 whenever(channel).thenReturn(null )
382400 whenever(state).thenReturn(CJitStateEnum .CREATED )
You can’t perform that action at this time.
0 commit comments