@@ -16,6 +16,7 @@ import * as sigchainErrors from '@/sigchain/errors';
1616import * as keysUtils from '@/keys/utils' ;
1717import * as claimsUtils from '@/claims/utils' ;
1818import * as utils from '@/utils' ;
19+ import * as testsNodesUtils from '../nodes/utils' ;
1920
2021describe ( Sigchain . name , ( ) => {
2122 const password = keysUtils . getRandomBytes ( 10 ) . toString ( 'utf-8' ) ;
@@ -317,4 +318,62 @@ describe(Sigchain.name, () => {
317318 await sigchain . stop ( ) ;
318319 } ,
319320 ) ;
321+ test ( 'getClaims with seek ascending' , async ( ) => {
322+ const sigchain = await Sigchain . createSigchain ( {
323+ keyRing,
324+ db,
325+ logger,
326+ fresh : true ,
327+ } ) ;
328+ const claims : Array < [ ClaimId , SignedClaim ] > = [ ] ;
329+ for ( let i = 0 ; i < 3 ; i ++ ) {
330+ claims . push ( await sigchain . addClaim ( { } ) ) ;
331+ }
332+ const claimsAsc = await AsyncIterable . as (
333+ sigchain . getClaims ( { seek : claims [ 1 ] [ 0 ] , order : 'asc' } ) ,
334+ ) . toArray ( ) ;
335+ expect ( claimsAsc ) . toHaveLength ( 2 ) ;
336+ // The claim we seeked to is included
337+ expect ( claimsAsc [ 0 ] [ 0 ] . equals ( claims [ 1 ] [ 0 ] ) ) . toBeTrue ( ) ;
338+ // And the claim after
339+ expect ( claimsAsc [ 1 ] [ 0 ] . equals ( claims [ 2 ] [ 0 ] ) ) . toBeTrue ( ) ;
340+ } ) ;
341+ test ( 'getClaims with seek descending' , async ( ) => {
342+ const sigchain = await Sigchain . createSigchain ( {
343+ keyRing,
344+ db,
345+ logger,
346+ fresh : true ,
347+ } ) ;
348+ const claims : Array < [ ClaimId , SignedClaim ] > = [ ] ;
349+ for ( let i = 0 ; i < 3 ; i ++ ) {
350+ claims . push ( await sigchain . addClaim ( { } ) ) ;
351+ }
352+ const claimsAsc = await AsyncIterable . as (
353+ sigchain . getClaims ( { seek : claims [ 1 ] [ 0 ] , order : 'desc' } ) ,
354+ ) . toArray ( ) ;
355+ expect ( claimsAsc ) . toHaveLength ( 2 ) ;
356+ // The claim we seeked to is included
357+ expect ( claimsAsc [ 0 ] [ 0 ] . equals ( claims [ 1 ] [ 0 ] ) ) . toBeTrue ( ) ;
358+ // And the claim after
359+ expect ( claimsAsc [ 1 ] [ 0 ] . equals ( claims [ 0 ] [ 0 ] ) ) . toBeTrue ( ) ;
360+ } ) ;
361+ test ( 'getClaims with seek with limit' , async ( ) => {
362+ const sigchain = await Sigchain . createSigchain ( {
363+ keyRing,
364+ db,
365+ logger,
366+ fresh : true ,
367+ } ) ;
368+ const claims : Array < [ ClaimId , SignedClaim ] > = [ ] ;
369+ for ( let i = 0 ; i < 3 ; i ++ ) {
370+ claims . push ( await sigchain . addClaim ( { } ) ) ;
371+ }
372+ const claimsAsc = await AsyncIterable . as (
373+ sigchain . getClaims ( { seek : claims [ 1 ] [ 0 ] , limit : 1 } ) ,
374+ ) . toArray ( ) ;
375+ expect ( claimsAsc ) . toHaveLength ( 1 ) ;
376+ // The claim we seeked to is included
377+ expect ( claimsAsc [ 0 ] [ 0 ] . equals ( claims [ 1 ] [ 0 ] ) ) . toBeTrue ( ) ;
378+ } ) ;
320379} ) ;
0 commit comments