mock.go 632 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
package blockservice

import (
	"testing"

	bitswap "github.com/jbenet/go-ipfs/exchange/bitswap"
	tn "github.com/jbenet/go-ipfs/exchange/bitswap/testnet"
	"github.com/jbenet/go-ipfs/routing/mock"
)

// Mocks returns |n| connected mock Blockservices
func Mocks(t *testing.T, n int) []*BlockService {
	net := tn.VirtualNetwork()
	rs := mock.VirtualRoutingServer()
	sg := bitswap.NewSessionGenerator(net, rs)

	instances := sg.Instances(n)

	var servs []*BlockService
	for _, i := range instances {
		bserv, err := New(i.Blockstore(), i.Exchange)
		if err != nil {
			t.Fatal(err)
		}
		servs = append(servs, bserv)
	}
	return servs
}