@@ -15,6 +15,7 @@ import (
1515 "github.com/ipfs/boxo/bitswap/server"
1616 testinstance "github.com/ipfs/boxo/bitswap/testinstance"
1717 tn "github.com/ipfs/boxo/bitswap/testnet"
18+ mockrouting "github.com/ipfs/boxo/routing/mock"
1819 blocks "github.com/ipfs/go-block-format"
1920 cid "github.com/ipfs/go-cid"
2021 detectrace "github.com/ipfs/go-detect-race"
@@ -51,7 +52,8 @@ const kNetworkDelay = 0 * time.Millisecond
5152
5253func TestClose (t * testing.T ) {
5354 vnet := tn .VirtualNetwork (delay .Fixed (kNetworkDelay ))
54- ig := testinstance .NewTestInstanceGenerator (vnet , nil , nil )
55+ router := mockrouting .NewServer ()
56+ ig := testinstance .NewTestInstanceGenerator (vnet , router , nil , nil )
5557 defer ig .Close ()
5658 block := random .BlocksOfSize (1 , blockSize )[0 ]
5759 bitswap := ig .Next ()
@@ -65,12 +67,13 @@ func TestClose(t *testing.T) {
6567
6668func TestProviderForKeyButNetworkCannotFind (t * testing.T ) { // TODO revisit this
6769 net := tn .VirtualNetwork (delay .Fixed (kNetworkDelay ))
68- ig := testinstance .NewTestInstanceGenerator (net , nil , nil )
70+ router := mockrouting .NewServer ()
71+ ig := testinstance .NewTestInstanceGenerator (net , router , nil , nil )
6972 defer ig .Close ()
7073
7174 block := blocks .NewBlock ([]byte ("block" ))
7275 pinfo := p2ptestutil .RandTestBogusIdentityOrFatal (t )
73- err := ig . Routing () .Client (pinfo ).Provide (context .Background (), block .Cid (), true ) // but not on network
76+ err := router .Client (pinfo ).Provide (context .Background (), block .Cid (), true ) // but not on network
7477 if err != nil {
7578 t .Fatal (err )
7679 }
@@ -90,7 +93,8 @@ func TestProviderForKeyButNetworkCannotFind(t *testing.T) { // TODO revisit this
9093func TestGetBlockFromPeerAfterPeerAnnounces (t * testing.T ) {
9194 net := tn .VirtualNetwork (delay .Fixed (kNetworkDelay ))
9295 block := blocks .NewBlock ([]byte ("block" ))
93- ig := testinstance .NewTestInstanceGenerator (net , nil , nil )
96+ router := mockrouting .NewServer ()
97+ ig := testinstance .NewTestInstanceGenerator (net , router , nil , nil )
9498 defer ig .Close ()
9599
96100 peers := ig .Instances (2 )
@@ -119,7 +123,8 @@ func TestDoesNotProvideWhenConfiguredNotTo(t *testing.T) {
119123 net := tn .VirtualNetwork (delay .Fixed (kNetworkDelay ))
120124 block := blocks .NewBlock ([]byte ("block" ))
121125 bsOpts := []bitswap.Option {bitswap .ProviderSearchDelay (50 * time .Millisecond )}
122- ig := testinstance .NewTestInstanceGenerator (net , nil , bsOpts )
126+ router := mockrouting .NewServer ()
127+ ig := testinstance .NewTestInstanceGenerator (net , router , nil , bsOpts )
123128 defer ig .Close ()
124129
125130 hasBlock := ig .Next ()
@@ -153,7 +158,8 @@ func TestUnwantedBlockNotAdded(t *testing.T) {
153158 bsMessage := bsmsg .New (true )
154159 bsMessage .AddBlock (block )
155160
156- ig := testinstance .NewTestInstanceGenerator (net , nil , nil )
161+ router := mockrouting .NewServer ()
162+ ig := testinstance .NewTestInstanceGenerator (net , router , nil , nil )
157163 defer ig .Close ()
158164
159165 peers := ig .Instances (2 )
@@ -168,7 +174,7 @@ func TestUnwantedBlockNotAdded(t *testing.T) {
168174 ctx , cancel := context .WithTimeout (context .Background (), time .Second )
169175 defer cancel ()
170176
171- doesNotWantBlock .Exchange .ReceiveMessage (ctx , hasBlock .Peer , bsMessage )
177+ doesNotWantBlock .Exchange .ReceiveMessage (ctx , hasBlock .Identity . ID () , bsMessage )
172178
173179 blockInStore , err := doesNotWantBlock .Blockstore ().Has (ctx , block .Cid ())
174180 if err != nil || blockInStore {
@@ -187,7 +193,8 @@ func TestPendingBlockAdded(t *testing.T) {
187193 net := tn .VirtualNetwork (delay .Fixed (kNetworkDelay ))
188194 sessionBroadcastWantCapacity := 4
189195
190- ig := testinstance .NewTestInstanceGenerator (net , nil , nil )
196+ router := mockrouting .NewServer ()
197+ ig := testinstance .NewTestInstanceGenerator (net , router , nil , nil )
191198 defer ig .Close ()
192199
193200 instance := ig .Instances (1 )[0 ]
@@ -276,7 +283,8 @@ func PerformDistributionTest(t *testing.T, numInstances, numBlocks int) {
276283 t .SkipNow ()
277284 }
278285 net := tn .VirtualNetwork (delay .Fixed (kNetworkDelay ))
279- ig := testinstance .NewTestInstanceGenerator (net , nil , []bitswap.Option {
286+ router := mockrouting .NewServer ()
287+ ig := testinstance .NewTestInstanceGenerator (net , router , nil , []bitswap.Option {
280288 bitswap .TaskWorkerCount (5 ),
281289 bitswap .EngineTaskWorkerCount (5 ),
282290 bitswap .MaxOutstandingBytesPerPeer (1 << 20 ),
@@ -332,15 +340,16 @@ func TestSendToWantingPeer(t *testing.T) {
332340 }
333341
334342 net := tn .VirtualNetwork (delay .Fixed (kNetworkDelay ))
335- ig := testinstance .NewTestInstanceGenerator (net , nil , nil )
343+ router := mockrouting .NewServer ()
344+ ig := testinstance .NewTestInstanceGenerator (net , router , nil , nil )
336345 defer ig .Close ()
337346
338347 peers := ig .Instances (2 )
339348 peerA := peers [0 ]
340349 peerB := peers [1 ]
341350
342- t .Logf ("Session %v\n " , peerA .Peer )
343- t .Logf ("Session %v\n " , peerB .Peer )
351+ t .Logf ("Session %v\n " , peerA .Identity . ID () )
352+ t .Logf ("Session %v\n " , peerB .Identity . ID () )
344353
345354 waitTime := time .Second * 5
346355
@@ -369,7 +378,8 @@ func TestSendToWantingPeer(t *testing.T) {
369378
370379func TestEmptyKey (t * testing.T ) {
371380 net := tn .VirtualNetwork (delay .Fixed (kNetworkDelay ))
372- ig := testinstance .NewTestInstanceGenerator (net , nil , nil )
381+ router := mockrouting .NewServer ()
382+ ig := testinstance .NewTestInstanceGenerator (net , router , nil , nil )
373383 defer ig .Close ()
374384 bs := ig .Instances (1 )[0 ].Exchange
375385
@@ -402,7 +412,8 @@ func assertStat(t *testing.T, st *bitswap.Stat, sblks, rblks, sdata, rdata uint6
402412
403413func TestBasicBitswap (t * testing.T ) {
404414 net := tn .VirtualNetwork (delay .Fixed (kNetworkDelay ))
405- ig := testinstance .NewTestInstanceGenerator (net , nil , nil )
415+ router := mockrouting .NewServer ()
416+ ig := testinstance .NewTestInstanceGenerator (net , router , nil , nil )
406417 defer ig .Close ()
407418
408419 t .Log ("Test a one node trying to get one block from another" )
@@ -426,7 +437,7 @@ func TestBasicBitswap(t *testing.T) {
426437 // When second peer receives block, it should send out a cancel, so third
427438 // peer should no longer keep second peer's want
428439 if err = tu .WaitFor (ctx , func () error {
429- if len (instances [2 ].Exchange .WantlistForPeer (instances [1 ].Peer )) != 0 {
440+ if len (instances [2 ].Exchange .WantlistForPeer (instances [1 ].Identity . ID () )) != 0 {
430441 return errors .New ("should have no items in other peers wantlist" )
431442 }
432443 if len (instances [1 ].Exchange .GetWantlist ()) != 0 {
@@ -473,7 +484,8 @@ func TestBasicBitswap(t *testing.T) {
473484
474485func TestDoubleGet (t * testing.T ) {
475486 net := tn .VirtualNetwork (delay .Fixed (kNetworkDelay ))
476- ig := testinstance .NewTestInstanceGenerator (net , nil , nil )
487+ router := mockrouting .NewServer ()
488+ ig := testinstance .NewTestInstanceGenerator (net , router , nil , nil )
477489 defer ig .Close ()
478490
479491 t .Log ("Test a one node trying to get one block from another" )
@@ -516,7 +528,7 @@ func TestDoubleGet(t *testing.T) {
516528 }
517529 t .Log (blk )
518530 case <- time .After (time .Second * 5 ):
519- p1wl := instances [0 ].Exchange .WantlistForPeer (instances [1 ].Peer )
531+ p1wl := instances [0 ].Exchange .WantlistForPeer (instances [1 ].Identity . ID () )
520532 if len (p1wl ) != 1 {
521533 t .Logf ("wantlist view didnt have 1 item (had %d)" , len (p1wl ))
522534 } else if ! p1wl [0 ].Equals (blocks [0 ].Cid ()) {
@@ -537,7 +549,8 @@ func TestDoubleGet(t *testing.T) {
537549
538550func TestWantlistCleanup (t * testing.T ) {
539551 net := tn .VirtualNetwork (delay .Fixed (kNetworkDelay ))
540- ig := testinstance .NewTestInstanceGenerator (net , nil , nil )
552+ router := mockrouting .NewServer ()
553+ ig := testinstance .NewTestInstanceGenerator (net , router , nil , nil )
541554 defer ig .Close ()
542555
543556 instances := ig .Instances (2 )
@@ -658,7 +671,8 @@ func newReceipt(sent, recv, exchanged uint64) *server.Receipt {
658671
659672func TestBitswapLedgerOneWay (t * testing.T ) {
660673 net := tn .VirtualNetwork (delay .Fixed (kNetworkDelay ))
661- ig := testinstance .NewTestInstanceGenerator (net , nil , nil )
674+ router := mockrouting .NewServer ()
675+ ig := testinstance .NewTestInstanceGenerator (net , router , nil , nil )
662676 defer ig .Close ()
663677
664678 t .Log ("Test ledgers match when one peer sends block to another" )
@@ -674,8 +688,8 @@ func TestBitswapLedgerOneWay(t *testing.T) {
674688 t .Fatal (err )
675689 }
676690
677- ra := instances [0 ].Exchange .LedgerForPeer (instances [1 ].Peer )
678- rb := instances [1 ].Exchange .LedgerForPeer (instances [0 ].Peer )
691+ ra := instances [0 ].Exchange .LedgerForPeer (instances [1 ].Identity . ID () )
692+ rb := instances [1 ].Exchange .LedgerForPeer (instances [0 ].Identity . ID () )
679693
680694 // compare peer ledger receipts
681695 err = assertLedgerMatch (ra , rb )
@@ -706,7 +720,8 @@ func TestBitswapLedgerOneWay(t *testing.T) {
706720
707721func TestBitswapLedgerTwoWay (t * testing.T ) {
708722 net := tn .VirtualNetwork (delay .Fixed (kNetworkDelay ))
709- ig := testinstance .NewTestInstanceGenerator (net , nil , nil )
723+ router := mockrouting .NewServer ()
724+ ig := testinstance .NewTestInstanceGenerator (net , router , nil , nil )
710725 defer ig .Close ()
711726
712727 t .Log ("Test ledgers match when two peers send one block to each other" )
@@ -730,8 +745,8 @@ func TestBitswapLedgerTwoWay(t *testing.T) {
730745 t .Fatal (err )
731746 }
732747
733- ra := instances [0 ].Exchange .LedgerForPeer (instances [1 ].Peer )
734- rb := instances [1 ].Exchange .LedgerForPeer (instances [0 ].Peer )
748+ ra := instances [0 ].Exchange .LedgerForPeer (instances [1 ].Identity . ID () )
749+ rb := instances [1 ].Exchange .LedgerForPeer (instances [0 ].Identity . ID () )
735750
736751 // compare peer ledger receipts
737752 err = assertLedgerMatch (ra , rb )
@@ -794,8 +809,9 @@ func (tsl *testingScoreLedger) Stop() {
794809func TestWithScoreLedger (t * testing.T ) {
795810 tsl := newTestingScoreLedger ()
796811 net := tn .VirtualNetwork (delay .Fixed (kNetworkDelay ))
812+ router := mockrouting .NewServer ()
797813 bsOpts := []bitswap.Option {bitswap .WithScoreLedger (tsl )}
798- ig := testinstance .NewTestInstanceGenerator (net , nil , bsOpts )
814+ ig := testinstance .NewTestInstanceGenerator (net , router , nil , bsOpts )
799815 defer ig .Close ()
800816 i := ig .Next ()
801817 defer i .Exchange .Close ()
0 commit comments