mirror of
https://github.com/permissionlesstech/bitchat.git
synced 2026-07-25 04:45:20 +00:00
[codex] Extract BLE link state store (#1310)
* 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 * Extract BLE link state store * Extract BLE connection scheduler --------- Co-authored-by: jack <jackjackbits@users.noreply.github.com>
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
import BitFoundation
|
||||
import Testing
|
||||
@testable import bitchat
|
||||
|
||||
struct BLELinkStateStoreTests {
|
||||
@Test
|
||||
func centralBindingExposesDirectLinkStateAndLinks() {
|
||||
let store = BLELinkStateStore()
|
||||
let peerID = PeerID(str: "1122334455667788")
|
||||
|
||||
store.bindCentral("central-a", to: peerID)
|
||||
|
||||
#expect(store.peerID(forCentralUUID: "central-a") == peerID)
|
||||
#expect(store.directLinkState(for: peerID) == BLEDirectLinkState(hasPeripheral: false, hasCentral: true))
|
||||
#expect(store.links(to: peerID) == [.central("central-a")])
|
||||
}
|
||||
|
||||
@Test
|
||||
func linksReturnsAllCentralBindingsForPeer() {
|
||||
let store = BLELinkStateStore()
|
||||
let peerID = PeerID(str: "1122334455667788")
|
||||
let otherPeerID = PeerID(str: "8899aabbccddeeff")
|
||||
|
||||
store.bindCentral("central-a", to: peerID)
|
||||
store.bindCentral("central-b", to: peerID)
|
||||
store.bindCentral("central-c", to: otherPeerID)
|
||||
|
||||
#expect(store.links(to: peerID) == [.central("central-a"), .central("central-b")])
|
||||
}
|
||||
|
||||
@Test
|
||||
func clearCentralsReturnsPreviouslyBoundPeerIDsAndClearsLookups() {
|
||||
let store = BLELinkStateStore()
|
||||
let firstPeerID = PeerID(str: "1122334455667788")
|
||||
let secondPeerID = PeerID(str: "8899aabbccddeeff")
|
||||
|
||||
store.bindCentral("central-a", to: firstPeerID)
|
||||
store.bindCentral("central-b", to: secondPeerID)
|
||||
|
||||
let removedPeerIDs = Set(store.clearCentrals())
|
||||
|
||||
#expect(removedPeerIDs == Set([firstPeerID, secondPeerID]))
|
||||
#expect(store.peerID(forCentralUUID: "central-a") == nil)
|
||||
#expect(store.links(to: firstPeerID).isEmpty)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user