diff --git a/modules/sdk-coin-canton/src/lib/utils.ts b/modules/sdk-coin-canton/src/lib/utils.ts index fdafe902fb..2c5c191ea2 100644 --- a/modules/sdk-coin-canton/src/lib/utils.ts +++ b/modules/sdk-coin-canton/src/lib/utils.ts @@ -20,7 +20,9 @@ export class Utils implements BaseUtils { /** @inheritdoc */ isValidBlockId(hash: string): boolean { - throw new Error('Method not implemented.'); + // In canton, there is no block hash, we store the height as the _id (hash) + const blockHeight = Number(hash); + return !isNaN(blockHeight) && blockHeight > 0; } /** @inheritdoc */ diff --git a/modules/sdk-coin-canton/src/lib/walletInitBuilder.ts b/modules/sdk-coin-canton/src/lib/walletInitBuilder.ts index 291a0d74cc..a52a3ba281 100644 --- a/modules/sdk-coin-canton/src/lib/walletInitBuilder.ts +++ b/modules/sdk-coin-canton/src/lib/walletInitBuilder.ts @@ -8,6 +8,7 @@ import { InvalidTransactionError, PublicKey, Signature, + TransactionType, } from '@bitgo/sdk-core'; import { BaseCoin as CoinConfig } from '@bitgo/statics'; @@ -37,6 +38,10 @@ export class WalletInitBuilder extends BaseTransactionBuilder { this._transaction = tx; } + protected get transactionType(): TransactionType { + return TransactionType.WalletInitialization; + } + protected buildImplementation(): Promise { throw new Error('Not implemented'); } diff --git a/modules/sdk-coin-canton/test/resources.ts b/modules/sdk-coin-canton/test/resources.ts index 7d6f1db9b0..455b196792 100644 --- a/modules/sdk-coin-canton/test/resources.ts +++ b/modules/sdk-coin-canton/test/resources.ts @@ -72,6 +72,12 @@ export const CANTON_ADDRESSES = { MISSING_FINGERPRINT: '12205::', }; +export const CANTON_BLOCK_HEIGHT = { + VALID_HASH: '123456', + INVALID_BLOCK_HASH: 'xyz', + NEGATIVE_BLOCK_HASH: '-100', +}; + export const TransferAcceptance = { partyId: 'ravi-test-party-1::12205b4e3537a95126d90604592344d8ad3c3ddccda4f79901954280ee19c576714d', commandId: '3935a06d-3b03-41be-99a5-95b2ecaabf7d', diff --git a/modules/sdk-coin-canton/test/unit/utils.ts b/modules/sdk-coin-canton/test/unit/utils.ts index fc0edb2e59..e7d25e88c8 100644 --- a/modules/sdk-coin-canton/test/unit/utils.ts +++ b/modules/sdk-coin-canton/test/unit/utils.ts @@ -3,6 +3,7 @@ import should from 'should'; import utils from '../../src/lib/utils'; import { CANTON_ADDRESSES, + CANTON_BLOCK_HEIGHT, GenerateTopologyResponse, OneStepPreApprovalPrepareResponse, PreparedTransactionRawData, @@ -95,4 +96,24 @@ describe('Canton Util', function () { assert.strictEqual(isValid, false); }); }); + + describe('Check if block hash is valid', function () { + it('should return true when the block hash is valid', function () { + const isValid = utils.isValidBlockId(CANTON_BLOCK_HEIGHT.VALID_HASH); + 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); + assert.strictEqual(isValid, false); + }); + + it('should return false when the block hash is negative', function () { + const isValid = utils.isValidBlockId(CANTON_BLOCK_HEIGHT.NEGATIVE_BLOCK_HASH); + should.exist(isValid); + assert.strictEqual(isValid, false); + }); + }); });