Fixes quartz test cases for the new structure

This commit is contained in:
Vitor Pamplona
2025-07-25 12:41:43 -04:00
parent 39152d4e90
commit e7a9890eb1
5 changed files with 56 additions and 61 deletions
@@ -21,6 +21,7 @@
package com.vitorpamplona.quartz.nip10Notes package com.vitorpamplona.quartz.nip10Notes
import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.ext.junit.runners.AndroidJUnit4
import com.vitorpamplona.quartz.nip01Core.relay.normalizer.RelayUrlNormalizer
import com.vitorpamplona.quartz.nip01Core.tags.people.PTag import com.vitorpamplona.quartz.nip01Core.tags.people.PTag
import com.vitorpamplona.quartz.nip01Core.tags.people.taggedUsers import com.vitorpamplona.quartz.nip01Core.tags.people.taggedUsers
import com.vitorpamplona.quartz.nip10Notes.tags.MarkedETag import com.vitorpamplona.quartz.nip10Notes.tags.MarkedETag
@@ -186,7 +187,7 @@ class ThreadingTests {
val taggedUsers = val taggedUsers =
listOf( listOf(
PTag("4ca4f5533e40da5e0508796d409e6bb35a50b26fc304345617ab017183d83ac0", "wss://goiaba.com"), PTag("4ca4f5533e40da5e0508796d409e6bb35a50b26fc304345617ab017183d83ac0", RelayUrlNormalizer.normalize("wss://goiaba.com")),
PTag("534780e44da7b494485e85cd4cca6af4f6caa1627472432b6f2a4ece0e9e54ec"), PTag("534780e44da7b494485e85cd4cca6af4f6caa1627472432b6f2a4ece0e9e54ec"),
PTag("77ce56f89d1228f7ff3743ce1ad1b254857b9008564727ebd5a1f317362f6ca7"), PTag("77ce56f89d1228f7ff3743ce1ad1b254857b9008564727ebd5a1f317362f6ca7"),
) )
@@ -249,7 +250,7 @@ class ThreadingTests {
val taggedUsers = val taggedUsers =
listOf( listOf(
PTag("534780e44da7b494485e85cd4cca6af4f6caa1627472432b6f2a4ece0e9e54ec", "wss://banana.com"), PTag("534780e44da7b494485e85cd4cca6af4f6caa1627472432b6f2a4ece0e9e54ec", RelayUrlNormalizer.normalize("wss://banana.com")),
) )
assertEquals(taggedUsers, note.taggedUsers()) assertEquals(taggedUsers, note.taggedUsers())
@@ -302,7 +303,7 @@ class ThreadingTests {
val taggedUsers = val taggedUsers =
listOf( listOf(
PTag("534780e44da7b494485e85cd4cca6af4f6caa1627472432b6f2a4ece0e9e54ec", "wss://banana.com"), PTag("534780e44da7b494485e85cd4cca6af4f6caa1627472432b6f2a4ece0e9e54ec", RelayUrlNormalizer.normalize("wss://banana.com")),
) )
assertEquals(taggedUsers, note.taggedUsers()) assertEquals(taggedUsers, note.taggedUsers())
@@ -22,7 +22,6 @@ package com.vitorpamplona.quartz.nip19Bech32
import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.ext.junit.runners.AndroidJUnit4
import com.vitorpamplona.quartz.experimental.medical.FhirResourceEvent import com.vitorpamplona.quartz.experimental.medical.FhirResourceEvent
import com.vitorpamplona.quartz.nip01Core.core.Event
import com.vitorpamplona.quartz.nip01Core.core.hexToByteArray import com.vitorpamplona.quartz.nip01Core.core.hexToByteArray
import com.vitorpamplona.quartz.nip01Core.crypto.KeyPair import com.vitorpamplona.quartz.nip01Core.crypto.KeyPair
import com.vitorpamplona.quartz.nip01Core.signers.NostrSignerInternal import com.vitorpamplona.quartz.nip01Core.signers.NostrSignerInternal
@@ -33,6 +32,7 @@ import com.vitorpamplona.quartz.utils.Hex
import junit.framework.TestCase.assertEquals import junit.framework.TestCase.assertEquals
import junit.framework.TestCase.assertNotNull import junit.framework.TestCase.assertNotNull
import junit.framework.TestCase.assertTrue import junit.framework.TestCase.assertTrue
import kotlinx.coroutines.runBlocking
import org.junit.Assert import org.junit.Assert
import org.junit.Test import org.junit.Test
import org.junit.runner.RunWith import org.junit.runner.RunWith
@@ -48,18 +48,12 @@ class NIP19EmbedTests {
KeyPair(Hex.decode("e8e7197ccc53c9ed4cf9b1c8dce085475fa1ffdd71f2c14e44fe23d0bdf77598")), KeyPair(Hex.decode("e8e7197ccc53c9ed4cf9b1c8dce085475fa1ffdd71f2c14e44fe23d0bdf77598")),
) )
var textNote: Event? = null val textNote: TextNoteEvent =
runBlocking {
val countDownLatch = CountDownLatch(1) signer.sign(
TextNoteEvent.build("I like this. It could solve the ninvite problem in #1062, and it seems like it could be applied very broadly to limit the spread of events that shouldn't stand on their own or need to be private. The one question I have is how long are these embeds? If it's 50 lines of text, that breaks the human readable (or at least parseable) requirement of kind 1s. Also, encoding json in a tlv is silly, we should at least use the tlv to reduce the payload size."),
signer.sign( )
TextNoteEvent.build("I like this. It could solve the ninvite problem in #1062, and it seems like it could be applied very broadly to limit the spread of events that shouldn't stand on their own or need to be private. The one question I have is how long are these embeds? If it's 50 lines of text, that breaks the human readable (or at least parseable) requirement of kind 1s. Also, encoding json in a tlv is silly, we should at least use the tlv to reduce the payload size."), }
) {
textNote = it
countDownLatch.countDown()
}
Assert.assertTrue(countDownLatch.await(1, TimeUnit.SECONDS))
assertNotNull(textNote) assertNotNull(textNote)
@@ -81,29 +75,23 @@ class NIP19EmbedTests {
KeyPair(Hex.decode("e8e7197ccc53c9ed4cf9b1c8dce085475fa1ffdd71f2c14e44fe23d0bdf77598")), KeyPair(Hex.decode("e8e7197ccc53c9ed4cf9b1c8dce085475fa1ffdd71f2c14e44fe23d0bdf77598")),
) )
var eyeglassesPrescriptionEvent: Event? = null val eyeglassesPrescriptionEvent =
runBlocking {
val countDownLatch = CountDownLatch(1) signer.sign(FhirResourceEvent.build(visionPrescriptionFhir))
}
signer.sign(FhirResourceEvent.build(visionPrescriptionFhir)) {
eyeglassesPrescriptionEvent = it
countDownLatch.countDown()
}
Assert.assertTrue(countDownLatch.await(1, TimeUnit.SECONDS))
assertNotNull(eyeglassesPrescriptionEvent) assertNotNull(eyeglassesPrescriptionEvent)
val bech32 = NEmbed.create(eyeglassesPrescriptionEvent!!) val bech32 = NEmbed.create(eyeglassesPrescriptionEvent)
println(eyeglassesPrescriptionEvent!!.toJson()) println(eyeglassesPrescriptionEvent.toJson())
println(bech32) println(bech32)
val decodedNote = (Nip19Parser.uriToRoute(bech32)?.entity as NEmbed).event val decodedNote = (Nip19Parser.uriToRoute(bech32)?.entity as NEmbed).event
assertTrue(decodedNote.verify()) assertTrue(decodedNote.verify())
assertEquals(eyeglassesPrescriptionEvent!!.toJson(), decodedNote.toJson()) assertEquals(eyeglassesPrescriptionEvent.toJson(), decodedNote.toJson())
} }
@Test @Test
@@ -113,29 +101,27 @@ class NIP19EmbedTests {
KeyPair(Hex.decode("e8e7197ccc53c9ed4cf9b1c8dce085475fa1ffdd71f2c14e44fe23d0bdf77598")), KeyPair(Hex.decode("e8e7197ccc53c9ed4cf9b1c8dce085475fa1ffdd71f2c14e44fe23d0bdf77598")),
) )
var eyeglassesPrescriptionEvent: Event? = null
val countDownLatch = CountDownLatch(1) val countDownLatch = CountDownLatch(1)
signer.sign(FhirResourceEvent.build(visionPrescriptionBundle)) { val eyeglassesPrescriptionEvent =
eyeglassesPrescriptionEvent = it runBlocking {
countDownLatch.countDown() signer.sign(FhirResourceEvent.build(visionPrescriptionBundle))
} }
Assert.assertTrue(countDownLatch.await(1, TimeUnit.SECONDS)) Assert.assertTrue(countDownLatch.await(1, TimeUnit.SECONDS))
assertNotNull(eyeglassesPrescriptionEvent) assertNotNull(eyeglassesPrescriptionEvent)
val bech32 = NEmbed.create(eyeglassesPrescriptionEvent!!) val bech32 = NEmbed.create(eyeglassesPrescriptionEvent)
println(eyeglassesPrescriptionEvent!!.toJson()) println(eyeglassesPrescriptionEvent.toJson())
println(bech32) println(bech32)
val decodedNote = (Nip19Parser.uriToRoute(bech32)?.entity as NEmbed).event val decodedNote = (Nip19Parser.uriToRoute(bech32)?.entity as NEmbed).event
assertTrue(decodedNote.verify()) assertTrue(decodedNote.verify())
assertEquals(eyeglassesPrescriptionEvent!!.toJson(), decodedNote.toJson()) assertEquals(eyeglassesPrescriptionEvent.toJson(), decodedNote.toJson())
} }
@Test @Test
@@ -145,29 +131,23 @@ class NIP19EmbedTests {
KeyPair(decodePrivateKeyAsHexOrNull("nsec1arn3jlxv20y76n8ek8ydecy9ga06rl7aw8evznjylc3ap00hwkvqx4vvy6")!!.hexToByteArray()), KeyPair(decodePrivateKeyAsHexOrNull("nsec1arn3jlxv20y76n8ek8ydecy9ga06rl7aw8evznjylc3ap00hwkvqx4vvy6")!!.hexToByteArray()),
) )
var eyeglassesPrescriptionEvent: Event? = null val eyeglassesPrescriptionEvent =
runBlocking {
val countDownLatch = CountDownLatch(1) signer.sign(FhirResourceEvent.build(visionPrescriptionBundle2))
}
signer.sign(FhirResourceEvent.build(visionPrescriptionBundle2)) {
eyeglassesPrescriptionEvent = it
countDownLatch.countDown()
}
Assert.assertTrue(countDownLatch.await(1, TimeUnit.SECONDS))
assertNotNull(eyeglassesPrescriptionEvent) assertNotNull(eyeglassesPrescriptionEvent)
val bech32 = NEmbed.create(eyeglassesPrescriptionEvent!!) val bech32 = NEmbed.create(eyeglassesPrescriptionEvent)
println(eyeglassesPrescriptionEvent!!.toJson()) println(eyeglassesPrescriptionEvent.toJson())
println(bech32) println(bech32)
val decodedNote = (Nip19Parser.uriToRoute(bech32)?.entity as NEmbed).event val decodedNote = (Nip19Parser.uriToRoute(bech32)?.entity as NEmbed).event
assertTrue(decodedNote.verify()) assertTrue(decodedNote.verify())
assertEquals(eyeglassesPrescriptionEvent!!.toJson(), decodedNote.toJson()) assertEquals(eyeglassesPrescriptionEvent.toJson(), decodedNote.toJson())
} }
@Test @Test
@@ -23,8 +23,10 @@ package com.vitorpamplona.quartz.nip46RemoteSigner
import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.ext.junit.runners.AndroidJUnit4
import com.vitorpamplona.quartz.nip01Core.core.Event import com.vitorpamplona.quartz.nip01Core.core.Event
import com.vitorpamplona.quartz.nip01Core.crypto.KeyPair import com.vitorpamplona.quartz.nip01Core.crypto.KeyPair
import com.vitorpamplona.quartz.nip01Core.signers.EventTemplate
import com.vitorpamplona.quartz.nip01Core.signers.NostrSignerInternal import com.vitorpamplona.quartz.nip01Core.signers.NostrSignerInternal
import com.vitorpamplona.quartz.nip02FollowList.ReadWrite import com.vitorpamplona.quartz.nip02FollowList.ReadWrite
import com.vitorpamplona.quartz.nip10Notes.TextNoteEvent
import com.vitorpamplona.quartz.utils.TimeUtils import com.vitorpamplona.quartz.utils.TimeUtils
import junit.framework.TestCase.assertEquals import junit.framework.TestCase.assertEquals
import kotlinx.coroutines.runBlocking import kotlinx.coroutines.runBlocking
@@ -39,11 +41,18 @@ internal class Nip46Test {
val peer = NostrSignerInternal(KeyPair()) val peer = NostrSignerInternal(KeyPair())
val dummyEvent = val dummyEvent =
Event( EventTemplate<Event>(
createdAt = TimeUtils.now(),
kind = 1,
tags = emptyArray(),
content = "test",
)
val dummyEventSigned =
TextNoteEvent(
id = "", id = "",
pubKey = "", pubKey = "",
createdAt = TimeUtils.now(), createdAt = TimeUtils.now(),
kind = 1,
tags = emptyArray(), tags = emptyArray(),
content = "test", content = "test",
sig = "", sig = "",
@@ -63,7 +72,7 @@ internal class Nip46Test {
assertEquals(BunkerRequestSign.METHOD_NAME, actual.method) assertEquals(BunkerRequestSign.METHOD_NAME, actual.method)
assertEquals(expected.id, actual.id) assertEquals(expected.id, actual.id)
assertEquals(dummyEvent.id, actual.event.id) assertEquals(dummyEvent.createdAt, actual.event.createdAt)
} }
@Test @Test
@@ -192,13 +201,13 @@ internal class Nip46Test {
@Test @Test
fun testEventResponse() = fun testEventResponse() =
runBlocking { runBlocking {
val expected = BunkerResponseEvent(event = dummyEvent) val expected = BunkerResponseEvent(event = dummyEventSigned)
val actual = encodeDecodeEvent(expected) val actual = encodeDecodeEvent(expected)
assertEquals(expected.id, actual.id) assertEquals(expected.id, actual.id)
assertEquals(expected.result, actual.result) assertEquals(expected.result, actual.result)
assertEquals(expected.error, actual.error) assertEquals(expected.error, actual.error)
assertEquals(dummyEvent.id, actual.event.id) assertEquals(dummyEventSigned.id, actual.event.id)
} }
@Test @Test
@@ -25,6 +25,7 @@ import com.vitorpamplona.quartz.nip01Core.core.Event
import com.vitorpamplona.quartz.nip01Core.core.toHexKey import com.vitorpamplona.quartz.nip01Core.core.toHexKey
import com.vitorpamplona.quartz.nip01Core.crypto.KeyPair import com.vitorpamplona.quartz.nip01Core.crypto.KeyPair
import com.vitorpamplona.quartz.nip01Core.jackson.JsonMapper import com.vitorpamplona.quartz.nip01Core.jackson.JsonMapper
import com.vitorpamplona.quartz.nip01Core.relay.normalizer.RelayUrlNormalizer
import com.vitorpamplona.quartz.nip01Core.signers.NostrSignerInternal import com.vitorpamplona.quartz.nip01Core.signers.NostrSignerInternal
import com.vitorpamplona.quartz.nip57Zaps.PrivateZapEncryption.Companion.createEncryptionPrivateKey import com.vitorpamplona.quartz.nip57Zaps.PrivateZapEncryption.Companion.createEncryptionPrivateKey
import com.vitorpamplona.quartz.utils.Hex import com.vitorpamplona.quartz.utils.Hex
@@ -93,7 +94,7 @@ class PrivateZapTests {
runBlocking { runBlocking {
LnZapRequestEvent.create( LnZapRequestEvent.create(
zappedEvent = poll, zappedEvent = poll,
relays = setOf("wss://relay.damus.io/"), relays = setOf(RelayUrlNormalizer.normalize("wss://relay.damus.io/")),
signer = loggedIn, signer = loggedIn,
pollOption = 0, pollOption = 0,
message = "", message = "",
@@ -153,7 +154,12 @@ class PrivateZapTests {
runBlocking { runBlocking {
LnZapRequestEvent.create( LnZapRequestEvent.create(
zappedEvent = textNote, zappedEvent = textNote,
relays = setOf("wss://relay.damus.io/", "wss://relay.damus2.io/", "wss://relay.damus3.io/"), relays =
setOf(
RelayUrlNormalizer.normalize("wss://relay.damus.io/"),
RelayUrlNormalizer.normalize("wss://relay.damus2.io/"),
RelayUrlNormalizer.normalize("wss://relay.damus3.io/"),
),
signer = loggedIn, signer = loggedIn,
pollOption = null, pollOption = null,
message = "test", message = "test",
@@ -26,13 +26,12 @@ import java.util.UUID
class BunkerResponseEvent( class BunkerResponseEvent(
id: String = UUID.randomUUID().toString(), id: String = UUID.randomUUID().toString(),
val event: Event, val event: Event,
) : com.vitorpamplona.quartz.nip46RemoteSigner.BunkerResponse(id, event.toJson(), null) { ) : BunkerResponse(id, event.toJson(), null) {
companion object { companion object {
fun parse( fun parse(
id: String, id: String,
result: String, result: String,
error: String? = null, error: String? = null,
) = com.vitorpamplona.quartz.nip46RemoteSigner ) = BunkerResponseEvent(id, Event.fromJson(result))
.BunkerResponseEvent(id, Event.fromJson(result))
} }
} }