17
17
package modules
18
18
19
19
import (
20
+ "errors"
20
21
"fmt"
21
22
"math/big"
22
23
"os"
@@ -89,7 +90,7 @@ func newNetworkService(t *testing.T) *network.Service {
89
90
func TestSystemModule_Health (t * testing.T ) {
90
91
net := newNetworkService (t )
91
92
net .Stop ()
92
- sys := NewSystemModule (net , nil , nil , nil , nil )
93
+ sys := NewSystemModule (net , nil , nil , nil , nil , nil )
93
94
94
95
res := & SystemHealthResponse {}
95
96
err := sys .Health (nil , nil , res )
@@ -103,7 +104,7 @@ func TestSystemModule_Health(t *testing.T) {
103
104
// Test RPC's System.NetworkState() response
104
105
func TestSystemModule_NetworkState (t * testing.T ) {
105
106
net := newNetworkService (t )
106
- sys := NewSystemModule (net , nil , nil , nil , nil )
107
+ sys := NewSystemModule (net , nil , nil , nil , nil , nil )
107
108
108
109
res := & SystemNetworkStateResponse {}
109
110
err := sys .NetworkState (nil , nil , res )
@@ -120,7 +121,7 @@ func TestSystemModule_NetworkState(t *testing.T) {
120
121
func TestSystemModule_Peers (t * testing.T ) {
121
122
net := newNetworkService (t )
122
123
net .Stop ()
123
- sys := NewSystemModule (net , nil , nil , nil , nil )
124
+ sys := NewSystemModule (net , nil , nil , nil , nil , nil )
124
125
125
126
res := & SystemPeersResponse {}
126
127
err := sys .Peers (nil , nil , res )
@@ -133,7 +134,7 @@ func TestSystemModule_Peers(t *testing.T) {
133
134
134
135
func TestSystemModule_NodeRoles (t * testing.T ) {
135
136
net := newNetworkService (t )
136
- sys := NewSystemModule (net , nil , nil , nil , nil )
137
+ sys := NewSystemModule (net , nil , nil , nil , nil , nil )
137
138
expected := []interface {}{"Full" }
138
139
139
140
var res []interface {}
@@ -165,7 +166,7 @@ func newMockSystemAPI() *mocks.MockSystemAPI {
165
166
}
166
167
167
168
func TestSystemModule_Chain (t * testing.T ) {
168
- sys := NewSystemModule (nil , newMockSystemAPI (), nil , nil , nil )
169
+ sys := NewSystemModule (nil , newMockSystemAPI (), nil , nil , nil , nil )
169
170
170
171
res := new (string )
171
172
err := sys .Chain (nil , nil , res )
@@ -176,14 +177,14 @@ func TestSystemModule_Chain(t *testing.T) {
176
177
func TestSystemModule_ChainType (t * testing.T ) {
177
178
api := newMockSystemAPI ()
178
179
179
- sys := NewSystemModule (nil , api , nil , nil , nil )
180
+ sys := NewSystemModule (nil , api , nil , nil , nil , nil )
180
181
181
182
res := new (string )
182
183
sys .ChainType (nil , nil , res )
183
184
require .Equal (t , testGenesisData .ChainType , * res )
184
185
}
185
186
func TestSystemModule_Name (t * testing.T ) {
186
- sys := NewSystemModule (nil , newMockSystemAPI (), nil , nil , nil )
187
+ sys := NewSystemModule (nil , newMockSystemAPI (), nil , nil , nil , nil )
187
188
188
189
res := new (string )
189
190
err := sys .Name (nil , nil , res )
@@ -192,7 +193,7 @@ func TestSystemModule_Name(t *testing.T) {
192
193
}
193
194
194
195
func TestSystemModule_Version (t * testing.T ) {
195
- sys := NewSystemModule (nil , newMockSystemAPI (), nil , nil , nil )
196
+ sys := NewSystemModule (nil , newMockSystemAPI (), nil , nil , nil , nil )
196
197
197
198
res := new (string )
198
199
err := sys .Version (nil , nil , res )
@@ -201,7 +202,7 @@ func TestSystemModule_Version(t *testing.T) {
201
202
}
202
203
203
204
func TestSystemModule_Properties (t * testing.T ) {
204
- sys := NewSystemModule (nil , newMockSystemAPI (), nil , nil , nil )
205
+ sys := NewSystemModule (nil , newMockSystemAPI (), nil , nil , nil , nil )
205
206
206
207
expected := map [string ]interface {}(nil )
207
208
@@ -318,7 +319,7 @@ func setupSystemModule(t *testing.T) *SystemModule {
318
319
core := newCoreService (t , chain )
319
320
// TODO (ed) add transactions to txQueue and add test for those
320
321
txQueue := state .NewTransactionState ()
321
- return NewSystemModule (net , nil , core , chain .Storage , txQueue )
322
+ return NewSystemModule (net , nil , core , chain .Storage , txQueue , nil )
322
323
}
323
324
324
325
func newCoreService (t * testing.T , srvc * state.Service ) * core.Service {
@@ -356,6 +357,41 @@ func newCoreService(t *testing.T, srvc *state.Service) *core.Service {
356
357
return core .NewTestService (t , cfg )
357
358
}
358
359
360
+ func TestSyncState (t * testing.T ) {
361
+ fakeCommonHash := common .NewHash ([]byte ("fake" ))
362
+ fakeHeader := & types.Header {
363
+ Number : big .NewInt (int64 (49 )),
364
+ }
365
+
366
+ blockapiMock := new (mocks.MockBlockAPI )
367
+ blockapiMock .On ("BestBlockHash" ).Return (fakeCommonHash )
368
+ blockapiMock .On ("GetHeader" , fakeCommonHash ).Return (fakeHeader , nil ).Once ()
369
+
370
+ netapiMock := new (mocks.MockNetworkAPI )
371
+ netapiMock .On ("HighestBlock" ).Return (int64 (90 ))
372
+ netapiMock .On ("StartingBlock" ).Return (int64 (10 ))
373
+
374
+ sysmodule := new (SystemModule )
375
+ sysmodule .blockAPI = blockapiMock
376
+ sysmodule .networkAPI = netapiMock
377
+
378
+ var res SyncStateResponse
379
+ err := sysmodule .SyncState (nil , nil , & res )
380
+ require .NoError (t , err )
381
+
382
+ expectedSyncState := SyncStateResponse {
383
+ CurrentBlock : uint32 (49 ),
384
+ HighestBlock : uint32 (90 ),
385
+ StartingBlock : uint32 (10 ),
386
+ }
387
+
388
+ require .Equal (t , expectedSyncState , res )
389
+
390
+ blockapiMock .On ("GetHeader" , fakeCommonHash ).Return (nil , errors .New ("Problems while getting header" )).Once ()
391
+ err = sysmodule .SyncState (nil , nil , nil )
392
+ require .Error (t , err )
393
+ }
394
+
359
395
func TestLocalListenAddresses (t * testing.T ) {
360
396
ma , err := multiaddr .NewMultiaddr ("/ip4/127.0.0.1/tcp/7001/p2p/12D3KooWCYyh5xoAc5oRyiGU4d9ktcqFQ23JjitNFR6bEcbw7YdN" )
361
397
require .NoError (t , err )
0 commit comments