-
Notifications
You must be signed in to change notification settings - Fork 5
/
SerializedKeyTests.swift
65 lines (55 loc) · 1.65 KB
/
SerializedKeyTests.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import Foundation
import XCTest
@testable import BIP32
final class SerializedKeyTests: XCTestCase {
private func sut(data: Data) throws -> SerializedKey {
try .init(data: data)
}
func testGivenKey_WithInvalidByteCount_WhenInit_ThenThrowError() {
XCTAssertThrowsError(
try sut(data: .init())
)
}
func testGivenKey_WithValidByteCount_WhenInit_ThenNoErrorThrown() {
XCTAssertNoThrow(
try validKey()
)
}
func testGivenValidKey_WhenCountVersionBytes_ThenEqual4() throws {
XCTAssertEqual(
try validKey().version.bytes.count, 4
)
}
func testGivenValidKey_WhenCountDepthBytes_ThenEqual1() throws {
XCTAssertEqual(
try validKey().depth.bytes.count, 1
)
}
func testGivenValidKey_WhenCountParentKeyFingerprintBytes_ThenEqual4() throws {
XCTAssertEqual(
try validKey().parentKeyFingerprint.bytes.count, 4
)
}
func testGivenValidKey_WhenCountIndexBytes_ThenEqual4() throws {
XCTAssertEqual(
try validKey().index.bytes.count, 4
)
}
func testGivenValidKey_WhenCountChainCodeBytes_ThenEqual32() throws {
XCTAssertEqual(
try validKey().chainCode.count, 32
)
}
func testGivenValidKey_WhenCountKeyBytes_ThenEqual33() throws {
XCTAssertEqual(
try validKey().key.count, 33
)
}
}
// MARK: - Helpers
fileprivate extension SerializedKeyTests {
func validKey() throws -> SerializedKey {
let data = Data(hex: SerializedKeyTestVector.hexEncodedKey)
return try sut(data: data)
}
}