From a682b5d90e4c651e4e5d5d7c700237a9b6fe22bf Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Tue, 22 May 2018 11:18:50 -0700 Subject: Remove 0x.js dep from contracts --- .../contracts/test/unlimited_allowance_token.ts | 50 +++++++++++----------- 1 file changed, 25 insertions(+), 25 deletions(-) (limited to 'packages/contracts/test/unlimited_allowance_token.ts') diff --git a/packages/contracts/test/unlimited_allowance_token.ts b/packages/contracts/test/unlimited_allowance_token.ts index 5ad9321e8..147f77ab1 100644 --- a/packages/contracts/test/unlimited_allowance_token.ts +++ b/packages/contracts/test/unlimited_allowance_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('UnlimitedAllowanceToken', () => { let owner: string; let spender: string; - const zeroEx = new ZeroEx(provider, { + const contractWrappers = new ContractWrappers(provider, { networkId: constants.TESTRPC_NETWORK_ID, }); @@ -51,7 +51,7 @@ describe('UnlimitedAllowanceToken', () => { }); describe('transfer', () => { it('should throw if owner has insufficient balance', async () => { - const ownerBalance = await zeroEx.token.getBalanceAsync(tokenAddress, owner); + const ownerBalance = await contractWrappers.token.getBalanceAsync(tokenAddress, owner); const amountToTransfer = ownerBalance.plus(1); return expect(token.transfer.callAsync(spender, amountToTransfer, { from: owner })).to.be.rejectedWith( constants.REVERT, @@ -60,11 +60,11 @@ describe('UnlimitedAllowanceToken', () => { it('should transfer balance from sender to receiver', async () => { const receiver = spender; - const initOwnerBalance = await zeroEx.token.getBalanceAsync(tokenAddress, owner); + const initOwnerBalance = await contractWrappers.token.getBalanceAsync(tokenAddress, owner); const amountToTransfer = new BigNumber(1); - await zeroEx.token.transferAsync(tokenAddress, owner, receiver, amountToTransfer); - const finalOwnerBalance = await zeroEx.token.getBalanceAsync(tokenAddress, owner); - const finalReceiverBalance = await zeroEx.token.getBalanceAsync(tokenAddress, receiver); + await contractWrappers.token.transferAsync(tokenAddress, owner, receiver, amountToTransfer); + const finalOwnerBalance = await contractWrappers.token.getBalanceAsync(tokenAddress, owner); + const finalReceiverBalance = await contractWrappers.token.getBalanceAsync(tokenAddress, receiver); const expectedFinalOwnerBalance = initOwnerBalance.minus(amountToTransfer); const expectedFinalReceiverBalance = amountToTransfer; @@ -82,9 +82,9 @@ describe('UnlimitedAllowanceToken', () => { describe('transferFrom', () => { it('should throw if owner has insufficient balance', async () => { - const ownerBalance = await zeroEx.token.getBalanceAsync(tokenAddress, owner); + const ownerBalance = await contractWrappers.token.getBalanceAsync(tokenAddress, owner); const amountToTransfer = ownerBalance.plus(1); - await zeroEx.token.setAllowanceAsync(tokenAddress, owner, spender, amountToTransfer); + await contractWrappers.token.setAllowanceAsync(tokenAddress, owner, spender, amountToTransfer); return expect( token.transferFrom.callAsync(owner, spender, amountToTransfer, { from: spender, @@ -93,10 +93,10 @@ describe('UnlimitedAllowanceToken', () => { }); it('should throw if spender has insufficient allowance', async () => { - const ownerBalance = await zeroEx.token.getBalanceAsync(tokenAddress, owner); + const ownerBalance = await contractWrappers.token.getBalanceAsync(tokenAddress, owner); const amountToTransfer = ownerBalance; - const spenderAllowance = await zeroEx.token.getAllowanceAsync(tokenAddress, owner, spender); + const spenderAllowance = await contractWrappers.token.getAllowanceAsync(tokenAddress, owner, spender); const isSpenderAllowanceInsufficient = spenderAllowance.cmp(amountToTransfer) < 0; expect(isSpenderAllowanceInsufficient).to.be.true(); @@ -116,44 +116,44 @@ describe('UnlimitedAllowanceToken', () => { }); it('should not modify spender allowance if spender allowance is 2^256 - 1', async () => { - const initOwnerBalance = await zeroEx.token.getBalanceAsync(tokenAddress, owner); + const initOwnerBalance = await contractWrappers.token.getBalanceAsync(tokenAddress, owner); const amountToTransfer = initOwnerBalance; - const initSpenderAllowance = zeroEx.token.UNLIMITED_ALLOWANCE_IN_BASE_UNITS; - await zeroEx.token.setAllowanceAsync(tokenAddress, owner, spender, initSpenderAllowance); - await zeroEx.token.transferFromAsync(tokenAddress, owner, spender, spender, amountToTransfer, { + const initSpenderAllowance = contractWrappers.token.UNLIMITED_ALLOWANCE_IN_BASE_UNITS; + await contractWrappers.token.setAllowanceAsync(tokenAddress, owner, spender, initSpenderAllowance); + await contractWrappers.token.transferFromAsync(tokenAddress, owner, spender, spender, amountToTransfer, { gasLimit: constants.MAX_TOKEN_TRANSFERFROM_GAS, }); - const newSpenderAllowance = await zeroEx.token.getAllowanceAsync(tokenAddress, owner, spender); + const newSpenderAllowance = await contractWrappers.token.getAllowanceAsync(tokenAddress, 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(tokenAddress, owner); + const initOwnerBalance = await contractWrappers.token.getBalanceAsync(tokenAddress, owner); const amountToTransfer = initOwnerBalance; const initSpenderAllowance = initOwnerBalance; - await zeroEx.token.setAllowanceAsync(tokenAddress, owner, spender, initSpenderAllowance); - await zeroEx.token.transferFromAsync(tokenAddress, owner, spender, spender, amountToTransfer, { + await contractWrappers.token.setAllowanceAsync(tokenAddress, owner, spender, initSpenderAllowance); + await contractWrappers.token.transferFromAsync(tokenAddress, owner, spender, spender, amountToTransfer, { gasLimit: constants.MAX_TOKEN_TRANSFERFROM_GAS, }); - const newOwnerBalance = await zeroEx.token.getBalanceAsync(tokenAddress, owner); - const newSpenderBalance = await zeroEx.token.getBalanceAsync(tokenAddress, spender); + const newOwnerBalance = await contractWrappers.token.getBalanceAsync(tokenAddress, owner); + const newSpenderBalance = await contractWrappers.token.getBalanceAsync(tokenAddress, spender); expect(newOwnerBalance).to.be.bignumber.equal(0); expect(newSpenderBalance).to.be.bignumber.equal(initOwnerBalance); }); it('should modify allowance if spender has sufficient allowance less than 2^256 - 1', async () => { - const initOwnerBalance = await zeroEx.token.getBalanceAsync(tokenAddress, owner); + const initOwnerBalance = await contractWrappers.token.getBalanceAsync(tokenAddress, owner); const amountToTransfer = initOwnerBalance; const initSpenderAllowance = initOwnerBalance; - await zeroEx.token.setAllowanceAsync(tokenAddress, owner, spender, initSpenderAllowance); - await zeroEx.token.transferFromAsync(tokenAddress, owner, spender, spender, amountToTransfer, { + await contractWrappers.token.setAllowanceAsync(tokenAddress, owner, spender, initSpenderAllowance); + await contractWrappers.token.transferFromAsync(tokenAddress, owner, spender, spender, amountToTransfer, { gasLimit: constants.MAX_TOKEN_TRANSFERFROM_GAS, }); - const newSpenderAllowance = await zeroEx.token.getAllowanceAsync(tokenAddress, owner, spender); + const newSpenderAllowance = await contractWrappers.token.getAllowanceAsync(tokenAddress, owner, spender); expect(newSpenderAllowance).to.be.bignumber.equal(0); }); }); -- cgit