Rebased against 3.0.

Run prettier/linter.
This commit is contained in:
Lawrence Forman 2019-04-23 23:50:48 -04:00 committed by Amir Bandeali
parent a1293f160f
commit 61bdbd2d74
7 changed files with 39 additions and 195 deletions

View File

@ -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);

View File

@ -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);
});

View File

@ -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]);
})();
});

View File

@ -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);
});

View File

@ -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,
});

View File

@ -20,6 +20,7 @@ pragma solidity ^0.5.5;
import "./MRichErrorTypes.sol";
contract MRichErrors is
MRichErrorTypes
{

View File

@ -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 = {