refactor: improves mock rippled structure (#1569)

* better error handling + tests

* fix tests

* change addResponse to take a string instead of a Request

* remove unneeded change

* respond to comments

* fix tests, re-lint

* improve error message
This commit is contained in:
Mayukha Vadari
2021-08-27 10:17:39 -04:00
parent 759e075e54
commit b8be6c2f1b
30 changed files with 763 additions and 2110 deletions

View File

@@ -241,7 +241,7 @@ class RequestManager {
}
if (data.status !== "success") {
const error = new ResponseFormatError(
`unrecognized status: ${data.status}`,
`unrecognized response.status: ${data.status}`,
data
);
this.reject(data.id, error);

View File

@@ -24,7 +24,7 @@ describe("BroadcastClient", function () {
it("base", function () {
this.mocks.forEach((mock) => {
mock.addResponse({ command: "server_info" }, rippled.server_info.normal);
mock.addResponse("server_info", rippled.server_info.normal);
});
assert(this.client.isConnected());
return this.client.request({ command: "server_info" }).then((response) => {
@@ -35,7 +35,7 @@ describe("BroadcastClient", function () {
it("error propagation", function (done) {
const data = { error: "type", error_message: "info" };
this.mocks.forEach((mock) => {
mock.addResponse({ command: "echo" }, data);
mock.addResponse("echo", data);
});
this.client.once("error", (type, info) => {
assert.strictEqual(type, "type");

View File

@@ -10,30 +10,18 @@ import { assertResultMatch, TestSuite } from "../testUtils";
*/
export default <TestSuite>{
async getBalances(client, address, mockRippled) {
mockRippled.addResponse(
{ command: "account_info" },
rippled.account_info.normal
);
mockRippled.addResponse(
{ command: "account_lines" },
rippledAccountLines.normal
);
mockRippled.addResponse({ command: "ledger" }, rippled.ledger.normal);
mockRippled.addResponse("account_info", rippled.account_info.normal);
mockRippled.addResponse("account_lines", rippledAccountLines.normal);
mockRippled.addResponse("ledger", rippled.ledger.normal);
const result = await client.getBalances(address);
assertResultMatch(result, responses.getBalances, "getBalances");
},
"getBalances - limit": async (client, address, mockRippled) => {
const options = { limit: 3, ledgerVersion: 123456 };
mockRippled.addResponse(
{ command: "account_info" },
rippled.account_info.normal
);
mockRippled.addResponse(
{ command: "account_lines" },
rippledAccountLines.normal
);
mockRippled.addResponse({ command: "ledger" }, rippled.ledger.normal);
mockRippled.addResponse("account_info", rippled.account_info.normal);
mockRippled.addResponse("account_lines", rippledAccountLines.normal);
mockRippled.addResponse("ledger", rippled.ledger.normal);
const expectedResponse = responses.getBalances.slice(0, 3);
const result = await client.getBalances(address, options);
assertResultMatch(result, expectedResponse, "getBalances");
@@ -41,15 +29,9 @@ export default <TestSuite>{
"getBalances - limit & currency": async (client, address, mockRippled) => {
const options = { currency: "USD", limit: 3 };
mockRippled.addResponse(
{ command: "account_info" },
rippled.account_info.normal
);
mockRippled.addResponse(
{ command: "account_lines" },
rippledAccountLines.normal
);
mockRippled.addResponse({ command: "ledger" }, rippled.ledger.normal);
mockRippled.addResponse("account_info", rippled.account_info.normal);
mockRippled.addResponse("account_lines", rippledAccountLines.normal);
mockRippled.addResponse("ledger", rippled.ledger.normal);
const expectedResponse = responses.getBalances
.filter((item) => item.currency === "USD")
.slice(0, 3);
@@ -67,15 +49,9 @@ export default <TestSuite>{
counterparty: "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B",
limit: 3,
};
mockRippled.addResponse(
{ command: "account_info" },
rippled.account_info.normal
);
mockRippled.addResponse(
{ command: "account_lines" },
rippledAccountLines.normal
);
mockRippled.addResponse({ command: "ledger" }, rippled.ledger.normal);
mockRippled.addResponse("account_info", rippled.account_info.normal);
mockRippled.addResponse("account_lines", rippledAccountLines.normal);
mockRippled.addResponse("ledger", rippled.ledger.normal);
const expectedResponse = responses.getBalances
.filter(

View File

@@ -10,29 +10,20 @@ import { TestSuite } from "../testUtils";
*/
export default <TestSuite>{
async getFee(client, address, mockRippled) {
mockRippled.addResponse(
{ command: "server_info" },
rippled.server_info.normal
);
mockRippled.addResponse("server_info", rippled.server_info.normal);
const fee = await client.getFee();
assert.strictEqual(fee, "0.000012");
},
"getFee default": async (client, address, mockRippled) => {
mockRippled.addResponse(
{ command: "server_info" },
rippled.server_info.normal
);
mockRippled.addResponse("server_info", rippled.server_info.normal);
client._feeCushion = undefined as unknown as number;
const fee = await client.getFee();
assert.strictEqual(fee, "0.000012");
},
"getFee - high load_factor": async (client, address, mockRippled) => {
mockRippled.addResponse(
{ command: "server_info" },
rippled.server_info.highLoadFactor
);
mockRippled.addResponse("server_info", rippled.server_info.highLoadFactor);
const fee = await client.getFee();
assert.strictEqual(fee, "2");
},
@@ -42,10 +33,7 @@ export default <TestSuite>{
address,
mockRippled
) => {
mockRippled.addResponse(
{ command: "server_info" },
rippled.server_info.highLoadFactor
);
mockRippled.addResponse("server_info", rippled.server_info.highLoadFactor);
// Ensure that overriding with high maxFeeXRP of '51540' causes no errors.
// (fee will actually be 51539.607552)
client._maxFeeXRP = "51540";
@@ -54,10 +42,7 @@ export default <TestSuite>{
},
"getFee custom cushion": async (client, address, mockRippled) => {
mockRippled.addResponse(
{ command: "server_info" },
rippled.server_info.normal
);
mockRippled.addResponse("server_info", rippled.server_info.normal);
client._feeCushion = 1.4;
const fee = await client.getFee();
assert.strictEqual(fee, "0.000014");
@@ -66,20 +51,14 @@ export default <TestSuite>{
// This is not recommended since it may result in attempting to pay
// less than the base fee. However, this test verifies the existing behavior.
"getFee cushion less than 1.0": async (client, address, mockRippled) => {
mockRippled.addResponse(
{ command: "server_info" },
rippled.server_info.normal
);
mockRippled.addResponse("server_info", rippled.server_info.normal);
client._feeCushion = 0.9;
const fee = await client.getFee();
assert.strictEqual(fee, "0.000009");
},
"getFee reporting": async (client, address, mockRippled) => {
mockRippled.addResponse(
{ command: "server_info" },
rippled.server_info.normal
);
mockRippled.addResponse("server_info", rippled.server_info.normal);
const fee = await client.getFee();
assert.strictEqual(fee, "0.000012");
},

View File

@@ -88,7 +88,7 @@ function xrpRippledResponse(request: BookOffersRequest): object {
*/
export default <TestSuite>{
async normal(client, address, mockRippled) {
mockRippled.addResponse({ command: "book_offers" }, normalRippledResponse);
mockRippled.addResponse("book_offers", normalRippledResponse);
const response = await client.getOrderbook(
address,
requests.getOrderbook.normal,
@@ -98,7 +98,7 @@ export default <TestSuite>{
},
"invalid options": async (client, address, mockRippled) => {
mockRippled.addResponse({ command: "book_offers" }, normalRippledResponse);
mockRippled.addResponse("book_offers", normalRippledResponse);
assertRejects(
client.getOrderbook(address, requests.getOrderbook.normal, {
// @ts-expect-error
@@ -109,7 +109,7 @@ export default <TestSuite>{
},
"with XRP": async (client, address, mockRippled) => {
mockRippled.addResponse({ command: "book_offers" }, xrpRippledResponse);
mockRippled.addResponse("book_offers", xrpRippledResponse);
const response = await client.getOrderbook(
address,
requests.getOrderbook.withXRP
@@ -154,7 +154,7 @@ export default <TestSuite>{
address,
mockRippled
) => {
mockRippled.addResponse({ command: "book_offers" }, normalRippledResponse);
mockRippled.addResponse("book_offers", normalRippledResponse);
const response = await client.getOrderbook(
address,
requests.getOrderbook.normal
@@ -183,7 +183,7 @@ export default <TestSuite>{
address,
mockRippled
) => {
mockRippled.addResponse({ command: "book_offers" }, normalRippledResponse);
mockRippled.addResponse("book_offers", normalRippledResponse);
const response = await client.getOrderbook(
address,
requests.getOrderbook.normal
@@ -204,7 +204,7 @@ export default <TestSuite>{
address,
mockRippled
) => {
mockRippled.addResponse({ command: "book_offers" }, normalRippledResponse);
mockRippled.addResponse("book_offers", normalRippledResponse);
const response = await client.getOrderbook(
address,
requests.getOrderbook.normal

View File

@@ -48,7 +48,7 @@ export default <TestSuite>{
// assertResultMatch(response, RESPONSE_FIXTURES.XrpToXrp, 'getPaths')
// },
"source with issuer": async (client, _, mockRippled) => {
mockRippled.addResponse({ command: "ripple_path_find" }, rippledResponse);
mockRippled.addResponse("ripple_path_find", rippledResponse);
return assertRejects(
client.getPaths(REQUEST_FIXTURES.issuer),
client.errors.NotFoundError
@@ -61,41 +61,41 @@ export default <TestSuite>{
// )
// },
"invalid PathFind": async (client, _, mockRippled) => {
mockRippled.addResponse({ command: "ripple_path_find" }, rippledResponse);
mockRippled.addResponse("ripple_path_find", rippledResponse);
assert.throws(() => {
client.getPaths(REQUEST_FIXTURES.invalid);
}, /Cannot specify both source.amount/);
},
"does not accept currency": async (client, _, mockRippled) => {
mockRippled.addResponse({ command: "ripple_path_find" }, rippledResponse);
mockRippled.addResponse("ripple_path_find", rippledResponse);
return assertRejects(
client.getPaths(REQUEST_FIXTURES.NotAcceptCurrency),
client.errors.NotFoundError
);
},
"no paths": async (client, _, mockRippled) => {
mockRippled.addResponse({ command: "ripple_path_find" }, rippledResponse);
mockRippled.addResponse("ripple_path_find", rippledResponse);
return assertRejects(
client.getPaths(REQUEST_FIXTURES.NoPaths),
client.errors.NotFoundError
);
},
"no paths source amount": async (client, _, mockRippled) => {
mockRippled.addResponse({ command: "ripple_path_find" }, rippledResponse);
mockRippled.addResponse("ripple_path_find", rippledResponse);
return assertRejects(
client.getPaths(REQUEST_FIXTURES.NoPathsSource),
client.errors.NotFoundError
);
},
"no paths with source currencies": async (client, _, mockRippled) => {
mockRippled.addResponse({ command: "ripple_path_find" }, rippledResponse);
mockRippled.addResponse("ripple_path_find", rippledResponse);
return assertRejects(
client.getPaths(REQUEST_FIXTURES.NoPathsWithCurrencies),
client.errors.NotFoundError
);
},
"error: srcActNotFound": async (client, _, mockRippled) => {
mockRippled.addResponse({ command: "ripple_path_find" }, rippledResponse);
mockRippled.addResponse("ripple_path_find", rippledResponse);
return assertRejects(
client.getPaths({
...REQUEST_FIXTURES.normal,

View File

@@ -12,7 +12,7 @@ const { getTrustlines: RESPONSE_FIXTURES } = responses;
*/
export default <TestSuite>{
"getTrustlines - filtered": async (client, address, mockRippled) => {
mockRippled.addResponse({ command: "account_lines" }, rippled.normal);
mockRippled.addResponse("account_lines", rippled.normal);
const options = { currency: "USD" };
const result = await client.getTrustlines(address, options);
assertResultMatch(result, RESPONSE_FIXTURES.filtered, "getTrustlines");
@@ -23,7 +23,7 @@ export default <TestSuite>{
address,
mockRippled
) => {
mockRippled.addResponse({ command: "account_lines" }, rippled.manyItems);
mockRippled.addResponse("account_lines", rippled.manyItems);
const options = { limit: 401 };
const result = await client.getTrustlines(address, options);
assertResultMatch(
@@ -34,7 +34,7 @@ export default <TestSuite>{
},
"getTrustlines - no options": async (client, address, mockRippled) => {
mockRippled.addResponse({ command: "account_lines" }, rippled.normal);
mockRippled.addResponse("account_lines", rippled.normal);
await client.getTrustlines(address);
},
@@ -43,10 +43,7 @@ export default <TestSuite>{
address,
mockRippled
) => {
mockRippled.addResponse(
{ command: "account_lines" },
rippled.ripplingDisabled
);
mockRippled.addResponse("account_lines", rippled.ripplingDisabled);
const result = await client.getTrustlines(address);
assertResultMatch(
result,
@@ -60,7 +57,7 @@ export default <TestSuite>{
address,
mockRippled
) => {
mockRippled.addResponse({ command: "account_lines" }, rippled.manyItems);
mockRippled.addResponse("account_lines", rippled.manyItems);
const result = await client.getTrustlines(addresses.FOURTH_ACCOUNT, {
ledgerVersion: 5,
});

View File

@@ -14,10 +14,7 @@ export default <TestSuite>{
address,
mockRippled
) => {
mockRippled.addResponse(
{ command: "ledger_data" },
rippled.ledger_data.first_page
);
mockRippled.addResponse("ledger_data", rippled.ledger_data.first_page);
const response = await client.request({ command: "ledger_data" });
assert(client.hasNextPage(response));
},
@@ -33,7 +30,7 @@ export default <TestSuite>{
}
return rippled.ledger_data.first_page;
};
mockRippled.addResponse({ command: "ledger_data" }, rippledResponse);
mockRippled.addResponse("ledger_data", rippledResponse);
const response = await client.request({ command: "ledger_data" });
const responseNextPage = await client.requestNextPage(
{ command: "ledger_data" },

View File

@@ -12,19 +12,10 @@ const instructionsWithMaxLedgerVersionOffset = { maxLedgerVersionOffset: 100 };
*/
export default <TestSuite>{
async prepareCheckCancel(client, address, mockRippled) {
mockRippled.addResponse(
{ command: "server_info" },
rippled.server_info.normal
);
mockRippled.addResponse({ command: "fee" }, rippled.fee);
mockRippled.addResponse(
{ command: "ledger_current" },
rippled.ledger_current
);
mockRippled.addResponse(
{ command: "account_info" },
rippled.account_info.normal
);
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 result = await client.prepareCheckCancel(
address,
requests.prepareCheckCancel.normal
@@ -33,19 +24,10 @@ export default <TestSuite>{
},
"with ticket": async (client, address, mockRippled) => {
mockRippled.addResponse(
{ command: "server_info" },
rippled.server_info.normal
);
mockRippled.addResponse({ command: "fee" }, rippled.fee);
mockRippled.addResponse(
{ command: "ledger_current" },
rippled.ledger_current
);
mockRippled.addResponse(
{ command: "account_info" },
rippled.account_info.normal
);
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 = {
...instructionsWithMaxLedgerVersionOffset,
maxFee: "0.000012",

View File

@@ -12,19 +12,10 @@ const instructionsWithMaxLedgerVersionOffset = { maxLedgerVersionOffset: 100 };
*/
export default <TestSuite>{
"prepareCheckCash amount": async (client, address, mockRippled) => {
mockRippled.addResponse(
{ command: "server_info" },
rippled.server_info.normal
);
mockRippled.addResponse({ command: "fee" }, rippled.fee);
mockRippled.addResponse(
{ command: "ledger_current" },
rippled.ledger_current
);
mockRippled.addResponse(
{ command: "account_info" },
rippled.account_info.normal
);
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 result = await client.prepareCheckCash(
address,
requests.prepareCheckCash.amount
@@ -33,19 +24,10 @@ export default <TestSuite>{
},
"prepareCheckCash deliverMin": async (client, address, mockRippled) => {
mockRippled.addResponse(
{ command: "server_info" },
rippled.server_info.normal
);
mockRippled.addResponse({ command: "fee" }, rippled.fee);
mockRippled.addResponse(
{ command: "ledger_current" },
rippled.ledger_current
);
mockRippled.addResponse(
{ command: "account_info" },
rippled.account_info.normal
);
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 result = await client.prepareCheckCash(
address,
requests.prepareCheckCash.deliverMin
@@ -54,19 +36,10 @@ export default <TestSuite>{
},
"with ticket": async (client, address, mockRippled) => {
mockRippled.addResponse(
{ command: "server_info" },
rippled.server_info.normal
);
mockRippled.addResponse({ command: "fee" }, rippled.fee);
mockRippled.addResponse(
{ command: "ledger_current" },
rippled.ledger_current
);
mockRippled.addResponse(
{ command: "account_info" },
rippled.account_info.normal
);
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 = {
...instructionsWithMaxLedgerVersionOffset,
maxFee: "0.000012",

View File

@@ -12,19 +12,10 @@ const instructionsWithMaxLedgerVersionOffset = { maxLedgerVersionOffset: 100 };
*/
export default <TestSuite>{
async prepareCheckCreate(client, address, mockRippled) {
mockRippled.addResponse(
{ command: "server_info" },
rippled.server_info.normal
);
mockRippled.addResponse({ command: "fee" }, rippled.fee);
mockRippled.addResponse(
{ command: "ledger_current" },
rippled.ledger_current
);
mockRippled.addResponse(
{ command: "account_info" },
rippled.account_info.normal
);
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 = {
...instructionsWithMaxLedgerVersionOffset,
maxFee: "0.000012",
@@ -38,19 +29,10 @@ export default <TestSuite>{
},
"prepareCheckCreate full": async (client, address, mockRippled) => {
mockRippled.addResponse(
{ command: "server_info" },
rippled.server_info.normal
);
mockRippled.addResponse({ command: "fee" }, rippled.fee);
mockRippled.addResponse(
{ command: "ledger_current" },
rippled.ledger_current
);
mockRippled.addResponse(
{ command: "account_info" },
rippled.account_info.normal
);
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 result = await client.prepareCheckCreate(
address,
requests.prepareCheckCreate.full
@@ -59,19 +41,10 @@ export default <TestSuite>{
},
"prepareCheckCreate with ticket": async (client, address, mockRippled) => {
mockRippled.addResponse(
{ command: "server_info" },
rippled.server_info.normal
);
mockRippled.addResponse({ command: "fee" }, rippled.fee);
mockRippled.addResponse(
{ command: "ledger_current" },
rippled.ledger_current
);
mockRippled.addResponse(
{ command: "account_info" },
rippled.account_info.normal
);
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 = {
...instructionsWithMaxLedgerVersionOffset,
maxFee: "0.000012",

View File

@@ -12,19 +12,10 @@ const instructionsWithMaxLedgerVersionOffset = { maxLedgerVersionOffset: 100 };
*/
export default <TestSuite>{
async prepareEscrowCancellation(client, address, mockRippled) {
mockRippled.addResponse(
{ command: "server_info" },
rippled.server_info.normal
);
mockRippled.addResponse({ command: "fee" }, rippled.fee);
mockRippled.addResponse(
{ command: "ledger_current" },
rippled.ledger_current
);
mockRippled.addResponse(
{ command: "account_info" },
rippled.account_info.normal
);
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 result = await client.prepareEscrowCancellation(
address,
requests.prepareEscrowCancellation.normal,
@@ -42,19 +33,10 @@ export default <TestSuite>{
address,
mockRippled
) => {
mockRippled.addResponse(
{ command: "server_info" },
rippled.server_info.normal
);
mockRippled.addResponse({ command: "fee" }, rippled.fee);
mockRippled.addResponse(
{ command: "ledger_current" },
rippled.ledger_current
);
mockRippled.addResponse(
{ command: "account_info" },
rippled.account_info.normal
);
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 result = await client.prepareEscrowCancellation(
address,
requests.prepareEscrowCancellation.memos
@@ -67,19 +49,10 @@ export default <TestSuite>{
},
"with ticket": async (client, address, mockRippled) => {
mockRippled.addResponse(
{ command: "server_info" },
rippled.server_info.normal
);
mockRippled.addResponse({ command: "fee" }, rippled.fee);
mockRippled.addResponse(
{ command: "ledger_current" },
rippled.ledger_current
);
mockRippled.addResponse(
{ command: "account_info" },
rippled.account_info.normal
);
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 = {
...instructionsWithMaxLedgerVersionOffset,
maxFee: "0.000012",

View File

@@ -19,19 +19,10 @@ export const config = {
*/
export default <TestSuite>{
async prepareEscrowCreation(client, address, mockRippled) {
mockRippled.addResponse(
{ command: "server_info" },
rippled.server_info.normal
);
mockRippled.addResponse({ command: "fee" }, rippled.fee);
mockRippled.addResponse(
{ command: "ledger_current" },
rippled.ledger_current
);
mockRippled.addResponse(
{ command: "account_info" },
rippled.account_info.normal
);
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 = {
...instructionsWithMaxLedgerVersionOffset,
maxFee: "0.000012",
@@ -49,19 +40,10 @@ export default <TestSuite>{
},
"prepareEscrowCreation full": async (client, address, mockRippled) => {
mockRippled.addResponse(
{ command: "server_info" },
rippled.server_info.normal
);
mockRippled.addResponse({ command: "fee" }, rippled.fee);
mockRippled.addResponse(
{ command: "ledger_current" },
rippled.ledger_current
);
mockRippled.addResponse(
{ command: "account_info" },
rippled.account_info.normal
);
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 result = await client.prepareEscrowCreation(
address,
requests.prepareEscrowCreation.full
@@ -70,19 +52,10 @@ export default <TestSuite>{
},
"prepareEscrowCreation - invalid": async (client, address, mockRippled) => {
mockRippled.addResponse(
{ command: "server_info" },
rippled.server_info.normal
);
mockRippled.addResponse({ command: "fee" }, rippled.fee);
mockRippled.addResponse(
{ command: "ledger_current" },
rippled.ledger_current
);
mockRippled.addResponse(
{ command: "account_info" },
rippled.account_info.normal
);
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 escrow = { ...requests.prepareEscrowCreation.full };
delete escrow.amount; // Make invalid
await assertRejects(
@@ -93,19 +66,10 @@ export default <TestSuite>{
},
"with ticket": async (client, address, mockRippled) => {
mockRippled.addResponse(
{ command: "server_info" },
rippled.server_info.normal
);
mockRippled.addResponse({ command: "fee" }, rippled.fee);
mockRippled.addResponse(
{ command: "ledger_current" },
rippled.ledger_current
);
mockRippled.addResponse(
{ command: "account_info" },
rippled.account_info.normal
);
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 = {
...instructionsWithMaxLedgerVersionOffset,
maxFee: "0.000396",

View File

@@ -12,19 +12,10 @@ const instructionsWithMaxLedgerVersionOffset = { maxLedgerVersionOffset: 100 };
*/
export default <TestSuite>{
async prepareEscrowExecution(client, address, mockRippled) {
mockRippled.addResponse(
{ command: "server_info" },
rippled.server_info.normal
);
mockRippled.addResponse({ command: "fee" }, rippled.fee);
mockRippled.addResponse(
{ command: "ledger_current" },
rippled.ledger_current
);
mockRippled.addResponse(
{ command: "account_info" },
rippled.account_info.normal
);
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 result = await client.prepareEscrowExecution(
address,
requests.prepareEscrowExecution.normal,
@@ -38,19 +29,10 @@ export default <TestSuite>{
},
"prepareEscrowExecution - simple": async (client, address, mockRippled) => {
mockRippled.addResponse(
{ command: "server_info" },
rippled.server_info.normal
);
mockRippled.addResponse({ command: "fee" }, rippled.fee);
mockRippled.addResponse(
{ command: "ledger_current" },
rippled.ledger_current
);
mockRippled.addResponse(
{ command: "account_info" },
rippled.account_info.normal
);
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 result = await client.prepareEscrowExecution(
address,
requests.prepareEscrowExecution.simple
@@ -67,19 +49,10 @@ export default <TestSuite>{
address,
mockRippled
) => {
mockRippled.addResponse(
{ command: "server_info" },
rippled.server_info.normal
);
mockRippled.addResponse({ command: "fee" }, rippled.fee);
mockRippled.addResponse(
{ command: "ledger_current" },
rippled.ledger_current
);
mockRippled.addResponse(
{ command: "account_info" },
rippled.account_info.normal
);
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);
await assertRejects(
client.prepareEscrowExecution(
address,
@@ -96,19 +69,10 @@ export default <TestSuite>{
address,
mockRippled
) => {
mockRippled.addResponse(
{ command: "server_info" },
rippled.server_info.normal
);
mockRippled.addResponse({ command: "fee" }, rippled.fee);
mockRippled.addResponse(
{ command: "ledger_current" },
rippled.ledger_current
);
mockRippled.addResponse(
{ command: "account_info" },
rippled.account_info.normal
);
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);
await assertRejects(
client.prepareEscrowExecution(
address,
@@ -121,19 +85,10 @@ export default <TestSuite>{
},
"with ticket": async (client, address, mockRippled) => {
mockRippled.addResponse(
{ command: "server_info" },
rippled.server_info.normal
);
mockRippled.addResponse({ command: "fee" }, rippled.fee);
mockRippled.addResponse(
{ command: "ledger_current" },
rippled.ledger_current
);
mockRippled.addResponse(
{ command: "account_info" },
rippled.account_info.normal
);
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 = {
...instructionsWithMaxLedgerVersionOffset,
maxFee: "0.000396",

View File

@@ -12,38 +12,20 @@ const instructionsWithMaxLedgerVersionOffset = { maxLedgerVersionOffset: 100 };
*/
export default <TestSuite>{
"buy order": async (client, address, mockRippled) => {
mockRippled.addResponse(
{ command: "server_info" },
rippled.server_info.normal
);
mockRippled.addResponse({ command: "fee" }, rippled.fee);
mockRippled.addResponse(
{ command: "ledger_current" },
rippled.ledger_current
);
mockRippled.addResponse(
{ command: "account_info" },
rippled.account_info.normal
);
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) => {
mockRippled.addResponse(
{ command: "server_info" },
rippled.server_info.normal
);
mockRippled.addResponse({ command: "fee" }, rippled.fee);
mockRippled.addResponse(
{ command: "ledger_current" },
rippled.ledger_current
);
mockRippled.addResponse(
{ command: "account_info" },
rippled.account_info.normal
);
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.expiration;
const response = responses.prepareOrder.expiration;
const result = await client.prepareOrder(
@@ -55,19 +37,10 @@ export default <TestSuite>{
},
"sell order": async (client, address, mockRippled) => {
mockRippled.addResponse(
{ command: "server_info" },
rippled.server_info.normal
);
mockRippled.addResponse({ command: "fee" }, rippled.fee);
mockRippled.addResponse(
{ command: "ledger_current" },
rippled.ledger_current
);
mockRippled.addResponse(
{ command: "account_info" },
rippled.account_info.normal
);
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.sell;
const result = await client.prepareOrder(
address,
@@ -78,19 +51,10 @@ export default <TestSuite>{
},
async invalid(client, address, mockRippled) {
mockRippled.addResponse(
{ command: "server_info" },
rippled.server_info.normal
);
mockRippled.addResponse({ command: "fee" }, rippled.fee);
mockRippled.addResponse(
{ command: "ledger_current" },
rippled.ledger_current
);
mockRippled.addResponse(
{ command: "account_info" },
rippled.account_info.normal
);
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.sell };
delete request.direction; // Make invalid
await assertRejects(
@@ -105,19 +69,10 @@ export default <TestSuite>{
},
"with ticket": async (client, address, mockRippled) => {
mockRippled.addResponse(
{ command: "server_info" },
rippled.server_info.normal
);
mockRippled.addResponse({ command: "fee" }, rippled.fee);
mockRippled.addResponse(
{ command: "ledger_current" },
rippled.ledger_current
);
mockRippled.addResponse(
{ command: "account_info" },
rippled.account_info.normal
);
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.sell;
const localInstructions = {
...instructionsWithMaxLedgerVersionOffset,

View File

@@ -12,19 +12,10 @@ const instructionsWithMaxLedgerVersionOffset = { maxLedgerVersionOffset: 100 };
*/
export default <TestSuite>{
async prepareOrderCancellation(client, address, mockRippled) {
mockRippled.addResponse(
{ command: "server_info" },
rippled.server_info.normal
);
mockRippled.addResponse({ command: "fee" }, rippled.fee);
mockRippled.addResponse(
{ command: "ledger_current" },
rippled.ledger_current
);
mockRippled.addResponse(
{ command: "account_info" },
rippled.account_info.normal
);
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.prepareOrderCancellation.simple;
const result = await client.prepareOrderCancellation(
address,
@@ -39,19 +30,10 @@ export default <TestSuite>{
},
"no instructions": async (client, address, mockRippled) => {
mockRippled.addResponse(
{ command: "server_info" },
rippled.server_info.normal
);
mockRippled.addResponse({ command: "fee" }, rippled.fee);
mockRippled.addResponse(
{ command: "ledger_current" },
rippled.ledger_current
);
mockRippled.addResponse(
{ command: "account_info" },
rippled.account_info.normal
);
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.prepareOrderCancellation.simple;
const result = await client.prepareOrderCancellation(address, request);
assertResultMatch(
@@ -62,19 +44,10 @@ export default <TestSuite>{
},
"with memos": async (client, address, mockRippled) => {
mockRippled.addResponse(
{ command: "server_info" },
rippled.server_info.normal
);
mockRippled.addResponse({ command: "fee" }, rippled.fee);
mockRippled.addResponse(
{ command: "ledger_current" },
rippled.ledger_current
);
mockRippled.addResponse(
{ command: "account_info" },
rippled.account_info.normal
);
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.prepareOrderCancellation.withMemos;
const result = await client.prepareOrderCancellation(address, request);
assertResultMatch(
@@ -85,19 +58,10 @@ export default <TestSuite>{
},
async invalid(client, address, mockRippled) {
mockRippled.addResponse(
{ command: "server_info" },
rippled.server_info.normal
);
mockRippled.addResponse({ command: "fee" }, rippled.fee);
mockRippled.addResponse(
{ command: "ledger_current" },
rippled.ledger_current
);
mockRippled.addResponse(
{ command: "account_info" },
rippled.account_info.normal
);
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.prepareOrderCancellation.withMemos,
};
@@ -111,19 +75,10 @@ export default <TestSuite>{
},
"with ticket": async (client, address, mockRippled) => {
mockRippled.addResponse(
{ command: "server_info" },
rippled.server_info.normal
);
mockRippled.addResponse({ command: "fee" }, rippled.fee);
mockRippled.addResponse(
{ command: "ledger_current" },
rippled.ledger_current
);
mockRippled.addResponse(
{ command: "account_info" },
rippled.account_info.normal
);
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.prepareOrderCancellation.simple;
const localInstructions = {
...instructionsWithMaxLedgerVersionOffset,

View File

@@ -1,8 +1,4 @@
import { assert } from "chai";
import binary from "ripple-binary-codec";
import { ValidationError } from "xrpl-local/common/errors";
import * as schemaValidator from "xrpl-local/common/schema-validator";
import requests from "../fixtures/requests";
import responses from "../fixtures/responses";
@@ -21,19 +17,10 @@ const RECIPIENT_ADDRESS = "rpZc4mVfWUif9CRoHRKKcmhu1nx2xktxBo";
*/
export default <TestSuite>{
async normal(client, address, mockRippled) {
mockRippled.addResponse(
{ command: "server_info" },
rippled.server_info.normal
);
mockRippled.addResponse({ command: "fee" }, rippled.fee);
mockRippled.addResponse(
{ command: "ledger_current" },
rippled.ledger_current
);
mockRippled.addResponse(
{ command: "account_info" },
rippled.account_info.normal
);
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 = {
...instructionsWithMaxLedgerVersionOffset,
maxFee: "0.000012",
@@ -47,19 +34,10 @@ export default <TestSuite>{
},
"min amount xrp": async (client, address, mockRippled) => {
mockRippled.addResponse(
{ command: "server_info" },
rippled.server_info.normal
);
mockRippled.addResponse({ command: "fee" }, rippled.fee);
mockRippled.addResponse(
{ command: "ledger_current" },
rippled.ledger_current
);
mockRippled.addResponse(
{ command: "account_info" },
rippled.account_info.normal
);
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 = {
...instructionsWithMaxLedgerVersionOffset,
maxFee: "0.000012",
@@ -73,19 +51,10 @@ export default <TestSuite>{
},
"min amount xrp2xrp": async (client, address, mockRippled) => {
mockRippled.addResponse(
{ command: "server_info" },
rippled.server_info.normal
);
mockRippled.addResponse({ command: "fee" }, rippled.fee);
mockRippled.addResponse(
{ command: "ledger_current" },
rippled.ledger_current
);
mockRippled.addResponse(
{ command: "account_info" },
rippled.account_info.normal
);
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 response = await client.preparePayment(
address,
REQUEST_FIXTURES.minAmount,
@@ -95,19 +64,10 @@ export default <TestSuite>{
},
"XRP to XRP": async (client, address, mockRippled) => {
mockRippled.addResponse(
{ command: "server_info" },
rippled.server_info.normal
);
mockRippled.addResponse({ command: "fee" }, rippled.fee);
mockRippled.addResponse(
{ command: "ledger_current" },
rippled.ledger_current
);
mockRippled.addResponse(
{ command: "account_info" },
rippled.account_info.normal
);
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 = {
source: {
address: "r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59",
@@ -136,19 +96,10 @@ export default <TestSuite>{
},
"XRP drops to XRP drops": async (client, address, mockRippled) => {
mockRippled.addResponse(
{ command: "server_info" },
rippled.server_info.normal
);
mockRippled.addResponse({ command: "fee" }, rippled.fee);
mockRippled.addResponse(
{ command: "ledger_current" },
rippled.ledger_current
);
mockRippled.addResponse(
{ command: "account_info" },
rippled.account_info.normal
);
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 = {
source: {
address: "r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59",
@@ -177,19 +128,10 @@ export default <TestSuite>{
},
"XRP drops to XRP": async (client, address, mockRippled) => {
mockRippled.addResponse(
{ command: "server_info" },
rippled.server_info.normal
);
mockRippled.addResponse({ command: "fee" }, rippled.fee);
mockRippled.addResponse(
{ command: "ledger_current" },
rippled.ledger_current
);
mockRippled.addResponse(
{ command: "account_info" },
rippled.account_info.normal
);
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 = {
source: {
address: "r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59",
@@ -218,19 +160,10 @@ export default <TestSuite>{
},
"XRP to XRP drops": async (client, address, mockRippled) => {
mockRippled.addResponse(
{ command: "server_info" },
rippled.server_info.normal
);
mockRippled.addResponse({ command: "fee" }, rippled.fee);
mockRippled.addResponse(
{ command: "ledger_current" },
rippled.ledger_current
);
mockRippled.addResponse(
{ command: "account_info" },
rippled.account_info.normal
);
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 = {
source: {
address: "r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59",
@@ -264,19 +197,10 @@ export default <TestSuite>{
address,
mockRippled
) => {
mockRippled.addResponse(
{ command: "server_info" },
rippled.server_info.normal
);
mockRippled.addResponse({ command: "fee" }, rippled.fee);
mockRippled.addResponse(
{ command: "ledger_current" },
rippled.ledger_current
);
mockRippled.addResponse(
{ command: "account_info" },
rippled.account_info.normal
);
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 = {
source: {
address,
@@ -301,19 +225,10 @@ export default <TestSuite>{
address,
mockRippled
) => {
mockRippled.addResponse(
{ command: "server_info" },
rippled.server_info.normal
);
mockRippled.addResponse({ command: "fee" }, rippled.fee);
mockRippled.addResponse(
{ command: "ledger_current" },
rippled.ledger_current
);
mockRippled.addResponse(
{ command: "account_info" },
rippled.account_info.normal
);
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);
// Marking as "any" to get around the fact that TS won't allow this.
const payment: any = {
source: { address },
@@ -335,19 +250,10 @@ export default <TestSuite>{
address,
mockRippled
) => {
mockRippled.addResponse(
{ command: "server_info" },
rippled.server_info.normal
);
mockRippled.addResponse({ command: "fee" }, rippled.fee);
mockRippled.addResponse(
{ command: "ledger_current" },
rippled.ledger_current
);
mockRippled.addResponse(
{ command: "account_info" },
rippled.account_info.normal
);
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 = {
source: {
address,
@@ -366,19 +272,10 @@ export default <TestSuite>{
},
"XRP to XRP no partial": async (client, address, mockRippled) => {
mockRippled.addResponse(
{ command: "server_info" },
rippled.server_info.normal
);
mockRippled.addResponse({ command: "fee" }, rippled.fee);
mockRippled.addResponse(
{ command: "ledger_current" },
rippled.ledger_current
);
mockRippled.addResponse(
{ command: "account_info" },
rippled.account_info.normal
);
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);
return assertRejects(
client.preparePayment(address, REQUEST_FIXTURES.wrongPartial),
ValidationError,
@@ -391,19 +288,10 @@ export default <TestSuite>{
address,
mockRippled
) => {
mockRippled.addResponse(
{ command: "server_info" },
rippled.server_info.normal
);
mockRippled.addResponse({ command: "fee" }, rippled.fee);
mockRippled.addResponse(
{ command: "ledger_current" },
rippled.ledger_current
);
mockRippled.addResponse(
{ command: "account_info" },
rippled.account_info.normal
);
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);
return assertRejects(
client.preparePayment(address, REQUEST_FIXTURES.wrongAddress),
ValidationError,
@@ -412,19 +300,10 @@ export default <TestSuite>{
},
"wrong amount": async (client, address, mockRippled) => {
mockRippled.addResponse(
{ command: "server_info" },
rippled.server_info.normal
);
mockRippled.addResponse({ command: "fee" }, rippled.fee);
mockRippled.addResponse(
{ command: "ledger_current" },
rippled.ledger_current
);
mockRippled.addResponse(
{ command: "account_info" },
rippled.account_info.normal
);
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);
return assertRejects(
client.preparePayment(address, REQUEST_FIXTURES.wrongAmount),
ValidationError,
@@ -433,19 +312,10 @@ export default <TestSuite>{
},
"throws when fee exceeds 2 XRP": async (client, address, mockRippled) => {
mockRippled.addResponse(
{ command: "server_info" },
rippled.server_info.normal
);
mockRippled.addResponse({ command: "fee" }, rippled.fee);
mockRippled.addResponse(
{ command: "ledger_current" },
rippled.ledger_current
);
mockRippled.addResponse(
{ command: "account_info" },
rippled.account_info.normal
);
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 = {
...instructionsWithMaxLedgerVersionOffset,
fee: "2.1",
@@ -481,19 +351,10 @@ export default <TestSuite>{
address,
mockRippled
) => {
mockRippled.addResponse(
{ command: "server_info" },
rippled.server_info.normal
);
mockRippled.addResponse({ command: "fee" }, rippled.fee);
mockRippled.addResponse(
{ command: "ledger_current" },
rippled.ledger_current
);
mockRippled.addResponse(
{ command: "account_info" },
rippled.account_info.normal
);
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 = {
...instructionsWithMaxLedgerVersionOffset,
sequence: 23,
@@ -508,19 +369,10 @@ export default <TestSuite>{
"preparePayment with source.amount/destination.minAmount can be signed":
async (client, address, mockRippled) => {
mockRippled.addResponse(
{ command: "server_info" },
rippled.server_info.normal
);
mockRippled.addResponse({ command: "fee" }, rippled.fee);
mockRippled.addResponse(
{ command: "ledger_current" },
rippled.ledger_current
);
mockRippled.addResponse(
{ command: "account_info" },
rippled.account_info.normal
);
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);
// See also: 'sign succeeds with source.amount/destination.minAmount'
const localInstructions = {
@@ -529,60 +381,17 @@ export default <TestSuite>{
};
const response = await client.preparePayment(
address,
{
source: {
address,
amount: {
currency: "GBP",
value: "0.1",
counterparty: "rpat5TmYjDsnFSStmgTumFgXCM9eqsWPro",
},
},
destination: {
address: "rEX4LtGJubaUcMWCJULcy4NVxGT9ZEMVRq",
minAmount: {
currency: "USD",
value: "0.1248548562296331",
counterparty: "rMaa8VLBTjwTJWA2kSme4Sqgphhr6Lr6FH",
},
},
},
REQUEST_FIXTURES.noCounterparty,
localInstructions
);
// Important: check that the prepared transaction can actually be signed
// https://github.com/ripple/ripple-lib/issues/1237#issuecomment-631670946
const secret = "shotKgaEotpcYsshSE39vmSnBDRim";
const result = client.sign(response.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);
assertResultMatch(response, RESPONSE_FIXTURES.noCounterparty, "prepare");
},
"destination.minAmount": async (client, address, mockRippled) => {
mockRippled.addResponse(
{ command: "server_info" },
rippled.server_info.normal
);
mockRippled.addResponse({ command: "fee" }, rippled.fee);
mockRippled.addResponse(
{ command: "ledger_current" },
rippled.ledger_current
);
mockRippled.addResponse(
{ command: "account_info" },
rippled.account_info.normal
);
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 response = await client.preparePayment(
address,
responses.getPaths.sendAll[0],
@@ -592,19 +401,10 @@ export default <TestSuite>{
},
"caps fee at 2 XRP by default": async (client, address, mockRippled) => {
mockRippled.addResponse(
{ command: "server_info" },
rippled.server_info.normal
);
mockRippled.addResponse({ command: "fee" }, rippled.fee);
mockRippled.addResponse(
{ command: "ledger_current" },
rippled.ledger_current
);
mockRippled.addResponse(
{ command: "account_info" },
rippled.account_info.normal
);
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);
client._feeCushion = 1000000;
const expectedResponse = {
txJSON:
@@ -628,19 +428,10 @@ export default <TestSuite>{
address,
mockRippled
) => {
mockRippled.addResponse(
{ command: "server_info" },
rippled.server_info.normal
);
mockRippled.addResponse({ command: "fee" }, rippled.fee);
mockRippled.addResponse(
{ command: "ledger_current" },
rippled.ledger_current
);
mockRippled.addResponse(
{ command: "account_info" },
rippled.account_info.normal
);
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);
client._maxFeeXRP = "2.2";
const localInstructions = {
...instructionsWithMaxLedgerVersionOffset,
@@ -664,19 +455,10 @@ export default <TestSuite>{
},
"fee - default maxFee of 2 XRP": async (client, address, mockRippled) => {
mockRippled.addResponse(
{ command: "server_info" },
rippled.server_info.normal
);
mockRippled.addResponse({ command: "fee" }, rippled.fee);
mockRippled.addResponse(
{ command: "ledger_current" },
rippled.ledger_current
);
mockRippled.addResponse(
{ command: "account_info" },
rippled.account_info.normal
);
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);
client._feeCushion = 1000000;
const expectedResponse = {
txJSON:
@@ -700,19 +482,10 @@ export default <TestSuite>{
address,
mockRippled
) => {
mockRippled.addResponse(
{ command: "server_info" },
rippled.server_info.normal
);
mockRippled.addResponse({ command: "fee" }, rippled.fee);
mockRippled.addResponse(
{ command: "ledger_current" },
rippled.ledger_current
);
mockRippled.addResponse(
{ command: "account_info" },
rippled.account_info.normal
);
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);
client._feeCushion = 1000000;
client._maxFeeXRP = "3";
const localInstructions = {
@@ -737,19 +510,10 @@ export default <TestSuite>{
},
"fee - capped to maxFee": async (client, address, mockRippled) => {
mockRippled.addResponse(
{ command: "server_info" },
rippled.server_info.normal
);
mockRippled.addResponse({ command: "fee" }, rippled.fee);
mockRippled.addResponse(
{ command: "ledger_current" },
rippled.ledger_current
);
mockRippled.addResponse(
{ command: "account_info" },
rippled.account_info.normal
);
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);
client._feeCushion = 1000000;
client._maxFeeXRP = "5";
const localInstructions = {

View File

@@ -16,19 +16,10 @@ const { preparePaymentChannelClaim: RESPONSE_FIXTURES } = responses;
*/
export default <TestSuite>{
async default(client, address, mockRippled) {
mockRippled.addResponse(
{ command: "server_info" },
rippled.server_info.normal
);
mockRippled.addResponse({ command: "fee" }, rippled.fee);
mockRippled.addResponse(
{ command: "ledger_current" },
rippled.ledger_current
);
mockRippled.addResponse(
{ command: "account_info" },
rippled.account_info.normal
);
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 = {
...instructionsWithMaxLedgerVersionOffset,
maxFee: "0.000012",
@@ -42,19 +33,10 @@ export default <TestSuite>{
},
"with renew": async (client, address, mockRippled) => {
mockRippled.addResponse(
{ command: "server_info" },
rippled.server_info.normal
);
mockRippled.addResponse({ command: "fee" }, rippled.fee);
mockRippled.addResponse(
{ command: "ledger_current" },
rippled.ledger_current
);
mockRippled.addResponse(
{ command: "account_info" },
rippled.account_info.normal
);
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 = {
...instructionsWithMaxLedgerVersionOffset,
maxFee: "0.000012",
@@ -68,19 +50,10 @@ export default <TestSuite>{
},
"with close": async (client, address, mockRippled) => {
mockRippled.addResponse(
{ command: "server_info" },
rippled.server_info.normal
);
mockRippled.addResponse({ command: "fee" }, rippled.fee);
mockRippled.addResponse(
{ command: "ledger_current" },
rippled.ledger_current
);
mockRippled.addResponse(
{ command: "account_info" },
rippled.account_info.normal
);
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 = {
...instructionsWithMaxLedgerVersionOffset,
maxFee: "0.000012",
@@ -94,19 +67,10 @@ export default <TestSuite>{
},
"with ticket": async (client, address, mockRippled) => {
mockRippled.addResponse(
{ command: "server_info" },
rippled.server_info.normal
);
mockRippled.addResponse({ command: "fee" }, rippled.fee);
mockRippled.addResponse(
{ command: "ledger_current" },
rippled.ledger_current
);
mockRippled.addResponse(
{ command: "account_info" },
rippled.account_info.normal
);
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 = {
...instructionsWithMaxLedgerVersionOffset,
maxFee: "0.000012",
@@ -125,19 +89,10 @@ export default <TestSuite>{
address,
mockRippled
) => {
mockRippled.addResponse(
{ command: "server_info" },
rippled.server_info.normal
);
mockRippled.addResponse({ command: "fee" }, rippled.fee);
mockRippled.addResponse(
{ command: "ledger_current" },
rippled.ledger_current
);
mockRippled.addResponse(
{ command: "account_info" },
rippled.account_info.normal
);
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);
try {
const prepared = await client.preparePaymentChannelClaim(
address,
@@ -162,19 +117,10 @@ export default <TestSuite>{
address,
mockRippled
) => {
mockRippled.addResponse(
{ command: "server_info" },
rippled.server_info.normal
);
mockRippled.addResponse({ command: "fee" }, rippled.fee);
mockRippled.addResponse(
{ command: "ledger_current" },
rippled.ledger_current
);
mockRippled.addResponse(
{ command: "account_info" },
rippled.account_info.normal
);
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);
try {
const prepared = await client.preparePaymentChannelClaim(
address,

View File

@@ -19,19 +19,10 @@ export const config = {
*/
export default <TestSuite>{
async preparePaymentChannelCreate(client, address, mockRippled) {
mockRippled.addResponse(
{ command: "server_info" },
rippled.server_info.normal
);
mockRippled.addResponse({ command: "fee" }, rippled.fee);
mockRippled.addResponse(
{ command: "ledger_current" },
rippled.ledger_current
);
mockRippled.addResponse(
{ command: "account_info" },
rippled.account_info.normal
);
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 = {
...instructionsWithMaxLedgerVersionOffset,
maxFee: "0.000012",
@@ -49,19 +40,10 @@ export default <TestSuite>{
},
"preparePaymentChannelCreate full": async (client, address, mockRippled) => {
mockRippled.addResponse(
{ command: "server_info" },
rippled.server_info.normal
);
mockRippled.addResponse({ command: "fee" }, rippled.fee);
mockRippled.addResponse(
{ command: "ledger_current" },
rippled.ledger_current
);
mockRippled.addResponse(
{ command: "account_info" },
rippled.account_info.normal
);
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 result = await client.preparePaymentChannelCreate(
address,
requests.preparePaymentChannelCreate.full
@@ -78,19 +60,10 @@ export default <TestSuite>{
address,
mockRippled
) => {
mockRippled.addResponse(
{ command: "server_info" },
rippled.server_info.normal
);
mockRippled.addResponse({ command: "fee" }, rippled.fee);
mockRippled.addResponse(
{ command: "ledger_current" },
rippled.ledger_current
);
mockRippled.addResponse(
{ command: "account_info" },
rippled.account_info.normal
);
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 = {
...instructionsWithMaxLedgerVersionOffset,
maxFee: "0.000012",

View File

@@ -12,19 +12,10 @@ const instructionsWithMaxLedgerVersionOffset = { maxLedgerVersionOffset: 100 };
*/
export default <TestSuite>{
async preparePaymentChannelFund(client, address, mockRippled) {
mockRippled.addResponse(
{ command: "server_info" },
rippled.server_info.normal
);
mockRippled.addResponse({ command: "fee" }, rippled.fee);
mockRippled.addResponse(
{ command: "ledger_current" },
rippled.ledger_current
);
mockRippled.addResponse(
{ command: "account_info" },
rippled.account_info.normal
);
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 = {
...instructionsWithMaxLedgerVersionOffset,
maxFee: "0.000012",
@@ -42,19 +33,10 @@ export default <TestSuite>{
},
"preparePaymentChannelFund full": async (client, address, mockRippled) => {
mockRippled.addResponse(
{ command: "server_info" },
rippled.server_info.normal
);
mockRippled.addResponse({ command: "fee" }, rippled.fee);
mockRippled.addResponse(
{ command: "ledger_current" },
rippled.ledger_current
);
mockRippled.addResponse(
{ command: "account_info" },
rippled.account_info.normal
);
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 result = await client.preparePaymentChannelFund(
address,
requests.preparePaymentChannelFund.full
@@ -67,19 +49,10 @@ export default <TestSuite>{
},
"with ticket": async (client, address, mockRippled) => {
mockRippled.addResponse(
{ command: "server_info" },
rippled.server_info.normal
);
mockRippled.addResponse({ command: "fee" }, rippled.fee);
mockRippled.addResponse(
{ command: "ledger_current" },
rippled.ledger_current
);
mockRippled.addResponse(
{ command: "account_info" },
rippled.account_info.normal
);
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 = {
...instructionsWithMaxLedgerVersionOffset,
maxFee: "0.000012",

View File

@@ -1,6 +1,6 @@
import { assert } from "chai";
import { FormattedSettings } from "../../src/common/types/objects";
import { FormattedSettings } from "../../src/common/types/objects";
import requests from "../fixtures/requests";
import responses from "../fixtures/responses";
import rippled from "../fixtures/rippled";
@@ -15,19 +15,10 @@ const instructionsWithMaxLedgerVersionOffset = { maxLedgerVersionOffset: 100 };
*/
export default <TestSuite>{
"simple test": async (client, address, mockRippled) => {
mockRippled.addResponse(
{ command: "server_info" },
rippled.server_info.normal
);
mockRippled.addResponse({ command: "fee" }, rippled.fee);
mockRippled.addResponse(
{ command: "ledger_current" },
rippled.ledger_current
);
mockRippled.addResponse(
{ command: "account_info" },
rippled.account_info.normal
);
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 response = await client.prepareSettings(
address,
requests.prepareSettings.domain,
@@ -36,19 +27,10 @@ export default <TestSuite>{
assertResultMatch(response, responses.prepareSettings.flags, "prepare");
},
"no maxLedgerVersion": async (client, address, mockRippled) => {
mockRippled.addResponse(
{ command: "server_info" },
rippled.server_info.normal
);
mockRippled.addResponse({ command: "fee" }, rippled.fee);
mockRippled.addResponse(
{ command: "ledger_current" },
rippled.ledger_current
);
mockRippled.addResponse(
{ command: "account_info" },
rippled.account_info.normal
);
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 response = await client.prepareSettings(
address,
requests.prepareSettings.domain,
@@ -63,19 +45,10 @@ export default <TestSuite>{
);
},
"no instructions": async (client, address, mockRippled) => {
mockRippled.addResponse(
{ command: "server_info" },
rippled.server_info.normal
);
mockRippled.addResponse({ command: "fee" }, rippled.fee);
mockRippled.addResponse(
{ command: "ledger_current" },
rippled.ledger_current
);
mockRippled.addResponse(
{ command: "account_info" },
rippled.account_info.normal
);
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 response = await client.prepareSettings(
address,
requests.prepareSettings.domain
@@ -87,19 +60,10 @@ export default <TestSuite>{
);
},
async regularKey(client, address, mockRippled) {
mockRippled.addResponse(
{ command: "server_info" },
rippled.server_info.normal
);
mockRippled.addResponse({ command: "fee" }, rippled.fee);
mockRippled.addResponse(
{ command: "ledger_current" },
rippled.ledger_current
);
mockRippled.addResponse(
{ command: "account_info" },
rippled.account_info.normal
);
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 regularKey = { regularKey: "rAR8rR8sUkBoCZFawhkWzY4Y5YoyuznwD" };
const response = await client.prepareSettings(
address,
@@ -113,19 +77,10 @@ export default <TestSuite>{
);
},
"remove regularKey": async (client, address, mockRippled) => {
mockRippled.addResponse(
{ command: "server_info" },
rippled.server_info.normal
);
mockRippled.addResponse({ command: "fee" }, rippled.fee);
mockRippled.addResponse(
{ command: "ledger_current" },
rippled.ledger_current
);
mockRippled.addResponse(
{ command: "account_info" },
rippled.account_info.normal
);
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 regularKey = { regularKey: null };
const response = await client.prepareSettings(
address,
@@ -139,19 +94,10 @@ export default <TestSuite>{
);
},
"flag set": async (client, address, mockRippled) => {
mockRippled.addResponse(
{ command: "server_info" },
rippled.server_info.normal
);
mockRippled.addResponse({ command: "fee" }, rippled.fee);
mockRippled.addResponse(
{ command: "ledger_current" },
rippled.ledger_current
);
mockRippled.addResponse(
{ command: "account_info" },
rippled.account_info.normal
);
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 settings = { requireDestinationTag: true };
const response = await client.prepareSettings(
address,
@@ -161,19 +107,10 @@ export default <TestSuite>{
assertResultMatch(response, responses.prepareSettings.flagSet, "prepare");
},
"flag clear": async (client, address, mockRippled) => {
mockRippled.addResponse(
{ command: "server_info" },
rippled.server_info.normal
);
mockRippled.addResponse({ command: "fee" }, rippled.fee);
mockRippled.addResponse(
{ command: "ledger_current" },
rippled.ledger_current
);
mockRippled.addResponse(
{ command: "account_info" },
rippled.account_info.normal
);
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 settings = { requireDestinationTag: false };
const response = await client.prepareSettings(
address,
@@ -183,19 +120,10 @@ export default <TestSuite>{
assertResultMatch(response, responses.prepareSettings.flagClear, "prepare");
},
"set depositAuth flag": async (client, address, mockRippled) => {
mockRippled.addResponse(
{ command: "server_info" },
rippled.server_info.normal
);
mockRippled.addResponse({ command: "fee" }, rippled.fee);
mockRippled.addResponse(
{ command: "ledger_current" },
rippled.ledger_current
);
mockRippled.addResponse(
{ command: "account_info" },
rippled.account_info.normal
);
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 settings = { depositAuth: true };
const response = await client.prepareSettings(
address,
@@ -209,19 +137,10 @@ export default <TestSuite>{
);
},
"clear depositAuth flag": async (client, address, mockRippled) => {
mockRippled.addResponse(
{ command: "server_info" },
rippled.server_info.normal
);
mockRippled.addResponse({ command: "fee" }, rippled.fee);
mockRippled.addResponse(
{ command: "ledger_current" },
rippled.ledger_current
);
mockRippled.addResponse(
{ command: "account_info" },
rippled.account_info.normal
);
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 settings = { depositAuth: false };
const response = await client.prepareSettings(
address,
@@ -235,19 +154,10 @@ export default <TestSuite>{
);
},
"integer field clear": async (client, address, mockRippled) => {
mockRippled.addResponse(
{ command: "server_info" },
rippled.server_info.normal
);
mockRippled.addResponse({ command: "fee" }, rippled.fee);
mockRippled.addResponse(
{ command: "ledger_current" },
rippled.ledger_current
);
mockRippled.addResponse(
{ command: "account_info" },
rippled.account_info.normal
);
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 settings = { transferRate: null };
const response = await client.prepareSettings(
address,
@@ -258,19 +168,10 @@ export default <TestSuite>{
assert.strictEqual(JSON.parse(response.txJSON).TransferRate, 0);
},
"set transferRate": async (client, address, mockRippled) => {
mockRippled.addResponse(
{ command: "server_info" },
rippled.server_info.normal
);
mockRippled.addResponse({ command: "fee" }, rippled.fee);
mockRippled.addResponse(
{ command: "ledger_current" },
rippled.ledger_current
);
mockRippled.addResponse(
{ command: "account_info" },
rippled.account_info.normal
);
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 settings = { transferRate: 1 };
const response = await client.prepareSettings(
address,
@@ -284,19 +185,10 @@ export default <TestSuite>{
);
},
"set signers": async (client, address, mockRippled) => {
mockRippled.addResponse(
{ command: "server_info" },
rippled.server_info.normal
);
mockRippled.addResponse({ command: "fee" }, rippled.fee);
mockRippled.addResponse(
{ command: "ledger_current" },
rippled.ledger_current
);
mockRippled.addResponse(
{ command: "account_info" },
rippled.account_info.normal
);
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 settings = requests.prepareSettings.signers.normal;
const response = await client.prepareSettings(
address,
@@ -306,19 +198,10 @@ export default <TestSuite>{
assertResultMatch(response, responses.prepareSettings.signers, "prepare");
},
"signers no threshold": async (client, address, mockRippled) => {
mockRippled.addResponse(
{ command: "server_info" },
rippled.server_info.normal
);
mockRippled.addResponse({ command: "fee" }, rippled.fee);
mockRippled.addResponse(
{ command: "ledger_current" },
rippled.ledger_current
);
mockRippled.addResponse(
{ command: "account_info" },
rippled.account_info.normal
);
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 settings = requests.prepareSettings.signers.noThreshold;
try {
const response = await client.prepareSettings(
@@ -340,19 +223,10 @@ export default <TestSuite>{
}
},
"signers no weights": async (client, address, mockRippled) => {
mockRippled.addResponse(
{ command: "server_info" },
rippled.server_info.normal
);
mockRippled.addResponse({ command: "fee" }, rippled.fee);
mockRippled.addResponse(
{ command: "ledger_current" },
rippled.ledger_current
);
mockRippled.addResponse(
{ command: "account_info" },
rippled.account_info.normal
);
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 settings = requests.prepareSettings.signers.noWeights;
const localInstructions = {
signersCount: 1,
@@ -366,19 +240,10 @@ export default <TestSuite>{
assertResultMatch(response, responses.prepareSettings.noWeights, "prepare");
},
"fee for multisign": async (client, address, mockRippled) => {
mockRippled.addResponse(
{ command: "server_info" },
rippled.server_info.normal
);
mockRippled.addResponse({ command: "fee" }, rippled.fee);
mockRippled.addResponse(
{ command: "ledger_current" },
rippled.ledger_current
);
mockRippled.addResponse(
{ command: "account_info" },
rippled.account_info.normal
);
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 = {
signersCount: 4,
...instructionsWithMaxLedgerVersionOffset,
@@ -395,19 +260,10 @@ export default <TestSuite>{
);
},
"no signer list": async (client, address, mockRippled) => {
mockRippled.addResponse(
{ command: "server_info" },
rippled.server_info.normal
);
mockRippled.addResponse({ command: "fee" }, rippled.fee);
mockRippled.addResponse(
{ command: "ledger_current" },
rippled.ledger_current
);
mockRippled.addResponse(
{ command: "account_info" },
rippled.account_info.normal
);
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 settings = requests.prepareSettings.noSignerEntries;
const localInstructions = {
signersCount: 1,
@@ -425,19 +281,10 @@ export default <TestSuite>{
);
},
async invalid(client, address, mockRippled) {
mockRippled.addResponse(
{ command: "server_info" },
rippled.server_info.normal
);
mockRippled.addResponse({ command: "fee" }, rippled.fee);
mockRippled.addResponse(
{ command: "ledger_current" },
rippled.ledger_current
);
mockRippled.addResponse(
{ command: "account_info" },
rippled.account_info.normal
);
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);
// domain must be a string
const settings = { ...requests.prepareSettings.domain, domain: 123 };
const localInstructions = {
@@ -465,19 +312,10 @@ export default <TestSuite>{
}
},
async offline(client, address, mockRippled) {
mockRippled.addResponse(
{ command: "server_info" },
rippled.server_info.normal
);
mockRippled.addResponse({ command: "fee" }, rippled.fee);
mockRippled.addResponse(
{ command: "ledger_current" },
rippled.ledger_current
);
mockRippled.addResponse(
{ command: "account_info" },
rippled.account_info.normal
);
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 secret = "shsWGZcmZz6YsWWmcnpfr6fLTdtFV";
const settings = requests.prepareSettings.domain;
@@ -498,19 +336,10 @@ export default <TestSuite>{
);
},
"prepare settings with ticket": async (client, address, mockRippled) => {
mockRippled.addResponse(
{ command: "server_info" },
rippled.server_info.normal
);
mockRippled.addResponse({ command: "fee" }, rippled.fee);
mockRippled.addResponse(
{ command: "ledger_current" },
rippled.ledger_current
);
mockRippled.addResponse(
{ command: "account_info" },
rippled.account_info.normal
);
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 instructions = {
ticketSequence: 23,
maxLedgerVersion: 8820051,

View File

@@ -24,19 +24,10 @@ export default <TestSuite>{
address,
mockRippled
) => {
mockRippled.addResponse(
{ command: "server_info" },
rippled.server_info.normal
);
mockRippled.addResponse({ command: "fee" }, rippled.fee);
mockRippled.addResponse(
{ command: "ledger_current" },
rippled.ledger_current
);
mockRippled.addResponse(
{ command: "account_info" },
rippled.account_info.normal
);
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 expected = {
txJSON:
'{"TransactionType":"TicketCreate", "TicketCount": 2, "Account":"r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59","Flags":2147483648,"LastLedgerSequence":8819954,"Sequence":23,"Fee":"12"}',
@@ -55,19 +46,10 @@ export default <TestSuite>{
address,
mockRippled
) => {
mockRippled.addResponse(
{ command: "server_info" },
rippled.server_info.normal
);
mockRippled.addResponse({ command: "fee" }, rippled.fee);
mockRippled.addResponse(
{ command: "ledger_current" },
rippled.ledger_current
);
mockRippled.addResponse(
{ command: "account_info" },
rippled.account_info.normal
);
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 expected = {
txJSON:
'{"TransactionType":"TicketCreate", "TicketCount": 1, "Account":"r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59","Flags":2147483648,"LastLedgerSequence":8819954,"Sequence": 0,"TicketSequence":23,"Fee":"12"}',

File diff suppressed because it is too large Load Diff

View File

@@ -12,19 +12,10 @@ const instructionsWithMaxLedgerVersionOffset = { maxLedgerVersionOffset: 100 };
*/
export default <TestSuite>{
async simple(client, address, mockRippled) {
mockRippled.addResponse(
{ command: "server_info" },
rippled.server_info.normal
);
mockRippled.addResponse({ command: "fee" }, rippled.fee);
mockRippled.addResponse(
{ command: "ledger_current" },
rippled.ledger_current
);
mockRippled.addResponse(
{ command: "account_info" },
rippled.account_info.normal
);
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 result = await client.prepareTrustline(
address,
requests.prepareTrustline.simple,
@@ -34,19 +25,10 @@ export default <TestSuite>{
},
async frozen(client, address, mockRippled) {
mockRippled.addResponse(
{ command: "server_info" },
rippled.server_info.normal
);
mockRippled.addResponse({ command: "fee" }, rippled.fee);
mockRippled.addResponse(
{ command: "ledger_current" },
rippled.ledger_current
);
mockRippled.addResponse(
{ command: "account_info" },
rippled.account_info.normal
);
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 result = await client.prepareTrustline(
address,
requests.prepareTrustline.frozen
@@ -55,19 +37,10 @@ export default <TestSuite>{
},
async complex(client, address, mockRippled) {
mockRippled.addResponse(
{ command: "server_info" },
rippled.server_info.normal
);
mockRippled.addResponse({ command: "fee" }, rippled.fee);
mockRippled.addResponse(
{ command: "ledger_current" },
rippled.ledger_current
);
mockRippled.addResponse(
{ command: "account_info" },
rippled.account_info.normal
);
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 result = await client.prepareTrustline(
address,
requests.prepareTrustline.complex,
@@ -77,19 +50,10 @@ export default <TestSuite>{
},
async invalid(client, address, mockRippled) {
mockRippled.addResponse(
{ command: "server_info" },
rippled.server_info.normal
);
mockRippled.addResponse({ command: "fee" }, rippled.fee);
mockRippled.addResponse(
{ command: "ledger_current" },
rippled.ledger_current
);
mockRippled.addResponse(
{ command: "account_info" },
rippled.account_info.normal
);
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 trustline = { ...requests.prepareTrustline.complex };
delete trustline.limit; // Make invalid
@@ -105,19 +69,10 @@ export default <TestSuite>{
},
"xaddress-issuer": async (client, address, mockRippled) => {
mockRippled.addResponse(
{ command: "server_info" },
rippled.server_info.normal
);
mockRippled.addResponse({ command: "fee" }, rippled.fee);
mockRippled.addResponse(
{ command: "ledger_current" },
rippled.ledger_current
);
mockRippled.addResponse(
{ command: "account_info" },
rippled.account_info.normal
);
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 result = await client.prepareTrustline(
address,
requests.prepareTrustline.issuedXAddress,
@@ -131,19 +86,10 @@ export default <TestSuite>{
},
"with ticket": async (client, address, mockRippled) => {
mockRippled.addResponse(
{ command: "server_info" },
rippled.server_info.normal
);
mockRippled.addResponse({ command: "fee" }, rippled.fee);
mockRippled.addResponse(
{ command: "ledger_current" },
rippled.ledger_current
);
mockRippled.addResponse(
{ command: "account_info" },
rippled.account_info.normal
);
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 = {
...instructionsWithMaxLedgerVersionOffset,
maxFee: "0.000012",

View File

@@ -9,10 +9,7 @@ import { TestSuite, assertResultMatch } from "../testUtils";
*/
export default <TestSuite>{
"request account_objects": async (client, address, mockRippled) => {
mockRippled.addResponse(
{ command: "account_objects", account: address },
rippled.account_objects.normal
);
mockRippled.addResponse("account_objects", rippled.account_objects.normal);
const result = await client.request({
command: "account_objects",
account: address,
@@ -30,10 +27,7 @@ export default <TestSuite>{
address,
mockRippled
) => {
mockRippled.addResponse(
{ command: "account_objects", account: address },
rippled.account_objects.normal
);
mockRippled.addResponse("account_objects", rippled.account_objects.normal);
const result = await client.request({
command: "account_objects",
account: address,

View File

@@ -17,7 +17,7 @@ const rippledResponse = function (request: Request): object {
*/
export default <TestSuite>{
"requests the next page": async (client, address, mockRippled) => {
mockRippled.addResponse({ command: "ledger_data" }, rippledResponse);
mockRippled.addResponse("ledger_data", rippledResponse);
const response = await client.request({ command: "ledger_data" });
const responseNextPage = await client.requestNextPage(
{ command: "ledger_data" },
@@ -34,7 +34,7 @@ export default <TestSuite>{
address,
mockRippled
) => {
mockRippled.addResponse({ command: "ledger_data" }, rippledResponse);
mockRippled.addResponse("ledger_data", rippledResponse);
const response = await client.request({ command: "ledger_data" });
const responseNextPage = await client.requestNextPage(
{ command: "ledger_data" },

View File

@@ -59,19 +59,10 @@ export default <TestSuite>{
},
"sign with paths": async (client, address, mockRippled) => {
mockRippled.addResponse(
{ command: "server_info" },
rippled.server_info.normal
);
mockRippled.addResponse({ command: "fee" }, rippled.fee);
mockRippled.addResponse(
{ command: "ledger_current" },
rippled.ledger_current
);
mockRippled.addResponse(
{ command: "account_info" },
rippled.account_info.normal
);
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 secret = "shsWGZcmZz6YsWWmcnpfr6fLTdtFV";
const payment = {
source: {
@@ -184,19 +175,10 @@ export default <TestSuite>{
},
"succeeds - prepared payment": async (client, address, mockRippled) => {
mockRippled.addResponse(
{ command: "server_info" },
rippled.server_info.normal
);
mockRippled.addResponse({ command: "fee" }, rippled.fee);
mockRippled.addResponse(
{ command: "ledger_current" },
rippled.ledger_current
);
mockRippled.addResponse(
{ command: "account_info" },
rippled.account_info.normal
);
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: {
address,
@@ -272,19 +254,10 @@ export default <TestSuite>{
address,
mockRippled
) => {
mockRippled.addResponse(
{ command: "server_info" },
rippled.server_info.normal
);
mockRippled.addResponse({ command: "fee" }, rippled.fee);
mockRippled.addResponse(
{ command: "ledger_current" },
rippled.ledger_current
);
mockRippled.addResponse(
{ command: "account_info" },
rippled.account_info.normal
);
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: {
address,
@@ -312,19 +285,10 @@ export default <TestSuite>{
address,
mockRippled
) => {
mockRippled.addResponse(
{ command: "server_info" },
rippled.server_info.normal
);
mockRippled.addResponse({ command: "fee" }, rippled.fee);
mockRippled.addResponse(
{ command: "ledger_current" },
rippled.ledger_current
);
mockRippled.addResponse(
{ command: "account_info" },
rippled.account_info.normal
);
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 order = {
direction: "sell",
quantity: {

View File

@@ -6,6 +6,15 @@ import _ from "lodash";
import { Client } from "xrpl-local";
import { Connection } from "xrpl-local/client";
import {
ConnectionError,
DisconnectedError,
NotConnectedError,
ResponseFormatError,
RippleError,
TimeoutError,
} from "../src/common/errors";
import rippled from "./fixtures/rippled";
import setupClient from "./setupClient";
import { ignoreWebSocketDisconnect } from "./testUtils";
@@ -109,7 +118,7 @@ describe("Connection", function () {
};
const connection = new Connection(this.client.connection._url, options);
connection.connect().catch((err) => {
assert(err instanceof this.client.errors.NotConnectedError);
assert(err instanceof NotConnectedError);
});
}, done);
});
@@ -131,10 +140,10 @@ describe("Connection", function () {
ledger_index: "validated",
})
.then(() => {
assert(false, "Should throw NotConnectedError");
assert.fail("Should throw NotConnectedError");
})
.catch((error) => {
assert(error instanceof this.client.errors.NotConnectedError);
assert(error instanceof NotConnectedError);
});
});
@@ -151,53 +160,48 @@ describe("Connection", function () {
const connection = new Connection("ws://testripple.circleci.com:129");
connection.on("error", done);
connection.connect().catch((error) => {
assert(error instanceof this.client.errors.NotConnectedError);
assert(error instanceof NotConnectedError);
done();
});
});
it("DisconnectedError", async function () {
this.mockRippled.suppressOutput = true;
this.mockRippled.on(`request_server_info`, function (request, conn) {
assert.strictEqual(request.command, "server_info");
conn.close();
});
return this.client
.request({ command: "server_info" })
.request({ command: "test_command", data: { closeServer: true } })
.then(() => {
assert(false, "Should throw DisconnectedError");
assert.fail("Should throw DisconnectedError");
})
.catch((error) => {
assert(error instanceof this.client.errors.DisconnectedError);
assert(error instanceof DisconnectedError);
});
});
it("TimeoutError", function () {
this.client.connection._ws.send = function (message, callback) {
this.client.connection._ws.send = function (_, callback) {
callback(null);
};
const request = { command: "server_info" };
return this.client.connection
.request(request, 10)
.then(() => {
assert(false, "Should throw TimeoutError");
assert.fail("Should throw TimeoutError");
})
.catch((error) => {
assert(error instanceof this.client.errors.TimeoutError);
assert(error instanceof TimeoutError);
});
});
it("DisconnectedError on send", function () {
this.client.connection._ws.send = function (message, callback) {
this.client.connection._ws.send = function (_, callback) {
callback({ message: "not connected" });
};
return this.client
.request({ command: "server_info" })
.then(() => {
assert(false, "Should throw DisconnectedError");
assert.fail("Should throw DisconnectedError");
})
.catch((error) => {
assert(error instanceof this.client.errors.DisconnectedError);
assert(error instanceof DisconnectedError);
assert.strictEqual(error.message, "not connected");
});
});
@@ -210,7 +214,7 @@ describe("Connection", function () {
// stub _onOpen to only run logic relevant to test case
this.client.connection._onOpen = () => {
// overload websocket send on open when _ws exists
this.client.connection._ws.send = function (data, options, cb) {
this.client.connection._ws.send = function (_0, _1, _2) {
// recent ws throws this error instead of calling back
throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");
};
@@ -221,7 +225,7 @@ describe("Connection", function () {
try {
await this.client.connect();
} catch (error) {
assert(error instanceof this.client.errors.DisconnectedError);
assert(error instanceof DisconnectedError);
assert.strictEqual(
error.message,
"WebSocket is not open: readyState 0 (CONNECTING)"
@@ -236,10 +240,10 @@ describe("Connection", function () {
data: { unrecognizedResponse: true },
})
.then(() => {
assert(false, "Should throw ResponseFormatError");
assert.fail("Should throw ResponseFormatError");
})
.catch((error) => {
assert(error instanceof this.client.errors.ResponseFormatError);
assert(error instanceof ResponseFormatError);
});
});
@@ -403,11 +407,11 @@ describe("Connection", function () {
return connection
.connect()
.then(() => {
assert(false, "Should throw ConnectionError");
assert.fail("Should throw ConnectionError");
})
.catch((error) => {
assert(
error instanceof this.client.errors.ConnectionError,
error instanceof ConnectionError,
"Should throw ConnectionError"
);
});
@@ -418,7 +422,7 @@ describe("Connection", function () {
new Client({
servers: ["wss://server1.com", "wss://server2.com"],
} as any);
}, this.client.errors.RippleError);
}, RippleError);
});
it("connect throws error", function (done) {
@@ -496,7 +500,7 @@ describe("Connection", function () {
it("propagates RippledError data", function (done) {
const request = { command: "subscribe", streams: "validations" };
this.mockRippled.addResponse(request, rippled.subscribe.error);
this.mockRippled.addResponse(request.command, rippled.subscribe.error);
this.client.request(request).catch((error) => {
assert.strictEqual(error.name, "RippledError");

View File

@@ -6,13 +6,15 @@ import type { Request } from "../src";
import { getFreePort } from "./testUtils";
function createResponse(request, response, overrides = {}) {
const result = { ...response.result, ...overrides };
const change =
response.result && !_.isEmpty(overrides)
? { id: request.id, result }
: { id: request.id };
return JSON.stringify({ ...response, ...change });
function createResponse(request: { id: number | string }, response: object) {
if (!("type" in response) && !("error" in response)) {
throw new Error(
`Bad response format. Must contain \`type\` or \`error\`. ${JSON.stringify(
response
)}`
);
}
return JSON.stringify({ ...response, id: request.id });
}
function ping(conn, request) {
@@ -41,8 +43,12 @@ export function createMockRippled(port) {
mock.on("connection", function (this: MockedWebSocketServer, conn: any) {
this.socket = conn;
conn.on("message", function (requestJSON) {
let request;
try {
const request = JSON.parse(requestJSON);
request = JSON.parse(requestJSON);
if (request.id == null) {
throw new Error("Request has no id");
}
if (request.command === "ping") {
ping(conn, request);
} else if (request.command === "test_command") {
@@ -58,7 +64,15 @@ export function createMockRippled(port) {
if (!mock.suppressOutput) {
console.error(`Error: ${err.message}`);
}
conn.close(4000, err.message);
if (request != null) {
conn.send(
createResponse(request, {
type: "response",
status: "error",
error: err.message,
})
);
}
}
});
});
@@ -67,10 +81,23 @@ export function createMockRippled(port) {
// If an object is passed in for `response`, then the response is static for the command
// If a function is passed in for `response`, then the response can be determined by the exact request shape
mock.addResponse = (
request: Request,
command: string,
response: object | ((r: Request) => object)
) => {
const command = request.command;
if (typeof command !== "string") {
throw new Error("command is not a string");
}
if (
typeof response === "object" &&
!("type" in response) &&
!("error" in response)
) {
throw new Error(
`Bad response format. Must contain \`type\` or \`error\`. ${JSON.stringify(
response
)}`
);
}
mock.responses[command] = response;
};
@@ -123,6 +150,8 @@ export function createMockRippled(port) {
result: {},
})
);
} else if (request.data.closeServer) {
conn.close();
}
};

36
test/mockRippledTest.ts Normal file
View File

@@ -0,0 +1,36 @@
import { assert } from "chai";
import { RippledError } from "../src/common/errors";
import setupClient from "./setupClient";
import { assertRejects } from "./testUtils";
describe("mock rippled tests", function () {
beforeEach(setupClient.setup);
afterEach(setupClient.teardown);
it("errors if a mock is not provided", async function () {
this.mockRippled.suppressOutput = true;
await assertRejects(
this.client.request({ command: "server_info" }),
RippledError
);
});
it("provide bad response shape", async function () {
assert.throws(
() => this.mockRippled.addResponse("account_info", { data: {} }),
Error
);
});
it("provide bad response shape in function", async function () {
this.mockRippled.suppressOutput = true;
this.mockRippled.addResponse("account_info", (request) => {
return { data: request };
});
await assertRejects(
this.client.request({ command: "account_info", account: "" }),
RippledError
);
});
});