Merge pull request #1524 from davotoula/use-runTest-instead-of-runBlocking

change from runBlocking to runTest where appropriate
This commit is contained in:
Vitor Pamplona
2025-10-15 18:57:42 -04:00
committed by GitHub
9 changed files with 294 additions and 310 deletions

View File

@@ -28,7 +28,7 @@ import io.mockk.impl.annotations.SpyK
import io.mockk.mockk import io.mockk.mockk
import io.mockk.mockkStatic import io.mockk.mockkStatic
import io.mockk.unmockkAll import io.mockk.unmockkAll
import kotlinx.coroutines.runBlocking import kotlinx.coroutines.test.runTest
import org.junit.After import org.junit.After
import org.junit.Assert.assertEquals import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse import org.junit.Assert.assertFalse
@@ -54,7 +54,7 @@ class SplitterTest {
@Test @Test
fun testSplit() = fun testSplit() =
runBlocking { runTest {
val vitor = mySplitBuilder.addItem("Vitor") val vitor = mySplitBuilder.addItem("Vitor")
assertEquals(1f, mySplitBuilder.items[vitor].percentage, 0.01f) assertEquals(1f, mySplitBuilder.items[vitor].percentage, 0.01f)

View File

@@ -117,6 +117,7 @@ kotlin {
commonTest { commonTest {
dependencies { dependencies {
implementation(libs.kotlin.test) implementation(libs.kotlin.test)
implementation(libs.kotlinx.coroutines.test)
} }
} }
@@ -148,6 +149,7 @@ kotlin {
dependsOn(commonTest.get()) dependsOn(commonTest.get())
dependencies { dependencies {
implementation(libs.kotlin.test) implementation(libs.kotlin.test)
implementation(libs.kotlinx.coroutines.test)
} }
} }
@@ -201,6 +203,7 @@ kotlin {
implementation(libs.androidx.core) implementation(libs.androidx.core)
implementation(libs.androidx.junit) implementation(libs.androidx.junit)
implementation(libs.androidx.espresso.core) implementation(libs.androidx.espresso.core)
implementation(libs.kotlinx.coroutines.test)
} }
} }

View File

