key_test.go 546 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10
package dshelp

import (
	"testing"

	cid "github.com/ipfs/go-cid"
)

func TestKey(t *testing.T) {
	c, _ := cid.Decode("QmP63DkAFEnDYNjDYBpyNDfttu1fvUw99x1brscPzpqmmq")
11 12
	dsKey := MultihashToDsKey(c.Hash())
	mh, err := DsKeyToMultihash(dsKey)
13 14 15
	if err != nil {
		t.Fatal(err)
	}
16 17
	if string(c.Hash()) != string(mh) {
		t.Fatal("should have parsed the same multihash")
18
	}
19

20
	c2, err := DsKeyToCidV1(dsKey, cid.Raw)
21
	if err != nil || c.Equals(c2) || c2.Type() != cid.Raw || c2.Version() != 1 {
22 23
		t.Fatal("should have been converted to CIDv1-raw")
	}
24
}