test: removes the use of TestSuite (#1566)* switch all methods to new format* clean up rippleClient* rename files to remove ripple from name* additional cleanup

This commit is contained in:
Mayukha Vadari
2021-08-30 18:04:06 -04:00
parent 43802f9e22
commit 6268b9ea26
41 changed files with 3880 additions and 3699 deletions

View File

@@ -1,14 +1,19 @@
import { fromSeed } from 'bip32'; import { fromSeed } from "bip32";
import { mnemonicToSeedSync } from 'bip39'; import { mnemonicToSeedSync } from "bip39";
import { classicAddressToXAddress } from 'ripple-address-codec' import { classicAddressToXAddress } from "ripple-address-codec";
import { decode, encodeForSigning } from 'ripple-binary-codec'; import { decode, encodeForSigning } from "ripple-binary-codec";
import { deriveAddress, deriveKeypair, generateSeed, verify } from 'ripple-keypairs'; import {
deriveAddress,
deriveKeypair,
generateSeed,
verify,
} from "ripple-keypairs";
import ECDSA from './common/ecdsa'; import ECDSA from "./common/ecdsa";
import { ValidationError } from './common/errors'; import { ValidationError } from "./common/errors";
import { SignedTransaction } from './common/types/objects'; import { SignedTransaction } from "./common/types/objects";
import { signOffline } from './transaction/sign'; import { signOffline } from "./transaction/sign";
import { SignOptions } from './transaction/types'; import { SignOptions } from "./transaction/types";
/** /**
* A utility for deriving a wallet composed of a keypair (publicKey/privateKey). * A utility for deriving a wallet composed of a keypair (publicKey/privateKey).
@@ -125,16 +130,13 @@ class Wallet {
/** /**
* Gets an X-address in Testnet/Mainnet format. * Gets an X-address in Testnet/Mainnet format.
* @param {number} tag A tag to be included within the X-address. *
* @param {boolean} test A boolean to indicate if X-address should be in Testnet (true) or Mainnet (false) format. * @param tag - A tag to be included within the X-address.
* @returns {string} An X-address. * @param test - A boolean to indicate if X-address should be in Testnet (true) or Mainnet (false) format.
* @returns An X-address.
*/ */
getXAddress(tag: number, test: boolean = false): string { getXAddress(tag: number, test = false): string {
return classicAddressToXAddress( return classicAddressToXAddress(deriveAddress(this.publicKey), tag, test);
deriveAddress(this.publicKey),
tag,
test,
)
} }
} }

View File

@@ -3,29 +3,28 @@ import binary from "ripple-binary-codec";
import requests from "../fixtures/requests"; import requests from "../fixtures/requests";
import responses from "../fixtures/responses"; import responses from "../fixtures/responses";
import { assertResultMatch, TestSuite } from "../testUtils"; import setupClient from "../setupClient";
import { assertResultMatch } from "../testUtils";
const { combine: REQUEST_FIXTURES } = requests; const { combine: REQUEST_FIXTURES } = requests;
const { combine: RESPONSE_FIXTURES } = responses; const { combine: RESPONSE_FIXTURES } = responses;
/** describe("client.combine", function () {
* Every test suite exports their tests in the default object. beforeEach(setupClient.setup);
* - Check out the "TestSuite" type for documentation on the interface. afterEach(setupClient.teardown);
* - Check out "test/client/index.ts" for more information about the test runner.
*/
export default <TestSuite>{
async combine(client, address) {
const combined = client.combine(REQUEST_FIXTURES.setDomain);
assertResultMatch(combined, RESPONSE_FIXTURES.single, "sign");
},
"combine - different transactions": async (client, address) => { it("combine", async function () {
const combined = this.client.combine(REQUEST_FIXTURES.setDomain);
assertResultMatch(combined, RESPONSE_FIXTURES.single, "sign");
});
it("combine - different transactions", async function () {
const request = [REQUEST_FIXTURES.setDomain[0]]; const request = [REQUEST_FIXTURES.setDomain[0]];
const tx = binary.decode(REQUEST_FIXTURES.setDomain[0]); const tx = binary.decode(REQUEST_FIXTURES.setDomain[0]);
tx.Flags = 0; tx.Flags = 0;
request.push(binary.encode(tx)); request.push(binary.encode(tx));
assert.throws(() => { assert.throws(() => {
client.combine(request); this.client.combine(request);
}, /txJSON is not the same for all signedTransactions/); }, /txJSON is not the same for all signedTransactions/);
}, });
}; });

View File

@@ -2,30 +2,23 @@ import { assert } from "chai";
import { Client } from "xrpl-local"; import { Client } from "xrpl-local";
import { TestSuite } from "../testUtils"; describe("client constructor", function () {
it("Client - implicit server port", function () {
/**
* Every test suite exports their tests in the default object.
* - Check out the "TestSuite" type for documentation on the interface.
* - Check out "test/client/index.ts" for more information about the test runner.
*/
export default <TestSuite>{
"Client - implicit server port": () => {
new Client("wss://s1.ripple.com"); new Client("wss://s1.ripple.com");
}, });
"Client invalid options": () => { it("Client invalid options", function () {
// @ts-expect-error - This is intentionally invalid // @ts-expect-error - This is intentionally invalid
assert.throws(() => new Client({ invalid: true })); assert.throws(() => new Client({ invalid: true }));
}, });
"Client valid options": () => { it("Client valid options", function () {
const client = new Client("wss://s:1"); const client = new Client("wss://s:1");
const privateConnectionUrl = (client.connection as any)._url; const privateConnectionUrl = (client.connection as any)._url;
assert.deepEqual(privateConnectionUrl, "wss://s:1"); assert.deepEqual(privateConnectionUrl, "wss://s:1");
}, });
"Client invalid server uri": () => { it("Client invalid server uri", function () {
assert.throws(() => new Client("wss//s:1")); assert.throws(() => new Client("wss//s:1"));
}, });
}; });

View File

@@ -1,15 +1,9 @@
import { assert } from "chai"; import { assert } from "chai";
import { Client } from "../../src"; import { Client } from "../../src";
import { TestSuite } from "../testUtils";
/** describe("client.deriveXAddress", function () {
* Every test suite exports their tests in the default object. it("returns address for public key", function () {
* - Check out the "TestSuite" type for documentation on the interface.
* - Check out "test/client/index.ts" for more information about the test runner.
*/
export default <TestSuite>{
"returns address for public key": async (client, address) => {
assert.equal( assert.equal(
Client.deriveXAddress({ Client.deriveXAddress({
publicKey: publicKey:
@@ -28,5 +22,5 @@ export default <TestSuite>{
}), }),
"TVVrSWtmQQssgVcmoMBcFQZKKf56QscyWLKnUyiuZW8ALU4" "TVVrSWtmQQssgVcmoMBcFQZKKf56QscyWLKnUyiuZW8ALU4"
); );
}, });
}; });

View File

@@ -1,20 +1,18 @@
import { assert } from "chai"; import { assert } from "chai";
import { TestSuite } from "../testUtils"; import setupClient from "../setupClient";
/** describe("client errors", function () {
* Every test suite exports their tests in the default object. beforeEach(setupClient.setup);
* - Check out the "TestSuite" type for documentation on the interface. afterEach(setupClient.teardown);
* - Check out "test/client/index.ts" for more information about the test runner.
*/ it("RippleError with data", async function () {
export default <TestSuite>{ const error = new this.client.errors.RippleError("_message_", "_data_");
"RippleError with data": async (client, address) => {
const error = new client.errors.RippleError("_message_", "_data_");
assert.strictEqual(error.toString(), "[RippleError(_message_, '_data_')]"); assert.strictEqual(error.toString(), "[RippleError(_message_, '_data_')]");
}, });
"NotFoundError default message": async (client, address) => { it("NotFoundError default message", async function () {
const error = new client.errors.NotFoundError(); const error = new this.client.errors.NotFoundError();
assert.strictEqual(error.toString(), "[NotFoundError(Not found)]"); assert.strictEqual(error.toString(), "[NotFoundError(Not found)]");
}, });
}; });

View File

@@ -3,7 +3,6 @@
// import {Client} from 'xrpl-local' // import {Client} from 'xrpl-local'
// import requests from '../fixtures/requests' // import requests from '../fixtures/requests'
// import responses from '../fixtures/responses' // import responses from '../fixtures/responses'
import { TestSuite } from "../testUtils";
// function checkSortingOfOrders(orders) { // function checkSortingOfOrders(orders) {
// let previousRate = '0' // let previousRate = '0'
@@ -39,12 +38,7 @@ import { TestSuite } from "../testUtils";
// return true // return true
// } // }
/** describe("client.formatBidsAndAsks", function () {
* Every test suite exports their tests in the default object.
* - Check out the "TestSuite" type for documentation on the interface.
* - Check out "test/client/index.ts" for more information about the test runner.
*/
export default <TestSuite>{
// 'normal': async (client, address) => { // 'normal': async (client, address) => {
// const orderbookInfo = { // const orderbookInfo = {
// base: { // base: {
@@ -365,4 +359,4 @@ export default <TestSuite>{
// ) // )
// }) // })
// } // }
}; });

View File

@@ -1,57 +1,83 @@
import responses from "../fixtures/responses"; import responses from "../fixtures/responses";
import rippled from "../fixtures/rippled"; import rippled from "../fixtures/rippled";
import rippledAccountLines from "../fixtures/rippled/accountLines"; import rippledAccountLines from "../fixtures/rippled/accountLines";
import { assertResultMatch, TestSuite } from "../testUtils"; import setupClient from "../setupClient";
import { assertResultMatch, addressTests } from "../testUtils";
/** /**
* Every test suite exports their tests in the default object. * Every test suite exports their tests in the default object.
* - Check out the "TestSuite" type for documentation on the interface. * - Check out the "TestSuite" type for documentation on the interface.
* - Check out "test/client/index.ts" for more information about the test runner. * - Check out "test/client/index.ts" for more information about the test runner.
*/ */
export default <TestSuite>{ describe("getBalances", function () {
async getBalances(client, address, mockRippled) { beforeEach(setupClient.setup);
mockRippled.addResponse("account_info", rippled.account_info.normal); afterEach(setupClient.teardown);
mockRippled.addResponse("account_lines", rippledAccountLines.normal);
mockRippled.addResponse("ledger", rippled.ledger.normal); addressTests.forEach(function (test) {
const result = await client.getBalances(address); describe(test.type, function () {
it("getBalances", async function () {
this.mockRippled.addResponse(
"account_info",
rippled.account_info.normal
);
this.mockRippled.addResponse(
"account_lines",
rippledAccountLines.normal
);
this.mockRippled.addResponse("ledger", rippled.ledger.normal);
const result = await this.client.getBalances(test.address);
assertResultMatch(result, responses.getBalances, "getBalances"); assertResultMatch(result, responses.getBalances, "getBalances");
}, });
"getBalances - limit": async (client, address, mockRippled) => { it("getBalances - limit", async function () {
const options = { limit: 3, ledgerVersion: 123456 }; const options = { limit: 3, ledgerVersion: 123456 };
mockRippled.addResponse("account_info", rippled.account_info.normal); this.mockRippled.addResponse(
mockRippled.addResponse("account_lines", rippledAccountLines.normal); "account_info",
mockRippled.addResponse("ledger", rippled.ledger.normal); rippled.account_info.normal
);
this.mockRippled.addResponse(
"account_lines",
rippledAccountLines.normal
);
this.mockRippled.addResponse("ledger", rippled.ledger.normal);
const expectedResponse = responses.getBalances.slice(0, 3); const expectedResponse = responses.getBalances.slice(0, 3);
const result = await client.getBalances(address, options); const result = await this.client.getBalances(test.address, options);
assertResultMatch(result, expectedResponse, "getBalances"); assertResultMatch(result, expectedResponse, "getBalances");
}, });
"getBalances - limit & currency": async (client, address, mockRippled) => { it("getBalances - limit & currency", async function () {
const options = { currency: "USD", limit: 3 }; const options = { currency: "USD", limit: 3 };
mockRippled.addResponse("account_info", rippled.account_info.normal); this.mockRippled.addResponse(
mockRippled.addResponse("account_lines", rippledAccountLines.normal); "account_info",
mockRippled.addResponse("ledger", rippled.ledger.normal); rippled.account_info.normal
);
this.mockRippled.addResponse(
"account_lines",
rippledAccountLines.normal
);
this.mockRippled.addResponse("ledger", rippled.ledger.normal);
const expectedResponse = responses.getBalances const expectedResponse = responses.getBalances
.filter((item) => item.currency === "USD") .filter((item) => item.currency === "USD")
.slice(0, 3); .slice(0, 3);
const result = await client.getBalances(address, options); const result = await this.client.getBalances(test.address, options);
assertResultMatch(result, expectedResponse, "getBalances"); assertResultMatch(result, expectedResponse, "getBalances");
}, });
"getBalances - limit & currency & issuer": async ( it("getBalances - limit & currency & issuer", async function () {
client,
address,
mockRippled
) => {
const options = { const options = {
currency: "USD", currency: "USD",
counterparty: "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B", counterparty: "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B",
limit: 3, limit: 3,
}; };
mockRippled.addResponse("account_info", rippled.account_info.normal); this.mockRippled.addResponse(
mockRippled.addResponse("account_lines", rippledAccountLines.normal); "account_info",
mockRippled.addResponse("ledger", rippled.ledger.normal); rippled.account_info.normal
);
this.mockRippled.addResponse(
"account_lines",
rippledAccountLines.normal
);
this.mockRippled.addResponse("ledger", rippled.ledger.normal);
const expectedResponse = responses.getBalances const expectedResponse = responses.getBalances
.filter( .filter(
@@ -60,7 +86,9 @@ export default <TestSuite>{
item.counterparty === "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B" item.counterparty === "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B"
) )
.slice(0, 3); .slice(0, 3);
const result = await client.getBalances(address, options); const result = await this.client.getBalances(test.address, options);
assertResultMatch(result, expectedResponse, "getBalances"); assertResultMatch(result, expectedResponse, "getBalances");
}, });
}; });
});
});

View File

@@ -1,65 +1,70 @@
import { assert } from "chai"; import { assert } from "chai";
import rippled from "../fixtures/rippled"; import rippled from "../fixtures/rippled";
import { TestSuite } from "../testUtils"; import setupClient from "../setupClient";
import { addressTests } from "../testUtils";
/** describe("client.getFee", function () {
* Every test suite exports their tests in the default object. beforeEach(setupClient.setup);
* - Check out the "TestSuite" type for documentation on the interface. afterEach(setupClient.teardown);
* - Check out "test/client/index.ts" for more information about the test runner.
*/ addressTests.forEach(function (test) {
export default <TestSuite>{ describe(test.type, function () {
async getFee(client, address, mockRippled) { it("getFee", async function () {
mockRippled.addResponse("server_info", rippled.server_info.normal); this.mockRippled.addResponse("server_info", rippled.server_info.normal);
const fee = await client.getFee(); const fee = await this.client.getFee();
assert.strictEqual(fee, "0.000012"); assert.strictEqual(fee, "0.000012");
}, });
"getFee default": async (client, address, mockRippled) => { it("getFee default", async function () {
mockRippled.addResponse("server_info", rippled.server_info.normal); this.mockRippled.addResponse("server_info", rippled.server_info.normal);
client._feeCushion = undefined as unknown as number; this.client._feeCushion = undefined as unknown as number;
const fee = await client.getFee(); const fee = await this.client.getFee();
assert.strictEqual(fee, "0.000012"); assert.strictEqual(fee, "0.000012");
}, });
"getFee - high load_factor": async (client, address, mockRippled) => { it("getFee - high load_factor", async function () {
mockRippled.addResponse("server_info", rippled.server_info.highLoadFactor); this.mockRippled.addResponse(
const fee = await client.getFee(); "server_info",
rippled.server_info.highLoadFactor
);
const fee = await this.client.getFee();
assert.strictEqual(fee, "2"); assert.strictEqual(fee, "2");
}, });
"getFee - high load_factor with custom maxFeeXRP": async ( it("getFee - high load_factor with custom maxFeeXRP", async function () {
client, this.mockRippled.addResponse(
address, "server_info",
mockRippled rippled.server_info.highLoadFactor
) => { );
mockRippled.addResponse("server_info", rippled.server_info.highLoadFactor);
// Ensure that overriding with high maxFeeXRP of '51540' causes no errors. // Ensure that overriding with high maxFeeXRP of '51540' causes no errors.
// (fee will actually be 51539.607552) // (fee will actually be 51539.607552)
client._maxFeeXRP = "51540"; this.client._maxFeeXRP = "51540";
const fee = await client.getFee(); const fee = await this.client.getFee();
assert.strictEqual(fee, "51539.607552"); assert.strictEqual(fee, "51539.607552");
}, });
"getFee custom cushion": async (client, address, mockRippled) => { it("getFee custom cushion", async function () {
mockRippled.addResponse("server_info", rippled.server_info.normal); this.mockRippled.addResponse("server_info", rippled.server_info.normal);
client._feeCushion = 1.4; this.client._feeCushion = 1.4;
const fee = await client.getFee(); const fee = await this.client.getFee();
assert.strictEqual(fee, "0.000014"); assert.strictEqual(fee, "0.000014");
}, });
// This is not recommended since it may result in attempting to pay // This is not recommended since it may result in attempting to pay
// less than the base fee. However, this test verifies the existing behavior. // less than the base fee. However, this test verifies the existing behavior.
"getFee cushion less than 1.0": async (client, address, mockRippled) => { it("getFee cushion less than 1.0", async function () {
mockRippled.addResponse("server_info", rippled.server_info.normal); this.mockRippled.addResponse("server_info", rippled.server_info.normal);
client._feeCushion = 0.9; this.client._feeCushion = 0.9;
const fee = await client.getFee(); const fee = await this.client.getFee();
assert.strictEqual(fee, "0.000009"); assert.strictEqual(fee, "0.000009");
}, });
"getFee reporting": async (client, address, mockRippled) => { it("getFee reporting", async function () {
mockRippled.addResponse("server_info", rippled.server_info.normal); this.mockRippled.addResponse("server_info", rippled.server_info.normal);
const fee = await client.getFee(); const fee = await this.client.getFee();
assert.strictEqual(fee, "0.000012"); assert.strictEqual(fee, "0.000012");
}, });
}; });
});
});

View File

@@ -4,7 +4,8 @@ import { BookOffersRequest } from "../../src";
import requests from "../fixtures/requests"; import requests from "../fixtures/requests";
import responses from "../fixtures/responses"; import responses from "../fixtures/responses";
import rippled from "../fixtures/rippled"; import rippled from "../fixtures/rippled";
import { TestSuite, assertResultMatch, assertRejects } from "../testUtils"; import setupClient from "../setupClient";
import { addressTests, assertResultMatch, assertRejects } from "../testUtils";
// import BigNumber from 'bignumber.js' // import BigNumber from 'bignumber.js'
// function checkSortingOfOrders(orders) { // function checkSortingOfOrders(orders) {
@@ -81,43 +82,50 @@ function xrpRippledResponse(request: BookOffersRequest): object {
throw new Error("unexpected end"); throw new Error("unexpected end");
} }
/** describe("client.getOrderbook", function () {
* Every test suite exports their tests in the default object. beforeEach(setupClient.setup);
* - Check out the "TestSuite" type for documentation on the interface. afterEach(setupClient.teardown);
* - Check out "test/client/index.ts" for more information about the test runner.
*/ addressTests.forEach(function (test) {
export default <TestSuite>{ describe(test.type, function () {
async normal(client, address, mockRippled) { it("normal", async function () {
mockRippled.addResponse("book_offers", normalRippledResponse); this.mockRippled.addResponse("book_offers", normalRippledResponse);
const response = await client.getOrderbook( const response = await this.client.getOrderbook(
address, test.address,
requests.getOrderbook.normal, requests.getOrderbook.normal,
{ limit: 20 } { limit: 20 }
); );
assertResultMatch(response, responses.getOrderbook.normal, "getOrderbook"); assertResultMatch(
}, response,
responses.getOrderbook.normal,
"getOrderbook"
);
});
"invalid options": async (client, address, mockRippled) => { it("invalid options", async function () {
mockRippled.addResponse("book_offers", normalRippledResponse); this.mockRippled.addResponse("book_offers", normalRippledResponse);
assertRejects( assertRejects(
client.getOrderbook(address, requests.getOrderbook.normal, { this.client.getOrderbook(test.address, requests.getOrderbook.normal, {
// @ts-expect-error
invalid: "options", invalid: "options",
}), }),
client.errors.ValidationError this.client.errors.ValidationError
); );
}, });
"with XRP": async (client, address, mockRippled) => { it("with XRP", async function () {
mockRippled.addResponse("book_offers", xrpRippledResponse); this.mockRippled.addResponse("book_offers", xrpRippledResponse);
const response = await client.getOrderbook( const response = await this.client.getOrderbook(
address, test.address,
requests.getOrderbook.withXRP requests.getOrderbook.withXRP
); );
assertResultMatch(response, responses.getOrderbook.withXRP, "getOrderbook"); assertResultMatch(
}, response,
responses.getOrderbook.withXRP,
"getOrderbook"
);
});
// 'sample XRP/JPY book has orders sorted correctly': async (client, address, mockRippled) => { // 'sample XRP/JPY book has orders sorted correctly', async function () {
// const orderbookInfo = { // const orderbookInfo = {
// base: { // base: {
// // the first currency in pair // // the first currency in pair
@@ -129,12 +137,12 @@ export default <TestSuite>{
// } // }
// } // }
// const myAddress = 'rE9qNjzJXpiUbVomdv7R4xhrXVeH2oVmGR' // const myAddress = 'rE9qNjzJXpiUbVomdv7R4xhrXVeH2oVmGR'
// const response = await client.getOrderbook(myAddress, orderbookInfo) // const response = await this.client.getOrderbook(myAddress, orderbookInfo)
// assert.deepStrictEqual([], response.bids) // assert.deepStrictEqual([], response.bids)
// checkSortingOfOrders(response.asks) // checkSortingOfOrders(response.asks)
// }, // },
// 'sample USD/XRP book has orders sorted correctly': async (client, address, mockRippled) => { // 'sample USD/XRP book has orders sorted correctly', async function () {
// const orderbookInfo = { // const orderbookInfo = {
// counter: {currency: 'XRP'}, // counter: {currency: 'XRP'},
// base: { // base: {
@@ -143,20 +151,16 @@ export default <TestSuite>{
// } // }
// } // }
// const myAddress = 'rE9qNjzJXpiUbVomdv7R4xhrXVeH2oVmGR' // const myAddress = 'rE9qNjzJXpiUbVomdv7R4xhrXVeH2oVmGR'
// const response = await client.getOrderbook(myAddress, orderbookInfo) // const response = await this.client.getOrderbook(myAddress, orderbookInfo)
// checkSortingOfOrders(response.bids) // checkSortingOfOrders(response.bids)
// checkSortingOfOrders(response.asks) // checkSortingOfOrders(response.asks)
// }, // },
// WARNING: This test fails to catch the sorting bug, issue #766 // WARNING: This test fails to catch the sorting bug, issue #766
"sorted so that best deals come first [bad test]": async ( it("sorted so that best deals come first [bad test]", async function () {
client, this.mockRippled.addResponse("book_offers", normalRippledResponse);
address, const response = await this.client.getOrderbook(
mockRippled test.address,
) => {
mockRippled.addResponse("book_offers", normalRippledResponse);
const response = await client.getOrderbook(
address,
requests.getOrderbook.normal requests.getOrderbook.normal
); );
const bidRates = response.bids.map( const bidRates = response.bids.map(
@@ -176,16 +180,12 @@ export default <TestSuite>{
askRates.sort((x) => Number(x)), askRates.sort((x) => Number(x)),
askRates askRates
); );
}, });
"currency & counterparty are correct": async ( it("currency & counterparty are correct", async function () {
client, this.mockRippled.addResponse("book_offers", normalRippledResponse);
address, const response = await this.client.getOrderbook(
mockRippled test.address,
) => {
mockRippled.addResponse("book_offers", normalRippledResponse);
const response = await client.getOrderbook(
address,
requests.getOrderbook.normal requests.getOrderbook.normal
); );
[...response.bids, ...response.asks].forEach((order) => { [...response.bids, ...response.asks].forEach((order) => {
@@ -197,21 +197,21 @@ export default <TestSuite>{
assert.strictEqual(totalPrice.currency, counter.currency); assert.strictEqual(totalPrice.currency, counter.currency);
assert.strictEqual(totalPrice.counterparty, counter.counterparty); assert.strictEqual(totalPrice.counterparty, counter.counterparty);
}); });
}, });
"direction is correct for bids and asks": async ( it("direction is correct for bids and asks", async function () {
client, this.mockRippled.addResponse("book_offers", normalRippledResponse);
address, const response = await this.client.getOrderbook(
mockRippled test.address,
) => {
mockRippled.addResponse("book_offers", normalRippledResponse);
const response = await client.getOrderbook(
address,
requests.getOrderbook.normal requests.getOrderbook.normal
); );
assert(response.bids.every((bid) => bid.specification.direction === "buy")); assert(
response.bids.every((bid) => bid.specification.direction === "buy")
);
assert( assert(
response.asks.every((ask) => ask.specification.direction === "sell") response.asks.every((ask) => ask.specification.direction === "sell")
); );
}, });
}; });
});
});

View File

@@ -3,7 +3,8 @@ import { assert } from "chai";
import addresses from "../fixtures/addresses.json"; import addresses from "../fixtures/addresses.json";
import requests from "../fixtures/requests"; import requests from "../fixtures/requests";
import rippled from "../fixtures/rippled"; import rippled from "../fixtures/rippled";
import { assertRejects, TestSuite } from "../testUtils"; import setupClient from "../setupClient";
import { assertRejects } from "../testUtils";
// import responses from '../fixtures/responses' // import responses from '../fixtures/responses'
const { getPaths: REQUEST_FIXTURES } = requests; const { getPaths: REQUEST_FIXTURES } = requests;
// const {getPaths: RESPONSE_FIXTURES} = responses // const {getPaths: RESPONSE_FIXTURES} = responses
@@ -15,97 +16,94 @@ const rippledResponse = rippled.path_find.generate.generateIOUPaymentPaths(
REQUEST_FIXTURES.normal.destination.amount REQUEST_FIXTURES.normal.destination.amount
); );
/** describe("client.getPaths", function () {
* Every test suite exports their tests in the default object. beforeEach(setupClient.setup);
* - Check out the "TestSuite" type for documentation on the interface. afterEach(setupClient.teardown);
* - Check out "test/client/index.ts" for more information about the test runner. // 'simple test', function () {
*/ // const response = await this.client.getPaths(REQUEST_FIXTURES.normal)
export default <TestSuite>{
// 'simple test': async (client) => {
// const response = await client.getPaths(REQUEST_FIXTURES.normal)
// assertResultMatch(response, RESPONSE_FIXTURES.XrpToUsd, 'getPaths') // assertResultMatch(response, RESPONSE_FIXTURES.XrpToUsd, 'getPaths')
// }, // })
// 'queuing': async (client) => { // 'queuing', function () {
// const [normalResult, usdOnlyResult, xrpOnlyResult] = await Promise.all([ // const [normalResult, usdOnlyResult, xrpOnlyResult] = await Promise.all([
// client.getPaths(REQUEST_FIXTURES.normal), // this.client.getPaths(REQUEST_FIXTURES.normal),
// client.getPaths(REQUEST_FIXTURES.UsdToUsd), // this.client.getPaths(REQUEST_FIXTURES.UsdToUsd),
// client.getPaths(REQUEST_FIXTURES.XrpToXrp) // this.client.getPaths(REQUEST_FIXTURES.XrpToXrp)
// ]) // ])
// assertResultMatch(normalResult, RESPONSE_FIXTURES.XrpToUsd, 'getPaths') // assertResultMatch(normalResult, RESPONSE_FIXTURES.XrpToUsd, 'getPaths')
// assertResultMatch(usdOnlyResult, RESPONSE_FIXTURES.UsdToUsd, 'getPaths') // assertResultMatch(usdOnlyResult, RESPONSE_FIXTURES.UsdToUsd, 'getPaths')
// assertResultMatch(xrpOnlyResult, RESPONSE_FIXTURES.XrpToXrp, 'getPaths') // assertResultMatch(xrpOnlyResult, RESPONSE_FIXTURES.XrpToXrp, 'getPaths')
// }, // })
// // @TODO // // @TODO
// // need decide what to do with currencies/XRP: // // need decide what to do with currencies/XRP:
// // if add 'XRP' in currencies, then there will be exception in // // if add 'XRP' in currencies, then there will be exception in
// // xrpToDrops function (called from toRippledAmount) // // xrpToDrops function (called from toRippledAmount)
// 'getPaths USD 2 USD': async (client) => { // 'getPaths USD 2 USD', function () {
// const response = await client.getPaths(REQUEST_FIXTURES.UsdToUsd) // const response = await this.client.getPaths(REQUEST_FIXTURES.UsdToUsd)
// assertResultMatch(response, RESPONSE_FIXTURES.UsdToUsd, 'getPaths') // assertResultMatch(response, RESPONSE_FIXTURES.UsdToUsd, 'getPaths')
// }, // })
// 'getPaths XRP 2 XRP': async (client) => { // 'getPaths XRP 2 XRP', function () {
// const response = await client.getPaths(REQUEST_FIXTURES.XrpToXrp) // const response = await this.client.getPaths(REQUEST_FIXTURES.XrpToXrp)
// assertResultMatch(response, RESPONSE_FIXTURES.XrpToXrp, 'getPaths') // assertResultMatch(response, RESPONSE_FIXTURES.XrpToXrp, 'getPaths')
// }, // })
"source with issuer": async (client, _, mockRippled) => { it("source with issuer", function () {
mockRippled.addResponse("ripple_path_find", rippledResponse); this.mockRippled.addResponse("ripple_path_find", rippledResponse);
return assertRejects( return assertRejects(
client.getPaths(REQUEST_FIXTURES.issuer), this.client.getPaths(REQUEST_FIXTURES.issuer),
client.errors.NotFoundError this.client.errors.NotFoundError
); );
}, });
// 'XRP 2 XRP - not enough': async (client) => { // 'XRP 2 XRP - not enough', function () {
// return assertRejects( // return assertRejects(
// client.getPaths(REQUEST_FIXTURES.XrpToXrpNotEnough), // this.client.getPaths(REQUEST_FIXTURES.XrpToXrpNotEnough),
// client.errors.NotFoundError // this.client.errors.NotFoundError
// ) // )
// }, // })
"invalid PathFind": async (client, _, mockRippled) => { it("invalid PathFind", function () {
mockRippled.addResponse("ripple_path_find", rippledResponse); this.mockRippled.addResponse("ripple_path_find", rippledResponse);
assert.throws(() => { assert.throws(() => {
client.getPaths(REQUEST_FIXTURES.invalid); this.client.getPaths(REQUEST_FIXTURES.invalid);
}, /Cannot specify both source.amount/); }, /Cannot specify both source.amount/);
}, });
"does not accept currency": async (client, _, mockRippled) => { it("does not accept currency", function () {
mockRippled.addResponse("ripple_path_find", rippledResponse); this.mockRippled.addResponse("ripple_path_find", rippledResponse);
return assertRejects( return assertRejects(
client.getPaths(REQUEST_FIXTURES.NotAcceptCurrency), this.client.getPaths(REQUEST_FIXTURES.NotAcceptCurrency),
client.errors.NotFoundError this.client.errors.NotFoundError
); );
}, });
"no paths": async (client, _, mockRippled) => { it("no paths", function () {
mockRippled.addResponse("ripple_path_find", rippledResponse); this.mockRippled.addResponse("ripple_path_find", rippledResponse);
return assertRejects( return assertRejects(
client.getPaths(REQUEST_FIXTURES.NoPaths), this.client.getPaths(REQUEST_FIXTURES.NoPaths),
client.errors.NotFoundError this.client.errors.NotFoundError
); );
}, });
"no paths source amount": async (client, _, mockRippled) => { it("no paths source amount", function () {
mockRippled.addResponse("ripple_path_find", rippledResponse); this.mockRippled.addResponse("ripple_path_find", rippledResponse);
return assertRejects( return assertRejects(
client.getPaths(REQUEST_FIXTURES.NoPathsSource), this.client.getPaths(REQUEST_FIXTURES.NoPathsSource),
client.errors.NotFoundError this.client.errors.NotFoundError
); );
}, });
"no paths with source currencies": async (client, _, mockRippled) => { it("no paths with source currencies", function () {
mockRippled.addResponse("ripple_path_find", rippledResponse); this.mockRippled.addResponse("ripple_path_find", rippledResponse);
return assertRejects( return assertRejects(
client.getPaths(REQUEST_FIXTURES.NoPathsWithCurrencies), this.client.getPaths(REQUEST_FIXTURES.NoPathsWithCurrencies),
client.errors.NotFoundError this.client.errors.NotFoundError
); );
}, });
"error: srcActNotFound": async (client, _, mockRippled) => { it("error: srcActNotFound", function () {
mockRippled.addResponse("ripple_path_find", rippledResponse); this.mockRippled.addResponse("ripple_path_find", rippledResponse);
return assertRejects( return assertRejects(
client.getPaths({ this.client.getPaths({
...REQUEST_FIXTURES.normal, ...REQUEST_FIXTURES.normal,
source: { address: addresses.NOTFOUND }, source: { address: addresses.NOTFOUND },
}), }),
client.errors.RippleError this.client.errors.RippleError
); );
}, });
// 'send all': async (client) => { // 'send all', function () {
// const response = await client.getPaths(REQUEST_FIXTURES.sendAll) // const response = await this.client.getPaths(REQUEST_FIXTURES.sendAll)
// assertResultMatch(response, RESPONSE_FIXTURES.sendAll, 'getPaths') // assertResultMatch(response, RESPONSE_FIXTURES.sendAll, 'getPaths')
// } // })
}; });

