mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-20 12:15:51 +00:00
test: adds integration tests for rippled utility methods (#1597)
* add utility tests * type client better * simplify ledgerAccept
This commit is contained in:
48
test/integration/requests/utility.ts
Normal file
48
test/integration/requests/utility.ts
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
import { assert } from 'chai'
|
||||||
|
import _ from 'lodash'
|
||||||
|
import { Client } from 'xrpl-local'
|
||||||
|
|
||||||
|
import serverUrl from '../serverUrl'
|
||||||
|
import { setupClient, suiteClientSetup, teardownClient } from '../setup'
|
||||||
|
|
||||||
|
// how long before each test case times out
|
||||||
|
const TIMEOUT = 20000
|
||||||
|
|
||||||
|
describe('Utility method integration tests', function () {
|
||||||
|
this.timeout(TIMEOUT)
|
||||||
|
|
||||||
|
before(suiteClientSetup)
|
||||||
|
beforeEach(_.partial(setupClient, serverUrl))
|
||||||
|
afterEach(teardownClient)
|
||||||
|
|
||||||
|
it('ping', async function () {
|
||||||
|
const response = await (this.client as Client).request({
|
||||||
|
command: 'ping',
|
||||||
|
})
|
||||||
|
const expected = {
|
||||||
|
id: 0,
|
||||||
|
result: { role: 'admin', unlimited: true },
|
||||||
|
status: 'success',
|
||||||
|
type: 'response',
|
||||||
|
}
|
||||||
|
assert.deepEqual(response, expected)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('random', async function () {
|
||||||
|
const response = await (this.client as Client).request({
|
||||||
|
command: 'random',
|
||||||
|
})
|
||||||
|
const expected = {
|
||||||
|
id: 0,
|
||||||
|
result: {
|
||||||
|
random: '[random string of 64 bytes]',
|
||||||
|
},
|
||||||
|
status: 'success',
|
||||||
|
type: 'response',
|
||||||
|
}
|
||||||
|
assert.equal(response.id, expected.id)
|
||||||
|
assert.equal(response.status, expected.status)
|
||||||
|
assert.equal(response.type, expected.type)
|
||||||
|
assert.equal(response.result.random.length, 64)
|
||||||
|
})
|
||||||
|
})
|
||||||
@@ -11,7 +11,7 @@ export async function suiteClientSetup(this: Mocha.Context): Promise<void> {
|
|||||||
this.transactions = []
|
this.transactions = []
|
||||||
|
|
||||||
await setupClient.bind(this)(serverUrl)
|
await setupClient.bind(this)(serverUrl)
|
||||||
ledgerAccept(this.client)
|
await ledgerAccept(this.client)
|
||||||
this.newWallet = generateXAddress({ includeClassicAddress: true })
|
this.newWallet = generateXAddress({ includeClassicAddress: true })
|
||||||
// two times to give time to server to send `ledgerClosed` event
|
// two times to give time to server to send `ledgerClosed` event
|
||||||
// so getLedgerVersion will return right value
|
// so getLedgerVersion will return right value
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import _ from 'lodash'
|
|||||||
import { decode } from 'ripple-binary-codec'
|
import { decode } from 'ripple-binary-codec'
|
||||||
|
|
||||||
import { Client, SubmitResponse, Wallet } from 'xrpl-local'
|
import { Client, SubmitResponse, Wallet } from 'xrpl-local'
|
||||||
import { BaseResponse } from 'xrpl-local/models/methods/baseMethod'
|
|
||||||
import {
|
import {
|
||||||
verifyPayment,
|
verifyPayment,
|
||||||
Payment,
|
Payment,
|
||||||
@@ -18,17 +17,9 @@ import { walletAddress, walletSecret } from './wallet'
|
|||||||
const masterAccount = 'rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh'
|
const masterAccount = 'rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh'
|
||||||
const masterSecret = 'snoPBrXtMeMyMHUVTgbuqAfg1SUTb'
|
const masterSecret = 'snoPBrXtMeMyMHUVTgbuqAfg1SUTb'
|
||||||
|
|
||||||
interface LedgerAcceptResponse extends BaseResponse {
|
export async function ledgerAccept(client: Client): Promise<void> {
|
||||||
result: {
|
|
||||||
ledger_current_index: number
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function ledgerAccept(
|
|
||||||
client: Client,
|
|
||||||
): Promise<LedgerAcceptResponse> {
|
|
||||||
const request = { command: 'ledger_accept' }
|
const request = { command: 'ledger_accept' }
|
||||||
return client.connection.request(request) as Promise<LedgerAcceptResponse>
|
await client.connection.request(request)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: replace with `client.submitTransaction` once that has been merged
|
// TODO: replace with `client.submitTransaction` once that has been merged
|
||||||
|
|||||||
Reference in New Issue
Block a user