test: a confederation formed over its groups' rooms and inboxes end to end, and the record (confederation-dkg-inboxes, Phase 8)

ConfederationNetworkJvmTest forms a confederation on three groups of three, each with a real inbox
and a real MLS room, with one group's first admin never carrying. All nine devices reach one key,
and none holds a NIP-17 room or a ceremony gift wrap. ConfederationTestGroups.pumpConfederation
takes devices that do not carry.

The record: the plan's progress and where the build chose differently, the report marked as
implemented, the README rows, and since notes in the coordinator-free, profile and room-removal
plans. Nothing has run on a device or a real relay.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Kgothatso NgakoandClaude Opus 5.5 committed 2026-11-23 14:22:04 +02:00
1 parent 1a857e6d45
commit 8ef02129ad
8 files changed
+93 -22

No files matched your search

@@ -14,6 +14,7 @@ import mobi.giza.compose.database.model.ChatMessage
import mobi.giza.compose.nostr.confederation.ConfederationKinds
import mobi.giza.compose.nostr.confederation.ConfederationProposalState
import kotlin.time.Clock
import kotlin.time.Duration.Companion.minutes
/**
* Three groups agreeing, or not, to form a confederation, end to end, with nobody coordinating it
@@ -153,4 +154,37 @@ class ConfederationNetworkJvmTest {
withoutInbox.close()
}
}
// ---- docs/confederation-dkg-inboxes.md, Phase 8: forming it with no NIP-17 room ----------------
@Test
fun `the groups form the confederation over their own rooms and inboxes, with one group's first admin never carrying`() = runBlocking<Unit> {
val proposalId = proposeAtlas()
network.signed(polis) { ConfederationManager.proposeAcceptance(it.db, it.room(), it.publicKey, proposalId).id }
network.signed(ekklesia) { ConfederationManager.proposeAcceptance(it.db, it.room(), it.publicKey, proposalId).id }
assertEquals(setOf(ConfederationProposalState.ACCEPTED), states(proposalId))
val idle = polis.devices.minBy { it.publicKey }
val owedBefore = idle.db.groupInboxDao().getPublicationsForRoom(polis.roomId).size
network.everyDevice.forEach { ConfederationRitualManager.join(it.db, proposalId, it.publicKey, it.secret) }
network.pumpConfederation(at = Clock.System.now() + 10.minutes, noCarry = setOf(idle))
val ceremonies = network.everyDevice.associateWith { it.db.confederationCeremonyDao().getLatestForProposal(proposalId) }
ceremonies.forEach { (device, ceremony) ->
assertEquals(mobi.giza.compose.database.model.ConfederationCeremonyStage.COMPLETE, ceremony?.stage, "${device.name}: ${ceremony?.failureReason}")
}
assertEquals(1, ceremonies.values.map { it!!.confederationPublicKey }.toSet().size, "one key on all nine devices")
network.everyDevice.forEach { device ->
val formed = assertNotNull(device.db.confederationCeremonyDao().getConfederationForProposal(proposalId), "${device.name} holds the record")
assertTrue(ConfederationFormation.verifies(formed))
}
// No NIP-17 room, and nothing as a gift wrap: the rounds went through the groups.
val people = network.everyDevice.map { it.publicKey }.toSet()
network.everyDevice.forEach { device ->
kotlin.test.assertNull(device.db.chatRoomDao().findChatRoomById(mobi.giza.compose.database.model.ChatRoom.deriveChatRoomId(people)), "${device.name}")
assertEquals(emptyList(), device.db.giftWrapPayloadDao().getByKinds(mobi.giza.compose.nostr.confederation.ConfederationRitualEvents.ALL.toList()))
}
assertEquals(owedBefore, idle.db.groupInboxDao().getPublicationsForRoom(polis.roomId).size, "Polis's first admin carried nothing; its next admins did")
}
}
@@ -120,13 +120,14 @@ class ConfederationTestGroups(
}
/**
* A confederation's signing between these groups, until nothing moves: each group's room, every
* admin's turn at carrying at [at], and the inboxes (docs/confederation-room-removal.md, D4).
* A confederation's signing, or its key ceremony (docs/confederation-dkg-inboxes.md), between these
* groups, until nothing moves: each group's room, every admin's turn at carrying at [at], and the
* inboxes (docs/confederation-room-removal.md, D4). [noCarry] devices take part but never carry.
*/
suspend fun pumpConfederation(at: Instant? = null) {
suspend fun pumpConfederation(at: Instant? = null, noCarry: Set<GroupInboxHarness.Device> = emptySet()) {
do {
groups.forEach { it.harness.pump() }
val carried = everyDevice.sumOf { ConfederationBridge.sweep(it.db, it.publicKey, it.secret, at ?: Clock.System.now()) }
val carried = everyDevice.filter { it !in noCarry }.sumOf { ConfederationBridge.sweep(it.db, it.publicKey, it.secret, at ?: Clock.System.now()) }
val moved = deliver()
} while (carried > 0 || moved > 0)
groups.forEach { it.harness.pump() }