View File

@@ -1,64 +1,52 @@
import addresses from "../fixtures/addresses.json";
import responses from "../fixtures/responses"; import responses from "../fixtures/responses";
import rippled from "../fixtures/rippled/accountLines"; import rippled from "../fixtures/rippled/accountLines";
import { assertResultMatch, TestSuite } from "../testUtils"; import setupClient from "../setupClient";
import { assertResultMatch, addressTests } from "../testUtils";
const { getTrustlines: RESPONSE_FIXTURES } = responses; const { getTrustlines: RESPONSE_FIXTURES } = responses;
/** describe("client.getTrustlines", function () {
* Every test suite exports their tests in the default object. beforeEach(setupClient.setup);
* - Check out the "TestSuite" type for documentation on the interface. afterEach(setupClient.teardown);
* - Check out "test/client/index.ts" for more information about the test runner.
*/
export default <TestSuite>{
"getTrustlines - filtered": async (client, address, mockRippled) => {
mockRippled.addResponse("account_lines", rippled.normal);
const options = { currency: "USD" };
const result = await client.getTrustlines(address, options);
assertResultMatch(result, RESPONSE_FIXTURES.filtered, "getTrustlines");
},
"getTrustlines - more than 400 items": async ( addressTests.forEach(function (test) {
client, describe(test.type, function () {
address, it("getTrustlines - filtered", async function () {
mockRippled this.mockRippled.addResponse("account_lines", rippled.normal);
) => { const options = { currency: "USD" };
mockRippled.addResponse("account_lines", rippled.manyItems); const result = await this.client.getTrustlines(test.address, options);
assertResultMatch(result, RESPONSE_FIXTURES.filtered, "getTrustlines");
});
it("getTrustlines - more than 400 items", async function () {
this.mockRippled.addResponse("account_lines", rippled.manyItems);
const options = { limit: 401 }; const options = { limit: 401 };
const result = await client.getTrustlines(address, options); const result = await this.client.getTrustlines(test.address, options);
assertResultMatch( assertResultMatch(
result, result,
RESPONSE_FIXTURES.moreThan400Items, RESPONSE_FIXTURES.moreThan400Items,
"getTrustlines" "getTrustlines"
); );
}, });
"getTrustlines - no options": async (client, address, mockRippled) => { it("getTrustlines - no options", async function () {
mockRippled.addResponse("account_lines", rippled.normal); this.mockRippled.addResponse("account_lines", rippled.normal);
await client.getTrustlines(address); await this.client.getTrustlines(test.address);
}, });
"getTrustlines - ripplingDisabled works properly": async ( it("getTrustlines - ripplingDisabled works properly", async function () {
client, this.mockRippled.addResponse("account_lines", rippled.ripplingDisabled);
address, const result = await this.client.getTrustlines(test.address);
mockRippled
) => {
mockRippled.addResponse("account_lines", rippled.ripplingDisabled);
const result = await client.getTrustlines(address);
assertResultMatch( assertResultMatch(
result, result,
RESPONSE_FIXTURES.ripplingDisabled, RESPONSE_FIXTURES.ripplingDisabled,
"getTrustlines" "getTrustlines"
); );
}, });
"getTrustlines - ledger version option": async ( it("getTrustlines - ledger version option", async function () {
client, this.mockRippled.addResponse("account_lines", rippled.manyItems);
address, const result = await this.client.getTrustlines(test.address, {
mockRippled
) => {
mockRippled.addResponse("account_lines", rippled.manyItems);
const result = await client.getTrustlines(addresses.FOURTH_ACCOUNT, {
ledgerVersion: 5, ledgerVersion: 5,
}); });
assertResultMatch( assertResultMatch(
@@ -66,5 +54,7 @@ export default <TestSuite>{
RESPONSE_FIXTURES.moreThan400Items, RESPONSE_FIXTURES.moreThan400Items,
"getTrustlines" "getTrustlines"
); );
}, });
}; });
});
});

View File

@@ -1,41 +1,31 @@
import { assert } from "chai"; import { assert } from "chai";
import rippled from "../fixtures/rippled"; import rippled from "../fixtures/rippled";
import { TestSuite } from "../testUtils"; import setupClient from "../setupClient";
/** describe("client.hasNextPage", function () {
* Every test suite exports their tests in the default object. beforeEach(setupClient.setup);
* - Check out the "TestSuite" type for documentation on the interface. afterEach(setupClient.teardown);
* - Check out "test/client/index.ts" for more information about the test runner.
*/
export default <TestSuite>{
"returns true when there is another page": async (
client,
address,
mockRippled
) => {
mockRippled.addResponse("ledger_data", rippled.ledger_data.first_page);
const response = await client.request({ command: "ledger_data" });
assert(client.hasNextPage(response));
},
"returns false when there are no more pages": async ( it("returns true when there is another page", async function () {
client, this.mockRippled.addResponse("ledger_data", rippled.ledger_data.first_page);
address, const response = await this.client.request({ command: "ledger_data" });
mockRippled assert(this.client.hasNextPage(response));
) => { });
it("returns false when there are no more pages", async function () {
const rippledResponse = function (request: Request): object { const rippledResponse = function (request: Request): object {
if ("marker" in request) { if ("marker" in request) {
return rippled.ledger_data.last_page; return rippled.ledger_data.last_page;
} }
return rippled.ledger_data.first_page; return rippled.ledger_data.first_page;
}; };
mockRippled.addResponse("ledger_data", rippledResponse); this.mockRippled.addResponse("ledger_data", rippledResponse);
const response = await client.request({ command: "ledger_data" }); const response = await this.client.request({ command: "ledger_data" });
const responseNextPage = await client.requestNextPage( const responseNextPage = await this.client.requestNextPage(
{ command: "ledger_data" }, { command: "ledger_data" },
response response
); );
assert(!client.hasNextPage(responseNextPage)); assert(!this.client.hasNextPage(responseNextPage));
}, });
}; });

View File

@@ -1,16 +1,14 @@
import { assert } from "chai"; import { assert } from "chai";
import { TestSuite } from "../testUtils"; import setupClient from "../setupClient";
/** describe("client.isConnected", function () {
* Every test suite exports their tests in the default object. beforeEach(setupClient.setup);
* - Check out the "TestSuite" type for documentation on the interface. afterEach(setupClient.teardown);
* - Check out "test/client/index.ts" for more information about the test runner.
*/ it("disconnect & isConnected", async function () {
export default <TestSuite>{ assert.strictEqual(this.client.isConnected(), true);
"disconnect & isConnected": async (client, address) => { await this.client.disconnect();
assert.strictEqual(client.isConnected(), true); assert.strictEqual(this.client.isConnected(), false);
await client.disconnect(); });
assert.strictEqual(client.isConnected(), false); });
},
};

View File

@@ -1,18 +1,21 @@
import { assert } from "chai"; import { assert } from "chai";
import addresses from "../fixtures/addresses.json"; import addresses from "../fixtures/addresses.json";
import { TestSuite } from "../testUtils"; import setupClient from "../setupClient";
export default <TestSuite>{ describe("isValidAddress", function () {
"returns true for valid address": async (client, address) => { beforeEach(setupClient.setup);
assert(client.isValidAddress("rLczgQHxPhWtjkaQqn3Q6UM8AbRbbRvs5K")); afterEach(setupClient.teardown);
assert(client.isValidAddress(addresses.ACCOUNT_X));
assert(client.isValidAddress(addresses.ACCOUNT_T));
},
"returns false for invalid address": async (client, address) => { it("returns true for valid address", async function () {
assert(!client.isValidAddress("foobar")); assert(this.client.isValidAddress("rLczgQHxPhWtjkaQqn3Q6UM8AbRbbRvs5K"));
assert(!client.isValidAddress(addresses.ACCOUNT_X.slice(0, -1))); assert(this.client.isValidAddress(addresses.ACCOUNT_X));
assert(!client.isValidAddress(addresses.ACCOUNT_T.slice(1))); assert(this.client.isValidAddress(addresses.ACCOUNT_T));
}, });
};
it("returns false for invalid address", async function () {
assert(!this.client.isValidAddress("foobar"));
assert(!this.client.isValidAddress(addresses.ACCOUNT_X.slice(0, -1)));
assert(!this.client.isValidAddress(addresses.ACCOUNT_T.slice(1)));
});
});

View File

@@ -1,13 +1,16 @@
import { assert } from "chai"; import { assert } from "chai";
import { TestSuite } from "../testUtils"; import setupClient from "../setupClient";
export default <TestSuite>{ describe("isValidSecret", function () {
"returns true for valid secret": async (client, address) => { beforeEach(setupClient.setup);
assert(client.isValidSecret("snsakdSrZSLkYpCXxfRkS4Sh96PMK")); afterEach(setupClient.teardown);
},
"returns false for invalid secret": async (client, address) => { it("returns true for valid secret", async function () {
assert(!client.isValidSecret("foobar")); assert(this.client.isValidSecret("snsakdSrZSLkYpCXxfRkS4Sh96PMK"));
}, });
};
it("returns false for invalid secret", async function () {
assert(!this.client.isValidSecret("foobar"));
});
});

View File

@@ -1,43 +1,60 @@
import requests from "../fixtures/requests"; import requests from "../fixtures/requests";
import responses from "../fixtures/responses"; import responses from "../fixtures/responses";
import rippled from "../fixtures/rippled"; import rippled from "../fixtures/rippled";
import { assertResultMatch, TestSuite } from "../testUtils"; import setupClient from "../setupClient";
import { assertResultMatch, addressTests } from "../testUtils";
const instructionsWithMaxLedgerVersionOffset = { maxLedgerVersionOffset: 100 }; const instructionsWithMaxLedgerVersionOffset = { maxLedgerVersionOffset: 100 };
/** describe("client.prepareCheckCancel", function () {
* Every test suite exports their tests in the default object. beforeEach(setupClient.setup);
* - Check out the "TestSuite" type for documentation on the interface. afterEach(setupClient.teardown);
* - Check out "test/client/index.ts" for more information about the test runner.
*/ addressTests.forEach(function (test) {
export default <TestSuite>{ describe(test.type, function () {
async prepareCheckCancel(client, address, mockRippled) { it("prepareCheckCancel", async function () {
mockRippled.addResponse("server_info", rippled.server_info.normal); this.mockRippled.addResponse("server_info", rippled.server_info.normal);
mockRippled.addResponse("fee", rippled.fee); this.mockRippled.addResponse("fee", rippled.fee);
mockRippled.addResponse("ledger_current", rippled.ledger_current); this.mockRippled.addResponse("ledger_current", rippled.ledger_current);
mockRippled.addResponse("account_info", rippled.account_info.normal); this.mockRippled.addResponse(
const result = await client.prepareCheckCancel( "account_info",
address, rippled.account_info.normal
);
const result = await this.client.prepareCheckCancel(
test.address,
requests.prepareCheckCancel.normal requests.prepareCheckCancel.normal
); );
assertResultMatch(result, responses.prepareCheckCancel.normal, "prepare"); assertResultMatch(
}, result,
responses.prepareCheckCancel.normal,
"prepare"
);
});
"with ticket": async (client, address, mockRippled) => { it("with ticket", async function () {
mockRippled.addResponse("server_info", rippled.server_info.normal); this.mockRippled.addResponse("server_info", rippled.server_info.normal);
mockRippled.addResponse("fee", rippled.fee); this.mockRippled.addResponse("fee", rippled.fee);
mockRippled.addResponse("ledger_current", rippled.ledger_current); this.mockRippled.addResponse("ledger_current", rippled.ledger_current);
mockRippled.addResponse("account_info", rippled.account_info.normal); this.mockRippled.addResponse(
"account_info",
rippled.account_info.normal
);
const localInstructions = { const localInstructions = {
...instructionsWithMaxLedgerVersionOffset, ...instructionsWithMaxLedgerVersionOffset,
maxFee: "0.000012", maxFee: "0.000012",
ticketSequence: 23, ticketSequence: 23,
}; };
const result = await client.prepareCheckCancel( const result = await this.client.prepareCheckCancel(
address, test.address,
requests.prepareCheckCancel.normal, requests.prepareCheckCancel.normal,
localInstructions localInstructions
); );
assertResultMatch(result, responses.prepareCheckCancel.ticket, "prepare"); assertResultMatch(
}, result,
}; responses.prepareCheckCancel.ticket,
"prepare"
);
});
});
});
});

View File

@@ -1,55 +1,71 @@
import requests from "../fixtures/requests"; import requests from "../fixtures/requests";
import responses from "../fixtures/responses"; import responses from "../fixtures/responses";
import rippled from "../fixtures/rippled"; import rippled from "../fixtures/rippled";
import { assertResultMatch, TestSuite } from "../testUtils"; import setupClient from "../setupClient";
import { assertResultMatch, addressTests } from "../testUtils";
const instructionsWithMaxLedgerVersionOffset = { maxLedgerVersionOffset: 100 }; const instructionsWithMaxLedgerVersionOffset = { maxLedgerVersionOffset: 100 };
/** describe("client.prepareCheckCash", function () {
* Every test suite exports their tests in the default object. beforeEach(setupClient.setup);
* - Check out the "TestSuite" type for documentation on the interface. afterEach(setupClient.teardown);
* - Check out "test/client/index.ts" for more information about the test runner.
*/ addressTests.forEach(function (test) {
export default <TestSuite>{ describe(test.type, function () {
"prepareCheckCash amount": async (client, address, mockRippled) => { it("prepareCheckCash amount", async function () {
mockRippled.addResponse("server_info", rippled.server_info.normal); this.mockRippled.addResponse("server_info", rippled.server_info.normal);
mockRippled.addResponse("fee", rippled.fee); this.mockRippled.addResponse("fee", rippled.fee);
mockRippled.addResponse("ledger_current", rippled.ledger_current); this.mockRippled.addResponse("ledger_current", rippled.ledger_current);
mockRippled.addResponse("account_info", rippled.account_info.normal); this.mockRippled.addResponse(
const result = await client.prepareCheckCash( "account_info",
address, rippled.account_info.normal
);
const result = await this.client.prepareCheckCash(
test.address,
requests.prepareCheckCash.amount requests.prepareCheckCash.amount
); );
assertResultMatch(result, responses.prepareCheckCash.amount, "prepare"); assertResultMatch(result, responses.prepareCheckCash.amount, "prepare");
}, });
"prepareCheckCash deliverMin": async (client, address, mockRippled) => { it("prepareCheckCash deliverMin", async function () {
mockRippled.addResponse("server_info", rippled.server_info.normal); this.mockRippled.addResponse("server_info", rippled.server_info.normal);
mockRippled.addResponse("fee", rippled.fee); this.mockRippled.addResponse("fee", rippled.fee);
mockRippled.addResponse("ledger_current", rippled.ledger_current); this.mockRippled.addResponse("ledger_current", rippled.ledger_current);
mockRippled.addResponse("account_info", rippled.account_info.normal); this.mockRippled.addResponse(
const result = await client.prepareCheckCash( "account_info",
address, rippled.account_info.normal
);
const result = await this.client.prepareCheckCash(
test.address,
requests.prepareCheckCash.deliverMin requests.prepareCheckCash.deliverMin
); );
assertResultMatch(result, responses.prepareCheckCash.deliverMin, "prepare"); assertResultMatch(
}, result,
responses.prepareCheckCash.deliverMin,
"prepare"
);
});
"with ticket": async (client, address, mockRippled) => { it("with ticket", async function () {
mockRippled.addResponse("server_info", rippled.server_info.normal); this.mockRippled.addResponse("server_info", rippled.server_info.normal);
mockRippled.addResponse("fee", rippled.fee); this.mockRippled.addResponse("fee", rippled.fee);
mockRippled.addResponse("ledger_current", rippled.ledger_current); this.mockRippled.addResponse("ledger_current", rippled.ledger_current);
mockRippled.addResponse("account_info", rippled.account_info.normal); this.mockRippled.addResponse(
"account_info",
rippled.account_info.normal
);
const localInstructions = { const localInstructions = {
...instructionsWithMaxLedgerVersionOffset, ...instructionsWithMaxLedgerVersionOffset,
maxFee: "0.000012", maxFee: "0.000012",
ticketSequence: 23, ticketSequence: 23,
}; };
const result = await client.prepareCheckCash( const result = await this.client.prepareCheckCash(
address, test.address,
requests.prepareCheckCash.amount, requests.prepareCheckCash.amount,
localInstructions localInstructions
); );
assertResultMatch(result, responses.prepareCheckCash.ticket, "prepare"); assertResultMatch(result, responses.prepareCheckCash.ticket, "prepare");
}, });
}; });
});
});

View File

@@ -1,60 +1,80 @@
import requests from "../fixtures/requests"; import requests from "../fixtures/requests";
import responses from "../fixtures/responses"; import responses from "../fixtures/responses";
import rippled from "../fixtures/rippled"; import rippled from "../fixtures/rippled";
import { assertResultMatch, TestSuite } from "../testUtils"; import setupClient from "../setupClient";
import { assertResultMatch, addressTests } from "../testUtils";
const instructionsWithMaxLedgerVersionOffset = { maxLedgerVersionOffset: 100 }; const instructionsWithMaxLedgerVersionOffset = { maxLedgerVersionOffset: 100 };
/** describe("client.prepareCheckCreate", function () {
* Every test suite exports their tests in the default object. beforeEach(setupClient.setup);
* - Check out the "TestSuite" type for documentation on the interface. afterEach(setupClient.teardown);
* - Check out "test/client/index.ts" for more information about the test runner.
*/ addressTests.forEach(function (test) {
export default <TestSuite>{ describe(test.type, function () {
async prepareCheckCreate(client, address, mockRippled) { it("prepareCheckCreate", async function () {
mockRippled.addResponse("server_info", rippled.server_info.normal); this.mockRippled.addResponse("server_info", rippled.server_info.normal);
mockRippled.addResponse("fee", rippled.fee); this.mockRippled.addResponse("fee", rippled.fee);
mockRippled.addResponse("ledger_current", rippled.ledger_current); this.mockRippled.addResponse("ledger_current", rippled.ledger_current);
mockRippled.addResponse("account_info", rippled.account_info.normal); this.mockRippled.addResponse(
"account_info",
rippled.account_info.normal
);
const localInstructions = { const localInstructions = {
...instructionsWithMaxLedgerVersionOffset, ...instructionsWithMaxLedgerVersionOffset,
maxFee: "0.000012", maxFee: "0.000012",
}; };
const result = await client.prepareCheckCreate( const result = await this.client.prepareCheckCreate(
address, test.address,
requests.prepareCheckCreate.normal, requests.prepareCheckCreate.normal,
localInstructions localInstructions
); );
assertResultMatch(result, responses.prepareCheckCreate.normal, "prepare"); assertResultMatch(
}, result,
responses.prepareCheckCreate.normal,
"prepare"
);
});
"prepareCheckCreate full": async (client, address, mockRippled) => { it("prepareCheckCreate full", async function () {
mockRippled.addResponse("server_info", rippled.server_info.normal); this.mockRippled.addResponse("server_info", rippled.server_info.normal);
mockRippled.addResponse("fee", rippled.fee); this.mockRippled.addResponse("fee", rippled.fee);
mockRippled.addResponse("ledger_current", rippled.ledger_current); this.mockRippled.addResponse("ledger_current", rippled.ledger_current);
mockRippled.addResponse("account_info", rippled.account_info.normal); this.mockRippled.addResponse(
const result = await client.prepareCheckCreate( "account_info",
address, rippled.account_info.normal
);
const result = await this.client.prepareCheckCreate(
test.address,
requests.prepareCheckCreate.full requests.prepareCheckCreate.full
); );
assertResultMatch(result, responses.prepareCheckCreate.full, "prepare"); assertResultMatch(result, responses.prepareCheckCreate.full, "prepare");
}, });
"prepareCheckCreate with ticket": async (client, address, mockRippled) => { it("prepareCheckCreate with ticket", async function () {
mockRippled.addResponse("server_info", rippled.server_info.normal); this.mockRippled.addResponse("server_info", rippled.server_info.normal);
mockRippled.addResponse("fee", rippled.fee); this.mockRippled.addResponse("fee", rippled.fee);
mockRippled.addResponse("ledger_current", rippled.ledger_current); this.mockRippled.addResponse("ledger_current", rippled.ledger_current);
mockRippled.addResponse("account_info", rippled.account_info.normal); this.mockRippled.addResponse(
"account_info",
rippled.account_info.normal
);
const localInstructions = { const localInstructions = {
...instructionsWithMaxLedgerVersionOffset, ...instructionsWithMaxLedgerVersionOffset,
maxFee: "0.000012", maxFee: "0.000012",
ticketSequence: 23, ticketSequence: 23,
}; };
const result = await client.prepareCheckCreate( const result = await this.client.prepareCheckCreate(
address, test.address,
requests.prepareCheckCreate.normal, requests.prepareCheckCreate.normal,
localInstructions localInstructions
); );
assertResultMatch(result, responses.prepareCheckCreate.ticket, "prepare"); assertResultMatch(
}, result,
}; responses.prepareCheckCreate.ticket,
"prepare"
);
});
});
});
});

View File

@@ -1,23 +1,27 @@
import requests from "../fixtures/requests"; import requests from "../fixtures/requests";
import responses from "../fixtures/responses"; import responses from "../fixtures/responses";
import rippled from "../fixtures/rippled"; import rippled from "../fixtures/rippled";
import { assertResultMatch, TestSuite } from "../testUtils"; import setupClient from "../setupClient";
import { assertResultMatch, addressTests } from "../testUtils";
const instructionsWithMaxLedgerVersionOffset = { maxLedgerVersionOffset: 100 }; const instructionsWithMaxLedgerVersionOffset = { maxLedgerVersionOffset: 100 };
/** describe("client.prepareEscrowCancellation", function () {
* Every test suite exports their tests in the default object. beforeEach(setupClient.setup);
* - Check out the "TestSuite" type for documentation on the interface. afterEach(setupClient.teardown);
* - Check out "test/client/index.ts" for more information about the test runner.
*/ addressTests.forEach(function (test) {
export default <TestSuite>{ describe(test.type, function () {
async prepareEscrowCancellation(client, address, mockRippled) { it("prepareEscrowCancellation", async function () {
mockRippled.addResponse("server_info", rippled.server_info.normal); this.mockRippled.addResponse("server_info", rippled.server_info.normal);
mockRippled.addResponse("fee", rippled.fee); this.mockRippled.addResponse("fee", rippled.fee);
mockRippled.addResponse("ledger_current", rippled.ledger_current); this.mockRippled.addResponse("ledger_current", rippled.ledger_current);
mockRippled.addResponse("account_info", rippled.account_info.normal); this.mockRippled.addResponse(
const result = await client.prepareEscrowCancellation( "account_info",
address, rippled.account_info.normal
);
const result = await this.client.prepareEscrowCancellation(
test.address,
requests.prepareEscrowCancellation.normal, requests.prepareEscrowCancellation.normal,
instructionsWithMaxLedgerVersionOffset instructionsWithMaxLedgerVersionOffset
); );
@@ -26,19 +30,18 @@ export default <TestSuite>{
responses.prepareEscrowCancellation.normal, responses.prepareEscrowCancellation.normal,
"prepare" "prepare"
); );
}, });
"prepareEscrowCancellation with memos": async ( it("prepareEscrowCancellation with memos", async function () {
client, this.mockRippled.addResponse("server_info", rippled.server_info.normal);
address, this.mockRippled.addResponse("fee", rippled.fee);
mockRippled this.mockRippled.addResponse("ledger_current", rippled.ledger_current);
) => { this.mockRippled.addResponse(
mockRippled.addResponse("server_info", rippled.server_info.normal); "account_info",
mockRippled.addResponse("fee", rippled.fee); rippled.account_info.normal
mockRippled.addResponse("ledger_current", rippled.ledger_current); );
mockRippled.addResponse("account_info", rippled.account_info.normal); const result = await this.client.prepareEscrowCancellation(
const result = await client.prepareEscrowCancellation( test.address,
address,
requests.prepareEscrowCancellation.memos requests.prepareEscrowCancellation.memos
); );
assertResultMatch( assertResultMatch(
@@ -46,20 +49,23 @@ export default <TestSuite>{
responses.prepareEscrowCancellation.memos, responses.prepareEscrowCancellation.memos,
"prepare" "prepare"
); );
}, });
"with ticket": async (client, address, mockRippled) => { it("with ticket", async function () {
mockRippled.addResponse("server_info", rippled.server_info.normal); this.mockRippled.addResponse("server_info", rippled.server_info.normal);
mockRippled.addResponse("fee", rippled.fee); this.mockRippled.addResponse("fee", rippled.fee);
mockRippled.addResponse("ledger_current", rippled.ledger_current); this.mockRippled.addResponse("ledger_current", rippled.ledger_current);
mockRippled.addResponse("account_info", rippled.account_info.normal); this.mockRippled.addResponse(
"account_info",
rippled.account_info.normal
);
const localInstructions = { const localInstructions = {
...instructionsWithMaxLedgerVersionOffset, ...instructionsWithMaxLedgerVersionOffset,
maxFee: "0.000012", maxFee: "0.000012",
ticketSequence: 23, ticketSequence: 23,
}; };
const result = await client.prepareEscrowCancellation( const result = await this.client.prepareEscrowCancellation(
address, test.address,
requests.prepareEscrowCancellation.normal, requests.prepareEscrowCancellation.normal,
localInstructions localInstructions
); );
@@ -68,5 +74,7 @@ export default <TestSuite>{
responses.prepareEscrowCancellation.ticket, responses.prepareEscrowCancellation.ticket,
"prepare" "prepare"
); );
}, });
}; });
});
});

View File

