aboutsummaryrefslogtreecommitdiffstats
path: root/packages/contracts/test/unlimited_allowance_token.ts
diff options
context:
space:
mode:
authorLeonid Logvinov <logvinov.leon@gmail.com>2018-05-26 06:51:43 +0800
committerLeonid Logvinov <logvinov.leon@gmail.com>2018-05-26 07:09:17 +0800
commit1d68692bb6ae6be25b989cca8e5d3040bd6d1502 (patch)
tree838f0a3308f092dc16de5fc6bb0cc7bb00b4e454 /packages/contracts/test/unlimited_allowance_token.ts
parentc7f5e77b3fe7c1805202a5b1e1e1ce1e9d31a6b0 (diff)
downloaddexon-sol-tools-1d68692bb6ae6be25b989cca8e5d3040bd6d1502.tar.gz
dexon-sol-tools-1d68692bb6ae6be25b989cca8e5d3040bd6d1502.tar.zst
dexon-sol-tools-1d68692bb6ae6be25b989cca8e5d3040bd6d1502.zip
Remove contracts -> @0xproject/order-utils dependency
Diffstat (limited to 'packages/contracts/test/unlimited_allowance_token.ts')
-rw-r--r--packages/contracts/test/unlimited_allowance_token.ts62
1 files changed, 29 insertions, 33 deletions
diff --git a/packages/contracts/test/unlimited_allowance_token.ts b/packages/contracts/test/unlimited_allowance_token.ts
index e3e3bd485..c68d8bdcf 100644
--- a/packages/contracts/test/unlimited_allowance_token.ts
+++ b/packages/contracts/test/unlimited_allowance_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,7 @@ const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper);
describe('UnlimitedAllowanceToken', () => {
let owner: string;
let spender: string;
- const contractWrappers = new ContractWrappers(provider, {
- networkId: constants.TESTRPC_NETWORK_ID,
- });
-
const MAX_MINT_VALUE = new BigNumber(100000000000000000000);
- let tokenAddress: string;
let token: DummyERC20TokenContract;
before(async () => {
@@ -50,7 +44,6 @@ describe('UnlimitedAllowanceToken', () => {
await token.mint.sendTransactionAsync(MAX_MINT_VALUE, { from: owner }),
constants.AWAIT_TRANSACTION_MINED_MS,
);
- tokenAddress = token.address;
});
beforeEach(async () => {
await blockchainLifecycle.startAsync();
@@ -60,7 +53,7 @@ describe('UnlimitedAllowanceToken', () => {
});
describe('transfer', () => {
it('should throw if owner has insufficient balance', async () => {
- const ownerBalance = await contractWrappers.token.getBalanceAsync(tokenAddress, owner);
+ const ownerBalance = await token.balanceOf.callAsync(owner);
const amountToTransfer = ownerBalance.plus(1);
return expect(token.transfer.callAsync(spender, amountToTransfer, { from: owner })).to.be.rejectedWith(
constants.REVERT,
@@ -69,11 +62,11 @@ describe('UnlimitedAllowanceToken', () => {
it('should transfer balance from sender to receiver', async () => {
const receiver = spender;
- const initOwnerBalance = await contractWrappers.token.getBalanceAsync(tokenAddress, owner);
+ const initOwnerBalance = await token.balanceOf.callAsync(owner);
const amountToTransfer = new BigNumber(1);
- await contractWrappers.token.transferAsync(tokenAddress, owner, receiver, amountToTransfer);
- const finalOwnerBalance = await contractWrappers.token.getBalanceAsync(tokenAddress, owner);
- const finalReceiverBalance = await contractWrappers.token.getBalanceAsync(tokenAddress, receiver);
+ await token.transfer.sendTransactionAsync(receiver, amountToTransfer, { from: owner });
+ const finalOwnerBalance = await token.balanceOf.callAsync(owner);
+ const finalReceiverBalance = await token.balanceOf.callAsync(receiver);
const expectedFinalOwnerBalance = initOwnerBalance.minus(amountToTransfer);
const expectedFinalReceiverBalance = amountToTransfer;
@@ -91,9 +84,9 @@ describe('UnlimitedAllowanceToken', () => {
describe('transferFrom', () => {
it('should throw if owner has insufficient balance', async () => {
- const ownerBalance = await contractWrappers.token.getBalanceAsync(tokenAddress, owner);
+ const ownerBalance = await token.balanceOf.callAsync(owner);
const amountToTransfer = ownerBalance.plus(1);
- await contractWrappers.token.setAllowanceAsync(tokenAddress, owner, spender, amountToTransfer);
+ await token.approve.sendTransactionAsync(spender, amountToTransfer, { from: owner });
return expect(
token.transferFrom.callAsync(owner, spender, amountToTransfer, {
from: spender,
@@ -102,10 +95,10 @@ describe('UnlimitedAllowanceToken', () => {
});
it('should throw if spender has insufficient allowance', async () => {
- const ownerBalance = await contractWrappers.token.getBalanceAsync(tokenAddress, owner);
+ const ownerBalance = await token.balanceOf.callAsync(owner);
const amountToTransfer = ownerBalance;
- const spenderAllowance = await contractWrappers.token.getAllowanceAsync(tokenAddress, owner, spender);
+ const spenderAllowance = await token.allowance.callAsync(owner, spender);
const isSpenderAllowanceInsufficient = spenderAllowance.cmp(amountToTransfer) < 0;
expect(isSpenderAllowanceInsufficient).to.be.true();
@@ -125,44 +118,47 @@ describe('UnlimitedAllowanceToken', () => {
});
it('should not modify spender allowance if spender allowance is 2^256 - 1', async () => {
- const initOwnerBalance = await contractWrappers.token.getBalanceAsync(tokenAddress, owner);
+ const initOwnerBalance = await token.balanceOf.callAsync(owner);
const amountToTransfer = initOwnerBalance;
- 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 initSpenderAllowance = constants.UNLIMITED_ALLOWANCE_IN_BASE_UNITS;
+ await token.approve.sendTransactionAsync(spender, initSpenderAllowance, { from: owner });
+ await token.transferFrom.sendTransactionAsync(owner, spender, amountToTransfer, {
+ from: spender,
+ gas: constants.MAX_TOKEN_TRANSFERFROM_GAS,
});
- const newSpenderAllowance = await contractWrappers.token.getAllowanceAsync(tokenAddress, owner, spender);
+ const newSpenderAllowance = await token.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(tokenAddress, owner);
+ const initOwnerBalance = await token.balanceOf.callAsync(owner);
const amountToTransfer = initOwnerBalance;
const initSpenderAllowance = initOwnerBalance;
- await contractWrappers.token.setAllowanceAsync(tokenAddress, owner, spender, initSpenderAllowance);
- await contractWrappers.token.transferFromAsync(tokenAddress, owner, spender, spender, amountToTransfer, {
- gasLimit: constants.MAX_TOKEN_TRANSFERFROM_GAS,
+ await token.approve.sendTransactionAsync(spender, initSpenderAllowance, { from: owner });
+ await token.transferFrom.sendTransactionAsync(owner, spender, amountToTransfer, {
+ from: spender,
+ gas: constants.MAX_TOKEN_TRANSFERFROM_GAS,
});
- const newOwnerBalance = await contractWrappers.token.getBalanceAsync(tokenAddress, owner);
- const newSpenderBalance = await contractWrappers.token.getBalanceAsync(tokenAddress, spender);
+ const newOwnerBalance = await token.balanceOf.callAsync(owner);
+ const newSpenderBalance = await token.balanceOf.callAsync(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 contractWrappers.token.getBalanceAsync(tokenAddress, owner);
+ const initOwnerBalance = await token.balanceOf.callAsync(owner);
const amountToTransfer = initOwnerBalance;
const initSpenderAllowance = initOwnerBalance;
- await contractWrappers.token.setAllowanceAsync(tokenAddress, owner, spender, initSpenderAllowance);
- await contractWrappers.token.transferFromAsync(tokenAddress, owner, spender, spender, amountToTransfer, {
- gasLimit: constants.MAX_TOKEN_TRANSFERFROM_GAS,
+ await token.approve.sendTransactionAsync(spender, initSpenderAllowance, { from: owner });
+ await token.transferFrom.sendTransactionAsync(owner, spender, amountToTransfer, {
+ from: spender,
+ gas: constants.MAX_TOKEN_TRANSFERFROM_GAS,
});
- const newSpenderAllowance = await contractWrappers.token.getAllowanceAsync(tokenAddress, owner, spender);
+ const newSpenderAllowance = await token.allowance.callAsync(owner, spender);
expect(newSpenderAllowance).to.be.bignumber.equal(0);
});
});