mirror of
https://github.com/permissionlesstech/bitchat.git
synced 2026-07-25 03:45:20 +00:00
Convert the remaining tests to Swift Testing (#781)
* SwiftTesting: NoiseProtocolTests + BinaryProtocolPaddingTests * SwiftTesting: `NotificationStreamAssemblerTests` * SwiftTesting: `NostrProtocolTests` * SwiftTesting: `BinaryProtocolTests` * SwiftTesting: `PeerIDTests` * SwiftTesting: `BLEServiceTests` * SwiftTesting: `CommandProcessorTests` * SwiftTesting: `GCSFilterTests` * SwiftTesting: `GeohashBookmarksStoreTests` * Remove `peerID` test constants * Remove PeerID + String interop from tests * Refactor IntegrationTests to extract state management * Refactor global state management of MockBLEService * NoiseProtocolSwiftTests: `actor` -> `struct` * Remove measurement tests w/ no benchmark * `NoiseProtocolSwiftTests` -> `NoiseProtocolTests` * SwiftTesting: `LocationChannelsTests` * SwiftTesting: `GossipSyncManagerTests` * SwiftTesting: `LocationNotesManagerTests` * Global `sleep` function for tests * SwiftTesting: `IntegrationTests` --------- Co-authored-by: jack <jackjackbits@users.noreply.github.com>
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
import XCTest
|
||||
import Testing
|
||||
import Foundation
|
||||
@testable import bitchat
|
||||
|
||||
final class LocationChannelsTests: XCTestCase {
|
||||
func testGeohashEncoderPrecisionMapping() {
|
||||
struct LocationChannelsTests {
|
||||
@Test func geohashEncoderPrecisionMapping() {
|
||||
// Sanity: known coords (Statue of Liberty approx)
|
||||
let lat = 40.6892
|
||||
let lon = -74.0445
|
||||
@@ -12,35 +13,35 @@ final class LocationChannelsTests: XCTestCase {
|
||||
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)
|
||||
#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
|
||||
XCTAssertTrue(block.hasPrefix(neighborhood))
|
||||
XCTAssertTrue(neighborhood.hasPrefix(city))
|
||||
XCTAssertTrue(city.hasPrefix(region))
|
||||
XCTAssertTrue(region.hasPrefix(country))
|
||||
#expect(block.hasPrefix(neighborhood))
|
||||
#expect(neighborhood.hasPrefix(city))
|
||||
#expect(city.hasPrefix(region))
|
||||
#expect(region.hasPrefix(country))
|
||||
}
|
||||
|
||||
func testNostrGeohashFilterEncoding() throws {
|
||||
@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]
|
||||
XCTAssertTrue(json.contains("20000"))
|
||||
XCTAssertTrue(json.contains("\"#g\":[\"\(gh)\"]"))
|
||||
#expect(json.contains("20000"))
|
||||
#expect(json.contains("\"#g\":[\"\(gh)\"]"))
|
||||
}
|
||||
|
||||
func testPerGeohashIdentityDeterministic() throws {
|
||||
@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)
|
||||
XCTAssertEqual(id1.publicKeyHex, id2.publicKeyHex)
|
||||
#expect(id1.publicKeyHex == id2.publicKeyHex)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user