-
Notifications
You must be signed in to change notification settings - Fork 0
/
ReportServiceTests.swift
280 lines (256 loc) · 8.63 KB
/
ReportServiceTests.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
import Combine
import XCTest
@testable import SubVTData
final class ReportServiceTests: BaseTest {
private var cancellables: Set<AnyCancellable>!
private let service = ReportService()
private let validatorAccountId = AccountId(
hex: "0xa00505eb2a4607f27837f57232f0c456602e39540582685b4f58cde293f1a116"
)
override func setUp() {
super.setUp()
cancellables = []
}
func test01GetSingleEraReport() {
testServiceCall(
publisher: service.getEraReport(
startEraIndex: 3391
)
) {
(reports, error) in
XCTAssertNil(error)
XCTAssertEqual(1, reports?.count ?? 0)
let report = reports![0]
XCTAssertTrue(report.activeValidatorCount > 0)
XCTAssertTrue(report.inactiveValidatorCount > 0)
}
}
func test02GetMultipleEraReport() {
testServiceCall(
publisher: service.getEraReport(
startEraIndex: 3391,
endEraIndex: 3400
)
) {
(reports, error) in
XCTAssertNil(error)
XCTAssertEqual(10, reports?.count ?? 0)
}
}
func test03GetSingleEraValidatorReport() {
testServiceCall(
publisher: service.getEraValidatorReport(
validatorAccountId: validatorAccountId,
startEraIndex: 3391
)
) {
(reports, error) in
XCTAssertNil(error)
XCTAssertEqual(1, reports?.count ?? 0)
}
}
func test04GetMultipleEraValidatorReport() {
testServiceCall(
publisher: service.getEraValidatorReport(
validatorAccountId: validatorAccountId,
startEraIndex: 3391,
endEraIndex: 3400
)
) {
(reports, error) in
XCTAssertNil(error)
XCTAssertEqual(10, reports?.count ?? 0)
}
}
func test05GetValidatorSummaryReport() {
testServiceCall(
publisher: service.getValidatorSummaryReport(
validatorAccountId: validatorAccountId
)
) {
[weak self]
(report, error) in
guard let self = self else { return }
XCTAssertNil(error)
XCTAssertEqual(report?.validatorSummary.accountId, self.validatorAccountId)
}
}
func test05GetValidatorDetailsReport() {
testServiceCall(
publisher: service.getValidatorDetailsReport(
validatorAccountId: validatorAccountId
)
) {
[weak self]
(report, error) in
guard let self = self else { return }
XCTAssertNil(error)
XCTAssertEqual(report?.validatorDetails.account.id, self.validatorAccountId)
}
}
func test06GetValidatorListReport() {
testServiceCall(
publisher: service.getValidatorListReport()
) {
(report, error) in
XCTAssertNil(error)
XCTAssertTrue(report?.validators.count ?? 0 > 0)
}
}
func test07GetActiveValidatorListReport() {
testServiceCall(
publisher: service.getActiveValidatorListReport()
) {
(report, error) in
XCTAssertNil(error)
XCTAssertTrue(report?.validators.count ?? 0 > 0)
}
}
func test08GetInactiveValidatorListReport() {
testServiceCall(
publisher: service.getInactiveValidatorListReport()
) {
(report, error) in
XCTAssertNil(error)
XCTAssertTrue(report?.validators.count ?? 0 > 0)
}
}
func test09SearchValidators() {
testServiceCall(
publisher: service.searchValidators(query: "heli")
) {
(report, error) in
XCTAssertNil(error)
XCTAssertTrue(report?.count ?? 0 > 0)
}
}
func test10GetOneKVNominatorSummaries() {
testServiceCall(
publisher: service.getOneKVNominatorSummaries()
) {
(report, error) in
XCTAssertNil(error)
XCTAssertTrue(report?.count ?? 0 > 0)
}
}
func test10GetCurrentEra() {
testServiceCall(
publisher: service.getCurrentEra()
) {
(era, error) in
XCTAssertNil(error)
XCTAssertTrue(era?.index ?? 0 > 0)
}
}
func test11GetCurrentEra() {
testServiceCall(
publisher: service.getCurrentEra()
) {
(session, error) in
XCTAssertNil(error)
}
}
func test12GetAllEras() {
testServiceCall(
publisher: service.getAllEras()
) {
(eras, error) in
XCTAssertNil(error)
XCTAssertTrue(eras?.count ?? 0 > 0)
}
}
func test13GetValidatorEraRewardReport() {
testServiceCall(
publisher: service.getValidatorEraRewardReport(validatorAccountId: validatorAccountId)
) {
(reports, error) in
XCTAssertNil(error)
XCTAssertTrue(reports?.count ?? 0 > 0)
}
}
func test14GetValidatorEraPayoutReport() {
testServiceCall(
publisher: service.getValidatorEraPayoutReport(validatorAccountId: validatorAccountId)
) {
(reports, error) in
XCTAssertNil(error)
XCTAssertTrue(reports?.count ?? 0 > 0)
}
}
func test15GetSingleSessionValidatorReport() {
testServiceCall(
publisher: service.getSessionValidatorReport(
validatorAccountId: validatorAccountId,
startSessionIndex: 39931
)
) {
(reports, error) in
XCTAssertNil(error)
XCTAssertEqual(1, reports?.count ?? 0)
let report = reports![0]
XCTAssertNotNil(report.paraVotesSummary)
XCTAssertNil(report.heartbeatEvent)
}
}
func test16GetMultipleSessionValidatorReport() {
testServiceCall(
publisher: service.getSessionValidatorReport(
validatorAccountId: validatorAccountId,
startSessionIndex: 39950,
endSessionIndex: 39959
)
) {
(reports, error) in
XCTAssertNil(error)
XCTAssertEqual(10, reports?.count ?? 0)
}
}
func test17GetCurrentSession() {
testServiceCall(
publisher: service.getCurrentSession()
) {
(session, error) in
XCTAssertNil(error)
}
}
func test18GetNetworkStatus() {
testServiceCall(
publisher: service.getNetworkStatus()
) {
(networkStatus, error) in
XCTAssertNil(error)
}
}
func test19GetMonthlyIncome() {
testServiceCall(
publisher: service.getMonthlyIncomeReport(
rewardeeAccountId: validatorAccountId
)
) {
(report, error) in
print("\(report!.monthlyIncome[0].income)")
XCTAssertNil(error)
}
}
static var allTests = [
("test01GetSingleEraReport", test01GetSingleEraReport),
("test02GetMultipleEraReport", test02GetMultipleEraReport),
("test03GetSingleEraValidatorReport", test03GetSingleEraValidatorReport),
("test04GetMultipleEraValidatorReport", test04GetMultipleEraValidatorReport),
("test05GetValidatorDetailsReport", test05GetValidatorDetailsReport),
("test06GetValidatorListReport", test06GetValidatorListReport),
("test07GetActiveValidatorListReport", test07GetActiveValidatorListReport),
("test08GetInactiveValidatorListReport", test08GetInactiveValidatorListReport),
("test09SearchValidators", test09SearchValidators),
("test10GetOneKVNominatorSummaries", test10GetOneKVNominatorSummaries),
("test11GetCurrentEra", test11GetCurrentEra),
("test12GetAllEras", test12GetAllEras),
("test13GetValidatorEraRewardReport", test13GetValidatorEraRewardReport),
("test14GetValidatorEraPayoutReport", test14GetValidatorEraPayoutReport),
("test15GetSingleSessionValidatorReport", test15GetSingleSessionValidatorReport),
("test16GetMultipleSessionValidatorReport", test16GetMultipleSessionValidatorReport),
("test17GetCurrentSession", test17GetCurrentSession),
("test18GetNetworkStatus", test18GetNetworkStatus),
("test19GetMonthlyIncome", test19GetMonthlyIncome),
]
}