initial unit tests for DEX sampler

This commit is contained in:
Daniel Pyrathon 2020-02-27 14:00:08 -08:00
parent 3c0fd540b1
commit 8be60e2ff5
2 changed files with 56 additions and 2 deletions

View File

@ -184,6 +184,20 @@ const samplerOperations = {
}, },
}; };
}, },
getLiquidityProviderFromRegistry(
registryAddress: string,
makerToken: string,
takerToken: string,
): BatchedOperation<string> {
return {
encodeCall: contract => {
return contract.getLiquidityProviderFromRegistry(registryAddress, makerToken, takerToken).getABIEncodedTransactionData()
},
handleCallResultsAsync: async (contract, callResults) => {
return contract.getABIDecodedReturnData<string>('getLiquidityProviderFromRegistry', callResults);
},
};
},
getSellQuotes( getSellQuotes(
sources: ERC20BridgeSource[], sources: ERC20BridgeSource[],
makerToken: string, makerToken: string,

View File

@ -1,13 +1,15 @@
import { constants, expect, getRandomFloat, getRandomInteger, randomAddress } from '@0x/contracts-test-utils'; import { constants, expect, getRandomFloat, getRandomInteger, randomAddress, provider, txDefaults } from '@0x/contracts-test-utils';
import { assetDataUtils, generatePseudoRandomSalt } from '@0x/order-utils'; import { assetDataUtils, generatePseudoRandomSalt } from '@0x/order-utils';
import { SignedOrder } from '@0x/types'; import { SignedOrder } from '@0x/types';
import { BigNumber, hexUtils } from '@0x/utils'; import { BigNumber, hexUtils, NULL_ADDRESS } from '@0x/utils';
import * as _ from 'lodash'; import * as _ from 'lodash';
import { DexOrderSampler, getSampleAmounts } from '../src/utils/market_operation_utils/sampler'; import { DexOrderSampler, getSampleAmounts } from '../src/utils/market_operation_utils/sampler';
import { ERC20BridgeSource } from '../src/utils/market_operation_utils/types'; import { ERC20BridgeSource } from '../src/utils/market_operation_utils/types';
import { MockSamplerContract } from './utils/mock_sampler_contract'; import { MockSamplerContract } from './utils/mock_sampler_contract';
import { DummyLiquidityProviderRegistryContract, ERC20BridgeSamplerContract, IERC20BridgeSamplerContract } from '@0x/contract-wrappers';
import { artifacts as erc20BridgeSamplerArtifacts } from '@0x/contracts-erc20-bridge-sampler/lib/src/artifacts';
const CHAIN_ID = 1; const CHAIN_ID = 1;
// tslint:disable: custom-no-magic-numbers // tslint:disable: custom-no-magic-numbers
@ -326,6 +328,44 @@ describe('DexSampler tests', () => {
); );
expect(quotes).to.deep.eq(expectedQuotes); expect(quotes).to.deep.eq(expectedQuotes);
}); });
it.only('getLiquidityProviderFromRegistry()', async () => {
const xAsset = randomAddress();
const yAsset = randomAddress();
const zAsset = randomAddress();
const liquidityPool1 = randomAddress();
const liquidityPool2 = randomAddress();
// Deploy Registry
const registryContract = await DummyLiquidityProviderRegistryContract.deployFrom0xArtifactAsync(
erc20BridgeSamplerArtifacts.DummyLiquidityProviderRegistry,
provider,
txDefaults,
{},
);
// Write 2 new liquidity pools
await registryContract.setLiquidityProviderForMarket(xAsset, yAsset, liquidityPool1).awaitTransactionSuccessAsync();
await registryContract.setLiquidityProviderForMarket(xAsset, zAsset, liquidityPool2).awaitTransactionSuccessAsync();
// Deploy the sampler
const samplerContract = await ERC20BridgeSamplerContract.deployFrom0xArtifactAsync(
erc20BridgeSamplerArtifacts.ERC20BridgeSampler,
provider,
txDefaults,
{},
);
// Test multiple combinations: 2 pools that are present, 1 pool that is not present.
const dexOrderSampler = new DexOrderSampler(new IERC20BridgeSamplerContract(samplerContract.address, provider));
const [xyPool, xzPool, yzPool] = await dexOrderSampler.executeBatchAsync([
DexOrderSampler.ops.getLiquidityProviderFromRegistry(registryContract.address, xAsset, yAsset),
DexOrderSampler.ops.getLiquidityProviderFromRegistry(registryContract.address, xAsset, zAsset),
DexOrderSampler.ops.getLiquidityProviderFromRegistry(registryContract.address, yAsset, zAsset),
]);
expect(xyPool).to.eql(liquidityPool1);
expect(xzPool).to.eql(liquidityPool2);
expect(yzPool).to.eql(NULL_ADDRESS);
});
}); });
describe('batched operations', () => { describe('batched operations', () => {