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 @@ -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 */
Expand Down
5 changes: 5 additions & 0 deletions modules/sdk-coin-canton/src/lib/walletInitBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
InvalidTransactionError,
PublicKey,
Signature,
TransactionType,
} from '@bitgo/sdk-core';
import { BaseCoin as CoinConfig } from '@bitgo/statics';

Expand Down Expand Up @@ -37,6 +38,10 @@ export class WalletInitBuilder extends BaseTransactionBuilder {
this._transaction = tx;
}

protected get transactionType(): TransactionType {
return TransactionType.WalletInitialization;
}

protected buildImplementation(): Promise<WalletInitTransaction> {
throw new Error('Not implemented');
}
Expand Down
6 changes: 6 additions & 0 deletions modules/sdk-coin-canton/test/resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
21 changes: 21 additions & 0 deletions modules/sdk-coin-canton/test/unit/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import should from 'should';
import utils from '../../src/lib/utils';
import {
CANTON_ADDRESSES,
CANTON_BLOCK_HEIGHT,
GenerateTopologyResponse,
OneStepPreApprovalPrepareResponse,
PreparedTransactionRawData,
Expand Down Expand Up @@ -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);
});
});
});