From f6e28ae356a7db4f78eea92357b761de4a5829ef Mon Sep 17 00:00:00 2001 From: Ravi Hegde Date: Thu, 11 Dec 2025 03:03:22 +0530 Subject: [PATCH] feat: added support for versioned blockId validation Ticket: COIN-6858 --- modules/sdk-coin-canton/src/lib/utils.ts | 4 +++- modules/sdk-coin-canton/test/resources.ts | 1 + modules/sdk-coin-canton/test/unit/utils.ts | 6 ++++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/modules/sdk-coin-canton/src/lib/utils.ts b/modules/sdk-coin-canton/src/lib/utils.ts index 725ea4ee59..547bb5f73f 100644 --- a/modules/sdk-coin-canton/src/lib/utils.ts +++ b/modules/sdk-coin-canton/src/lib/utils.ts @@ -25,7 +25,9 @@ export class Utils implements BaseUtils { /** @inheritdoc */ isValidBlockId(hash: string): boolean { // In canton, there is no block hash, we store the height as the _id (hash) - const blockHeight = Number(hash); + // this will be of the form, _ + const [height] = hash.split('_'); + const blockHeight = Number(height); return !isNaN(blockHeight) && blockHeight > 0; } diff --git a/modules/sdk-coin-canton/test/resources.ts b/modules/sdk-coin-canton/test/resources.ts index c70beeee6e..b12bb27759 100644 --- a/modules/sdk-coin-canton/test/resources.ts +++ b/modules/sdk-coin-canton/test/resources.ts @@ -100,6 +100,7 @@ export const CANTON_ADDRESSES = { export const CANTON_BLOCK_HEIGHT = { VALID_HASH: '123456', + VALID_HASH_WITH_VERSION: '123456_5.1.0', INVALID_BLOCK_HASH: 'xyz', NEGATIVE_BLOCK_HASH: '-100', }; diff --git a/modules/sdk-coin-canton/test/unit/utils.ts b/modules/sdk-coin-canton/test/unit/utils.ts index feb6f20a4f..77b12a3744 100644 --- a/modules/sdk-coin-canton/test/unit/utils.ts +++ b/modules/sdk-coin-canton/test/unit/utils.ts @@ -162,6 +162,12 @@ describe('Canton Util', function () { assert.strictEqual(isValid, true); }); + it('should return true when the block hash has version', function () { + const isValid = utils.isValidBlockId(CANTON_BLOCK_HEIGHT.VALID_HASH_WITH_VERSION); + should.exist(isValid); + assert.strictEqual(isValid, true); + }); + it('should return false when the block hash is not a number', function () { const isValid = utils.isValidBlockId(CANTON_BLOCK_HEIGHT.INVALID_BLOCK_HASH); should.exist(isValid);