diff options
author | Amir Bandeali <abandeali1@gmail.com> | 2017-12-20 10:31:46 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-12-20 10:31:46 +0800 |
commit | 14c994ce1472e2fbd56efb73387505edd2a3ebc1 (patch) | |
tree | 3e5c192487e0cebd1f0130b3c612e554807d167b /packages | |
parent | d1c36f50d5849e70e16b785f5fff8f58435536d7 (diff) | |
parent | 766824120ab9e36e5c396725fa6bc5b666c43fbc (diff) | |
download | dexon-sol-tools-14c994ce1472e2fbd56efb73387505edd2a3ebc1.tar dexon-sol-tools-14c994ce1472e2fbd56efb73387505edd2a3ebc1.tar.gz dexon-sol-tools-14c994ce1472e2fbd56efb73387505edd2a3ebc1.tar.bz2 dexon-sol-tools-14c994ce1472e2fbd56efb73387505edd2a3ebc1.tar.lz dexon-sol-tools-14c994ce1472e2fbd56efb73387505edd2a3ebc1.tar.xz dexon-sol-tools-14c994ce1472e2fbd56efb73387505edd2a3ebc1.tar.zst dexon-sol-tools-14c994ce1472e2fbd56efb73387505edd2a3ebc1.zip |
Merge pull request #282 from 0xProject/fix/zrx-tests
Remove reliance on testrpc snapshot in ZRX tests
Diffstat (limited to 'packages')
-rw-r--r-- | packages/contracts/test/ts/zrx_token.ts | 38 |
1 files changed, 18 insertions, 20 deletions
diff --git a/packages/contracts/test/ts/zrx_token.ts b/packages/contracts/test/ts/zrx_token.ts index 6312056b2..89e3c3ae2 100644 --- a/packages/contracts/test/ts/zrx_token.ts +++ b/packages/contracts/test/ts/zrx_token.ts @@ -29,8 +29,8 @@ contract('ZRXToken', (accounts: string[]) => { exchangeContractAddress: Exchange.address, networkId: constants.TESTRPC_NETWORK_ID, }); - zrxAddress = zeroEx.exchange.getZRXTokenAddress(); - zrx = await ZRXToken.at(zrxAddress); + zrx = await ZRXToken.new(); + zrxAddress = zrx.address; MAX_UINT = zeroEx.token.UNLIMITED_ALLOWANCE_IN_BASE_UNITS; }); @@ -94,15 +94,12 @@ contract('ZRXToken', (accounts: string[]) => { it('should return false if owner has insufficient balance', async () => { const ownerBalance = await zeroEx.token.getBalanceAsync(zrxAddress, owner); const amountToTransfer = ownerBalance.plus(1); - let txHash = await zeroEx.token.setAllowanceAsync(zrxAddress, owner, spender, amountToTransfer, - {gasLimit: constants.MAX_TOKEN_APPROVE_GAS}); + const txHash = await zeroEx.token.setAllowanceAsync(zrxAddress, owner, spender, amountToTransfer, { + gasLimit: constants.MAX_TOKEN_APPROVE_GAS, + }); await zeroEx.awaitTransactionMinedAsync(txHash); const didReturnTrue = await zrx.transferFrom.call(owner, spender, amountToTransfer, {from: spender}); expect(didReturnTrue).to.be.false(); - // Reset allowance - txHash = await zeroEx.token.setAllowanceAsync(zrxAddress, owner, spender, new BigNumber(0), - {gasLimit: constants.MAX_TOKEN_APPROVE_GAS}); - await zeroEx.awaitTransactionMinedAsync(txHash); }); it('should return false if spender has insufficient allowance', async () => { @@ -127,17 +124,17 @@ contract('ZRXToken', (accounts: string[]) => { const initOwnerBalance = await zeroEx.token.getBalanceAsync(zrxAddress, owner); const amountToTransfer = initOwnerBalance; const initSpenderAllowance = MAX_UINT; - let txHash = await zeroEx.token.setAllowanceAsync(zrxAddress, owner, spender, initSpenderAllowance); + let txHash = await zeroEx.token.setAllowanceAsync(zrxAddress, owner, spender, initSpenderAllowance, { + gasLimit: constants.MAX_TOKEN_APPROVE_GAS, + }); await zeroEx.awaitTransactionMinedAsync(txHash); - txHash = await zeroEx.token.transferFromAsync(zrxAddress, owner, spender, spender, amountToTransfer, - {gasLimit: constants.MAX_TOKEN_TRANSFERFROM_GAS}); + txHash = await zeroEx.token.transferFromAsync(zrxAddress, owner, spender, spender, amountToTransfer, { + gasLimit: constants.MAX_TOKEN_TRANSFERFROM_GAS, + }); await zeroEx.awaitTransactionMinedAsync(txHash); const newSpenderAllowance = await zeroEx.token.getAllowanceAsync(zrxAddress, owner, spender); expect(initSpenderAllowance).to.be.bignumber.equal(newSpenderAllowance); - // Restore balance - txHash = await zeroEx.token.transferAsync(zrxAddress, spender, owner, amountToTransfer); - await zeroEx.awaitTransactionMinedAsync(txHash); }); it('should transfer the correct balances if spender has sufficient allowance', async () => { @@ -147,8 +144,9 @@ contract('ZRXToken', (accounts: string[]) => { const initSpenderAllowance = initOwnerBalance; let txHash = await zeroEx.token.setAllowanceAsync(zrxAddress, owner, spender, initSpenderAllowance); await zeroEx.awaitTransactionMinedAsync(txHash); - txHash = await zeroEx.token.transferFromAsync(zrxAddress, owner, spender, spender, amountToTransfer, - {gasLimit: constants.MAX_TOKEN_TRANSFERFROM_GAS}); + txHash = await zeroEx.token.transferFromAsync(zrxAddress, owner, spender, spender, amountToTransfer, { + gasLimit: constants.MAX_TOKEN_TRANSFERFROM_GAS, + }); await zeroEx.awaitTransactionMinedAsync(txHash); const newOwnerBalance = await zeroEx.token.getBalanceAsync(zrxAddress, owner); @@ -161,11 +159,11 @@ contract('ZRXToken', (accounts: string[]) => { it('should modify allowance if spender has sufficient allowance less than 2^256 - 1', async () => { const initOwnerBalance = await zeroEx.token.getBalanceAsync(zrxAddress, owner); const amountToTransfer = initOwnerBalance; - const initSpenderAllowance = initOwnerBalance; - let txHash = await zeroEx.token.setAllowanceAsync(zrxAddress, owner, spender, initSpenderAllowance); + let txHash = await zeroEx.token.setAllowanceAsync(zrxAddress, owner, spender, amountToTransfer); await zeroEx.awaitTransactionMinedAsync(txHash); - txHash = await zeroEx.token.transferFromAsync(zrxAddress, owner, spender, spender, amountToTransfer, - {gasLimit: constants.MAX_TOKEN_TRANSFERFROM_GAS}); + txHash = await zeroEx.token.transferFromAsync(zrxAddress, owner, spender, spender, amountToTransfer, { + gasLimit: constants.MAX_TOKEN_TRANSFERFROM_GAS, + }); await zeroEx.awaitTransactionMinedAsync(txHash); const newSpenderAllowance = await zeroEx.token.getAllowanceAsync(zrxAddress, owner, spender); |