@@ -1,7 +1,9 @@
import addresses from "../fixtures/addresses.json";
import requests from "../fixtures/requests"; import requests from "../fixtures/requests";
import responses from "../fixtures/responses"; import responses from "../fixtures/responses";
import rippled from "../fixtures/rippled"; import rippled from "../fixtures/rippled";
import { assertRejects, assertResultMatch, TestSuite } from "../testUtils"; import setupClient from "../setupClient";
import { assertRejects, assertResultMatch } from "../testUtils";
const instructionsWithMaxLedgerVersionOffset = { maxLedgerVersionOffset: 100 }; const instructionsWithMaxLedgerVersionOffset = { maxLedgerVersionOffset: 100 };
@@ -12,23 +14,21 @@ export const config = {
skipXAddress: true, skipXAddress: true,
}; };
/** describe("client.prepareEscrowCreation", function () {
* Every test suite exports their tests in the default object. beforeEach(setupClient.setup);
* - Check out the "TestSuite" type for documentation on the interface. afterEach(setupClient.teardown);
* - Check out "test/client/index.ts" for more information about the test runner.
*/ it("prepareEscrowCreation", async function () {
export default <TestSuite>{ this.mockRippled.addResponse("server_info", rippled.server_info.normal);
async prepareEscrowCreation(client, address, mockRippled) { this.mockRippled.addResponse("fee", rippled.fee);
mockRippled.addResponse("server_info", rippled.server_info.normal); this.mockRippled.addResponse("ledger_current", rippled.ledger_current);
mockRippled.addResponse("fee", rippled.fee); this.mockRippled.addResponse("account_info", rippled.account_info.normal);
mockRippled.addResponse("ledger_current", rippled.ledger_current);
mockRippled.addResponse("account_info", rippled.account_info.normal);
const localInstructions = { const localInstructions = {
...instructionsWithMaxLedgerVersionOffset, ...instructionsWithMaxLedgerVersionOffset,
maxFee: "0.000012", maxFee: "0.000012",
}; };
const result = await client.prepareEscrowCreation( const result = await this.client.prepareEscrowCreation(
address, addresses.ACCOUNT,
requests.prepareEscrowCreation.normal, requests.prepareEscrowCreation.normal,
localInstructions localInstructions
); );
@@ -37,46 +37,46 @@ export default <TestSuite>{
responses.prepareEscrowCreation.normal, responses.prepareEscrowCreation.normal,
"prepare" "prepare"
); );
}, });
"prepareEscrowCreation full": async (client, address, mockRippled) => { it("prepareEscrowCreation full", async function () {
mockRippled.addResponse("server_info", rippled.server_info.normal); this.mockRippled.addResponse("server_info", rippled.server_info.normal);
mockRippled.addResponse("fee", rippled.fee); this.mockRippled.addResponse("fee", rippled.fee);
mockRippled.addResponse("ledger_current", rippled.ledger_current); this.mockRippled.addResponse("ledger_current", rippled.ledger_current);
mockRippled.addResponse("account_info", rippled.account_info.normal); this.mockRippled.addResponse("account_info", rippled.account_info.normal);
const result = await client.prepareEscrowCreation( const result = await this.client.prepareEscrowCreation(
address, addresses.ACCOUNT,
requests.prepareEscrowCreation.full requests.prepareEscrowCreation.full
); );
assertResultMatch(result, responses.prepareEscrowCreation.full, "prepare"); assertResultMatch(result, responses.prepareEscrowCreation.full, "prepare");
}, });
"prepareEscrowCreation - invalid": async (client, address, mockRippled) => { it("prepareEscrowCreation - invalid", async function () {
mockRippled.addResponse("server_info", rippled.server_info.normal); this.mockRippled.addResponse("server_info", rippled.server_info.normal);
mockRippled.addResponse("fee", rippled.fee); this.mockRippled.addResponse("fee", rippled.fee);
mockRippled.addResponse("ledger_current", rippled.ledger_current); this.mockRippled.addResponse("ledger_current", rippled.ledger_current);
mockRippled.addResponse("account_info", rippled.account_info.normal); this.mockRippled.addResponse("account_info", rippled.account_info.normal);
const escrow = { ...requests.prepareEscrowCreation.full }; const escrow = { ...requests.prepareEscrowCreation.full };
delete escrow.amount; // Make invalid delete escrow.amount; // Make invalid
await assertRejects( await assertRejects(
client.prepareEscrowCreation(address, escrow), this.client.prepareEscrowCreation(addresses.ACCOUNT, escrow),
client.errors.ValidationError, this.client.errors.ValidationError,
'instance.escrowCreation requires property "amount"' 'instance.escrowCreation requires property "amount"'
); );
}, });
"with ticket": async (client, address, mockRippled) => { it("with ticket", async function () {
mockRippled.addResponse("server_info", rippled.server_info.normal); this.mockRippled.addResponse("server_info", rippled.server_info.normal);
mockRippled.addResponse("fee", rippled.fee); this.mockRippled.addResponse("fee", rippled.fee);
mockRippled.addResponse("ledger_current", rippled.ledger_current); this.mockRippled.addResponse("ledger_current", rippled.ledger_current);
mockRippled.addResponse("account_info", rippled.account_info.normal); this.mockRippled.addResponse("account_info", rippled.account_info.normal);
const localInstructions = { const localInstructions = {
...instructionsWithMaxLedgerVersionOffset, ...instructionsWithMaxLedgerVersionOffset,
maxFee: "0.000396", maxFee: "0.000396",
ticketSequence: 23, ticketSequence: 23,
}; };
const result = await client.prepareEscrowCreation( const result = await this.client.prepareEscrowCreation(
address, addresses.ACCOUNT,
requests.prepareEscrowCreation.normal, requests.prepareEscrowCreation.normal,
localInstructions localInstructions
); );
@@ -85,5 +85,5 @@ export default <TestSuite>{
responses.prepareEscrowCreation.ticket, responses.prepareEscrowCreation.ticket,
"prepare" "prepare"
); );
}, });
}; });

View File

@@ -1,23 +1,27 @@
import requests from "../fixtures/requests"; import requests from "../fixtures/requests";
import responses from "../fixtures/responses"; import responses from "../fixtures/responses";
import rippled from "../fixtures/rippled"; import rippled from "../fixtures/rippled";
import { TestSuite, assertRejects, assertResultMatch } from "../testUtils"; import setupClient from "../setupClient";
import { addressTests, assertRejects, assertResultMatch } from "../testUtils";
const instructionsWithMaxLedgerVersionOffset = { maxLedgerVersionOffset: 100 }; const instructionsWithMaxLedgerVersionOffset = { maxLedgerVersionOffset: 100 };
/** describe("client.prepareEscrowExecution", function () {
* Every test suite exports their tests in the default object. beforeEach(setupClient.setup);
* - Check out the "TestSuite" type for documentation on the interface. afterEach(setupClient.teardown);
* - Check out "test/client/index.ts" for more information about the test runner.
*/ addressTests.forEach(function (test) {
export default <TestSuite>{ describe(test.type, function () {
async prepareEscrowExecution(client, address, mockRippled) { it("prepareEscrowExecution", async function () {
mockRippled.addResponse("server_info", rippled.server_info.normal); this.mockRippled.addResponse("server_info", rippled.server_info.normal);
mockRippled.addResponse("fee", rippled.fee); this.mockRippled.addResponse("fee", rippled.fee);
mockRippled.addResponse("ledger_current", rippled.ledger_current); this.mockRippled.addResponse("ledger_current", rippled.ledger_current);
mockRippled.addResponse("account_info", rippled.account_info.normal); this.mockRippled.addResponse(
const result = await client.prepareEscrowExecution( "account_info",
address, rippled.account_info.normal
);
const result = await this.client.prepareEscrowExecution(
test.address,
requests.prepareEscrowExecution.normal, requests.prepareEscrowExecution.normal,
instructionsWithMaxLedgerVersionOffset instructionsWithMaxLedgerVersionOffset
); );
@@ -26,15 +30,18 @@ export default <TestSuite>{
responses.prepareEscrowExecution.normal, responses.prepareEscrowExecution.normal,
"prepare" "prepare"
); );
}, });
"prepareEscrowExecution - simple": async (client, address, mockRippled) => { it("prepareEscrowExecution - simple", async function () {
mockRippled.addResponse("server_info", rippled.server_info.normal); this.mockRippled.addResponse("server_info", rippled.server_info.normal);
mockRippled.addResponse("fee", rippled.fee); this.mockRippled.addResponse("fee", rippled.fee);
mockRippled.addResponse("ledger_current", rippled.ledger_current); this.mockRippled.addResponse("ledger_current", rippled.ledger_current);
mockRippled.addResponse("account_info", rippled.account_info.normal); this.mockRippled.addResponse(
const result = await client.prepareEscrowExecution( "account_info",
address, rippled.account_info.normal
);
const result = await this.client.prepareEscrowExecution(
test.address,
requests.prepareEscrowExecution.simple requests.prepareEscrowExecution.simple
); );
assertResultMatch( assertResultMatch(
@@ -42,60 +49,61 @@ export default <TestSuite>{
responses.prepareEscrowExecution.simple, responses.prepareEscrowExecution.simple,
"prepare" "prepare"
); );
}, });
"prepareEscrowExecution - no condition": async ( it("prepareEscrowExecution - no condition", async function () {
client, this.mockRippled.addResponse("server_info", rippled.server_info.normal);
address, this.mockRippled.addResponse("fee", rippled.fee);
mockRippled this.mockRippled.addResponse("ledger_current", rippled.ledger_current);
) => { this.mockRippled.addResponse(
mockRippled.addResponse("server_info", rippled.server_info.normal); "account_info",
mockRippled.addResponse("fee", rippled.fee); rippled.account_info.normal
mockRippled.addResponse("ledger_current", rippled.ledger_current); );
mockRippled.addResponse("account_info", rippled.account_info.normal);
await assertRejects( await assertRejects(
client.prepareEscrowExecution( this.client.prepareEscrowExecution(
address, test.address,
requests.prepareEscrowExecution.noCondition, requests.prepareEscrowExecution.noCondition,
instructionsWithMaxLedgerVersionOffset instructionsWithMaxLedgerVersionOffset
), ),
client.errors.ValidationError, this.client.errors.ValidationError,
'"condition" and "fulfillment" fields on EscrowFinish must only be specified together.' '"condition" and "fulfillment" fields on EscrowFinish must only be specified together.'
); );
}, });
"prepareEscrowExecution - no fulfillment": async ( it("prepareEscrowExecution - no fulfillment", async function () {
client, this.mockRippled.addResponse("server_info", rippled.server_info.normal);
address, this.mockRippled.addResponse("fee", rippled.fee);
mockRippled this.mockRippled.addResponse("ledger_current", rippled.ledger_current);
) => { this.mockRippled.addResponse(
mockRippled.addResponse("server_info", rippled.server_info.normal); "account_info",
mockRippled.addResponse("fee", rippled.fee); rippled.account_info.normal
mockRippled.addResponse("ledger_current", rippled.ledger_current); );
mockRippled.addResponse("account_info", rippled.account_info.normal);
await assertRejects( await assertRejects(
client.prepareEscrowExecution( this.client.prepareEscrowExecution(
address, test.address,
requests.prepareEscrowExecution.noFulfillment, requests.prepareEscrowExecution.noFulfillment,
instructionsWithMaxLedgerVersionOffset instructionsWithMaxLedgerVersionOffset
), ),
client.errors.ValidationError, this.client.errors.ValidationError,
'"condition" and "fulfillment" fields on EscrowFinish must only be specified together.' '"condition" and "fulfillment" fields on EscrowFinish must only be specified together.'
); );
}, });
"with ticket": async (client, address, mockRippled) => { it("with ticket", async function () {
mockRippled.addResponse("server_info", rippled.server_info.normal); this.mockRippled.addResponse("server_info", rippled.server_info.normal);
mockRippled.addResponse("fee", rippled.fee); this.mockRippled.addResponse("fee", rippled.fee);
mockRippled.addResponse("ledger_current", rippled.ledger_current); this.mockRippled.addResponse("ledger_current", rippled.ledger_current);
mockRippled.addResponse("account_info", rippled.account_info.normal); this.mockRippled.addResponse(
"account_info",
rippled.account_info.normal
);
const localInstructions = { const localInstructions = {
...instructionsWithMaxLedgerVersionOffset, ...instructionsWithMaxLedgerVersionOffset,
maxFee: "0.000396", maxFee: "0.000396",
ticketSequence: 23, ticketSequence: 23,
}; };
const result = await client.prepareEscrowExecution( const result = await this.client.prepareEscrowExecution(
address, test.address,
requests.prepareEscrowExecution.normal, requests.prepareEscrowExecution.normal,
localInstructions localInstructions
); );
@@ -104,5 +112,7 @@ export default <TestSuite>{
responses.prepareEscrowExecution.ticket, responses.prepareEscrowExecution.ticket,
"prepare" "prepare"
); );
}, });
}; });
});
});

View File

@@ -1,89 +1,107 @@
import requests from "../fixtures/requests"; import requests from "../fixtures/requests";
import responses from "../fixtures/responses"; import responses from "../fixtures/responses";
import rippled from "../fixtures/rippled"; import rippled from "../fixtures/rippled";
import { assertRejects, assertResultMatch, TestSuite } from "../testUtils"; import setupClient from "../setupClient";
import { assertRejects, assertResultMatch, addressTests } from "../testUtils";
const instructionsWithMaxLedgerVersionOffset = { maxLedgerVersionOffset: 100 }; const instructionsWithMaxLedgerVersionOffset = { maxLedgerVersionOffset: 100 };
/** describe("client.prepareOrder", function () {
* Every test suite exports their tests in the default object. beforeEach(setupClient.setup);
* - Check out the "TestSuite" type for documentation on the interface. afterEach(setupClient.teardown);
* - Check out "test/client/index.ts" for more information about the test runner.
*/
export default <TestSuite>{
"buy order": async (client, address, mockRippled) => {
mockRippled.addResponse("server_info", rippled.server_info.normal);
mockRippled.addResponse("fee", rippled.fee);
mockRippled.addResponse("ledger_current", rippled.ledger_current);
mockRippled.addResponse("account_info", rippled.account_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, mockRippled) => { addressTests.forEach(function (test) {
mockRippled.addResponse("server_info", rippled.server_info.normal); describe(test.type, function () {
mockRippled.addResponse("fee", rippled.fee); it("buy order", async function () {
mockRippled.addResponse("ledger_current", rippled.ledger_current); this.mockRippled.addResponse("server_info", rippled.server_info.normal);
mockRippled.addResponse("account_info", rippled.account_info.normal); this.mockRippled.addResponse("fee", rippled.fee);
this.mockRippled.addResponse("ledger_current", rippled.ledger_current);
this.mockRippled.addResponse(
"account_info",
rippled.account_info.normal
);
const request = requests.prepareOrder.buy;
const result = await this.client.prepareOrder(test.address, request);
assertResultMatch(result, responses.prepareOrder.buy, "prepare");
});
it("buy order with expiration", async function () {
this.mockRippled.addResponse("server_info", rippled.server_info.normal);
this.mockRippled.addResponse("fee", rippled.fee);
this.mockRippled.addResponse("ledger_current", rippled.ledger_current);
this.mockRippled.addResponse(
"account_info",
rippled.account_info.normal
);
const request = requests.prepareOrder.expiration; const request = requests.prepareOrder.expiration;
const response = responses.prepareOrder.expiration; const response = responses.prepareOrder.expiration;
const result = await client.prepareOrder( const result = await this.client.prepareOrder(
address, test.address,
request, request,
instructionsWithMaxLedgerVersionOffset instructionsWithMaxLedgerVersionOffset
); );
assertResultMatch(result, response, "prepare"); assertResultMatch(result, response, "prepare");
}, });
"sell order": async (client, address, mockRippled) => { it("sell order", async function () {
mockRippled.addResponse("server_info", rippled.server_info.normal); this.mockRippled.addResponse("server_info", rippled.server_info.normal);
mockRippled.addResponse("fee", rippled.fee); this.mockRippled.addResponse("fee", rippled.fee);
mockRippled.addResponse("ledger_current", rippled.ledger_current); this.mockRippled.addResponse("ledger_current", rippled.ledger_current);
mockRippled.addResponse("account_info", rippled.account_info.normal); this.mockRippled.addResponse(
"account_info",
rippled.account_info.normal
);
const request = requests.prepareOrder.sell; const request = requests.prepareOrder.sell;
const result = await client.prepareOrder( const result = await this.client.prepareOrder(
address, test.address,
request, request,
instructionsWithMaxLedgerVersionOffset instructionsWithMaxLedgerVersionOffset
); );
assertResultMatch(result, responses.prepareOrder.sell, "prepare"); assertResultMatch(result, responses.prepareOrder.sell, "prepare");
}, });
async invalid(client, address, mockRippled) { it("invalid", async function () {
mockRippled.addResponse("server_info", rippled.server_info.normal); this.mockRippled.addResponse("server_info", rippled.server_info.normal);
mockRippled.addResponse("fee", rippled.fee); this.mockRippled.addResponse("fee", rippled.fee);
mockRippled.addResponse("ledger_current", rippled.ledger_current); this.mockRippled.addResponse("ledger_current", rippled.ledger_current);
mockRippled.addResponse("account_info", rippled.account_info.normal); this.mockRippled.addResponse(
"account_info",
rippled.account_info.normal
);
const request = { ...requests.prepareOrder.sell }; const request = { ...requests.prepareOrder.sell };
delete request.direction; // Make invalid delete request.direction; // Make invalid
await assertRejects( await assertRejects(
client.prepareOrder( this.client.prepareOrder(
address, test.address,
request, request,
instructionsWithMaxLedgerVersionOffset instructionsWithMaxLedgerVersionOffset
), ),
client.errors.ValidationError, this.client.errors.ValidationError,
'instance.order requires property "direction"' 'instance.order requires property "direction"'
); );
}, });
"with ticket": async (client, address, mockRippled) => { it("with ticket", async function () {
mockRippled.addResponse("server_info", rippled.server_info.normal); this.mockRippled.addResponse("server_info", rippled.server_info.normal);
mockRippled.addResponse("fee", rippled.fee); this.mockRippled.addResponse("fee", rippled.fee);
mockRippled.addResponse("ledger_current", rippled.ledger_current); this.mockRippled.addResponse("ledger_current", rippled.ledger_current);
mockRippled.addResponse("account_info", rippled.account_info.normal); this.mockRippled.addResponse(
"account_info",
rippled.account_info.normal
);
const request = requests.prepareOrder.sell; const request = requests.prepareOrder.sell;
const localInstructions = { const localInstructions = {
...instructionsWithMaxLedgerVersionOffset, ...instructionsWithMaxLedgerVersionOffset,
maxFee: "0.000012", maxFee: "0.000012",
ticketSequence: 23, ticketSequence: 23,
}; };
const result = await client.prepareOrder( const result = await this.client.prepareOrder(
address, test.address,
request, request,
localInstructions localInstructions
); );
assertResultMatch(result, responses.prepareOrder.ticket, "prepare"); assertResultMatch(result, responses.prepareOrder.ticket, "prepare");
}, });
}; });
});
});

View File

@@ -1,24 +1,28 @@
import requests from "../fixtures/requests"; import requests from "../fixtures/requests";
import responses from "../fixtures/responses"; import responses from "../fixtures/responses";
import rippled from "../fixtures/rippled"; import rippled from "../fixtures/rippled";
import { assertRejects, assertResultMatch, TestSuite } from "../testUtils"; import setupClient from "../setupClient";
import { assertRejects, assertResultMatch, addressTests } from "../testUtils";
const instructionsWithMaxLedgerVersionOffset = { maxLedgerVersionOffset: 100 }; const instructionsWithMaxLedgerVersionOffset = { maxLedgerVersionOffset: 100 };
/** describe("client.prepareOrderCancellation", function () {
* Every test suite exports their tests in the default object. beforeEach(setupClient.setup);
* - Check out the "TestSuite" type for documentation on the interface. afterEach(setupClient.teardown);
* - Check out "test/client/index.ts" for more information about the test runner.
*/ addressTests.forEach(function (test) {
export default <TestSuite>{ describe(test.type, function () {
async prepareOrderCancellation(client, address, mockRippled) { it("prepareOrderCancellation", async function () {
mockRippled.addResponse("server_info", rippled.server_info.normal); this.mockRippled.addResponse("server_info", rippled.server_info.normal);
mockRippled.addResponse("fee", rippled.fee); this.mockRippled.addResponse("fee", rippled.fee);
mockRippled.addResponse("ledger_current", rippled.ledger_current); this.mockRippled.addResponse("ledger_current", rippled.ledger_current);
mockRippled.addResponse("account_info", rippled.account_info.normal); this.mockRippled.addResponse(
"account_info",
rippled.account_info.normal
);
const request = requests.prepareOrderCancellation.simple; const request = requests.prepareOrderCancellation.simple;
const result = await client.prepareOrderCancellation( const result = await this.client.prepareOrderCancellation(
address, test.address,
request, request,
instructionsWithMaxLedgerVersionOffset instructionsWithMaxLedgerVersionOffset
); );
@@ -27,66 +31,84 @@ export default <TestSuite>{
responses.prepareOrderCancellation.normal, responses.prepareOrderCancellation.normal,
"prepare" "prepare"
); );
}, });
"no instructions": async (client, address, mockRippled) => { it("no instructions", async function () {
mockRippled.addResponse("server_info", rippled.server_info.normal); this.mockRippled.addResponse("server_info", rippled.server_info.normal);
mockRippled.addResponse("fee", rippled.fee); this.mockRippled.addResponse("fee", rippled.fee);
mockRippled.addResponse("ledger_current", rippled.ledger_current); this.mockRippled.addResponse("ledger_current", rippled.ledger_current);
mockRippled.addResponse("account_info", rippled.account_info.normal); this.mockRippled.addResponse(
"account_info",
rippled.account_info.normal
);
const request = requests.prepareOrderCancellation.simple; const request = requests.prepareOrderCancellation.simple;
const result = await client.prepareOrderCancellation(address, request); const result = await this.client.prepareOrderCancellation(
test.address,
request
);
assertResultMatch( assertResultMatch(
result, result,
responses.prepareOrderCancellation.noInstructions, responses.prepareOrderCancellation.noInstructions,
"prepare" "prepare"
); );
}, });
"with memos": async (client, address, mockRippled) => { it("with memos", async function () {
mockRippled.addResponse("server_info", rippled.server_info.normal); this.mockRippled.addResponse("server_info", rippled.server_info.normal);
mockRippled.addResponse("fee", rippled.fee); this.mockRippled.addResponse("fee", rippled.fee);
mockRippled.addResponse("ledger_current", rippled.ledger_current); this.mockRippled.addResponse("ledger_current", rippled.ledger_current);
mockRippled.addResponse("account_info", rippled.account_info.normal); this.mockRippled.addResponse(
"account_info",
rippled.account_info.normal
);
const request = requests.prepareOrderCancellation.withMemos; const request = requests.prepareOrderCancellation.withMemos;
const result = await client.prepareOrderCancellation(address, request); const result = await this.client.prepareOrderCancellation(
test.address,
request
);
assertResultMatch( assertResultMatch(
result, result,
responses.prepareOrderCancellation.withMemos, responses.prepareOrderCancellation.withMemos,
"prepare" "prepare"
); );
}, });
async invalid(client, address, mockRippled) { it("invalid", async function () {
mockRippled.addResponse("server_info", rippled.server_info.normal); this.mockRippled.addResponse("server_info", rippled.server_info.normal);
mockRippled.addResponse("fee", rippled.fee); this.mockRippled.addResponse("fee", rippled.fee);
mockRippled.addResponse("ledger_current", rippled.ledger_current); this.mockRippled.addResponse("ledger_current", rippled.ledger_current);
mockRippled.addResponse("account_info", rippled.account_info.normal); this.mockRippled.addResponse(
"account_info",
rippled.account_info.normal
);
const request = { const request = {
...requests.prepareOrderCancellation.withMemos, ...requests.prepareOrderCancellation.withMemos,
}; };
delete request.orderSequence; // Make invalid delete request.orderSequence; // Make invalid
await assertRejects( await assertRejects(
client.prepareOrderCancellation(address, request), this.client.prepareOrderCancellation(test.address, request),
client.errors.ValidationError, this.client.errors.ValidationError,
'instance.orderCancellation requires property "orderSequence"' 'instance.orderCancellation requires property "orderSequence"'
); );
}, });
"with ticket": async (client, address, mockRippled) => { it("with ticket", async function () {
mockRippled.addResponse("server_info", rippled.server_info.normal); this.mockRippled.addResponse("server_info", rippled.server_info.normal);
mockRippled.addResponse("fee", rippled.fee); this.mockRippled.addResponse("fee", rippled.fee);
mockRippled.addResponse("ledger_current", rippled.ledger_current); this.mockRippled.addResponse("ledger_current", rippled.ledger_current);
mockRippled.addResponse("account_info", rippled.account_info.normal); this.mockRippled.addResponse(
"account_info",
rippled.account_info.normal
);
const request = requests.prepareOrderCancellation.simple; const request = requests.prepareOrderCancellation.simple;
const localInstructions = { const localInstructions = {
...instructionsWithMaxLedgerVersionOffset, ...instructionsWithMaxLedgerVersionOffset,
maxFee: "0.000012", maxFee: "0.000012",
ticketSequence: 23, ticketSequence: 23,
}; };
const result = await client.prepareOrderCancellation( const result = await this.client.prepareOrderCancellation(
address, test.address,
request, request,
localInstructions localInstructions
); );
@@ -95,5 +117,7 @@ export default <TestSuite>{
responses.prepareOrderCancellation.ticket, responses.prepareOrderCancellation.ticket,
"prepare" "prepare"
); );
}, });
}; });
});
});

View File

