Files
bitchat/bitchatTests/Services/BLENoisePayloadFactoryTests.swift
9e84f5e822 [codex] Refactor BLE outbound scheduling and Noise queues (#1306)
* Refactor BLE transport event handling

* Make image output paths unique

* Keep queued Nostr read receipts alive

* Refine BLE ingress fanout

* Rediscover BLE service after invalidation

* Extract BLE notification retry buffer

* Extract BLE inbound write buffer

* Extract BLE fragment assembly buffer

* Tidy secure log handling from device run

* Extract BLE outbound fragment scheduler

* Harden app CI media tests

* Redact BLE message content from logs

* Extract BLE Noise session queues

* Fix BLE read receipt UI updates

* Allow self-authored RSR ingress replies

* Harden read receipt queue test timing

* Extract BLE outbound policy and incoming file storage

* Avoid duplicate BLE link snapshots during send

* Canonicalize Nostr relay URLs

---------

Co-authored-by: jack <jackjackbits@users.noreply.github.com>
2026-05-31 14:16:11 +02:00

35 lines
1.3 KiB
Swift

import Foundation
import Testing
@testable import bitchat
struct BLENoisePayloadFactoryTests {
@Test
func privateMessagePayloadPrefixesTLVWithNoiseType() throws {
let payload = try #require(BLENoisePayloadFactory.privateMessage(content: "secret", messageID: "pm-1"))
#expect(payload.first == NoisePayloadType.privateMessage.rawValue)
let packet = try #require(PrivateMessagePacket.decode(from: Data(payload.dropFirst())))
#expect(packet.messageID == "pm-1")
#expect(packet.content == "secret")
}
@Test
func receiptPayloadsUseMessageIDBytes() {
let read = BLENoisePayloadFactory.readReceipt(originalMessageID: "read-id")
let delivered = BLENoisePayloadFactory.delivered(messageID: "delivered-id")
#expect(read.first == NoisePayloadType.readReceipt.rawValue)
#expect(String(data: Data(read.dropFirst()), encoding: .utf8) == "read-id")
#expect(delivered.first == NoisePayloadType.delivered.rawValue)
#expect(String(data: Data(delivered.dropFirst()), encoding: .utf8) == "delivered-id")
}
@Test
func typedPayloadKeepsOpaqueDataUnchanged() {
let payload = BLENoisePayloadFactory.typedPayload(.verifyChallenge, payload: Data([0xCA, 0xFE]))
#expect(payload == Data([NoisePayloadType.verifyChallenge.rawValue, 0xCA, 0xFE]))
}
}