From db015a3a518a0ce5eeb250c4eb825b35463a08c5 Mon Sep 17 00:00:00 2001 From: Naomi Plasterer Date: Tue, 20 Feb 2024 19:07:42 -0800 Subject: [PATCH 1/4] update the pod spec for the new group admin stuff --- Package.swift | 2 +- XMTP.podspec | 4 ++-- .../xcshareddata/swiftpm/Package.resolved | 8 ++++---- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Package.swift b/Package.swift index 6d45c0ec..66509435 100644 --- a/Package.swift +++ b/Package.swift @@ -25,7 +25,7 @@ let package = Package( .package(url: "https://github.com/1024jp/GzipSwift", from: "5.2.0"), .package(url: "https://github.com/bufbuild/connect-swift", exact: "0.3.0"), .package(url: "https://github.com/apple/swift-docc-plugin.git", from: "1.0.0"), - .package(url: "https://github.com/xmtp/libxmtp-swift", exact: "0.4.2-beta2"), + .package(url: "https://github.com/xmtp/libxmtp-swift", exact: "0.4.2-beta3"), ], targets: [ // Targets are the basic building blocks of a package. A target can define a module or a test suite. diff --git a/XMTP.podspec b/XMTP.podspec index 62a1c6c1..e1b4095f 100644 --- a/XMTP.podspec +++ b/XMTP.podspec @@ -16,7 +16,7 @@ Pod::Spec.new do |spec| # spec.name = "XMTP" - spec.version = "0.8.8" + spec.version = "0.8.9" spec.summary = "XMTP SDK Cocoapod" # This description is used to generate tags and improve search results. @@ -44,5 +44,5 @@ Pod::Spec.new do |spec| spec.dependency "web3.swift" spec.dependency "GzipSwift" spec.dependency "Connect-Swift", "= 0.3.0" - spec.dependency 'LibXMTP', '= 0.4.2-beta1' + spec.dependency 'LibXMTP', '= 0.4.2-beta3' end diff --git a/XMTPiOSExample/XMTPiOSExample.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/XMTPiOSExample/XMTPiOSExample.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index ae2d9158..46b25e43 100644 --- a/XMTPiOSExample/XMTPiOSExample.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/XMTPiOSExample/XMTPiOSExample.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -59,8 +59,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/xmtp/libxmtp-swift", "state" : { - "revision" : "db13df1fef0e4a11880a889640a3df2998e4abac", - "version" : "0.4.2-beta1" + "revision" : "de859c86a5854bdc2cfd54e8f98b6088a38a2f3c", + "version" : "0.4.2-beta2" } }, { @@ -230,8 +230,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/WalletConnect/WalletConnectSwiftV2", "state" : { - "branch" : "main", - "revision" : "13446a81e678e8eddc6ab506e85c522df0163f1f" + "revision" : "addf9a3688ef5e5d9d148ecbb30ca0fd3132b908", + "version" : "1.9.8" } }, { From 70e38c902b9fed37042247bddf050f5f52e23324 Mon Sep 17 00:00:00 2001 From: Naomi Plasterer Date: Tue, 20 Feb 2024 19:38:07 -0800 Subject: [PATCH 2/4] add more involved tests for the functions --- Sources/XMTPiOS/Group.swift | 16 ++++++++++++++++ Tests/XMTPTests/GroupTests.swift | 14 ++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/Sources/XMTPiOS/Group.swift b/Sources/XMTPiOS/Group.swift index d5932dfb..cb978ea6 100644 --- a/Sources/XMTPiOS/Group.swift +++ b/Sources/XMTPiOS/Group.swift @@ -42,6 +42,10 @@ public struct Group: Identifiable, Equatable, Hashable { public var id: Data { ffiGroup.id() } + + var metadata: FfiGroupMetadata { + return ffiGroup.groupMetadata() + } public func sync() async throws { try await ffiGroup.sync() @@ -58,7 +62,19 @@ public struct Group: Identifiable, Equatable, Hashable { public func isActive() throws -> Bool { return try ffiGroup.isActive() } + + public func isAdmin(): Bool { + return metadata.creatorAccountAddress() == client.address + } + public func permissionLevel(): GroupPermissions { + return metadata.policyType() + } + + public func adminAddress(): String { + return metadata.creatorAccountAddress() + } + public var memberAddresses: [String] { do { return try ffiGroup.listMembers().map(\.fromFFI.accountAddress) diff --git a/Tests/XMTPTests/GroupTests.swift b/Tests/XMTPTests/GroupTests.swift index e782d728..e54f3275 100644 --- a/Tests/XMTPTests/GroupTests.swift +++ b/Tests/XMTPTests/GroupTests.swift @@ -107,6 +107,13 @@ class GroupTests: XCTestCase { try await aliceGroup.sync() XCTAssertEqual(aliceGroup.memberAddresses.count, 3) XCTAssertEqual(bobGroup.memberAddresses.count, 3) + + XCTAssertEqual(bobGroup.permissionLevel(), .everyoneIsAdmin) + XCTAssertEqual(aliceGroup.permissionLevel(), .everyoneIsAdmin) + XCTAssertEqual(bobGroup.adminAddress(), fixtures.bobClient.address) + XCTAssertEqual(aliceGroup.adminAddress(), fixtures.bobClient.address) + XCTAssert(bobGroup.isAdmin()) + XCTAssert(!aliceGroup.isAdmin()) } func testCanCreateAGroupWithAdminPermissions() async throws { @@ -141,6 +148,13 @@ class GroupTests: XCTestCase { try await bobGroup.sync() XCTAssertEqual(aliceGroup.memberAddresses.count, 2) XCTAssertEqual(bobGroup.memberAddresses.count, 2) + + XCTAssertEqual(bobGroup.permissionLevel(), .groupCreatorIsAdmin) + XCTAssertEqual(aliceGroup.permissionLevel(), .groupCreatorIsAdmin) + XCTAssertEqual(bobGroup.adminAddress(), fixtures.bobClient.address) + XCTAssertEqual(aliceGroup.adminAddress(), fixtures.bobClient.address) + XCTAssert(bobGroup.isAdmin()) + XCTAssert(!aliceGroup.isAdmin()) } func testCanListGroups() async throws { From c79e4d9cbfd9625a1e2a498eec3d2071818dcf5a Mon Sep 17 00:00:00 2001 From: Naomi Plasterer Date: Tue, 20 Feb 2024 20:05:17 -0800 Subject: [PATCH 3/4] fix up the tests --- Sources/XMTPiOS/Group.swift | 16 ++++++------- Tests/XMTPTests/GroupTests.swift | 24 +++++++++---------- .../xcshareddata/swiftpm/Package.resolved | 4 ++-- 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/Sources/XMTPiOS/Group.swift b/Sources/XMTPiOS/Group.swift index cb978ea6..f7c37279 100644 --- a/Sources/XMTPiOS/Group.swift +++ b/Sources/XMTPiOS/Group.swift @@ -43,8 +43,8 @@ public struct Group: Identifiable, Equatable, Hashable { ffiGroup.id() } - var metadata: FfiGroupMetadata { - return ffiGroup.groupMetadata() + func metadata() throws -> FfiGroupMetadata { + return try ffiGroup.groupMetadata() } public func sync() async throws { @@ -63,16 +63,16 @@ public struct Group: Identifiable, Equatable, Hashable { return try ffiGroup.isActive() } - public func isAdmin(): Bool { - return metadata.creatorAccountAddress() == client.address + public func isAdmin() throws -> Bool { + return try metadata().creatorAccountAddress() == client.address } - public func permissionLevel(): GroupPermissions { - return metadata.policyType() + public func permissionLevel() throws -> GroupPermissions { + return try metadata().policyType() } - public func adminAddress(): String { - return metadata.creatorAccountAddress() + public func adminAddress() throws -> String { + return try metadata().creatorAccountAddress() } public var memberAddresses: [String] { diff --git a/Tests/XMTPTests/GroupTests.swift b/Tests/XMTPTests/GroupTests.swift index e54f3275..fdae9665 100644 --- a/Tests/XMTPTests/GroupTests.swift +++ b/Tests/XMTPTests/GroupTests.swift @@ -108,12 +108,12 @@ class GroupTests: XCTestCase { XCTAssertEqual(aliceGroup.memberAddresses.count, 3) XCTAssertEqual(bobGroup.memberAddresses.count, 3) - XCTAssertEqual(bobGroup.permissionLevel(), .everyoneIsAdmin) - XCTAssertEqual(aliceGroup.permissionLevel(), .everyoneIsAdmin) - XCTAssertEqual(bobGroup.adminAddress(), fixtures.bobClient.address) - XCTAssertEqual(aliceGroup.adminAddress(), fixtures.bobClient.address) - XCTAssert(bobGroup.isAdmin()) - XCTAssert(!aliceGroup.isAdmin()) + XCTAssertEqual(try bobGroup.permissionLevel(), .everyoneIsAdmin) + XCTAssertEqual(try aliceGroup.permissionLevel(), .everyoneIsAdmin) + XCTAssertEqual(try bobGroup.adminAddress(), fixtures.bobClient.address) + XCTAssertEqual(try aliceGroup.adminAddress(), fixtures.bobClient.address) + XCTAssert(try bobGroup.isAdmin()) + XCTAssert(try !aliceGroup.isAdmin()) } func testCanCreateAGroupWithAdminPermissions() async throws { @@ -149,12 +149,12 @@ class GroupTests: XCTestCase { XCTAssertEqual(aliceGroup.memberAddresses.count, 2) XCTAssertEqual(bobGroup.memberAddresses.count, 2) - XCTAssertEqual(bobGroup.permissionLevel(), .groupCreatorIsAdmin) - XCTAssertEqual(aliceGroup.permissionLevel(), .groupCreatorIsAdmin) - XCTAssertEqual(bobGroup.adminAddress(), fixtures.bobClient.address) - XCTAssertEqual(aliceGroup.adminAddress(), fixtures.bobClient.address) - XCTAssert(bobGroup.isAdmin()) - XCTAssert(!aliceGroup.isAdmin()) + XCTAssertEqual(try bobGroup.permissionLevel(), .groupCreatorIsAdmin) + XCTAssertEqual(try aliceGroup.permissionLevel(), .groupCreatorIsAdmin) + XCTAssertEqual(try bobGroup.adminAddress(), fixtures.bobClient.address) + XCTAssertEqual(try aliceGroup.adminAddress(), fixtures.bobClient.address) + XCTAssert(try bobGroup.isAdmin()) + XCTAssert(try !aliceGroup.isAdmin()) } func testCanListGroups() async throws { diff --git a/XMTPiOSExample/XMTPiOSExample.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/XMTPiOSExample/XMTPiOSExample.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index 46b25e43..3612b1e6 100644 --- a/XMTPiOSExample/XMTPiOSExample.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/XMTPiOSExample/XMTPiOSExample.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -59,8 +59,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/xmtp/libxmtp-swift", "state" : { - "revision" : "de859c86a5854bdc2cfd54e8f98b6088a38a2f3c", - "version" : "0.4.2-beta2" + "revision" : "f6571b6b771b4c0a2a9469bd407ce124a9d91fed", + "version" : "0.4.2-beta3" } }, { From 96060a441cdb3b6e8e39b5f8295f246e39ffcfe5 Mon Sep 17 00:00:00 2001 From: Naomi Plasterer Date: Tue, 20 Feb 2024 20:07:23 -0800 Subject: [PATCH 4/4] fix up the tests --- Sources/XMTPiOS/Group.swift | 2 +- Tests/XMTPTests/GroupTests.swift | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Sources/XMTPiOS/Group.swift b/Sources/XMTPiOS/Group.swift index f7c37279..e0af35d7 100644 --- a/Sources/XMTPiOS/Group.swift +++ b/Sources/XMTPiOS/Group.swift @@ -64,7 +64,7 @@ public struct Group: Identifiable, Equatable, Hashable { } public func isAdmin() throws -> Bool { - return try metadata().creatorAccountAddress() == client.address + return try metadata().creatorAccountAddress().lowercased() == client.address.lowercased() } public func permissionLevel() throws -> GroupPermissions { diff --git a/Tests/XMTPTests/GroupTests.swift b/Tests/XMTPTests/GroupTests.swift index fdae9665..d4e56f52 100644 --- a/Tests/XMTPTests/GroupTests.swift +++ b/Tests/XMTPTests/GroupTests.swift @@ -110,8 +110,8 @@ class GroupTests: XCTestCase { XCTAssertEqual(try bobGroup.permissionLevel(), .everyoneIsAdmin) XCTAssertEqual(try aliceGroup.permissionLevel(), .everyoneIsAdmin) - XCTAssertEqual(try bobGroup.adminAddress(), fixtures.bobClient.address) - XCTAssertEqual(try aliceGroup.adminAddress(), fixtures.bobClient.address) + XCTAssertEqual(try bobGroup.adminAddress().lowercased(), fixtures.bobClient.address.lowercased()) + XCTAssertEqual(try aliceGroup.adminAddress().lowercased(), fixtures.bobClient.address.lowercased()) XCTAssert(try bobGroup.isAdmin()) XCTAssert(try !aliceGroup.isAdmin()) } @@ -151,8 +151,8 @@ class GroupTests: XCTestCase { XCTAssertEqual(try bobGroup.permissionLevel(), .groupCreatorIsAdmin) XCTAssertEqual(try aliceGroup.permissionLevel(), .groupCreatorIsAdmin) - XCTAssertEqual(try bobGroup.adminAddress(), fixtures.bobClient.address) - XCTAssertEqual(try aliceGroup.adminAddress(), fixtures.bobClient.address) + XCTAssertEqual(try bobGroup.adminAddress().lowercased(), fixtures.bobClient.address.lowercased()) + XCTAssertEqual(try aliceGroup.adminAddress().lowercased(), fixtures.bobClient.address.lowercased()) XCTAssert(try bobGroup.isAdmin()) XCTAssert(try !aliceGroup.isAdmin()) }