refactor: move fixtures closer to tests (part 2) (#1561)

* move echo

* move fee

* move subscribe/unsubscribe

* move ledger_current

* move ledger_data

* move submit/submit_multisigned

* remove account_tx/account_offers/gateway_balances

* move account_info

* remove ledger_entry

* remove tx

* remove account_lines

* remove ripple_path_find

* remove ledger

* remove book_offers

* move ping

* remove global_config

* move test_command

* additional mock-rippled cleanup

* add explanatory comment to mock.addResponse
This commit is contained in:
Mayukha Vadari
2021-08-26 14:02:48 -04:00
parent f9fe5936b1
commit 09ef8595e7
31 changed files with 657 additions and 752 deletions

View File

@@ -21,6 +21,9 @@ const RECIPIENT_ADDRESS = 'rpZc4mVfWUif9CRoHRKKcmhu1nx2xktxBo'
export default <TestSuite>{
'normal': async (client, address, mockRippled) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
mockRippled.addResponse({command: 'fee'}, rippled.fee)
mockRippled.addResponse({command: 'ledger_current'}, rippled.ledger_current)
mockRippled.addResponse({command: 'account_info'}, rippled.account_info.normal)
const localInstructions = {
...instructionsWithMaxLedgerVersionOffset,
maxFee: '0.000012'
@@ -35,6 +38,9 @@ export default <TestSuite>{
'min amount xrp': async (client, address, mockRippled) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
mockRippled.addResponse({command: 'fee'}, rippled.fee)
mockRippled.addResponse({command: 'ledger_current'}, rippled.ledger_current)
mockRippled.addResponse({command: 'account_info'}, rippled.account_info.normal)
const localInstructions = {
...instructionsWithMaxLedgerVersionOffset,
maxFee: '0.000012'
@@ -49,6 +55,9 @@ export default <TestSuite>{
'min amount xrp2xrp': async (client, address, mockRippled) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
mockRippled.addResponse({command: 'fee'}, rippled.fee)
mockRippled.addResponse({command: 'ledger_current'}, rippled.ledger_current)
mockRippled.addResponse({command: 'account_info'}, rippled.account_info.normal)
const response = await client.preparePayment(
address,
REQUEST_FIXTURES.minAmount,
@@ -59,6 +68,9 @@ export default <TestSuite>{
'XRP to XRP': async (client, address, mockRippled) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
mockRippled.addResponse({command: 'fee'}, rippled.fee)
mockRippled.addResponse({command: 'ledger_current'}, rippled.ledger_current)
mockRippled.addResponse({command: 'account_info'}, rippled.account_info.normal)
const payment = {
source: {
address: 'r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59',
@@ -88,6 +100,9 @@ export default <TestSuite>{
'XRP drops to XRP drops': async (client, address, mockRippled) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
mockRippled.addResponse({command: 'fee'}, rippled.fee)
mockRippled.addResponse({command: 'ledger_current'}, rippled.ledger_current)
mockRippled.addResponse({command: 'account_info'}, rippled.account_info.normal)
const payment = {
source: {
address: 'r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59',
@@ -117,6 +132,9 @@ export default <TestSuite>{
'XRP drops to XRP': async (client, address, mockRippled) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
mockRippled.addResponse({command: 'fee'}, rippled.fee)
mockRippled.addResponse({command: 'ledger_current'}, rippled.ledger_current)
mockRippled.addResponse({command: 'account_info'}, rippled.account_info.normal)
const payment = {
source: {
address: 'r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59',
@@ -146,6 +164,9 @@ export default <TestSuite>{
'XRP to XRP drops': async (client, address, mockRippled) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
mockRippled.addResponse({command: 'fee'}, rippled.fee)
mockRippled.addResponse({command: 'ledger_current'}, rippled.ledger_current)
mockRippled.addResponse({command: 'account_info'}, rippled.account_info.normal)
const payment = {
source: {
address: 'r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59',
@@ -180,6 +201,9 @@ export default <TestSuite>{
mockRippled
) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
mockRippled.addResponse({command: 'fee'}, rippled.fee)
mockRippled.addResponse({command: 'ledger_current'}, rippled.ledger_current)
mockRippled.addResponse({command: 'account_info'}, rippled.account_info.normal)
const payment = {
source: {
address: address,
@@ -205,6 +229,9 @@ export default <TestSuite>{
mockRippled
) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
mockRippled.addResponse({command: 'fee'}, rippled.fee)
mockRippled.addResponse({command: 'ledger_current'}, rippled.ledger_current)
mockRippled.addResponse({command: 'account_info'}, rippled.account_info.normal)
// Marking as "any" to get around the fact that TS won't allow this.
const payment: any = {
source: {address: address},
@@ -227,6 +254,9 @@ export default <TestSuite>{
mockRippled
) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
mockRippled.addResponse({command: 'fee'}, rippled.fee)
mockRippled.addResponse({command: 'ledger_current'}, rippled.ledger_current)
mockRippled.addResponse({command: 'account_info'}, rippled.account_info.normal)
const payment = {
source: {
address: address,
@@ -246,6 +276,9 @@ export default <TestSuite>{
'XRP to XRP no partial': async (client, address, mockRippled) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
mockRippled.addResponse({command: 'fee'}, rippled.fee)
mockRippled.addResponse({command: 'ledger_current'}, rippled.ledger_current)
mockRippled.addResponse({command: 'account_info'}, rippled.account_info.normal)
return assertRejects(
client.preparePayment(address, REQUEST_FIXTURES.wrongPartial),
ValidationError,
@@ -255,6 +288,9 @@ export default <TestSuite>{
'address must match payment.source.address': async (client, address, mockRippled) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
mockRippled.addResponse({command: 'fee'}, rippled.fee)
mockRippled.addResponse({command: 'ledger_current'}, rippled.ledger_current)
mockRippled.addResponse({command: 'account_info'}, rippled.account_info.normal)
return assertRejects(
client.preparePayment(address, REQUEST_FIXTURES.wrongAddress),
ValidationError,
@@ -264,6 +300,9 @@ export default <TestSuite>{
'wrong amount': async (client, address, mockRippled) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
mockRippled.addResponse({command: 'fee'}, rippled.fee)
mockRippled.addResponse({command: 'ledger_current'}, rippled.ledger_current)
mockRippled.addResponse({command: 'account_info'}, rippled.account_info.normal)
return assertRejects(
client.preparePayment(address, REQUEST_FIXTURES.wrongAmount),
ValidationError,
@@ -273,6 +312,9 @@ export default <TestSuite>{
'throws when fee exceeds 2 XRP': async (client, address, mockRippled) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
mockRippled.addResponse({command: 'fee'}, rippled.fee)
mockRippled.addResponse({command: 'ledger_current'}, rippled.ledger_current)
mockRippled.addResponse({command: 'account_info'}, rippled.account_info.normal)
const localInstructions = {
...instructionsWithMaxLedgerVersionOffset,
fee: '2.1'
@@ -301,6 +343,9 @@ export default <TestSuite>{
'preparePayment without counterparty set': async (client, address, mockRippled) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
mockRippled.addResponse({command: 'fee'}, rippled.fee)
mockRippled.addResponse({command: 'ledger_current'}, rippled.ledger_current)
mockRippled.addResponse({command: 'account_info'}, rippled.account_info.normal)
const localInstructions = {
...instructionsWithMaxLedgerVersionOffset,
sequence: 23
@@ -319,6 +364,9 @@ export default <TestSuite>{
mockRippled
) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
mockRippled.addResponse({command: 'fee'}, rippled.fee)
mockRippled.addResponse({command: 'ledger_current'}, rippled.ledger_current)
mockRippled.addResponse({command: 'account_info'}, rippled.account_info.normal)
// See also: 'sign succeeds with source.amount/destination.minAmount'
const localInstructions = {
@@ -369,6 +417,9 @@ export default <TestSuite>{
'destination.minAmount': async (client, address, mockRippled) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
mockRippled.addResponse({command: 'fee'}, rippled.fee)
mockRippled.addResponse({command: 'ledger_current'}, rippled.ledger_current)
mockRippled.addResponse({command: 'account_info'}, rippled.account_info.normal)
const response = await client.preparePayment(
address,
responses.getPaths.sendAll[0],
@@ -379,6 +430,9 @@ export default <TestSuite>{
'caps fee at 2 XRP by default': async (client, address, mockRippled) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
mockRippled.addResponse({command: 'fee'}, rippled.fee)
mockRippled.addResponse({command: 'ledger_current'}, rippled.ledger_current)
mockRippled.addResponse({command: 'account_info'}, rippled.account_info.normal)
client._feeCushion = 1000000
const expectedResponse = {
txJSON:
@@ -403,6 +457,9 @@ export default <TestSuite>{
mockRippled
) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
mockRippled.addResponse({command: 'fee'}, rippled.fee)
mockRippled.addResponse({command: 'ledger_current'}, rippled.ledger_current)
mockRippled.addResponse({command: 'account_info'}, rippled.account_info.normal)
client._maxFeeXRP = '2.2'
const localInstructions = {
...instructionsWithMaxLedgerVersionOffset,
@@ -427,6 +484,9 @@ export default <TestSuite>{
'fee - default maxFee of 2 XRP': async (client, address, mockRippled) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
mockRippled.addResponse({command: 'fee'}, rippled.fee)
mockRippled.addResponse({command: 'ledger_current'}, rippled.ledger_current)
mockRippled.addResponse({command: 'account_info'}, rippled.account_info.normal)
client._feeCushion = 1000000
const expectedResponse = {
txJSON:
@@ -451,6 +511,9 @@ export default <TestSuite>{
mockRippled
) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
mockRippled.addResponse({command: 'fee'}, rippled.fee)
mockRippled.addResponse({command: 'ledger_current'}, rippled.ledger_current)
mockRippled.addResponse({command: 'account_info'}, rippled.account_info.normal)
client._feeCushion = 1000000
client._maxFeeXRP = '3'
const localInstructions = {
@@ -476,6 +539,9 @@ export default <TestSuite>{
'fee - capped to maxFee': async (client, address, mockRippled) => {
mockRippled.addResponse({command: 'server_info'}, rippled.server_info.normal)
mockRippled.addResponse({command: 'fee'}, rippled.fee)
mockRippled.addResponse({command: 'ledger_current'}, rippled.ledger_current)
mockRippled.addResponse({command: 'account_info'}, rippled.account_info.normal)
client._feeCushion = 1000000
client._maxFeeXRP = '5'
const localInstructions = {