Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion modules/sdk-coin-canton/src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, <blockHeight>_<version>
const [height] = hash.split('_');
const blockHeight = Number(height);
return !isNaN(blockHeight) && blockHeight > 0;
}

Expand Down
1 change: 1 addition & 0 deletions modules/sdk-coin-canton/test/resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
};
Expand Down
6 changes: 6 additions & 0 deletions modules/sdk-coin-canton/test/unit/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down