Skip to content

Commit eaeadd3

Browse files
committed
fix: change the way sigchain handles getting signedClaims when given an order (it was the wrong way around)
fix: fixed discovery test failure for updates previously discovered gestalts
1 parent 465e40f commit eaeadd3

File tree

4 files changed

+76
-7
lines changed

4 files changed

+76
-7
lines changed

src/nodes/NodeManager.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1257,12 +1257,18 @@ class NodeManager {
12571257
return await this.withConnF(targetNodeId, ctx, async (connection) => {
12581258
const claims: Record<ClaimId, SignedClaim> = {};
12591259
const client = connection.getClient();
1260+
let claimIdEncoded: ClaimIdEncoded | undefined;
1261+
1262+
if(claimId != null){
1263+
claimIdEncoded = claimsUtils.encodeClaimId(claimId);
1264+
}else
1265+
{
1266+
claimIdEncoded = undefined;
1267+
}
1268+
12601269
for await (const agentClaim of await client.methods.nodesClaimsGet(
12611270
{
1262-
seek:
1263-
claimId != null
1264-
? claimsUtils.encodeClaimId(claimId)
1265-
: ('' as ClaimIdEncoded),
1271+
seek: claimIdEncoded,
12661272
},
12671273
ctx,
12681274
)) {

src/nodes/agent/handlers/NodesClaimsGet.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@ class NodesClaimsGet extends ServerHandler<
3232
const { seek, order, limit } = input;
3333
const { sigchain, db }: { sigchain: Sigchain; db: DB } = this.container;
3434

35-
const decodedClaimId = ids.decodeClaimId(seek);
35+
let decodedClaimId = ids.decodeClaimId(seek);
36+
if (decodedClaimId == null) {
37+
decodedClaimId = undefined;
38+
}
3639

3740
yield* db.withTransactionG(async function* (tran): AsyncGenerator<
3841
AgentRPCResponseResult<AgentClaimMessage>

src/sigchain/Sigchain.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -354,10 +354,10 @@ class Sigchain {
354354
seekOptions =
355355
order === 'asc'
356356
? {
357-
lte: [seek.toBuffer()],
357+
gte: [seek.toBuffer()],
358358
}
359359
: {
360-
gte: [seek.toBuffer()],
360+
lte: [seek.toBuffer()],
361361
};
362362
}
363363
for await (const [kP, claim] of tran.iterator<Claim>(this.dbClaimsPath, {

tests/nodes/agent/handlers/nodesClaimsGet.test.ts

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import * as keysUtils from '@/keys/utils';
1616
import * as networkUtils from '@/network/utils';
1717
import * as tlsTestsUtils from '../../../utils/tls';
1818
import * as testNodesUtils from '../../../nodes/utils';
19+
import { ClaimIdEncoded } from '@/ids';
1920

2021
describe('nodesClaimsGet', () => {
2122
const logger = new Logger('nodesClaimsGet test', LogLevel.WARN, [
@@ -314,4 +315,63 @@ describe('nodesClaimsGet', () => {
314315
// Verify the array is empty
315316
expect(claimIds).toHaveLength(0);
316317
});
318+
319+
320+
test('Should get chain data with valid seek parameter and all chain data if invalid seek', async () => {
321+
const srcNodeIdEncoded = nodesUtils.encodeNodeId(keyRing.getNodeId());
322+
323+
// Add 10 claims
324+
for (let i = 1; i <= 5; i++) {
325+
const node2 = nodesUtils.encodeNodeId(
326+
testNodesUtils.generateRandomNodeId(),
327+
);
328+
const nodeLink = {
329+
type: 'ClaimLinkNode',
330+
iss: srcNodeIdEncoded,
331+
sub: node2,
332+
};
333+
await sigchain.addClaim(nodeLink);
334+
}
335+
for (let i = 6; i <= 10; i++) {
336+
const identityLink = {
337+
type: 'ClaimLinkIdentity',
338+
iss: srcNodeIdEncoded,
339+
sub: encodeProviderIdentityId([
340+
('ProviderId' + i.toString()) as ProviderId,
341+
('IdentityId' + i.toString()) as IdentityId,
342+
]),
343+
};
344+
await sigchain.addClaim(identityLink);
345+
}
346+
347+
// First, if we provide an invalid seek value, we should get all claims.
348+
let response = await rpcClient.methods.nodesClaimsGet({ seek: undefined });
349+
const allClaimIds: ClaimIdEncoded[] = [];
350+
for await (const claim of response) {
351+
// We assume claimIdEncoded is defined for all returned claims.
352+
allClaimIds.push(claim.claimIdEncoded!);
353+
}
354+
expect(allClaimIds).toHaveLength(10);
355+
356+
// Now choose a seek claim.
357+
const seekClaimId = allClaimIds[3];
358+
359+
// Now retrieve claims starting from the seek value.
360+
response = await rpcClient.methods.nodesClaimsGet({ order: 'asc', seek: seekClaimId });
361+
const subsetClaimIds: string[] = [];
362+
for await (const claim of response) {
363+
subsetClaimIds.push(claim.claimIdEncoded!);
364+
}
365+
366+
// Our expectation is that the claim with the seek value is excluded
367+
// and that the remaining claims match the tail of allClaimIds.
368+
console.log("subsetClaimIds",subsetClaimIds);
369+
console.log("allClaimIds",allClaimIds);
370+
console.log("allClaimIds.slice(4)",allClaimIds.slice(3));
371+
console.log("seekClaimId", seekClaimId);
372+
expect(subsetClaimIds).toEqual(allClaimIds.slice(3));
373+
});
374+
375+
376+
317377
});

0 commit comments

Comments
 (0)