mirror of
https://github.com/permissionlesstech/bitchat.git
synced 2026-07-25 20:05:19 +00:00
PeerID 11/n: Noise types use PeerID + create separate files (#750)
* Noise types use PeerID * Fix tests * Extract `NoiseSessionManager` into a separate file * Extract `NoiseSessionState` into a separate file * Remove `failed` state from `NoiseSessionState` * Extract `NoiseSessionError` into a separate file
This commit is contained in:
@@ -7,16 +7,17 @@
|
||||
//
|
||||
|
||||
import Foundation
|
||||
@testable import bitchat
|
||||
|
||||
struct TestConstants {
|
||||
static let defaultTimeout: TimeInterval = 5.0
|
||||
static let shortTimeout: TimeInterval = 1.0
|
||||
static let longTimeout: TimeInterval = 10.0
|
||||
|
||||
static let testPeerID1 = "PEER1234"
|
||||
static let testPeerID2 = "PEER5678"
|
||||
static let testPeerID3 = "PEER9012"
|
||||
static let testPeerID4 = "PEER3456"
|
||||
static let testPeerID1: PeerID = "PEER1234"
|
||||
static let testPeerID2: PeerID = "PEER5678"
|
||||
static let testPeerID3: PeerID = "PEER9012"
|
||||
static let testPeerID4: PeerID = "PEER3456"
|
||||
|
||||
static let testNickname1 = "Alice"
|
||||
static let testNickname2 = "Bob"
|
||||
|
||||
@@ -30,7 +30,7 @@ final class TestHelpers {
|
||||
static func createTestMessage(
|
||||
content: String = TestConstants.testMessage1,
|
||||
sender: String = TestConstants.testNickname1,
|
||||
senderPeerID: String = TestConstants.testPeerID1,
|
||||
senderPeerID: PeerID = TestConstants.testPeerID1,
|
||||
isPrivate: Bool = false,
|
||||
recipientNickname: String? = nil,
|
||||
mentions: [String]? = nil
|
||||
@@ -44,23 +44,23 @@ final class TestHelpers {
|
||||
originalSender: nil,
|
||||
isPrivate: isPrivate,
|
||||
recipientNickname: recipientNickname,
|
||||
senderPeerID: senderPeerID,
|
||||
senderPeerID: senderPeerID.id,
|
||||
mentions: mentions
|
||||
)
|
||||
}
|
||||
|
||||
static func createTestPacket(
|
||||
type: UInt8 = 0x01,
|
||||
senderID: String = TestConstants.testPeerID1,
|
||||
recipientID: String? = nil,
|
||||
senderID: PeerID = TestConstants.testPeerID1,
|
||||
recipientID: PeerID? = nil,
|
||||
payload: Data = "test payload".data(using: .utf8)!,
|
||||
signature: Data? = nil,
|
||||
ttl: UInt8 = 3
|
||||
) -> BitchatPacket {
|
||||
return BitchatPacket(
|
||||
type: type,
|
||||
senderID: senderID.data(using: .utf8)!,
|
||||
recipientID: recipientID?.data(using: .utf8),
|
||||
senderID: senderID.id.data(using: .utf8)!,
|
||||
recipientID: recipientID?.id.data(using: .utf8),
|
||||
timestamp: UInt64(Date().timeIntervalSince1970 * 1000),
|
||||
payload: payload,
|
||||
signature: signature,
|
||||
@@ -119,4 +119,16 @@ enum TestError: Error {
|
||||
case timeout
|
||||
case unexpectedValue
|
||||
case testFailure(String)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - PeerID String Helpers
|
||||
|
||||
/// Raw String can be passed as PeerID
|
||||
extension PeerID: @retroactive ExpressibleByStringLiteral {
|
||||
public init(stringLiteral value: String) {
|
||||
self.init(str: value)
|
||||
}
|
||||
}
|
||||
|
||||
/// Interpolated String can be passed as PeerID
|
||||
extension PeerID: @retroactive ExpressibleByStringInterpolation {}
|
||||
|
||||
Reference in New Issue
Block a user