-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathValidatorDetailsServiceTests.swift
56 lines (52 loc) · 1.93 KB
/
ValidatorDetailsServiceTests.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
import Combine
import XCTest
@testable import SubVTData
final class ValidatorDetailsServiceTests: XCTestCase {
private var cancellables: Set<AnyCancellable>!
override func setUp() {
initLog()
cancellables = []
}
func testValidatorDetailsSubscription() {
var error: Error? = nil
let finishExpectation = self.expectation(description: "Finished.")
let service = ValidatorDetailsService()
var updateCount = 0
service
.subscribe(parameter: "0xA00505EB2A4607F27837F57232F0C456602E39540582685B4F58CDE293F1A116")
.sink { (completion) in
switch completion {
case .finished:
print("Finished.")
finishExpectation.fulfill()
case .failure(let rpcError):
print("Finished with error: \(rpcError)")
error = rpcError
finishExpectation.fulfill()
}
} receiveValue: { (event) in
switch event {
case .subscribed(_):
break
case .update(let validatorDetailsUpdate):
updateCount += 1
if updateCount == 1 {
XCTAssertNotNil(validatorDetailsUpdate.validatorDetails)
print("Validator details received.")
} else {
print("Validator details diff received.")
if updateCount == 3 {
service.unsubscribe()
}
}
case .unsubscribed:
break
}
}.store(in: &cancellables)
waitForExpectations(timeout: 60 * 3)
XCTAssertNil(error)
}
static var allTests = [
("testValidatorDetailsSubscription", testValidatorDetailsSubscription),
]
}