Moves test assets to resources to make it work with kmp

This commit is contained in:
Vitor Pamplona
2025-08-27 21:09:21 -04:00
parent ce991a8aea
commit 170b6cfe69
24 changed files with 30 additions and 52 deletions
@@ -21,7 +21,6 @@
package com.vitorpamplona.quartz
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.platform.app.InstrumentationRegistry.getInstrumentation
import com.fasterxml.jackson.module.kotlin.readValue
import com.vitorpamplona.quartz.nip01Core.core.Event
import com.vitorpamplona.quartz.nip01Core.jackson.JsonMapper
@@ -39,7 +38,7 @@ class LargeDBSignatureCheck {
@Test
fun insertDatabaseSample() =
runBlocking {
val fullDBInputStream = getInstrumentation().context.assets.open("nostr_vitor_short.json")
val fullDBInputStream = javaClass.classLoader?.getResourceAsStream("nostr_vitor_short.json")
val eventArray =
JsonMapper.mapper.readValue<ArrayList<Event>>(
@@ -59,7 +58,7 @@ class LargeDBSignatureCheck {
fun insertStartupDatabase() =
runBlocking {
// This file includes duplicates
val fullDBInputStream = getInstrumentation().context.assets.open("nostr_vitor_startup_data.json")
val fullDBInputStream = javaClass.classLoader?.getResourceAsStream("nostr_vitor_startup_data.json")
val eventArray =
JsonMapper.mapper.readValue<ArrayList<Event>>(
@@ -25,7 +25,6 @@ import android.database.sqlite.SQLiteException
import android.util.Log
import androidx.test.core.app.ApplicationProvider
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.platform.app.InstrumentationRegistry.getInstrumentation
import com.fasterxml.jackson.module.kotlin.readValue
import com.vitorpamplona.quartz.nip01Core.core.Event
import com.vitorpamplona.quartz.nip01Core.jackson.JsonMapper
@@ -42,7 +41,7 @@ class LargeDBTests {
companion object {
fun getEventDB(): List<Event> {
// This file includes duplicates
val fullDBInputStream = getInstrumentation().context.assets.open("nostr_vitor_startup_data.json")
val fullDBInputStream = javaClass.classLoader?.getResourceAsStream("nostr_vitor_startup_data.json")
return JsonMapper.mapper.readValue<ArrayList<Event>>(
GZIPInputStream(fullDBInputStream),
@@ -21,7 +21,6 @@
package com.vitorpamplona.quartz.nip06KeyDerivation
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.platform.app.InstrumentationRegistry
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import com.vitorpamplona.quartz.nip01Core.core.toHexKey
import com.vitorpamplona.quartz.utils.Hex
@@ -36,12 +35,7 @@ import org.junit.runner.RunWith
class Bip39MnemonicsTest {
private val tests =
jacksonObjectMapper()
.readTree(
InstrumentationRegistry
.getInstrumentation()
.context.assets
.open("bip39.vectors.json"),
)
.readTree(javaClass.classLoader?.getResourceAsStream("bip39.vectors.json"))
@Test
fun toSeed() {
@@ -21,7 +21,6 @@
package com.vitorpamplona.quartz.nip17Dm
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.platform.app.InstrumentationRegistry.getInstrumentation
import com.vitorpamplona.quartz.nip01Core.core.hexToByteArray
import com.vitorpamplona.quartz.nip17Dm.files.encryption.AESGCM
import junit.framework.TestCase.assertEquals
@@ -46,9 +45,9 @@ class AESGCMTest {
@Test
fun imageTest() {
val image =
getInstrumentation().context.assets.open("ovxxk2vz.jpg").use {
javaClass.classLoader?.getResourceAsStream("ovxxk2vz.jpg")?.use {
it.readAllBytes()
}
}!!
val decrypted = cipher.decrypt(image)
@@ -64,9 +63,9 @@ class AESGCMTest {
)
val encrypted =
getInstrumentation().context.assets.open("trouble_video").use {
javaClass.classLoader?.getResourceAsStream("trouble_video")?.use {
it.readAllBytes()
}
}!!
val decrypted = myCipher.decrypt(encrypted)
@@ -33,11 +33,8 @@ 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
import java.util.concurrent.CountDownLatch
import java.util.concurrent.TimeUnit
@RunWith(AndroidJUnit4::class)
class NIP19EmbedTests {
@@ -57,7 +54,7 @@ class NIP19EmbedTests {
assertNotNull(textNote)
val bech32 = NEmbed.create(textNote!!)
val bech32 = NEmbed.create(textNote)
println(bech32)
@@ -65,7 +62,7 @@ class NIP19EmbedTests {
assertTrue(decodedNote.verify())
assertEquals(textNote!!.toJson(), decodedNote.toJson())
assertEquals(textNote.toJson(), decodedNote.toJson())
}
@Test
@@ -101,15 +98,11 @@ class NIP19EmbedTests {
KeyPair(Hex.decode("e8e7197ccc53c9ed4cf9b1c8dce085475fa1ffdd71f2c14e44fe23d0bdf77598")),
)
val countDownLatch = CountDownLatch(1)
val eyeglassesPrescriptionEvent =
runBlocking {
signer.sign(FhirResourceEvent.build(visionPrescriptionBundle))
}
Assert.assertTrue(countDownLatch.await(1, TimeUnit.SECONDS))
assertNotNull(eyeglassesPrescriptionEvent)
val bech32 = NEmbed.create(eyeglassesPrescriptionEvent)
@@ -21,7 +21,6 @@
package com.vitorpamplona.quartz.nip44Encryption
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.platform.app.InstrumentationRegistry.getInstrumentation
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import com.vitorpamplona.quartz.nip01Core.core.hexToByteArray
import com.vitorpamplona.quartz.nip01Core.core.toHexKey
@@ -41,7 +40,7 @@ class Nip44v2Test {
private val vectors: VectorFile =
jacksonObjectMapper()
.readValue(
getInstrumentation().context.assets.open("nip44.vectors.json"),
javaClass.classLoader?.getResourceAsStream("nip44.vectors.json"),
VectorFile::class.java,
)
@@ -237,7 +237,7 @@ class GiftWrapEventTest {
fail("Should not be able to decrypt msg for the receiver decrypted by the sender")
}
giftWrapToReceiver.unwrapOrNull(receiver)?.let { _ ->
giftWrapToSender.unwrapOrNull(receiver)?.let { _ ->
fail("Should not be able to decrypt msg for the sender decrypted by the receiver")
}
@@ -78,14 +78,13 @@ class SealedRumorEvent(
return event
}
suspend fun unsealOrNull(signer: NostrSigner): Event? {
return try {
return unsealThrowing(signer)
suspend fun unsealOrNull(signer: NostrSigner): Event? =
try {
unsealThrowing(signer)
} catch (e: Exception) {
Log.w("RumorEvent", "Fail to decrypt or parse Rumor", e)
null
}
}
private suspend fun plainContent(signer: NostrSigner): String {
if (content.isEmpty()) return ""
@@ -80,14 +80,13 @@ class GiftWrapEvent(
return gift
}
suspend fun unwrapOrNull(signer: NostrSigner): Event? {
suspend fun unwrapOrNull(signer: NostrSigner): Event? =
try {
return unwrapThrowing(signer)
unwrapThrowing(signer)
} catch (_: Exception) {
Log.w("GiftWrapEvent", "Couldn't Decrypt the content " + this.toNostrUri())
return null
null
}
}
private suspend fun plainContent(signer: NostrSigner): String {
if (content.isEmpty()) return ""