Raise protocol coverage to 99 percent (#1058)

* Expand protocol coverage with edge-case tests

* Stabilize read receipt transport test

* Stabilize BLE duplicate packet test

---------

Co-authored-by: jack <jackjackbits@users.noreply.github.com>
This commit is contained in:
jack
2026-03-12 17:55:41 -10:00
committed by GitHub
co-authored by jack
parent 8562a76367
commit 264a95b61a
9 changed files with 288 additions and 9 deletions
@@ -44,4 +44,33 @@ final class BitchatFilePacketTests: XCTestCase {
XCTAssertEqual(decoded.fileSize, UInt64(content.count))
XCTAssertEqual(decoded.content, content)
}
func testDecodeSupportsLegacyEightByteFileSizeTLV() throws {
let content = Data([0x01, 0x02, 0x03, 0x04])
var data = Data()
data.append(0x02)
data.append(contentsOf: [0x00, 0x08])
data.append(contentsOf: [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00])
data.append(0x04)
data.append(contentsOf: [0x00, 0x00, 0x00, 0x04])
data.append(content)
let decoded = try XCTUnwrap(BitchatFilePacket.decode(data))
XCTAssertEqual(decoded.fileSize, 256)
XCTAssertEqual(decoded.content, content)
}
func testDecodeUsesContentCountWhenFileSizeTLVIsMissing() throws {
let content = Data([0xAA, 0xBB, 0xCC])
var data = Data()
data.append(0x04)
data.append(contentsOf: [0x00, 0x00, 0x00, 0x03])
data.append(content)
let decoded = try XCTUnwrap(BitchatFilePacket.decode(data))
XCTAssertEqual(decoded.fileSize, UInt64(content.count))
XCTAssertEqual(decoded.content, content)
}
}