diff --git a/.eslintrc.js b/.eslintrc.js index 02a8bbd6..759056c5 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -81,6 +81,13 @@ module.exports = { 'max-nested-callbacks': 'off', }, }, + { + files: ['test/client/*.ts'], + rules: { + // Rule does not work with dynamically generated tests. + 'mocha/no-setup-in-describe': 'off', + }, + }, { files: ['test/models/*.ts'], rules: { diff --git a/test/client/combine.ts b/test/client/combine.ts index 8442d676..a34bcfa8 100644 --- a/test/client/combine.ts +++ b/test/client/combine.ts @@ -25,6 +25,6 @@ describe('client.combine', function () { request.push(binary.encode(tx)) assert.throws(() => { this.client.combine(request) - }, /txJSON is not the same for all signedTransactions/) + }, /txJSON is not the same for all signedTransactions/u) }) }) diff --git a/test/client/constructor.ts b/test/client/constructor.ts index 1fa7e30a..1a87f069 100644 --- a/test/client/constructor.ts +++ b/test/client/constructor.ts @@ -14,7 +14,7 @@ describe('client constructor', function () { it('Client valid options', function () { const client = new Client('wss://s:1') - const privateConnectionUrl = (client.connection as any).url + const privateConnectionUrl = client.connection.getUrl() assert.deepEqual(privateConnectionUrl, 'wss://s:1') }) diff --git a/test/client/getBalances.ts b/test/client/getBalances.ts index 35f309a6..e4b1286e 100644 --- a/test/client/getBalances.ts +++ b/test/client/getBalances.ts @@ -13,9 +13,8 @@ describe('getBalances', function () { beforeEach(setupClient) afterEach(teardownClient) - // eslint-disable-next-line mocha/no-setup-in-describe -- Rule does not allow dynamic test generation. - addressTests.forEach(function (testCase) { - describe(testCase.type, function () { + addressTests.forEach(function (testcase) { + describe(testcase.type, function () { it('getBalances', async function () { this.mockRippled.addResponse( 'account_info', @@ -26,45 +25,43 @@ describe('getBalances', function () { rippledAccountLines.normal, ) this.mockRippled.addResponse('ledger', rippled.ledger.normal) - const result = await this.client.getBalances(testCase.address) + const result = await this.client.getBalances(testcase.address) assertResultMatch(result, responses.getBalances, 'getBalances') }) - // it("getBalances - limit", async function () { - // const request = { - // account: test.address, - // limit: 10, - // ledger_index: 123456, - // }; + // it('getBalances - limit', async function () { + // const options = { limit: 3, ledgerVersion: 123456 } // this.mockRippled.addResponse( - // "account_info", - // rippled.account_info.normal - // ); + // 'account_info', + // rippled.account_info.normal, + // ) // this.mockRippled.addResponse( - // "account_lines", - // rippledAccountLines.normal - // ); - // this.mockRippled.addResponse("ledger", rippled.ledger.normal); - // const expectedResponse = responses.getBalances.slice(0, 10); - // const result = await this.client.getBalances(request); - // assertResultMatch(result, expectedResponse, "getBalances"); - // }); + // 'account_lines', + // rippledAccountLines.normal, + // ) + // this.mockRippled.addResponse('ledger', rippled.ledger.normal) + // const expectedResponse = responses.getBalances.slice(0, 3) + // const result = await this.client.getBalances(testcase.address, options) + // assertResultMatch(result, expectedResponse, 'getBalances') + // }) - // it("getBalances - limit", async function () { - // const options = { limit: 3, ledgerVersion: 123456 }; - // this.mockRippled.addResponse( - // "account_info", - // rippled.account_info.normal - // ); - // this.mockRippled.addResponse( - // "account_lines", - // rippledAccountLines.normal - // ); - // this.mockRippled.addResponse("ledger", rippled.ledger.normal); - // const expectedResponse = responses.getBalances.slice(0, 3); - // const result = await this.client.getBalances(test.address, options); - // assertResultMatch(result, expectedResponse, "getBalances"); - // }); + // it('getBalances - limit & currency', async function () { + // const options = { currency: 'USD', limit: 3 } + // this.mockRippled.addResponse( + // 'account_info', + // rippled.account_info.normal, + // ) + // this.mockRippled.addResponse( + // 'account_lines', + // rippledAccountLines.normal, + // ) + // this.mockRippled.addResponse('ledger', rippled.ledger.normal) + // const expectedResponse = responses.getBalances + // .filter((item) => item.currency === 'USD') + // .slice(0, 3) + // const result = await this.client.getBalances(testcase.address, options) + // assertResultMatch(result, expectedResponse, 'getBalances') + // }) // it("getBalances - limit & currency", async function () { // const options = { currency: "USD", limit: 3 }; diff --git a/test/client/getOrderbook.ts b/test/client/getOrderbook.ts index 7b9ed3ba..3b880237 100644 --- a/test/client/getOrderbook.ts +++ b/test/client/getOrderbook.ts @@ -40,21 +40,23 @@ import { addressTests } from '../testUtils' // return true; // } -function isUSD(currency: string) { +function isUSD(currency: string): boolean { return ( currency === 'USD' || currency === '0000000000000000000000005553440000000000' ) } -function isBTC(currency: string) { +function isBTC(currency: string): boolean { return ( currency === 'BTC' || currency === '0000000000000000000000004254430000000000' ) } -function normalRippledResponse(request: BookOffersRequest): object { +function normalRippledResponse( + request: BookOffersRequest, +): Record { if ( isBTC(request.taker_gets.currency) && isUSD(request.taker_pays.currency) @@ -70,57 +72,59 @@ function normalRippledResponse(request: BookOffersRequest): object { throw new Error('unexpected end') } -// function xrpRippledResponse(request: BookOffersRequest): object { -// if (request.taker_pays.issuer === "rp8rJYTpodf8qbSCHVTNacf8nSW8mRakFw") { -// return rippled.book_offers.xrp_usd; +// function xrpRippledResponse( +// request: BookOffersRequest, +// ): Record { +// if (request.taker_pays.issuer === 'rp8rJYTpodf8qbSCHVTNacf8nSW8mRakFw') { +// return rippled.book_offers.xrp_usd // } -// if (request.taker_gets.issuer === "rp8rJYTpodf8qbSCHVTNacf8nSW8mRakFw") { -// return rippled.book_offers.usd_xrp; +// if (request.taker_gets.issuer === 'rp8rJYTpodf8qbSCHVTNacf8nSW8mRakFw') { +// return rippled.book_offers.usd_xrp // } -// throw new Error("unexpected end"); +// throw new Error('unexpected end') // } describe('client.getOrderbook', function () { beforeEach(setupClient) afterEach(teardownClient) - addressTests.forEach(function (test) { - describe(test.type, function () { + addressTests.forEach(function (testcase) { + describe(testcase.type, function () { it('normal', async function () { this.mockRippled.addResponse('book_offers', normalRippledResponse) const response = await this.client.getOrderbook( requests.getOrderbook.normal.taker_pays, requests.getOrderbook.normal.taker_gets, - { - limit: 1, - }, + { limit: 1 }, ) assert.deepEqual(response, responses.getOrderbook.normal) }) - // it("invalid options", async function () { - // this.mockRippled.addResponse("book_offers", normalRippledResponse); + // it('invalid options', async function () { + // this.mockRippled.addResponse('book_offers', normalRippledResponse) // assertRejects( - // this.client.getOrderbook(test.address, requests.getOrderbook.normal, { - // invalid: "options", - // }), - // this.client.errors.ValidationError - // ); - // }); - - // it("with XRP", async function () { - // this.mockRippled.addResponse("book_offers", xrpRippledResponse); + // this.client.getOrderbook( + // testcase.address, + // requests.getOrderbook.normal, + // { + // invalid: 'options', + // }, + // ), + // this.client.errors.ValidationError, + // ) + // }) + // it('with XRP', async function () { + // this.mockRippled.addResponse('book_offers', xrpRippledResponse) // const response = await this.client.getOrderbook( - // test.address, - // requests.getOrderbook.withXRP - // ); + // testcase.address, + // requests.getOrderbook.withXRP, + // ) // assertResultMatch( // response, // responses.getOrderbook.withXRP, - // "getOrderbook" - // ); - // }); - + // 'getOrderbook', + // ) + // }) // 'sample XRP/JPY book has orders sorted correctly', async function () { // const orderbookInfo = { // base: { @@ -137,7 +141,6 @@ describe('client.getOrderbook', function () { // assert.deepStrictEqual([], response.bids) // checkSortingOfOrders(response.asks) // }, - // 'sample USD/XRP book has orders sorted correctly', async function () { // const orderbookInfo = { // counter: {currency: 'XRP'}, @@ -151,7 +154,6 @@ describe('client.getOrderbook', function () { // checkSortingOfOrders(response.bids) // checkSortingOfOrders(response.asks) // }, - // WARNING: This test fails to catch the sorting bug, issue #766 // it("sorted so that best deals come first [bad test]", async function () { // this.mockRippled.addResponse("book_offers", normalRippledResponse); @@ -177,7 +179,6 @@ describe('client.getOrderbook', function () { // askRates // ); // }); - // it("currency & counterparty are correct", async function () { // this.mockRippled.addResponse("book_offers", normalRippledResponse); // const response = await this.client.getOrderbook( @@ -194,7 +195,6 @@ describe('client.getOrderbook', function () { // assert.strictEqual(totalPrice.counterparty, counter.counterparty); // }); // }); - // it("direction is correct for bids and asks", async function () { // this.mockRippled.addResponse("book_offers", normalRippledResponse); // const response = await this.client.getOrderbook( diff --git a/test/client/hasNextPage.ts b/test/client/hasNextPage.ts index ef403ca4..0212a1fa 100644 --- a/test/client/hasNextPage.ts +++ b/test/client/hasNextPage.ts @@ -15,7 +15,9 @@ describe('client.hasNextPage', function () { }) it('returns false when there are no more pages', async function () { - const rippledResponse = function (request: Request): object { + const rippledResponse = function ( + request: Request, + ): Record { if ('marker' in request) { return rippled.ledger_data.last_page } diff --git a/test/client/isConnected.ts b/test/client/isConnected.ts index b3761e88..b73de078 100644 --- a/test/client/isConnected.ts +++ b/test/client/isConnected.ts @@ -1,3 +1,4 @@ +/* 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' diff --git a/test/client/request.ts b/test/client/request.ts index b7eee87a..c20600a8 100644 --- a/test/client/request.ts +++ b/test/client/request.ts @@ -7,8 +7,8 @@ describe('client.request', function () { beforeEach(setupClient) afterEach(teardownClient) - addressTests.forEach(function (test) { - describe(test.type, function () { + addressTests.forEach(function (testcase) { + describe(testcase.type, function () { it('request account_objects', async function () { this.mockRippled.addResponse( 'account_objects', @@ -16,7 +16,7 @@ describe('client.request', function () { ) const result = await this.client.request({ command: 'account_objects', - account: test.address, + account: testcase.address, }) assertResultMatch( @@ -33,7 +33,7 @@ describe('client.request', function () { ) const result = await this.client.request({ command: 'account_objects', - account: test.address, + account: testcase.address, }) assertResultMatch( diff --git a/test/client/requestNextPage.ts b/test/client/requestNextPage.ts index 6a44ad60..fce9a578 100644 --- a/test/client/requestNextPage.ts +++ b/test/client/requestNextPage.ts @@ -5,7 +5,7 @@ import rippled from '../fixtures/rippled' import { setupClient, teardownClient } from '../setupClient' import { assertRejects } from '../testUtils' -const rippledResponse = function (request: Request): object { +const rippledResponse = function (request: Request): Record { if ('marker' in request) { return rippled.ledger_data.last_page } diff --git a/test/client/sign.ts b/test/client/sign.ts index 119bd7c6..a30c0a90 100644 --- a/test/client/sign.ts +++ b/test/client/sign.ts @@ -88,7 +88,7 @@ describe('client.sign', function () { assert.throws(() => { const tx = JSON.stringify(binary.decode(result.signedTransaction)) this.client.sign(tx, keypair) - }, /txJSON must not contain "TxnSignature" or "Signers" properties/) + }, /txJSON must not contain "TxnSignature" or "Signers" properties/u) }) it('withKeypair EscrowExecution', async function () { @@ -122,7 +122,7 @@ describe('client.sign', function () { assert.throws(() => { const tx = JSON.stringify(binary.decode(result.signedTransaction)) this.client.sign(tx, secret) - }, /txJSON must not contain "TxnSignature" or "Signers" properties/) + }, /txJSON must not contain "TxnSignature" or "Signers" properties/u) }) it('succeeds - no flags', async function () { @@ -138,7 +138,7 @@ describe('client.sign', function () { const decoded = binary.decode(result.signedTransaction) assert( decoded.Flags == null, - `Flags = ${decoded.Flags}, should be undefined`, + `Flags = ${decoded.Flags as number}, should be undefined`, ) assert.deepEqual(result, expectedResult) }) @@ -158,7 +158,7 @@ describe('client.sign', function () { const decoded = binary.decode(result.signedTransaction) assert( decoded.Flags === 2147614720, - `Flags = ${decoded.Flags}, should be 2147614720`, + `Flags = ${decoded.Flags as number}, should be 2147614720`, ) assert.deepEqual(result, expectedResult) }) @@ -177,7 +177,7 @@ describe('client.sign', function () { assert.throws(() => { this.client.sign(request.txJSON, secret) - }, /1\.2 is an illegal amount/) + }, /1\.2 is an illegal amount/u) }) it('throws when encoded tx does not match decoded tx - higher fee', async function () { @@ -194,7 +194,7 @@ describe('client.sign', function () { assert.throws(() => { this.client.sign(request.txJSON, secret) - }, /1123456\.7 is an illegal amount/) + }, /1123456\.7 is an illegal amount/u) }) it('permits fee exceeding 2000000 drops when maxFeeXRP is higher than 2 XRP', async function () { @@ -240,7 +240,7 @@ describe('client.sign', function () { assert.throws(() => { this.client.sign(request.txJSON, secret) - }, /Fee" should not exceed "2000000"\. To use a higher fee, set `maxFeeXRP` in the Client constructor\./) + }, /Fee" should not exceed "2000000"\. To use a higher fee, set `maxFeeXRP` in the Client constructor\./u) }) it('throws when Fee exceeds maxFeeXRP (in drops) - custom maxFeeXRP', async function () { @@ -257,7 +257,7 @@ describe('client.sign', function () { assert.throws(() => { this.client.sign(request.txJSON, secret) - }, /Fee" should not exceed "1900000"\. To use a higher fee, set `maxFeeXRP` in the Client constructor\./) + }, /Fee" should not exceed "1900000"\. To use a higher fee, set `maxFeeXRP` in the Client constructor\./u) }) it('sign with paths', async function () { @@ -329,7 +329,7 @@ describe('client.sign', function () { const secret = 'shsWGZcmZz6YsWWmcnpfr6fLTdtFV' assert.throws(() => { this.client.sign(JSON.stringify(payment), secret) - }, /^1.1234567 is an illegal amount/) + }, /^1.1234567 is an illegal amount/u) }) it('throws when encoded tx does not match decoded tx - prepared order', async function () {