Fix tests

This commit is contained in:
Amir Bandeali 2019-09-03 19:03:27 -07:00
parent d1eb414749
commit 90ac5ec577
7 changed files with 45 additions and 56 deletions

View File

@ -136,61 +136,27 @@ contract LibExchangeRichErrorDecoder {
orderStatus = LibOrder.OrderStatus(_orderStatus);
}
/// @dev Decompose an ABI-encoded InvalidSenderError.
/// @dev Decompose an ABI-encoded OrderStatusError.
/// @param encoded ABI-encoded revert error.
/// @return errorCode Error code that corresponds to invalid maker, taker, or sender.
/// @return orderHash The order hash.
/// @return senderAddress The sender.
function decodeInvalidSenderError(bytes memory encoded)
/// @return contextAddress The maker, taker, or sender address
function decodeExchangeInvalidContextError(bytes memory encoded)
public
pure
returns (
LibExchangeRichErrors.ExchangeContextErrorCodes errorCode,
bytes32 orderHash,
address senderAddress
address contextAddress
)
{
_assertSelectorBytes(encoded, LibExchangeRichErrors.InvalidSenderErrorSelector());
(orderHash, senderAddress) = abi.decode(
_assertSelectorBytes(encoded, LibExchangeRichErrors.ExchangeInvalidContextErrorSelector());
uint8 _errorCode;
(_errorCode, orderHash, contextAddress) = abi.decode(
encoded.sliceDestructive(4, encoded.length),
(bytes32, address)
);
}
/// @dev Decompose an ABI-encoded InvalidMakerError.
/// @param encoded ABI-encoded revert error.
/// @return orderHash The order hash.
/// @return makerAddress The maker of the order.
function decodeInvalidMakerError(bytes memory encoded)
public
pure
returns (
bytes32 orderHash,
address makerAddress
)
{
_assertSelectorBytes(encoded, LibExchangeRichErrors.InvalidMakerErrorSelector());
(orderHash, makerAddress) = abi.decode(
encoded.sliceDestructive(4, encoded.length),
(bytes32, address)
);
}
/// @dev Decompose an ABI-encoded InvalidTaker.
/// @param encoded ABI-encoded revert error.
/// @return orderHash The order hash.
/// @return takerAddress The taker of the order.
function decodeInvalidTakerError(bytes memory encoded)
public
pure
returns (
bytes32 orderHash,
address takerAddress
)
{
_assertSelectorBytes(encoded, LibExchangeRichErrors.InvalidTakerErrorSelector());
(orderHash, takerAddress) = abi.decode(
encoded.sliceDestructive(4, encoded.length),
(bytes32, address)
(uint8, bytes32, address)
);
errorCode = LibExchangeRichErrors.ExchangeContextErrorCodes(_errorCode);
}
/// @dev Decompose an ABI-encoded FillError.

View File

@ -51,8 +51,8 @@ contract TestExchangeInternals is
_assertValidMatch(
leftOrder,
rightOrder,
getOrderInfo(leftOrder),
getOrderInfo(rightOrder)
leftOrder.getTypedDataHash(EIP712_EXCHANGE_DOMAIN_HASH),
rightOrder.getTypedDataHash(EIP712_EXCHANGE_DOMAIN_HASH)
);
}

View File

@ -493,7 +493,11 @@ blockchainTests.resets('Exchange core', () => {
it('should revert if not sent by maker', async () => {
const orderHash = orderHashUtils.getOrderHashHex(signedOrder);
const expectedError = new ExchangeRevertErrors.InvalidMakerError(orderHash, takerAddress);
const expectedError = new ExchangeRevertErrors.ExchangeInvalidContextError(
ExchangeRevertErrors.ExchangeContextErrorCodes.InvalidMaker,
orderHash,
takerAddress,
);
const tx = exchangeWrapper.cancelOrderAsync(signedOrder, takerAddress);
return expect(tx).to.revertWith(expectedError);
});

View File

@ -387,7 +387,8 @@ blockchainTests('Isolated fillOrder() tests', env => {
const order = createOrder({
takerAddress: randomAddress(),
});
const expectedError = new ExchangeRevertErrors.InvalidTakerError(
const expectedError = new ExchangeRevertErrors.ExchangeInvalidContextError(
ExchangeRevertErrors.ExchangeContextErrorCodes.InvalidTaker,
exchange.getOrderHash(order),
takerAddress,
);
@ -398,7 +399,8 @@ blockchainTests('Isolated fillOrder() tests', env => {
const order = createOrder({
senderAddress: randomAddress(),
});
const expectedError = new ExchangeRevertErrors.InvalidSenderError(
const expectedError = new ExchangeRevertErrors.ExchangeInvalidContextError(
ExchangeRevertErrors.ExchangeContextErrorCodes.InvalidSender,
exchange.getOrderHash(order),
takerAddress,
);

View File

@ -79,9 +79,21 @@ blockchainTests.resets('LibExchangeRichErrorDecoder', ({ provider, txDefaults })
(() => {
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.ExchangeInvalidContextError, [
ExchangeRevertErrors.ExchangeContextErrorCodes.InvalidMaker,
orderHash,
address,
]);
createDecodeTest(ExchangeRevertErrors.ExchangeInvalidContextError, [
ExchangeRevertErrors.ExchangeContextErrorCodes.InvalidTaker,
orderHash,
address,
]);
createDecodeTest(ExchangeRevertErrors.ExchangeInvalidContextError, [
ExchangeRevertErrors.ExchangeContextErrorCodes.InvalidSender,
orderHash,
address,
]);
})();
(() => {

View File

@ -423,7 +423,8 @@ blockchainTests.resets('Exchange transactions', env => {
const data = exchangeDataEncoder.encodeOrdersToExchangeData(ExchangeFunctionName.CancelOrder, orders);
const transaction = await takerTransactionFactory.newSignedTransactionAsync({ data });
const transactionHashHex = transactionHashUtils.getTransactionHashHex(transaction);
const nestedError = new ExchangeRevertErrors.InvalidMakerError(
const nestedError = new ExchangeRevertErrors.ExchangeInvalidContextError(
ExchangeRevertErrors.ExchangeContextErrorCodes.InvalidMaker,
orderHashUtils.getOrderHashHex(order),
takerAddress,
).encode();
@ -479,7 +480,8 @@ blockchainTests.resets('Exchange transactions', env => {
);
const transaction = await takerTransactionFactory.newSignedTransactionAsync({ data });
const transactionHashHex = transactionHashUtils.getTransactionHashHex(transaction);
const nestedError = new ExchangeRevertErrors.InvalidMakerError(
const nestedError = new ExchangeRevertErrors.ExchangeInvalidContextError(
ExchangeRevertErrors.ExchangeContextErrorCodes.InvalidMaker,
orderHashUtils.getOrderHashHex(orders[0]),
takerAddress,
).encode();

View File

@ -1045,7 +1045,10 @@ function fillErrorToRevertError(order: Order, error: FillOrderError): RevertErro
const orderHash = orderHashUtils.getOrderHashHex(order);
switch (error) {
case FillOrderError.InvalidTaker:
return new ExchangeRevertErrors.InvalidTakerError(orderHash);
return new ExchangeRevertErrors.ExchangeInvalidContextError(
ExchangeRevertErrors.ExchangeContextErrorCodes.InvalidTaker,
orderHash,
);
case FillOrderError.InvalidMakerAmount:
case FillOrderError.OrderUnfillable:
return new ExchangeRevertErrors.OrderStatusError(orderHash);