generated from ipfs/ipfs-repository-template
-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(message): test custom CID type (#309)
This got dropped from my other patch. This commit was moved from ipfs/go-bitswap@03e6d1f
- Loading branch information
Showing
1 changed file
with
32 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} | ||
} |