mirror of
https://github.com/permissionlesstech/bitchat.git
synced 2026-07-25 02:05:19 +00:00
Extract BLE and chat architecture policies (#1324)
Co-authored-by: jack <jackjackbits@users.noreply.github.com>
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user