diff --git a/.eslintrc.js b/.eslintrc.js index 759056c5..dc96e262 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -36,7 +36,7 @@ module.exports = { ], 'max-lines-per-function': [ 'warn', - { max: 40, skipBlankLines: 'true', skipComments: 'true' }, + { max: 40, skipBlankLines: true, skipComments: true }, ], 'max-statements': ['warn', 25], 'id-length': ['error', { exceptions: ['_'] }], // exception for lodash diff --git a/src/client/requestManager.ts b/src/client/requestManager.ts index 74f2fc0a..a9e00c05 100644 --- a/src/client/requestManager.ts +++ b/src/client/requestManager.ts @@ -4,7 +4,7 @@ import { TimeoutError, } from '../common/errors' import { Response } from '../models/methods' -import { BaseRequest } from '../models/methods/baseMethod' +import { BaseRequest, ErrorResponse } from '../models/methods/baseMethod' /** * Manage all the requests made to the websocket, and their async responses @@ -126,7 +126,7 @@ export default class RequestManager { * @param response - The response to handle. * @throws ResponseFormatError if the response format is invalid, RippledError if rippled returns an error. */ - public handleResponse(response: Partial): void { + public handleResponse(response: Partial): void { if ( response.id == null || !Number.isInteger(response.id) || @@ -142,9 +142,11 @@ export default class RequestManager { this.reject(response.id, error) } if (response.status === 'error') { + // eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- We know this must be true + const errorResponse = response as Partial const error = new RippledError( - response.error_message ?? response.error, - response, + errorResponse.error_message ?? errorResponse.error, + errorResponse, ) this.reject(response.id, error) return diff --git a/src/models/methods/baseMethod.ts b/src/models/methods/baseMethod.ts index a00af8f8..34f76694 100644 --- a/src/models/methods/baseMethod.ts +++ b/src/models/methods/baseMethod.ts @@ -1,3 +1,5 @@ +import type { Request } from '.' + export interface BaseRequest { [x: string]: unknown id?: number | string @@ -13,15 +15,22 @@ interface Warning { export interface BaseResponse { id: number | string - status: 'success' | 'error' | string + status: 'success' | string type: 'response' | string result: unknown warning?: 'load' warnings?: Warning[] forwarded?: boolean - error?: string - error_message?: string - // TODO: type this better - request?: unknown + api_version?: number +} + +export interface ErrorResponse { + id: number | string + status: 'error' + type: 'response' | string + error: string + error_code?: string + error_message?: string + request: Request api_version?: number } diff --git a/src/models/methods/index.ts b/src/models/methods/index.ts index 0bb2bfaf..59594158 100644 --- a/src/models/methods/index.ts +++ b/src/models/methods/index.ts @@ -1,5 +1,3 @@ -/* eslint-disable import/max-dependencies -- All methods need to be exported */ - import { AccountChannelsRequest, AccountChannelsResponse, @@ -13,6 +11,7 @@ import { AccountLinesRequest, AccountLinesResponse } from './accountLines' import { AccountObjectsRequest, AccountObjectsResponse } from './accountObjects' import { AccountOffersRequest, AccountOffersResponse } from './accountOffers' import { AccountTxRequest, AccountTxResponse } from './accountTx' +import { ErrorResponse } from './baseMethod' import { BookOffersRequest, BookOffersResponse } from './bookOffers' import { ChannelVerifyRequest, ChannelVerifyResponse } from './channelVerify' import { @@ -224,4 +223,5 @@ export { PingResponse, RandomRequest, RandomResponse, + ErrorResponse, } diff --git a/src/models/transactions/transaction.ts b/src/models/transactions/transaction.ts index 420d0baa..d199d7b9 100644 --- a/src/models/transactions/transaction.ts +++ b/src/models/transactions/transaction.ts @@ -1,12 +1,11 @@ /* eslint-disable complexity -- verifies 19 tx types hence a lot of checks needed */ /* eslint-disable max-lines-per-function -- need to work with a lot of Tx verifications */ -/* eslint-disable import/max-dependencies -- need to test more than 5 TxTypes */ import _ from 'lodash' import { encode, decode } from 'ripple-binary-codec' import { ValidationError } from '../../common/errors' -import TransactionMetadata from './metadata' +import { setTransactionFlagsToNumber } from '../utils' import { AccountDelete, verifyAccountDelete } from './accountDelete' import { @@ -22,12 +21,14 @@ import { DepositPreauth, verifyDepositPreauth } from './depositPreauth' import { EscrowCancel, verifyEscrowCancel } from './escrowCancel' import { EscrowCreate, verifyEscrowCreate } from './escrowCreate' import { EscrowFinish, verifyEscrowFinish } from './escrowFinish' +import TransactionMetadata from './metadata' import { OfferCancel, verifyOfferCancel } from './offerCancel' import { OfferCreate, verifyOfferCreate, OfferCreateTransactionFlags, } from './offerCreate' +import { Payment, verifyPayment, PaymentTransactionFlags } from './payment' import { PaymentChannelClaim, verifyPaymentChannelClaim, @@ -41,12 +42,10 @@ import { PaymentChannelFund, verifyPaymentChannelFund, } from './paymentChannelFund' -import { Payment, verifyPayment, PaymentTransactionFlags } from './payment' import { SetRegularKey, verifySetRegularKey } from './setRegularKey' import { SignerListSet, verifySignerListSet } from './signerListSet' import { TicketCreate, verifyTicketCreate } from './ticketCreate' import { TrustSet, verifyTrustSet, TrustSetTransactionFlags } from './trustSet' -import { setTransactionFlagsToNumber } from '../utils' export type Transaction = | AccountDelete @@ -78,7 +77,7 @@ export interface TransactionAndMetadata { * Verifies various Transaction Types. * Encode/decode and individual type validation. * - * @param tx - A Transaction. + * @param transaction - A Transaction. * @throws ValidationError When the Transaction is malformed. */ export function verify(transaction: Record): void { diff --git a/src/wallet/index.ts b/src/wallet/index.ts index 32199a42..3d8fe460 100644 --- a/src/wallet/index.ts +++ b/src/wallet/index.ts @@ -73,7 +73,7 @@ class Wallet { } /** - * Derives a wallet from a secret (AKA a seed) + * Derives a wallet from a secret (AKA a seed). * * @param secret - A string used to generate a keypair (publicKey/privateKey) to derive a wallet. * @param algorithm - The digital signature algorithm to generate an address fro. diff --git a/test/client/subscribe.ts b/test/client/subscribe.ts index aa3dba9a..66d2956a 100644 --- a/test/client/subscribe.ts +++ b/test/client/subscribe.ts @@ -1,8 +1,7 @@ import { assert } from 'chai' import rippled from '../fixtures/rippled' -import {setupClient, teardownClient} from '../setupClient' - +import { setupClient, teardownClient } from '../setupClient' describe('Subscription', function () { beforeEach(setupClient) diff --git a/test/integration/integration.ts b/test/integration/integration.ts index cd3d5b29..1c883bf3 100644 --- a/test/integration/integration.ts +++ b/test/integration/integration.ts @@ -7,6 +7,7 @@ import { Client, Wallet } from 'xrpl-local' import { AccountSet, SignerListSet } from 'xrpl-local/models/transactions' import { convertStringToHex } from 'xrpl-local/utils' import { sign, multisign } from 'xrpl-local/wallet/signer' + import { Transaction } from '../../src/models/transactions' import serverUrl from './serverUrl' diff --git a/test/integration/requests/utility.ts b/test/integration/requests/utility.ts index 1eeacfc9..365afdbd 100644 --- a/test/integration/requests/utility.ts +++ b/test/integration/requests/utility.ts @@ -1,5 +1,6 @@ import { assert } from 'chai' import _ from 'lodash' + import { Client } from 'xrpl-local' import serverUrl from '../serverUrl' diff --git a/test/mockRippled.ts b/test/mockRippled.ts index 7d5169e2..6c847062 100644 --- a/test/mockRippled.ts +++ b/test/mockRippled.ts @@ -3,7 +3,10 @@ import _ from 'lodash' import { Server as WebSocketServer } from 'ws' import type { Request } from '../src' -import type { BaseResponse } from '../src/models/methods/baseMethod' +import type { + BaseResponse, + ErrorResponse, +} from '../src/models/methods/baseMethod' import { getFreePort } from './testUtils' @@ -83,6 +86,7 @@ export default function createMockRippled(port: number): MockedWebSocketServer { } if (!mock.suppressOutput) { + // eslint-disable-next-line no-console -- only printed out on error console.error(err.message) } if (request != null) { @@ -104,8 +108,9 @@ export default function createMockRippled(port: number): MockedWebSocketServer { mock.addResponse = function ( command: string, response: - | Record - | ((r: Request) => Record), + | Response + | ErrorResponse + | ((r: Request) => Response | ErrorResponse), ): void { if (typeof command !== 'string') { throw new Error('command is not a string') diff --git a/test/models/accountDelete.ts b/test/models/accountDelete.ts index 2e0f386b..c98f95e8 100644 --- a/test/models/accountDelete.ts +++ b/test/models/accountDelete.ts @@ -1,8 +1,10 @@ -import { ValidationError } from 'xrpl-local/common/errors' -import { verifyAccountDelete } from './../../src/models/transactions/accountDelete' -import { verify } from './../../src/models/transactions' import { assert } from 'chai' +import { ValidationError } from 'xrpl-local/common/errors' + +import { verify } from '../../src/models/transactions' +import { verifyAccountDelete } from '../../src/models/transactions/accountDelete' + /** * AccountDelete Transaction Verification Testing. * diff --git a/test/models/accountSet.ts b/test/models/accountSet.ts index 2e9dbb0e..6f3ce356 100644 --- a/test/models/accountSet.ts +++ b/test/models/accountSet.ts @@ -1,8 +1,10 @@ -import { ValidationError } from 'xrpl-local/common/errors' -import { verifyAccountSet } from './../../src/models/transactions/accountSet' -import { verify } from '../../src/models/transactions' import { assert } from 'chai' +import { ValidationError } from 'xrpl-local/common/errors' + +import { verify } from '../../src/models/transactions' +import { verifyAccountSet } from '../../src/models/transactions/accountSet' + /** * AccountSet Transaction Verification Testing. * diff --git a/test/models/checkCancel.ts b/test/models/checkCancel.ts index ac315159..70b2b503 100644 --- a/test/models/checkCancel.ts +++ b/test/models/checkCancel.ts @@ -1,7 +1,9 @@ -import { ValidationError } from 'xrpl-local/common/errors' -import { verifyCheckCancel } from './../../src/models/transactions/checkCancel' import { assert } from 'chai' + +import { ValidationError } from 'xrpl-local/common/errors' + import { verify } from '../../src/models/transactions' +import { verifyCheckCancel } from '../../src/models/transactions/checkCancel' /** * CheckCancel Transaction Verification Testing. diff --git a/test/models/checkCash.ts b/test/models/checkCash.ts index 78bf2f7f..1118c721 100644 --- a/test/models/checkCash.ts +++ b/test/models/checkCash.ts @@ -1,7 +1,9 @@ -import { ValidationError } from 'xrpl-local/common/errors' -import { verifyCheckCash } from './../../src/models/transactions/checkCash' import { assert } from 'chai' + +import { ValidationError } from 'xrpl-local/common/errors' + import { verify } from '../../src/models/transactions' +import { verifyCheckCash } from '../../src/models/transactions/checkCash' /** * CheckCash Transaction Verification Testing. diff --git a/test/models/checkCreate.ts b/test/models/checkCreate.ts index 8d296b1d..84bbfadd 100644 --- a/test/models/checkCreate.ts +++ b/test/models/checkCreate.ts @@ -1,7 +1,9 @@ -import { ValidationError } from 'xrpl-local/common/errors' -import { verifyCheckCreate } from './../../src/models/transactions/checkCreate' import { assert } from 'chai' + +import { ValidationError } from 'xrpl-local/common/errors' + import { verify } from '../../src/models/transactions' +import { verifyCheckCreate } from '../../src/models/transactions/checkCreate' /** * CheckCreate Transaction Verification Testing. diff --git a/test/models/depositPreauth.ts b/test/models/depositPreauth.ts index f522fd67..5e22868b 100644 --- a/test/models/depositPreauth.ts +++ b/test/models/depositPreauth.ts @@ -1,7 +1,9 @@ -import { ValidationError } from 'xrpl-local/common/errors' -import { verifyDepositPreauth } from './../../src/models/transactions/depositPreauth' import { assert } from 'chai' + +import { ValidationError } from 'xrpl-local/common/errors' + import { verify } from '../../src/models/transactions' +import { verifyDepositPreauth } from '../../src/models/transactions/depositPreauth' /** * DepositPreauth Transaction Verification Testing. diff --git a/test/models/escrowCancel.ts b/test/models/escrowCancel.ts index a3004a0d..b5a7648a 100644 --- a/test/models/escrowCancel.ts +++ b/test/models/escrowCancel.ts @@ -1,7 +1,8 @@ -import { verifyEscrowCancel } from './../../src/models/transactions/escrowCancel' import { assert } from 'chai' + import { ValidationError } from '../../src/common/errors' import { verify } from '../../src/models/transactions' +import { verifyEscrowCancel } from '../../src/models/transactions/escrowCancel' /** * Transaction Verification Testing. diff --git a/test/models/escrowCreate.ts b/test/models/escrowCreate.ts index 14237b96..eb57550d 100644 --- a/test/models/escrowCreate.ts +++ b/test/models/escrowCreate.ts @@ -1,7 +1,9 @@ -import { ValidationError } from 'xrpl-local/common/errors' -import { verifyEscrowCreate } from './../../src/models/transactions/escrowCreate' import { assert } from 'chai' + +import { ValidationError } from 'xrpl-local/common/errors' + import { verify } from '../../src/models/transactions' +import { verifyEscrowCreate } from '../../src/models/transactions/escrowCreate' /** * EscrowCreate Transaction Verification Testing. diff --git a/test/models/escrowFinish.ts b/test/models/escrowFinish.ts index 2f75ac8d..3f06693b 100644 --- a/test/models/escrowFinish.ts +++ b/test/models/escrowFinish.ts @@ -1,7 +1,9 @@ -import { ValidationError } from 'xrpl-local/common/errors' -import { verifyEscrowFinish } from './../../src/models/transactions/escrowFinish' import { assert } from 'chai' + +import { ValidationError } from 'xrpl-local/common/errors' + import { verify } from '../../src/models/transactions' +import { verifyEscrowFinish } from '../../src/models/transactions/escrowFinish' /** * EscrowFinish Transaction Verification Testing. diff --git a/test/models/offerCancel.ts b/test/models/offerCancel.ts index 8bfa672c..6b97d9bd 100644 --- a/test/models/offerCancel.ts +++ b/test/models/offerCancel.ts @@ -1,7 +1,9 @@ -import { ValidationError } from 'xrpl-local/common/errors' -import { verifyOfferCancel } from './../../src/models/transactions/offerCancel' import { assert } from 'chai' + +import { ValidationError } from 'xrpl-local/common/errors' + import { verify } from '../../src/models/transactions' +import { verifyOfferCancel } from '../../src/models/transactions/offerCancel' /** * OfferCancel Transaction Verification Testing. diff --git a/test/models/offerCreate.ts b/test/models/offerCreate.ts index f32ec405..543efa5b 100644 --- a/test/models/offerCreate.ts +++ b/test/models/offerCreate.ts @@ -1,7 +1,9 @@ -import { ValidationError } from 'xrpl-local/common/errors' -import { verifyOfferCreate } from './../../src/models/transactions/offerCreate' import { assert } from 'chai' + +import { ValidationError } from 'xrpl-local/common/errors' + import { verify } from '../../src/models/transactions' +import { verifyOfferCreate } from '../../src/models/transactions/offerCreate' /** * OfferCreate Transaction Verification Testing. diff --git a/test/models/paymentChannelClaim.ts b/test/models/paymentChannelClaim.ts index c661dab7..67874b9e 100644 --- a/test/models/paymentChannelClaim.ts +++ b/test/models/paymentChannelClaim.ts @@ -1,7 +1,9 @@ -import { ValidationError } from 'xrpl-local/common/errors' -import { verifyPaymentChannelClaim } from './../../src/models/transactions/paymentChannelClaim' import { assert } from 'chai' + +import { ValidationError } from 'xrpl-local/common/errors' + import { verify } from '../../src/models/transactions' +import { verifyPaymentChannelClaim } from '../../src/models/transactions/paymentChannelClaim' /** * PaymentChannelClaim Transaction Verification Testing. diff --git a/test/models/paymentChannelCreate.ts b/test/models/paymentChannelCreate.ts index a452835f..3a400476 100644 --- a/test/models/paymentChannelCreate.ts +++ b/test/models/paymentChannelCreate.ts @@ -1,7 +1,9 @@ -import { ValidationError } from 'xrpl-local/common/errors' -import { verifyPaymentChannelCreate } from './../../src/models/transactions/paymentChannelCreate' import { assert } from 'chai' + +import { ValidationError } from 'xrpl-local/common/errors' + import { verify } from '../../src/models/transactions' +import { verifyPaymentChannelCreate } from '../../src/models/transactions/paymentChannelCreate' /** * PaymentChannelCreate Transaction Verification Testing. diff --git a/test/models/paymentChannelFund.ts b/test/models/paymentChannelFund.ts index 30d33446..de30292a 100644 --- a/test/models/paymentChannelFund.ts +++ b/test/models/paymentChannelFund.ts @@ -1,7 +1,9 @@ -import { ValidationError } from 'xrpl-local/common/errors' -import { verifyPaymentChannelFund } from './../../src/models/transactions/paymentChannelFund' import { assert } from 'chai' + +import { ValidationError } from 'xrpl-local/common/errors' + import { verify } from '../../src/models/transactions' +import { verifyPaymentChannelFund } from '../../src/models/transactions/paymentChannelFund' /** * PaymentChannelFund Transaction Verification Testing. diff --git a/test/models/ticketCreate.ts b/test/models/ticketCreate.ts index c26c08fa..88e8ad4f 100644 --- a/test/models/ticketCreate.ts +++ b/test/models/ticketCreate.ts @@ -1,7 +1,9 @@ -import { ValidationError } from 'xrpl-local/common/errors' -import { verifyTicketCreate } from './../../src/models/transactions/ticketCreate' import { assert } from 'chai' + +import { ValidationError } from 'xrpl-local/common/errors' + import { verify } from '../../src/models/transactions' +import { verifyTicketCreate } from '../../src/models/transactions/ticketCreate' /** * TicketCreate Transaction Verification Testing. diff --git a/test/models/trustSet.ts b/test/models/trustSet.ts index a62a8255..bf3c2396 100644 --- a/test/models/trustSet.ts +++ b/test/models/trustSet.ts @@ -1,7 +1,9 @@ -import { ValidationError } from 'xrpl-local/common/errors' -import { verifyTrustSet } from './../../src/models/transactions/trustSet' import { assert } from 'chai' + +import { ValidationError } from 'xrpl-local/common/errors' + import { verify } from '../../src/models/transactions' +import { verifyTrustSet } from '../../src/models/transactions/trustSet' /** * TrustSet Transaction Verification Testing.