mirror of
https://github.com/permissionlesstech/bitchat.git
synced 2026-07-25 00:05:18 +00:00
PeerID 2/n: Count and hex conversion done with bare (#705)
This commit is contained in:
@@ -206,6 +206,18 @@ final class PeerIDTests: XCTestCase {
|
||||
XCTAssertEqual(short.prefix, .empty)
|
||||
}
|
||||
|
||||
func test_toShort_whenNoiseKeyExists_withNoisePrefix() {
|
||||
let peerID = PeerID(str: "noise:" + hex64)
|
||||
let short = peerID.toShort()
|
||||
|
||||
// `toShort()` should derive 16-hex peerID
|
||||
let expected = Data(hexString: hex64)!.sha256Fingerprint().prefix(16)
|
||||
|
||||
XCTAssertEqual(short.bare, String(expected))
|
||||
XCTAssertEqual(short.prefix, .empty)
|
||||
XCTAssertEqual(peerID.prefix, .noise)
|
||||
}
|
||||
|
||||
func test_toShort_whenNoNoiseKey() {
|
||||
let peerID = PeerID(str: "some_random_key")
|
||||
let short = peerID.toShort()
|
||||
@@ -340,6 +352,10 @@ final class PeerIDTests: XCTestCase {
|
||||
XCTAssertTrue(peerID.isNoiseKeyHex)
|
||||
XCTAssertNotNil(peerID.noiseKey)
|
||||
|
||||
let prefixedPeerID = PeerID(str: "noise:" + hex64)
|
||||
XCTAssertTrue(prefixedPeerID.isNoiseKeyHex)
|
||||
XCTAssertNotNil(prefixedPeerID.noiseKey)
|
||||
|
||||
let bad = String(repeating: "z", count: 64) // invalid hex
|
||||
let badPeerID = PeerID(str: bad)
|
||||
XCTAssertFalse(badPeerID.isNoiseKeyHex)
|
||||
|
||||
Reference in New Issue
Block a user