@@ -31,7 +31,7 @@ import com.vitorpamplona.quartz.nip19Bech32.entities.NEmbed
import com.vitorpamplona.quartz.utils.Hex import com.vitorpamplona.quartz.utils.Hex
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 kotlinx.coroutines.test.runTest
import org.junit.Assert.assertEquals import org.junit.Assert.assertEquals
import org.junit.Test import org.junit.Test
import org.junit.runner.RunWith import org.junit.runner.RunWith
@@ -39,109 +39,102 @@ import org.junit.runner.RunWith
@RunWith(AndroidJUnit4::class) @RunWith(AndroidJUnit4::class)
class NIP19EmbedTests { class NIP19EmbedTests {
@Test @Test
fun testEmbedKind1Event() { fun testEmbedKind1Event() =
val signer = runTest {
NostrSignerInternal( val signer =
KeyPair(Hex.decode("e8e7197ccc53c9ed4cf9b1c8dce085475fa1ffdd71f2c14e44fe23d0bdf77598")), NostrSignerInternal(
) KeyPair(Hex.decode("e8e7197ccc53c9ed4cf9b1c8dce085475fa1ffdd71f2c14e44fe23d0bdf77598")),
)
val textNote: TextNoteEvent = val textNote =
runBlocking {
signer.sign( 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."), 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) assertNotNull(textNote)
val bech32 = NEmbed.create(textNote) val bech32 = NEmbed.create(textNote)
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(textNote.toJson(), decodedNote.toJson()) assertEquals(textNote.toJson(), decodedNote.toJson())
} }
@Test @Test
fun testVisionPrescriptionEmbedEvent() { fun testVisionPrescriptionEmbedEvent() =
val signer = runTest {
NostrSignerInternal( val signer =
KeyPair(Hex.decode("e8e7197ccc53c9ed4cf9b1c8dce085475fa1ffdd71f2c14e44fe23d0bdf77598")), NostrSignerInternal(
) KeyPair(Hex.decode("e8e7197ccc53c9ed4cf9b1c8dce085475fa1ffdd71f2c14e44fe23d0bdf77598")),
)
val eyeglassesPrescriptionEvent = val eyeglassesPrescriptionEvent = signer.sign(FhirResourceEvent.build(visionPrescriptionFhir))
runBlocking {
signer.sign(FhirResourceEvent.build(visionPrescriptionFhir))
}
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
fun testVisionPrescriptionBundleEmbedEvent() { fun testVisionPrescriptionBundleEmbedEvent() =
val signer = runTest {
NostrSignerInternal( val signer =
KeyPair(Hex.decode("e8e7197ccc53c9ed4cf9b1c8dce085475fa1ffdd71f2c14e44fe23d0bdf77598")), NostrSignerInternal(
) KeyPair(Hex.decode("e8e7197ccc53c9ed4cf9b1c8dce085475fa1ffdd71f2c14e44fe23d0bdf77598")),
)
val eyeglassesPrescriptionEvent = val eyeglassesPrescriptionEvent = signer.sign(FhirResourceEvent.build(visionPrescriptionBundle))
runBlocking {
signer.sign(FhirResourceEvent.build(visionPrescriptionBundle))
}
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
fun testVisionPrescriptionBundle2EmbedEvent() { fun testVisionPrescriptionBundle2EmbedEvent() =
val signer = runTest {
NostrSignerInternal( val signer =
KeyPair(decodePrivateKeyAsHexOrNull("nsec1arn3jlxv20y76n8ek8ydecy9ga06rl7aw8evznjylc3ap00hwkvqx4vvy6")!!.hexToByteArray()), NostrSignerInternal(
) KeyPair(decodePrivateKeyAsHexOrNull("nsec1arn3jlxv20y76n8ek8ydecy9ga06rl7aw8evznjylc3ap00hwkvqx4vvy6")!!.hexToByteArray()),
)
val eyeglassesPrescriptionEvent = val eyeglassesPrescriptionEvent = signer.sign(FhirResourceEvent.build(visionPrescriptionBundle2))
runBlocking {
signer.sign(FhirResourceEvent.build(visionPrescriptionBundle2))
}
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
fun testTimsNembed() { fun testTimsNembed() {

View File

@@ -27,7 +27,7 @@ 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.nip10Notes.TextNoteEvent import com.vitorpamplona.quartz.nip10Notes.TextNoteEvent
import com.vitorpamplona.quartz.utils.TimeUtils import com.vitorpamplona.quartz.utils.TimeUtils
import kotlinx.coroutines.runBlocking import kotlinx.coroutines.test.runTest
import org.junit.Assert.assertEquals import org.junit.Assert.assertEquals
import org.junit.Ignore import org.junit.Ignore
import org.junit.Test import org.junit.Test
@@ -65,7 +65,7 @@ internal class Nip46Test {
@Test @Test
fun signEncoder() = fun signEncoder() =
runBlocking { runTest {
val expected = BunkerRequestSign(event = dummyEvent) val expected = BunkerRequestSign(event = dummyEvent)
val actual = encodeDecodeEvent(expected) val actual = encodeDecodeEvent(expected)
@@ -76,7 +76,7 @@ internal class Nip46Test {
@Test @Test
fun connectEncoder() = fun connectEncoder() =
runBlocking { runTest {
val expected = BunkerRequestConnect(remoteKey = remoteKey.pubKey) val expected = BunkerRequestConnect(remoteKey = remoteKey.pubKey)
val actual = encodeDecodeEvent(expected) val actual = encodeDecodeEvent(expected)
@@ -86,7 +86,7 @@ internal class Nip46Test {
@Test @Test
fun pingEncoder() = fun pingEncoder() =
runBlocking { runTest {
val expected = BunkerRequestPing() val expected = BunkerRequestPing()
val actual = encodeDecodeEvent(expected) val actual = encodeDecodeEvent(expected)
@@ -96,7 +96,7 @@ internal class Nip46Test {
@Test @Test
fun getPubkeyEncoder() = fun getPubkeyEncoder() =
runBlocking { runTest {
val expected = BunkerRequestGetPublicKey() val expected = BunkerRequestGetPublicKey()
val actual = encodeDecodeEvent(expected) val actual = encodeDecodeEvent(expected)
@@ -106,7 +106,7 @@ internal class Nip46Test {
@Test @Test
fun getRelaysEncoder() = fun getRelaysEncoder() =
runBlocking { runTest {
val expected = BunkerRequestGetRelays() val expected = BunkerRequestGetRelays()
val actual = encodeDecodeEvent(expected) val actual = encodeDecodeEvent(expected)
@@ -116,7 +116,7 @@ internal class Nip46Test {
@Test @Test
fun testNip04Encrypt() = fun testNip04Encrypt() =
runBlocking { runTest {
val expected = BunkerRequestNip04Encrypt(pubKey = peer.pubKey, message = "Test") val expected = BunkerRequestNip04Encrypt(pubKey = peer.pubKey, message = "Test")
val actual = encodeDecodeEvent(expected) val actual = encodeDecodeEvent(expected)
@@ -128,7 +128,7 @@ internal class Nip46Test {
@Test @Test
fun testNip44Encrypt() = fun testNip44Encrypt() =
runBlocking { runTest {
val expected = BunkerRequestNip44Encrypt(pubKey = peer.pubKey, message = "Test") val expected = BunkerRequestNip44Encrypt(pubKey = peer.pubKey, message = "Test")
val actual = encodeDecodeEvent(expected) val actual = encodeDecodeEvent(expected)
@@ -140,7 +140,7 @@ internal class Nip46Test {
@Test @Test
fun testNip04Decrypt() = fun testNip04Decrypt() =
runBlocking { runTest {
val expected = BunkerRequestNip04Decrypt(pubKey = peer.pubKey, ciphertext = "Test") val expected = BunkerRequestNip04Decrypt(pubKey = peer.pubKey, ciphertext = "Test")
val actual = encodeDecodeEvent(expected) val actual = encodeDecodeEvent(expected)
@@ -152,7 +152,7 @@ internal class Nip46Test {
@Test @Test
fun testNip44Decrypt() = fun testNip44Decrypt() =
runBlocking { runTest {
val expected = BunkerRequestNip44Decrypt(pubKey = peer.pubKey, ciphertext = "Test") val expected = BunkerRequestNip44Decrypt(pubKey = peer.pubKey, ciphertext = "Test")
val actual = encodeDecodeEvent(expected) val actual = encodeDecodeEvent(expected)
@@ -166,7 +166,7 @@ internal class Nip46Test {
@Test @Test
fun testAckResponse() = fun testAckResponse() =
runBlocking { runTest {
val expected = BunkerResponseAck() val expected = BunkerResponseAck()
val actual = encodeDecodeEvent(expected) val actual = encodeDecodeEvent(expected)
@@ -177,7 +177,7 @@ internal class Nip46Test {
@Test @Test
fun testPongResponse() = fun testPongResponse() =
runBlocking { runTest {
val expected = BunkerResponsePong() val expected = BunkerResponsePong()
val actual = encodeDecodeEvent(expected) val actual = encodeDecodeEvent(expected)
@@ -188,7 +188,7 @@ internal class Nip46Test {
@Test @Test
fun testErrorResponse() = fun testErrorResponse() =
runBlocking { runTest {
val expected = BunkerResponseError(error = "Error") val expected = BunkerResponseError(error = "Error")
val actual = encodeDecodeEvent(expected) val actual = encodeDecodeEvent(expected)
@@ -199,7 +199,7 @@ internal class Nip46Test {
@Test @Test
fun testEventResponse() = fun testEventResponse() =
runBlocking { runTest {
val expected = BunkerResponseEvent(event = dummyEventSigned) val expected = BunkerResponseEvent(event = dummyEventSigned)
val actual = encodeDecodeEvent(expected) val actual = encodeDecodeEvent(expected)
@@ -211,7 +211,7 @@ internal class Nip46Test {
@Test @Test
fun testPubkeyResponse() = fun testPubkeyResponse() =
runBlocking { runTest {
val expected = BunkerResponsePublicKey(pubkey = peer.pubKey) val expected = BunkerResponsePublicKey(pubkey = peer.pubKey)
val actual = encodeDecodeEvent(expected) val actual = encodeDecodeEvent(expected)
@@ -223,7 +223,7 @@ internal class Nip46Test {
@Test @Test
fun testRelaysResponse() = fun testRelaysResponse() =
runBlocking { runTest {
val expected = BunkerResponseGetRelays(relays = mapOf("url" to ReadWrite(true, false))) val expected = BunkerResponseGetRelays(relays = mapOf("url" to ReadWrite(true, false)))
val actual = encodeDecodeEvent(expected) val actual = encodeDecodeEvent(expected)
@@ -236,7 +236,7 @@ internal class Nip46Test {
@Test @Test
@Ignore("Impossible to recreate the class since there are no hints on the json") @Ignore("Impossible to recreate the class since there are no hints on the json")
fun testDecryptResponse() = fun testDecryptResponse() =
runBlocking { runTest {
val expected = BunkerResponseDecrypt(plaintext = "Test") val expected = BunkerResponseDecrypt(plaintext = "Test")
val actual = encodeDecodeEvent(expected) val actual = encodeDecodeEvent(expected)
@@ -249,7 +249,7 @@ internal class Nip46Test {
@Test @Test
@Ignore("Impossible to recreate the class since there are no hints on the json") @Ignore("Impossible to recreate the class since there are no hints on the json")
fun testEncryptResponse() = fun testEncryptResponse() =
runBlocking { runTest {
val expected = BunkerResponseEncrypt(ciphertext = "Test") val expected = BunkerResponseEncrypt(ciphertext = "Test")
val actual = encodeDecodeEvent(expected) val actual = encodeDecodeEvent(expected)

View File

@@ -31,17 +31,18 @@ import com.vitorpamplona.quartz.nip57Zaps.PrivateZapEncryption.Companion.createE
import com.vitorpamplona.quartz.utils.Hex import com.vitorpamplona.quartz.utils.Hex
import junit.framework.TestCase.assertNotNull import junit.framework.TestCase.assertNotNull
import junit.framework.TestCase.fail import junit.framework.TestCase.fail
import kotlinx.coroutines.runBlocking import kotlinx.coroutines.test.runTest
import org.junit.Test import org.junit.Test
import org.junit.runner.RunWith import org.junit.runner.RunWith
@RunWith(AndroidJUnit4::class) @RunWith(AndroidJUnit4::class)
class PrivateZapTests { class PrivateZapTests {
@Test @Test
fun testPollZap() { fun testPollZap() =
val poll = runTest {
OptimizedJsonMapper.fromJson( val poll =
"""{ OptimizedJsonMapper.fromJson(
"""{
"content": "New poll \n\n #zappoll", "content": "New poll \n\n #zappoll",
"created_at": 1682440713, "created_at": 1682440713,
"id": "16291ba452bb0786a4bf5c278d38de73c96b58c056ed75c5ea466b0795197288", "id": "16291ba452bb0786a4bf5c278d38de73c96b58c056ed75c5ea466b0795197288",
@@ -81,17 +82,16 @@ class PrivateZapTests {
] ]
} }
""", """,
) )
val loggedIn = val loggedIn =
NostrSignerInternal( NostrSignerInternal(
KeyPair( KeyPair(
Hex.decode("e8e7197ccc53c9ed4cf9b1c8dce085475fa1ffdd71f2c14e44fe23d0bdf77598"), Hex.decode("e8e7197ccc53c9ed4cf9b1c8dce085475fa1ffdd71f2c14e44fe23d0bdf77598"),
), ),
) )
val privateZapRequest = val privateZapRequest =
runBlocking {
LnZapRequestEvent.create( LnZapRequestEvent.create(
zappedEvent = poll, zappedEvent = poll,
relays = setOf(RelayUrlNormalizer.normalize("wss://relay.damus.io/")), relays = setOf(RelayUrlNormalizer.normalize("wss://relay.damus.io/")),
@@ -101,31 +101,31 @@ class PrivateZapTests {
zapType = LnZapEvent.ZapType.PRIVATE, zapType = LnZapEvent.ZapType.PRIVATE,
toUserPubHex = null, toUserPubHex = null,
) )
val recepientPK = privateZapRequest.zappedAuthor().firstOrNull()
val recepientPost = privateZapRequest.zappedPost().firstOrNull()
if (recepientPK != null && recepientPost != null) {
val privateKey =
createEncryptionPrivateKey(
loggedIn.keyPair.privKey!!.toHexKey(),
recepientPost,
privateZapRequest.createdAt,
)
val decodedPrivateZap = PrivateZapRequestBuilder().decryptAnonTag(privateZapRequest.getAnonTag(), privateKey, recepientPK)
assertNotNull(decodedPrivateZap)
} else {
fail("Should not be null")
} }
val recepientPK = privateZapRequest.zappedAuthor().firstOrNull()
val recepientPost = privateZapRequest.zappedPost().firstOrNull()
if (recepientPK != null && recepientPost != null) {
val privateKey =
createEncryptionPrivateKey(
loggedIn.keyPair.privKey!!.toHexKey(),
recepientPost,
privateZapRequest.createdAt,
)
val decodedPrivateZap = PrivateZapRequestBuilder().decryptAnonTag(privateZapRequest.getAnonTag(), privateKey, recepientPK)
assertNotNull(decodedPrivateZap)
} else {
fail("Should not be null")
} }
}
@Test @Test
fun testKind1PrivateZap() { fun testKind1PrivateZap() =
val textNote = runTest {
Event.fromJson( val textNote =
"""{ Event.fromJson(
"""{
"content": "Testing copied author. \n\nnostr:npub1gcxzte5zlkncx26j68ez60fzkvtkm9e0vrwdcvsjakxf9mu9qewqlfnj5z", "content": "Testing copied author. \n\nnostr:npub1gcxzte5zlkncx26j68ez60fzkvtkm9e0vrwdcvsjakxf9mu9qewqlfnj5z",
"created_at": 1682369982, "created_at": 1682369982,
"id": "c757e1371d715c711ec9ef9740a3df6475d64b3d0af45ffcbfca08d273baf1c1", "id": "c757e1371d715c711ec9ef9740a3df6475d64b3d0af45ffcbfca08d273baf1c1",
@@ -143,15 +143,14 @@ class PrivateZapTests {
] ]
} }
""", """,
) )
val loggedIn = val loggedIn =
NostrSignerInternal( NostrSignerInternal(
KeyPair(Hex.decode("e8e7197ccc53c9ed4cf9b1c8dce085475fa1ffdd71f2c14e44fe23d0bdf77598")), KeyPair(Hex.decode("e8e7197ccc53c9ed4cf9b1c8dce085475fa1ffdd71f2c14e44fe23d0bdf77598")),
) )
val privateZapRequest = val privateZapRequest =
runBlocking {
LnZapRequestEvent.create( LnZapRequestEvent.create(
zappedEvent = textNote, zappedEvent = textNote,
relays = relays =
@@ -166,23 +165,22 @@ class PrivateZapTests {
zapType = LnZapEvent.ZapType.PRIVATE, zapType = LnZapEvent.ZapType.PRIVATE,
toUserPubHex = null, toUserPubHex = null,
) )
val recepientPK = privateZapRequest.zappedAuthor().firstOrNull()
val recepientPost = privateZapRequest.zappedPost().firstOrNull()
if (recepientPK != null && recepientPost != null) {
val privateKey =
createEncryptionPrivateKey(
loggedIn.keyPair.privKey!!.toHexKey(),
recepientPost,
privateZapRequest.createdAt,
)
val decodedPrivateZap = PrivateZapRequestBuilder().decryptAnonTag(privateZapRequest.getAnonTag(), privateKey, recepientPK)
assertNotNull(decodedPrivateZap)
} else {
fail("Should not be null")
} }
val recepientPK = privateZapRequest.zappedAuthor().firstOrNull()
val recepientPost = privateZapRequest.zappedPost().firstOrNull()
if (recepientPK != null && recepientPost != null) {
val privateKey =
createEncryptionPrivateKey(
loggedIn.keyPair.privKey!!.toHexKey(),
recepientPost,
privateZapRequest.createdAt,
)
val decodedPrivateZap = PrivateZapRequestBuilder().decryptAnonTag(privateZapRequest.getAnonTag(), privateKey, recepientPK)
assertNotNull(decodedPrivateZap)
} else {
fail("Should not be null")
} }
}
} }

View File

@@ -34,7 +34,7 @@ import com.vitorpamplona.quartz.nip17Dm.messages.ChatMessageEvent
import com.vitorpamplona.quartz.nip59Giftwrap.seals.SealedRumorEvent import com.vitorpamplona.quartz.nip59Giftwrap.seals.SealedRumorEvent
import com.vitorpamplona.quartz.nip59Giftwrap.wraps.GiftWrapEvent import com.vitorpamplona.quartz.nip59Giftwrap.wraps.GiftWrapEvent
import com.vitorpamplona.quartz.utils.Hex import com.vitorpamplona.quartz.utils.Hex
import kotlinx.coroutines.runBlocking import kotlinx.coroutines.test.runTest
import org.junit.Assert.assertEquals import org.junit.Assert.assertEquals
import org.junit.Assert.assertNotEquals import org.junit.Assert.assertNotEquals
import org.junit.Assert.assertNotNull import org.junit.Assert.assertNotNull
@@ -47,7 +47,7 @@ import org.junit.runner.RunWith
class GiftWrapEventTest { class GiftWrapEventTest {
@Test() @Test()
fun testNip17Utils() = fun testNip17Utils() =
runBlocking { runTest {
val sender = NostrSignerInternal(KeyPair()) val sender = NostrSignerInternal(KeyPair())
val receiver = NostrSignerInternal(KeyPair()) val receiver = NostrSignerInternal(KeyPair())
val message = "Hola, que tal?" val message = "Hola, que tal?"
@@ -88,7 +88,7 @@ class GiftWrapEventTest {
@Test() @Test()
fun testNip17UtilsForGroups() = fun testNip17UtilsForGroups() =
runBlocking { runTest {
val sender = NostrSignerInternal(KeyPair()) val sender = NostrSignerInternal(KeyPair())
val receiver1 = NostrSignerInternal(KeyPair()) val receiver1 = NostrSignerInternal(KeyPair())
val receiver2 = NostrSignerInternal(KeyPair()) val receiver2 = NostrSignerInternal(KeyPair())
@@ -142,7 +142,7 @@ class GiftWrapEventTest {
@Test() @Test()
fun testInternalsSimpleMessage() = fun testInternalsSimpleMessage() =
runBlocking { runTest {
val sender = NostrSignerInternal(KeyPair()) val sender = NostrSignerInternal(KeyPair())
val receiver = NostrSignerInternal(KeyPair()) val receiver = NostrSignerInternal(KeyPair())
@@ -259,7 +259,7 @@ class GiftWrapEventTest {
@Test() @Test()
fun testInternalsGroupMessage() = fun testInternalsGroupMessage() =
runBlocking { runTest {
val sender = NostrSignerInternal(KeyPair()) val sender = NostrSignerInternal(KeyPair())
val receiverA = NostrSignerInternal(KeyPair()) val receiverA = NostrSignerInternal(KeyPair())
val receiverB = NostrSignerInternal(KeyPair()) val receiverB = NostrSignerInternal(KeyPair())
@@ -446,174 +446,164 @@ class GiftWrapEventTest {
} }
@Test @Test
fun testCaseFromAmethyst1() { fun testCaseFromAmethyst1() =
val json = runTest {
""" val json =
{ """
"content":"{\"ciphertext\":\"AaTN5Mt7AOeMosjHeLfai89kmvW/qJ7W2VMttAwuh6hwRGV+ylJhpDbdVRhVmkCotbDjBgS6xioLrSDcdSngFOiVMHS5dTAP0MkQv09aZlBh/NgdmyfHHd24YlHPkDuF5Yb4Vmz7kq/vmjsNZvDrTen3TG2DcEoTV9GKexdMEqyBA4LsB2DLnWfpvOi0olDkGjPGSteTaU1nCdOtN8knoEKumrxwevvbygKphorvKX/j3ojMMb0AceJM6Cr6TRIvSsQnKGEv5V8qbC/uIrQoH3N108Fd/2SY2MWuyLKRnuak9F/w82MV13elq8ngyjcktLYM5yrPg5nrxZlyJsV8D7V/g/bvhoL+UmWe0XoCR5LXzy77SfIkgA1ePKEfGp5sD2CVIzXt9zHdFwGxAKZuyB4qwrRaAFrS2xx+Bw4nnEmF6V9NhfheSCmGzTILuTePx4ubvnYw/j8Hmqd6UvM3DBNnlJ3D6po0blirfWvMe/ea+Em4CMXfq8Iq+7r4gRx8azADygKeJ+C89GTBEvS9EvgrXCVfTMVTcFc44YAZhekOqYY1BOZgfxIV4gUiJfpMMd4B9MQv/tmnewrpTsq1reSQQcEW/mXT2cnMeCZbAIJSPg8usZ30QlrH+np+YSzFKWYDP1kThcV0ElEE2Ne8KaUUFIRE5KmhBQc/qtORefCpne5s7V7J5vLjT5rinsDzzENB1XVlmY1Icx42raP5tGAL1gOK5gRHLvtcgFQR3WcDRYaNqELiYxx41j9w9lz5e00Ttla255rZkb760KSLaBFBss6wYGiYCabVgtBNpkExpCFPPEd5eAZa5rNK2QrnojYsdxEnlicF6A+zSChLy/TbzxYwyQywDfoF9F8kBakPZkAhsciQViCii2KlieRq4OgJFZGndmnS82hyPqsoJIm22vWr1iqMvSBHo/9cLj/r+lfmGVOdgM62JHckPZjOLS0QWIb9gQiT+zXZG22+eZElMYbGXVpR1dyMaQtde8ivEVVLas6kMCVKaDTHEFglaCBXjJ3RNJv73HsG1kb0rMmOj8ltbBakjHpv7M59amavuu6SReYt\",\"nonce\":\"6anNjUdNwW6MNfoKzRZcz1R09N1h8G4L\",\"v\":1}", {
"created_at":1690660515, "content":"{\"ciphertext\":\"AaTN5Mt7AOeMosjHeLfai89kmvW/qJ7W2VMttAwuh6hwRGV+ylJhpDbdVRhVmkCotbDjBgS6xioLrSDcdSngFOiVMHS5dTAP0MkQv09aZlBh/NgdmyfHHd24YlHPkDuF5Yb4Vmz7kq/vmjsNZvDrTen3TG2DcEoTV9GKexdMEqyBA4LsB2DLnWfpvOi0olDkGjPGSteTaU1nCdOtN8knoEKumrxwevvbygKphorvKX/j3ojMMb0AceJM6Cr6TRIvSsQnKGEv5V8qbC/uIrQoH3N108Fd/2SY2MWuyLKRnuak9F/w82MV13elq8ngyjcktLYM5yrPg5nrxZlyJsV8D7V/g/bvhoL+UmWe0XoCR5LXzy77SfIkgA1ePKEfGp5sD2CVIzXt9zHdFwGxAKZuyB4qwrRaAFrS2xx+Bw4nnEmF6V9NhfheSCmGzTILuTePx4ubvnYw/j8Hmqd6UvM3DBNnlJ3D6po0blirfWvMe/ea+Em4CMXfq8Iq+7r4gRx8azADygKeJ+C89GTBEvS9EvgrXCVfTMVTcFc44YAZhekOqYY1BOZgfxIV4gUiJfpMMd4B9MQv/tmnewrpTsq1reSQQcEW/mXT2cnMeCZbAIJSPg8usZ30QlrH+np+YSzFKWYDP1kThcV0ElEE2Ne8KaUUFIRE5KmhBQc/qtORefCpne5s7V7J5vLjT5rinsDzzENB1XVlmY1Icx42raP5tGAL1gOK5gRHLvtcgFQR3WcDRYaNqELiYxx41j9w9lz5e00Ttla255rZkb760KSLaBFBss6wYGiYCabVgtBNpkExpCFPPEd5eAZa5rNK2QrnojYsdxEnlicF6A+zSChLy/TbzxYwyQywDfoF9F8kBakPZkAhsciQViCii2KlieRq4OgJFZGndmnS82hyPqsoJIm22vWr1iqMvSBHo/9cLj/r+lfmGVOdgM62JHckPZjOLS0QWIb9gQiT+zXZG22+eZElMYbGXVpR1dyMaQtde8ivEVVLas6kMCVKaDTHEFglaCBXjJ3RNJv73HsG1kb0rMmOj8ltbBakjHpv7M59amavuu6SReYt\",\"nonce\":\"6anNjUdNwW6MNfoKzRZcz1R09N1h8G4L\",\"v\":1}",
"id":"d90739741c2f5a8c1a03aab5dc219c0b708ed6b0566044495731cd0307cf19a5", "created_at":1690660515,
"kind":1059, "id":"d90739741c2f5a8c1a03aab5dc219c0b708ed6b0566044495731cd0307cf19a5",
"pubkey":"a79b7162f8ebb9c9f7aa65a48977ab7f32aa097520bc543e4d625812154ff6af", "kind":1059,
"sig":"9b012504e779632a2a1f55562fa9a85f8ae6245cbc149b83d25b2971249053abc77f65cc068e5d025b871d743678265fede70de4eaf5af642e675a5b6210077d", "pubkey":"a79b7162f8ebb9c9f7aa65a48977ab7f32aa097520bc543e4d625812154ff6af",
"tags":[ "sig":"9b012504e779632a2a1f55562fa9a85f8ae6245cbc149b83d25b2971249053abc77f65cc068e5d025b871d743678265fede70de4eaf5af642e675a5b6210077d",
[ "tags":[
"p", [
"c55f0b0cb4dd180dd4395867b28dd4c208b709144a69fb7c31a46c369a5ad1c6" "p",
] "c55f0b0cb4dd180dd4395867b28dd4c208b709144a69fb7c31a46c369a5ad1c6"
] ]
}
""".trimIndent()
val rumor: Event =
runBlocking {
val privateKey = "de6152a85a0dea3b09a08a6f8139a314d498a7b52f7e5c28858b64270abd4c70"
unwrapUnsealRumor(json, privateKey)
}
assertNotNull(rumor)
assertEquals("Hola, que tal?", rumor.content)
}
@Test
fun testCaseFromAmethyst2() {
val json =
"""
{
"content":"{\"ciphertext\":\"Zb0ZNYAcDG5y7BiCWgbxY/i7rN7TxPwr3Oaste6em4VcetuenaMu2SyH6OuCCxxmIa7kFennJD8ZCrev0086azsPNutl9I6OCoOfDQb2GoFaLoJAkE/FuW0uEoEJuN72KsKj05HEjOM6nqL2KiW0pxTCNmlGpweMwpXQdm2ItWkybNpq8+b4NJUDee2czBUd9Kr2ELbPISTYzA17z1IzPXGQw8c73NL+QX9I/QZjM/agqX2x5q11SU52xiRyVd9zHf7TMctZI4QEsqDB6xi54D1bAeZlMhVdcpQRpGDfqRz3KXFlhB3Bwdc8GLgY0aLTn6tJs4qrHP3mQkxFYk0mju0afoc0rloMEUHcBVtM18S9OrTPqfmSqFTQsjaT8g+PkmeiLBo1sXsMCS62w0abSZD9OzQtciMz70ZpcWoLjx5f8panjFClvg4tJ8czMURIHM/IFS1uKAUHBArGN8QpCw8MXQBblpyLDiEkFcSX334Zdps0OIw4z328JSdeejyRh4ks+NHDt9FcjC4iicEqfEh8OTkXuKqEAVkRyfAioNQxWQPnXDzMX0Q+BXvKzBA7NaEBDpbV36H/KnrpBBQwokV9/Byb6Seh3g6GSqRAWD3U6Nk2aBMXkD0xY8vnIqMckBeYHxn8BW7k1FdXFC9lE5xCxWZHkmksJ4f0NVaF37O6d8qOe6RK7bfUeF8/SouJEu+eEX1f4KCMboslwkdk8QA8bThGcRGn8GQBMrPKrpZwHYNyyH8jwt9pywigXJejRLDDnDp3FH/3dbZy5CfuNH6KGydf/O5xx1r316so1UPO1mL5LHJUFZVIaMaMMUsgq12gpI0lLEh5NJPpsi9e3ibkzEZGf7FlAJjJQURbQ8xacN7R+w3GWKbJNHiQbUZ2lXo6fwz33t0DrSqEW970yWPHlqxcpd27EI+qqb5IqfklQZ3RObZZBhzDvImaCPG+U7SmgLhPxnilpGjd5lw/ttiqJhPG9mYFMf1eJXSG+Q9VVkGzN7jxXYtx0q0WGjVq98ZGv5RSnF1d9+QVGCd1fiPS3rsaWdYWly8l0y2quYObJ6Mv3Wh3\",\"nonce\":\"/Q2UTTjVZthm/atcCuDjU1e4reF+ZSgZ\",\"v\":1}",
"created_at":1690660515,
"id":"087d9627d63135a5050758a69222e566c86702e930c9905f0b93ccd6bebeca3f",
"kind":1059,
"pubkey":"e59c00796ae2aa9077fc8bcd57fe8d32c0fc363f7c8b93d055c70804ffff3772",
"sig":"807cb641c314ca6910aaeefadcf87d859137520be1039eb40e39832ed59d456fdd800c5f88bba09e1b395ee90c66d5330847bdd010b63be9919bf091adbc2c2a",
"tags":[
[
"p",
"f85f315c06aaf19c2b30a96ca80d9644720655ee8d3ec43b84657a7c98f36a23"
] ]
] }
} """.trimIndent()
""".trimIndent()
val privateKey = "409ff7654141eaa16cd2161fe5bd127aeaef71f270c67587474b78998a8e3533" val privateKey = "de6152a85a0dea3b09a08a6f8139a314d498a7b52f7e5c28858b64270abd4c70"
val rumor = unwrapUnsealRumor(json, privateKey)
val rumor: Event = assertNotNull(rumor)
runBlocking { assertEquals("Hola, que tal?", rumor.content)
unwrapUnsealRumor(json, privateKey) }
}
assertNotNull(rumor)
assertEquals("Hola, que tal?", rumor.content)
}
@Test @Test
fun testDecryptFromCoracle() { fun testCaseFromAmethyst2() =
val json = runTest {
""" val json =
{ """
"content": "{\"ciphertext\":\"fo0/Ywyfu86cXKoOOeFFlMRv+LYM6GJUL+F/J4ARv6EcAufOZP46vimlurPBLPjNgzuGemGjlTFfC3vtq84AqIsqFo3dqKunq8Vp+mmubvxIQUDzOGYvM0WE/XOiW5LEe3U3Vq399Dq07xRpXELcp4EZxGyu4Fowv2Ppb4SKpH8g+9N3z2+bwYcSxBvI6SrL+hgmVMrRlgvsUHN1d53ni9ehRseBqrLj/DqyyEiygsKm6vnEZAPKnl1MrBaVOBZmGsyjAa/G4SBVVmk78sW7xWWvo4cV+C22FluDWUOdj/bYabH4aR4scnBX3GLYqfLuzGnuQlRNsb5unXVX41+39uXzROrmNP6iYVyYxy5tfoyN7PPZ4osoKpLDUGldmXHD6RjMcAFuou4hXt2JlTPmXpj/x8qInXId5mkmU4nTGiasvsCIpJljbCujwCjbjLTcD4QrjuhMdtSsAzjT0CDv5Lmc632eKRYtDu/9B+lkqBBkp7amhzbqp8suNTnybkvbGFQQGEQnsLfNJw/GGopAuthfi8zkTgUZR/LxFR7ZKAX73G+5PQSDSjPuGH/dQEnsFo45zsh1Xro8SfUQBsPphbX2GS31Lwu5vA30O922T4UiWuU+EdNgZR0JankQ5NPgvr1uS56C3v84VwdrNWQUCwC4eYJl4Mb/OdpEy9qwsisisppq6uuzxmxd1qx3JfocnGsvB7h2g2sG+0lyZADDSobOEZEKHaBP3w+dRcJW9D95EmzPym9GO0n+33OfqFQbda7G0rzUWfPDV0gXIuZcKs/HmDqepgIZN8FG7JhRBeAv0bCbKQACre0c8tzVEn5yCYemltScdKop3pC/r6gH50jRhAlFAiIKx8R+XwuMmJRqOcH4WfkpZlfVU85/I0XJOCHWKk6BnJi/NPP9zYiZiJe+5LecqMUVjtO0YAlv138+U/3FIT/anQ4H5bjVWBZmajwf\",\"nonce\":\"Mv70S6jgrs4D1rlqV9b5DddiymGAcVVe\",\"v\":1}", {
"created_at": 1690528373, "content":"{\"ciphertext\":\"Zb0ZNYAcDG5y7BiCWgbxY/i7rN7TxPwr3Oaste6em4VcetuenaMu2SyH6OuCCxxmIa7kFennJD8ZCrev0086azsPNutl9I6OCoOfDQb2GoFaLoJAkE/FuW0uEoEJuN72KsKj05HEjOM6nqL2KiW0pxTCNmlGpweMwpXQdm2ItWkybNpq8+b4NJUDee2czBUd9Kr2ELbPISTYzA17z1IzPXGQw8c73NL+QX9I/QZjM/agqX2x5q11SU52xiRyVd9zHf7TMctZI4QEsqDB6xi54D1bAeZlMhVdcpQRpGDfqRz3KXFlhB3Bwdc8GLgY0aLTn6tJs4qrHP3mQkxFYk0mju0afoc0rloMEUHcBVtM18S9OrTPqfmSqFTQsjaT8g+PkmeiLBo1sXsMCS62w0abSZD9OzQtciMz70ZpcWoLjx5f8panjFClvg4tJ8czMURIHM/IFS1uKAUHBArGN8QpCw8MXQBblpyLDiEkFcSX334Zdps0OIw4z328JSdeejyRh4ks+NHDt9FcjC4iicEqfEh8OTkXuKqEAVkRyfAioNQxWQPnXDzMX0Q+BXvKzBA7NaEBDpbV36H/KnrpBBQwokV9/Byb6Seh3g6GSqRAWD3U6Nk2aBMXkD0xY8vnIqMckBeYHxn8BW7k1FdXFC9lE5xCxWZHkmksJ4f0NVaF37O6d8qOe6RK7bfUeF8/SouJEu+eEX1f4KCMboslwkdk8QA8bThGcRGn8GQBMrPKrpZwHYNyyH8jwt9pywigXJejRLDDnDp3FH/3dbZy5CfuNH6KGydf/O5xx1r316so1UPO1mL5LHJUFZVIaMaMMUsgq12gpI0lLEh5NJPpsi9e3ibkzEZGf7FlAJjJQURbQ8xacN7R+w3GWKbJNHiQbUZ2lXo6fwz33t0DrSqEW970yWPHlqxcpd27EI+qqb5IqfklQZ3RObZZBhzDvImaCPG+U7SmgLhPxnilpGjd5lw/ttiqJhPG9mYFMf1eJXSG+Q9VVkGzN7jxXYtx0q0WGjVq98ZGv5RSnF1d9+QVGCd1fiPS3rsaWdYWly8l0y2quYObJ6Mv3Wh3\",\"nonce\":\"/Q2UTTjVZthm/atcCuDjU1e4reF+ZSgZ\",\"v\":1}",
"id": "6b108e4236c3c338236ee589388ce0f91f921e1532ae52e75d1d2add6f8e691a", "created_at":1690660515,
"kind": 1059, "id":"087d9627d63135a5050758a69222e566c86702e930c9905f0b93ccd6bebeca3f",
"pubkey": "627dc0248335e2bf9adac14be9494139ebbeb12c422d7df5b0e3cd72d04c209c", "kind":1059,
"sig": "be11da487196db298e4ffb7a03e74176c37441c88b39c95b518fadce6fd02f23c58b2c435ca38c24d512713935ab719dae80bf952267630809e1f84be8e95174", "pubkey":"e59c00796ae2aa9077fc8bcd57fe8d32c0fc363f7c8b93d055c70804ffff3772",
"tags": [ "sig":"807cb641c314ca6910aaeefadcf87d859137520be1039eb40e39832ed59d456fdd800c5f88bba09e1b395ee90c66d5330847bdd010b63be9919bf091adbc2c2a",
[ "tags":[
"p", [
"e7764a227c12ac1ef2db79ae180392c90903b2cec1e37f5c1a4afed38117185e" "p",
] "f85f315c06aaf19c2b30a96ca80d9644720655ee8d3ec43b84657a7c98f36a23"
], ]
"seenOn": [ ]
"wss://relay.damus.io/" }
] """.trimIndent()
}
""".trimIndent()
val privateKey = "09e0051fdf5fdd9dd7a54713583006442cbdbf87bdcdab1a402f26e527d56771" val privateKey = "409ff7654141eaa16cd2161fe5bd127aeaef71f270c67587474b78998a8e3533"
val rumor: Event = val rumor = unwrapUnsealRumor(json, privateKey)
runBlocking {
unwrapUnsealRumor(json, privateKey)
}
assertNotNull(rumor) assertNotNull(rumor)
assertEquals("test", rumor.content) assertEquals("Hola, que tal?", rumor.content)
} }
@Test @Test
fun testFromCoracle2() { fun testDecryptFromCoracle() =
val json = runTest {
""" val json =
{ """
"content": "{\"ciphertext\":\"Hn/dHo/I8Qk6QWWAiKyo/SfKJqQfHdV0O5tMmgqMyfHrsFoDY6IhGQP2EgCJ/6HsNQyO/8EMAmLW8w0PbDKlBKYGKGpaMwCA6B1r0rLjvu+149RJZuggRNm9rd7tNVNkNs38iqt1KYD++bohePm52q+VhAQikbX2gTONV82ROwZylAg9vjvMnYkDt45g6N97s9FRB6V7YMiUEtJnneMixa6klucpUuenQ4569tyt5vnUMD2VNhKYCc2jit2hf7k0DIhvZrVC3OdopUvxIuYYWr3r7XpuEB3HJ6Ji3ajHPzgGeFcItBR7uKZ9s6XU34F3keyZbxrv3yWHFM5NrOctAdZexSGpqWRW93M0KZUAp9HgQh3YzMLl8xt0mcrVywCgjU6Kx8IwkI0bjPU+Am8acY3cItted6hZQ4Vy1xFITdKVfPWDl3Ab59iBg9+IkY5C31wqsKPgPVVycwQE6UpaGW74gy3qZshwyoo01owvEIbVvrSJWXH7EUVvndDPvUbo+f+EVa84IEwVjPmY2oR7VsxVfqRBdmPg23OSw/9rzVybmruqaQHd3xrTTEcnG0qBc/ugCXsiuILTeScOovEnqIlKKK3KB36jMtdScdJB+b4YrzJInY1AvqU7IAgqe0vmo1LdbMtj7kjuxkXJhhQsunAbTvPigTrsOfJ08P9l7r/95kpxudgagEaW7XAjYVfLphseJT3Iy1IuQEyG5sshQ+pl/CYvkGide7ykHwm9pjSBVkD9Mdcn5X6lSnLNJEcwY43pz43r6Kq3L09qneILY3DSKyQ16Zcu1MiAMAM5r6JGvpAHqcMmixi9ORuiryjteTmY4L0vI7b3W/0RSUblXxUrb8IpeysBrFmiKJBgCoU0r/D/8tgR+Eewyp1qxKI4SfKG5GFH40zZ2oVvKyoHAR4x1oVDp/MttcnxkzAsCFL6QuJC9A/vImjsumpmYB/EChcZCOAsfqkuzH4VSjZx\",\"nonce\":\"K537d+7m5tUcXZfkr3Qk2J2G86vdBMmY\",\"v\":1}", {
"created_at": 1690655012, "content": "{\"ciphertext\":\"fo0/Ywyfu86cXKoOOeFFlMRv+LYM6GJUL+F/J4ARv6EcAufOZP46vimlurPBLPjNgzuGemGjlTFfC3vtq84AqIsqFo3dqKunq8Vp+mmubvxIQUDzOGYvM0WE/XOiW5LEe3U3Vq399Dq07xRpXELcp4EZxGyu4Fowv2Ppb4SKpH8g+9N3z2+bwYcSxBvI6SrL+hgmVMrRlgvsUHN1d53ni9ehRseBqrLj/DqyyEiygsKm6vnEZAPKnl1MrBaVOBZmGsyjAa/G4SBVVmk78sW7xWWvo4cV+C22FluDWUOdj/bYabH4aR4scnBX3GLYqfLuzGnuQlRNsb5unXVX41+39uXzROrmNP6iYVyYxy5tfoyN7PPZ4osoKpLDUGldmXHD6RjMcAFuou4hXt2JlTPmXpj/x8qInXId5mkmU4nTGiasvsCIpJljbCujwCjbjLTcD4QrjuhMdtSsAzjT0CDv5Lmc632eKRYtDu/9B+lkqBBkp7amhzbqp8suNTnybkvbGFQQGEQnsLfNJw/GGopAuthfi8zkTgUZR/LxFR7ZKAX73G+5PQSDSjPuGH/dQEnsFo45zsh1Xro8SfUQBsPphbX2GS31Lwu5vA30O922T4UiWuU+EdNgZR0JankQ5NPgvr1uS56C3v84VwdrNWQUCwC4eYJl4Mb/OdpEy9qwsisisppq6uuzxmxd1qx3JfocnGsvB7h2g2sG+0lyZADDSobOEZEKHaBP3w+dRcJW9D95EmzPym9GO0n+33OfqFQbda7G0rzUWfPDV0gXIuZcKs/HmDqepgIZN8FG7JhRBeAv0bCbKQACre0c8tzVEn5yCYemltScdKop3pC/r6gH50jRhAlFAiIKx8R+XwuMmJRqOcH4WfkpZlfVU85/I0XJOCHWKk6BnJi/NPP9zYiZiJe+5LecqMUVjtO0YAlv138+U/3FIT/anQ4H5bjVWBZmajwf\",\"nonce\":\"Mv70S6jgrs4D1rlqV9b5DddiymGAcVVe\",\"v\":1}",
"id": "c4f97c6332b0a63912c44c9e1f8c7b23581dc67a8489ec1522ec205fea7133db", "created_at": 1690528373,
"kind": 1059, "id": "6b108e4236c3c338236ee589388ce0f91f921e1532ae52e75d1d2add6f8e691a",
"pubkey": "8def03a22b1039256a3883d46c7ccd5562f61743100db401344284547de7ec61", "kind": 1059,
"sig": "25dcf24bdda99c04abc72274d9f7a30538a4a00a70ac4b39db4082b73823979858df93cd649c25edfb759857eac46ed70bb9ad0598f2e011d733a5a382bc4def", "pubkey": "627dc0248335e2bf9adac14be9494139ebbeb12c422d7df5b0e3cd72d04c209c",
"tags": [ "sig": "be11da487196db298e4ffb7a03e74176c37441c88b39c95b518fadce6fd02f23c58b2c435ca38c24d512713935ab719dae80bf952267630809e1f84be8e95174",
[ "tags": [
"p", [
"e7764a227c12ac1ef2db79ae180392c90903b2cec1e37f5c1a4afed38117185e" "p",
] "e7764a227c12ac1ef2db79ae180392c90903b2cec1e37f5c1a4afed38117185e"
] ]
} ],
""".trimIndent() "seenOn": [
"wss://relay.damus.io/"
]
}
""".trimIndent()
val privateKey = "09e0051fdf5fdd9dd7a54713583006442cbdbf87bdcdab1a402f26e527d56771" val privateKey = "09e0051fdf5fdd9dd7a54713583006442cbdbf87bdcdab1a402f26e527d56771"
val rumor = val rumor: Event = unwrapUnsealRumor(json, privateKey)
runBlocking {
unwrapUnsealRumor(json, privateKey)
}
assertEquals("asdfasdfasdf", rumor.content) assertNotNull(rumor)
assertEquals(1690659269L, rumor.createdAt) assertEquals("test", rumor.content)
assertEquals("827ba09d32ab81d62c60f657b350198c8aaba84372dab9ad3f4f6b8b7274b707", rumor.id) }
assertEquals(14, rumor.kind)
assertEquals("subject", rumor.tags.firstOrNull()?.get(0))
assertEquals("test", rumor.tags.firstOrNull()?.get(1))
}
@Test @Test
fun testFromCoracle3() { fun testFromCoracle2() =
val json = runTest {
""" val json =
{ """
"content": "{\"ciphertext\":\"PGCodiacmCB/sClw0C6DQRpP/XIfNAKCVZdKLQpOqytgbFryhs9Z+cPldq2FajXzxs3jQsF7/EVQyWpuV8pXetvFT9tvzjg4Xcm7ZcooLUnAeAo2xZNcJontN4cGubuDqKuXy5n59yXP1fIxfnJxRTRRdCZ2edhsKeNR5NSByUi+StjV10rnfHt8AhZCpiXiZ/giTOsC4wdaeONPgMzMeljaJWLvl6n11VjmXhkx1mXIQt43CNB1hIqO3p89Mbd9p+nlLrOsR+Xs0TB4DCh4XTPbvgf7B7Z+PgOfl3GZfJy9x6TciLcF4E3Ba1zrPe4f79czCIEiJ1yrIKrzzYvv+it35DZQ8fgveFXpyHnNL29hml8PNjyOsFbCHVYLMGw88evI5PijOcpe1TtdoioX8kX5kVEQSKJXuoSjTorvbRPCgGzaa1m0J0uTpzri5VD22a/Jh2CcAnubg6w4JDdUWCogdSV3NqiJllo7ZF7WnZ3apPdRD23MEfphVBJrcLBUNlmwajnY5IvVTKTkZOP50r9dBapvMWXIo6M6zhy/5vVWJz57863pelYCRG4upaXZuNK9sMBtbiphxmFR83i8RML8KN8Q391Cd/xBN7TxJNo5p2YU25VeGZUAmHY8DYlMQDm8Br0nStAXp3T+DzTRL8FTECa8DJV+KTAPoCxqhv3B28Ehr0XAP75CsHoLU00G48cR7h3vQ0CnfKh6KXU6nnDA5OWfpMYpirACCpsnpSD0OaCQ3gkQp3zZNMS3HcOpnPK/IY7R0esbzgAkvNhkyxaIfPDdf+eRUSOA9+2Ji28MwjjY8Dw3SLdUqCOzIDjQeR/T5oNmaQJm3lZ8G0FxxC6ejD4VJX/NI/x+STeB9jWHWmHZvqKzV6JHNh6qmZb6TKSIPOHpafWFoeJFOmiiigf46sju9vRXmVEAx59HXWnvnvCBNJg877yCMulB6xyQuSdVDuotQU4tQZwCKedTHJ6GqjesM98UlJrDtdWQURwwW1qc7N8tS6PukmUVEf0jmbIWVIBmUlkcVuiSs1g1h1kjt8c4MnGTz3CSgpOd1MqxLrl9WwrTqM+YnE+yeZYUjFoewyKZIQ==\",\"nonce\":\"OdCZczJiUGR4bOGIElQ4UUH4dQmG5U/3\",\"v\":1}", {
"kind": 1059, "content": "{\"ciphertext\":\"Hn/dHo/I8Qk6QWWAiKyo/SfKJqQfHdV0O5tMmgqMyfHrsFoDY6IhGQP2EgCJ/6HsNQyO/8EMAmLW8w0PbDKlBKYGKGpaMwCA6B1r0rLjvu+149RJZuggRNm9rd7tNVNkNs38iqt1KYD++bohePm52q+VhAQikbX2gTONV82ROwZylAg9vjvMnYkDt45g6N97s9FRB6V7YMiUEtJnneMixa6klucpUuenQ4569tyt5vnUMD2VNhKYCc2jit2hf7k0DIhvZrVC3OdopUvxIuYYWr3r7XpuEB3HJ6Ji3ajHPzgGeFcItBR7uKZ9s6XU34F3keyZbxrv3yWHFM5NrOctAdZexSGpqWRW93M0KZUAp9HgQh3YzMLl8xt0mcrVywCgjU6Kx8IwkI0bjPU+Am8acY3cItted6hZQ4Vy1xFITdKVfPWDl3Ab59iBg9+IkY5C31wqsKPgPVVycwQE6UpaGW74gy3qZshwyoo01owvEIbVvrSJWXH7EUVvndDPvUbo+f+EVa84IEwVjPmY2oR7VsxVfqRBdmPg23OSw/9rzVybmruqaQHd3xrTTEcnG0qBc/ugCXsiuILTeScOovEnqIlKKK3KB36jMtdScdJB+b4YrzJInY1AvqU7IAgqe0vmo1LdbMtj7kjuxkXJhhQsunAbTvPigTrsOfJ08P9l7r/95kpxudgagEaW7XAjYVfLphseJT3Iy1IuQEyG5sshQ+pl/CYvkGide7ykHwm9pjSBVkD9Mdcn5X6lSnLNJEcwY43pz43r6Kq3L09qneILY3DSKyQ16Zcu1MiAMAM5r6JGvpAHqcMmixi9ORuiryjteTmY4L0vI7b3W/0RSUblXxUrb8IpeysBrFmiKJBgCoU0r/D/8tgR+Eewyp1qxKI4SfKG5GFH40zZ2oVvKyoHAR4x1oVDp/MttcnxkzAsCFL6QuJC9A/vImjsumpmYB/EChcZCOAsfqkuzH4VSjZx\",\"nonce\":\"K537d+7m5tUcXZfkr3Qk2J2G86vdBMmY\",\"v\":1}",
"created_at": 1690772945, "created_at": 1690655012,
"pubkey": "e01475e87896800b7285eb0daf263c59f811c8fc5bc8daa105d2c98b6d7c4952", "id": "c4f97c6332b0a63912c44c9e1f8c7b23581dc67a8489ec1522ec205fea7133db",
"tags": [ "kind": 1059,
[ "pubkey": "8def03a22b1039256a3883d46c7ccd5562f61743100db401344284547de7ec61",
"p", "sig": "25dcf24bdda99c04abc72274d9f7a30538a4a00a70ac4b39db4082b73823979858df93cd649c25edfb759857eac46ed70bb9ad0598f2e011d733a5a382bc4def",
"b08d8857a92b4d6aa580ff55cc3c18c4edf313c83388c34abc118621f74f1a78" "tags": [
] [
], "p",
"id": "d9fc85ece892ce45ffa737b3ddc0f8b752623181d75363b966191f8c03d2debe", "e7764a227c12ac1ef2db79ae180392c90903b2cec1e37f5c1a4afed38117185e"
"sig": "1b20416b83f4b5b8eead11e29c185f46b5e76d1960e4505210ddd00f7a6973cc11268f52a8989e3799b774d5f3a55db95bed4d66a1b6e88ab54becec5c771c17" ]
} ]
""".trimIndent() }
""".trimIndent()
val privateKey = "7dd22cafc512c0bc363a259f6dcda515b13ae3351066d7976fd0bb79cbd0d700" val privateKey = "09e0051fdf5fdd9dd7a54713583006442cbdbf87bdcdab1a402f26e527d56771"
val rumor = val rumor = unwrapUnsealRumor(json, privateKey)
runBlocking {
unwrapUnsealRumor(json, privateKey)
}
assertEquals("8d1a56008d4e31dae2fb8bef36b3efea519eff75f57033107e2aa16702466ef2", rumor.id) assertEquals("asdfasdfasdf", rumor.content)
assertEquals("Howdy", rumor.content) assertEquals(1690659269L, rumor.createdAt)
assertEquals(1690833960L, rumor.createdAt) assertEquals("827ba09d32ab81d62c60f657b350198c8aaba84372dab9ad3f4f6b8b7274b707", rumor.id)
assertEquals(14, rumor.kind) assertEquals(14, rumor.kind)
assertEquals("p", rumor.tags.firstOrNull()?.get(0)) assertEquals("subject", rumor.tags.firstOrNull()?.get(0))
assertEquals( assertEquals("test", rumor.tags.firstOrNull()?.get(1))
"b08d8857a92b4d6aa580ff55cc3c18c4edf313c83388c34abc118621f74f1a78", }
rumor.tags.firstOrNull()?.get(1),
) @Test
assertEquals("subject", rumor.tags.getOrNull(1)?.get(0)) fun testFromCoracle3() =
assertEquals("Stuff", rumor.tags.getOrNull(1)?.get(1)) runTest {
} val json =
"""
{
"content": "{\"ciphertext\":\"PGCodiacmCB/sClw0C6DQRpP/XIfNAKCVZdKLQpOqytgbFryhs9Z+cPldq2FajXzxs3jQsF7/EVQyWpuV8pXetvFT9tvzjg4Xcm7ZcooLUnAeAo2xZNcJontN4cGubuDqKuXy5n59yXP1fIxfnJxRTRRdCZ2edhsKeNR5NSByUi+StjV10rnfHt8AhZCpiXiZ/giTOsC4wdaeONPgMzMeljaJWLvl6n11VjmXhkx1mXIQt43CNB1hIqO3p89Mbd9p+nlLrOsR+Xs0TB4DCh4XTPbvgf7B7Z+PgOfl3GZfJy9x6TciLcF4E3Ba1zrPe4f79czCIEiJ1yrIKrzzYvv+it35DZQ8fgveFXpyHnNL29hml8PNjyOsFbCHVYLMGw88evI5PijOcpe1TtdoioX8kX5kVEQSKJXuoSjTorvbRPCgGzaa1m0J0uTpzri5VD22a/Jh2CcAnubg6w4JDdUWCogdSV3NqiJllo7ZF7WnZ3apPdRD23MEfphVBJrcLBUNlmwajnY5IvVTKTkZOP50r9dBapvMWXIo6M6zhy/5vVWJz57863pelYCRG4upaXZuNK9sMBtbiphxmFR83i8RML8KN8Q391Cd/xBN7TxJNo5p2YU25VeGZUAmHY8DYlMQDm8Br0nStAXp3T+DzTRL8FTECa8DJV+KTAPoCxqhv3B28Ehr0XAP75CsHoLU00G48cR7h3vQ0CnfKh6KXU6nnDA5OWfpMYpirACCpsnpSD0OaCQ3gkQp3zZNMS3HcOpnPK/IY7R0esbzgAkvNhkyxaIfPDdf+eRUSOA9+2Ji28MwjjY8Dw3SLdUqCOzIDjQeR/T5oNmaQJm3lZ8G0FxxC6ejD4VJX/NI/x+STeB9jWHWmHZvqKzV6JHNh6qmZb6TKSIPOHpafWFoeJFOmiiigf46sju9vRXmVEAx59HXWnvnvCBNJg877yCMulB6xyQuSdVDuotQU4tQZwCKedTHJ6GqjesM98UlJrDtdWQURwwW1qc7N8tS6PukmUVEf0jmbIWVIBmUlkcVuiSs1g1h1kjt8c4MnGTz3CSgpOd1MqxLrl9WwrTqM+YnE+yeZYUjFoewyKZIQ==\",\"nonce\":\"OdCZczJiUGR4bOGIElQ4UUH4dQmG5U/3\",\"v\":1}",
"kind": 1059,
"created_at": 1690772945,
"pubkey": "e01475e87896800b7285eb0daf263c59f811c8fc5bc8daa105d2c98b6d7c4952",
"tags": [
[
"p",
"b08d8857a92b4d6aa580ff55cc3c18c4edf313c83388c34abc118621f74f1a78"
]
],
"id": "d9fc85ece892ce45ffa737b3ddc0f8b752623181d75363b966191f8c03d2debe",
"sig": "1b20416b83f4b5b8eead11e29c185f46b5e76d1960e4505210ddd00f7a6973cc11268f52a8989e3799b774d5f3a55db95bed4d66a1b6e88ab54becec5c771c17"
}
""".trimIndent()
val privateKey = "7dd22cafc512c0bc363a259f6dcda515b13ae3351066d7976fd0bb79cbd0d700"
val rumor = unwrapUnsealRumor(json, privateKey)
assertEquals("8d1a56008d4e31dae2fb8bef36b3efea519eff75f57033107e2aa16702466ef2", rumor.id)
assertEquals("Howdy", rumor.content)
assertEquals(1690833960L, rumor.createdAt)
assertEquals(14, rumor.kind)
assertEquals("p", rumor.tags.firstOrNull()?.get(0))
assertEquals(
"b08d8857a92b4d6aa580ff55cc3c18c4edf313c83388c34abc118621f74f1a78",
rumor.tags.firstOrNull()?.get(1),
)
assertEquals("subject", rumor.tags.getOrNull(1)?.get(0))
assertEquals("Stuff", rumor.tags.getOrNull(1)?.get(1))
}
suspend fun unwrapUnsealRumor( suspend fun unwrapUnsealRumor(
json: String, json: String,
@@ -659,7 +649,7 @@ class GiftWrapEventTest {
wrap.checkSignature() wrap.checkSignature()
val event = val event =
runBlocking { runTest {
wrap.unwrapThrowing(receiversPrivateKey) wrap.unwrapThrowing(receiversPrivateKey)
} }

View File

@@ -20,7 +20,7 @@
*/ */
package com.vitorpamplona.quartz.nip05DnsIdentifiers package com.vitorpamplona.quartz.nip05DnsIdentifiers
import kotlinx.coroutines.runBlocking import kotlinx.coroutines.test.runTest
import kotlin.test.Test import kotlin.test.Test
import kotlin.test.assertEquals import kotlin.test.assertEquals
import kotlin.test.assertNull import kotlin.test.assertNull
@@ -36,7 +36,7 @@ class Nip05Test {
@Test @Test
fun `test with matching case on user name`() = fun `test with matching case on user name`() =
runBlocking { runTest {
// Set-up // Set-up
val userNameToTest = ALL_UPPER_CASE_USER_NAME val userNameToTest = ALL_UPPER_CASE_USER_NAME
val expectedPubKey = "ca29c211f1c72d5b6622268ff43d2288ea2b2cb5b9aa196ff9f1704fc914b71b" val expectedPubKey = "ca29c211f1c72d5b6622268ff43d2288ea2b2cb5b9aa196ff9f1704fc914b71b"
@@ -51,7 +51,7 @@ class Nip05Test {
@Test @Test
fun `test with NOT matching case on user name`() = fun `test with NOT matching case on user name`() =
runBlocking { runTest {
// Set-up // Set-up
val expectedPubKey = "ca29c211f1c72d5b6622268ff43d2288ea2b2cb5b9aa196ff9f1704fc914b71b" val expectedPubKey = "ca29c211f1c72d5b6622268ff43d2288ea2b2cb5b9aa196ff9f1704fc914b71b"
val nostrJson = "{ \"names\": { \"$ALL_UPPER_CASE_USER_NAME\": \"$expectedPubKey\" }}" val nostrJson = "{ \"names\": { \"$ALL_UPPER_CASE_USER_NAME\": \"$expectedPubKey\" }}"

View File

@@ -23,7 +23,7 @@ package com.vitorpamplona.quartz.nip51Lists.bookmarkList
import com.vitorpamplona.quartz.nip01Core.signers.NostrSignerInternal import com.vitorpamplona.quartz.nip01Core.signers.NostrSignerInternal
import com.vitorpamplona.quartz.nip51Lists.bookmarkList.tags.EventBookmark import com.vitorpamplona.quartz.nip51Lists.bookmarkList.tags.EventBookmark
import com.vitorpamplona.quartz.utils.nsecToKeyPair import com.vitorpamplona.quartz.utils.nsecToKeyPair
import kotlinx.coroutines.runBlocking import kotlinx.coroutines.test.runTest
import kotlin.test.Test import kotlin.test.Test
import kotlin.test.assertFalse import kotlin.test.assertFalse
import kotlin.test.assertTrue import kotlin.test.assertTrue
@@ -33,7 +33,7 @@ class BookmarkListEventTest {
@Test @Test
fun publicTagsPreservedWhenRemovingFromPrivateBookmarks() = fun publicTagsPreservedWhenRemovingFromPrivateBookmarks() =
runBlocking { runTest {
// Create a test event bookmark // Create a test event bookmark
val testEventId = "a".repeat(64) val testEventId = "a".repeat(64)
val testBookmark = EventBookmark(testEventId) val testBookmark = EventBookmark(testEventId)
@@ -84,7 +84,7 @@ class BookmarkListEventTest {
@Test @Test
fun publicTagsRemovedWhenRemovingFromPublicBookmarks() = fun publicTagsRemovedWhenRemovingFromPublicBookmarks() =
runBlocking { runTest {
// Create a test event bookmark // Create a test event bookmark
val testEventId = "b".repeat(64) val testEventId = "b".repeat(64)
val testBookmark = EventBookmark(testEventId) val testBookmark = EventBookmark(testEventId)

View File

@@ -30,14 +30,14 @@ import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.SupervisorJob import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.cancel import kotlinx.coroutines.cancel
import kotlinx.coroutines.runBlocking import kotlinx.coroutines.test.runTest
import kotlin.test.Test import kotlin.test.Test
import kotlin.test.assertEquals import kotlin.test.assertEquals
class NostrClientSendAndWaitTest : BaseNostrClientTest() { class NostrClientSendAndWaitTest : BaseNostrClientTest() {
@Test @Test
fun testSendAndWaitForResponse() = fun testSendAndWaitForResponse() =
runBlocking { runTest {
val appScope = CoroutineScope(Dispatchers.Default + SupervisorJob()) val appScope = CoroutineScope(Dispatchers.Default + SupervisorJob())
val client = NostrClient(socketBuilder, appScope) val client = NostrClient(socketBuilder, appScope)