migrate ripple-address-codec tests back to javascript for now - jest and mocha cannot be used in the same typescript project due to type name conflicts

This commit is contained in:
Greg Weisbrod
2021-11-07 20:47:55 -05:00
parent 9f19d771d2
commit b5beeb6668
6 changed files with 11 additions and 42 deletions

View File

@@ -1,9 +0,0 @@
language: node_js
node_js:
- 10
- 12
- 13
script:
- npm run compile
- npm test
- npm run lint

View File

@@ -1,9 +1,9 @@
import {
const {
classicAddressToXAddress,
xAddressToClassicAddress,
isValidXAddress,
encodeXAddress
} from './index'
} = require('./index')
const testCases = [
[
@@ -146,9 +146,9 @@ const testCases = [
for (const i in testCases) {
const testCase = testCases[i]
const classicAddress = testCase[0] as string
const tag = testCase[1] !== false ? testCase[1] as number : false
const xAddress = isTestAddress ? testCase[3] as string : testCase[2] as string
const classicAddress = testCase[0]
const tag = testCase[1] !== false ? testCase[1] : false
const xAddress = isTestAddress ? testCase[3] : testCase[2]
test(`Converts ${classicAddress}${tag ? ':' + tag : ''} to ${xAddress}${network}`, () => {
expect(classicAddressToXAddress(classicAddress, tag, isTestAddress)).toBe(xAddress)
const myClassicAddress = xAddressToClassicAddress(xAddress)
@@ -191,7 +191,7 @@ const testCases = [
highAndLowAccounts.forEach(accountId => {
[false, 0, 1, MAX_32_BIT_UNSIGNED_INT].forEach(t => {
const tag = (t as number | false)
const tag = (t | false)
const xAddress = encodeXAddress(accountId, tag, isTestAddress)
test(`Encoding ${accountId.toString('hex')}${tag ? ':' + tag : ''} to ${xAddress} has expected length`, () => {
expect(xAddress.length).toBe(47)

View File

@@ -1,4 +1,4 @@
import {seqEqual, concatArgs} from './utils'
const {seqEqual, concatArgs} = require('./utils')
test('two sequences are equal', () => {
expect(seqEqual([1, 2, 3], [1, 2, 3])).toBe(true)

View File

@@ -1,10 +1,10 @@
import * as api from './xrp-codec'
const api = require('./xrp-codec')
function toHex(bytes: Buffer) {
function toHex(bytes) {
return Buffer.from(bytes).toString('hex').toUpperCase()
}
function toBytes(hex: string) {
function toBytes(hex) {
return Buffer.from(hex, 'hex')
}
@@ -16,7 +16,7 @@ function toBytes(hex: string) {
* @param base58 Base58-encoded string to decode
* @param hex Hexadecimal representation of expected decoded data
*/
function makeEncodeDecodeTest(encoder: Function, decoder: Function, base58: string, hex: string) {
function makeEncodeDecodeTest(encoder, decoder, base58, hex) {
test(`can translate between ${hex} and ${base58}`, function() {
const actual = encoder(toBytes(hex))
expect(actual).toBe(base58)