* FQT: Pack Protocol/source name into source ID (#162) * `@0x/contracts-zero-ex`: Encode protocol ID and source name in bridge source ID `@0x/asset-swapper`: Use new bridge source ID encoding. * fix linter issues * contracts cleanup (#164) * `@0x/contracts-zero-ex`: Add PancakeSwapFeature * `@0x/contracts-zero-ex`: Remove tokenspender/allowance target/greedy tokens stuff.' `@0x/contract-addresses`: Add BSC addresses. Remove exchangeProxyAllowanceTarget. `@0x/migrations`: Remove exchangeProxyAllowanceTarget. * Update contracts/zero-ex/contracts/src/features/IPancakeSwapFeature.sol Co-authored-by: mzhu25 <mchl.zhu.96@gmail.com> * `@0x/contracts-zero-ex`: Add sushiswap support to PancakeSwap * `@0x/contract-artifacts`: Regenerate artifacts `@0x/contract-wrappers`: Regenerate wrappers * `@0x/contract-addresses`: Add BSC addresses Co-authored-by: mzhu25 <mchl.zhu.96@gmail.com> Co-authored-by: mzhu25 <mchl.zhu.96@gmail.com> * feat: Better chain support (#163) * feat: Better chain support * feat: better chain support refactor deployment constants (#166) * proliferate the chainId * Refactor sampler to remove DeploymentConstants dependency and fixed addresses * Rework WETH out, replacing with address(0) * wat * hack DeploymentConstants for now * proliferate the chainId * Refactor sampler to remove DeploymentConstants dependency and fixed addresses * remove duped network addresses * Rework the bridge source encoder * Use the constants NATIVE_FEE_TOKEN in EP consumer * `@0x/contract-addresses`: Fix WBNB address (#170) Co-authored-by: Lawrence Forman <lawrence@0xproject.com> * multichain enable cakez vip (#171) * feat: Better chain support * feat: better chain support refactor deployment constants (#166) * proliferate the chainId * Refactor sampler to remove DeploymentConstants dependency and fixed addresses * Rework WETH out, replacing with address(0) * wat * hack DeploymentConstants for now * proliferate the chainId * Refactor sampler to remove DeploymentConstants dependency and fixed addresses * remove duped network addresses * `asset-swapper`: enable pancake VIP route generation Co-authored-by: Jacob Evans <jacob@dekz.net> Co-authored-by: Lawrence Forman <me@merklejerk.com> * `@0x/contracts-zero-ex`: Fix `PancakeSwapFeature` sushi values (#172) * `@0x/contracts-zero-ex`: Fix `PancakeSwapFeature` sushi values * `@0x/contracts-zero-ex`: I am a bad protocologist Co-authored-by: Lawrence Forman <me@merklejerk.com> * feat: BSC Nerve + Dodo + Nerve + Ellipsis (#181) * feat: BSC Nerve + DODO v1 * CHANGELOGs * Remove extra balance fetch * Add Belt * Added Ellipsis * Update FQT address * `@0x/contracts-zero-ex`: Delete TokenSpenderFeature and get stuff compiling * `@0x/asset-swapper`: fix compilation * prettier * `@0x/asset-swapper`: Truncate LiquidityProvider source ID name * Update packages/asset-swapper/src/utils/market_operation_utils/sampler_operations.ts Co-authored-by: Jacob Evans <jacob@dekz.net> * Update packages/asset-swapper/src/utils/market_operation_utils/sampler_operations.ts Co-authored-by: Jacob Evans <jacob@dekz.net> * `@0x/contracts-zero-ex`: Fix BakerySwap on PackageSwapFeature (#190) * address review comments Co-authored-by: mzhu25 <mchl.zhu.96@gmail.com> Co-authored-by: Jacob Evans <jacob@dekz.net> Co-authored-by: Lawrence Forman <me@merklejerk.com>
92 lines
3.8 KiB
TypeScript
92 lines
3.8 KiB
TypeScript
import { BigNumber } from '@0x/utils';
|
|
import axios, { AxiosInstance } from 'axios';
|
|
import AxiosMockAdapter from 'axios-mock-adapter';
|
|
import * as _ from 'lodash';
|
|
|
|
import { InsufficientAssetLiquidityError } from '../../src/errors';
|
|
import { AltMockedRfqQuoteResponse, MockedRfqQuoteResponse } from '../../src/types';
|
|
|
|
export enum RfqQuoteEndpoint {
|
|
Indicative = 'price',
|
|
Firm = 'quote',
|
|
}
|
|
|
|
export const testHelpers = {
|
|
expectInsufficientLiquidityErrorAsync: async (
|
|
expect: Chai.ExpectStatic,
|
|
functionWhichTriggersErrorAsync: () => Promise<void>,
|
|
expectedAmountAvailableToFill: BigNumber,
|
|
): Promise<void> => {
|
|
let wasErrorThrown = false;
|
|
try {
|
|
await functionWhichTriggersErrorAsync();
|
|
} catch (e) {
|
|
wasErrorThrown = true;
|
|
expect(e).to.be.instanceOf(InsufficientAssetLiquidityError);
|
|
if (expectedAmountAvailableToFill) {
|
|
expect(e.amountAvailableToFill).to.be.bignumber.equal(expectedAmountAvailableToFill);
|
|
} else {
|
|
expect(e.amountAvailableToFill).to.be.undefined();
|
|
}
|
|
}
|
|
|
|
expect(wasErrorThrown).to.be.true();
|
|
},
|
|
/**
|
|
* A helper utility for testing which mocks out
|
|
* requests to RFQ-T/M providers
|
|
*/
|
|
withMockedRfqQuotes: async (
|
|
standardMockedResponses: MockedRfqQuoteResponse[],
|
|
altMockedResponses: AltMockedRfqQuoteResponse[],
|
|
quoteType: RfqQuoteEndpoint,
|
|
afterResponseCallback: () => Promise<void>,
|
|
axiosClient: AxiosInstance = axios,
|
|
): Promise<void> => {
|
|
const mockedAxios = new AxiosMockAdapter(axiosClient, { onNoMatch: 'throwException' } as any);
|
|
try {
|
|
// Mock out Standard RFQ-T/M responses
|
|
for (const mockedResponse of standardMockedResponses) {
|
|
const { endpoint, requestApiKey, requestParams, responseData, responseCode } = mockedResponse;
|
|
const requestHeaders = { Accept: 'application/json, text/plain, */*', '0x-api-key': requestApiKey };
|
|
if (mockedResponse.callback !== undefined) {
|
|
mockedAxios
|
|
.onGet(`${endpoint}/${quoteType}`, { params: requestParams }, requestHeaders)
|
|
.reply(mockedResponse.callback);
|
|
} else {
|
|
mockedAxios
|
|
.onGet(`${endpoint}/${quoteType}`, { params: requestParams }, requestHeaders)
|
|
.replyOnce(responseCode, responseData);
|
|
}
|
|
}
|
|
// Mock out Alt RFQ-T/M responses
|
|
for (const mockedResponse of altMockedResponses) {
|
|
const { endpoint, mmApiKey, requestData, responseData, responseCode } = mockedResponse;
|
|
const requestHeaders = {
|
|
Accept: 'application/json, text/plain, */*',
|
|
'Content-Type': 'application/json;charset=utf-8',
|
|
Authorization: `Bearer ${mmApiKey}`,
|
|
};
|
|
mockedAxios
|
|
.onPost(
|
|
`${endpoint}/quotes`,
|
|
// hack to get AxiosMockAdapter to recognize the match
|
|
// b/t the mock data and the request data
|
|
{
|
|
asymmetricMatch: (x: any) => {
|
|
return _.isEqual(requestData, x);
|
|
},
|
|
},
|
|
requestHeaders,
|
|
)
|
|
.replyOnce(responseCode, responseData);
|
|
}
|
|
// Perform the callback function, e.g. a test validation
|
|
await afterResponseCallback();
|
|
} finally {
|
|
// Ensure we always restore axios afterwards
|
|
mockedAxios.restore();
|
|
}
|
|
},
|
|
};
|