-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathChainRegistryIntegrationTests.swift
125 lines (125 loc) · 4.63 KB
/
ChainRegistryIntegrationTests.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
//import XCTest
//@testable import fearless
//import SSFUtils
//import RobinHood
//import IrohaCrypto
//
//class ChainRegistryIntegrationTests: XCTestCase {
// func testNetworkConnection() {
// let address = "12hAtDZJGt4of3m2GqZcUCVAjZPALfvPwvtUTFZPQUbdX1Ud"
//
// let chainRegistry = ChainRegistryFactory.createDefaultRegistry(
// from: SubstrateStorageTestFacade()
// )
//
// chainRegistry.syncUp()
//
// var availableChains: [ChainModel.Id: ChainModel] = [:]
//
// let syncExpectation = XCTestExpectation()
//
// chainRegistry.chainsSubscribe(self, runningInQueue: .main) { changes in
// for change in changes {
// switch change {
// case let .insert(chain):
// availableChains[chain.chainId] = chain
// case let .update(chain):
// availableChains[chain.chainId] = chain
// case let .delete(deletedIdentifier):
// availableChains[deletedIdentifier] = nil
// }
// }
//
// if !changes.isEmpty {
// syncExpectation.fulfill()
// }
// }
//
// wait(for: [syncExpectation], timeout: 10)
//
// guard !availableChains.isEmpty else {
// XCTFail("Unexpected empty chains")
// return
// }
//
// Logger.shared.info("Did receive chains: \(availableChains)")
//
// let storageOperationFactory = StorageRequestFactory(
// remoteFactory: StorageKeyFactory(),
// operationManager: OperationManagerFacade.sharedManager
// )
//
// let addressFactory = SS58AddressFactory()
// let accountId = try! addressFactory.accountId(from: address)
//
// let operationQueue = OperationQueue()
//
// for chain in availableChains.values {
// guard let connection = chainRegistry.getConnection(for: chain.chainId) else {
// XCTFail("Unexpected missing connection for chain: \(chain.chainId)")
// return
// }
//
// guard let runtimeProvider = chainRegistry.getRuntimeProvider(for: chain.chainId) else {
// XCTFail("Unexpected missing runtime provider: \(chain.chainId)")
// return
// }
//
// guard let utilityAsset = chain.assets.first(where: { $0.isUtility }) else {
// XCTFail("Can't find utility asset: \(chain.chainId)")
// return
// }
//
// let factoryOperation = runtimeProvider.fetchCoderFactoryOperation()
//
// let queryWrapper: CompoundOperationWrapper<[StorageResponse<AccountInfo>]> = storageOperationFactory.queryItems(
// engine: connection,
// keyParams: {
// [accountId]
// }, factory: {
// try factoryOperation.extractNoCancellableResultData()
// }, storagePath: .account
// )
//
// queryWrapper.addDependency(operations: [factoryOperation])
//
// let mapOperation: BaseOperation<AccountInfo?> = ClosureOperation {
// guard let response = try queryWrapper.targetOperation.extractNoCancellableResultData()
// .first else {
// throw BaseOperationError.unexpectedDependentResult
// }
//
// return response.value
// }
//
// mapOperation.addDependency(queryWrapper.targetOperation)
//
// let wrapper = CompoundOperationWrapper(
// targetOperation: mapOperation,
// dependencies: [factoryOperation] + queryWrapper.allOperations)
//
// let queryExpectation = XCTestExpectation()
//
// wrapper.targetOperation.completionBlock = {
// queryExpectation.fulfill()
// }
//
// operationQueue.addOperations(wrapper.allOperations, waitUntilFinished: true)
//
// do {
// let accountInfo = try wrapper.targetOperation.extractNoCancellableResultData()
// let available = accountInfo.map {
// Decimal.fromSubstrateAmount(
// $0.data.available,
// precision: Int16(utilityAsset.asset.precision)
// ) ?? 0.0
// } ?? 0.0
//
// let balanceString = available.stringWithPointSeparator + " \(utilityAsset.assetId)"
// Logger.shared.info("Balance: \(balanceString)")
// } catch {
// Logger.shared.error("Couldn't fetch from chain \(chain.chainId): \(error)")
// }
// }
// }
//}