diff options
Diffstat (limited to 'packages/contracts/test/zrx_token.ts')
-rw-r--r-- | packages/contracts/test/zrx_token.ts | 56 |
1 files changed, 28 insertions, 28 deletions
diff --git a/packages/contracts/test/zrx_token.ts b/packages/contracts/test/zrx_token.ts index 48b8f6e36..d621d9065 100644 --- a/packages/contracts/test/zrx_token.ts +++ b/packages/contracts/test/zrx_token.ts @@ -1,4 +1,4 @@ -import { ZeroEx } from '0x.js'; +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,7 +19,7 @@ const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper); describe('ZRXToken', () => { let owner: string; let spender: string; - let zeroEx: ZeroEx; + let contractWrappers: ContractWrappers; let MAX_UINT: BigNumber; @@ -30,12 +30,12 @@ describe('ZRXToken', () => { const accounts = await web3Wrapper.getAvailableAddressesAsync(); owner = accounts[0]; spender = accounts[1]; - zeroEx = new ZeroEx(provider, { + contractWrappers = new ContractWrappers(provider, { networkId: constants.TESTRPC_NETWORK_ID, }); zrxToken = await ZRXTokenContract.deployFrom0xArtifactAsync(artifacts.ZRX, provider, txDefaults); zrxAddress = zrxToken.address; - MAX_UINT = zeroEx.token.UNLIMITED_ALLOWANCE_IN_BASE_UNITS; + MAX_UINT = contractWrappers.token.UNLIMITED_ALLOWANCE_IN_BASE_UNITS; }); beforeEach(async () => { await blockchainLifecycle.startAsync(); @@ -53,7 +53,7 @@ describe('ZRXToken', () => { it('should have a total supply of 1 billion tokens', async () => { const totalSupply = new BigNumber(await zrxToken.totalSupply.callAsync()); const expectedTotalSupply = 1000000000; - expect(ZeroEx.toUnitAmount(totalSupply, 18)).to.be.bignumber.equal(expectedTotalSupply); + expect(Web3Wrapper.toUnitAmount(totalSupply, 18)).to.be.bignumber.equal(expectedTotalSupply); }); it('should be named 0x Protocol Token', async () => { @@ -71,7 +71,7 @@ describe('ZRXToken', () => { describe('constructor', () => { it('should initialize owner balance to totalSupply', async () => { - const ownerBalance = await zeroEx.token.getBalanceAsync(zrxAddress, owner); + const ownerBalance = await contractWrappers.token.getBalanceAsync(zrxAddress, owner); const totalSupply = new BigNumber(await zrxToken.totalSupply.callAsync()); expect(totalSupply).to.be.bignumber.equal(ownerBalance); }); @@ -80,11 +80,11 @@ describe('ZRXToken', () => { describe('transfer', () => { it('should transfer balance from sender to receiver', async () => { const receiver = spender; - const initOwnerBalance = await zeroEx.token.getBalanceAsync(zrxAddress, owner); + const initOwnerBalance = await contractWrappers.token.getBalanceAsync(zrxAddress, owner); const amountToTransfer = new BigNumber(1); - await zeroEx.token.transferAsync(zrxAddress, owner, receiver, amountToTransfer); - const finalOwnerBalance = await zeroEx.token.getBalanceAsync(zrxAddress, owner); - const finalReceiverBalance = await zeroEx.token.getBalanceAsync(zrxAddress, receiver); + await contractWrappers.token.transferAsync(zrxAddress, owner, receiver, amountToTransfer); + const finalOwnerBalance = await contractWrappers.token.getBalanceAsync(zrxAddress, owner); + const finalReceiverBalance = await contractWrappers.token.getBalanceAsync(zrxAddress, receiver); const expectedFinalOwnerBalance = initOwnerBalance.minus(amountToTransfer); const expectedFinalReceiverBalance = amountToTransfer; @@ -102,9 +102,9 @@ describe('ZRXToken', () => { describe('transferFrom', () => { it('should return false if owner has insufficient balance', async () => { - const ownerBalance = await zeroEx.token.getBalanceAsync(zrxAddress, owner); + const ownerBalance = await contractWrappers.token.getBalanceAsync(zrxAddress, owner); const amountToTransfer = ownerBalance.plus(1); - await zeroEx.token.setAllowanceAsync(zrxAddress, owner, spender, amountToTransfer, { + await contractWrappers.token.setAllowanceAsync(zrxAddress, owner, spender, amountToTransfer, { gasLimit: constants.MAX_TOKEN_APPROVE_GAS, }); const didReturnTrue = await zrxToken.transferFrom.callAsync(owner, spender, amountToTransfer, { @@ -114,10 +114,10 @@ describe('ZRXToken', () => { }); it('should return false if spender has insufficient allowance', async () => { - const ownerBalance = await zeroEx.token.getBalanceAsync(zrxAddress, owner); + const ownerBalance = await contractWrappers.token.getBalanceAsync(zrxAddress, owner); const amountToTransfer = ownerBalance; - const spenderAllowance = await zeroEx.token.getAllowanceAsync(zrxAddress, owner, spender); + const spenderAllowance = await contractWrappers.token.getAllowanceAsync(zrxAddress, owner, spender); const isSpenderAllowanceInsufficient = spenderAllowance.cmp(amountToTransfer) < 0; expect(isSpenderAllowanceInsufficient).to.be.true(); @@ -136,46 +136,46 @@ describe('ZRXToken', () => { }); it('should not modify spender allowance if spender allowance is 2^256 - 1', async () => { - const initOwnerBalance = await zeroEx.token.getBalanceAsync(zrxAddress, owner); + const initOwnerBalance = await contractWrappers.token.getBalanceAsync(zrxAddress, owner); const amountToTransfer = initOwnerBalance; const initSpenderAllowance = MAX_UINT; - await zeroEx.token.setAllowanceAsync(zrxAddress, owner, spender, initSpenderAllowance, { + await contractWrappers.token.setAllowanceAsync(zrxAddress, owner, spender, initSpenderAllowance, { gasLimit: constants.MAX_TOKEN_APPROVE_GAS, }); - await zeroEx.token.transferFromAsync(zrxAddress, owner, spender, spender, amountToTransfer, { + await contractWrappers.token.transferFromAsync(zrxAddress, owner, spender, spender, amountToTransfer, { gasLimit: constants.MAX_TOKEN_TRANSFERFROM_GAS, }); - const newSpenderAllowance = await zeroEx.token.getAllowanceAsync(zrxAddress, owner, spender); + const newSpenderAllowance = await contractWrappers.token.getAllowanceAsync(zrxAddress, owner, spender); expect(initSpenderAllowance).to.be.bignumber.equal(newSpenderAllowance); }); it('should transfer the correct balances if spender has sufficient allowance', async () => { - const initOwnerBalance = await zeroEx.token.getBalanceAsync(zrxAddress, owner); - const initSpenderBalance = await zeroEx.token.getBalanceAsync(zrxAddress, spender); + const initOwnerBalance = await contractWrappers.token.getBalanceAsync(zrxAddress, owner); + const initSpenderBalance = await contractWrappers.token.getBalanceAsync(zrxAddress, spender); const amountToTransfer = initOwnerBalance; const initSpenderAllowance = initOwnerBalance; - await zeroEx.token.setAllowanceAsync(zrxAddress, owner, spender, initSpenderAllowance); - await zeroEx.token.transferFromAsync(zrxAddress, owner, spender, spender, amountToTransfer, { + await contractWrappers.token.setAllowanceAsync(zrxAddress, owner, spender, initSpenderAllowance); + await contractWrappers.token.transferFromAsync(zrxAddress, owner, spender, spender, amountToTransfer, { gasLimit: constants.MAX_TOKEN_TRANSFERFROM_GAS, }); - const newOwnerBalance = await zeroEx.token.getBalanceAsync(zrxAddress, owner); - const newSpenderBalance = await zeroEx.token.getBalanceAsync(zrxAddress, spender); + const newOwnerBalance = await contractWrappers.token.getBalanceAsync(zrxAddress, owner); + const newSpenderBalance = await contractWrappers.token.getBalanceAsync(zrxAddress, 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 zeroEx.token.getBalanceAsync(zrxAddress, owner); + const initOwnerBalance = await contractWrappers.token.getBalanceAsync(zrxAddress, owner); const amountToTransfer = initOwnerBalance; - await zeroEx.token.setAllowanceAsync(zrxAddress, owner, spender, amountToTransfer); - await zeroEx.token.transferFromAsync(zrxAddress, owner, spender, spender, amountToTransfer, { + await contractWrappers.token.setAllowanceAsync(zrxAddress, owner, spender, amountToTransfer); + await contractWrappers.token.transferFromAsync(zrxAddress, owner, spender, spender, amountToTransfer, { gasLimit: constants.MAX_TOKEN_TRANSFERFROM_GAS, }); - const newSpenderAllowance = await zeroEx.token.getAllowanceAsync(zrxAddress, owner, spender); + const newSpenderAllowance = await contractWrappers.token.getAllowanceAsync(zrxAddress, owner, spender); expect(newSpenderAllowance).to.be.bignumber.equal(0); }); }); |