From a5a7217c8f24fe98275fd9927ca8c5e5f140c6f3 Mon Sep 17 00:00:00 2001 From: Amir Bandeali Date: Wed, 9 May 2018 16:27:50 -0700 Subject: Add deepCopyBytes method to LibBytes --- packages/contracts/test/libraries/lib_bytes.ts | 34 ++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'packages/contracts/test') diff --git a/packages/contracts/test/libraries/lib_bytes.ts b/packages/contracts/test/libraries/lib_bytes.ts index 968bac300..1fd30a3e0 100644 --- a/packages/contracts/test/libraries/lib_bytes.ts +++ b/packages/contracts/test/libraries/lib_bytes.ts @@ -60,6 +60,40 @@ describe('LibBytes', () => { await blockchainLifecycle.revertAsync(); }); + describe.only('deepCopyBytes', () => { + const byteArrayLongerThan32BytesLen = (byteArrayLongerThan32Bytes.length - 2) / 2; + it('should throw if length of copy is 0', async () => { + const index = new BigNumber(0); + const len = new BigNumber(0); + return expect( + libBytes.publicDeepCopyBytes.callAsync(byteArrayLongerThan32Bytes, index, len), + ).to.be.rejectedWith(constants.REVERT); + }); + + it('should throw if start index + length to copy is greater than length of byte array', async () => { + const index = new BigNumber(0); + const len = new BigNumber(byteArrayLongerThan32BytesLen + 1); + return expect( + libBytes.publicDeepCopyBytes.callAsync(byteArrayLongerThan32Bytes, index, len), + ).to.be.rejectedWith(constants.REVERT); + }); + + it('should copy the entire byte array if index = 0 and len = b.length', async () => { + const index = new BigNumber(0); + const len = new BigNumber(byteArrayLongerThan32BytesLen); + const copy = await libBytes.publicDeepCopyBytes.callAsync(byteArrayLongerThan32Bytes, index, len); + expect(copy).to.equal(byteArrayLongerThan32Bytes); + }); + + it('should copy part of the byte array if area to copy is less than b.length', async () => { + const index = new BigNumber(10); + const len = new BigNumber(4); + const copy = await libBytes.publicDeepCopyBytes.callAsync(byteArrayLongerThan32Bytes, index, len); + const expectedCopy = `0x${byteArrayLongerThan32Bytes.slice(22, 30)}`; + expect(copy).to.equal(expectedCopy); + }); + }); + describe('areBytesEqual', () => { it('should return true if byte arrays are equal (both arrays < 32 bytes)', async () => { const areBytesEqual = await libBytes.publicAreBytesEqual.callAsync( -- cgit v1.2.3 From b587f076fe02a21274c91d35b6a18a7ba86e3b58 Mon Sep 17 00:00:00 2001 From: Amir Bandeali Date: Wed, 9 May 2018 16:42:25 -0700 Subject: Add Validator signature type --- packages/contracts/test/libraries/lib_bytes.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'packages/contracts/test') diff --git a/packages/contracts/test/libraries/lib_bytes.ts b/packages/contracts/test/libraries/lib_bytes.ts index 1fd30a3e0..ac654e037 100644 --- a/packages/contracts/test/libraries/lib_bytes.ts +++ b/packages/contracts/test/libraries/lib_bytes.ts @@ -60,7 +60,7 @@ describe('LibBytes', () => { await blockchainLifecycle.revertAsync(); }); - describe.only('deepCopyBytes', () => { + describe('deepCopyBytes', () => { const byteArrayLongerThan32BytesLen = (byteArrayLongerThan32Bytes.length - 2) / 2; it('should throw if length of copy is 0', async () => { const index = new BigNumber(0); -- cgit v1.2.3 From d6be6f79ce944258193d01fa3a23c5210e17ed49 Mon Sep 17 00:00:00 2001 From: Amir Bandeali Date: Thu, 26 Apr 2018 12:55:16 -0700 Subject: Add example whitelist contract and minimum tests --- packages/contracts/test/exchange/transactions.ts | 91 +++++++++++++++++++++++- 1 file changed, 89 insertions(+), 2 deletions(-) (limited to 'packages/contracts/test') diff --git a/packages/contracts/test/exchange/transactions.ts b/packages/contracts/test/exchange/transactions.ts index 33fe11bfa..7242b0063 100644 --- a/packages/contracts/test/exchange/transactions.ts +++ b/packages/contracts/test/exchange/transactions.ts @@ -8,6 +8,7 @@ import * as Web3 from 'web3'; import { DummyERC20TokenContract } from '../../src/contract_wrappers/generated/dummy_e_r_c20_token'; import { ERC20ProxyContract } from '../../src/contract_wrappers/generated/e_r_c20_proxy'; import { ExchangeContract } from '../../src/contract_wrappers/generated/exchange'; +import { WhitelistContract } from '../../src/contract_wrappers/generated/whitelist'; import { artifacts } from '../../src/utils/artifacts'; import { assetProxyUtils } from '../../src/utils/asset_proxy_utils'; import { chaiSetup } from '../../src/utils/chai_setup'; @@ -55,6 +56,8 @@ describe('Exchange transactions', () => { let defaultMakerTokenAddress: string; let defaultTakerTokenAddress: string; + let makerPrivateKey: Buffer; + let takerPrivateKey: Buffer; before(async () => { await blockchainLifecycle.startAsync(); @@ -98,8 +101,8 @@ describe('Exchange transactions', () => { makerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultMakerTokenAddress), takerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultTakerTokenAddress), }; - const makerPrivateKey = constants.TESTRPC_PRIVATE_KEYS[accounts.indexOf(makerAddress)]; - const takerPrivateKey = constants.TESTRPC_PRIVATE_KEYS[accounts.indexOf(takerAddress)]; + makerPrivateKey = constants.TESTRPC_PRIVATE_KEYS[accounts.indexOf(makerAddress)]; + takerPrivateKey = constants.TESTRPC_PRIVATE_KEYS[accounts.indexOf(takerAddress)]; orderFactory = new OrderFactory(makerPrivateKey, defaultOrderParams); makerTransactionFactory = new TransactionFactory(makerPrivateKey, exchange.address); takerTransactionFactory = new TransactionFactory(takerPrivateKey, exchange.address); @@ -203,4 +206,88 @@ describe('Exchange transactions', () => { }); }); }); + + describe('Whitelist', () => { + let whitelist: WhitelistContract; + let whitelistOrderFactory: OrderFactory; + + before(async () => { + const whitelistInstance = await deployer.deployAsync(ContractName.Whitelist, [exchange.address]); + whitelist = new WhitelistContract(whitelistInstance.abi, whitelistInstance.address, provider); + const defaultOrderParams = { + ...constants.STATIC_ORDER_PARAMS, + senderAddress: whitelist.address, + exchangeAddress: exchange.address, + makerAddress, + feeRecipientAddress, + makerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultMakerTokenAddress), + takerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultTakerTokenAddress), + }; + whitelistOrderFactory = new OrderFactory(makerPrivateKey, defaultOrderParams); + }); + + beforeEach(async () => { + signedOrder = whitelistOrderFactory.newSignedOrder(); + erc20Balances = await erc20Wrapper.getBalancesAsync(); + }); + + it('should revert if taker has not been whitelisted', async () => { + const orderStruct = orderUtils.getOrderStruct(signedOrder); + const takerAssetFillAmount = signedOrder.takerAssetAmount; + const salt = ZeroEx.generatePseudoRandomSalt(); + return expect( + whitelist.fillOrderIfWhitelisted.sendTransactionAsync( + orderStruct, + takerAssetFillAmount, + salt, + signedOrder.signature, + { from: takerAddress }, + ), + ).to.be.rejectedWith(constants.REVERT); + }); + + it('should fill the order if taker has been whitelisted', async () => { + const isApproved = true; + await whitelist.updateWhitelistStatus.sendTransactionAsync(takerAddress, isApproved, { from: owner }); + + const orderStruct = orderUtils.getOrderStruct(signedOrder); + const takerAssetFillAmount = signedOrder.takerAssetAmount; + const salt = ZeroEx.generatePseudoRandomSalt(); + await whitelist.fillOrderIfWhitelisted.sendTransactionAsync( + orderStruct, + takerAssetFillAmount, + salt, + signedOrder.signature, + { from: takerAddress }, + ); + + const newBalances = await erc20Wrapper.getBalancesAsync(); + + const makerAssetFillAmount = signedOrder.makerAssetAmount; + const makerFeePaid = signedOrder.makerFee; + const takerFeePaid = signedOrder.takerFee; + + expect(newBalances[makerAddress][defaultMakerTokenAddress]).to.be.bignumber.equal( + erc20Balances[makerAddress][defaultMakerTokenAddress].minus(makerAssetFillAmount), + ); + expect(newBalances[makerAddress][defaultTakerTokenAddress]).to.be.bignumber.equal( + erc20Balances[makerAddress][defaultTakerTokenAddress].add(takerAssetFillAmount), + ); + expect(newBalances[makerAddress][zrxToken.address]).to.be.bignumber.equal( + erc20Balances[makerAddress][zrxToken.address].minus(makerFeePaid), + ); + expect(newBalances[takerAddress][defaultTakerTokenAddress]).to.be.bignumber.equal( + erc20Balances[takerAddress][defaultTakerTokenAddress].minus(takerAssetFillAmount), + ); + expect(newBalances[takerAddress][defaultMakerTokenAddress]).to.be.bignumber.equal( + erc20Balances[takerAddress][defaultMakerTokenAddress].add(makerAssetFillAmount), + ); + expect(newBalances[takerAddress][zrxToken.address]).to.be.bignumber.equal( + erc20Balances[takerAddress][zrxToken.address].minus(takerFeePaid), + ); + expect(newBalances[feeRecipientAddress][zrxToken.address]).to.be.bignumber.equal( + erc20Balances[feeRecipientAddress][zrxToken.address].add(makerFeePaid.add(takerFeePaid)), + ); + }); + }); }); -- cgit v1.2.3 From 4b71c65aea44bba34429e288c5411a090dd78071 Mon Sep 17 00:00:00 2001 From: Amir Bandeali Date: Wed, 9 May 2018 14:41:44 -0700 Subject: Update Whitelist contract with comments, also require maker to be whitelisted --- packages/contracts/test/exchange/transactions.ts | 33 +++++++++++++++++++++--- 1 file changed, 29 insertions(+), 4 deletions(-) (limited to 'packages/contracts/test') diff --git a/packages/contracts/test/exchange/transactions.ts b/packages/contracts/test/exchange/transactions.ts index 7242b0063..fe6df2f75 100644 --- a/packages/contracts/test/exchange/transactions.ts +++ b/packages/contracts/test/exchange/transactions.ts @@ -212,8 +212,12 @@ describe('Exchange transactions', () => { let whitelistOrderFactory: OrderFactory; before(async () => { - const whitelistInstance = await deployer.deployAsync(ContractName.Whitelist, [exchange.address]); - whitelist = new WhitelistContract(whitelistInstance.abi, whitelistInstance.address, provider); + whitelist = await WhitelistContract.deployFrom0xArtifactAsync( + artifacts.Whitelist, + provider, + txDefaults, + exchange.address, + ); const defaultOrderParams = { ...constants.STATIC_ORDER_PARAMS, senderAddress: whitelist.address, @@ -231,7 +235,28 @@ describe('Exchange transactions', () => { erc20Balances = await erc20Wrapper.getBalancesAsync(); }); + it('should revert if maker has not been whitelisted', async () => { + const isApproved = true; + await whitelist.updateWhitelistStatus.sendTransactionAsync(takerAddress, isApproved, { from: owner }); + + const orderStruct = orderUtils.getOrderStruct(signedOrder); + const takerAssetFillAmount = signedOrder.takerAssetAmount; + const salt = ZeroEx.generatePseudoRandomSalt(); + return expect( + whitelist.fillOrderIfWhitelisted.sendTransactionAsync( + orderStruct, + takerAssetFillAmount, + salt, + signedOrder.signature, + { from: takerAddress }, + ), + ).to.be.rejectedWith(constants.REVERT); + }); + it('should revert if taker has not been whitelisted', async () => { + const isApproved = true; + await whitelist.updateWhitelistStatus.sendTransactionAsync(makerAddress, isApproved, { from: owner }); + const orderStruct = orderUtils.getOrderStruct(signedOrder); const takerAssetFillAmount = signedOrder.takerAssetAmount; const salt = ZeroEx.generatePseudoRandomSalt(); @@ -246,8 +271,9 @@ describe('Exchange transactions', () => { ).to.be.rejectedWith(constants.REVERT); }); - it('should fill the order if taker has been whitelisted', async () => { + it('should fill the order if maker and taker have been whitelisted', async () => { const isApproved = true; + await whitelist.updateWhitelistStatus.sendTransactionAsync(makerAddress, isApproved, { from: owner }); await whitelist.updateWhitelistStatus.sendTransactionAsync(takerAddress, isApproved, { from: owner }); const orderStruct = orderUtils.getOrderStruct(signedOrder); @@ -260,7 +286,6 @@ describe('Exchange transactions', () => { signedOrder.signature, { from: takerAddress }, ); - const newBalances = await erc20Wrapper.getBalancesAsync(); const makerAssetFillAmount = signedOrder.makerAssetAmount; -- cgit v1.2.3 From 6d462fc961da2ba4d5502ad6b71654c1715550d9 Mon Sep 17 00:00:00 2001 From: Amir Bandeali Date: Mon, 21 May 2018 10:04:17 -0700 Subject: Remove TxOrigin signature type, modify whitelist to use Validator signature type --- packages/contracts/test/exchange/transactions.ts | 4 ++++ packages/contracts/test/libraries/lib_bytes.ts | 7 +++---- 2 files changed, 7 insertions(+), 4 deletions(-) (limited to 'packages/contracts/test') diff --git a/packages/contracts/test/exchange/transactions.ts b/packages/contracts/test/exchange/transactions.ts index fe6df2f75..294e3aae9 100644 --- a/packages/contracts/test/exchange/transactions.ts +++ b/packages/contracts/test/exchange/transactions.ts @@ -218,6 +218,10 @@ describe('Exchange transactions', () => { txDefaults, exchange.address, ); + const isApproved = true; + await exchange.approveSignatureValidator.sendTransactionAsync(whitelist.address, isApproved, { + from: takerAddress, + }); const defaultOrderParams = { ...constants.STATIC_ORDER_PARAMS, senderAddress: whitelist.address, diff --git a/packages/contracts/test/libraries/lib_bytes.ts b/packages/contracts/test/libraries/lib_bytes.ts index ac654e037..c85cee5e3 100644 --- a/packages/contracts/test/libraries/lib_bytes.ts +++ b/packages/contracts/test/libraries/lib_bytes.ts @@ -62,12 +62,11 @@ describe('LibBytes', () => { describe('deepCopyBytes', () => { const byteArrayLongerThan32BytesLen = (byteArrayLongerThan32Bytes.length - 2) / 2; - it('should throw if length of copy is 0', async () => { + it('should return a byte array of length 0 if len is 0', async () => { const index = new BigNumber(0); const len = new BigNumber(0); - return expect( - libBytes.publicDeepCopyBytes.callAsync(byteArrayLongerThan32Bytes, index, len), - ).to.be.rejectedWith(constants.REVERT); + const copy = await libBytes.publicDeepCopyBytes.callAsync(byteArrayLongerThan32Bytes, index, len); + expect(copy).to.equal(constants.NULL_BYTES); }); it('should throw if start index + length to copy is greater than length of byte array', async () => { -- cgit v1.2.3 From 822e319efea9c862702ddf589eb2344ff02e5bc5 Mon Sep 17 00:00:00 2001 From: Amir Bandeali Date: Mon, 21 May 2018 15:59:58 -0700 Subject: Use last byte of signature as signature type --- packages/contracts/test/exchange/core.ts | 5 ++- .../contracts/test/exchange/signature_validator.ts | 8 ++-- packages/contracts/test/libraries/lib_bytes.ts | 47 ++++++++++------------ 3 files changed, 28 insertions(+), 32 deletions(-) (limited to 'packages/contracts/test') diff --git a/packages/contracts/test/exchange/core.ts b/packages/contracts/test/exchange/core.ts index be8d14cb0..bc476a5ee 100644 --- a/packages/contracts/test/exchange/core.ts +++ b/packages/contracts/test/exchange/core.ts @@ -460,10 +460,11 @@ describe('Exchange core', () => { makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(10), 18), }); + const v = ethUtil.toBuffer(signedOrder.signature.slice(0, 4)); const invalidR = ethUtil.sha3('invalidR'); const invalidS = ethUtil.sha3('invalidS'); - const signatureTypeAndV = signedOrder.signature.slice(0, 6); - const invalidSigBuff = Buffer.concat([ethUtil.toBuffer(signatureTypeAndV), invalidR, invalidS]); + const signatureType = ethUtil.toBuffer(`0x${signedOrder.signature.slice(-2)}`); + const invalidSigBuff = Buffer.concat([v, invalidR, invalidS, signatureType]); const invalidSigHex = `0x${invalidSigBuff.toString('hex')}`; signedOrder.signature = invalidSigHex; return expect(exchangeWrapper.fillOrderAsync(signedOrder, takerAddress)).to.be.rejectedWith( diff --git a/packages/contracts/test/exchange/signature_validator.ts b/packages/contracts/test/exchange/signature_validator.ts index 376fff438..ca679e344 100644 --- a/packages/contracts/test/exchange/signature_validator.ts +++ b/packages/contracts/test/exchange/signature_validator.ts @@ -75,13 +75,11 @@ describe('MixinSignatureValidator', () => { }); it('should return false with an invalid signature', async () => { + const v = ethUtil.toBuffer(signedOrder.signature.slice(0, 4)); const invalidR = ethUtil.sha3('invalidR'); const invalidS = ethUtil.sha3('invalidS'); - const invalidSigBuff = Buffer.concat([ - ethUtil.toBuffer(signedOrder.signature.slice(0, 6)), - invalidR, - invalidS, - ]); + const signatureType = ethUtil.toBuffer(`0x${signedOrder.signature.slice(-2)}`); + const invalidSigBuff = Buffer.concat([v, invalidR, invalidS, signatureType]); const invalidSigHex = `0x${invalidSigBuff.toString('hex')}`; signedOrder.signature = invalidSigHex; const orderHashHex = orderUtils.getOrderHashHex(signedOrder); diff --git a/packages/contracts/test/libraries/lib_bytes.ts b/packages/contracts/test/libraries/lib_bytes.ts index c85cee5e3..4eedad25d 100644 --- a/packages/contracts/test/libraries/lib_bytes.ts +++ b/packages/contracts/test/libraries/lib_bytes.ts @@ -22,6 +22,7 @@ describe('LibBytes', () => { let owner: string; let libBytes: TestLibBytesContract; const byteArrayShorterThan32Bytes = '0x012345'; + const byteArrayShorterThan20Bytes = byteArrayShorterThan32Bytes; const byteArrayLongerThan32Bytes = '0x0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef'; const byteArrayLongerThan32BytesFirstBytesSwapped = @@ -60,39 +61,35 @@ describe('LibBytes', () => { await blockchainLifecycle.revertAsync(); }); - describe('deepCopyBytes', () => { - const byteArrayLongerThan32BytesLen = (byteArrayLongerThan32Bytes.length - 2) / 2; - it('should return a byte array of length 0 if len is 0', async () => { - const index = new BigNumber(0); - const len = new BigNumber(0); - const copy = await libBytes.publicDeepCopyBytes.callAsync(byteArrayLongerThan32Bytes, index, len); - expect(copy).to.equal(constants.NULL_BYTES); + describe('popByte', () => { + it('should revert if length is 0', async () => { + return expect(libBytes.publicPopByte.callAsync(constants.NULL_BYTES)).to.be.rejectedWith(constants.REVERT); }); - it('should throw if start index + length to copy is greater than length of byte array', async () => { - const index = new BigNumber(0); - const len = new BigNumber(byteArrayLongerThan32BytesLen + 1); - return expect( - libBytes.publicDeepCopyBytes.callAsync(byteArrayLongerThan32Bytes, index, len), - ).to.be.rejectedWith(constants.REVERT); + it('should pop the last byte from the input and return it', async () => { + const [newBytes, poppedByte] = await libBytes.publicPopByte.callAsync(byteArrayLongerThan32Bytes); + const expectedNewBytes = byteArrayLongerThan32Bytes.slice(0, -2); + const expectedPoppedByte = `0x${byteArrayLongerThan32Bytes.slice(-2)}`; + expect(newBytes).to.equal(expectedNewBytes); + expect(poppedByte).to.equal(expectedPoppedByte); }); + }); - it('should copy the entire byte array if index = 0 and len = b.length', async () => { - const index = new BigNumber(0); - const len = new BigNumber(byteArrayLongerThan32BytesLen); - const copy = await libBytes.publicDeepCopyBytes.callAsync(byteArrayLongerThan32Bytes, index, len); - expect(copy).to.equal(byteArrayLongerThan32Bytes); + describe('popAddress', () => { + it('should revert if length is less than 20', async () => { + return expect(libBytes.publicPopAddress.callAsync(byteArrayShorterThan20Bytes)).to.be.rejectedWith( + constants.REVERT, + ); }); - it('should copy part of the byte array if area to copy is less than b.length', async () => { - const index = new BigNumber(10); - const len = new BigNumber(4); - const copy = await libBytes.publicDeepCopyBytes.callAsync(byteArrayLongerThan32Bytes, index, len); - const expectedCopy = `0x${byteArrayLongerThan32Bytes.slice(22, 30)}`; - expect(copy).to.equal(expectedCopy); + it('should pop the last 20 bytes from the input and return it', async () => { + const [newBytes, poppedAddress] = await libBytes.publicPopAddress.callAsync(byteArrayLongerThan32Bytes); + const expectedNewBytes = byteArrayLongerThan32Bytes.slice(0, -40); + const expectedPoppedAddress = `0x${byteArrayLongerThan32Bytes.slice(-40)}`; + expect(newBytes).to.equal(expectedNewBytes); + expect(poppedAddress).to.equal(expectedPoppedAddress); }); }); - describe('areBytesEqual', () => { it('should return true if byte arrays are equal (both arrays < 32 bytes)', async () => { const areBytesEqual = await libBytes.publicAreBytesEqual.callAsync( -- cgit v1.2.3 From ecdd0ce9f2378a1ac271b9eb5661a6d37d6edf41 Mon Sep 17 00:00:00 2001 From: Amir Bandeali Date: Tue, 22 May 2018 16:57:02 -0700 Subject: Update Whitelist --- packages/contracts/test/libraries/lib_bytes.ts | 1 + 1 file changed, 1 insertion(+) (limited to 'packages/contracts/test') diff --git a/packages/contracts/test/libraries/lib_bytes.ts b/packages/contracts/test/libraries/lib_bytes.ts index 4eedad25d..e817951ab 100644 --- a/packages/contracts/test/libraries/lib_bytes.ts +++ b/packages/contracts/test/libraries/lib_bytes.ts @@ -90,6 +90,7 @@ describe('LibBytes', () => { expect(poppedAddress).to.equal(expectedPoppedAddress); }); }); + describe('areBytesEqual', () => { it('should return true if byte arrays are equal (both arrays < 32 bytes)', async () => { const areBytesEqual = await libBytes.publicAreBytesEqual.callAsync( -- cgit v1.2.3 From 9f93d8f53380bf650702c653fea13b3e7ed5f8f7 Mon Sep 17 00:00:00 2001 From: Amir Bandeali Date: Thu, 24 May 2018 10:24:32 -0700 Subject: Fix formatting and tests --- packages/contracts/test/asset_proxy/authorizable.ts | 6 ------ packages/contracts/test/asset_proxy/proxies.ts | 6 ------ packages/contracts/test/ether_token.ts | 6 ------ packages/contracts/test/exchange/core.ts | 6 ------ packages/contracts/test/exchange/dispatcher.ts | 6 ------ packages/contracts/test/exchange/libs.ts | 10 ++-------- packages/contracts/test/exchange/match_orders.ts | 6 ------ packages/contracts/test/exchange/signature_validator.ts | 7 ------- packages/contracts/test/exchange/transactions.ts | 13 ++++--------- packages/contracts/test/exchange/wrapper.ts | 6 ------ packages/contracts/test/libraries/lib_bytes.ts | 6 ------ packages/contracts/test/token_registry.ts | 6 ------ packages/contracts/test/unlimited_allowance_token.ts | 6 ------ packages/contracts/test/zrx_token.ts | 6 ------ 14 files changed, 6 insertions(+), 90 deletions(-) (limited to 'packages/contracts/test') diff --git a/packages/contracts/test/asset_proxy/authorizable.ts b/packages/contracts/test/asset_proxy/authorizable.ts index 87f89c513..1b7f2bdaf 100644 --- a/packages/contracts/test/asset_proxy/authorizable.ts +++ b/packages/contracts/test/asset_proxy/authorizable.ts @@ -19,12 +19,6 @@ describe('Authorizable', () => { let notOwner: string; let address: string; let authorizable: MixinAuthorizableContract; - before(async () => { - await blockchainLifecycle.startAsync(); - }); - after(async () => { - await blockchainLifecycle.revertAsync(); - }); before(async () => { const accounts = await web3Wrapper.getAvailableAddressesAsync(); owner = address = accounts[0]; diff --git a/packages/contracts/test/asset_proxy/proxies.ts b/packages/contracts/test/asset_proxy/proxies.ts index 9bcdfa2b8..cecc75937 100644 --- a/packages/contracts/test/asset_proxy/proxies.ts +++ b/packages/contracts/test/asset_proxy/proxies.ts @@ -36,12 +36,6 @@ describe('Asset Transfer Proxies', () => { let erc721Wrapper: ERC721Wrapper; let erc721MakerTokenId: BigNumber; - before(async () => { - await blockchainLifecycle.startAsync(); - }); - after(async () => { - await blockchainLifecycle.revertAsync(); - }); before(async () => { const accounts = await web3Wrapper.getAvailableAddressesAsync(); const usedAddresses = ([owner, notAuthorized, exchangeAddress, makerAddress, takerAddress] = accounts); diff --git a/packages/contracts/test/ether_token.ts b/packages/contracts/test/ether_token.ts index 10dd635fe..84b43e05a 100644 --- a/packages/contracts/test/ether_token.ts +++ b/packages/contracts/test/ether_token.ts @@ -19,12 +19,6 @@ describe('EtherToken', () => { const gasPrice = Web3Wrapper.toBaseUnitAmount(new BigNumber(20), 9); let etherToken: WETH9Contract; - before(async () => { - await blockchainLifecycle.startAsync(); - }); - after(async () => { - await blockchainLifecycle.revertAsync(); - }); before(async () => { const accounts = await web3Wrapper.getAvailableAddressesAsync(); account = accounts[0]; diff --git a/packages/contracts/test/exchange/core.ts b/packages/contracts/test/exchange/core.ts index bc476a5ee..70f9ff915 100644 --- a/packages/contracts/test/exchange/core.ts +++ b/packages/contracts/test/exchange/core.ts @@ -60,12 +60,6 @@ describe('Exchange core', () => { let defaultMakerAssetAddress: string; let defaultTakerAssetAddress: string; - before(async () => { - await blockchainLifecycle.startAsync(); - }); - after(async () => { - await blockchainLifecycle.revertAsync(); - }); before(async () => { const accounts = await web3Wrapper.getAvailableAddressesAsync(); const usedAddresses = ([owner, makerAddress, takerAddress, feeRecipientAddress] = accounts); diff --git a/packages/contracts/test/exchange/dispatcher.ts b/packages/contracts/test/exchange/dispatcher.ts index b9c7039bd..66407322b 100644 --- a/packages/contracts/test/exchange/dispatcher.ts +++ b/packages/contracts/test/exchange/dispatcher.ts @@ -35,12 +35,6 @@ describe('AssetProxyDispatcher', () => { let erc20Wrapper: ERC20Wrapper; let erc721Wrapper: ERC721Wrapper; - before(async () => { - await blockchainLifecycle.startAsync(); - }); - after(async () => { - await blockchainLifecycle.revertAsync(); - }); before(async () => { // Setup accounts & addresses const accounts = await web3Wrapper.getAvailableAddressesAsync(); diff --git a/packages/contracts/test/exchange/libs.ts b/packages/contracts/test/exchange/libs.ts index bbca54274..c6c07f633 100644 --- a/packages/contracts/test/exchange/libs.ts +++ b/packages/contracts/test/exchange/libs.ts @@ -24,12 +24,6 @@ describe('Exchange libs', () => { let orderFactory: OrderFactory; let libs: TestLibsContract; - before(async () => { - await blockchainLifecycle.startAsync(); - }); - after(async () => { - await blockchainLifecycle.revertAsync(); - }); before(async () => { const accounts = await web3Wrapper.getAvailableAddressesAsync(); const makerAddress = accounts[0]; @@ -49,7 +43,6 @@ describe('Exchange libs', () => { beforeEach(async () => { await blockchainLifecycle.startAsync(); - signedOrder = orderFactory.newSignedOrder(); }); afterEach(async () => { await blockchainLifecycle.revertAsync(); @@ -69,7 +62,8 @@ describe('Exchange libs', () => { }); }); describe('getOrderHash', () => { - it('should output the correct order hash', async () => { + it('should output the correct orderHash', async () => { + signedOrder = orderFactory.newSignedOrder(); const orderHashHex = await libs.publicGetOrderHash.callAsync(signedOrder); expect(orderUtils.getOrderHashHex(signedOrder)).to.be.equal(orderHashHex); }); diff --git a/packages/contracts/test/exchange/match_orders.ts b/packages/contracts/test/exchange/match_orders.ts index 0da0287bc..754a73d78 100644 --- a/packages/contracts/test/exchange/match_orders.ts +++ b/packages/contracts/test/exchange/match_orders.ts @@ -76,12 +76,6 @@ describe('matchOrders', () => { let matchOrderTester: MatchOrderTester; - before(async () => { - await blockchainLifecycle.startAsync(); - }); - after(async () => { - await blockchainLifecycle.revertAsync(); - }); before(async () => { // Create accounts const accounts = await web3Wrapper.getAvailableAddressesAsync(); diff --git a/packages/contracts/test/exchange/signature_validator.ts b/packages/contracts/test/exchange/signature_validator.ts index ca679e344..08de05047 100644 --- a/packages/contracts/test/exchange/signature_validator.ts +++ b/packages/contracts/test/exchange/signature_validator.ts @@ -24,12 +24,6 @@ describe('MixinSignatureValidator', () => { let orderFactory: OrderFactory; let signatureValidator: TestSignatureValidatorContract; - before(async () => { - await blockchainLifecycle.startAsync(); - }); - after(async () => { - await blockchainLifecycle.revertAsync(); - }); before(async () => { const accounts = await web3Wrapper.getAvailableAddressesAsync(); const makerAddress = accounts[0]; @@ -53,7 +47,6 @@ describe('MixinSignatureValidator', () => { beforeEach(async () => { await blockchainLifecycle.startAsync(); - signedOrder = orderFactory.newSignedOrder(); }); afterEach(async () => { await blockchainLifecycle.revertAsync(); diff --git a/packages/contracts/test/exchange/transactions.ts b/packages/contracts/test/exchange/transactions.ts index 294e3aae9..0d10f6723 100644 --- a/packages/contracts/test/exchange/transactions.ts +++ b/packages/contracts/test/exchange/transactions.ts @@ -1,4 +1,5 @@ import { BlockchainLifecycle } from '@0xproject/dev-utils'; +import { generatePseudoRandomSalt } from '@0xproject/order-utils'; import { Order, SignedOrder } from '@0xproject/types'; import { BigNumber } from '@0xproject/utils'; import * as chai from 'chai'; @@ -59,12 +60,6 @@ describe('Exchange transactions', () => { let makerPrivateKey: Buffer; let takerPrivateKey: Buffer; - before(async () => { - await blockchainLifecycle.startAsync(); - }); - after(async () => { - await blockchainLifecycle.revertAsync(); - }); before(async () => { const accounts = await web3Wrapper.getAvailableAddressesAsync(); const usedAddresses = ([owner, senderAddress, makerAddress, takerAddress, feeRecipientAddress] = accounts); @@ -245,7 +240,7 @@ describe('Exchange transactions', () => { const orderStruct = orderUtils.getOrderStruct(signedOrder); const takerAssetFillAmount = signedOrder.takerAssetAmount; - const salt = ZeroEx.generatePseudoRandomSalt(); + const salt = generatePseudoRandomSalt(); return expect( whitelist.fillOrderIfWhitelisted.sendTransactionAsync( orderStruct, @@ -263,7 +258,7 @@ describe('Exchange transactions', () => { const orderStruct = orderUtils.getOrderStruct(signedOrder); const takerAssetFillAmount = signedOrder.takerAssetAmount; - const salt = ZeroEx.generatePseudoRandomSalt(); + const salt = generatePseudoRandomSalt(); return expect( whitelist.fillOrderIfWhitelisted.sendTransactionAsync( orderStruct, @@ -282,7 +277,7 @@ describe('Exchange transactions', () => { const orderStruct = orderUtils.getOrderStruct(signedOrder); const takerAssetFillAmount = signedOrder.takerAssetAmount; - const salt = ZeroEx.generatePseudoRandomSalt(); + const salt = generatePseudoRandomSalt(); await whitelist.fillOrderIfWhitelisted.sendTransactionAsync( orderStruct, takerAssetFillAmount, diff --git a/packages/contracts/test/exchange/wrapper.ts b/packages/contracts/test/exchange/wrapper.ts index 7e1818f4a..8c27d993e 100644 --- a/packages/contracts/test/exchange/wrapper.ts +++ b/packages/contracts/test/exchange/wrapper.ts @@ -54,12 +54,6 @@ describe('Exchange wrappers', () => { let defaultMakerAssetAddress: string; let defaultTakerAssetAddress: string; - before(async () => { - await blockchainLifecycle.startAsync(); - }); - after(async () => { - await blockchainLifecycle.revertAsync(); - }); before(async () => { const accounts = await web3Wrapper.getAvailableAddressesAsync(); const usedAddresses = ([owner, makerAddress, takerAddress, feeRecipientAddress] = accounts); diff --git a/packages/contracts/test/libraries/lib_bytes.ts b/packages/contracts/test/libraries/lib_bytes.ts index e817951ab..ab92dfc8c 100644 --- a/packages/contracts/test/libraries/lib_bytes.ts +++ b/packages/contracts/test/libraries/lib_bytes.ts @@ -33,12 +33,6 @@ describe('LibBytes', () => { const testBytes32 = '0x102030405060708090a0b0c0d0e0f0102030405060708090a0b0c0d0e0f01020'; const testUint256 = new BigNumber(testBytes32, 16); - before(async () => { - await blockchainLifecycle.startAsync(); - }); - after(async () => { - await blockchainLifecycle.revertAsync(); - }); before(async () => { // Setup accounts & addresses const accounts = await web3Wrapper.getAvailableAddressesAsync(); diff --git a/packages/contracts/test/token_registry.ts b/packages/contracts/test/token_registry.ts index 1cc519c53..df835d8f4 100644 --- a/packages/contracts/test/token_registry.ts +++ b/packages/contracts/test/token_registry.ts @@ -23,12 +23,6 @@ describe('TokenRegistry', () => { let notOwner: string; let tokenReg: TokenRegistryContract; let tokenRegWrapper: TokenRegWrapper; - before(async () => { - await blockchainLifecycle.startAsync(); - }); - after(async () => { - await blockchainLifecycle.revertAsync(); - }); before(async () => { const accounts = await web3Wrapper.getAvailableAddressesAsync(); owner = accounts[0]; diff --git a/packages/contracts/test/unlimited_allowance_token.ts b/packages/contracts/test/unlimited_allowance_token.ts index c68d8bdcf..ab001b770 100644 --- a/packages/contracts/test/unlimited_allowance_token.ts +++ b/packages/contracts/test/unlimited_allowance_token.ts @@ -21,12 +21,6 @@ describe('UnlimitedAllowanceToken', () => { const MAX_MINT_VALUE = new BigNumber(100000000000000000000); let token: DummyERC20TokenContract; - before(async () => { - await blockchainLifecycle.startAsync(); - }); - after(async () => { - await blockchainLifecycle.revertAsync(); - }); before(async () => { const accounts = await web3Wrapper.getAvailableAddressesAsync(); owner = accounts[0]; diff --git a/packages/contracts/test/zrx_token.ts b/packages/contracts/test/zrx_token.ts index fe37e802b..a159b6ed5 100644 --- a/packages/contracts/test/zrx_token.ts +++ b/packages/contracts/test/zrx_token.ts @@ -21,12 +21,6 @@ describe('ZRXToken', () => { let MAX_UINT: BigNumber; let zrxToken: ZRXTokenContract; - before(async () => { - await blockchainLifecycle.startAsync(); - }); - after(async () => { - await blockchainLifecycle.revertAsync(); - }); before(async () => { const accounts = await web3Wrapper.getAvailableAddressesAsync(); owner = accounts[0]; -- cgit v1.2.3 From 1382c1243a421a5ad9e53ede491782cf22de0a5e Mon Sep 17 00:00:00 2001 From: Amir Bandeali Date: Tue, 29 May 2018 12:02:11 -0700 Subject: Add back before/after snapshots for each test --- packages/contracts/test/asset_proxy/authorizable.ts | 6 ++++++ packages/contracts/test/asset_proxy/proxies.ts | 6 ++++++ packages/contracts/test/asset_proxy_owner.ts | 6 ++++++ packages/contracts/test/ether_token.ts | 6 ++++++ packages/contracts/test/exchange/core.ts | 6 ++++++ packages/contracts/test/exchange/dispatcher.ts | 6 ++++++ packages/contracts/test/exchange/libs.ts | 6 ++++++ packages/contracts/test/exchange/match_orders.ts | 6 ++++++ packages/contracts/test/exchange/signature_validator.ts | 6 ++++++ packages/contracts/test/exchange/transactions.ts | 6 ++++++ packages/contracts/test/exchange/wrapper.ts | 6 ++++++ packages/contracts/test/libraries/lib_bytes.ts | 6 ++++++ packages/contracts/test/multi_sig_with_time_lock.ts | 6 ++++++ packages/contracts/test/token_registry.ts | 7 +++++++ packages/contracts/test/unlimited_allowance_token.ts | 6 ++++++ packages/contracts/test/zrx_token.ts | 6 ++++++ 16 files changed, 97 insertions(+) (limited to 'packages/contracts/test') diff --git a/packages/contracts/test/asset_proxy/authorizable.ts b/packages/contracts/test/asset_proxy/authorizable.ts index 1b7f2bdaf..87f89c513 100644 --- a/packages/contracts/test/asset_proxy/authorizable.ts +++ b/packages/contracts/test/asset_proxy/authorizable.ts @@ -19,6 +19,12 @@ describe('Authorizable', () => { let notOwner: string; let address: string; let authorizable: MixinAuthorizableContract; + before(async () => { + await blockchainLifecycle.startAsync(); + }); + after(async () => { + await blockchainLifecycle.revertAsync(); + }); before(async () => { const accounts = await web3Wrapper.getAvailableAddressesAsync(); owner = address = accounts[0]; diff --git a/packages/contracts/test/asset_proxy/proxies.ts b/packages/contracts/test/asset_proxy/proxies.ts index cecc75937..9bcdfa2b8 100644 --- a/packages/contracts/test/asset_proxy/proxies.ts +++ b/packages/contracts/test/asset_proxy/proxies.ts @@ -36,6 +36,12 @@ describe('Asset Transfer Proxies', () => { let erc721Wrapper: ERC721Wrapper; let erc721MakerTokenId: BigNumber; + before(async () => { + await blockchainLifecycle.startAsync(); + }); + after(async () => { + await blockchainLifecycle.revertAsync(); + }); before(async () => { const accounts = await web3Wrapper.getAvailableAddressesAsync(); const usedAddresses = ([owner, notAuthorized, exchangeAddress, makerAddress, takerAddress] = accounts); diff --git a/packages/contracts/test/asset_proxy_owner.ts b/packages/contracts/test/asset_proxy_owner.ts index db68b5678..43c5da512 100644 --- a/packages/contracts/test/asset_proxy_owner.ts +++ b/packages/contracts/test/asset_proxy_owner.ts @@ -35,6 +35,12 @@ describe('AssetProxyOwner', () => { let multiSig: AssetProxyOwnerContract; let multiSigWrapper: MultiSigWrapper; + before(async () => { + await blockchainLifecycle.startAsync(); + }); + after(async () => { + await blockchainLifecycle.revertAsync(); + }); before(async () => { const accounts = await web3Wrapper.getAvailableAddressesAsync(); owners = [accounts[0], accounts[1]]; diff --git a/packages/contracts/test/ether_token.ts b/packages/contracts/test/ether_token.ts index 84b43e05a..10dd635fe 100644 --- a/packages/contracts/test/ether_token.ts +++ b/packages/contracts/test/ether_token.ts @@ -19,6 +19,12 @@ describe('EtherToken', () => { const gasPrice = Web3Wrapper.toBaseUnitAmount(new BigNumber(20), 9); let etherToken: WETH9Contract; + before(async () => { + await blockchainLifecycle.startAsync(); + }); + after(async () => { + await blockchainLifecycle.revertAsync(); + }); before(async () => { const accounts = await web3Wrapper.getAvailableAddressesAsync(); account = accounts[0]; diff --git a/packages/contracts/test/exchange/core.ts b/packages/contracts/test/exchange/core.ts index 70f9ff915..bc476a5ee 100644 --- a/packages/contracts/test/exchange/core.ts +++ b/packages/contracts/test/exchange/core.ts @@ -60,6 +60,12 @@ describe('Exchange core', () => { let defaultMakerAssetAddress: string; let defaultTakerAssetAddress: string; + before(async () => { + await blockchainLifecycle.startAsync(); + }); + after(async () => { + await blockchainLifecycle.revertAsync(); + }); before(async () => { const accounts = await web3Wrapper.getAvailableAddressesAsync(); const usedAddresses = ([owner, makerAddress, takerAddress, feeRecipientAddress] = accounts); diff --git a/packages/contracts/test/exchange/dispatcher.ts b/packages/contracts/test/exchange/dispatcher.ts index 66407322b..b9c7039bd 100644 --- a/packages/contracts/test/exchange/dispatcher.ts +++ b/packages/contracts/test/exchange/dispatcher.ts @@ -35,6 +35,12 @@ describe('AssetProxyDispatcher', () => { let erc20Wrapper: ERC20Wrapper; let erc721Wrapper: ERC721Wrapper; + before(async () => { + await blockchainLifecycle.startAsync(); + }); + after(async () => { + await blockchainLifecycle.revertAsync(); + }); before(async () => { // Setup accounts & addresses const accounts = await web3Wrapper.getAvailableAddressesAsync(); diff --git a/packages/contracts/test/exchange/libs.ts b/packages/contracts/test/exchange/libs.ts index c6c07f633..a3282876b 100644 --- a/packages/contracts/test/exchange/libs.ts +++ b/packages/contracts/test/exchange/libs.ts @@ -24,6 +24,12 @@ describe('Exchange libs', () => { let orderFactory: OrderFactory; let libs: TestLibsContract; + before(async () => { + await blockchainLifecycle.startAsync(); + }); + after(async () => { + await blockchainLifecycle.revertAsync(); + }); before(async () => { const accounts = await web3Wrapper.getAvailableAddressesAsync(); const makerAddress = accounts[0]; diff --git a/packages/contracts/test/exchange/match_orders.ts b/packages/contracts/test/exchange/match_orders.ts index 754a73d78..0da0287bc 100644 --- a/packages/contracts/test/exchange/match_orders.ts +++ b/packages/contracts/test/exchange/match_orders.ts @@ -76,6 +76,12 @@ describe('matchOrders', () => { let matchOrderTester: MatchOrderTester; + before(async () => { + await blockchainLifecycle.startAsync(); + }); + after(async () => { + await blockchainLifecycle.revertAsync(); + }); before(async () => { // Create accounts const accounts = await web3Wrapper.getAvailableAddressesAsync(); diff --git a/packages/contracts/test/exchange/signature_validator.ts b/packages/contracts/test/exchange/signature_validator.ts index 08de05047..1f030b742 100644 --- a/packages/contracts/test/exchange/signature_validator.ts +++ b/packages/contracts/test/exchange/signature_validator.ts @@ -24,6 +24,12 @@ describe('MixinSignatureValidator', () => { let orderFactory: OrderFactory; let signatureValidator: TestSignatureValidatorContract; + before(async () => { + await blockchainLifecycle.startAsync(); + }); + after(async () => { + await blockchainLifecycle.revertAsync(); + }); before(async () => { const accounts = await web3Wrapper.getAvailableAddressesAsync(); const makerAddress = accounts[0]; diff --git a/packages/contracts/test/exchange/transactions.ts b/packages/contracts/test/exchange/transactions.ts index 0d10f6723..2b2236e2e 100644 --- a/packages/contracts/test/exchange/transactions.ts +++ b/packages/contracts/test/exchange/transactions.ts @@ -60,6 +60,12 @@ describe('Exchange transactions', () => { let makerPrivateKey: Buffer; let takerPrivateKey: Buffer; + before(async () => { + await blockchainLifecycle.startAsync(); + }); + after(async () => { + await blockchainLifecycle.revertAsync(); + }); before(async () => { const accounts = await web3Wrapper.getAvailableAddressesAsync(); const usedAddresses = ([owner, senderAddress, makerAddress, takerAddress, feeRecipientAddress] = accounts); diff --git a/packages/contracts/test/exchange/wrapper.ts b/packages/contracts/test/exchange/wrapper.ts index 8c27d993e..7e1818f4a 100644 --- a/packages/contracts/test/exchange/wrapper.ts +++ b/packages/contracts/test/exchange/wrapper.ts @@ -54,6 +54,12 @@ describe('Exchange wrappers', () => { let defaultMakerAssetAddress: string; let defaultTakerAssetAddress: string; + before(async () => { + await blockchainLifecycle.startAsync(); + }); + after(async () => { + await blockchainLifecycle.revertAsync(); + }); before(async () => { const accounts = await web3Wrapper.getAvailableAddressesAsync(); const usedAddresses = ([owner, makerAddress, takerAddress, feeRecipientAddress] = accounts); diff --git a/packages/contracts/test/libraries/lib_bytes.ts b/packages/contracts/test/libraries/lib_bytes.ts index ab92dfc8c..e817951ab 100644 --- a/packages/contracts/test/libraries/lib_bytes.ts +++ b/packages/contracts/test/libraries/lib_bytes.ts @@ -33,6 +33,12 @@ describe('LibBytes', () => { const testBytes32 = '0x102030405060708090a0b0c0d0e0f0102030405060708090a0b0c0d0e0f01020'; const testUint256 = new BigNumber(testBytes32, 16); + before(async () => { + await blockchainLifecycle.startAsync(); + }); + after(async () => { + await blockchainLifecycle.revertAsync(); + }); before(async () => { // Setup accounts & addresses const accounts = await web3Wrapper.getAvailableAddressesAsync(); diff --git a/packages/contracts/test/multi_sig_with_time_lock.ts b/packages/contracts/test/multi_sig_with_time_lock.ts index ace0f0045..7b7885a00 100644 --- a/packages/contracts/test/multi_sig_with_time_lock.ts +++ b/packages/contracts/test/multi_sig_with_time_lock.ts @@ -26,6 +26,12 @@ describe('MultiSigWalletWithTimeLock', () => { const REQUIRED_APPROVALS = new BigNumber(2); const SECONDS_TIME_LOCKED = new BigNumber(1000000); + before(async () => { + await blockchainLifecycle.startAsync(); + }); + after(async () => { + await blockchainLifecycle.revertAsync(); + }); before(async () => { const accounts = await web3Wrapper.getAvailableAddressesAsync(); owners = [accounts[0], accounts[1]]; diff --git a/packages/contracts/test/token_registry.ts b/packages/contracts/test/token_registry.ts index df835d8f4..7980977c8 100644 --- a/packages/contracts/test/token_registry.ts +++ b/packages/contracts/test/token_registry.ts @@ -23,6 +23,13 @@ describe('TokenRegistry', () => { let notOwner: string; let tokenReg: TokenRegistryContract; let tokenRegWrapper: TokenRegWrapper; + + before(async () => { + await blockchainLifecycle.startAsync(); + }); + after(async () => { + await blockchainLifecycle.revertAsync(); + }); before(async () => { const accounts = await web3Wrapper.getAvailableAddressesAsync(); owner = accounts[0]; diff --git a/packages/contracts/test/unlimited_allowance_token.ts b/packages/contracts/test/unlimited_allowance_token.ts index ab001b770..c68d8bdcf 100644 --- a/packages/contracts/test/unlimited_allowance_token.ts +++ b/packages/contracts/test/unlimited_allowance_token.ts @@ -21,6 +21,12 @@ describe('UnlimitedAllowanceToken', () => { const MAX_MINT_VALUE = new BigNumber(100000000000000000000); let token: DummyERC20TokenContract; + before(async () => { + await blockchainLifecycle.startAsync(); + }); + after(async () => { + await blockchainLifecycle.revertAsync(); + }); before(async () => { const accounts = await web3Wrapper.getAvailableAddressesAsync(); owner = accounts[0]; diff --git a/packages/contracts/test/zrx_token.ts b/packages/contracts/test/zrx_token.ts index a159b6ed5..fe37e802b 100644 --- a/packages/contracts/test/zrx_token.ts +++ b/packages/contracts/test/zrx_token.ts @@ -21,6 +21,12 @@ describe('ZRXToken', () => { let MAX_UINT: BigNumber; let zrxToken: ZRXTokenContract; + before(async () => { + await blockchainLifecycle.startAsync(); + }); + after(async () => { + await blockchainLifecycle.revertAsync(); + }); before(async () => { const accounts = await web3Wrapper.getAvailableAddressesAsync(); owner = accounts[0]; -- cgit v1.2.3 From 79e7c44884f81f12733d555314c54d4c912f0e88 Mon Sep 17 00:00:00 2001 From: Amir Bandeali Date: Wed, 30 May 2018 17:52:37 -0700 Subject: Check length before accessing indices, add awaitTransactionSuccess where needed, and rename function --- packages/contracts/test/exchange/transactions.ts | 40 ++++++++++++++++-------- 1 file changed, 27 insertions(+), 13 deletions(-) (limited to 'packages/contracts/test') diff --git a/packages/contracts/test/exchange/transactions.ts b/packages/contracts/test/exchange/transactions.ts index 2b2236e2e..6b3083ae5 100644 --- a/packages/contracts/test/exchange/transactions.ts +++ b/packages/contracts/test/exchange/transactions.ts @@ -220,9 +220,11 @@ describe('Exchange transactions', () => { exchange.address, ); const isApproved = true; - await exchange.approveSignatureValidator.sendTransactionAsync(whitelist.address, isApproved, { - from: takerAddress, - }); + await web3Wrapper.awaitTransactionSuccessAsync( + await exchange.approveSignatureValidator.sendTransactionAsync(whitelist.address, isApproved, { + from: takerAddress, + }), + ); const defaultOrderParams = { ...constants.STATIC_ORDER_PARAMS, senderAddress: whitelist.address, @@ -242,7 +244,9 @@ describe('Exchange transactions', () => { it('should revert if maker has not been whitelisted', async () => { const isApproved = true; - await whitelist.updateWhitelistStatus.sendTransactionAsync(takerAddress, isApproved, { from: owner }); + await web3Wrapper.awaitTransactionSuccessAsync( + await whitelist.updateWhitelistStatus.sendTransactionAsync(takerAddress, isApproved, { from: owner }), + ); const orderStruct = orderUtils.getOrderStruct(signedOrder); const takerAssetFillAmount = signedOrder.takerAssetAmount; @@ -260,7 +264,9 @@ describe('Exchange transactions', () => { it('should revert if taker has not been whitelisted', async () => { const isApproved = true; - await whitelist.updateWhitelistStatus.sendTransactionAsync(makerAddress, isApproved, { from: owner }); + await web3Wrapper.awaitTransactionSuccessAsync( + await whitelist.updateWhitelistStatus.sendTransactionAsync(makerAddress, isApproved, { from: owner }), + ); const orderStruct = orderUtils.getOrderStruct(signedOrder); const takerAssetFillAmount = signedOrder.takerAssetAmount; @@ -278,19 +284,27 @@ describe('Exchange transactions', () => { it('should fill the order if maker and taker have been whitelisted', async () => { const isApproved = true; - await whitelist.updateWhitelistStatus.sendTransactionAsync(makerAddress, isApproved, { from: owner }); - await whitelist.updateWhitelistStatus.sendTransactionAsync(takerAddress, isApproved, { from: owner }); + await web3Wrapper.awaitTransactionSuccessAsync( + await whitelist.updateWhitelistStatus.sendTransactionAsync(makerAddress, isApproved, { from: owner }), + ); + + await web3Wrapper.awaitTransactionSuccessAsync( + await whitelist.updateWhitelistStatus.sendTransactionAsync(takerAddress, isApproved, { from: owner }), + ); const orderStruct = orderUtils.getOrderStruct(signedOrder); const takerAssetFillAmount = signedOrder.takerAssetAmount; const salt = generatePseudoRandomSalt(); - await whitelist.fillOrderIfWhitelisted.sendTransactionAsync( - orderStruct, - takerAssetFillAmount, - salt, - signedOrder.signature, - { from: takerAddress }, + await web3Wrapper.awaitTransactionSuccessAsync( + await whitelist.fillOrderIfWhitelisted.sendTransactionAsync( + orderStruct, + takerAssetFillAmount, + salt, + signedOrder.signature, + { from: takerAddress }, + ), ); + const newBalances = await erc20Wrapper.getBalancesAsync(); const makerAssetFillAmount = signedOrder.makerAssetAmount; -- cgit v1.2.3