File tree Expand file tree Collapse file tree 4 files changed +36
-4
lines changed
Expand file tree Collapse file tree 4 files changed +36
-4
lines changed Original file line number Diff line number Diff line change 1- export const DEFAULT_GAS_UNIT_PRICE = 100 ;
21export const VET_TRANSACTION_ID_LENGTH = 64 ;
2+ export const VET_ADDRESS_LENGTH = 40 ;
3+ export const VET_BLOCK_ID_LENGTH = 64 ;
Original file line number Diff line number Diff line change 11import { BaseUtils , TransactionType } from '@bitgo/sdk-core' ;
2- import { VET_TRANSACTION_ID_LENGTH } from './constants' ;
2+ import { VET_ADDRESS_LENGTH , VET_BLOCK_ID_LENGTH , VET_TRANSACTION_ID_LENGTH } from './constants' ;
33import { KeyPair } from './keyPair' ;
44import { HexUInt , Transaction , TransactionClause } from '@vechain/sdk-core' ;
55
66export class Utils implements BaseUtils {
77 isValidAddress ( address : string ) : boolean {
8- return / ^ 0 x [ 0 - 9 a - f A - F ] { 40 } $ / . test ( address ) ;
8+ return this . isValidHex ( address , VET_ADDRESS_LENGTH ) ;
99 }
1010
1111 isValidBlockId ( hash : string ) : boolean {
12- throw new Error ( 'Method not implemented' ) ;
12+ return this . isValidHex ( hash , VET_BLOCK_ID_LENGTH ) ;
1313 }
1414
1515 isValidPrivateKey ( key : string ) : boolean {
Original file line number Diff line number Diff line change @@ -31,6 +31,18 @@ export const addresses = {
3131 ] ,
3232} ;
3333
34+ export const blockIds : { validBlockIds : string [ ] ; invalidBlockIds : string [ ] } = {
35+ validBlockIds : [
36+ '0x014f12ed94c4b4770f7f9a73e2aa41a9dfbac02a49f36ec05acfdba8c7244ff0' ,
37+ '0x014f130d00a2fe06d471a35e7f2cd18d25bdefe5370c07a2ad68c0ae3852ad86' ,
38+ ] ,
39+ invalidBlockIds : [
40+ 'randomString' ,
41+ '0xc4173a804406a365e69dfb297ddfgsdcvf' ,
42+ '5ne7phA48Jrvpn39AtupB8ZkCCAy8gLTfpGihZPuDqen' ,
43+ ] ,
44+ } ;
45+
3446export const invalidRecipients : Recipient [ ] = [
3547 {
3648 address : addresses . invalidAddresses [ 0 ] ,
Original file line number Diff line number Diff line change @@ -24,6 +24,25 @@ describe('Vechain util library', function () {
2424 } ) ;
2525 } ) ;
2626
27+ describe ( 'isValidBlockId' , function ( ) {
28+ it ( 'should succeed to validate valid block IDs' , function ( ) {
29+ for ( const blockId of testData . blockIds . validBlockIds ) {
30+ should . equal ( utils . isValidBlockId ( blockId ) , true ) ;
31+ }
32+ } ) ;
33+
34+ it ( 'should fail to validate invalid block IDs' , function ( ) {
35+ for ( const blockId of testData . blockIds . invalidBlockIds ) {
36+ should . doesNotThrow ( ( ) => utils . isValidBlockId ( blockId ) ) ;
37+ should . equal ( utils . isValidBlockId ( blockId ) , false ) ;
38+ }
39+ // @ts -expect-error Testing for missing param, should not throw an error
40+ should . doesNotThrow ( ( ) => utils . isValidBlockId ( undefined ) ) ;
41+ // @ts -expect-error Testing for missing param, should return false
42+ should . equal ( utils . isValidBlockId ( undefined ) , false ) ;
43+ } ) ;
44+ } ) ;
45+
2746 describe ( 'isValidDeserialize' , function ( ) {
2847 it ( 'should succeed to correctly deserialize sponsored signed serialized transaction' , function ( ) {
2948 const signedTxn : VetTransaction = utils . deserializeTransaction ( testData . SPONSORED_TRANSACTION ) ;
You can’t perform that action at this time.
0 commit comments