master
sh 131 lines 2.95 KB
Raw
1 #!/usr/bin/env bash
2 #
3 # Copyright (c) 2017 Jakub Sztandera
4 # MIT Licensed; see the LICENSE file in this repository.
5 #
6
7 test_description="CID Version 0/1 Duality"
8
9 . lib/test-lib.sh
10
11 test_init_ipfs
12
13 #
14 #
15 #
16
17 test_expect_success "create two small files" '
18 random-data -size=1000 -seed=7 > afile
19 random-data -size=1000 -seed=9 > bfile
20 '
21
22 test_expect_success "add file using CIDv1 but don't pin" '
23 AHASHv1=$(ipfs add -q --cid-version=1 --raw-leaves=false --pin=false afile)
24 '
25
26 test_expect_success "add file using CIDv0" '
27 AHASHv0=$(ipfs add -q --cid-version=0 afile)
28 '
29
30 test_expect_success "check hashes" '
31 test "$(cid-fmt %v-%c $AHASHv0)" = "cidv0-dag-pb" &&
32 test "$(cid-fmt %v-%c $AHASHv1)" = "cidv1-dag-pb" &&
33 test "$(cid-fmt -b z -v 0 %s $AHASHv1)" = "$AHASHv0"
34 '
35
36 test_expect_success "make sure CIDv1 hash really is in the repo" '
37 ipfs block stat $AHASHv1
38 '
39
40 test_expect_success "make sure CIDv0 hash really is in the repo" '
41 ipfs block stat $AHASHv0
42 '
43
44 test_expect_success "run gc" '
45 ipfs repo gc
46 '
47
48 test_expect_success "make sure the CIDv0 hash is in the repo" '
49 ipfs block stat $AHASHv0
50 '
51
52 test_expect_success "make sure we can get CIDv0 added file" '
53 ipfs cat $AHASHv0 > thefile &&
54 test_cmp afile thefile
55 '
56
57 test_expect_success "make sure the CIDv1 hash is not in the repo" '
58 ! ipfs refs local | grep -q $AHASHv1
59 '
60
61 test_expect_success "clean up" '
62 ipfs pin rm $AHASHv0 &&
63 ipfs repo gc &&
64 ! ipfs refs local | grep -q $AHASHv0
65 '
66
67 #
68 #
69 #
70
71 test_expect_success "add file using CIDv1 but don't pin" '
72 ipfs add -q --cid-version=1 --raw-leaves=false --pin=false afile
73 '
74
75 test_expect_success "check that we can access the file when converted to CIDv0" '
76 ipfs cat $AHASHv0 > thefile &&
77 test_cmp afile thefile
78 '
79
80 test_expect_success "clean up" '
81 ipfs repo gc
82 '
83
84 test_expect_success "add file using CIDv0 but don't pin" '
85 ipfs add -q --cid-version=0 --raw-leaves=false --pin=false afile
86 '
87
88 test_expect_success "check that we can access the file when converted to CIDv1" '
89 ipfs cat $AHASHv1 > thefile &&
90 test_cmp afile thefile
91 '
92
93 #
94 #
95 #
96
97 test_expect_success "set up iptb testbed" '
98 iptb testbed create -type localipfs -count 2 -init &&
99 iptb run -- ipfs config --json "Routing.LoopbackAddressesOnLanDHT" true
100 '
101
102 test_expect_success "start nodes" '
103 iptb start -wait &&
104 iptb connect 0 1
105 '
106
107 test_expect_success "add afile using CIDv0 to node 0" '
108 iptb run 0 -- ipfs add -q --cid-version=0 afile
109 '
110
111 test_expect_success "get afile using CIDv1 via node 1" '
112 iptb -quiet run 1 -- ipfs --timeout=2s cat $AHASHv1 > thefile &&
113 test_cmp afile thefile
114 '
115
116 test_expect_success "add bfile using CIDv1 to node 0" '
117 BHASHv1=$(iptb -quiet run 0 -- ipfs add -q --cid-version=1 --raw-leaves=false bfile)
118 '
119
120 test_expect_success "get bfile using CIDv0 via node 1" '
121 BHASHv0=$(cid-fmt -b z -v 0 %s $BHASHv1)
122 echo $BHASHv1 &&
123 iptb -quiet run 1 -- ipfs --timeout=2s cat $BHASHv0 > thefile &&
124 test_cmp bfile thefile
125 '
126
127 test_expect_success "stop testbed" '
128 iptb stop
129 '
130
131 test_done