In @0x/contracts-exchange: Change parameter order and naming of some rich revert errors.

In `@0x/order-utils`: Change parameter order for `OrderStatusError`.
This commit is contained in:
Lawrence Forman
2019-04-23 11:46:02 -04:00
committed by Amir Bandeali
parent fdaee1375c
commit d942c47f08
8 changed files with 71 additions and 44 deletions

View File

@@ -331,8 +331,8 @@ contract MixinExchangeCore is
// An order can only be filled if its status is FILLABLE.
if (orderInfo.orderStatus != uint8(OrderStatus.FILLABLE)) {
rrevert(OrderStatusError(
OrderStatus(orderInfo.orderStatus),
orderInfo.orderHash
orderInfo.orderHash,
OrderStatus(orderInfo.orderStatus)
));
}
@@ -441,7 +441,10 @@ contract MixinExchangeCore is
// Ensure order is valid
// An order can only be cancelled if its status is FILLABLE.
if (orderInfo.orderStatus != uint8(OrderStatus.FILLABLE)) {
rrevert(OrderStatusError(OrderStatus(orderInfo.orderStatus), orderInfo.orderHash));
rrevert(OrderStatusError(
orderInfo.orderHash,
OrderStatus(orderInfo.orderStatus)
));
}
// Validate sender is allowed to cancel this order

View File

