ci: run lint tests (#1603)

* turn on lint tests

* remove tsc

* fix errors in src/utils/hashes

* fix linter errors in src/utils

* fix lint issues in test/

* resolve lint issues in src/client

* resolve dependency cycle

* resolve other linting issues in src/models

* resolve rest of linting issues

* fix tests

* fix linting errors in test/integration

* fix rest of linting issues

* fix test name
This commit is contained in:
Mayukha Vadari
2021-09-22 16:39:10 -04:00
parent 57a6586898
commit 98c9b9bc14
43 changed files with 258 additions and 558 deletions

View File

@@ -4,6 +4,7 @@ import { Client } from 'xrpl-local'
describe('client constructor', function () {
it('Client - implicit server port', function () {
// eslint-disable-next-line no-new -- Testing constructor
new Client('wss://s1.ripple.com')
})

View File

@@ -1,362 +0,0 @@
// import BigNumber from 'bignumber.js'
// import {assert} from 'chai'
// import {Client} from 'xrpl-local'
// import requests from '../fixtures/requests'
// import responses from '../fixtures/responses'
// function checkSortingOfOrders(orders) {
// let previousRate = '0'
// for (var i = 0; i < orders.length; i++) {
// const order = orders[i]
// let rate
// // We calculate the quality of output/input here as a test.
// // This won't hold in general because when output and input amounts get tiny,
// // the quality can differ significantly. However, the offer stays in the
// // order book where it was originally placed. It would be more consistent
// // to check the quality from the offer book, but for the test data set,
// // this calculation holds.
// if (order.specification.direction === 'buy') {
// rate = new BigNumber(order.specification.quantity.value)
// .dividedBy(order.specification.totalPrice.value)
// .toString()
// } else {
// rate = new BigNumber(order.specification.totalPrice.value)
// .dividedBy(order.specification.quantity.value)
// .toString()
// }
// assert(
// new BigNumber(rate).isGreaterThanOrEqualTo(previousRate),
// 'Rates must be sorted from least to greatest: ' +
// rate +
// ' should be >= ' +
// previousRate
// )
// previousRate = rate
// }
// return true
// }
describe('client.formatBidsAndAsks', function () {
// 'normal': async (client, address) => {
// const orderbookInfo = {
// base: {
// currency: 'USD',
// counterparty: 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B'
// },
// counter: {
// currency: 'BTC',
// counterparty: 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B'
// }
// }
// await Promise.all([
// client.request({command: 'book_offers',
// taker_gets: orderbookInfo.base,
// taker_pays: orderbookInfo.counter,
// ledger_index: 'validated',
// limit: 20,
// taker: address
// }),
// client.request({command: 'book_offers',
// taker_gets: orderbookInfo.counter,
// taker_pays: orderbookInfo.base,
// ledger_index: 'validated',
// limit: 20,
// taker: address
// })
// ]).then(([directOfferResults, reverseOfferResults]) => {
// const directOffers = (directOfferResults
// ? directOfferResults.result.offers
// : []
// ).reduce((acc, res) => acc.concat(res), [])
// const reverseOffers = (reverseOfferResults
// ? reverseOfferResults.result.offers
// : []
// ).reduce((acc, res) => acc.concat(res), [])
// const orderbook = Client.formatBidsAndAsks(orderbookInfo, [
// ...directOffers,
// ...reverseOffers
// ])
// assert.deepEqual(orderbook, responses.getOrderbook.normal)
// })
// },
// 'with XRP': async (client, address) => {
// const orderbookInfo = {
// base: {
// currency: 'USD',
// issuer: 'rp8rJYTpodf8qbSCHVTNacf8nSW8mRakFw'
// },
// counter: {
// currency: 'XRP'
// }
// }
// await Promise.all([
// client.request({command: 'book_offers',
// taker_gets: orderbookInfo.base,
// taker_pays: orderbookInfo.counter,
// ledger_index: 'validated',
// limit: 20,
// taker: address
// }),
// client.request({command: 'book_offers',
// taker_gets: orderbookInfo.counter,
// taker_pays: orderbookInfo.base,
// ledger_index: 'validated',
// limit: 20,
// taker: address
// })
// ]).then(([directOfferResults, reverseOfferResults]) => {
// const directOffers = (directOfferResults
// ? directOfferResults.result.offers
// : []
// ).reduce((acc, res) => acc.concat(res), [])
// const reverseOffers = (reverseOfferResults
// ? reverseOfferResults.result.offers
// : []
// ).reduce((acc, res) => acc.concat(res), [])
// const orderbook = Client.formatBidsAndAsks(orderbookInfo, [
// ...directOffers,
// ...reverseOffers
// ])
// assert.deepEqual(orderbook, responses.getOrderbook.withXRP)
// })
// },
// 'sample XRP/JPY book has orders sorted correctly': async (client, address) => {
// const orderbookInfo = {
// base: {
// // the first currency in pair
// currency: 'XRP'
// },
// counter: {
// currency: 'JPY',
// issuer: 'rB3gZey7VWHYRqJHLoHDEJXJ2pEPNieKiS'
// }
// }
// const myAddress = 'rE9qNjzJXpiUbVomdv7R4xhrXVeH2oVmGR'
// await Promise.all([
// client.request({command: 'book_offers',
// taker_gets: orderbookInfo.base,
// taker_pays: orderbookInfo.counter,
// ledger_index: 'validated',
// limit: 400, // must match `test/fixtures/rippled/requests/1-taker_gets-XRP-taker_pays-JPY.json`
// taker: myAddress
// }),
// client.request({command: 'book_offers',
// taker_gets: orderbookInfo.counter,
// taker_pays: orderbookInfo.base,
// ledger_index: 'validated',
// limit: 400, // must match `test/fixtures/rippled/requests/2-taker_gets-JPY-taker_pays-XRP.json`
// taker: myAddress
// })
// ]).then(([directOfferResults, reverseOfferResults]) => {
// const directOffers = (directOfferResults
// ? directOfferResults.result.offers
// : []
// ).reduce((acc, res) => acc.concat(res), [])
// const reverseOffers = (reverseOfferResults
// ? reverseOfferResults.result.offers
// : []
// ).reduce((acc, res) => acc.concat(res), [])
// const orderbook = Client.formatBidsAndAsks(orderbookInfo, [
// ...directOffers,
// ...reverseOffers
// ])
// assert.deepStrictEqual([], orderbook.bids)
// return checkSortingOfOrders(orderbook.asks)
// })
// },
// 'sample USD/XRP book has orders sorted correctly': async (client, address) => {
// const orderbookInfo = {
// counter: {currency: 'XRP'},
// base: {
// currency: 'USD',
// counterparty: 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B'
// }
// }
// const myAddress = 'rE9qNjzJXpiUbVomdv7R4xhrXVeH2oVmGR'
// await Promise.all([
// client.request({command: 'book_offers',
// taker_gets: orderbookInfo.base,
// taker_pays: orderbookInfo.counter,
// ledger_index: 'validated',
// limit: 400, // must match `test/fixtures/rippled/requests/1-taker_gets-XRP-taker_pays-JPY.json`
// taker: myAddress
// }),
// client.request({command: 'book_offers',
// taker_gets: orderbookInfo.counter,
// taker_pays: orderbookInfo.base,
// ledger_index: 'validated',
// limit: 400, // must match `test/fixtures/rippled/requests/2-taker_gets-JPY-taker_pays-XRP.json`
// taker: myAddress
// })
// ]).then(([directOfferResults, reverseOfferResults]) => {
// const directOffers = (directOfferResults
// ? directOfferResults.result.offers
// : []
// ).reduce((acc, res) => acc.concat(res), [])
// const reverseOffers = (reverseOfferResults
// ? reverseOfferResults.result.offers
// : []
// ).reduce((acc, res) => acc.concat(res), [])
// const orderbook = Client.formatBidsAndAsks(orderbookInfo, [
// ...directOffers,
// ...reverseOffers
// ])
// return (
// checkSortingOfOrders(orderbook.bids) &&
// checkSortingOfOrders(orderbook.asks)
// )
// })
// },
// 'sorted so that best deals come first': async (client, address) => {
// const orderbookInfo = {
// base: {
// currency: 'USD',
// counterparty: 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B'
// },
// counter: {
// currency: 'BTC',
// counterparty: 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B'
// }
// }
// await Promise.all([
// client.request({command: 'book_offers',
// taker_gets: orderbookInfo.base,
// taker_pays: orderbookInfo.counter,
// ledger_index: 'validated',
// limit: 20,
// taker: address
// }),
// client.request({command: 'book_offers',
// taker_gets: orderbookInfo.counter,
// taker_pays: orderbookInfo.base,
// ledger_index: 'validated',
// limit: 20,
// taker: address
// })
// ]).then(([directOfferResults, reverseOfferResults]) => {
// const directOffers = (directOfferResults
// ? directOfferResults.result.offers
// : []
// ).reduce((acc, res) => acc.concat(res), [])
// const reverseOffers = (reverseOfferResults
// ? reverseOfferResults.result.offers
// : []
// ).reduce((acc, res) => acc.concat(res), [])
// const orderbook = Client.formatBidsAndAsks(orderbookInfo, [
// ...directOffers,
// ...reverseOffers
// ])
// const bidRates = orderbook.bids.map(
// (bid) => bid.properties.makerExchangeRate
// )
// const askRates = orderbook.asks.map(
// (ask) => ask.properties.makerExchangeRate
// )
// // makerExchangeRate = quality = takerPays.value/takerGets.value
// // so the best deal for the taker is the lowest makerExchangeRate
// // bids and asks should be sorted so that the best deals come first
// assert.deepEqual(bidRates.map((x) => Number(x)).sort(), bidRates)
// assert.deepEqual(askRates.map((x) => Number(x)).sort(), askRates)
// })
// },
// 'currency & counterparty are correct': async (client, address) => {
// const orderbookInfo = {
// base: {
// currency: 'USD',
// counterparty: 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B'
// },
// counter: {
// currency: 'BTC',
// counterparty: 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B'
// }
// }
// await Promise.all([
// client.request({command: 'book_offers',
// taker_gets: orderbookInfo.base,
// taker_pays: orderbookInfo.counter,
// ledger_index: 'validated',
// limit: 20,
// taker: address
// }),
// client.request({command: 'book_offers',
// taker_gets: orderbookInfo.counter,
// taker_pays: orderbookInfo.base,
// ledger_index: 'validated',
// limit: 20,
// taker: address
// })
// ]).then(([directOfferResults, reverseOfferResults]) => {
// const directOffers = (directOfferResults
// ? directOfferResults.result.offers
// : []
// ).reduce((acc, res) => acc.concat(res), [])
// const reverseOffers = (reverseOfferResults
// ? reverseOfferResults.result.offers
// : []
// ).reduce((acc, res) => acc.concat(res), [])
// const orderbook = Client.formatBidsAndAsks(orderbookInfo, [
// ...directOffers,
// ...reverseOffers
// ])
// const orders = [...orderbook.bids, ...orderbook.asks]
// orders.forEach((order) => {
// const quantity = order.specification.quantity
// const totalPrice = order.specification.totalPrice
// const {base, counter} = requests.getOrderbook.normal
// assert.strictEqual(quantity.currency, base.currency)
// assert.strictEqual(quantity.counterparty, base.counterparty)
// assert.strictEqual(totalPrice.currency, counter.currency)
// assert.strictEqual(totalPrice.counterparty, counter.counterparty)
// })
// })
// },
// 'direction is correct for bids and asks': async (client, address) => {
// const orderbookInfo = {
// base: {
// currency: 'USD',
// counterparty: 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B'
// },
// counter: {
// currency: 'BTC',
// counterparty: 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B'
// }
// }
// await Promise.all([
// client.request({command: 'book_offers',
// taker_gets: orderbookInfo.base,
// taker_pays: orderbookInfo.counter,
// ledger_index: 'validated',
// limit: 20,
// taker: address
// }),
// client.request({command: 'book_offers',
// taker_gets: orderbookInfo.counter,
// taker_pays: orderbookInfo.base,
// ledger_index: 'validated',
// limit: 20,
// taker: address
// })
// ]).then(([directOfferResults, reverseOfferResults]) => {
// const directOffers = (directOfferResults
// ? directOfferResults.result.offers
// : []
// ).reduce((acc, res) => acc.concat(res), [])
// const reverseOffers = (reverseOfferResults
// ? reverseOfferResults.result.offers
// : []
// ).reduce((acc, res) => acc.concat(res), [])
// const orderbook = Client.formatBidsAndAsks(orderbookInfo, [
// ...directOffers,
// ...reverseOffers
// ])
// assert(
// orderbook.bids.every((bid) => bid.specification.direction === 'buy')
// )
// assert(
// orderbook.asks.every((ask) => ask.specification.direction === 'sell')
// )
// })
// }
})

View File

@@ -2,6 +2,7 @@
// import { assert } from "chai";
import { assert } from 'chai'
import { BookOffersRequest } from '../../src'
import requests from '../fixtures/requests'
import responses from '../fixtures/responses'

View File

@@ -1,4 +1,3 @@
/* eslint-disable mocha/no-hooks-for-single-case -- Use of hooks is restricted when there is a single test case. */
import { assert } from 'chai'
import { setupClient, teardownClient } from '../setupClient'

View File

@@ -1,4 +1,3 @@
/* eslint-disable mocha/no-hooks-for-single-case -- expected for setupClient & teardownClient */
import { assert } from 'chai'
import { Transaction } from 'xrpl-local/models/transactions'

View File

@@ -3,7 +3,7 @@ import { assert } from 'chai'
import rippled from '../fixtures/rippled'
import { setupClient, teardownClient } from '../setupClient'
describe('Subscription', function () {
describe('Client subscription', function () {
beforeEach(setupClient)
afterEach(teardownClient)
@@ -74,15 +74,6 @@ describe('Subscription', function () {
this.client.connection.onMessage(JSON.stringify(rippled.streams.pathFind))
})
it('Emits peerStatusChange', async function (done) {
this.client.on('peerStatusChange', (path) => {
assert(path.type === 'peerStatusChange')
done()
})
this.client.connection.onMessage(JSON.stringify(rippled.streams.peerStatus))
})
it('Emits validationReceived', async function (done) {
this.client.on('validationReceived', (path) => {
assert(path.type === 'validationReceived')

View File

@@ -12,7 +12,7 @@ import {
XrplError,
TimeoutError,
} from 'xrpl-local'
import { Connection } from 'xrpl-local/client'
import { Connection } from 'xrpl-local/client/connection'
import rippled from './fixtures/rippled'
import { setupClient, teardownClient } from './setupClient'

View File

@@ -1,4 +1,3 @@
/* eslint-disable max-params -- helper test functions */
import { assert } from 'chai'
import _ from 'lodash'
import { decode } from 'ripple-binary-codec'

View File

@@ -2,4 +2,6 @@ import { Wallet } from 'xrpl-local'
const walletSecret = 'shK6YXzwYfnFVn3YZSaMh5zuAddKx'
export const wallet = Wallet.fromSeed(walletSecret)
const wallet = Wallet.fromSeed(walletSecret)
export default wallet

View File

@@ -12,11 +12,8 @@ import {
TrustSet,
TrustSetTransactionFlags,
} from 'xrpl-local'
import {
isFlagEnabled,
setTransactionFlagsToNumber,
} from '../../src/models/utils'
import { isFlagEnabled } from 'xrpl-local/models/utils'
import setTransactionFlagsToNumber from 'xrpl-local/models/utils/flags'
/**
* Utils Testing.

View File

@@ -1,6 +1,7 @@
import { assert } from 'chai'
import { ValidationError, XrplError } from 'xrpl-local'
import { computeLedgerHash } from '../../src/utils'
import requests from '../fixtures/requests'
import responses from '../fixtures/responses'
@@ -23,7 +24,7 @@ describe('computeLedgerHash', function () {
)
ledger.parent_close_time = ledger.close_time
let hash
let hash: string
try {
hash = computeLedgerHash(ledger, { computeTreeHashes: true })
} catch (error) {
@@ -139,6 +140,7 @@ describe('computeLedgerHash', function () {
...REQUEST_FIXTURES.header,
transaction_hash:
'325EACC5271322539EEEC2D6A5292471EF1B3E72AE7180533EFC3B8F0AD435C9',
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- okay for tests
transactions: REQUEST_FIXTURES.transactions as any,
}

View File

@@ -1,7 +1,8 @@
import { assert } from 'chai'
import ECDSA from '../../src/ecdsa'
import { UnexpectedError } from 'xrpl-local'
import ECDSA from '../../src/ecdsa'
import {
generateXAddress,
GenerateAddressOptions,