@@ -3,71 +3,88 @@ import { ValidationError } from "xrpl-local/common/errors";
import requests from "../fixtures/requests"; import requests from "../fixtures/requests";
import responses from "../fixtures/responses"; import responses from "../fixtures/responses";
import rippled from "../fixtures/rippled"; import rippled from "../fixtures/rippled";
import { assertResultMatch, TestSuite, assertRejects } from "../testUtils"; import setupClient from "../setupClient";
import { assertResultMatch, addressTests, assertRejects } from "../testUtils";
const instructionsWithMaxLedgerVersionOffset = { maxLedgerVersionOffset: 100 }; const instructionsWithMaxLedgerVersionOffset = { maxLedgerVersionOffset: 100 };
const { preparePayment: REQUEST_FIXTURES } = requests; const { preparePayment: REQUEST_FIXTURES } = requests;
const { preparePayment: RESPONSE_FIXTURES } = responses; const { preparePayment: RESPONSE_FIXTURES } = responses;
const RECIPIENT_ADDRESS = "rpZc4mVfWUif9CRoHRKKcmhu1nx2xktxBo"; const RECIPIENT_ADDRESS = "rpZc4mVfWUif9CRoHRKKcmhu1nx2xktxBo";
/** describe("client.preparePayment", function () {
* Every test suite exports their tests in the default object. beforeEach(setupClient.setup);
* - Check out the "TestSuite" type for documentation on the interface. afterEach(setupClient.teardown);
* - Check out "test/client/index.ts" for more information about the test runner.
*/ addressTests.forEach(function (test) {
export default <TestSuite>{ describe(test.type, function () {
async normal(client, address, mockRippled) { it("normal", async function () {
mockRippled.addResponse("server_info", rippled.server_info.normal); this.mockRippled.addResponse("server_info", rippled.server_info.normal);
mockRippled.addResponse("fee", rippled.fee); this.mockRippled.addResponse("fee", rippled.fee);
mockRippled.addResponse("ledger_current", rippled.ledger_current); this.mockRippled.addResponse("ledger_current", rippled.ledger_current);
mockRippled.addResponse("account_info", rippled.account_info.normal); this.mockRippled.addResponse(
"account_info",
rippled.account_info.normal
);
const localInstructions = { const localInstructions = {
...instructionsWithMaxLedgerVersionOffset, ...instructionsWithMaxLedgerVersionOffset,
maxFee: "0.000012", maxFee: "0.000012",
}; };
const response = await client.preparePayment( const response = await this.client.preparePayment(
address, test.address,
REQUEST_FIXTURES.normal, REQUEST_FIXTURES.normal,
localInstructions localInstructions
); );
assertResultMatch(response, RESPONSE_FIXTURES.normal, "prepare"); assertResultMatch(response, RESPONSE_FIXTURES.normal, "prepare");
}, });
"min amount xrp": async (client, address, mockRippled) => { it("min amount xrp", async function () {
mockRippled.addResponse("server_info", rippled.server_info.normal); this.mockRippled.addResponse("server_info", rippled.server_info.normal);
mockRippled.addResponse("fee", rippled.fee); this.mockRippled.addResponse("fee", rippled.fee);
mockRippled.addResponse("ledger_current", rippled.ledger_current); this.mockRippled.addResponse("ledger_current", rippled.ledger_current);
mockRippled.addResponse("account_info", rippled.account_info.normal); this.mockRippled.addResponse(
"account_info",
rippled.account_info.normal
);
const localInstructions = { const localInstructions = {
...instructionsWithMaxLedgerVersionOffset, ...instructionsWithMaxLedgerVersionOffset,
maxFee: "0.000012", maxFee: "0.000012",
}; };
const response = await client.preparePayment( const response = await this.client.preparePayment(
address, test.address,
REQUEST_FIXTURES.minAmountXRP, REQUEST_FIXTURES.minAmountXRP,
localInstructions localInstructions
); );
assertResultMatch(response, RESPONSE_FIXTURES.minAmountXRP, "prepare"); assertResultMatch(response, RESPONSE_FIXTURES.minAmountXRP, "prepare");
}, });
"min amount xrp2xrp": async (client, address, mockRippled) => { it("min amount xrp2xrp", async function () {
mockRippled.addResponse("server_info", rippled.server_info.normal); this.mockRippled.addResponse("server_info", rippled.server_info.normal);
mockRippled.addResponse("fee", rippled.fee); this.mockRippled.addResponse("fee", rippled.fee);
mockRippled.addResponse("ledger_current", rippled.ledger_current); this.mockRippled.addResponse("ledger_current", rippled.ledger_current);
mockRippled.addResponse("account_info", rippled.account_info.normal); this.mockRippled.addResponse(
const response = await client.preparePayment( "account_info",
address, rippled.account_info.normal
);
const response = await this.client.preparePayment(
test.address,
REQUEST_FIXTURES.minAmount, REQUEST_FIXTURES.minAmount,
instructionsWithMaxLedgerVersionOffset instructionsWithMaxLedgerVersionOffset
); );
assertResultMatch(response, RESPONSE_FIXTURES.minAmountXRPXRP, "prepare"); assertResultMatch(
}, response,
RESPONSE_FIXTURES.minAmountXRPXRP,
"prepare"
);
});
"XRP to XRP": async (client, address, mockRippled) => { it("XRP to XRP", async function () {
mockRippled.addResponse("server_info", rippled.server_info.normal); this.mockRippled.addResponse("server_info", rippled.server_info.normal);
mockRippled.addResponse("fee", rippled.fee); this.mockRippled.addResponse("fee", rippled.fee);
mockRippled.addResponse("ledger_current", rippled.ledger_current); this.mockRippled.addResponse("ledger_current", rippled.ledger_current);
mockRippled.addResponse("account_info", rippled.account_info.normal); this.mockRippled.addResponse(
"account_info",
rippled.account_info.normal
);
const payment = { const payment = {
source: { source: {
address: "r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59", address: "r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59",
@@ -87,19 +104,22 @@ export default <TestSuite>{
maxLedgerVersion: 8820051, maxLedgerVersion: 8820051,
}, },
}; };
const response = await client.preparePayment( const response = await this.client.preparePayment(
address, test.address,
payment, payment,
instructionsWithMaxLedgerVersionOffset instructionsWithMaxLedgerVersionOffset
); );
assertResultMatch(response, expected, "prepare"); assertResultMatch(response, expected, "prepare");
}, });
"XRP drops to XRP drops": async (client, address, mockRippled) => { it("XRP drops to XRP drops", async function () {
mockRippled.addResponse("server_info", rippled.server_info.normal); this.mockRippled.addResponse("server_info", rippled.server_info.normal);
mockRippled.addResponse("fee", rippled.fee); this.mockRippled.addResponse("fee", rippled.fee);
mockRippled.addResponse("ledger_current", rippled.ledger_current); this.mockRippled.addResponse("ledger_current", rippled.ledger_current);
mockRippled.addResponse("account_info", rippled.account_info.normal); this.mockRippled.addResponse(
"account_info",
rippled.account_info.normal
);
const payment = { const payment = {
source: { source: {
address: "r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59", address: "r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59",
@@ -119,19 +139,22 @@ export default <TestSuite>{
maxLedgerVersion: 8820051, maxLedgerVersion: 8820051,
}, },
}; };
const response = await client.preparePayment( const response = await this.client.preparePayment(
address, test.address,
payment, payment,
instructionsWithMaxLedgerVersionOffset instructionsWithMaxLedgerVersionOffset
); );
assertResultMatch(response, expected, "prepare"); assertResultMatch(response, expected, "prepare");
}, });
"XRP drops to XRP": async (client, address, mockRippled) => { it("XRP drops to XRP", async function () {
mockRippled.addResponse("server_info", rippled.server_info.normal); this.mockRippled.addResponse("server_info", rippled.server_info.normal);
mockRippled.addResponse("fee", rippled.fee); this.mockRippled.addResponse("fee", rippled.fee);
mockRippled.addResponse("ledger_current", rippled.ledger_current); this.mockRippled.addResponse("ledger_current", rippled.ledger_current);
mockRippled.addResponse("account_info", rippled.account_info.normal); this.mockRippled.addResponse(
"account_info",
rippled.account_info.normal
);
const payment = { const payment = {
source: { source: {
address: "r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59", address: "r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59",
@@ -151,19 +174,22 @@ export default <TestSuite>{
maxLedgerVersion: 8820051, maxLedgerVersion: 8820051,
}, },
}; };
const response = await client.preparePayment( const response = await this.client.preparePayment(
address, test.address,
payment, payment,
instructionsWithMaxLedgerVersionOffset instructionsWithMaxLedgerVersionOffset
); );
assertResultMatch(response, expected, "prepare"); assertResultMatch(response, expected, "prepare");
}, });
"XRP to XRP drops": async (client, address, mockRippled) => { it("XRP to XRP drops", async function () {
mockRippled.addResponse("server_info", rippled.server_info.normal); this.mockRippled.addResponse("server_info", rippled.server_info.normal);
mockRippled.addResponse("fee", rippled.fee); this.mockRippled.addResponse("fee", rippled.fee);
mockRippled.addResponse("ledger_current", rippled.ledger_current); this.mockRippled.addResponse("ledger_current", rippled.ledger_current);
mockRippled.addResponse("account_info", rippled.account_info.normal); this.mockRippled.addResponse(
"account_info",
rippled.account_info.normal
);
const payment = { const payment = {
source: { source: {
address: "r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59", address: "r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59",
@@ -183,27 +209,26 @@ export default <TestSuite>{
maxLedgerVersion: 8820051, maxLedgerVersion: 8820051,
}, },
}; };
const response = await client.preparePayment( const response = await this.client.preparePayment(
address, test.address,
payment, payment,
instructionsWithMaxLedgerVersionOffset instructionsWithMaxLedgerVersionOffset
); );
assertResultMatch(response, expected, "prepare"); assertResultMatch(response, expected, "prepare");
}, });
// Errors // Errors
"rejects promise and does not throw when payment object is invalid": async ( it("rejects promise and does not throw when payment object is invalid", async function () {
client, this.mockRippled.addResponse("server_info", rippled.server_info.normal);
address, this.mockRippled.addResponse("fee", rippled.fee);
mockRippled this.mockRippled.addResponse("ledger_current", rippled.ledger_current);
) => { this.mockRippled.addResponse(
mockRippled.addResponse("server_info", rippled.server_info.normal); "account_info",
mockRippled.addResponse("fee", rippled.fee); rippled.account_info.normal
mockRippled.addResponse("ledger_current", rippled.ledger_current); );
mockRippled.addResponse("account_info", rippled.account_info.normal);
const payment = { const payment = {
source: { source: {
address, address: test.address,
// instead of `maxAmount` // instead of `maxAmount`
amount: { value: "1000", currency: "drops" }, amount: { value: "1000", currency: "drops" },
}, },
@@ -214,24 +239,23 @@ export default <TestSuite>{
}; };
return assertRejects( return assertRejects(
client.preparePayment(address, payment), this.client.preparePayment(test.address, payment),
ValidationError, ValidationError,
"payment must specify either (source.maxAmount and destination.amount) or (source.amount and destination.minAmount)" "payment must specify either (source.maxAmount and destination.amount) or (source.amount and destination.minAmount)"
); );
}, });
"rejects promise and does not throw when field is missing": async ( it("rejects promise and does not throw when field is missing", async function () {
client, this.mockRippled.addResponse("server_info", rippled.server_info.normal);
address, this.mockRippled.addResponse("fee", rippled.fee);
mockRippled this.mockRippled.addResponse("ledger_current", rippled.ledger_current);
) => { this.mockRippled.addResponse(
mockRippled.addResponse("server_info", rippled.server_info.normal); "account_info",
mockRippled.addResponse("fee", rippled.fee); rippled.account_info.normal
mockRippled.addResponse("ledger_current", rippled.ledger_current); );
mockRippled.addResponse("account_info", rippled.account_info.normal);
// Marking as "any" to get around the fact that TS won't allow this. // Marking as "any" to get around the fact that TS won't allow this.
const payment: any = { const payment: any = {
source: { address }, source: { address: test.address },
destination: { destination: {
address: RECIPIENT_ADDRESS, address: RECIPIENT_ADDRESS,
amount: { value: "1000", currency: "drops" }, amount: { value: "1000", currency: "drops" },
@@ -239,24 +263,23 @@ export default <TestSuite>{
}; };
return assertRejects( return assertRejects(
client.preparePayment(address, payment), this.client.preparePayment(test.address, payment),
ValidationError, ValidationError,
"instance.payment.source is not exactly one from <sourceExactAdjustment>,<maxAdjustment>" "instance.payment.source is not exactly one from <sourceExactAdjustment>,<maxAdjustment>"
); );
}, });
"rejects promise and does not throw when fee exceeds maxFeeXRP": async ( it("rejects promise and does not throw when fee exceeds maxFeeXRP", async function () {
client, this.mockRippled.addResponse("server_info", rippled.server_info.normal);
address, this.mockRippled.addResponse("fee", rippled.fee);
mockRippled this.mockRippled.addResponse("ledger_current", rippled.ledger_current);
) => { this.mockRippled.addResponse(
mockRippled.addResponse("server_info", rippled.server_info.normal); "account_info",
mockRippled.addResponse("fee", rippled.fee); rippled.account_info.normal
mockRippled.addResponse("ledger_current", rippled.ledger_current); );
mockRippled.addResponse("account_info", rippled.account_info.normal);
const payment = { const payment = {
source: { source: {
address, address: test.address,
maxAmount: { value: "1000", currency: "drops" }, maxAmount: { value: "1000", currency: "drops" },
}, },
destination: { destination: {
@@ -265,147 +288,179 @@ export default <TestSuite>{
}, },
}; };
return assertRejects( return assertRejects(
client.preparePayment(address, payment, { fee: "3" }), this.client.preparePayment(test.address, payment, { fee: "3" }),
ValidationError, ValidationError,
"Fee of 3 XRP exceeds max of 2 XRP. To use this fee, increase `maxFeeXRP` in the Client constructor." "Fee of 3 XRP exceeds max of 2 XRP. To use this fee, increase `maxFeeXRP` in the Client constructor."
); );
}, });
"XRP to XRP no partial": async (client, address, mockRippled) => { it("XRP to XRP no partial", async function () {
mockRippled.addResponse("server_info", rippled.server_info.normal); this.mockRippled.addResponse("server_info", rippled.server_info.normal);
mockRippled.addResponse("fee", rippled.fee); this.mockRippled.addResponse("fee", rippled.fee);
mockRippled.addResponse("ledger_current", rippled.ledger_current); this.mockRippled.addResponse("ledger_current", rippled.ledger_current);
mockRippled.addResponse("account_info", rippled.account_info.normal); this.mockRippled.addResponse(
"account_info",
rippled.account_info.normal
);
return assertRejects( return assertRejects(
client.preparePayment(address, REQUEST_FIXTURES.wrongPartial), this.client.preparePayment(
test.address,
REQUEST_FIXTURES.wrongPartial
),
ValidationError, ValidationError,
"XRP to XRP payments cannot be partial payments" "XRP to XRP payments cannot be partial payments"
); );
}, });
"address must match payment.source.address": async ( it("address must match payment.source.address", async function () {
client, this.mockRippled.addResponse("server_info", rippled.server_info.normal);
address, this.mockRippled.addResponse("fee", rippled.fee);
mockRippled this.mockRippled.addResponse("ledger_current", rippled.ledger_current);
) => { this.mockRippled.addResponse(
mockRippled.addResponse("server_info", rippled.server_info.normal); "account_info",
mockRippled.addResponse("fee", rippled.fee); rippled.account_info.normal
mockRippled.addResponse("ledger_current", rippled.ledger_current); );
mockRippled.addResponse("account_info", rippled.account_info.normal);
return assertRejects( return assertRejects(
client.preparePayment(address, REQUEST_FIXTURES.wrongAddress), this.client.preparePayment(
test.address,
REQUEST_FIXTURES.wrongAddress
),
ValidationError, ValidationError,
"address must match payment.source.address" "address must match payment.source.address"
); );
}, });
"wrong amount": async (client, address, mockRippled) => { it("wrong amount", async function () {
mockRippled.addResponse("server_info", rippled.server_info.normal); this.mockRippled.addResponse("server_info", rippled.server_info.normal);
mockRippled.addResponse("fee", rippled.fee); this.mockRippled.addResponse("fee", rippled.fee);
mockRippled.addResponse("ledger_current", rippled.ledger_current); this.mockRippled.addResponse("ledger_current", rippled.ledger_current);
mockRippled.addResponse("account_info", rippled.account_info.normal); this.mockRippled.addResponse(
"account_info",
rippled.account_info.normal
);
return assertRejects( return assertRejects(
client.preparePayment(address, REQUEST_FIXTURES.wrongAmount), this.client.preparePayment(
test.address,
REQUEST_FIXTURES.wrongAmount
),
ValidationError, ValidationError,
"payment must specify either (source.maxAmount and destination.amount) or (source.amount and destination.minAmount)" "payment must specify either (source.maxAmount and destination.amount) or (source.amount and destination.minAmount)"
); );
}, });
"throws when fee exceeds 2 XRP": async (client, address, mockRippled) => { it("throws when fee exceeds 2 XRP", async function () {
mockRippled.addResponse("server_info", rippled.server_info.normal); this.mockRippled.addResponse("server_info", rippled.server_info.normal);
mockRippled.addResponse("fee", rippled.fee); this.mockRippled.addResponse("fee", rippled.fee);
mockRippled.addResponse("ledger_current", rippled.ledger_current); this.mockRippled.addResponse("ledger_current", rippled.ledger_current);
mockRippled.addResponse("account_info", rippled.account_info.normal); this.mockRippled.addResponse(
"account_info",
rippled.account_info.normal
);
const localInstructions = { const localInstructions = {
...instructionsWithMaxLedgerVersionOffset, ...instructionsWithMaxLedgerVersionOffset,
fee: "2.1", fee: "2.1",
}; };
return assertRejects( return assertRejects(
client.preparePayment( this.client.preparePayment(
address, test.address,
REQUEST_FIXTURES.normal, REQUEST_FIXTURES.normal,
localInstructions localInstructions
), ),
ValidationError, ValidationError,
"Fee of 2.1 XRP exceeds max of 2 XRP. To use this fee, increase `maxFeeXRP` in the Client constructor." "Fee of 2.1 XRP exceeds max of 2 XRP. To use this fee, increase `maxFeeXRP` in the Client constructor."
); );
}, });
// 'preparePayment with all options specified': async (client, address) => { // 'preparePayment with all options specified': async (client, test.address) => {
// const ledgerResponse = await client.request({command: 'ledger', ledger_index: 'validated'}) // const ledgerResponse = await this.client.request({command: 'ledger', ledger_index: 'validated'})
// const version = ledgerResponse.result.ledger_index // const version = ledgerResponse.result.ledger_index
// const localInstructions = { // const localInstructions = {
// maxLedgerVersion: version + 100, // maxLedgerVersion: version + 100,
// fee: '0.000012' // fee: '0.000012'
// } // }
// const response = await client.preparePayment( // const response = await this.client.preparePayment(
// address, // test.address,
// REQUEST_FIXTURES.allOptions, // REQUEST_FIXTURES.allOptions,
// localInstructions // localInstructions
// ) // )
// assertResultMatch(response, RESPONSE_FIXTURES.allOptions, 'prepare') // assertResultMatch(response, RESPONSE_FIXTURES.allOptions, 'prepare')
// }, // },
"preparePayment without counterparty set": async ( it("preparePayment without counterparty set", async function () {
client, this.mockRippled.addResponse("server_info", rippled.server_info.normal);
address, this.mockRippled.addResponse("fee", rippled.fee);
mockRippled this.mockRippled.addResponse("ledger_current", rippled.ledger_current);
) => { this.mockRippled.addResponse(
mockRippled.addResponse("server_info", rippled.server_info.normal); "account_info",
mockRippled.addResponse("fee", rippled.fee); rippled.account_info.normal
mockRippled.addResponse("ledger_current", rippled.ledger_current); );
mockRippled.addResponse("account_info", rippled.account_info.normal);
const localInstructions = { const localInstructions = {
...instructionsWithMaxLedgerVersionOffset, ...instructionsWithMaxLedgerVersionOffset,
sequence: 23, sequence: 23,
}; };
const response = await client.preparePayment( const response = await this.client.preparePayment(
address, test.address,
REQUEST_FIXTURES.noCounterparty, REQUEST_FIXTURES.noCounterparty,
localInstructions localInstructions
); );
assertResultMatch(response, RESPONSE_FIXTURES.noCounterparty, "prepare"); assertResultMatch(
}, response,
RESPONSE_FIXTURES.noCounterparty,
"prepare"
);
});
"preparePayment with source.amount/destination.minAmount can be signed": it("preparePayment with source.amount/destination.minAmount can be signed", async function () {
async (client, address, mockRippled) => { this.mockRippled.addResponse("server_info", rippled.server_info.normal);
mockRippled.addResponse("server_info", rippled.server_info.normal); this.mockRippled.addResponse("fee", rippled.fee);
mockRippled.addResponse("fee", rippled.fee); this.mockRippled.addResponse("ledger_current", rippled.ledger_current);
mockRippled.addResponse("ledger_current", rippled.ledger_current); this.mockRippled.addResponse(
mockRippled.addResponse("account_info", rippled.account_info.normal); "account_info",
rippled.account_info.normal
);
// See also: 'sign succeeds with source.amount/destination.minAmount' // See also: 'sign succeeds with source.amount/destination.minAmount'
const localInstructions = { const localInstructions = {
...instructionsWithMaxLedgerVersionOffset, ...instructionsWithMaxLedgerVersionOffset,
sequence: 23, sequence: 23,
}; };
const response = await client.preparePayment( const response = await this.client.preparePayment(
address, test.address,
REQUEST_FIXTURES.noCounterparty, REQUEST_FIXTURES.noCounterparty,
localInstructions localInstructions
); );
assertResultMatch(response, RESPONSE_FIXTURES.noCounterparty, "prepare"); assertResultMatch(
}, response,
RESPONSE_FIXTURES.noCounterparty,
"prepare"
);
});
"destination.minAmount": async (client, address, mockRippled) => { it("destination.minAmount", async function () {
mockRippled.addResponse("server_info", rippled.server_info.normal); this.mockRippled.addResponse("server_info", rippled.server_info.normal);
mockRippled.addResponse("fee", rippled.fee); this.mockRippled.addResponse("fee", rippled.fee);
mockRippled.addResponse("ledger_current", rippled.ledger_current); this.mockRippled.addResponse("ledger_current", rippled.ledger_current);
mockRippled.addResponse("account_info", rippled.account_info.normal); this.mockRippled.addResponse(
const response = await client.preparePayment( "account_info",
address, rippled.account_info.normal
);
const response = await this.client.preparePayment(
test.address,
responses.getPaths.sendAll[0], responses.getPaths.sendAll[0],
instructionsWithMaxLedgerVersionOffset instructionsWithMaxLedgerVersionOffset
); );
assertResultMatch(response, RESPONSE_FIXTURES.minAmount, "prepare"); assertResultMatch(response, RESPONSE_FIXTURES.minAmount, "prepare");
}, });
"caps fee at 2 XRP by default": async (client, address, mockRippled) => { it("caps fee at 2 XRP by default", async function () {
mockRippled.addResponse("server_info", rippled.server_info.normal); this.mockRippled.addResponse("server_info", rippled.server_info.normal);
mockRippled.addResponse("fee", rippled.fee); this.mockRippled.addResponse("fee", rippled.fee);
mockRippled.addResponse("ledger_current", rippled.ledger_current); this.mockRippled.addResponse("ledger_current", rippled.ledger_current);
mockRippled.addResponse("account_info", rippled.account_info.normal); this.mockRippled.addResponse(
client._feeCushion = 1000000; "account_info",
rippled.account_info.normal
);
this.client._feeCushion = 1000000;
const expectedResponse = { const expectedResponse = {
txJSON: txJSON:
'{"Flags":2147483648,"TransactionType":"Payment","Account":"r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59","Destination":"rpZc4mVfWUif9CRoHRKKcmhu1nx2xktxBo","Amount":{"value":"0.01","currency":"USD","issuer":"rMH4UxPrbuMa1spCBR98hLLyNJp4d8p4tM"},"SendMax":{"value":"0.01","currency":"USD","issuer":"rMH4UxPrbuMa1spCBR98hLLyNJp4d8p4tM"},"LastLedgerSequence":8820051,"Fee":"2000000","Sequence":23}', '{"Flags":2147483648,"TransactionType":"Payment","Account":"r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59","Destination":"rpZc4mVfWUif9CRoHRKKcmhu1nx2xktxBo","Amount":{"value":"0.01","currency":"USD","issuer":"rMH4UxPrbuMa1spCBR98hLLyNJp4d8p4tM"},"SendMax":{"value":"0.01","currency":"USD","issuer":"rMH4UxPrbuMa1spCBR98hLLyNJp4d8p4tM"},"LastLedgerSequence":8820051,"Fee":"2000000","Sequence":23}',
@@ -415,24 +470,23 @@ export default <TestSuite>{
maxLedgerVersion: 8820051, maxLedgerVersion: 8820051,
}, },
}; };
const response = await client.preparePayment( const response = await this.client.preparePayment(
address, test.address,
REQUEST_FIXTURES.normal, REQUEST_FIXTURES.normal,
instructionsWithMaxLedgerVersionOffset instructionsWithMaxLedgerVersionOffset
); );
assertResultMatch(response, expectedResponse, "prepare"); assertResultMatch(response, expectedResponse, "prepare");
}, });
"allows fee exceeding 2 XRP when maxFeeXRP is higher": async ( it("allows fee exceeding 2 XRP when maxFeeXRP is higher", async function () {
client, this.mockRippled.addResponse("server_info", rippled.server_info.normal);
address, this.mockRippled.addResponse("fee", rippled.fee);
mockRippled this.mockRippled.addResponse("ledger_current", rippled.ledger_current);
) => { this.mockRippled.addResponse(
mockRippled.addResponse("server_info", rippled.server_info.normal); "account_info",
mockRippled.addResponse("fee", rippled.fee); rippled.account_info.normal
mockRippled.addResponse("ledger_current", rippled.ledger_current); );
mockRippled.addResponse("account_info", rippled.account_info.normal); this.client._maxFeeXRP = "2.2";
client._maxFeeXRP = "2.2";
const localInstructions = { const localInstructions = {
...instructionsWithMaxLedgerVersionOffset, ...instructionsWithMaxLedgerVersionOffset,
fee: "2.1", fee: "2.1",
@@ -446,20 +500,23 @@ export default <TestSuite>{
maxLedgerVersion: 8820051, maxLedgerVersion: 8820051,
}, },
}; };
const response = await client.preparePayment( const response = await this.client.preparePayment(
address, test.address,
REQUEST_FIXTURES.normal, REQUEST_FIXTURES.normal,
localInstructions localInstructions
); );
assertResultMatch(response, expectedResponse, "prepare"); assertResultMatch(response, expectedResponse, "prepare");
}, });
"fee - default maxFee of 2 XRP": async (client, address, mockRippled) => { it("fee - default maxFee of 2 XRP", async function () {
mockRippled.addResponse("server_info", rippled.server_info.normal); this.mockRippled.addResponse("server_info", rippled.server_info.normal);
mockRippled.addResponse("fee", rippled.fee); this.mockRippled.addResponse("fee", rippled.fee);
mockRippled.addResponse("ledger_current", rippled.ledger_current); this.mockRippled.addResponse("ledger_current", rippled.ledger_current);
mockRippled.addResponse("account_info", rippled.account_info.normal); this.mockRippled.addResponse(
client._feeCushion = 1000000; "account_info",
rippled.account_info.normal
);
this.client._feeCushion = 1000000;
const expectedResponse = { const expectedResponse = {
txJSON: txJSON:
'{"Flags":2147483648,"TransactionType":"Payment","Account":"r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59","Destination":"rpZc4mVfWUif9CRoHRKKcmhu1nx2xktxBo","Amount":{"value":"0.01","currency":"USD","issuer":"rMH4UxPrbuMa1spCBR98hLLyNJp4d8p4tM"},"SendMax":{"value":"0.01","currency":"USD","issuer":"rMH4UxPrbuMa1spCBR98hLLyNJp4d8p4tM"},"LastLedgerSequence":8820051,"Fee":"2000000","Sequence":23}', '{"Flags":2147483648,"TransactionType":"Payment","Account":"r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59","Destination":"rpZc4mVfWUif9CRoHRKKcmhu1nx2xktxBo","Amount":{"value":"0.01","currency":"USD","issuer":"rMH4UxPrbuMa1spCBR98hLLyNJp4d8p4tM"},"SendMax":{"value":"0.01","currency":"USD","issuer":"rMH4UxPrbuMa1spCBR98hLLyNJp4d8p4tM"},"LastLedgerSequence":8820051,"Fee":"2000000","Sequence":23}',
@@ -469,25 +526,24 @@ export default <TestSuite>{
maxLedgerVersion: 8820051, maxLedgerVersion: 8820051,
}, },
}; };
const response = await client.preparePayment( const response = await this.client.preparePayment(
address, test.address,
requests.preparePayment.normal, requests.preparePayment.normal,
instructionsWithMaxLedgerVersionOffset instructionsWithMaxLedgerVersionOffset
); );
assertResultMatch(response, expectedResponse, "prepare"); assertResultMatch(response, expectedResponse, "prepare");
}, });
"fee - capped to maxFeeXRP when maxFee exceeds maxFeeXRP": async ( it("fee - capped to maxFeeXRP when maxFee exceeds maxFeeXRP", async function () {
client, this.mockRippled.addResponse("server_info", rippled.server_info.normal);
address, this.mockRippled.addResponse("fee", rippled.fee);
mockRippled this.mockRippled.addResponse("ledger_current", rippled.ledger_current);
) => { this.mockRippled.addResponse(
mockRippled.addResponse("server_info", rippled.server_info.normal); "account_info",
mockRippled.addResponse("fee", rippled.fee); rippled.account_info.normal
mockRippled.addResponse("ledger_current", rippled.ledger_current); );
mockRippled.addResponse("account_info", rippled.account_info.normal); this.client._feeCushion = 1000000;
client._feeCushion = 1000000; this.client._maxFeeXRP = "3";
client._maxFeeXRP = "3";
const localInstructions = { const localInstructions = {
...instructionsWithMaxLedgerVersionOffset, ...instructionsWithMaxLedgerVersionOffset,
maxFee: "4", maxFee: "4",
@@ -501,21 +557,24 @@ export default <TestSuite>{
maxLedgerVersion: 8820051, maxLedgerVersion: 8820051,
}, },
}; };
const response = await client.preparePayment( const response = await this.client.preparePayment(
address, test.address,
requests.preparePayment.normal, requests.preparePayment.normal,
localInstructions localInstructions
); );
assertResultMatch(response, expectedResponse, "prepare"); assertResultMatch(response, expectedResponse, "prepare");
}, });
"fee - capped to maxFee": async (client, address, mockRippled) => { it("fee - capped to maxFee", async function () {
mockRippled.addResponse("server_info", rippled.server_info.normal); this.mockRippled.addResponse("server_info", rippled.server_info.normal);
mockRippled.addResponse("fee", rippled.fee); this.mockRippled.addResponse("fee", rippled.fee);
mockRippled.addResponse("ledger_current", rippled.ledger_current); this.mockRippled.addResponse("ledger_current", rippled.ledger_current);
mockRippled.addResponse("account_info", rippled.account_info.normal); this.mockRippled.addResponse(
client._feeCushion = 1000000; "account_info",
client._maxFeeXRP = "5"; rippled.account_info.normal
);
this.client._feeCushion = 1000000;
this.client._maxFeeXRP = "5";
const localInstructions = { const localInstructions = {
...instructionsWithMaxLedgerVersionOffset, ...instructionsWithMaxLedgerVersionOffset,
maxFee: "4", maxFee: "4",
@@ -529,19 +588,19 @@ export default <TestSuite>{
maxLedgerVersion: 8820051, maxLedgerVersion: 8820051,
}, },
}; };
const response = await client.preparePayment( const response = await this.client.preparePayment(
address, test.address,
requests.preparePayment.normal, requests.preparePayment.normal,
localInstructions localInstructions
); );
assertResultMatch(response, expectedResponse, "prepare"); assertResultMatch(response, expectedResponse, "prepare");
}, });
// 'fee - calculated fee does not use more than 6 decimal places': async ( // 'fee - calculated fee does not use more than 6 decimal places': async (
// client, // client,
// address // test.address
// ) => { // ) => {
// client.connection.request({ // this.client.connection.request({
// command: 'config', // command: 'config',
// data: {loadFactor: 5407.96875} // data: {loadFactor: 5407.96875}
// }) // })
@@ -554,8 +613,8 @@ export default <TestSuite>{
// maxLedgerVersion: 8820051 // maxLedgerVersion: 8820051
// } // }
// } // }
// const response = await client.preparePayment( // const response = await this.client.preparePayment(
// address, // test.address,
// requests.preparePayment.normal, // requests.preparePayment.normal,
// instructionsWithMaxLedgerVersionOffset // instructionsWithMaxLedgerVersionOffset
// ) // )
@@ -563,8 +622,8 @@ export default <TestSuite>{
// }, // },
// Tickets // Tickets
// 'preparePayment with ticketSequence': async (client, address) => { // 'preparePayment with ticketSequence': async (client, test.address) => {
// const ledgerResponse = await client.request({ // const ledgerResponse = await this.client.request({
// command: 'ledger', // command: 'ledger',
// ledger_index: 'validated' // ledger_index: 'validated'
// }) // })
@@ -574,8 +633,8 @@ export default <TestSuite>{
// fee: '0.000012', // fee: '0.000012',
// ticketSequence: 23 // ticketSequence: 23
// } // }
// const response = await client.preparePayment( // const response = await this.client.preparePayment(
// address, // test.address,
// REQUEST_FIXTURES.allOptions, // REQUEST_FIXTURES.allOptions,
// localInstructions // localInstructions
// ) // )
@@ -584,9 +643,9 @@ export default <TestSuite>{
// 'throws when both sequence and ticketSequence are set': async ( // 'throws when both sequence and ticketSequence are set': async (
// client, // client,
// address // test.address
// ) => { // ) => {
// const ledgerResponse = await client.request({ // const ledgerResponse = await this.client.request({
// command: 'ledger', // command: 'ledger',
// ledger_index: 'validated' // ledger_index: 'validated'
// }) // })
@@ -598,8 +657,8 @@ export default <TestSuite>{
// sequence: 12 // sequence: 12
// } // }
// return assertRejects( // return assertRejects(
// client.preparePayment( // this.client.preparePayment(
// address, // test.address,
// REQUEST_FIXTURES.allOptions, // REQUEST_FIXTURES.allOptions,
// localInstructions // localInstructions
// ), // ),
@@ -607,4 +666,6 @@ export default <TestSuite>{
// 'instance.instructions is of prohibited type [object Object]' // 'instance.instructions is of prohibited type [object Object]'
// ) // )
// } // }
}; });
});
});

View File

@@ -3,99 +3,111 @@ import { assert } from "chai";
import requests from "../fixtures/requests"; import requests from "../fixtures/requests";
import responses from "../fixtures/responses"; import responses from "../fixtures/responses";
import rippled from "../fixtures/rippled"; import rippled from "../fixtures/rippled";
import { assertResultMatch, TestSuite } from "../testUtils"; import setupClient from "../setupClient";
import { assertResultMatch, addressTests } from "../testUtils";
const instructionsWithMaxLedgerVersionOffset = { maxLedgerVersionOffset: 100 }; const instructionsWithMaxLedgerVersionOffset = { maxLedgerVersionOffset: 100 };
const { preparePaymentChannelClaim: REQUEST_FIXTURES } = requests; const { preparePaymentChannelClaim: REQUEST_FIXTURES } = requests;
const { preparePaymentChannelClaim: RESPONSE_FIXTURES } = responses; const { preparePaymentChannelClaim: RESPONSE_FIXTURES } = responses;
/** describe("client.preparePaymentChannelClaim", function () {
* Every test suite exports their tests in the default object. beforeEach(setupClient.setup);
* - Check out the "TestSuite" type for documentation on the interface. afterEach(setupClient.teardown);
* - Check out "test/client/index.ts" for more information about the test runner.
*/ addressTests.forEach(function (test) {
export default <TestSuite>{ describe(test.type, function () {
async default(client, address, mockRippled) { it("default", async function () {
mockRippled.addResponse("server_info", rippled.server_info.normal); this.mockRippled.addResponse("server_info", rippled.server_info.normal);
mockRippled.addResponse("fee", rippled.fee); this.mockRippled.addResponse("fee", rippled.fee);
mockRippled.addResponse("ledger_current", rippled.ledger_current); this.mockRippled.addResponse("ledger_current", rippled.ledger_current);
mockRippled.addResponse("account_info", rippled.account_info.normal); this.mockRippled.addResponse(
"account_info",
rippled.account_info.normal
);
const localInstructions = { const localInstructions = {
...instructionsWithMaxLedgerVersionOffset, ...instructionsWithMaxLedgerVersionOffset,
maxFee: "0.000012", maxFee: "0.000012",
}; };
const response = await client.preparePaymentChannelClaim( const response = await this.client.preparePaymentChannelClaim(
address, test.address,
REQUEST_FIXTURES.normal, REQUEST_FIXTURES.normal,
localInstructions localInstructions
); );
assertResultMatch(response, RESPONSE_FIXTURES.normal, "prepare"); assertResultMatch(response, RESPONSE_FIXTURES.normal, "prepare");
}, });
"with renew": async (client, address, mockRippled) => { it("with renew", async function () {
mockRippled.addResponse("server_info", rippled.server_info.normal); this.mockRippled.addResponse("server_info", rippled.server_info.normal);
mockRippled.addResponse("fee", rippled.fee); this.mockRippled.addResponse("fee", rippled.fee);
mockRippled.addResponse("ledger_current", rippled.ledger_current); this.mockRippled.addResponse("ledger_current", rippled.ledger_current);
mockRippled.addResponse("account_info", rippled.account_info.normal); this.mockRippled.addResponse(
"account_info",
rippled.account_info.normal
);
const localInstructions = { const localInstructions = {
...instructionsWithMaxLedgerVersionOffset, ...instructionsWithMaxLedgerVersionOffset,
maxFee: "0.000012", maxFee: "0.000012",
}; };
const response = await client.preparePaymentChannelClaim( const response = await this.client.preparePaymentChannelClaim(
address, test.address,
REQUEST_FIXTURES.renew, REQUEST_FIXTURES.renew,
localInstructions localInstructions
); );
assertResultMatch(response, RESPONSE_FIXTURES.renew, "prepare"); assertResultMatch(response, RESPONSE_FIXTURES.renew, "prepare");
}, });
"with close": async (client, address, mockRippled) => { it("with close", async function () {
mockRippled.addResponse("server_info", rippled.server_info.normal); this.mockRippled.addResponse("server_info", rippled.server_info.normal);
mockRippled.addResponse("fee", rippled.fee); this.mockRippled.addResponse("fee", rippled.fee);
mockRippled.addResponse("ledger_current", rippled.ledger_current); this.mockRippled.addResponse("ledger_current", rippled.ledger_current);
mockRippled.addResponse("account_info", rippled.account_info.normal); this.mockRippled.addResponse(
"account_info",
rippled.account_info.normal
);
const localInstructions = { const localInstructions = {
...instructionsWithMaxLedgerVersionOffset, ...instructionsWithMaxLedgerVersionOffset,
maxFee: "0.000012", maxFee: "0.000012",
}; };
const response = await client.preparePaymentChannelClaim( const response = await this.client.preparePaymentChannelClaim(
address, test.address,
REQUEST_FIXTURES.close, REQUEST_FIXTURES.close,
localInstructions localInstructions
); );
assertResultMatch(response, RESPONSE_FIXTURES.close, "prepare"); assertResultMatch(response, RESPONSE_FIXTURES.close, "prepare");
}, });
"with ticket": async (client, address, mockRippled) => { it("with ticket", async function () {
mockRippled.addResponse("server_info", rippled.server_info.normal); this.mockRippled.addResponse("server_info", rippled.server_info.normal);
mockRippled.addResponse("fee", rippled.fee); this.mockRippled.addResponse("fee", rippled.fee);
mockRippled.addResponse("ledger_current", rippled.ledger_current); this.mockRippled.addResponse("ledger_current", rippled.ledger_current);
mockRippled.addResponse("account_info", rippled.account_info.normal); this.mockRippled.addResponse(
"account_info",
rippled.account_info.normal
);
const localInstructions = { const localInstructions = {
...instructionsWithMaxLedgerVersionOffset, ...instructionsWithMaxLedgerVersionOffset,
maxFee: "0.000012", maxFee: "0.000012",
ticketSequence: 23, ticketSequence: 23,
}; };
const response = await client.preparePaymentChannelClaim( const response = await this.client.preparePaymentChannelClaim(
address, test.address,
REQUEST_FIXTURES.normal, REQUEST_FIXTURES.normal,
localInstructions localInstructions
); );
assertResultMatch(response, RESPONSE_FIXTURES.ticket, "prepare"); assertResultMatch(response, RESPONSE_FIXTURES.ticket, "prepare");
}, });
"rejects Promise on preparePaymentChannelClaim with renew and close": async ( it("rejects Promise on preparePaymentChannelClaim with renew and close", async function () {
client, this.mockRippled.addResponse("server_info", rippled.server_info.normal);
address, this.mockRippled.addResponse("fee", rippled.fee);
mockRippled this.mockRippled.addResponse("ledger_current", rippled.ledger_current);
) => { this.mockRippled.addResponse(
mockRippled.addResponse("server_info", rippled.server_info.normal); "account_info",
mockRippled.addResponse("fee", rippled.fee); rippled.account_info.normal
mockRippled.addResponse("ledger_current", rippled.ledger_current); );
mockRippled.addResponse("account_info", rippled.account_info.normal);
try { try {
const prepared = await client.preparePaymentChannelClaim( const prepared = await this.client.preparePaymentChannelClaim(
address, test.address,
REQUEST_FIXTURES.full REQUEST_FIXTURES.full
); );
throw new Error( throw new Error(
@@ -110,20 +122,19 @@ export default <TestSuite>{
'"renew" and "close" flags on PaymentChannelClaim are mutually exclusive' '"renew" and "close" flags on PaymentChannelClaim are mutually exclusive'
); );
} }
}, });
"rejects Promise on preparePaymentChannelClaim with no signature": async ( it("rejects Promise on preparePaymentChannelClaim with no signature", async function () {
client, this.mockRippled.addResponse("server_info", rippled.server_info.normal);
address, this.mockRippled.addResponse("fee", rippled.fee);
mockRippled this.mockRippled.addResponse("ledger_current", rippled.ledger_current);
) => { this.mockRippled.addResponse(
mockRippled.addResponse("server_info", rippled.server_info.normal); "account_info",
mockRippled.addResponse("fee", rippled.fee); rippled.account_info.normal
mockRippled.addResponse("ledger_current", rippled.ledger_current); );
mockRippled.addResponse("account_info", rippled.account_info.normal);
try { try {
const prepared = await client.preparePaymentChannelClaim( const prepared = await this.client.preparePaymentChannelClaim(
address, test.address,
REQUEST_FIXTURES.noSignature REQUEST_FIXTURES.noSignature
); );
throw new Error( throw new Error(
@@ -138,5 +149,7 @@ export default <TestSuite>{
'"signature" and "publicKey" fields on PaymentChannelClaim must only be specified together.' '"signature" and "publicKey" fields on PaymentChannelClaim must only be specified together.'
); );
} }
}, });
}; });
});
});

View File

@@ -1,7 +1,9 @@
import addresses from "../fixtures/addresses.json";
import requests from "../fixtures/requests"; import requests from "../fixtures/requests";
import responses from "../fixtures/responses"; import responses from "../fixtures/responses";
import rippled from "../fixtures/rippled"; import rippled from "../fixtures/rippled";
import { assertResultMatch, TestSuite } from "../testUtils"; import setupClient from "../setupClient";
import { assertResultMatch } from "../testUtils";
const instructionsWithMaxLedgerVersionOffset = { maxLedgerVersionOffset: 100 }; const instructionsWithMaxLedgerVersionOffset = { maxLedgerVersionOffset: 100 };
@@ -12,23 +14,21 @@ export const config = {
skipXAddress: true, skipXAddress: true,
}; };
/** describe("client.preparePaymentChannelCreate", function () {
* Every test suite exports their tests in the default object. beforeEach(setupClient.setup);
* - Check out the "TestSuite" type for documentation on the interface. afterEach(setupClient.teardown);
* - Check out "test/client/index.ts" for more information about the test runner.
*/ it("preparePaymentChannelCreate", async function () {
export default <TestSuite>{ this.mockRippled.addResponse("server_info", rippled.server_info.normal);
async preparePaymentChannelCreate(client, address, mockRippled) { this.mockRippled.addResponse("fee", rippled.fee);
mockRippled.addResponse("server_info", rippled.server_info.normal); this.mockRippled.addResponse("ledger_current", rippled.ledger_current);
mockRippled.addResponse("fee", rippled.fee); this.mockRippled.addResponse("account_info", rippled.account_info.normal);
mockRippled.addResponse("ledger_current", rippled.ledger_current);
mockRippled.addResponse("account_info", rippled.account_info.normal);
const localInstructions = { const localInstructions = {
...instructionsWithMaxLedgerVersionOffset, ...instructionsWithMaxLedgerVersionOffset,
maxFee: "0.000012", maxFee: "0.000012",
}; };
const result = await client.preparePaymentChannelCreate( const result = await this.client.preparePaymentChannelCreate(
address, addresses.ACCOUNT,
requests.preparePaymentChannelCreate.normal, requests.preparePaymentChannelCreate.normal,
localInstructions localInstructions
); );
@@ -37,15 +37,15 @@ export default <TestSuite>{
responses.preparePaymentChannelCreate.normal, responses.preparePaymentChannelCreate.normal,
"prepare" "prepare"
); );
}, });
"preparePaymentChannelCreate full": async (client, address, mockRippled) => { it("preparePaymentChannelCreate full", async function () {
mockRippled.addResponse("server_info", rippled.server_info.normal); this.mockRippled.addResponse("server_info", rippled.server_info.normal);
mockRippled.addResponse("fee", rippled.fee); this.mockRippled.addResponse("fee", rippled.fee);
mockRippled.addResponse("ledger_current", rippled.ledger_current); this.mockRippled.addResponse("ledger_current", rippled.ledger_current);
mockRippled.addResponse("account_info", rippled.account_info.normal); this.mockRippled.addResponse("account_info", rippled.account_info.normal);
const result = await client.preparePaymentChannelCreate( const result = await this.client.preparePaymentChannelCreate(
address, addresses.ACCOUNT,
requests.preparePaymentChannelCreate.full requests.preparePaymentChannelCreate.full
); );
assertResultMatch( assertResultMatch(
@@ -53,24 +53,20 @@ export default <TestSuite>{
responses.preparePaymentChannelCreate.full, responses.preparePaymentChannelCreate.full,
"prepare" "prepare"
); );
}, });
"preparePaymentChannelCreate with ticket": async ( it("preparePaymentChannelCreate with ticket", async function () {
client, this.mockRippled.addResponse("server_info", rippled.server_info.normal);
address, this.mockRippled.addResponse("fee", rippled.fee);
mockRippled this.mockRippled.addResponse("ledger_current", rippled.ledger_current);
) => { this.mockRippled.addResponse("account_info", rippled.account_info.normal);
mockRippled.addResponse("server_info", rippled.server_info.normal);
mockRippled.addResponse("fee", rippled.fee);
mockRippled.addResponse("ledger_current", rippled.ledger_current);
mockRippled.addResponse("account_info", rippled.account_info.normal);
const localInstructions = { const localInstructions = {
...instructionsWithMaxLedgerVersionOffset, ...instructionsWithMaxLedgerVersionOffset,
maxFee: "0.000012", maxFee: "0.000012",
ticketSequence: 23, ticketSequence: 23,
}; };
const result = await client.preparePaymentChannelCreate( const result = await this.client.preparePaymentChannelCreate(
address, addresses.ACCOUNT,
requests.preparePaymentChannelCreate.normal, requests.preparePaymentChannelCreate.normal,
localInstructions localInstructions
); );
@@ -79,5 +75,5 @@ export default <TestSuite>{
responses.preparePaymentChannelCreate.ticket, responses.preparePaymentChannelCreate.ticket,
"prepare" "prepare"
); );
}, });
}; });

View File

@@ -1,27 +1,31 @@
import requests from "../fixtures/requests"; import requests from "../fixtures/requests";
import responses from "../fixtures/responses"; import responses from "../fixtures/responses";
import rippled from "../fixtures/rippled"; import rippled from "../fixtures/rippled";
import { assertResultMatch, TestSuite } from "../testUtils"; import setupClient from "../setupClient";
import { assertResultMatch, addressTests } from "../testUtils";
const instructionsWithMaxLedgerVersionOffset = { maxLedgerVersionOffset: 100 }; const instructionsWithMaxLedgerVersionOffset = { maxLedgerVersionOffset: 100 };
/** describe("client.preparePaymentChannelFund", function () {
* Every test suite exports their tests in the default object. beforeEach(setupClient.setup);
* - Check out the "TestSuite" type for documentation on the interface. afterEach(setupClient.teardown);
* - Check out "test/client/index.ts" for more information about the test runner.
*/ addressTests.forEach(function (test) {
export default <TestSuite>{ describe(test.type, function () {
async preparePaymentChannelFund(client, address, mockRippled) { it("preparePaymentChannelFund", async function () {
mockRippled.addResponse("server_info", rippled.server_info.normal); this.mockRippled.addResponse("server_info", rippled.server_info.normal);
mockRippled.addResponse("fee", rippled.fee); this.mockRippled.addResponse("fee", rippled.fee);
mockRippled.addResponse("ledger_current", rippled.ledger_current); this.mockRippled.addResponse("ledger_current", rippled.ledger_current);
mockRippled.addResponse("account_info", rippled.account_info.normal); this.mockRippled.addResponse(
"account_info",
rippled.account_info.normal
);
const localInstructions = { const localInstructions = {
...instructionsWithMaxLedgerVersionOffset, ...instructionsWithMaxLedgerVersionOffset,
maxFee: "0.000012", maxFee: "0.000012",
}; };
const result = await client.preparePaymentChannelFund( const result = await this.client.preparePaymentChannelFund(
address, test.address,
requests.preparePaymentChannelFund.normal, requests.preparePaymentChannelFund.normal,
localInstructions localInstructions
); );
@@ -30,15 +34,18 @@ export default <TestSuite>{
responses.preparePaymentChannelFund.normal, responses.preparePaymentChannelFund.normal,
"prepare" "prepare"
); );
}, });
"preparePaymentChannelFund full": async (client, address, mockRippled) => { it("preparePaymentChannelFund full", async function () {
mockRippled.addResponse("server_info", rippled.server_info.normal); this.mockRippled.addResponse("server_info", rippled.server_info.normal);
mockRippled.addResponse("fee", rippled.fee); this.mockRippled.addResponse("fee", rippled.fee);
mockRippled.addResponse("ledger_current", rippled.ledger_current); this.mockRippled.addResponse("ledger_current", rippled.ledger_current);
mockRippled.addResponse("account_info", rippled.account_info.normal); this.mockRippled.addResponse(
const result = await client.preparePaymentChannelFund( "account_info",
address, rippled.account_info.normal
);
const result = await this.client.preparePaymentChannelFund(
test.address,
requests.preparePaymentChannelFund.full requests.preparePaymentChannelFund.full
); );
assertResultMatch( assertResultMatch(
@@ -46,20 +53,23 @@ export default <TestSuite>{
responses.preparePaymentChannelFund.full, responses.preparePaymentChannelFund.full,
"prepare" "prepare"
); );
}, });
"with ticket": async (client, address, mockRippled) => { it("with ticket", async function () {
mockRippled.addResponse("server_info", rippled.server_info.normal); this.mockRippled.addResponse("server_info", rippled.server_info.normal);
mockRippled.addResponse("fee", rippled.fee); this.mockRippled.addResponse("fee", rippled.fee);
mockRippled.addResponse("ledger_current", rippled.ledger_current); this.mockRippled.addResponse("ledger_current", rippled.ledger_current);
mockRippled.addResponse("account_info", rippled.account_info.normal); this.mockRippled.addResponse(
"account_info",
rippled.account_info.normal
);
const localInstructions = { const localInstructions = {
...instructionsWithMaxLedgerVersionOffset, ...instructionsWithMaxLedgerVersionOffset,
maxFee: "0.000012", maxFee: "0.000012",
ticketSequence: 23, ticketSequence: 23,
}; };
const result = await client.preparePaymentChannelFund( const result = await this.client.preparePaymentChannelFund(
address, test.address,
requests.preparePaymentChannelFund.normal, requests.preparePaymentChannelFund.normal,
localInstructions localInstructions
); );
@@ -68,5 +78,7 @@ export default <TestSuite>{
responses.preparePaymentChannelFund.ticket, responses.preparePaymentChannelFund.ticket,
"prepare" "prepare"
); );
}, });
}; });
});
});

View File

@@ -4,35 +4,42 @@ import { FormattedSettings } from "../../src/common/types/objects";
import requests from "../fixtures/requests"; import requests from "../fixtures/requests";
import responses from "../fixtures/responses"; import responses from "../fixtures/responses";
import rippled from "../fixtures/rippled"; import rippled from "../fixtures/rippled";
import { assertResultMatch, TestSuite } from "../testUtils"; import setupClient from "../setupClient";
import { assertResultMatch, addressTests } from "../testUtils";
const instructionsWithMaxLedgerVersionOffset = { maxLedgerVersionOffset: 100 }; const instructionsWithMaxLedgerVersionOffset = { maxLedgerVersionOffset: 100 };
/** describe("client.prepareSettings", function () {
* Every test suite exports their tests in the default object. beforeEach(setupClient.setup);
* - Check out the "TestSuite" type for documentation on the interface. afterEach(setupClient.teardown);
* - Check out "test/client/index.ts" for more information about the test runner.
*/ addressTests.forEach(function (test) {
export default <TestSuite>{ describe(test.type, function () {
"simple test": async (client, address, mockRippled) => { it("simple test", async function () {
mockRippled.addResponse("server_info", rippled.server_info.normal); this.mockRippled.addResponse("server_info", rippled.server_info.normal);
mockRippled.addResponse("fee", rippled.fee); this.mockRippled.addResponse("fee", rippled.fee);
mockRippled.addResponse("ledger_current", rippled.ledger_current); this.mockRippled.addResponse("ledger_current", rippled.ledger_current);
mockRippled.addResponse("account_info", rippled.account_info.normal); this.mockRippled.addResponse(
const response = await client.prepareSettings( "account_info",
address, rippled.account_info.normal
);
const response = await this.client.prepareSettings(
test.address,
requests.prepareSettings.domain, requests.prepareSettings.domain,
instructionsWithMaxLedgerVersionOffset instructionsWithMaxLedgerVersionOffset
); );
assertResultMatch(response, responses.prepareSettings.flags, "prepare"); assertResultMatch(response, responses.prepareSettings.flags, "prepare");
}, });
"no maxLedgerVersion": async (client, address, mockRippled) => { it("no maxLedgerVersion", async function () {
mockRippled.addResponse("server_info", rippled.server_info.normal); this.mockRippled.addResponse("server_info", rippled.server_info.normal);
mockRippled.addResponse("fee", rippled.fee); this.mockRippled.addResponse("fee", rippled.fee);
mockRippled.addResponse("ledger_current", rippled.ledger_current); this.mockRippled.addResponse("ledger_current", rippled.ledger_current);
mockRippled.addResponse("account_info", rippled.account_info.normal); this.mockRippled.addResponse(
const response = await client.prepareSettings( "account_info",
address, rippled.account_info.normal
);
const response = await this.client.prepareSettings(
test.address,
requests.prepareSettings.domain, requests.prepareSettings.domain,
{ {
maxLedgerVersion: null as unknown as undefined, maxLedgerVersion: null as unknown as undefined,
@@ -43,14 +50,17 @@ export default <TestSuite>{
responses.prepareSettings.noMaxLedgerVersion, responses.prepareSettings.noMaxLedgerVersion,
"prepare" "prepare"
); );
}, });
"no instructions": async (client, address, mockRippled) => { it("no instructions", async function () {
mockRippled.addResponse("server_info", rippled.server_info.normal); this.mockRippled.addResponse("server_info", rippled.server_info.normal);
mockRippled.addResponse("fee", rippled.fee); this.mockRippled.addResponse("fee", rippled.fee);
mockRippled.addResponse("ledger_current", rippled.ledger_current); this.mockRippled.addResponse("ledger_current", rippled.ledger_current);
mockRippled.addResponse("account_info", rippled.account_info.normal); this.mockRippled.addResponse(
const response = await client.prepareSettings( "account_info",
address, rippled.account_info.normal
);
const response = await this.client.prepareSettings(
test.address,
requests.prepareSettings.domain requests.prepareSettings.domain
); );
assertResultMatch( assertResultMatch(
@@ -58,15 +68,18 @@ export default <TestSuite>{
responses.prepareSettings.noInstructions, responses.prepareSettings.noInstructions,
"prepare" "prepare"
); );
}, });
async regularKey(client, address, mockRippled) { it("regularKey", async function () {
mockRippled.addResponse("server_info", rippled.server_info.normal); this.mockRippled.addResponse("server_info", rippled.server_info.normal);
mockRippled.addResponse("fee", rippled.fee); this.mockRippled.addResponse("fee", rippled.fee);
mockRippled.addResponse("ledger_current", rippled.ledger_current); this.mockRippled.addResponse("ledger_current", rippled.ledger_current);
mockRippled.addResponse("account_info", rippled.account_info.normal); this.mockRippled.addResponse(
"account_info",
rippled.account_info.normal
);
const regularKey = { regularKey: "rAR8rR8sUkBoCZFawhkWzY4Y5YoyuznwD" }; const regularKey = { regularKey: "rAR8rR8sUkBoCZFawhkWzY4Y5YoyuznwD" };
const response = await client.prepareSettings( const response = await this.client.prepareSettings(
address, test.address,
regularKey, regularKey,
instructionsWithMaxLedgerVersionOffset instructionsWithMaxLedgerVersionOffset
); );
@@ -75,15 +88,18 @@ export default <TestSuite>{
responses.prepareSettings.regularKey, responses.prepareSettings.regularKey,
"prepare" "prepare"
); );
}, });
"remove regularKey": async (client, address, mockRippled) => { it("remove regularKey", async function () {
mockRippled.addResponse("server_info", rippled.server_info.normal); this.mockRippled.addResponse("server_info", rippled.server_info.normal);
mockRippled.addResponse("fee", rippled.fee); this.mockRippled.addResponse("fee", rippled.fee);
mockRippled.addResponse("ledger_current", rippled.ledger_current); this.mockRippled.addResponse("ledger_current", rippled.ledger_current);
mockRippled.addResponse("account_info", rippled.account_info.normal); this.mockRippled.addResponse(
"account_info",
rippled.account_info.normal
);
const regularKey = { regularKey: null }; const regularKey = { regularKey: null };
const response = await client.prepareSettings( const response = await this.client.prepareSettings(
address, test.address,
regularKey as unknown as FormattedSettings, regularKey as unknown as FormattedSettings,
instructionsWithMaxLedgerVersionOffset instructionsWithMaxLedgerVersionOffset
); );
@@ -92,41 +108,58 @@ export default <TestSuite>{
responses.prepareSettings.removeRegularKey, responses.prepareSettings.removeRegularKey,
"prepare" "prepare"
); );
}, });
"flag set": async (client, address, mockRippled) => { it("flag set", async function () {
mockRippled.addResponse("server_info", rippled.server_info.normal); this.mockRippled.addResponse("server_info", rippled.server_info.normal);
mockRippled.addResponse("fee", rippled.fee); this.mockRippled.addResponse("fee", rippled.fee);
mockRippled.addResponse("ledger_current", rippled.ledger_current); this.mockRippled.addResponse("ledger_current", rippled.ledger_current);
mockRippled.addResponse("account_info", rippled.account_info.normal); this.mockRippled.addResponse(
"account_info",
rippled.account_info.normal
);
const settings = { requireDestinationTag: true }; const settings = { requireDestinationTag: true };
const response = await client.prepareSettings( const response = await this.client.prepareSettings(
address, test.address,
settings, settings,
instructionsWithMaxLedgerVersionOffset instructionsWithMaxLedgerVersionOffset
); );
assertResultMatch(response, responses.prepareSettings.flagSet, "prepare"); assertResultMatch(
}, response,
"flag clear": async (client, address, mockRippled) => { responses.prepareSettings.flagSet,
mockRippled.addResponse("server_info", rippled.server_info.normal); "prepare"
mockRippled.addResponse("fee", rippled.fee); );
mockRippled.addResponse("ledger_current", rippled.ledger_current); });
mockRippled.addResponse("account_info", rippled.account_info.normal); it("flag clear", async function () {
this.mockRippled.addResponse("server_info", rippled.server_info.normal);
this.mockRippled.addResponse("fee", rippled.fee);
this.mockRippled.addResponse("ledger_current", rippled.ledger_current);
this.mockRippled.addResponse(
"account_info",
rippled.account_info.normal
);
const settings = { requireDestinationTag: false }; const settings = { requireDestinationTag: false };
const response = await client.prepareSettings( const response = await this.client.prepareSettings(
address, test.address,
settings, settings,
instructionsWithMaxLedgerVersionOffset instructionsWithMaxLedgerVersionOffset
); );
assertResultMatch(response, responses.prepareSettings.flagClear, "prepare"); assertResultMatch(
}, response,
"set depositAuth flag": async (client, address, mockRippled) => { responses.prepareSettings.flagClear,
mockRippled.addResponse("server_info", rippled.server_info.normal); "prepare"
mockRippled.addResponse("fee", rippled.fee); );
mockRippled.addResponse("ledger_current", rippled.ledger_current); });
mockRippled.addResponse("account_info", rippled.account_info.normal); it("set depositAuth flag", async function () {
this.mockRippled.addResponse("server_info", rippled.server_info.normal);
this.mockRippled.addResponse("fee", rippled.fee);
this.mockRippled.addResponse("ledger_current", rippled.ledger_current);
this.mockRippled.addResponse(
"account_info",
rippled.account_info.normal
);
const settings = { depositAuth: true }; const settings = { depositAuth: true };
const response = await client.prepareSettings( const response = await this.client.prepareSettings(
address, test.address,
settings, settings,
instructionsWithMaxLedgerVersionOffset instructionsWithMaxLedgerVersionOffset
); );
@@ -135,15 +168,18 @@ export default <TestSuite>{
responses.prepareSettings.flagSetDepositAuth, responses.prepareSettings.flagSetDepositAuth,
"prepare" "prepare"
); );
}, });
"clear depositAuth flag": async (client, address, mockRippled) => { it("clear depositAuth flag", async function () {
mockRippled.addResponse("server_info", rippled.server_info.normal); this.mockRippled.addResponse("server_info", rippled.server_info.normal);
mockRippled.addResponse("fee", rippled.fee); this.mockRippled.addResponse("fee", rippled.fee);
mockRippled.addResponse("ledger_current", rippled.ledger_current); this.mockRippled.addResponse("ledger_current", rippled.ledger_current);
mockRippled.addResponse("account_info", rippled.account_info.normal); this.mockRippled.addResponse(
"account_info",
rippled.account_info.normal
);
const settings = { depositAuth: false }; const settings = { depositAuth: false };
const response = await client.prepareSettings( const response = await this.client.prepareSettings(
address, test.address,
settings, settings,
instructionsWithMaxLedgerVersionOffset instructionsWithMaxLedgerVersionOffset
); );
@@ -152,29 +188,35 @@ export default <TestSuite>{
responses.prepareSettings.flagClearDepositAuth, responses.prepareSettings.flagClearDepositAuth,
"prepare" "prepare"
); );
}, });
"integer field clear": async (client, address, mockRippled) => { it("integer field clear", async function () {
mockRippled.addResponse("server_info", rippled.server_info.normal); this.mockRippled.addResponse("server_info", rippled.server_info.normal);
mockRippled.addResponse("fee", rippled.fee); this.mockRippled.addResponse("fee", rippled.fee);
mockRippled.addResponse("ledger_current", rippled.ledger_current); this.mockRippled.addResponse("ledger_current", rippled.ledger_current);
mockRippled.addResponse("account_info", rippled.account_info.normal); this.mockRippled.addResponse(
"account_info",
rippled.account_info.normal
);
const settings = { transferRate: null }; const settings = { transferRate: null };
const response = await client.prepareSettings( const response = await this.client.prepareSettings(
address, test.address,
settings, settings,
instructionsWithMaxLedgerVersionOffset instructionsWithMaxLedgerVersionOffset
); );
assert(response); assert(response);
assert.strictEqual(JSON.parse(response.txJSON).TransferRate, 0); assert.strictEqual(JSON.parse(response.txJSON).TransferRate, 0);
}, });
"set transferRate": async (client, address, mockRippled) => { it("set transferRate", async function () {
mockRippled.addResponse("server_info", rippled.server_info.normal); this.mockRippled.addResponse("server_info", rippled.server_info.normal);
mockRippled.addResponse("fee", rippled.fee); this.mockRippled.addResponse("fee", rippled.fee);
mockRippled.addResponse("ledger_current", rippled.ledger_current); this.mockRippled.addResponse("ledger_current", rippled.ledger_current);
mockRippled.addResponse("account_info", rippled.account_info.normal); this.mockRippled.addResponse(
"account_info",
rippled.account_info.normal
);
const settings = { transferRate: 1 }; const settings = { transferRate: 1 };
const response = await client.prepareSettings( const response = await this.client.prepareSettings(
address, test.address,
settings, settings,
instructionsWithMaxLedgerVersionOffset instructionsWithMaxLedgerVersionOffset
); );
@@ -183,29 +225,39 @@ export default <TestSuite>{
responses.prepareSettings.setTransferRate, responses.prepareSettings.setTransferRate,
"prepare" "prepare"
); );
}, });
"set signers": async (client, address, mockRippled) => { it("set signers", async function () {
mockRippled.addResponse("server_info", rippled.server_info.normal); this.mockRippled.addResponse("server_info", rippled.server_info.normal);
mockRippled.addResponse("fee", rippled.fee); this.mockRippled.addResponse("fee", rippled.fee);
mockRippled.addResponse("ledger_current", rippled.ledger_current); this.mockRippled.addResponse("ledger_current", rippled.ledger_current);
mockRippled.addResponse("account_info", rippled.account_info.normal); this.mockRippled.addResponse(
"account_info",
rippled.account_info.normal
);
const settings = requests.prepareSettings.signers.normal; const settings = requests.prepareSettings.signers.normal;
const response = await client.prepareSettings( const response = await this.client.prepareSettings(
address, test.address,
settings, settings,
instructionsWithMaxLedgerVersionOffset instructionsWithMaxLedgerVersionOffset
); );
assertResultMatch(response, responses.prepareSettings.signers, "prepare"); assertResultMatch(
}, response,
"signers no threshold": async (client, address, mockRippled) => { responses.prepareSettings.signers,
mockRippled.addResponse("server_info", rippled.server_info.normal); "prepare"
mockRippled.addResponse("fee", rippled.fee); );
mockRippled.addResponse("ledger_current", rippled.ledger_current); });
mockRippled.addResponse("account_info", rippled.account_info.normal); it("signers no threshold", async function () {
this.mockRippled.addResponse("server_info", rippled.server_info.normal);
this.mockRippled.addResponse("fee", rippled.fee);
this.mockRippled.addResponse("ledger_current", rippled.ledger_current);
this.mockRippled.addResponse(
"account_info",
rippled.account_info.normal
);
const settings = requests.prepareSettings.signers.noThreshold; const settings = requests.prepareSettings.signers.noThreshold;
try { try {
const response = await client.prepareSettings( const response = await this.client.prepareSettings(
address, test.address,
settings, settings,
instructionsWithMaxLedgerVersionOffset instructionsWithMaxLedgerVersionOffset
); );
@@ -221,35 +273,45 @@ export default <TestSuite>{
); );
assert.strictEqual(err.name, "ValidationError"); assert.strictEqual(err.name, "ValidationError");
} }
}, });
"signers no weights": async (client, address, mockRippled) => { it("signers no weights", async function () {
mockRippled.addResponse("server_info", rippled.server_info.normal); this.mockRippled.addResponse("server_info", rippled.server_info.normal);
mockRippled.addResponse("fee", rippled.fee); this.mockRippled.addResponse("fee", rippled.fee);
mockRippled.addResponse("ledger_current", rippled.ledger_current); this.mockRippled.addResponse("ledger_current", rippled.ledger_current);
mockRippled.addResponse("account_info", rippled.account_info.normal); this.mockRippled.addResponse(
"account_info",
rippled.account_info.normal
);
const settings = requests.prepareSettings.signers.noWeights; const settings = requests.prepareSettings.signers.noWeights;
const localInstructions = { const localInstructions = {
signersCount: 1, signersCount: 1,
...instructionsWithMaxLedgerVersionOffset, ...instructionsWithMaxLedgerVersionOffset,
}; };
const response = await client.prepareSettings( const response = await this.client.prepareSettings(
address, test.address,
settings, settings,
localInstructions localInstructions
); );
assertResultMatch(response, responses.prepareSettings.noWeights, "prepare"); assertResultMatch(
}, response,
"fee for multisign": async (client, address, mockRippled) => { responses.prepareSettings.noWeights,
mockRippled.addResponse("server_info", rippled.server_info.normal); "prepare"
mockRippled.addResponse("fee", rippled.fee); );
mockRippled.addResponse("ledger_current", rippled.ledger_current); });
mockRippled.addResponse("account_info", rippled.account_info.normal); it("fee for multisign", async function () {
this.mockRippled.addResponse("server_info", rippled.server_info.normal);
this.mockRippled.addResponse("fee", rippled.fee);
this.mockRippled.addResponse("ledger_current", rippled.ledger_current);
this.mockRippled.addResponse(
"account_info",
rippled.account_info.normal
);
const localInstructions = { const localInstructions = {
signersCount: 4, signersCount: 4,
...instructionsWithMaxLedgerVersionOffset, ...instructionsWithMaxLedgerVersionOffset,
}; };
const response = await client.prepareSettings( const response = await this.client.prepareSettings(
address, test.address,
requests.prepareSettings.domain, requests.prepareSettings.domain,
localInstructions localInstructions
); );
@@ -258,19 +320,22 @@ export default <TestSuite>{
responses.prepareSettings.flagsMultisign, responses.prepareSettings.flagsMultisign,
"prepare" "prepare"
); );
}, });
"no signer list": async (client, address, mockRippled) => { it("no signer list", async function () {
mockRippled.addResponse("server_info", rippled.server_info.normal); this.mockRippled.addResponse("server_info", rippled.server_info.normal);
mockRippled.addResponse("fee", rippled.fee); this.mockRippled.addResponse("fee", rippled.fee);
mockRippled.addResponse("ledger_current", rippled.ledger_current); this.mockRippled.addResponse("ledger_current", rippled.ledger_current);
mockRippled.addResponse("account_info", rippled.account_info.normal); this.mockRippled.addResponse(
"account_info",
rippled.account_info.normal
);
const settings = requests.prepareSettings.noSignerEntries; const settings = requests.prepareSettings.noSignerEntries;
const localInstructions = { const localInstructions = {
signersCount: 1, signersCount: 1,
...instructionsWithMaxLedgerVersionOffset, ...instructionsWithMaxLedgerVersionOffset,
}; };
const response = await client.prepareSettings( const response = await this.client.prepareSettings(
address, test.address,
settings, settings,
localInstructions localInstructions
); );
@@ -279,12 +344,15 @@ export default <TestSuite>{
responses.prepareSettings.noSignerList, responses.prepareSettings.noSignerList,
"prepare" "prepare"
); );
}, });
async invalid(client, address, mockRippled) { it("invalid", async function () {
mockRippled.addResponse("server_info", rippled.server_info.normal); this.mockRippled.addResponse("server_info", rippled.server_info.normal);
mockRippled.addResponse("fee", rippled.fee); this.mockRippled.addResponse("fee", rippled.fee);
mockRippled.addResponse("ledger_current", rippled.ledger_current); this.mockRippled.addResponse("ledger_current", rippled.ledger_current);
mockRippled.addResponse("account_info", rippled.account_info.normal); this.mockRippled.addResponse(
"account_info",
rippled.account_info.normal
);
// domain must be a string // domain must be a string
const settings = { ...requests.prepareSettings.domain, domain: 123 }; const settings = { ...requests.prepareSettings.domain, domain: 123 };
const localInstructions = { const localInstructions = {
@@ -293,8 +361,8 @@ export default <TestSuite>{
}; };
try { try {
const response = await client.prepareSettings( const response = await this.client.prepareSettings(
address, test.address,
settings, settings,
localInstructions localInstructions
); );
@@ -310,12 +378,15 @@ export default <TestSuite>{
); );
assert.strictEqual(err.name, "ValidationError"); assert.strictEqual(err.name, "ValidationError");
} }
}, });
async offline(client, address, mockRippled) { it("offline", async function () {
mockRippled.addResponse("server_info", rippled.server_info.normal); this.mockRippled.addResponse("server_info", rippled.server_info.normal);
mockRippled.addResponse("fee", rippled.fee); this.mockRippled.addResponse("fee", rippled.fee);
mockRippled.addResponse("ledger_current", rippled.ledger_current); this.mockRippled.addResponse("ledger_current", rippled.ledger_current);
mockRippled.addResponse("account_info", rippled.account_info.normal); this.mockRippled.addResponse(
"account_info",
rippled.account_info.normal
);
const secret = "shsWGZcmZz6YsWWmcnpfr6fLTdtFV"; const secret = "shsWGZcmZz6YsWWmcnpfr6fLTdtFV";
const settings = requests.prepareSettings.domain; const settings = requests.prepareSettings.domain;
@@ -324,32 +395,41 @@ export default <TestSuite>{
maxLedgerVersion: 8820051, maxLedgerVersion: 8820051,
fee: "0.000012", fee: "0.000012",
}; };
const result = await client.prepareSettings( const result = await this.client.prepareSettings(
address, test.address,
settings, settings,
instructions instructions
); );
assertResultMatch(result, responses.prepareSettings.flags, "prepare"); assertResultMatch(result, responses.prepareSettings.flags, "prepare");
assert.deepEqual( assert.deepEqual(
client.sign(result.txJSON, secret), this.client.sign(result.txJSON, secret),
responses.prepareSettings.signed responses.prepareSettings.signed
); );
}, });
"prepare settings with ticket": async (client, address, mockRippled) => { it("prepare settings with ticket", async function () {
mockRippled.addResponse("server_info", rippled.server_info.normal); this.mockRippled.addResponse("server_info", rippled.server_info.normal);
mockRippled.addResponse("fee", rippled.fee); this.mockRippled.addResponse("fee", rippled.fee);
mockRippled.addResponse("ledger_current", rippled.ledger_current); this.mockRippled.addResponse("ledger_current", rippled.ledger_current);
mockRippled.addResponse("account_info", rippled.account_info.normal); this.mockRippled.addResponse(
"account_info",
rippled.account_info.normal
);
const instructions = { const instructions = {
ticketSequence: 23, ticketSequence: 23,
maxLedgerVersion: 8820051, maxLedgerVersion: 8820051,
fee: "0.000012", fee: "0.000012",
}; };
const response = await client.prepareSettings( const response = await this.client.prepareSettings(
address, test.address,
requests.prepareSettings.domain, requests.prepareSettings.domain,
instructions instructions
); );
assertResultMatch(response, responses.prepareSettings.ticket, "prepare"); assertResultMatch(
}, response,
}; responses.prepareSettings.ticket,
"prepare"
);
});
});
});
});

