|
1 | 1 | import { NetworkType } from '@bitgo/statics'; |
2 | 2 | import should from 'should'; |
3 | 3 | import { CoreumUtils } from '../../src/lib/utils'; |
4 | | -import { blockHash, mainnetCoinAmounts, txIds } from '../resources/coreum'; |
| 4 | +import { mainnetAccountAddressRegex, testnetAccountAddressRegex } from '../../src/lib/constants'; |
| 5 | +import { blockHash, mainnetAddress, mainnetCoinAmounts, txIds } from '../resources/coreum'; |
5 | 6 | import { testnetCoinAmounts } from '../resources/tcoreum'; |
6 | 7 |
|
7 | 8 | describe('utils', () => { |
@@ -36,6 +37,32 @@ describe('utils', () => { |
36 | 37 | should.equal(mainnetUtils.isValidTransactionId('dalij43ta0ga2dadda02'), false); |
37 | 38 | }); |
38 | 39 |
|
| 40 | + it('should accept 32-byte (group module / smart contract) addresses', () => { |
| 41 | + should.equal(mainnetUtils.isValidAddress(mainnetAddress.address32byte1), true); |
| 42 | + should.equal(mainnetUtils.isValidAddress(`${mainnetAddress.address32byte1}?memoId=1`), true); |
| 43 | + }); |
| 44 | + |
| 45 | + it('should reject 32-byte addresses with an invalid checksum', () => { |
| 46 | + const corrupted = mainnetAddress.address32byte1.slice(0, -1) + 'q'; |
| 47 | + should.equal(mainnetUtils.isValidAddress(corrupted), false); |
| 48 | + }); |
| 49 | + |
| 50 | + it('should reject addresses with intermediate data lengths (not 38 or 58 chars)', () => { |
| 51 | + const bech32Chars = 'qpzry9x8gf2tvdw0s3jn54khce6mua7l'; |
| 52 | + const intermediateData = bech32Chars.repeat(2).slice(0, 48); |
| 53 | + should.equal(mainnetAccountAddressRegex.test(`core1${intermediateData}`), false); |
| 54 | + should.equal(testnetAccountAddressRegex.test(`testcore1${intermediateData}`), false); |
| 55 | + }); |
| 56 | + |
| 57 | + it('testnet regex should accept both 20-byte and 32-byte address lengths', () => { |
| 58 | + const data38 = 'qpzry9x8gf2tvdw0s3jn54khce6mua7lqpzry9'; |
| 59 | + should.equal(testnetAccountAddressRegex.test(`testcore1${data38}`), true); |
| 60 | + const data58 = 'qpzry9x8gf2tvdw0s3jn54khce6mua7lqpzry9x8gf2tvdw0s3jn54khce'; |
| 61 | + should.equal(testnetAccountAddressRegex.test(`testcore1${data58}`), true); |
| 62 | + const data39 = 'qpzry9x8gf2tvdw0s3jn54khce6mua7lqpzry9x'; |
| 63 | + should.equal(testnetAccountAddressRegex.test(`testcore1${data39}`), false); |
| 64 | + }); |
| 65 | + |
39 | 66 | it('validateAmount', function () { |
40 | 67 | should.doesNotThrow(() => mainnetUtils.validateAmountData([mainnetCoinAmounts.amount1])); |
41 | 68 | should.doesNotThrow(() => mainnetUtils.validateAmountData([mainnetCoinAmounts.amount2])); |
|
0 commit comments