bitchatTests/README.md
This test suite uses an in-memory networking harness to make end-to-end and integration tests deterministic, fast, and race-free without touching production code.
bitchatTests/Mocks/MockBLEService.swiftregistry maps peerID to a MockBLEService instance; adjacency records simulated links between peers.MockBLEService.resetTestBus() in setUp() to clear state between tests.simulateConnectedPeer(_:) and simulateDisconnectedPeer(_:) to add/remove links. connectFullMesh() helpers in tests build larger topologies.messageDeliveryHandler (decoded BitchatMessage) and packetDeliveryHandler (raw BitchatPacket).seenMessageIDs prevents duplicate deliveries during flooding/relays.MockBLEService.autoFloodEnabledtrue, public broadcasts propagate across the entire connected component (ignores TTL for reach) while still de‑duping to prevent loops.setUp) to simulate large-network broadcast; disabled in E2E tests to keep routing explicit and verify TTL behavior (see PublicChatE2ETests.testZeroTTLNotRelayed).NoiseSessionManager manages per-peer sessions.IntegrationTests.testRehandshakeAfterDecryptionFailure
removeSession(for:) on the initiator’s manager before initiateHandshake(with:) to avoid alreadyEstablished.autoFloodEnabled toggled only within Integration tests; always reset in tearDown() to avoid cross-test contamination.let svc = MockBLEService(); svc.myPeerID = "PEER1"svc.simulateConnectedPeer("PEER2")svc.messageDeliveryHandler = { msg in /* asserts */ }MockBLEService.autoFloodEnabled = true