test: the ceremony's room, its unsigned rumors and the bridge's one envelope, pinned (confederation-dkg-inboxes, Phase 1)

Five pins in ConfederationCeremonyJvmTest, each passing today and named for the phase that flips
it: a message leaves as a gift wrap p-tagged to every person, in the room of the people; a bare
unsigned ritual rumor is recorded; the bridge carries nothing for a proposal; it sends every due
event in one envelope whatever the bytes; and a ceremony row cannot exist without its room.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Kgothatso NgakoandClaude Opus 5.5 committed 2026-11-23 12:40:10 +02:00
1 parent 6a6ce0066c
commit c117995fc5
2 files changed
+91

No files matched your search

@@ -37,6 +37,8 @@ import kotlin.test.assertTrue
import kotlin.time.Clock
import kotlin.time.Instant
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.flow.first
import com.vitorpamplona.quartz.nip01Core.signers.NostrSignerSync
import mobi.giza.compose.ConfederationFixture
import mobi.giza.compose.database.GizaDatabase
import mobi.giza.compose.database.builder.getRoomDatabase
@@ -331,6 +333,93 @@ class ConfederationCeremonyJvmTest {
ceremonies().values.forEach { assertEquals(ConfederationCeremonyStage.COMPLETE, it?.stage, it?.failureReason) }
}
// ---- docs/confederation-dkg-inboxes.md, Phase 1: today, pinned to be flipped -----------------
/** Flipped by Phase 5: a message leaves as an envelope in each seat group's room, p-tagged to nobody. */
@Test
fun `today a ceremony message leaves as one gift wrap p-tagged to every other person, in the room of the people`() {
setUp()
val first = network.device(11)
runBlocking { network.join(first) }
runBlocking {
val sent = first.db.giftWrapPayloadDao().getByChatRoomAndKinds(first.room.chatRoom.id, listOf(ConfederationRitualEvents.HOST_KEYS))
val hostKeys = sent.single { it.publicKey == first.person }
val tagged = hostKeys.tags.filter { it[0] == "p" }.map { it[1] }.toSet()
assertEquals(devices.keys - first.person, tagged, "every other person in the roster")
assertEquals(mobi.giza.compose.database.model.ChatRoom.deriveChatRoomId(devices.keys.toSet()), first.room.chatRoom.id)
assertEquals(first.room.chatRoom.id, ceremonies().getValue(first.person)!!.chatRoomId)
}
}
/** Flipped by Phase 3: a bare rumor of a ritual kind is dropped, and only signed events in an envelope are read. */
@Test
fun `today an unsigned ritual rumor from someone in the roster is recorded`() {
setUp()
joinAll(except = setOf(npub(12)))
runBlocking {
val late = network.device(12)
network.join(late)
val from = network.device(21)
val bare = from.db.giftWrapPayloadDao().getByChatRoomAndKinds(from.room.chatRoom.id, listOf(ConfederationRitualEvents.HOST_KEYS))
.single { it.publicKey == from.person }
assertEquals(null, mobi.giza.compose.nostr.confederation.ConfederationSigningEvents.decodeCarried(bare.content), "a bare value, not an envelope")
ConfederationRitualManager.process(
late.db, late.room, Event(bare.id, bare.publicKey, bare.createdAt.epochSeconds, bare.kind, bare.tags, bare.content, ""), late.person, late.nsec,
)
val ceremony = ceremonies().getValue(late.person)!!
assertNotNull(late.db.confederationCeremonyDao().getMessage(ceremony.id, from.person, ConfederationRitualEvents.HOST_KEYS), "recorded with no signature")
}
}
/** Flipped by Phase 4: the bridge carries a running ceremony's messages, by its proposal. */
@Test
fun `today the bridge carries nothing for a proposal that is not yet a confederation`() {
setUp()
runBlocking {
network.withGroupRooms()
val admin = network.device(11)
val signed = NostrSignerSync(KeyPair(admin.nsec)).sign<Event>(
Clock.System.now().epochSeconds, ConfederationRitualEvents.HOST_KEYS,
arrayOf(arrayOf(ConfederationRitualEvents.PROPOSAL_TAG, network.proposalId)), "{}",
)
ConfederationBridge.heardInRoom(admin.db, groups[0], network.proposalId, listOf(signed), admin.person)
assertEquals(0, ConfederationBridge.sweep(admin.db, admin.person, admin.nsec, Clock.System.now() + 10.minutes))
assertEquals(emptyList(), admin.db.groupInboxDao().observeUnpublished().first())
}
}
/** Flipped by Phase 4: an envelope is filled to a byte budget, and a large round is several. */
@Test
fun `today the bridge puts every due event into one envelope a group, whatever its bytes`() {
val confederation = formed()
runBlocking {
network.withGroupRooms()
val admin = network.device(11)
val events = (0 until 40).map { n ->
NostrSignerSync(KeyPair(admin.nsec)).sign<Event>(
Clock.System.now().epochSeconds + n, mobi.giza.compose.nostr.confederation.ConfederationSigningEvents.NONCES,
arrayOf(mobi.giza.compose.nostr.confederation.ConfederationSigningEvents.confederationTag(confederation.id)), "x".repeat(2_000),
)
}
ConfederationBridge.heardInRoom(admin.db, groups[0], confederation.id, events, admin.person)
assertEquals(1, ConfederationBridge.sweep(admin.db, admin.person, admin.nsec, Clock.System.now() + 10.minutes), "one envelope")
assertEquals(groups.size, admin.db.groupInboxDao().observeUnpublished().first().size, "one wrap for each member group, holding all forty")
}
}
/** Flipped by Phase 5: the column, and its key onto a room, go. */
@Test
fun `today a ceremony cannot be stored without the room it runs in`() {
setUp()
runBlocking {
val device = network.device(11)
val stray = ConfederationCeremony(
id = "ce".repeat(32), chatRoomId = "no-such-room", proposalId = network.proposalId, userPublicKey = device.person, basisJson = "{}",
)
kotlin.test.assertFails { device.db.confederationCeremonyDao().upsert(stray) }
}
}
// ---- docs/confederation-room-removal.md, Phase 7: no room of its own -------------------------
private fun formed(): mobi.giza.compose.database.model.Confederation {
+2
View File
@@ -146,6 +146,8 @@ nine devices:
**Done when** all five pass on the current code, each with a KDoc line naming its phase.
**Done.** The five are in `ConfederationCeremonyJvmTest` under a Phase 1 heading, each named "today …" and with a KDoc line naming the phase that flips it. The sweep pin runs on a formed confederation with `withGroupRooms`: forty 2 KB events go out as one envelope, a wrap to each of the three groups. `ConfederationCeremonyJvmTest` 19/19.
### Phase 2: storage, schema 54
`AutoMigration(53, 54, spec = ConfederationCeremonyInboxMigration::class)`. Phases 5 and 7 add to the