Skip to content

Commit

Permalink
Fix passing DB Path (#260)
Browse files Browse the repository at this point in the history
* fix up the db path on init

* bump the pod spec

* add a test for it

* write a test for it
  • Loading branch information
nplasterer authored and kele-leanes committed Feb 23, 2024
1 parent 8b4b81f commit 80be4b1
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 2 deletions.
4 changes: 3 additions & 1 deletion Sources/XMTPiOS/Client.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,16 @@ 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
self.preEnableIdentityCallback = preEnableIdentityCallback
self.preCreateIdentityCallback = preCreateIdentityCallback
self.mlsAlpha = mlsAlpha
self.mlsEncryptionKey = mlsEncryptionKey
self.mlsDbPath = mlsDbPath
}
}

Expand Down
53 changes: 53 additions & 0 deletions Tests/XMTPTests/ClientTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion XMTP.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 80be4b1

Please sign in to comment.