In @0x/contracts-exchange
: Add more tests for LibExchangeRichErrorDecoder
.
This commit is contained in:
committed by
Amir Bandeali
parent
fdb6bee65f
commit
576242551f
@@ -220,7 +220,7 @@ contract LibExchangeRichErrorDecoder is
|
||||
{
|
||||
_assertSelectorBytes(encoded, FILL_ERROR_SELECTOR);
|
||||
errorCode = FillErrorCodes(_readErrorParameterAsUint256(encoded, 0));
|
||||
orderHash = _readErrorParameterAsBytes32(encoded, 0);
|
||||
orderHash = _readErrorParameterAsBytes32(encoded, 1);
|
||||
}
|
||||
|
||||
/// @dev Decompose an ABI-encoded OrderEpochError.
|
||||
|
@@ -8,8 +8,8 @@ import {
|
||||
web3Wrapper,
|
||||
} from '@0x/contracts-test-utils';
|
||||
import { BlockchainLifecycle } from '@0x/dev-utils';
|
||||
import { assetDataUtils, ExchangeRevertErrors, orderHashUtils } from '@0x/order-utils';
|
||||
import { RevertError } from '@0x/utils';
|
||||
import { ExchangeRevertErrors, generatePseudoRandomSalt } from '@0x/order-utils';
|
||||
import { BigNumber, RevertError } from '@0x/utils';
|
||||
import * as chai from 'chai';
|
||||
import * as crypto from 'crypto';
|
||||
import * as _ from 'lodash';
|
||||
@@ -24,6 +24,9 @@ const expect = chai.expect;
|
||||
const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper);
|
||||
|
||||
describe.only('LibExchangeRichErrorDecoder', () => {
|
||||
const SIGNATURE_LENGTH = 66;
|
||||
const ASSET_DATA_LENGTH = 36;
|
||||
const ERROR_DATA_LENGTH = 100;
|
||||
let decoder: TestLibExchangeRichErrorDecoderContract;
|
||||
|
||||
before(async () => {
|
||||
@@ -51,6 +54,8 @@ describe.only('LibExchangeRichErrorDecoder', () => {
|
||||
) {
|
||||
const revert = new revertType(...parameters);
|
||||
const encoded = revert.encode();
|
||||
// Exploit the fact that `RevertError` types have the smae name as their
|
||||
// Solidity counterparts.
|
||||
const endpointName = `decode${revert.name}`;
|
||||
const callAsync = (encoded: string) => {
|
||||
return (decoder as any)[endpointName].callAsync.call(
|
||||
@@ -60,7 +65,10 @@ describe.only('LibExchangeRichErrorDecoder', () => {
|
||||
};
|
||||
describe(`${endpointName}()`, async () => {
|
||||
it('decodes encoded parameters', async () => {
|
||||
const results = await callAsync(encoded);
|
||||
let results = await callAsync(encoded);
|
||||
if (!_.isArray(results)) {
|
||||
results = [results];
|
||||
}
|
||||
return expect(results).to.deep.equal(parameters);
|
||||
});
|
||||
it('reverts if selector does not match', async () => {
|
||||
@@ -76,8 +84,8 @@ describe.only('LibExchangeRichErrorDecoder', () => {
|
||||
const errorCode = ExchangeRevertErrors.SignatureErrorCode.Illegal;
|
||||
const orderHash = orderUtils.generatePseudoRandomOrderHash();
|
||||
const signer = addressUtils.generatePseudoRandomAddress();
|
||||
const signature = generateRandomBytes(66);
|
||||
const errorData = generateRandomBytes(4+32+32+32);
|
||||
const signature = generateRandomBytes(SIGNATURE_LENGTH);
|
||||
const errorData = generateRandomBytes(ERROR_DATA_LENGTH);
|
||||
createDecodeTest(
|
||||
ExchangeRevertErrors.SignatureError,
|
||||
[
|
||||
@@ -124,4 +132,118 @@ describe.only('LibExchangeRichErrorDecoder', () => {
|
||||
],
|
||||
);
|
||||
})();
|
||||
|
||||
(() => {
|
||||
const orderHash = orderUtils.generatePseudoRandomOrderHash();
|
||||
const orderStatus = OrderStatus.FullyFilled;
|
||||
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,
|
||||
],
|
||||
);
|
||||
})();
|
||||
|
||||
(() => {
|
||||
const errorCode = ExchangeRevertErrors.FillErrorCode.TakerOverpay;
|
||||
const orderHash = orderUtils.generatePseudoRandomOrderHash();
|
||||
createDecodeTest(
|
||||
ExchangeRevertErrors.FillError,
|
||||
[
|
||||
errorCode,
|
||||
orderHash,
|
||||
],
|
||||
);
|
||||
})();
|
||||
|
||||
(() => {
|
||||
const maker = addressUtils.generatePseudoRandomAddress();
|
||||
const sender = addressUtils.generatePseudoRandomAddress();
|
||||
const currentEpoch = generatePseudoRandomSalt();
|
||||
createDecodeTest(
|
||||
ExchangeRevertErrors.OrderEpochError,
|
||||
[
|
||||
maker,
|
||||
sender,
|
||||
currentEpoch,
|
||||
],
|
||||
);
|
||||
})();
|
||||
|
||||
(() => {
|
||||
const assetProxyAddress = addressUtils.generatePseudoRandomAddress();
|
||||
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,
|
||||
],
|
||||
);
|
||||
})();
|
||||
|
||||
(() => {
|
||||
const orderHash = orderUtils.generatePseudoRandomOrderHash();
|
||||
const assetData = generateRandomBytes(ASSET_DATA_LENGTH);
|
||||
const errorData = generateRandomBytes(ERROR_DATA_LENGTH);
|
||||
createDecodeTest(
|
||||
ExchangeRevertErrors.AssetProxyTransferError,
|
||||
[
|
||||
orderHash,
|
||||
assetData,
|
||||
errorData,
|
||||
],
|
||||
);
|
||||
})();
|
||||
|
||||
(() => {
|
||||
const leftOrderHash = orderUtils.generatePseudoRandomOrderHash();
|
||||
const rightOrderHash = orderUtils.generatePseudoRandomOrderHash();
|
||||
createDecodeTest(
|
||||
ExchangeRevertErrors.NegativeSpreadError,
|
||||
[
|
||||
leftOrderHash,
|
||||
rightOrderHash,
|
||||
],
|
||||
);
|
||||
})();
|
||||
});
|
||||
|
Reference in New Issue
Block a user