@@ -13,7 +13,7 @@ class EthereumConvenienceMethodsTests: XCTestCase {
13
13
var mockEthereumDelegate : MockEthereumDelegate !
14
14
var trackEventMock : ( ( Event , [ String : Any ] ) -> Void ) !
15
15
var ethereum : Ethereum !
16
- var mockInfuraProvider : MockInfuraProvider !
16
+ var mockReadOnlyRPCProvider : MockReadOnlyRPCProvider !
17
17
let infuraApiKey = " testApiKey "
18
18
var store : SecureStore !
19
19
var trackedEvents : [ ( Event , [ String : Any ] ) ] = [ ]
@@ -27,15 +27,18 @@ class EthereumConvenienceMethodsTests: XCTestCase {
27
27
28
28
store = Keychain ( service: " com.example.ethconvenience " )
29
29
mockNetwork = MockNetwork ( )
30
- mockInfuraProvider = MockInfuraProvider ( infuraAPIKey: infuraApiKey, network: mockNetwork)
30
+ mockReadOnlyRPCProvider = MockReadOnlyRPCProvider (
31
+ infuraAPIKey: infuraApiKey,
32
+ readonlyRPCMap: [ : ] ,
33
+ network: mockNetwork)
31
34
mockEthereumDelegate = MockEthereumDelegate ( )
32
35
EthereumWrapper . shared. ethereum = nil
33
36
SDKWrapper . shared. sdk = nil
34
37
ethereum = Ethereum . shared (
35
38
transport: . socket,
36
39
store: store,
37
40
commClientFactory: mockCommClientFactory,
38
- infuraProvider : mockInfuraProvider ,
41
+ readOnlyRPCProvider : mockReadOnlyRPCProvider ,
39
42
trackEvent: trackEventMock)
40
43
ethereum. delegate = mockEthereumDelegate
41
44
}
@@ -46,7 +49,7 @@ class EthereumConvenienceMethodsTests: XCTestCase {
46
49
mockNetwork = nil
47
50
store. deleteAll ( )
48
51
mockEthereumDelegate = nil
49
- mockInfuraProvider = nil
52
+ mockReadOnlyRPCProvider = nil
50
53
mockCommClientFactory = nil
51
54
EthereumWrapper . shared. ethereum = nil
52
55
SDKWrapper . shared. sdk = nil
@@ -55,93 +58,93 @@ class EthereumConvenienceMethodsTests: XCTestCase {
55
58
56
59
func testGetChainId( ) async {
57
60
ethereum. connected = true
58
- ethereum. infuraProvider = nil
59
61
let chainId = " 0x1 "
60
62
61
63
let expectation = self . expectation ( description: " Request should return chainId " )
62
64
performSuccessfulTask (
63
65
ethereum. getChainId,
64
66
expectedValue: chainId,
65
67
expectation: expectation)
68
+ mockReadOnlyRPCProvider. expectation = expectation
66
69
sendResultAndAwait ( chainId, method: . ethChainId)
67
70
await fulfillment ( of: [ expectation] , timeout: 2.0 )
68
71
}
69
72
70
73
func testGetEthAccounts( ) async {
71
74
ethereum. connected = true
72
- ethereum. infuraProvider = nil
73
75
let accounts = [ " 0x1234 " ]
74
76
75
77
let expectation = self . expectation ( description: " Request should return accounts " )
76
78
performSuccessfulTaskCollectionResult (
77
79
ethereum. getEthAccounts,
78
80
expectedValue: accounts,
79
81
expectation: expectation)
82
+ mockReadOnlyRPCProvider. expectation = expectation
80
83
sendResultAndAwait ( accounts, method: . ethAccounts)
81
84
await fulfillment ( of: [ expectation] , timeout: 2.0 )
82
85
}
83
86
84
87
func testGetEthGasPrice( ) async {
85
88
ethereum. connected = true
86
- ethereum. infuraProvider = nil
87
89
let balance = " 0x1000 "
88
90
89
91
let expectation = self . expectation ( description: " Request should return gas price " )
90
92
performSuccessfulTask ( ethereum. getEthGasPrice,
91
93
expectedValue: balance,
92
94
expectation: expectation)
95
+ mockReadOnlyRPCProvider. expectation = expectation
93
96
sendResultAndAwait ( balance, method: . ethGasPrice)
94
97
await fulfillment ( of: [ expectation] , timeout: 2.0 )
95
98
}
96
99
97
100
func testGetEthBalance( ) async {
98
101
ethereum. connected = true
99
- ethereum. infuraProvider = nil
100
102
let balance = " 0x1000 "
101
103
102
104
let expectation = self . expectation ( description: " Request should return balance " )
103
105
performSuccessfulTask ( {
104
106
await self . ethereum. getEthBalance ( address: " 0x1234 " , block: " latest " )
105
107
} , expectedValue: balance, expectation: expectation)
108
+ mockReadOnlyRPCProvider. expectation = expectation
106
109
sendResultAndAwait ( balance, method: . ethGetBalance)
107
110
await fulfillment ( of: [ expectation] , timeout: 2.0 )
108
111
}
109
112
110
113
func testGetEthBlockNumber( ) async {
111
114
ethereum. connected = true
112
- ethereum. infuraProvider = nil
113
115
let blockNumber = " 0x10 "
114
116
115
117
let expectation = self . expectation ( description: " Request should return block number " )
116
118
performSuccessfulTask ( {
117
119
await self . ethereum. getEthBlockNumber ( )
118
120
} , expectedValue: blockNumber, expectation: expectation)
121
+ mockReadOnlyRPCProvider. expectation = expectation
119
122
sendResultAndAwait ( blockNumber, method: . ethBlockNumber)
120
123
await fulfillment ( of: [ expectation] , timeout: 2.0 )
121
124
}
122
125
123
126
func testGetEthEstimateGas( ) async {
124
127
ethereum. connected = true
125
- ethereum. infuraProvider = nil
126
128
let gasEstimate = " 0x5208 "
127
129
128
130
let expectation = self . expectation ( description: " Request should return gas estimate " )
129
131
performSuccessfulTask ( {
130
132
await self . ethereum. getEthEstimateGas ( )
131
133
} , expectedValue: gasEstimate, expectation: expectation)
134
+ mockReadOnlyRPCProvider. expectation = expectation
132
135
sendResultAndAwait ( gasEstimate, method: . ethEstimateGas)
133
136
await fulfillment ( of: [ expectation] , timeout: 2.0 )
134
137
}
135
138
136
139
func testGetWeb3ClientVersion( ) async {
137
140
ethereum. connected = true
138
- ethereum. infuraProvider = nil
139
141
let web3Version = " Geth/v1.8.23-stable "
140
142
141
143
let expectation = self . expectation ( description: " Request should return web3 version " )
142
144
performSuccessfulTask ( {
143
145
await self . ethereum. getWeb3ClientVersion ( )
144
146
} , expectedValue: web3Version, expectation: expectation)
147
+ mockReadOnlyRPCProvider. expectation = expectation
145
148
sendResultAndAwait ( web3Version, method: . web3ClientVersion)
146
149
await fulfillment ( of: [ expectation] , timeout: 2.0 )
147
150
}
@@ -184,52 +187,54 @@ class EthereumConvenienceMethodsTests: XCTestCase {
184
187
185
188
func testSendRawTransaction( ) async {
186
189
ethereum. connected = true
187
- ethereum. infuraProvider = nil
188
190
let transactionHash = " 0x345678 "
189
191
190
192
let expectation = self . expectation ( description: " Request should return transaction hash result " )
191
193
performSuccessfulTask ( {
192
194
await self . ethereum. sendRawTransaction ( signedTransaction: " signedTx " )
193
195
} , expectedValue: transactionHash, expectation: expectation)
196
+ mockReadOnlyRPCProvider. response = transactionHash
197
+ mockReadOnlyRPCProvider. expectation = expectation
194
198
sendResultAndAwait ( transactionHash, method: . ethSendRawTransaction)
195
199
await fulfillment ( of: [ expectation] , timeout: 2.0 )
196
200
}
197
201
198
202
func testGetBlockTransactionCountByNumber( ) async {
199
203
ethereum. connected = true
200
- ethereum. infuraProvider = nil
201
204
let transactionCount = " 0x20 "
202
205
203
206
let expectation = self . expectation ( description: " Request should return transaction count " )
207
+ mockReadOnlyRPCProvider. response = transactionCount
208
+
204
209
performSuccessfulTask ( {
205
210
await self . ethereum. getBlockTransactionCountByNumber ( blockNumber: " 0x10 " )
206
211
} , expectedValue: transactionCount, expectation: expectation)
212
+
207
213
sendResultAndAwait ( transactionCount, method: . ethGetBlockTransactionCountByNumber)
208
- await fulfillment ( of: [ expectation] , timeout: 2 .0)
214
+ await fulfillment ( of: [ expectation] , timeout: 20 .0)
209
215
}
210
216
211
217
func testGetBlockTransactionCountByHash( ) async {
212
218
ethereum. connected = true
213
- ethereum. infuraProvider = nil
214
219
let transactionCount = " 0x30 "
215
220
216
221
let expectation = self . expectation ( description: " Request should return transaction count " )
217
222
performSuccessfulTask ( {
218
223
await self . ethereum. getBlockTransactionCountByHash ( blockHash: " 0xabcdef " )
219
224
} , expectedValue: transactionCount, expectation: expectation)
225
+ mockReadOnlyRPCProvider. response = transactionCount
226
+ mockReadOnlyRPCProvider. expectation = expectation
220
227
sendResultAndAwait ( transactionCount, method: . ethGetBlockTransactionCountByHash)
221
228
await fulfillment ( of: [ expectation] , timeout: 2.0 )
222
229
}
223
230
224
231
func testGetTransactionCount( ) async {
225
232
ethereum. connected = true
226
- ethereum. infuraProvider = nil
227
233
let transactionCount = " 0x40 "
228
234
229
235
let expectation = self . expectation ( description: " Request should return transaction count " )
230
- performSuccessfulTask ( {
231
- await self . ethereum. getTransactionCount ( address: " 0x1234 " , tagOrblockNumber: " latest " )
232
- } , expectedValue: transactionCount, expectation: expectation)
236
+ let result = await self . ethereum. getTransactionCount ( address: " 0x1234 " , tagOrblockNumber: " latest " )
237
+ mockReadOnlyRPCProvider. response = transactionCount
233
238
sendResultAndAwait ( transactionCount, method: . ethGetTransactionCount)
234
239
await fulfillment ( of: [ expectation] , timeout: 2.0 )
235
240
}
0 commit comments