-
Notifications
You must be signed in to change notification settings - Fork 302
Expand file tree
/
Copy pathutils.ts
More file actions
52 lines (45 loc) · 2.43 KB
/
utils.ts
File metadata and controls
52 lines (45 loc) · 2.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import should from 'should';
import utils from '../../src/lib/utils';
import * as testData from '../resources/hash';
import { blockHash, txIds } from '../resources/hash';
describe('utils', () => {
it('should validate block hash correctly', () => {
should.equal(utils.isValidBlockId(blockHash.hash1), true);
should.equal(utils.isValidBlockId(blockHash.hash2), true);
// param is coming as undefined so it was causing an issue
should.equal(utils.isValidBlockId(undefined as unknown as string), false);
should.equal(utils.isValidBlockId(''), false);
});
it('should validate long mainnet account address correctly', () => {
// HASH bech32 addresses can be longer than the standard 20-byte data-part length.
should.equal(utils.isValidAddress('pb1w9ew2yu0w3c72j6j4m85daz7qch5x2w4cfm408js0ku087mq87gq4f9gcj'), true);
});
it('should validate invalid block hash correctly', () => {
should.equal(utils.isValidBlockId(''), false);
should.equal(utils.isValidBlockId('0xade35465gfvdcsxsz24300'), false);
should.equal(utils.isValidBlockId(blockHash.hash2 + 'ff'), false);
should.equal(utils.isValidBlockId('latest'), false);
});
it('should validate transaction id correctly', () => {
should.equal(utils.isValidTransactionId(txIds.hash1), true);
should.equal(utils.isValidTransactionId(txIds.hash2), true);
should.equal(utils.isValidTransactionId(txIds.hash3), true);
});
it('should validate invalid transaction id correctly', () => {
should.equal(utils.isValidTransactionId(''), false);
should.equal(utils.isValidTransactionId(txIds.hash1.slice(3)), false);
should.equal(utils.isValidTransactionId(txIds.hash3 + '00'), false);
should.equal(utils.isValidTransactionId('dalij43ta0ga2dadda02'), false);
});
it('validateAmount', function () {
should.doesNotThrow(() => utils.validateAmountData([testData.coinAmounts.amount1]));
should.doesNotThrow(() => utils.validateAmountData([testData.coinAmounts.amount2]));
should.doesNotThrow(() => utils.validateAmountData([testData.coinAmounts.amount3]));
should(() => utils.validateAmountData([testData.coinAmounts.amount4])).throwError(
'transactionBuilder: validateAmount: Invalid amount: ' + testData.coinAmounts.amount4.amount
);
should(() => utils.validateAmountData([testData.coinAmounts.amount5])).throwError(
'transactionBuilder: validateAmount: Invalid denom: ' + testData.coinAmounts.amount5.denom
);
});
});