mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-04 21:15:47 +00:00
fix: remove response.status from returned object (#1698)
* remove response.status * fix unit tests * fix integration tests * remove now-unneeded helper method * fix rename
This commit is contained in:
@@ -169,6 +169,8 @@ export default class RequestManager {
|
||||
this.reject(response.id, error)
|
||||
return
|
||||
}
|
||||
// status no longer needed because error is thrown if status is not "success"
|
||||
delete response.status
|
||||
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- Must be a valid Response here
|
||||
this.resolve(response.id, response as unknown as Response)
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ interface Warning {
|
||||
|
||||
export interface BaseResponse {
|
||||
id: number | string
|
||||
status: 'success' | string
|
||||
status?: 'success' | string
|
||||
type: 'response' | string
|
||||
result: unknown
|
||||
warning?: 'load'
|
||||
|
||||
@@ -3,6 +3,16 @@ import { assert } from 'chai'
|
||||
import rippled from '../fixtures/rippled'
|
||||
import { setupClient, teardownClient } from '../setupClient'
|
||||
|
||||
async function assertDoesNotThrow(promise: Promise<unknown>): Promise<void> {
|
||||
try {
|
||||
await promise
|
||||
assert(true)
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- should be type error
|
||||
} catch (err: any) {
|
||||
assert.fail(err.message || err)
|
||||
}
|
||||
}
|
||||
|
||||
describe('Client subscription', function () {
|
||||
beforeEach(setupClient)
|
||||
afterEach(teardownClient)
|
||||
@@ -10,21 +20,17 @@ describe('Client subscription', function () {
|
||||
it('Successfully Subscribes', async function () {
|
||||
this.mockRippled.addResponse('subscribe', rippled.subscribe.success)
|
||||
|
||||
const result = await this.client.request({
|
||||
command: 'subscribe',
|
||||
})
|
||||
|
||||
assert.equal(result.status, 'success')
|
||||
await assertDoesNotThrow(this.client.request({ command: 'subscribe' }))
|
||||
})
|
||||
|
||||
it('Successfully Unsubscribes', async function () {
|
||||
this.mockRippled.addResponse('unsubscribe', rippled.unsubscribe)
|
||||
|
||||
const result = await this.client.request({
|
||||
command: 'unsubscribe',
|
||||
})
|
||||
|
||||
assert.equal(result.status, 'success')
|
||||
await assertDoesNotThrow(
|
||||
this.client.request({
|
||||
command: 'unsubscribe',
|
||||
}),
|
||||
)
|
||||
})
|
||||
|
||||
it('Emits transaction', async function (done) {
|
||||
|
||||
@@ -29,7 +29,7 @@ export * from './requests/ledgerClosed'
|
||||
export * from './requests/ledgerCurrent'
|
||||
export * from './requests/ledgerData'
|
||||
export * from './requests/ledgerEntry'
|
||||
export * from './requests/multisign'
|
||||
export * from './requests/submitMultisigned'
|
||||
export * from './requests/noRippleCheck'
|
||||
export * from './requests/pathFind'
|
||||
export * from './requests/ripplePathFind'
|
||||
|
||||
@@ -33,10 +33,8 @@ describe('account_channels', function () {
|
||||
ledger_index: 150,
|
||||
validated: true,
|
||||
},
|
||||
status: 'success',
|
||||
type: 'response',
|
||||
}
|
||||
assert.equal(response.status, expected.status)
|
||||
assert.equal(response.type, expected.type)
|
||||
assert.equal(typeof response.result.ledger_hash, 'string')
|
||||
assert.equal(typeof response.result.ledger_index, 'number')
|
||||
|
||||
@@ -34,10 +34,8 @@ describe('account_currencies', function () {
|
||||
ledger_index: 150,
|
||||
validated: true,
|
||||
},
|
||||
status: 'success',
|
||||
type: 'response',
|
||||
}
|
||||
assert.equal(response.status, expected.status)
|
||||
assert.equal(response.type, expected.type)
|
||||
assert.equal(typeof response.result.ledger_hash, 'string')
|
||||
assert.equal(typeof response.result.ledger_index, 'number')
|
||||
|
||||
@@ -45,10 +45,8 @@ describe('account_info', function () {
|
||||
ledger_index: 582,
|
||||
validated: true,
|
||||
},
|
||||
status: 'success',
|
||||
type: 'response',
|
||||
}
|
||||
assert.equal(response.status, expected.status)
|
||||
assert.equal(response.type, expected.type)
|
||||
assert.equal(response.result.validated, expected.result.validated)
|
||||
assert.equal(typeof response.result.ledger_hash, 'string')
|
||||
|
||||
@@ -34,10 +34,8 @@ describe('account_lines', function () {
|
||||
lines: [],
|
||||
validated: true,
|
||||
},
|
||||
status: 'success',
|
||||
type: 'response',
|
||||
}
|
||||
assert.equal(response.status, expected.status)
|
||||
assert.equal(response.type, expected.type)
|
||||
assert.equal(typeof response.result.ledger_hash, 'string')
|
||||
assert.equal(typeof response.result.ledger_index, 'number')
|
||||
|
||||
@@ -33,10 +33,8 @@ describe('account_objects', function () {
|
||||
ledger_index: 1294,
|
||||
validated: true,
|
||||
},
|
||||
status: 'success',
|
||||
type: 'response',
|
||||
}
|
||||
assert.equal(response.status, expected.status)
|
||||
assert.equal(response.type, expected.type)
|
||||
assert.equal(typeof response.result.ledger_hash, 'string')
|
||||
assert.equal(typeof response.result.ledger_index, 'number')
|
||||
|
||||
@@ -31,10 +31,8 @@ describe('account_offers', function () {
|
||||
offers: [],
|
||||
validated: false,
|
||||
},
|
||||
status: 'success',
|
||||
type: 'response',
|
||||
}
|
||||
assert.equal(response.status, expected.status)
|
||||
assert.equal(response.type, expected.type)
|
||||
assert.equal(typeof response.result.ledger_current_index, 'number')
|
||||
assert.deepEqual(
|
||||
|
||||
@@ -50,10 +50,8 @@ describe('account_tx', function () {
|
||||
},
|
||||
],
|
||||
},
|
||||
status: 'success',
|
||||
type: 'response',
|
||||
}
|
||||
assert.equal(response.status, expected.status)
|
||||
assert.equal(response.type, expected.type)
|
||||
assert.equal(response.result.account, expected.result.account)
|
||||
assert.equal(
|
||||
|
||||
@@ -31,7 +31,6 @@ describe('book_offers', function () {
|
||||
|
||||
const expectedResponse: BookOffersResponse = {
|
||||
id: response.id,
|
||||
status: 'success',
|
||||
type: 'response',
|
||||
result: {
|
||||
ledger_current_index: response.result.ledger_current_index,
|
||||
|
||||
@@ -31,7 +31,6 @@ describe('channel_verify', function () {
|
||||
|
||||
const expectedResponse: ChannelVerifyResponse = {
|
||||
id: response.id,
|
||||
status: 'success',
|
||||
type: 'response',
|
||||
result: {
|
||||
signature_verified: response.result.signature_verified,
|
||||
|
||||
@@ -29,7 +29,6 @@ describe('deposit_authorized', function () {
|
||||
|
||||
const expectedResponse: DepositAuthorizedResponse = {
|
||||
id: response.id,
|
||||
status: 'success',
|
||||
type: 'response',
|
||||
result: {
|
||||
deposit_authorized: true,
|
||||
|
||||
@@ -42,10 +42,8 @@ describe('fee', function () {
|
||||
},
|
||||
max_queue_size: '20000',
|
||||
},
|
||||
status: 'success',
|
||||
type: 'response',
|
||||
}
|
||||
assert.equal(response.status, expected.status)
|
||||
assert.equal(response.type, expected.type)
|
||||
assert.equal(typeof response.result.ledger_current_index, 'number')
|
||||
assert.deepEqual(
|
||||
|
||||
@@ -33,10 +33,8 @@ describe('gateway_balances', function () {
|
||||
ledger_index: 1294,
|
||||
validated: true,
|
||||
},
|
||||
status: 'success',
|
||||
type: 'response',
|
||||
}
|
||||
assert.equal(response.status, expected.status)
|
||||
assert.equal(response.type, expected.type)
|
||||
assert.equal(typeof response.result.ledger_hash, 'string')
|
||||
assert.equal(typeof response.result.ledger_index, 'number')
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import { assert } from 'chai'
|
||||
import _ from 'lodash'
|
||||
|
||||
import { LedgerRequest } from 'xrpl-local'
|
||||
import { LedgerRequest, LedgerResponse } from 'xrpl-local'
|
||||
import { Ledger } from 'xrpl-local/models/ledger'
|
||||
|
||||
import serverUrl from '../serverUrl'
|
||||
import { setupClient, suiteClientSetup, teardownClient } from '../setup'
|
||||
import { verifySuccessfulResponse } from '../utils'
|
||||
|
||||
// how long before each test case times out
|
||||
const TIMEOUT = 20000
|
||||
@@ -23,9 +23,55 @@ describe('ledger', function () {
|
||||
ledger_index: 'validated',
|
||||
}
|
||||
|
||||
const ledgerResponse = await this.client.request(ledgerRequest)
|
||||
const expected = {
|
||||
id: 0,
|
||||
result: {
|
||||
ledger: {
|
||||
accepted: true,
|
||||
account_hash: 'string',
|
||||
close_flags: 0,
|
||||
close_time: 0,
|
||||
close_time_human: 'string',
|
||||
},
|
||||
ledger_hash: 'string',
|
||||
ledger_index: 1,
|
||||
validated: true,
|
||||
},
|
||||
type: 'response',
|
||||
}
|
||||
|
||||
verifySuccessfulResponse(ledgerResponse)
|
||||
assert(ledgerResponse.result.validated)
|
||||
const ledgerResponse: LedgerResponse = await this.client.request(
|
||||
ledgerRequest,
|
||||
)
|
||||
|
||||
assert.equal(ledgerResponse.type, expected.type)
|
||||
|
||||
assert.equal(ledgerResponse.result.validated, expected.result.validated)
|
||||
assert.typeOf(ledgerResponse.result.ledger_hash, 'string')
|
||||
assert.typeOf(ledgerResponse.result.ledger_index, 'number')
|
||||
|
||||
const ledger = ledgerResponse.result.ledger as Ledger & {
|
||||
accepted: boolean
|
||||
hash: string
|
||||
seqNum: string
|
||||
}
|
||||
assert.equal(ledger.closed, true)
|
||||
const stringTypes = [
|
||||
'account_hash',
|
||||
'close_time_human',
|
||||
'ledger_hash',
|
||||
'ledger_index',
|
||||
'parent_hash',
|
||||
'total_coins',
|
||||
'transaction_hash',
|
||||
]
|
||||
stringTypes.forEach((strType) => assert.typeOf(ledger[strType], 'string'))
|
||||
const numTypes = [
|
||||
'close_flags',
|
||||
'close_time',
|
||||
'close_time_resolution',
|
||||
'parent_close_time',
|
||||
]
|
||||
numTypes.forEach((numType) => assert.typeOf(ledger[numType], 'number'))
|
||||
})
|
||||
})
|
||||
|
||||
@@ -5,7 +5,6 @@ import { LedgerClosedRequest, LedgerClosedResponse } from 'xrpl-local'
|
||||
|
||||
import serverUrl from '../serverUrl'
|
||||
import { setupClient, suiteClientSetup, teardownClient } from '../setup'
|
||||
import { verifySuccessfulResponse } from '../utils'
|
||||
|
||||
// how long before each test case times out
|
||||
const TIMEOUT = 20000
|
||||
@@ -24,17 +23,16 @@ describe('ledger_closed', function () {
|
||||
const ledgerClosedResponse: LedgerClosedResponse =
|
||||
await this.client.request(ledgerClosedRequest)
|
||||
|
||||
verifySuccessfulResponse(ledgerClosedResponse)
|
||||
|
||||
const expectedResponse: LedgerClosedResponse = {
|
||||
id: ledgerClosedResponse.id,
|
||||
status: 'success',
|
||||
type: 'response',
|
||||
result: {
|
||||
ledger_hash: ledgerClosedResponse.result.ledger_hash,
|
||||
ledger_index: ledgerClosedResponse.result.ledger_index,
|
||||
ledger_hash: 'string',
|
||||
ledger_index: 1,
|
||||
},
|
||||
}
|
||||
assert.deepEqual(ledgerClosedResponse, expectedResponse)
|
||||
assert.equal(ledgerClosedResponse.type, expectedResponse.type)
|
||||
assert.typeOf(ledgerClosedResponse.result.ledger_hash, 'string')
|
||||
assert.typeOf(ledgerClosedResponse.result.ledger_index, 'number')
|
||||
})
|
||||
})
|
||||
|
||||
@@ -5,7 +5,6 @@ import { LedgerCurrentResponse, LedgerCurrentRequest } from 'xrpl-local'
|
||||
|
||||
import serverUrl from '../serverUrl'
|
||||
import { setupClient, suiteClientSetup, teardownClient } from '../setup'
|
||||
import { verifySuccessfulResponse } from '../utils'
|
||||
|
||||
// how long before each test case times out
|
||||
const TIMEOUT = 20000
|
||||
@@ -26,16 +25,14 @@ describe('ledger_current', function () {
|
||||
ledgerCurrentRequest,
|
||||
)
|
||||
|
||||
verifySuccessfulResponse(ledgerCurrentResponse)
|
||||
|
||||
const expectedResponse: LedgerCurrentResponse = {
|
||||
id: ledgerCurrentResponse.id,
|
||||
status: 'success',
|
||||
type: 'response',
|
||||
result: {
|
||||
ledger_current_index: ledgerCurrentResponse.result.ledger_current_index,
|
||||
ledger_current_index: 1,
|
||||
},
|
||||
}
|
||||
assert.deepEqual(ledgerCurrentResponse, expectedResponse)
|
||||
assert.equal(ledgerCurrentResponse.type, expectedResponse.type)
|
||||
assert.typeOf(ledgerCurrentResponse.result.ledger_current_index, 'number')
|
||||
})
|
||||
})
|
||||
|
||||
@@ -5,7 +5,6 @@ import { LedgerDataRequest } from 'xrpl-local'
|
||||
|
||||
import serverUrl from '../serverUrl'
|
||||
import { setupClient, suiteClientSetup, teardownClient } from '../setup'
|
||||
import { verifySuccessfulResponse } from '../utils'
|
||||
|
||||
// how long before each test case times out
|
||||
const TIMEOUT = 20000
|
||||
@@ -21,15 +20,38 @@ describe('ledger_data', function () {
|
||||
const ledgerDataRequest: LedgerDataRequest = {
|
||||
command: 'ledger_data',
|
||||
ledger_index: 'validated',
|
||||
limit: 5,
|
||||
binary: true,
|
||||
}
|
||||
|
||||
const ledgerDataResponse = await this.client.request(ledgerDataRequest)
|
||||
|
||||
verifySuccessfulResponse(ledgerDataResponse)
|
||||
const expected = {
|
||||
id: 0,
|
||||
result: {
|
||||
ledger_hash: 'string',
|
||||
ledger_index: 0,
|
||||
marker: 'string',
|
||||
state: [
|
||||
{
|
||||
data: 'string',
|
||||
index: 'string',
|
||||
},
|
||||
],
|
||||
},
|
||||
type: 'response',
|
||||
}
|
||||
|
||||
assert.equal(ledgerDataResponse.result.validated, true)
|
||||
assert(ledgerDataResponse.result.state.length > 0)
|
||||
assert.equal(ledgerDataResponse.status, 'success')
|
||||
assert.equal(ledgerDataResponse.type, 'response')
|
||||
assert.equal(ledgerDataResponse.type, expected.type)
|
||||
|
||||
assert.typeOf(ledgerDataResponse.result.ledger_hash, 'string')
|
||||
assert.typeOf(ledgerDataResponse.result.ledger_index, 'number')
|
||||
assert.typeOf(ledgerDataResponse.result.marker, 'string')
|
||||
|
||||
assert.equal(ledgerDataResponse.result.state.length, 5)
|
||||
ledgerDataResponse.result.state.forEach((item) => {
|
||||
assert.typeOf(item.data, 'string')
|
||||
assert.typeOf(item.index, 'string')
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -5,7 +5,6 @@ import { LedgerEntryRequest, LedgerEntryResponse } from 'xrpl-local'
|
||||
|
||||
import serverUrl from '../serverUrl'
|
||||
import { setupClient, suiteClientSetup, teardownClient } from '../setup'
|
||||
import { verifySuccessfulResponse } from '../utils'
|
||||
|
||||
// how long before each test case times out
|
||||
const TIMEOUT = 20000
|
||||
@@ -23,7 +22,7 @@ describe('ledger_entry', function () {
|
||||
ledger_index: 'validated',
|
||||
})
|
||||
|
||||
verifySuccessfulResponse(validatedLedgerResponse)
|
||||
assert.equal(validatedLedgerResponse.type, 'response')
|
||||
const ledgerEntryIndex = validatedLedgerResponse.result.state[0].index
|
||||
|
||||
const ledgerEntryRequest: LedgerEntryRequest = {
|
||||
@@ -35,7 +34,6 @@ describe('ledger_entry', function () {
|
||||
|
||||
const expectedResponse: LedgerEntryResponse = {
|
||||
id: ledgerEntryResponse.id,
|
||||
status: 'success',
|
||||
type: 'response',
|
||||
result: {
|
||||
index: ledgerEntryIndex,
|
||||
@@ -45,7 +43,7 @@ describe('ledger_entry', function () {
|
||||
},
|
||||
}
|
||||
|
||||
verifySuccessfulResponse(ledgerEntryResponse)
|
||||
assert.equal(ledgerEntryResponse.type, 'response')
|
||||
assert.deepEqual(ledgerEntryResponse, expectedResponse)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -41,10 +41,8 @@ describe('noripple_check', function () {
|
||||
],
|
||||
validated: false,
|
||||
},
|
||||
status: 'success',
|
||||
type: 'response',
|
||||
}
|
||||
assert.equal(response.status, expected.status)
|
||||
assert.equal(response.type, expected.type)
|
||||
assert.equal(typeof response.result.transactions[0].Fee, 'number')
|
||||
assert.equal(typeof response.result.transactions[0].Sequence, 'number')
|
||||
|
||||
@@ -31,7 +31,6 @@ describe('path_find', function () {
|
||||
|
||||
const expectedResponse: PathFindResponse = {
|
||||
id: response.id,
|
||||
status: 'success',
|
||||
type: 'response',
|
||||
result: {
|
||||
alternatives: response.result.alternatives,
|
||||
|
||||
@@ -31,7 +31,6 @@ describe('ripple_path_find', function () {
|
||||
|
||||
const expectedResponse: RipplePathFindResponse = {
|
||||
id: response.id,
|
||||
status: 'success',
|
||||
type: 'response',
|
||||
result: {
|
||||
alternatives: response.result.alternatives,
|
||||
|
||||
@@ -79,10 +79,8 @@ describe('server_info', function () {
|
||||
},
|
||||
},
|
||||
},
|
||||
status: 'success',
|
||||
type: 'response',
|
||||
}
|
||||
assert.equal(response.status, expected.status)
|
||||
assert.equal(response.type, expected.type)
|
||||
|
||||
assert.equal(typeof response.result.info.time, 'string')
|
||||
|
||||
@@ -82,10 +82,8 @@ describe('server_state', function () {
|
||||
validator_list_expires: 0,
|
||||
},
|
||||
},
|
||||
status: 'success',
|
||||
type: 'response',
|
||||
}
|
||||
assert.equal(response.status, expected.status)
|
||||
assert.equal(response.type, expected.type)
|
||||
|
||||
assert.equal(typeof response.result.state.complete_ledgers, 'string')
|
||||
|
||||
@@ -39,7 +39,6 @@ describe('submit', function () {
|
||||
tx_blob: signedTx,
|
||||
}
|
||||
const submitResponse = await this.client.request(submitRequest)
|
||||
assert.equal(submitResponse.status, 'success')
|
||||
|
||||
await ledgerAccept(this.client)
|
||||
await verifySubmittedTransaction(this.client, signedTx)
|
||||
@@ -47,7 +46,6 @@ describe('submit', function () {
|
||||
const expectedResponse: SubmitResponse = {
|
||||
id: submitResponse.id,
|
||||
type: 'response',
|
||||
status: 'success',
|
||||
result: {
|
||||
engine_result: 'tesSUCCESS',
|
||||
engine_result_code: 0,
|
||||
|
||||
@@ -81,7 +81,6 @@ describe('submit_multisigned', function () {
|
||||
|
||||
const expectedResponse: SubmitMultisignedResponse = {
|
||||
id: submitResponse.id,
|
||||
status: 'success',
|
||||
type: 'response',
|
||||
result: {
|
||||
engine_result: 'tesSUCCESS',
|
||||
@@ -44,7 +44,6 @@ describe('tx', function () {
|
||||
const expectedResponse: TxResponse = {
|
||||
id: txResponse.id,
|
||||
type: 'response',
|
||||
status: 'success',
|
||||
result: {
|
||||
...accountSet,
|
||||
Fee: txResponse.result.Fee,
|
||||
|
||||
@@ -23,7 +23,6 @@ describe('Utility method integration tests', function () {
|
||||
const expected = {
|
||||
id: 0,
|
||||
result: { role: 'admin', unlimited: true },
|
||||
status: 'success',
|
||||
type: 'response',
|
||||
}
|
||||
assert.deepEqual(_.omit(response, 'id'), _.omit(expected, 'id'))
|
||||
@@ -38,10 +37,8 @@ describe('Utility method integration tests', function () {
|
||||
result: {
|
||||
random: '[random string of 64 bytes]',
|
||||
},
|
||||
status: 'success',
|
||||
type: 'response',
|
||||
}
|
||||
assert.equal(response.status, expected.status)
|
||||
assert.equal(response.type, expected.type)
|
||||
assert.equal(response.result.random.length, 64)
|
||||
})
|
||||
|
||||
@@ -2,7 +2,7 @@ import { assert } from 'chai'
|
||||
import _ from 'lodash'
|
||||
import { decode } from 'ripple-binary-codec'
|
||||
|
||||
import { Client, Wallet, Response, AccountInfoRequest } from 'xrpl-local'
|
||||
import { Client, Wallet, AccountInfoRequest } from 'xrpl-local'
|
||||
import { Payment, Transaction } from 'xrpl-local/models/transactions'
|
||||
import { computeSignedTransactionHash } from 'xrpl-local/utils/hashes'
|
||||
|
||||
@@ -73,11 +73,6 @@ export async function verifySubmittedTransaction(
|
||||
}
|
||||
}
|
||||
|
||||
export function verifySuccessfulResponse(response: Response): void {
|
||||
assert.equal(response.status, 'success')
|
||||
assert.equal(response.type, 'response')
|
||||
}
|
||||
|
||||
export async function testTransaction(
|
||||
client: Client,
|
||||
transaction: Transaction,
|
||||
@@ -90,7 +85,6 @@ export async function testTransaction(
|
||||
const response = await client.submitTransaction(wallet, transaction)
|
||||
|
||||
// check that the transaction was successful
|
||||
assert.equal(response.status, 'success')
|
||||
assert.equal(response.type, 'response')
|
||||
assert.equal(
|
||||
response.result.engine_result,
|
||||
|
||||
Reference in New Issue
Block a user