From b7bac3abf6159aa400b19b0e483df777eb3ecd0c Mon Sep 17 00:00:00 2001 From: James Towle Date: Thu, 6 Jun 2019 14:04:46 -0700 Subject: [PATCH] Updated the asset-proxy tests to use RichErrors --- contracts/asset-proxy/test/authorizable.ts | 27 +++++++++---------- packages/utils/src/safe_math_revert_errors.ts | 3 ++- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/contracts/asset-proxy/test/authorizable.ts b/contracts/asset-proxy/test/authorizable.ts index ccceb0862a..c8967fc73b 100644 --- a/contracts/asset-proxy/test/authorizable.ts +++ b/contracts/asset-proxy/test/authorizable.ts @@ -8,7 +8,7 @@ import { } from '@0x/contracts-test-utils'; import { BlockchainLifecycle } from '@0x/dev-utils'; import { RevertReason } from '@0x/types'; -import { BigNumber } from '@0x/utils'; +import { BigNumber, OwnableRevertErrors } from '@0x/utils'; import * as chai from 'chai'; import * as _ from 'lodash'; @@ -47,10 +47,11 @@ describe('Authorizable', () => { }); describe('addAuthorizedAddress', () => { it('should throw if not called by owner', async () => { - return expectTransactionFailedAsync( - authorizable.addAuthorizedAddress.sendTransactionAsync(notOwner, { from: notOwner }), - RevertReason.OnlyContractOwner, + const expectedError = new OwnableRevertErrors.OnlyOwnerError(notOwner, owner); + const tx = authorizable.addAuthorizedAddress.sendTransactionAsync( + notOwner, { from: notOwner } ); + expect(tx).to.revertWith(expectedError); }); it('should allow owner to add an authorized address', async () => { await authorizable.addAuthorizedAddress.awaitTransactionSuccessAsync( @@ -81,12 +82,11 @@ describe('Authorizable', () => { { from: owner }, constants.AWAIT_TRANSACTION_MINED_MS, ); - return expectTransactionFailedAsync( - authorizable.removeAuthorizedAddress.sendTransactionAsync(address, { - from: notOwner, - }), - RevertReason.OnlyContractOwner, + const expectedError = new OwnableRevertErrors.OnlyOwnerError(notOwner, owner); + const tx = authorizable.removeAuthorizedAddress.sendTransactionAsync( + address, { from: notOwner, } ); + expect(tx).to.revertWith(expectedError); }); it('should allow owner to remove an authorized address', async () => { @@ -122,12 +122,11 @@ describe('Authorizable', () => { constants.AWAIT_TRANSACTION_MINED_MS, ); const index = new BigNumber(0); - return expectTransactionFailedAsync( - authorizable.removeAuthorizedAddressAtIndex.sendTransactionAsync(address, index, { - from: notOwner, - }), - RevertReason.OnlyContractOwner, + const expectedError = new OwnableRevertErrors.OnlyOwnerError(notOwner, owner); + const tx = authorizable.removeAuthorizedAddressAtIndex.sendTransactionAsync( + address, index, { from: notOwner, } ); + expect(tx).to.revertWith(expectedError); }); it('should throw if index is >= authorities.length', async () => { await authorizable.addAuthorizedAddress.awaitTransactionSuccessAsync( diff --git a/packages/utils/src/safe_math_revert_errors.ts b/packages/utils/src/safe_math_revert_errors.ts index 656d88d45f..8c50eed9f4 100644 --- a/packages/utils/src/safe_math_revert_errors.ts +++ b/packages/utils/src/safe_math_revert_errors.ts @@ -1,5 +1,6 @@ import { BigNumber } from './configured_bignumber'; import { RevertError } from './revert_error'; +import * as _ from 'lodash'; // tslint:disable:max-classes-per-file @@ -24,7 +25,7 @@ export class Uint256UnderflowError extends RevertError { const types = [ Uint256OverflowError, Uint256UnderflowError, -] +]; // Register the types we've defined. for (const type of types) {