parent
0c56207abc
commit
076f263a86
@ -45,7 +45,7 @@ contract TestNativeOrderSampler is
|
|||||||
UtilitySampler
|
UtilitySampler
|
||||||
{
|
{
|
||||||
uint8 private constant MAX_ORDER_STATUS = uint8(IExchange.OrderStatus.CANCELLED) + 1;
|
uint8 private constant MAX_ORDER_STATUS = uint8(IExchange.OrderStatus.CANCELLED) + 1;
|
||||||
bytes32 private constant VALID_SIGNATURE_HASH = keccak256(hex"01");
|
bytes32 private constant VALID_SIGNATURE_HASH = bytes32(hex"01");
|
||||||
|
|
||||||
function createTokens(uint256 count)
|
function createTokens(uint256 count)
|
||||||
external
|
external
|
||||||
|
@ -7,6 +7,7 @@ import {
|
|||||||
getRandomInteger,
|
getRandomInteger,
|
||||||
randomAddress,
|
randomAddress,
|
||||||
} from '@0x/contracts-test-utils';
|
} from '@0x/contracts-test-utils';
|
||||||
|
import { Web3Wrapper } from '@0x/dev-utils';
|
||||||
import { SignatureType } from '@0x/protocol-utils';
|
import { SignatureType } from '@0x/protocol-utils';
|
||||||
import { BigNumber, hexUtils } from '@0x/utils';
|
import { BigNumber, hexUtils } from '@0x/utils';
|
||||||
import * as _ from 'lodash';
|
import * as _ from 'lodash';
|
||||||
@ -20,11 +21,11 @@ const { NULL_BYTES, ZERO_AMOUNT } = constants;
|
|||||||
|
|
||||||
// tslint:disable: custom-no-magic-numbers
|
// tslint:disable: custom-no-magic-numbers
|
||||||
|
|
||||||
// TODO jacob
|
blockchainTests.resets('NativeOrderSampler contract', env => {
|
||||||
blockchainTests.resets.skip('NativeOrderSampler contract', env => {
|
|
||||||
let testContract: TestNativeOrderSamplerContract;
|
let testContract: TestNativeOrderSamplerContract;
|
||||||
let makerToken: string;
|
let makerToken: string;
|
||||||
let takerToken: string;
|
let takerToken: string;
|
||||||
|
let makerAddress: string;
|
||||||
const VALID_SIGNATURE = { v: 1, r: '0x01', s: '0x01', signatureType: SignatureType.EthSign };
|
const VALID_SIGNATURE = { v: 1, r: '0x01', s: '0x01', signatureType: SignatureType.EthSign };
|
||||||
|
|
||||||
before(async () => {
|
before(async () => {
|
||||||
@ -36,6 +37,7 @@ blockchainTests.resets.skip('NativeOrderSampler contract', env => {
|
|||||||
);
|
);
|
||||||
const NUM_TOKENS = new BigNumber(3);
|
const NUM_TOKENS = new BigNumber(3);
|
||||||
[makerToken, takerToken] = await testContract.createTokens(NUM_TOKENS).callAsync();
|
[makerToken, takerToken] = await testContract.createTokens(NUM_TOKENS).callAsync();
|
||||||
|
[makerAddress] = await new Web3Wrapper(env.provider).getAvailableAddressesAsync();
|
||||||
await testContract.createTokens(NUM_TOKENS).awaitTransactionSuccessAsync();
|
await testContract.createTokens(NUM_TOKENS).awaitTransactionSuccessAsync();
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -79,8 +81,8 @@ blockchainTests.resets.skip('NativeOrderSampler contract', env => {
|
|||||||
return {
|
return {
|
||||||
chainId: 1337,
|
chainId: 1337,
|
||||||
verifyingContract: randomAddress(),
|
verifyingContract: randomAddress(),
|
||||||
maker: randomAddress(),
|
maker: makerAddress,
|
||||||
taker: randomAddress(),
|
taker: NULL_ADDRESS,
|
||||||
pool: NULL_BYTES,
|
pool: NULL_BYTES,
|
||||||
sender: NULL_ADDRESS,
|
sender: NULL_ADDRESS,
|
||||||
feeRecipient: randomAddress(),
|
feeRecipient: randomAddress(),
|
||||||
@ -147,8 +149,8 @@ blockchainTests.resets.skip('NativeOrderSampler contract', env => {
|
|||||||
describe('getLimitOrderFillableTakerAmount()', () => {
|
describe('getLimitOrderFillableTakerAmount()', () => {
|
||||||
it('returns the full amount for a fully funded order', async () => {
|
it('returns the full amount for a fully funded order', async () => {
|
||||||
const order = createOrder();
|
const order = createOrder();
|
||||||
const expected = getLimitOrderFillableTakerAmount(order);
|
|
||||||
await fundMakerAsync(order);
|
await fundMakerAsync(order);
|
||||||
|
const expected = getLimitOrderFillableTakerAmount(order);
|
||||||
const actual = await testContract
|
const actual = await testContract
|
||||||
.getLimitOrderFillableTakerAmount(order, VALID_SIGNATURE, testContract.address)
|
.getLimitOrderFillableTakerAmount(order, VALID_SIGNATURE, testContract.address)
|
||||||
.callAsync();
|
.callAsync();
|
||||||
|
@ -8,7 +8,7 @@ import {
|
|||||||
toBaseUnitAmount,
|
toBaseUnitAmount,
|
||||||
} from '@0x/contracts-test-utils';
|
} from '@0x/contracts-test-utils';
|
||||||
import { FillQuoteTransformerOrderType, LimitOrderFields, SignatureType } from '@0x/protocol-utils';
|
import { FillQuoteTransformerOrderType, LimitOrderFields, SignatureType } from '@0x/protocol-utils';
|
||||||
import { BigNumber, hexUtils, NULL_ADDRESS, NULL_BYTES } from '@0x/utils';
|
import { BigNumber, hexUtils, NULL_ADDRESS } from '@0x/utils';
|
||||||
import { Pool } from '@balancer-labs/sor/dist/types';
|
import { Pool } from '@balancer-labs/sor/dist/types';
|
||||||
import * as _ from 'lodash';
|
import * as _ from 'lodash';
|
||||||
|
|
||||||
@ -21,13 +21,13 @@ import { MockSamplerContract } from './utils/mock_sampler_contract';
|
|||||||
import { generatePseudoRandomSalt } from './utils/utils';
|
import { generatePseudoRandomSalt } from './utils/utils';
|
||||||
|
|
||||||
const CHAIN_ID = 1;
|
const CHAIN_ID = 1;
|
||||||
|
const EMPTY_BYTES32 = '0x0000000000000000000000000000000000000000000000000000000000000000';
|
||||||
// tslint:disable: custom-no-magic-numbers
|
// tslint:disable: custom-no-magic-numbers
|
||||||
describe('DexSampler tests', () => {
|
describe('DexSampler tests', () => {
|
||||||
const MAKER_TOKEN = randomAddress();
|
const MAKER_TOKEN = randomAddress();
|
||||||
const TAKER_TOKEN = randomAddress();
|
const TAKER_TOKEN = randomAddress();
|
||||||
|
|
||||||
const wethAddress = getContractAddressesForChainOrThrow(CHAIN_ID).etherToken;
|
const wethAddress = getContractAddressesForChainOrThrow(CHAIN_ID).etherToken;
|
||||||
const exchangeAddress = getContractAddressesForChainOrThrow(CHAIN_ID).exchange;
|
|
||||||
const exchangeProxyAddress = getContractAddressesForChainOrThrow(CHAIN_ID).exchangeProxy;
|
const exchangeProxyAddress = getContractAddressesForChainOrThrow(CHAIN_ID).exchangeProxy;
|
||||||
|
|
||||||
const tokenAdjacencyGraph: TokenAdjacencyGraph = { default: [wethAddress] };
|
const tokenAdjacencyGraph: TokenAdjacencyGraph = { default: [wethAddress] };
|
||||||
@ -78,7 +78,7 @@ describe('DexSampler tests', () => {
|
|||||||
takerAmount: getRandomInteger(1, 1e18),
|
takerAmount: getRandomInteger(1, 1e18),
|
||||||
takerTokenFeeAmount: constants.ZERO_AMOUNT,
|
takerTokenFeeAmount: constants.ZERO_AMOUNT,
|
||||||
chainId: CHAIN_ID,
|
chainId: CHAIN_ID,
|
||||||
pool: NULL_BYTES,
|
pool: EMPTY_BYTES32,
|
||||||
feeRecipient: NULL_ADDRESS,
|
feeRecipient: NULL_ADDRESS,
|
||||||
sender: NULL_ADDRESS,
|
sender: NULL_ADDRESS,
|
||||||
maker: NULL_ADDRESS,
|
maker: NULL_ADDRESS,
|
||||||
@ -92,11 +92,10 @@ describe('DexSampler tests', () => {
|
|||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
const ORDERS = _.times(4, () => createOrder());
|
const ORDERS = _.times(4, () => createOrder());
|
||||||
const SIMPLE_ORDERS = ORDERS.map(o => _.omit(o, ['signature', 'chainId']));
|
const SIMPLE_ORDERS = ORDERS.map(o => _.omit(o.order, ['chainId', 'verifyingContract']));
|
||||||
|
|
||||||
describe('operations', () => {
|
describe('operations', () => {
|
||||||
// TODO jacob
|
it('getLimitOrderFillableMakerAssetAmounts()', async () => {
|
||||||
it.skip('getLimitOrderFillableMakerAssetAmounts()', async () => {
|
|
||||||
const expectedFillableAmounts = ORDERS.map(() => getRandomInteger(0, 100e18));
|
const expectedFillableAmounts = ORDERS.map(() => getRandomInteger(0, 100e18));
|
||||||
const sampler = new MockSamplerContract({
|
const sampler = new MockSamplerContract({
|
||||||
getLimitOrderFillableMakerAssetAmounts: (orders, signatures) => {
|
getLimitOrderFillableMakerAssetAmounts: (orders, signatures) => {
|
||||||
@ -115,13 +114,12 @@ describe('DexSampler tests', () => {
|
|||||||
async () => undefined,
|
async () => undefined,
|
||||||
);
|
);
|
||||||
const [fillableAmounts] = await dexOrderSampler.executeAsync(
|
const [fillableAmounts] = await dexOrderSampler.executeAsync(
|
||||||
dexOrderSampler.getLimitOrderFillableMakerAmounts(ORDERS, exchangeAddress),
|
dexOrderSampler.getLimitOrderFillableMakerAmounts(ORDERS, exchangeProxyAddress),
|
||||||
);
|
);
|
||||||
expect(fillableAmounts).to.deep.eq(expectedFillableAmounts);
|
expect(fillableAmounts).to.deep.eq(expectedFillableAmounts);
|
||||||
});
|
});
|
||||||
|
|
||||||
// TODO jacob
|
it('getLimitOrderFillableTakerAssetAmounts()', async () => {
|
||||||
it.skip('getLimitOrderFillableTakerAssetAmounts()', async () => {
|
|
||||||
const expectedFillableAmounts = ORDERS.map(() => getRandomInteger(0, 100e18));
|
const expectedFillableAmounts = ORDERS.map(() => getRandomInteger(0, 100e18));
|
||||||
const sampler = new MockSamplerContract({
|
const sampler = new MockSamplerContract({
|
||||||
getLimitOrderFillableTakerAssetAmounts: (orders, signatures) => {
|
getLimitOrderFillableTakerAssetAmounts: (orders, signatures) => {
|
||||||
@ -140,7 +138,7 @@ describe('DexSampler tests', () => {
|
|||||||
async () => undefined,
|
async () => undefined,
|
||||||
);
|
);
|
||||||
const [fillableAmounts] = await dexOrderSampler.executeAsync(
|
const [fillableAmounts] = await dexOrderSampler.executeAsync(
|
||||||
dexOrderSampler.getLimitOrderFillableTakerAmounts(ORDERS, exchangeAddress),
|
dexOrderSampler.getLimitOrderFillableTakerAmounts(ORDERS, exchangeProxyAddress),
|
||||||
);
|
);
|
||||||
expect(fillableAmounts).to.deep.eq(expectedFillableAmounts);
|
expect(fillableAmounts).to.deep.eq(expectedFillableAmounts);
|
||||||
});
|
});
|
||||||
@ -631,7 +629,7 @@ describe('DexSampler tests', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('batched operations', () => {
|
describe('batched operations', () => {
|
||||||
it.skip('getLimitOrderFillableMakerAssetAmounts(), getLimitOrderFillableTakerAssetAmounts()', async () => {
|
it('getLimitOrderFillableMakerAssetAmounts(), getLimitOrderFillableTakerAssetAmounts()', async () => {
|
||||||
const expectedFillableTakerAmounts = ORDERS.map(() => getRandomInteger(0, 100e18));
|
const expectedFillableTakerAmounts = ORDERS.map(() => getRandomInteger(0, 100e18));
|
||||||
const expectedFillableMakerAmounts = ORDERS.map(() => getRandomInteger(0, 100e18));
|
const expectedFillableMakerAmounts = ORDERS.map(() => getRandomInteger(0, 100e18));
|
||||||
const sampler = new MockSamplerContract({
|
const sampler = new MockSamplerContract({
|
||||||
@ -656,8 +654,8 @@ describe('DexSampler tests', () => {
|
|||||||
async () => undefined,
|
async () => undefined,
|
||||||
);
|
);
|
||||||
const [fillableMakerAmounts, fillableTakerAmounts] = await dexOrderSampler.executeAsync(
|
const [fillableMakerAmounts, fillableTakerAmounts] = await dexOrderSampler.executeAsync(
|
||||||
dexOrderSampler.getLimitOrderFillableMakerAmounts(ORDERS, exchangeAddress),
|
dexOrderSampler.getLimitOrderFillableMakerAmounts(ORDERS, exchangeProxyAddress),
|
||||||
dexOrderSampler.getLimitOrderFillableTakerAmounts(ORDERS, exchangeAddress),
|
dexOrderSampler.getLimitOrderFillableTakerAmounts(ORDERS, exchangeProxyAddress),
|
||||||
);
|
);
|
||||||
expect(fillableMakerAmounts).to.deep.eq(expectedFillableMakerAmounts);
|
expect(fillableMakerAmounts).to.deep.eq(expectedFillableMakerAmounts);
|
||||||
expect(fillableTakerAmounts).to.deep.eq(expectedFillableTakerAmounts);
|
expect(fillableTakerAmounts).to.deep.eq(expectedFillableTakerAmounts);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user