Fix tests
This commit is contained in:
parent
d1eb414749
commit
90ac5ec577
@ -136,61 +136,27 @@ contract LibExchangeRichErrorDecoder {
|
|||||||
orderStatus = LibOrder.OrderStatus(_orderStatus);
|
orderStatus = LibOrder.OrderStatus(_orderStatus);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @dev Decompose an ABI-encoded InvalidSenderError.
|
/// @dev Decompose an ABI-encoded OrderStatusError.
|
||||||
/// @param encoded ABI-encoded revert error.
|
/// @param encoded ABI-encoded revert error.
|
||||||
|
/// @return errorCode Error code that corresponds to invalid maker, taker, or sender.
|
||||||
/// @return orderHash The order hash.
|
/// @return orderHash The order hash.
|
||||||
/// @return senderAddress The sender.
|
/// @return contextAddress The maker, taker, or sender address
|
||||||
function decodeInvalidSenderError(bytes memory encoded)
|
function decodeExchangeInvalidContextError(bytes memory encoded)
|
||||||
public
|
public
|
||||||
pure
|
pure
|
||||||
returns (
|
returns (
|
||||||
|
LibExchangeRichErrors.ExchangeContextErrorCodes errorCode,
|
||||||
bytes32 orderHash,
|
bytes32 orderHash,
|
||||||
address senderAddress
|
address contextAddress
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
_assertSelectorBytes(encoded, LibExchangeRichErrors.InvalidSenderErrorSelector());
|
_assertSelectorBytes(encoded, LibExchangeRichErrors.ExchangeInvalidContextErrorSelector());
|
||||||
(orderHash, senderAddress) = abi.decode(
|
uint8 _errorCode;
|
||||||
|
(_errorCode, orderHash, contextAddress) = abi.decode(
|
||||||
encoded.sliceDestructive(4, encoded.length),
|
encoded.sliceDestructive(4, encoded.length),
|
||||||
(bytes32, address)
|
(uint8, 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)
|
|
||||||
);
|
);
|
||||||
|
errorCode = LibExchangeRichErrors.ExchangeContextErrorCodes(_errorCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @dev Decompose an ABI-encoded FillError.
|
/// @dev Decompose an ABI-encoded FillError.
|
||||||
|
@ -51,8 +51,8 @@ contract TestExchangeInternals is
|
|||||||
_assertValidMatch(
|
_assertValidMatch(
|
||||||
leftOrder,
|
leftOrder,
|
||||||
rightOrder,
|
rightOrder,
|
||||||
getOrderInfo(leftOrder),
|
leftOrder.getTypedDataHash(EIP712_EXCHANGE_DOMAIN_HASH),
|
||||||
getOrderInfo(rightOrder)
|
rightOrder.getTypedDataHash(EIP712_EXCHANGE_DOMAIN_HASH)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -493,7 +493,11 @@ blockchainTests.resets('Exchange core', () => {
|
|||||||
|
|
||||||
it('should revert if not sent by maker', async () => {
|
it('should revert if not sent by maker', async () => {
|
||||||
const orderHash = orderHashUtils.getOrderHashHex(signedOrder);
|
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);
|
const tx = exchangeWrapper.cancelOrderAsync(signedOrder, takerAddress);
|
||||||
return expect(tx).to.revertWith(expectedError);
|
return expect(tx).to.revertWith(expectedError);
|
||||||
});
|
});
|
||||||
|
@ -387,7 +387,8 @@ blockchainTests('Isolated fillOrder() tests', env => {
|
|||||||
const order = createOrder({
|
const order = createOrder({
|
||||||
takerAddress: randomAddress(),
|
takerAddress: randomAddress(),
|
||||||
});
|
});
|
||||||
const expectedError = new ExchangeRevertErrors.InvalidTakerError(
|
const expectedError = new ExchangeRevertErrors.ExchangeInvalidContextError(
|
||||||
|
ExchangeRevertErrors.ExchangeContextErrorCodes.InvalidTaker,
|
||||||
exchange.getOrderHash(order),
|
exchange.getOrderHash(order),
|
||||||
takerAddress,
|
takerAddress,
|
||||||
);
|
);
|
||||||
@ -398,7 +399,8 @@ blockchainTests('Isolated fillOrder() tests', env => {
|
|||||||
const order = createOrder({
|
const order = createOrder({
|
||||||
senderAddress: randomAddress(),
|
senderAddress: randomAddress(),
|
||||||
});
|
});
|
||||||
const expectedError = new ExchangeRevertErrors.InvalidSenderError(
|
const expectedError = new ExchangeRevertErrors.ExchangeInvalidContextError(
|
||||||
|
ExchangeRevertErrors.ExchangeContextErrorCodes.InvalidSender,
|
||||||
exchange.getOrderHash(order),
|
exchange.getOrderHash(order),
|
||||||
takerAddress,
|
takerAddress,
|
||||||
);
|
);
|
||||||
|
@ -79,9 +79,21 @@ blockchainTests.resets('LibExchangeRichErrorDecoder', ({ provider, txDefaults })
|
|||||||
(() => {
|
(() => {
|
||||||
const orderHash = orderUtils.generatePseudoRandomOrderHash();
|
const orderHash = orderUtils.generatePseudoRandomOrderHash();
|
||||||
const address = addressUtils.generatePseudoRandomAddress();
|
const address = addressUtils.generatePseudoRandomAddress();
|
||||||
createDecodeTest(ExchangeRevertErrors.InvalidSenderError, [orderHash, address]);
|
createDecodeTest(ExchangeRevertErrors.ExchangeInvalidContextError, [
|
||||||
createDecodeTest(ExchangeRevertErrors.InvalidMakerError, [orderHash, address]);
|
ExchangeRevertErrors.ExchangeContextErrorCodes.InvalidMaker,
|
||||||
createDecodeTest(ExchangeRevertErrors.InvalidTakerError, [orderHash, address]);
|
orderHash,
|
||||||
|
address,
|
||||||
|
]);
|
||||||
|
createDecodeTest(ExchangeRevertErrors.ExchangeInvalidContextError, [
|
||||||
|
ExchangeRevertErrors.ExchangeContextErrorCodes.InvalidTaker,
|
||||||
|
orderHash,
|
||||||
|
address,
|
||||||
|
]);
|
||||||
|
createDecodeTest(ExchangeRevertErrors.ExchangeInvalidContextError, [
|
||||||
|
ExchangeRevertErrors.ExchangeContextErrorCodes.InvalidSender,
|
||||||
|
orderHash,
|
||||||
|
address,
|
||||||
|
]);
|
||||||
})();
|
})();
|
||||||
|
|
||||||
(() => {
|
(() => {
|
||||||
|
@ -423,7 +423,8 @@ blockchainTests.resets('Exchange transactions', env => {
|
|||||||
const data = exchangeDataEncoder.encodeOrdersToExchangeData(ExchangeFunctionName.CancelOrder, orders);
|
const data = exchangeDataEncoder.encodeOrdersToExchangeData(ExchangeFunctionName.CancelOrder, orders);
|
||||||
const transaction = await takerTransactionFactory.newSignedTransactionAsync({ data });
|
const transaction = await takerTransactionFactory.newSignedTransactionAsync({ data });
|
||||||
const transactionHashHex = transactionHashUtils.getTransactionHashHex(transaction);
|
const transactionHashHex = transactionHashUtils.getTransactionHashHex(transaction);
|
||||||
const nestedError = new ExchangeRevertErrors.InvalidMakerError(
|
const nestedError = new ExchangeRevertErrors.ExchangeInvalidContextError(
|
||||||
|
ExchangeRevertErrors.ExchangeContextErrorCodes.InvalidMaker,
|
||||||
orderHashUtils.getOrderHashHex(order),
|
orderHashUtils.getOrderHashHex(order),
|
||||||
takerAddress,
|
takerAddress,
|
||||||
).encode();
|
).encode();
|
||||||
@ -479,7 +480,8 @@ blockchainTests.resets('Exchange transactions', env => {
|
|||||||
);
|
);
|
||||||
const transaction = await takerTransactionFactory.newSignedTransactionAsync({ data });
|
const transaction = await takerTransactionFactory.newSignedTransactionAsync({ data });
|
||||||
const transactionHashHex = transactionHashUtils.getTransactionHashHex(transaction);
|
const transactionHashHex = transactionHashUtils.getTransactionHashHex(transaction);
|
||||||
const nestedError = new ExchangeRevertErrors.InvalidMakerError(
|
const nestedError = new ExchangeRevertErrors.ExchangeInvalidContextError(
|
||||||
|
ExchangeRevertErrors.ExchangeContextErrorCodes.InvalidMaker,
|
||||||
orderHashUtils.getOrderHashHex(orders[0]),
|
orderHashUtils.getOrderHashHex(orders[0]),
|
||||||
takerAddress,
|
takerAddress,
|
||||||
).encode();
|
).encode();
|
||||||
|
@ -1045,7 +1045,10 @@ function fillErrorToRevertError(order: Order, error: FillOrderError): RevertErro
|
|||||||
const orderHash = orderHashUtils.getOrderHashHex(order);
|
const orderHash = orderHashUtils.getOrderHashHex(order);
|
||||||
switch (error) {
|
switch (error) {
|
||||||
case FillOrderError.InvalidTaker:
|
case FillOrderError.InvalidTaker:
|
||||||
return new ExchangeRevertErrors.InvalidTakerError(orderHash);
|
return new ExchangeRevertErrors.ExchangeInvalidContextError(
|
||||||
|
ExchangeRevertErrors.ExchangeContextErrorCodes.InvalidTaker,
|
||||||
|
orderHash,
|
||||||
|
);
|
||||||
case FillOrderError.InvalidMakerAmount:
|
case FillOrderError.InvalidMakerAmount:
|
||||||
case FillOrderError.OrderUnfillable:
|
case FillOrderError.OrderUnfillable:
|
||||||
return new ExchangeRevertErrors.OrderStatusError(orderHash);
|
return new ExchangeRevertErrors.OrderStatusError(orderHash);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user