mirror of
https://github.com/warppipe/swift-torrent.git
synced 2026-05-28 15:27:20 +00:00
6c8c581517
Full BEP-3 peer wire protocol, BEP-5 DHT, BEP-15 UDP trackers, magnet link support, bencode serialization, rarest-first piece selection, and async session management using SwiftNIO and swift-crypto. Includes 64 passing unit tests. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
44 lines
1.4 KiB
Swift
44 lines
1.4 KiB
Swift
import XCTest
|
|
@testable import SwiftTorrent
|
|
|
|
final class InfoHashTests: XCTestCase {
|
|
func testFromHex() {
|
|
let hash = InfoHash(hex: "0123456789abcdef0123456789abcdef01234567")
|
|
XCTAssertNotNil(hash)
|
|
XCTAssertEqual(hash?.bytes.count, 20)
|
|
XCTAssertEqual(hash?.version, .v1)
|
|
}
|
|
|
|
func testInvalidHex() {
|
|
XCTAssertNil(InfoHash(hex: "short"))
|
|
XCTAssertNil(InfoHash(hex: "xyz"))
|
|
}
|
|
|
|
func testV1Hash() {
|
|
let data = Data("test info dictionary".utf8)
|
|
let hash = InfoHash.v1(from: data)
|
|
XCTAssertEqual(hash.bytes.count, 20)
|
|
XCTAssertEqual(hash.version, .v1)
|
|
}
|
|
|
|
func testV2Hash() {
|
|
let data = Data("test info dictionary".utf8)
|
|
let hash = InfoHash.v2(from: data)
|
|
XCTAssertEqual(hash.bytes.count, 32)
|
|
XCTAssertEqual(hash.version, .v2)
|
|
}
|
|
|
|
func testDescription() {
|
|
let hash = InfoHash(hex: "0123456789abcdef0123456789abcdef01234567")!
|
|
XCTAssertEqual(hash.description, "0123456789abcdef0123456789abcdef01234567")
|
|
}
|
|
|
|
func testEquatable() {
|
|
let h1 = InfoHash(hex: "0123456789abcdef0123456789abcdef01234567")!
|
|
let h2 = InfoHash(hex: "0123456789abcdef0123456789abcdef01234567")!
|
|
let h3 = InfoHash(hex: "abcdef0123456789abcdef0123456789abcdef01")!
|
|
XCTAssertEqual(h1, h2)
|
|
XCTAssertNotEqual(h1, h3)
|
|
}
|
|
}
|