refactor: moves fixtures closer to tests (#1551)

* modify account_info mocks

* move account_objects

* move server_info

* remove config (no longer needed)

* switch to simple dictionary instead of handlers

* fix rebase issues

* refactor: addResponse method on mock server object (#1555)

Co-authored-by: Elliot Lee <github.public@intelliot.com>
This commit is contained in:
Mayukha Vadari
2021-08-24 10:49:16 -04:00
parent 221ebee87a
commit 0b457b3769
27 changed files with 455 additions and 334 deletions

View File

@@ -2,6 +2,7 @@ import _ from 'lodash'
import assert from 'assert-diff'
import setupClient from './setup-client'
import responses from './fixtures/responses'
import rippled from './fixtures/rippled'
import {ignoreWebSocketDisconnect} from './utils'
const TIMEOUT = 20000
@@ -21,6 +22,9 @@ describe('BroadcastClient', function () {
afterEach(setupClient.teardown)
it('base', function () {
this.mocks.forEach((mock) => {
mock.addResponse({command: 'server_info'}, rippled.server_info.normal)
})
const expected = {request_server_info: 1}
this.mocks.forEach((mock) => mock.expect(Object.assign({}, expected)))
assert(this.client.isConnected())

View File

@@ -1,4 +1,5 @@
import assert from 'assert-diff'
import rippled from '../../fixtures/rippled'
import {TestSuite} from '../../utils'
/**
@@ -7,41 +8,37 @@ import {TestSuite} from '../../utils'
* - Check out "test/client/index.ts" for more information about the test runner.
*/
export default <TestSuite>{
'getFee': async (client, address) => {
'getFee': async (client, address, mockRippled) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
const fee = await client.getFee()
assert.strictEqual(fee, '0.000012')
},
'getFee default': async (client, address) => {
'getFee default': async (client, address, mockRippled) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
client._feeCushion = undefined
const fee = await client.getFee()
assert.strictEqual(fee, '0.000012')
},
'getFee - high load_factor': async (client, address) => {
client.connection.request({
// @ts-ignore TODO: resolve
command: 'config',
data: {highLoadFactor: true}
})
'getFee - high load_factor': async (client, address, mockRippled) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.highLoadFactor)
const fee = await client.getFee()
assert.strictEqual(fee, '2')
},
'getFee - high load_factor with custom maxFeeXRP': async (client, address) => {
'getFee - high load_factor with custom maxFeeXRP': async (client, address, mockRippled) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.highLoadFactor)
// Ensure that overriding with high maxFeeXRP of '51540' causes no errors.
// (fee will actually be 51539.607552)
client._maxFeeXRP = '51540'
client.connection.request({
// @ts-ignore TODO: resolve
command: 'config',
data: {highLoadFactor: true}
})
const fee = await client.getFee()
assert.strictEqual(fee, '51539.607552')
},
'getFee custom cushion': async (client, address) => {
'getFee custom cushion': async (client, address, mockRippled) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
client._feeCushion = 1.4
const fee = await client.getFee()
assert.strictEqual(fee, '0.000014')
@@ -49,18 +46,15 @@ export default <TestSuite>{
// This is not recommended since it may result in attempting to pay
// less than the base fee. However, this test verifies the existing behavior.
'getFee cushion less than 1.0': async (client, address) => {
'getFee cushion less than 1.0': async (client, address, mockRippled) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
client._feeCushion = 0.9
const fee = await client.getFee()
assert.strictEqual(fee, '0.000009')
},
'getFee reporting': async (client, address) => {
client.connection.request({
// @ts-ignore TODO: resolve
command: 'config',
data: {reporting: true}
})
'getFee reporting': async (client, address, mockRippled) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
const fee = await client.getFee()
assert.strictEqual(fee, '0.000012')
}

View File

@@ -1,5 +1,6 @@
import requests from '../../fixtures/requests'
import responses from '../../fixtures/responses'
import rippled from '../../fixtures/rippled'
import {assertResultMatch, TestSuite} from '../../utils'
const instructionsWithMaxLedgerVersionOffset = {maxLedgerVersionOffset: 100}
@@ -9,7 +10,8 @@ const instructionsWithMaxLedgerVersionOffset = {maxLedgerVersionOffset: 100}
* - Check out "test/client/index.ts" for more information about the test runner.
*/
export default <TestSuite>{
'prepareCheckCancel': async (client, address) => {
'prepareCheckCancel': async (client, address, mockRippled) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
const result = await client.prepareCheckCancel(
address,
requests.prepareCheckCancel.normal
@@ -17,7 +19,8 @@ export default <TestSuite>{
assertResultMatch(result, responses.prepareCheckCancel.normal, 'prepare')
},
'with ticket': async (client, address) => {
'with ticket': async (client, address, mockRippled) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
const localInstructions = {
...instructionsWithMaxLedgerVersionOffset,
maxFee: '0.000012',

View File

@@ -1,5 +1,6 @@
import requests from '../../fixtures/requests'
import responses from '../../fixtures/responses'
import rippled from '../../fixtures/rippled'
import {assertResultMatch, TestSuite} from '../../utils'
const instructionsWithMaxLedgerVersionOffset = {maxLedgerVersionOffset: 100}
@@ -9,7 +10,8 @@ const instructionsWithMaxLedgerVersionOffset = {maxLedgerVersionOffset: 100}
* - Check out "test/client/index.ts" for more information about the test runner.
*/
export default <TestSuite>{
'prepareCheckCash amount': async (client, address) => {
'prepareCheckCash amount': async (client, address, mockRippled) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
const result = await client.prepareCheckCash(
address,
requests.prepareCheckCash.amount
@@ -17,7 +19,8 @@ export default <TestSuite>{
assertResultMatch(result, responses.prepareCheckCash.amount, 'prepare')
},
'prepareCheckCash deliverMin': async (client, address) => {
'prepareCheckCash deliverMin': async (client, address, mockRippled) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
const result = await client.prepareCheckCash(
address,
requests.prepareCheckCash.deliverMin
@@ -25,7 +28,8 @@ export default <TestSuite>{
assertResultMatch(result, responses.prepareCheckCash.deliverMin, 'prepare')
},
'with ticket': async (client, address) => {
'with ticket': async (client, address, mockRippled) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
const localInstructions = {
...instructionsWithMaxLedgerVersionOffset,
maxFee: '0.000012',

View File

@@ -1,5 +1,6 @@
import requests from '../../fixtures/requests'
import responses from '../../fixtures/responses'
import rippled from '../../fixtures/rippled'
import {assertResultMatch, TestSuite} from '../../utils'
const instructionsWithMaxLedgerVersionOffset = {maxLedgerVersionOffset: 100}
@@ -9,7 +10,8 @@ const instructionsWithMaxLedgerVersionOffset = {maxLedgerVersionOffset: 100}
* - Check out "test/client/index.ts" for more information about the test runner.
*/
export default <TestSuite>{
'prepareCheckCreate': async (client, address) => {
'prepareCheckCreate': async (client, address, mockRippled) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
const localInstructions = {
...instructionsWithMaxLedgerVersionOffset,
maxFee: '0.000012'
@@ -22,7 +24,8 @@ export default <TestSuite>{
assertResultMatch(result, responses.prepareCheckCreate.normal, 'prepare')
},
'prepareCheckCreate full': async (client, address) => {
'prepareCheckCreate full': async (client, address, mockRippled) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
const result = await client.prepareCheckCreate(
address,
requests.prepareCheckCreate.full
@@ -30,7 +33,8 @@ export default <TestSuite>{
assertResultMatch(result, responses.prepareCheckCreate.full, 'prepare')
},
'prepareCheckCreate with ticket': async (client, address) => {
'prepareCheckCreate with ticket': async (client, address, mockRippled) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
const localInstructions = {
...instructionsWithMaxLedgerVersionOffset,
maxFee: '0.000012',

View File

@@ -1,5 +1,6 @@
import requests from '../../fixtures/requests'
import responses from '../../fixtures/responses'
import rippled from '../../fixtures/rippled'
import {assertResultMatch, TestSuite} from '../../utils'
const instructionsWithMaxLedgerVersionOffset = {maxLedgerVersionOffset: 100}
@@ -9,7 +10,8 @@ const instructionsWithMaxLedgerVersionOffset = {maxLedgerVersionOffset: 100}
* - Check out "test/client/index.ts" for more information about the test runner.
*/
export default <TestSuite>{
'prepareEscrowCancellation': async (client, address) => {
'prepareEscrowCancellation': async (client, address, mockRippled) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
const result = await client.prepareEscrowCancellation(
address,
requests.prepareEscrowCancellation.normal,
@@ -22,7 +24,8 @@ export default <TestSuite>{
)
},
'prepareEscrowCancellation with memos': async (client, address) => {
'prepareEscrowCancellation with memos': async (client, address, mockRippled) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
const result = await client.prepareEscrowCancellation(
address,
requests.prepareEscrowCancellation.memos
@@ -34,7 +37,8 @@ export default <TestSuite>{
)
},
'with ticket': async (client, address) => {
'with ticket': async (client, address, mockRippled) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
const localInstructions = {
...instructionsWithMaxLedgerVersionOffset,
maxFee: '0.000012',

View File

@@ -1,5 +1,6 @@
import requests from '../../fixtures/requests'
import responses from '../../fixtures/responses'
import rippled from '../../fixtures/rippled'
import {assertRejects, assertResultMatch, TestSuite} from '../../utils'
const instructionsWithMaxLedgerVersionOffset = {maxLedgerVersionOffset: 100}
@@ -16,7 +17,8 @@ export const config = {
* - Check out "test/client/index.ts" for more information about the test runner.
*/
export default <TestSuite>{
'prepareEscrowCreation': async (client, address) => {
'prepareEscrowCreation': async (client, address, mockRippled) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
const localInstructions = {
...instructionsWithMaxLedgerVersionOffset,
maxFee: '0.000012'
@@ -29,7 +31,8 @@ export default <TestSuite>{
assertResultMatch(result, responses.prepareEscrowCreation.normal, 'prepare')
},
'prepareEscrowCreation full': async (client, address) => {
'prepareEscrowCreation full': async (client, address, mockRippled) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
const result = await client.prepareEscrowCreation(
address,
requests.prepareEscrowCreation.full
@@ -37,7 +40,8 @@ export default <TestSuite>{
assertResultMatch(result, responses.prepareEscrowCreation.full, 'prepare')
},
'prepareEscrowCreation - invalid': async (client, address) => {
'prepareEscrowCreation - invalid': async (client, address, mockRippled) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
const escrow = Object.assign({}, requests.prepareEscrowCreation.full)
delete escrow.amount // Make invalid
await assertRejects(
@@ -47,7 +51,8 @@ export default <TestSuite>{
)
},
'with ticket': async (client, address) => {
'with ticket': async (client, address, mockRippled) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
const localInstructions = {
...instructionsWithMaxLedgerVersionOffset,
maxFee: '0.000396',

View File

@@ -1,6 +1,7 @@
import {TestSuite, assertRejects, assertResultMatch} from '../../utils'
import requests from '../../fixtures/requests'
import responses from '../../fixtures/responses'
import rippled from '../../fixtures/rippled'
const instructionsWithMaxLedgerVersionOffset = {maxLedgerVersionOffset: 100}
/**
@@ -9,7 +10,8 @@ const instructionsWithMaxLedgerVersionOffset = {maxLedgerVersionOffset: 100}
* - Check out "test/client/index.ts" for more information about the test runner.
*/
export default <TestSuite>{
'prepareEscrowExecution': async (client, address) => {
'prepareEscrowExecution': async (client, address, mockRippled) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
const result = await client.prepareEscrowExecution(
address,
requests.prepareEscrowExecution.normal,
@@ -22,7 +24,8 @@ export default <TestSuite>{
)
},
'prepareEscrowExecution - simple': async (client, address) => {
'prepareEscrowExecution - simple': async (client, address, mockRippled) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
const result = await client.prepareEscrowExecution(
address,
requests.prepareEscrowExecution.simple
@@ -34,7 +37,8 @@ export default <TestSuite>{
)
},
'prepareEscrowExecution - no condition': async (client, address) => {
'prepareEscrowExecution - no condition': async (client, address, mockRippled) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
await assertRejects(
client.prepareEscrowExecution(
address,
@@ -46,7 +50,8 @@ export default <TestSuite>{
)
},
'prepareEscrowExecution - no fulfillment': async (client, address) => {
'prepareEscrowExecution - no fulfillment': async (client, address, mockRippled) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
await assertRejects(
client.prepareEscrowExecution(
address,
@@ -58,7 +63,8 @@ export default <TestSuite>{
)
},
'with ticket': async (client, address) => {
'with ticket': async (client, address, mockRippled) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
const localInstructions = {
...instructionsWithMaxLedgerVersionOffset,
maxFee: '0.000396',

View File

@@ -1,5 +1,6 @@
import requests from '../../fixtures/requests'
import responses from '../../fixtures/responses'
import rippled from '../../fixtures/rippled'
import {assertRejects, assertResultMatch, TestSuite} from '../../utils'
const instructionsWithMaxLedgerVersionOffset = {maxLedgerVersionOffset: 100}
@@ -9,13 +10,15 @@ const instructionsWithMaxLedgerVersionOffset = {maxLedgerVersionOffset: 100}
* - Check out "test/client/index.ts" for more information about the test runner.
*/
export default <TestSuite>{
'buy order': async (client, address) => {
'buy order': async (client, address, mockRippled) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
const request = requests.prepareOrder.buy
const result = await client.prepareOrder(address, request)
assertResultMatch(result, responses.prepareOrder.buy, 'prepare')
},
'buy order with expiration': async (client, address) => {
'buy order with expiration': async (client, address, mockRippled) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
const request = requests.prepareOrder.expiration
const response = responses.prepareOrder.expiration
const result = await client.prepareOrder(
@@ -26,7 +29,8 @@ export default <TestSuite>{
assertResultMatch(result, response, 'prepare')
},
'sell order': async (client, address) => {
'sell order': async (client, address, mockRippled) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
const request = requests.prepareOrder.sell
const result = await client.prepareOrder(
address,
@@ -36,7 +40,8 @@ export default <TestSuite>{
assertResultMatch(result, responses.prepareOrder.sell, 'prepare')
},
'invalid': async (client, address) => {
'invalid': async (client, address, mockRippled) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
const request = Object.assign({}, requests.prepareOrder.sell)
delete request.direction // Make invalid
await assertRejects(
@@ -50,7 +55,8 @@ export default <TestSuite>{
)
},
'with ticket': async (client, address) => {
'with ticket': async (client, address, mockRippled) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
const request = requests.prepareOrder.sell
const localInstructions = {
...instructionsWithMaxLedgerVersionOffset,

View File

@@ -1,5 +1,6 @@
import requests from '../../fixtures/requests'
import responses from '../../fixtures/responses'
import rippled from '../../fixtures/rippled'
import {assertRejects, assertResultMatch, TestSuite} from '../../utils'
const instructionsWithMaxLedgerVersionOffset = {maxLedgerVersionOffset: 100}
@@ -9,7 +10,8 @@ const instructionsWithMaxLedgerVersionOffset = {maxLedgerVersionOffset: 100}
* - Check out "test/client/index.ts" for more information about the test runner.
*/
export default <TestSuite>{
'prepareOrderCancellation': async (client, address) => {
'prepareOrderCancellation': async (client, address, mockRippled) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
const request = requests.prepareOrderCancellation.simple
const result = await client.prepareOrderCancellation(
address,
@@ -23,7 +25,8 @@ export default <TestSuite>{
)
},
'no instructions': async (client, address) => {
'no instructions': async (client, address, mockRippled) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
const request = requests.prepareOrderCancellation.simple
const result = await client.prepareOrderCancellation(address, request)
assertResultMatch(
@@ -33,7 +36,8 @@ export default <TestSuite>{
)
},
'with memos': async (client, address) => {
'with memos': async (client, address, mockRippled) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
const request = requests.prepareOrderCancellation.withMemos
const result = await client.prepareOrderCancellation(address, request)
assertResultMatch(
@@ -43,7 +47,8 @@ export default <TestSuite>{
)
},
'invalid': async (client, address) => {
'invalid': async (client, address, mockRippled) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
const request = Object.assign(
{},
requests.prepareOrderCancellation.withMemos
@@ -57,7 +62,8 @@ export default <TestSuite>{
)
},
'with ticket': async (client, address) => {
'with ticket': async (client, address, mockRippled) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
const request = requests.prepareOrderCancellation.simple
const localInstructions = {
...instructionsWithMaxLedgerVersionOffset,

View File

@@ -1,5 +1,6 @@
import {assertResultMatch, TestSuite, assertRejects} from '../../utils'
import responses from '../../fixtures/responses'
import rippled from '../../fixtures/rippled'
import requests from '../../fixtures/requests'
import {ValidationError} from 'xrpl-local/common/errors'
import binary from 'ripple-binary-codec'
@@ -18,7 +19,8 @@ const RECIPIENT_ADDRESS = 'rpZc4mVfWUif9CRoHRKKcmhu1nx2xktxBo'
* - Check out "test/client/index.ts" for more information about the test runner.
*/
export default <TestSuite>{
'normal': async (client, address) => {
'normal': async (client, address, mockRippled) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
const localInstructions = {
...instructionsWithMaxLedgerVersionOffset,
maxFee: '0.000012'
@@ -31,7 +33,8 @@ export default <TestSuite>{
assertResultMatch(response, RESPONSE_FIXTURES.normal, 'prepare')
},
'min amount xrp': async (client, address) => {
'min amount xrp': async (client, address, mockRippled) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
const localInstructions = {
...instructionsWithMaxLedgerVersionOffset,
maxFee: '0.000012'
@@ -44,7 +47,8 @@ export default <TestSuite>{
assertResultMatch(response, RESPONSE_FIXTURES.minAmountXRP, 'prepare')
},
'min amount xrp2xrp': async (client, address) => {
'min amount xrp2xrp': async (client, address, mockRippled) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
const response = await client.preparePayment(
address,
REQUEST_FIXTURES.minAmount,
@@ -53,7 +57,8 @@ export default <TestSuite>{
assertResultMatch(response, RESPONSE_FIXTURES.minAmountXRPXRP, 'prepare')
},
'XRP to XRP': async (client, address) => {
'XRP to XRP': async (client, address, mockRippled) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
const payment = {
source: {
address: 'r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59',
@@ -81,7 +86,8 @@ export default <TestSuite>{
assertResultMatch(response, expected, 'prepare')
},
'XRP drops to XRP drops': async (client, address) => {
'XRP drops to XRP drops': async (client, address, mockRippled) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
const payment = {
source: {
address: 'r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59',
@@ -109,7 +115,8 @@ export default <TestSuite>{
assertResultMatch(response, expected, 'prepare')
},
'XRP drops to XRP': async (client, address) => {
'XRP drops to XRP': async (client, address, mockRippled) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
const payment = {
source: {
address: 'r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59',
@@ -137,7 +144,8 @@ export default <TestSuite>{
assertResultMatch(response, expected, 'prepare')
},
'XRP to XRP drops': async (client, address) => {
'XRP to XRP drops': async (client, address, mockRippled) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
const payment = {
source: {
address: 'r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59',
@@ -168,8 +176,10 @@ export default <TestSuite>{
// Errors
'rejects promise and does not throw when payment object is invalid': async (
client,
address
address,
mockRippled
) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
const payment = {
source: {
address: address,
@@ -191,8 +201,10 @@ export default <TestSuite>{
'rejects promise and does not throw when field is missing': async (
client,
address
address,
mockRippled
) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
// Marking as "any" to get around the fact that TS won't allow this.
const payment: any = {
source: {address: address},
@@ -211,8 +223,10 @@ export default <TestSuite>{
'rejects promise and does not throw when fee exceeds maxFeeXRP': async (
client,
address
address,
mockRippled
) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
const payment = {
source: {
address: address,
@@ -230,7 +244,8 @@ export default <TestSuite>{
)
},
'XRP to XRP no partial': async (client, address) => {
'XRP to XRP no partial': async (client, address, mockRippled) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
return assertRejects(
client.preparePayment(address, REQUEST_FIXTURES.wrongPartial),
ValidationError,
@@ -238,7 +253,8 @@ export default <TestSuite>{
)
},
'address must match payment.source.address': async (client, address) => {
'address must match payment.source.address': async (client, address, mockRippled) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
return assertRejects(
client.preparePayment(address, REQUEST_FIXTURES.wrongAddress),
ValidationError,
@@ -246,7 +262,8 @@ export default <TestSuite>{
)
},
'wrong amount': async (client, address) => {
'wrong amount': async (client, address, mockRippled) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
return assertRejects(
client.preparePayment(address, REQUEST_FIXTURES.wrongAmount),
ValidationError,
@@ -254,7 +271,8 @@ export default <TestSuite>{
)
},
'throws when fee exceeds 2 XRP': async (client, address) => {
'throws when fee exceeds 2 XRP': async (client, address, mockRippled) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
const localInstructions = {
...instructionsWithMaxLedgerVersionOffset,
fee: '2.1'
@@ -281,7 +299,8 @@ export default <TestSuite>{
// assertResultMatch(response, RESPONSE_FIXTURES.allOptions, 'prepare')
// },
'preparePayment without counterparty set': async (client, address) => {
'preparePayment without counterparty set': async (client, address, mockRippled) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
const localInstructions = {
...instructionsWithMaxLedgerVersionOffset,
sequence: 23
@@ -296,8 +315,10 @@ export default <TestSuite>{
'preparePayment with source.amount/destination.minAmount can be signed': async (
client,
address
address,
mockRippled
) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
// See also: 'sign succeeds with source.amount/destination.minAmount'
const localInstructions = {
@@ -346,7 +367,8 @@ export default <TestSuite>{
schemaValidator.schemaValidate('sign', result)
},
'destination.minAmount': async (client, address) => {
'destination.minAmount': async (client, address, mockRippled) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
const response = await client.preparePayment(
address,
responses.getPaths.sendAll[0],
@@ -355,7 +377,8 @@ export default <TestSuite>{
assertResultMatch(response, RESPONSE_FIXTURES.minAmount, 'prepare')
},
'caps fee at 2 XRP by default': async (client, address) => {
'caps fee at 2 XRP by default': async (client, address, mockRippled) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
client._feeCushion = 1000000
const expectedResponse = {
txJSON:
@@ -376,8 +399,10 @@ export default <TestSuite>{
'allows fee exceeding 2 XRP when maxFeeXRP is higher': async (
client,
address
address,
mockRippled
) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
client._maxFeeXRP = '2.2'
const localInstructions = {
...instructionsWithMaxLedgerVersionOffset,
@@ -400,7 +425,8 @@ export default <TestSuite>{
assertResultMatch(response, expectedResponse, 'prepare')
},
'fee - default maxFee of 2 XRP': async (client, address) => {
'fee - default maxFee of 2 XRP': async (client, address, mockRippled) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
client._feeCushion = 1000000
const expectedResponse = {
txJSON:
@@ -421,8 +447,10 @@ export default <TestSuite>{
'fee - capped to maxFeeXRP when maxFee exceeds maxFeeXRP': async (
client,
address
address,
mockRippled
) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
client._feeCushion = 1000000
client._maxFeeXRP = '3'
const localInstructions = {
@@ -446,7 +474,8 @@ export default <TestSuite>{
assertResultMatch(response, expectedResponse, 'prepare')
},
'fee - capped to maxFee': async (client, address) => {
'fee - capped to maxFee': async (client, address, mockRippled) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
client._feeCushion = 1000000
client._maxFeeXRP = '5'
const localInstructions = {

View File

@@ -1,6 +1,7 @@
import assert from 'assert-diff'
import requests from '../../fixtures/requests'
import responses from '../../fixtures/responses'
import rippled from '../../fixtures/rippled'
import {assertResultMatch, TestSuite} from '../../utils'
const instructionsWithMaxLedgerVersionOffset = {maxLedgerVersionOffset: 100}
const {preparePaymentChannelClaim: REQUEST_FIXTURES} = requests
@@ -12,7 +13,8 @@ const {preparePaymentChannelClaim: RESPONSE_FIXTURES} = responses
* - Check out "test/client/index.ts" for more information about the test runner.
*/
export default <TestSuite>{
'default': async (client, address) => {
'default': async (client, address, mockRippled) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
const localInstructions = {
...instructionsWithMaxLedgerVersionOffset,
maxFee: '0.000012'
@@ -25,7 +27,8 @@ export default <TestSuite>{
assertResultMatch(response, RESPONSE_FIXTURES.normal, 'prepare')
},
'with renew': async (client, address) => {
'with renew': async (client, address, mockRippled) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
const localInstructions = {
...instructionsWithMaxLedgerVersionOffset,
maxFee: '0.000012'
@@ -38,7 +41,8 @@ export default <TestSuite>{
assertResultMatch(response, RESPONSE_FIXTURES.renew, 'prepare')
},
'with close': async (client, address) => {
'with close': async (client, address, mockRippled) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
const localInstructions = {
...instructionsWithMaxLedgerVersionOffset,
maxFee: '0.000012'
@@ -51,7 +55,8 @@ export default <TestSuite>{
assertResultMatch(response, RESPONSE_FIXTURES.close, 'prepare')
},
'with ticket': async (client, address) => {
'with ticket': async (client, address, mockRippled) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
const localInstructions = {
...instructionsWithMaxLedgerVersionOffset,
maxFee: '0.000012',
@@ -67,8 +72,10 @@ export default <TestSuite>{
'rejects Promise on preparePaymentChannelClaim with renew and close': async (
client,
address
address,
mockRippled
) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
try {
const prepared = await client.preparePaymentChannelClaim(
address,
@@ -89,8 +96,10 @@ export default <TestSuite>{
'rejects Promise on preparePaymentChannelClaim with no signature': async (
client,
address
address,
mockRippled
) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
try {
const prepared = await client.preparePaymentChannelClaim(
address,

View File

@@ -1,5 +1,6 @@
import requests from '../../fixtures/requests'
import responses from '../../fixtures/responses'
import rippled from '../../fixtures/rippled'
import {assertResultMatch, TestSuite} from '../../utils'
const instructionsWithMaxLedgerVersionOffset = {maxLedgerVersionOffset: 100}
@@ -16,7 +17,8 @@ export const config = {
* - Check out "test/client/index.ts" for more information about the test runner.
*/
export default <TestSuite>{
'preparePaymentChannelCreate': async (client, address) => {
'preparePaymentChannelCreate': async (client, address, mockRippled) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
const localInstructions = {
...instructionsWithMaxLedgerVersionOffset,
maxFee: '0.000012'
@@ -33,7 +35,8 @@ export default <TestSuite>{
)
},
'preparePaymentChannelCreate full': async (client, address) => {
'preparePaymentChannelCreate full': async (client, address, mockRippled) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
const result = await client.preparePaymentChannelCreate(
address,
requests.preparePaymentChannelCreate.full
@@ -45,7 +48,8 @@ export default <TestSuite>{
)
},
'preparePaymentChannelCreate with ticket': async (client, address) => {
'preparePaymentChannelCreate with ticket': async (client, address, mockRippled) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
const localInstructions = {
...instructionsWithMaxLedgerVersionOffset,
maxFee: '0.000012',

View File

@@ -1,5 +1,6 @@
import requests from '../../fixtures/requests'
import responses from '../../fixtures/responses'
import rippled from '../../fixtures/rippled'
import {assertResultMatch, TestSuite} from '../../utils'
const instructionsWithMaxLedgerVersionOffset = {maxLedgerVersionOffset: 100}
@@ -9,7 +10,8 @@ const instructionsWithMaxLedgerVersionOffset = {maxLedgerVersionOffset: 100}
* - Check out "test/client/index.ts" for more information about the test runner.
*/
export default <TestSuite>{
'preparePaymentChannelFund': async (client, address) => {
'preparePaymentChannelFund': async (client, address, mockRippled) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
const localInstructions = {
...instructionsWithMaxLedgerVersionOffset,
maxFee: '0.000012'
@@ -26,7 +28,8 @@ export default <TestSuite>{
)
},
'preparePaymentChannelFund full': async (client, address) => {
'preparePaymentChannelFund full': async (client, address, mockRippled) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
const result = await client.preparePaymentChannelFund(
address,
requests.preparePaymentChannelFund.full
@@ -38,7 +41,8 @@ export default <TestSuite>{
)
},
'with ticket': async (client, address) => {
'with ticket': async (client, address, mockRippled) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
const localInstructions = {
...instructionsWithMaxLedgerVersionOffset,
maxFee: '0.000012',

View File

@@ -1,6 +1,7 @@
import assert from 'assert-diff'
import requests from '../../fixtures/requests'
import responses from '../../fixtures/responses'
import rippled from '../../fixtures/rippled'
import {assertResultMatch, TestSuite} from '../../utils'
const instructionsWithMaxLedgerVersionOffset = {maxLedgerVersionOffset: 100}
@@ -10,7 +11,8 @@ const instructionsWithMaxLedgerVersionOffset = {maxLedgerVersionOffset: 100}
* - Check out "test/client/index.ts" for more information about the test runner.
*/
export default <TestSuite>{
'simple test': async (client, address) => {
'simple test': async (client, address, mockRippled) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
const response = await client.prepareSettings(
address,
requests.prepareSettings.domain,
@@ -18,7 +20,8 @@ export default <TestSuite>{
)
assertResultMatch(response, responses.prepareSettings.flags, 'prepare')
},
'no maxLedgerVersion': async (client, address) => {
'no maxLedgerVersion': async (client, address, mockRippled) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
const response = await client.prepareSettings(
address,
requests.prepareSettings.domain,
@@ -32,7 +35,8 @@ export default <TestSuite>{
'prepare'
)
},
'no instructions': async (client, address) => {
'no instructions': async (client, address, mockRippled) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
const response = await client.prepareSettings(
address,
requests.prepareSettings.domain
@@ -43,7 +47,8 @@ export default <TestSuite>{
'prepare'
)
},
'regularKey': async (client, address) => {
'regularKey': async (client, address, mockRippled) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
const regularKey = {regularKey: 'rAR8rR8sUkBoCZFawhkWzY4Y5YoyuznwD'}
const response = await client.prepareSettings(
address,
@@ -52,7 +57,8 @@ export default <TestSuite>{
)
assertResultMatch(response, responses.prepareSettings.regularKey, 'prepare')
},
'remove regularKey': async (client, address) => {
'remove regularKey': async (client, address, mockRippled) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
const regularKey = {regularKey: null}
const response = await client.prepareSettings(
address,
@@ -65,7 +71,8 @@ export default <TestSuite>{
'prepare'
)
},
'flag set': async (client, address) => {
'flag set': async (client, address, mockRippled) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
const settings = {requireDestinationTag: true}
const response = await client.prepareSettings(
address,
@@ -74,7 +81,8 @@ export default <TestSuite>{
)
assertResultMatch(response, responses.prepareSettings.flagSet, 'prepare')
},
'flag clear': async (client, address) => {
'flag clear': async (client, address, mockRippled) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
const settings = {requireDestinationTag: false}
const response = await client.prepareSettings(
address,
@@ -83,7 +91,8 @@ export default <TestSuite>{
)
assertResultMatch(response, responses.prepareSettings.flagClear, 'prepare')
},
'set depositAuth flag': async (client, address) => {
'set depositAuth flag': async (client, address, mockRippled) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
const settings = {depositAuth: true}
const response = await client.prepareSettings(
address,
@@ -96,7 +105,8 @@ export default <TestSuite>{
'prepare'
)
},
'clear depositAuth flag': async (client, address) => {
'clear depositAuth flag': async (client, address, mockRippled) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
const settings = {depositAuth: false}
const response = await client.prepareSettings(
address,
@@ -109,7 +119,8 @@ export default <TestSuite>{
'prepare'
)
},
'integer field clear': async (client, address) => {
'integer field clear': async (client, address, mockRippled) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
const settings = {transferRate: null}
const response = await client.prepareSettings(
address,
@@ -119,7 +130,8 @@ export default <TestSuite>{
assert(response)
assert.strictEqual(JSON.parse(response.txJSON).TransferRate, 0)
},
'set transferRate': async (client, address) => {
'set transferRate': async (client, address, mockRippled) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
const settings = {transferRate: 1}
const response = await client.prepareSettings(
address,
@@ -132,7 +144,8 @@ export default <TestSuite>{
'prepare'
)
},
'set signers': async (client, address) => {
'set signers': async (client, address, mockRippled) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
const settings = requests.prepareSettings.signers.normal
const response = await client.prepareSettings(
address,
@@ -141,7 +154,8 @@ export default <TestSuite>{
)
assertResultMatch(response, responses.prepareSettings.signers, 'prepare')
},
'signers no threshold': async (client, address) => {
'signers no threshold': async (client, address, mockRippled) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
const settings = requests.prepareSettings.signers.noThreshold
try {
const response = await client.prepareSettings(
@@ -161,7 +175,8 @@ export default <TestSuite>{
assert.strictEqual(err.name, 'ValidationError')
}
},
'signers no weights': async (client, address) => {
'signers no weights': async (client, address, mockRippled) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
const settings = requests.prepareSettings.signers.noWeights
const localInstructions = {
signersCount: 1,
@@ -174,7 +189,8 @@ export default <TestSuite>{
)
assertResultMatch(response, responses.prepareSettings.noWeights, 'prepare')
},
'fee for multisign': async (client, address) => {
'fee for multisign': async (client, address, mockRippled) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
const localInstructions = {
signersCount: 4,
...instructionsWithMaxLedgerVersionOffset
@@ -190,7 +206,8 @@ export default <TestSuite>{
'prepare'
)
},
'no signer list': async (client, address) => {
'no signer list': async (client, address, mockRippled) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
const settings = requests.prepareSettings.noSignerEntries
const localInstructions = {
signersCount: 1,
@@ -207,7 +224,8 @@ export default <TestSuite>{
'prepare'
)
},
'invalid': async (client, address) => {
'invalid': async (client, address, mockRippled) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
// domain must be a string
const settings = Object.assign({}, requests.prepareSettings.domain, {
domain: 123
@@ -235,7 +253,8 @@ export default <TestSuite>{
assert.strictEqual(err.name, 'ValidationError')
}
},
'offline': async (client, address) => {
'offline': async (client, address, mockRippled) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
const secret = 'shsWGZcmZz6YsWWmcnpfr6fLTdtFV'
const settings = requests.prepareSettings.domain
@@ -251,7 +270,8 @@ export default <TestSuite>{
responses.prepareSettings.signed
)
},
'prepare settings with ticket': async (client, address) => {
'prepare settings with ticket': async (client, address, mockRippled) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
const instructions = {
ticketSequence: 23,
maxLedgerVersion: 8820051,

View File

@@ -1,5 +1,6 @@
import {assertResultMatch, TestSuite} from '../../utils'
// import responses from '../../fixtures/responses'
import rippled from '../../fixtures/rippled'
// import requests from '../../fixtures/requests'
// import {ValidationError} from 'xrpl-local/common/errors'
// import binary from 'ripple-binary-codec'
@@ -20,8 +21,10 @@ import {assertResultMatch, TestSuite} from '../../utils'
export default <TestSuite>{
'creates a ticket successfully with a sequence number': async (
client,
address
address,
mockRippled
) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
const expected = {
txJSON:
'{"TransactionType":"TicketCreate", "TicketCount": 2, "Account":"r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59","Flags":2147483648,"LastLedgerSequence":8819954,"Sequence":23,"Fee":"12"}',
@@ -35,7 +38,8 @@ export default <TestSuite>{
assertResultMatch(response, expected, 'prepare')
},
'creates a ticket successfully with another ticket': async (client, address) => {
'creates a ticket successfully with another ticket': async (client, address, mockRippled) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
const expected = {
txJSON:
'{"TransactionType":"TicketCreate", "TicketCount": 1, "Account":"r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59","Flags":2147483648,"LastLedgerSequence":8819954,"Sequence": 0,"TicketSequence":23,"Fee":"12"}',

View File

@@ -1,6 +1,7 @@
import {RippledError, ValidationError} from 'xrpl-local/common/errors'
import {ValidationError} from 'xrpl-local/common/errors'
// import requests from '../../fixtures/requests'
import responses from '../../fixtures/responses'
import rippled from '../../fixtures/rippled'
import {assertRejects, assertResultMatch, TestSuite} from '../../utils'
const instructionsWithMaxLedgerVersionOffset = {maxLedgerVersionOffset: 100}
@@ -19,8 +20,10 @@ export const config = {
export default <TestSuite>{
'auto-fillable fields - does not overwrite Fee in txJSON': async (
client,
address
address,
mockRippled
) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
const localInstructions = instructionsWithMaxLedgerVersionOffset
const txJSON = {
TransactionType: 'DepositPreauth',
@@ -40,7 +43,8 @@ export default <TestSuite>{
return assertResultMatch(response, expected, 'prepare')
},
'does not overwrite Fee in Instructions': async (client, address) => {
'does not overwrite Fee in Instructions': async (client, address, mockRippled) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
const localInstructions = {
...instructionsWithMaxLedgerVersionOffset,
fee: '0.000014' // CAUTION: This `fee` is specified in XRP, not drops.
@@ -64,8 +68,10 @@ export default <TestSuite>{
'rejects Promise if both are set, even when txJSON.Fee matches instructions.fee': async (
client,
address
address,
mockRippled
) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
const localInstructions = {
...instructionsWithMaxLedgerVersionOffset,
fee: '0.000016'
@@ -85,8 +91,10 @@ export default <TestSuite>{
'rejects Promise if both are set, when txJSON.Fee does not match instructions.fee': async (
client,
address
address,
mockRippled
) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
const localInstructions = {
...instructionsWithMaxLedgerVersionOffset,
fee: '0.000018'
@@ -106,8 +114,10 @@ export default <TestSuite>{
'rejects Promise when the Fee is capitalized in Instructions': async (
client,
address
address,
mockRippled
) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
const localInstructions = {
...instructionsWithMaxLedgerVersionOffset,
Fee: '0.000022' // Intentionally capitalized in this test, but the correct field would be `fee`
@@ -126,8 +136,10 @@ export default <TestSuite>{
'rejects Promise when the fee is specified in txJSON': async (
client,
address
address,
mockRippled
) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
const localInstructions = instructionsWithMaxLedgerVersionOffset
const txJSON = {
TransactionType: 'DepositPreauth',
@@ -142,7 +154,8 @@ export default <TestSuite>{
)
},
'does not overwrite Sequence in txJSON': async (client, address) => {
'does not overwrite Sequence in txJSON': async (client, address, mockRippled) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
const localInstructions = {
...instructionsWithMaxLedgerVersionOffset,
maxFee: '0.000012'
@@ -165,7 +178,8 @@ export default <TestSuite>{
return assertResultMatch(response, expected, 'prepare')
},
'does not overwrite Sequence in Instructions': async (client, address) => {
'does not overwrite Sequence in Instructions': async (client, address, mockRippled) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
const localInstructions = {
...instructionsWithMaxLedgerVersionOffset,
maxFee: '0.000012',
@@ -190,8 +204,10 @@ export default <TestSuite>{
'does not overwrite Sequence when same sequence is provided in both txJSON and Instructions': async (
client,
address
address,
mockRippled
) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
const localInstructions = {
...instructionsWithMaxLedgerVersionOffset,
maxFee: '0.000012',
@@ -217,8 +233,10 @@ export default <TestSuite>{
'rejects Promise when Sequence in txJSON does not match sequence in Instructions': async (
client,
address
address,
mockRippled
) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
const localInstructions = {
...instructionsWithMaxLedgerVersionOffset,
maxFee: '0.000012',
@@ -239,8 +257,10 @@ export default <TestSuite>{
'rejects Promise when the Sequence is capitalized in Instructions': async (
client,
address
address,
mockRippled
) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
const localInstructions = {
...instructionsWithMaxLedgerVersionOffset,
maxFee: '0.000012',
@@ -260,7 +280,8 @@ export default <TestSuite>{
// LastLedgerSequence aka maxLedgerVersion/maxLedgerVersionOffset:
'does not overwrite LastLedgerSequence in txJSON': async (client, address) => {
'does not overwrite LastLedgerSequence in txJSON': async (client, address, mockRippled) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
const localInstructions = {}
const txJSON = {
TransactionType: 'DepositPreauth',
@@ -283,8 +304,10 @@ export default <TestSuite>{
'does not overwrite maxLedgerVersion in Instructions': async (
client,
address
address,
mockRippled
) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
const localInstructions = {
maxLedgerVersion: 8890000
}
@@ -307,8 +330,10 @@ export default <TestSuite>{
'does not overwrite maxLedgerVersionOffset in Instructions': async (
client,
address
address,
mockRippled
) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
const localInstructions = {
...instructionsWithMaxLedgerVersionOffset,
maxLedgerVersionOffset: 124
@@ -332,8 +357,10 @@ export default <TestSuite>{
'rejects Promise if txJSON.LastLedgerSequence and instructions.maxLedgerVersion both are set': async (
client,
address
address,
mockRippled
) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
const localInstructions = {
maxLedgerVersion: 8900000
}
@@ -353,8 +380,10 @@ export default <TestSuite>{
'rejects Promise if txJSON.LastLedgerSequence and instructions.maxLedgerVersionOffset both are set': async (
client,
address
address,
mockRippled
) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
const localInstructions = {
...instructionsWithMaxLedgerVersionOffset,
maxLedgerVersionOffset: 123
@@ -375,8 +404,10 @@ export default <TestSuite>{
'rejects Promise if instructions.maxLedgerVersion and instructions.maxLedgerVersionOffset both are set': async (
client,
address
address,
mockRippled
) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
const localInstructions = {
...instructionsWithMaxLedgerVersionOffset,
maxLedgerVersion: 8900000,
@@ -397,8 +428,10 @@ export default <TestSuite>{
'rejects Promise if txJSON.LastLedgerSequence and instructions.maxLedgerVersion and instructions.maxLedgerVersionOffset all are set': async (
client,
address
address,
mockRippled
) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
const localInstructions = {
...instructionsWithMaxLedgerVersionOffset,
maxLedgerVersion: 8900000,
@@ -420,8 +453,10 @@ export default <TestSuite>{
'rejects Promise when the maxLedgerVersion is capitalized in Instructions': async (
client,
address
address,
mockRippled
) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
const localInstructions = {
...instructionsWithMaxLedgerVersionOffset,
MaxLedgerVersion: 8900000 // Intentionally capitalized in this test, but the correct field would be `maxLedgerVersion`
@@ -440,8 +475,10 @@ export default <TestSuite>{
'rejects Promise when the maxLedgerVersion is specified in txJSON': async (
client,
address
address,
mockRippled
) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
const localInstructions = instructionsWithMaxLedgerVersionOffset
const txJSON = {
TransactionType: 'DepositPreauth',
@@ -458,8 +495,10 @@ export default <TestSuite>{
'rejects Promise when the maxLedgerVersionOffset is specified in txJSON': async (
client,
address
address,
mockRippled
) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
const localInstructions = instructionsWithMaxLedgerVersionOffset
const txJSON = {
TransactionType: 'DepositPreauth',
@@ -476,8 +515,10 @@ export default <TestSuite>{
'rejects Promise when the sequence is specified in txJSON': async (
client,
address
address,
mockRippled
) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
const localInstructions = instructionsWithMaxLedgerVersionOffset
const txJSON = {
TransactionType: 'DepositPreauth',
@@ -498,8 +539,10 @@ export default <TestSuite>{
'rejects Promise when an unrecognized field is in Instructions': async (
client,
address
address,
mockRippled
) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
const localInstructions = {
...instructionsWithMaxLedgerVersionOffset,
maxFee: '0.000012',
@@ -517,7 +560,8 @@ export default <TestSuite>{
)
},
'rejects Promise when Account is missing': async (client, address) => {
'rejects Promise when Account is missing': async (client, address, mockRippled) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
const localInstructions = {
...instructionsWithMaxLedgerVersionOffset,
maxFee: '0.000012'
@@ -534,7 +578,8 @@ export default <TestSuite>{
)
},
'rejects Promise when Account is not a string': async (client, address) => {
'rejects Promise when Account is not a string': async (client, address, mockRippled) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
const localInstructions = {
...instructionsWithMaxLedgerVersionOffset,
maxFee: '0.000012'
@@ -552,7 +597,8 @@ export default <TestSuite>{
)
},
'rejects Promise when Account is invalid': async (client, address) => {
'rejects Promise when Account is invalid': async (client, address, mockRippled) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
const localInstructions = {
...instructionsWithMaxLedgerVersionOffset,
maxFee: '0.000012'
@@ -569,26 +615,27 @@ export default <TestSuite>{
)
},
'rejects Promise when Account is valid but non-existent on the ledger': async (
client
) => {
const localInstructions = {
...instructionsWithMaxLedgerVersionOffset,
maxFee: '0.000012'
}
const txJSON = {
Account: 'rogvkYnY8SWjxkJNgU4ZRVfLeRyt5DR9i',
TransactionType: 'DepositPreauth',
Authorize: 'rpZc4mVfWUif9CRoHRKKcmhu1nx2xktxBo'
}
await assertRejects(
client.prepareTransaction(txJSON, localInstructions),
RippledError,
'Account not found.'
)
},
// 'rejects Promise when Account is valid but non-existent on the ledger': async (
// client
// ) => {
// const localInstructions = {
// ...instructionsWithMaxLedgerVersionOffset,
// maxFee: '0.000012'
// }
// const txJSON = {
// Account: 'rogvkYnY8SWjxkJNgU4ZRVfLeRyt5DR9i',
// TransactionType: 'DepositPreauth',
// Authorize: 'rpZc4mVfWUif9CRoHRKKcmhu1nx2xktxBo'
// }
// await assertRejects(
// client.prepareTransaction(txJSON, localInstructions),
// RippledError,
// 'Account not found.'
// )
// },
'rejects Promise when TransactionType is missing': async (client, address) => {
'rejects Promise when TransactionType is missing': async (client, address, mockRippled) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
const localInstructions = {
...instructionsWithMaxLedgerVersionOffset,
maxFee: '0.000012'
@@ -610,7 +657,8 @@ export default <TestSuite>{
// Error: DepositPreXXXX is not a valid name or ordinal for TransactionType
//
// at Function.from (ripple-binary-codec/distrib/npm/enums/index.js:43:15)
'prepares tx when TransactionType is invalid': async (client, address) => {
'prepares tx when TransactionType is invalid': async (client, address, mockRippled) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
const localInstructions = {
...instructionsWithMaxLedgerVersionOffset,
maxFee: '0.000012'
@@ -634,8 +682,10 @@ export default <TestSuite>{
'rejects Promise when TransactionType is not a string': async (
client,
address
address,
mockRippled
) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
const localInstructions = {
...instructionsWithMaxLedgerVersionOffset,
maxFee: '0.000012'
@@ -673,7 +723,8 @@ export default <TestSuite>{
// '304402201F0EF6A2DE7F96966F7082294D14F3EC1EF59C21E29443E5858A0120079357A302203CDB7FEBDEAAD93FF39CB589B55778CB80DC3979F96F27E828D5E659BEB26B7A',
// hash:
// 'C181D470684311658852713DA81F8201062535C8DE2FF853F7DD9981BB85312F' } })]
'prepares tx when a required field is missing': async (client, address) => {
'prepares tx when a required field is missing': async (client, address, mockRippled) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
const localInstructions = {
...instructionsWithMaxLedgerVersionOffset,
maxFee: '0.000012'
@@ -695,7 +746,8 @@ export default <TestSuite>{
return assertResultMatch(response, expected, 'prepare')
},
'DepositPreauth - Authorize': async (client, address) => {
'DepositPreauth - Authorize': async (client, address, mockRippled) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
const localInstructions = {
...instructionsWithMaxLedgerVersionOffset,
maxFee: '0.000012'
@@ -720,7 +772,8 @@ export default <TestSuite>{
return assertResultMatch(response, expected, 'prepare')
},
'DepositPreauth - Unauthorize': async (client, address) => {
'DepositPreauth - Unauthorize': async (client, address, mockRippled) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
const localInstructions = {
...instructionsWithMaxLedgerVersionOffset,
maxFee: '0.000012'
@@ -747,7 +800,8 @@ export default <TestSuite>{
return assertResultMatch(response, expected, 'prepare')
},
'AccountDelete': async (client, address) => {
'AccountDelete': async (client, address, mockRippled) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
const localInstructions = {
...instructionsWithMaxLedgerVersionOffset,
maxFee: '5.0' // 5 XRP fee for AccountDelete
@@ -775,7 +829,8 @@ export default <TestSuite>{
},
// prepareTransaction - Payment
'Payment - normal': async (client, address) => {
'Payment - normal': async (client, address, mockRippled) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
const localInstructions = {
...instructionsWithMaxLedgerVersionOffset,
maxFee: '0.000012'
@@ -802,7 +857,8 @@ export default <TestSuite>{
assertResultMatch(response, responses.preparePayment.normal, 'prepare')
},
'min amount xrp': async (client, address) => {
'min amount xrp': async (client, address, mockRippled) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
const localInstructions = {
...instructionsWithMaxLedgerVersionOffset,
maxFee: '0.000012'
@@ -834,7 +890,8 @@ export default <TestSuite>{
)
},
'min amount xrp2xrp': async (client, address) => {
'min amount xrp2xrp': async (client, address, mockRippled) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
const txJSON = {
TransactionType: 'Payment',
Account: address,
@@ -893,8 +950,10 @@ export default <TestSuite>{
'fee is capped at default maxFee of 2 XRP (using txJSON.LastLedgerSequence)': async (
client,
address
address,
mockRippled
) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
client._feeCushion = 1000000
const txJSON = {
@@ -930,8 +989,10 @@ export default <TestSuite>{
'fee is capped at default maxFee of 2 XRP (using instructions.maxLedgerVersion)': async (
client,
address
address,
mockRippled
) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
client._feeCushion = 1000000
const txJSON = {
@@ -972,8 +1033,10 @@ export default <TestSuite>{
// prepareTransaction - Payment
'fee is capped to custom maxFeeXRP when maxFee exceeds maxFeeXRP': async (
client,
address
address,
mockRippled
) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
client._feeCushion = 1000000
client._maxFeeXRP = '3'
const localInstructions = {
@@ -1013,7 +1076,8 @@ export default <TestSuite>{
},
// prepareTransaction - Payment
'fee is capped to maxFee': async (client, address) => {
'fee is capped to maxFee': async (client, address, mockRippled) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
client._feeCushion = 1000000
client._maxFeeXRP = '5'
const localInstructions = {
@@ -1080,7 +1144,8 @@ export default <TestSuite>{
// },
'xaddress-issuer': async (client, address) => {
'xaddress-issuer': async (client, address, mockRippled) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
const localInstructions = {
...instructionsWithMaxLedgerVersionOffset,
maxFee: '0.000012'
@@ -1107,7 +1172,8 @@ export default <TestSuite>{
assertResultMatch(response, responses.preparePayment.normal, 'prepare')
},
'PaymentChannelCreate': async (client, address) => {
'PaymentChannelCreate': async (client, address, mockRippled) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
const localInstructions = {
...instructionsWithMaxLedgerVersionOffset,
maxFee: '0.000012'
@@ -1136,7 +1202,8 @@ export default <TestSuite>{
)
},
'PaymentChannelCreate full': async (client, address) => {
'PaymentChannelCreate full': async (client, address, mockRippled) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
const txJSON = {
Account: address,
TransactionType: 'PaymentChannelCreate',
@@ -1158,7 +1225,8 @@ export default <TestSuite>{
)
},
'PaymentChannelFund': async (client, address) => {
'PaymentChannelFund': async (client, address, mockRippled) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
const localInstructions = {
...instructionsWithMaxLedgerVersionOffset,
maxFee: '0.000012'
@@ -1178,7 +1246,8 @@ export default <TestSuite>{
)
},
'PaymentChannelFund full': async (client, address) => {
'PaymentChannelFund full': async (client, address, mockRippled) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
const txJSON = {
Account: address,
TransactionType: 'PaymentChannelFund',
@@ -1196,7 +1265,8 @@ export default <TestSuite>{
)
},
'PaymentChannelClaim': async (client, address) => {
'PaymentChannelClaim': async (client, address, mockRippled) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
const localInstructions = {
...instructionsWithMaxLedgerVersionOffset,
maxFee: '0.000012'
@@ -1218,7 +1288,8 @@ export default <TestSuite>{
)
},
'PaymentChannelClaim with renew': async (client, address) => {
'PaymentChannelClaim with renew': async (client, address, mockRippled) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
const localInstructions = {
...instructionsWithMaxLedgerVersionOffset,
maxFee: '0.000012'
@@ -1247,7 +1318,8 @@ export default <TestSuite>{
)
},
'PaymentChannelClaim with close': async (client, address) => {
'PaymentChannelClaim with close': async (client, address, mockRippled) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
const localInstructions = {
...instructionsWithMaxLedgerVersionOffset,
maxFee: '0.000012'
@@ -1278,8 +1350,10 @@ export default <TestSuite>{
'rejects Promise if both sequence and ticketSecuence are set': async (
client,
address
address,
mockRippled
) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
const localInstructions = {
ticketSequence: 23,
sequence: 23
@@ -1297,7 +1371,8 @@ export default <TestSuite>{
)
},
'sets sequence to 0 if a ticketSequence is passed': async (client, address) => {
'sets sequence to 0 if a ticketSequence is passed': async (client, address, mockRippled) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
const localInstructions = {
...instructionsWithMaxLedgerVersionOffset,
maxFee: '0.000012',
@@ -1327,8 +1402,10 @@ export default <TestSuite>{
'rejects Promise if a sequence with value 0 is passed': async (
client,
address
address,
mockRippled
) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
const localInstructions = {
...instructionsWithMaxLedgerVersionOffset,
maxFee: '0.000012',

View File

@@ -1,5 +1,6 @@
import requests from '../../fixtures/requests'
import responses from '../../fixtures/responses'
import rippled from '../../fixtures/rippled'
import {assertRejects, assertResultMatch, TestSuite} from '../../utils'
const instructionsWithMaxLedgerVersionOffset = {maxLedgerVersionOffset: 100}
@@ -9,7 +10,8 @@ const instructionsWithMaxLedgerVersionOffset = {maxLedgerVersionOffset: 100}
* - Check out "test/client/index.ts" for more information about the test runner.
*/
export default <TestSuite>{
'simple': async (client, address) => {
'simple': async (client, address, mockRippled) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
const result = await client.prepareTrustline(
address,
requests.prepareTrustline.simple,
@@ -18,7 +20,8 @@ export default <TestSuite>{
assertResultMatch(result, responses.prepareTrustline.simple, 'prepare')
},
'frozen': async (client, address) => {
'frozen': async (client, address, mockRippled) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
const result = await client.prepareTrustline(
address,
requests.prepareTrustline.frozen
@@ -26,7 +29,8 @@ export default <TestSuite>{
assertResultMatch(result, responses.prepareTrustline.frozen, 'prepare')
},
'complex': async (client, address) => {
'complex': async (client, address, mockRippled) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
const result = await client.prepareTrustline(
address,
requests.prepareTrustline.complex,
@@ -35,7 +39,8 @@ export default <TestSuite>{
assertResultMatch(result, responses.prepareTrustline.complex, 'prepare')
},
'invalid': async (client, address) => {
'invalid': async (client, address, mockRippled) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
const trustline = Object.assign({}, requests.prepareTrustline.complex)
delete trustline.limit // Make invalid
@@ -50,7 +55,8 @@ export default <TestSuite>{
)
},
'xaddress-issuer': async (client, address) => {
'xaddress-issuer': async (client, address, mockRippled) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
const result = await client.prepareTrustline(
address,
requests.prepareTrustline.issuedXAddress,
@@ -59,7 +65,8 @@ export default <TestSuite>{
assertResultMatch(result, responses.prepareTrustline.issuedXAddress, 'prepare')
},
'with ticket': async (client, address) => {
'with ticket': async (client, address, mockRippled) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
const localInstructions = {
...instructionsWithMaxLedgerVersionOffset,
maxFee: '0.000012',

View File

@@ -1,4 +1,5 @@
import responses from '../../fixtures/responses'
import rippled from '../../fixtures/rippled'
import {TestSuite, assertResultMatch} from '../../utils'
/**
@@ -7,7 +8,8 @@ import {TestSuite, assertResultMatch} from '../../utils'
* - Check out "test/client/index.ts" for more information about the test runner.
*/
export default <TestSuite>{
'request account_objects': async (client, address) => {
'request account_objects': async (client, address, mockRippled) => {
mockRippled.addResponse({command: 'account_objects', account: address}, rippled.account_objects.normal)
const result = await client.request({command: 'account_objects',
account: address
})
@@ -19,7 +21,8 @@ export default <TestSuite>{
)
},
'request account_objects - invalid options': async (client, address) => {
'request account_objects - invalid options': async (client, address, mockRippled) => {
mockRippled.addResponse({command: 'account_objects', account: address}, rippled.account_objects.normal)
// @ts-ignore Intentionally no local validation of these options
const result = await client.request({command: 'account_objects',
account: address,

View File

@@ -3,6 +3,7 @@ import {Client} from 'xrpl-local'
import binary from 'ripple-binary-codec'
import requests from '../../fixtures/requests'
import responses from '../../fixtures/responses'
import rippled from '../../fixtures/rippled'
import {TestSuite} from '../../utils'
const {schemaValidator} = Client._PRIVATE
@@ -55,8 +56,10 @@ export default <TestSuite>{
'sign with paths': async (
client,
address
address,
mockRippled
) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
const secret = 'shsWGZcmZz6YsWWmcnpfr6fLTdtFV'
const payment = {
source: {
@@ -163,7 +166,8 @@ export default <TestSuite>{
assert.deepEqual(signature, RESPONSE_FIXTURES.signAs)
},
'succeeds - prepared payment': async (client, address) => {
'succeeds - prepared payment': async (client, address, mockRippled) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
const payment = await client.preparePayment(address, {
source: {
address: address,
@@ -236,8 +240,10 @@ export default <TestSuite>{
'throws when encoded tx does not match decoded tx - prepared payment': async (
client,
address
address,
mockRippled
) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
const payment = await client.preparePayment(address, {
source: {
address: address,
@@ -262,8 +268,10 @@ export default <TestSuite>{
'throws when encoded tx does not match decoded tx - prepared order': async (
client,
address
address,
mockRippled
) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
const order = {
direction: 'sell',
quantity: {

View File

@@ -158,9 +158,9 @@ describe('Connection', function () {
})
it('DisconnectedError', async function () {
await this.client.connection.request({
command: 'config',
data: {disconnectOnServerInfo: true}
this.mockRippled.on(`request_server_info`, function (request, conn) {
assert.strictEqual(request.command, 'server_info')
conn.close()
})
return this.client
.request({command: "server_info"})

View File

@@ -1,7 +0,0 @@
'use strict'
const accountObjectsNormal = require('./account-objects-normal')
module.exports = function(request, options = {}) {
return JSON.stringify(Object.assign({}, accountObjectsNormal, {id: request.id}))
}

View File

@@ -21,7 +21,7 @@ module.exports = {
subscribe_error: require('./subscribe_error'),
unsubscribe: require('./unsubscribe'),
account_objects: {
normal: require('./account-objects'),
normal: require('./account-objects-normal'),
// notfound: require('./account-objects-not-found')
},
account_info: {
@@ -52,7 +52,8 @@ module.exports = {
noValidated: require('./server-info-no-validated'),
syncing: require('./server-info-syncing'),
error: require('./server-info-error'),
reporting: require('./server-info-reporting')
reporting: require('./server-info-reporting'),
highLoadFactor: require('./server-info-high-load-factor')
},
path_find: {
generate: require('./path-find'),

View File

@@ -0,0 +1,31 @@
{
"id": 0,
"status": "success",
"type": "response",
"result": {
"info": {
"build_version": "0.24.0-rc1",
"complete_ledgers": "32570-6595042",
"hostid": "ARTS",
"io_latency_ms": 1,
"last_close": {
"converge_time_s": 2.007,
"proposers": 4
},
"load_factor": 4294967296,
"peers": 53,
"pubkey_node": "n94wWvFUmaKGYrKUGgpv1DyYgDeXRGdACkNQaSe7zJiy5Znio7UC",
"server_state": "full",
"validated_ledger": {
"age": 5,
"base_fee_xrp": 0.00001,
"hash":
"4482DEE5362332F54A4036ED57EE1767C9F33CF7CE5A6670355C16CECE381D46",
"reserve_base_xrp": 20,
"reserve_inc_xrp": 5,
"seq": 6595042
},
"validation_quorum": 3
}
}
}

View File

@@ -8,9 +8,9 @@ import addresses from './fixtures/addresses.json'
import hashes from './fixtures/hashes.json'
import transactionsResponse from './fixtures/rippled/account-tx'
import accountLinesResponse from './fixtures/rippled/account-lines'
import accountObjectsResponse from './fixtures/rippled/account-objects'
import fullLedger from './fixtures/rippled/ledger-full-38129.json'
import {getFreePort} from './utils'
import { Request } from '../src'
function isUSD(json) {
return json === 'USD' || json === '0000000000000000000000005553440000000000'
@@ -59,6 +59,13 @@ export function createMockRippled(port) {
const mock = new WebSocketServer({port: port}) as MockedWebSocketServer
Object.assign(mock, EventEmitter2.prototype)
mock.responses = {}
mock.addResponse = (request: Request, response: object) => {
const command = request.command
mock.responses[command] = response
}
const close = mock.close
mock.close = function () {
if (mock.expectedRequests != null) {
@@ -92,7 +99,12 @@ export function createMockRippled(port) {
conn.on('message', function (requestJSON) {
try {
const request = JSON.parse(requestJSON)
mock.emit('request_' + request.command, request, conn)
if (request.command in mock.responses) {
conn.send(createResponse(request, mock.responses[request.command]))
} else {
// TODO: remove this block once all the handlers have been removed
mock.emit('request_' + request.command, request, conn)
}
} catch (err) {
console.error('Error: ' + err.message)
assert(false, err.message)
@@ -119,18 +131,6 @@ export function createMockRippled(port) {
mock.expectedRequests[this.event] -= 1
})
mock.on('request_config', function (request, conn) {
assert.strictEqual(request.command, 'config')
conn.config = Object.assign(conn.config, request.data)
conn.send(
createResponse(request, {
status: 'success',
type: 'response',
result: {}
})
)
})
mock.on('request_test_command', function (request, conn) {
assert.strictEqual(request.command, 'test_command')
if (request.data.disconnectIn) {
@@ -190,63 +190,6 @@ export function createMockRippled(port) {
conn.send(JSON.stringify(request.data))
})
mock.on('request_fee', function (request, conn) {
assert.strictEqual(request.command, 'fee')
conn.send(createResponse(request, fixtures.fee))
})
mock.on('request_server_info', function (request, conn) {
assert.strictEqual(request.command, 'server_info')
if (conn.config.highLoadFactor || conn.config.loadFactor) {
const response = {
id: 0,
status: 'success',
type: 'response',
result: {
info: {
build_version: '0.24.0-rc1',
complete_ledgers: '32570-6595042',
hostid: 'ARTS',
io_latency_ms: 1,
last_close: {
converge_time_s: 2.007,
proposers: 4
},
load_factor: conn.config.loadFactor || 4294967296,
peers: 53,
pubkey_node: 'n94wWvFUmaKGYrKUGgpv1DyYgDeXRGdACkNQaSe7zJiy5Znio7UC',
server_state: 'full',
validated_ledger: {
age: 5,
base_fee_xrp: 0.00001,
hash:
'4482DEE5362332F54A4036ED57EE1767C9F33CF7CE5A6670355C16CECE381D46',
reserve_base_xrp: 20,
reserve_inc_xrp: 5,
seq: 6595042
},
validation_quorum: 3
}
}
}
conn.send(createResponse(request, response))
} else if (conn.config.reporting) {
conn.send(createResponse(request, fixtures.server_info.reporting))
} else if (conn.config.returnErrorOnServerInfo) {
conn.send(createResponse(request, fixtures.server_info.error))
} else if (conn.config.disconnectOnServerInfo) {
conn.close()
} else if (conn.config.serverInfoWithoutValidated) {
conn.send(createResponse(request, fixtures.server_info.noValidated))
} else if (mock.config.returnSyncingServerInfo) {
mock.config.returnSyncingServerInfo--
conn.send(createResponse(request, fixtures.server_info.syncing))
} else {
conn.send(createResponse(request, fixtures.server_info.normal))
}
})
mock.on('request_subscribe', function (request, conn) {
assert.strictEqual(request.command, 'subscribe')
if (request && request.streams === 'validations') {
@@ -260,6 +203,11 @@ export function createMockRippled(port) {
conn.send(createResponse(request, fixtures.subscribe))
})
mock.on('request_fee', function (request, conn) {
assert.strictEqual(request.command, 'fee')
conn.send(createResponse(request, fixtures.fee))
})
mock.on('request_unsubscribe', function (request, conn) {
assert.strictEqual(request.command, 'unsubscribe')
if (request.accounts) {
@@ -270,64 +218,10 @@ export function createMockRippled(port) {
conn.send(createResponse(request, fixtures.unsubscribe))
})
mock.on('request_account_objects', function (request, conn) {
assert.strictEqual(request.command, 'account_objects')
if (request.account === addresses.ACCOUNT) {
conn.send(accountObjectsResponse(request))
} else {
assert(false, 'Unrecognized account address: ' + request.account)
}
})
// TODO: remove this and move fixtures closer when the prepare functions are gone
mock.on('request_account_info', function (request, conn) {
assert.strictEqual(request.command, 'account_info')
if (request.account === addresses.ACCOUNT) {
conn.send(createResponse(request, fixtures.account_info.normal))
} else if (request.account === addresses.NOTFOUND) {
conn.send(createResponse(request, fixtures.account_info.notfound))
} else if (request.account === addresses.THIRD_ACCOUNT) {
const response = Object.assign({}, fixtures.account_info.normal)
response.Account = addresses.THIRD_ACCOUNT
conn.send(createResponse(request, response))
} else if (request.account == null) {
const response = Object.assign(
{},
{
error: 'invalidParams',
error_code: 31,
error_message: "Missing field 'account'.",
id: 2,
request: {command: 'account_info', id: 2},
status: 'error',
type: 'response'
}
)
conn.send(createResponse(request, response))
} else {
const response = Object.assign(
{},
{
account: request.account,
error: 'actNotFound',
error_code: 19,
error_message: 'Account not found.',
id: 2,
ledger_current_index: 17714714,
request:
// This will be inaccurate, but that's OK because this is just a mock rippled
{
account: 'rogvkYnY8SWjxkJNgU4ZRVfLeRyt5DR9i',
command: 'account_info',
id: 2
},
status: 'error',
type: 'response',
validated: false
}
)
conn.send(createResponse(request, response))
}
conn.send(createResponse(request, fixtures.account_info.normal))
})
mock.on('request_ledger', function (request, conn) {

View File

@@ -38,16 +38,16 @@ describe('Client [Test Runner]', function () {
for (const [testName, fn] of tests) {
if (fn.length === 1) {
it(testName, function () {
return fn(this.client, addresses.ACCOUNT)
return fn(this.client, addresses.ACCOUNT, this.mockRippled)
})
}
}
// Run each test with a classic address.
describe(`[Classic Address]`, () => {
for (const [testName, fn] of tests) {
if (fn.length === 2) {
if (fn.length >= 2) {
it(testName, function () {
return fn(this.client, addresses.ACCOUNT)
return fn(this.client, addresses.ACCOUNT, this.mockRippled)
})
}
}
@@ -56,9 +56,9 @@ describe('Client [Test Runner]', function () {
if (!config.skipXAddress) {
describe(`[X-address]`, () => {
for (const [testName, fn] of tests) {
if (fn.length === 2) {
if (fn.length >= 2) {
it(testName, function () {
return fn(this.client, addresses.ACCOUNT_X)
return fn(this.client, addresses.ACCOUNT_X, this.mockRippled)
})
}
}

View File

@@ -12,7 +12,8 @@ import assert from 'assert-diff'
*/
export type TestFn = (
client: Client,
address: string
address: string,
mockRippled?: any
) => void | PromiseLike<void>
/**