mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-20 12:15:51 +00:00
build: Initial linting setup (#1560)
* sets up linting config and runs `yarn lint --fix` once, so that all changes will show up correctly in future PRs. * Note that there are still a lot of linter errors.
This commit is contained in:
committed by
Mayukha Vadari
parent
12cfed5c17
commit
8b95ee5fab
@@ -1,9 +1,10 @@
|
||||
import assert from 'assert-diff'
|
||||
import responses from '../fixtures/responses'
|
||||
import requests from '../fixtures/requests'
|
||||
import rippled from '../fixtures/rippled'
|
||||
import {TestSuite, assertResultMatch, assertRejects} from '../testUtils'
|
||||
import { BookOffersRequest } from '../../src'
|
||||
import assert from "assert-diff";
|
||||
|
||||
import { BookOffersRequest } from "../../src";
|
||||
import requests from "../fixtures/requests";
|
||||
import responses from "../fixtures/responses";
|
||||
import rippled from "../fixtures/rippled";
|
||||
import { TestSuite, assertResultMatch, assertRejects } from "../testUtils";
|
||||
// import BigNumber from 'bignumber.js'
|
||||
|
||||
// function checkSortingOfOrders(orders) {
|
||||
@@ -41,11 +42,17 @@ import { BookOffersRequest } from '../../src'
|
||||
// }
|
||||
|
||||
function isUSD(currency: string) {
|
||||
return currency === 'USD' || currency === '0000000000000000000000005553440000000000'
|
||||
return (
|
||||
currency === "USD" ||
|
||||
currency === "0000000000000000000000005553440000000000"
|
||||
);
|
||||
}
|
||||
|
||||
function isBTC(currency: string) {
|
||||
return currency === 'BTC' || currency === '0000000000000000000000004254430000000000'
|
||||
return (
|
||||
currency === "BTC" ||
|
||||
currency === "0000000000000000000000004254430000000000"
|
||||
);
|
||||
}
|
||||
|
||||
function normalRippledResponse(request: BookOffersRequest): object {
|
||||
@@ -53,23 +60,27 @@ function normalRippledResponse(request: BookOffersRequest): object {
|
||||
isBTC(request.taker_gets.currency) &&
|
||||
isUSD(request.taker_pays.currency)
|
||||
) {
|
||||
return rippled.book_offers.fabric.requestBookOffersBidsResponse(request)
|
||||
} else if (
|
||||
return rippled.book_offers.fabric.requestBookOffersBidsResponse(request);
|
||||
}
|
||||
if (
|
||||
isUSD(request.taker_gets.currency) &&
|
||||
isBTC(request.taker_pays.currency)
|
||||
) {
|
||||
return rippled.book_offers.fabric.requestBookOffersAsksResponse(request)
|
||||
return rippled.book_offers.fabric.requestBookOffersAsksResponse(request);
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
function xrpRippledResponse(request: BookOffersRequest): object {
|
||||
if (request.taker_pays.issuer === 'rp8rJYTpodf8qbSCHVTNacf8nSW8mRakFw') {
|
||||
return rippled.book_offers.xrp_usd
|
||||
} else if (
|
||||
request.taker_gets.issuer === 'rp8rJYTpodf8qbSCHVTNacf8nSW8mRakFw'
|
||||
) {
|
||||
return rippled.book_offers.usd_xrp
|
||||
if (request.taker_pays.issuer === "rp8rJYTpodf8qbSCHVTNacf8nSW8mRakFw") {
|
||||
return rippled.book_offers.xrp_usd;
|
||||
}
|
||||
if (request.taker_gets.issuer === "rp8rJYTpodf8qbSCHVTNacf8nSW8mRakFw") {
|
||||
return rippled.book_offers.usd_xrp;
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -78,34 +89,34 @@ function xrpRippledResponse(request: BookOffersRequest): object {
|
||||
* - Check out "test/client/index.ts" for more information about the test runner.
|
||||
*/
|
||||
export default <TestSuite>{
|
||||
'normal': async (client, address, mockRippled) => {
|
||||
mockRippled.addResponse({command: 'book_offers'}, normalRippledResponse)
|
||||
async normal(client, address, mockRippled) {
|
||||
mockRippled.addResponse({ command: "book_offers" }, normalRippledResponse);
|
||||
const response = await client.getOrderbook(
|
||||
address,
|
||||
requests.getOrderbook.normal,
|
||||
{limit: 20}
|
||||
)
|
||||
assertResultMatch(response, responses.getOrderbook.normal, 'getOrderbook')
|
||||
{ limit: 20 }
|
||||
);
|
||||
assertResultMatch(response, responses.getOrderbook.normal, "getOrderbook");
|
||||
},
|
||||
|
||||
'invalid options': async (client, address, mockRippled) => {
|
||||
mockRippled.addResponse({command: 'book_offers'}, normalRippledResponse)
|
||||
"invalid options": async (client, address, mockRippled) => {
|
||||
mockRippled.addResponse({ command: "book_offers" }, normalRippledResponse);
|
||||
assertRejects(
|
||||
client.getOrderbook(address, requests.getOrderbook.normal, {
|
||||
// @ts-ignore
|
||||
invalid: 'options'
|
||||
// @ts-expect-error
|
||||
invalid: "options",
|
||||
}),
|
||||
client.errors.ValidationError
|
||||
)
|
||||
);
|
||||
},
|
||||
|
||||
'with XRP': async (client, address, mockRippled) => {
|
||||
mockRippled.addResponse({command: 'book_offers'}, xrpRippledResponse)
|
||||
"with XRP": async (client, address, mockRippled) => {
|
||||
mockRippled.addResponse({ command: "book_offers" }, xrpRippledResponse);
|
||||
const response = await client.getOrderbook(
|
||||
address,
|
||||
requests.getOrderbook.withXRP
|
||||
)
|
||||
assertResultMatch(response, responses.getOrderbook.withXRP, 'getOrderbook')
|
||||
);
|
||||
assertResultMatch(response, responses.getOrderbook.withXRP, "getOrderbook");
|
||||
},
|
||||
|
||||
// 'sample XRP/JPY book has orders sorted correctly': async (client, address, mockRippled) => {
|
||||
@@ -140,55 +151,69 @@ export default <TestSuite>{
|
||||
// },
|
||||
|
||||
// WARNING: This test fails to catch the sorting bug, issue #766
|
||||
'sorted so that best deals come first [bad test]': async (client, address, mockRippled) => {
|
||||
mockRippled.addResponse({command: 'book_offers'}, normalRippledResponse)
|
||||
"sorted so that best deals come first [bad test]": async (
|
||||
client,
|
||||
address,
|
||||
mockRippled
|
||||
) => {
|
||||
mockRippled.addResponse({ command: "book_offers" }, normalRippledResponse);
|
||||
const response = await client.getOrderbook(
|
||||
address,
|
||||
requests.getOrderbook.normal
|
||||
)
|
||||
);
|
||||
const bidRates = response.bids.map(
|
||||
(bid) => bid.properties.makerExchangeRate
|
||||
)
|
||||
);
|
||||
const askRates = response.asks.map(
|
||||
(ask) => ask.properties.makerExchangeRate
|
||||
)
|
||||
);
|
||||
// makerExchangeRate = quality = takerPays.value/takerGets.value
|
||||
// so the best deal for the taker is the lowest makerExchangeRate
|
||||
// bids and asks should be sorted so that the best deals come first
|
||||
assert.deepEqual(
|
||||
bidRates.sort((x) => Number(x)),
|
||||
bidRates
|
||||
)
|
||||
);
|
||||
assert.deepEqual(
|
||||
askRates.sort((x) => Number(x)),
|
||||
askRates
|
||||
)
|
||||
);
|
||||
},
|
||||
|
||||
'currency & counterparty are correct': async (client, address, mockRippled) => {
|
||||
mockRippled.addResponse({command: 'book_offers'}, normalRippledResponse)
|
||||
"currency & counterparty are correct": async (
|
||||
client,
|
||||
address,
|
||||
mockRippled
|
||||
) => {
|
||||
mockRippled.addResponse({ command: "book_offers" }, normalRippledResponse);
|
||||
const response = await client.getOrderbook(
|
||||
address,
|
||||
requests.getOrderbook.normal
|
||||
)
|
||||
;[...response.bids, ...response.asks].forEach((order) => {
|
||||
const quantity = order.specification.quantity
|
||||
const totalPrice = order.specification.totalPrice
|
||||
const {base, counter} = requests.getOrderbook.normal
|
||||
assert.strictEqual(quantity.currency, base.currency)
|
||||
assert.strictEqual(quantity.counterparty, base.counterparty)
|
||||
assert.strictEqual(totalPrice.currency, counter.currency)
|
||||
assert.strictEqual(totalPrice.counterparty, counter.counterparty)
|
||||
})
|
||||
);
|
||||
[...response.bids, ...response.asks].forEach((order) => {
|
||||
const quantity = order.specification.quantity;
|
||||
const totalPrice = order.specification.totalPrice;
|
||||
const { base, counter } = requests.getOrderbook.normal;
|
||||
assert.strictEqual(quantity.currency, base.currency);
|
||||
assert.strictEqual(quantity.counterparty, base.counterparty);
|
||||
assert.strictEqual(totalPrice.currency, counter.currency);
|
||||
assert.strictEqual(totalPrice.counterparty, counter.counterparty);
|
||||
});
|
||||
},
|
||||
|
||||
'direction is correct for bids and asks': async (client, address, mockRippled) => {
|
||||
mockRippled.addResponse({command: 'book_offers'}, normalRippledResponse)
|
||||
"direction is correct for bids and asks": async (
|
||||
client,
|
||||
address,
|
||||
mockRippled
|
||||
) => {
|
||||
mockRippled.addResponse({ command: "book_offers" }, normalRippledResponse);
|
||||
const response = await client.getOrderbook(
|
||||
address,
|
||||
requests.getOrderbook.normal
|
||||
)
|
||||
assert(response.bids.every((bid) => bid.specification.direction === 'buy'))
|
||||
assert(response.asks.every((ask) => ask.specification.direction === 'sell'))
|
||||
}
|
||||
}
|
||||
);
|
||||
assert(response.bids.every((bid) => bid.specification.direction === "buy"));
|
||||
assert(
|
||||
response.asks.every((ask) => ask.specification.direction === "sell")
|
||||
);
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user