refactor SafeMath rich errors and use them in staking libs

This commit is contained in:
Michael Zhu
2019-08-23 15:49:17 -07:00
parent cd1fc6a1f0
commit 98e5b26eb7
19 changed files with 371 additions and 174 deletions

View File

@@ -77,8 +77,8 @@ blockchainTests('Exchange core internal functions', env => {
makerAssetAmount: constants.MAX_UINT256_ROOT,
takerAssetAmount: Web3Wrapper.toBaseUnitAmount(50, 18),
});
const expectedError = new SafeMathRevertErrors.SafeMathError(
SafeMathRevertErrors.SafeMathErrorCodes.Uint256MultiplicationOverflow,
const expectedError = new SafeMathRevertErrors.Uint256BinopError(
SafeMathRevertErrors.BinopErrorCodes.MultiplicationOverflow,
leftOrder.makerAssetAmount,
rightOrder.makerAssetAmount,
);
@@ -94,8 +94,8 @@ blockchainTests('Exchange core internal functions', env => {
makerAssetAmount: Web3Wrapper.toBaseUnitAmount(50, 18),
takerAssetAmount: constants.MAX_UINT256_ROOT,
});
const expectedError = new SafeMathRevertErrors.SafeMathError(
SafeMathRevertErrors.SafeMathErrorCodes.Uint256MultiplicationOverflow,
const expectedError = new SafeMathRevertErrors.Uint256BinopError(
SafeMathRevertErrors.BinopErrorCodes.MultiplicationOverflow,
leftOrder.takerAssetAmount,
rightOrder.takerAssetAmount,
);
@@ -228,8 +228,8 @@ blockchainTests('Exchange core internal functions', env => {
makerFeePaid: constants.ZERO_AMOUNT,
takerFeePaid: constants.ZERO_AMOUNT,
};
const expectedError = new SafeMathRevertErrors.SafeMathError(
SafeMathRevertErrors.SafeMathErrorCodes.Uint256AdditionOverflow,
const expectedError = new SafeMathRevertErrors.Uint256BinopError(
SafeMathRevertErrors.BinopErrorCodes.AdditionOverflow,
orderTakerAssetFilledAmount,
takerAssetFillAmount,
);
@@ -357,8 +357,8 @@ blockchainTests('Exchange core internal functions', env => {
rightOrder.takerFeeAssetData = leftOrder.takerFeeAssetData;
// The expected error that should be thrown by the function.
const expectedError = new SafeMathRevertErrors.SafeMathError(
SafeMathRevertErrors.SafeMathErrorCodes.Uint256AdditionOverflow,
const expectedError = new SafeMathRevertErrors.Uint256BinopError(
SafeMathRevertErrors.BinopErrorCodes.AdditionOverflow,
matchedFillResults.left.takerFeePaid,
matchedFillResults.right.takerFeePaid,
);

View File

@@ -443,8 +443,8 @@ blockchainTests('Isolated fillOrder() tests', env => {
takerAssetAmount: MAX_UINT256_ROOT,
});
const takerAssetFillAmount = MAX_UINT256_ROOT;
const expectedError = new SafeMathRevertErrors.SafeMathError(
SafeMathRevertErrors.SafeMathErrorCodes.Uint256MultiplicationOverflow,
const expectedError = new SafeMathRevertErrors.Uint256BinopError(
SafeMathRevertErrors.BinopErrorCodes.MultiplicationOverflow,
takerAssetFillAmount,
order.makerAssetAmount,
);
@@ -464,8 +464,8 @@ blockchainTests('Isolated fillOrder() tests', env => {
order.takerAssetAmount,
order.makerAssetAmount,
);
const expectedError = new SafeMathRevertErrors.SafeMathError(
SafeMathRevertErrors.SafeMathErrorCodes.Uint256MultiplicationOverflow,
const expectedError = new SafeMathRevertErrors.Uint256BinopError(
SafeMathRevertErrors.BinopErrorCodes.MultiplicationOverflow,
makerAssetFilledAmount,
order.makerFee,
);
@@ -480,8 +480,8 @@ blockchainTests('Isolated fillOrder() tests', env => {
takerFee: MAX_UINT256_ROOT.times(11),
});
const takerAssetFillAmount = MAX_UINT256_ROOT.dividedToIntegerBy(10);
const expectedError = new SafeMathRevertErrors.SafeMathError(
SafeMathRevertErrors.SafeMathErrorCodes.Uint256MultiplicationOverflow,
const expectedError = new SafeMathRevertErrors.Uint256BinopError(
SafeMathRevertErrors.BinopErrorCodes.MultiplicationOverflow,
takerAssetFillAmount,
order.takerFee,
);

View File

@@ -39,8 +39,8 @@ describe('Reference functions', () => {
takerAssetAmount: MAX_UINT256_ROOT,
});
const takerAssetFilledAmount = MAX_UINT256_ROOT;
const expectedError = new SafeMathRevertErrors.SafeMathError(
SafeMathRevertErrors.SafeMathErrorCodes.Uint256MultiplicationOverflow,
const expectedError = new SafeMathRevertErrors.Uint256BinopError(
SafeMathRevertErrors.BinopErrorCodes.MultiplicationOverflow,
takerAssetFilledAmount,
order.makerAssetAmount,
);
@@ -60,8 +60,8 @@ describe('Reference functions', () => {
order.takerAssetAmount,
order.makerAssetAmount,
);
const expectedError = new SafeMathRevertErrors.SafeMathError(
SafeMathRevertErrors.SafeMathErrorCodes.Uint256MultiplicationOverflow,
const expectedError = new SafeMathRevertErrors.Uint256BinopError(
SafeMathRevertErrors.BinopErrorCodes.MultiplicationOverflow,
makerAssetFilledAmount,
order.makerFee,
);
@@ -76,8 +76,8 @@ describe('Reference functions', () => {
takerFee: MAX_UINT256_ROOT.times(11),
});
const takerAssetFilledAmount = MAX_UINT256_ROOT.dividedToIntegerBy(10);
const expectedError = new SafeMathRevertErrors.SafeMathError(
SafeMathRevertErrors.SafeMathErrorCodes.Uint256MultiplicationOverflow,
const expectedError = new SafeMathRevertErrors.Uint256BinopError(
SafeMathRevertErrors.BinopErrorCodes.MultiplicationOverflow,
takerAssetFilledAmount,
order.takerFee,
);

View File

@@ -718,8 +718,8 @@ blockchainTests('Exchange wrapper functions unit tests.', env => {
const signatures = _.times(COUNT, i => createOrderSignature(orders[i]));
orders[1].takerAssetAmount = MAX_UINT256;
const takerAssetFillAmount = MAX_UINT256;
const expectedError = new SafeMathRevertErrors.SafeMathError(
SafeMathRevertErrors.SafeMathErrorCodes.Uint256AdditionOverflow,
const expectedError = new SafeMathRevertErrors.Uint256BinopError(
SafeMathRevertErrors.BinopErrorCodes.AdditionOverflow,
orders[0].takerAssetAmount,
orders[1].takerAssetAmount,
);
@@ -1031,8 +1031,8 @@ blockchainTests('Exchange wrapper functions unit tests.', env => {
const orders = [randomOrder({ takerAssetAmount: MAX_UINT256 })];
const signatures = _.times(orders.length, i => createOrderSignature(orders[i]));
const makerAssetFillAmount = new BigNumber(2);
const expectedError = new SafeMathRevertErrors.SafeMathError(
SafeMathRevertErrors.SafeMathErrorCodes.Uint256MultiplicationOverflow,
const expectedError = new SafeMathRevertErrors.Uint256BinopError(
SafeMathRevertErrors.BinopErrorCodes.MultiplicationOverflow,
orders[0].takerAssetAmount,
makerAssetFillAmount,
);
@@ -1044,8 +1044,8 @@ blockchainTests('Exchange wrapper functions unit tests.', env => {
const orders = [randomOrder({ makerAssetAmount: constants.ZERO_AMOUNT })];
const signatures = _.times(orders.length, i => createOrderSignature(orders[i]));
const makerAssetFillAmount = ONE_ETHER;
const expectedError = new SafeMathRevertErrors.SafeMathError(
SafeMathRevertErrors.SafeMathErrorCodes.Uint256DivisionByZero,
const expectedError = new SafeMathRevertErrors.Uint256BinopError(
SafeMathRevertErrors.BinopErrorCodes.DivisionByZero,
orders[0].takerAssetAmount.times(makerAssetFillAmount),
orders[0].makerAssetAmount,
);
@@ -1066,8 +1066,8 @@ blockchainTests('Exchange wrapper functions unit tests.', env => {
];
const signatures = _.times(orders.length, i => createOrderSignature(orders[i]));
const makerAssetFillAmount = new BigNumber(2);
const expectedError = new SafeMathRevertErrors.SafeMathError(
SafeMathRevertErrors.SafeMathErrorCodes.Uint256AdditionOverflow,
const expectedError = new SafeMathRevertErrors.Uint256BinopError(
SafeMathRevertErrors.BinopErrorCodes.AdditionOverflow,
orders[0].makerAssetAmount,
orders[1].makerAssetAmount,
);