diff --git a/composeApp/src/commonTest/kotlin/mobi/giza/compose/text/ProposedEventTest.kt b/composeApp/src/commonTest/kotlin/mobi/giza/compose/text/ProposedEventTest.kt index 03bf3ef3..3ae38941 100644 --- a/composeApp/src/commonTest/kotlin/mobi/giza/compose/text/ProposedEventTest.kt +++ b/composeApp/src/commonTest/kotlin/mobi/giza/compose/text/ProposedEventTest.kt @@ -111,6 +111,17 @@ class ProposedEventTest { ) } + /** + * docs/group-inbox.md, Phase 1: the events a group's inbox is made of are, today, kinds + * the app has no words for. Phases 5 and 8 give them words. + */ + @Test + fun `an inbox key, a DM relay list and a seal are said by their numbers today`() { + listOf(10044, 10050, 13).forEach { kind -> + assertEquals("Event of kind $kind", ProposedEvent.summarize(event(kind)).label) + } + } + private fun event( kind: Int, tags: Array> = emptyArray(), diff --git a/composeApp/src/jvmTest/kotlin/mobi/giza/compose/managers/GroupInboxTodayJvmTest.kt b/composeApp/src/jvmTest/kotlin/mobi/giza/compose/managers/GroupInboxTodayJvmTest.kt new file mode 100644 index 00000000..f103565e --- /dev/null +++ b/composeApp/src/jvmTest/kotlin/mobi/giza/compose/managers/GroupInboxTodayJvmTest.kt @@ -0,0 +1,74 @@ +package mobi.giza.compose.managers + +import com.vitorpamplona.quartz.nip01Core.core.Event +import com.vitorpamplona.quartz.nip01Core.signers.EventTemplate +import kotlin.test.AfterTest +import kotlin.test.Test +import kotlin.test.assertEquals +import kotlin.test.assertNotNull +import kotlin.test.assertNull +import kotlin.test.assertTrue +import kotlinx.coroutines.runBlocking +import mobi.giza.compose.nostr.frost.FrostSigningEvents +import mobi.giza.compose.text.ProposedEvent + +/** + * What Giza does today with the events a group's inbox is made of (docs/group-inbox.md, + * Phase 1). Written to pass now and flipped on purpose by the phase that changes each: + * + * - a peer's proposal to sign a kind 10044 (an encryption key) or a kind 13 (a NIP-17 seal) + * reaches the member as a bare number, and nothing declines it. Phase 5 and Phase 8 put a + * refusal in front of each; + * - the only gift wraps the app asks relays for are its own identity's. Phase 6 adds the + * group's. + */ +class GroupInboxTodayJvmTest { + private val harness = SigningProposalHarness() + private val alice = harness.members[0] + private val bob = harness.members[1] + + @AfterTest + fun close() = harness.close() + + private fun proposeAndDeliver(kind: Int, tags: Array>, content: String) = runBlocking { + val sent = harness.propose(alice) { db, room -> + FrostSigningManager.proposeSigningBatch( + db, room, alice, + events = listOf(EventTemplate(1_700_000_000L, kind, tags, content)), + ) + } + harness.deliver(sent, bob) + sent + } + + private fun assertPutToTheMemberByNumber(sent: SigningProposalHarness.Sent, kind: Int) = runBlocking { + val session = assertNotNull(harness.db.frostSigningSessionDao().getSessionById(sent.session.id)) + assertNull(session.signDeclinedAt, "nothing declines it today") + assertTrue(FrostSigningManager.isAwaitingApproval(session, harness.db.frostSigningSessionDao().getItems(session.id))) + assertEquals(emptyList(), harness.queued(FrostSigningEvents.DECLINE)) + + val item = harness.db.frostSigningSessionDao().getItems(session.id).single() + assertEquals("Event of kind $kind", ProposedEvent.summarize(Event.fromJson(item.unsignedEventJson)).label) + } + + @Test + fun `a peer's inbox key reaches the member as a number, and can be signed`() { + val sent = proposeAndDeliver(10044, arrayOf(arrayOf("n", "e".repeat(64))), "") + assertPutToTheMemberByNumber(sent, 10044) + } + + @Test + fun `a peer's sealed ciphertext reaches the member as a number, and can be signed`() { + // The member is asked to sign bytes it cannot read: the rubber stamp + // docs/giza-wallet-removal.md says a Giza device must not be. Phase 8 declines it. + val sent = proposeAndDeliver(13, arrayOf(arrayOf("n", "e".repeat(64))), "AnOpaqueCiphertext") + assertPutToTheMemberByNumber(sent, 13) + } + + @Test + fun `the only gift wraps asked for are the identity's own`() { + val filter = LiveSubscriptionManager.giftWrapFilter(alice) + assertEquals(listOf(1059), filter.kinds) + assertEquals(mapOf("p" to listOf(alice)), filter.tags) + } +}