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
|
targetCompatibility JavaVersion.VERSION_21
|
||||||
}
|
}
|
||||||
|
|
||||||
sourceSets.androidTest.assets.srcDirs += ["../quartz/src/androidTest/assets"]
|
sourceSets.androidTest.resources.srcDirs += ["../quartz/src/androidDeviceTest/resources"]
|
||||||
|
|
||||||
testBuildType = "benchmark"
|
testBuildType = "benchmark"
|
||||||
buildTypes {
|
buildTypes {
|
||||||
|
|||||||
+2
-4
@@ -23,7 +23,6 @@ package com.vitorpamplona.amethyst.benchmark
|
|||||||
import androidx.benchmark.junit4.BenchmarkRule
|
import androidx.benchmark.junit4.BenchmarkRule
|
||||||
import androidx.benchmark.junit4.measureRepeated
|
import androidx.benchmark.junit4.measureRepeated
|
||||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||||
import androidx.test.platform.app.InstrumentationRegistry.getInstrumentation
|
|
||||||
import com.vitorpamplona.amethyst.commons.preview.MetaTagsParser
|
import com.vitorpamplona.amethyst.commons.preview.MetaTagsParser
|
||||||
import org.junit.Assert.assertEquals
|
import org.junit.Assert.assertEquals
|
||||||
import org.junit.Assert.assertNotNull
|
import org.junit.Assert.assertNotNull
|
||||||
@@ -35,9 +34,8 @@ import java.nio.charset.Charset
|
|||||||
@RunWith(AndroidJUnit4::class)
|
@RunWith(AndroidJUnit4::class)
|
||||||
class MetaTagsParserBenchmark {
|
class MetaTagsParserBenchmark {
|
||||||
private val html =
|
private val html =
|
||||||
getInstrumentation()
|
javaClass.classLoader!!
|
||||||
.context.assets
|
.getResourceAsStream("github_amethyst.html")
|
||||||
.open("github_amethyst.html")
|
|
||||||
.readBytes()
|
.readBytes()
|
||||||
.toString(Charset.forName("utf-8"))
|
.toString(Charset.forName("utf-8"))
|
||||||
|
|
||||||
|
|||||||
+1
-2
@@ -20,7 +20,6 @@
|
|||||||
*/
|
*/
|
||||||
package com.vitorpamplona.quartz.benchmark
|
package com.vitorpamplona.quartz.benchmark
|
||||||
|
|
||||||
import androidx.test.platform.app.InstrumentationRegistry.getInstrumentation
|
|
||||||
import com.fasterxml.jackson.module.kotlin.readValue
|
import com.fasterxml.jackson.module.kotlin.readValue
|
||||||
import com.vitorpamplona.quartz.nip01Core.core.Event
|
import com.vitorpamplona.quartz.nip01Core.core.Event
|
||||||
import com.vitorpamplona.quartz.nip01Core.core.HexKey
|
import com.vitorpamplona.quartz.nip01Core.core.HexKey
|
||||||
@@ -34,7 +33,7 @@ open class BaseLargeCacheBenchmark {
|
|||||||
companion object {
|
companion object {
|
||||||
fun getEventDB(): List<Event> {
|
fun getEventDB(): List<Event> {
|
||||||
// This file includes duplicates
|
// 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>>(
|
return JsonMapper.mapper.readValue<ArrayList<Event>>(
|
||||||
GZIPInputStream(fullDBInputStream),
|
GZIPInputStream(fullDBInputStream),
|
||||||
|
|||||||
@@ -23,7 +23,6 @@ package com.vitorpamplona.quartz.benchmark
|
|||||||
import androidx.benchmark.junit4.BenchmarkRule
|
import androidx.benchmark.junit4.BenchmarkRule
|
||||||
import androidx.benchmark.junit4.measureRepeated
|
import androidx.benchmark.junit4.measureRepeated
|
||||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||||
import androidx.test.platform.app.InstrumentationRegistry.getInstrumentation
|
|
||||||
import com.fasterxml.jackson.module.kotlin.readValue
|
import com.fasterxml.jackson.module.kotlin.readValue
|
||||||
import com.vitorpamplona.quartz.nip01Core.core.Event
|
import com.vitorpamplona.quartz.nip01Core.core.Event
|
||||||
import com.vitorpamplona.quartz.nip01Core.core.HexKey
|
import com.vitorpamplona.quartz.nip01Core.core.HexKey
|
||||||
@@ -42,7 +41,7 @@ import java.util.zip.GZIPInputStream
|
|||||||
open class BaseCacheBenchmark {
|
open class BaseCacheBenchmark {
|
||||||
fun getEventDB(): List<Event> {
|
fun getEventDB(): List<Event> {
|
||||||
// This file includes duplicates
|
// 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>>(
|
return JsonMapper.mapper.readValue<ArrayList<Event>>(
|
||||||
GZIPInputStream(fullDBInputStream),
|
GZIPInputStream(fullDBInputStream),
|
||||||
|
|||||||
+2
-4
@@ -23,7 +23,6 @@ package com.vitorpamplona.quartz.benchmark
|
|||||||
import androidx.benchmark.junit4.BenchmarkRule
|
import androidx.benchmark.junit4.BenchmarkRule
|
||||||
import androidx.benchmark.junit4.measureRepeated
|
import androidx.benchmark.junit4.measureRepeated
|
||||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
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.HexKey
|
||||||
import com.vitorpamplona.quartz.nip01Core.core.toHexKey
|
import com.vitorpamplona.quartz.nip01Core.core.toHexKey
|
||||||
import com.vitorpamplona.quartz.nip01Core.hints.HintIndexer
|
import com.vitorpamplona.quartz.nip01Core.hints.HintIndexer
|
||||||
@@ -47,9 +46,8 @@ class HintIndexerBenchmark {
|
|||||||
}
|
}
|
||||||
|
|
||||||
val relays =
|
val relays =
|
||||||
getInstrumentation()
|
javaClass.classLoader
|
||||||
.context.assets
|
?.getResourceAsStream("relayDB.txt")!!
|
||||||
.open("relayDB.txt")
|
|
||||||
.readBytes()
|
.readBytes()
|
||||||
.toString(Charset.forName("utf-8"))
|
.toString(Charset.forName("utf-8"))
|
||||||
.split("\n")
|
.split("\n")
|
||||||
|
|||||||
Vendored
+3
-1
@@ -20,4 +20,6 @@
|
|||||||
# hide the original source file name.
|
# hide the original source file name.
|
||||||
#-renamesourcefileattribute SourceFile
|
#-renamesourcefileattribute SourceFile
|
||||||
|
|
||||||
-keep class com.vitorpamplona.amethyst.commons.** { *; }
|
-keep class com.vitorpamplona.quartz.** { *; }
|
||||||
|
-keep class com.vitorpamplona.amethyst.** { *; }
|
||||||
|
-keep class com.vitorpamplona.ammolite.** { *; }
|
||||||
Vendored
+1
@@ -59,3 +59,4 @@
|
|||||||
|
|
||||||
# JSON parsing
|
# JSON parsing
|
||||||
-keep class com.vitorpamplona.quartz.** { *; }
|
-keep class com.vitorpamplona.quartz.** { *; }
|
||||||
|
|
||||||
|
|||||||
+2
-3
@@ -21,7 +21,6 @@
|
|||||||
package com.vitorpamplona.quartz
|
package com.vitorpamplona.quartz
|
||||||
|
|
||||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||||
import androidx.test.platform.app.InstrumentationRegistry.getInstrumentation
|
|
||||||
import com.fasterxml.jackson.module.kotlin.readValue
|
import com.fasterxml.jackson.module.kotlin.readValue
|
||||||
import com.vitorpamplona.quartz.nip01Core.core.Event
|
import com.vitorpamplona.quartz.nip01Core.core.Event
|
||||||
import com.vitorpamplona.quartz.nip01Core.jackson.JsonMapper
|
import com.vitorpamplona.quartz.nip01Core.jackson.JsonMapper
|
||||||
@@ -39,7 +38,7 @@ class LargeDBSignatureCheck {
|
|||||||
@Test
|
@Test
|
||||||
fun insertDatabaseSample() =
|
fun insertDatabaseSample() =
|
||||||
runBlocking {
|
runBlocking {
|
||||||
val fullDBInputStream = getInstrumentation().context.assets.open("nostr_vitor_short.json")
|
val fullDBInputStream = javaClass.classLoader?.getResourceAsStream("nostr_vitor_short.json")
|
||||||
|
|
||||||
val eventArray =
|
val eventArray =
|
||||||
JsonMapper.mapper.readValue<ArrayList<Event>>(
|
JsonMapper.mapper.readValue<ArrayList<Event>>(
|
||||||
@@ -59,7 +58,7 @@ class LargeDBSignatureCheck {
|
|||||||
fun insertStartupDatabase() =
|
fun insertStartupDatabase() =
|
||||||
runBlocking {
|
runBlocking {
|
||||||
// This file includes duplicates
|
// 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 =
|
val eventArray =
|
||||||
JsonMapper.mapper.readValue<ArrayList<Event>>(
|
JsonMapper.mapper.readValue<ArrayList<Event>>(
|
||||||
|
|||||||
+1
-2
@@ -25,7 +25,6 @@ import android.database.sqlite.SQLiteException
|
|||||||
import android.util.Log
|
import android.util.Log
|
||||||
import androidx.test.core.app.ApplicationProvider
|
import androidx.test.core.app.ApplicationProvider
|
||||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||||
import androidx.test.platform.app.InstrumentationRegistry.getInstrumentation
|
|
||||||
import com.fasterxml.jackson.module.kotlin.readValue
|
import com.fasterxml.jackson.module.kotlin.readValue
|
||||||
import com.vitorpamplona.quartz.nip01Core.core.Event
|
import com.vitorpamplona.quartz.nip01Core.core.Event
|
||||||
import com.vitorpamplona.quartz.nip01Core.jackson.JsonMapper
|
import com.vitorpamplona.quartz.nip01Core.jackson.JsonMapper
|
||||||
@@ -42,7 +41,7 @@ class LargeDBTests {
|
|||||||
companion object {
|
companion object {
|
||||||
fun getEventDB(): List<Event> {
|
fun getEventDB(): List<Event> {
|
||||||
// This file includes duplicates
|
// 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>>(
|
return JsonMapper.mapper.readValue<ArrayList<Event>>(
|
||||||
GZIPInputStream(fullDBInputStream),
|
GZIPInputStream(fullDBInputStream),
|
||||||
|
|||||||
+1
-7
@@ -21,7 +21,6 @@
|
|||||||
package com.vitorpamplona.quartz.nip06KeyDerivation
|
package com.vitorpamplona.quartz.nip06KeyDerivation
|
||||||
|
|
||||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||||
import androidx.test.platform.app.InstrumentationRegistry
|
|
||||||
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
|
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
|
||||||
import com.vitorpamplona.quartz.nip01Core.core.toHexKey
|
import com.vitorpamplona.quartz.nip01Core.core.toHexKey
|
||||||
import com.vitorpamplona.quartz.utils.Hex
|
import com.vitorpamplona.quartz.utils.Hex
|
||||||
@@ -36,12 +35,7 @@ import org.junit.runner.RunWith
|
|||||||
class Bip39MnemonicsTest {
|
class Bip39MnemonicsTest {
|
||||||
private val tests =
|
private val tests =
|
||||||
jacksonObjectMapper()
|
jacksonObjectMapper()
|
||||||
.readTree(
|
.readTree(javaClass.classLoader?.getResourceAsStream("bip39.vectors.json"))
|
||||||
InstrumentationRegistry
|
|
||||||
.getInstrumentation()
|
|
||||||
.context.assets
|
|
||||||
.open("bip39.vectors.json"),
|
|
||||||
)
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun toSeed() {
|
fun toSeed() {
|
||||||
|
|||||||
@@ -21,7 +21,6 @@
|
|||||||
package com.vitorpamplona.quartz.nip17Dm
|
package com.vitorpamplona.quartz.nip17Dm
|
||||||
|
|
||||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
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.nip01Core.core.hexToByteArray
|
||||||
import com.vitorpamplona.quartz.nip17Dm.files.encryption.AESGCM
|
import com.vitorpamplona.quartz.nip17Dm.files.encryption.AESGCM
|
||||||
import junit.framework.TestCase.assertEquals
|
import junit.framework.TestCase.assertEquals
|
||||||
@@ -46,9 +45,9 @@ class AESGCMTest {
|
|||||||
@Test
|
@Test
|
||||||
fun imageTest() {
|
fun imageTest() {
|
||||||
val image =
|
val image =
|
||||||
getInstrumentation().context.assets.open("ovxxk2vz.jpg").use {
|
javaClass.classLoader?.getResourceAsStream("ovxxk2vz.jpg")?.use {
|
||||||
it.readAllBytes()
|
it.readAllBytes()
|
||||||
}
|
}!!
|
||||||
|
|
||||||
val decrypted = cipher.decrypt(image)
|
val decrypted = cipher.decrypt(image)
|
||||||
|
|
||||||
@@ -64,9 +63,9 @@ class AESGCMTest {
|
|||||||
)
|
)
|
||||||
|
|
||||||
val encrypted =
|
val encrypted =
|
||||||
getInstrumentation().context.assets.open("trouble_video").use {
|
javaClass.classLoader?.getResourceAsStream("trouble_video")?.use {
|
||||||
it.readAllBytes()
|
it.readAllBytes()
|
||||||
}
|
}!!
|
||||||
|
|
||||||
val decrypted = myCipher.decrypt(encrypted)
|
val decrypted = myCipher.decrypt(encrypted)
|
||||||
|
|
||||||
|
|||||||
+2
-9
@@ -33,11 +33,8 @@ 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 kotlinx.coroutines.runBlocking
|
||||||
import org.junit.Assert
|
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
import org.junit.runner.RunWith
|
import org.junit.runner.RunWith
|
||||||
import java.util.concurrent.CountDownLatch
|
|
||||||
import java.util.concurrent.TimeUnit
|
|
||||||
|
|
||||||
@RunWith(AndroidJUnit4::class)
|
@RunWith(AndroidJUnit4::class)
|
||||||
class NIP19EmbedTests {
|
class NIP19EmbedTests {
|
||||||
@@ -57,7 +54,7 @@ class NIP19EmbedTests {
|
|||||||
|
|
||||||
assertNotNull(textNote)
|
assertNotNull(textNote)
|
||||||
|
|
||||||
val bech32 = NEmbed.create(textNote!!)
|
val bech32 = NEmbed.create(textNote)
|
||||||
|
|
||||||
println(bech32)
|
println(bech32)
|
||||||
|
|
||||||
@@ -65,7 +62,7 @@ class NIP19EmbedTests {
|
|||||||
|
|
||||||
assertTrue(decodedNote.verify())
|
assertTrue(decodedNote.verify())
|
||||||
|
|
||||||
assertEquals(textNote!!.toJson(), decodedNote.toJson())
|
assertEquals(textNote.toJson(), decodedNote.toJson())
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -101,15 +98,11 @@ class NIP19EmbedTests {
|
|||||||
KeyPair(Hex.decode("e8e7197ccc53c9ed4cf9b1c8dce085475fa1ffdd71f2c14e44fe23d0bdf77598")),
|
KeyPair(Hex.decode("e8e7197ccc53c9ed4cf9b1c8dce085475fa1ffdd71f2c14e44fe23d0bdf77598")),
|
||||||
)
|
)
|
||||||
|
|
||||||
val countDownLatch = CountDownLatch(1)
|
|
||||||
|
|
||||||
val eyeglassesPrescriptionEvent =
|
val eyeglassesPrescriptionEvent =
|
||||||
runBlocking {
|
runBlocking {
|
||||||
signer.sign(FhirResourceEvent.build(visionPrescriptionBundle))
|
signer.sign(FhirResourceEvent.build(visionPrescriptionBundle))
|
||||||
}
|
}
|
||||||
|
|
||||||
Assert.assertTrue(countDownLatch.await(1, TimeUnit.SECONDS))
|
|
||||||
|
|
||||||
assertNotNull(eyeglassesPrescriptionEvent)
|
assertNotNull(eyeglassesPrescriptionEvent)
|
||||||
|
|
||||||
val bech32 = NEmbed.create(eyeglassesPrescriptionEvent)
|
val bech32 = NEmbed.create(eyeglassesPrescriptionEvent)
|
||||||
|
|||||||
+1
-2
@@ -21,7 +21,6 @@
|
|||||||
package com.vitorpamplona.quartz.nip44Encryption
|
package com.vitorpamplona.quartz.nip44Encryption
|
||||||
|
|
||||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||||
import androidx.test.platform.app.InstrumentationRegistry.getInstrumentation
|
|
||||||
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
|
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
|
||||||
import com.vitorpamplona.quartz.nip01Core.core.hexToByteArray
|
import com.vitorpamplona.quartz.nip01Core.core.hexToByteArray
|
||||||
import com.vitorpamplona.quartz.nip01Core.core.toHexKey
|
import com.vitorpamplona.quartz.nip01Core.core.toHexKey
|
||||||
@@ -41,7 +40,7 @@ class Nip44v2Test {
|
|||||||
private val vectors: VectorFile =
|
private val vectors: VectorFile =
|
||||||
jacksonObjectMapper()
|
jacksonObjectMapper()
|
||||||
.readValue(
|
.readValue(
|
||||||
getInstrumentation().context.assets.open("nip44.vectors.json"),
|
javaClass.classLoader?.getResourceAsStream("nip44.vectors.json"),
|
||||||
VectorFile::class.java,
|
VectorFile::class.java,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -237,7 +237,7 @@ class GiftWrapEventTest {
|
|||||||
fail("Should not be able to decrypt msg for the receiver decrypted by the sender")
|
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")
|
fail("Should not be able to decrypt msg for the sender decrypted by the receiver")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+3
-4
@@ -78,14 +78,13 @@ class SealedRumorEvent(
|
|||||||
return event
|
return event
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun unsealOrNull(signer: NostrSigner): Event? {
|
suspend fun unsealOrNull(signer: NostrSigner): Event? =
|
||||||
return try {
|
try {
|
||||||
return unsealThrowing(signer)
|
unsealThrowing(signer)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Log.w("RumorEvent", "Fail to decrypt or parse Rumor", e)
|
Log.w("RumorEvent", "Fail to decrypt or parse Rumor", e)
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private suspend fun plainContent(signer: NostrSigner): String {
|
private suspend fun plainContent(signer: NostrSigner): String {
|
||||||
if (content.isEmpty()) return ""
|
if (content.isEmpty()) return ""
|
||||||
|
|||||||
+3
-4
@@ -80,14 +80,13 @@ class GiftWrapEvent(
|
|||||||
return gift
|
return gift
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun unwrapOrNull(signer: NostrSigner): Event? {
|
suspend fun unwrapOrNull(signer: NostrSigner): Event? =
|
||||||
try {
|
try {
|
||||||
return unwrapThrowing(signer)
|
unwrapThrowing(signer)
|
||||||
} catch (_: Exception) {
|
} catch (_: Exception) {
|
||||||
Log.w("GiftWrapEvent", "Couldn't Decrypt the content " + this.toNostrUri())
|
Log.w("GiftWrapEvent", "Couldn't Decrypt the content " + this.toNostrUri())
|
||||||
return null
|
null
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private suspend fun plainContent(signer: NostrSigner): String {
|
private suspend fun plainContent(signer: NostrSigner): String {
|
||||||
if (content.isEmpty()) return ""
|
if (content.isEmpty()) return ""
|
||||||
|
|||||||
Reference in New Issue
Block a user