Lints src/client (#1577)

* lint backoff

* lint wsWrapper

* remove rangeset - not used

* split out connection.ts classes

* lint requestManager

* lint connectionManager

* lint most of connection

* fix most of client

* lint broadcastClient

* resolve more linter issues

* resolve magic numbers

* clean up more linting

* resolve rest of issues

* fix tests

* fix browser tests

* fix tests after rebase

* respond to comments

* fix dependency cycles
This commit is contained in:
Mayukha Vadari
2021-09-03 10:43:25 -05:00
parent aa6cef520c
commit 8c5bc22317
48 changed files with 1046 additions and 864 deletions

View File

@@ -14,7 +14,7 @@ describe("client constructor", function () {
it("Client valid options", function () {
const client = new Client("wss://s:1");
const privateConnectionUrl = (client.connection as any)._url;
const privateConnectionUrl = (client.connection as any).url;
assert.deepEqual(privateConnectionUrl, "wss://s:1");
});

View File

@@ -18,7 +18,7 @@ describe("client.getFee", function () {
it("getFee default", async function () {
this.mockRippled.addResponse("server_info", rippled.server_info.normal);
this.client._feeCushion = undefined as unknown as number;
this.client.feeCushion = undefined as unknown as number;
const fee = await this.client.getFee();
assert.strictEqual(fee, "0.000012");
});
@@ -39,14 +39,14 @@ describe("client.getFee", function () {
);
// Ensure that overriding with high maxFeeXRP of '51540' causes no errors.
// (fee will actually be 51539.607552)
this.client._maxFeeXRP = "51540";
this.client.maxFeeXRP = "51540";
const fee = await this.client.getFee();
assert.strictEqual(fee, "51539.607552");
});
it("getFee custom cushion", async function () {
this.mockRippled.addResponse("server_info", rippled.server_info.normal);
this.client._feeCushion = 1.4;
this.client.feeCushion = 1.4;
const fee = await this.client.getFee();
assert.strictEqual(fee, "0.000014");
});
@@ -55,7 +55,7 @@ describe("client.getFee", function () {
// less than the base fee. However, this test verifies the existing behavior.
it("getFee cushion less than 1.0", async function () {
this.mockRippled.addResponse("server_info", rippled.server_info.normal);
this.client._feeCushion = 0.9;
this.client.feeCushion = 0.9;
const fee = await this.client.getFee();
assert.strictEqual(fee, "0.000009");
});

View File

@@ -1,5 +1,6 @@
import { assert } from "chai";
import { Client } from "../../src";
import rippled from "../fixtures/rippled";
import setupClient from "../setupClient";
@@ -10,7 +11,7 @@ describe("client.hasNextPage", function () {
it("returns true when there is another page", async function () {
this.mockRippled.addResponse("ledger_data", rippled.ledger_data.first_page);
const response = await this.client.request({ command: "ledger_data" });
assert(this.client.hasNextPage(response));
assert(Client.hasNextPage(response));
});
it("returns false when there are no more pages", async function () {
@@ -26,6 +27,6 @@ describe("client.hasNextPage", function () {
{ command: "ledger_data" },
response
);
assert(!this.client.hasNextPage(responseNextPage));
assert(!Client.hasNextPage(responseNextPage));
});
});

View File

@@ -460,7 +460,7 @@ describe("client.preparePayment", function () {
"account_info",
rippled.account_info.normal
);
this.client._feeCushion = 1000000;
this.client.feeCushion = 1000000;
const expectedResponse = {
txJSON:
'{"Flags":2147483648,"TransactionType":"Payment","Account":"r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59","Destination":"rpZc4mVfWUif9CRoHRKKcmhu1nx2xktxBo","Amount":{"value":"0.01","currency":"USD","issuer":"rMH4UxPrbuMa1spCBR98hLLyNJp4d8p4tM"},"SendMax":{"value":"0.01","currency":"USD","issuer":"rMH4UxPrbuMa1spCBR98hLLyNJp4d8p4tM"},"LastLedgerSequence":8820051,"Fee":"2000000","Sequence":23}',
@@ -486,7 +486,7 @@ describe("client.preparePayment", function () {
"account_info",
rippled.account_info.normal
);
this.client._maxFeeXRP = "2.2";
this.client.maxFeeXRP = "2.2";
const localInstructions = {
...instructionsWithMaxLedgerVersionOffset,
fee: "2.1",
@@ -516,7 +516,7 @@ describe("client.preparePayment", function () {
"account_info",
rippled.account_info.normal
);
this.client._feeCushion = 1000000;
this.client.feeCushion = 1000000;
const expectedResponse = {
txJSON:
'{"Flags":2147483648,"TransactionType":"Payment","Account":"r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59","Destination":"rpZc4mVfWUif9CRoHRKKcmhu1nx2xktxBo","Amount":{"value":"0.01","currency":"USD","issuer":"rMH4UxPrbuMa1spCBR98hLLyNJp4d8p4tM"},"SendMax":{"value":"0.01","currency":"USD","issuer":"rMH4UxPrbuMa1spCBR98hLLyNJp4d8p4tM"},"LastLedgerSequence":8820051,"Fee":"2000000","Sequence":23}',
@@ -542,8 +542,8 @@ describe("client.preparePayment", function () {
"account_info",
rippled.account_info.normal
);
this.client._feeCushion = 1000000;
this.client._maxFeeXRP = "3";
this.client.feeCushion = 1000000;
this.client.maxFeeXRP = "3";
const localInstructions = {
...instructionsWithMaxLedgerVersionOffset,
maxFee: "4",
@@ -573,8 +573,8 @@ describe("client.preparePayment", function () {
"account_info",
rippled.account_info.normal
);
this.client._feeCushion = 1000000;
this.client._maxFeeXRP = "5";
this.client.feeCushion = 1000000;
this.client.maxFeeXRP = "5";
const localInstructions = {
...instructionsWithMaxLedgerVersionOffset,
maxFee: "4",

View File

@@ -1005,7 +1005,7 @@ describe("client.prepareTransaction", function () {
this.mockRippled.addResponse("fee", rippled.fee);
this.mockRippled.addResponse("ledger_current", rippled.ledger_current);
this.mockRippled.addResponse("account_info", rippled.account_info.normal);
this.client._feeCushion = 1000000;
this.client.feeCushion = 1000000;
const txJSON = {
Flags: 2147483648,
@@ -1046,7 +1046,7 @@ describe("client.prepareTransaction", function () {
this.mockRippled.addResponse("fee", rippled.fee);
this.mockRippled.addResponse("ledger_current", rippled.ledger_current);
this.mockRippled.addResponse("account_info", rippled.account_info.normal);
this.client._feeCushion = 1000000;
this.client.feeCushion = 1000000;
const txJSON = {
Flags: 2147483648,
@@ -1092,8 +1092,8 @@ describe("client.prepareTransaction", function () {
this.mockRippled.addResponse("fee", rippled.fee);
this.mockRippled.addResponse("ledger_current", rippled.ledger_current);
this.mockRippled.addResponse("account_info", rippled.account_info.normal);
this.client._feeCushion = 1000000;
this.client._maxFeeXRP = "3";
this.client.feeCushion = 1000000;
this.client.maxFeeXRP = "3";
const localInstructions = {
maxFee: "4", // We are testing that this does not matter; fee is still capped to maxFeeXRP
};
@@ -1139,8 +1139,8 @@ describe("client.prepareTransaction", function () {
this.mockRippled.addResponse("fee", rippled.fee);
this.mockRippled.addResponse("ledger_current", rippled.ledger_current);
this.mockRippled.addResponse("account_info", rippled.account_info.normal);
this.client._feeCushion = 1000000;
this.client._maxFeeXRP = "5";
this.client.feeCushion = 1000000;
this.client.maxFeeXRP = "5";
const localInstructions = {
maxFee: "4", // maxFeeXRP does not matter if maxFee is lower than maxFeeXRP
};

View File

@@ -1,5 +1,6 @@
import { assert } from "chai";
import { Client } from "../../src";
import rippled from "../fixtures/rippled";
import setupClient from "../setupClient";
import { assertRejects } from "../testUtils";
@@ -34,7 +35,7 @@ describe("client.requestNextPage", function () {
{ command: "ledger_data" },
response
);
assert(!this.client.hasNextPage(responseNextPage));
assert(!Client.hasNextPage(responseNextPage));
await assertRejects(
this.client.requestNextPage({ command: "ledger_data" }, responseNextPage),
Error,

View File

@@ -199,7 +199,7 @@ describe("client.sign", function () {
});
it("permits fee exceeding 2000000 drops when maxFeeXRP is higher than 2 XRP", async function () {
this.client._maxFeeXRP = "2.1";
this.client.maxFeeXRP = "2.1";
const secret = "shsWGZcmZz6YsWWmcnpfr6fLTdtFV";
const request = {
// TODO: This fails when address is X-address
@@ -247,7 +247,7 @@ describe("client.sign", function () {
});
it("throws when Fee exceeds maxFeeXRP (in drops) - custom maxFeeXRP", async function () {
this.client._maxFeeXRP = "1.9";
this.client.maxFeeXRP = "1.9";
const secret = "shsWGZcmZz6YsWWmcnpfr6fLTdtFV";
const request = {
txJSON: `{"Flags":2147483648,"TransactionType":"AccountSet","Account":"${test.address}","Domain":"6578616D706C652E636F6D","LastLedgerSequence":8820051,"Fee":"2010000","Sequence":23,"SigningPubKey":"02F89EAEC7667B30F33D0687BBA86C3FE2A08CCA40A9186C5BDE2DAA6FA97A37D8"}`,