github.com/celestiaorg/celestia-node@v0.15.0-beta.1/share/availability/full/testing.go (about) 1 package full 2 3 import ( 4 "context" 5 "testing" 6 "time" 7 8 "github.com/ipfs/go-datastore" 9 routinghelpers "github.com/libp2p/go-libp2p-routing-helpers" 10 "github.com/libp2p/go-libp2p/p2p/discovery/routing" 11 "github.com/stretchr/testify/require" 12 13 "github.com/celestiaorg/celestia-node/share" 14 availability_test "github.com/celestiaorg/celestia-node/share/availability/test" 15 "github.com/celestiaorg/celestia-node/share/eds" 16 "github.com/celestiaorg/celestia-node/share/getters" 17 "github.com/celestiaorg/celestia-node/share/ipld" 18 "github.com/celestiaorg/celestia-node/share/p2p/discovery" 19 ) 20 21 // GetterWithRandSquare provides a share.Getter filled with 'n' NMT 22 // trees of 'n' random shares, essentially storing a whole square. 23 func GetterWithRandSquare(t *testing.T, n int) (share.Getter, *share.Root) { 24 bServ := ipld.NewMemBlockservice() 25 getter := getters.NewIPLDGetter(bServ) 26 return getter, availability_test.RandFillBS(t, n, bServ) 27 } 28 29 // RandNode creates a Full Node filled with a random block of the given size. 30 func RandNode(dn *availability_test.TestDagNet, squareSize int) (*availability_test.TestNode, *share.Root) { 31 nd := Node(dn) 32 return nd, availability_test.RandFillBS(dn.T, squareSize, nd.BlockService) 33 } 34 35 // Node creates a new empty Full Node. 36 func Node(dn *availability_test.TestDagNet) *availability_test.TestNode { 37 nd := dn.NewTestNode() 38 nd.Getter = getters.NewIPLDGetter(nd.BlockService) 39 nd.Availability = TestAvailability(dn.T, nd.Getter) 40 return nd 41 } 42 43 func TestAvailability(t *testing.T, getter share.Getter) *ShareAvailability { 44 params := discovery.DefaultParameters() 45 params.AdvertiseInterval = time.Second 46 params.PeersLimit = 10 47 disc, err := discovery.NewDiscovery( 48 params, 49 nil, 50 routing.NewRoutingDiscovery(routinghelpers.Null{}), 51 "full", 52 ) 53 require.NoError(t, err) 54 store, err := eds.NewStore(eds.DefaultParameters(), t.TempDir(), datastore.NewMapDatastore()) 55 require.NoError(t, err) 56 err = store.Start(context.Background()) 57 require.NoError(t, err) 58 59 t.Cleanup(func() { 60 err = store.Stop(context.Background()) 61 require.NoError(t, err) 62 }) 63 return NewShareAvailability(store, getter, disc) 64 }