File tree Expand file tree Collapse file tree 4 files changed +35
-1
lines changed Expand file tree Collapse file tree 4 files changed +35
-1
lines changed Original file line number Diff line number Diff 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 */
Original file line number Diff line number Diff line change 88 InvalidTransactionError ,
99 PublicKey ,
1010 Signature ,
11+ TransactionType ,
1112} from '@bitgo/sdk-core' ;
1213import { 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 }
Original file line number Diff line number Diff 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+
7581export const TransferAcceptance = {
7682 partyId : 'ravi-test-party-1::12205b4e3537a95126d90604592344d8ad3c3ddccda4f79901954280ee19c576714d' ,
7783 commandId : '3935a06d-3b03-41be-99a5-95b2ecaabf7d' ,
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ import should from 'should';
33import utils from '../../src/lib/utils' ;
44import {
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} ) ;
You can’t perform that action at this time.
0 commit comments