Skip to content

Commit

Permalink
fix up tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nplasterer committed Sep 20, 2024
1 parent 58f0c82 commit f909726
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
26 changes: 14 additions & 12 deletions Tests/XMTPTests/ClientTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ import XMTPTestHelpers
@available(iOS 15, *)
class ClientTests: XCTestCase {
func testTakesAWallet() async throws {
try TestConfig.skip(because: "run manually against dev")
let opts = ClientOptions(api: ClientOptions.Api(env: .local, isSecure: false))
let fakeWallet = try PrivateKey.generate()
_ = try await Client.create(account: fakeWallet)
_ = try await Client.create(account: fakeWallet, options: opts)
}

func testPassingSavedKeysWithNoSignerWithMLSErrors() async throws {
Expand Down Expand Up @@ -212,49 +212,51 @@ class ClientTests: XCTestCase {
}

func testCanBeCreatedWithBundle() async throws {
try TestConfig.skip(because: "run manually against dev")
let opts = ClientOptions(api: ClientOptions.Api(env: .local, isSecure: false))
let fakeWallet = try PrivateKey.generate()
let client = try await Client.create(account: fakeWallet)
let client = try await Client.create(account: fakeWallet, options: opts)

let bundle = try client.privateKeyBundle
let clientFromV1Bundle = try await Client.from(bundle: bundle)
let clientFromV1Bundle = try await Client.from(bundle: bundle, options: opts)

XCTAssertEqual(client.address, clientFromV1Bundle.address)
XCTAssertEqual(try client.v1keys.identityKey, try clientFromV1Bundle.v1keys.identityKey)
XCTAssertEqual(try client.v1keys.preKeys, try clientFromV1Bundle.v1keys.preKeys)
}

func testCanBeCreatedWithV1Bundle() async throws {
try TestConfig.skip(because: "run manually against dev")
let opts = ClientOptions(api: ClientOptions.Api(env: .local, isSecure: false))
let fakeWallet = try PrivateKey.generate()
let client = try await Client.create(account: fakeWallet)
let client = try await Client.create(account: fakeWallet, options: opts)

let bundleV1 = try client.v1keys
let clientFromV1Bundle = try await Client.from(v1Bundle: bundleV1)
let clientFromV1Bundle = try await Client.from(v1Bundle: bundleV1, options: opts)

XCTAssertEqual(client.address, clientFromV1Bundle.address)
XCTAssertEqual(try client.v1keys.identityKey, try clientFromV1Bundle.v1keys.identityKey)
XCTAssertEqual(try client.v1keys.preKeys, try clientFromV1Bundle.v1keys.preKeys)
}

func testCanAccessPublicKeyBundle() async throws {
let opts = ClientOptions(api: ClientOptions.Api(env: .local, isSecure: false))
let fakeWallet = try PrivateKey.generate()
let client = try await Client.create(account: fakeWallet)
let client = try await Client.create(account: fakeWallet, options: opts)

let publicKeyBundle = try client.keys.getPublicKeyBundle()
XCTAssertEqual(publicKeyBundle, try client.publicKeyBundle)
}

func testCanSignWithPrivateIdentityKey() async throws {
let opts = ClientOptions(api: ClientOptions.Api(env: .local, isSecure: false))
let fakeWallet = try PrivateKey.generate()
let client = try await Client.create(account: fakeWallet)
let client = try await Client.create(account: fakeWallet, options: opts)

let digest = Util.keccak256(Data("hello world".utf8))
let signature = try await client.keys.identityKey.sign(digest)

let recovered = try KeyUtilx.recoverPublicKeyKeccak256(from: signature.rawData, message: Data("hello world".utf8))

XCTAssertEqual(recovered, try client.keys.identityKey.publicKey.secp256K1Uncompressed.bytes)
let bytes = try client.keys.identityKey.publicKey.secp256K1Uncompressed.bytes
XCTAssertEqual(recovered, bytes)
}

func testPreEnableIdentityCallback() async throws {
Expand Down
2 changes: 1 addition & 1 deletion Tests/XMTPTests/ConversationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class ConversationTests: XCTestCase {
}

func testCanStreamConversationsV2() async throws {
let options = ClientOptions(api: ClientOptions.Api(env: .dev, isSecure: true))
let options = ClientOptions(api: ClientOptions.Api(env: .local, isSecure: false))
let wallet = try PrivateKey.generate()
let client = try await Client.create(account: wallet, options: options)

Expand Down

0 comments on commit f909726

Please sign in to comment.