master
sh 111 lines 2.83 KB
Raw
1 #!/usr/bin/env bash
2
3 test_description="Test basic operations with identity hash"
4
5 . lib/test-lib.sh
6
7 test_init_ipfs
8
9 ID_HASH0=bafkqaedknncdsodknncdsnzvnbvuioak
10 ID_HASH0_CONTENTS=jkD98jkD975hkD8
11
12 test_expect_success "can fetch random identity hash" '
13 ipfs cat $ID_HASH0 > expected &&
14 echo $ID_HASH0_CONTENTS > actual &&
15 test_cmp expected actual
16 '
17
18 test_expect_success "can pin random identity hash" '
19 ipfs pin add $ID_HASH0
20 '
21
22 test_expect_success "ipfs add succeeds with identity hash" '
23 echo "djkd7jdkd7jkHHG" > junk.txt &&
24 HASH=$(ipfs add -q --hash=identity junk.txt)
25 '
26
27 test_expect_success "content not actually added" '
28 ipfs refs local > locals &&
29 test_should_not_contain $HASH locals
30 '
31
32 test_expect_success "but can fetch it anyway" '
33 ipfs cat $HASH > actual &&
34 test_cmp junk.txt actual
35 '
36
37 test_expect_success "block rm does nothing" '
38 ipfs pin rm $HASH &&
39 ipfs block rm $HASH
40 '
41
42 test_expect_success "can still fetch it" '
43 ipfs cat $HASH > actual
44 test_cmp junk.txt actual
45 '
46
47 test_expect_success "ipfs add --inline works as expected" '
48 echo $ID_HASH0_CONTENTS > afile &&
49 HASH=$(ipfs add -q --inline afile)
50 '
51
52 test_expect_success "ipfs add --inline uses identity multihash" '
53 MHTYPE=`cid-fmt %h $HASH`
54 echo "mhtype is $MHTYPE"
55 test "$MHTYPE" = identity
56 '
57
58 test_expect_success "ipfs add --inline --raw-leaves works as expected" '
59 echo $ID_HASH0_CONTENTS > afile &&
60 HASH=$(ipfs add -q --inline --raw-leaves afile)
61 '
62
63 test_expect_success "ipfs add --inline --raw-leaves outputs the correct hash" '
64 echo "$ID_HASH0" = "$HASH" &&
65 test "$ID_HASH0" = "$HASH"
66 '
67
68 test_expect_success "create 1000 bytes file and get its hash" '
69 random-data -size=1000 -seed=2 > 1000bytes &&
70 HASH0=$(ipfs add -q --raw-leaves --only-hash 1000bytes)
71 '
72
73 test_expect_success "ipfs add --inline --raw-leaves works as expected on large file" '
74 HASH=$(ipfs add -q --inline --raw-leaves 1000bytes)
75 '
76
77 test_expect_success "ipfs add --inline --raw-leaves outputs the correct hash on large file" '
78 echo "$HASH0" = "$HASH" &&
79 test "$HASH0" = "$HASH"
80 '
81
82 test_expect_success "enable filestore" '
83 ipfs config --json Experimental.FilestoreEnabled true
84 '
85
86 test_expect_success "can fetch random identity hash (filestore enabled)" '
87 ipfs cat $ID_HASH0 > expected &&
88 echo $ID_HASH0_CONTENTS > actual &&
89 test_cmp expected actual
90 '
91
92 test_expect_success "can pin random identity hash (filestore enabled)" '
93 ipfs pin add $ID_HASH0
94 '
95
96 test_expect_success "ipfs add succeeds with identity hash and --nocopy" '
97 echo "djkd7jdkd7jkHHG" > junk.txt &&
98 HASH=$(ipfs add -q --hash=identity --nocopy junk.txt)
99 '
100
101 test_expect_success "content not actually added (filestore enabled)" '
102 ipfs refs local > locals &&
103 test_should_not_contain $HASH locals
104 '
105
106 test_expect_success "but can fetch it anyway (filestore enabled)" '
107 ipfs cat $HASH > actual &&
108 test_cmp junk.txt actual
109 '
110
111 test_done