mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-21 04:35:49 +00:00
test: update address-codec tests to typescript (#2447)
- Switch files to typescript - Add missing types in test files - Change how the codec functions were imported. They now count towards the "% Funcs" calculation, increasing it from 75% to 100%. - Lint test files
This commit is contained in:
@@ -5,7 +5,7 @@ module.exports = {
|
|||||||
parserOptions: {
|
parserOptions: {
|
||||||
// Enable linting rules with type information from our tsconfig
|
// Enable linting rules with type information from our tsconfig
|
||||||
tsconfigRootDir: __dirname,
|
tsconfigRootDir: __dirname,
|
||||||
project: ['./tsconfig.json'],
|
project: ['./tsconfig.eslint.json'],
|
||||||
|
|
||||||
sourceType: 'module', // Allow the use of imports / ES modules
|
sourceType: 'module', // Allow the use of imports / ES modules
|
||||||
|
|
||||||
|
|||||||
@@ -3,5 +3,6 @@ const base = require('../../jest.config.base.js')
|
|||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
...base,
|
...base,
|
||||||
|
roots: [...base.roots, '<rootDir>/test'],
|
||||||
displayName: 'ripple-address-codec',
|
displayName: 'ripple-address-codec',
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,10 +26,10 @@
|
|||||||
"prepublish": "tsc -b",
|
"prepublish": "tsc -b",
|
||||||
"prepublishOnly": "tslint -b ./ && jest",
|
"prepublishOnly": "tslint -b ./ && jest",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "tsc -b",
|
"build": "tsc --build tsconfig.build.json",
|
||||||
"test": "jest --verbose false --silent=false ./src/*.test.js",
|
"test": "jest --verbose false --silent=false ./test/*.test.ts",
|
||||||
"lint": "eslint . --ext .ts",
|
"lint": "eslint . --ext .ts",
|
||||||
"clean": "rm -rf ./dist && rm -rf tsconfig.tsbuildinfo"
|
"clean": "rm -rf ./dist && rm -rf ./coverage && rm -rf tsconfig.tsbuildinfo"
|
||||||
},
|
},
|
||||||
"prettier": "@xrplf/prettier-config",
|
"prettier": "@xrplf/prettier-config",
|
||||||
"engines": {
|
"engines": {
|
||||||
|
|||||||
@@ -1,11 +1,22 @@
|
|||||||
const {
|
import {
|
||||||
classicAddressToXAddress,
|
classicAddressToXAddress,
|
||||||
xAddressToClassicAddress,
|
xAddressToClassicAddress,
|
||||||
isValidXAddress,
|
isValidXAddress,
|
||||||
encodeXAddress,
|
encodeXAddress,
|
||||||
} = require('./index')
|
} from '../src'
|
||||||
|
|
||||||
const testCases = [
|
interface AddressTestCase {
|
||||||
|
// classicAddress
|
||||||
|
[0]: string
|
||||||
|
// tag
|
||||||
|
[1]: false | number
|
||||||
|
// mainnetAddress
|
||||||
|
[2]: string
|
||||||
|
// testnetAddress
|
||||||
|
[3]: string
|
||||||
|
}
|
||||||
|
|
||||||
|
const testCases: AddressTestCase[] = [
|
||||||
[
|
[
|
||||||
'r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59',
|
'r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59',
|
||||||
false,
|
false,
|
||||||
@@ -144,10 +155,9 @@ const testCases = [
|
|||||||
const MAX_32_BIT_UNSIGNED_INT = 4294967295
|
const MAX_32_BIT_UNSIGNED_INT = 4294967295
|
||||||
const network = isTestAddress ? ' (test)' : ' (main)'
|
const network = isTestAddress ? ' (test)' : ' (main)'
|
||||||
|
|
||||||
for (const i in testCases) {
|
testCases.forEach((testCase) => {
|
||||||
const testCase = testCases[i]
|
|
||||||
const classicAddress = testCase[0]
|
const classicAddress = testCase[0]
|
||||||
const tag = testCase[1] !== false ? testCase[1] : false
|
const tag = testCase[1] === false ? false : testCase[1]
|
||||||
const xAddress = isTestAddress ? testCase[3] : testCase[2]
|
const xAddress = isTestAddress ? testCase[3] : testCase[2]
|
||||||
test(`Converts ${classicAddress}${
|
test(`Converts ${classicAddress}${
|
||||||
tag ? `:${tag}` : ''
|
tag ? `:${tag}` : ''
|
||||||
@@ -163,7 +173,7 @@ const testCases = [
|
|||||||
})
|
})
|
||||||
expect(isValidXAddress(xAddress)).toBe(true)
|
expect(isValidXAddress(xAddress)).toBe(true)
|
||||||
})
|
})
|
||||||
}
|
})
|
||||||
|
|
||||||
{
|
{
|
||||||
const classicAddress = 'rGWrZyQqhTp9Xu7G5Pkayo7bXjH4k4QYpf'
|
const classicAddress = 'rGWrZyQqhTp9Xu7G5Pkayo7bXjH4k4QYpf'
|
||||||
@@ -196,9 +206,14 @@ const testCases = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
highAndLowAccounts.forEach((accountId) => {
|
highAndLowAccounts.forEach((accountId) => {
|
||||||
const testCases = [false, 0, 1, MAX_32_BIT_UNSIGNED_INT]
|
const tagTestCases: Array<false | number> = [
|
||||||
testCases.forEach((t) => {
|
false,
|
||||||
const tag = t | false
|
0,
|
||||||
|
1,
|
||||||
|
MAX_32_BIT_UNSIGNED_INT,
|
||||||
|
]
|
||||||
|
tagTestCases.forEach((testCase) => {
|
||||||
|
const tag = testCase || false
|
||||||
const xAddress = encodeXAddress(accountId, tag, isTestAddress)
|
const xAddress = encodeXAddress(accountId, tag, isTestAddress)
|
||||||
test(`Encoding ${accountId.toString('hex')}${
|
test(`Encoding ${accountId.toString('hex')}${
|
||||||
tag ? `:${tag}` : ''
|
tag ? `:${tag}` : ''
|
||||||
@@ -253,6 +268,7 @@ test(`isValidXAddress returns false for invalid X-address`, () => {
|
|||||||
|
|
||||||
test(`Converts X7AcgcsBL6XDcUb... to r9cZA1mLK5R5A... and tag: false`, () => {
|
test(`Converts X7AcgcsBL6XDcUb... to r9cZA1mLK5R5A... and tag: false`, () => {
|
||||||
const classicAddress = 'r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59'
|
const classicAddress = 'r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59'
|
||||||
|
// eslint-disable-next-line @typescript-eslint/naming-convention -- tag can be false or a number
|
||||||
const tag = false
|
const tag = false
|
||||||
const xAddress = 'X7AcgcsBL6XDcUb289X4mJ8djcdyKaB5hJDWMArnXr61cqZ'
|
const xAddress = 'X7AcgcsBL6XDcUb289X4mJ8djcdyKaB5hJDWMArnXr61cqZ'
|
||||||
const isTestAddress = false
|
const isTestAddress = false
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
const {seqEqual, concatArgs} = require('./utils')
|
import { seqEqual, concatArgs } from '../src/utils'
|
||||||
|
|
||||||
test('two sequences are equal', () => {
|
test('two sequences are equal', () => {
|
||||||
expect(seqEqual([1, 2, 3], [1, 2, 3])).toBe(true)
|
expect(seqEqual([1, 2, 3], [1, 2, 3])).toBe(true)
|
||||||
@@ -28,7 +28,9 @@ test('plain numbers are concatenated', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
test('a variety of values are concatenated', () => {
|
test('a variety of values are concatenated', () => {
|
||||||
expect(concatArgs(1, [2, 3], Buffer.from([4,5]), new Uint8Array([6, 7]))).toStrictEqual([1,2,3,4,5,6,7])
|
expect(
|
||||||
|
concatArgs(1, [2, 3], Buffer.from([4, 5]), new Uint8Array([6, 7])),
|
||||||
|
).toStrictEqual([1, 2, 3, 4, 5, 6, 7])
|
||||||
})
|
})
|
||||||
|
|
||||||
test('a single value is returned as an array', () => {
|
test('a single value is returned as an array', () => {
|
||||||
@@ -1,22 +1,39 @@
|
|||||||
const api = require('./xrp-codec')
|
import {
|
||||||
|
codec,
|
||||||
|
decodeAccountID,
|
||||||
|
decodeAccountPublic,
|
||||||
|
decodeNodePublic,
|
||||||
|
decodeSeed,
|
||||||
|
encodeAccountID,
|
||||||
|
encodeAccountPublic,
|
||||||
|
encodeNodePublic,
|
||||||
|
encodeSeed,
|
||||||
|
isValidClassicAddress,
|
||||||
|
} from '../src'
|
||||||
|
|
||||||
function toHex(bytes) {
|
function toHex(bytes: Buffer): string {
|
||||||
return Buffer.from(bytes).toString('hex').toUpperCase()
|
return Buffer.from(bytes).toString('hex').toUpperCase()
|
||||||
}
|
}
|
||||||
|
|
||||||
function toBytes(hex) {
|
function toBytes(hex: string): Buffer {
|
||||||
return Buffer.from(hex, 'hex')
|
return Buffer.from(hex, 'hex')
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a test case for encoding data and a test case for decoding data.
|
* Create a test case for encoding data and a test case for decoding data.
|
||||||
*
|
*
|
||||||
* @param encoder Encoder function to test
|
* @param encoder - Encoder function to test
|
||||||
* @param decoder Decoder function to test
|
* @param decoder - Decoder function to test
|
||||||
* @param base58 Base58-encoded string to decode
|
* @param base58 - Base58-encoded string to decode
|
||||||
* @param hex Hexadecimal representation of expected decoded data
|
* @param hex - Hexadecimal representation of expected decoded data
|
||||||
*/
|
*/
|
||||||
function makeEncodeDecodeTest(encoder, decoder, base58, hex) {
|
// eslint-disable-next-line max-params -- needs them
|
||||||
|
function makeEncodeDecodeTest(
|
||||||
|
encoder: (val: Buffer) => string,
|
||||||
|
decoder: (val: string) => Buffer,
|
||||||
|
base58: string,
|
||||||
|
hex: string,
|
||||||
|
): void {
|
||||||
test(`can translate between ${hex} and ${base58}`, function () {
|
test(`can translate between ${hex} and ${base58}`, function () {
|
||||||
const actual = encoder(toBytes(hex))
|
const actual = encoder(toBytes(hex))
|
||||||
expect(actual).toBe(base58)
|
expect(actual).toBe(base58)
|
||||||
@@ -28,70 +45,66 @@ function makeEncodeDecodeTest(encoder, decoder, base58, hex) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
makeEncodeDecodeTest(
|
makeEncodeDecodeTest(
|
||||||
api.encodeAccountID,
|
encodeAccountID,
|
||||||
api.decodeAccountID,
|
decodeAccountID,
|
||||||
'rJrRMgiRgrU6hDF4pgu5DXQdWyPbY35ErN',
|
'rJrRMgiRgrU6hDF4pgu5DXQdWyPbY35ErN',
|
||||||
'BA8E78626EE42C41B46D46C3048DF3A1C3C87072',
|
'BA8E78626EE42C41B46D46C3048DF3A1C3C87072',
|
||||||
)
|
)
|
||||||
|
|
||||||
makeEncodeDecodeTest(
|
makeEncodeDecodeTest(
|
||||||
api.encodeNodePublic,
|
encodeNodePublic,
|
||||||
api.decodeNodePublic,
|
decodeNodePublic,
|
||||||
'n9MXXueo837zYH36DvMc13BwHcqtfAWNJY5czWVbp7uYTj7x17TH',
|
'n9MXXueo837zYH36DvMc13BwHcqtfAWNJY5czWVbp7uYTj7x17TH',
|
||||||
'0388E5BA87A000CB807240DF8C848EB0B5FFA5C8E5A521BC8E105C0F0A44217828',
|
'0388E5BA87A000CB807240DF8C848EB0B5FFA5C8E5A521BC8E105C0F0A44217828',
|
||||||
)
|
)
|
||||||
|
|
||||||
makeEncodeDecodeTest(
|
makeEncodeDecodeTest(
|
||||||
api.encodeAccountPublic,
|
encodeAccountPublic,
|
||||||
api.decodeAccountPublic,
|
decodeAccountPublic,
|
||||||
'aB44YfzW24VDEJQ2UuLPV2PvqcPCSoLnL7y5M1EzhdW4LnK5xMS3',
|
'aB44YfzW24VDEJQ2UuLPV2PvqcPCSoLnL7y5M1EzhdW4LnK5xMS3',
|
||||||
'023693F15967AE357D0327974AD46FE3C127113B1110D6044FD41E723689F81CC6',
|
'023693F15967AE357D0327974AD46FE3C127113B1110D6044FD41E723689F81CC6',
|
||||||
)
|
)
|
||||||
|
|
||||||
test('can decode arbitrary seeds', function () {
|
test('can decode arbitrary seeds', function () {
|
||||||
const decoded = api.decodeSeed('sEdTM1uX8pu2do5XvTnutH6HsouMaM2')
|
const decoded = decodeSeed('sEdTM1uX8pu2do5XvTnutH6HsouMaM2')
|
||||||
expect(toHex(decoded.bytes)).toBe('4C3A1D213FBDFB14C7C28D609469B341')
|
expect(toHex(decoded.bytes)).toBe('4C3A1D213FBDFB14C7C28D609469B341')
|
||||||
expect(decoded.type).toBe('ed25519')
|
expect(decoded.type).toBe('ed25519')
|
||||||
|
|
||||||
const decoded2 = api.decodeSeed('sn259rEFXrQrWyx3Q7XneWcwV6dfL')
|
const decoded2 = decodeSeed('sn259rEFXrQrWyx3Q7XneWcwV6dfL')
|
||||||
expect(toHex(decoded2.bytes)).toBe('CF2DE378FBDD7E2EE87D486DFB5A7BFF')
|
expect(toHex(decoded2.bytes)).toBe('CF2DE378FBDD7E2EE87D486DFB5A7BFF')
|
||||||
expect(decoded2.type).toBe('secp256k1')
|
expect(decoded2.type).toBe('secp256k1')
|
||||||
})
|
})
|
||||||
|
|
||||||
test('can pass a type as second arg to encodeSeed', function () {
|
test('can pass a type as second arg to encodeSeed', function () {
|
||||||
const edSeed = 'sEdTM1uX8pu2do5XvTnutH6HsouMaM2'
|
const edSeed = 'sEdTM1uX8pu2do5XvTnutH6HsouMaM2'
|
||||||
const decoded = api.decodeSeed(edSeed)
|
const decoded = decodeSeed(edSeed)
|
||||||
const type = 'ed25519'
|
const type = 'ed25519'
|
||||||
expect(toHex(decoded.bytes)).toBe('4C3A1D213FBDFB14C7C28D609469B341')
|
expect(toHex(decoded.bytes)).toBe('4C3A1D213FBDFB14C7C28D609469B341')
|
||||||
expect(decoded.type).toBe(type)
|
expect(decoded.type).toBe(type)
|
||||||
expect(api.encodeSeed(decoded.bytes, type)).toBe(edSeed)
|
expect(encodeSeed(decoded.bytes, type)).toBe(edSeed)
|
||||||
})
|
})
|
||||||
|
|
||||||
test('isValidClassicAddress - secp256k1 address valid', function () {
|
test('isValidClassicAddress - secp256k1 address valid', function () {
|
||||||
expect(api.isValidClassicAddress('rU6K7V3Po4snVhBBaU29sesqs2qTQJWDw1')).toBe(
|
expect(isValidClassicAddress('rU6K7V3Po4snVhBBaU29sesqs2qTQJWDw1')).toBe(true)
|
||||||
true,
|
|
||||||
)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
test('isValidClassicAddress - ed25519 address valid', function () {
|
test('isValidClassicAddress - ed25519 address valid', function () {
|
||||||
expect(api.isValidClassicAddress('rLUEXYuLiQptky37CqLcm9USQpPiz5rkpD')).toBe(
|
expect(isValidClassicAddress('rLUEXYuLiQptky37CqLcm9USQpPiz5rkpD')).toBe(true)
|
||||||
true,
|
|
||||||
)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
test('isValidClassicAddress - invalid', function () {
|
test('isValidClassicAddress - invalid', function () {
|
||||||
expect(api.isValidClassicAddress('rU6K7V3Po4snVhBBaU29sesqs2qTQJWDw2')).toBe(
|
expect(isValidClassicAddress('rU6K7V3Po4snVhBBaU29sesqs2qTQJWDw2')).toBe(
|
||||||
false,
|
false,
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
test('isValidClassicAddress - empty', function () {
|
test('isValidClassicAddress - empty', function () {
|
||||||
expect(api.isValidClassicAddress('')).toBe(false)
|
expect(isValidClassicAddress('')).toBe(false)
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('encodeSeed', function () {
|
describe('encodeSeed', function () {
|
||||||
it('encodes a secp256k1 seed', function () {
|
it('encodes a secp256k1 seed', function () {
|
||||||
const result = api.encodeSeed(
|
const result = encodeSeed(
|
||||||
Buffer.from('CF2DE378FBDD7E2EE87D486DFB5A7BFF', 'hex'),
|
Buffer.from('CF2DE378FBDD7E2EE87D486DFB5A7BFF', 'hex'),
|
||||||
'secp256k1',
|
'secp256k1',
|
||||||
)
|
)
|
||||||
@@ -99,7 +112,7 @@ describe('encodeSeed', function () {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('encodes low secp256k1 seed', function () {
|
it('encodes low secp256k1 seed', function () {
|
||||||
const result = api.encodeSeed(
|
const result = encodeSeed(
|
||||||
Buffer.from('00000000000000000000000000000000', 'hex'),
|
Buffer.from('00000000000000000000000000000000', 'hex'),
|
||||||
'secp256k1',
|
'secp256k1',
|
||||||
)
|
)
|
||||||
@@ -107,7 +120,7 @@ describe('encodeSeed', function () {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('encodes high secp256k1 seed', function () {
|
it('encodes high secp256k1 seed', function () {
|
||||||
const result = api.encodeSeed(
|
const result = encodeSeed(
|
||||||
Buffer.from('FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF', 'hex'),
|
Buffer.from('FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF', 'hex'),
|
||||||
'secp256k1',
|
'secp256k1',
|
||||||
)
|
)
|
||||||
@@ -115,7 +128,7 @@ describe('encodeSeed', function () {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('encodes an ed25519 seed', function () {
|
it('encodes an ed25519 seed', function () {
|
||||||
const result = api.encodeSeed(
|
const result = encodeSeed(
|
||||||
Buffer.from('4C3A1D213FBDFB14C7C28D609469B341', 'hex'),
|
Buffer.from('4C3A1D213FBDFB14C7C28D609469B341', 'hex'),
|
||||||
'ed25519',
|
'ed25519',
|
||||||
)
|
)
|
||||||
@@ -123,7 +136,7 @@ describe('encodeSeed', function () {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('encodes low ed25519 seed', function () {
|
it('encodes low ed25519 seed', function () {
|
||||||
const result = api.encodeSeed(
|
const result = encodeSeed(
|
||||||
Buffer.from('00000000000000000000000000000000', 'hex'),
|
Buffer.from('00000000000000000000000000000000', 'hex'),
|
||||||
'ed25519',
|
'ed25519',
|
||||||
)
|
)
|
||||||
@@ -131,7 +144,7 @@ describe('encodeSeed', function () {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('encodes high ed25519 seed', function () {
|
it('encodes high ed25519 seed', function () {
|
||||||
const result = api.encodeSeed(
|
const result = encodeSeed(
|
||||||
Buffer.from('FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF', 'hex'),
|
Buffer.from('FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF', 'hex'),
|
||||||
'ed25519',
|
'ed25519',
|
||||||
)
|
)
|
||||||
@@ -140,7 +153,7 @@ describe('encodeSeed', function () {
|
|||||||
|
|
||||||
test('attempting to encode a seed with less than 16 bytes of entropy throws', function () {
|
test('attempting to encode a seed with less than 16 bytes of entropy throws', function () {
|
||||||
expect(() => {
|
expect(() => {
|
||||||
api.encodeSeed(
|
encodeSeed(
|
||||||
Buffer.from('CF2DE378FBDD7E2EE87D486DFB5A7B', 'hex'),
|
Buffer.from('CF2DE378FBDD7E2EE87D486DFB5A7B', 'hex'),
|
||||||
'secp256k1',
|
'secp256k1',
|
||||||
)
|
)
|
||||||
@@ -149,7 +162,7 @@ describe('encodeSeed', function () {
|
|||||||
|
|
||||||
test('attempting to encode a seed with more than 16 bytes of entropy throws', function () {
|
test('attempting to encode a seed with more than 16 bytes of entropy throws', function () {
|
||||||
expect(() => {
|
expect(() => {
|
||||||
api.encodeSeed(
|
encodeSeed(
|
||||||
Buffer.from('CF2DE378FBDD7E2EE87D486DFB5A7BFFFF', 'hex'),
|
Buffer.from('CF2DE378FBDD7E2EE87D486DFB5A7BFFFF', 'hex'),
|
||||||
'secp256k1',
|
'secp256k1',
|
||||||
)
|
)
|
||||||
@@ -159,13 +172,13 @@ describe('encodeSeed', function () {
|
|||||||
|
|
||||||
describe('decodeSeed', function () {
|
describe('decodeSeed', function () {
|
||||||
it('can decode an Ed25519 seed', function () {
|
it('can decode an Ed25519 seed', function () {
|
||||||
const decoded = api.decodeSeed('sEdTM1uX8pu2do5XvTnutH6HsouMaM2')
|
const decoded = decodeSeed('sEdTM1uX8pu2do5XvTnutH6HsouMaM2')
|
||||||
expect(toHex(decoded.bytes)).toBe('4C3A1D213FBDFB14C7C28D609469B341')
|
expect(toHex(decoded.bytes)).toBe('4C3A1D213FBDFB14C7C28D609469B341')
|
||||||
expect(decoded.type).toBe('ed25519')
|
expect(decoded.type).toBe('ed25519')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('can decode a secp256k1 seed', function () {
|
it('can decode a secp256k1 seed', function () {
|
||||||
const decoded = api.decodeSeed('sn259rEFXrQrWyx3Q7XneWcwV6dfL')
|
const decoded = decodeSeed('sn259rEFXrQrWyx3Q7XneWcwV6dfL')
|
||||||
expect(toHex(decoded.bytes)).toBe('CF2DE378FBDD7E2EE87D486DFB5A7BFF')
|
expect(toHex(decoded.bytes)).toBe('CF2DE378FBDD7E2EE87D486DFB5A7BFF')
|
||||||
expect(decoded.type).toBe('secp256k1')
|
expect(decoded.type).toBe('secp256k1')
|
||||||
})
|
})
|
||||||
@@ -173,7 +186,7 @@ describe('decodeSeed', function () {
|
|||||||
|
|
||||||
describe('encodeAccountID', function () {
|
describe('encodeAccountID', function () {
|
||||||
it('can encode an AccountID', function () {
|
it('can encode an AccountID', function () {
|
||||||
const encoded = api.encodeAccountID(
|
const encoded = encodeAccountID(
|
||||||
Buffer.from('BA8E78626EE42C41B46D46C3048DF3A1C3C87072', 'hex'),
|
Buffer.from('BA8E78626EE42C41B46D46C3048DF3A1C3C87072', 'hex'),
|
||||||
)
|
)
|
||||||
expect(encoded).toBe('rJrRMgiRgrU6hDF4pgu5DXQdWyPbY35ErN')
|
expect(encoded).toBe('rJrRMgiRgrU6hDF4pgu5DXQdWyPbY35ErN')
|
||||||
@@ -181,7 +194,7 @@ describe('encodeAccountID', function () {
|
|||||||
|
|
||||||
test('unexpected length should throw', function () {
|
test('unexpected length should throw', function () {
|
||||||
expect(() => {
|
expect(() => {
|
||||||
api.encodeAccountID(Buffer.from('ABCDEF', 'hex'))
|
encodeAccountID(Buffer.from('ABCDEF', 'hex'))
|
||||||
}).toThrow(
|
}).toThrow(
|
||||||
'unexpected_payload_length: bytes.length does not match expectedLength',
|
'unexpected_payload_length: bytes.length does not match expectedLength',
|
||||||
)
|
)
|
||||||
@@ -190,7 +203,7 @@ describe('encodeAccountID', function () {
|
|||||||
|
|
||||||
describe('decodeNodePublic', function () {
|
describe('decodeNodePublic', function () {
|
||||||
it('can decode a NodePublic', function () {
|
it('can decode a NodePublic', function () {
|
||||||
const decoded = api.decodeNodePublic(
|
const decoded = decodeNodePublic(
|
||||||
'n9MXXueo837zYH36DvMc13BwHcqtfAWNJY5czWVbp7uYTj7x17TH',
|
'n9MXXueo837zYH36DvMc13BwHcqtfAWNJY5czWVbp7uYTj7x17TH',
|
||||||
)
|
)
|
||||||
expect(toHex(decoded)).toBe(
|
expect(toHex(decoded)).toBe(
|
||||||
@@ -201,7 +214,7 @@ describe('decodeNodePublic', function () {
|
|||||||
|
|
||||||
test('encodes 123456789 with version byte of 0', () => {
|
test('encodes 123456789 with version byte of 0', () => {
|
||||||
expect(
|
expect(
|
||||||
api.codec.encode(Buffer.from('123456789'), {
|
codec.encode(Buffer.from('123456789'), {
|
||||||
versions: [0],
|
versions: [0],
|
||||||
expectedLength: 9,
|
expectedLength: 9,
|
||||||
}),
|
}),
|
||||||
@@ -210,7 +223,7 @@ test('encodes 123456789 with version byte of 0', () => {
|
|||||||
|
|
||||||
test('multiple versions with no expected length should throw', () => {
|
test('multiple versions with no expected length should throw', () => {
|
||||||
expect(() => {
|
expect(() => {
|
||||||
api.codec.decode('rnaC7gW34M77Kneb78s', {
|
codec.decode('rnaC7gW34M77Kneb78s', {
|
||||||
versions: [0, 1],
|
versions: [0, 1],
|
||||||
})
|
})
|
||||||
}).toThrow(
|
}).toThrow(
|
||||||
@@ -220,7 +233,7 @@ test('multiple versions with no expected length should throw', () => {
|
|||||||
|
|
||||||
test('attempting to decode data with length < 5 should throw', () => {
|
test('attempting to decode data with length < 5 should throw', () => {
|
||||||
expect(() => {
|
expect(() => {
|
||||||
api.codec.decode('1234', {
|
codec.decode('1234', {
|
||||||
versions: [0],
|
versions: [0],
|
||||||
})
|
})
|
||||||
}).toThrow('invalid_input_size: decoded data must have length >= 5')
|
}).toThrow('invalid_input_size: decoded data must have length >= 5')
|
||||||
@@ -228,7 +241,7 @@ test('attempting to decode data with length < 5 should throw', () => {
|
|||||||
|
|
||||||
test('attempting to decode data with unexpected version should throw', () => {
|
test('attempting to decode data with unexpected version should throw', () => {
|
||||||
expect(() => {
|
expect(() => {
|
||||||
api.codec.decode('rnaC7gW34M77Kneb78s', {
|
codec.decode('rnaC7gW34M77Kneb78s', {
|
||||||
versions: [2],
|
versions: [2],
|
||||||
})
|
})
|
||||||
}).toThrow(
|
}).toThrow(
|
||||||
@@ -238,7 +251,7 @@ test('attempting to decode data with unexpected version should throw', () => {
|
|||||||
|
|
||||||
test('invalid checksum should throw', () => {
|
test('invalid checksum should throw', () => {
|
||||||
expect(() => {
|
expect(() => {
|
||||||
api.codec.decode('123456789', {
|
codec.decode('123456789', {
|
||||||
versions: [0, 1],
|
versions: [0, 1],
|
||||||
})
|
})
|
||||||
}).toThrow('checksum_invalid')
|
}).toThrow('checksum_invalid')
|
||||||
@@ -246,7 +259,7 @@ test('invalid checksum should throw', () => {
|
|||||||
|
|
||||||
test('empty payload should throw', () => {
|
test('empty payload should throw', () => {
|
||||||
expect(() => {
|
expect(() => {
|
||||||
api.codec.decode('', {
|
codec.decode('', {
|
||||||
versions: [0, 1],
|
versions: [0, 1],
|
||||||
})
|
})
|
||||||
}).toThrow('invalid_input_size: decoded data must have length >= 5')
|
}).toThrow('invalid_input_size: decoded data must have length >= 5')
|
||||||
@@ -254,7 +267,7 @@ test('empty payload should throw', () => {
|
|||||||
|
|
||||||
test('decode data', () => {
|
test('decode data', () => {
|
||||||
expect(
|
expect(
|
||||||
api.codec.decode('rnaC7gW34M77Kneb78s', {
|
codec.decode('rnaC7gW34M77Kneb78s', {
|
||||||
versions: [0],
|
versions: [0],
|
||||||
}),
|
}),
|
||||||
).toStrictEqual({
|
).toStrictEqual({
|
||||||
@@ -266,7 +279,7 @@ test('decode data', () => {
|
|||||||
|
|
||||||
test('decode data with expected length', function () {
|
test('decode data with expected length', function () {
|
||||||
expect(
|
expect(
|
||||||
api.codec.decode('rnaC7gW34M77Kneb78s', {
|
codec.decode('rnaC7gW34M77Kneb78s', {
|
||||||
versions: [0],
|
versions: [0],
|
||||||
expectedLength: 9,
|
expectedLength: 9,
|
||||||
}),
|
}),
|
||||||
@@ -279,7 +292,7 @@ test('decode data with expected length', function () {
|
|||||||
|
|
||||||
test('decode data with wrong expected length should throw', function () {
|
test('decode data with wrong expected length should throw', function () {
|
||||||
expect(() => {
|
expect(() => {
|
||||||
api.codec.decode('rnaC7gW34M77Kneb78s', {
|
codec.decode('rnaC7gW34M77Kneb78s', {
|
||||||
versions: [0],
|
versions: [0],
|
||||||
expectedLength: 8,
|
expectedLength: 8,
|
||||||
})
|
})
|
||||||
@@ -287,7 +300,7 @@ test('decode data with wrong expected length should throw', function () {
|
|||||||
'version_invalid: version bytes do not match any of the provided version(s)',
|
'version_invalid: version bytes do not match any of the provided version(s)',
|
||||||
)
|
)
|
||||||
expect(() => {
|
expect(() => {
|
||||||
api.codec.decode('rnaC7gW34M77Kneb78s', {
|
codec.decode('rnaC7gW34M77Kneb78s', {
|
||||||
versions: [0],
|
versions: [0],
|
||||||
expectedLength: 10,
|
expectedLength: 10,
|
||||||
})
|
})
|
||||||
7
packages/ripple-address-codec/tsconfig.build.json
Normal file
7
packages/ripple-address-codec/tsconfig.build.json
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"extends": "./tsconfig.json",
|
||||||
|
"compilerOptions": {
|
||||||
|
"rootDir": "./src",
|
||||||
|
},
|
||||||
|
"include": ["./src/**/*.ts", "./src/**/*.json"]
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
{
|
{
|
||||||
"extends": "./tsconfig.json",
|
"extends": "./tsconfig.json",
|
||||||
"include": ["src/**/*.ts", "src/*.test.ts"]
|
"include": ["src/**/*.ts", "test/*.test.ts"]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,6 @@
|
|||||||
"lib": [
|
"lib": [
|
||||||
"es2017"
|
"es2017"
|
||||||
],
|
],
|
||||||
"rootDir": "./src",
|
|
||||||
"outDir": "./dist",
|
"outDir": "./dist",
|
||||||
"noUnusedLocals": true,
|
"noUnusedLocals": true,
|
||||||
"noUnusedParameters": true,
|
"noUnusedParameters": true,
|
||||||
|
|||||||
Reference in New Issue
Block a user