Commit c67d48d9 authored by Brian Tiger Chow's avatar Brian Tiger Chow

test(bitswap)

parent 0881636a
...@@ -33,19 +33,45 @@ func TestProviderForKeyButNetworkCannotFind(t *testing.T) { ...@@ -33,19 +33,45 @@ func TestProviderForKeyButNetworkCannotFind(t *testing.T) {
net := LocalNetwork() net := LocalNetwork()
rs := newRoutingServer() rs := newRoutingServer()
ipfs := session(net, rs, []byte("peer id"))
// ctx := context.Background()
ctx, _ := context.WithTimeout(context.Background(), time.Nanosecond)
block := testutil.NewBlockOrFail(t, "block")
block := testutil.NewBlockOrFail(t, "block")
rs.Announce(&peer.Peer{}, block.Key()) // but not on network rs.Announce(&peer.Peer{}, block.Key()) // but not on network
_, err := ipfs.exchange.Block(ctx, block.Key()) solo := session(net, rs, []byte("peer id"))
ctx, _ := context.WithTimeout(context.Background(), time.Nanosecond)
_, err := solo.exchange.Block(ctx, block.Key())
if err != context.DeadlineExceeded { if err != context.DeadlineExceeded {
t.Fatal("Expected DeadlineExceeded error") t.Fatal("Expected DeadlineExceeded error")
} }
} }
// TestGetBlockAfterRequesting...
func TestGetBlockFromPeerAfterPeerAnnounces(t *testing.T) {
t.Skip("Failing. Work in progress")
net := LocalNetwork()
rs := newRoutingServer()
block := testutil.NewBlockOrFail(t, "block")
hasBlock := session(net, rs, []byte("hasBlock"))
rs.Announce(hasBlock.peer, block.Key())
hasBlock.blockstore.Put(block)
hasBlock.exchange.HasBlock(context.Background(), block)
wantsBlock := session(net, rs, []byte("wantsBlock"))
ctx, _ := context.WithTimeout(context.Background(), time.Second)
_, err := wantsBlock.exchange.Block(ctx, block.Key())
if err != nil {
t.Log(err)
t.Fatal("Expected to succeed")
}
}
type ipfs struct { type ipfs struct {
peer *peer.Peer peer *peer.Peer
exchange exchange.Interface exchange exchange.Interface
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment