cidset_test.go 631 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
package cidset

import (
	"testing"

	"github.com/ipfs/go-cid"
	"github.com/ipfs/go-graphsync/testutil"
	"github.com/stretchr/testify/require"
)

func TestDecodeEncodeCidSet(t *testing.T) {
	cids := testutil.GenerateCids(10)
	set := cid.NewSet()
	for _, c := range cids {
		set.Add(c)
	}
	encoded, err := EncodeCidSet(set)
	require.NoError(t, err, "encode errored")
	decodedCidSet, err := DecodeCidSet(encoded)
	require.NoError(t, err, "decode errored")
	require.Equal(t, decodedCidSet.Len(), set.Len())
	err = decodedCidSet.ForEach(func(c cid.Cid) error {
		require.True(t, set.Has(c))
		return nil
	})
	require.NoError(t, err)
}