mirror of
https://github.com/permissionlesstech/bitchat.git
synced 2026-07-25 10:45:20 +00:00
* Extract each type to a separate file * Nostr ID Bridge: Convert static func/vars to instance * `KeychainHelper` behind a protocol to easily mock * Update tests with ID Bridge and MockKeychainHelper --------- Co-authored-by: jack <212554440+jackjackbits@users.noreply.github.com>
47 lines
2.1 KiB
Swift
47 lines
2.1 KiB
Swift
import XCTest
|
|
@testable import bitchat
|
|
|
|
final class LocationChannelsTests: XCTestCase {
|
|
func testGeohashEncoderPrecisionMapping() {
|
|
// 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)
|
|
|
|
XCTAssertEqual(block.count, 7)
|
|
XCTAssertEqual(neighborhood.count, 6)
|
|
XCTAssertEqual(city.count, 5)
|
|
XCTAssertEqual(region.count, 4)
|
|
XCTAssertEqual(country.count, 2)
|
|
|
|
// All prefixes must match progressively
|
|
XCTAssertTrue(block.hasPrefix(neighborhood))
|
|
XCTAssertTrue(neighborhood.hasPrefix(city))
|
|
XCTAssertTrue(city.hasPrefix(region))
|
|
XCTAssertTrue(region.hasPrefix(country))
|
|
}
|
|
|
|
func testNostrGeohashFilterEncoding() 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]
|
|
XCTAssertTrue(json.contains("20000"))
|
|
XCTAssertTrue(json.contains("\"#g\":[\"\(gh)\"]"))
|
|
}
|
|
|
|
func testPerGeohashIdentityDeterministic() 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)
|
|
XCTAssertEqual(id1.publicKeyHex, id2.publicKeyHex)
|
|
}
|
|
}
|