test: adds integration tests for rippled utility methods (#1597)

* add utility tests

* type client better

* simplify ledgerAccept
This commit is contained in:
Mayukha Vadari
2021-09-13 18:09:33 -04:00
parent b9b32eb3d2
commit fcc8977623
3 changed files with 51 additions and 12 deletions

View 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)
})
})

View File

@@ -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

View File

@@ -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