cid_test.go 684 Bytes
Newer Older
1 2 3 4 5 6
package bitswap_message_pb_test

import (
	"bytes"
	"testing"

7 8
	"gitlab.dms3.io/dms3/go-cid"
	u "gitlab.dms3.io/dms3/go-dms3-util"
9

10
	pb "gitlab.dms3.io/dms3/go-bitswap/message/pb"
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
)

func TestCID(t *testing.T) {
	var expected = [...]byte{
		10, 34, 18, 32, 195, 171,
		143, 241, 55, 32, 232, 173,
		144, 71, 221, 57, 70, 107,
		60, 137, 116, 229, 146, 194,
		250, 56, 61, 74, 57, 96,
		113, 76, 174, 240, 196, 242,
	}

	c := cid.NewCidV0(u.Hash([]byte("foobar")))
	msg := pb.Message_BlockPresence{Cid: pb.Cid{Cid: c}}
	actual, err := msg.Marshal()
	if err != nil {
		t.Fatal(err)
	}
	if !bytes.Equal(actual, expected[:]) {
		t.Fatal("failed to correctly encode custom CID type")
	}
}