Updated the erc1155 tests in asset-proxy to use RichErrors

This commit is contained in:
James Towle 2019-06-06 14:40:00 -07:00 committed by Amir Bandeali
parent b7bac3abf6
commit cf3790c2f8
2 changed files with 28 additions and 27 deletions

View File

@ -17,7 +17,7 @@ import {
import { BlockchainLifecycle } from '@0x/dev-utils'; import { BlockchainLifecycle } from '@0x/dev-utils';
import { assetDataUtils } from '@0x/order-utils'; import { assetDataUtils } from '@0x/order-utils';
import { AssetProxyId, RevertReason } from '@0x/types'; import { AssetProxyId, RevertReason } from '@0x/types';
import { BigNumber } from '@0x/utils'; import { BigNumber, SafeMathRevertErrors } from '@0x/utils';
import * as chai from 'chai'; import * as chai from 'chai';
import { LogWithDecodedArgs } from 'ethereum-types'; import { LogWithDecodedArgs } from 'ethereum-types';
import * as ethUtil from 'ethereumjs-util'; import * as ethUtil from 'ethereumjs-util';
@ -1747,10 +1747,10 @@ describe('ERC1155Proxy', () => {
nftNotOwnerBalance, nftNotOwnerBalance,
]; ];
await erc1155Wrapper.assertBalancesAsync(tokenHolders, tokensToTransfer, expectedInitialBalances); await erc1155Wrapper.assertBalancesAsync(tokenHolders, tokensToTransfer, expectedInitialBalances);
const expectedError = new SafeMathRevertErrors.Uint256OverflowError(maxUintValue, valueMultiplier);
// execute transfer // execute transfer
// note - this will overflow because we are trying to transfer `maxUintValue * 2` of the 2nd token // note - this will overflow because we are trying to transfer `maxUintValue * 2` of the 2nd token
await expectTransactionFailedAsync( const tx = erc1155ProxyWrapper.transferFromAsync(
erc1155ProxyWrapper.transferFromAsync(
spender, spender,
receiver, receiver,
erc1155Contract.address, erc1155Contract.address,
@ -1759,9 +1759,8 @@ describe('ERC1155Proxy', () => {
valueMultiplier, valueMultiplier,
receiverCallbackData, receiverCallbackData,
authorized, authorized,
),
RevertReason.Uint256Overflow,
); );
expect(tx).to.revertWith(expectedError);
}); });
it('should revert if transferring > 1 instances of a non-fungible token (valueMultiplier field >1)', async () => { it('should revert if transferring > 1 instances of a non-fungible token (valueMultiplier field >1)', async () => {
// setup test parameters // setup test parameters
@ -1831,9 +1830,12 @@ describe('ERC1155Proxy', () => {
// check balances before transfer // check balances before transfer
const expectedInitialBalances = [spenderInitialFungibleBalance, receiverInitialFungibleBalance]; const expectedInitialBalances = [spenderInitialFungibleBalance, receiverInitialFungibleBalance];
await erc1155Wrapper.assertBalancesAsync(tokenHolders, tokensToTransfer, expectedInitialBalances); await erc1155Wrapper.assertBalancesAsync(tokenHolders, tokensToTransfer, expectedInitialBalances);
const expectedError = new SafeMathRevertErrors.Uint256UnderflowError(
spenderInitialFungibleBalance,
valueGreaterThanSpenderBalance,
);
// execute transfer // execute transfer
await expectTransactionFailedAsync( const tx = erc1155ProxyWrapper.transferFromAsync(
erc1155ProxyWrapper.transferFromAsync(
spender, spender,
receiver, receiver,
erc1155Contract.address, erc1155Contract.address,
@ -1842,9 +1844,8 @@ describe('ERC1155Proxy', () => {
valueMultiplier, valueMultiplier,
receiverCallbackData, receiverCallbackData,
authorized, authorized,
),
RevertReason.Uint256Underflow,
); );
expect(tx).to.revertWith(expectedError);
}); });
it('should revert if sender allowance is insufficient', async () => { it('should revert if sender allowance is insufficient', async () => {
// dremove allowance for ERC1155 proxy // dremove allowance for ERC1155 proxy

View File

@ -54,7 +54,7 @@ const emptySignedOrder: SignedOrder = {
const overflowErrorForCall = ( const overflowErrorForCall = (
a?: BigNumber | string | number, a?: BigNumber | string | number,
b?: BigNumber | string | number, b?: BigNumber | string | number,
) => new SafeMathRevertErrors.Uint256OverflowError(a, b); ) => new SafeMathRevertErrors.Uint256OverflowError();
describe('Exchange core internal functions', () => { describe('Exchange core internal functions', () => {
let chainId: number; let chainId: number;