From eaabe1586374a25439c880ada348d87a5b3df740 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Thu, 21 Jun 2018 16:53:05 +0200 Subject: Update core tests to actually check revert message --- packages/contracts/src/utils/assertions.ts | 12 +++++ packages/contracts/src/utils/types.ts | 32 +++++++++++ packages/contracts/test/exchange/core.ts | 87 ++++++++++++++++++------------ 3 files changed, 97 insertions(+), 34 deletions(-) (limited to 'packages/contracts') diff --git a/packages/contracts/src/utils/assertions.ts b/packages/contracts/src/utils/assertions.ts index 615e648f3..29489e648 100644 --- a/packages/contracts/src/utils/assertions.ts +++ b/packages/contracts/src/utils/assertions.ts @@ -51,6 +51,18 @@ export function expectRevertOrAlwaysFailingTransactionAsync(p: Promise): P return expectRevertOrOtherErrorAsync(p, 'always failing transaction'); } +/** + * Rejects if the given Promise does not reject with the given revert reason or "always + * failing transaction" error. + * @param p the Promise which is expected to reject + * @param reason a specific revert reason + * @returns a new Promise which will reject if the conditions are not met and + * otherwise resolve with no value. + */ +export function expectRevertReasonOrAlwaysFailingTransactionAsync(p: Promise, reason: string): PromiseLike { + return _expectEitherErrorAsync(p, 'always failing transaction', reason); +} + /** * Rejects if the given Promise does not reject with a "revert" or "Contract * call failed" error. diff --git a/packages/contracts/src/utils/types.ts b/packages/contracts/src/utils/types.ts index bb8c12088..da8ea588f 100644 --- a/packages/contracts/src/utils/types.ts +++ b/packages/contracts/src/utils/types.ts @@ -150,3 +150,35 @@ export interface MatchOrder { leftSignature: string; rightSignature: string; } + +export enum ContractLibErrors { + OrderUnfillable = 'ORDER_UNFILLABLE', + InvalidMaker = 'INVALID_MAKER', + InvalidTaker = 'INVALID_TAKER', + InvalidSender = 'INVALID_SENDER', + InvalidOrderSignature = 'INVALID_ORDER_SIGNATURE', + InvalidTakerAmount = 'INVALID_TAKER_AMOUNT', + RoundingError = 'ROUNDING_ERROR', + InvalidSignature = 'INVALID_SIGNATURE', + SignatureIllegal = 'SIGNATURE_ILLEGAL', + SignatureUnsupported = 'SIGNATURE_UNSUPPORTED', + InvalidNewOrderEpoch = 'INVALID_NEW_ORDER_EPOCH', + CompleteFillFailed = 'COMPLETE_FILL_FAILED', + NegativeSpreadRequired = 'NEGATIVE_SPREAD_REQUIRED', + ReentrancyIllegal = 'REENTRANCY_ILLEGAL', + InvalidTxHash = 'INVALID_TX_HASH', + InvalidTxSignature = 'INVALID_TX_SIGNATURE', + FailedExecution = 'FAILED_EXECUTION', + AssetProxyMismatch = 'ASSET_PROXY_MISMATCH', + AssetProxyIdMismatch = 'ASSET_PROXY_ID_MISMATCH', + LengthGreaterThan0Required = 'LENGTH_GREATER_THAN_0_REQUIRED', + Length1Required = 'LENGTH_1_REQUIRED', + Length66Required = 'LENGTH_66_REQUIRED', + InvalidAmount = 'INVALID_AMOUNT', + TransferFailed = 'TRANSFER_FAILED', + SenderNotAuthorized = 'SENDER_NOT_AUTHORIZED', + TargetNotAuthorized = 'TARGET_NOT_AUTHORIZED', + TargetAlreadyAuthorized = 'TARGET_ALREADY_AUTHORIZED', + IndexOutOfBounds = 'INDEX_OUT_OF_BOUNDS', + AuthorizedAddressMismatch = 'AUTHORIZED_ADDRESS_MISMATCH', +} diff --git a/packages/contracts/test/exchange/core.ts b/packages/contracts/test/exchange/core.ts index ea37a1e99..e0a9d5b92 100644 --- a/packages/contracts/test/exchange/core.ts +++ b/packages/contracts/test/exchange/core.ts @@ -18,14 +18,17 @@ import { FillContractEventArgs, } from '../../src/generated_contract_wrappers/exchange'; import { artifacts } from '../../src/utils/artifacts'; -import { expectRevertOrAlwaysFailingTransactionAsync } from '../../src/utils/assertions'; +import { + expectRevertOrAlwaysFailingTransactionAsync, + expectRevertReasonOrAlwaysFailingTransactionAsync, +} from '../../src/utils/assertions'; import { chaiSetup } from '../../src/utils/chai_setup'; import { constants } from '../../src/utils/constants'; import { ERC20Wrapper } from '../../src/utils/erc20_wrapper'; import { ERC721Wrapper } from '../../src/utils/erc721_wrapper'; import { ExchangeWrapper } from '../../src/utils/exchange_wrapper'; import { OrderFactory } from '../../src/utils/order_factory'; -import { ERC20BalancesByOwner } from '../../src/utils/types'; +import { ContractLibErrors, ERC20BalancesByOwner } from '../../src/utils/types'; import { provider, txDefaults, web3Wrapper } from '../../src/utils/web3_wrapper'; chaiSetup.configure(); @@ -126,7 +129,7 @@ describe('Exchange core', () => { afterEach(async () => { await blockchainLifecycle.revertAsync(); }); - describe('fillOrder', () => { + describe.only('fillOrder', () => { beforeEach(async () => { erc20Balances = await erc20Wrapper.getBalancesAsync(); signedOrder = orderFactory.newSignedOrder(); @@ -415,8 +418,9 @@ describe('Exchange core', () => { makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(100), 18), takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(200), 18), }); - return expectRevertOrAlwaysFailingTransactionAsync( + return expectRevertReasonOrAlwaysFailingTransactionAsync( exchangeWrapper.fillOrderAsync(signedOrder, takerAddress), + ContractLibErrors.InvalidTaker, ); }); @@ -432,8 +436,9 @@ describe('Exchange core', () => { const invalidSigBuff = Buffer.concat([v, invalidR, invalidS, signatureType]); const invalidSigHex = `0x${invalidSigBuff.toString('hex')}`; signedOrder.signature = invalidSigHex; - return expectRevertOrAlwaysFailingTransactionAsync( + return expectRevertReasonOrAlwaysFailingTransactionAsync( exchangeWrapper.fillOrderAsync(signedOrder, takerAddress), + ContractLibErrors.InvalidOrderSignature, ); }); @@ -442,8 +447,9 @@ describe('Exchange core', () => { makerAssetAmount: new BigNumber(0), }); - return expectRevertOrAlwaysFailingTransactionAsync( + return expectRevertReasonOrAlwaysFailingTransactionAsync( exchangeWrapper.fillOrderAsync(signedOrder, takerAddress), + ContractLibErrors.OrderUnfillable, ); }); @@ -452,18 +458,20 @@ describe('Exchange core', () => { takerAssetAmount: new BigNumber(0), }); - return expectRevertOrAlwaysFailingTransactionAsync( + return expectRevertReasonOrAlwaysFailingTransactionAsync( exchangeWrapper.fillOrderAsync(signedOrder, takerAddress), + ContractLibErrors.OrderUnfillable, ); }); it('should throw if takerAssetFillAmount is 0', async () => { signedOrder = orderFactory.newSignedOrder(); - return expectRevertOrAlwaysFailingTransactionAsync( + return expectRevertReasonOrAlwaysFailingTransactionAsync( exchangeWrapper.fillOrderAsync(signedOrder, takerAddress, { takerAssetFillAmount: new BigNumber(0), }), + ContractLibErrors.InvalidTakerAmount, ); }); @@ -472,8 +480,9 @@ describe('Exchange core', () => { makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(100000), 18), }); - return expectRevertOrAlwaysFailingTransactionAsync( + return expectRevertReasonOrAlwaysFailingTransactionAsync( exchangeWrapper.fillOrderAsync(signedOrder, takerAddress), + ContractLibErrors.TransferFailed, ); }); @@ -481,8 +490,9 @@ describe('Exchange core', () => { signedOrder = orderFactory.newSignedOrder({ takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(100000), 18), }); - return expectRevertOrAlwaysFailingTransactionAsync( + return expectRevertReasonOrAlwaysFailingTransactionAsync( exchangeWrapper.fillOrderAsync(signedOrder, takerAddress), + ContractLibErrors.TransferFailed, ); }); @@ -493,8 +503,9 @@ describe('Exchange core', () => { }), constants.AWAIT_TRANSACTION_MINED_MS, ); - return expectRevertOrAlwaysFailingTransactionAsync( + return expectRevertReasonOrAlwaysFailingTransactionAsync( exchangeWrapper.fillOrderAsync(signedOrder, takerAddress), + ContractLibErrors.TransferFailed, ); }); @@ -505,8 +516,9 @@ describe('Exchange core', () => { }), constants.AWAIT_TRANSACTION_MINED_MS, ); - return expectRevertOrAlwaysFailingTransactionAsync( + return expectRevertReasonOrAlwaysFailingTransactionAsync( exchangeWrapper.fillOrderAsync(signedOrder, takerAddress), + ContractLibErrors.TransferFailed, ); }); @@ -514,16 +526,18 @@ describe('Exchange core', () => { signedOrder = orderFactory.newSignedOrder({ expirationTimeSeconds: new BigNumber(Math.floor((Date.now() - 10000) / 1000)), }); - return expectRevertOrAlwaysFailingTransactionAsync( + return expectRevertReasonOrAlwaysFailingTransactionAsync( exchangeWrapper.fillOrderAsync(signedOrder, takerAddress), + ContractLibErrors.OrderUnfillable, ); }); it('should throw if no value is filled', async () => { signedOrder = orderFactory.newSignedOrder(); await exchangeWrapper.fillOrderAsync(signedOrder, takerAddress); - return expectRevertOrAlwaysFailingTransactionAsync( + return expectRevertReasonOrAlwaysFailingTransactionAsync( exchangeWrapper.fillOrderAsync(signedOrder, takerAddress), + ContractLibErrors.OrderUnfillable, ); }); }); @@ -545,8 +559,9 @@ describe('Exchange core', () => { makerAssetAmount: new BigNumber(0), }); - return expectRevertOrAlwaysFailingTransactionAsync( + return expectRevertReasonOrAlwaysFailingTransactionAsync( exchangeWrapper.cancelOrderAsync(signedOrder, makerAddress), + ContractLibErrors.OrderUnfillable, ); }); @@ -555,17 +570,19 @@ describe('Exchange core', () => { takerAssetAmount: new BigNumber(0), }); - return expectRevertOrAlwaysFailingTransactionAsync( + return expectRevertReasonOrAlwaysFailingTransactionAsync( exchangeWrapper.cancelOrderAsync(signedOrder, makerAddress), + ContractLibErrors.OrderUnfillable, ); }); it('should be able to cancel a full order', async () => { await exchangeWrapper.cancelOrderAsync(signedOrder, makerAddress); - return expectRevertOrAlwaysFailingTransactionAsync( + return expectRevertReasonOrAlwaysFailingTransactionAsync( exchangeWrapper.fillOrderAsync(signedOrder, takerAddress, { takerAssetFillAmount: signedOrder.takerAssetAmount.div(2), }), + ContractLibErrors.OrderUnfillable, ); }); @@ -585,8 +602,9 @@ describe('Exchange core', () => { it('should throw if already cancelled', async () => { await exchangeWrapper.cancelOrderAsync(signedOrder, makerAddress); - return expectRevertOrAlwaysFailingTransactionAsync( + return expectRevertReasonOrAlwaysFailingTransactionAsync( exchangeWrapper.cancelOrderAsync(signedOrder, makerAddress), + ContractLibErrors.OrderUnfillable, ); }); @@ -594,8 +612,9 @@ describe('Exchange core', () => { signedOrder = orderFactory.newSignedOrder({ expirationTimeSeconds: new BigNumber(Math.floor((Date.now() - 10000) / 1000)), }); - return expectRevertOrAlwaysFailingTransactionAsync( + return expectRevertReasonOrAlwaysFailingTransactionAsync( exchangeWrapper.cancelOrderAsync(signedOrder, makerAddress), + ContractLibErrors.OrderUnfillable, ); }); @@ -611,10 +630,11 @@ describe('Exchange core', () => { }); const fillTakerAssetAmount2 = new BigNumber(1); - return expectRevertOrAlwaysFailingTransactionAsync( + return expectRevertReasonOrAlwaysFailingTransactionAsync( exchangeWrapper.fillOrderAsync(signedOrder, takerAddress, { takerAssetFillAmount: fillTakerAssetAmount2, }), + ContractLibErrors.RoundingError, ); }); }); @@ -624,16 +644,18 @@ describe('Exchange core', () => { const orderEpoch = new BigNumber(1); await exchangeWrapper.cancelOrdersUpToAsync(orderEpoch, makerAddress); const lesserOrderEpoch = new BigNumber(0); - return expectRevertOrAlwaysFailingTransactionAsync( + return expectRevertReasonOrAlwaysFailingTransactionAsync( exchangeWrapper.cancelOrdersUpToAsync(lesserOrderEpoch, makerAddress), + ContractLibErrors.InvalidNewOrderEpoch, ); }); it('should fail to set orderEpoch equal to existing orderEpoch', async () => { const orderEpoch = new BigNumber(1); await exchangeWrapper.cancelOrdersUpToAsync(orderEpoch, makerAddress); - return expectRevertOrAlwaysFailingTransactionAsync( + return expectRevertReasonOrAlwaysFailingTransactionAsync( exchangeWrapper.cancelOrdersUpToAsync(orderEpoch, makerAddress), + ContractLibErrors.InvalidNewOrderEpoch, ); }); @@ -791,8 +813,9 @@ describe('Exchange core', () => { expect(initialOwnerTakerAsset).to.be.bignumber.equal(takerAddress); // Call Exchange const takerAssetFillAmount = signedOrder.takerAssetAmount; - return expectRevertOrAlwaysFailingTransactionAsync( + return expectRevertReasonOrAlwaysFailingTransactionAsync( exchangeWrapper.fillOrderAsync(signedOrder, takerAddress, { takerAssetFillAmount }), + ContractLibErrors.OrderUnfillable, ); }); @@ -813,30 +836,26 @@ describe('Exchange core', () => { expect(initialOwnerTakerAsset).to.be.bignumber.equal(takerAddress); // Call Exchange const takerAssetFillAmount = signedOrder.takerAssetAmount; - return expectRevertOrAlwaysFailingTransactionAsync( + return expectRevertReasonOrAlwaysFailingTransactionAsync( exchangeWrapper.fillOrderAsync(signedOrder, takerAddress, { takerAssetFillAmount }), + ContractLibErrors.OrderUnfillable, ); }); it('should throw on partial fill', async () => { // Construct Exchange parameters const makerAssetId = erc721MakerAssetIds[0]; - const takerAssetId = erc721TakerAssetIds[0]; signedOrder = orderFactory.newSignedOrder({ makerAssetAmount: new BigNumber(1), - takerAssetAmount: new BigNumber(0), + takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(100), 18), makerAssetData: assetProxyUtils.encodeERC721AssetData(erc721Token.address, makerAssetId), - takerAssetData: assetProxyUtils.encodeERC721AssetData(erc721Token.address, takerAssetId), + takerAssetData: assetProxyUtils.encodeERC20AssetData(defaultTakerAssetAddress), }); - // Verify pre-conditions - const initialOwnerMakerAsset = await erc721Token.ownerOf.callAsync(makerAssetId); - expect(initialOwnerMakerAsset).to.be.bignumber.equal(makerAddress); - const initialOwnerTakerAsset = await erc721Token.ownerOf.callAsync(takerAssetId); - expect(initialOwnerTakerAsset).to.be.bignumber.equal(takerAddress); // Call Exchange - const takerAssetFillAmount = signedOrder.takerAssetAmount; - return expectRevertOrAlwaysFailingTransactionAsync( + const takerAssetFillAmount = signedOrder.takerAssetAmount.div(2); + return expectRevertReasonOrAlwaysFailingTransactionAsync( exchangeWrapper.fillOrderAsync(signedOrder, takerAddress, { takerAssetFillAmount }), + ContractLibErrors.RoundingError, ); }); -- cgit From 5706b29c8c52f70a76e39b583ded931c847c9236 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Thu, 21 Jun 2018 17:06:44 +0200 Subject: remove .only --- packages/contracts/test/exchange/core.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'packages/contracts') diff --git a/packages/contracts/test/exchange/core.ts b/packages/contracts/test/exchange/core.ts index e0a9d5b92..fe8a8203a 100644 --- a/packages/contracts/test/exchange/core.ts +++ b/packages/contracts/test/exchange/core.ts @@ -129,7 +129,7 @@ describe('Exchange core', () => { afterEach(async () => { await blockchainLifecycle.revertAsync(); }); - describe.only('fillOrder', () => { + describe('fillOrder', () => { beforeEach(async () => { erc20Balances = await erc20Wrapper.getBalancesAsync(); signedOrder = orderFactory.newSignedOrder(); -- cgit From 7869c19245c4f5c69bda8726b66df405aca8754c Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Thu, 21 Jun 2018 17:23:42 +0200 Subject: Change revert reason in ownable to be similar to all other revert reasons --- packages/contracts/src/contracts/current/utils/Ownable/Ownable.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'packages/contracts') diff --git a/packages/contracts/src/contracts/current/utils/Ownable/Ownable.sol b/packages/contracts/src/contracts/current/utils/Ownable/Ownable.sol index 296c6c856..048fdb46f 100644 --- a/packages/contracts/src/contracts/current/utils/Ownable/Ownable.sol +++ b/packages/contracts/src/contracts/current/utils/Ownable/Ownable.sol @@ -22,7 +22,7 @@ contract Ownable is IOwnable { modifier onlyOwner() { require( msg.sender == owner, - "Only contract owner is allowed to call this method." + 'ONLY_CONTRACT_OWNER' ); _; } -- cgit From ada5428df7f056293d826d28362f8be08874771c Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Thu, 21 Jun 2018 17:23:59 +0200 Subject: Check revert reasons in Authorizable tests --- packages/contracts/src/utils/types.ts | 1 + packages/contracts/test/asset_proxy/authorizable.ts | 20 ++++++++++++++------ 2 files changed, 15 insertions(+), 6 deletions(-) (limited to 'packages/contracts') diff --git a/packages/contracts/src/utils/types.ts b/packages/contracts/src/utils/types.ts index da8ea588f..db590213c 100644 --- a/packages/contracts/src/utils/types.ts +++ b/packages/contracts/src/utils/types.ts @@ -181,4 +181,5 @@ export enum ContractLibErrors { TargetAlreadyAuthorized = 'TARGET_ALREADY_AUTHORIZED', IndexOutOfBounds = 'INDEX_OUT_OF_BOUNDS', AuthorizedAddressMismatch = 'AUTHORIZED_ADDRESS_MISMATCH', + OnlyContractOwner = 'ONLY_CONTRACT_OWNER', } diff --git a/packages/contracts/test/asset_proxy/authorizable.ts b/packages/contracts/test/asset_proxy/authorizable.ts index 347d060d6..9896895bd 100644 --- a/packages/contracts/test/asset_proxy/authorizable.ts +++ b/packages/contracts/test/asset_proxy/authorizable.ts @@ -4,16 +4,20 @@ import 'make-promises-safe'; import { MixinAuthorizableContract } from '../../src/generated_contract_wrappers/mixin_authorizable'; import { artifacts } from '../../src/utils/artifacts'; -import { expectRevertOrAlwaysFailingTransactionAsync } from '../../src/utils/assertions'; +import { + expectRevertOrAlwaysFailingTransactionAsync, + expectRevertReasonOrAlwaysFailingTransactionAsync, +} from '../../src/utils/assertions'; import { chaiSetup } from '../../src/utils/chai_setup'; import { constants } from '../../src/utils/constants'; +import { ContractLibErrors } from '../../src/utils/types'; import { provider, txDefaults, web3Wrapper } from '../../src/utils/web3_wrapper'; chaiSetup.configure(); const expect = chai.expect; const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper); -describe('Authorizable', () => { +describe.only('Authorizable', () => { let owner: string; let notOwner: string; let address: string; @@ -43,8 +47,9 @@ describe('Authorizable', () => { }); describe('addAuthorizedAddress', () => { it('should throw if not called by owner', async () => { - return expectRevertOrAlwaysFailingTransactionAsync( + return expectRevertReasonOrAlwaysFailingTransactionAsync( authorizable.addAuthorizedAddress.sendTransactionAsync(notOwner, { from: notOwner }), + ContractLibErrors.OnlyContractOwner, ); }); it('should allow owner to add an authorized address', async () => { @@ -60,8 +65,9 @@ describe('Authorizable', () => { await authorizable.addAuthorizedAddress.sendTransactionAsync(address, { from: owner }), constants.AWAIT_TRANSACTION_MINED_MS, ); - return expectRevertOrAlwaysFailingTransactionAsync( + return expectRevertReasonOrAlwaysFailingTransactionAsync( authorizable.addAuthorizedAddress.sendTransactionAsync(address, { from: owner }), + ContractLibErrors.TargetAlreadyAuthorized, ); }); }); @@ -72,10 +78,11 @@ describe('Authorizable', () => { await authorizable.addAuthorizedAddress.sendTransactionAsync(address, { from: owner }), constants.AWAIT_TRANSACTION_MINED_MS, ); - return expectRevertOrAlwaysFailingTransactionAsync( + return expectRevertReasonOrAlwaysFailingTransactionAsync( authorizable.removeAuthorizedAddress.sendTransactionAsync(address, { from: notOwner, }), + ContractLibErrors.OnlyContractOwner, ); }); @@ -95,10 +102,11 @@ describe('Authorizable', () => { }); it('should throw if owner attempts to remove an address that is not authorized', async () => { - return expectRevertOrAlwaysFailingTransactionAsync( + return expectRevertReasonOrAlwaysFailingTransactionAsync( authorizable.removeAuthorizedAddress.sendTransactionAsync(address, { from: owner, }), + ContractLibErrors.TargetNotAuthorized, ); }); }); -- cgit From 323e8756ba7ff0d5d0b2a80fcc5a66deaef02de5 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Thu, 21 Jun 2018 17:27:26 +0200 Subject: remove only --- packages/contracts/test/asset_proxy/authorizable.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'packages/contracts') diff --git a/packages/contracts/test/asset_proxy/authorizable.ts b/packages/contracts/test/asset_proxy/authorizable.ts index 9896895bd..5807e646e 100644 --- a/packages/contracts/test/asset_proxy/authorizable.ts +++ b/packages/contracts/test/asset_proxy/authorizable.ts @@ -17,7 +17,7 @@ chaiSetup.configure(); const expect = chai.expect; const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper); -describe.only('Authorizable', () => { +describe('Authorizable', () => { let owner: string; let notOwner: string; let address: string; -- cgit From a0b225b8b17b60fe073da6a2744cfd35d32a54a5 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Thu, 21 Jun 2018 17:43:48 +0200 Subject: Test revert reasons in proxy tests --- packages/contracts/test/asset_proxy/proxies.ts | 34 +++++++++++++++++--------- 1 file changed, 23 insertions(+), 11 deletions(-) (limited to 'packages/contracts') diff --git a/packages/contracts/test/asset_proxy/proxies.ts b/packages/contracts/test/asset_proxy/proxies.ts index 2c27f7382..2c1f52973 100644 --- a/packages/contracts/test/asset_proxy/proxies.ts +++ b/packages/contracts/test/asset_proxy/proxies.ts @@ -15,12 +15,16 @@ import { DummyERC721TokenContract } from '../../src/generated_contract_wrappers/ import { ERC20ProxyContract } from '../../src/generated_contract_wrappers/e_r_c20_proxy'; import { ERC721ProxyContract } from '../../src/generated_contract_wrappers/e_r_c721_proxy'; import { artifacts } from '../../src/utils/artifacts'; -import { expectRevertOrAlwaysFailingTransactionAsync } from '../../src/utils/assertions'; +import { + expectRevertOrAlwaysFailingTransactionAsync, + expectRevertReasonOrAlwaysFailingTransactionAsync, +} from '../../src/utils/assertions'; import { chaiSetup } from '../../src/utils/chai_setup'; import { constants } from '../../src/utils/constants'; import { ERC20Wrapper } from '../../src/utils/erc20_wrapper'; import { ERC721Wrapper } from '../../src/utils/erc721_wrapper'; import { LogDecoder } from '../../src/utils/log_decoder'; +import { ContractLibErrors } from '../../src/utils/types'; import { provider, txDefaults, web3Wrapper } from '../../src/utils/web3_wrapper'; chaiSetup.configure(); @@ -160,14 +164,15 @@ describe('Asset Transfer Proxies', () => { constants.AWAIT_TRANSACTION_MINED_MS, ); // Perform a transfer; expect this to fail. - return expectRevertOrAlwaysFailingTransactionAsync( + return expectRevertReasonOrAlwaysFailingTransactionAsync( erc20Proxy.transferFrom.sendTransactionAsync( encodedAssetData, makerAddress, takerAddress, transferAmount, - { from: notAuthorized }, + { from: exchangeAddress }, ), + ContractLibErrors.TransferFailed, ); }); @@ -177,7 +182,7 @@ describe('Asset Transfer Proxies', () => { const encodedAssetDataWithoutProxyId = encodedAssetData.slice(0, -2); // Perform a transfer from makerAddress to takerAddress const amount = new BigNumber(10); - return expectRevertOrAlwaysFailingTransactionAsync( + return expectRevertReasonOrAlwaysFailingTransactionAsync( erc20Proxy.transferFrom.sendTransactionAsync( encodedAssetDataWithoutProxyId, makerAddress, @@ -187,6 +192,7 @@ describe('Asset Transfer Proxies', () => { from: notAuthorized, }, ), + ContractLibErrors.SenderNotAuthorized, ); }); }); @@ -236,10 +242,11 @@ describe('Asset Transfer Proxies', () => { const toAddresses = _.times(numTransfers, () => takerAddress); const amounts = _.times(numTransfers, () => amount); - return expectRevertOrAlwaysFailingTransactionAsync( + return expectRevertReasonOrAlwaysFailingTransactionAsync( erc20Proxy.batchTransferFrom.sendTransactionAsync(assetData, fromAddresses, toAddresses, amounts, { from: notAuthorized, }), + ContractLibErrors.SenderNotAuthorized, ); }); }); @@ -377,7 +384,7 @@ describe('Asset Transfer Proxies', () => { expect(ownerMakerAsset).to.be.bignumber.equal(makerAddress); // Perform a transfer from makerAddress to takerAddress const amount = new BigNumber(0); - return expectRevertOrAlwaysFailingTransactionAsync( + return expectRevertReasonOrAlwaysFailingTransactionAsync( erc721Proxy.transferFrom.sendTransactionAsync( encodedAssetDataWithoutProxyId, makerAddress, @@ -385,6 +392,7 @@ describe('Asset Transfer Proxies', () => { amount, { from: exchangeAddress }, ), + ContractLibErrors.InvalidAmount, ); }); @@ -397,7 +405,7 @@ describe('Asset Transfer Proxies', () => { expect(ownerMakerAsset).to.be.bignumber.equal(makerAddress); // Perform a transfer from makerAddress to takerAddress const amount = new BigNumber(500); - return expectRevertOrAlwaysFailingTransactionAsync( + return expectRevertReasonOrAlwaysFailingTransactionAsync( erc721Proxy.transferFrom.sendTransactionAsync( encodedAssetDataWithoutProxyId, makerAddress, @@ -405,6 +413,7 @@ describe('Asset Transfer Proxies', () => { amount, { from: exchangeAddress }, ), + ContractLibErrors.InvalidAmount, ); }); @@ -421,16 +430,17 @@ describe('Asset Transfer Proxies', () => { ); // Perform a transfer; expect this to fail. const amount = new BigNumber(1); - return expectRevertOrAlwaysFailingTransactionAsync( + return expectRevertReasonOrAlwaysFailingTransactionAsync( erc20Proxy.transferFrom.sendTransactionAsync( encodedAssetDataWithoutProxyId, makerAddress, takerAddress, amount, { - from: notAuthorized, + from: exchangeAddress, }, ), + ContractLibErrors.TransferFailed, ); }); @@ -440,7 +450,7 @@ describe('Asset Transfer Proxies', () => { const encodedAssetDataWithoutProxyId = encodedAssetData.slice(0, -2); // Perform a transfer from makerAddress to takerAddress const amount = new BigNumber(1); - return expectRevertOrAlwaysFailingTransactionAsync( + return expectRevertReasonOrAlwaysFailingTransactionAsync( erc721Proxy.transferFrom.sendTransactionAsync( encodedAssetDataWithoutProxyId, makerAddress, @@ -448,6 +458,7 @@ describe('Asset Transfer Proxies', () => { amount, { from: notAuthorized }, ), + ContractLibErrors.SenderNotAuthorized, ); }); }); @@ -498,10 +509,11 @@ describe('Asset Transfer Proxies', () => { const toAddresses = _.times(numTransfers, () => takerAddress); const amounts = _.times(numTransfers, () => new BigNumber(1)); - return expectRevertOrAlwaysFailingTransactionAsync( + return expectRevertReasonOrAlwaysFailingTransactionAsync( erc721Proxy.batchTransferFrom.sendTransactionAsync(assetData, fromAddresses, toAddresses, amounts, { from: notAuthorized, }), + ContractLibErrors.SenderNotAuthorized, ); }); }); -- cgit From d8df6968d39f87771c3544c80d2e1842e718090b Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Fri, 22 Jun 2018 10:37:25 +0200 Subject: remove unused import --- packages/contracts/test/asset_proxy/authorizable.ts | 1 - 1 file changed, 1 deletion(-) (limited to 'packages/contracts') diff --git a/packages/contracts/test/asset_proxy/authorizable.ts b/packages/contracts/test/asset_proxy/authorizable.ts index 5807e646e..3eaef3142 100644 --- a/packages/contracts/test/asset_proxy/authorizable.ts +++ b/packages/contracts/test/asset_proxy/authorizable.ts @@ -5,7 +5,6 @@ import 'make-promises-safe'; import { MixinAuthorizableContract } from '../../src/generated_contract_wrappers/mixin_authorizable'; import { artifacts } from '../../src/utils/artifacts'; import { - expectRevertOrAlwaysFailingTransactionAsync, expectRevertReasonOrAlwaysFailingTransactionAsync, } from '../../src/utils/assertions'; import { chaiSetup } from '../../src/utils/chai_setup'; -- cgit From a30107ab867964d371b2d5fc6791c7b1963f1c7b Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Fri, 22 Jun 2018 10:38:08 +0200 Subject: Check revert reason in dispatcher tests --- packages/contracts/test/exchange/core.ts | 3 ++- packages/contracts/test/exchange/dispatcher.ts | 15 +++++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) (limited to 'packages/contracts') diff --git a/packages/contracts/test/exchange/core.ts b/packages/contracts/test/exchange/core.ts index fe8a8203a..b4649378e 100644 --- a/packages/contracts/test/exchange/core.ts +++ b/packages/contracts/test/exchange/core.ts @@ -549,8 +549,9 @@ describe('Exchange core', () => { }); it('should throw if not sent by maker', async () => { - return expectRevertOrAlwaysFailingTransactionAsync( + return expectRevertReasonOrAlwaysFailingTransactionAsync( exchangeWrapper.cancelOrderAsync(signedOrder, takerAddress), + ContractLibErrors.InvalidMaker, ); }); diff --git a/packages/contracts/test/exchange/dispatcher.ts b/packages/contracts/test/exchange/dispatcher.ts index abbfd7ac7..299950603 100644 --- a/packages/contracts/test/exchange/dispatcher.ts +++ b/packages/contracts/test/exchange/dispatcher.ts @@ -9,11 +9,15 @@ import { ERC20ProxyContract } from '../../src/generated_contract_wrappers/e_r_c2 import { ERC721ProxyContract } from '../../src/generated_contract_wrappers/e_r_c721_proxy'; import { TestAssetProxyDispatcherContract } from '../../src/generated_contract_wrappers/test_asset_proxy_dispatcher'; import { artifacts } from '../../src/utils/artifacts'; -import { expectRevertOrAlwaysFailingTransactionAsync } from '../../src/utils/assertions'; +import { + expectRevertOrAlwaysFailingTransactionAsync, + expectRevertReasonOrAlwaysFailingTransactionAsync, +} from '../../src/utils/assertions'; import { chaiSetup } from '../../src/utils/chai_setup'; import { constants } from '../../src/utils/constants'; import { ERC20Wrapper } from '../../src/utils/erc20_wrapper'; import { ERC721Wrapper } from '../../src/utils/erc721_wrapper'; +import { ContractLibErrors } from '../../src/utils/types'; import { provider, txDefaults, web3Wrapper } from '../../src/utils/web3_wrapper'; chaiSetup.configure(); @@ -175,13 +179,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 expectRevertOrAlwaysFailingTransactionAsync( + return expectRevertReasonOrAlwaysFailingTransactionAsync( assetProxyDispatcher.registerAssetProxy.sendTransactionAsync( AssetProxyId.ERC20, erc20Proxy.address, constants.NULL_ADDRESS, { from: owner }, ), + ContractLibErrors.AssetProxyMismatch, ); }); @@ -216,25 +221,27 @@ describe('AssetProxyDispatcher', () => { it('should throw if requesting address is not owner', async () => { const prevProxyAddress = constants.NULL_ADDRESS; - return expectRevertOrAlwaysFailingTransactionAsync( + return expectRevertReasonOrAlwaysFailingTransactionAsync( assetProxyDispatcher.registerAssetProxy.sendTransactionAsync( AssetProxyId.ERC20, erc20Proxy.address, prevProxyAddress, { from: notOwner }, ), + ContractLibErrors.OnlyContractOwner, ); }); it('should throw if attempting to register a proxy to the incorrect id', async () => { const prevProxyAddress = constants.NULL_ADDRESS; - return expectRevertOrAlwaysFailingTransactionAsync( + return expectRevertReasonOrAlwaysFailingTransactionAsync( assetProxyDispatcher.registerAssetProxy.sendTransactionAsync( AssetProxyId.ERC721, erc20Proxy.address, prevProxyAddress, { from: owner }, ), + ContractLibErrors.AssetProxyIdMismatch, ); }); }); -- cgit From 76fd7f47ebfb48d04faece04af0db3ab5277d864 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Fri, 22 Jun 2018 14:13:44 +0200 Subject: Fix tests --- packages/contracts/test/exchange/core.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'packages/contracts') diff --git a/packages/contracts/test/exchange/core.ts b/packages/contracts/test/exchange/core.ts index 32b3fffd4..d35ff7dee 100644 --- a/packages/contracts/test/exchange/core.ts +++ b/packages/contracts/test/exchange/core.ts @@ -817,7 +817,7 @@ describe('Exchange core', () => { const takerAssetFillAmount = signedOrder.takerAssetAmount; return expectRevertReasonOrAlwaysFailingTransactionAsync( exchangeWrapper.fillOrderAsync(signedOrder, takerAddress, { takerAssetFillAmount }), - ContractLibErrors.OrderUnfillable, + ContractLibErrors.InvalidAmount, ); }); @@ -840,7 +840,7 @@ describe('Exchange core', () => { const takerAssetFillAmount = signedOrder.takerAssetAmount; return expectRevertReasonOrAlwaysFailingTransactionAsync( exchangeWrapper.fillOrderAsync(signedOrder, takerAddress, { takerAssetFillAmount }), - ContractLibErrors.OrderUnfillable, + ContractLibErrors.InvalidAmount, ); }); -- cgit From daa50442c90f30ce7a873bf228875241a083bba5 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Fri, 22 Jun 2018 14:28:01 +0200 Subject: Add revert reason checks to match_orders tests --- packages/contracts/test/exchange/match_orders.ts | 25 +++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) (limited to 'packages/contracts') diff --git a/packages/contracts/test/exchange/match_orders.ts b/packages/contracts/test/exchange/match_orders.ts index b8dca04fd..6cc0631fe 100644 --- a/packages/contracts/test/exchange/match_orders.ts +++ b/packages/contracts/test/exchange/match_orders.ts @@ -12,7 +12,9 @@ import { ERC20ProxyContract } from '../../src/generated_contract_wrappers/e_r_c2 import { ERC721ProxyContract } from '../../src/generated_contract_wrappers/e_r_c721_proxy'; import { ExchangeContract } from '../../src/generated_contract_wrappers/exchange'; import { artifacts } from '../../src/utils/artifacts'; -import { expectRevertOrAlwaysFailingTransactionAsync } from '../../src/utils/assertions'; +import { + expectRevertReasonOrAlwaysFailingTransactionAsync, +} from '../../src/utils/assertions'; import { chaiSetup } from '../../src/utils/chai_setup'; import { constants } from '../../src/utils/constants'; import { ERC20Wrapper } from '../../src/utils/erc20_wrapper'; @@ -20,7 +22,7 @@ import { ERC721Wrapper } from '../../src/utils/erc721_wrapper'; import { ExchangeWrapper } from '../../src/utils/exchange_wrapper'; import { MatchOrderTester } from '../../src/utils/match_order_tester'; import { OrderFactory } from '../../src/utils/order_factory'; -import { ERC20BalancesByOwner, ERC721TokenIdsByOwner, OrderInfo, OrderStatus } from '../../src/utils/types'; +import { ContractLibErrors, ERC20BalancesByOwner, ERC721TokenIdsByOwner, OrderInfo, OrderStatus } from '../../src/utils/types'; import { provider, txDefaults, web3Wrapper } from '../../src/utils/web3_wrapper'; chaiSetup.configure(); @@ -598,8 +600,9 @@ describe('matchOrders', () => { // Cancel left order await exchangeWrapper.cancelOrderAsync(signedOrderLeft, signedOrderLeft.makerAddress); // Match orders - return expectRevertOrAlwaysFailingTransactionAsync( + return expectRevertReasonOrAlwaysFailingTransactionAsync( exchangeWrapper.matchOrdersAsync(signedOrderLeft, signedOrderRight, takerAddress), + ContractLibErrors.OrderUnfillable, ); }); @@ -622,8 +625,9 @@ describe('matchOrders', () => { // Cancel right order await exchangeWrapper.cancelOrderAsync(signedOrderRight, signedOrderRight.makerAddress); // Match orders - return expectRevertOrAlwaysFailingTransactionAsync( + return expectRevertReasonOrAlwaysFailingTransactionAsync( exchangeWrapper.matchOrdersAsync(signedOrderLeft, signedOrderRight, takerAddress), + ContractLibErrors.OrderUnfillable, ); }); @@ -644,7 +648,7 @@ describe('matchOrders', () => { feeRecipientAddress: feeRecipientAddressRight, }); // Match orders - return expectRevertOrAlwaysFailingTransactionAsync( + return expectRevertReasonOrAlwaysFailingTransactionAsync( matchOrderTester.matchOrdersAndVerifyBalancesAsync( signedOrderLeft, signedOrderRight, @@ -652,6 +656,7 @@ describe('matchOrders', () => { erc20BalancesByOwner, erc721TokenIdsByOwner, ), + ContractLibErrors.NegativeSpreadRequired, ); }); @@ -672,7 +677,7 @@ describe('matchOrders', () => { feeRecipientAddress: feeRecipientAddressRight, }); // Match orders - return expectRevertOrAlwaysFailingTransactionAsync( + return expectRevertReasonOrAlwaysFailingTransactionAsync( matchOrderTester.matchOrdersAndVerifyBalancesAsync( signedOrderLeft, signedOrderRight, @@ -680,6 +685,11 @@ describe('matchOrders', () => { erc20BalancesByOwner, erc721TokenIdsByOwner, ), + // We are assuming assetData fields of the right order are the + // reverse of the left order, rather than checking equality. This + // saves a bunch of gas, but as a result if the assetData fields are + // off then the failure ends up happening at signature validation + ContractLibErrors.InvalidSignature, ); }); @@ -702,7 +712,7 @@ describe('matchOrders', () => { feeRecipientAddress: feeRecipientAddressRight, }); // Match orders - return expectRevertOrAlwaysFailingTransactionAsync( + return expectRevertReasonOrAlwaysFailingTransactionAsync( matchOrderTester.matchOrdersAndVerifyBalancesAsync( signedOrderLeft, signedOrderRight, @@ -710,6 +720,7 @@ describe('matchOrders', () => { erc20BalancesByOwner, erc721TokenIdsByOwner, ), + ContractLibErrors.InvalidSignature, ); }); -- cgit From 914b00936199526f67398d5b9823f893f1773cdd Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Fri, 22 Jun 2018 17:12:17 +0200 Subject: Change Whitelist error messages to conform to rest and added revert reason checks to transactions tests --- .../contracts/current/test/Whitelist/Whitelist.sol | 10 +++--- packages/contracts/src/utils/types.ts | 2 ++ packages/contracts/test/exchange/transactions.ts | 40 +++++++++++++--------- 3 files changed, 31 insertions(+), 21 deletions(-) (limited to 'packages/contracts') diff --git a/packages/contracts/src/contracts/current/test/Whitelist/Whitelist.sol b/packages/contracts/src/contracts/current/test/Whitelist/Whitelist.sol index d35815474..8b52858b1 100644 --- a/packages/contracts/src/contracts/current/test/Whitelist/Whitelist.sol +++ b/packages/contracts/src/contracts/current/test/Whitelist/Whitelist.sol @@ -23,13 +23,13 @@ import "../../protocol/Exchange/interfaces/IExchange.sol"; import "../../protocol/Exchange/libs/LibOrder.sol"; import "../../utils/Ownable/Ownable.sol"; -contract Whitelist is +contract Whitelist is Ownable { // Revert reasons - string constant MAKER_NOT_WHITELISTED = "Maker address not whitelisted."; - string constant TAKER_NOT_WHITELISTED = "Taker address not whitelisted."; - string constant INVALID_SENDER = "Sender must equal transaction origin."; + string constant MAKER_NOT_WHITELISTED = "MAKER_NOT_WHITELISTED"; // Maker address not whitelisted. + string constant TAKER_NOT_WHITELISTED = "TAKER_NOT_WHITELISTED"; // Taker address not whitelisted. + string constant INVALID_SENDER = "INVALID_SENDER"; // Sender must equal transaction origin. // Mapping of address => whitelist status. mapping (address => bool) public isWhitelisted; @@ -77,7 +77,7 @@ contract Whitelist is public { address takerAddress = msg.sender; - + // This contract must be the entry point for the transaction. require( takerAddress == tx.origin, diff --git a/packages/contracts/src/utils/types.ts b/packages/contracts/src/utils/types.ts index 24183b549..c1eb72099 100644 --- a/packages/contracts/src/utils/types.ts +++ b/packages/contracts/src/utils/types.ts @@ -183,4 +183,6 @@ export enum ContractLibErrors { IndexOutOfBounds = 'INDEX_OUT_OF_BOUNDS', AuthorizedAddressMismatch = 'AUTHORIZED_ADDRESS_MISMATCH', OnlyContractOwner = 'ONLY_CONTRACT_OWNER', + MakerNotWhitelisted = 'MAKER_NOT_WHITELISTED', + TakerNotWhitelisted = 'TAKER_NOT_WHITELISTED', } diff --git a/packages/contracts/test/exchange/transactions.ts b/packages/contracts/test/exchange/transactions.ts index 9a625880c..958a6dce8 100644 --- a/packages/contracts/test/exchange/transactions.ts +++ b/packages/contracts/test/exchange/transactions.ts @@ -10,7 +10,9 @@ import { ExchangeContract } from '../../src/generated_contract_wrappers/exchange import { ExchangeWrapperContract } from '../../src/generated_contract_wrappers/exchange_wrapper'; import { WhitelistContract } from '../../src/generated_contract_wrappers/whitelist'; import { artifacts } from '../../src/utils/artifacts'; -import { expectRevertOrAlwaysFailingTransactionAsync } from '../../src/utils/assertions'; +import { + expectRevertReasonOrAlwaysFailingTransactionAsync, +} from '../../src/utils/assertions'; import { chaiSetup } from '../../src/utils/chai_setup'; import { constants } from '../../src/utils/constants'; import { ERC20Wrapper } from '../../src/utils/erc20_wrapper'; @@ -18,7 +20,7 @@ import { ExchangeWrapper } from '../../src/utils/exchange_wrapper'; import { OrderFactory } from '../../src/utils/order_factory'; import { orderUtils } from '../../src/utils/order_utils'; import { TransactionFactory } from '../../src/utils/transaction_factory'; -import { ERC20BalancesByOwner, SignedTransaction } from '../../src/utils/types'; +import { ContractLibErrors, ERC20BalancesByOwner, SignedTransaction } from '../../src/utils/types'; import { provider, txDefaults, web3Wrapper } from '../../src/utils/web3_wrapper'; chaiSetup.configure(); @@ -59,6 +61,12 @@ describe('Exchange transactions', () => { after(async () => { await blockchainLifecycle.revertAsync(); }); + beforeEach(async () => { + await blockchainLifecycle.startAsync(); + }); + afterEach(async () => { + await blockchainLifecycle.revertAsync(); + }); before(async () => { const accounts = await web3Wrapper.getAvailableAddressesAsync(); const usedAddresses = ([owner, senderAddress, makerAddress, takerAddress, feeRecipientAddress] = accounts); @@ -101,13 +109,6 @@ describe('Exchange transactions', () => { makerTransactionFactory = new TransactionFactory(makerPrivateKey, exchange.address); takerTransactionFactory = new TransactionFactory(takerPrivateKey, exchange.address); }); - beforeEach(async () => { - await blockchainLifecycle.startAsync(); - }); - afterEach(async () => { - await blockchainLifecycle.revertAsync(); - }); - describe('executeTransaction', () => { describe('fillOrder', () => { let takerAssetFillAmount: BigNumber; @@ -126,8 +127,9 @@ describe('Exchange transactions', () => { }); it('should throw if not called by specified sender', async () => { - return expectRevertOrAlwaysFailingTransactionAsync( + return expectRevertReasonOrAlwaysFailingTransactionAsync( exchangeWrapper.executeTransactionAsync(signedTx, takerAddress), + ContractLibErrors.FailedExecution, ); }); @@ -168,8 +170,9 @@ 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 expectRevertOrAlwaysFailingTransactionAsync( + return expectRevertReasonOrAlwaysFailingTransactionAsync( exchangeWrapper.executeTransactionAsync(signedTx, senderAddress), + ContractLibErrors.InvalidTxHash, ); }); @@ -187,15 +190,17 @@ describe('Exchange transactions', () => { }); it('should throw if not called by specified sender', async () => { - return expectRevertOrAlwaysFailingTransactionAsync( + return expectRevertReasonOrAlwaysFailingTransactionAsync( exchangeWrapper.executeTransactionAsync(signedTx, makerAddress), + ContractLibErrors.FailedExecution, ); }); it('should cancel the order when signed by maker and called by sender', async () => { await exchangeWrapper.executeTransactionAsync(signedTx, senderAddress); - return expectRevertOrAlwaysFailingTransactionAsync( + return expectRevertReasonOrAlwaysFailingTransactionAsync( exchangeWrapper.fillOrderAsync(signedOrder, senderAddress), + ContractLibErrors.OrderUnfillable, ); }); }); @@ -238,7 +243,7 @@ describe('Exchange transactions', () => { signedOrder.signature, ); const signedFillTx = takerTransactionFactory.newSignedTransaction(fillData); - return expectRevertOrAlwaysFailingTransactionAsync( + return expectRevertReasonOrAlwaysFailingTransactionAsync( exchangeWrapperContract.fillOrder.sendTransactionAsync( orderWithoutExchangeAddress, takerAssetFillAmount, @@ -247,6 +252,7 @@ describe('Exchange transactions', () => { signedFillTx.signature, { from: takerAddress }, ), + ContractLibErrors.FailedExecution, ); }); @@ -357,7 +363,7 @@ describe('Exchange transactions', () => { orderWithoutExchangeAddress = orderUtils.getOrderWithoutExchangeAddress(signedOrder); const takerAssetFillAmount = signedOrder.takerAssetAmount; const salt = generatePseudoRandomSalt(); - return expectRevertOrAlwaysFailingTransactionAsync( + return expectRevertReasonOrAlwaysFailingTransactionAsync( whitelist.fillOrderIfWhitelisted.sendTransactionAsync( orderWithoutExchangeAddress, takerAssetFillAmount, @@ -365,6 +371,7 @@ describe('Exchange transactions', () => { signedOrder.signature, { from: takerAddress }, ), + ContractLibErrors.MakerNotWhitelisted, ); }); @@ -378,7 +385,7 @@ describe('Exchange transactions', () => { orderWithoutExchangeAddress = orderUtils.getOrderWithoutExchangeAddress(signedOrder); const takerAssetFillAmount = signedOrder.takerAssetAmount; const salt = generatePseudoRandomSalt(); - return expectRevertOrAlwaysFailingTransactionAsync( + return expectRevertReasonOrAlwaysFailingTransactionAsync( whitelist.fillOrderIfWhitelisted.sendTransactionAsync( orderWithoutExchangeAddress, takerAssetFillAmount, @@ -386,6 +393,7 @@ describe('Exchange transactions', () => { signedOrder.signature, { from: takerAddress }, ), + ContractLibErrors.TakerNotWhitelisted, ); }); -- cgit From 8b4077d7dea335ce6daa0f37717100bec1fe9ed1 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Fri, 22 Jun 2018 17:12:31 +0200 Subject: Fix tests --- packages/contracts/test/exchange/match_orders.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'packages/contracts') diff --git a/packages/contracts/test/exchange/match_orders.ts b/packages/contracts/test/exchange/match_orders.ts index 6cc0631fe..9d2378dc8 100644 --- a/packages/contracts/test/exchange/match_orders.ts +++ b/packages/contracts/test/exchange/match_orders.ts @@ -689,7 +689,7 @@ describe('matchOrders', () => { // reverse of the left order, rather than checking equality. This // saves a bunch of gas, but as a result if the assetData fields are // off then the failure ends up happening at signature validation - ContractLibErrors.InvalidSignature, + ContractLibErrors.InvalidOrderSignature, ); }); @@ -720,7 +720,7 @@ describe('matchOrders', () => { erc20BalancesByOwner, erc721TokenIdsByOwner, ), - ContractLibErrors.InvalidSignature, + ContractLibErrors.InvalidOrderSignature, ); }); -- cgit From 4c14372b4afd9473a9b86c83dfcda076027a2e6c Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Fri, 22 Jun 2018 17:12:52 +0200 Subject: Add revert reason checks to wrapper tests --- packages/contracts/test/exchange/wrapper.ts | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) (limited to 'packages/contracts') diff --git a/packages/contracts/test/exchange/wrapper.ts b/packages/contracts/test/exchange/wrapper.ts index 703f644b8..3d7465659 100644 --- a/packages/contracts/test/exchange/wrapper.ts +++ b/packages/contracts/test/exchange/wrapper.ts @@ -12,14 +12,16 @@ import { ERC20ProxyContract } from '../../src/generated_contract_wrappers/e_r_c2 import { ERC721ProxyContract } from '../../src/generated_contract_wrappers/e_r_c721_proxy'; import { ExchangeContract } from '../../src/generated_contract_wrappers/exchange'; import { artifacts } from '../../src/utils/artifacts'; -import { expectRevertOrAlwaysFailingTransactionAsync } from '../../src/utils/assertions'; +import { + expectRevertReasonOrAlwaysFailingTransactionAsync, +} from '../../src/utils/assertions'; import { chaiSetup } from '../../src/utils/chai_setup'; import { constants } from '../../src/utils/constants'; import { ERC20Wrapper } from '../../src/utils/erc20_wrapper'; import { ERC721Wrapper } from '../../src/utils/erc721_wrapper'; import { ExchangeWrapper } from '../../src/utils/exchange_wrapper'; import { OrderFactory } from '../../src/utils/order_factory'; -import { ERC20BalancesByOwner } from '../../src/utils/types'; +import { ContractLibErrors, ERC20BalancesByOwner } from '../../src/utils/types'; import { provider, txDefaults, web3Wrapper } from '../../src/utils/web3_wrapper'; chaiSetup.configure(); @@ -165,13 +167,14 @@ describe('Exchange wrappers', () => { ); }); - it('should throw if an signedOrder is expired', async () => { + it('should throw if a signedOrder is expired', async () => { const signedOrder = orderFactory.newSignedOrder({ expirationTimeSeconds: new BigNumber(Math.floor((Date.now() - 10000) / 1000)), }); - return expectRevertOrAlwaysFailingTransactionAsync( + return expectRevertReasonOrAlwaysFailingTransactionAsync( exchangeWrapper.fillOrKillOrderAsync(signedOrder, takerAddress), + ContractLibErrors.OrderUnfillable, ); }); @@ -182,8 +185,9 @@ describe('Exchange wrappers', () => { takerAssetFillAmount: signedOrder.takerAssetAmount.div(2), }); - return expectRevertOrAlwaysFailingTransactionAsync( + return expectRevertReasonOrAlwaysFailingTransactionAsync( exchangeWrapper.fillOrKillOrderAsync(signedOrder, takerAddress), + ContractLibErrors.CompleteFillFailed, ); }); }); @@ -494,10 +498,11 @@ describe('Exchange wrappers', () => { await exchangeWrapper.fillOrKillOrderAsync(signedOrders[0], takerAddress); - return expectRevertOrAlwaysFailingTransactionAsync( + return expectRevertReasonOrAlwaysFailingTransactionAsync( exchangeWrapper.batchFillOrKillOrdersAsync(signedOrders, takerAddress, { takerAssetFillAmounts, }), + ContractLibErrors.OrderUnfillable, ); }); }); @@ -687,7 +692,7 @@ describe('Exchange wrappers', () => { expect(newBalances).to.be.deep.equal(erc20Balances); }); - it('should throw when an signedOrder does not use the same takerAssetAddress', async () => { + it('should throw when a signedOrder does not use the same takerAssetAddress', async () => { signedOrders = [ orderFactory.newSignedOrder(), orderFactory.newSignedOrder({ @@ -696,10 +701,13 @@ describe('Exchange wrappers', () => { orderFactory.newSignedOrder(), ]; - return expectRevertOrAlwaysFailingTransactionAsync( + return expectRevertReasonOrAlwaysFailingTransactionAsync( exchangeWrapper.marketSellOrdersAsync(signedOrders, takerAddress, { takerAssetFillAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(1000), 18), }), + // We simply use the takerAssetData from the first order for all orders. + // If they are not the same, the contract throws when validating the order signature + ContractLibErrors.InvalidOrderSignature, ); }); }); @@ -902,7 +910,7 @@ describe('Exchange wrappers', () => { expect(newBalances).to.be.deep.equal(erc20Balances); }); - it('should throw when an signedOrder does not use the same makerAssetAddress', async () => { + it('should throw when a signedOrder does not use the same makerAssetAddress', async () => { signedOrders = [ orderFactory.newSignedOrder(), orderFactory.newSignedOrder({ @@ -911,10 +919,11 @@ describe('Exchange wrappers', () => { orderFactory.newSignedOrder(), ]; - return expectRevertOrAlwaysFailingTransactionAsync( + return expectRevertReasonOrAlwaysFailingTransactionAsync( exchangeWrapper.marketBuyOrdersAsync(signedOrders, takerAddress, { makerAssetFillAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(1000), 18), }), + ContractLibErrors.InvalidOrderSignature, ); }); }); -- cgit From 59d3a219937a80fa6f8d6096e9a54534103c0cd7 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Fri, 22 Jun 2018 17:39:41 +0200 Subject: Fix test now that contract reverts with message --- packages/contracts/src/utils/types.ts | 1 + packages/contracts/test/exchange/dispatcher.ts | 8 +++----- 2 files changed, 4 insertions(+), 5 deletions(-) (limited to 'packages/contracts') diff --git a/packages/contracts/src/utils/types.ts b/packages/contracts/src/utils/types.ts index c1eb72099..43c9109e7 100644 --- a/packages/contracts/src/utils/types.ts +++ b/packages/contracts/src/utils/types.ts @@ -185,4 +185,5 @@ export enum ContractLibErrors { OnlyContractOwner = 'ONLY_CONTRACT_OWNER', MakerNotWhitelisted = 'MAKER_NOT_WHITELISTED', TakerNotWhitelisted = 'TAKER_NOT_WHITELISTED', + AssetProxyDoesNotExist = 'ASSET_PROXY_DOES_NOT_EXIST', } diff --git a/packages/contracts/test/exchange/dispatcher.ts b/packages/contracts/test/exchange/dispatcher.ts index 299950603..d463f6c35 100644 --- a/packages/contracts/test/exchange/dispatcher.ts +++ b/packages/contracts/test/exchange/dispatcher.ts @@ -9,10 +9,7 @@ import { ERC20ProxyContract } from '../../src/generated_contract_wrappers/e_r_c2 import { ERC721ProxyContract } from '../../src/generated_contract_wrappers/e_r_c721_proxy'; import { TestAssetProxyDispatcherContract } from '../../src/generated_contract_wrappers/test_asset_proxy_dispatcher'; import { artifacts } from '../../src/utils/artifacts'; -import { - expectRevertOrAlwaysFailingTransactionAsync, - expectRevertReasonOrAlwaysFailingTransactionAsync, -} from '../../src/utils/assertions'; +import { expectRevertReasonOrAlwaysFailingTransactionAsync } from '../../src/utils/assertions'; import { chaiSetup } from '../../src/utils/chai_setup'; import { constants } from '../../src/utils/constants'; import { ERC20Wrapper } from '../../src/utils/erc20_wrapper'; @@ -314,7 +311,7 @@ describe('AssetProxyDispatcher', () => { const encodedAssetDataWithoutProxyId = encodedAssetData.slice(0, -2); // Perform a transfer from makerAddress to takerAddress const amount = new BigNumber(10); - return expectRevertOrAlwaysFailingTransactionAsync( + return expectRevertReasonOrAlwaysFailingTransactionAsync( assetProxyDispatcher.publicDispatchTransferFrom.sendTransactionAsync( encodedAssetDataWithoutProxyId, AssetProxyId.ERC20, @@ -323,6 +320,7 @@ describe('AssetProxyDispatcher', () => { amount, { from: owner }, ), + ContractLibErrors.AssetProxyDoesNotExist, ); }); }); -- cgit From ba14850c9a3f774169db1b67446618bb84daae54 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Fri, 22 Jun 2018 18:35:35 +0200 Subject: Standardize ERC20 error strings given convention --- .../contracts/src/contracts/current/tokens/ERC20Token/ERC20Token.sol | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'packages/contracts') diff --git a/packages/contracts/src/contracts/current/tokens/ERC20Token/ERC20Token.sol b/packages/contracts/src/contracts/current/tokens/ERC20Token/ERC20Token.sol index f0bcdafef..b6961a6ec 100644 --- a/packages/contracts/src/contracts/current/tokens/ERC20Token/ERC20Token.sol +++ b/packages/contracts/src/contracts/current/tokens/ERC20Token/ERC20Token.sol @@ -23,8 +23,8 @@ import "./IERC20Token.sol"; contract ERC20Token is IERC20Token { - string constant INSUFFICIENT_BALANCE = "Insufficient balance to complete transfer."; - string constant INSUFFICIENT_ALLOWANCE = "Insufficient allowance to complete transfer."; + string constant INSUFFICIENT_BALANCE = "ERC20_INSUFFICIENT_BALANCE"; + string constant INSUFFICIENT_ALLOWANCE = "ERC20_INSUFFICIENT_ALLOWANCE"; string constant OVERFLOW = "Transfer would result in an overflow."; mapping (address => uint256) balances; @@ -97,4 +97,3 @@ contract ERC20Token is IERC20Token { return allowed[_owner][_spender]; } } - -- cgit From 0e7c254b938045f0c6e0a57c78bb1db8a23557b6 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Fri, 22 Jun 2018 18:36:15 +0200 Subject: Move constants over to ContractLibError enum and update all tests --- packages/contracts/src/utils/constants.ts | 13 ------- packages/contracts/src/utils/types.ts | 12 +++++- .../contracts/test/exchange/signature_validator.ts | 9 +++-- packages/contracts/test/libraries/lib_bytes.ts | 45 +++++++++++----------- .../contracts/test/unlimited_allowance_token.ts | 7 ++-- 5 files changed, 42 insertions(+), 44 deletions(-) (limited to 'packages/contracts') diff --git a/packages/contracts/src/utils/constants.ts b/packages/contracts/src/utils/constants.ts index f21b8c7a0..2b2bd2425 100644 --- a/packages/contracts/src/utils/constants.ts +++ b/packages/contracts/src/utils/constants.ts @@ -19,19 +19,6 @@ const TESTRPC_PRIVATE_KEYS_STRINGS = [ export const constants = { INVALID_OPCODE: 'invalid opcode', REVERT: 'revert', - LIB_BYTES_GREATER_THAN_ZERO_LENGTH_REQUIRED: 'GREATER_THAN_ZERO_LENGTH_REQUIRED', - LIB_BYTES_GREATER_OR_EQUAL_TO_4_LENGTH_REQUIRED: 'GREATER_OR_EQUAL_TO_4_LENGTH_REQUIRED', - LIB_BYTES_GREATER_OR_EQUAL_TO_20_LENGTH_REQUIRED: 'GREATER_OR_EQUAL_TO_20_LENGTH_REQUIRED', - LIB_BYTES_GREATER_OR_EQUAL_TO_32_LENGTH_REQUIRED: 'GREATER_OR_EQUAL_TO_32_LENGTH_REQUIRED', - LIB_BYTES_GREATER_OR_EQUAL_TO_NESTED_BYTES_LENGTH_REQUIRED: 'GREATER_OR_EQUAL_TO_NESTED_BYTES_LENGTH_REQUIRED', - LIB_BYTES_GREATER_OR_EQUAL_TO_SOURCE_BYTES_LENGTH_REQUIRED: 'GREATER_OR_EQUAL_TO_SOURCE_BYTES_LENGTH_REQUIRED', - ERC20_INSUFFICIENT_BALANCE: 'Insufficient balance to complete transfer.', - ERC20_INSUFFICIENT_ALLOWANCE: 'Insufficient allowance to complete transfer.', - EXCHANGE_LENGTH_GREATER_THAN_0_REQUIRED: 'LENGTH_GREATER_THAN_0_REQUIRED', - EXCHANGE_SIGNATURE_UNSUPPORTED: 'SIGNATURE_UNSUPPORTED', - EXCHANGE_SIGNATURE_ILLEGAL: 'SIGNATURE_ILLEGAL', - EXCHANGE_LENGTH_0_REQUIRED: 'LENGTH_0_REQUIRED', - EXCHANGE_LENGTH_65_REQUIRED: 'LENGTH_65_REQUIRED', TESTRPC_NETWORK_ID: 50, // Note(albrow): In practice V8 and most other engines limit the minimum // interval for setInterval to 10ms. We still set it to 0 here in order to diff --git a/packages/contracts/src/utils/types.ts b/packages/contracts/src/utils/types.ts index 43c9109e7..f65a9858b 100644 --- a/packages/contracts/src/utils/types.ts +++ b/packages/contracts/src/utils/types.ts @@ -173,8 +173,8 @@ export enum ContractLibErrors { AssetProxyMismatch = 'ASSET_PROXY_MISMATCH', AssetProxyIdMismatch = 'ASSET_PROXY_ID_MISMATCH', LengthGreaterThan0Required = 'LENGTH_GREATER_THAN_0_REQUIRED', - Length1Required = 'LENGTH_1_REQUIRED', - Length66Required = 'LENGTH_66_REQUIRED', + ExchangeLength0Required = 'LENGTH_0_REQUIRED', + ExchangeLength65Required = 'LENGTH_65_REQUIRED', InvalidAmount = 'INVALID_AMOUNT', TransferFailed = 'TRANSFER_FAILED', SenderNotAuthorized = 'SENDER_NOT_AUTHORIZED', @@ -186,4 +186,12 @@ export enum ContractLibErrors { MakerNotWhitelisted = 'MAKER_NOT_WHITELISTED', TakerNotWhitelisted = 'TAKER_NOT_WHITELISTED', AssetProxyDoesNotExist = 'ASSET_PROXY_DOES_NOT_EXIST', + LibBytesGreaterThanZeroLengthRequired = 'GREATER_THAN_ZERO_LENGTH_REQUIRED', + LibBytesGreaterOrEqualTo4LengthRequired = 'GREATER_OR_EQUAL_TO_4_LENGTH_REQUIRED', + LibBytesGreaterOrEqualTo20LengthRequired = 'GREATER_OR_EQUAL_TO_20_LENGTH_REQUIRED', + LibBytesGreaterOrEqualTo32LengthRequired = 'GREATER_OR_EQUAL_TO_32_LENGTH_REQUIRED', + LibBytesGreaterOrEqualToNestedBytesLengthRequired = 'GREATER_OR_EQUAL_TO_NESTED_BYTES_LENGTH_REQUIRED', + LibBytesGreaterOrEqualToSourceBytesLengthRequired = 'GREATER_OR_EQUAL_TO_SOURCE_BYTES_LENGTH_REQUIRED', + Erc20InsufficientBalance = 'ERC20_INSUFFICIENT_BALANCE', + Erc20InsufficientAllowance = 'ERC20_INSUFFICIENT_ALLOWANCE', } diff --git a/packages/contracts/test/exchange/signature_validator.ts b/packages/contracts/test/exchange/signature_validator.ts index 8e221e3f1..d53e0758e 100644 --- a/packages/contracts/test/exchange/signature_validator.ts +++ b/packages/contracts/test/exchange/signature_validator.ts @@ -18,6 +18,7 @@ import { chaiSetup } from '../../src/utils/chai_setup'; import { constants } from '../../src/utils/constants'; import { LogDecoder } from '../../src/utils/log_decoder'; import { OrderFactory } from '../../src/utils/order_factory'; +import { ContractLibErrors } from '../../src/utils/types'; import { provider, txDefaults, web3Wrapper } from '../../src/utils/web3_wrapper'; chaiSetup.configure(); @@ -107,7 +108,7 @@ describe('MixinSignatureValidator', () => { signedOrder.makerAddress, emptySignature, ), - constants.EXCHANGE_LENGTH_GREATER_THAN_0_REQUIRED, + ContractLibErrors.LengthGreaterThan0Required, ); }); @@ -121,7 +122,7 @@ describe('MixinSignatureValidator', () => { signedOrder.makerAddress, unsupportedSignatureHex, ), - constants.EXCHANGE_SIGNATURE_UNSUPPORTED, + ContractLibErrors.SignatureUnsupported, ); }); @@ -134,7 +135,7 @@ describe('MixinSignatureValidator', () => { signedOrder.makerAddress, unsupportedSignatureHex, ), - constants.EXCHANGE_SIGNATURE_ILLEGAL, + ContractLibErrors.SignatureIllegal, ); }); @@ -161,7 +162,7 @@ describe('MixinSignatureValidator', () => { signedOrder.makerAddress, signatureHex, ), - constants.EXCHANGE_LENGTH_0_REQUIRED, + ContractLibErrors.ExchangeLength0Required, ); }); diff --git a/packages/contracts/test/libraries/lib_bytes.ts b/packages/contracts/test/libraries/lib_bytes.ts index a31a4789c..2d54596d5 100644 --- a/packages/contracts/test/libraries/lib_bytes.ts +++ b/packages/contracts/test/libraries/lib_bytes.ts @@ -11,6 +11,7 @@ import { artifacts } from '../../src/utils/artifacts'; import { expectRevertOrOtherErrorAsync } from '../../src/utils/assertions'; import { chaiSetup } from '../../src/utils/chai_setup'; import { constants } from '../../src/utils/constants'; +import { ContractLibErrors } from '../../src/utils/types'; import { provider, txDefaults, web3Wrapper } from '../../src/utils/web3_wrapper'; chaiSetup.configure(); @@ -95,7 +96,7 @@ describe('LibBytes', () => { it('should revert if length is 0', async () => { return expectRevertOrOtherErrorAsync( libBytes.publicPopLastByte.callAsync(constants.NULL_BYTES), - constants.LIB_BYTES_GREATER_THAN_ZERO_LENGTH_REQUIRED, + ContractLibErrors.LibBytesGreaterThanZeroLengthRequired, ); }); it('should pop the last byte from the input and return it', async () => { @@ -111,7 +112,7 @@ describe('LibBytes', () => { it('should revert if length is less than 20', async () => { return expectRevertOrOtherErrorAsync( libBytes.publicPopLast20Bytes.callAsync(byteArrayShorterThan20Bytes), - constants.LIB_BYTES_GREATER_OR_EQUAL_TO_20_LENGTH_REQUIRED, + ContractLibErrors.LibBytesGreaterOrEqualTo20LengthRequired ); }); it('should pop the last 20 bytes from the input and return it', async () => { @@ -172,7 +173,7 @@ describe('LibBytes', () => { it('should revert if dest is shorter than source', async () => { return expectRevertOrOtherErrorAsync( libBytes.publicDeepCopyBytes.callAsync(byteArrayShorterThan32Bytes, byteArrayLongerThan32Bytes), - constants.LIB_BYTES_GREATER_OR_EQUAL_TO_SOURCE_BYTES_LENGTH_REQUIRED, + ContractLibErrors.LibBytesGreaterOrEqualToSourceBytesLengthRequired ); }); it('should overwrite dest with source if source and dest have equal length', async () => { @@ -225,7 +226,7 @@ describe('LibBytes', () => { const offset = new BigNumber(0); return expectRevertOrOtherErrorAsync( libBytes.publicReadAddress.callAsync(shortByteArray, offset), - constants.LIB_BYTES_GREATER_OR_EQUAL_TO_20_LENGTH_REQUIRED, + ContractLibErrors.LibBytesGreaterOrEqualTo20LengthRequired, ); }); it('should fail if the length between the offset and end of the byte array is too short to hold an address', async () => { @@ -233,7 +234,7 @@ describe('LibBytes', () => { const badOffset = new BigNumber(ethUtil.toBuffer(byteArray).byteLength); return expectRevertOrOtherErrorAsync( libBytes.publicReadAddress.callAsync(byteArray, badOffset), - constants.LIB_BYTES_GREATER_OR_EQUAL_TO_20_LENGTH_REQUIRED, + ContractLibErrors.LibBytesGreaterOrEqualTo20LengthRequired, ); }); }); @@ -269,7 +270,7 @@ describe('LibBytes', () => { const offset = new BigNumber(0); return expectRevertOrOtherErrorAsync( libBytes.publicWriteAddress.callAsync(byteArrayShorterThan20Bytes, offset, testAddress), - constants.LIB_BYTES_GREATER_OR_EQUAL_TO_20_LENGTH_REQUIRED, + ContractLibErrors.LibBytesGreaterOrEqualTo20LengthRequired, ); }); it('should fail if the length between the offset and end of the byte array is too short to hold an address', async () => { @@ -277,7 +278,7 @@ describe('LibBytes', () => { const badOffset = new BigNumber(ethUtil.toBuffer(byteArray).byteLength); return expectRevertOrOtherErrorAsync( libBytes.publicWriteAddress.callAsync(byteArray, badOffset, testAddress), - constants.LIB_BYTES_GREATER_OR_EQUAL_TO_20_LENGTH_REQUIRED, + ContractLibErrors.LibBytesGreaterOrEqualTo20LengthRequired, ); }); }); @@ -301,14 +302,14 @@ describe('LibBytes', () => { const offset = new BigNumber(0); return expectRevertOrOtherErrorAsync( libBytes.publicReadBytes32.callAsync(byteArrayShorterThan32Bytes, offset), - constants.LIB_BYTES_GREATER_OR_EQUAL_TO_32_LENGTH_REQUIRED, + ContractLibErrors.LibBytesGreaterOrEqualTo32LengthRequired, ); }); it('should fail if the length between the offset and end of the byte array is too short to hold a bytes32', async () => { const badOffset = new BigNumber(ethUtil.toBuffer(testBytes32).byteLength); return expectRevertOrOtherErrorAsync( libBytes.publicReadBytes32.callAsync(testBytes32, badOffset), - constants.LIB_BYTES_GREATER_OR_EQUAL_TO_32_LENGTH_REQUIRED, + ContractLibErrors.LibBytesGreaterOrEqualTo32LengthRequired, ); }); }); @@ -344,7 +345,7 @@ describe('LibBytes', () => { const offset = new BigNumber(0); return expectRevertOrOtherErrorAsync( libBytes.publicWriteBytes32.callAsync(byteArrayShorterThan32Bytes, offset, testBytes32), - constants.LIB_BYTES_GREATER_OR_EQUAL_TO_32_LENGTH_REQUIRED, + ContractLibErrors.LibBytesGreaterOrEqualTo32LengthRequired, ); }); it('should fail if the length between the offset and end of the byte array is too short to hold a bytes32', async () => { @@ -352,7 +353,7 @@ describe('LibBytes', () => { const badOffset = new BigNumber(ethUtil.toBuffer(byteArray).byteLength); return expectRevertOrOtherErrorAsync( libBytes.publicWriteBytes32.callAsync(byteArray, badOffset, testBytes32), - constants.LIB_BYTES_GREATER_OR_EQUAL_TO_32_LENGTH_REQUIRED, + ContractLibErrors.LibBytesGreaterOrEqualTo32LengthRequired, ); }); }); @@ -380,7 +381,7 @@ describe('LibBytes', () => { const offset = new BigNumber(0); return expectRevertOrOtherErrorAsync( libBytes.publicReadUint256.callAsync(byteArrayShorterThan32Bytes, offset), - constants.LIB_BYTES_GREATER_OR_EQUAL_TO_32_LENGTH_REQUIRED, + ContractLibErrors.LibBytesGreaterOrEqualTo32LengthRequired, ); }); it('should fail if the length between the offset and end of the byte array is too short to hold a uint256', async () => { @@ -390,7 +391,7 @@ describe('LibBytes', () => { const badOffset = new BigNumber(testUint256AsBuffer.byteLength); return expectRevertOrOtherErrorAsync( libBytes.publicReadUint256.callAsync(byteArray, badOffset), - constants.LIB_BYTES_GREATER_OR_EQUAL_TO_32_LENGTH_REQUIRED, + ContractLibErrors.LibBytesGreaterOrEqualTo32LengthRequired, ); }); }); @@ -430,7 +431,7 @@ describe('LibBytes', () => { const offset = new BigNumber(0); return expectRevertOrOtherErrorAsync( libBytes.publicWriteUint256.callAsync(byteArrayShorterThan32Bytes, offset, testUint256), - constants.LIB_BYTES_GREATER_OR_EQUAL_TO_32_LENGTH_REQUIRED, + ContractLibErrors.LibBytesGreaterOrEqualTo32LengthRequired, ); }); it('should fail if the length between the offset and end of the byte array is too short to hold a uint256', async () => { @@ -438,7 +439,7 @@ describe('LibBytes', () => { const badOffset = new BigNumber(ethUtil.toBuffer(byteArray).byteLength); return expectRevertOrOtherErrorAsync( libBytes.publicWriteUint256.callAsync(byteArray, badOffset, testUint256), - constants.LIB_BYTES_GREATER_OR_EQUAL_TO_32_LENGTH_REQUIRED, + ContractLibErrors.LibBytesGreaterOrEqualTo32LengthRequired, ); }); }); @@ -449,7 +450,7 @@ describe('LibBytes', () => { const byteArrayLessThan4Bytes = '0x010101'; return expectRevertOrOtherErrorAsync( libBytes.publicReadFirst4.callAsync(byteArrayLessThan4Bytes), - constants.LIB_BYTES_GREATER_OR_EQUAL_TO_4_LENGTH_REQUIRED, + ContractLibErrors.LibBytesGreaterOrEqualTo4LengthRequired, ); }); it('should return the first 4 bytes of a byte array of arbitrary length', async () => { @@ -504,28 +505,28 @@ describe('LibBytes', () => { const offset = new BigNumber(0); return expectRevertOrOtherErrorAsync( libBytes.publicReadBytes.callAsync(byteArrayShorterThan32Bytes, offset), - constants.LIB_BYTES_GREATER_OR_EQUAL_TO_32_LENGTH_REQUIRED, + ContractLibErrors.LibBytesGreaterOrEqualTo32LengthRequired, ); }); it('should fail if we store a nested byte array length, without a nested byte array', async () => { const offset = new BigNumber(0); return expectRevertOrOtherErrorAsync( libBytes.publicReadBytes.callAsync(testBytes32, offset), - constants.LIB_BYTES_GREATER_OR_EQUAL_TO_NESTED_BYTES_LENGTH_REQUIRED, + ContractLibErrors.LibBytesGreaterOrEqualToNestedBytesLengthRequired, ); }); it('should fail if the length between the offset and end of the byte array is too short to hold the length of a nested byte array', async () => { const badOffset = new BigNumber(ethUtil.toBuffer(byteArrayShorterThan32Bytes).byteLength); return expectRevertOrOtherErrorAsync( libBytes.publicReadBytes.callAsync(byteArrayShorterThan32Bytes, badOffset), - constants.LIB_BYTES_GREATER_OR_EQUAL_TO_32_LENGTH_REQUIRED, + ContractLibErrors.LibBytesGreaterOrEqualTo32LengthRequired, ); }); it('should fail if the length between the offset and end of the byte array is too short to hold the nested byte array', async () => { const badOffset = new BigNumber(ethUtil.toBuffer(testBytes32).byteLength); return expectRevertOrOtherErrorAsync( libBytes.publicReadBytes.callAsync(testBytes32, badOffset), - constants.LIB_BYTES_GREATER_OR_EQUAL_TO_32_LENGTH_REQUIRED, + ContractLibErrors.LibBytesGreaterOrEqualTo32LengthRequired, ); }); }); @@ -605,7 +606,7 @@ describe('LibBytes', () => { const emptyByteArray = ethUtil.bufferToHex(new Buffer(1)); return expectRevertOrOtherErrorAsync( libBytes.publicWriteBytes.callAsync(emptyByteArray, offset, longData), - constants.LIB_BYTES_GREATER_OR_EQUAL_TO_NESTED_BYTES_LENGTH_REQUIRED, + ContractLibErrors.LibBytesGreaterOrEqualToNestedBytesLengthRequired, ); }); it('should fail if the length between the offset and end of the byte array is too short to hold the length of a nested byte array)', async () => { @@ -613,7 +614,7 @@ describe('LibBytes', () => { const badOffset = new BigNumber(ethUtil.toBuffer(shortTestBytesAsBuffer).byteLength); return expectRevertOrOtherErrorAsync( libBytes.publicWriteBytes.callAsync(emptyByteArray, badOffset, shortData), - constants.LIB_BYTES_GREATER_OR_EQUAL_TO_NESTED_BYTES_LENGTH_REQUIRED, + ContractLibErrors.LibBytesGreaterOrEqualToNestedBytesLengthRequired, ); }); }); diff --git a/packages/contracts/test/unlimited_allowance_token.ts b/packages/contracts/test/unlimited_allowance_token.ts index 7132c57bf..b7d7acd48 100644 --- a/packages/contracts/test/unlimited_allowance_token.ts +++ b/packages/contracts/test/unlimited_allowance_token.ts @@ -7,6 +7,7 @@ import { artifacts } from '../src/utils/artifacts'; import { expectRevertOrOtherErrorAsync } from '../src/utils/assertions'; import { chaiSetup } from '../src/utils/chai_setup'; import { constants } from '../src/utils/constants'; +import { ContractLibErrors } from '../src/utils/types'; import { provider, txDefaults, web3Wrapper } from '../src/utils/web3_wrapper'; chaiSetup.configure(); @@ -55,7 +56,7 @@ describe('UnlimitedAllowanceToken', () => { const amountToTransfer = ownerBalance.plus(1); return expectRevertOrOtherErrorAsync( token.transfer.callAsync(spender, amountToTransfer, { from: owner }), - constants.ERC20_INSUFFICIENT_BALANCE, + ContractLibErrors.Erc20InsufficientBalance, ); }); @@ -96,7 +97,7 @@ describe('UnlimitedAllowanceToken', () => { token.transferFrom.callAsync(owner, spender, amountToTransfer, { from: spender, }), - constants.ERC20_INSUFFICIENT_BALANCE, + ContractLibErrors.Erc20InsufficientBalance, ); }); @@ -112,7 +113,7 @@ describe('UnlimitedAllowanceToken', () => { token.transferFrom.callAsync(owner, spender, amountToTransfer, { from: spender, }), - constants.ERC20_INSUFFICIENT_ALLOWANCE, + ContractLibErrors.Erc20InsufficientAllowance, ); }); -- cgit From 7a216901bec6f7f3640d41fb90dcc49ed673cc6f Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Fri, 22 Jun 2018 18:41:55 +0200 Subject: Remove revert reason 'Exchange' prefix --- packages/contracts/src/utils/types.ts | 4 ++-- packages/contracts/test/exchange/signature_validator.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'packages/contracts') diff --git a/packages/contracts/src/utils/types.ts b/packages/contracts/src/utils/types.ts index f65a9858b..b3da040c3 100644 --- a/packages/contracts/src/utils/types.ts +++ b/packages/contracts/src/utils/types.ts @@ -173,8 +173,8 @@ export enum ContractLibErrors { AssetProxyMismatch = 'ASSET_PROXY_MISMATCH', AssetProxyIdMismatch = 'ASSET_PROXY_ID_MISMATCH', LengthGreaterThan0Required = 'LENGTH_GREATER_THAN_0_REQUIRED', - ExchangeLength0Required = 'LENGTH_0_REQUIRED', - ExchangeLength65Required = 'LENGTH_65_REQUIRED', + Length0Required = 'LENGTH_0_REQUIRED', + Length65Required = 'LENGTH_65_REQUIRED', InvalidAmount = 'INVALID_AMOUNT', TransferFailed = 'TRANSFER_FAILED', SenderNotAuthorized = 'SENDER_NOT_AUTHORIZED', diff --git a/packages/contracts/test/exchange/signature_validator.ts b/packages/contracts/test/exchange/signature_validator.ts index d53e0758e..e3442a4c2 100644 --- a/packages/contracts/test/exchange/signature_validator.ts +++ b/packages/contracts/test/exchange/signature_validator.ts @@ -162,7 +162,7 @@ describe('MixinSignatureValidator', () => { signedOrder.makerAddress, signatureHex, ), - ContractLibErrors.ExchangeLength0Required, + ContractLibErrors.Length0Required, ); }); -- cgit From 4409f11b24324e23ee2f53436c0226028820e96d Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Fri, 22 Jun 2018 18:45:45 +0200 Subject: Rename ContractLibErrors to RevertReasons --- packages/contracts/src/utils/types.ts | 2 +- .../contracts/test/asset_proxy/authorizable.ts | 10 ++--- packages/contracts/test/asset_proxy/proxies.ts | 18 ++++---- packages/contracts/test/exchange/core.ts | 48 +++++++++++----------- packages/contracts/test/exchange/dispatcher.ts | 10 ++--- packages/contracts/test/exchange/match_orders.ts | 12 +++--- .../contracts/test/exchange/signature_validator.ts | 10 ++--- packages/contracts/test/exchange/transactions.ts | 16 ++++---- packages/contracts/test/exchange/wrapper.ts | 12 +++--- packages/contracts/test/libraries/lib_bytes.ts | 46 ++++++++++----------- .../contracts/test/unlimited_allowance_token.ts | 8 ++-- 11 files changed, 96 insertions(+), 96 deletions(-) (limited to 'packages/contracts') diff --git a/packages/contracts/src/utils/types.ts b/packages/contracts/src/utils/types.ts index b3da040c3..03eb5c9b2 100644 --- a/packages/contracts/src/utils/types.ts +++ b/packages/contracts/src/utils/types.ts @@ -152,7 +152,7 @@ export interface MatchOrder { rightSignature: string; } -export enum ContractLibErrors { +export enum RevertReasons { OrderUnfillable = 'ORDER_UNFILLABLE', InvalidMaker = 'INVALID_MAKER', InvalidTaker = 'INVALID_TAKER', diff --git a/packages/contracts/test/asset_proxy/authorizable.ts b/packages/contracts/test/asset_proxy/authorizable.ts index 1ebb094a1..267444ee6 100644 --- a/packages/contracts/test/asset_proxy/authorizable.ts +++ b/packages/contracts/test/asset_proxy/authorizable.ts @@ -8,7 +8,7 @@ import { } from '../../src/utils/assertions'; import { chaiSetup } from '../../src/utils/chai_setup'; import { constants } from '../../src/utils/constants'; -import { ContractLibErrors } from '../../src/utils/types'; +import { RevertReasons } from '../../src/utils/types'; import { provider, txDefaults, web3Wrapper } from '../../src/utils/web3_wrapper'; chaiSetup.configure(); @@ -47,7 +47,7 @@ describe('Authorizable', () => { it('should throw if not called by owner', async () => { return expectRevertReasonOrAlwaysFailingTransactionAsync( authorizable.addAuthorizedAddress.sendTransactionAsync(notOwner, { from: notOwner }), - ContractLibErrors.OnlyContractOwner, + RevertReasons.OnlyContractOwner, ); }); it('should allow owner to add an authorized address', async () => { @@ -65,7 +65,7 @@ describe('Authorizable', () => { ); return expectRevertReasonOrAlwaysFailingTransactionAsync( authorizable.addAuthorizedAddress.sendTransactionAsync(address, { from: owner }), - ContractLibErrors.TargetAlreadyAuthorized, + RevertReasons.TargetAlreadyAuthorized, ); }); }); @@ -80,7 +80,7 @@ describe('Authorizable', () => { authorizable.removeAuthorizedAddress.sendTransactionAsync(address, { from: notOwner, }), - ContractLibErrors.OnlyContractOwner, + RevertReasons.OnlyContractOwner, ); }); @@ -104,7 +104,7 @@ describe('Authorizable', () => { authorizable.removeAuthorizedAddress.sendTransactionAsync(address, { from: owner, }), - ContractLibErrors.TargetNotAuthorized, + RevertReasons.TargetNotAuthorized, ); }); }); diff --git a/packages/contracts/test/asset_proxy/proxies.ts b/packages/contracts/test/asset_proxy/proxies.ts index 2c1f52973..0429a3137 100644 --- a/packages/contracts/test/asset_proxy/proxies.ts +++ b/packages/contracts/test/asset_proxy/proxies.ts @@ -24,7 +24,7 @@ import { constants } from '../../src/utils/constants'; import { ERC20Wrapper } from '../../src/utils/erc20_wrapper'; import { ERC721Wrapper } from '../../src/utils/erc721_wrapper'; import { LogDecoder } from '../../src/utils/log_decoder'; -import { ContractLibErrors } from '../../src/utils/types'; +import { RevertReasons } from '../../src/utils/types'; import { provider, txDefaults, web3Wrapper } from '../../src/utils/web3_wrapper'; chaiSetup.configure(); @@ -172,7 +172,7 @@ describe('Asset Transfer Proxies', () => { transferAmount, { from: exchangeAddress }, ), - ContractLibErrors.TransferFailed, + RevertReasons.TransferFailed, ); }); @@ -192,7 +192,7 @@ describe('Asset Transfer Proxies', () => { from: notAuthorized, }, ), - ContractLibErrors.SenderNotAuthorized, + RevertReasons.SenderNotAuthorized, ); }); }); @@ -246,7 +246,7 @@ describe('Asset Transfer Proxies', () => { erc20Proxy.batchTransferFrom.sendTransactionAsync(assetData, fromAddresses, toAddresses, amounts, { from: notAuthorized, }), - ContractLibErrors.SenderNotAuthorized, + RevertReasons.SenderNotAuthorized, ); }); }); @@ -392,7 +392,7 @@ describe('Asset Transfer Proxies', () => { amount, { from: exchangeAddress }, ), - ContractLibErrors.InvalidAmount, + RevertReasons.InvalidAmount, ); }); @@ -413,7 +413,7 @@ describe('Asset Transfer Proxies', () => { amount, { from: exchangeAddress }, ), - ContractLibErrors.InvalidAmount, + RevertReasons.InvalidAmount, ); }); @@ -440,7 +440,7 @@ describe('Asset Transfer Proxies', () => { from: exchangeAddress, }, ), - ContractLibErrors.TransferFailed, + RevertReasons.TransferFailed, ); }); @@ -458,7 +458,7 @@ describe('Asset Transfer Proxies', () => { amount, { from: notAuthorized }, ), - ContractLibErrors.SenderNotAuthorized, + RevertReasons.SenderNotAuthorized, ); }); }); @@ -513,7 +513,7 @@ describe('Asset Transfer Proxies', () => { erc721Proxy.batchTransferFrom.sendTransactionAsync(assetData, fromAddresses, toAddresses, amounts, { from: notAuthorized, }), - ContractLibErrors.SenderNotAuthorized, + RevertReasons.SenderNotAuthorized, ); }); }); diff --git a/packages/contracts/test/exchange/core.ts b/packages/contracts/test/exchange/core.ts index d35ff7dee..7d4539ae6 100644 --- a/packages/contracts/test/exchange/core.ts +++ b/packages/contracts/test/exchange/core.ts @@ -27,7 +27,7 @@ import { ERC20Wrapper } from '../../src/utils/erc20_wrapper'; import { ERC721Wrapper } from '../../src/utils/erc721_wrapper'; import { ExchangeWrapper } from '../../src/utils/exchange_wrapper'; import { OrderFactory } from '../../src/utils/order_factory'; -import { ContractLibErrors, ERC20BalancesByOwner } from '../../src/utils/types'; +import { RevertReasons, ERC20BalancesByOwner } from '../../src/utils/types'; import { provider, txDefaults, web3Wrapper } from '../../src/utils/web3_wrapper'; chaiSetup.configure(); @@ -420,7 +420,7 @@ describe('Exchange core', () => { }); return expectRevertReasonOrAlwaysFailingTransactionAsync( exchangeWrapper.fillOrderAsync(signedOrder, takerAddress), - ContractLibErrors.InvalidTaker, + RevertReasons.InvalidTaker, ); }); @@ -438,7 +438,7 @@ describe('Exchange core', () => { signedOrder.signature = invalidSigHex; return expectRevertReasonOrAlwaysFailingTransactionAsync( exchangeWrapper.fillOrderAsync(signedOrder, takerAddress), - ContractLibErrors.InvalidOrderSignature, + RevertReasons.InvalidOrderSignature, ); }); @@ -449,7 +449,7 @@ describe('Exchange core', () => { return expectRevertReasonOrAlwaysFailingTransactionAsync( exchangeWrapper.fillOrderAsync(signedOrder, takerAddress), - ContractLibErrors.OrderUnfillable, + RevertReasons.OrderUnfillable, ); }); @@ -460,7 +460,7 @@ describe('Exchange core', () => { return expectRevertReasonOrAlwaysFailingTransactionAsync( exchangeWrapper.fillOrderAsync(signedOrder, takerAddress), - ContractLibErrors.OrderUnfillable, + RevertReasons.OrderUnfillable, ); }); @@ -471,7 +471,7 @@ describe('Exchange core', () => { exchangeWrapper.fillOrderAsync(signedOrder, takerAddress, { takerAssetFillAmount: new BigNumber(0), }), - ContractLibErrors.InvalidTakerAmount, + RevertReasons.InvalidTakerAmount, ); }); @@ -482,7 +482,7 @@ describe('Exchange core', () => { return expectRevertReasonOrAlwaysFailingTransactionAsync( exchangeWrapper.fillOrderAsync(signedOrder, takerAddress), - ContractLibErrors.TransferFailed, + RevertReasons.TransferFailed, ); }); @@ -492,7 +492,7 @@ describe('Exchange core', () => { }); return expectRevertReasonOrAlwaysFailingTransactionAsync( exchangeWrapper.fillOrderAsync(signedOrder, takerAddress), - ContractLibErrors.TransferFailed, + RevertReasons.TransferFailed, ); }); @@ -505,7 +505,7 @@ describe('Exchange core', () => { ); return expectRevertReasonOrAlwaysFailingTransactionAsync( exchangeWrapper.fillOrderAsync(signedOrder, takerAddress), - ContractLibErrors.TransferFailed, + RevertReasons.TransferFailed, ); }); @@ -518,7 +518,7 @@ describe('Exchange core', () => { ); return expectRevertReasonOrAlwaysFailingTransactionAsync( exchangeWrapper.fillOrderAsync(signedOrder, takerAddress), - ContractLibErrors.TransferFailed, + RevertReasons.TransferFailed, ); }); @@ -528,7 +528,7 @@ describe('Exchange core', () => { }); return expectRevertReasonOrAlwaysFailingTransactionAsync( exchangeWrapper.fillOrderAsync(signedOrder, takerAddress), - ContractLibErrors.OrderUnfillable, + RevertReasons.OrderUnfillable, ); }); @@ -537,7 +537,7 @@ describe('Exchange core', () => { await exchangeWrapper.fillOrderAsync(signedOrder, takerAddress); return expectRevertReasonOrAlwaysFailingTransactionAsync( exchangeWrapper.fillOrderAsync(signedOrder, takerAddress), - ContractLibErrors.OrderUnfillable, + RevertReasons.OrderUnfillable, ); }); }); @@ -551,7 +551,7 @@ describe('Exchange core', () => { it('should throw if not sent by maker', async () => { return expectRevertReasonOrAlwaysFailingTransactionAsync( exchangeWrapper.cancelOrderAsync(signedOrder, takerAddress), - ContractLibErrors.InvalidMaker, + RevertReasons.InvalidMaker, ); }); @@ -562,7 +562,7 @@ describe('Exchange core', () => { return expectRevertReasonOrAlwaysFailingTransactionAsync( exchangeWrapper.cancelOrderAsync(signedOrder, makerAddress), - ContractLibErrors.OrderUnfillable, + RevertReasons.OrderUnfillable, ); }); @@ -573,7 +573,7 @@ describe('Exchange core', () => { return expectRevertReasonOrAlwaysFailingTransactionAsync( exchangeWrapper.cancelOrderAsync(signedOrder, makerAddress), - ContractLibErrors.OrderUnfillable, + RevertReasons.OrderUnfillable, ); }); @@ -583,7 +583,7 @@ describe('Exchange core', () => { exchangeWrapper.fillOrderAsync(signedOrder, takerAddress, { takerAssetFillAmount: signedOrder.takerAssetAmount.div(2), }), - ContractLibErrors.OrderUnfillable, + RevertReasons.OrderUnfillable, ); }); @@ -606,7 +606,7 @@ describe('Exchange core', () => { await exchangeWrapper.cancelOrderAsync(signedOrder, makerAddress); return expectRevertReasonOrAlwaysFailingTransactionAsync( exchangeWrapper.cancelOrderAsync(signedOrder, makerAddress), - ContractLibErrors.OrderUnfillable, + RevertReasons.OrderUnfillable, ); }); @@ -616,7 +616,7 @@ describe('Exchange core', () => { }); return expectRevertReasonOrAlwaysFailingTransactionAsync( exchangeWrapper.cancelOrderAsync(signedOrder, makerAddress), - ContractLibErrors.OrderUnfillable, + RevertReasons.OrderUnfillable, ); }); @@ -636,7 +636,7 @@ describe('Exchange core', () => { exchangeWrapper.fillOrderAsync(signedOrder, takerAddress, { takerAssetFillAmount: fillTakerAssetAmount2, }), - ContractLibErrors.RoundingError, + RevertReasons.RoundingError, ); }); }); @@ -648,7 +648,7 @@ describe('Exchange core', () => { const lesserOrderEpoch = new BigNumber(0); return expectRevertReasonOrAlwaysFailingTransactionAsync( exchangeWrapper.cancelOrdersUpToAsync(lesserOrderEpoch, makerAddress), - ContractLibErrors.InvalidNewOrderEpoch, + RevertReasons.InvalidNewOrderEpoch, ); }); @@ -657,7 +657,7 @@ describe('Exchange core', () => { await exchangeWrapper.cancelOrdersUpToAsync(orderEpoch, makerAddress); return expectRevertReasonOrAlwaysFailingTransactionAsync( exchangeWrapper.cancelOrdersUpToAsync(orderEpoch, makerAddress), - ContractLibErrors.InvalidNewOrderEpoch, + RevertReasons.InvalidNewOrderEpoch, ); }); @@ -817,7 +817,7 @@ describe('Exchange core', () => { const takerAssetFillAmount = signedOrder.takerAssetAmount; return expectRevertReasonOrAlwaysFailingTransactionAsync( exchangeWrapper.fillOrderAsync(signedOrder, takerAddress, { takerAssetFillAmount }), - ContractLibErrors.InvalidAmount, + RevertReasons.InvalidAmount, ); }); @@ -840,7 +840,7 @@ describe('Exchange core', () => { const takerAssetFillAmount = signedOrder.takerAssetAmount; return expectRevertReasonOrAlwaysFailingTransactionAsync( exchangeWrapper.fillOrderAsync(signedOrder, takerAddress, { takerAssetFillAmount }), - ContractLibErrors.InvalidAmount, + RevertReasons.InvalidAmount, ); }); @@ -857,7 +857,7 @@ describe('Exchange core', () => { const takerAssetFillAmount = signedOrder.takerAssetAmount.div(2); return expectRevertReasonOrAlwaysFailingTransactionAsync( exchangeWrapper.fillOrderAsync(signedOrder, takerAddress, { takerAssetFillAmount }), - ContractLibErrors.RoundingError, + RevertReasons.RoundingError, ); }); diff --git a/packages/contracts/test/exchange/dispatcher.ts b/packages/contracts/test/exchange/dispatcher.ts index d463f6c35..8bf1b3d37 100644 --- a/packages/contracts/test/exchange/dispatcher.ts +++ b/packages/contracts/test/exchange/dispatcher.ts @@ -14,7 +14,7 @@ import { chaiSetup } from '../../src/utils/chai_setup'; import { constants } from '../../src/utils/constants'; import { ERC20Wrapper } from '../../src/utils/erc20_wrapper'; import { ERC721Wrapper } from '../../src/utils/erc721_wrapper'; -import { ContractLibErrors } from '../../src/utils/types'; +import { RevertReasons } from '../../src/utils/types'; import { provider, txDefaults, web3Wrapper } from '../../src/utils/web3_wrapper'; chaiSetup.configure(); @@ -183,7 +183,7 @@ describe('AssetProxyDispatcher', () => { constants.NULL_ADDRESS, { from: owner }, ), - ContractLibErrors.AssetProxyMismatch, + RevertReasons.AssetProxyMismatch, ); }); @@ -225,7 +225,7 @@ describe('AssetProxyDispatcher', () => { prevProxyAddress, { from: notOwner }, ), - ContractLibErrors.OnlyContractOwner, + RevertReasons.OnlyContractOwner, ); }); @@ -238,7 +238,7 @@ describe('AssetProxyDispatcher', () => { prevProxyAddress, { from: owner }, ), - ContractLibErrors.AssetProxyIdMismatch, + RevertReasons.AssetProxyIdMismatch, ); }); }); @@ -320,7 +320,7 @@ describe('AssetProxyDispatcher', () => { amount, { from: owner }, ), - ContractLibErrors.AssetProxyDoesNotExist, + RevertReasons.AssetProxyDoesNotExist, ); }); }); diff --git a/packages/contracts/test/exchange/match_orders.ts b/packages/contracts/test/exchange/match_orders.ts index 9d2378dc8..0f7cd32fd 100644 --- a/packages/contracts/test/exchange/match_orders.ts +++ b/packages/contracts/test/exchange/match_orders.ts @@ -22,7 +22,7 @@ import { ERC721Wrapper } from '../../src/utils/erc721_wrapper'; import { ExchangeWrapper } from '../../src/utils/exchange_wrapper'; import { MatchOrderTester } from '../../src/utils/match_order_tester'; import { OrderFactory } from '../../src/utils/order_factory'; -import { ContractLibErrors, ERC20BalancesByOwner, ERC721TokenIdsByOwner, OrderInfo, OrderStatus } from '../../src/utils/types'; +import { RevertReasons, ERC20BalancesByOwner, ERC721TokenIdsByOwner, OrderInfo, OrderStatus } from '../../src/utils/types'; import { provider, txDefaults, web3Wrapper } from '../../src/utils/web3_wrapper'; chaiSetup.configure(); @@ -602,7 +602,7 @@ describe('matchOrders', () => { // Match orders return expectRevertReasonOrAlwaysFailingTransactionAsync( exchangeWrapper.matchOrdersAsync(signedOrderLeft, signedOrderRight, takerAddress), - ContractLibErrors.OrderUnfillable, + RevertReasons.OrderUnfillable, ); }); @@ -627,7 +627,7 @@ describe('matchOrders', () => { // Match orders return expectRevertReasonOrAlwaysFailingTransactionAsync( exchangeWrapper.matchOrdersAsync(signedOrderLeft, signedOrderRight, takerAddress), - ContractLibErrors.OrderUnfillable, + RevertReasons.OrderUnfillable, ); }); @@ -656,7 +656,7 @@ describe('matchOrders', () => { erc20BalancesByOwner, erc721TokenIdsByOwner, ), - ContractLibErrors.NegativeSpreadRequired, + RevertReasons.NegativeSpreadRequired, ); }); @@ -689,7 +689,7 @@ describe('matchOrders', () => { // reverse of the left order, rather than checking equality. This // saves a bunch of gas, but as a result if the assetData fields are // off then the failure ends up happening at signature validation - ContractLibErrors.InvalidOrderSignature, + RevertReasons.InvalidOrderSignature, ); }); @@ -720,7 +720,7 @@ describe('matchOrders', () => { erc20BalancesByOwner, erc721TokenIdsByOwner, ), - ContractLibErrors.InvalidOrderSignature, + RevertReasons.InvalidOrderSignature, ); }); diff --git a/packages/contracts/test/exchange/signature_validator.ts b/packages/contracts/test/exchange/signature_validator.ts index e3442a4c2..f829e0820 100644 --- a/packages/contracts/test/exchange/signature_validator.ts +++ b/packages/contracts/test/exchange/signature_validator.ts @@ -18,7 +18,7 @@ import { chaiSetup } from '../../src/utils/chai_setup'; import { constants } from '../../src/utils/constants'; import { LogDecoder } from '../../src/utils/log_decoder'; import { OrderFactory } from '../../src/utils/order_factory'; -import { ContractLibErrors } from '../../src/utils/types'; +import { RevertReasons } from '../../src/utils/types'; import { provider, txDefaults, web3Wrapper } from '../../src/utils/web3_wrapper'; chaiSetup.configure(); @@ -108,7 +108,7 @@ describe('MixinSignatureValidator', () => { signedOrder.makerAddress, emptySignature, ), - ContractLibErrors.LengthGreaterThan0Required, + RevertReasons.LengthGreaterThan0Required, ); }); @@ -122,7 +122,7 @@ describe('MixinSignatureValidator', () => { signedOrder.makerAddress, unsupportedSignatureHex, ), - ContractLibErrors.SignatureUnsupported, + RevertReasons.SignatureUnsupported, ); }); @@ -135,7 +135,7 @@ describe('MixinSignatureValidator', () => { signedOrder.makerAddress, unsupportedSignatureHex, ), - ContractLibErrors.SignatureIllegal, + RevertReasons.SignatureIllegal, ); }); @@ -162,7 +162,7 @@ describe('MixinSignatureValidator', () => { signedOrder.makerAddress, signatureHex, ), - ContractLibErrors.Length0Required, + RevertReasons.Length0Required, ); }); diff --git a/packages/contracts/test/exchange/transactions.ts b/packages/contracts/test/exchange/transactions.ts index 958a6dce8..c2a70de26 100644 --- a/packages/contracts/test/exchange/transactions.ts +++ b/packages/contracts/test/exchange/transactions.ts @@ -20,7 +20,7 @@ import { ExchangeWrapper } from '../../src/utils/exchange_wrapper'; import { OrderFactory } from '../../src/utils/order_factory'; import { orderUtils } from '../../src/utils/order_utils'; import { TransactionFactory } from '../../src/utils/transaction_factory'; -import { ContractLibErrors, ERC20BalancesByOwner, SignedTransaction } from '../../src/utils/types'; +import { RevertReasons, ERC20BalancesByOwner, SignedTransaction } from '../../src/utils/types'; import { provider, txDefaults, web3Wrapper } from '../../src/utils/web3_wrapper'; chaiSetup.configure(); @@ -129,7 +129,7 @@ describe('Exchange transactions', () => { it('should throw if not called by specified sender', async () => { return expectRevertReasonOrAlwaysFailingTransactionAsync( exchangeWrapper.executeTransactionAsync(signedTx, takerAddress), - ContractLibErrors.FailedExecution, + RevertReasons.FailedExecution, ); }); @@ -172,7 +172,7 @@ describe('Exchange transactions', () => { await exchangeWrapper.executeTransactionAsync(signedTx, senderAddress); return expectRevertReasonOrAlwaysFailingTransactionAsync( exchangeWrapper.executeTransactionAsync(signedTx, senderAddress), - ContractLibErrors.InvalidTxHash, + RevertReasons.InvalidTxHash, ); }); @@ -192,7 +192,7 @@ describe('Exchange transactions', () => { it('should throw if not called by specified sender', async () => { return expectRevertReasonOrAlwaysFailingTransactionAsync( exchangeWrapper.executeTransactionAsync(signedTx, makerAddress), - ContractLibErrors.FailedExecution, + RevertReasons.FailedExecution, ); }); @@ -200,7 +200,7 @@ describe('Exchange transactions', () => { await exchangeWrapper.executeTransactionAsync(signedTx, senderAddress); return expectRevertReasonOrAlwaysFailingTransactionAsync( exchangeWrapper.fillOrderAsync(signedOrder, senderAddress), - ContractLibErrors.OrderUnfillable, + RevertReasons.OrderUnfillable, ); }); }); @@ -252,7 +252,7 @@ describe('Exchange transactions', () => { signedFillTx.signature, { from: takerAddress }, ), - ContractLibErrors.FailedExecution, + RevertReasons.FailedExecution, ); }); @@ -371,7 +371,7 @@ describe('Exchange transactions', () => { signedOrder.signature, { from: takerAddress }, ), - ContractLibErrors.MakerNotWhitelisted, + RevertReasons.MakerNotWhitelisted, ); }); @@ -393,7 +393,7 @@ describe('Exchange transactions', () => { signedOrder.signature, { from: takerAddress }, ), - ContractLibErrors.TakerNotWhitelisted, + RevertReasons.TakerNotWhitelisted, ); }); diff --git a/packages/contracts/test/exchange/wrapper.ts b/packages/contracts/test/exchange/wrapper.ts index 3d7465659..26bdc24d0 100644 --- a/packages/contracts/test/exchange/wrapper.ts +++ b/packages/contracts/test/exchange/wrapper.ts @@ -21,7 +21,7 @@ import { ERC20Wrapper } from '../../src/utils/erc20_wrapper'; import { ERC721Wrapper } from '../../src/utils/erc721_wrapper'; import { ExchangeWrapper } from '../../src/utils/exchange_wrapper'; import { OrderFactory } from '../../src/utils/order_factory'; -import { ContractLibErrors, ERC20BalancesByOwner } from '../../src/utils/types'; +import { RevertReasons, ERC20BalancesByOwner } from '../../src/utils/types'; import { provider, txDefaults, web3Wrapper } from '../../src/utils/web3_wrapper'; chaiSetup.configure(); @@ -174,7 +174,7 @@ describe('Exchange wrappers', () => { return expectRevertReasonOrAlwaysFailingTransactionAsync( exchangeWrapper.fillOrKillOrderAsync(signedOrder, takerAddress), - ContractLibErrors.OrderUnfillable, + RevertReasons.OrderUnfillable, ); }); @@ -187,7 +187,7 @@ describe('Exchange wrappers', () => { return expectRevertReasonOrAlwaysFailingTransactionAsync( exchangeWrapper.fillOrKillOrderAsync(signedOrder, takerAddress), - ContractLibErrors.CompleteFillFailed, + RevertReasons.CompleteFillFailed, ); }); }); @@ -502,7 +502,7 @@ describe('Exchange wrappers', () => { exchangeWrapper.batchFillOrKillOrdersAsync(signedOrders, takerAddress, { takerAssetFillAmounts, }), - ContractLibErrors.OrderUnfillable, + RevertReasons.OrderUnfillable, ); }); }); @@ -707,7 +707,7 @@ describe('Exchange wrappers', () => { }), // We simply use the takerAssetData from the first order for all orders. // If they are not the same, the contract throws when validating the order signature - ContractLibErrors.InvalidOrderSignature, + RevertReasons.InvalidOrderSignature, ); }); }); @@ -923,7 +923,7 @@ describe('Exchange wrappers', () => { exchangeWrapper.marketBuyOrdersAsync(signedOrders, takerAddress, { makerAssetFillAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(1000), 18), }), - ContractLibErrors.InvalidOrderSignature, + RevertReasons.InvalidOrderSignature, ); }); }); diff --git a/packages/contracts/test/libraries/lib_bytes.ts b/packages/contracts/test/libraries/lib_bytes.ts index 2d54596d5..bc1856b40 100644 --- a/packages/contracts/test/libraries/lib_bytes.ts +++ b/packages/contracts/test/libraries/lib_bytes.ts @@ -11,7 +11,7 @@ import { artifacts } from '../../src/utils/artifacts'; import { expectRevertOrOtherErrorAsync } from '../../src/utils/assertions'; import { chaiSetup } from '../../src/utils/chai_setup'; import { constants } from '../../src/utils/constants'; -import { ContractLibErrors } from '../../src/utils/types'; +import { RevertReasons } from '../../src/utils/types'; import { provider, txDefaults, web3Wrapper } from '../../src/utils/web3_wrapper'; chaiSetup.configure(); @@ -96,7 +96,7 @@ describe('LibBytes', () => { it('should revert if length is 0', async () => { return expectRevertOrOtherErrorAsync( libBytes.publicPopLastByte.callAsync(constants.NULL_BYTES), - ContractLibErrors.LibBytesGreaterThanZeroLengthRequired, + RevertReasons.LibBytesGreaterThanZeroLengthRequired, ); }); it('should pop the last byte from the input and return it', async () => { @@ -112,7 +112,7 @@ describe('LibBytes', () => { it('should revert if length is less than 20', async () => { return expectRevertOrOtherErrorAsync( libBytes.publicPopLast20Bytes.callAsync(byteArrayShorterThan20Bytes), - ContractLibErrors.LibBytesGreaterOrEqualTo20LengthRequired + RevertReasons.LibBytesGreaterOrEqualTo20LengthRequired ); }); it('should pop the last 20 bytes from the input and return it', async () => { @@ -173,7 +173,7 @@ describe('LibBytes', () => { it('should revert if dest is shorter than source', async () => { return expectRevertOrOtherErrorAsync( libBytes.publicDeepCopyBytes.callAsync(byteArrayShorterThan32Bytes, byteArrayLongerThan32Bytes), - ContractLibErrors.LibBytesGreaterOrEqualToSourceBytesLengthRequired + RevertReasons.LibBytesGreaterOrEqualToSourceBytesLengthRequired ); }); it('should overwrite dest with source if source and dest have equal length', async () => { @@ -226,7 +226,7 @@ describe('LibBytes', () => { const offset = new BigNumber(0); return expectRevertOrOtherErrorAsync( libBytes.publicReadAddress.callAsync(shortByteArray, offset), - ContractLibErrors.LibBytesGreaterOrEqualTo20LengthRequired, + RevertReasons.LibBytesGreaterOrEqualTo20LengthRequired, ); }); it('should fail if the length between the offset and end of the byte array is too short to hold an address', async () => { @@ -234,7 +234,7 @@ describe('LibBytes', () => { const badOffset = new BigNumber(ethUtil.toBuffer(byteArray).byteLength); return expectRevertOrOtherErrorAsync( libBytes.publicReadAddress.callAsync(byteArray, badOffset), - ContractLibErrors.LibBytesGreaterOrEqualTo20LengthRequired, + RevertReasons.LibBytesGreaterOrEqualTo20LengthRequired, ); }); }); @@ -270,7 +270,7 @@ describe('LibBytes', () => { const offset = new BigNumber(0); return expectRevertOrOtherErrorAsync( libBytes.publicWriteAddress.callAsync(byteArrayShorterThan20Bytes, offset, testAddress), - ContractLibErrors.LibBytesGreaterOrEqualTo20LengthRequired, + RevertReasons.LibBytesGreaterOrEqualTo20LengthRequired, ); }); it('should fail if the length between the offset and end of the byte array is too short to hold an address', async () => { @@ -278,7 +278,7 @@ describe('LibBytes', () => { const badOffset = new BigNumber(ethUtil.toBuffer(byteArray).byteLength); return expectRevertOrOtherErrorAsync( libBytes.publicWriteAddress.callAsync(byteArray, badOffset, testAddress), - ContractLibErrors.LibBytesGreaterOrEqualTo20LengthRequired, + RevertReasons.LibBytesGreaterOrEqualTo20LengthRequired, ); }); }); @@ -302,14 +302,14 @@ describe('LibBytes', () => { const offset = new BigNumber(0); return expectRevertOrOtherErrorAsync( libBytes.publicReadBytes32.callAsync(byteArrayShorterThan32Bytes, offset), - ContractLibErrors.LibBytesGreaterOrEqualTo32LengthRequired, + RevertReasons.LibBytesGreaterOrEqualTo32LengthRequired, ); }); it('should fail if the length between the offset and end of the byte array is too short to hold a bytes32', async () => { const badOffset = new BigNumber(ethUtil.toBuffer(testBytes32).byteLength); return expectRevertOrOtherErrorAsync( libBytes.publicReadBytes32.callAsync(testBytes32, badOffset), - ContractLibErrors.LibBytesGreaterOrEqualTo32LengthRequired, + RevertReasons.LibBytesGreaterOrEqualTo32LengthRequired, ); }); }); @@ -345,7 +345,7 @@ describe('LibBytes', () => { const offset = new BigNumber(0); return expectRevertOrOtherErrorAsync( libBytes.publicWriteBytes32.callAsync(byteArrayShorterThan32Bytes, offset, testBytes32), - ContractLibErrors.LibBytesGreaterOrEqualTo32LengthRequired, + RevertReasons.LibBytesGreaterOrEqualTo32LengthRequired, ); }); it('should fail if the length between the offset and end of the byte array is too short to hold a bytes32', async () => { @@ -353,7 +353,7 @@ describe('LibBytes', () => { const badOffset = new BigNumber(ethUtil.toBuffer(byteArray).byteLength); return expectRevertOrOtherErrorAsync( libBytes.publicWriteBytes32.callAsync(byteArray, badOffset, testBytes32), - ContractLibErrors.LibBytesGreaterOrEqualTo32LengthRequired, + RevertReasons.LibBytesGreaterOrEqualTo32LengthRequired, ); }); }); @@ -381,7 +381,7 @@ describe('LibBytes', () => { const offset = new BigNumber(0); return expectRevertOrOtherErrorAsync( libBytes.publicReadUint256.callAsync(byteArrayShorterThan32Bytes, offset), - ContractLibErrors.LibBytesGreaterOrEqualTo32LengthRequired, + RevertReasons.LibBytesGreaterOrEqualTo32LengthRequired, ); }); it('should fail if the length between the offset and end of the byte array is too short to hold a uint256', async () => { @@ -391,7 +391,7 @@ describe('LibBytes', () => { const badOffset = new BigNumber(testUint256AsBuffer.byteLength); return expectRevertOrOtherErrorAsync( libBytes.publicReadUint256.callAsync(byteArray, badOffset), - ContractLibErrors.LibBytesGreaterOrEqualTo32LengthRequired, + RevertReasons.LibBytesGreaterOrEqualTo32LengthRequired, ); }); }); @@ -431,7 +431,7 @@ describe('LibBytes', () => { const offset = new BigNumber(0); return expectRevertOrOtherErrorAsync( libBytes.publicWriteUint256.callAsync(byteArrayShorterThan32Bytes, offset, testUint256), - ContractLibErrors.LibBytesGreaterOrEqualTo32LengthRequired, + RevertReasons.LibBytesGreaterOrEqualTo32LengthRequired, ); }); it('should fail if the length between the offset and end of the byte array is too short to hold a uint256', async () => { @@ -439,7 +439,7 @@ describe('LibBytes', () => { const badOffset = new BigNumber(ethUtil.toBuffer(byteArray).byteLength); return expectRevertOrOtherErrorAsync( libBytes.publicWriteUint256.callAsync(byteArray, badOffset, testUint256), - ContractLibErrors.LibBytesGreaterOrEqualTo32LengthRequired, + RevertReasons.LibBytesGreaterOrEqualTo32LengthRequired, ); }); }); @@ -450,7 +450,7 @@ describe('LibBytes', () => { const byteArrayLessThan4Bytes = '0x010101'; return expectRevertOrOtherErrorAsync( libBytes.publicReadFirst4.callAsync(byteArrayLessThan4Bytes), - ContractLibErrors.LibBytesGreaterOrEqualTo4LengthRequired, + RevertReasons.LibBytesGreaterOrEqualTo4LengthRequired, ); }); it('should return the first 4 bytes of a byte array of arbitrary length', async () => { @@ -505,28 +505,28 @@ describe('LibBytes', () => { const offset = new BigNumber(0); return expectRevertOrOtherErrorAsync( libBytes.publicReadBytes.callAsync(byteArrayShorterThan32Bytes, offset), - ContractLibErrors.LibBytesGreaterOrEqualTo32LengthRequired, + RevertReasons.LibBytesGreaterOrEqualTo32LengthRequired, ); }); it('should fail if we store a nested byte array length, without a nested byte array', async () => { const offset = new BigNumber(0); return expectRevertOrOtherErrorAsync( libBytes.publicReadBytes.callAsync(testBytes32, offset), - ContractLibErrors.LibBytesGreaterOrEqualToNestedBytesLengthRequired, + RevertReasons.LibBytesGreaterOrEqualToNestedBytesLengthRequired, ); }); it('should fail if the length between the offset and end of the byte array is too short to hold the length of a nested byte array', async () => { const badOffset = new BigNumber(ethUtil.toBuffer(byteArrayShorterThan32Bytes).byteLength); return expectRevertOrOtherErrorAsync( libBytes.publicReadBytes.callAsync(byteArrayShorterThan32Bytes, badOffset), - ContractLibErrors.LibBytesGreaterOrEqualTo32LengthRequired, + RevertReasons.LibBytesGreaterOrEqualTo32LengthRequired, ); }); it('should fail if the length between the offset and end of the byte array is too short to hold the nested byte array', async () => { const badOffset = new BigNumber(ethUtil.toBuffer(testBytes32).byteLength); return expectRevertOrOtherErrorAsync( libBytes.publicReadBytes.callAsync(testBytes32, badOffset), - ContractLibErrors.LibBytesGreaterOrEqualTo32LengthRequired, + RevertReasons.LibBytesGreaterOrEqualTo32LengthRequired, ); }); }); @@ -606,7 +606,7 @@ describe('LibBytes', () => { const emptyByteArray = ethUtil.bufferToHex(new Buffer(1)); return expectRevertOrOtherErrorAsync( libBytes.publicWriteBytes.callAsync(emptyByteArray, offset, longData), - ContractLibErrors.LibBytesGreaterOrEqualToNestedBytesLengthRequired, + RevertReasons.LibBytesGreaterOrEqualToNestedBytesLengthRequired, ); }); it('should fail if the length between the offset and end of the byte array is too short to hold the length of a nested byte array)', async () => { @@ -614,7 +614,7 @@ describe('LibBytes', () => { const badOffset = new BigNumber(ethUtil.toBuffer(shortTestBytesAsBuffer).byteLength); return expectRevertOrOtherErrorAsync( libBytes.publicWriteBytes.callAsync(emptyByteArray, badOffset, shortData), - ContractLibErrors.LibBytesGreaterOrEqualToNestedBytesLengthRequired, + RevertReasons.LibBytesGreaterOrEqualToNestedBytesLengthRequired, ); }); }); diff --git a/packages/contracts/test/unlimited_allowance_token.ts b/packages/contracts/test/unlimited_allowance_token.ts index b7d7acd48..9f52232e2 100644 --- a/packages/contracts/test/unlimited_allowance_token.ts +++ b/packages/contracts/test/unlimited_allowance_token.ts @@ -7,7 +7,7 @@ import { artifacts } from '../src/utils/artifacts'; import { expectRevertOrOtherErrorAsync } from '../src/utils/assertions'; import { chaiSetup } from '../src/utils/chai_setup'; import { constants } from '../src/utils/constants'; -import { ContractLibErrors } from '../src/utils/types'; +import { RevertReasons } from '../src/utils/types'; import { provider, txDefaults, web3Wrapper } from '../src/utils/web3_wrapper'; chaiSetup.configure(); @@ -56,7 +56,7 @@ describe('UnlimitedAllowanceToken', () => { const amountToTransfer = ownerBalance.plus(1); return expectRevertOrOtherErrorAsync( token.transfer.callAsync(spender, amountToTransfer, { from: owner }), - ContractLibErrors.Erc20InsufficientBalance, + RevertReasons.Erc20InsufficientBalance, ); }); @@ -97,7 +97,7 @@ describe('UnlimitedAllowanceToken', () => { token.transferFrom.callAsync(owner, spender, amountToTransfer, { from: spender, }), - ContractLibErrors.Erc20InsufficientBalance, + RevertReasons.Erc20InsufficientBalance, ); }); @@ -113,7 +113,7 @@ describe('UnlimitedAllowanceToken', () => { token.transferFrom.callAsync(owner, spender, amountToTransfer, { from: spender, }), - ContractLibErrors.Erc20InsufficientAllowance, + RevertReasons.Erc20InsufficientAllowance, ); }); -- cgit From 1e03fbe1a8aba1c5a8b358272de81a09a201eec9 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Fri, 22 Jun 2018 18:50:02 +0200 Subject: Fix prettier --- packages/contracts/test/asset_proxy/authorizable.ts | 4 +--- packages/contracts/test/exchange/match_orders.ts | 12 ++++++++---- packages/contracts/test/exchange/transactions.ts | 4 +--- packages/contracts/test/exchange/wrapper.ts | 4 +--- packages/contracts/test/libraries/lib_bytes.ts | 4 ++-- 5 files changed, 13 insertions(+), 15 deletions(-) (limited to 'packages/contracts') diff --git a/packages/contracts/test/asset_proxy/authorizable.ts b/packages/contracts/test/asset_proxy/authorizable.ts index 267444ee6..a317f217a 100644 --- a/packages/contracts/test/asset_proxy/authorizable.ts +++ b/packages/contracts/test/asset_proxy/authorizable.ts @@ -3,9 +3,7 @@ import * as chai from 'chai'; import { MixinAuthorizableContract } from '../../src/generated_contract_wrappers/mixin_authorizable'; import { artifacts } from '../../src/utils/artifacts'; -import { - expectRevertReasonOrAlwaysFailingTransactionAsync, -} from '../../src/utils/assertions'; +import { expectRevertReasonOrAlwaysFailingTransactionAsync } from '../../src/utils/assertions'; import { chaiSetup } from '../../src/utils/chai_setup'; import { constants } from '../../src/utils/constants'; import { RevertReasons } from '../../src/utils/types'; diff --git a/packages/contracts/test/exchange/match_orders.ts b/packages/contracts/test/exchange/match_orders.ts index 0f7cd32fd..30a37e01e 100644 --- a/packages/contracts/test/exchange/match_orders.ts +++ b/packages/contracts/test/exchange/match_orders.ts @@ -12,9 +12,7 @@ import { ERC20ProxyContract } from '../../src/generated_contract_wrappers/e_r_c2 import { ERC721ProxyContract } from '../../src/generated_contract_wrappers/e_r_c721_proxy'; import { ExchangeContract } from '../../src/generated_contract_wrappers/exchange'; import { artifacts } from '../../src/utils/artifacts'; -import { - expectRevertReasonOrAlwaysFailingTransactionAsync, -} from '../../src/utils/assertions'; +import { expectRevertReasonOrAlwaysFailingTransactionAsync } from '../../src/utils/assertions'; import { chaiSetup } from '../../src/utils/chai_setup'; import { constants } from '../../src/utils/constants'; import { ERC20Wrapper } from '../../src/utils/erc20_wrapper'; @@ -22,7 +20,13 @@ import { ERC721Wrapper } from '../../src/utils/erc721_wrapper'; import { ExchangeWrapper } from '../../src/utils/exchange_wrapper'; import { MatchOrderTester } from '../../src/utils/match_order_tester'; import { OrderFactory } from '../../src/utils/order_factory'; -import { RevertReasons, ERC20BalancesByOwner, ERC721TokenIdsByOwner, OrderInfo, OrderStatus } from '../../src/utils/types'; +import { + RevertReasons, + ERC20BalancesByOwner, + ERC721TokenIdsByOwner, + OrderInfo, + OrderStatus, +} from '../../src/utils/types'; import { provider, txDefaults, web3Wrapper } from '../../src/utils/web3_wrapper'; chaiSetup.configure(); diff --git a/packages/contracts/test/exchange/transactions.ts b/packages/contracts/test/exchange/transactions.ts index c2a70de26..d74dde749 100644 --- a/packages/contracts/test/exchange/transactions.ts +++ b/packages/contracts/test/exchange/transactions.ts @@ -10,9 +10,7 @@ import { ExchangeContract } from '../../src/generated_contract_wrappers/exchange import { ExchangeWrapperContract } from '../../src/generated_contract_wrappers/exchange_wrapper'; import { WhitelistContract } from '../../src/generated_contract_wrappers/whitelist'; import { artifacts } from '../../src/utils/artifacts'; -import { - expectRevertReasonOrAlwaysFailingTransactionAsync, -} from '../../src/utils/assertions'; +import { expectRevertReasonOrAlwaysFailingTransactionAsync } from '../../src/utils/assertions'; import { chaiSetup } from '../../src/utils/chai_setup'; import { constants } from '../../src/utils/constants'; import { ERC20Wrapper } from '../../src/utils/erc20_wrapper'; diff --git a/packages/contracts/test/exchange/wrapper.ts b/packages/contracts/test/exchange/wrapper.ts index 26bdc24d0..3ff02f9e2 100644 --- a/packages/contracts/test/exchange/wrapper.ts +++ b/packages/contracts/test/exchange/wrapper.ts @@ -12,9 +12,7 @@ import { ERC20ProxyContract } from '../../src/generated_contract_wrappers/e_r_c2 import { ERC721ProxyContract } from '../../src/generated_contract_wrappers/e_r_c721_proxy'; import { ExchangeContract } from '../../src/generated_contract_wrappers/exchange'; import { artifacts } from '../../src/utils/artifacts'; -import { - expectRevertReasonOrAlwaysFailingTransactionAsync, -} from '../../src/utils/assertions'; +import { expectRevertReasonOrAlwaysFailingTransactionAsync } from '../../src/utils/assertions'; import { chaiSetup } from '../../src/utils/chai_setup'; import { constants } from '../../src/utils/constants'; import { ERC20Wrapper } from '../../src/utils/erc20_wrapper'; diff --git a/packages/contracts/test/libraries/lib_bytes.ts b/packages/contracts/test/libraries/lib_bytes.ts index bc1856b40..7db0f60b5 100644 --- a/packages/contracts/test/libraries/lib_bytes.ts +++ b/packages/contracts/test/libraries/lib_bytes.ts @@ -112,7 +112,7 @@ describe('LibBytes', () => { it('should revert if length is less than 20', async () => { return expectRevertOrOtherErrorAsync( libBytes.publicPopLast20Bytes.callAsync(byteArrayShorterThan20Bytes), - RevertReasons.LibBytesGreaterOrEqualTo20LengthRequired + RevertReasons.LibBytesGreaterOrEqualTo20LengthRequired, ); }); it('should pop the last 20 bytes from the input and return it', async () => { @@ -173,7 +173,7 @@ describe('LibBytes', () => { it('should revert if dest is shorter than source', async () => { return expectRevertOrOtherErrorAsync( libBytes.publicDeepCopyBytes.callAsync(byteArrayShorterThan32Bytes, byteArrayLongerThan32Bytes), - RevertReasons.LibBytesGreaterOrEqualToSourceBytesLengthRequired + RevertReasons.LibBytesGreaterOrEqualToSourceBytesLengthRequired, ); }); it('should overwrite dest with source if source and dest have equal length', async () => { -- cgit From 2f6f815d81ff0f36a35a31c40bff7df1a974a1af Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Fri, 22 Jun 2018 18:54:18 +0200 Subject: Fix tslint --- packages/contracts/test/exchange/core.ts | 2 +- packages/contracts/test/exchange/match_orders.ts | 2 +- packages/contracts/test/exchange/transactions.ts | 2 +- packages/contracts/test/exchange/wrapper.ts | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) (limited to 'packages/contracts') diff --git a/packages/contracts/test/exchange/core.ts b/packages/contracts/test/exchange/core.ts index 7d4539ae6..069a2ab87 100644 --- a/packages/contracts/test/exchange/core.ts +++ b/packages/contracts/test/exchange/core.ts @@ -27,7 +27,7 @@ import { ERC20Wrapper } from '../../src/utils/erc20_wrapper'; import { ERC721Wrapper } from '../../src/utils/erc721_wrapper'; import { ExchangeWrapper } from '../../src/utils/exchange_wrapper'; import { OrderFactory } from '../../src/utils/order_factory'; -import { RevertReasons, ERC20BalancesByOwner } from '../../src/utils/types'; +import { ERC20BalancesByOwner, RevertReasons } from '../../src/utils/types'; import { provider, txDefaults, web3Wrapper } from '../../src/utils/web3_wrapper'; chaiSetup.configure(); diff --git a/packages/contracts/test/exchange/match_orders.ts b/packages/contracts/test/exchange/match_orders.ts index 30a37e01e..c9a78321d 100644 --- a/packages/contracts/test/exchange/match_orders.ts +++ b/packages/contracts/test/exchange/match_orders.ts @@ -21,11 +21,11 @@ import { ExchangeWrapper } from '../../src/utils/exchange_wrapper'; import { MatchOrderTester } from '../../src/utils/match_order_tester'; import { OrderFactory } from '../../src/utils/order_factory'; import { - RevertReasons, ERC20BalancesByOwner, ERC721TokenIdsByOwner, OrderInfo, OrderStatus, + RevertReasons, } from '../../src/utils/types'; import { provider, txDefaults, web3Wrapper } from '../../src/utils/web3_wrapper'; diff --git a/packages/contracts/test/exchange/transactions.ts b/packages/contracts/test/exchange/transactions.ts index d74dde749..b2e097760 100644 --- a/packages/contracts/test/exchange/transactions.ts +++ b/packages/contracts/test/exchange/transactions.ts @@ -18,7 +18,7 @@ import { ExchangeWrapper } from '../../src/utils/exchange_wrapper'; import { OrderFactory } from '../../src/utils/order_factory'; import { orderUtils } from '../../src/utils/order_utils'; import { TransactionFactory } from '../../src/utils/transaction_factory'; -import { RevertReasons, ERC20BalancesByOwner, SignedTransaction } from '../../src/utils/types'; +import { ERC20BalancesByOwner, RevertReasons, SignedTransaction } from '../../src/utils/types'; import { provider, txDefaults, web3Wrapper } from '../../src/utils/web3_wrapper'; chaiSetup.configure(); diff --git a/packages/contracts/test/exchange/wrapper.ts b/packages/contracts/test/exchange/wrapper.ts index 3ff02f9e2..6e8a1aeb7 100644 --- a/packages/contracts/test/exchange/wrapper.ts +++ b/packages/contracts/test/exchange/wrapper.ts @@ -19,7 +19,7 @@ import { ERC20Wrapper } from '../../src/utils/erc20_wrapper'; import { ERC721Wrapper } from '../../src/utils/erc721_wrapper'; import { ExchangeWrapper } from '../../src/utils/exchange_wrapper'; import { OrderFactory } from '../../src/utils/order_factory'; -import { RevertReasons, ERC20BalancesByOwner } from '../../src/utils/types'; +import { ERC20BalancesByOwner, RevertReasons } from '../../src/utils/types'; import { provider, txDefaults, web3Wrapper } from '../../src/utils/web3_wrapper'; chaiSetup.configure(); -- cgit