@@ -7,12 +7,13 @@ import (
7
7
"io/ioutil"
8
8
"testing"
9
9
10
- mdtest "github.com/ipfs/go-merkledag/test"
11
10
uio "github.com/ipfs/go-unixfs/io"
12
11
12
+ cid "github.com/ipfs/go-cid"
13
13
chunker "github.com/ipfs/go-ipfs-chunker"
14
14
u "github.com/ipfs/go-ipfs-util"
15
15
ipld "github.com/ipfs/go-ipld-format"
16
+ mdtest "github.com/ipfs/go-merkledag/test"
16
17
)
17
18
18
19
func getBalancedDag (t testing.TB , size int64 , blksize int64 ) (ipld.Node , ipld.DAGService ) {
@@ -35,6 +36,40 @@ func getTrickleDag(t testing.TB, size int64, blksize int64) (ipld.Node, ipld.DAG
35
36
return nd , ds
36
37
}
37
38
39
+ func TestStableCid (t * testing.T ) {
40
+ ds := mdtest .Mock ()
41
+ buf := make ([]byte , 10 * 1024 * 1024 )
42
+ u .NewSeededRand (0xdeadbeef ).Read (buf )
43
+ r := bytes .NewReader (buf )
44
+
45
+ nd , err := BuildDagFromReader (ds , chunker .DefaultSplitter (r ))
46
+ if err != nil {
47
+ t .Fatal (err )
48
+ }
49
+
50
+ expected , err := cid .Decode ("QmZN1qquw84zhV4j6vT56tCcmFxaDaySL1ezTXFvMdNmrK" )
51
+ if err != nil {
52
+ t .Fatal (err )
53
+ }
54
+ if ! expected .Equals (nd .Cid ()) {
55
+ t .Fatalf ("expected CID %s, got CID %s" , expected , nd )
56
+ }
57
+
58
+ dr , err := uio .NewDagReader (context .Background (), nd , ds )
59
+ if err != nil {
60
+ t .Fatal (err )
61
+ }
62
+
63
+ out , err := ioutil .ReadAll (dr )
64
+ if err != nil {
65
+ t .Fatal (err )
66
+ }
67
+
68
+ if ! bytes .Equal (out , buf ) {
69
+ t .Fatal ("bad read" )
70
+ }
71
+ }
72
+
38
73
func TestBalancedDag (t * testing.T ) {
39
74
ds := mdtest .Mock ()
40
75
buf := make ([]byte , 10000 )
0 commit comments