mirror of
https://github.com/permissionlesstech/bitchat.git
synced 2026-07-24 21:45:20 +00:00
* 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>
56 lines
2.3 KiB
Swift
56 lines
2.3 KiB
Swift
import Testing
|
|
import Foundation
|
|
@testable import bitchat
|
|
|
|
struct LocationChannelsTests {
|
|
@Test func geohashEncoderPrecisionMapping() {
|
|
// Sanity: known coords (Statue of Liberty approx)
|
|
let lat = 40.6892
|
|
let lon = -74.0445
|
|
let block = Geohash.encode(latitude: lat, longitude: lon, precision: GeohashChannelLevel.block.precision)
|
|
let neighborhood = Geohash.encode(latitude: lat, longitude: lon, precision: GeohashChannelLevel.neighborhood.precision)
|
|
let city = Geohash.encode(latitude: lat, longitude: lon, precision: GeohashChannelLevel.city.precision)
|
|
let region = Geohash.encode(latitude: lat, longitude: lon, precision: GeohashChannelLevel.province.precision)
|
|
let country = Geohash.encode(latitude: lat, longitude: lon, precision: GeohashChannelLevel.region.precision)
|
|
|
|
#expect(block.count == 7)
|
|
#expect(neighborhood.count == 6)
|
|
#expect(city.count == 5)
|
|
#expect(region.count == 4)
|
|
#expect(country.count == 2)
|
|
|
|
// All prefixes must match progressively
|
|
#expect(block.hasPrefix(neighborhood))
|
|
#expect(neighborhood.hasPrefix(city))
|
|
#expect(city.hasPrefix(region))
|
|
#expect(region.hasPrefix(country))
|
|
}
|
|
|
|
@Test func nostrGeohashFilterEncoding() throws {
|
|
let gh = "u4pruy"
|
|
let filter = NostrFilter.geohashEphemeral(gh)
|
|
let data = try JSONEncoder().encode(filter)
|
|
let json = String(data: data, encoding: .utf8) ?? ""
|
|
// Expect kinds includes 20000 and tag filter '#g':[gh]
|
|
#expect(json.contains("20000"))
|
|
#expect(json.contains("\"#g\":[\"\(gh)\"]"))
|
|
}
|
|
|
|
@Test func perGeohashIdentityDeterministic() throws {
|
|
// Derive twice for same geohash; should be identical
|
|
let idBridge = NostrIdentityBridge(keychain: MockKeychainHelper())
|
|
let gh = "u4pruy"
|
|
let id1 = try idBridge.deriveIdentity(forGeohash: gh)
|
|
let id2 = try idBridge.deriveIdentity(forGeohash: gh)
|
|
#expect(id1.publicKeyHex == id2.publicKeyHex)
|
|
}
|
|
|
|
@Test func geohashNeighborsNearPoleSkipOutOfBoundsCells() {
|
|
let nearPole = Geohash.encode(latitude: 89.9999, longitude: 0.0, precision: 8)
|
|
let neighbors = Geohash.neighbors(of: nearPole)
|
|
|
|
#expect(neighbors.isEmpty == false)
|
|
#expect(neighbors.count < 8)
|
|
}
|
|
}
|