Normalize the dependencies

This commit is contained in:
Leonid Logvinov
2018-01-25 15:12:46 +01:00
parent 2f65fadeaa
commit 1e9147b8bb
21 changed files with 76 additions and 147 deletions

View File

@@ -600,4 +600,3 @@ contract Exchange is SafeMath {
return Token(token).allowance.gas(EXTERNAL_QUERY_GAS_LIMIT)(owner, TOKEN_TRANSFER_PROXY_CONTRACT); // Limit gas to prevent reentrancy
}
}

View File

@@ -52,7 +52,7 @@
"truffle": "^4.0.1",
"tslint": "5.8.0",
"types-bn": "^0.0.1",
"types-ethereumjs-util": "0xProject/types-ethereumjs-util",
"types-ethereumjs-util": "0xproject/types-ethereumjs-util",
"typescript": "~2.6.1",
"web3-typescript-typings": "^0.9.7",
"yargs": "^10.0.3"

View File

@@ -147,9 +147,8 @@ describe('Exchange', () => {
takerTokenAmount: new BigNumber(3),
});
const filledTakerTokenAmountBefore = await zeroEx.exchange.getFilledTakerAmountAsync(
order.params.orderHashHex,
);
const filledTakerTokenAmountBefore = await zeroEx.exchange.getFilledTakerAmountAsync(order.params
.orderHashHex as string);
expect(filledTakerTokenAmountBefore).to.be.bignumber.equal(0);
const fillTakerTokenAmount1 = new BigNumber(2);
@@ -157,9 +156,8 @@ describe('Exchange', () => {
fillTakerTokenAmount: fillTakerTokenAmount1,
});
const filledTakerTokenAmountAfter1 = await zeroEx.exchange.getFilledTakerAmountAsync(
order.params.orderHashHex,
);
const filledTakerTokenAmountAfter1 = await zeroEx.exchange.getFilledTakerAmountAsync(order.params
.orderHashHex as string);
expect(filledTakerTokenAmountAfter1).to.be.bignumber.equal(fillTakerTokenAmount1);
const fillTakerTokenAmount2 = new BigNumber(1);
@@ -167,9 +165,8 @@ describe('Exchange', () => {
fillTakerTokenAmount: fillTakerTokenAmount2,
});
const filledTakerTokenAmountAfter2 = await zeroEx.exchange.getFilledTakerAmountAsync(
order.params.orderHashHex,
);
const filledTakerTokenAmountAfter2 = await zeroEx.exchange.getFilledTakerAmountAsync(order.params
.orderHashHex as string);
expect(filledTakerTokenAmountAfter2).to.be.bignumber.equal(filledTakerTokenAmountAfter1);
});
@@ -179,17 +176,15 @@ describe('Exchange', () => {
takerTokenAmount: ZeroEx.toBaseUnitAmount(new BigNumber(100), 18),
});
const filledTakerTokenAmountBefore = await zeroEx.exchange.getFilledTakerAmountAsync(
order.params.orderHashHex,
);
const filledTakerTokenAmountBefore = await zeroEx.exchange.getFilledTakerAmountAsync(order.params
.orderHashHex as string);
expect(filledTakerTokenAmountBefore).to.be.bignumber.equal(0);
const fillTakerTokenAmount = order.params.takerTokenAmount.div(2);
await exWrapper.fillOrderAsync(order, taker, { fillTakerTokenAmount });
const filledTakerTokenAmountAfter = await zeroEx.exchange.getFilledTakerAmountAsync(
order.params.orderHashHex,
);
const filledTakerTokenAmountAfter = await zeroEx.exchange.getFilledTakerAmountAsync(order.params
.orderHashHex as string);
expect(filledTakerTokenAmountAfter).to.be.bignumber.equal(fillTakerTokenAmount);
const newBalances = await dmyBalances.getAsync();
@@ -232,17 +227,15 @@ describe('Exchange', () => {
takerTokenAmount: ZeroEx.toBaseUnitAmount(new BigNumber(100), 18),
});
const filledTakerTokenAmountBefore = await zeroEx.exchange.getFilledTakerAmountAsync(
order.params.orderHashHex,
);
const filledTakerTokenAmountBefore = await zeroEx.exchange.getFilledTakerAmountAsync(order.params
.orderHashHex as string);
expect(filledTakerTokenAmountBefore).to.be.bignumber.equal(0);
const fillTakerTokenAmount = order.params.takerTokenAmount.div(2);
await exWrapper.fillOrderAsync(order, taker, { fillTakerTokenAmount });
const filledTakerTokenAmountAfter = await zeroEx.exchange.getFilledTakerAmountAsync(
order.params.orderHashHex,
);
const filledTakerTokenAmountAfter = await zeroEx.exchange.getFilledTakerAmountAsync(order.params
.orderHashHex as string);
expect(filledTakerTokenAmountAfter).to.be.bignumber.equal(fillTakerTokenAmount);
const newBalances = await dmyBalances.getAsync();
@@ -285,17 +278,15 @@ describe('Exchange', () => {
takerTokenAmount: ZeroEx.toBaseUnitAmount(new BigNumber(200), 18),
});
const filledTakerTokenAmountBefore = await zeroEx.exchange.getFilledTakerAmountAsync(
order.params.orderHashHex,
);
const filledTakerTokenAmountBefore = await zeroEx.exchange.getFilledTakerAmountAsync(order.params
.orderHashHex as string);
expect(filledTakerTokenAmountBefore).to.be.bignumber.equal(0);
const fillTakerTokenAmount = order.params.takerTokenAmount.div(2);
await exWrapper.fillOrderAsync(order, taker, { fillTakerTokenAmount });
const filledTakerTokenAmountAfter = await zeroEx.exchange.getFilledTakerAmountAsync(
order.params.orderHashHex,
);
const filledTakerTokenAmountAfter = await zeroEx.exchange.getFilledTakerAmountAsync(order.params
.orderHashHex as string);
expect(filledTakerTokenAmountAfter).to.be.bignumber.equal(fillTakerTokenAmount);
const newBalances = await dmyBalances.getAsync();
@@ -339,17 +330,15 @@ describe('Exchange', () => {
takerTokenAmount: ZeroEx.toBaseUnitAmount(new BigNumber(200), 18),
});
const filledTakerTokenAmountBefore = await zeroEx.exchange.getFilledTakerAmountAsync(
order.params.orderHashHex,
);
const filledTakerTokenAmountBefore = await zeroEx.exchange.getFilledTakerAmountAsync(order.params
.orderHashHex as string);
expect(filledTakerTokenAmountBefore).to.be.bignumber.equal(0);
const fillTakerTokenAmount = order.params.takerTokenAmount.div(2);
await exWrapper.fillOrderAsync(order, taker, { fillTakerTokenAmount });
const filledTakerTokenAmountAfter = await zeroEx.exchange.getFilledTakerAmountAsync(
order.params.orderHashHex,
);
const filledTakerTokenAmountAfter = await zeroEx.exchange.getFilledTakerAmountAsync(order.params
.orderHashHex as string);
const expectedFillAmountTAfter = fillTakerTokenAmount.add(filledTakerTokenAmountBefore);
expect(filledTakerTokenAmountAfter).to.be.bignumber.equal(expectedFillAmountTAfter);
@@ -678,7 +667,7 @@ describe('Exchange', () => {
expect(newBalances).to.be.deep.equal(balances);
});
it.skip('should throw if getBalance or getAllowance attempts to change state and \
it('should throw if getBalance or getAllowance attempts to change state and \
shouldThrowOnInsufficientBalanceOrAllowance = false', async () => {
const maliciousToken = await deployer.deployAsync('MaliciousToken');
await maliciousToken.approve(tokenTransferProxy.address, INITIAL_ALLOWANCE, { from: taker });
@@ -691,7 +680,7 @@ describe('Exchange', () => {
exWrapper.fillOrderAsync(order, taker, {
shouldThrowOnInsufficientBalanceOrAllowance: false,
}),
).to.be.rejectedWith(constants.REVERT);
).to.be.rejectedWith(constants.INVALID_OPCODE);
});
it('should not change balances if an order is expired', async () => {

View File

@@ -175,7 +175,7 @@ describe('TokenRegistry', () => {
});
it('should change the token symbol when called by owner', async () => {
const res = await tokenReg.setTokenSymbol(token1.address, token2.symbol, { from: owner });
await tokenReg.setTokenSymbol(token1.address, token2.symbol, { from: owner });
const [newData, oldData] = await Promise.all([
tokenRegWrapper.getTokenBySymbolAsync(token2.symbol),
tokenRegWrapper.getTokenBySymbolAsync(token1.symbol),
@@ -216,7 +216,7 @@ describe('TokenRegistry', () => {
it('should remove token metadata when called by owner', async () => {
const index = 0;
const res = await tokenReg.removeToken(token1.address, index, {
await tokenReg.removeToken(token1.address, index, {
from: owner,
});
const tokenData = await tokenRegWrapper.getTokenMetaDataAsync(token1.address);

View File

@@ -4,8 +4,6 @@
"outDir": "lib",
"baseUrl": ".",
"declaration": false,
"strictNullChecks": false,
"strictFunctionTypes": false,
"allowJs": true
},
"include": [

View File

@@ -1,4 +1,4 @@
import { ExchangeContractEventArgs, TransactionReceiptWithDecodedLogs, ZeroEx } from '0x.js';
import { TransactionReceiptWithDecodedLogs, ZeroEx } from '0x.js';
import { BigNumber } from '@0xproject/utils';
import * as _ from 'lodash';
import * as Web3 from 'web3';
@@ -108,9 +108,14 @@ export class ExchangeWrapper {
public async batchFillOrKillOrdersAsync(
orders: Order[],
from: string,
opts: { fillTakerTokenAmounts?: BigNumber[] } = {},
opts: { fillTakerTokenAmounts?: BigNumber[]; shouldThrowOnInsufficientBalanceOrAllowance?: boolean } = {},
): Promise<TransactionReceiptWithDecodedLogs> {
const params = formatters.createBatchFill(orders, undefined, opts.fillTakerTokenAmounts);
const shouldThrowOnInsufficientBalanceOrAllowance = !!opts.shouldThrowOnInsufficientBalanceOrAllowance;
const params = formatters.createBatchFill(
orders,
shouldThrowOnInsufficientBalanceOrAllowance,
opts.fillTakerTokenAmounts,
);
const txHash = await this._exchange.batchFillOrKillOrders(
params.orderAddresses,
params.orderValues,
@@ -128,10 +133,7 @@ export class ExchangeWrapper {
public async fillOrdersUpToAsync(
orders: Order[],
from: string,
opts: {
fillTakerTokenAmount?: BigNumber;
shouldThrowOnInsufficientBalanceOrAllowance?: boolean;
} = {},
opts: { fillTakerTokenAmount: BigNumber; shouldThrowOnInsufficientBalanceOrAllowance?: boolean },
): Promise<TransactionReceiptWithDecodedLogs> {
const shouldThrowOnInsufficientBalanceOrAllowance = !!opts.shouldThrowOnInsufficientBalanceOrAllowance;
const params = formatters.createFillUpTo(

View File

@@ -35,9 +35,9 @@ export const formatters = {
order.params.expirationTimestampInSec,
order.params.salt,
]);
batchFill.v.push(order.params.v);
batchFill.r.push(order.params.r);
batchFill.s.push(order.params.s);
batchFill.v.push(order.params.v as number);
batchFill.r.push(order.params.r as string);
batchFill.s.push(order.params.s as string);
if (fillTakerTokenAmounts.length < orders.length) {
batchFill.fillTakerTokenAmounts.push(order.params.takerTokenAmount);
}
@@ -74,9 +74,9 @@ export const formatters = {
order.params.expirationTimestampInSec,
order.params.salt,
]);
fillUpTo.v.push(order.params.v);
fillUpTo.r.push(order.params.r);
fillUpTo.s.push(order.params.s);
fillUpTo.v.push(order.params.v as number);
fillUpTo.r.push(order.params.r as string);
fillUpTo.s.push(order.params.s as string);
});
return fillUpTo;
},

View File

@@ -1,16 +1,11 @@
import { BigNumber, promisify } from '@0xproject/utils';
import { BigNumber } from '@0xproject/utils';
import { Web3Wrapper } from '@0xproject/web3-wrapper';
import ethUtil = require('ethereumjs-util');
import * as _ from 'lodash';
import Web3 = require('web3');
import { crypto } from './crypto';
import { OrderParams } from './types';
// In order to benefit from type-safety, we re-assign the global web3 instance injected by Truffle
// with type `any` to a variable of type `Web3`.
const web3: Web3 = (global as any).web3;
export class Order {
public params: OrderParams;
private _web3Wrapper: Web3Wrapper;

View File

@@ -13,7 +13,7 @@ export class OrderFactory {
this._defaultOrderParams = defaultOrderParams;
this._web3Wrapper = web3Wrapper;
}
public async newSignedOrderAsync(customOrderParams: OptionalOrderParams = {}) {
public async newSignedOrderAsync(customOrderParams: OptionalOrderParams = {}): Promise<Order> {
const randomExpiration = new BigNumber(Math.floor((Date.now() + Math.random() * 100000000000) / 1000));
const orderParams: OrderParams = _.assign(
{},