@@ -6,6 +6,7 @@ const { getDescribe, getIt, expect } = require('../utils/mocha')
66const { DAGNode } = require ( 'ipld-dag-pb' )
77const all = require ( 'it-all' )
88const testTimeout = require ( '../utils/test-timeout' )
9+ const CID = require ( 'cids' )
910
1011/** @typedef { import("ipfsd-ctl/src/factory") } Factory */
1112/**
@@ -58,15 +59,15 @@ module.exports = (common, options) => {
5859 // the initial list and contain hash
5960 const refsAfterAdd = await all ( ipfs . refs . local ( ) )
6061 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 )
6263
6364 // Run garbage collection
6465 await all ( ipfs . repo . gc ( ) )
6566
6667 // Get the list of local blocks after GC, should still contain the hash,
6768 // because the file is still pinned
6869 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 )
7071
7172 // Unpin the data
7273 await ipfs . pin . rm ( cid )
@@ -76,7 +77,7 @@ module.exports = (common, options) => {
7677
7778 // The list of local blocks should no longer contain the hash
7879 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 )
8081 } )
8182
8283 it ( 'should clean up removed MFS files' , async ( ) => {
@@ -87,21 +88,20 @@ module.exports = (common, options) => {
8788 await ipfs . files . write ( '/test' , Buffer . from ( 'oranges' ) , { create : true } )
8889 const stats = await ipfs . files . stat ( '/test' )
8990 expect ( stats . type ) . to . equal ( 'file' )
90- const hash = stats . cid . toString ( )
9191
9292 // Get the list of local blocks after the add, should be bigger than
9393 // the initial list and contain hash
9494 const refsAfterAdd = await all ( ipfs . refs . local ( ) )
9595 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 )
9797
9898 // Run garbage collection
9999 await all ( ipfs . repo . gc ( ) )
100100
101101 // Get the list of local blocks after GC, should still contain the hash,
102102 // because the file is in MFS
103103 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 )
105105
106106 // Remove the file
107107 await ipfs . files . rm ( '/test' )
@@ -111,7 +111,7 @@ module.exports = (common, options) => {
111111
112112 // The list of local blocks should no longer contain the hash
113113 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 )
115115 } )
116116
117117 it ( 'should clean up block only after unpinned and removed from MFS' , async ( ) => {
@@ -135,17 +135,15 @@ module.exports = (common, options) => {
135135 // the initial list and contain the data hash
136136 const refsAfterAdd = await all ( ipfs . refs . local ( ) )
137137 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 )
140139
141140 // Run garbage collection
142141 await all ( ipfs . repo . gc ( ) )
143142
144143 // Get the list of local blocks after GC, should still contain the hash,
145144 // because the file is pinned and in MFS
146145 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 )
149147
150148 // Remove the file
151149 await ipfs . files . rm ( '/test' )
@@ -156,9 +154,8 @@ module.exports = (common, options) => {
156154 // Get the list of local blocks after GC, should still contain the hash,
157155 // because the file is still pinned
158156 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 )
162159
163160 // Unpin the data
164161 await ipfs . pin . rm ( dataCid )
@@ -168,9 +165,8 @@ module.exports = (common, options) => {
168165
169166 // The list of local blocks should no longer contain the hashes
170167 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 )
174170 } )
175171
176172 it ( 'should clean up indirectly pinned data after recursive pin removal' , async ( ) => {
@@ -201,9 +197,8 @@ module.exports = (common, options) => {
201197 // the initial list and contain data and object hash
202198 const refsAfterAdd = await all ( ipfs . refs . local ( ) )
203199 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 )
207202
208203 // Recursively pin the object
209204 await ipfs . pin . add ( objCid , { recursive : true } )
@@ -218,7 +213,7 @@ module.exports = (common, options) => {
218213 // Get the list of local blocks after GC, should still contain the data
219214 // hash, because the data is still (indirectly) pinned
220215 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 )
222217
223218 // Recursively unpin the object
224219 await ipfs . pin . rm ( objCid . toString ( ) )
@@ -228,9 +223,8 @@ module.exports = (common, options) => {
228223
229224 // The list of local blocks should no longer contain the hashes
230225 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 )
234228 } )
235229 } )
236230}
0 commit comments