From 61bdbd2d74c0f20b59044370d3abb28424d24f36 Mon Sep 17 00:00:00 2001 From: Lawrence Forman Date: Tue, 23 Apr 2019 23:50:48 -0400 Subject: [PATCH] Rebased against `3.0`. Run prettier/linter. --- .../src/libs/LibExchangeRichErrorDecoder.sol | 4 +- contracts/exchange/test/core.ts | 20 +- .../test/lib_exchange_rich_error_decoder.ts | 188 +++--------------- contracts/exchange/test/match_orders.ts | 10 +- contracts/exchange/test/wrapper.ts | 10 +- .../contracts/src/mixins/MRichErrors.sol | 1 + packages/order-utils/src/eip712_utils.ts | 1 - 7 files changed, 39 insertions(+), 195 deletions(-) diff --git a/contracts/exchange/contracts/src/libs/LibExchangeRichErrorDecoder.sol b/contracts/exchange/contracts/src/libs/LibExchangeRichErrorDecoder.sol index 9382a20ee1..faac72efdc 100644 --- a/contracts/exchange/contracts/src/libs/LibExchangeRichErrorDecoder.sol +++ b/contracts/exchange/contracts/src/libs/LibExchangeRichErrorDecoder.sol @@ -249,9 +249,7 @@ contract LibExchangeRichErrorDecoder is function decodeAssetProxyExistsError(bytes memory encoded) public pure - returns ( - address assetProxyAddress - ) + returns (address assetProxyAddress) { _assertSelectorBytes(encoded, ASSET_PROXY_EXISTS_ERROR_SELECTOR); assetProxyAddress = _readErrorParameterAsAddress(encoded, 0); diff --git a/contracts/exchange/test/core.ts b/contracts/exchange/test/core.ts index 820a31de86..f0028ae676 100644 --- a/contracts/exchange/test/core.ts +++ b/contracts/exchange/test/core.ts @@ -275,10 +275,7 @@ describe('Exchange core', () => { signedOrder = await orderFactory.newSignedOrderAsync(); const orderHashHex = orderHashUtils.getOrderHashHex(signedOrder); await exchangeWrapper.fillOrderAsync(signedOrder, takerAddress); - const expectedError = new ExchangeRevertErrors.OrderStatusError( - orderHashHex, - OrderStatus.FullyFilled, - ); + const expectedError = new ExchangeRevertErrors.OrderStatusError(orderHashHex, OrderStatus.FullyFilled); const tx = exchangeWrapper.fillOrderAsync(signedOrder, takerAddress); return expect(tx).to.revertWith(expectedError); }); @@ -534,10 +531,7 @@ describe('Exchange core', () => { it('should be able to cancel an order', async () => { await exchangeWrapper.cancelOrderAsync(signedOrder, makerAddress); const orderHash = orderHashUtils.getOrderHashHex(signedOrder); - const expectedError = new ExchangeRevertErrors.OrderStatusError( - orderHash, - OrderStatus.Cancelled, - ); + const expectedError = new ExchangeRevertErrors.OrderStatusError(orderHash, OrderStatus.Cancelled); const tx = exchangeWrapper.fillOrderAsync(signedOrder, takerAddress, { takerAssetFillAmount: signedOrder.takerAssetAmount.div(2), }); @@ -562,10 +556,7 @@ describe('Exchange core', () => { it('should throw if already cancelled', async () => { await exchangeWrapper.cancelOrderAsync(signedOrder, makerAddress); const orderHash = orderHashUtils.getOrderHashHex(signedOrder); - const expectedError = new ExchangeRevertErrors.OrderStatusError( - orderHash, - OrderStatus.Cancelled, - ); + const expectedError = new ExchangeRevertErrors.OrderStatusError(orderHash, OrderStatus.Cancelled); const tx = exchangeWrapper.cancelOrderAsync(signedOrder, makerAddress); return expect(tx).to.revertWith(expectedError); }); @@ -576,10 +567,7 @@ describe('Exchange core', () => { expirationTimeSeconds: new BigNumber(currentTimestamp).minus(10), }); const orderHash = orderHashUtils.getOrderHashHex(signedOrder); - const expectedError = new ExchangeRevertErrors.OrderStatusError( - orderHash, - OrderStatus.Expired, - ); + const expectedError = new ExchangeRevertErrors.OrderStatusError(orderHash, OrderStatus.Expired); const tx = exchangeWrapper.cancelOrderAsync(signedOrder, makerAddress); return expect(tx).to.revertWith(expectedError); }); diff --git a/contracts/exchange/test/lib_exchange_rich_error_decoder.ts b/contracts/exchange/test/lib_exchange_rich_error_decoder.ts index 4e675b18f2..7c49d6d9f0 100644 --- a/contracts/exchange/test/lib_exchange_rich_error_decoder.ts +++ b/contracts/exchange/test/lib_exchange_rich_error_decoder.ts @@ -14,10 +14,7 @@ import * as chai from 'chai'; import * as crypto from 'crypto'; import * as _ from 'lodash'; -import { - artifacts, - TestLibExchangeRichErrorDecoderContract, -} from '../src'; +import { artifacts, TestLibExchangeRichErrorDecoderContract } from '../src'; chaiSetup.configure(); const expect = chai.expect; @@ -48,20 +45,14 @@ describe('LibExchangeRichErrorDecoder', () => { return `0x${bytes}`; } - function createDecodeTest( - revertType: new(...args: any[]) => RevertError, - parameters: any[], - ) { + function createDecodeTest(revertType: new (...args: any[]) => RevertError, parameters: any[]): void { const revert = new revertType(...parameters); const encoded = revert.encode(); // Exploit the fact that `RevertError` types have the same names as their // Solidity counterparts. const endpointName = `decode${revert.name}`; - const callAsync = (encoded: string) => { - return (decoder as any)[endpointName].callAsync.call( - (decoder as any)[endpointName], - encoded, - ); + const callAsync = (_encoded: string) => { + return (decoder as any)[endpointName].callAsync.call((decoder as any)[endpointName], _encoded); }; describe(`${endpointName}()`, async () => { it('decodes encoded parameters', async () => { @@ -78,7 +69,7 @@ describe('LibExchangeRichErrorDecoder', () => { return expect(callAsync(withBadSelector)).to.revertWith('BAD_SELECTOR'); }); }); - }; + } (() => { const errorCode = ExchangeRevertErrors.SignatureErrorCode.Illegal; @@ -86,212 +77,91 @@ describe('LibExchangeRichErrorDecoder', () => { const signer = addressUtils.generatePseudoRandomAddress(); const signature = generateRandomBytes(SIGNATURE_LENGTH); const errorData = generateRandomBytes(ERROR_DATA_LENGTH); - createDecodeTest( - ExchangeRevertErrors.SignatureError, - [ - errorCode, - orderHash, - signer, - signature, - ], - ); - createDecodeTest( - ExchangeRevertErrors.SignatureValidatorError, - [ - orderHash, - signer, - signature, - errorData, - ], - ); - createDecodeTest( - ExchangeRevertErrors.SignatureWalletError, - [ - orderHash, - signer, - signature, - errorData, - ], - ); - createDecodeTest( - ExchangeRevertErrors.SignatureOrderValidatorError, - [ - orderHash, - signer, - signature, - errorData, - ], - ); - createDecodeTest( - ExchangeRevertErrors.SignatureWalletOrderValidatorError, - [ - orderHash, - signer, - signature, - errorData, - ], - ); + createDecodeTest(ExchangeRevertErrors.SignatureError, [errorCode, orderHash, signer, signature]); + createDecodeTest(ExchangeRevertErrors.SignatureValidatorError, [orderHash, signer, signature, errorData]); + createDecodeTest(ExchangeRevertErrors.SignatureWalletError, [orderHash, signer, signature, errorData]); + createDecodeTest(ExchangeRevertErrors.SignatureOrderValidatorError, [orderHash, signer, signature, errorData]); + createDecodeTest(ExchangeRevertErrors.SignatureWalletOrderValidatorError, [ + orderHash, + signer, + signature, + errorData, + ]); })(); (() => { const orderHash = orderUtils.generatePseudoRandomOrderHash(); const orderStatus = OrderStatus.FullyFilled; - createDecodeTest( - ExchangeRevertErrors.OrderStatusError, - [ - orderHash, - orderStatus, - ], - ); + createDecodeTest(ExchangeRevertErrors.OrderStatusError, [orderHash, orderStatus]); })(); (() => { const orderHash = orderUtils.generatePseudoRandomOrderHash(); const address = addressUtils.generatePseudoRandomAddress(); - createDecodeTest( - ExchangeRevertErrors.InvalidSenderError, - [ - orderHash, - address, - ], - ); - createDecodeTest( - ExchangeRevertErrors.InvalidMakerError, - [ - orderHash, - address, - ], - ); - createDecodeTest( - ExchangeRevertErrors.InvalidTakerError, - [ - orderHash, - address, - ], - ); + createDecodeTest(ExchangeRevertErrors.InvalidSenderError, [orderHash, address]); + createDecodeTest(ExchangeRevertErrors.InvalidMakerError, [orderHash, address]); + createDecodeTest(ExchangeRevertErrors.InvalidTakerError, [orderHash, address]); })(); (() => { const errorCode = ExchangeRevertErrors.FillErrorCode.TakerOverpay; const orderHash = orderUtils.generatePseudoRandomOrderHash(); - createDecodeTest( - ExchangeRevertErrors.FillError, - [ - errorCode, - orderHash, - ], - ); + createDecodeTest(ExchangeRevertErrors.FillError, [errorCode, orderHash]); })(); (() => { const maker = addressUtils.generatePseudoRandomAddress(); const sender = addressUtils.generatePseudoRandomAddress(); const currentEpoch = generatePseudoRandomSalt(); - createDecodeTest( - ExchangeRevertErrors.OrderEpochError, - [ - maker, - sender, - currentEpoch, - ], - ); + createDecodeTest(ExchangeRevertErrors.OrderEpochError, [maker, sender, currentEpoch]); })(); (() => { const assetProxyAddress = addressUtils.generatePseudoRandomAddress(); - createDecodeTest( - ExchangeRevertErrors.AssetProxyExistsError, - [ - assetProxyAddress, - ], - ); + createDecodeTest(ExchangeRevertErrors.AssetProxyExistsError, [assetProxyAddress]); })(); (() => { const errorCode = ExchangeRevertErrors.AssetProxyDispatchErrorCode.UnknownAssetProxy; const orderHash = orderUtils.generatePseudoRandomOrderHash(); const assetData = generateRandomBytes(ASSET_DATA_LENGTH); - createDecodeTest( - ExchangeRevertErrors.AssetProxyDispatchError, - [ - errorCode, - orderHash, - assetData, - ], - ); + createDecodeTest(ExchangeRevertErrors.AssetProxyDispatchError, [errorCode, orderHash, assetData]); })(); (() => { const orderHash = orderUtils.generatePseudoRandomOrderHash(); const assetData = generateRandomBytes(ASSET_DATA_LENGTH); const errorData = generateRandomBytes(ERROR_DATA_LENGTH); - createDecodeTest( - ExchangeRevertErrors.AssetProxyTransferError, - [ - orderHash, - assetData, - errorData, - ], - ); + createDecodeTest(ExchangeRevertErrors.AssetProxyTransferError, [orderHash, assetData, errorData]); })(); (() => { const leftOrderHash = orderUtils.generatePseudoRandomOrderHash(); const rightOrderHash = orderUtils.generatePseudoRandomOrderHash(); - createDecodeTest( - ExchangeRevertErrors.NegativeSpreadError, - [ - leftOrderHash, - rightOrderHash, - ], - ); + createDecodeTest(ExchangeRevertErrors.NegativeSpreadError, [leftOrderHash, rightOrderHash]); })(); (() => { const errorCode = ExchangeRevertErrors.TransactionErrorCode.AlreadyExecuted; const transactionHash = orderUtils.generatePseudoRandomOrderHash(); - createDecodeTest( - ExchangeRevertErrors.TransactionError, - [ - errorCode, - transactionHash, - ], - ); + createDecodeTest(ExchangeRevertErrors.TransactionError, [errorCode, transactionHash]); })(); (() => { const transactionHash = orderUtils.generatePseudoRandomOrderHash(); const signer = addressUtils.generatePseudoRandomAddress(); const signature = generateRandomBytes(SIGNATURE_LENGTH); - createDecodeTest( - ExchangeRevertErrors.TransactionSignatureError, - [ - transactionHash, - signer, - signature, - ], - ); + createDecodeTest(ExchangeRevertErrors.TransactionSignatureError, [transactionHash, signer, signature]); })(); (() => { const transactionHash = orderUtils.generatePseudoRandomOrderHash(); const errorData = generateRandomBytes(ERROR_DATA_LENGTH); - createDecodeTest( - ExchangeRevertErrors.TransactionExecutionError, - [ - transactionHash, - errorData, - ], - ); + createDecodeTest(ExchangeRevertErrors.TransactionExecutionError, [transactionHash, errorData]); })(); (() => { const orderHash = orderUtils.generatePseudoRandomOrderHash(); - createDecodeTest( - ExchangeRevertErrors.IncompleteFillError, - [ - orderHash, - ], - ); + createDecodeTest(ExchangeRevertErrors.IncompleteFillError, [orderHash]); })(); }); diff --git a/contracts/exchange/test/match_orders.ts b/contracts/exchange/test/match_orders.ts index e76b2d513c..d495704263 100644 --- a/contracts/exchange/test/match_orders.ts +++ b/contracts/exchange/test/match_orders.ts @@ -1127,10 +1127,7 @@ describe('matchOrders', () => { // Cancel left order await exchangeWrapper.cancelOrderAsync(signedOrderLeft, signedOrderLeft.makerAddress); // Match orders - const expectedError = new ExchangeRevertErrors.OrderStatusError( - orderHashHexLeft, - OrderStatus.Cancelled, - ); + const expectedError = new ExchangeRevertErrors.OrderStatusError(orderHashHexLeft, OrderStatus.Cancelled); const tx = exchangeWrapper.matchOrdersAsync(signedOrderLeft, signedOrderRight, takerAddress); return expect(tx).to.revertWith(expectedError); }); @@ -1149,10 +1146,7 @@ describe('matchOrders', () => { // Cancel right order await exchangeWrapper.cancelOrderAsync(signedOrderRight, signedOrderRight.makerAddress); // Match orders - const expectedError = new ExchangeRevertErrors.OrderStatusError( - orderHashHexRight, - OrderStatus.Cancelled, - ); + const expectedError = new ExchangeRevertErrors.OrderStatusError(orderHashHexRight, OrderStatus.Cancelled); const tx = exchangeWrapper.matchOrdersAsync(signedOrderLeft, signedOrderRight, takerAddress); return expect(tx).to.revertWith(expectedError); }); diff --git a/contracts/exchange/test/wrapper.ts b/contracts/exchange/test/wrapper.ts index e33ce20524..06878fe6aa 100644 --- a/contracts/exchange/test/wrapper.ts +++ b/contracts/exchange/test/wrapper.ts @@ -213,10 +213,7 @@ describe('Exchange wrappers', () => { expirationTimeSeconds: new BigNumber(currentTimestamp).minus(10), }); const orderHashHex = orderHashUtils.getOrderHashHex(signedOrder); - const expectedError = new ExchangeRevertErrors.OrderStatusError( - orderHashHex, - OrderStatus.Expired, - ); + const expectedError = new ExchangeRevertErrors.OrderStatusError(orderHashHex, OrderStatus.Expired); const tx = exchangeWrapper.fillOrKillOrderAsync(signedOrder, takerAddress); return expect(tx).to.revertWith(expectedError); }); @@ -597,10 +594,7 @@ describe('Exchange wrappers', () => { await exchangeWrapper.fillOrKillOrderAsync(signedOrders[0], takerAddress); const orderHashHex = orderHashUtils.getOrderHashHex(signedOrders[0]); - const expectedError = new ExchangeRevertErrors.OrderStatusError( - orderHashHex, - OrderStatus.FullyFilled, - ); + const expectedError = new ExchangeRevertErrors.OrderStatusError(orderHashHex, OrderStatus.FullyFilled); const tx = exchangeWrapper.batchFillOrKillOrdersAsync(signedOrders, takerAddress, { takerAssetFillAmounts, }); diff --git a/contracts/utils/contracts/src/mixins/MRichErrors.sol b/contracts/utils/contracts/src/mixins/MRichErrors.sol index 7af2e9a4e8..0f86eb907e 100644 --- a/contracts/utils/contracts/src/mixins/MRichErrors.sol +++ b/contracts/utils/contracts/src/mixins/MRichErrors.sol @@ -20,6 +20,7 @@ pragma solidity ^0.5.5; import "./MRichErrorTypes.sol"; + contract MRichErrors is MRichErrorTypes { diff --git a/packages/order-utils/src/eip712_utils.ts b/packages/order-utils/src/eip712_utils.ts index f38c24231a..aa482c575e 100644 --- a/packages/order-utils/src/eip712_utils.ts +++ b/packages/order-utils/src/eip712_utils.ts @@ -107,7 +107,6 @@ export const eip712Utils = { name: constants.COORDINATOR_DOMAIN_NAME, version: constants.COORDINATOR_DOMAIN_VERSION, verifyingContractAddress, - chainId: transaction.chainId, }; const transactionHash = transactionHashUtils.getTransactionHashHex(transaction); const approval = {