mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-30 09:05:50 +00:00
committed by
Mayukha Vadari
parent
3cbdbac4f9
commit
10445cff01
@@ -40,21 +40,23 @@ import { addressTests } from '../testUtils'
|
||||
// return true;
|
||||
// }
|
||||
|
||||
function isUSD(currency: string) {
|
||||
function isUSD(currency: string): boolean {
|
||||
return (
|
||||
currency === 'USD' ||
|
||||
currency === '0000000000000000000000005553440000000000'
|
||||
)
|
||||
}
|
||||
|
||||
function isBTC(currency: string) {
|
||||
function isBTC(currency: string): boolean {
|
||||
return (
|
||||
currency === 'BTC' ||
|
||||
currency === '0000000000000000000000004254430000000000'
|
||||
)
|
||||
}
|
||||
|
||||
function normalRippledResponse(request: BookOffersRequest): object {
|
||||
function normalRippledResponse(
|
||||
request: BookOffersRequest,
|
||||
): Record<string, unknown> {
|
||||
if (
|
||||
isBTC(request.taker_gets.currency) &&
|
||||
isUSD(request.taker_pays.currency)
|
||||
@@ -70,57 +72,59 @@ function normalRippledResponse(request: BookOffersRequest): object {
|
||||
throw new Error('unexpected end')
|
||||
}
|
||||
|
||||
// function xrpRippledResponse(request: BookOffersRequest): object {
|
||||
// if (request.taker_pays.issuer === "rp8rJYTpodf8qbSCHVTNacf8nSW8mRakFw") {
|
||||
// return rippled.book_offers.xrp_usd;
|
||||
// function xrpRippledResponse(
|
||||
// request: BookOffersRequest,
|
||||
// ): Record<string, unknown> {
|
||||
// if (request.taker_pays.issuer === 'rp8rJYTpodf8qbSCHVTNacf8nSW8mRakFw') {
|
||||
// return rippled.book_offers.xrp_usd
|
||||
// }
|
||||
// if (request.taker_gets.issuer === "rp8rJYTpodf8qbSCHVTNacf8nSW8mRakFw") {
|
||||
// return rippled.book_offers.usd_xrp;
|
||||
// if (request.taker_gets.issuer === 'rp8rJYTpodf8qbSCHVTNacf8nSW8mRakFw') {
|
||||
// return rippled.book_offers.usd_xrp
|
||||
// }
|
||||
// throw new Error("unexpected end");
|
||||
// throw new Error('unexpected end')
|
||||
// }
|
||||
|
||||
describe('client.getOrderbook', function () {
|
||||
beforeEach(setupClient)
|
||||
afterEach(teardownClient)
|
||||
|
||||
addressTests.forEach(function (test) {
|
||||
describe(test.type, function () {
|
||||
addressTests.forEach(function (testcase) {
|
||||
describe(testcase.type, function () {
|
||||
it('normal', async function () {
|
||||
this.mockRippled.addResponse('book_offers', normalRippledResponse)
|
||||
const response = await this.client.getOrderbook(
|
||||
requests.getOrderbook.normal.taker_pays,
|
||||
requests.getOrderbook.normal.taker_gets,
|
||||
{
|
||||
limit: 1,
|
||||
},
|
||||
{ limit: 1 },
|
||||
)
|
||||
assert.deepEqual(response, responses.getOrderbook.normal)
|
||||
})
|
||||
|
||||
// it("invalid options", async function () {
|
||||
// this.mockRippled.addResponse("book_offers", normalRippledResponse);
|
||||
// it('invalid options', async function () {
|
||||
// this.mockRippled.addResponse('book_offers', normalRippledResponse)
|
||||
// assertRejects(
|
||||
// this.client.getOrderbook(test.address, requests.getOrderbook.normal, {
|
||||
// invalid: "options",
|
||||
// }),
|
||||
// this.client.errors.ValidationError
|
||||
// );
|
||||
// });
|
||||
|
||||
// it("with XRP", async function () {
|
||||
// this.mockRippled.addResponse("book_offers", xrpRippledResponse);
|
||||
// this.client.getOrderbook(
|
||||
// testcase.address,
|
||||
// requests.getOrderbook.normal,
|
||||
// {
|
||||
// invalid: 'options',
|
||||
// },
|
||||
// ),
|
||||
// this.client.errors.ValidationError,
|
||||
// )
|
||||
// })
|
||||
// it('with XRP', async function () {
|
||||
// this.mockRippled.addResponse('book_offers', xrpRippledResponse)
|
||||
// const response = await this.client.getOrderbook(
|
||||
// test.address,
|
||||
// requests.getOrderbook.withXRP
|
||||
// );
|
||||
// testcase.address,
|
||||
// requests.getOrderbook.withXRP,
|
||||
// )
|
||||
// assertResultMatch(
|
||||
// response,
|
||||
// responses.getOrderbook.withXRP,
|
||||
// "getOrderbook"
|
||||
// );
|
||||
// });
|
||||
|
||||
// 'getOrderbook',
|
||||
// )
|
||||
// })
|
||||
// 'sample XRP/JPY book has orders sorted correctly', async function () {
|
||||
// const orderbookInfo = {
|
||||
// base: {
|
||||
@@ -137,7 +141,6 @@ describe('client.getOrderbook', function () {
|
||||
// assert.deepStrictEqual([], response.bids)
|
||||
// checkSortingOfOrders(response.asks)
|
||||
// },
|
||||
|
||||
// 'sample USD/XRP book has orders sorted correctly', async function () {
|
||||
// const orderbookInfo = {
|
||||
// counter: {currency: 'XRP'},
|
||||
@@ -151,7 +154,6 @@ describe('client.getOrderbook', function () {
|
||||
// checkSortingOfOrders(response.bids)
|
||||
// checkSortingOfOrders(response.asks)
|
||||
// },
|
||||
|
||||
// WARNING: This test fails to catch the sorting bug, issue #766
|
||||
// it("sorted so that best deals come first [bad test]", async function () {
|
||||
// this.mockRippled.addResponse("book_offers", normalRippledResponse);
|
||||
@@ -177,7 +179,6 @@ describe('client.getOrderbook', function () {
|
||||
// askRates
|
||||
// );
|
||||
// });
|
||||
|
||||
// it("currency & counterparty are correct", async function () {
|
||||
// this.mockRippled.addResponse("book_offers", normalRippledResponse);
|
||||
// const response = await this.client.getOrderbook(
|
||||
@@ -194,7 +195,6 @@ describe('client.getOrderbook', function () {
|
||||
// assert.strictEqual(totalPrice.counterparty, counter.counterparty);
|
||||
// });
|
||||
// });
|
||||
|
||||
// it("direction is correct for bids and asks", async function () {
|
||||
// this.mockRippled.addResponse("book_offers", normalRippledResponse);
|
||||
// const response = await this.client.getOrderbook(
|
||||
|
||||
Reference in New Issue
Block a user