@@ -19,14 +19,16 @@ import (
19
19
blocks "github.com/ipfs/go-block-format"
20
20
cid "github.com/ipfs/go-cid"
21
21
detectrace "github.com/ipfs/go-detect-race"
22
- blocksutil "github.com/ipfs/go-ipfs-blocksutil"
23
22
delay "github.com/ipfs/go-ipfs-delay"
24
23
ipld "github.com/ipfs/go-ipld-format"
24
+ "github.com/ipfs/go-test/random"
25
25
tu "github.com/libp2p/go-libp2p-testing/etc"
26
26
p2ptestutil "github.com/libp2p/go-libp2p-testing/netutil"
27
27
peer "github.com/libp2p/go-libp2p/core/peer"
28
28
)
29
29
30
+ const blockSize = 4
31
+
30
32
func isCI () bool {
31
33
// https://github.blog/changelog/2020-04-15-github-actions-sets-the-ci-environment-variable-to-true/
32
34
return os .Getenv ("CI" ) != ""
@@ -52,9 +54,7 @@ func TestClose(t *testing.T) {
52
54
vnet := tn .VirtualNetwork (mockrouting .NewServer (), delay .Fixed (kNetworkDelay ))
53
55
ig := testinstance .NewTestInstanceGenerator (vnet , nil , nil )
54
56
defer ig .Close ()
55
- bgen := blocksutil .NewBlockGenerator ()
56
-
57
- block := bgen .Next ()
57
+ block := random .BlocksOfSize (1 , blockSize )[0 ]
58
58
bitswap := ig .Next ()
59
59
60
60
bitswap .Exchange .Close ()
@@ -187,7 +187,6 @@ func TestUnwantedBlockNotAdded(t *testing.T) {
187
187
func TestPendingBlockAdded (t * testing.T ) {
188
188
ctx := context .Background ()
189
189
net := tn .VirtualNetwork (mockrouting .NewServer (), delay .Fixed (kNetworkDelay ))
190
- bg := blocksutil .NewBlockGenerator ()
191
190
sessionBroadcastWantCapacity := 4
192
191
193
192
ig := testinstance .NewTestInstanceGenerator (net , nil , nil )
@@ -202,7 +201,7 @@ func TestPendingBlockAdded(t *testing.T) {
202
201
// Request enough blocks to exceed the session's broadcast want list
203
202
// capacity (by one block). The session will put the remaining block
204
203
// into the "tofetch" queue
205
- blks := bg . Blocks (sessionBroadcastWantCapacity + 1 )
204
+ blks := random . BlocksOfSize (sessionBroadcastWantCapacity + 1 , blockSize )
206
205
ks := make ([]cid.Cid , 0 , len (blks ))
207
206
for _ , b := range blks {
208
207
ks = append (ks , b .Cid ())
@@ -285,10 +284,9 @@ func PerformDistributionTest(t *testing.T, numInstances, numBlocks int) {
285
284
bitswap .MaxOutstandingBytesPerPeer (1 << 20 ),
286
285
})
287
286
defer ig .Close ()
288
- bg := blocksutil .NewBlockGenerator ()
289
287
290
288
instances := ig .Instances (numInstances )
291
- blocks := bg . Blocks (numBlocks )
289
+ blocks := random . BlocksOfSize (numBlocks , blockSize )
292
290
293
291
t .Log ("Give the blocks to the first instance" )
294
292
@@ -338,7 +336,6 @@ func TestSendToWantingPeer(t *testing.T) {
338
336
net := tn .VirtualNetwork (mockrouting .NewServer (), delay .Fixed (kNetworkDelay ))
339
337
ig := testinstance .NewTestInstanceGenerator (net , nil , nil )
340
338
defer ig .Close ()
341
- bg := blocksutil .NewBlockGenerator ()
342
339
343
340
peers := ig .Instances (2 )
344
341
peerA := peers [0 ]
@@ -349,7 +346,7 @@ func TestSendToWantingPeer(t *testing.T) {
349
346
350
347
waitTime := time .Second * 5
351
348
352
- alpha := bg . Next ()
349
+ alpha := random . BlocksOfSize ( 1 , blockSize )[ 0 ]
353
350
// peerA requests and waits for block alpha
354
351
ctx , cancel := context .WithTimeout (context .Background (), waitTime )
355
352
defer cancel ()
@@ -409,12 +406,11 @@ func TestBasicBitswap(t *testing.T) {
409
406
net := tn .VirtualNetwork (mockrouting .NewServer (), delay .Fixed (kNetworkDelay ))
410
407
ig := testinstance .NewTestInstanceGenerator (net , nil , nil )
411
408
defer ig .Close ()
412
- bg := blocksutil .NewBlockGenerator ()
413
409
414
410
t .Log ("Test a one node trying to get one block from another" )
415
411
416
412
instances := ig .Instances (3 )
417
- blocks := bg . Blocks ( 1 )
413
+ blocks := random . BlocksOfSize ( 1 , blockSize )
418
414
419
415
// First peer has block
420
416
addBlock (t , context .Background (), instances [0 ], blocks [0 ])
@@ -481,12 +477,11 @@ func TestDoubleGet(t *testing.T) {
481
477
net := tn .VirtualNetwork (mockrouting .NewServer (), delay .Fixed (kNetworkDelay ))
482
478
ig := testinstance .NewTestInstanceGenerator (net , nil , nil )
483
479
defer ig .Close ()
484
- bg := blocksutil .NewBlockGenerator ()
485
480
486
481
t .Log ("Test a one node trying to get one block from another" )
487
482
488
483
instances := ig .Instances (2 )
489
- blocks := bg . Blocks ( 1 )
484
+ blocks := random . BlocksOfSize ( 1 , blockSize )
490
485
491
486
// NOTE: A race condition can happen here where these GetBlocks requests go
492
487
// through before the peers even get connected. This is okay, bitswap
@@ -546,12 +541,11 @@ func TestWantlistCleanup(t *testing.T) {
546
541
net := tn .VirtualNetwork (mockrouting .NewServer (), delay .Fixed (kNetworkDelay ))
547
542
ig := testinstance .NewTestInstanceGenerator (net , nil , nil )
548
543
defer ig .Close ()
549
- bg := blocksutil .NewBlockGenerator ()
550
544
551
545
instances := ig .Instances (2 )
552
546
instance := instances [0 ]
553
547
bswap := instance .Exchange
554
- blocks := bg . Blocks (20 )
548
+ blocks := random . BlocksOfSize (20 , blockSize )
555
549
556
550
var keys []cid.Cid
557
551
for _ , b := range blocks {
@@ -668,12 +662,11 @@ func TestBitswapLedgerOneWay(t *testing.T) {
668
662
net := tn .VirtualNetwork (mockrouting .NewServer (), delay .Fixed (kNetworkDelay ))
669
663
ig := testinstance .NewTestInstanceGenerator (net , nil , nil )
670
664
defer ig .Close ()
671
- bg := blocksutil .NewBlockGenerator ()
672
665
673
666
t .Log ("Test ledgers match when one peer sends block to another" )
674
667
675
668
instances := ig .Instances (2 )
676
- blocks := bg . Blocks ( 1 )
669
+ blocks := random . BlocksOfSize ( 1 , blockSize )
677
670
addBlock (t , context .Background (), instances [0 ], blocks [0 ])
678
671
679
672
ctx , cancel := context .WithTimeout (context .Background (), time .Second * 5 )
@@ -693,12 +686,12 @@ func TestBitswapLedgerOneWay(t *testing.T) {
693
686
}
694
687
695
688
// check that receipts have intended values
696
- ratest := newReceipt (1 , 0 , 1 )
689
+ ratest := newReceipt (blockSize , 0 , 1 )
697
690
err = assertLedgerEqual (ratest , ra )
698
691
if err != nil {
699
692
t .Fatal (err )
700
693
}
701
- rbtest := newReceipt (0 , 1 , 1 )
694
+ rbtest := newReceipt (0 , blockSize , 1 )
702
695
err = assertLedgerEqual (rbtest , rb )
703
696
if err != nil {
704
697
t .Fatal (err )
@@ -717,12 +710,11 @@ func TestBitswapLedgerTwoWay(t *testing.T) {
717
710
net := tn .VirtualNetwork (mockrouting .NewServer (), delay .Fixed (kNetworkDelay ))
718
711
ig := testinstance .NewTestInstanceGenerator (net , nil , nil )
719
712
defer ig .Close ()
720
- bg := blocksutil .NewBlockGenerator ()
721
713
722
714
t .Log ("Test ledgers match when two peers send one block to each other" )
723
715
724
716
instances := ig .Instances (2 )
725
- blocks := bg . Blocks ( 2 )
717
+ blocks := random . BlocksOfSize ( 2 , blockSize )
726
718
addBlock (t , context .Background (), instances [0 ], blocks [0 ])
727
719
addBlock (t , context .Background (), instances [1 ], blocks [1 ])
728
720
@@ -750,7 +742,7 @@ func TestBitswapLedgerTwoWay(t *testing.T) {
750
742
}
751
743
752
744
// check that receipts have intended values
753
- rtest := newReceipt (1 , 1 , 2 )
745
+ rtest := newReceipt (blockSize , blockSize , 2 )
754
746
err = assertLedgerEqual (rtest , ra )
755
747
if err != nil {
756
748
t .Fatal (err )
0 commit comments