@@ -29,8 +29,8 @@ contract MixinExchangeRichErrors is
{
// solhint-disable func-name-mixedcase
function SignatureError(
SignatureErrorCodes error,
bytes32 orderHash,
SignatureErrorCodes errorCode,
bytes32 hash,
address signer,
bytes memory signature
)
@@ -40,15 +40,15 @@ contract MixinExchangeRichErrors is
{
return abi.encodeWithSelector(
SIGNATURE_ERROR_SELECTOR,
error,
orderHash,
errorCode,
hash,
signer,
signature
);
}
function SignatureValidatorError(
bytes32 orderHash,
bytes32 hash,
address signer,
bytes memory signature,
bytes memory errorData
@@ -59,7 +59,7 @@ contract MixinExchangeRichErrors is
{
return abi.encodeWithSelector(
SIGNATURE_VALIDATOR_ERROR_SELECTOR,
orderHash,
hash,
signer,
signature,
errorData
@@ -67,7 +67,7 @@ contract MixinExchangeRichErrors is
}
function SignatureWalletError(
bytes32 orderHash,
bytes32 hash,
address signer,
bytes memory signature,
bytes memory errorData
@@ -78,7 +78,7 @@ contract MixinExchangeRichErrors is
{
return abi.encodeWithSelector(
SIGNATURE_WALLET_ERROR_SELECTOR,
orderHash,
hash,
signer,
signature,
errorData
@@ -124,8 +124,8 @@ contract MixinExchangeRichErrors is
}
function OrderStatusError(
LibOrder.OrderStatus orderStatus,
bytes32 orderHash
bytes32 orderHash,
LibOrder.OrderStatus orderStatus
)
internal
pure
@@ -133,8 +133,8 @@ contract MixinExchangeRichErrors is
{
return abi.encodeWithSelector(
ORDER_STATUS_ERROR_SELECTOR,
orderStatus,
orderHash
orderHash,
orderStatus
);
}
@@ -169,7 +169,7 @@ contract MixinExchangeRichErrors is
}
function FillError(
FillErrorCodes error,
FillErrorCodes errorCode,
bytes32 orderHash
)
internal
@@ -178,7 +178,7 @@ contract MixinExchangeRichErrors is
{
return abi.encodeWithSelector(
FILL_ERROR_SELECTOR,
error,
errorCode,
orderHash
);
}
@@ -229,7 +229,7 @@ contract MixinExchangeRichErrors is
}
function AssetProxyDispatchError(
AssetProxyDispatchErrorCodes error,
AssetProxyDispatchErrorCodes errorCode,
bytes32 orderHash,
bytes memory assetData
)
@@ -239,7 +239,7 @@ contract MixinExchangeRichErrors is
{
return abi.encodeWithSelector(
ASSET_PROXY_DISPATCH_ERROR_SELECTOR,
error,
errorCode,
orderHash,
assetData
);
@@ -278,7 +278,7 @@ contract MixinExchangeRichErrors is
}
function TransactionError(
TransactionErrorCodes error,
TransactionErrorCodes errorCode,
bytes32 transactionHash
)
internal
@@ -287,7 +287,7 @@ contract MixinExchangeRichErrors is
{
return abi.encodeWithSelector(
TRANSACTION_ERROR_SELECTOR,
error,
errorCode,
transactionHash
);
}

View File

@@ -55,8 +55,8 @@ contract MExchangeRichErrors is
bytes4(keccak256("SignatureError(uint8,bytes32,address,bytes)"));
function SignatureError(
SignatureErrorCodes error,
bytes32 orderHash,
SignatureErrorCodes errorCode,
bytes32 hash,
address signer,
bytes memory signature
)
@@ -68,7 +68,7 @@ contract MExchangeRichErrors is
bytes4(keccak256("SignatureValidatorError(bytes32,address,bytes,bytes)"));
function SignatureValidatorError(
bytes32 orderHash,
bytes32 hash,
address signer,
bytes memory signature,
bytes memory errorData
@@ -81,7 +81,7 @@ contract MExchangeRichErrors is
bytes4(keccak256("SignatureWalletError(bytes32,address,bytes,bytes)"));
function SignatureWalletError(
bytes32 orderHash,
bytes32 hash,
address signer,
bytes memory signature,
bytes memory errorData
@@ -117,11 +117,11 @@ contract MExchangeRichErrors is
returns (bytes memory);
bytes4 internal constant ORDER_STATUS_ERROR_SELECTOR =
bytes4(keccak256("OrderStatusError(uint8,bytes32)"));
bytes4(keccak256("OrderStatusError(bytes32,uint8)"));
function OrderStatusError(
LibOrder.OrderStatus orderStatus,
bytes32 orderHash
bytes32 orderHash,
LibOrder.OrderStatus orderStatus
)
internal
pure
@@ -153,7 +153,7 @@ contract MExchangeRichErrors is
bytes4(keccak256("FillError(uint8,bytes32)"));
function FillError(
FillErrorCodes error,
FillErrorCodes errorCode,
bytes32 orderHash
)
internal
@@ -197,7 +197,7 @@ contract MExchangeRichErrors is
bytes4(keccak256("AssetProxyDispatchError(uint8,bytes32,bytes)"));
function AssetProxyDispatchError(
AssetProxyDispatchErrorCodes error,
AssetProxyDispatchErrorCodes errorCode,
bytes32 orderHash,
bytes memory assetData
)
@@ -232,7 +232,7 @@ contract MExchangeRichErrors is
bytes4(keccak256("TransactionError(uint8,bytes32)"));
function TransactionError(
TransactionErrorCodes error,
TransactionErrorCodes errorCode,
bytes32 transactionHash
)
internal

View File

@@ -277,7 +277,10 @@ describe('Exchange core', () => {
signedOrder = await orderFactory.newSignedOrderAsync();
const orderHashHex = orderHashUtils.getOrderHashHex(signedOrder);
await exchangeWrapper.fillOrderAsync(signedOrder, takerAddress);
const expectedError = new ExchangeRevertErrors.OrderStatusError(OrderStatus.FullyFilled, orderHashHex);
const expectedError = new ExchangeRevertErrors.OrderStatusError(
orderHashHex,
OrderStatus.FullyFilled,
);
const tx = exchangeWrapper.fillOrderAsync(signedOrder, takerAddress);
return expect(tx).to.revertWith(expectedError);
});
@@ -510,8 +513,8 @@ describe('Exchange core', () => {
});
const orderHash = orderHashUtils.getOrderHashHex(signedOrder);
const expectedError = new ExchangeRevertErrors.OrderStatusError(
OrderStatus.InvalidMakerAssetAmount,
orderHash,
OrderStatus.InvalidMakerAssetAmount,
);
const tx = exchangeWrapper.cancelOrderAsync(signedOrder, makerAddress);
return expect(tx).to.revertWith(expectedError);
@@ -523,8 +526,8 @@ describe('Exchange core', () => {
});
const orderHash = orderHashUtils.getOrderHashHex(signedOrder);
const expectedError = new ExchangeRevertErrors.OrderStatusError(
OrderStatus.InvalidTakerAssetAmount,
orderHash,
OrderStatus.InvalidTakerAssetAmount,
);
const tx = exchangeWrapper.cancelOrderAsync(signedOrder, makerAddress);
return expect(tx).to.revertWith(expectedError);
@@ -533,7 +536,10 @@ 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(OrderStatus.Cancelled, orderHash);
const expectedError = new ExchangeRevertErrors.OrderStatusError(
orderHash,
OrderStatus.Cancelled,
);
const tx = exchangeWrapper.fillOrderAsync(signedOrder, takerAddress, {
takerAssetFillAmount: signedOrder.takerAssetAmount.div(2),
});
@@ -558,7 +564,10 @@ 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(OrderStatus.Cancelled, orderHash);
const expectedError = new ExchangeRevertErrors.OrderStatusError(
orderHash,
OrderStatus.Cancelled,
);
const tx = exchangeWrapper.cancelOrderAsync(signedOrder, makerAddress);
return expect(tx).to.revertWith(expectedError);
});
@@ -569,7 +578,10 @@ describe('Exchange core', () => {
expirationTimeSeconds: new BigNumber(currentTimestamp).minus(10),
});
const orderHash = orderHashUtils.getOrderHashHex(signedOrder);
const expectedError = new ExchangeRevertErrors.OrderStatusError(OrderStatus.Expired, orderHash);
const expectedError = new ExchangeRevertErrors.OrderStatusError(
orderHash,
OrderStatus.Expired,
);
const tx = exchangeWrapper.cancelOrderAsync(signedOrder, makerAddress);
return expect(tx).to.revertWith(expectedError);
});

View File

@@ -1127,7 +1127,10 @@ describe('matchOrders', () => {
// Cancel left order
await exchangeWrapper.cancelOrderAsync(signedOrderLeft, signedOrderLeft.makerAddress);
// Match orders
const expectedError = new ExchangeRevertErrors.OrderStatusError(OrderStatus.Cancelled, orderHashHexLeft);
const expectedError = new ExchangeRevertErrors.OrderStatusError(
orderHashHexLeft,
OrderStatus.Cancelled,
);
const tx = exchangeWrapper.matchOrdersAsync(signedOrderLeft, signedOrderRight, takerAddress);
return expect(tx).to.revertWith(expectedError);
});
@@ -1146,7 +1149,10 @@ describe('matchOrders', () => {
// Cancel right order
await exchangeWrapper.cancelOrderAsync(signedOrderRight, signedOrderRight.makerAddress);
// Match orders
const expectedError = new ExchangeRevertErrors.OrderStatusError(OrderStatus.Cancelled, orderHashHexRight);
const expectedError = new ExchangeRevertErrors.OrderStatusError(
orderHashHexRight,
OrderStatus.Cancelled,
);
const tx = exchangeWrapper.matchOrdersAsync(signedOrderLeft, signedOrderRight, takerAddress);
return expect(tx).to.revertWith(expectedError);
});

View File

@@ -940,7 +940,7 @@ function validationErrorToRevertError(order: Order, reason: RevertReason): Rever
case RevertReason.InvalidTaker:
return new ExchangeRevertErrors.InvalidTakerError(orderHash);
case RevertReason.OrderUnfillable:
return new ExchangeRevertErrors.OrderStatusError(undefined, orderHash);
return new ExchangeRevertErrors.OrderStatusError(orderHash);
case RevertReason.InvalidTakerAmount:
return new ExchangeRevertErrors.FillError(ExchangeRevertErrors.FillErrorCode.InvalidTakerAmount, orderHash);
case RevertReason.TakerOverpay:

View File

@@ -213,7 +213,10 @@ describe('Exchange wrappers', () => {
expirationTimeSeconds: new BigNumber(currentTimestamp).minus(10),
});
const orderHashHex = orderHashUtils.getOrderHashHex(signedOrder);
const expectedError = new ExchangeRevertErrors.OrderStatusError(OrderStatus.Expired, orderHashHex);
const expectedError = new ExchangeRevertErrors.OrderStatusError(
orderHashHex,
OrderStatus.Expired,
);
const tx = exchangeWrapper.fillOrKillOrderAsync(signedOrder, takerAddress);
return expect(tx).to.revertWith(expectedError);
});
@@ -594,7 +597,10 @@ describe('Exchange wrappers', () => {
await exchangeWrapper.fillOrKillOrderAsync(signedOrders[0], takerAddress);
const orderHashHex = orderHashUtils.getOrderHashHex(signedOrders[0]);
const expectedError = new ExchangeRevertErrors.OrderStatusError(OrderStatus.FullyFilled, orderHashHex);
const expectedError = new ExchangeRevertErrors.OrderStatusError(
orderHashHex,
OrderStatus.FullyFilled,
);
const tx = exchangeWrapper.batchFillOrKillOrdersAsync(signedOrders, takerAddress, {
takerAssetFillAmounts,
});

View File

@@ -85,8 +85,8 @@ export class SignatureWalletOrderValidatorError extends RevertError {
}
export class OrderStatusError extends RevertError {
constructor(status?: OrderStatus, orderHash?: string) {
super('OrderStatusError(uint8 status, bytes32 orderHash)', { status, orderHash });
constructor(orderHash?: string, status?: OrderStatus) {
super('OrderStatusError(bytes32 orderHash, uint8 status)', { orderHash, status });
}
}