View File

@@ -1,5 +1,6 @@
import rippled from "../fixtures/rippled"; import rippled from "../fixtures/rippled";
import { assertResultMatch, TestSuite } from "../testUtils"; import setupClient from "../setupClient";
import { assertResultMatch, addressTests } from "../testUtils";
// import responses from '../fixtures/responses' // import responses from '../fixtures/responses'
// import requests from '../fixtures/requests' // import requests from '../fixtures/requests'
// import {ValidationError} from 'xrpl-local/common/errors' // import {ValidationError} from 'xrpl-local/common/errors'
@@ -13,21 +14,20 @@ import { assertResultMatch, TestSuite } from "../testUtils";
// const {preparePayment: RESPONSE_FIXTURES} = responses // const {preparePayment: RESPONSE_FIXTURES} = responses
// const ADDRESS = 'rpZc4mVfWUif9CRoHRKKcmhu1nx2xktxBo' // const ADDRESS = 'rpZc4mVfWUif9CRoHRKKcmhu1nx2xktxBo'
/** describe("client.prepareTicket", function () {
* Every test suite exports their tests in the default object. beforeEach(setupClient.setup);
* - Check out the "TestSuite" type for documentation on the interface. afterEach(setupClient.teardown);
* - Check out "test/client/index.ts" for more information about the test runner.
*/ addressTests.forEach(function (test) {
export default <TestSuite>{ describe(test.type, function () {
"creates a ticket successfully with a sequence number": async ( it("creates a ticket successfully with a sequence number", async function () {
client, this.mockRippled.addResponse("server_info", rippled.server_info.normal);
address, this.mockRippled.addResponse("fee", rippled.fee);
mockRippled this.mockRippled.addResponse("ledger_current", rippled.ledger_current);
) => { this.mockRippled.addResponse(
mockRippled.addResponse("server_info", rippled.server_info.normal); "account_info",
mockRippled.addResponse("fee", rippled.fee); rippled.account_info.normal
mockRippled.addResponse("ledger_current", rippled.ledger_current); );
mockRippled.addResponse("account_info", rippled.account_info.normal);
const expected = { const expected = {
txJSON: txJSON:
'{"TransactionType":"TicketCreate", "TicketCount": 2, "Account":"r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59","Flags":2147483648,"LastLedgerSequence":8819954,"Sequence":23,"Fee":"12"}', '{"TransactionType":"TicketCreate", "TicketCount": 2, "Account":"r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59","Flags":2147483648,"LastLedgerSequence":8819954,"Sequence":23,"Fee":"12"}',
@@ -37,19 +37,18 @@ export default <TestSuite>{
fee: "0.000012", fee: "0.000012",
}, },
}; };
const response = await client.prepareTicketCreate(address, 2); const response = await this.client.prepareTicketCreate(test.address, 2);
assertResultMatch(response, expected, "prepare"); assertResultMatch(response, expected, "prepare");
}, });
"creates a ticket successfully with another ticket": async ( it("creates a ticket successfully with another ticket", async function () {
client, this.mockRippled.addResponse("server_info", rippled.server_info.normal);
address, this.mockRippled.addResponse("fee", rippled.fee);
mockRippled this.mockRippled.addResponse("ledger_current", rippled.ledger_current);
) => { this.mockRippled.addResponse(
mockRippled.addResponse("server_info", rippled.server_info.normal); "account_info",
mockRippled.addResponse("fee", rippled.fee); rippled.account_info.normal
mockRippled.addResponse("ledger_current", rippled.ledger_current); );
mockRippled.addResponse("account_info", rippled.account_info.normal);
const expected = { const expected = {
txJSON: txJSON:
'{"TransactionType":"TicketCreate", "TicketCount": 1, "Account":"r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59","Flags":2147483648,"LastLedgerSequence":8819954,"Sequence": 0,"TicketSequence":23,"Fee":"12"}', '{"TransactionType":"TicketCreate", "TicketCount": 1, "Account":"r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59","Flags":2147483648,"LastLedgerSequence":8819954,"Sequence": 0,"TicketSequence":23,"Fee":"12"}',
@@ -64,7 +63,13 @@ export default <TestSuite>{
ticketSequence: 23, ticketSequence: 23,
fee: "0.000012", fee: "0.000012",
}; };
const response = await client.prepareTicketCreate(address, 1, instructions); const response = await this.client.prepareTicketCreate(
test.address,
1,
instructions
);
assertResultMatch(response, expected, "prepare"); assertResultMatch(response, expected, "prepare");
}, });
}; });
});
});

