mirror of
https://github.com/permissionlesstech/bitchat.git
synced 2026-07-25 18:45:20 +00:00
Convert the remaining tests to Swift Testing (#781)
* SwiftTesting: NoiseProtocolTests + BinaryProtocolPaddingTests * SwiftTesting: `NotificationStreamAssemblerTests` * SwiftTesting: `NostrProtocolTests` * SwiftTesting: `BinaryProtocolTests` * SwiftTesting: `PeerIDTests` * SwiftTesting: `BLEServiceTests` * SwiftTesting: `CommandProcessorTests` * SwiftTesting: `GCSFilterTests` * SwiftTesting: `GeohashBookmarksStoreTests` * Remove `peerID` test constants * Remove PeerID + String interop from tests * Refactor IntegrationTests to extract state management * Refactor global state management of MockBLEService * NoiseProtocolSwiftTests: `actor` -> `struct` * Remove measurement tests w/ no benchmark * `NoiseProtocolSwiftTests` -> `NoiseProtocolTests` * SwiftTesting: `LocationChannelsTests` * SwiftTesting: `GossipSyncManagerTests` * SwiftTesting: `LocationNotesManagerTests` * Global `sleep` function for tests * SwiftTesting: `IntegrationTests` --------- Co-authored-by: jack <jackjackbits@users.noreply.github.com>
This commit is contained in:
@@ -11,21 +11,19 @@ import CryptoKit
|
||||
import struct Foundation.UUID
|
||||
@testable import bitchat
|
||||
|
||||
// TODO: Remove once MockBLEService is refactored to fix race condition
|
||||
@Suite(.serialized)
|
||||
struct PrivateChatE2ETests {
|
||||
|
||||
private let alice: MockBLEService
|
||||
private let bob: MockBLEService
|
||||
private let charlie: MockBLEService
|
||||
private let mockKeychain: MockKeychain
|
||||
private let mockKeychain = MockKeychain()
|
||||
private let bus = MockBLEBus()
|
||||
|
||||
init() {
|
||||
// Create services with unique peer IDs to avoid any collision
|
||||
alice = MockBLEService(peerID: PeerID(str: UUID().uuidString), nickname: TestConstants.testNickname1)
|
||||
bob = MockBLEService(peerID: PeerID(str: UUID().uuidString), nickname: TestConstants.testNickname2)
|
||||
charlie = MockBLEService(peerID: PeerID(str: UUID().uuidString), nickname: TestConstants.testNickname3)
|
||||
mockKeychain = MockKeychain()
|
||||
alice = MockBLEService(peerID: PeerID(str: UUID().uuidString), nickname: TestConstants.testNickname1, bus: bus)
|
||||
bob = MockBLEService(peerID: PeerID(str: UUID().uuidString), nickname: TestConstants.testNickname2, bus: bus)
|
||||
charlie = MockBLEService(peerID: PeerID(str: UUID().uuidString), nickname: TestConstants.testNickname3, bus: bus)
|
||||
}
|
||||
|
||||
// MARK: - Basic Private Messaging Tests
|
||||
@@ -53,7 +51,7 @@ struct PrivateChatE2ETests {
|
||||
)
|
||||
|
||||
// Wait a bit to ensure message would have been delivered if it was going to be
|
||||
try? await Task.sleep(nanoseconds: UInt64(TestConstants.shortTimeout * 1_000_000_000))
|
||||
try? await sleep(0.1)
|
||||
}
|
||||
|
||||
#expect(!bobReceivedMessage, "Bob should not have received the message")
|
||||
@@ -171,7 +169,7 @@ struct PrivateChatE2ETests {
|
||||
// Send encrypted private message
|
||||
alice.sendPrivateMessage(
|
||||
TestConstants.testMessage1,
|
||||
to: TestConstants.testPeerID2,
|
||||
to: bob.peerID,
|
||||
recipientNickname: TestConstants.testNickname2
|
||||
)
|
||||
}
|
||||
@@ -235,7 +233,7 @@ struct PrivateChatE2ETests {
|
||||
for i in 0..<messageCount {
|
||||
alice.sendPrivateMessage(
|
||||
"Private message \(i)",
|
||||
to: TestConstants.testPeerID2,
|
||||
to: bob.peerID,
|
||||
recipientNickname: TestConstants.testNickname2
|
||||
)
|
||||
}
|
||||
@@ -254,7 +252,7 @@ struct PrivateChatE2ETests {
|
||||
|
||||
alice.sendPrivateMessage(
|
||||
TestConstants.testLongMessage,
|
||||
to: TestConstants.testPeerID2,
|
||||
to: bob.peerID,
|
||||
recipientNickname: TestConstants.testNickname2
|
||||
)
|
||||
}
|
||||
|
||||
@@ -10,22 +10,22 @@ import Testing
|
||||
import struct Foundation.UUID
|
||||
@testable import bitchat
|
||||
|
||||
@Suite(.serialized)
|
||||
struct PublicChatE2ETests {
|
||||
|
||||
private let alice: MockBLEService
|
||||
private let bob: MockBLEService
|
||||
private let charlie: MockBLEService
|
||||
private let david: MockBLEService
|
||||
private let bus = MockBLEBus()
|
||||
|
||||
private var receivedMessages: [String: [BitchatMessage]] = [:]
|
||||
|
||||
init() {
|
||||
// Create mock services with unique peer IDs to avoid any collision
|
||||
alice = MockBLEService(peerID: PeerID(str: UUID().uuidString), nickname: TestConstants.testNickname1)
|
||||
bob = MockBLEService(peerID: PeerID(str: UUID().uuidString), nickname: TestConstants.testNickname2)
|
||||
charlie = MockBLEService(peerID: PeerID(str: UUID().uuidString), nickname: TestConstants.testNickname3)
|
||||
david = MockBLEService(peerID: PeerID(str: UUID().uuidString), nickname: TestConstants.testNickname4)
|
||||
alice = MockBLEService(peerID: PeerID(str: UUID().uuidString), nickname: TestConstants.testNickname1, bus: bus)
|
||||
bob = MockBLEService(peerID: PeerID(str: UUID().uuidString), nickname: TestConstants.testNickname2, bus: bus)
|
||||
charlie = MockBLEService(peerID: PeerID(str: UUID().uuidString), nickname: TestConstants.testNickname3, bus: bus)
|
||||
david = MockBLEService(peerID: PeerID(str: UUID().uuidString), nickname: TestConstants.testNickname4, bus: bus)
|
||||
}
|
||||
|
||||
// MARK: - Basic Broadcasting Tests
|
||||
|
||||
Reference in New Issue
Block a user