sentwantblockstracker_test.go 703 Bytes
Newer Older
dirkmc's avatar
dirkmc committed
1 2 3 4 5
package session

import (
	"testing"

6
	"gitlab.dms3.io/dms3/go-bitswap/internal/testutil"
dirkmc's avatar
dirkmc committed
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
)

func TestSendWantBlocksTracker(t *testing.T) {
	peers := testutil.GeneratePeers(2)
	cids := testutil.GenerateCids(2)
	swbt := newSentWantBlocksTracker()

	if swbt.haveSentWantBlockTo(peers[0], cids[0]) {
		t.Fatal("expected not to have sent anything yet")
	}

	swbt.addSentWantBlocksTo(peers[0], cids)
	if !swbt.haveSentWantBlockTo(peers[0], cids[0]) {
		t.Fatal("expected to have sent cid to peer")
	}
	if !swbt.haveSentWantBlockTo(peers[0], cids[1]) {
		t.Fatal("expected to have sent cid to peer")
	}
	if swbt.haveSentWantBlockTo(peers[1], cids[0]) {
		t.Fatal("expected not to have sent cid to peer")
	}
}