|
| 1 | +package to.bitkit.ext |
| 2 | + |
| 3 | +import org.junit.Test |
| 4 | +import to.bitkit.test.BaseUnitTest |
| 5 | +import kotlin.test.assertEquals |
| 6 | +import kotlin.test.assertNull |
| 7 | + |
| 8 | +class ShortChannelIdTest : BaseUnitTest() { |
| 9 | + |
| 10 | + @Test |
| 11 | + fun `formattedAsShortChannelId formats lnd scid into cln form`() { |
| 12 | + // The two formats the issue calls out (LND uint64 and CLN block x tx x output) |
| 13 | + // are two encodings of the same channel. |
| 14 | + assertEquals("777477x916x0", 854_845_001_888_432_128uL.formattedAsShortChannelId()) |
| 15 | + } |
| 16 | + |
| 17 | + @Test |
| 18 | + fun `formattedAsShortChannelId formats from components`() { |
| 19 | + val scid = (700_000uL shl 40) or (1uL shl 16) or 2uL |
| 20 | + assertEquals("700000x1x2", scid.formattedAsShortChannelId()) |
| 21 | + } |
| 22 | + |
| 23 | + @Test |
| 24 | + fun `formattedAsShortChannelId formats zero as all zeroes`() { |
| 25 | + assertEquals("0x0x0", 0uL.formattedAsShortChannelId()) |
| 26 | + } |
| 27 | + |
| 28 | + @Test |
| 29 | + fun `formattedAsShortChannelId keeps max components in their fields`() { |
| 30 | + val scid = (0xFFFFFFuL shl 40) or (0xFFFFFFuL shl 16) or 0xFFFFuL |
| 31 | + assertEquals("16777215x16777215x65535", scid.formattedAsShortChannelId()) |
| 32 | + } |
| 33 | + |
| 34 | + @Test |
| 35 | + fun `resolveDisplayShortChannelId prefers channel scid for open channel`() { |
| 36 | + val result = resolveDisplayShortChannelId( |
| 37 | + channelScid = 854_845_001_888_432_128uL, |
| 38 | + linkedOrderScid = "0", |
| 39 | + ) |
| 40 | + assertEquals("777477x916x0", result) |
| 41 | + } |
| 42 | + |
| 43 | + @Test |
| 44 | + fun `resolveDisplayShortChannelId keeps cln-form linked order scid for closed channel`() { |
| 45 | + // Blocktank delivers the order scid already in `block x tx x output` form. |
| 46 | + val result = resolveDisplayShortChannelId(channelScid = null, linkedOrderScid = "792906x599x1") |
| 47 | + assertEquals("792906x599x1", result) |
| 48 | + } |
| 49 | + |
| 50 | + @Test |
| 51 | + fun `resolveDisplayShortChannelId decodes numeric linked order scid`() { |
| 52 | + val result = resolveDisplayShortChannelId(channelScid = null, linkedOrderScid = "854845001888432128") |
| 53 | + assertEquals("777477x916x0", result) |
| 54 | + } |
| 55 | + |
| 56 | + @Test |
| 57 | + fun `resolveDisplayShortChannelId returns null when both unavailable`() { |
| 58 | + assertNull(resolveDisplayShortChannelId(channelScid = null, linkedOrderScid = null)) |
| 59 | + assertNull(resolveDisplayShortChannelId(channelScid = null, linkedOrderScid = "")) |
| 60 | + } |
| 61 | + |
| 62 | + @Test |
| 63 | + fun `resolveDisplayShortChannelId returns null for malformed order scid`() { |
| 64 | + assertNull(resolveDisplayShortChannelId(channelScid = null, linkedOrderScid = "not-a-scid")) |
| 65 | + } |
| 66 | +} |
0 commit comments