@@ -11,6 +11,7 @@ import { sha256 } from 'multiformats/hashes/sha2'
1111import { IdentityBlockstore } from '../src/identity.js'
1212import { MemoryBlockstore } from '../src/memory.js'
1313import type { Blockstore } from 'interface-blockstore'
14+ import type { AbortOptions } from 'interface-store'
1415
1516describe ( 'identity' , ( ) => {
1617 let blockstore : Blockstore
@@ -86,6 +87,20 @@ describe('identity', () => {
8687 expect ( toBuffer ( await all ( blockstore . get ( cid ) ) ) ) . to . equalBytes ( block )
8788 } )
8889
90+ it ( 'gets CIDs from child (async)' , async ( ) => {
91+ const block = Uint8Array . from ( [ 0 , 1 , 2 , 3 , 4 ] )
92+ const multihash = await sha256 . digest ( block )
93+ const cid = CID . createV1 ( raw . code , multihash )
94+
95+ await child . put ( cid , block )
96+
97+ const { get } = child
98+ child . get = async function * ( key : CID , options : AbortOptions ) { yield * get . bind ( child ) ( key , options ) }
99+ blockstore = new IdentityBlockstore ( child )
100+ expect ( blockstore . has ( cid ) ) . to . be . true ( )
101+ expect ( toBuffer ( await all ( blockstore . get ( cid ) ) ) ) . to . equalBytes ( block )
102+ } )
103+
89104 it ( 'has CIDs from child' , async ( ) => {
90105 const block = Uint8Array . from ( [ 0 , 1 , 2 , 3 , 4 ] )
91106 const multihash = await sha256 . digest ( block )
@@ -128,6 +143,24 @@ describe('identity', () => {
128143 expect ( result [ 0 ] . cid . toString ( ) ) . to . equal ( cid . toString ( ) )
129144 } )
130145
146+ it ( 'gets all pairs from child (async)' , async ( ) => {
147+ const block = Uint8Array . from ( [ 0 , 1 , 2 , 3 , 4 ] )
148+ const multihash = await sha256 . digest ( block )
149+ const cid = CID . createV1 ( raw . code , multihash )
150+
151+ await child . put ( cid , block )
152+
153+ const { getAll } = child
154+ child . getAll = async function * ( options ?: AbortOptions ) { yield * getAll . bind ( child ) ( options ) }
155+ blockstore = new IdentityBlockstore ( child )
156+ expect ( blockstore . has ( cid ) ) . to . be . true ( )
157+
158+ const result = await all ( blockstore . getAll ( ) )
159+
160+ expect ( result ) . to . have . lengthOf ( 1 )
161+ expect ( result [ 0 ] . cid . toString ( ) ) . to . equal ( cid . toString ( ) )
162+ } )
163+
131164 it ( 'should enforce a maximum digest size' , async ( ) => {
132165 blockstore = new IdentityBlockstore ( child , {
133166 maxDigestLength : 5
@@ -141,7 +174,7 @@ describe('identity', () => {
141174 expect ( blockstore . put ( CID . createV1 ( raw . code , identity . digest ( ok ) ) , buf ) ) . to . be . ok ( )
142175 expect ( blockstore . has ( CID . createV1 ( raw . code , identity . digest ( ok ) ) ) ) . to . be . ok ( )
143176
144- expect ( ( ) => all ( blockstore . get ( CID . createV1 ( raw . code , identity . digest ( tooLong ) ) ) ) ) . to . throw ( )
177+ await expect ( all ( blockstore . get ( CID . createV1 ( raw . code , identity . digest ( tooLong ) ) ) ) ) . to . eventually . be . rejected ( )
145178 . with . property ( 'name' , 'IdentityHashDigestTooLongError' )
146179
147180 expect ( ( ) => blockstore . put ( CID . createV1 ( raw . code , identity . digest ( tooLong ) ) , buf ) ) . to . throw ( )
0 commit comments