Extract BLE and chat architecture policies (#1324)

Co-authored-by: jack <jackjackbits@users.noreply.github.com>
This commit is contained in:
jack
2026-06-02 09:01:59 +02:00
committed by GitHub
co-authored by jack
parent 193cfdc06a
commit 3eb4f2bd72
46 changed files with 3286 additions and 786 deletions
@@ -0,0 +1,44 @@
import Foundation
import Testing
@testable import bitchat
struct BLEPacketFreshnessPolicyTests {
@Test
func nilRecipientCountsAsBroadcast() {
#expect(BLEPacketFreshnessPolicy.isBroadcastRecipient(nil))
}
@Test
func allOnesEightByteRecipientCountsAsBroadcast() {
#expect(BLEPacketFreshnessPolicy.isBroadcastRecipient(Data(repeating: 0xFF, count: 8)))
}
@Test
func directedRecipientIsNotBroadcast() {
#expect(!BLEPacketFreshnessPolicy.isBroadcastRecipient(Data([0, 1, 2, 3, 4, 5, 6, 7])))
}
@Test
func recentPacketIsNotStale() {
let now = Date(timeIntervalSince1970: 1000)
let timestamp = UInt64((now.timeIntervalSince1970 - 100) * 1000)
#expect(!BLEPacketFreshnessPolicy.isStale(timestampMilliseconds: timestamp, now: now))
}
@Test
func oldPacketIsStale() {
let now = Date(timeIntervalSince1970: 1000)
let timestamp = UInt64((now.timeIntervalSince1970 - 901) * 1000)
#expect(BLEPacketFreshnessPolicy.isStale(timestampMilliseconds: timestamp, now: now))
}
@Test
func futurePacketAgeIsZero() {
let now = Date(timeIntervalSince1970: 1000)
let timestamp = UInt64((now.timeIntervalSince1970 + 10) * 1000)
#expect(BLEPacketFreshnessPolicy.ageSeconds(timestampMilliseconds: timestamp, now: now) == 0)
}
}