aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFabio Berger <me@fabioberger.com>2017-06-03 02:34:16 +0800
committerFabio Berger <me@fabioberger.com>2017-06-03 02:34:16 +0800
commitc6ceb44682a19c9f53505803547fcb2012691b5b (patch)
tree5336a6ad855bba28caa9b7aa27ca85a2a0781c0d
parentbae4b1ee1b991340df5bf2c5317b7af7088cedd3 (diff)
downloaddexon-sol-tools-c6ceb44682a19c9f53505803547fcb2012691b5b.tar
dexon-sol-tools-c6ceb44682a19c9f53505803547fcb2012691b5b.tar.gz
dexon-sol-tools-c6ceb44682a19c9f53505803547fcb2012691b5b.tar.bz2
dexon-sol-tools-c6ceb44682a19c9f53505803547fcb2012691b5b.tar.lz
dexon-sol-tools-c6ceb44682a19c9f53505803547fcb2012691b5b.tar.xz
dexon-sol-tools-c6ceb44682a19c9f53505803547fcb2012691b5b.tar.zst
dexon-sol-tools-c6ceb44682a19c9f53505803547fcb2012691b5b.zip
Fix bug
-rw-r--r--src/contract_wrappers/token_wrapper.ts2
-rw-r--r--test/token_wrapper_test.ts12
2 files changed, 6 insertions, 8 deletions
diff --git a/src/contract_wrappers/token_wrapper.ts b/src/contract_wrappers/token_wrapper.ts
index 5c556dd4f..8bec39a52 100644
--- a/src/contract_wrappers/token_wrapper.ts
+++ b/src/contract_wrappers/token_wrapper.ts
@@ -129,7 +129,7 @@ export class TokenWrapper extends ContractWrapper {
const tokenContract = await this.getTokenContractAsync(tokenAddress);
- const fromAddressAllowance = await this.getAllowanceAsync(tokenAddress, fromAddress, toAddress);
+ const fromAddressAllowance = await this.getAllowanceAsync(tokenAddress, fromAddress, senderAddress);
if (fromAddressAllowance.lessThan(amountInBaseUnits)) {
throw new Error(ZeroExError.INSUFFICIENT_ALLOWANCE_FOR_TRANSFER);
}
diff --git a/test/token_wrapper_test.ts b/test/token_wrapper_test.ts
index 08eb8aec0..698ad5b6a 100644
--- a/test/token_wrapper_test.ts
+++ b/test/token_wrapper_test.ts
@@ -68,9 +68,11 @@ describe('TokenWrapper', () => {
describe('#transferFromAsync', () => {
let token: Token;
let toAddress: string;
+ let senderAddress: string;
before(async () => {
token = tokens[0];
toAddress = addressWithoutFunds;
+ senderAddress = userAddresses[2];
});
it('should fail to transfer tokens if fromAddress has insufficient allowance set', async () => {
const fromAddress = coinbase;
@@ -83,7 +85,6 @@ describe('TokenWrapper', () => {
toAddress);
expect(fromAddressAllowance).to.be.bignumber.equal(0);
- const senderAddress = toAddress;
return expect(zeroEx.token.transferFromAsync(
token.address, fromAddress, toAddress, senderAddress, transferAmount,
)).to.be.rejectedWith(ZeroExError.INSUFFICIENT_ALLOWANCE_FOR_TRANSFER);
@@ -95,12 +96,11 @@ describe('TokenWrapper', () => {
const fromAddressBalance = await zeroEx.token.getBalanceAsync(token.address, fromAddress);
expect(fromAddressBalance).to.be.bignumber.equal(0);
- await zeroEx.token.setAllowanceAsync(token.address, fromAddress, toAddress, transferAmount);
+ await zeroEx.token.setAllowanceAsync(token.address, fromAddress, senderAddress, transferAmount);
const fromAddressAllowance = await zeroEx.token.getAllowanceAsync(token.address, fromAddress,
- toAddress);
+ senderAddress);
expect(fromAddressAllowance).to.be.bignumber.equal(transferAmount);
- const senderAddress = toAddress;
return expect(zeroEx.token.transferFromAsync(
token.address, fromAddress, toAddress, senderAddress, transferAmount,
)).to.be.rejectedWith(ZeroExError.INSUFFICIENT_BALANCE_FOR_TRANSFER);
@@ -112,9 +112,8 @@ describe('TokenWrapper', () => {
expect(preBalance).to.be.bignumber.equal(0);
const transferAmount = new BigNumber(42);
- await zeroEx.token.setAllowanceAsync(token.address, fromAddress, toAddress, transferAmount);
+ await zeroEx.token.setAllowanceAsync(token.address, fromAddress, senderAddress, transferAmount);
- const senderAddress = toAddress;
await zeroEx.token.transferFromAsync(token.address, fromAddress, toAddress, senderAddress,
transferAmount);
const postBalance = await zeroEx.token.getBalanceAsync(token.address, toAddress);
@@ -123,7 +122,6 @@ describe('TokenWrapper', () => {
it('should throw a CONTRACT_DOES_NOT_EXIST error for a non-existent token contract', async () => {
const fromAddress = coinbase;
const nonExistentTokenAddress = '0x9dd402f14d67e001d8efbe6583e51bf9706aa065';
- const senderAddress = fromAddress;
return expect(zeroEx.token.transferFromAsync(
nonExistentTokenAddress, fromAddress, toAddress, senderAddress, new BigNumber(42),
)).to.be.rejectedWith(ZeroExError.CONTRACT_DOES_NOT_EXIST);