@@ -10,7 +10,6 @@ import (
10
10
"testing"
11
11
"time"
12
12
13
- "github.com/benbjohnson/clock"
14
13
"github.com/ipfs/boxo/coreiface/path"
15
14
ipns "github.com/ipfs/boxo/ipns"
16
15
ipfspath "github.com/ipfs/boxo/path"
@@ -22,7 +21,6 @@ import (
22
21
"github.com/libp2p/go-libp2p/core/crypto"
23
22
"github.com/libp2p/go-libp2p/core/peer"
24
23
"github.com/multiformats/go-multiaddr"
25
- "github.com/multiformats/go-multibase"
26
24
"github.com/multiformats/go-multihash"
27
25
"github.com/stretchr/testify/assert"
28
26
"github.com/stretchr/testify/mock"
@@ -36,16 +34,6 @@ func (m *mockContentRouter) FindProviders(ctx context.Context, key cid.Cid, limi
36
34
return args .Get (0 ).(iter.ResultIter [types.ProviderResponse ]), args .Error (1 )
37
35
}
38
36
39
- func (m * mockContentRouter ) ProvideBitswap (ctx context.Context , req * server.BitswapWriteProvideRequest ) (time.Duration , error ) {
40
- args := m .Called (ctx , req )
41
- return args .Get (0 ).(time.Duration ), args .Error (1 )
42
- }
43
-
44
- func (m * mockContentRouter ) Provide (ctx context.Context , req * server.WriteProvideRequest ) (types.ProviderResponse , error ) {
45
- args := m .Called (ctx , req )
46
- return args .Get (0 ).(types.ProviderResponse ), args .Error (1 )
47
- }
48
-
49
37
func (m * mockContentRouter ) FindIPNSRecord (ctx context.Context , name ipns.Name ) (* ipns.Record , error ) {
50
38
args := m .Called (ctx , name )
51
39
return args .Get (0 ).(* ipns.Record ), args .Error (1 )
@@ -151,13 +139,6 @@ func addrsToDRAddrs(addrs []multiaddr.Multiaddr) (drmas []types.Multiaddr) {
151
139
return
152
140
}
153
141
154
- func drAddrsToAddrs (drmas []types.Multiaddr ) (addrs []multiaddr.Multiaddr ) {
155
- for _ , a := range drmas {
156
- addrs = append (addrs , a .Multiaddr )
157
- }
158
- return
159
- }
160
-
161
142
func makeBSReadProviderResp () types.ReadBitswapProviderRecord {
162
143
peerID , addrs , _ := makeProviderAndIdentity ()
163
144
return types.ReadBitswapProviderRecord {
@@ -333,130 +314,6 @@ func TestClient_FindProviders(t *testing.T) {
333
314
}
334
315
}
335
316
336
- func TestClient_Provide (t * testing.T ) {
337
- cases := []struct {
338
- name string
339
- manglePath bool
340
- mangleSignature bool
341
- stopServer bool
342
- noProviderInfo bool
343
- noIdentity bool
344
-
345
- cids []cid.Cid
346
- ttl time.Duration
347
-
348
- routerAdvisoryTTL time.Duration
349
- routerErr error
350
-
351
- expErrContains string
352
- expWinErrContains string
353
-
354
- expAdvisoryTTL time.Duration
355
- }{
356
- {
357
- name : "happy case" ,
358
- cids : []cid.Cid {makeCID ()},
359
- ttl : 1 * time .Hour ,
360
- routerAdvisoryTTL : 1 * time .Minute ,
361
-
362
- expAdvisoryTTL : 1 * time .Minute ,
363
- },
364
- {
365
- name : "should return a 403 if the payload signature verification fails" ,
366
- cids : []cid.Cid {},
367
- mangleSignature : true ,
368
- expErrContains : "HTTP error with StatusCode=403" ,
369
- },
370
- {
371
- name : "should return error if identity is not provided" ,
372
- noIdentity : true ,
373
- expErrContains : "cannot provide Bitswap records without an identity" ,
374
- },
375
- {
376
- name : "should return error if provider is not provided" ,
377
- noProviderInfo : true ,
378
- expErrContains : "cannot provide Bitswap records without a peer ID" ,
379
- },
380
- {
381
- name : "returns an error if there's a non-200 response" ,
382
- manglePath : true ,
383
- expErrContains : "HTTP error with StatusCode=404: 404 page not found" ,
384
- },
385
- {
386
- name : "returns an error if the HTTP client returns a non-HTTP error" ,
387
- stopServer : true ,
388
- expErrContains : "connect: connection refused" ,
389
- expWinErrContains : "connectex: No connection could be made because the target machine actively refused it." ,
390
- },
391
- }
392
- for _ , c := range cases {
393
- t .Run (c .name , func (t * testing.T ) {
394
- deps := makeTestDeps (t , nil , nil )
395
- client := deps .client
396
- router := deps .router
397
-
398
- if c .noIdentity {
399
- client .identity = nil
400
- }
401
- if c .noProviderInfo {
402
- client .peerID = ""
403
- client .addrs = nil
404
- }
405
-
406
- clock := clock .NewMock ()
407
- clock .Set (time .Now ())
408
- client .clock = clock
409
-
410
- ctx := context .Background ()
411
-
412
- if c .manglePath {
413
- client .baseURL += "/foo"
414
- }
415
- if c .stopServer {
416
- deps .server .Close ()
417
- }
418
- if c .mangleSignature {
419
- client .afterSignCallback = func (req * types.WriteBitswapProviderRecord ) {
420
- mh , err := multihash .Encode ([]byte ("boom" ), multihash .SHA2_256 )
421
- require .NoError (t , err )
422
- mb , err := multibase .Encode (multibase .Base64 , mh )
423
- require .NoError (t , err )
424
-
425
- req .Signature = mb
426
- }
427
- }
428
-
429
- expectedProvReq := & server.BitswapWriteProvideRequest {
430
- Keys : c .cids ,
431
- Timestamp : clock .Now ().Truncate (time .Millisecond ),
432
- AdvisoryTTL : c .ttl ,
433
- Addrs : drAddrsToAddrs (client .addrs ),
434
- ID : client .peerID ,
435
- }
436
-
437
- router .On ("ProvideBitswap" , mock .Anything , expectedProvReq ).
438
- Return (c .routerAdvisoryTTL , c .routerErr )
439
-
440
- advisoryTTL , err := client .ProvideBitswap (ctx , c .cids , c .ttl )
441
-
442
- var errorString string
443
- if runtime .GOOS == "windows" && c .expWinErrContains != "" {
444
- errorString = c .expWinErrContains
445
- } else {
446
- errorString = c .expErrContains
447
- }
448
-
449
- if errorString != "" {
450
- require .ErrorContains (t , err , errorString )
451
- } else {
452
- require .NoError (t , err )
453
- }
454
-
455
- assert .Equal (t , c .expAdvisoryTTL , advisoryTTL )
456
- })
457
- }
458
- }
459
-
460
317
func makeName (t * testing.T ) (crypto.PrivKey , ipns.Name ) {
461
318
sk , _ , err := crypto .GenerateEd25519Key (rand .Reader )
462
319
require .NoError (t , err )
0 commit comments