fixed tests
This commit is contained in:
parent
ceb90989d0
commit
7cd30610f9
@ -10,7 +10,7 @@ import { Agent as HttpsAgent } from 'https';
|
||||
import { constants } from '../constants';
|
||||
import { MarketOperation, RfqtMakerAssetOfferings, RfqtRequestOpts } from '../types';
|
||||
|
||||
const httpClient: AxiosInstance = Axios.create({
|
||||
export const quoteRequestorHttpClient: AxiosInstance = Axios.create({
|
||||
httpAgent: new HttpAgent({ keepAlive: true }),
|
||||
httpsAgent: new HttpsAgent({ keepAlive: true }),
|
||||
});
|
||||
@ -337,7 +337,7 @@ export class QuoteRequestor {
|
||||
throw new Error(`Unexpected quote type ${quoteType}`);
|
||||
}
|
||||
})();
|
||||
const response = await httpClient.get<ResponseT>(`${url}/${quotePath}`, {
|
||||
const response = await quoteRequestorHttpClient.get<ResponseT>(`${url}/${quotePath}`, {
|
||||
headers: { '0x-api-key': options.apiKey },
|
||||
params: requestParams,
|
||||
timeout: options.makerEndpointMaxResponseTimeMs,
|
||||
|
@ -1,4 +1,4 @@
|
||||
import axios from 'axios';
|
||||
import axios, { AxiosInstance } from 'axios';
|
||||
import AxiosMockAdapter from 'axios-mock-adapter';
|
||||
|
||||
import { MockedRfqtFirmQuoteResponse } from '../types';
|
||||
@ -16,8 +16,9 @@ export const rfqtMocker = {
|
||||
withMockedRfqtFirmQuotes: async (
|
||||
mockedResponses: MockedRfqtFirmQuoteResponse[],
|
||||
performFn: () => Promise<void>,
|
||||
axiosClient: AxiosInstance = axios,
|
||||
) => {
|
||||
const mockedAxios = new AxiosMockAdapter(axios);
|
||||
const mockedAxios = new AxiosMockAdapter(axiosClient);
|
||||
try {
|
||||
// Mock out RFQT responses
|
||||
for (const mockedResponse of mockedResponses) {
|
||||
@ -37,8 +38,9 @@ export const rfqtMocker = {
|
||||
withMockedRfqtIndicativeQuotes: async (
|
||||
mockedResponses: MockedRfqtFirmQuoteResponse[],
|
||||
performFn: () => Promise<void>,
|
||||
axiosClient: AxiosInstance = axios,
|
||||
) => {
|
||||
const mockedAxios = new AxiosMockAdapter(axios);
|
||||
const mockedAxios = new AxiosMockAdapter(axiosClient);
|
||||
try {
|
||||
// Mock out RFQT responses
|
||||
for (const mockedResponse of mockedResponses) {
|
||||
|
@ -7,7 +7,7 @@ import 'mocha';
|
||||
|
||||
import { constants } from '../src/constants';
|
||||
import { MarketOperation, MockedRfqtFirmQuoteResponse, MockedRfqtIndicativeQuoteResponse } from '../src/types';
|
||||
import { QuoteRequestor } from '../src/utils/quote_requestor';
|
||||
import { QuoteRequestor, quoteRequestorHttpClient } from '../src/utils/quote_requestor';
|
||||
import { rfqtMocker } from '../src/utils/rfqt_mocker';
|
||||
|
||||
import { chaiSetup } from './utils/chai_setup';
|
||||
@ -22,7 +22,7 @@ function makeThreeMinuteExpiry(): BigNumber {
|
||||
return new BigNumber(Math.round(expiry.valueOf() / constants.ONE_SECOND_MS));
|
||||
}
|
||||
|
||||
describe('QuoteRequestor', async () => {
|
||||
describe.only('QuoteRequestor', async () => {
|
||||
const [makerToken, takerToken, otherToken1] = tokenUtils.getDummyERC20TokenAddresses();
|
||||
const makerAssetData = assetDataUtils.encodeERC20AssetData(makerToken);
|
||||
const takerAssetData = assetDataUtils.encodeERC20AssetData(takerToken);
|
||||
@ -153,35 +153,39 @@ describe('QuoteRequestor', async () => {
|
||||
responseCode: StatusCodes.Success,
|
||||
});
|
||||
|
||||
return rfqtMocker.withMockedRfqtFirmQuotes(mockedRequests, async () => {
|
||||
const qr = new QuoteRequestor({
|
||||
'https://1337.0.0.1': [[makerToken, takerToken]],
|
||||
'https://420.0.0.1': [[makerToken, takerToken]],
|
||||
'https://421.0.0.1': [[makerToken, takerToken]],
|
||||
'https://421.1.0.1': [[makerToken, takerToken]],
|
||||
'https://422.0.0.1': [[makerToken, takerToken]],
|
||||
'https://423.0.0.1': [[makerToken, takerToken]],
|
||||
'https://424.0.0.1': [[makerToken, takerToken]],
|
||||
'https://425.0.0.1': [[makerToken, takerToken]],
|
||||
'https://426.0.0.1': [] /* Shouldn't ping an RFQ-T
|
||||
return rfqtMocker.withMockedRfqtFirmQuotes(
|
||||
mockedRequests,
|
||||
async () => {
|
||||
const qr = new QuoteRequestor({
|
||||
'https://1337.0.0.1': [[makerToken, takerToken]],
|
||||
'https://420.0.0.1': [[makerToken, takerToken]],
|
||||
'https://421.0.0.1': [[makerToken, takerToken]],
|
||||
'https://421.1.0.1': [[makerToken, takerToken]],
|
||||
'https://422.0.0.1': [[makerToken, takerToken]],
|
||||
'https://423.0.0.1': [[makerToken, takerToken]],
|
||||
'https://424.0.0.1': [[makerToken, takerToken]],
|
||||
'https://425.0.0.1': [[makerToken, takerToken]],
|
||||
'https://426.0.0.1': [] /* Shouldn't ping an RFQ-T
|
||||
provider when they don't support the requested asset pair. */,
|
||||
'https://37.0.0.1': [[makerToken, takerToken]],
|
||||
});
|
||||
const resp = await qr.requestRfqtFirmQuotesAsync(
|
||||
makerAssetData,
|
||||
takerAssetData,
|
||||
new BigNumber(10000),
|
||||
MarketOperation.Sell,
|
||||
{
|
||||
apiKey,
|
||||
takerAddress,
|
||||
intentOnFilling: true,
|
||||
},
|
||||
);
|
||||
expect(resp.sort()).to.eql(
|
||||
[{ signedOrder: successfulOrder1 }, { signedOrder: successfulOrder2 }].sort(),
|
||||
);
|
||||
});
|
||||
'https://37.0.0.1': [[makerToken, takerToken]],
|
||||
});
|
||||
const resp = await qr.requestRfqtFirmQuotesAsync(
|
||||
makerAssetData,
|
||||
takerAssetData,
|
||||
new BigNumber(10000),
|
||||
MarketOperation.Sell,
|
||||
{
|
||||
apiKey,
|
||||
takerAddress,
|
||||
intentOnFilling: true,
|
||||
},
|
||||
);
|
||||
expect(resp.sort()).to.eql(
|
||||
[{ signedOrder: successfulOrder1 }, { signedOrder: successfulOrder2 }].sort(),
|
||||
);
|
||||
},
|
||||
quoteRequestorHttpClient,
|
||||
);
|
||||
});
|
||||
});
|
||||
describe('requestRfqtIndicativeQuotesAsync for Indicative quotes', async () => {
|
||||
@ -255,29 +259,33 @@ describe('QuoteRequestor', async () => {
|
||||
responseCode: StatusCodes.Success,
|
||||
});
|
||||
|
||||
return rfqtMocker.withMockedRfqtIndicativeQuotes(mockedRequests, async () => {
|
||||
const qr = new QuoteRequestor({
|
||||
'https://1337.0.0.1': [[makerToken, takerToken]],
|
||||
'https://420.0.0.1': [[makerToken, takerToken]],
|
||||
'https://421.0.0.1': [[makerToken, takerToken]],
|
||||
'https://422.0.0.1': [[makerToken, takerToken]],
|
||||
'https://423.0.0.1': [[makerToken, takerToken]],
|
||||
'https://424.0.0.1': [[makerToken, takerToken]],
|
||||
'https://37.0.0.1': [[makerToken, takerToken]],
|
||||
});
|
||||
const resp = await qr.requestRfqtIndicativeQuotesAsync(
|
||||
makerAssetData,
|
||||
takerAssetData,
|
||||
new BigNumber(10000),
|
||||
MarketOperation.Sell,
|
||||
{
|
||||
apiKey,
|
||||
takerAddress,
|
||||
intentOnFilling: true,
|
||||
},
|
||||
);
|
||||
expect(resp.sort()).to.eql([successfulQuote1, successfulQuote1].sort());
|
||||
});
|
||||
return rfqtMocker.withMockedRfqtIndicativeQuotes(
|
||||
mockedRequests,
|
||||
async () => {
|
||||
const qr = new QuoteRequestor({
|
||||
'https://1337.0.0.1': [[makerToken, takerToken]],
|
||||
'https://420.0.0.1': [[makerToken, takerToken]],
|
||||
'https://421.0.0.1': [[makerToken, takerToken]],
|
||||
'https://422.0.0.1': [[makerToken, takerToken]],
|
||||
'https://423.0.0.1': [[makerToken, takerToken]],
|
||||
'https://424.0.0.1': [[makerToken, takerToken]],
|
||||
'https://37.0.0.1': [[makerToken, takerToken]],
|
||||
});
|
||||
const resp = await qr.requestRfqtIndicativeQuotesAsync(
|
||||
makerAssetData,
|
||||
takerAssetData,
|
||||
new BigNumber(10000),
|
||||
MarketOperation.Sell,
|
||||
{
|
||||
apiKey,
|
||||
takerAddress,
|
||||
intentOnFilling: true,
|
||||
},
|
||||
);
|
||||
expect(resp.sort()).to.eql([successfulQuote1, successfulQuote1].sort());
|
||||
},
|
||||
quoteRequestorHttpClient,
|
||||
);
|
||||
});
|
||||
it('should return successful RFQT indicative quote requests', async () => {
|
||||
const takerAddress = '0xd209925defc99488e3afff1174e48b4fa628302a';
|
||||
@ -309,21 +317,25 @@ describe('QuoteRequestor', async () => {
|
||||
responseCode: StatusCodes.Success,
|
||||
});
|
||||
|
||||
return rfqtMocker.withMockedRfqtIndicativeQuotes(mockedRequests, async () => {
|
||||
const qr = new QuoteRequestor({ 'https://1337.0.0.1': [[makerToken, takerToken]] });
|
||||
const resp = await qr.requestRfqtIndicativeQuotesAsync(
|
||||
makerAssetData,
|
||||
takerAssetData,
|
||||
new BigNumber(10000),
|
||||
MarketOperation.Buy,
|
||||
{
|
||||
apiKey,
|
||||
takerAddress,
|
||||
intentOnFilling: true,
|
||||
},
|
||||
);
|
||||
expect(resp.sort()).to.eql([successfulQuote1].sort());
|
||||
});
|
||||
return rfqtMocker.withMockedRfqtIndicativeQuotes(
|
||||
mockedRequests,
|
||||
async () => {
|
||||
const qr = new QuoteRequestor({ 'https://1337.0.0.1': [[makerToken, takerToken]] });
|
||||
const resp = await qr.requestRfqtIndicativeQuotesAsync(
|
||||
makerAssetData,
|
||||
takerAssetData,
|
||||
new BigNumber(10000),
|
||||
MarketOperation.Buy,
|
||||
{
|
||||
apiKey,
|
||||
takerAddress,
|
||||
intentOnFilling: true,
|
||||
},
|
||||
);
|
||||
expect(resp.sort()).to.eql([successfulQuote1].sort());
|
||||
},
|
||||
quoteRequestorHttpClient,
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user