File diff suppressed because it is too large Load Diff

View File

@@ -1,80 +1,100 @@
import requests from "../fixtures/requests"; import requests from "../fixtures/requests";
import responses from "../fixtures/responses"; import responses from "../fixtures/responses";
import rippled from "../fixtures/rippled"; import rippled from "../fixtures/rippled";
import { assertRejects, assertResultMatch, TestSuite } from "../testUtils"; import setupClient from "../setupClient";
import { assertRejects, assertResultMatch, addressTests } from "../testUtils";
const instructionsWithMaxLedgerVersionOffset = { maxLedgerVersionOffset: 100 }; const instructionsWithMaxLedgerVersionOffset = { maxLedgerVersionOffset: 100 };
/** describe("client.prepareTrustline", function () {
* Every test suite exports their tests in the default object. beforeEach(setupClient.setup);
* - Check out the "TestSuite" type for documentation on the interface. afterEach(setupClient.teardown);
* - Check out "test/client/index.ts" for more information about the test runner.
*/ addressTests.forEach(function (test) {
export default <TestSuite>{ describe(test.type, function () {
async simple(client, address, mockRippled) { it("simple", async function () {
mockRippled.addResponse("server_info", rippled.server_info.normal); this.mockRippled.addResponse("server_info", rippled.server_info.normal);
mockRippled.addResponse("fee", rippled.fee); this.mockRippled.addResponse("fee", rippled.fee);
mockRippled.addResponse("ledger_current", rippled.ledger_current); this.mockRippled.addResponse("ledger_current", rippled.ledger_current);
mockRippled.addResponse("account_info", rippled.account_info.normal); this.mockRippled.addResponse(
const result = await client.prepareTrustline( "account_info",
address, rippled.account_info.normal
);
const result = await this.client.prepareTrustline(
test.address,
requests.prepareTrustline.simple, requests.prepareTrustline.simple,
instructionsWithMaxLedgerVersionOffset instructionsWithMaxLedgerVersionOffset
); );
assertResultMatch(result, responses.prepareTrustline.simple, "prepare"); assertResultMatch(result, responses.prepareTrustline.simple, "prepare");
}, });
async frozen(client, address, mockRippled) { it("frozen", async function () {
mockRippled.addResponse("server_info", rippled.server_info.normal); this.mockRippled.addResponse("server_info", rippled.server_info.normal);
mockRippled.addResponse("fee", rippled.fee); this.mockRippled.addResponse("fee", rippled.fee);
mockRippled.addResponse("ledger_current", rippled.ledger_current); this.mockRippled.addResponse("ledger_current", rippled.ledger_current);
mockRippled.addResponse("account_info", rippled.account_info.normal); this.mockRippled.addResponse(
const result = await client.prepareTrustline( "account_info",
address, rippled.account_info.normal
);
const result = await this.client.prepareTrustline(
test.address,
requests.prepareTrustline.frozen requests.prepareTrustline.frozen
); );
assertResultMatch(result, responses.prepareTrustline.frozen, "prepare"); assertResultMatch(result, responses.prepareTrustline.frozen, "prepare");
}, });
async complex(client, address, mockRippled) { it("complex", async function () {
mockRippled.addResponse("server_info", rippled.server_info.normal); this.mockRippled.addResponse("server_info", rippled.server_info.normal);
mockRippled.addResponse("fee", rippled.fee); this.mockRippled.addResponse("fee", rippled.fee);
mockRippled.addResponse("ledger_current", rippled.ledger_current); this.mockRippled.addResponse("ledger_current", rippled.ledger_current);
mockRippled.addResponse("account_info", rippled.account_info.normal); this.mockRippled.addResponse(
const result = await client.prepareTrustline( "account_info",
address, rippled.account_info.normal
);
const result = await this.client.prepareTrustline(
test.address,
requests.prepareTrustline.complex, requests.prepareTrustline.complex,
instructionsWithMaxLedgerVersionOffset instructionsWithMaxLedgerVersionOffset
); );
assertResultMatch(result, responses.prepareTrustline.complex, "prepare"); assertResultMatch(
}, result,
responses.prepareTrustline.complex,
"prepare"
);
});
async invalid(client, address, mockRippled) { it("invalid", async function () {
mockRippled.addResponse("server_info", rippled.server_info.normal); this.mockRippled.addResponse("server_info", rippled.server_info.normal);
mockRippled.addResponse("fee", rippled.fee); this.mockRippled.addResponse("fee", rippled.fee);
mockRippled.addResponse("ledger_current", rippled.ledger_current); this.mockRippled.addResponse("ledger_current", rippled.ledger_current);
mockRippled.addResponse("account_info", rippled.account_info.normal); this.mockRippled.addResponse(
"account_info",
rippled.account_info.normal
);
const trustline = { ...requests.prepareTrustline.complex }; const trustline = { ...requests.prepareTrustline.complex };
delete trustline.limit; // Make invalid delete trustline.limit; // Make invalid
await assertRejects( await assertRejects(
client.prepareTrustline( this.client.prepareTrustline(
address, test.address,
trustline, trustline,
instructionsWithMaxLedgerVersionOffset instructionsWithMaxLedgerVersionOffset
), ),
client.errors.ValidationError, this.client.errors.ValidationError,
'instance.trustline requires property "limit"' 'instance.trustline requires property "limit"'
); );
}, });
"xaddress-issuer": async (client, address, mockRippled) => { it("xtest.address-issuer", async function () {
mockRippled.addResponse("server_info", rippled.server_info.normal); this.mockRippled.addResponse("server_info", rippled.server_info.normal);
mockRippled.addResponse("fee", rippled.fee); this.mockRippled.addResponse("fee", rippled.fee);
mockRippled.addResponse("ledger_current", rippled.ledger_current); this.mockRippled.addResponse("ledger_current", rippled.ledger_current);
mockRippled.addResponse("account_info", rippled.account_info.normal); this.mockRippled.addResponse(
const result = await client.prepareTrustline( "account_info",
address, rippled.account_info.normal
);
const result = await this.client.prepareTrustline(
test.address,
requests.prepareTrustline.issuedXAddress, requests.prepareTrustline.issuedXAddress,
instructionsWithMaxLedgerVersionOffset instructionsWithMaxLedgerVersionOffset
); );
@@ -83,23 +103,28 @@ export default <TestSuite>{
responses.prepareTrustline.issuedXAddress, responses.prepareTrustline.issuedXAddress,
"prepare" "prepare"
); );
}, });
"with ticket": async (client, address, mockRippled) => { it("with ticket", async function () {
mockRippled.addResponse("server_info", rippled.server_info.normal); this.mockRippled.addResponse("server_info", rippled.server_info.normal);
mockRippled.addResponse("fee", rippled.fee); this.mockRippled.addResponse("fee", rippled.fee);
mockRippled.addResponse("ledger_current", rippled.ledger_current); this.mockRippled.addResponse("ledger_current", rippled.ledger_current);
mockRippled.addResponse("account_info", rippled.account_info.normal); this.mockRippled.addResponse(
"account_info",
rippled.account_info.normal
);
const localInstructions = { const localInstructions = {
...instructionsWithMaxLedgerVersionOffset, ...instructionsWithMaxLedgerVersionOffset,
maxFee: "0.000012", maxFee: "0.000012",
ticketSequence: 23, ticketSequence: 23,
}; };
const result = await client.prepareTrustline( const result = await this.client.prepareTrustline(
address, test.address,
requests.prepareTrustline.simple, requests.prepareTrustline.simple,
localInstructions localInstructions
); );
assertResultMatch(result, responses.prepareTrustline.ticket, "prepare"); assertResultMatch(result, responses.prepareTrustline.ticket, "prepare");
}, });
}; });
});
});

View File

@@ -1,18 +1,22 @@
import responses from "../fixtures/responses"; import responses from "../fixtures/responses";
import rippled from "../fixtures/rippled"; import rippled from "../fixtures/rippled";
import { TestSuite, assertResultMatch } from "../testUtils"; import setupClient from "../setupClient";
import { addressTests, assertResultMatch } from "../testUtils";
/** describe("client.request", function () {
* Every test suite exports their tests in the default object. beforeEach(setupClient.setup);
* - Check out the "TestSuite" type for documentation on the interface. afterEach(setupClient.teardown);
* - Check out "test/client/index.ts" for more information about the test runner.
*/ addressTests.forEach(function (test) {
export default <TestSuite>{ describe(test.type, function () {
"request account_objects": async (client, address, mockRippled) => { it("request account_objects", async function () {
mockRippled.addResponse("account_objects", rippled.account_objects.normal); this.mockRippled.addResponse(
const result = await client.request({ "account_objects",
rippled.account_objects.normal
);
const result = await this.client.request({
command: "account_objects", command: "account_objects",
account: address, account: test.address,
}); });
assertResultMatch( assertResultMatch(
@@ -20,17 +24,16 @@ export default <TestSuite>{
responses.getAccountObjects, responses.getAccountObjects,
"AccountObjectsResponse" "AccountObjectsResponse"
); );
}, });
"request account_objects - invalid options": async ( it("request account_objects - invalid options", async function () {
client, this.mockRippled.addResponse(
address, "account_objects",
mockRippled rippled.account_objects.normal
) => { );
mockRippled.addResponse("account_objects", rippled.account_objects.normal); const result = await this.client.request({
const result = await client.request({
command: "account_objects", command: "account_objects",
account: address, account: test.address,
}); });
assertResultMatch( assertResultMatch(
@@ -38,5 +41,7 @@ export default <TestSuite>{
responses.getAccountObjects, responses.getAccountObjects,
"AccountObjectsResponse" "AccountObjectsResponse"
); );
}, });
}; });
});
});

View File

@@ -1,7 +1,8 @@
import { assert } from "chai"; import { assert } from "chai";
import rippled from "../fixtures/rippled"; import rippled from "../fixtures/rippled";
import { assertRejects, TestSuite } from "../testUtils"; import setupClient from "../setupClient";
import { assertRejects } from "../testUtils";
const rippledResponse = function (request: Request): object { const rippledResponse = function (request: Request): object {
if ("marker" in request) { if ("marker" in request) {
@@ -10,16 +11,13 @@ const rippledResponse = function (request: Request): object {
return rippled.ledger_data.first_page; return rippled.ledger_data.first_page;
}; };
/** describe("client.requestNextPage", function () {
* Every test suite exports their tests in the default object. beforeEach(setupClient.setup);
* - Check out the "TestSuite" type for documentation on the interface. afterEach(setupClient.teardown);
* - Check out "test/client/index.ts" for more information about the test runner. it("requests the next page", async function () {
*/ this.mockRippled.addResponse("ledger_data", rippledResponse);
export default <TestSuite>{ const response = await this.client.request({ command: "ledger_data" });
"requests the next page": async (client, address, mockRippled) => { const responseNextPage = await this.client.requestNextPage(
mockRippled.addResponse("ledger_data", rippledResponse);
const response = await client.request({ command: "ledger_data" });
const responseNextPage = await client.requestNextPage(
{ command: "ledger_data" }, { command: "ledger_data" },
response response
); );
@@ -27,24 +25,20 @@ export default <TestSuite>{
responseNextPage.result.state[0].index, responseNextPage.result.state[0].index,
"000B714B790C3C79FEE00D17C4DEB436B375466F29679447BA64F265FD63D731" "000B714B790C3C79FEE00D17C4DEB436B375466F29679447BA64F265FD63D731"
); );
}, });
"rejects when there are no more pages": async ( it("rejects when there are no more pages", async function () {
client, this.mockRippled.addResponse("ledger_data", rippledResponse);
address, const response = await this.client.request({ command: "ledger_data" });
mockRippled const responseNextPage = await this.client.requestNextPage(
) => {
mockRippled.addResponse("ledger_data", rippledResponse);
const response = await client.request({ command: "ledger_data" });
const responseNextPage = await client.requestNextPage(
{ command: "ledger_data" }, { command: "ledger_data" },
response response
); );
assert(!client.hasNextPage(responseNextPage)); assert(!this.client.hasNextPage(responseNextPage));
await assertRejects( await assertRejects(
client.requestNextPage({ command: "ledger_data" }, responseNextPage), this.client.requestNextPage({ command: "ledger_data" }, responseNextPage),
Error, Error,
"response does not have a next page" "response does not have a next page"
); );
}, });
}; });

View File

