mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-20 12:15:51 +00:00
Lints top-level test files (#1594)
* lint broadcastClient * lint client * fix most of connection * remove unused files * lint mockRippled * lint mockRippledTest * lint runClientTests * lint setupClient * lint setupClientWeb * lint shamap * lint testUtils * resolve tsc issues * Fix tests * lint rest of connection * respond to comments
This commit is contained in:
@@ -2,27 +2,19 @@ import { assert } from 'chai'
|
||||
import _ from 'lodash'
|
||||
|
||||
import { Client } from 'xrpl-local'
|
||||
import {
|
||||
RecursiveData,
|
||||
renameCounterpartyToIssuerInOrder,
|
||||
compareTransactions,
|
||||
getRecursive,
|
||||
} from 'xrpl-local/ledger/utils'
|
||||
|
||||
import { toRippledAmount } from '../src'
|
||||
|
||||
import setupClient from './setupClient'
|
||||
import { assertRejects } from './testUtils'
|
||||
import { setupClient, teardownClient } from './setupClient'
|
||||
|
||||
// how long before each test case times out
|
||||
const TIMEOUT = 20000
|
||||
|
||||
describe('Client', function () {
|
||||
this.timeout(TIMEOUT)
|
||||
beforeEach(setupClient.setup)
|
||||
afterEach(setupClient.teardown)
|
||||
beforeEach(setupClient)
|
||||
afterEach(teardownClient)
|
||||
|
||||
it('Client - implicit server port', function () {
|
||||
// eslint-disable-next-line no-new -- Need to test constructor
|
||||
new Client('wss://s1.ripple.com')
|
||||
})
|
||||
|
||||
@@ -33,6 +25,7 @@ describe('Client', function () {
|
||||
|
||||
it('Client valid options', function () {
|
||||
const client = new Client('wss://s:1')
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- TODO: fix when src/client linting is merged
|
||||
const privateConnectionUrl = (client.connection as any).url
|
||||
assert.deepEqual(privateConnectionUrl, 'wss://s:1')
|
||||
})
|
||||
@@ -45,54 +38,4 @@ describe('Client', function () {
|
||||
// TODO: Use a timer mock like https://jestjs.io/docs/en/timer-mocks
|
||||
// to test that connect() times out after 2 seconds.
|
||||
})
|
||||
|
||||
describe('[private] validator', function () {
|
||||
it('common utils - toRippledAmount', async function () {
|
||||
const amount = { issuer: 'is', currency: 'c', value: 'v' }
|
||||
assert.deepEqual(toRippledAmount(amount), {
|
||||
issuer: 'is',
|
||||
currency: 'c',
|
||||
value: 'v',
|
||||
})
|
||||
})
|
||||
|
||||
it('ledger utils - renameCounterpartyToIssuerInOrder', async function () {
|
||||
const order = {
|
||||
taker_gets: { counterparty: '1', currency: 'XRP' },
|
||||
taker_pays: { counterparty: '1', currency: 'XRP' },
|
||||
}
|
||||
const expected = {
|
||||
taker_gets: { issuer: '1', currency: 'XRP' },
|
||||
taker_pays: { issuer: '1', currency: 'XRP' },
|
||||
}
|
||||
assert.deepEqual(renameCounterpartyToIssuerInOrder(order), expected)
|
||||
})
|
||||
|
||||
it('ledger utils - compareTransactions', async function () {
|
||||
// @ts-expect-error
|
||||
assert.strictEqual(compareTransactions({}, {}), 0)
|
||||
let first: any = { outcome: { ledgerVersion: 1, indexInLedger: 100 } }
|
||||
let second: any = { outcome: { ledgerVersion: 1, indexInLedger: 200 } }
|
||||
assert.strictEqual(compareTransactions(first, second), -1)
|
||||
first = { outcome: { ledgerVersion: 1, indexInLedger: 100 } }
|
||||
second = { outcome: { ledgerVersion: 1, indexInLedger: 100 } }
|
||||
assert.strictEqual(compareTransactions(first, second), 0)
|
||||
first = { outcome: { ledgerVersion: 1, indexInLedger: 200 } }
|
||||
second = { outcome: { ledgerVersion: 1, indexInLedger: 100 } }
|
||||
assert.strictEqual(compareTransactions(first, second), 1)
|
||||
})
|
||||
|
||||
it('ledger utils - getRecursive', async function () {
|
||||
async function getter(marker) {
|
||||
return new Promise<RecursiveData>((resolve, reject) => {
|
||||
if (marker != null) {
|
||||
reject(new Error())
|
||||
return
|
||||
}
|
||||
resolve({ marker: 'A', results: [1] })
|
||||
})
|
||||
}
|
||||
await assertRejects(getRecursive(getter, 10), Error)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user