mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-09-19 19:31:43 +02:00
Moves test assets to resources to make it work with kmp
This commit is contained in:
@@ -24,7 +24,7 @@ android {
|
||||
targetCompatibility JavaVersion.VERSION_21
|
||||
}
|
||||
|
||||
sourceSets.androidTest.assets.srcDirs += ["../quartz/src/androidTest/assets"]
|
||||
sourceSets.androidTest.resources.srcDirs += ["../quartz/src/androidDeviceTest/resources"]
|
||||
|
||||
testBuildType = "benchmark"
|
||||
buildTypes {
|
||||
|
@@ -23,7 +23,6 @@ package com.vitorpamplona.amethyst.benchmark
|
||||
import androidx.benchmark.junit4.BenchmarkRule
|
||||
import androidx.benchmark.junit4.measureRepeated
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
import androidx.test.platform.app.InstrumentationRegistry.getInstrumentation
|
||||
import com.vitorpamplona.amethyst.commons.preview.MetaTagsParser
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertNotNull
|
||||
@@ -35,9 +34,8 @@ import java.nio.charset.Charset
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
class MetaTagsParserBenchmark {
|
||||
private val html =
|
||||
getInstrumentation()
|
||||
.context.assets
|
||||
.open("github_amethyst.html")
|
||||
javaClass.classLoader!!
|
||||
.getResourceAsStream("github_amethyst.html")
|
||||
.readBytes()
|
||||
.toString(Charset.forName("utf-8"))
|
||||
|
||||
|
@@ -20,7 +20,6 @@
|
||||
*/
|
||||
package com.vitorpamplona.quartz.benchmark
|
||||
|
||||
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.core.HexKey
|
||||
@@ -34,7 +33,7 @@ open class BaseLargeCacheBenchmark {
|
||||
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),
|
||||
|
@@ -23,7 +23,6 @@ package com.vitorpamplona.quartz.benchmark
|
||||
import androidx.benchmark.junit4.BenchmarkRule
|
||||
import androidx.benchmark.junit4.measureRepeated
|
||||
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.core.HexKey
|
||||
@@ -42,7 +41,7 @@ import java.util.zip.GZIPInputStream
|
||||
open class BaseCacheBenchmark {
|
||||
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),
|
||||
|
@@ -23,7 +23,6 @@ package com.vitorpamplona.quartz.benchmark
|
||||
import androidx.benchmark.junit4.BenchmarkRule
|
||||
import androidx.benchmark.junit4.measureRepeated
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
import androidx.test.platform.app.InstrumentationRegistry.getInstrumentation
|
||||
import com.vitorpamplona.quartz.nip01Core.core.HexKey
|
||||
import com.vitorpamplona.quartz.nip01Core.core.toHexKey
|
||||
import com.vitorpamplona.quartz.nip01Core.hints.HintIndexer
|
||||
@@ -47,9 +46,8 @@ class HintIndexerBenchmark {
|
||||
}
|
||||
|
||||
val relays =
|
||||
getInstrumentation()
|
||||
.context.assets
|
||||
.open("relayDB.txt")
|
||||
javaClass.classLoader
|
||||
?.getResourceAsStream("relayDB.txt")!!
|
||||
.readBytes()
|
||||
.toString(Charset.forName("utf-8"))
|
||||
.split("\n")
|
||||
|
4
commons/proguard-rules.pro
vendored
4
commons/proguard-rules.pro
vendored
@@ -20,4 +20,6 @@
|
||||
# hide the original source file name.
|
||||
#-renamesourcefileattribute SourceFile
|
||||
|
||||
-keep class com.vitorpamplona.amethyst.commons.** { *; }
|
||||
-keep class com.vitorpamplona.quartz.** { *; }
|
||||
-keep class com.vitorpamplona.amethyst.** { *; }
|
||||
-keep class com.vitorpamplona.ammolite.** { *; }
|
3
quartz/proguard-rules.pro
vendored
3
quartz/proguard-rules.pro
vendored
@@ -58,4 +58,5 @@
|
||||
}
|
||||
|
||||
# JSON parsing
|
||||
-keep class com.vitorpamplona.quartz.** { *; }
|
||||
-keep class com.vitorpamplona.quartz.** { *; }
|
||||
|
||||
|
@@ -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 ""
|
||||
|
Reference in New Issue
Block a user