3232 testcache * BlockCache
3333)
3434
35+ const (
36+ testTxid = "1234000000000000000000000000000000000000000000000000000000000000"
37+ testBlockid40 = "0000000000000000000000000000000000000000000000000000000000380640"
38+ testBlockid41 = "0000000000000000000000000000000000000000000000000000000000380641"
39+ testBlockid42 = "0000000000000000000000000000000000000000000000000000000000380642"
40+ )
41+
3542// TestMain does common setup that's shared across multiple tests
3643func TestMain (m * testing.M ) {
3744 output , err := os .OpenFile ("test-log" , os .O_CREATE | os .O_TRUNC | os .O_WRONLY , 0644 )
@@ -196,36 +203,36 @@ func blockIngestorStub(method string, params []json.RawMessage) (json.RawMessage
196203 case 1 :
197204 checkSleepMethod (0 , 0 , "getbestblockhash" , method )
198205 // This hash doesn't matter, won't match anything
199- r , _ := json .Marshal ("010101" )
206+ r , _ := json .Marshal (strings . Repeat ( "01" , 32 ) )
200207 return r , nil
201208 case 2 :
202209 checkSleepMethod (0 , 0 , "getblock" , method )
203210 if arg != "380640" {
204211 testT .Fatal ("incorrect height requested" )
205212 }
206213 // height 380640
207- return []byte ("{\" Tx\" : [\" 00 \" ], \" Hash\" : \" 0000380640 \" }" ), nil
214+ return []byte ("{\" Tx\" : [\" " + testTxid + " \" ], \" Hash\" : \" " + testBlockid40 + " \" }" ), nil
208215 case 3 :
209216 checkSleepMethod (0 , 0 , "getblock" , method )
210- if arg != "0000380640" {
217+ if arg != testBlockid40 {
211218 testT .Fatal ("incorrect hash requested" )
212219 }
213220 return blocks [0 ], nil
214221 case 4 :
215222 checkSleepMethod (0 , 0 , "getbestblockhash" , method )
216223 // This hash doesn't matter, won't match anything
217- r , _ := json .Marshal ("010101" )
224+ r , _ := json .Marshal (strings . Repeat ( "01" , 32 ) )
218225 return r , nil
219226 case 5 :
220227 checkSleepMethod (0 , 0 , "getblock" , method )
221228 if arg != "380641" {
222229 testT .Fatal ("incorrect height requested" )
223230 }
224231 // height 380641
225- return []byte ("{\" Tx\" : [\" 00 \" ], \" Hash\" : \" 0000380641 \" }" ), nil
232+ return []byte ("{\" Tx\" : [\" " + testTxid + " \" ], \" Hash\" : \" " + testBlockid41 + " \" }" ), nil
226233 case 6 :
227234 checkSleepMethod (0 , 0 , "getblock" , method )
228- if arg != "0000380641" {
235+ if arg != testBlockid41 {
229236 testT .Fatal ("incorrect hash requested" )
230237 }
231238 return blocks [1 ], nil
@@ -244,18 +251,18 @@ func blockIngestorStub(method string, params []json.RawMessage) (json.RawMessage
244251 case 9 :
245252 // Simulate new block (any non-matching hash will do)
246253 checkSleepMethod (2 , 4 , "getbestblockhash" , method )
247- r , _ := json .Marshal ("aabb" )
254+ r , _ := json .Marshal (strings . Repeat ( "ab" , 32 ) )
248255 return r , nil
249256 case 10 :
250257 checkSleepMethod (2 , 4 , "getblock" , method )
251258 if arg != "380642" {
252259 testT .Fatal ("incorrect height requested" )
253260 }
254261 // height 380642
255- return []byte ("{\" Tx\" : [\" 00 \" ], \" Hash\" : \" 0000380642 \" }" ), nil
262+ return []byte ("{\" Tx\" : [\" " + testTxid + " \" ], \" Hash\" : \" " + testBlockid42 + " \" }" ), nil
256263 case 11 :
257264 checkSleepMethod (2 , 4 , "getblock" , method )
258- if arg != "0000380642" {
265+ if arg != testBlockid42 {
259266 testT .Fatal ("incorrect hash requested" )
260267 }
261268 return blocks [2 ], nil
@@ -270,7 +277,7 @@ func blockIngestorStub(method string, params []json.RawMessage) (json.RawMessage
270277 // simulate a 1-block reorg, new version (replacement) of 380642
271278 checkSleepMethod (3 , 6 , "getbestblockhash" , method )
272279 // hash doesn't matter, just something that doesn't match
273- r , _ := json .Marshal ("4545" )
280+ r , _ := json .Marshal (strings . Repeat ( "45" , 32 ) )
274281 return r , nil
275282 case 14 :
276283 // It thinks there may simply be a new block, but we'll say
@@ -284,7 +291,7 @@ func blockIngestorStub(method string, params []json.RawMessage) (json.RawMessage
284291 // It will re-ask the best hash (let's make no change)
285292 checkSleepMethod (3 , 6 , "getbestblockhash" , method )
286293 // hash doesn't matter, just something that doesn't match
287- r , _ := json .Marshal ("4545" )
294+ r , _ := json .Marshal (strings . Repeat ( "45" , 32 ) )
288295 return r , nil
289296 case 16 :
290297 // It should have backed up one block
@@ -293,10 +300,10 @@ func blockIngestorStub(method string, params []json.RawMessage) (json.RawMessage
293300 testT .Fatal ("incorrect height requested" )
294301 }
295302 // height 380642
296- return []byte ("{\" Tx\" : [\" 00 \" ], \" Hash\" : \" 0000380642 \" }" ), nil
303+ return []byte ("{\" Tx\" : [\" " + testTxid + " \" ], \" Hash\" : \" " + testBlockid42 + " \" }" ), nil
297304 case 17 :
298305 checkSleepMethod (3 , 6 , "getblock" , method )
299- if arg != "0000380642" {
306+ if arg != testBlockid42 {
300307 testT .Fatal ("incorrect height requested" )
301308 }
302309 return blocks [2 ], nil
@@ -305,7 +312,7 @@ func blockIngestorStub(method string, params []json.RawMessage) (json.RawMessage
305312 // we'll make it back up 2 blocks (rather than one)
306313 checkSleepMethod (3 , 6 , "getbestblockhash" , method )
307314 // hash doesn't matter, just something that doesn't match
308- r , _ := json .Marshal ("5656" )
315+ r , _ := json .Marshal (strings . Repeat ( "56" , 32 ) )
309316 return r , nil
310317 case 19 :
311318 // It thinks there may simply be a new block, but we'll say
@@ -318,7 +325,7 @@ func blockIngestorStub(method string, params []json.RawMessage) (json.RawMessage
318325 case 20 :
319326 checkSleepMethod (3 , 6 , "getbestblockhash" , method )
320327 // hash doesn't matter, just something that doesn't match
321- r , _ := json .Marshal ("5656" )
328+ r , _ := json .Marshal (strings . Repeat ( "56" , 32 ) )
322329 return r , nil
323330 case 21 :
324331 // Like case 13, it should have backed up one block, but
@@ -331,18 +338,18 @@ func blockIngestorStub(method string, params []json.RawMessage) (json.RawMessage
331338 case 22 :
332339 checkSleepMethod (3 , 6 , "getbestblockhash" , method )
333340 // hash doesn't matter, just something that doesn't match
334- r , _ := json .Marshal ("5656" )
341+ r , _ := json .Marshal (strings . Repeat ( "56" , 32 ) )
335342 return r , nil
336343 case 23 :
337344 // It should have backed up one more
338345 checkSleepMethod (3 , 6 , "getblock" , method )
339346 if arg != "380641" {
340347 testT .Fatal ("incorrect height requested" )
341348 }
342- return []byte ("{\" Tx\" : [\" 00 \" ], \" Hash\" : \" 0000380641 \" }" ), nil
349+ return []byte ("{\" Tx\" : [\" " + testTxid + " \" ], \" Hash\" : \" " + testBlockid41 + " \" }" ), nil
343350 case 24 :
344351 checkSleepMethod (3 , 6 , "getblock" , method )
345- if arg != "0000380641" {
352+ if arg != testBlockid41 {
346353 testT .Fatal ("incorrect height requested" )
347354 }
348355 return blocks [1 ], nil
@@ -385,17 +392,17 @@ func getblockStub(method string, params []json.RawMessage) (json.RawMessage, err
385392 step ++
386393 switch step {
387394 case 1 :
388- return []byte ("{\" Tx\" : [\" 00 \" ], \" Hash\" : \" 0000380640 \" }" ), nil
395+ return []byte ("{\" Tx\" : [\" " + testTxid + " \" ], \" Hash\" : \" " + testBlockid40 + " \" }" ), nil
389396 case 2 :
390- if arg != "0000380640" {
397+ if arg != testBlockid40 {
391398 testT .Error ("unexpected hash" )
392399 }
393400 // Sunny-day
394401 return blocks [0 ], nil
395402 case 3 :
396- return []byte ("{\" Tx\" : [\" 00 \" ], \" Hash\" : \" 0000380641 \" }" ), nil
403+ return []byte ("{\" Tx\" : [\" " + testTxid + " \" ], \" Hash\" : \" " + testBlockid41 + " \" }" ), nil
397404 case 4 :
398- if arg != "0000380641" {
405+ if arg != testBlockid41 {
399406 testT .Error ("unexpected hash" )
400407 }
401408 // Sunny-day
@@ -475,9 +482,9 @@ func getblockStubReverse(method string, params []json.RawMessage) (json.RawMessa
475482 testT .Error ("unexpected height" )
476483 }
477484 // Sunny-day
478- return []byte ("{\" Tx\" : [\" 00 \" ], \" Hash\" : \" 0000380642 \" }" ), nil
485+ return []byte ("{\" Tx\" : [\" " + testTxid + " \" ], \" Hash\" : \" " + testBlockid42 + " \" }" ), nil
479486 case 2 :
480- if arg != "0000380642" {
487+ if arg != testBlockid42 {
481488 testT .Error ("unexpected hash" )
482489 }
483490 return blocks [2 ], nil
@@ -486,9 +493,9 @@ func getblockStubReverse(method string, params []json.RawMessage) (json.RawMessa
486493 testT .Error ("unexpected height" )
487494 }
488495 // Sunny-day
489- return []byte ("{\" Tx\" : [\" 00 \" ], \" Hash\" : \" 0000380641 \" }" ), nil
496+ return []byte ("{\" Tx\" : [\" " + testTxid + " \" ], \" Hash\" : \" " + testBlockid41 + " \" }" ), nil
490497 case 4 :
491- if arg != "0000380641" {
498+ if arg != testBlockid41 {
492499 testT .Error ("unexpected hash" )
493500 }
494501 return blocks [1 ], nil
@@ -497,9 +504,9 @@ func getblockStubReverse(method string, params []json.RawMessage) (json.RawMessa
497504 testT .Error ("unexpected height" )
498505 }
499506 // Sunny-day
500- return []byte ("{\" Tx\" : [\" 00 \" ], \" Hash\" : \" 0000380640 \" }" ), nil
507+ return []byte ("{\" Tx\" : [\" " + testTxid + " \" ], \" Hash\" : \" " + testBlockid40 + " \" }" ), nil
501508 case 6 :
502- if arg != "0000380640" {
509+ if arg != testBlockid40 {
503510 testT .Error ("unexpected hash" )
504511 }
505512 return blocks [0 ], nil
0 commit comments