From 3476034a39147ccd35e2625f49638f170bbcb8ec Mon Sep 17 00:00:00 2001 From: Andrew Gillis Date: Thu, 6 Apr 2023 11:34:59 -0700 Subject: [PATCH] Update version (#17) * Update version * Remove redundant test code * Rename test go file * In tests, use linkproto prefix defined in schema * Update README with license --- README.md | 3 +++ dagsync/http_test.go | 2 +- dagsync/selector_test.go | 6 ++--- dagsync/subscriber_test.go | 4 +-- dagsync/sync_test.go | 2 +- dagsync/test/util.go | 49 ++++++++----------------------------- test/{util.go => random.go} | 9 +------ version.json | 2 +- 8 files changed, 21 insertions(+), 56 deletions(-) rename test/{util.go => random.go} (95%) diff --git a/README.md b/README.md index ca90621..f6b8b90 100644 --- a/README.md +++ b/README.md @@ -6,3 +6,6 @@ > IPNI library implementation in Go This project provides a Golang implementation of indexer API, data definitions, and utilities that can be used to build and interact with indexing services. + +## License +[SPDX-License-Identifier: Apache-2.0 OR MIT](LICENSE.md) diff --git a/dagsync/http_test.go b/dagsync/http_test.go index 6c680f4..bda5e51 100644 --- a/dagsync/http_test.go +++ b/dagsync/http_test.go @@ -138,7 +138,7 @@ func TestSyncFnHttp(t *testing.T) { // Try to sync with a non-existing cid to chack that sync returns with err, // and SyncFinished watcher does not get event. - cids, _ := test.RandomCids(1) + cids := test.RandomCids(1) ctx, syncncl := context.WithTimeout(context.Background(), time.Second) defer syncncl() diff --git a/dagsync/selector_test.go b/dagsync/selector_test.go index f82ce7f..b7c9488 100644 --- a/dagsync/selector_test.go +++ b/dagsync/selector_test.go @@ -31,8 +31,7 @@ func TestGetStopNodeWhenNil(t *testing.T) { } func TestGetRecursionLimit(t *testing.T) { - testCid, err := test.RandomCids(1) - require.NoError(t, err) + testCid := test.RandomCids(1) testStopLink := cidlink.Link{Cid: testCid[0]} ssb := selectorbuilder.NewSelectorSpecBuilder(basicnode.Prototype.Any) tests := []struct { @@ -99,8 +98,7 @@ func TestGetRecursionLimit(t *testing.T) { } func TestWithRecursionLimit(t *testing.T) { - testCid, err := test.RandomCids(1) - require.NoError(t, err) + testCid := test.RandomCids(1) testStopLink := cidlink.Link{Cid: testCid[0]} ssb := selectorbuilder.NewSelectorSpecBuilder(basicnode.Prototype.Any) tests := []struct { diff --git a/dagsync/subscriber_test.go b/dagsync/subscriber_test.go index f8e870e..dd2970b 100644 --- a/dagsync/subscriber_test.go +++ b/dagsync/subscriber_test.go @@ -759,14 +759,14 @@ func (h *hostSystem) close() { } func (b dagsyncPubSubBuilder) Build(t *testing.T, topicName string, pubSys hostSystem, subSys hostSystem, subOpts []dagsync.Option) (dagsync.Publisher, *dagsync.Subscriber) { - var pub dagsync.Publisher var senders []announce.Sender - if !b.P2PAnnounce { p2pSender, err := p2psender.New(pubSys.host, topicName) require.NoError(t, err) senders = append(senders, p2pSender) } + + var pub dagsync.Publisher var err error if b.IsHttp { pub, err = httpsync.NewPublisher("127.0.0.1:0", pubSys.lsys, pubSys.privKey, httpsync.WithAnnounceSenders(senders...)) diff --git a/dagsync/sync_test.go b/dagsync/sync_test.go index 1397e6d..69b3fa8 100644 --- a/dagsync/sync_test.go +++ b/dagsync/sync_test.go @@ -110,7 +110,7 @@ func TestSyncFn(t *testing.T) { // Try to sync with a non-existing cid to check that sync returns with err, // and SyncFinished watcher does not get event. - cids, _ := test.RandomCids(1) + cids := test.RandomCids(1) ctx, syncncl := context.WithTimeout(context.Background(), updateTimeout) defer syncncl() peerInfo := peer.AddrInfo{ diff --git a/dagsync/test/util.go b/dagsync/test/util.go index acb680e..1de51d6 100644 --- a/dagsync/test/util.go +++ b/dagsync/test/util.go @@ -6,7 +6,6 @@ import ( "errors" "fmt" "io" - "math/rand" "net/http" "path" "sync" @@ -20,13 +19,14 @@ import ( cidlink "github.com/ipld/go-ipld-prime/linking/cid" basicnode "github.com/ipld/go-ipld-prime/node/basic" "github.com/ipni/go-libipni/dagsync/p2p/protocol/head" + "github.com/ipni/go-libipni/ingest/schema" "github.com/ipni/go-libipni/maurl" + "github.com/ipni/go-libipni/test" "github.com/libp2p/go-libp2p" pubsub "github.com/libp2p/go-libp2p-pubsub" "github.com/libp2p/go-libp2p/core/host" "github.com/libp2p/go-libp2p/core/peer" "github.com/multiformats/go-multiaddr" - "github.com/multiformats/go-multicodec" "github.com/stretchr/testify/require" ) @@ -158,38 +158,15 @@ func waitForMeshWithMessage(t *testing.T, topic string, hosts ...host.Host) []*p // just gimme a link and stuff the bytes in a map. // (also return the node again for convenient assignment.) func encode(lsys ipld.LinkSystem, n ipld.Node) (ipld.Node, ipld.Link) { - lp := cidlink.LinkPrototype{ - Prefix: prefix, - } - - lnk, err := lsys.Store(ipld.LinkContext{}, lp, n) + lnk, err := lsys.Store(ipld.LinkContext{}, schema.Linkproto, n) if err != nil { panic(err) } return n, lnk } -var prefix = cid.Prefix{ - Version: 1, - Codec: uint64(multicodec.DagJson), - MhType: uint64(multicodec.Sha2_256), - MhLength: 16, -} - -func RandomCids(n int) ([]cid.Cid, error) { - var prng = rand.New(rand.NewSource(time.Now().UnixNano())) - - res := make([]cid.Cid, n) - for i := 0; i < n; i++ { - b := make([]byte, 10*n) - prng.Read(b) - c, err := prefix.Sum(b) - if err != nil { - return nil, err - } - res[i] = c - } - return res, nil +func RandomCids(n int) []cid.Cid { + return test.RandomCids(n) } func MkLinkSystem(ds datastore.Batching) ipld.LinkSystem { @@ -211,22 +188,16 @@ func MkLinkSystem(ds datastore.Batching) ipld.LinkSystem { } func Store(srcStore datastore.Batching, n ipld.Node) (ipld.Link, error) { - linkproto := cidlink.LinkPrototype{ - Prefix: cid.Prefix{ - Version: 1, - Codec: uint64(multicodec.DagJson), - MhType: uint64(multicodec.Sha2_256), - MhLength: 16, - }, - } lsys := MkLinkSystem(srcStore) - - return lsys.Store(ipld.LinkContext{}, linkproto, n) + return lsys.Store(ipld.LinkContext{}, schema.Linkproto, n) } func MkTestHost(options ...libp2p.Option) host.Host { options = append(options, libp2p.ListenAddrStrings("/ip4/127.0.0.1/tcp/0")) - h, _ := libp2p.New(options...) + h, err := libp2p.New(options...) + if err != nil { + panic(err) + } return h } diff --git a/test/util.go b/test/random.go similarity index 95% rename from test/util.go rename to test/random.go index 1201ede..2c47dc5 100644 --- a/test/util.go +++ b/test/random.go @@ -95,14 +95,7 @@ retry: // RandomMultihashes returns a slice of n random unique Multihashes. func RandomMultihashes(n int) []multihash.Multihash { rng := rand.New(rand.NewSource(globalSeed.Add(1))) - - prefix := cid.Prefix{ - Version: 1, - Codec: cid.Raw, - MhType: multihash.SHA2_256, - MhLength: -1, // default length - } - + prefix := schema.Linkproto.Prefix set := make(map[string]struct{}) mhashes := make([]multihash.Multihash, n) for i := 0; i < n; i++ { diff --git a/version.json b/version.json index edc249c..b9ab021 100644 --- a/version.json +++ b/version.json @@ -1,3 +1,3 @@ { - "version": "v0.0.4" + "version": "v0.0.5" }