Skip to content

Commit

Permalink
fix up all the tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nplasterer committed Nov 8, 2024
1 parent 4e0c55e commit 4588b4d
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 279 deletions.
34 changes: 0 additions & 34 deletions Sources/XMTPTestHelpers/TestHelpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,40 +61,6 @@
}
}

public struct FakeSCWWallet: SigningKey {
public var walletAddress: String
private var internalSignature: String

public init() throws {
// Simulate a wallet address (could be derived from a hash of some internal data)
self.walletAddress = UUID().uuidString // Using UUID for uniqueness in this fake example
self.internalSignature = Data(repeating: 0x01, count: 64).toHex // Fake internal signature
}

public var address: String {
walletAddress
}

public var type: WalletType {
WalletType.SCW
}

public var chainId: Int64? {
1
}

public static func generate() throws -> FakeSCWWallet {
return try FakeSCWWallet()
}

public func signSCW(message: String) async throws -> Data {
// swiftlint:disable force_unwrapping
let digest = SHA256.hash(data: message.data(using: .utf8)!)
// swiftlint:enable force_unwrapping
return Data(digest)
}
}

@available(iOS 15, *)
public struct Fixtures {
public var alix: PrivateKey!
Expand Down
245 changes: 0 additions & 245 deletions Tests/XMTPTests/ConversationsTests.swift

This file was deleted.

102 changes: 102 additions & 0 deletions Tests/XMTPTests/GroupTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,108 @@ class GroupTests: XCTestCase {
XCTAssertEqual(1, alixGroupCount)
XCTAssertEqual(1, boGroupCount)
}

func testCanFindConversationByTopic() async throws {
let fixtures = try await fixtures()

let group = try await fixtures.boClient.conversations.newGroup(with: [
fixtures.caro.walletAddress
])
let dm = try await fixtures.boClient.conversations.findOrCreateDm(
with: fixtures.caro.walletAddress)

let sameDm = try fixtures.boClient.findConversationByTopic(
topic: dm.topic)
let sameGroup = try fixtures.boClient.findConversationByTopic(
topic: group.topic)

XCTAssertEqual(group.id, try sameGroup?.id)
XCTAssertEqual(dm.id, try sameDm?.id)
}

func testCanListConversations() async throws {
let fixtures = try await fixtures()

let dm = try await fixtures.boClient.conversations.findOrCreateDm(
with: fixtures.caro.walletAddress)
let group = try await fixtures.boClient.conversations.newGroup(with: [
fixtures.caro.walletAddress
])

let convoCount = try await fixtures.boClient.conversations
.list().count
let dmCount = try await fixtures.boClient.conversations.listDms().count
let groupCount = try await fixtures.boClient.conversations.listGroups()
.count
XCTAssertEqual(convoCount, 2)
XCTAssertEqual(dmCount, 1)
XCTAssertEqual(groupCount, 1)

try await fixtures.caroClient.conversations.sync()
let convoCount2 = try await fixtures.caroClient.conversations.list()
.count
let groupCount2 = try await fixtures.caroClient.conversations
.listGroups().count
XCTAssertEqual(convoCount2, 2)
XCTAssertEqual(groupCount2, 1)
}

func testCanListConversationsFiltered() async throws {
let fixtures = try await fixtures()

let dm = try await fixtures.boClient.conversations.findOrCreateDm(
with: fixtures.caro.walletAddress)
let group = try await fixtures.boClient.conversations.newGroup(with: [
fixtures.caro.walletAddress
])

let convoCount = try await fixtures.boClient.conversations
.list().count
let convoCountConsent = try await fixtures.boClient.conversations
.list(consentState: .allowed).count

XCTAssertEqual(convoCount, 2)
XCTAssertEqual(convoCountConsent, 2)

try await group.updateConsentState(state: .denied)

let convoCountAllowed = try await fixtures.boClient.conversations
.list(consentState: .allowed).count
let convoCountDenied = try await fixtures.boClient.conversations
.list(consentState: .denied).count

XCTAssertEqual(convoCountAllowed, 1)
XCTAssertEqual(convoCountDenied, 1)
}

func testCanListConversationsOrder() async throws {
let fixtures = try await fixtures()

let dm = try await fixtures.boClient.conversations.findOrCreateDm(
with: fixtures.caro.walletAddress)
let group1 = try await fixtures.boClient.conversations.newGroup(
with: [fixtures.caro.walletAddress])
let group2 = try await fixtures.boClient.conversations.newGroup(
with: [fixtures.caro.walletAddress])

_ = try await dm.send(content: "Howdy")
_ = try await group2.send(content: "Howdy")
_ = try await fixtures.boClient.conversations.syncAllConversations()

let conversations = try await fixtures.boClient.conversations
.list()
let conversationsOrdered = try await fixtures.boClient.conversations
.list(order: .lastMessage)

XCTAssertEqual(conversations.count, 3)
XCTAssertEqual(conversationsOrdered.count, 3)

XCTAssertEqual(
try conversations.map { try $0.id }, [dm.id, group1.id, group2.id])
XCTAssertEqual(
try conversationsOrdered.map { try $0.id },
[group2.id, dm.id, group1.id])
}

func testCanListGroupsAndConversations() async throws {
let fixtures = try await fixtures()
Expand Down

0 comments on commit 4588b4d

Please sign in to comment.