diff --git a/quartz/src/commonTest/kotlin/com/vitorpamplona/quartz/nip47WalletConnect/NotificationTest.kt b/quartz/src/commonTest/kotlin/com/vitorpamplona/quartz/nip47WalletConnect/NotificationTest.kt index 163d25841..39fd0f56b 100644 --- a/quartz/src/commonTest/kotlin/com/vitorpamplona/quartz/nip47WalletConnect/NotificationTest.kt +++ b/quartz/src/commonTest/kotlin/com/vitorpamplona/quartz/nip47WalletConnect/NotificationTest.kt @@ -23,6 +23,7 @@ package com.vitorpamplona.quartz.nip47WalletConnect import com.vitorpamplona.quartz.nip01Core.core.OptimizedJsonMapper import kotlin.test.Test import kotlin.test.assertEquals +import kotlin.test.assertFailsWith import kotlin.test.assertIs import kotlin.test.assertNotNull import kotlin.test.assertNull @@ -35,16 +36,16 @@ class NotificationTest { val notification = OptimizedJsonMapper.fromJsonTo(json) assertIs(notification) assertNotNull(notification.notification) - assertEquals("incoming", notification.notification?.type) - assertEquals("lnbc50n1...", notification.notification?.invoice) - assertEquals("coffee", notification.notification?.description) - assertEquals("abc", notification.notification?.preimage) - assertEquals("hash123", notification.notification?.payment_hash) - assertEquals(5000L, notification.notification?.amount) - assertEquals(10L, notification.notification?.fees_paid) - assertEquals(1693876497L, notification.notification?.created_at) - assertEquals(1694876497L, notification.notification?.expires_at) - assertEquals(1694876500L, notification.notification?.settled_at) + assertEquals("incoming", notification.notification.type) + assertEquals("lnbc50n1...", notification.notification.invoice) + assertEquals("coffee", notification.notification.description) + assertEquals("abc", notification.notification.preimage) + assertEquals("hash123", notification.notification.payment_hash) + assertEquals(5000L, notification.notification.amount) + assertEquals(10L, notification.notification.fees_paid) + assertEquals(1693876497L, notification.notification.created_at) + assertEquals(1694876497L, notification.notification.expires_at) + assertEquals(1694876500L, notification.notification.settled_at) } @Test @@ -54,11 +55,11 @@ class NotificationTest { val notification = OptimizedJsonMapper.fromJsonTo(json) assertIs(notification) assertNotNull(notification.notification) - assertEquals("outgoing", notification.notification?.type) - assertEquals("lnbc100n1...", notification.notification?.invoice) - assertEquals("def456", notification.notification?.preimage) - assertEquals(10000L, notification.notification?.amount) - assertEquals(50L, notification.notification?.fees_paid) + assertEquals("outgoing", notification.notification.type) + assertEquals("lnbc100n1...", notification.notification.invoice) + assertEquals("def456", notification.notification.preimage) + assertEquals(10000L, notification.notification.amount) + assertEquals(50L, notification.notification.fees_paid) } @Test @@ -68,13 +69,13 @@ class NotificationTest { val notification = OptimizedJsonMapper.fromJsonTo(json) assertIs(notification) assertNotNull(notification.notification) - assertEquals("incoming", notification.notification?.type) - assertEquals("lnbc200n1...", notification.notification?.invoice) - assertEquals("hash789", notification.notification?.payment_hash) - assertEquals(20000L, notification.notification?.amount) - assertEquals(800000L, notification.notification?.settle_deadline) - assertEquals(1693876497L, notification.notification?.created_at) - assertEquals(1694876497L, notification.notification?.expires_at) + assertEquals("incoming", notification.notification.type) + assertEquals("lnbc200n1...", notification.notification.invoice) + assertEquals("hash789", notification.notification.payment_hash) + assertEquals(20000L, notification.notification.amount) + assertEquals(800000L, notification.notification.settle_deadline) + assertEquals(1693876497L, notification.notification.created_at) + assertEquals(1694876497L, notification.notification.expires_at) } @Test @@ -89,9 +90,11 @@ class NotificationTest { } @Test + @Throws(IllegalArgumentException::class) fun testUnknownNotificationTypeReturnsNull() { val json = """{"notification_type":"unknown_type","notification":{}}""" - val notification = runCatching { OptimizedJsonMapper.fromJsonTo(json) }.getOrNull() - assertNull(notification) + assertFailsWith { + OptimizedJsonMapper.fromJsonTo(json) + } } } diff --git a/quartz/src/commonTest/kotlin/com/vitorpamplona/quartz/nip47WalletConnect/NwcInfoEventTest.kt b/quartz/src/commonTest/kotlin/com/vitorpamplona/quartz/nip47WalletConnect/NwcInfoEventTest.kt index 3a8b15ca8..82d55cc64 100644 --- a/quartz/src/commonTest/kotlin/com/vitorpamplona/quartz/nip47WalletConnect/NwcInfoEventTest.kt +++ b/quartz/src/commonTest/kotlin/com/vitorpamplona/quartz/nip47WalletConnect/NwcInfoEventTest.kt @@ -28,7 +28,7 @@ import kotlin.test.assertFalse import kotlin.test.assertTrue class NwcInfoEventTest { - private val signer = DeterministicSigner("nsec1w4uucmeyyng0kegm7486r23sv4majkmvqsj6eypprq0xttxss55s5mgg9t".nsecToKeyPair()) + private val signer = DeterministicSigner("nsec10g0wheggqn9dawlc0yuv6adnat6n09anr7eyykevw2dm8xa5fffs0wsdsr".nsecToKeyPair()) @Test fun testBuildInfoEvent() { diff --git a/quartz/src/commonTest/kotlin/com/vitorpamplona/quartz/nip47WalletConnect/RequestTest.kt b/quartz/src/commonTest/kotlin/com/vitorpamplona/quartz/nip47WalletConnect/RequestTest.kt index 21816b647..5b43e7bf9 100644 --- a/quartz/src/commonTest/kotlin/com/vitorpamplona/quartz/nip47WalletConnect/RequestTest.kt +++ b/quartz/src/commonTest/kotlin/com/vitorpamplona/quartz/nip47WalletConnect/RequestTest.kt @@ -23,6 +23,7 @@ package com.vitorpamplona.quartz.nip47WalletConnect import com.vitorpamplona.quartz.nip01Core.core.OptimizedJsonMapper import kotlin.test.Test import kotlin.test.assertEquals +import kotlin.test.assertFailsWith import kotlin.test.assertIs import kotlin.test.assertNotNull import kotlin.test.assertNull @@ -396,7 +397,8 @@ class RequestTest { @Test fun testUnknownMethodReturnsNull() { val json = """{"method":"unknown_method","params":{}}""" - val request = OptimizedJsonMapper.fromJsonTo(json) - assertNull(request) + assertFailsWith { + OptimizedJsonMapper.fromJsonTo(json) + } } } diff --git a/quartz/src/jvmAndroid/kotlin/com/vitorpamplona/quartz/nip01Core/core/OptimizedJsonMapper.jvmAndroid.kt b/quartz/src/jvmAndroid/kotlin/com/vitorpamplona/quartz/nip01Core/core/OptimizedJsonMapper.jvmAndroid.kt index 65af77421..5a501c070 100644 --- a/quartz/src/jvmAndroid/kotlin/com/vitorpamplona/quartz/nip01Core/core/OptimizedJsonMapper.jvmAndroid.kt +++ b/quartz/src/jvmAndroid/kotlin/com/vitorpamplona/quartz/nip01Core/core/OptimizedJsonMapper.jvmAndroid.kt @@ -20,6 +20,7 @@ */ package com.vitorpamplona.quartz.nip01Core.core +import com.fasterxml.jackson.databind.RuntimeJsonMappingException import com.vitorpamplona.quartz.nip01Core.jackson.JacksonMapper import com.vitorpamplona.quartz.nip01Core.relay.commands.toClient.Message import com.vitorpamplona.quartz.nip01Core.relay.commands.toRelay.Command @@ -78,6 +79,10 @@ actual object OptimizedJsonMapper { JacksonMapper.fromJsonTo(json) } catch (e: com.fasterxml.jackson.core.JsonParseException) { throw IllegalArgumentException(e.message, e) + } catch (e: com.fasterxml.jackson.core.JsonProcessingException) { + throw IllegalArgumentException(e.message, e) + } catch (e: RuntimeJsonMappingException) { + throw IllegalArgumentException(e.message, e) } actual fun toJson(value: OptimizedSerializable): String = JacksonMapper.toJson(value)