From 80be4b1dc7455e08d538110c9d7452a0e385f639 Mon Sep 17 00:00:00 2001 From: Naomi Plasterer Date: Wed, 21 Feb 2024 08:29:07 -0800 Subject: [PATCH] Fix passing DB Path (#260) * fix up the db path on init * bump the pod spec * add a test for it * write a test for it --- Sources/XMTPiOS/Client.swift | 4 ++- Tests/XMTPTests/ClientTests.swift | 53 +++++++++++++++++++++++++++++++ XMTP.podspec | 2 +- 3 files changed, 57 insertions(+), 2 deletions(-) diff --git a/Sources/XMTPiOS/Client.swift b/Sources/XMTPiOS/Client.swift index e4e42fa1..f74e6945 100644 --- a/Sources/XMTPiOS/Client.swift +++ b/Sources/XMTPiOS/Client.swift @@ -61,7 +61,8 @@ public struct ClientOptions { preEnableIdentityCallback: PreEventCallback? = nil, preCreateIdentityCallback: PreEventCallback? = nil, mlsAlpha: Bool = false, - mlsEncryptionKey: Data? = nil + mlsEncryptionKey: Data? = nil, + mlsDbPath: String? = nil ) { self.api = api self.codecs = codecs @@ -69,6 +70,7 @@ public struct ClientOptions { self.preCreateIdentityCallback = preCreateIdentityCallback self.mlsAlpha = mlsAlpha self.mlsEncryptionKey = mlsEncryptionKey + self.mlsDbPath = mlsDbPath } } diff --git a/Tests/XMTPTests/ClientTests.swift b/Tests/XMTPTests/ClientTests.swift index 6efea951..cff9a2c3 100644 --- a/Tests/XMTPTests/ClientTests.swift +++ b/Tests/XMTPTests/ClientTests.swift @@ -93,6 +93,59 @@ class ClientTests: XCTestCase { XCTAssert(true) } } + + func testPassingMLSEncryptionKeyAndDatabasePath() async throws { + let bo = try PrivateKey.generate() + let key = try Crypto.secureRandomBytes(count: 32) + let dbPath = URL.documentsDirectory.appendingPathComponent("xmtp-\(bo.walletAddress).db3").path + + let client = try await Client.create( + account: bo, + options: .init( + api: .init(env: .local, isSecure: false), + mlsAlpha: true, + mlsEncryptionKey: key, + mlsDbPath: dbPath + ) + ) + + let keys = client.privateKeyBundle + let bundleClient = try await Client.from( + bundle: keys, + options: .init( + api: .init(env: .local, isSecure: false), + mlsAlpha: true, + mlsEncryptionKey: key, + mlsDbPath: dbPath + ) + ) + + XCTAssertEqual(client.address, bundleClient.address) + + await assertThrowsAsyncError( + _ = try await Client.from( + bundle: keys, + options: .init( + api: .init(env: .local, isSecure: false), + mlsAlpha: true, + mlsEncryptionKey: nil, + mlsDbPath: dbPath + ) + ) + ) + + await assertThrowsAsyncError( + _ = try await Client.from( + bundle: keys, + options: .init( + api: .init(env: .local, isSecure: false), + mlsAlpha: true, + mlsEncryptionKey: key, + mlsDbPath: nil + ) + ) + ) + } func testCanMessage() async throws { let fixtures = await fixtures() diff --git a/XMTP.podspec b/XMTP.podspec index 609b0dd7..2ef64b0b 100644 --- a/XMTP.podspec +++ b/XMTP.podspec @@ -16,7 +16,7 @@ Pod::Spec.new do |spec| # spec.name = "XMTP" - spec.version = "0.8.10" + spec.version = "0.8.11" spec.summary = "XMTP SDK Cocoapod" # This description is used to generate tags and improve search results.