@@ -6,6 +6,7 @@ const { getDescribe, getIt, expect } = require('../utils/mocha')
6
6
const { DAGNode } = require ( 'ipld-dag-pb' )
7
7
const all = require ( 'it-all' )
8
8
const testTimeout = require ( '../utils/test-timeout' )
9
+ const CID = require ( 'cids' )
9
10
10
11
/** @typedef { import("ipfsd-ctl/src/factory") } Factory */
11
12
/**
@@ -58,15 +59,15 @@ module.exports = (common, options) => {
58
59
// the initial list and contain hash
59
60
const refsAfterAdd = await all ( ipfs . refs . local ( ) )
60
61
expect ( refsAfterAdd . length ) . to . be . gt ( refsBeforeAdd . length )
61
- expect ( refsAfterAdd . map ( r => r . ref ) ) . includes ( cid . toString ( ) )
62
+ expect ( refsAfterAdd . map ( r => new CID ( r . ref ) . multihash ) ) . deep . includes ( cid . multihash )
62
63
63
64
// Run garbage collection
64
65
await all ( ipfs . repo . gc ( ) )
65
66
66
67
// Get the list of local blocks after GC, should still contain the hash,
67
68
// because the file is still pinned
68
69
const refsAfterGc = await all ( ipfs . refs . local ( ) )
69
- expect ( refsAfterGc . map ( r => r . ref ) ) . includes ( cid . toString ( ) )
70
+ expect ( refsAfterGc . map ( r => new CID ( r . ref ) . multihash ) ) . deep . includes ( cid . multihash )
70
71
71
72
// Unpin the data
72
73
await ipfs . pin . rm ( cid )
@@ -76,7 +77,7 @@ module.exports = (common, options) => {
76
77
77
78
// The list of local blocks should no longer contain the hash
78
79
const refsAfterUnpinAndGc = await all ( ipfs . refs . local ( ) )
79
- expect ( refsAfterUnpinAndGc . map ( r => r . ref ) ) . not . includes ( cid . toString ( ) )
80
+ expect ( refsAfterUnpinAndGc . map ( r => new CID ( r . ref ) . multihash ) ) . not . deep . includes ( cid . multihash )
80
81
} )
81
82
82
83
it ( 'should clean up removed MFS files' , async ( ) => {
@@ -87,21 +88,20 @@ module.exports = (common, options) => {
87
88
await ipfs . files . write ( '/test' , Buffer . from ( 'oranges' ) , { create : true } )
88
89
const stats = await ipfs . files . stat ( '/test' )
89
90
expect ( stats . type ) . to . equal ( 'file' )
90
- const hash = stats . cid . toString ( )
91
91
92
92
// Get the list of local blocks after the add, should be bigger than
93
93
// the initial list and contain hash
94
94
const refsAfterAdd = await all ( ipfs . refs . local ( ) )
95
95
expect ( refsAfterAdd . length ) . to . be . gt ( refsBeforeAdd . length )
96
- expect ( refsAfterAdd . map ( r => r . ref ) ) . includes ( hash )
96
+ expect ( refsAfterAdd . map ( r => new CID ( r . ref ) . multihash ) ) . deep . includes ( stats . cid . multihash )
97
97
98
98
// Run garbage collection
99
99
await all ( ipfs . repo . gc ( ) )
100
100
101
101
// Get the list of local blocks after GC, should still contain the hash,
102
102
// because the file is in MFS
103
103
const refsAfterGc = await all ( ipfs . refs . local ( ) )
104
- expect ( refsAfterGc . map ( r => r . ref ) ) . includes ( hash )
104
+ expect ( refsAfterGc . map ( r => new CID ( r . ref ) . multihash ) ) . deep . includes ( stats . cid . multihash )
105
105
106
106
// Remove the file
107
107
await ipfs . files . rm ( '/test' )
@@ -111,7 +111,7 @@ module.exports = (common, options) => {
111
111
112
112
// The list of local blocks should no longer contain the hash
113
113
const refsAfterUnpinAndGc = await all ( ipfs . refs . local ( ) )
114
- expect ( refsAfterUnpinAndGc . map ( r => r . ref ) ) . not . includes ( hash )
114
+ expect ( refsAfterUnpinAndGc . map ( r => new CID ( r . ref ) . multihash ) ) . not . deep . includes ( stats . cid . multihash )
115
115
} )
116
116
117
117
it ( 'should clean up block only after unpinned and removed from MFS' , async ( ) => {
@@ -135,17 +135,15 @@ module.exports = (common, options) => {
135
135
// the initial list and contain the data hash
136
136
const refsAfterAdd = await all ( ipfs . refs . local ( ) )
137
137
expect ( refsAfterAdd . length ) . to . be . gt ( refsBeforeAdd . length )
138
- const hashesAfterAdd = refsAfterAdd . map ( r => r . ref )
139
- expect ( hashesAfterAdd ) . includes ( dataCid . toString ( ) )
138
+ expect ( refsAfterAdd . map ( r => new CID ( r . ref ) . multihash ) ) . deep . includes ( dataCid . multihash )
140
139
141
140
// Run garbage collection
142
141
await all ( ipfs . repo . gc ( ) )
143
142
144
143
// Get the list of local blocks after GC, should still contain the hash,
145
144
// because the file is pinned and in MFS
146
145
const refsAfterGc = await all ( ipfs . refs . local ( ) )
147
- const hashesAfterGc = refsAfterGc . map ( r => r . ref )
148
- expect ( hashesAfterGc ) . includes ( dataCid . toString ( ) )
146
+ expect ( refsAfterGc . map ( r => new CID ( r . ref ) . multihash ) ) . deep . includes ( dataCid . multihash )
149
147
150
148
// Remove the file
151
149
await ipfs . files . rm ( '/test' )
@@ -156,9 +154,8 @@ module.exports = (common, options) => {
156
154
// Get the list of local blocks after GC, should still contain the hash,
157
155
// because the file is still pinned
158
156
const refsAfterRmAndGc = await all ( ipfs . refs . local ( ) )
159
- const hashesAfterRmAndGc = refsAfterRmAndGc . map ( r => r . ref )
160
- expect ( hashesAfterRmAndGc ) . not . includes ( mfsFileCid . toString ( ) )
161
- expect ( hashesAfterRmAndGc ) . includes ( dataCid . toString ( ) )
157
+ expect ( refsAfterRmAndGc . map ( r => new CID ( r . ref ) . multihash ) ) . not . deep . includes ( mfsFileCid . multihash )
158
+ expect ( refsAfterRmAndGc . map ( r => new CID ( r . ref ) . multihash ) ) . deep . includes ( dataCid . multihash )
162
159
163
160
// Unpin the data
164
161
await ipfs . pin . rm ( dataCid )
@@ -168,9 +165,8 @@ module.exports = (common, options) => {
168
165
169
166
// The list of local blocks should no longer contain the hashes
170
167
const refsAfterUnpinAndGc = await all ( ipfs . refs . local ( ) )
171
- const hashesAfterUnpinAndGc = refsAfterUnpinAndGc . map ( r => r . ref )
172
- expect ( hashesAfterUnpinAndGc ) . not . includes ( mfsFileCid . toString ( ) )
173
- expect ( hashesAfterUnpinAndGc ) . not . includes ( dataCid . toString ( ) )
168
+ expect ( refsAfterUnpinAndGc . map ( r => new CID ( r . ref ) . multihash ) ) . not . deep . includes ( mfsFileCid . multihash )
169
+ expect ( refsAfterUnpinAndGc . map ( r => new CID ( r . ref ) . multihash ) ) . not . deep . includes ( dataCid . multihash )
174
170
} )
175
171
176
172
it ( 'should clean up indirectly pinned data after recursive pin removal' , async ( ) => {
@@ -201,9 +197,8 @@ module.exports = (common, options) => {
201
197
// the initial list and contain data and object hash
202
198
const refsAfterAdd = await all ( ipfs . refs . local ( ) )
203
199
expect ( refsAfterAdd . length ) . to . be . gt ( refsBeforeAdd . length )
204
- const hashesAfterAdd = refsAfterAdd . map ( r => r . ref )
205
- expect ( hashesAfterAdd ) . includes ( objCid . toString ( ) )
206
- expect ( hashesAfterAdd ) . includes ( dataCid . toString ( ) )
200
+ expect ( refsAfterAdd . map ( r => new CID ( r . ref ) . multihash ) ) . deep . includes ( objCid . multihash )
201
+ expect ( refsAfterAdd . map ( r => new CID ( r . ref ) . multihash ) ) . deep . includes ( dataCid . multihash )
207
202
208
203
// Recursively pin the object
209
204
await ipfs . pin . add ( objCid , { recursive : true } )
@@ -218,7 +213,7 @@ module.exports = (common, options) => {
218
213
// Get the list of local blocks after GC, should still contain the data
219
214
// hash, because the data is still (indirectly) pinned
220
215
const refsAfterGc = await all ( ipfs . refs . local ( ) )
221
- expect ( refsAfterGc . map ( r => r . ref ) ) . includes ( dataCid . toString ( ) )
216
+ expect ( refsAfterGc . map ( r => new CID ( r . ref ) . multihash ) ) . deep . includes ( dataCid . multihash )
222
217
223
218
// Recursively unpin the object
224
219
await ipfs . pin . rm ( objCid . toString ( ) )
@@ -228,9 +223,8 @@ module.exports = (common, options) => {
228
223
229
224
// The list of local blocks should no longer contain the hashes
230
225
const refsAfterUnpinAndGc = await all ( ipfs . refs . local ( ) )
231
- const hashesAfterUnpinAndGc = refsAfterUnpinAndGc . map ( r => r . ref )
232
- expect ( hashesAfterUnpinAndGc ) . not . includes ( objCid . toString ( ) )
233
- expect ( hashesAfterUnpinAndGc ) . not . includes ( dataCid . toString ( ) )
226
+ expect ( refsAfterUnpinAndGc . map ( r => new CID ( r . ref ) . multihash ) ) . not . deep . includes ( objCid . multihash )
227
+ expect ( refsAfterUnpinAndGc . map ( r => new CID ( r . ref ) . multihash ) ) . not . deep . includes ( dataCid . multihash )
234
228
} )
235
229
} )
236
230
}
0 commit comments