@@ -6,26 +6,23 @@ import * as schemaValidator from "xrpl-local/common/schema-validator";
import requests from "../fixtures/requests"; import requests from "../fixtures/requests";
import responses from "../fixtures/responses"; import responses from "../fixtures/responses";
import rippled from "../fixtures/rippled"; import rippled from "../fixtures/rippled";
import { TestSuite } from "../testUtils"; import setupClient from "../setupClient";
import { addressTests } from "../testUtils";
const { sign: REQUEST_FIXTURES } = requests; const { sign: REQUEST_FIXTURES } = requests;
const { sign: RESPONSE_FIXTURES } = responses; const { sign: RESPONSE_FIXTURES } = responses;
/** describe("client.sign", function () {
* Every test suite exports their tests in the default object. beforeEach(setupClient.setup);
* - Check out the "TestSuite" type for documentation on the interface. afterEach(setupClient.teardown);
* - Check out "test/client/index.ts" for more information about the test runner. it("sign", async function () {
*/
export default <TestSuite>{
async sign(client, address) {
const secret = "shsWGZcmZz6YsWWmcnpfr6fLTdtFV"; const secret = "shsWGZcmZz6YsWWmcnpfr6fLTdtFV";
const result = client.sign(REQUEST_FIXTURES.normal.txJSON, secret); const result = this.client.sign(REQUEST_FIXTURES.normal.txJSON, secret);
assert.deepEqual(result, RESPONSE_FIXTURES.normal); assert.deepEqual(result, RESPONSE_FIXTURES.normal);
schemaValidator.schemaValidate("sign", result); schemaValidator.schemaValidate("sign", result);
}, });
"sign with lowercase hex data in memo (hex should be case insensitive)": it("sign with lowercase hex data in memo (hex should be case insensitive)", async function () {
async (client, address) => {
const secret = "shd2nxpFD6iBRKWsRss2P4tKMWyy9"; const secret = "shd2nxpFD6iBRKWsRss2P4tKMWyy9";
const lowercaseMemoTxJson = { const lowercaseMemoTxJson = {
TransactionType: "Payment", TransactionType: "Payment",
@@ -50,23 +47,244 @@ export default <TestSuite>{
}; };
const txParams = JSON.stringify(lowercaseMemoTxJson); const txParams = JSON.stringify(lowercaseMemoTxJson);
const result = client.sign(txParams, secret); const result = this.client.sign(txParams, secret);
assert.deepEqual(result, { assert.deepEqual(result, {
signedTransaction: signedTransaction:
"120000228000000023000022B8240000000C2E0000270F201B00D5A36761400000000098968068400000000000000C73210305E09ED602D40AB1AF65646A4007C2DAC17CB6CDACDE301E74FB2D728EA057CF744730450221009C00E8439E017CA622A5A1EE7643E26B4DE9C808DE2ABE45D33479D49A4CEC66022062175BE8733442FA2A4D9A35F85A57D58252AE7B19A66401FE238B36FA28E5A081146C1856D0E36019EA75C56D7E8CBA6E35F9B3F71583147FB49CD110A1C46838788CD12764E3B0F837E0DDF9EA7C1F687474703A2F2F6578616D706C652E636F6D2F6D656D6F2F67656E657269637D0472656E74E1F1", "120000228000000023000022B8240000000C2E0000270F201B00D5A36761400000000098968068400000000000000C73210305E09ED602D40AB1AF65646A4007C2DAC17CB6CDACDE301E74FB2D728EA057CF744730450221009C00E8439E017CA622A5A1EE7643E26B4DE9C808DE2ABE45D33479D49A4CEC66022062175BE8733442FA2A4D9A35F85A57D58252AE7B19A66401FE238B36FA28E5A081146C1856D0E36019EA75C56D7E8CBA6E35F9B3F71583147FB49CD110A1C46838788CD12764E3B0F837E0DDF9EA7C1F687474703A2F2F6578616D706C652E636F6D2F6D656D6F2F67656E657269637D0472656E74E1F1",
id: "41B9CB78D8E18A796CDD4B0BC6FB0EA19F64C4F25FDE23049197852CAB71D10D", id: "41B9CB78D8E18A796CDD4B0BC6FB0EA19F64C4F25FDE23049197852CAB71D10D",
}); });
}, });
"sign with paths": async (client, address, mockRippled) => { it("EscrowExecution", async function () {
mockRippled.addResponse("server_info", rippled.server_info.normal); const secret = "snoPBrXtMeMyMHUVTgbuqAfg1SUTb";
mockRippled.addResponse("fee", rippled.fee); const result = this.client.sign(REQUEST_FIXTURES.escrow.txJSON, secret);
mockRippled.addResponse("ledger_current", rippled.ledger_current); assert.deepEqual(result, RESPONSE_FIXTURES.escrow);
mockRippled.addResponse("account_info", rippled.account_info.normal); schemaValidator.schemaValidate("sign", result);
});
it("signAs", async function () {
const txJSON = REQUEST_FIXTURES.signAs;
const secret = "snoPBrXtMeMyMHUVTgbuqAfg1SUTb";
const signature = this.client.sign(JSON.stringify(txJSON), secret, {
signAs: "rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh",
});
assert.deepEqual(signature, RESPONSE_FIXTURES.signAs);
});
it("withKeypair", async function () {
const keypair = {
privateKey:
"00ACCD3309DB14D1A4FC9B1DAE608031F4408C85C73EE05E035B7DC8B25840107A",
publicKey:
"02F89EAEC7667B30F33D0687BBA86C3FE2A08CCA40A9186C5BDE2DAA6FA97A37D8",
};
const result = this.client.sign(REQUEST_FIXTURES.normal.txJSON, keypair);
assert.deepEqual(result, RESPONSE_FIXTURES.normal);
schemaValidator.schemaValidate("sign", result);
});
it("withKeypair already signed", async function () {
const keypair = {
privateKey:
"00ACCD3309DB14D1A4FC9B1DAE608031F4408C85C73EE05E035B7DC8B25840107A",
publicKey:
"02F89EAEC7667B30F33D0687BBA86C3FE2A08CCA40A9186C5BDE2DAA6FA97A37D8",
};
const result = this.client.sign(REQUEST_FIXTURES.normal.txJSON, keypair);
assert.throws(() => {
const tx = JSON.stringify(binary.decode(result.signedTransaction));
this.client.sign(tx, keypair);
}, /txJSON must not contain "TxnSignature" or "Signers" properties/);
});
it("withKeypair EscrowExecution", async function () {
const keypair = {
privateKey:
"001ACAAEDECE405B2A958212629E16F2EB46B153EEE94CDD350FDEFF52795525B7",
publicKey:
"0330E7FC9D56BB25D6893BA3F317AE5BCF33B3291BD63DB32654A313222F7FD020",
};
const result = this.client.sign(REQUEST_FIXTURES.escrow.txJSON, keypair);
assert.deepEqual(result, RESPONSE_FIXTURES.escrow);
schemaValidator.schemaValidate("sign", result);
});
it("withKeypair signAs", async function () {
const txJSON = REQUEST_FIXTURES.signAs;
const keypair = {
privateKey:
"001ACAAEDECE405B2A958212629E16F2EB46B153EEE94CDD350FDEFF52795525B7",
publicKey:
"0330E7FC9D56BB25D6893BA3F317AE5BCF33B3291BD63DB32654A313222F7FD020",
};
const signature = this.client.sign(JSON.stringify(txJSON), keypair, {
signAs: "rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh",
});
assert.deepEqual(signature, RESPONSE_FIXTURES.signAs);
});
it("already signed", async function () {
const secret = "shsWGZcmZz6YsWWmcnpfr6fLTdtFV";
const result = this.client.sign(REQUEST_FIXTURES.normal.txJSON, secret);
assert.throws(() => {
const tx = JSON.stringify(binary.decode(result.signedTransaction));
this.client.sign(tx, secret);
}, /txJSON must not contain "TxnSignature" or "Signers" properties/);
});
it("succeeds - no flags", async function () {
const txJSON =
'{"TransactionType":"Payment","Account":"r45Rev1EXGxy2hAUmJPCne97KUE7qyrD3j","Destination":"rQ3PTWGLCbPz8ZCicV5tCX3xuymojTng5r","Amount":"20000000","Sequence":1,"Fee":"12"}';
const secret = "shotKgaEotpcYsshSE39vmSnBDRim";
const result = this.client.sign(txJSON, secret);
const expectedResult = {
signedTransaction:
"1200002400000001614000000001312D0068400000000000000C7321022B05847086686F9D0499B13136B94AD4323EE1B67D4C429ECC987AB35ACFA34574473045022100C104B7B97C31FACA4597E7D6FCF13BD85BD11375963A62A0AC45B0061236E39802207784F157F6A98DFC85B051CDDF61CC3084C4F5750B82674801C8E9950280D1998114EE3046A5DDF8422C40DDB93F1D522BB4FE6419158314FDB08D07AAA0EB711793A3027304D688E10C3648",
id: "0596925967F541BF332FF6756645B2576A9858414B5B363DC3D34915BE8A70D6",
};
const decoded = binary.decode(result.signedTransaction);
assert(
decoded.Flags == null,
`Flags = ${decoded.Flags}, should be undefined`
);
assert.deepEqual(result, expectedResult);
schemaValidator.schemaValidate("sign", result);
});
it("sign succeeds with source.amount/destination.minAmount", async function () {
// See also: 'preparePayment with source.amount/destination.minAmount'
const txJSON =
'{"TransactionType":"Payment","Account":"r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59","Destination":"rEX4LtGJubaUcMWCJULcy4NVxGT9ZEMVRq","Amount":{"currency":"USD","issuer":"rMaa8VLBTjwTJWA2kSme4Sqgphhr6Lr6FH","value":"999999999999999900000000000000000000000000000000000000000000000000000000000000000000000000000000"},"Flags":2147614720,"SendMax":{"currency":"GBP","issuer":"rpat5TmYjDsnFSStmgTumFgXCM9eqsWPro","value":"0.1"},"DeliverMin":{"currency":"USD","issuer":"rMaa8VLBTjwTJWA2kSme4Sqgphhr6Lr6FH","value":"0.1248548562296331"},"Sequence":23,"LastLedgerSequence":8820051,"Fee":"12"}';
const secret = "shotKgaEotpcYsshSE39vmSnBDRim";
const result = this.client.sign(txJSON, secret);
const expectedResult = {
signedTransaction:
"12000022800200002400000017201B0086955361EC6386F26FC0FFFF0000000000000000000000005553440000000000DC596C88BCDE4E818D416FCDEEBF2C8656BADC9A68400000000000000C69D4438D7EA4C6800000000000000000000000000047425000000000000C155FFE99C8C91F67083CEFFDB69EBFE76348CA6AD4446F8C5D8A5E0B0000000000000000000000005553440000000000DC596C88BCDE4E818D416FCDEEBF2C8656BADC9A7321022B05847086686F9D0499B13136B94AD4323EE1B67D4C429ECC987AB35ACFA34574473045022100D9634523D8E232D4A7807A71856023D82AC928FA29848571B820867898413B5F022041AC00EC1F81A26A6504EBF844A38CC3204694EF2CC1A97A87632721631F93DA81145E7B112523F68D2F5E879DB4EAC51C6698A6930483149F500E50C2F016CA01945E5A1E5846B61EF2D376",
id: "1C558AA9B926C24FB6BBD6950B2DB1350A83F9F12E4385208867907019761A2D",
};
const decoded = binary.decode(result.signedTransaction);
assert(
decoded.Flags === 2147614720,
`Flags = ${decoded.Flags}, should be 2147614720`
);
assert.deepEqual(result, expectedResult);
schemaValidator.schemaValidate("sign", result);
});
it("throws when encoded tx does not match decoded tx - AccountSet", async function () {
const secret = "shsWGZcmZz6YsWWmcnpfr6fLTdtFV";
const request = {
// TODO: This fails when address is X-address
txJSON: `{"Flags":2147483648,"TransactionType":"AccountSet","Account":"r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59","Domain":"6578616D706C652E636F6D","LastLedgerSequence":8820051,"Fee":"1.2","Sequence":23,"SigningPubKey":"02F89EAEC7667B30F33D0687BBA86C3FE2A08CCA40A9186C5BDE2DAA6FA97A37D8"}`,
instructions: {
fee: "0.0000012",
sequence: 23,
maxLedgerVersion: 8820051,
},
};
assert.throws(() => {
this.client.sign(request.txJSON, secret);
}, /1\.2 is an illegal amount/);
});
it("throws when encoded tx does not match decoded tx - higher fee", async function () {
const secret = "shsWGZcmZz6YsWWmcnpfr6fLTdtFV";
const request = {
// TODO: This fails when address is X-address
txJSON: `{"Flags":2147483648,"TransactionType":"AccountSet","Account":"r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59","Domain":"6578616D706C652E636F6D","LastLedgerSequence":8820051,"Fee":"1123456.7","Sequence":23,"SigningPubKey":"02F89EAEC7667B30F33D0687BBA86C3FE2A08CCA40A9186C5BDE2DAA6FA97A37D8"}`,
instructions: {
fee: "1.1234567",
sequence: 23,
maxLedgerVersion: 8820051,
},
};
assert.throws(() => {
this.client.sign(request.txJSON, secret);
}, /1123456\.7 is an illegal amount/);
});
it("permits fee exceeding 2000000 drops when maxFeeXRP is higher than 2 XRP", async function () {
this.client._maxFeeXRP = "2.1";
const secret = "shsWGZcmZz6YsWWmcnpfr6fLTdtFV";
const request = {
// TODO: This fails when address is X-address
txJSON: `{"Flags":2147483648,"TransactionType":"AccountSet","Account":"r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59","LastLedgerSequence":8820051,"Fee":"2010000","Sequence":23,"SigningPubKey":"02F89EAEC7667B30F33D0687BBA86C3FE2A08CCA40A9186C5BDE2DAA6FA97A37D8"}`,
instructions: {
fee: "2.01",
sequence: 23,
maxLedgerVersion: 8820051,
},
};
const result = this.client.sign(request.txJSON, secret);
const expectedResponse = {
signedTransaction:
"12000322800000002400000017201B008695536840000000001EAB90732102F89EAEC7667B30F33D0687BBA86C3FE2A08CCA40A9186C5BDE2DAA6FA97A37D87446304402200203F219F5371D2C6506888B1B02B27E74998F7A42D412C32FE319AC1A5B8DEF02205959A1B02253ACCCE542759E9886466C56D16B04676FA492AD34AA0E877E91F381145E7B112523F68D2F5E879DB4EAC51C6698A69304",
id: "061D5593E0A117F389826419CAC049A73C7CFCA65A20B788781D41240143D864",
};
assert.deepEqual(result, expectedResponse);
schemaValidator.schemaValidate("sign", result);
});
it("sign with ticket", async function () {
const secret = "sn7n5R1cR5Y3fRFkuWXA94Ts1frVJ";
const result = this.client.sign(REQUEST_FIXTURES.ticket.txJSON, secret);
assert.deepEqual(result, RESPONSE_FIXTURES.ticket);
schemaValidator.schemaValidate("sign", result);
});
addressTests.forEach(function (test) {
describe(test.type, function () {
it("throws when Fee exceeds maxFeeXRP (in drops)", async function () {
const secret = "shsWGZcmZz6YsWWmcnpfr6fLTdtFV";
const request = {
txJSON: `{"Flags":2147483648,"TransactionType":"AccountSet","Account":"${test.address}","Domain":"6578616D706C652E636F6D","LastLedgerSequence":8820051,"Fee":"2010000","Sequence":23,"SigningPubKey":"02F89EAEC7667B30F33D0687BBA86C3FE2A08CCA40A9186C5BDE2DAA6FA97A37D8"}`,
instructions: {
fee: "2.01",
sequence: 23,
maxLedgerVersion: 8820051,
},
};
assert.throws(() => {
this.client.sign(request.txJSON, secret);
}, /Fee" should not exceed "2000000"\. To use a higher fee, set `maxFeeXRP` in the Client constructor\./);
});
it("throws when Fee exceeds maxFeeXRP (in drops) - custom maxFeeXRP", async function () {
this.client._maxFeeXRP = "1.9";
const secret = "shsWGZcmZz6YsWWmcnpfr6fLTdtFV";
const request = {
txJSON: `{"Flags":2147483648,"TransactionType":"AccountSet","Account":"${test.address}","Domain":"6578616D706C652E636F6D","LastLedgerSequence":8820051,"Fee":"2010000","Sequence":23,"SigningPubKey":"02F89EAEC7667B30F33D0687BBA86C3FE2A08CCA40A9186C5BDE2DAA6FA97A37D8"}`,
instructions: {
fee: "2.01",
sequence: 23,
maxLedgerVersion: 8820051,
},
};
assert.throws(() => {
this.client.sign(request.txJSON, secret);
}, /Fee" should not exceed "1900000"\. To use a higher fee, set `maxFeeXRP` in the Client constructor\./);
});
it("sign with paths", async function () {
this.mockRippled.addResponse("server_info", rippled.server_info.normal);
this.mockRippled.addResponse("fee", rippled.fee);
this.mockRippled.addResponse("ledger_current", rippled.ledger_current);
this.mockRippled.addResponse(
"account_info",
rippled.account_info.normal
);
const secret = "shsWGZcmZz6YsWWmcnpfr6fLTdtFV"; const secret = "shsWGZcmZz6YsWWmcnpfr6fLTdtFV";
const payment = { const payment = {
source: { source: {
address, address: test.address,
amount: { amount: {
currency: "drops", currency: "drops",
value: "100", value: "100",
@@ -84,104 +302,30 @@ export default <TestSuite>{
paths: paths:
'[[{"currency":"USD","issuer":"rVnYNK9yuxBz4uP8zC8LEFokM2nqH3poc"}]]', '[[{"currency":"USD","issuer":"rVnYNK9yuxBz4uP8zC8LEFokM2nqH3poc"}]]',
}; };
const ret = await client.preparePayment(address, payment, { const ret = await this.client.preparePayment(test.address, payment, {
sequence: 1, sequence: 1,
maxLedgerVersion: 15696358, maxLedgerVersion: 15696358,
}); });
const result = client.sign(ret.txJSON, secret); const result = this.client.sign(ret.txJSON, secret);
assert.deepEqual(result, { assert.deepEqual(result, {
signedTransaction: signedTransaction:
"12000022800200002400000001201B00EF81E661EC6386F26FC0FFFF0000000000000000000000005553440000000000054F6F784A58F9EFB0A9EB90B83464F9D166461968400000000000000C6940000000000000646AD3504529A0465E2E0000000000000000000000005553440000000000054F6F784A58F9EFB0A9EB90B83464F9D1664619732102F89EAEC7667B30F33D0687BBA86C3FE2A08CCA40A9186C5BDE2DAA6FA97A37D87446304402200A693FB5CA6B21250EBDFD8CFF526EE0DF7C9E4E31EB0660692E75E6A93BF5F802203CC39463DDA21386898CA31E18AD1A6828647D65741DD637BAD71BC83E29DB9481145E7B112523F68D2F5E879DB4EAC51C6698A693048314CA6EDC7A28252DAEA6F2045B24F4D7C333E146170112300000000000000000000000005553440000000000054F6F784A58F9EFB0A9EB90B83464F9D166461900", "12000022800200002400000001201B00EF81E661EC6386F26FC0FFFF0000000000000000000000005553440000000000054F6F784A58F9EFB0A9EB90B83464F9D166461968400000000000000C6940000000000000646AD3504529A0465E2E0000000000000000000000005553440000000000054F6F784A58F9EFB0A9EB90B83464F9D1664619732102F89EAEC7667B30F33D0687BBA86C3FE2A08CCA40A9186C5BDE2DAA6FA97A37D87446304402200A693FB5CA6B21250EBDFD8CFF526EE0DF7C9E4E31EB0660692E75E6A93BF5F802203CC39463DDA21386898CA31E18AD1A6828647D65741DD637BAD71BC83E29DB9481145E7B112523F68D2F5E879DB4EAC51C6698A693048314CA6EDC7A28252DAEA6F2045B24F4D7C333E146170112300000000000000000000000005553440000000000054F6F784A58F9EFB0A9EB90B83464F9D166461900",
id: "78874FE5F5299FEE3EA85D3CF6C1FB1F1D46BB08F716662A3E3D1F0ADE4EF796", id: "78874FE5F5299FEE3EA85D3CF6C1FB1F1D46BB08F716662A3E3D1F0ADE4EF796",
}); });
schemaValidator.schemaValidate("sign", result); schemaValidator.schemaValidate("sign", result);
},
"already signed": async (client, address) => {
const secret = "shsWGZcmZz6YsWWmcnpfr6fLTdtFV";
const result = client.sign(REQUEST_FIXTURES.normal.txJSON, secret);
assert.throws(() => {
const tx = JSON.stringify(binary.decode(result.signedTransaction));
client.sign(tx, secret);
}, /txJSON must not contain "TxnSignature" or "Signers" properties/);
},
async EscrowExecution(client, address) {
const secret = "snoPBrXtMeMyMHUVTgbuqAfg1SUTb";
const result = client.sign(REQUEST_FIXTURES.escrow.txJSON, secret);
assert.deepEqual(result, RESPONSE_FIXTURES.escrow);
schemaValidator.schemaValidate("sign", result);
},
async signAs(client, address) {
const txJSON = REQUEST_FIXTURES.signAs;
const secret = "snoPBrXtMeMyMHUVTgbuqAfg1SUTb";
const signature = client.sign(JSON.stringify(txJSON), secret, {
signAs: "rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh",
}); });
assert.deepEqual(signature, RESPONSE_FIXTURES.signAs);
},
async withKeypair(client, address) { it("succeeds - prepared payment", async function () {
const keypair = { this.mockRippled.addResponse("server_info", rippled.server_info.normal);
privateKey: this.mockRippled.addResponse("fee", rippled.fee);
"00ACCD3309DB14D1A4FC9B1DAE608031F4408C85C73EE05E035B7DC8B25840107A", this.mockRippled.addResponse("ledger_current", rippled.ledger_current);
publicKey: this.mockRippled.addResponse(
"02F89EAEC7667B30F33D0687BBA86C3FE2A08CCA40A9186C5BDE2DAA6FA97A37D8", "account_info",
}; rippled.account_info.normal
const result = client.sign(REQUEST_FIXTURES.normal.txJSON, keypair); );
assert.deepEqual(result, RESPONSE_FIXTURES.normal); const payment = await this.client.preparePayment(test.address, {
schemaValidator.schemaValidate("sign", result);
},
"withKeypair already signed": async (client, address) => {
const keypair = {
privateKey:
"00ACCD3309DB14D1A4FC9B1DAE608031F4408C85C73EE05E035B7DC8B25840107A",
publicKey:
"02F89EAEC7667B30F33D0687BBA86C3FE2A08CCA40A9186C5BDE2DAA6FA97A37D8",
};
const result = client.sign(REQUEST_FIXTURES.normal.txJSON, keypair);
assert.throws(() => {
const tx = JSON.stringify(binary.decode(result.signedTransaction));
client.sign(tx, keypair);
}, /txJSON must not contain "TxnSignature" or "Signers" properties/);
},
"withKeypair EscrowExecution": async (client, address) => {
const keypair = {
privateKey:
"001ACAAEDECE405B2A958212629E16F2EB46B153EEE94CDD350FDEFF52795525B7",
publicKey:
"0330E7FC9D56BB25D6893BA3F317AE5BCF33B3291BD63DB32654A313222F7FD020",
};
const result = client.sign(REQUEST_FIXTURES.escrow.txJSON, keypair);
assert.deepEqual(result, RESPONSE_FIXTURES.escrow);
schemaValidator.schemaValidate("sign", result);
},
"withKeypair signAs": async (client, address) => {
const txJSON = REQUEST_FIXTURES.signAs;
const keypair = {
privateKey:
"001ACAAEDECE405B2A958212629E16F2EB46B153EEE94CDD350FDEFF52795525B7",
publicKey:
"0330E7FC9D56BB25D6893BA3F317AE5BCF33B3291BD63DB32654A313222F7FD020",
};
const signature = client.sign(JSON.stringify(txJSON), keypair, {
signAs: "rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh",
});
assert.deepEqual(signature, RESPONSE_FIXTURES.signAs);
},
"succeeds - prepared payment": async (client, address, mockRippled) => {
mockRippled.addResponse("server_info", rippled.server_info.normal);
mockRippled.addResponse("fee", rippled.fee);
mockRippled.addResponse("ledger_current", rippled.ledger_current);
mockRippled.addResponse("account_info", rippled.account_info.normal);
const payment = await client.preparePayment(address, {
source: { source: {
address, address: test.address,
maxAmount: { maxAmount: {
value: "1", value: "1",
currency: "drops", currency: "drops",
@@ -196,7 +340,7 @@ export default <TestSuite>{
}, },
}); });
const secret = "shsWGZcmZz6YsWWmcnpfr6fLTdtFV"; const secret = "shsWGZcmZz6YsWWmcnpfr6fLTdtFV";
const result = client.sign(payment.txJSON, secret); const result = this.client.sign(payment.txJSON, secret);
const expectedResult = { const expectedResult = {
signedTransaction: signedTransaction:
"12000022800000002400000017201B008694F261400000000000000168400000000000000C732102F89EAEC7667B30F33D0687BBA86C3FE2A08CCA40A9186C5BDE2DAA6FA97A37D874473045022100A9C91D4CFAE45686146EE0B56D4C53A2E7C2D672FB834D43E0BE2D2E9106519A022075DDA2F92DE552B0C45D83D4E6D35889B3FBF51BFBBD9B25EBF70DE3C96D0D6681145E7B112523F68D2F5E879DB4EAC51C6698A693048314FDB08D07AAA0EB711793A3027304D688E10C3648", "12000022800000002400000017201B008694F261400000000000000168400000000000000C732102F89EAEC7667B30F33D0687BBA86C3FE2A08CCA40A9186C5BDE2DAA6FA97A37D874473045022100A9C91D4CFAE45686146EE0B56D4C53A2E7C2D672FB834D43E0BE2D2E9106519A022075DDA2F92DE552B0C45D83D4E6D35889B3FBF51BFBBD9B25EBF70DE3C96D0D6681145E7B112523F68D2F5E879DB4EAC51C6698A693048314FDB08D07AAA0EB711793A3027304D688E10C3648",
@@ -204,63 +348,19 @@ export default <TestSuite>{
}; };
assert.deepEqual(result, expectedResult); assert.deepEqual(result, expectedResult);
schemaValidator.schemaValidate("sign", result); schemaValidator.schemaValidate("sign", result);
}, });
"succeeds - no flags": async (client, address) => { it("throws when encoded tx does not match decoded tx - prepared payment", async function () {
const txJSON = this.mockRippled.addResponse("server_info", rippled.server_info.normal);
'{"TransactionType":"Payment","Account":"r45Rev1EXGxy2hAUmJPCne97KUE7qyrD3j","Destination":"rQ3PTWGLCbPz8ZCicV5tCX3xuymojTng5r","Amount":"20000000","Sequence":1,"Fee":"12"}'; this.mockRippled.addResponse("fee", rippled.fee);
const secret = "shotKgaEotpcYsshSE39vmSnBDRim"; this.mockRippled.addResponse("ledger_current", rippled.ledger_current);
const result = client.sign(txJSON, secret); this.mockRippled.addResponse(
const expectedResult = { "account_info",
signedTransaction: rippled.account_info.normal
"1200002400000001614000000001312D0068400000000000000C7321022B05847086686F9D0499B13136B94AD4323EE1B67D4C429ECC987AB35ACFA34574473045022100C104B7B97C31FACA4597E7D6FCF13BD85BD11375963A62A0AC45B0061236E39802207784F157F6A98DFC85B051CDDF61CC3084C4F5750B82674801C8E9950280D1998114EE3046A5DDF8422C40DDB93F1D522BB4FE6419158314FDB08D07AAA0EB711793A3027304D688E10C3648",
id: "0596925967F541BF332FF6756645B2576A9858414B5B363DC3D34915BE8A70D6",
};
const decoded = binary.decode(result.signedTransaction);
assert(
decoded.Flags == null,
`Flags = ${decoded.Flags}, should be undefined`
); );
assert.deepEqual(result, expectedResult); const payment = await this.client.preparePayment(test.address, {
schemaValidator.schemaValidate("sign", result);
},
"sign succeeds with source.amount/destination.minAmount": async (
client,
address
) => {
// See also: 'preparePayment with source.amount/destination.minAmount'
const txJSON =
'{"TransactionType":"Payment","Account":"r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59","Destination":"rEX4LtGJubaUcMWCJULcy4NVxGT9ZEMVRq","Amount":{"currency":"USD","issuer":"rMaa8VLBTjwTJWA2kSme4Sqgphhr6Lr6FH","value":"999999999999999900000000000000000000000000000000000000000000000000000000000000000000000000000000"},"Flags":2147614720,"SendMax":{"currency":"GBP","issuer":"rpat5TmYjDsnFSStmgTumFgXCM9eqsWPro","value":"0.1"},"DeliverMin":{"currency":"USD","issuer":"rMaa8VLBTjwTJWA2kSme4Sqgphhr6Lr6FH","value":"0.1248548562296331"},"Sequence":23,"LastLedgerSequence":8820051,"Fee":"12"}';
const secret = "shotKgaEotpcYsshSE39vmSnBDRim";
const result = client.sign(txJSON, secret);
const expectedResult = {
signedTransaction:
"12000022800200002400000017201B0086955361EC6386F26FC0FFFF0000000000000000000000005553440000000000DC596C88BCDE4E818D416FCDEEBF2C8656BADC9A68400000000000000C69D4438D7EA4C6800000000000000000000000000047425000000000000C155FFE99C8C91F67083CEFFDB69EBFE76348CA6AD4446F8C5D8A5E0B0000000000000000000000005553440000000000DC596C88BCDE4E818D416FCDEEBF2C8656BADC9A7321022B05847086686F9D0499B13136B94AD4323EE1B67D4C429ECC987AB35ACFA34574473045022100D9634523D8E232D4A7807A71856023D82AC928FA29848571B820867898413B5F022041AC00EC1F81A26A6504EBF844A38CC3204694EF2CC1A97A87632721631F93DA81145E7B112523F68D2F5E879DB4EAC51C6698A6930483149F500E50C2F016CA01945E5A1E5846B61EF2D376",
id: "1C558AA9B926C24FB6BBD6950B2DB1350A83F9F12E4385208867907019761A2D",
};
const decoded = binary.decode(result.signedTransaction);
assert(
decoded.Flags === 2147614720,
`Flags = ${decoded.Flags}, should be 2147614720`
);
assert.deepEqual(result, expectedResult);
schemaValidator.schemaValidate("sign", result);
},
"throws when encoded tx does not match decoded tx - prepared payment": async (
client,
address,
mockRippled
) => {
mockRippled.addResponse("server_info", rippled.server_info.normal);
mockRippled.addResponse("fee", rippled.fee);
mockRippled.addResponse("ledger_current", rippled.ledger_current);
mockRippled.addResponse("account_info", rippled.account_info.normal);
const payment = await client.preparePayment(address, {
source: { source: {
address, address: test.address,
maxAmount: { maxAmount: {
value: "1.1234567", value: "1.1234567",
currency: "drops", currency: "drops",
@@ -276,19 +376,18 @@ export default <TestSuite>{
}); });
const secret = "shsWGZcmZz6YsWWmcnpfr6fLTdtFV"; const secret = "shsWGZcmZz6YsWWmcnpfr6fLTdtFV";
assert.throws(() => { assert.throws(() => {
client.sign(payment.txJSON, secret); this.client.sign(payment.txJSON, secret);
}, /^1.1234567 is an illegal amount/); }, /^1.1234567 is an illegal amount/);
}, });
"throws when encoded tx does not match decoded tx - prepared order": async ( it("throws when encoded tx does not match decoded tx - prepared order", async function () {
client, this.mockRippled.addResponse("server_info", rippled.server_info.normal);
address, this.mockRippled.addResponse("fee", rippled.fee);
mockRippled this.mockRippled.addResponse("ledger_current", rippled.ledger_current);
) => { this.mockRippled.addResponse(
mockRippled.addResponse("server_info", rippled.server_info.normal); "account_info",
mockRippled.addResponse("fee", rippled.fee); rippled.account_info.normal
mockRippled.addResponse("ledger_current", rippled.ledger_current); );
mockRippled.addResponse("account_info", rippled.account_info.normal);
const order = { const order = {
direction: "sell", direction: "sell",
quantity: { quantity: {
@@ -301,13 +400,15 @@ export default <TestSuite>{
value: "31415", value: "31415",
}, },
}; };
const prepared = await client.prepareOrder(address, order, { const prepared = await this.client.prepareOrder(test.address, order, {
sequence: 123, sequence: 123,
}); });
const secret = "shsWGZcmZz6YsWWmcnpfr6fLTdtFV"; const secret = "shsWGZcmZz6YsWWmcnpfr6fLTdtFV";
try { try {
client.sign(prepared.txJSON, secret); this.client.sign(prepared.txJSON, secret);
return await Promise.reject(new Error("client.sign should have thrown")); return await Promise.reject(
new Error("this.client.sign should have thrown")
);
} catch (error) { } catch (error) {
assert.equal(error.name, "ValidationError"); assert.equal(error.name, "ValidationError");
assert.equal( assert.equal(
@@ -320,114 +421,7 @@ export default <TestSuite>{
}, },
}); });
} }
}, });
});
"throws when encoded tx does not match decoded tx - AccountSet": async ( });
client, });
address
) => {
const secret = "shsWGZcmZz6YsWWmcnpfr6fLTdtFV";
const request = {
// TODO: This fails when address is X-address
txJSON: `{"Flags":2147483648,"TransactionType":"AccountSet","Account":"r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59","Domain":"6578616D706C652E636F6D","LastLedgerSequence":8820051,"Fee":"1.2","Sequence":23,"SigningPubKey":"02F89EAEC7667B30F33D0687BBA86C3FE2A08CCA40A9186C5BDE2DAA6FA97A37D8"}`,
instructions: {
fee: "0.0000012",
sequence: 23,
maxLedgerVersion: 8820051,
},
};
assert.throws(() => {
client.sign(request.txJSON, secret);
}, /1\.2 is an illegal amount/);
},
"throws when encoded tx does not match decoded tx - higher fee": async (
client,
address
) => {
const secret = "shsWGZcmZz6YsWWmcnpfr6fLTdtFV";
const request = {
// TODO: This fails when address is X-address
txJSON: `{"Flags":2147483648,"TransactionType":"AccountSet","Account":"r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59","Domain":"6578616D706C652E636F6D","LastLedgerSequence":8820051,"Fee":"1123456.7","Sequence":23,"SigningPubKey":"02F89EAEC7667B30F33D0687BBA86C3FE2A08CCA40A9186C5BDE2DAA6FA97A37D8"}`,
instructions: {
fee: "1.1234567",
sequence: 23,
maxLedgerVersion: 8820051,
},
};
assert.throws(() => {
client.sign(request.txJSON, secret);
}, /1123456\.7 is an illegal amount/);
},
"throws when Fee exceeds maxFeeXRP (in drops)": async (client, address) => {
const secret = "shsWGZcmZz6YsWWmcnpfr6fLTdtFV";
const request = {
txJSON: `{"Flags":2147483648,"TransactionType":"AccountSet","Account":"${address}","Domain":"6578616D706C652E636F6D","LastLedgerSequence":8820051,"Fee":"2010000","Sequence":23,"SigningPubKey":"02F89EAEC7667B30F33D0687BBA86C3FE2A08CCA40A9186C5BDE2DAA6FA97A37D8"}`,
instructions: {
fee: "2.01",
sequence: 23,
maxLedgerVersion: 8820051,
},
};
assert.throws(() => {
client.sign(request.txJSON, secret);
}, /Fee" should not exceed "2000000"\. To use a higher fee, set `maxFeeXRP` in the Client constructor\./);
},
"throws when Fee exceeds maxFeeXRP (in drops) - custom maxFeeXRP": async (
client,
address
) => {
client._maxFeeXRP = "1.9";
const secret = "shsWGZcmZz6YsWWmcnpfr6fLTdtFV";
const request = {
txJSON: `{"Flags":2147483648,"TransactionType":"AccountSet","Account":"${address}","Domain":"6578616D706C652E636F6D","LastLedgerSequence":8820051,"Fee":"2010000","Sequence":23,"SigningPubKey":"02F89EAEC7667B30F33D0687BBA86C3FE2A08CCA40A9186C5BDE2DAA6FA97A37D8"}`,
instructions: {
fee: "2.01",
sequence: 23,
maxLedgerVersion: 8820051,
},
};
assert.throws(() => {
client.sign(request.txJSON, secret);
}, /Fee" should not exceed "1900000"\. To use a higher fee, set `maxFeeXRP` in the Client constructor\./);
},
"permits fee exceeding 2000000 drops when maxFeeXRP is higher than 2 XRP":
async (client, address) => {
client._maxFeeXRP = "2.1";
const secret = "shsWGZcmZz6YsWWmcnpfr6fLTdtFV";
const request = {
// TODO: This fails when address is X-address
txJSON: `{"Flags":2147483648,"TransactionType":"AccountSet","Account":"r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59","LastLedgerSequence":8820051,"Fee":"2010000","Sequence":23,"SigningPubKey":"02F89EAEC7667B30F33D0687BBA86C3FE2A08CCA40A9186C5BDE2DAA6FA97A37D8"}`,
instructions: {
fee: "2.01",
sequence: 23,
maxLedgerVersion: 8820051,
},
};
const result = client.sign(request.txJSON, secret);
const expectedResponse = {
signedTransaction:
"12000322800000002400000017201B008695536840000000001EAB90732102F89EAEC7667B30F33D0687BBA86C3FE2A08CCA40A9186C5BDE2DAA6FA97A37D87446304402200203F219F5371D2C6506888B1B02B27E74998F7A42D412C32FE319AC1A5B8DEF02205959A1B02253ACCCE542759E9886466C56D16B04676FA492AD34AA0E877E91F381145E7B112523F68D2F5E879DB4EAC51C6698A69304",
id: "061D5593E0A117F389826419CAC049A73C7CFCA65A20B788781D41240143D864",
};
assert.deepEqual(result, expectedResponse);
schemaValidator.schemaValidate("sign", result);
},
"sign with ticket": async (client, address) => {
const secret = "sn7n5R1cR5Y3fRFkuWXA94Ts1frVJ";
const result = client.sign(REQUEST_FIXTURES.ticket.txJSON, secret);
assert.deepEqual(result, RESPONSE_FIXTURES.ticket);
schemaValidator.schemaValidate("sign", result);
},
};

View File

@@ -18,7 +18,7 @@
mocha.ui('bdd') mocha.ui('bdd')
</script> </script>
<script src="../testCompiledForWeb/rippleClient.js"></script> <script src="../testCompiledForWeb/runClientTests.js"></script>
<script src="../testCompiledForWeb/broadcastClient.js"></script> <script src="../testCompiledForWeb/broadcastClient.js"></script>

View File

@@ -18,7 +18,7 @@
mocha.ui('bdd') mocha.ui('bdd')
</script> </script>
<script src="../testCompiledForWeb/rippleClient.js"></script> <script src="../testCompiledForWeb/runClientTests.js"></script>
<script src="../testCompiledForWeb/broadcastClient.js"></script> <script src="../testCompiledForWeb/broadcastClient.js"></script>

View File

@@ -1,83 +0,0 @@
import { Client } from "xrpl-local";
import addresses from "./fixtures/addresses.json";
import setupClient from "./setupClient";
import { getAllPublicMethods, loadTestSuites } from "./testUtils";
/**
* Client Test Runner.
*
* Background: "test/api-test.ts" had hit 4000+ lines of test code and 300+
* individual tests. Additionally, a new address format was added which
* forced us to copy-paste duplicate the test file to test both the old forms
* of address. This added a significant maintenance burden.
*
* This test runner allows us to split our tests by Client method, and
* automatically load, validate, and run them. Each tests accepts arguments to
* test with, which allows us to re-run tests across different data
* (ex: different address styles).
*
* Additional benefits:
* - Throw errors when we detect the absence of tests.
* - Type the Client object under test and catch typing issues (currently untyped).
* - Sets the stage for more cleanup, like moving test-specific fixtures closer to their tests.
*/
describe("Client [Test Runner]", function () {
beforeEach(setupClient.setup);
afterEach(setupClient.teardown);
// Collect all the tests:
const allPublicMethods = getAllPublicMethods(new Client("wss://"));
// doesn't need the client, just needs to instantiate to get public methods
const allTestSuites = loadTestSuites();
// Run all the tests:
for (const { name: methodName, tests, config } of allTestSuites) {
describe(`${methodName}`, function () {
// Run each test that does not use an address.
for (const [testName, fn] of tests) {
if (fn.length === 1) {
it(testName, function () {
return fn(this.client, addresses.ACCOUNT, this.mockRippled);
});
}
}
// Run each test with a classic address.
describe(`[Classic Address]`, function () {
for (const [testName, fn] of tests) {
if (fn.length >= 2) {
it(testName, function () {
return fn(this.client, addresses.ACCOUNT, this.mockRippled);
});
}
}
});
// Run each test with an X-address.
if (!config.skipXAddress) {
describe(`[X-address]`, function () {
for (const [testName, fn] of tests) {
if (fn.length >= 2) {
it(testName, function () {
return fn(this.client, addresses.ACCOUNT_X, this.mockRippled);
});
}
}
});
}
});
}
// Report any missing tests.
const allTestedMethods = new Set(allTestSuites.map((s) => s.name));
for (const methodName of allPublicMethods) {
if (!allTestedMethods.has(methodName)) {
// TODO: Once migration is complete, remove `.skip()` so that missing tests are reported as failures.
it.skip(`${methodName} - no test suite found`, function () {
throw new Error(
`Test file not found! Create file "test/client/${methodName}/index.ts".`
);
});
}
}
});

73
test/runClientTests.ts Normal file
View File

@@ -0,0 +1,73 @@
import fs from "fs";
import path from "path";
import { Client } from "xrpl-local";
/**
* Client Test Runner.
*
* Throws errors when we detect the absence of tests.
* Puts all the client methods under one "describe" umbrella.
*/
describe("Client [Test Runner]", function () {
// doesn't need a functional client, just needs to instantiate to get a list of public methods
// (to determine what methods are missing from )
const allPublicMethods = getAllPublicMethods(new Client("wss://"));
const allTestSuites = loadTestSuites();
// Report any missing tests.
const allTestedMethods = new Set(allTestSuites.map((s) => s.name));
for (const methodName of allPublicMethods) {
if (!allTestedMethods.has(methodName)) {
// TODO: Once migration is complete, remove `.skip()` so that missing tests are reported as failures.
it.skip(`${methodName} - no test suite found`, function () {
throw new Error(
`Test file not found! Create file "test/client/${methodName}.ts".`
);
});
}
}
});
function getAllPublicMethods(client: Client) {
return Array.from(
new Set([
...Object.getOwnPropertyNames(client),
...Object.getOwnPropertyNames(Client.prototype),
])
).filter((key) => !key.startsWith("_")); // removes private methods
}
/**
* When the test suite is loaded, we represent it with the following
* data structure containing tests and metadata about the suite.
* If no test suite exists, we return this object with `isMissing: true`
* so that we can report it.
*/
interface LoadedTestSuite {
name: string;
tests: Array<[string, () => void | PromiseLike<void>]>;
}
function loadTestSuites(): LoadedTestSuite[] {
const allTests: any[] = fs.readdirSync(path.join(__dirname, "client"), {
encoding: "utf8",
});
return allTests
.map((methodName) => {
if (methodName.startsWith(".DS_Store")) {
return null;
}
if (methodName.endsWith(".ts")) {
methodName = methodName.slice(0, -3);
}
const testSuite = require(`./client/${methodName}`);
return {
name: methodName,
config: testSuite.config || {},
tests: Object.entries(testSuite.default || {}),
} as LoadedTestSuite;
})
.filter(Boolean) as LoadedTestSuite[];
}

View File

@@ -1,44 +1,17 @@
import fs from "fs";
import net from "net"; import net from "net";
import path from "path";
import { assert } from "chai"; import { assert } from "chai";
import _ from "lodash"; import _ from "lodash";
import { Client } from "xrpl-local"; import addresses from "./fixtures/addresses.json";
/** /**
* The test function. It takes a Client object and then some other data to * Setup to run tests on both classic addresses and X-addresses.
* test (currently: an address). May be called multiple times with different
* arguments, to test different types of data.
*/ */
export type TestFn = ( export const addressTests = [
client: Client, { type: "Classic Address", address: addresses.ACCOUNT },
address: string, { type: "X-Address", address: addresses.ACCOUNT_X },
mockRippled?: any ];
) => void | PromiseLike<void>;
/**
* A suite of tests to run. Maps the test name to the test function.
*/
export interface TestSuite {
[testName: string]: TestFn;
}
/**
* When the test suite is loaded, we represent it with the following
* data structure containing tests and metadata about the suite.
* If no test suite exists, we return this object with `isMissing: true`
* so that we can report it.
*/
interface LoadedTestSuite {
name: string;
tests: Array<[string, TestFn]>;
config: {
/** Set to true to skip re-running tests with an X-address. */
skipXAddress?: boolean;
};
}
/** /**
* Check the response against the expected result. Optionally validate * Check the response against the expected result. Optionally validate
@@ -119,37 +92,6 @@ export function getFreePort() {
}); });
} }
export function getAllPublicMethods(client: Client) {
return Array.from(
new Set([
...Object.getOwnPropertyNames(client),
...Object.getOwnPropertyNames(Client.prototype),
])
).filter((key) => !key.startsWith("_"));
}
export function loadTestSuites(): LoadedTestSuite[] {
const allTests: any[] = fs.readdirSync(path.join(__dirname, "client"), {
encoding: "utf8",
});
return allTests
.map((methodName) => {
if (methodName.startsWith(".DS_Store")) {
return null;
}
if (methodName.endsWith(".ts")) {
methodName = methodName.slice(0, -3);
}
const testSuite = require(`./client/${methodName}`);
return {
name: methodName,
config: testSuite.config || {},
tests: Object.entries(testSuite.default || {}),
} as LoadedTestSuite;
})
.filter(Boolean) as LoadedTestSuite[];
}
/** /**
* Ignore WebSocket DisconnectErrors. Useful for making requests where we don't * Ignore WebSocket DisconnectErrors. Useful for making requests where we don't
* care about the response and plan to teardown the test before the response * care about the response and plan to teardown the test before the response

View File

@@ -1,183 +1,188 @@
import {assert} from 'chai' import { assert } from "chai";
import ECDSA from '../../src/common/ecdsa'
import Wallet from '../../src/Wallet' import ECDSA from "../../src/common/ecdsa";
import Wallet from "../../src/Wallet";
/** /**
* Wallet testing * Wallet testing.
* *
* Provides tests for Wallet class * Provides tests for Wallet class.
*/ */
describe('Wallet', () => { describe("Wallet", function () {
describe('fromSeed', () => { describe("fromSeed", function () {
const seed = 'ssL9dv2W5RK8L3tuzQxYY6EaZhSxW' const seed = "ssL9dv2W5RK8L3tuzQxYY6EaZhSxW";
const publicKey = const publicKey =
'030E58CDD076E798C84755590AAF6237CA8FAE821070A59F648B517A30DC6F589D' "030E58CDD076E798C84755590AAF6237CA8FAE821070A59F648B517A30DC6F589D";
const privateKey = const privateKey =
'00141BA006D3363D2FB2785E8DF4E44D3A49908780CB4FB51F6D217C08C021429F' "00141BA006D3363D2FB2785E8DF4E44D3A49908780CB4FB51F6D217C08C021429F";
it('derives a wallet using default algorithm', () => { it("derives a wallet using default algorithm", function () {
const wallet = Wallet.fromSeed(seed) const wallet = Wallet.fromSeed(seed);
assert.equal(wallet.publicKey, publicKey) assert.equal(wallet.publicKey, publicKey);
assert.equal(wallet.privateKey, privateKey) assert.equal(wallet.privateKey, privateKey);
}) });
it('derives a wallet using algorithm ecdsa-secp256k1', () => { it("derives a wallet using algorithm ecdsa-secp256k1", function () {
const algorithm = ECDSA.secp256k1 const algorithm = ECDSA.secp256k1;
const wallet = Wallet.fromSeed(seed, algorithm) const wallet = Wallet.fromSeed(seed, algorithm);
assert.equal(wallet.publicKey, publicKey) assert.equal(wallet.publicKey, publicKey);
assert.equal(wallet.privateKey, privateKey) assert.equal(wallet.privateKey, privateKey);
}) });
it('derives a wallet using algorithm ed25519', () => { it("derives a wallet using algorithm ed25519", function () {
const algorithm = ECDSA.ed25519 const algorithm = ECDSA.ed25519;
const wallet = Wallet.fromSeed(seed, algorithm) const wallet = Wallet.fromSeed(seed, algorithm);
assert.equal(wallet.publicKey, publicKey) assert.equal(wallet.publicKey, publicKey);
assert.equal(wallet.privateKey, privateKey) assert.equal(wallet.privateKey, privateKey);
}) });
}) });
describe('fromMnemonic', () => { describe("fromMnemonic", function () {
const mnemonic = const mnemonic =
'try milk link drift aware pass obtain again music stick pluck fold' "try milk link drift aware pass obtain again music stick pluck fold";
const publicKey = const publicKey =
'0257B550BA2FDCCF0ADDA3DEB2A5411700F3ADFDCC7C68E1DCD1E2B63E6B0C63E6' "0257B550BA2FDCCF0ADDA3DEB2A5411700F3ADFDCC7C68E1DCD1E2B63E6B0C63E6";
const privateKey = const privateKey =
'008F942B6E229C0E9CEE47E7A94253DABB6A9855F4BA2D8A741FA31851A1D423C3' "008F942B6E229C0E9CEE47E7A94253DABB6A9855F4BA2D8A741FA31851A1D423C3";
it('derives a wallet using default derivation path', () => { it("derives a wallet using default derivation path", function () {
const wallet = Wallet.fromMnemonic(mnemonic) const wallet = Wallet.fromMnemonic(mnemonic);
assert.equal(wallet.publicKey, publicKey) assert.equal(wallet.publicKey, publicKey);
assert.equal(wallet.privateKey, privateKey) assert.equal(wallet.privateKey, privateKey);
}) });
it('derives a wallet using an input derivation path', () => { it("derives a wallet using an input derivation path", function () {
const derivationPath = "m/44'/144'/0'/0/0" const derivationPath = "m/44'/144'/0'/0/0";
const wallet = Wallet.fromMnemonic(mnemonic, derivationPath) const wallet = Wallet.fromMnemonic(mnemonic, derivationPath);
assert.equal(wallet.publicKey, publicKey) assert.equal(wallet.publicKey, publicKey);
assert.equal(wallet.privateKey, privateKey) assert.equal(wallet.privateKey, privateKey);
}) });
}) });
describe('fromEntropy', () => { describe("fromEntropy", function () {
const entropy: number[] = new Array(16).fill(0) const entropy: number[] = new Array(16).fill(0);
const publicKey: string =
'0390A196799EE412284A5D80BF78C3E84CBB80E1437A0AECD9ADF94D7FEAAFA284'
const privateKey: string =
'002512BBDFDBB77510883B7DCCBEF270B86DEAC8B64AC762873D75A1BEE6298665'
const publicKeyED25519: string =
'ED1A7C082846CFF58FF9A892BA4BA2593151CCF1DBA59F37714CC9ED39824AF85F'
const privateKeyED25519: string =
'ED0B6CBAC838DFE7F47EA1BD0DF00EC282FDF45510C92161072CCFB84035390C4D'
it('derives a wallet using entropy', () => {
const wallet = Wallet.fromEntropy(entropy)
assert.equal(wallet.publicKey, publicKeyED25519)
assert.equal(wallet.privateKey, privateKeyED25519)
})
it('derives a wallet using algorithm ecdsa-secp256k1', () => {
const algorithm = ECDSA.secp256k1
const wallet = Wallet.fromEntropy(entropy, algorithm)
assert.equal(wallet.publicKey, publicKey)
assert.equal(wallet.privateKey, privateKey)
})
it('derives a wallet using algorithm ed25519', () => {
const algorithm = ECDSA.ed25519
const wallet = Wallet.fromEntropy(entropy, algorithm)
assert.equal(wallet.publicKey, publicKeyED25519)
assert.equal(wallet.privateKey, privateKeyED25519)
})
})
describe('signTransaction', () => {
const publicKey = const publicKey =
'030E58CDD076E798C84755590AAF6237CA8FAE821070A59F648B517A30DC6F589D' "0390A196799EE412284A5D80BF78C3E84CBB80E1437A0AECD9ADF94D7FEAAFA284";
const privateKey = const privateKey =
'00141BA006D3363D2FB2785E8DF4E44D3A49908780CB4FB51F6D217C08C021429F' "002512BBDFDBB77510883B7DCCBEF270B86DEAC8B64AC762873D75A1BEE6298665";
const address = 'rhvh5SrgBL5V8oeV9EpDuVszeJSSCEkbPc' const publicKeyED25519 =
"ED1A7C082846CFF58FF9A892BA4BA2593151CCF1DBA59F37714CC9ED39824AF85F";
const privateKeyED25519 =
"ED0B6CBAC838DFE7F47EA1BD0DF00EC282FDF45510C92161072CCFB84035390C4D";
it('signs a transaction offline', () => { it("derives a wallet using entropy", function () {
const wallet = Wallet.fromEntropy(entropy);
assert.equal(wallet.publicKey, publicKeyED25519);
assert.equal(wallet.privateKey, privateKeyED25519);
});
it("derives a wallet using algorithm ecdsa-secp256k1", function () {
const algorithm = ECDSA.secp256k1;
const wallet = Wallet.fromEntropy(entropy, algorithm);
assert.equal(wallet.publicKey, publicKey);
assert.equal(wallet.privateKey, privateKey);
});
it("derives a wallet using algorithm ed25519", function () {
const algorithm = ECDSA.ed25519;
const wallet = Wallet.fromEntropy(entropy, algorithm);
assert.equal(wallet.publicKey, publicKeyED25519);
assert.equal(wallet.privateKey, privateKeyED25519);
});
});
describe("signTransaction", function () {
const publicKey =
"030E58CDD076E798C84755590AAF6237CA8FAE821070A59F648B517A30DC6F589D";
const privateKey =
"00141BA006D3363D2FB2785E8DF4E44D3A49908780CB4FB51F6D217C08C021429F";
const address = "rhvh5SrgBL5V8oeV9EpDuVszeJSSCEkbPc";
it("signs a transaction offline", function () {
const txJSON = { const txJSON = {
TransactionType: 'Payment', TransactionType: "Payment",
Account: address, Account: address,
Destination: 'rQ3PTWGLCbPz8ZCicV5tCX3xuymojTng5r', Destination: "rQ3PTWGLCbPz8ZCicV5tCX3xuymojTng5r",
Amount: '20000000', Amount: "20000000",
Sequence: 1, Sequence: 1,
Fee: '12', Fee: "12",
SigningPubKey: publicKey SigningPubKey: publicKey,
} };
const wallet = new Wallet(publicKey, privateKey) const wallet = new Wallet(publicKey, privateKey);
const signedTx: { signedTransaction: string; id: string } = const signedTx: { signedTransaction: string; id: string } =
wallet.signTransaction(txJSON) wallet.signTransaction(txJSON);
assert.hasAllKeys(signedTx, ['id', 'signedTransaction']) assert.hasAllKeys(signedTx, ["id", "signedTransaction"]);
assert.isString(signedTx.id) assert.isString(signedTx.id);
assert.isString(signedTx.signedTransaction) assert.isString(signedTx.signedTransaction);
}) });
}) });
describe('verifyTransaction', () => { describe("verifyTransaction", function () {
const publicKey = const publicKey =
'030E58CDD076E798C84755590AAF6237CA8FAE821070A59F648B517A30DC6F589D' "030E58CDD076E798C84755590AAF6237CA8FAE821070A59F648B517A30DC6F589D";
const privateKey = const privateKey =
'00141BA006D3363D2FB2785E8DF4E44D3A49908780CB4FB51F6D217C08C021429F' "00141BA006D3363D2FB2785E8DF4E44D3A49908780CB4FB51F6D217C08C021429F";
const prepared = { const prepared = {
signedTransaction: signedTransaction:
'1200002400000001614000000001312D0068400000000000000C7321030E58CDD076E798C84755590AAF6237CA8FAE821070A59F648B517A30DC6F589D74473045022100CAF99A63B241F5F62B456C68A593D2835397101533BB5D0C4DC17362AC22046F022016A2CA2CF56E777B10E43B56541A4C2FB553E7E298CDD39F7A8A844DA491E51D81142AF1861DEC1316AEEC995C94FF9E2165B1B784608314FDB08D07AAA0EB711793A3027304D688E10C3648', "1200002400000001614000000001312D0068400000000000000C7321030E58CDD076E798C84755590AAF6237CA8FAE821070A59F648B517A30DC6F589D74473045022100CAF99A63B241F5F62B456C68A593D2835397101533BB5D0C4DC17362AC22046F022016A2CA2CF56E777B10E43B56541A4C2FB553E7E298CDD39F7A8A844DA491E51D81142AF1861DEC1316AEEC995C94FF9E2165B1B784608314FDB08D07AAA0EB711793A3027304D688E10C3648",
id: '30D9ECA2A7FB568C5A8607E5850D9567572A9E7C6094C26BEFD4DC4C2CF2657A' id: "30D9ECA2A7FB568C5A8607E5850D9567572A9E7C6094C26BEFD4DC4C2CF2657A",
} };
it('returns true when verifying a transaction signed by the same wallet', () => { it("returns true when verifying a transaction signed by the same wallet", function () {
const wallet = new Wallet(publicKey, privateKey) const wallet = new Wallet(publicKey, privateKey);
const isVerified: boolean = wallet.verifyTransaction(prepared.signedTransaction) const isVerified: boolean = wallet.verifyTransaction(
prepared.signedTransaction
);
assert.equal(isVerified, true) assert.equal(isVerified, true);
}) });
it('returns false when verifying a transaction signed by a different wallet', () => { it("returns false when verifying a transaction signed by a different wallet", function () {
const diffPublicKey = const diffPublicKey =
'02F89EAEC7667B30F33D0687BBA86C3FE2A08CCA40A9186C5BDE2DAA6FA97A37D8' "02F89EAEC7667B30F33D0687BBA86C3FE2A08CCA40A9186C5BDE2DAA6FA97A37D8";
const diffPrivateKey = const diffPrivateKey =
'00ACCD3309DB14D1A4FC9B1DAE608031F4408C85C73EE05E035B7DC8B25840107A' "00ACCD3309DB14D1A4FC9B1DAE608031F4408C85C73EE05E035B7DC8B25840107A";
const wallet = new Wallet(diffPublicKey, diffPrivateKey) const wallet = new Wallet(diffPublicKey, diffPrivateKey);
const isVerified: boolean = wallet.verifyTransaction(prepared.signedTransaction) const isVerified: boolean = wallet.verifyTransaction(
prepared.signedTransaction
);
assert.equal(isVerified, false) assert.equal(isVerified, false);
}) });
}) });
describe('getXAddress', () => { describe("getXAddress", function () {
const publicKey = const publicKey =
'030E58CDD076E798C84755590AAF6237CA8FAE821070A59F648B517A30DC6F589D' "030E58CDD076E798C84755590AAF6237CA8FAE821070A59F648B517A30DC6F589D";
const privateKey = const privateKey =
'00141BA006D3363D2FB2785E8DF4E44D3A49908780CB4FB51F6D217C08C021429F' "00141BA006D3363D2FB2785E8DF4E44D3A49908780CB4FB51F6D217C08C021429F";
const wallet = new Wallet(publicKey, privateKey) const wallet = new Wallet(publicKey, privateKey);
const tag = 1337 const tag = 1337;
const mainnetXAddress = 'X7gJ5YK8abHf2eTPWPFHAAot8Knck11QGqmQ7a6a3Z8PJvk' const mainnetXAddress = "X7gJ5YK8abHf2eTPWPFHAAot8Knck11QGqmQ7a6a3Z8PJvk";
const testnetXAddress = 'T7bq3e7kxYq9pwDz8UZhqAZoEkcRGTXSNr5immvcj3DYRaV' const testnetXAddress = "T7bq3e7kxYq9pwDz8UZhqAZoEkcRGTXSNr5immvcj3DYRaV";
it('returns a Testnet X-address when test is true', () => { it("returns a Testnet X-address when test is true", function () {
const result = wallet.getXAddress(tag, true) const result = wallet.getXAddress(tag, true);
assert.equal(result, testnetXAddress) assert.equal(result, testnetXAddress);
}) });
it('returns a Mainnet X-address when test is false', () => { it("returns a Mainnet X-address when test is false", function () {
const result = wallet.getXAddress(tag, false) const result = wallet.getXAddress(tag, false);
assert.equal(result, mainnetXAddress) assert.equal(result, mainnetXAddress);
}) });
it("returns a Mainnet X-address when test isn't provided", () => { it("returns a Mainnet X-address when test isn't provided", function () {
const result = wallet.getXAddress(tag) const result = wallet.getXAddress(tag);
assert.equal(result, mainnetXAddress) assert.equal(result, mainnetXAddress);
}) });
}) });
}) });