From ba6806df5d2d4b31c125a0c58cc6cd65bf555933 Mon Sep 17 00:00:00 2001 From: Alex Browne Date: Tue, 5 Jun 2018 16:45:37 -0700 Subject: Fix linter errors --- packages/contracts/src/utils/assertions.ts | 29 +++++++++++++++++++++++++++ packages/contracts/src/utils/increase_time.ts | 9 +++++++-- packages/contracts/test/exchange/core.ts | 8 ++------ 3 files changed, 38 insertions(+), 8 deletions(-) (limited to 'packages/contracts') diff --git a/packages/contracts/src/utils/assertions.ts b/packages/contracts/src/utils/assertions.ts index c08bc7271..fc57f93fb 100644 --- a/packages/contracts/src/utils/assertions.ts +++ b/packages/contracts/src/utils/assertions.ts @@ -17,18 +17,47 @@ function _expectEitherError(p: Promise, error1: string, error2: string): P }); } +/** + * Rejects if the given Promise does not reject with an error indicating + * insufficient funds. + * @param p the Promise which is expected to reject + * @returns a new Promise which will reject if the conditions are not met and + * otherwise resolve with no value. + */ export function expectInsufficientFunds(p: Promise): PromiseLike { return _expectEitherError(p, 'insufficient funds', "sender doesn't have enough funds"); } +/** + * Rejects if the given Promise does not reject with a "revert" error or the + * given otherError. + * @param p the Promise which is expected to reject + * @param otherError the other error which is accepted as a valid reject error. + * @returns a new Promise which will reject if the conditions are not met and + * otherwise resolve with no value. + */ export function expectRevertOrOtherError(p: Promise, otherError: string): PromiseLike { return _expectEitherError(p, constants.REVERT, otherError); } +/** + * Rejects if the given Promise does not reject with a "revert" or "always + * failing transaction" error. + * @param p the Promise which is expected to reject + * @returns a new Promise which will reject if the conditions are not met and + * otherwise resolve with no value. + */ export function expectRevertOrAlwaysFailingTransaction(p: Promise): PromiseLike { return expectRevertOrOtherError(p, 'always failing transaction'); } +/** + * Rejects if the given Promise does not reject with a "revert" or "Contract + * call failed" error. + * @param p the Promise which is expected to reject + * @returns a new Promise which will reject if the conditions are not met and + * otherwise resolve with no value. + */ export function expectRevertOrContractCallFailed(p: Promise): PromiseLike { return expectRevertOrOtherError(p, 'Contract call failed'); } diff --git a/packages/contracts/src/utils/increase_time.ts b/packages/contracts/src/utils/increase_time.ts index 726a759f3..5336a180d 100644 --- a/packages/contracts/src/utils/increase_time.ts +++ b/packages/contracts/src/utils/increase_time.ts @@ -5,8 +5,13 @@ import { web3Wrapper } from './web3_wrapper'; let firstAccount: string | undefined; -// increases time by the given number of seconds and then mines a block so that -// the current block timestamp has the offset applied. +/** + * Increases time by the given number of seconds and then mines a block so that + * the current block timestamp has the offset applied. + * @param seconds the Promise which is expected to reject + * @returns a new Promise which will resolve with the new total time offset or + * reject if the time could not be increased. + */ export async function increaseTimeAndMineBlockAsync(seconds: number): Promise { if (_.isUndefined(firstAccount)) { const accounts = await web3Wrapper.getAvailableAddressesAsync(); diff --git a/packages/contracts/test/exchange/core.ts b/packages/contracts/test/exchange/core.ts index 64221b63d..b44b8a344 100644 --- a/packages/contracts/test/exchange/core.ts +++ b/packages/contracts/test/exchange/core.ts @@ -472,7 +472,6 @@ describe('Exchange core', () => { signedOrder = orderFactory.newSignedOrder({ takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(100000), 18), }); - return expectRevertOrAlwaysFailingTransaction(exchangeWrapper.fillOrderAsync(signedOrder, takerAddress)); }); @@ -483,10 +482,7 @@ describe('Exchange core', () => { }), constants.AWAIT_TRANSACTION_MINED_MS, ); - // HACK: `rejectWith` returns a "promise-like" type, but not an actual "Promise", so TSLint - // complains, even though we do need to `await` it. So we disable the TSLint error below. - // tslint:disable-next-line:await-promise - await expectRevertOrAlwaysFailingTransaction(exchangeWrapper.fillOrderAsync(signedOrder, takerAddress)); + return expectRevertOrAlwaysFailingTransaction(exchangeWrapper.fillOrderAsync(signedOrder, takerAddress)); }); it('should throw if taker allowances are too low to fill order', async () => { @@ -496,7 +492,7 @@ describe('Exchange core', () => { }), constants.AWAIT_TRANSACTION_MINED_MS, ); - await expectRevertOrAlwaysFailingTransaction(exchangeWrapper.fillOrderAsync(signedOrder, takerAddress)); + return expectRevertOrAlwaysFailingTransaction(exchangeWrapper.fillOrderAsync(signedOrder, takerAddress)); }); it('should throw if an order is expired', async () => { -- cgit v1.2.3