-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcid_test.go
More file actions
130 lines (114 loc) · 2.54 KB
/
Copy pathcid_test.go
File metadata and controls
130 lines (114 loc) · 2.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
package ipfs_test
import (
"bytes"
"context"
"crypto/rand"
"fmt"
"testing"
"time"
"github.com/ipfs/go-merkledag"
"github.com/photon-storage/go-common/testing/require"
ipfs "github.com/photon-storage/go-ipfs-lite"
)
func TestCidTest(t *testing.T) {
dagTypes := []ipfs.DagType{
ipfs.DagBalanced,
ipfs.DagTrickle,
}
chunkSizes := []int64{
1023,
1024,
1025,
65535,
65536,
65537,
262143,
262144,
262145,
}
data := make([]byte, 4<<20+123)
_, err := rand.Reader.Read(data)
require.NoError(t, err)
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
defer cancel()
for _, dt := range dagTypes {
for _, cs := range chunkSizes {
for _, lpb := range []int{2, 7, 16} {
for _, rl := range []bool{true, false} {
cid0, err := ipfs.GenCid(
ctx,
data,
ipfs.CidOpts{
DagType: dt,
ChunkSize: cs,
LinksPerBlock: lpb,
RawLeaves: rl,
CidBuilder: merkledag.V1CidPrefix(),
},
)
require.NoError(t, err)
cid1, err := ipfs.GenCid(
ctx,
bytes.NewReader(data),
ipfs.CidOpts{
DagType: dt,
ChunkSize: cs,
LinksPerBlock: lpb,
RawLeaves: rl,
CidBuilder: merkledag.V1CidPrefix(),
},
)
require.NoError(t, err)
cid2, err := ipfs.GenCid(
ctx,
ipfs.NewDataProvider(
bytes.NewReader(data),
cs,
),
ipfs.CidOpts{
DagType: dt,
ChunkSize: cs,
LinksPerBlock: lpb,
RawLeaves: rl,
CidBuilder: merkledag.V1CidPrefix(),
},
)
require.NoError(t, err)
require.Equal(t, cid0.String(), cid1.String())
require.Equal(t, cid1.String(), cid2.String())
}
}
}
}
}
func TestCidConsistencyWithPut(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
defer cancel()
node, err := ipfs.New(ctx, ipfs.Config{
OfflineMode: true,
})
require.NoError(t, err)
// Wait 60 seconds for node to initialize.
// time.Sleep(60 * time.Second)
content := fmt.Sprintf("hello world test at unix nano %v", time.Now().UnixNano())
// Put object.
nd, err := node.PutObject(
ctx,
bytes.NewReader([]byte(content)),
ipfs.PutOpts{
DagType: ipfs.DagBalanced,
RawLeaves: false,
},
)
require.NoError(t, err)
cid, err := ipfs.GenCid(
ctx,
bytes.NewReader([]byte(content)),
ipfs.CidOpts{
DagType: ipfs.DagBalanced,
RawLeaves: false,
},
)
require.NoError(t, err)
require.Equal(t, nd.Cid().String(), cid.String())
}