-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathKeyIndexHardenerTests.swift
57 lines (50 loc) · 1.57 KB
/
KeyIndexHardenerTests.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
import XCTest
@testable import BIP32
final class KeyIndexHardenerTests: XCTestCase {
private func sut() -> KeyIndexHardener {
.init()
}
func testGivenNormalIndex_WhenHardened_ThenExpectedIndexOutput() throws {
try testValidIndex(
0x1,
expectedIndexOutput: 0x80000001
)
}
func testGivenNormalLowerBoundIndex_WhenHardened_ThenHardenedLowerBoundIndex() throws {
try testValidIndex(
KeyIndexRange.normal.lowerBound,
expectedIndexOutput: KeyIndexRange.hardened.lowerBound
)
}
func testGivenNormalUpperBoundIndex_WhenHardened_ThenHardenedUpperBoundIndex() throws {
try testValidIndex(
KeyIndexRange.normal.upperBound,
expectedIndexOutput: KeyIndexRange.hardened.upperBound
)
}
func testGivenHardenedIndex_WhenHardened_ThenThrowInvalidIndexError() {
testInvalidIndex(
0x80000001,
expectedError: .invalidIndex
)
}
}
// MARK: - Helpers
fileprivate extension KeyIndexHardenerTests {
func testValidIndex(_ index: UInt32, expectedIndexOutput: UInt32) throws {
XCTAssertEqual(
try sut().hardenedIndex(normalIndex: index),
expectedIndexOutput
)
}
func testInvalidIndex(_ index: UInt32, expectedError: KeyIndexError) {
XCTAssertThrowsError(
try sut().hardenedIndex(normalIndex: index)
) { error in
XCTAssertEqual(
error as! KeyIndexError,
expectedError
)
}
}
}