-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathShortChannelIdTest.kt
More file actions
61 lines (51 loc) · 2.05 KB
/
Copy pathShortChannelIdTest.kt
File metadata and controls
61 lines (51 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package to.bitkit.ext
import org.junit.Test
import to.bitkit.test.BaseUnitTest
import kotlin.test.assertEquals
import kotlin.test.assertNull
class ShortChannelIdTest : BaseUnitTest() {
@Test
fun `formattedAsShortChannelId formats lnd scid into cln form`() {
// The two formats the issue calls out (LND uint64 and CLN block x tx x output)
// are two encodings of the same channel.
assertEquals("777477x916x0", 854_845_001_888_432_128uL.formattedAsShortChannelId())
}
@Test
fun `formattedAsShortChannelId formats from components`() {
val scid = (700_000uL shl 40) or (1uL shl 16) or 2uL
assertEquals("700000x1x2", scid.formattedAsShortChannelId())
}
@Test
fun `formattedAsShortChannelId formats zero as all zeroes`() {
assertEquals("0x0x0", 0uL.formattedAsShortChannelId())
}
@Test
fun `formattedAsShortChannelId keeps max components in their fields`() {
val scid = (0xFFFFFFuL shl 40) or (0xFFFFFFuL shl 16) or 0xFFFFuL
assertEquals("16777215x16777215x65535", scid.formattedAsShortChannelId())
}
@Test
fun `resolveDisplayShortChannelId prefers channel scid for open channel`() {
val result = resolveDisplayShortChannelId(
channelScid = 854_845_001_888_432_128uL,
linkedOrderScid = "0",
)
assertEquals("777477x916x0", result)
}
@Test
fun `resolveDisplayShortChannelId falls back to linked order scid for closed channel`() {
val result = resolveDisplayShortChannelId(
channelScid = null,
linkedOrderScid = "854845001888432128",
)
assertEquals("777477x916x0", result)
}
@Test
fun `resolveDisplayShortChannelId returns null when both unavailable`() {
assertNull(resolveDisplayShortChannelId(channelScid = null, linkedOrderScid = null))
}
@Test
fun `resolveDisplayShortChannelId returns null for non-numeric order scid`() {
assertNull(resolveDisplayShortChannelId(channelScid = null, linkedOrderScid = "not-a-number"))
}
}