Merge branch 'claude/hierarchy-wallet-guarding-bug-75ab6e' into bennu
This commit is contained in:
commit
f57ac781ca
2 files changed
+22
-1
No files matched your search
+5
-1
@@ -210,6 +210,10 @@ object GuardianManager {
|
||||
* Tells every room in [rooms] about [statement], as [userPublicKey]: one
|
||||
* notice each, queued for the outbound pipeline the way every inner event
|
||||
* is. Returns how many were queued.
|
||||
*
|
||||
* Each notice names its room in an `h` tag. Without it, one statement told
|
||||
* to a grandchild's parent and grandparent in the same second is one id --
|
||||
* and one row, the last room's -- so the parent was never told.
|
||||
*/
|
||||
suspend fun share(
|
||||
database: BennuDatabase,
|
||||
@@ -219,9 +223,9 @@ object GuardianManager {
|
||||
createdAt: Long = Clock.System.now().epochSeconds,
|
||||
): Int {
|
||||
val content = statement.toJson()
|
||||
val tags = emptyArray<Array<String>>()
|
||||
|
||||
rooms.forEach { room ->
|
||||
val tags = arrayOf(arrayOf("h", room.chatRoom.id))
|
||||
val id = EventHasher.hashId(userPublicKey, createdAt, GuardedWalletNoticeEvent.KIND, tags, content)
|
||||
database.marmotInnerEventDao().upsert(
|
||||
MarmotInnerEvent(
|
||||
|
||||
+17
@@ -369,6 +369,23 @@ class GuardianSigningJvmTest {
|
||||
assertEquals(listOf(statement.id), GuardianManager.guardedWalletsOf(member.db, roomId).map { it.statement.id })
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a grandchild's statement told to its parent and grandparent at once reaches both`(): Unit = runBlocking {
|
||||
val member = device(members[0], signerIndex = 0)
|
||||
val grandparentRoomId = "9".repeat(64)
|
||||
member.db.chatRoomDao().upsert(ChatRoom(id = grandparentRoomId, userPublicKey = member.publicKey, subject = "Assembly", description = null, mlsGroupState = "00"))
|
||||
val rooms = listOf(roomId, grandparentRoomId).map { assertNotNull(member.db.chatRoomDao().findChatRoomById(it)) }
|
||||
|
||||
// One statement, one sharer, one second: only the room tells the two notices apart.
|
||||
assertEquals(2, GuardianManager.share(member.db, guardedStatement(), rooms, member.publicKey, createdAt = 1_700_000_100))
|
||||
|
||||
val told = listOf(roomId, grandparentRoomId).associateWith { room ->
|
||||
member.db.marmotInnerEventDao().getByChatRoomAndKinds(room, listOf(GuardedWalletNoticeEvent.KIND)).single()
|
||||
}
|
||||
told.forEach { (room, notice) -> assertEquals(listOf(listOf("h", room)), notice.tags.map { it.toList() }) }
|
||||
assertEquals(2, told.values.map { it.id }.toSet().size)
|
||||
}
|
||||
|
||||
// ---- Spending from a guarded wallet ------------------------------------
|
||||
|
||||
private val chain = Chain.Regtest
|
||||
|
||||
Reference in new issue
Block a user