Skip to content

Commit e54451f

Browse files
committed
feat: isValidBlockHash and get transactionType added
Ticket: COIN-6321
1 parent 5527e1f commit e54451f

File tree

4 files changed

+35
-1
lines changed

4 files changed

+35
-1
lines changed

modules/sdk-coin-canton/src/lib/utils.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ export class Utils implements BaseUtils {
2020

2121
/** @inheritdoc */
2222
isValidBlockId(hash: string): boolean {
23-
throw new Error('Method not implemented.');
23+
// In canton, there is no block hash, we store the height as the _id (hash)
24+
const blockHeight = Number(hash);
25+
return !isNaN(blockHeight) && blockHeight > 0;
2426
}
2527

2628
/** @inheritdoc */

modules/sdk-coin-canton/src/lib/walletInitBuilder.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
InvalidTransactionError,
99
PublicKey,
1010
Signature,
11+
TransactionType,
1112
} from '@bitgo/sdk-core';
1213
import { BaseCoin as CoinConfig } from '@bitgo/statics';
1314

@@ -37,6 +38,10 @@ export class WalletInitBuilder extends BaseTransactionBuilder {
3738
this._transaction = tx;
3839
}
3940

41+
protected get transactionType(): TransactionType {
42+
return TransactionType.WalletInitialization;
43+
}
44+
4045
protected buildImplementation(): Promise<WalletInitTransaction> {
4146
throw new Error('Not implemented');
4247
}

modules/sdk-coin-canton/test/resources.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,12 @@ export const CANTON_ADDRESSES = {
7272
MISSING_FINGERPRINT: '12205::',
7373
};
7474

75+
export const CANTON_BLOCK_HEIGHT = {
76+
VALID_HASH: '123456',
77+
INVALID_BLOCK_HASH: 'xyz',
78+
NEGATIVE_BLOCK_HASH: '-100',
79+
};
80+
7581
export const TransferAcceptance = {
7682
partyId: 'ravi-test-party-1::12205b4e3537a95126d90604592344d8ad3c3ddccda4f79901954280ee19c576714d',
7783
commandId: '3935a06d-3b03-41be-99a5-95b2ecaabf7d',

modules/sdk-coin-canton/test/unit/utils.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import should from 'should';
33
import utils from '../../src/lib/utils';
44
import {
55
CANTON_ADDRESSES,
6+
CANTON_BLOCK_HEIGHT,
67
GenerateTopologyResponse,
78
OneStepPreApprovalPrepareResponse,
89
PreparedTransactionRawData,
@@ -95,4 +96,24 @@ describe('Canton Util', function () {
9596
assert.strictEqual(isValid, false);
9697
});
9798
});
99+
100+
describe('Check if block hash is valid', function () {
101+
it('should return true when the block hash is valid', function () {
102+
const isValid = utils.isValidBlockId(CANTON_BLOCK_HEIGHT.VALID_HASH);
103+
should.exist(isValid);
104+
assert.strictEqual(isValid, true);
105+
});
106+
107+
it('should return false when the block hash is not a number', function () {
108+
const isValid = utils.isValidBlockId(CANTON_BLOCK_HEIGHT.INVALID_BLOCK_HASH);
109+
should.exist(isValid);
110+
assert.strictEqual(isValid, false);
111+
});
112+
113+
it('should return false when the block hash is negative', function () {
114+
const isValid = utils.isValidBlockId(CANTON_BLOCK_HEIGHT.NEGATIVE_BLOCK_HASH);
115+
should.exist(isValid);
116+
assert.strictEqual(isValid, false);
117+
});
118+
});
98119
});

0 commit comments

Comments
 (0)