Fixing benchmark tests after the refactoring.

This commit is contained in:
Vitor Pamplona
2023-11-26 21:10:15 -05:00
parent 34c2ba4922
commit ae3cc5da2a
5 changed files with 287 additions and 221 deletions
+5
View File
@@ -8,6 +8,11 @@ android {
namespace 'com.vitorpamplona.amethyst.benchmark' namespace 'com.vitorpamplona.amethyst.benchmark'
compileSdk 34 compileSdk 34
defaultConfig {
// Enable measuring on an emulator, or devices with low battery
testInstrumentationRunnerArguments["androidx.benchmark.suppressErrors"] = "EMULATOR,LOW-BATTERY"
}
compileOptions { compileOptions {
sourceCompatibility JavaVersion.VERSION_17 sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17 targetCompatibility JavaVersion.VERSION_17
@@ -10,10 +10,17 @@ import com.vitorpamplona.quartz.events.Event
import com.vitorpamplona.quartz.events.GiftWrapEvent import com.vitorpamplona.quartz.events.GiftWrapEvent
import com.vitorpamplona.quartz.events.NIP24Factory import com.vitorpamplona.quartz.events.NIP24Factory
import com.vitorpamplona.quartz.events.SealedGossipEvent import com.vitorpamplona.quartz.events.SealedGossipEvent
import com.vitorpamplona.quartz.signers.NostrSignerInternal
import junit.framework.TestCase
import org.junit.Assert import org.junit.Assert
import org.junit.Assert.assertTrue
import org.junit.Rule import org.junit.Rule
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
import kotlin.coroutines.resume
import kotlin.coroutines.suspendCoroutine
/** /**
* Benchmark, which will execute on an Android device. * Benchmark, which will execute on an Android device.
@@ -28,64 +35,94 @@ class GiftWrapBenchmark {
val benchmarkRule = BenchmarkRule() val benchmarkRule = BenchmarkRule()
fun basePerformanceTest(message: String, expectedLength: Int) { fun basePerformanceTest(message: String, expectedLength: Int) {
val sender = KeyPair() val sender = NostrSignerInternal(KeyPair())
val receiver = KeyPair() val receiver = NostrSignerInternal(KeyPair())
val events = NIP24Factory().createMsgNIP24( var events: NIP24Factory.Result? = null
val countDownLatch = CountDownLatch(1)
NIP24Factory().createMsgNIP24(
message, message,
listOf(receiver.pubKey.toHexKey()), listOf(receiver.pubKey),
sender sender
) ) {
events = it
countDownLatch.countDown()
}
Assert.assertEquals(expectedLength, events.map { it.toJson() }.joinToString("").length) assertTrue(countDownLatch.await(1, TimeUnit.SECONDS))
val countDownLatch2 = CountDownLatch(1)
Assert.assertEquals(expectedLength, events!!.wraps.map { it.toJson() }.joinToString("").length)
// Simulate Receiver // Simulate Receiver
events.forEach { events!!.wraps.forEach {
it.checkSignature() it.checkSignature()
val keyToUse = if (it.recipientPubKey() == sender.pubKey.toHexKey()) sender.privKey!! else receiver.privKey!! val keyToUse = if (it.recipientPubKey() == sender.pubKey) sender else receiver
val event = it.unwrap(keyToUse)
event?.checkSignature() it.cachedGift(keyToUse) { event ->
event.checkSignature()
if (event is SealedGossipEvent) { if (event is SealedGossipEvent) {
val innerData = event.unseal(keyToUse) event.cachedGossip(keyToUse) { innerData ->
Assert.assertEquals(message, innerData?.content) Assert.assertEquals(message, innerData.content)
countDownLatch2.countDown()
}
} else { } else {
Assert.fail("Wrong Event") Assert.fail("Wrong Event")
} }
} }
} }
assertTrue(countDownLatch2.await(1, TimeUnit.SECONDS))
}
fun receivePerformanceTest(message: String) { fun receivePerformanceTest(message: String) {
val sender = KeyPair() val sender = NostrSignerInternal(KeyPair())
val receiver = KeyPair() val receiver = NostrSignerInternal(KeyPair())
val giftWrap = NIP24Factory().createMsgNIP24( var giftWrap: GiftWrapEvent? = null
val countDownLatch = CountDownLatch(1)
NIP24Factory().createMsgNIP24(
message, message,
listOf(receiver.pubKey.toHexKey()), listOf(receiver.pubKey),
sender sender
).first() ) {
giftWrap = it.wraps.first()
countDownLatch.countDown()
}
val keyToUse = if (giftWrap.recipientPubKey() == sender.pubKey.toHexKey()) sender.privKey!! else receiver.privKey!! assertTrue(countDownLatch.await(1, TimeUnit.SECONDS))
val giftWrapJson = giftWrap.toJson()
val keyToUse = if (giftWrap!!.recipientPubKey() == sender.pubKey) sender else receiver
val giftWrapJson = giftWrap!!.toJson()
// Simulate Receiver // Simulate Receiver
benchmarkRule.measureRepeated { benchmarkRule.measureRepeated {
CryptoUtils.clearCache() CryptoUtils.clearCache()
val counter = CountDownLatch(1)
val wrap = Event.fromJson(giftWrapJson) as GiftWrapEvent val wrap = Event.fromJson(giftWrapJson) as GiftWrapEvent
wrap.checkSignature() wrap.checkSignature()
val seal = wrap.unwrap(keyToUse) wrap.cachedGift(keyToUse) {seal ->
seal?.checkSignature() seal.checkSignature()
if (seal is SealedGossipEvent) { if (seal is SealedGossipEvent) {
val innerData = seal.unseal(keyToUse) seal.cachedGossip(keyToUse) { innerData ->
Assert.assertEquals(message, innerData?.content) Assert.assertEquals(message, innerData.content)
counter.countDown()
}
} else { } else {
Assert.fail("Wrong Event") Assert.fail("Wrong Event")
} }
} }
TestCase.assertTrue(counter.await(1, TimeUnit.SECONDS))
}
} }
@@ -12,12 +12,17 @@ import com.vitorpamplona.quartz.events.ChatMessageEvent
import com.vitorpamplona.quartz.events.Event import com.vitorpamplona.quartz.events.Event
import com.vitorpamplona.quartz.events.GiftWrapEvent import com.vitorpamplona.quartz.events.GiftWrapEvent
import com.vitorpamplona.quartz.events.Gossip import com.vitorpamplona.quartz.events.Gossip
import com.vitorpamplona.quartz.events.NIP24Factory
import com.vitorpamplona.quartz.events.SealedGossipEvent import com.vitorpamplona.quartz.events.SealedGossipEvent
import com.vitorpamplona.quartz.signers.NostrSigner
import com.vitorpamplona.quartz.signers.NostrSignerInternal import com.vitorpamplona.quartz.signers.NostrSignerInternal
import junit.framework.TestCase.assertNotNull import junit.framework.TestCase.assertNotNull
import junit.framework.TestCase.assertTrue
import org.junit.Rule import org.junit.Rule
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
/** /**
* Benchmark, which will execute on an Android device. * Benchmark, which will execute on an Android device.
@@ -31,12 +36,13 @@ class GiftWrapReceivingBenchmark {
@get:Rule @get:Rule
val benchmarkRule = BenchmarkRule() val benchmarkRule = BenchmarkRule()
fun createMessage(sender: KeyPair, receiver: KeyPair): ChatMessageEvent { fun createWrap(sender: NostrSigner, receiver: NostrSigner): GiftWrapEvent {
val to = listOf(receiver.pubKey.toHexKey()) val countDownLatch = CountDownLatch(1)
var wrap: GiftWrapEvent? = null
return ChatMessageEvent.create( ChatMessageEvent.create(
msg = "Hi there! This is a test message", msg = "Hi there! This is a test message",
to = to, to = listOf(receiver.pubKey),
subject = "Party Tonight", subject = "Party Tonight",
replyTos = emptyList(), replyTos = emptyList(),
mentions = emptyList(), mentions = emptyList(),
@@ -44,31 +50,65 @@ class GiftWrapReceivingBenchmark {
markAsSensitive = true, markAsSensitive = true,
zapRaiserAmount = 10000, zapRaiserAmount = 10000,
geohash = null, geohash = null,
signer = NostrSignerInternal(keyPair = sender) signer = sender
) ) {
SealedGossipEvent.create(
event = it,
encryptTo = receiver.pubKey,
signer = sender
) {
GiftWrapEvent.create(
event = it,
recipientPubKey = receiver.pubKey
) {
wrap = it
countDownLatch.countDown()
}
}
}
assertTrue(countDownLatch.await(1, TimeUnit.SECONDS))
return wrap!!
}
fun createSeal(sender: NostrSigner, receiver: NostrSigner): SealedGossipEvent {
val countDownLatch = CountDownLatch(1)
var seal: SealedGossipEvent? = null
ChatMessageEvent.create(
msg = "Hi there! This is a test message",
to = listOf(receiver.pubKey),
subject = "Party Tonight",
replyTos = emptyList(),
mentions = emptyList(),
zapReceiver = null,
markAsSensitive = true,
zapRaiserAmount = 10000,
geohash = null,
signer = sender
) {
SealedGossipEvent.create(
event = it,
encryptTo = receiver.pubKey,
signer = sender
) {
seal = it
countDownLatch.countDown()
}
}
assertTrue(countDownLatch.await(1, TimeUnit.SECONDS))
return seal!!
} }
@Test @Test
fun parseWrapFromString() { fun parseWrapFromString() {
val sender = KeyPair() val sender = NostrSignerInternal(KeyPair())
val receiver = KeyPair() val receiver = NostrSignerInternal(KeyPair())
val senderPublicKey = CryptoUtils.pubkeyCreate(sender.privKey!!).toHexKey() val str = createWrap(sender, receiver).toJson()
val senderMessage = createMessage(sender, receiver)
val seal = SealedGossipEvent.create(
event = senderMessage,
encryptTo = senderPublicKey,
privateKey = sender.privKey!!
)
val wrap = GiftWrapEvent.create(
event = seal,
recipientPubKey = senderPublicKey
)
val str = wrap.toJson()
benchmarkRule.measureRepeated { benchmarkRule.measureRepeated {
Event.fromJson(str) Event.fromJson(str)
@@ -77,20 +117,10 @@ class GiftWrapReceivingBenchmark {
@Test @Test
fun checkId() { fun checkId() {
val sender = KeyPair() val sender = NostrSignerInternal(KeyPair())
val receiver = KeyPair() val receiver = NostrSignerInternal(KeyPair())
val senderPublicKey = CryptoUtils.pubkeyCreate(sender.privKey!!).toHexKey() val wrap = createWrap(sender, receiver)
val senderMessage = createMessage(sender, receiver)
val wrap = GiftWrapEvent.create(
event = SealedGossipEvent.create(
event = senderMessage,
encryptTo = senderPublicKey,
privateKey = sender.privKey!!
),
recipientPubKey = senderPublicKey
)
benchmarkRule.measureRepeated { benchmarkRule.measureRepeated {
wrap.hasCorrectIDHash() wrap.hasCorrectIDHash()
@@ -99,20 +129,10 @@ class GiftWrapReceivingBenchmark {
@Test @Test
fun checkSignature() { fun checkSignature() {
val sender = KeyPair() val sender = NostrSignerInternal(KeyPair())
val receiver = KeyPair() val receiver = NostrSignerInternal(KeyPair())
val senderPublicKey = CryptoUtils.pubkeyCreate(sender.privKey!!).toHexKey() val wrap = createWrap(sender, receiver)
val senderMessage = createMessage(sender, receiver)
val wrap = GiftWrapEvent.create(
event = SealedGossipEvent.create(
event = senderMessage,
encryptTo = senderPublicKey,
privateKey = sender.privKey!!
),
recipientPubKey = senderPublicKey
)
benchmarkRule.measureRepeated { benchmarkRule.measureRepeated {
wrap.hasVerifiedSignature() wrap.hasVerifiedSignature()
@@ -121,78 +141,39 @@ class GiftWrapReceivingBenchmark {
@Test @Test
fun decodeWrapEvent() { fun decodeWrapEvent() {
val sender = KeyPair() val sender = NostrSignerInternal(KeyPair())
val receiver = KeyPair() val receiver = NostrSignerInternal(KeyPair())
val senderPublicKey = CryptoUtils.pubkeyCreate(sender.privKey!!).toHexKey() val wrap = createWrap(sender, receiver)
val senderMessage = createMessage(sender, receiver)
val seal = SealedGossipEvent.create(
event = senderMessage,
encryptTo = senderPublicKey,
privateKey = sender.privKey!!
)
val wrappedEvent = GiftWrapEvent.create(
event = seal,
recipientPubKey = senderPublicKey
)
benchmarkRule.measureRepeated { benchmarkRule.measureRepeated {
assertNotNull(decodeNIP44(wrappedEvent.content)) assertNotNull(decodeNIP44(wrap.content))
} }
} }
@Test @Test
fun decryptWrapEvent() { fun decryptWrapEvent() {
val sender = KeyPair() val sender = NostrSignerInternal(KeyPair())
val receiver = KeyPair() val receiver = NostrSignerInternal(KeyPair())
val senderPublicKey = CryptoUtils.pubkeyCreate(sender.privKey!!).toHexKey() val wrap = createWrap(sender, receiver)
val senderMessage = createMessage(sender, receiver) val toDecrypt = decodeNIP44(wrap.content) ?: return
val seal = SealedGossipEvent.create(
event = senderMessage,
encryptTo = senderPublicKey,
privateKey = sender.privKey!!
)
val wrappedEvent = GiftWrapEvent.create(
event = seal,
recipientPubKey = senderPublicKey
)
val toDecrypt = decodeNIP44(wrappedEvent.content) ?: return
benchmarkRule.measureRepeated { benchmarkRule.measureRepeated {
assertNotNull(CryptoUtils.decryptNIP44(toDecrypt, sender.privKey!!, wrappedEvent.pubKey.hexToByteArray())) assertNotNull(CryptoUtils.decryptNIP44(toDecrypt, sender.keyPair.privKey!!, wrap.pubKey.hexToByteArray()))
} }
} }
@Test @Test
fun parseWrappedEvent() { fun parseWrappedEvent() {
val sender = KeyPair() val sender = NostrSignerInternal(KeyPair())
val receiver = KeyPair() val receiver = NostrSignerInternal(KeyPair())
val senderPublicKey = CryptoUtils.pubkeyCreate(sender.privKey!!).toHexKey() val wrap = createWrap(sender, receiver)
val senderMessage = createMessage(sender, receiver) val toDecrypt = decodeNIP44(wrap.content) ?: return
val innerJson = CryptoUtils.decryptNIP44(toDecrypt, receiver.keyPair.privKey!!, wrap.pubKey.hexToByteArray())
val seal = SealedGossipEvent.create(
event = senderMessage,
encryptTo = senderPublicKey,
privateKey = sender.privKey!!
)
val wrappedEvent = GiftWrapEvent.create(
event = seal,
recipientPubKey = senderPublicKey
)
val toDecrypt = decodeNIP44(wrappedEvent.content) ?: return
val innerJson = CryptoUtils.decryptNIP44(toDecrypt, sender.privKey!!, wrappedEvent.pubKey.hexToByteArray())
benchmarkRule.measureRepeated { benchmarkRule.measureRepeated {
assertNotNull(innerJson?.let { Event.fromJson(it) }) assertNotNull(innerJson?.let { Event.fromJson(it) })
@@ -201,18 +182,10 @@ class GiftWrapReceivingBenchmark {
@Test @Test
fun decodeSealEvent() { fun decodeSealEvent() {
val sender = KeyPair() val sender = NostrSignerInternal(KeyPair())
val receiver = KeyPair() val receiver = NostrSignerInternal(KeyPair())
val senderPublicKey = CryptoUtils.pubkeyCreate(sender.privKey!!).toHexKey() val seal = createSeal(sender, receiver)
val senderMessage = createMessage(sender, receiver)
val seal = SealedGossipEvent.create(
event = senderMessage,
encryptTo = senderPublicKey,
privateKey = sender.privKey!!
)
benchmarkRule.measureRepeated { benchmarkRule.measureRepeated {
assertNotNull(decodeNIP44(seal.content)) assertNotNull(decodeNIP44(seal.content))
@@ -221,43 +194,27 @@ class GiftWrapReceivingBenchmark {
@Test @Test
fun decryptSealedEvent() { fun decryptSealedEvent() {
val sender = KeyPair() val sender = NostrSignerInternal(KeyPair())
val receiver = KeyPair() val receiver = NostrSignerInternal(KeyPair())
val senderPublicKey = CryptoUtils.pubkeyCreate(sender.privKey!!).toHexKey() val seal = createSeal(sender, receiver)
val senderMessage = createMessage(sender, receiver)
val seal = SealedGossipEvent.create(
event = senderMessage,
encryptTo = senderPublicKey,
privateKey = sender.privKey!!
)
val toDecrypt = decodeNIP44(seal.content) ?: return val toDecrypt = decodeNIP44(seal.content) ?: return
benchmarkRule.measureRepeated { benchmarkRule.measureRepeated {
assertNotNull(CryptoUtils.decryptNIP44(toDecrypt, sender.privKey!!, seal.pubKey.hexToByteArray())) assertNotNull(CryptoUtils.decryptNIP44(toDecrypt, sender.keyPair.privKey!!, seal.pubKey.hexToByteArray()))
} }
} }
@Test @Test
fun parseSealedEvent() { fun parseSealedEvent() {
val sender = KeyPair() val sender = NostrSignerInternal(KeyPair())
val receiver = KeyPair() val receiver = NostrSignerInternal(KeyPair())
val senderPublicKey = CryptoUtils.pubkeyCreate(sender.privKey!!).toHexKey() val seal = createSeal(sender, receiver)
val senderMessage = createMessage(sender, receiver)
val seal = SealedGossipEvent.create(
event = senderMessage,
encryptTo = senderPublicKey,
privateKey = sender.privKey!!
)
val toDecrypt = decodeNIP44(seal.content) ?: return val toDecrypt = decodeNIP44(seal.content) ?: return
val innerJson = CryptoUtils.decryptNIP44(toDecrypt, sender.privKey!!, seal.pubKey.hexToByteArray()) val innerJson = CryptoUtils.decryptNIP44(toDecrypt, receiver.keyPair.privKey!!, seal.pubKey.hexToByteArray())
benchmarkRule.measureRepeated { benchmarkRule.measureRepeated {
assertNotNull(innerJson?.let { Gossip.fromJson(it) }) assertNotNull(innerJson?.let { Gossip.fromJson(it) })
@@ -11,11 +11,14 @@ import com.vitorpamplona.quartz.events.Event
import com.vitorpamplona.quartz.events.GiftWrapEvent import com.vitorpamplona.quartz.events.GiftWrapEvent
import com.vitorpamplona.quartz.events.Gossip import com.vitorpamplona.quartz.events.Gossip
import com.vitorpamplona.quartz.events.SealedGossipEvent import com.vitorpamplona.quartz.events.SealedGossipEvent
import com.vitorpamplona.quartz.signers.NostrSignerInternal
import junit.framework.TestCase.assertNotNull import junit.framework.TestCase.assertNotNull
import junit.framework.TestCase.assertTrue import junit.framework.TestCase.assertTrue
import org.junit.Rule import org.junit.Rule
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
/** /**
* Benchmark, which will execute on an Android device. * Benchmark, which will execute on an Android device.
@@ -29,12 +32,17 @@ class GiftWrapSigningBenchmark {
@get:Rule @get:Rule
val benchmarkRule = BenchmarkRule() val benchmarkRule = BenchmarkRule()
fun createMessage(sender: KeyPair, receiver: KeyPair): ChatMessageEvent { @Test
val to = listOf(receiver.pubKey.toHexKey()) fun createMessageEvent() {
val sender = NostrSignerInternal(KeyPair())
val receiver = NostrSignerInternal(KeyPair())
return ChatMessageEvent.create( benchmarkRule.measureRepeated {
val countDownLatch = CountDownLatch(1)
ChatMessageEvent.create(
msg = "Hi there! This is a test message", msg = "Hi there! This is a test message",
to = to, to = listOf(receiver.pubKey),
subject = "Party Tonight", subject = "Party Tonight",
replyTos = emptyList(), replyTos = emptyList(),
mentions = emptyList(), mentions = emptyList(),
@@ -42,82 +50,141 @@ class GiftWrapSigningBenchmark {
markAsSensitive = true, markAsSensitive = true,
zapRaiserAmount = 10000, zapRaiserAmount = 10000,
geohash = null, geohash = null,
keyPair = sender signer = sender
) ) {
countDownLatch.countDown()
} }
@Test assertTrue(countDownLatch.await(1, TimeUnit.SECONDS))
fun createMessageEvent() {
val sender = KeyPair()
val receiver = KeyPair()
benchmarkRule.measureRepeated {
createMessage(sender, receiver)
} }
} }
@Test @Test
fun sealMessage() { fun sealMessage() {
val sender = KeyPair() val sender = NostrSignerInternal(KeyPair())
val receiver = KeyPair() val receiver = NostrSignerInternal(KeyPair())
val senderMessage = createMessage(sender, receiver) val countDownLatch = CountDownLatch(1)
var msg: ChatMessageEvent? = null
ChatMessageEvent.create(
msg = "Hi there! This is a test message",
to = listOf(receiver.pubKey),
subject = "Party Tonight",
replyTos = emptyList(),
mentions = emptyList(),
zapReceiver = null,
markAsSensitive = true,
zapRaiserAmount = 10000,
geohash = null,
signer = sender
) {
msg = it
countDownLatch.countDown()
}
assertTrue(countDownLatch.await(1, TimeUnit.SECONDS))
benchmarkRule.measureRepeated { benchmarkRule.measureRepeated {
val senderPublicKey = CryptoUtils.pubkeyCreate(sender.privKey!!).toHexKey() val countDownLatch2 = CountDownLatch(1)
SealedGossipEvent.create( SealedGossipEvent.create(
event = senderMessage, event = msg!!,
encryptTo = senderPublicKey, encryptTo = receiver.pubKey,
privateKey = sender.privKey!! signer = sender
) ) {
countDownLatch2.countDown()
}
assertTrue(countDownLatch2.await(1, TimeUnit.SECONDS))
} }
} }
@Test @Test
fun wrapSeal() { fun wrapSeal() {
val sender = KeyPair() val sender = NostrSignerInternal(KeyPair())
val receiver = KeyPair() val receiver = NostrSignerInternal(KeyPair())
val senderPublicKey = CryptoUtils.pubkeyCreate(sender.privKey!!).toHexKey() val countDownLatch = CountDownLatch(1)
val senderMessage = createMessage(sender, receiver) var seal: SealedGossipEvent? = null
val seal = SealedGossipEvent.create( ChatMessageEvent.create(
event = senderMessage, msg = "Hi there! This is a test message",
encryptTo = senderPublicKey, to = listOf(receiver.pubKey),
privateKey = sender.privKey!! subject = "Party Tonight",
) replyTos = emptyList(),
mentions = emptyList(),
zapReceiver = null,
markAsSensitive = true,
zapRaiserAmount = 10000,
geohash = null,
signer = sender
) {
SealedGossipEvent.create(
event = it,
encryptTo = receiver.pubKey,
signer = sender
) {
seal = it
countDownLatch.countDown()
}
}
assertTrue(countDownLatch.await(1, TimeUnit.SECONDS))
benchmarkRule.measureRepeated { benchmarkRule.measureRepeated {
val countDownLatch2 = CountDownLatch(1)
GiftWrapEvent.create( GiftWrapEvent.create(
event = seal, event = seal!!,
recipientPubKey = senderPublicKey recipientPubKey = receiver.pubKey
) ) {
countDownLatch2.countDown()
}
assertTrue(countDownLatch2.await(1, TimeUnit.SECONDS))
} }
} }
@Test @Test
fun wrapToString() { fun wrapToString() {
val sender = KeyPair() val sender = NostrSignerInternal(KeyPair())
val receiver = KeyPair() val receiver = NostrSignerInternal(KeyPair())
val senderPublicKey = CryptoUtils.pubkeyCreate(sender.privKey!!).toHexKey() val countDownLatch = CountDownLatch(1)
val senderMessage = createMessage(sender, receiver) var wrap: GiftWrapEvent? = null
val seal = SealedGossipEvent.create( ChatMessageEvent.create(
event = senderMessage, msg = "Hi there! This is a test message",
encryptTo = senderPublicKey, to = listOf(receiver.pubKey),
privateKey = sender.privKey!! subject = "Party Tonight",
) replyTos = emptyList(),
mentions = emptyList(),
zapReceiver = null,
markAsSensitive = true,
zapRaiserAmount = 10000,
geohash = null,
signer = sender
) {
SealedGossipEvent.create(
event = it,
encryptTo = receiver.pubKey,
signer = sender
) {
GiftWrapEvent.create(
event = it,
recipientPubKey = receiver.pubKey
) {
wrap = it
countDownLatch.countDown()
}
}
}
val wrap = GiftWrapEvent.create( assertTrue(countDownLatch.await(1, TimeUnit.SECONDS))
event = seal,
recipientPubKey = senderPublicKey
)
benchmarkRule.measureRepeated { benchmarkRule.measureRepeated {
wrap.toJson() wrap!!.toJson()
} }
} }
} }
@@ -270,7 +270,7 @@ class GiftWrapEventTest {
} }
} }
countDownDecryptLatch.await(1, TimeUnit.SECONDS) assertTrue(countDownDecryptLatch.await(1, TimeUnit.SECONDS))
} }
@Test() @Test()