mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-19 19:55:51 +00:00
Reduce dependencies on lodash (#1467)
* assign -> Object.assign * replace isundefined * remove forEach * remove some * remove reduce * remove keys * remove map * remove includes * remove filter * remove last * remove isstring * remove every * remove rearg * remove indexOf * remove values * remove startswith * remove first and pick * build smaller lodash * remove lodash.isequal package * add lodash-cli dev dependency * add lodash script * test fix * Revert "build smaller lodash" This reverts commit 979446e57f60b29cb5d377b54efe91cfbeae0707. * upgrade npm * change ===/!== undefined to ==/!= null
This commit is contained in:
@@ -203,7 +203,7 @@ export default <TestSuite>{
|
||||
}
|
||||
const decoded = binary.decode(result.signedTransaction)
|
||||
assert(
|
||||
decoded.Flags === undefined,
|
||||
decoded.Flags == null,
|
||||
`Flags = ${decoded.Flags}, should be undefined`
|
||||
)
|
||||
assert.deepEqual(result, expectedResult)
|
||||
|
||||
@@ -28,7 +28,7 @@ describe('RippleAPIBroadcast', function () {
|
||||
|
||||
it('base', function () {
|
||||
const expected = {request_server_info: 1}
|
||||
this.mocks.forEach((mock) => mock.expect(_.assign({}, expected)))
|
||||
this.mocks.forEach((mock) => mock.expect(Object.assign({}, expected)))
|
||||
assert(this.api.isConnected())
|
||||
return this.api
|
||||
.getServerInfo()
|
||||
@@ -40,7 +40,7 @@ describe('RippleAPIBroadcast', function () {
|
||||
this.api.on('ledger', () => {
|
||||
gotLedger++
|
||||
})
|
||||
const ledgerNext = _.assign({}, ledgerClosed)
|
||||
const ledgerNext = Object.assign({}, ledgerClosed)
|
||||
ledgerNext.ledger_index++
|
||||
|
||||
this.api._apis.forEach((api) =>
|
||||
|
||||
@@ -31,8 +31,8 @@ describe('Connection', function () {
|
||||
it('default options', function () {
|
||||
const connection: any = new utils.common.Connection('url')
|
||||
assert.strictEqual(connection._url, 'url')
|
||||
assert(_.isUndefined(connection._config.proxy))
|
||||
assert(_.isUndefined(connection._config.authorization))
|
||||
assert(connection._config.proxy == null)
|
||||
assert(connection._config.authorization == null)
|
||||
})
|
||||
|
||||
describe('trace', () => {
|
||||
|
||||
4
test/fixtures/rippled/account-lines.js
vendored
4
test/fixtures/rippled/account-lines.js
vendored
@@ -44,7 +44,7 @@ module.exports.normal = function(request, options = {}) {
|
||||
marker: options.marker,
|
||||
limit: request.limit,
|
||||
ledger_index: options.ledger,
|
||||
lines: _.filter([{
|
||||
lines: [{
|
||||
account: 'r3vi7mWxru9rJCxETCyA1CHvzL96eZWx5z',
|
||||
balance: '0',
|
||||
currency: 'ASP',
|
||||
@@ -279,7 +279,7 @@ module.exports.normal = function(request, options = {}) {
|
||||
quality_out: 0,
|
||||
freeze: true
|
||||
}
|
||||
], item => !request.peer || item.account === request.peer)
|
||||
].filter(item => !request.peer || item.account === request.peer)
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
4
test/fixtures/rippled/account-tx.js
vendored
4
test/fixtures/rippled/account-tx.js
vendored
@@ -217,7 +217,7 @@ module.exports = function(request, options = {}) {
|
||||
tx.Destination = addresses.ACCOUNT;
|
||||
}
|
||||
if (request.limit === 13) {
|
||||
const res = _.assign({}, NotFound, {id: request.id});
|
||||
const res = Object.assign({}, NotFound, {id: request.id});
|
||||
return JSON.stringify(res);
|
||||
}
|
||||
return JSON.stringify({
|
||||
@@ -225,7 +225,7 @@ module.exports = function(request, options = {}) {
|
||||
status: 'success',
|
||||
type: 'response',
|
||||
result: {
|
||||
marker: marker === undefined ? undefined : String(marker),
|
||||
marker: marker == null ? undefined : String(marker),
|
||||
transactions: [
|
||||
{
|
||||
ledger_index: 348860 - Number(marker || 100),
|
||||
|
||||
@@ -29,7 +29,7 @@ function verifyTransaction(testcase, hash, type, options, txData, address) {
|
||||
assert.strictEqual(data.type, type)
|
||||
assert.strictEqual(data.address, address)
|
||||
assert.strictEqual(data.outcome.result, 'tesSUCCESS')
|
||||
if (testcase.transactions !== undefined) {
|
||||
if (testcase.transactions != null) {
|
||||
testcase.transactions.push(hash)
|
||||
}
|
||||
return {txJSON: JSON.stringify(txData), id: hash, tx: data}
|
||||
@@ -320,11 +320,11 @@ describe('integration tests', function () {
|
||||
const txData = JSON.parse(result.txJSON)
|
||||
return this.api.getOrders(address).then((orders) => {
|
||||
assert(orders && orders.length > 0)
|
||||
const createdOrder = _.first(
|
||||
_.filter(orders, (order) => {
|
||||
const createdOrder = (
|
||||
orders.filter((order) => {
|
||||
return order.properties.sequence === txData.Sequence
|
||||
})
|
||||
)
|
||||
)[0]
|
||||
assert(createdOrder)
|
||||
assert.strictEqual(createdOrder.properties.maker, address)
|
||||
assert.deepEqual(createdOrder.specification, orderSpecification)
|
||||
@@ -390,7 +390,8 @@ describe('integration tests', function () {
|
||||
|
||||
it('getTrustlines', function () {
|
||||
const fixture = requests.prepareTrustline.simple
|
||||
const options = _.pick(fixture, ['currency', 'counterparty'])
|
||||
const { currency, counterparty } = fixture
|
||||
const options = { currency, counterparty }
|
||||
return this.api.getTrustlines(address, options).then((data) => {
|
||||
assert(data && data.length > 0 && data[0] && data[0].specification)
|
||||
const specification = data[0].specification
|
||||
@@ -402,7 +403,8 @@ describe('integration tests', function () {
|
||||
|
||||
it('getBalances', function () {
|
||||
const fixture = requests.prepareTrustline.simple
|
||||
const options = _.pick(fixture, ['currency', 'counterparty'])
|
||||
const { currency, counterparty } = fixture
|
||||
const options = { currency, counterparty }
|
||||
return this.api.getBalances(address, options).then((data) => {
|
||||
assert(data && data.length > 0 && data[0])
|
||||
assert.strictEqual(data[0].currency, fixture.currency)
|
||||
@@ -488,7 +490,7 @@ describe('integration tests', function () {
|
||||
return this.api.getPaths(pathfind).then((data) => {
|
||||
assert(data && data.length > 0)
|
||||
assert(
|
||||
_.every(data, (path) => {
|
||||
data.every((path) => {
|
||||
return (
|
||||
parseFloat(path.source.amount.value) <=
|
||||
parseFloat(pathfind.source.amount.value)
|
||||
@@ -551,7 +553,7 @@ describe('integration tests - standalone rippled', function () {
|
||||
})
|
||||
})
|
||||
.then(() => {
|
||||
const multisignInstructions = _.assign({}, instructions, {
|
||||
const multisignInstructions = Object.assign({}, instructions, {
|
||||
signersCount: 2
|
||||
})
|
||||
return this.api
|
||||
|
||||
@@ -26,7 +26,7 @@ function pay(api, from, to, amount, secret, currency = 'XRP', counterparty) {
|
||||
}
|
||||
};
|
||||
|
||||
if (counterparty !== undefined) {
|
||||
if (counterparty != null) {
|
||||
paymentSpecification.source.maxAmount.counterparty = counterparty;
|
||||
paymentSpecification.destination.amount.counterparty = counterparty;
|
||||
}
|
||||
|
||||
@@ -21,12 +21,12 @@ function isBTC(json) {
|
||||
}
|
||||
|
||||
function createResponse(request, response, overrides = {}) {
|
||||
const result = _.assign({}, response.result, overrides)
|
||||
const result = Object.assign({}, response.result, overrides)
|
||||
const change =
|
||||
response.result && !_.isEmpty(overrides)
|
||||
? {id: request.id, result: result}
|
||||
: {id: request.id}
|
||||
return JSON.stringify(_.assign({}, response, change))
|
||||
return JSON.stringify(Object.assign({}, response, change))
|
||||
}
|
||||
|
||||
function createLedgerResponse(request, response) {
|
||||
@@ -39,10 +39,10 @@ function createLedgerResponse(request, response) {
|
||||
delete newResponse.result.ledger.accountState
|
||||
}
|
||||
// the following fields were not in the ledger response in the past
|
||||
if (newResponse.result.ledger.close_flags === undefined) {
|
||||
if (newResponse.result.ledger.close_flags == null) {
|
||||
newResponse.result.ledger.close_flags = 0
|
||||
}
|
||||
if (newResponse.result.ledger.parent_close_time === undefined) {
|
||||
if (newResponse.result.ledger.parent_close_time == null) {
|
||||
newResponse.result.ledger.parent_close_time =
|
||||
newResponse.result.ledger.close_time - 10
|
||||
}
|
||||
@@ -56,13 +56,13 @@ type MockedWebSocketServer = any
|
||||
|
||||
export function createMockRippled(port) {
|
||||
const mock = new WebSocketServer({port: port}) as MockedWebSocketServer
|
||||
_.assign(mock, EventEmitter2.prototype)
|
||||
Object.assign(mock, EventEmitter2.prototype)
|
||||
|
||||
const close = mock.close
|
||||
mock.close = function () {
|
||||
if (mock.expectedRequests !== undefined) {
|
||||
const allRequestsMade = _.every(mock.expectedRequests, function (
|
||||
counter
|
||||
if (mock.expectedRequests != null) {
|
||||
const allRequestsMade = Object.entries(mock.expectedRequests).every(function (
|
||||
_, counter
|
||||
) {
|
||||
return counter === 0
|
||||
})
|
||||
@@ -108,11 +108,11 @@ export function createMockRippled(port) {
|
||||
if (mock.listeners(this.event).length === 0) {
|
||||
throw new Error('No event handler registered for ' + this.event)
|
||||
}
|
||||
if (mock.expectedRequests === undefined) {
|
||||
if (mock.expectedRequests == null) {
|
||||
return // TODO: fail here to require expectedRequests
|
||||
}
|
||||
const expectedCount = mock.expectedRequests[this.event]
|
||||
if (expectedCount === undefined || expectedCount === 0) {
|
||||
if (expectedCount == null || expectedCount === 0) {
|
||||
throw new Error('Unexpected request: ' + this.event)
|
||||
}
|
||||
mock.expectedRequests[this.event] -= 1
|
||||
@@ -120,7 +120,7 @@ export function createMockRippled(port) {
|
||||
|
||||
mock.on('request_config', function (request, conn) {
|
||||
assert.strictEqual(request.command, 'config')
|
||||
conn.config = _.assign(conn.config, request.data)
|
||||
conn.config = Object.assign(conn.config, request.data)
|
||||
conn.send(
|
||||
createResponse(request, {
|
||||
status: 'success',
|
||||
@@ -174,7 +174,7 @@ export function createMockRippled(port) {
|
||||
|
||||
mock.on('request_global_config', function (request, conn) {
|
||||
assert.strictEqual(request.command, 'global_config')
|
||||
mock.config = _.assign(conn.config, request.data)
|
||||
mock.config = Object.assign(conn.config, request.data)
|
||||
conn.send(
|
||||
createResponse(request, {
|
||||
status: 'success',
|
||||
@@ -248,7 +248,7 @@ export function createMockRippled(port) {
|
||||
mock.config.returnEmptySubscribeRequest--
|
||||
conn.send(createResponse(request, fixtures.empty))
|
||||
} else if (request.accounts) {
|
||||
assert(_.indexOf(_.values(addresses), request.accounts[0]) !== -1)
|
||||
assert(Object.values(addresses).indexOf(request.accounts[0]) !== -1)
|
||||
}
|
||||
conn.send(createResponse(request, fixtures.subscribe))
|
||||
})
|
||||
@@ -256,7 +256,7 @@ export function createMockRippled(port) {
|
||||
mock.on('request_unsubscribe', function (request, conn) {
|
||||
assert.strictEqual(request.command, 'unsubscribe')
|
||||
if (request.accounts) {
|
||||
assert(_.indexOf(_.values(addresses), request.accounts[0]) !== -1)
|
||||
assert(Object.values(addresses).indexOf(request.accounts[0]) !== -1)
|
||||
} else {
|
||||
assert.deepEqual(request.streams, ['ledger', 'server'])
|
||||
}
|
||||
@@ -282,7 +282,7 @@ export function createMockRippled(port) {
|
||||
const response = Object.assign({}, fixtures.account_info.normal)
|
||||
response.Account = addresses.THIRD_ACCOUNT
|
||||
conn.send(createResponse(request, response))
|
||||
} else if (request.account === undefined) {
|
||||
} else if (request.account == null) {
|
||||
const response = Object.assign(
|
||||
{},
|
||||
{
|
||||
@@ -346,7 +346,7 @@ export function createMockRippled(port) {
|
||||
createLedgerResponse(request, fixtures.ledger.pre2014withPartial)
|
||||
)
|
||||
} else if (request.ledger_index === 38129) {
|
||||
const response = _.assign({}, fixtures.ledger.normal, {
|
||||
const response = Object.assign({}, fixtures.ledger.normal, {
|
||||
result: {ledger: fullLedger}
|
||||
})
|
||||
conn.send(createLedgerResponse(request, response))
|
||||
|
||||
@@ -172,7 +172,7 @@ describe('RippleAPI', function () {
|
||||
it('ledger utils - getRecursive', async () => {
|
||||
function getter(marker) {
|
||||
return new Promise<RecursiveData>((resolve, reject) => {
|
||||
if (marker !== undefined) {
|
||||
if (marker != null) {
|
||||
reject(new Error())
|
||||
return
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ function teardown(this: any, done) {
|
||||
this.api
|
||||
.disconnect()
|
||||
.then(() => {
|
||||
if (this.mockRippled !== undefined) {
|
||||
if (this.mockRippled != null) {
|
||||
this.mockRippled.close()
|
||||
} else {
|
||||
this.mocks.forEach((mock) => mock.close())
|
||||
|
||||
Reference in New Issue
Block a user