Skip to content

Commit a32b05a

Browse files
authored
Merge pull request #6281 from BitGo/coin-4471
feat(sdk-coin-vet): implement isValidBlockId for vet
2 parents 858eecd + 2a7e6e7 commit a32b05a

File tree

4 files changed

+36
-4
lines changed

4 files changed

+36
-4
lines changed
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
export const DEFAULT_GAS_UNIT_PRICE = 100;
21
export const VET_TRANSACTION_ID_LENGTH = 64;
2+
export const VET_ADDRESS_LENGTH = 40;
3+
export const VET_BLOCK_ID_LENGTH = 64;

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
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';
33
import { KeyPair } from './keyPair';
44
import { HexUInt, Transaction, TransactionClause } from '@vechain/sdk-core';
55

66
export class Utils implements BaseUtils {
77
isValidAddress(address: string): boolean {
8-
return /^0x[0-9a-fA-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 {

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff 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+
3446
export const invalidRecipients: Recipient[] = [
3547
{
3648
address: addresses.invalidAddresses[0],

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff 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);

0 commit comments

Comments
 (0)