Fixes quartz test cases for the new structure
This commit is contained in:
@@ -21,6 +21,7 @@
|
||||
package com.vitorpamplona.quartz.nip10Notes
|
||||
|
||||
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.taggedUsers
|
||||
import com.vitorpamplona.quartz.nip10Notes.tags.MarkedETag
|
||||
@@ -186,7 +187,7 @@ class ThreadingTests {
|
||||
|
||||
val taggedUsers =
|
||||
listOf(
|
||||
PTag("4ca4f5533e40da5e0508796d409e6bb35a50b26fc304345617ab017183d83ac0", "wss://goiaba.com"),
|
||||
PTag("4ca4f5533e40da5e0508796d409e6bb35a50b26fc304345617ab017183d83ac0", RelayUrlNormalizer.normalize("wss://goiaba.com")),
|
||||
PTag("534780e44da7b494485e85cd4cca6af4f6caa1627472432b6f2a4ece0e9e54ec"),
|
||||
PTag("77ce56f89d1228f7ff3743ce1ad1b254857b9008564727ebd5a1f317362f6ca7"),
|
||||
)
|
||||
@@ -249,7 +250,7 @@ class ThreadingTests {
|
||||
|
||||
val taggedUsers =
|
||||
listOf(
|
||||
PTag("534780e44da7b494485e85cd4cca6af4f6caa1627472432b6f2a4ece0e9e54ec", "wss://banana.com"),
|
||||
PTag("534780e44da7b494485e85cd4cca6af4f6caa1627472432b6f2a4ece0e9e54ec", RelayUrlNormalizer.normalize("wss://banana.com")),
|
||||
)
|
||||
|
||||
assertEquals(taggedUsers, note.taggedUsers())
|
||||
@@ -302,7 +303,7 @@ class ThreadingTests {
|
||||
|
||||
val taggedUsers =
|
||||
listOf(
|
||||
PTag("534780e44da7b494485e85cd4cca6af4f6caa1627472432b6f2a4ece0e9e54ec", "wss://banana.com"),
|
||||
PTag("534780e44da7b494485e85cd4cca6af4f6caa1627472432b6f2a4ece0e9e54ec", RelayUrlNormalizer.normalize("wss://banana.com")),
|
||||
)
|
||||
|
||||
assertEquals(taggedUsers, note.taggedUsers())
|
||||
|
||||
+28
-48
@@ -22,7 +22,6 @@ package com.vitorpamplona.quartz.nip19Bech32
|
||||
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
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.crypto.KeyPair
|
||||
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.assertNotNull
|
||||
import junit.framework.TestCase.assertTrue
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import org.junit.Assert
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
@@ -48,18 +48,12 @@ class NIP19EmbedTests {
|
||||
KeyPair(Hex.decode("e8e7197ccc53c9ed4cf9b1c8dce085475fa1ffdd71f2c14e44fe23d0bdf77598")),
|
||||
)
|
||||
|
||||
var textNote: Event? = null
|
||||
|
||||
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."),
|
||||
) {
|
||||
textNote = it
|
||||
countDownLatch.countDown()
|
||||
}
|
||||
|
||||
Assert.assertTrue(countDownLatch.await(1, TimeUnit.SECONDS))
|
||||
val textNote: TextNoteEvent =
|
||||
runBlocking {
|
||||
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."),
|
||||
)
|
||||
}
|
||||
|
||||
assertNotNull(textNote)
|
||||
|
||||
@@ -81,29 +75,23 @@ class NIP19EmbedTests {
|
||||
KeyPair(Hex.decode("e8e7197ccc53c9ed4cf9b1c8dce085475fa1ffdd71f2c14e44fe23d0bdf77598")),
|
||||
)
|
||||
|
||||
var eyeglassesPrescriptionEvent: Event? = null
|
||||
|
||||
val countDownLatch = CountDownLatch(1)
|
||||
|
||||
signer.sign(FhirResourceEvent.build(visionPrescriptionFhir)) {
|
||||
eyeglassesPrescriptionEvent = it
|
||||
countDownLatch.countDown()
|
||||
}
|
||||
|
||||
Assert.assertTrue(countDownLatch.await(1, TimeUnit.SECONDS))
|
||||
val eyeglassesPrescriptionEvent =
|
||||
runBlocking {
|
||||
signer.sign(FhirResourceEvent.build(visionPrescriptionFhir))
|
||||
}
|
||||
|
||||
assertNotNull(eyeglassesPrescriptionEvent)
|
||||
|
||||
val bech32 = NEmbed.create(eyeglassesPrescriptionEvent!!)
|
||||
val bech32 = NEmbed.create(eyeglassesPrescriptionEvent)
|
||||
|
||||
println(eyeglassesPrescriptionEvent!!.toJson())
|
||||
println(eyeglassesPrescriptionEvent.toJson())
|
||||
println(bech32)
|
||||
|
||||
val decodedNote = (Nip19Parser.uriToRoute(bech32)?.entity as NEmbed).event
|
||||
|
||||
assertTrue(decodedNote.verify())
|
||||
|
||||
assertEquals(eyeglassesPrescriptionEvent!!.toJson(), decodedNote.toJson())
|
||||
assertEquals(eyeglassesPrescriptionEvent.toJson(), decodedNote.toJson())
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -113,29 +101,27 @@ class NIP19EmbedTests {
|
||||
KeyPair(Hex.decode("e8e7197ccc53c9ed4cf9b1c8dce085475fa1ffdd71f2c14e44fe23d0bdf77598")),
|
||||
)
|
||||
|
||||
var eyeglassesPrescriptionEvent: Event? = null
|
||||
|
||||
val countDownLatch = CountDownLatch(1)
|
||||
|
||||
signer.sign(FhirResourceEvent.build(visionPrescriptionBundle)) {
|
||||
eyeglassesPrescriptionEvent = it
|
||||
countDownLatch.countDown()
|
||||
}
|
||||
val eyeglassesPrescriptionEvent =
|
||||
runBlocking {
|
||||
signer.sign(FhirResourceEvent.build(visionPrescriptionBundle))
|
||||
}
|
||||
|
||||
Assert.assertTrue(countDownLatch.await(1, TimeUnit.SECONDS))
|
||||
|
||||
assertNotNull(eyeglassesPrescriptionEvent)
|
||||
|
||||
val bech32 = NEmbed.create(eyeglassesPrescriptionEvent!!)
|
||||
val bech32 = NEmbed.create(eyeglassesPrescriptionEvent)
|
||||
|
||||
println(eyeglassesPrescriptionEvent!!.toJson())
|
||||
println(eyeglassesPrescriptionEvent.toJson())
|
||||
println(bech32)
|
||||
|
||||
val decodedNote = (Nip19Parser.uriToRoute(bech32)?.entity as NEmbed).event
|
||||
|
||||
assertTrue(decodedNote.verify())
|
||||
|
||||
assertEquals(eyeglassesPrescriptionEvent!!.toJson(), decodedNote.toJson())
|
||||
assertEquals(eyeglassesPrescriptionEvent.toJson(), decodedNote.toJson())
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -145,29 +131,23 @@ class NIP19EmbedTests {
|
||||
KeyPair(decodePrivateKeyAsHexOrNull("nsec1arn3jlxv20y76n8ek8ydecy9ga06rl7aw8evznjylc3ap00hwkvqx4vvy6")!!.hexToByteArray()),
|
||||
)
|
||||
|
||||
var eyeglassesPrescriptionEvent: Event? = null
|
||||
|
||||
val countDownLatch = CountDownLatch(1)
|
||||
|
||||
signer.sign(FhirResourceEvent.build(visionPrescriptionBundle2)) {
|
||||
eyeglassesPrescriptionEvent = it
|
||||
countDownLatch.countDown()
|
||||
}
|
||||
|
||||
Assert.assertTrue(countDownLatch.await(1, TimeUnit.SECONDS))
|
||||
val eyeglassesPrescriptionEvent =
|
||||
runBlocking {
|
||||
signer.sign(FhirResourceEvent.build(visionPrescriptionBundle2))
|
||||
}
|
||||
|
||||
assertNotNull(eyeglassesPrescriptionEvent)
|
||||
|
||||
val bech32 = NEmbed.create(eyeglassesPrescriptionEvent!!)
|
||||
val bech32 = NEmbed.create(eyeglassesPrescriptionEvent)
|
||||
|
||||
println(eyeglassesPrescriptionEvent!!.toJson())
|
||||
println(eyeglassesPrescriptionEvent.toJson())
|
||||
println(bech32)
|
||||
|
||||
val decodedNote = (Nip19Parser.uriToRoute(bech32)?.entity as NEmbed).event
|
||||
|
||||
assertTrue(decodedNote.verify())
|
||||
|
||||
assertEquals(eyeglassesPrescriptionEvent!!.toJson(), decodedNote.toJson())
|
||||
assertEquals(eyeglassesPrescriptionEvent.toJson(), decodedNote.toJson())
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+14
-5
@@ -23,8 +23,10 @@ package com.vitorpamplona.quartz.nip46RemoteSigner
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
import com.vitorpamplona.quartz.nip01Core.core.Event
|
||||
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.nip02FollowList.ReadWrite
|
||||
import com.vitorpamplona.quartz.nip10Notes.TextNoteEvent
|
||||
import com.vitorpamplona.quartz.utils.TimeUtils
|
||||
import junit.framework.TestCase.assertEquals
|
||||
import kotlinx.coroutines.runBlocking
|
||||
@@ -39,11 +41,18 @@ internal class Nip46Test {
|
||||
val peer = NostrSignerInternal(KeyPair())
|
||||
|
||||
val dummyEvent =
|
||||
Event(
|
||||
EventTemplate<Event>(
|
||||
createdAt = TimeUtils.now(),
|
||||
kind = 1,
|
||||
tags = emptyArray(),
|
||||
content = "test",
|
||||
)
|
||||
|
||||
val dummyEventSigned =
|
||||
TextNoteEvent(
|
||||
id = "",
|
||||
pubKey = "",
|
||||
createdAt = TimeUtils.now(),
|
||||
kind = 1,
|
||||
tags = emptyArray(),
|
||||
content = "test",
|
||||
sig = "",
|
||||
@@ -63,7 +72,7 @@ internal class Nip46Test {
|
||||
|
||||
assertEquals(BunkerRequestSign.METHOD_NAME, actual.method)
|
||||
assertEquals(expected.id, actual.id)
|
||||
assertEquals(dummyEvent.id, actual.event.id)
|
||||
assertEquals(dummyEvent.createdAt, actual.event.createdAt)
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -192,13 +201,13 @@ internal class Nip46Test {
|
||||
@Test
|
||||
fun testEventResponse() =
|
||||
runBlocking {
|
||||
val expected = BunkerResponseEvent(event = dummyEvent)
|
||||
val expected = BunkerResponseEvent(event = dummyEventSigned)
|
||||
val actual = encodeDecodeEvent(expected)
|
||||
|
||||
assertEquals(expected.id, actual.id)
|
||||
assertEquals(expected.result, actual.result)
|
||||
assertEquals(expected.error, actual.error)
|
||||
assertEquals(dummyEvent.id, actual.event.id)
|
||||
assertEquals(dummyEventSigned.id, actual.event.id)
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -25,6 +25,7 @@ import com.vitorpamplona.quartz.nip01Core.core.Event
|
||||
import com.vitorpamplona.quartz.nip01Core.core.toHexKey
|
||||
import com.vitorpamplona.quartz.nip01Core.crypto.KeyPair
|
||||
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.nip57Zaps.PrivateZapEncryption.Companion.createEncryptionPrivateKey
|
||||
import com.vitorpamplona.quartz.utils.Hex
|
||||
@@ -93,7 +94,7 @@ class PrivateZapTests {
|
||||
runBlocking {
|
||||
LnZapRequestEvent.create(
|
||||
zappedEvent = poll,
|
||||
relays = setOf("wss://relay.damus.io/"),
|
||||
relays = setOf(RelayUrlNormalizer.normalize("wss://relay.damus.io/")),
|
||||
signer = loggedIn,
|
||||
pollOption = 0,
|
||||
message = "",
|
||||
@@ -153,7 +154,12 @@ class PrivateZapTests {
|
||||
runBlocking {
|
||||
LnZapRequestEvent.create(
|
||||
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,
|
||||
pollOption = null,
|
||||
message = "test",
|
||||
|
||||
+2
-3
@@ -26,13 +26,12 @@ import java.util.UUID
|
||||
class BunkerResponseEvent(
|
||||
id: String = UUID.randomUUID().toString(),
|
||||
val event: Event,
|
||||
) : com.vitorpamplona.quartz.nip46RemoteSigner.BunkerResponse(id, event.toJson(), null) {
|
||||
) : BunkerResponse(id, event.toJson(), null) {
|
||||
companion object {
|
||||
fun parse(
|
||||
id: String,
|
||||
result: String,
|
||||
error: String? = null,
|
||||
) = com.vitorpamplona.quartz.nip46RemoteSigner
|
||||
.BunkerResponseEvent(id, Event.fromJson(result))
|
||||
) = BunkerResponseEvent(id, Event.fromJson(result))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user