Skip to content

Commit

Permalink
test(message): test custom CID type (#309)
Browse files Browse the repository at this point in the history
This got dropped from my other patch.

This commit was moved from ipfs/go-bitswap@03e6d1f
  • Loading branch information
Stebalien authored Mar 19, 2020
1 parent ea674aa commit 762d2dd
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions bitswap/message/pb/cid_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package bitswap_message_pb_test

import (
"bytes"
"testing"

"github.com/ipfs/go-cid"
u "github.com/ipfs/go-ipfs-util"

pb "github.com/ipfs/go-bitswap/message/pb"
)

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")
}
}

0 comments on commit 762d2dd

Please sign in to comment.