@@ -2,13 +2,16 @@ package to.bitkit.ext
22
33import android.content.Context
44import org.junit.Test
5+ import org.lightningdevkit.ldknode.NodeException
56import org.lightningdevkit.ldknode.PaymentFailureReason
67import org.mockito.kotlin.mock
78import org.mockito.kotlin.whenever
89import to.bitkit.R
910import to.bitkit.models.SendFailureDetails
11+ import to.bitkit.utils.LdkError
1012import kotlin.test.assertEquals
1113import kotlin.test.assertFalse
14+ import kotlin.test.assertNotEquals
1215import kotlin.test.assertTrue
1316
1417class PaymentFailureReasonExtTest {
@@ -38,13 +41,34 @@ class PaymentFailureReasonExtTest {
3841 whenever(context.getString(R .string.wallet__payment_failed_description)).thenReturn(message)
3942
4043 assertEquals(message, Exception (" " ).toSendFailureMessage(context))
41- assertEquals(message, Exception ( " Optional(NodeError( DuplicatePayment)) " ).toSendFailureMessage(context))
44+ assertEquals(message, LdkError ( NodeException . DuplicatePayment ( " Duplicate payment. " ) ).toSendFailureMessage(context))
4245 }
4346
4447 @Test
45- fun `compact failure types omit optional and node error wrappers ` () {
48+ fun `payment failure reason compact failure types use lower camel case ` () {
4649 assertEquals(" routeNotFound" , PaymentFailureReason .ROUTE_NOT_FOUND .toCompactFailureType())
47- assertEquals(" DuplicatePayment" , Exception (" Optional(NodeError(DuplicatePayment))" ).toCompactFailureType())
50+ }
51+
52+ @Test
53+ fun `compact failure types use android ldk error classes` () {
54+ assertEquals(
55+ " DuplicatePayment" ,
56+ LdkError (NodeException .DuplicatePayment (" Duplicate payment." )).toCompactFailureType(),
57+ )
58+ assertEquals(
59+ " InvalidCustomTlvs" ,
60+ LdkError (NodeException .InvalidCustomTlvs (" Invalid custom TLVs" )).toCompactFailureType(),
61+ )
62+ }
63+
64+ @Test
65+ fun `compact failure types fall back to the exception class name` () {
66+ assertEquals(" IllegalStateException" , IllegalStateException ().toCompactFailureType())
67+ }
68+
69+ @Test
70+ fun `compact failure types ignore sentence punctuation` () {
71+ assertNotEquals(" Unknown" , Exception (" Payment sending failed." ).toCompactFailureType())
4872 }
4973
5074 @Test
0 commit comments