diff options
Diffstat (limited to 'packages/contracts/test/exchange')
-rw-r--r-- | packages/contracts/test/exchange/core.ts | 80 | ||||
-rw-r--r-- | packages/contracts/test/exchange/dispatcher.ts | 17 | ||||
-rw-r--r-- | packages/contracts/test/exchange/match_orders.ts | 21 | ||||
-rw-r--r-- | packages/contracts/test/exchange/transactions.ts | 13 | ||||
-rw-r--r-- | packages/contracts/test/exchange/wrapper.ts | 29 |
5 files changed, 70 insertions, 90 deletions
diff --git a/packages/contracts/test/exchange/core.ts b/packages/contracts/test/exchange/core.ts index 91ead93f0..4f2fb80bd 100644 --- a/packages/contracts/test/exchange/core.ts +++ b/packages/contracts/test/exchange/core.ts @@ -18,6 +18,7 @@ import { FillContractEventArgs, } from '../../src/contract_wrappers/generated/exchange'; import { artifacts } from '../../src/utils/artifacts'; +import { expectRevertOrAlwaysFailingTransaction } from '../../src/utils/assertions'; import { chaiSetup } from '../../src/utils/chai_setup'; import { constants } from '../../src/utils/constants'; import { ERC20Wrapper } from '../../src/utils/erc20_wrapper'; @@ -415,9 +416,7 @@ describe('Exchange core', () => { makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(100), 18), takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(200), 18), }); - return expect(exchangeWrapper.fillOrderAsync(signedOrder, takerAddress)).to.be.rejectedWith( - constants.REVERT, - ); + return expectRevertOrAlwaysFailingTransaction(exchangeWrapper.fillOrderAsync(signedOrder, takerAddress)); }); it('should throw if signature is invalid', async () => { @@ -432,9 +431,7 @@ describe('Exchange core', () => { const invalidSigBuff = Buffer.concat([v, invalidR, invalidS, signatureType]); const invalidSigHex = `0x${invalidSigBuff.toString('hex')}`; signedOrder.signature = invalidSigHex; - return expect(exchangeWrapper.fillOrderAsync(signedOrder, takerAddress)).to.be.rejectedWith( - constants.REVERT, - ); + return expectRevertOrAlwaysFailingTransaction(exchangeWrapper.fillOrderAsync(signedOrder, takerAddress)); }); it('should throw if makerAssetAmount is 0', async () => { @@ -442,9 +439,7 @@ describe('Exchange core', () => { makerAssetAmount: new BigNumber(0), }); - return expect(exchangeWrapper.fillOrderAsync(signedOrder, takerAddress)).to.be.rejectedWith( - constants.REVERT, - ); + return expectRevertOrAlwaysFailingTransaction(exchangeWrapper.fillOrderAsync(signedOrder, takerAddress)); }); it('should throw if takerAssetAmount is 0', async () => { @@ -452,19 +447,17 @@ describe('Exchange core', () => { takerAssetAmount: new BigNumber(0), }); - return expect(exchangeWrapper.fillOrderAsync(signedOrder, takerAddress)).to.be.rejectedWith( - constants.REVERT, - ); + return expectRevertOrAlwaysFailingTransaction(exchangeWrapper.fillOrderAsync(signedOrder, takerAddress)); }); it('should throw if takerAssetFillAmount is 0', async () => { signedOrder = orderFactory.newSignedOrder(); - return expect( + return expectRevertOrAlwaysFailingTransaction( exchangeWrapper.fillOrderAsync(signedOrder, takerAddress, { takerAssetFillAmount: new BigNumber(0), }), - ).to.be.rejectedWith(constants.REVERT); + ); }); it('should throw if maker erc20Balances are too low to fill order', async () => { @@ -472,9 +465,7 @@ describe('Exchange core', () => { makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(100000), 18), }); - return expect(exchangeWrapper.fillOrderAsync(signedOrder, takerAddress)).to.be.rejectedWith( - constants.REVERT, - ); + return expectRevertOrAlwaysFailingTransaction(exchangeWrapper.fillOrderAsync(signedOrder, takerAddress)); }); it('should throw if taker erc20Balances are too low to fill order', async () => { @@ -482,9 +473,7 @@ describe('Exchange core', () => { takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(100000), 18), }); - return expect(exchangeWrapper.fillOrderAsync(signedOrder, takerAddress)).to.be.rejectedWith( - constants.REVERT, - ); + return expectRevertOrAlwaysFailingTransaction(exchangeWrapper.fillOrderAsync(signedOrder, takerAddress)); }); it('should throw if maker allowances are too low to fill order', async () => { @@ -497,9 +486,7 @@ describe('Exchange core', () => { // 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 expect(exchangeWrapper.fillOrderAsync(signedOrder, takerAddress)).to.be.rejectedWith( - constants.REVERT, - ); + await expectRevertOrAlwaysFailingTransaction(exchangeWrapper.fillOrderAsync(signedOrder, takerAddress)); }); it('should throw if taker allowances are too low to fill order', async () => { @@ -509,12 +496,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 expect(exchangeWrapper.fillOrderAsync(signedOrder, takerAddress)).to.be.rejectedWith( - constants.REVERT, - ); + await expectRevertOrAlwaysFailingTransaction(exchangeWrapper.fillOrderAsync(signedOrder, takerAddress)); }); it('should throw if an order is expired', async () => { @@ -542,9 +524,7 @@ describe('Exchange core', () => { }); it('should throw if not sent by maker', async () => { - return expect(exchangeWrapper.cancelOrderAsync(signedOrder, takerAddress)).to.be.rejectedWith( - constants.REVERT, - ); + return expectRevertOrAlwaysFailingTransaction(exchangeWrapper.cancelOrderAsync(signedOrder, takerAddress)); }); it('should throw if makerAssetAmount is 0', async () => { @@ -552,9 +532,7 @@ describe('Exchange core', () => { makerAssetAmount: new BigNumber(0), }); - return expect(exchangeWrapper.cancelOrderAsync(signedOrder, makerAddress)).to.be.rejectedWith( - constants.REVERT, - ); + return expectRevertOrAlwaysFailingTransaction(exchangeWrapper.cancelOrderAsync(signedOrder, makerAddress)); }); it('should throw if takerAssetAmount is 0', async () => { @@ -562,9 +540,7 @@ describe('Exchange core', () => { takerAssetAmount: new BigNumber(0), }); - return expect(exchangeWrapper.cancelOrderAsync(signedOrder, makerAddress)).to.be.rejectedWith( - constants.REVERT, - ); + return expectRevertOrAlwaysFailingTransaction(exchangeWrapper.cancelOrderAsync(signedOrder, makerAddress)); }); it('should be able to cancel a full order', async () => { @@ -632,16 +608,16 @@ describe('Exchange core', () => { const makerEpoch = new BigNumber(1); await exchangeWrapper.cancelOrdersUpToAsync(makerEpoch, makerAddress); const lesserMakerEpoch = new BigNumber(0); - return expect(exchangeWrapper.cancelOrdersUpToAsync(lesserMakerEpoch, makerAddress)).to.be.rejectedWith( - constants.REVERT, + return expectRevertOrAlwaysFailingTransaction( + exchangeWrapper.cancelOrdersUpToAsync(lesserMakerEpoch, makerAddress), ); }); it('should fail to set makerEpoch equal to existing makerEpoch', async () => { const makerEpoch = new BigNumber(1); await exchangeWrapper.cancelOrdersUpToAsync(makerEpoch, makerAddress); - return expect(exchangeWrapper.cancelOrdersUpToAsync(makerEpoch, makerAddress)).to.be.rejectedWith( - constants.REVERT, + return expectRevertOrAlwaysFailingTransaction( + exchangeWrapper.cancelOrdersUpToAsync(makerEpoch, makerAddress), ); }); @@ -749,9 +725,9 @@ describe('Exchange core', () => { expect(initialOwnerTakerAsset).to.be.bignumber.equal(takerAddress); // Call Exchange const takerAssetFillAmount = signedOrder.takerAssetAmount; - return expect( + return expectRevertOrAlwaysFailingTransaction( exchangeWrapper.fillOrderAsync(signedOrder, takerAddress, { takerAssetFillAmount }), - ).to.be.rejectedWith(constants.REVERT); + ); }); it('should throw when taker does not own the token with id takerAssetId', async () => { @@ -771,9 +747,9 @@ describe('Exchange core', () => { expect(initialOwnerTakerAsset).to.be.bignumber.not.equal(takerAddress); // Call Exchange const takerAssetFillAmount = signedOrder.takerAssetAmount; - return expect( + return expectRevertOrAlwaysFailingTransaction( exchangeWrapper.fillOrderAsync(signedOrder, takerAddress, { takerAssetFillAmount }), - ).to.be.rejectedWith(constants.REVERT); + ); }); it('should throw when makerAssetAmount is greater than 1', async () => { @@ -793,9 +769,9 @@ describe('Exchange core', () => { expect(initialOwnerTakerAsset).to.be.bignumber.equal(takerAddress); // Call Exchange const takerAssetFillAmount = signedOrder.takerAssetAmount; - return expect( + return expectRevertOrAlwaysFailingTransaction( exchangeWrapper.fillOrderAsync(signedOrder, takerAddress, { takerAssetFillAmount }), - ).to.be.rejectedWith(constants.REVERT); + ); }); it('should throw when takerAssetAmount is greater than 1', async () => { @@ -815,9 +791,9 @@ describe('Exchange core', () => { expect(initialOwnerTakerAsset).to.be.bignumber.equal(takerAddress); // Call Exchange const takerAssetFillAmount = signedOrder.takerAssetAmount; - return expect( + return expectRevertOrAlwaysFailingTransaction( exchangeWrapper.fillOrderAsync(signedOrder, takerAddress, { takerAssetFillAmount }), - ).to.be.rejectedWith(constants.REVERT); + ); }); it('should throw on partial fill', async () => { @@ -837,9 +813,9 @@ describe('Exchange core', () => { expect(initialOwnerTakerAsset).to.be.bignumber.equal(takerAddress); // Call Exchange const takerAssetFillAmount = signedOrder.takerAssetAmount; - return expect( + return expectRevertOrAlwaysFailingTransaction( exchangeWrapper.fillOrderAsync(signedOrder, takerAddress, { takerAssetFillAmount }), - ).to.be.rejectedWith(constants.REVERT); + ); }); it('should successfully fill order when makerAsset is ERC721 and takerAsset is ERC20', async () => { diff --git a/packages/contracts/test/exchange/dispatcher.ts b/packages/contracts/test/exchange/dispatcher.ts index 8bc66e3cf..3da5155ef 100644 --- a/packages/contracts/test/exchange/dispatcher.ts +++ b/packages/contracts/test/exchange/dispatcher.ts @@ -10,6 +10,7 @@ import { ERC20ProxyContract } from '../../src/contract_wrappers/generated/e_r_c2 import { ERC721ProxyContract } from '../../src/contract_wrappers/generated/e_r_c721_proxy'; import { TestAssetProxyDispatcherContract } from '../../src/contract_wrappers/generated/test_asset_proxy_dispatcher'; import { artifacts } from '../../src/utils/artifacts'; +import { expectRevertOrAlwaysFailingTransaction } from '../../src/utils/assertions'; import { chaiSetup } from '../../src/utils/chai_setup'; import { constants } from '../../src/utils/constants'; import { ERC20Wrapper } from '../../src/utils/erc20_wrapper'; @@ -177,14 +178,14 @@ describe('AssetProxyDispatcher', () => { const proxyAddress = await assetProxyDispatcher.getAssetProxy.callAsync(AssetProxyId.ERC20); expect(proxyAddress).to.be.equal(erc20Proxy.address); // The following transaction will throw because the currentAddress is no longer constants.NULL_ADDRESS - return expect( + return expectRevertOrAlwaysFailingTransaction( assetProxyDispatcher.registerAssetProxy.sendTransactionAsync( AssetProxyId.ERC20, erc20Proxy.address, constants.NULL_ADDRESS, { from: owner }, ), - ).to.be.rejectedWith(constants.REVERT); + ); }); it('should be able to reset proxy address to NULL', async () => { @@ -218,26 +219,26 @@ describe('AssetProxyDispatcher', () => { it('should throw if requesting address is not owner', async () => { const prevProxyAddress = constants.NULL_ADDRESS; - return expect( + return expectRevertOrAlwaysFailingTransaction( assetProxyDispatcher.registerAssetProxy.sendTransactionAsync( AssetProxyId.ERC20, erc20Proxy.address, prevProxyAddress, { from: notOwner }, ), - ).to.be.rejectedWith(constants.REVERT); + ); }); it('should throw if attempting to register a proxy to the incorrect id', async () => { const prevProxyAddress = constants.NULL_ADDRESS; - return expect( + return expectRevertOrAlwaysFailingTransaction( assetProxyDispatcher.registerAssetProxy.sendTransactionAsync( AssetProxyId.ERC721, erc20Proxy.address, prevProxyAddress, { from: owner }, ), - ).to.be.rejectedWith(constants.REVERT); + ); }); }); @@ -307,7 +308,7 @@ describe('AssetProxyDispatcher', () => { // Perform a transfer from makerAddress to takerAddress const erc20Balances = await erc20Wrapper.getBalancesAsync(); const amount = new BigNumber(10); - return expect( + return expectRevertOrAlwaysFailingTransaction( assetProxyDispatcher.publicDispatchTransferFrom.sendTransactionAsync( encodedProxyMetadata, makerAddress, @@ -315,7 +316,7 @@ describe('AssetProxyDispatcher', () => { amount, { from: owner }, ), - ).to.be.rejectedWith(constants.REVERT); + ); }); }); }); diff --git a/packages/contracts/test/exchange/match_orders.ts b/packages/contracts/test/exchange/match_orders.ts index 24ee794bc..3becb6220 100644 --- a/packages/contracts/test/exchange/match_orders.ts +++ b/packages/contracts/test/exchange/match_orders.ts @@ -18,6 +18,7 @@ import { FillContractEventArgs, } from '../../src/contract_wrappers/generated/exchange'; import { artifacts } from '../../src/utils/artifacts'; +import { expectRevertOrAlwaysFailingTransaction } from '../../src/utils/assertions'; import { chaiSetup } from '../../src/utils/chai_setup'; import { constants } from '../../src/utils/constants'; import { ERC20Wrapper } from '../../src/utils/erc20_wrapper'; @@ -639,9 +640,9 @@ describe('matchOrders', () => { // Cancel left order await exchangeWrapper.cancelOrderAsync(signedOrderLeft, signedOrderLeft.makerAddress); // Match orders - return expect( + return exexpectRevertOrAlwaysFailingTransactionpect( exchangeWrapper.matchOrdersAsync(signedOrderLeft, signedOrderRight, takerAddress), - ).to.be.rejectedWith(constants.REVERT); + ); }); it('Should throw if right order is not fillable', async () => { @@ -665,9 +666,9 @@ describe('matchOrders', () => { // Cancel right order await exchangeWrapper.cancelOrderAsync(signedOrderRight, signedOrderRight.makerAddress); // Match orders - return expect( + return expectRevertOrAlwaysFailingTransaction( exchangeWrapper.matchOrdersAsync(signedOrderLeft, signedOrderRight, takerAddress), - ).to.be.rejectedWith(constants.REVERT); + ); }); it('should throw if there is not a positive spread', async () => { @@ -689,7 +690,7 @@ describe('matchOrders', () => { feeRecipientAddress: feeRecipientAddressRight, }); // Match orders - return expect( + return expectRevertOrAlwaysFailingTransaction( matchOrderTester.matchOrdersAndVerifyBalancesAsync( signedOrderLeft, signedOrderRight, @@ -697,7 +698,7 @@ describe('matchOrders', () => { erc20BalancesByOwner, erc721TokenIdsByOwner, ), - ).to.be.rejectedWith(constants.REVERT); + ); }); it('should throw if the left maker asset is not equal to the right taker asset ', async () => { @@ -719,7 +720,7 @@ describe('matchOrders', () => { feeRecipientAddress: feeRecipientAddressRight, }); // Match orders - return expect( + return expectRevertOrAlwaysFailingTransaction( matchOrderTester.matchOrdersAndVerifyBalancesAsync( signedOrderLeft, signedOrderRight, @@ -727,7 +728,7 @@ describe('matchOrders', () => { erc20BalancesByOwner, erc721TokenIdsByOwner, ), - ).to.be.rejectedWith(constants.REVERT); + ); }); it('should throw if the right maker asset is not equal to the left taker asset', async () => { @@ -749,7 +750,7 @@ describe('matchOrders', () => { feeRecipientAddress: feeRecipientAddressRight, }); // Match orders - return expect( + return expectRevertOrAlwaysFailingTransaction( matchOrderTester.matchOrdersAndVerifyBalancesAsync( signedOrderLeft, signedOrderRight, @@ -757,7 +758,7 @@ describe('matchOrders', () => { erc20BalancesByOwner, erc721TokenIdsByOwner, ), - ).to.be.rejectedWith(constants.REVERT); + ); }); it('should transfer correct amounts when left order maker asset is an ERC721 token', async () => { diff --git a/packages/contracts/test/exchange/transactions.ts b/packages/contracts/test/exchange/transactions.ts index f31053ad3..8cd800ee2 100644 --- a/packages/contracts/test/exchange/transactions.ts +++ b/packages/contracts/test/exchange/transactions.ts @@ -11,6 +11,7 @@ import { ERC20ProxyContract } from '../../src/contract_wrappers/generated/e_r_c2 import { ExchangeContract } from '../../src/contract_wrappers/generated/exchange'; import { WhitelistContract } from '../../src/contract_wrappers/generated/whitelist'; import { artifacts } from '../../src/utils/artifacts'; +import { expectRevertOrAlwaysFailingTransaction } from '../../src/utils/assertions'; import { chaiSetup } from '../../src/utils/chai_setup'; import { constants } from '../../src/utils/constants'; import { ERC20Wrapper } from '../../src/utils/erc20_wrapper'; @@ -126,8 +127,8 @@ describe('Exchange transactions', () => { }); it('should throw if not called by specified sender', async () => { - return expect(exchangeWrapper.executeTransactionAsync(signedTx, takerAddress)).to.be.rejectedWith( - constants.REVERT, + return expectRevertOrAlwaysFailingTransaction( + exchangeWrapper.executeTransactionAsync(signedTx, takerAddress), ); }); @@ -168,8 +169,8 @@ describe('Exchange transactions', () => { it('should throw if the a 0x transaction with the same transactionHash has already been executed', async () => { await exchangeWrapper.executeTransactionAsync(signedTx, senderAddress); - return expect(exchangeWrapper.executeTransactionAsync(signedTx, senderAddress)).to.be.rejectedWith( - constants.REVERT, + return expectRevertOrAlwaysFailingTransaction( + exchangeWrapper.executeTransactionAsync(signedTx, senderAddress), ); }); @@ -187,8 +188,8 @@ describe('Exchange transactions', () => { }); it('should throw if not called by specified sender', async () => { - return expect(exchangeWrapper.executeTransactionAsync(signedTx, makerAddress)).to.be.rejectedWith( - constants.REVERT, + return expectRevertOrAlwaysFailingTransaction( + exchangeWrapper.executeTransactionAsync(signedTx, makerAddress), ); }); diff --git a/packages/contracts/test/exchange/wrapper.ts b/packages/contracts/test/exchange/wrapper.ts index 583ec9f91..18d69a647 100644 --- a/packages/contracts/test/exchange/wrapper.ts +++ b/packages/contracts/test/exchange/wrapper.ts @@ -15,6 +15,7 @@ import { ERC721ProxyContract } from '../../src/contract_wrappers/generated/e_r_c import { ExchangeContract } from '../../src/contract_wrappers/generated/exchange'; import { TokenRegistryContract } from '../../src/contract_wrappers/generated/token_registry'; import { artifacts } from '../../src/utils/artifacts'; +import { expectRevertOrAlwaysFailingTransaction } from '../../src/utils/assertions'; import { chaiSetup } from '../../src/utils/chai_setup'; import { constants } from '../../src/utils/constants'; import { ERC20Wrapper } from '../../src/utils/erc20_wrapper'; @@ -172,8 +173,8 @@ describe('Exchange wrappers', () => { expirationTimeSeconds: new BigNumber(Math.floor((Date.now() - 10000) / 1000)), }); - return expect(exchangeWrapper.fillOrKillOrderAsync(signedOrder, takerAddress)).to.be.rejectedWith( - constants.REVERT, + return expectRevertOrAlwaysFailingTransaction( + exchangeWrapper.fillOrKillOrderAsync(signedOrder, takerAddress), ); }); @@ -184,8 +185,8 @@ describe('Exchange wrappers', () => { takerAssetFillAmount: signedOrder.takerAssetAmount.div(2), }); - return expect(exchangeWrapper.fillOrKillOrderAsync(signedOrder, takerAddress)).to.be.rejectedWith( - constants.REVERT, + return expectRevertOrAlwaysFailingTransaction( + exchangeWrapper.fillOrKillOrderAsync(signedOrder, takerAddress), ); }); }); @@ -485,11 +486,11 @@ describe('Exchange wrappers', () => { await exchangeWrapper.fillOrKillOrderAsync(signedOrders[0], takerAddress); - return expect( + return expectRevertOrAlwaysFailingTransaction( exchangeWrapper.batchFillOrKillOrdersAsync(signedOrders, takerAddress, { takerAssetFillAmounts, }), - ).to.be.rejectedWith(constants.REVERT); + ); }); }); @@ -679,11 +680,11 @@ describe('Exchange wrappers', () => { orderFactory.newSignedOrder(), ]; - return expect( + return expectRevertOrAlwaysFailingTransaction( exchangeWrapper.marketSellOrdersAsync(signedOrders, takerAddress, { takerAssetFillAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(1000), 18), }), - ).to.be.rejectedWith(constants.REVERT); + ); }); }); @@ -768,11 +769,11 @@ describe('Exchange wrappers', () => { orderFactory.newSignedOrder(), ]; - return expect( + return expectRevertOrAlwaysFailingTransaction( exchangeWrapper.marketSellOrdersNoThrowAsync(signedOrders, takerAddress, { takerAssetFillAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(1000), 18), }), - ).to.be.rejectedWith(constants.REVERT); + ); }); }); @@ -857,11 +858,11 @@ describe('Exchange wrappers', () => { orderFactory.newSignedOrder(), ]; - return expect( + return expectRevertOrAlwaysFailingTransaction( exchangeWrapper.marketBuyOrdersAsync(signedOrders, takerAddress, { makerAssetFillAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(1000), 18), }), - ).to.be.rejectedWith(constants.REVERT); + ); }); }); @@ -946,11 +947,11 @@ describe('Exchange wrappers', () => { orderFactory.newSignedOrder(), ]; - return expect( + return expectRevertOrAlwaysFailingTransaction( exchangeWrapper.marketBuyOrdersNoThrowAsync(signedOrders, takerAddress, { makerAssetFillAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(1000), 18), }), - ).to.be.rejectedWith(constants.REVERT); + ); }); }); |