Lints src/common (#1595)

* lint errors (and remove unused error types)

* lint fee

* lint index

* lint ecdsa

* fix tests

* remove address tests from getFee

* fix more tests

* fix tests

* respond to comments
This commit is contained in:
Mayukha Vadari
2021-09-03 18:32:52 -05:00
parent e200de3073
commit a996fafe79
13 changed files with 137 additions and 152 deletions

View File

@@ -6,9 +6,9 @@ describe('client errors', function () {
beforeEach(setupClient.setup)
afterEach(setupClient.teardown)
it('RippleError with data', async function () {
const error = new this.client.errors.RippleError('_message_', '_data_')
assert.strictEqual(error.toString(), "[RippleError(_message_, '_data_')]")
it('XrplError with data', async function () {
const error = new this.client.errors.XrplError('_message_', '_data_')
assert.strictEqual(error.toString(), "[XrplError(_message_, '_data_')]")
})
it('NotFoundError default message', async function () {

View File

@@ -2,69 +2,57 @@ import { assert } from 'chai'
import rippled from '../fixtures/rippled'
import setupClient from '../setupClient'
import { addressTests } from '../testUtils'
describe('client.getFee', function () {
beforeEach(setupClient.setup)
afterEach(setupClient.teardown)
addressTests.forEach(function (test) {
describe(test.type, function () {
it('getFee', async function () {
this.mockRippled.addResponse('server_info', rippled.server_info.normal)
const fee = await this.client.getFee()
assert.strictEqual(fee, '0.000012')
})
it('getFee', async function () {
this.mockRippled.addResponse('server_info', rippled.server_info.normal)
const fee = await this.client.getFee()
assert.strictEqual(fee, '0.000012')
})
it('getFee default', async function () {
this.mockRippled.addResponse('server_info', rippled.server_info.normal)
this.client.feeCushion = undefined as unknown as number
const fee = await this.client.getFee()
assert.strictEqual(fee, '0.000012')
})
it('getFee - high load_factor', async function () {
this.mockRippled.addResponse(
'server_info',
rippled.server_info.highLoadFactor,
)
const fee = await this.client.getFee()
assert.strictEqual(fee, '2')
})
it('getFee - high load_factor', async function () {
this.mockRippled.addResponse(
'server_info',
rippled.server_info.highLoadFactor,
)
const fee = await this.client.getFee()
assert.strictEqual(fee, '2')
})
it('getFee - high load_factor with custom maxFeeXRP', async function () {
this.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)
this.client.maxFeeXRP = '51540'
const fee = await this.client.getFee()
assert.strictEqual(fee, '51539.607552')
})
it('getFee - high load_factor with custom maxFeeXRP', async function () {
this.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)
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
const fee = await this.client.getFee()
assert.strictEqual(fee, '0.000014')
})
it('getFee custom cushion', async function () {
this.mockRippled.addResponse('server_info', rippled.server_info.normal)
this.client.feeCushion = 1.4
const fee = await this.client.getFee()
assert.strictEqual(fee, '0.000014')
})
// This is not recommended since it may result in attempting to pay
// 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
const fee = await this.client.getFee()
assert.strictEqual(fee, '0.000009')
})
// This is not recommended since it may result in attempting to pay
// 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
const fee = await this.client.getFee()
assert.strictEqual(fee, '0.000009')
})
it('getFee reporting', async function () {
this.mockRippled.addResponse('server_info', rippled.server_info.normal)
const fee = await this.client.getFee()
assert.strictEqual(fee, '0.000012')
})
})
it('getFee reporting', async function () {
this.mockRippled.addResponse('server_info', rippled.server_info.normal)
const fee = await this.client.getFee()
assert.strictEqual(fee, '0.000012')
})
})

View File

@@ -97,7 +97,7 @@ describe('client.getPaths', function () {
...REQUEST_FIXTURES.normal,
source: { address: addresses.NOTFOUND },
}),
this.client.errors.RippleError,
this.client.errors.XrplError,
)
})
// 'send all', function () {

View File

@@ -11,7 +11,7 @@ import {
DisconnectedError,
NotConnectedError,
ResponseFormatError,
RippleError,
XrplError,
TimeoutError,
} from '../src/common/errors'
@@ -207,11 +207,11 @@ describe('Connection', function () {
})
it('DisconnectedError on initial onOpen send', async function () {
// _onOpen previously could throw PromiseRejectionHandledWarning: Promise rejection was handled asynchronously
// onOpen previously could throw PromiseRejectionHandledWarning: Promise rejection was handled asynchronously
// do not rely on the client.setup hook to test this as it bypasses the case, disconnect client connection first
await this.client.disconnect()
// stub _onOpen to only run logic relevant to test case
// 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 (_0, _1, _2) {
@@ -420,7 +420,7 @@ describe('Connection', function () {
new Client({
servers: ['wss://server1.com', 'wss://server2.com'],
} as any)
}, RippleError)
}, XrplError)
})
it('connect throws error', function (done) {

View File

@@ -4,7 +4,6 @@ import _ from 'lodash'
import { isValidXAddress } from 'ripple-address-codec'
import { Client } from 'xrpl-local'
import { errors } from 'xrpl-local/common'
import { isValidSecret } from 'xrpl-local/utils'
import { generateXAddress } from '../../src/utils/generateAddress'
@@ -46,24 +45,7 @@ function verifyTransaction(testcase, hash, type, options, txData, account) {
}
return { txJSON: JSON.stringify(txData), id: hash, tx: data }
})
.catch(async (error) => {
if (error instanceof errors.PendingLedgerVersionError) {
console.log('NOT VALIDATED YET...')
return new Promise((resolve, reject) => {
setTimeout(
() =>
verifyTransaction(
testcase,
hash,
type,
options,
txData,
account,
).then(resolve, reject),
INTERVAL,
)
})
}
.catch((error) => {
console.log(error.stack)
assert(false, `Transaction not successful: ${error.message}`)
})