diff options
author | Leonid Logvinov <logvinov.leon@gmail.com> | 2018-05-26 06:51:43 +0800 |
---|---|---|
committer | Leonid Logvinov <logvinov.leon@gmail.com> | 2018-05-26 07:09:17 +0800 |
commit | 1d68692bb6ae6be25b989cca8e5d3040bd6d1502 (patch) | |
tree | 838f0a3308f092dc16de5fc6bb0cc7bb00b4e454 /packages/contracts/test/zrx_token.ts | |
parent | c7f5e77b3fe7c1805202a5b1e1e1ce1e9d31a6b0 (diff) | |
download | dexon-0x-contracts-1d68692bb6ae6be25b989cca8e5d3040bd6d1502.tar dexon-0x-contracts-1d68692bb6ae6be25b989cca8e5d3040bd6d1502.tar.gz dexon-0x-contracts-1d68692bb6ae6be25b989cca8e5d3040bd6d1502.tar.bz2 dexon-0x-contracts-1d68692bb6ae6be25b989cca8e5d3040bd6d1502.tar.lz dexon-0x-contracts-1d68692bb6ae6be25b989cca8e5d3040bd6d1502.tar.xz dexon-0x-contracts-1d68692bb6ae6be25b989cca8e5d3040bd6d1502.tar.zst dexon-0x-contracts-1d68692bb6ae6be25b989cca8e5d3040bd6d1502.zip |
Remove contracts -> @0xproject/order-utils dependency
Diffstat (limited to 'packages/contracts/test/zrx_token.ts')
-rw-r--r-- | packages/contracts/test/zrx_token.ts | 72 |
1 files changed, 34 insertions, 38 deletions
diff --git a/packages/contracts/test/zrx_token.ts b/packages/contracts/test/zrx_token.ts index e632364ef..fe37e802b 100644 --- a/packages/contracts/test/zrx_token.ts +++ b/packages/contracts/test/zrx_token.ts @@ -1,4 +1,3 @@ -import { ContractWrappers } from '@0xproject/contract-wrappers'; import { BlockchainLifecycle, devConstants, web3Factory } from '@0xproject/dev-utils'; import { BigNumber } from '@0xproject/utils'; import { Web3Wrapper } from '@0xproject/web3-wrapper'; @@ -19,12 +18,8 @@ const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper); describe('ZRXToken', () => { let owner: string; let spender: string; - let contractWrappers: ContractWrappers; - let MAX_UINT: BigNumber; - let zrxToken: ZRXTokenContract; - let zrxAddress: string; before(async () => { await blockchainLifecycle.startAsync(); @@ -36,12 +31,8 @@ describe('ZRXToken', () => { const accounts = await web3Wrapper.getAvailableAddressesAsync(); owner = accounts[0]; spender = accounts[1]; - contractWrappers = new ContractWrappers(provider, { - networkId: constants.TESTRPC_NETWORK_ID, - }); zrxToken = await ZRXTokenContract.deployFrom0xArtifactAsync(artifacts.ZRX, provider, txDefaults); - zrxAddress = zrxToken.address; - MAX_UINT = contractWrappers.token.UNLIMITED_ALLOWANCE_IN_BASE_UNITS; + MAX_UINT = constants.UNLIMITED_ALLOWANCE_IN_BASE_UNITS; }); beforeEach(async () => { await blockchainLifecycle.startAsync(); @@ -77,7 +68,7 @@ describe('ZRXToken', () => { describe('constructor', () => { it('should initialize owner balance to totalSupply', async () => { - const ownerBalance = await contractWrappers.token.getBalanceAsync(zrxAddress, owner); + const ownerBalance = await zrxToken.balanceOf.callAsync(owner); const totalSupply = new BigNumber(await zrxToken.totalSupply.callAsync()); expect(totalSupply).to.be.bignumber.equal(ownerBalance); }); @@ -86,11 +77,11 @@ describe('ZRXToken', () => { describe('transfer', () => { it('should transfer balance from sender to receiver', async () => { const receiver = spender; - const initOwnerBalance = await contractWrappers.token.getBalanceAsync(zrxAddress, owner); + const initOwnerBalance = await zrxToken.balanceOf.callAsync(owner); const amountToTransfer = new BigNumber(1); - await contractWrappers.token.transferAsync(zrxAddress, owner, receiver, amountToTransfer); - const finalOwnerBalance = await contractWrappers.token.getBalanceAsync(zrxAddress, owner); - const finalReceiverBalance = await contractWrappers.token.getBalanceAsync(zrxAddress, receiver); + await zrxToken.transfer.sendTransactionAsync(receiver, amountToTransfer, { from: owner }); + const finalOwnerBalance = await zrxToken.balanceOf.callAsync(owner); + const finalReceiverBalance = await zrxToken.balanceOf.callAsync(receiver); const expectedFinalOwnerBalance = initOwnerBalance.minus(amountToTransfer); const expectedFinalReceiverBalance = amountToTransfer; @@ -108,10 +99,11 @@ describe('ZRXToken', () => { describe('transferFrom', () => { it('should return false if owner has insufficient balance', async () => { - const ownerBalance = await contractWrappers.token.getBalanceAsync(zrxAddress, owner); + const ownerBalance = await zrxToken.balanceOf.callAsync(owner); const amountToTransfer = ownerBalance.plus(1); - await contractWrappers.token.setAllowanceAsync(zrxAddress, owner, spender, amountToTransfer, { - gasLimit: constants.MAX_TOKEN_APPROVE_GAS, + await zrxToken.approve.sendTransactionAsync(spender, amountToTransfer, { + from: owner, + gas: constants.MAX_TOKEN_APPROVE_GAS, }); const didReturnTrue = await zrxToken.transferFrom.callAsync(owner, spender, amountToTransfer, { from: spender, @@ -120,10 +112,10 @@ describe('ZRXToken', () => { }); it('should return false if spender has insufficient allowance', async () => { - const ownerBalance = await contractWrappers.token.getBalanceAsync(zrxAddress, owner); + const ownerBalance = await zrxToken.balanceOf.callAsync(owner); const amountToTransfer = ownerBalance; - const spenderAllowance = await contractWrappers.token.getAllowanceAsync(zrxAddress, owner, spender); + const spenderAllowance = await zrxToken.allowance.callAsync(owner, spender); const isSpenderAllowanceInsufficient = spenderAllowance.cmp(amountToTransfer) < 0; expect(isSpenderAllowanceInsufficient).to.be.true(); @@ -142,46 +134,50 @@ describe('ZRXToken', () => { }); it('should not modify spender allowance if spender allowance is 2^256 - 1', async () => { - const initOwnerBalance = await contractWrappers.token.getBalanceAsync(zrxAddress, owner); + const initOwnerBalance = await zrxToken.balanceOf.callAsync(owner); const amountToTransfer = initOwnerBalance; const initSpenderAllowance = MAX_UINT; - await contractWrappers.token.setAllowanceAsync(zrxAddress, owner, spender, initSpenderAllowance, { - gasLimit: constants.MAX_TOKEN_APPROVE_GAS, + await zrxToken.approve.sendTransactionAsync(spender, initSpenderAllowance, { + from: owner, + gas: constants.MAX_TOKEN_APPROVE_GAS, }); - await contractWrappers.token.transferFromAsync(zrxAddress, owner, spender, spender, amountToTransfer, { - gasLimit: constants.MAX_TOKEN_TRANSFERFROM_GAS, + await zrxToken.transferFrom.sendTransactionAsync(owner, spender, amountToTransfer, { + from: spender, + gas: constants.MAX_TOKEN_TRANSFERFROM_GAS, }); - const newSpenderAllowance = await contractWrappers.token.getAllowanceAsync(zrxAddress, owner, spender); + const newSpenderAllowance = await zrxToken.allowance.callAsync(owner, spender); expect(initSpenderAllowance).to.be.bignumber.equal(newSpenderAllowance); }); it('should transfer the correct balances if spender has sufficient allowance', async () => { - const initOwnerBalance = await contractWrappers.token.getBalanceAsync(zrxAddress, owner); - const initSpenderBalance = await contractWrappers.token.getBalanceAsync(zrxAddress, spender); + const initOwnerBalance = await zrxToken.balanceOf.callAsync(owner); + const initSpenderBalance = await zrxToken.balanceOf.callAsync(spender); const amountToTransfer = initOwnerBalance; const initSpenderAllowance = initOwnerBalance; - await contractWrappers.token.setAllowanceAsync(zrxAddress, owner, spender, initSpenderAllowance); - await contractWrappers.token.transferFromAsync(zrxAddress, owner, spender, spender, amountToTransfer, { - gasLimit: constants.MAX_TOKEN_TRANSFERFROM_GAS, + await zrxToken.approve.sendTransactionAsync(spender, initSpenderAllowance); + await zrxToken.transferFrom.sendTransactionAsync(owner, spender, amountToTransfer, { + from: spender, + gas: constants.MAX_TOKEN_TRANSFERFROM_GAS, }); - const newOwnerBalance = await contractWrappers.token.getBalanceAsync(zrxAddress, owner); - const newSpenderBalance = await contractWrappers.token.getBalanceAsync(zrxAddress, spender); + const newOwnerBalance = await zrxToken.balanceOf.callAsync(owner); + const newSpenderBalance = await zrxToken.balanceOf.callAsync(spender); expect(newOwnerBalance).to.be.bignumber.equal(0); expect(newSpenderBalance).to.be.bignumber.equal(initSpenderBalance.plus(initOwnerBalance)); }); it('should modify allowance if spender has sufficient allowance less than 2^256 - 1', async () => { - const initOwnerBalance = await contractWrappers.token.getBalanceAsync(zrxAddress, owner); + const initOwnerBalance = await zrxToken.balanceOf.callAsync(owner); const amountToTransfer = initOwnerBalance; - await contractWrappers.token.setAllowanceAsync(zrxAddress, owner, spender, amountToTransfer); - await contractWrappers.token.transferFromAsync(zrxAddress, owner, spender, spender, amountToTransfer, { - gasLimit: constants.MAX_TOKEN_TRANSFERFROM_GAS, + await zrxToken.approve.sendTransactionAsync(spender, amountToTransfer); + await zrxToken.transferFrom.sendTransactionAsync(owner, spender, amountToTransfer, { + from: spender, + gas: constants.MAX_TOKEN_TRANSFERFROM_GAS, }); - const newSpenderAllowance = await contractWrappers.token.getAllowanceAsync(zrxAddress, owner, spender); + const newSpenderAllowance = await zrxToken.allowance.callAsync(owner, spender); expect(newSpenderAllowance).to.be.bignumber.equal(0); }); }); |