@0x:contracts-exchange Added the tests for getOrdersInfo back into the exchange
This commit is contained in:
@@ -10,7 +10,7 @@ import {
|
||||
} from '@0x/contracts-test-utils';
|
||||
import { ReferenceFunctions as UtilReferenceFunctions } from '@0x/contracts-utils';
|
||||
import { ExchangeRevertErrors, orderHashUtils } from '@0x/order-utils';
|
||||
import { FillResults, OrderWithoutDomain as Order } from '@0x/types';
|
||||
import { FillResults, OrderInfo, OrderStatus, OrderWithoutDomain as Order } from '@0x/types';
|
||||
import { AnyRevertError, BigNumber, SafeMathRevertErrors, StringRevertError } from '@0x/utils';
|
||||
import { LogEntry, LogWithDecodedArgs } from 'ethereum-types';
|
||||
import * as ethjs from 'ethereumjs-util';
|
||||
@@ -1320,6 +1320,51 @@ blockchainTests('Exchange wrapper functions unit tests.', env => {
|
||||
const tx = txHelper.getResultAndReceiptAsync(testContract.batchCancelOrders, orders);
|
||||
return expect(tx).to.revertWith(expectedError);
|
||||
});
|
||||
|
||||
describe('getOrdersInfo', () => {
|
||||
// Computes the expected (fake) order info generated by the `TestWrapperFunctions` contract.
|
||||
function getExpectedOrderInfo(order: Order): OrderInfo {
|
||||
const MAX_ORDER_STATUS = OrderStatus.Cancelled as number;
|
||||
return {
|
||||
orderHash: getExpectedOrderHash(order),
|
||||
// Lower uint128 of `order.salt` is the `orderTakerAssetFilledAmount`.
|
||||
orderTakerAssetFilledAmount: order.salt.mod(new BigNumber(2).pow(128)),
|
||||
// High byte of `order.salt` is the `orderStatus`.
|
||||
orderStatus:
|
||||
order.salt.dividedToIntegerBy(new BigNumber(2).pow(248)).toNumber() % (MAX_ORDER_STATUS + 1),
|
||||
};
|
||||
}
|
||||
|
||||
it('works with no orders', async () => {
|
||||
const infos = await testContract.getOrdersInfo.callAsync([]);
|
||||
expect(infos.length).to.eq(0);
|
||||
});
|
||||
|
||||
it('works with one order', async () => {
|
||||
const orders = [randomOrder()];
|
||||
const expectedResult = orders.map(getExpectedOrderInfo);
|
||||
const actualResult = await testContract.getOrdersInfo.callAsync(orders);
|
||||
expect(actualResult).to.deep.eq(expectedResult);
|
||||
});
|
||||
|
||||
it('works with many orders', async () => {
|
||||
const NUM_ORDERS = 16;
|
||||
const orders = _.times(NUM_ORDERS, () => randomOrder());
|
||||
const expectedResult = orders.map(getExpectedOrderInfo);
|
||||
const actualResult = await testContract.getOrdersInfo.callAsync(orders);
|
||||
expect(actualResult).to.deep.eq(expectedResult);
|
||||
});
|
||||
|
||||
it('works with duplicate orders', async () => {
|
||||
const NUM_UNIQUE_ORDERS = 4;
|
||||
const CLONE_COUNT = 2;
|
||||
const uniqueOrders = _.times(NUM_UNIQUE_ORDERS, () => randomOrder());
|
||||
const orders = _.shuffle(_.flatten(_.times(CLONE_COUNT, () => uniqueOrders)));
|
||||
const expectedResult = orders.map(getExpectedOrderInfo);
|
||||
const actualResult = await testContract.getOrdersInfo.callAsync(orders);
|
||||
expect(actualResult).to.deep.eq(expectedResult);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
// tslint:disable-next-line: max-file-line-count
|
||||
|
||||
Reference in New Issue
Block a user