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 ;
2
1
export 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 1
1
import { 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' ;
3
3
import { KeyPair } from './keyPair' ;
4
4
import { HexUInt , Transaction , TransactionClause } from '@vechain/sdk-core' ;
5
5
6
6
export class Utils implements BaseUtils {
7
7
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 ) ;
9
9
}
10
10
11
11
isValidBlockId ( hash : string ) : boolean {
12
- throw new Error ( 'Method not implemented' ) ;
12
+ return this . isValidHex ( hash , VET_BLOCK_ID_LENGTH ) ;
13
13
}
14
14
15
15
isValidPrivateKey ( key : string ) : boolean {
Original file line number Diff line number Diff line change @@ -31,6 +31,18 @@ export const addresses = {
31
31
] ,
32
32
} ;
33
33
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
+
34
46
export const invalidRecipients : Recipient [ ] = [
35
47
{
36
48
address : addresses . invalidAddresses [ 0 ] ,
Original file line number Diff line number Diff line change @@ -24,6 +24,25 @@ describe('Vechain util library', function () {
24
24
} ) ;
25
25
} ) ;
26
26
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
+
27
46
describe ( 'isValidDeserialize' , function ( ) {
28
47
it ( 'should succeed to correctly deserialize sponsored signed serialized transaction' , function ( ) {
29
48
const signedTxn : VetTransaction = utils . deserializeTransaction ( testData . SPONSORED_TRANSACTION ) ;
You can’t perform that action at this time.
0 commit comments