diff options
Diffstat (limited to 'packages/contracts')
-rw-r--r-- | packages/contracts/contracts/Exchange.sol | 1 | ||||
-rw-r--r-- | packages/contracts/package.json | 2 | ||||
-rw-r--r-- | packages/contracts/test/exchange/core.ts | 59 | ||||
-rw-r--r-- | packages/contracts/test/token_registry.ts | 4 | ||||
-rw-r--r-- | packages/contracts/tsconfig.json | 2 | ||||
-rw-r--r-- | packages/contracts/util/exchange_wrapper.ts | 16 | ||||
-rw-r--r-- | packages/contracts/util/formatters.ts | 12 | ||||
-rw-r--r-- | packages/contracts/util/order.ts | 7 | ||||
-rw-r--r-- | packages/contracts/util/order_factory.ts | 2 |
9 files changed, 44 insertions, 61 deletions
diff --git a/packages/contracts/contracts/Exchange.sol b/packages/contracts/contracts/Exchange.sol index a402e7ca5..1da74deef 100644 --- a/packages/contracts/contracts/Exchange.sol +++ b/packages/contracts/contracts/Exchange.sol @@ -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 } } - diff --git a/packages/contracts/package.json b/packages/contracts/package.json index 05df63004..49f7d85cc 100644 --- a/packages/contracts/package.json +++ b/packages/contracts/package.json @@ -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" diff --git a/packages/contracts/test/exchange/core.ts b/packages/contracts/test/exchange/core.ts index 5fe2a9452..ac8c7229e 100644 --- a/packages/contracts/test/exchange/core.ts +++ b/packages/contracts/test/exchange/core.ts @@ -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 () => { diff --git a/packages/contracts/test/token_registry.ts b/packages/contracts/test/token_registry.ts index 1146353da..549b2f175 100644 --- a/packages/contracts/test/token_registry.ts +++ b/packages/contracts/test/token_registry.ts @@ -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); diff --git a/packages/contracts/tsconfig.json b/packages/contracts/tsconfig.json index 38008a542..0c1b3bc16 100644 --- a/packages/contracts/tsconfig.json +++ b/packages/contracts/tsconfig.json @@ -4,8 +4,6 @@ "outDir": "lib", "baseUrl": ".", "declaration": false, - "strictNullChecks": false, - "strictFunctionTypes": false, "allowJs": true }, "include": [ diff --git a/packages/contracts/util/exchange_wrapper.ts b/packages/contracts/util/exchange_wrapper.ts index 84123c5f4..7a07239f5 100644 --- a/packages/contracts/util/exchange_wrapper.ts +++ b/packages/contracts/util/exchange_wrapper.ts @@ -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( diff --git a/packages/contracts/util/formatters.ts b/packages/contracts/util/formatters.ts index 0d0ef6df4..e16fe8d45 100644 --- a/packages/contracts/util/formatters.ts +++ b/packages/contracts/util/formatters.ts @@ -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; }, diff --git a/packages/contracts/util/order.ts b/packages/contracts/util/order.ts index 702b2312c..57bb2bcbf 100644 --- a/packages/contracts/util/order.ts +++ b/packages/contracts/util/order.ts @@ -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; diff --git a/packages/contracts/util/order_factory.ts b/packages/contracts/util/order_factory.ts index fa12889ca..2b50f13e8 100644 --- a/packages/contracts/util/order_factory.ts +++ b/packages/contracts/util/order_factory.ts @@ -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( {}, |