From 4ac0a1cda9aa8dd2b019e3c3ece3473b12eb9a87 Mon Sep 17 00:00:00 2001 From: Naomi Plasterer Date: Wed, 20 Nov 2024 17:18:53 -0800 Subject: [PATCH 1/6] bump the pod --- Package.swift | 2 +- XMTP.podspec | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Package.swift b/Package.swift index 1ecb5bc9..abdaa5a0 100644 --- a/Package.swift +++ b/Package.swift @@ -20,7 +20,7 @@ let package = Package( .package(url: "https://github.com/tesseract-one/CSecp256k1.swift.git", from: "0.2.0"), .package(url: "https://github.com/bufbuild/connect-swift", exact: "1.0.0"), .package(url: "https://github.com/apple/swift-docc-plugin.git", from: "1.4.3"), - .package(url: "https://github.com/xmtp/libxmtp-swift.git", exact: "3.0.3"), + .package(url: "https://github.com/xmtp/libxmtp-swift.git", exact: "3.0.4"), .package(url: "https://github.com/krzyzanowskim/CryptoSwift.git", exact: "1.8.3") ], targets: [ diff --git a/XMTP.podspec b/XMTP.podspec index 63c9919e..79562e7c 100644 --- a/XMTP.podspec +++ b/XMTP.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |spec| spec.name = "XMTP" - spec.version = "3.0.6" + spec.version = "3.0.7" spec.summary = "XMTP SDK Cocoapod" spec.description = <<-DESC @@ -22,7 +22,7 @@ Pod::Spec.new do |spec| spec.dependency 'CSecp256k1', '~> 0.2' spec.dependency "Connect-Swift", "= 1.0.0" - spec.dependency 'LibXMTP', '= 3.0.3' + spec.dependency 'LibXMTP', '= 3.0.4' spec.dependency 'CryptoSwift', '= 1.8.3' spec.ios.deployment_target = '14.0' From 63f06c1bd73b7b7536ae443212a444239dcae6b1 Mon Sep 17 00:00:00 2001 From: Naomi Plasterer Date: Wed, 20 Nov 2024 18:16:16 -0800 Subject: [PATCH 2/6] update to latest libxmtp --- .../project.xcworkspace/xcshareddata/swiftpm/Package.resolved | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/XMTPiOSExample/XMTPiOSExample.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/XMTPiOSExample/XMTPiOSExample.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index 21d422e2..f671b65c 100644 --- a/XMTPiOSExample/XMTPiOSExample.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/XMTPiOSExample/XMTPiOSExample.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -41,8 +41,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/xmtp/libxmtp-swift.git", "state" : { - "revision" : "d44798db766bd82e93c4f49f9997b5369f927971", - "version" : "3.0.3" + "revision" : "3acbfd1ce362df2bd9dae1674bc9faff89281ae6", + "version" : "3.0.4" } }, { From e60533b4a1e724aeb05a0b48adf990c2810d29f7 Mon Sep 17 00:00:00 2001 From: Naomi Plasterer Date: Fri, 22 Nov 2024 16:43:04 -0800 Subject: [PATCH 3/6] clean up the consent code and add streaming --- Sources/XMTPiOS/Client.swift | 4 - Sources/XMTPiOS/Extensions/Ffi.swift | 16 ++++ Sources/XMTPiOS/PrivatePreferences.swift | 93 ++++++++++++++++-------- 3 files changed, 78 insertions(+), 35 deletions(-) diff --git a/Sources/XMTPiOS/Client.swift b/Sources/XMTPiOS/Client.swift index 97f9c46e..738b768f 100644 --- a/Sources/XMTPiOS/Client.swift +++ b/Sources/XMTPiOS/Client.swift @@ -474,10 +474,6 @@ public final class Client { try await ffiClient.sendSyncRequest(kind: .messages) } - public func syncConsent() async throws { - try await ffiClient.sendSyncRequest(kind: .consent) - } - public func inboxState(refreshFromNetwork: Bool) async throws -> InboxState { return InboxState( diff --git a/Sources/XMTPiOS/Extensions/Ffi.swift b/Sources/XMTPiOS/Extensions/Ffi.swift index 743a1a4c..7158547f 100644 --- a/Sources/XMTPiOS/Extensions/Ffi.swift +++ b/Sources/XMTPiOS/Extensions/Ffi.swift @@ -45,6 +45,16 @@ extension FfiConsentState { } } +extension FfiConsentEntityType { + var fromFFI: EntryType { + switch self { + case .inboxId: return EntryType.inbox_id + case .address: return EntryType.address + case .conversationId: return EntryType.conversation_id + } + } +} + extension EntryType { var toFFI: FfiConsentEntityType { switch self { @@ -62,3 +72,9 @@ extension ConsentListEntry { ) } } + +extension FfiConsent { + var fromFfi: ConsentListEntry { + ConsentListEntry(value: self.entity, entryType: self.entityType.fromFFI, consentType: self.state.fromFFI) + } +} diff --git a/Sources/XMTPiOS/PrivatePreferences.swift b/Sources/XMTPiOS/PrivatePreferences.swift index 703c54e5..c0509602 100644 --- a/Sources/XMTPiOS/PrivatePreferences.swift +++ b/Sources/XMTPiOS/PrivatePreferences.swift @@ -9,12 +9,13 @@ public enum EntryType: String, Codable { } public struct ConsentListEntry: Codable, Hashable { - public init(value: String, entryType: EntryType, consentType: ConsentState) { + public init(value: String, entryType: EntryType, consentType: ConsentState) + { self.value = value self.entryType = entryType self.consentType = consentType } - + static func address(_ address: String, type: ConsentState = .unknown) -> ConsentListEntry { @@ -25,7 +26,8 @@ public struct ConsentListEntry: Codable, Hashable { conversationId: String, type: ConsentState = ConsentState.unknown ) -> ConsentListEntry { ConsentListEntry( - value: conversationId, entryType: .conversation_id, consentType: type) + value: conversationId, entryType: .conversation_id, + consentType: type) } static func inboxId(_ inboxId: String, type: ConsentState = .unknown) @@ -44,25 +46,8 @@ public struct ConsentListEntry: Codable, Hashable { } } -public enum ContactError: Error { - case invalidIdentifier -} - -public actor EntriesManager { - public var map: [String: ConsentListEntry] = [:] - - func set(_ key: String, _ object: ConsentListEntry) { - map[key] = object - } - - func get(_ key: String) -> ConsentListEntry? { - map[key] - } -} - -public class ConsentList { - public let entriesManager = EntriesManager() - var lastFetched: Date? +/// Provides access to contact bundles. +public actor PrivatePreferences { var client: Client var ffiClient: FfiXmtpClient @@ -82,7 +67,9 @@ public class ConsentList { ).fromFFI } - public func conversationState(conversationId: String) async throws -> ConsentState { + public func conversationState(conversationId: String) async throws + -> ConsentState + { return try await ffiClient.getConsentState( entityType: .conversationId, entity: conversationId @@ -95,17 +82,61 @@ public class ConsentList { entity: inboxId ).fromFFI } + + public func syncConsent() async throws { + try await ffiClient.sendSyncRequest(kind: .consent) + } + + public func streamConsent() + -> AsyncThrowingStream + { + AsyncThrowingStream { continuation in + let ffiStreamActor = FfiStreamActor() + + let consentCallback = ConsentCallback(client: self.client) { + consent in + guard !Task.isCancelled else { + continuation.finish() + Task { + await ffiStreamActor.endStream() + } + return + } + continuation.yield(consent) + } + + let task = Task { + let stream = await ffiClient.conversations().streamConsent( + callback: consentCallback) + await ffiStreamActor.setFfiStream(stream) + } + + continuation.onTermination = { _ in + task.cancel() + Task { + await ffiStreamActor.endStream() + } + } + } + } } -/// Provides access to contact bundles. -public actor PrivatePreferences { - var client: Client - var ffiClient: FfiXmtpClient - public var consentList: ConsentList +final class ConsentCallback: FfiConsentCallback { + let client: Client + let callback: (ConsentListEntry) -> Void - init(client: Client, ffiClient: FfiXmtpClient) { + init(client: Client, _ callback: @escaping (ConsentListEntry) -> Void) { self.client = client - self.ffiClient = ffiClient - consentList = ConsentList(client: client, ffiClient: ffiClient) + self.callback = callback + } + + func onConsentUpdate(consent: [LibXMTP.FfiConsent]) { + for record in consent { + callback(record.fromFfi) + } + } + + func onError(error: LibXMTP.FfiSubscribeError) { + print("Error ConsentCallback \(error)") } } From a231f4853ca7bd4d378eb90513604bcb12e853e1 Mon Sep 17 00:00:00 2001 From: Naomi Plasterer Date: Fri, 22 Nov 2024 17:07:11 -0800 Subject: [PATCH 4/6] add a test for it --- Tests/XMTPTests/ConversationTests.swift | 63 +++++++++++++++++++++++-- Tests/XMTPTests/DmTests.swift | 10 ++-- Tests/XMTPTests/GroupTests.swift | 24 +++++----- 3 files changed, 77 insertions(+), 20 deletions(-) diff --git a/Tests/XMTPTests/ConversationTests.swift b/Tests/XMTPTests/ConversationTests.swift index 7eefe69e..e78d92d8 100644 --- a/Tests/XMTPTests/ConversationTests.swift +++ b/Tests/XMTPTests/ConversationTests.swift @@ -200,7 +200,7 @@ class ConversationTests: XCTestCase { try await boDm?.sync() try await alixClient.conversations.sync() try await alixClient2.conversations.sync() - try await alixClient2.syncConsent() + try await alixClient2.preferences.syncConsent() try await alixClient.conversations.syncAllConversations() sleep(2) try await alixClient2.conversations.syncAllConversations() @@ -209,7 +209,7 @@ class ConversationTests: XCTestCase { if let dm2 = try alixClient2.findConversation(conversationId: dm.id) { XCTAssertEqual(try dm2.consentState(), .denied) - try await alixClient2.preferences.consentList.setConsentState( + try await alixClient2.preferences.setConsentState( entries: [ ConsentListEntry( value: dm2.id, @@ -218,12 +218,69 @@ class ConversationTests: XCTestCase { ) ] ) - let convoState = try await alixClient2.preferences.consentList + let convoState = try await alixClient2.preferences .conversationState( conversationId: dm2.id) XCTAssertEqual(convoState, .allowed) XCTAssertEqual(try dm2.consentState(), .allowed) } } + + func testStreamConsent() async throws { + let fixtures = try await fixtures() + + let key = try Crypto.secureRandomBytes(count: 32) + let alix = try PrivateKey.generate() + var alixClient = try await Client.create( + account: alix, + options: .init( + api: .init(env: .local, isSecure: false), + dbEncryptionKey: key, + dbDirectory: "xmtp_db" + ) + ) + + let alixGroup = try await alixClient.conversations.newGroup( + with: [fixtures.bo.walletAddress]) + + var alixClient2 = try await Client.create( + account: alix, + options: .init( + api: .init(env: .local, isSecure: false), + dbEncryptionKey: key, + dbDirectory: "xmtp_db2" + ) + ) + + try await alixGroup.send(content: "Hello") + try await alixClient.conversations.sync() + try await alixClient2.conversations.sync() + try await alixClient.conversations.syncAllConversations() + try await alixClient2.conversations.syncAllConversations() + + let alixGroup2 = try alixClient2.findGroup(groupId: alixGroup.id) + + let expectation1 = XCTestExpectation(description: "got a consent") + expectation1.expectedFulfillmentCount = 1 + + Task(priority: .userInitiated) { + for try await _ in await fixtures.alixClient.preferences.streamConsent() + { + expectation1.fulfill() + } + } + + try await alixGroup2!.updateConsentState(state: .denied) + let dm = try await alixClient2.conversations.newConversation(with: fixtures.caro.walletAddress) + try await dm.updateConsentState(state: .denied) + try await alixClient.conversations.sync() + try await alixClient2.conversations.sync() + try await alixClient.conversations.syncAllConversations() + try await alixClient2.conversations.syncAllConversations() + + await fulfillment(of: [expectation1], timeout: 5) + + XCTAssertEqual(try alixGroup.consentState(), .allowed) + } } diff --git a/Tests/XMTPTests/DmTests.swift b/Tests/XMTPTests/DmTests.swift index a33c9e66..f391b87b 100644 --- a/Tests/XMTPTests/DmTests.swift +++ b/Tests/XMTPTests/DmTests.swift @@ -82,7 +82,7 @@ class DmTests: XCTestCase { _ = try await dm.send(content: "gm") try await dm.sync() - let dmState = try await fixtures.boClient.preferences.consentList + let dmState = try await fixtures.boClient.preferences .conversationState(conversationId: dm.id) XCTAssertEqual(dmState, .allowed) XCTAssertEqual(try dm.consentState(), .allowed) @@ -248,24 +248,24 @@ class DmTests: XCTestCase { let dm = try await fixtures.boClient.conversations.findOrCreateDm( with: fixtures.alix.walletAddress) - let isDm = try await fixtures.boClient.preferences.consentList + let isDm = try await fixtures.boClient.preferences .conversationState(conversationId: dm.id) XCTAssertEqual(isDm, .allowed) XCTAssertEqual(try dm.consentState(), .allowed) - try await fixtures.boClient.preferences.consentList.setConsentState( + try await fixtures.boClient.preferences.setConsentState( entries: [ ConsentListEntry( value: dm.id, entryType: .conversation_id, consentType: .denied) ]) - let isDenied = try await fixtures.boClient.preferences.consentList + let isDenied = try await fixtures.boClient.preferences .conversationState(conversationId: dm.id) XCTAssertEqual(isDenied, .denied) XCTAssertEqual(try dm.consentState(), .denied) try await dm.updateConsentState(state: .allowed) - let isAllowed = try await fixtures.boClient.preferences.consentList + let isAllowed = try await fixtures.boClient.preferences .conversationState(conversationId: dm.id) XCTAssertEqual(isAllowed, .allowed) XCTAssertEqual(try dm.consentState(), .allowed) diff --git a/Tests/XMTPTests/GroupTests.swift b/Tests/XMTPTests/GroupTests.swift index 83ef0ea6..119a14f3 100644 --- a/Tests/XMTPTests/GroupTests.swift +++ b/Tests/XMTPTests/GroupTests.swift @@ -99,7 +99,7 @@ class GroupTests: XCTestCase { XCTAssertEqual(boConsentResult, ConsentState.allowed) let alixConsentResult = try await fixtures.alixClient.preferences - .consentList.conversationState(conversationId: alixGroup.id) + .conversationState(conversationId: alixGroup.id) XCTAssertEqual(alixConsentResult, ConsentState.unknown) try await boGroup.addMembers(addresses: [fixtures.caro.address]) @@ -793,7 +793,7 @@ class GroupTests: XCTestCase { XCTAssertEqual(try group.consentState(), .allowed) try await group.updateConsentState(state: .denied) - let isDenied = try await fixtures.boClient.preferences.consentList + let isDenied = try await fixtures.boClient.preferences .conversationState(conversationId: group.id) XCTAssertEqual(isDenied, .denied) XCTAssertEqual(try group.consentState(), .denied) @@ -806,12 +806,12 @@ class GroupTests: XCTestCase { let fixtures = try await fixtures() let boGroup = try await fixtures.boClient.conversations.newGroup( with: [fixtures.alix.address]) - let inboxState = try await fixtures.boClient.preferences.consentList + let inboxState = try await fixtures.boClient.preferences .inboxIdState( inboxId: fixtures.alixClient.inboxID) XCTAssertEqual(inboxState, .unknown) - try await fixtures.boClient.preferences.consentList.setConsentState( + try await fixtures.boClient.preferences.setConsentState( entries: [ ConsentListEntry( value: fixtures.alixClient.inboxID, entryType: .inbox_id, @@ -822,12 +822,12 @@ class GroupTests: XCTestCase { }) XCTAssertEqual(alixMember?.consentState, .allowed) - let inboxState2 = try await fixtures.boClient.preferences.consentList + let inboxState2 = try await fixtures.boClient.preferences .inboxIdState( inboxId: fixtures.alixClient.inboxID) XCTAssertEqual(inboxState2, .allowed) - try await fixtures.boClient.preferences.consentList.setConsentState( + try await fixtures.boClient.preferences.setConsentState( entries: [ ConsentListEntry( value: fixtures.alixClient.inboxID, entryType: .inbox_id, @@ -838,22 +838,22 @@ class GroupTests: XCTestCase { }) XCTAssertEqual(alixMember?.consentState, .denied) - let inboxState3 = try await fixtures.boClient.preferences.consentList + let inboxState3 = try await fixtures.boClient.preferences .inboxIdState( inboxId: fixtures.alixClient.inboxID) XCTAssertEqual(inboxState3, .denied) - try await fixtures.boClient.preferences.consentList.setConsentState( + try await fixtures.boClient.preferences.setConsentState( entries: [ ConsentListEntry( value: fixtures.alixClient.address, entryType: .address, consentType: .allowed) ]) - let inboxState4 = try await fixtures.boClient.preferences.consentList + let inboxState4 = try await fixtures.boClient.preferences .inboxIdState( inboxId: fixtures.alixClient.inboxID) XCTAssertEqual(inboxState4, .allowed) - let addressState = try await fixtures.boClient.preferences.consentList + let addressState = try await fixtures.boClient.preferences .addressState(address: fixtures.alixClient.address) XCTAssertEqual(addressState, .allowed) } @@ -892,12 +892,12 @@ class GroupTests: XCTestCase { try await fixtures.alixClient.conversations.sync() let alixGroup = try fixtures.alixClient.findGroup(groupId: boGroup.id)! let isGroupAllowed = try await fixtures.alixClient.preferences - .consentList.conversationState(conversationId: boGroup.id) + .conversationState(conversationId: boGroup.id) XCTAssertEqual(isGroupAllowed, .unknown) let preparedMessageId = try await alixGroup.prepareMessage( content: "Test text") let isGroupAllowed2 = try await fixtures.alixClient.preferences - .consentList.conversationState(conversationId: boGroup.id) + .conversationState(conversationId: boGroup.id) XCTAssertEqual(isGroupAllowed2, .allowed) let messageCount = try await alixGroup.messages().count XCTAssertEqual(messageCount, 1) From 339259ebea6882481c4ae37968513d43bff2c959 Mon Sep 17 00:00:00 2001 From: Naomi Plasterer Date: Mon, 25 Nov 2024 12:39:15 -0800 Subject: [PATCH 5/6] get the tests passing --- Tests/XMTPTests/ConversationTests.swift | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/Tests/XMTPTests/ConversationTests.swift b/Tests/XMTPTests/ConversationTests.swift index e78d92d8..7d45f754 100644 --- a/Tests/XMTPTests/ConversationTests.swift +++ b/Tests/XMTPTests/ConversationTests.swift @@ -231,7 +231,7 @@ class ConversationTests: XCTestCase { let key = try Crypto.secureRandomBytes(count: 32) let alix = try PrivateKey.generate() - var alixClient = try await Client.create( + let alixClient = try await Client.create( account: alix, options: .init( api: .init(env: .local, isSecure: false), @@ -243,7 +243,7 @@ class ConversationTests: XCTestCase { let alixGroup = try await alixClient.conversations.newGroup( with: [fixtures.bo.walletAddress]) - var alixClient2 = try await Client.create( + let alixClient2 = try await Client.create( account: alix, options: .init( api: .init(env: .local, isSecure: false), @@ -255,16 +255,19 @@ class ConversationTests: XCTestCase { try await alixGroup.send(content: "Hello") try await alixClient.conversations.sync() try await alixClient2.conversations.sync() - try await alixClient.conversations.syncAllConversations() - try await alixClient2.conversations.syncAllConversations() + let alixSize = try await alixClient.conversations.syncAllConversations() + let alix2Size = try await alixClient2.conversations.syncAllConversations() + + XCTAssertEqual(alixSize, 3) + XCTAssertEqual(alix2Size, 2) let alixGroup2 = try alixClient2.findGroup(groupId: alixGroup.id) let expectation1 = XCTestExpectation(description: "got a consent") - expectation1.expectedFulfillmentCount = 1 + expectation1.expectedFulfillmentCount = 3 Task(priority: .userInitiated) { - for try await _ in await fixtures.alixClient.preferences.streamConsent() + for try await _ in await alixClient.preferences.streamConsent() { expectation1.fulfill() } @@ -276,11 +279,13 @@ class ConversationTests: XCTestCase { try await alixClient.conversations.sync() try await alixClient2.conversations.sync() try await alixClient.conversations.syncAllConversations() + sleep(3) try await alixClient2.conversations.syncAllConversations() + sleep(3) - await fulfillment(of: [expectation1], timeout: 5) + await fulfillment(of: [expectation1], timeout: 20) - XCTAssertEqual(try alixGroup.consentState(), .allowed) + XCTAssertEqual(try alixGroup.consentState(), .denied) } } From 4d332d16b6004dcb12c5220ca80d876beb36ff7f Mon Sep 17 00:00:00 2001 From: Naomi Plasterer Date: Mon, 25 Nov 2024 13:06:28 -0800 Subject: [PATCH 6/6] fix up the flakiness in the test --- Sources/XMTPiOS/PrivatePreferences.swift | 18 +++++----- Tests/XMTPTests/ConversationTests.swift | 42 +++++++++++------------- 2 files changed, 28 insertions(+), 32 deletions(-) diff --git a/Sources/XMTPiOS/PrivatePreferences.swift b/Sources/XMTPiOS/PrivatePreferences.swift index c0509602..2362d7fd 100644 --- a/Sources/XMTPiOS/PrivatePreferences.swift +++ b/Sources/XMTPiOS/PrivatePreferences.swift @@ -94,7 +94,7 @@ public actor PrivatePreferences { let ffiStreamActor = FfiStreamActor() let consentCallback = ConsentCallback(client: self.client) { - consent in + records in guard !Task.isCancelled else { continuation.finish() Task { @@ -102,7 +102,9 @@ public actor PrivatePreferences { } return } - continuation.yield(consent) + for consent in records { + continuation.yield(consent.fromFfi) + } } let task = Task { @@ -123,20 +125,18 @@ public actor PrivatePreferences { final class ConsentCallback: FfiConsentCallback { let client: Client - let callback: (ConsentListEntry) -> Void + let callback: ([FfiConsent]) -> Void - init(client: Client, _ callback: @escaping (ConsentListEntry) -> Void) { + init(client: Client, _ callback: @escaping ([FfiConsent]) -> Void) { self.client = client self.callback = callback } - func onConsentUpdate(consent: [LibXMTP.FfiConsent]) { - for record in consent { - callback(record.fromFfi) - } + func onConsentUpdate(consent: [FfiConsent]) { + callback(consent) } - func onError(error: LibXMTP.FfiSubscribeError) { + func onError(error: FfiSubscribeError) { print("Error ConsentCallback \(error)") } } diff --git a/Tests/XMTPTests/ConversationTests.swift b/Tests/XMTPTests/ConversationTests.swift index 7d45f754..10eae2be 100644 --- a/Tests/XMTPTests/ConversationTests.swift +++ b/Tests/XMTPTests/ConversationTests.swift @@ -231,6 +231,7 @@ class ConversationTests: XCTestCase { let key = try Crypto.secureRandomBytes(count: 32) let alix = try PrivateKey.generate() + let alixClient = try await Client.create( account: alix, options: .init( @@ -240,8 +241,7 @@ class ConversationTests: XCTestCase { ) ) - let alixGroup = try await alixClient.conversations.newGroup( - with: [fixtures.bo.walletAddress]) + let alixGroup = try await alixClient.conversations.newGroup(with: [fixtures.bo.walletAddress]) let alixClient2 = try await Client.create( account: alix, @@ -255,37 +255,33 @@ class ConversationTests: XCTestCase { try await alixGroup.send(content: "Hello") try await alixClient.conversations.sync() try await alixClient2.conversations.sync() - let alixSize = try await alixClient.conversations.syncAllConversations() - let alix2Size = try await alixClient2.conversations.syncAllConversations() - - XCTAssertEqual(alixSize, 3) - XCTAssertEqual(alix2Size, 2) - - let alixGroup2 = try alixClient2.findGroup(groupId: alixGroup.id) - - let expectation1 = XCTestExpectation(description: "got a consent") - expectation1.expectedFulfillmentCount = 3 + try await alixClient.conversations.syncAllConversations() + try await alixClient2.conversations.syncAllConversations() + let alixGroup2 = try alixClient2.findGroup(groupId: alixGroup.id)! + + var consentList = [ConsentListEntry]() + let expectation = XCTestExpectation(description: "Stream Consent") + expectation.expectedFulfillmentCount = 3 Task(priority: .userInitiated) { - for try await _ in await alixClient.preferences.streamConsent() - { - expectation1.fulfill() + for try await entry in await alixClient.preferences.streamConsent() { + consentList.append(entry) + expectation.fulfill() } } - - try await alixGroup2!.updateConsentState(state: .denied) + sleep(1) + try await alixGroup2.updateConsentState(state: .denied) let dm = try await alixClient2.conversations.newConversation(with: fixtures.caro.walletAddress) try await dm.updateConsentState(state: .denied) - try await alixClient.conversations.sync() - try await alixClient2.conversations.sync() + + sleep(5) try await alixClient.conversations.syncAllConversations() - sleep(3) try await alixClient2.conversations.syncAllConversations() - sleep(3) - - await fulfillment(of: [expectation1], timeout: 20) + await fulfillment(of: [expectation], timeout: 3) + print(consentList) XCTAssertEqual(try alixGroup.consentState(), .denied) } + }