remove unnecessary assertion and add regression test

This commit is contained in:
Fabio Berger 2017-08-16 15:44:39 -07:00
parent 2e668a771a
commit 20045a438a
2 changed files with 40 additions and 18 deletions

View File

@ -89,7 +89,6 @@ export class TokenWrapper extends ContractWrapper {
public async getAllowanceAsync(tokenAddress: string, ownerAddress: string, spenderAddress: string) { public async getAllowanceAsync(tokenAddress: string, ownerAddress: string, spenderAddress: string) {
assert.isETHAddressHex('ownerAddress', ownerAddress); assert.isETHAddressHex('ownerAddress', ownerAddress);
assert.isETHAddressHex('tokenAddress', tokenAddress); assert.isETHAddressHex('tokenAddress', tokenAddress);
await assert.isUserAddressAvailableAsync(this._web3Wrapper);
const tokenContract = await this._getTokenContractAsync(tokenAddress); const tokenContract = await this._getTokenContractAsync(tokenAddress);
let allowanceInBaseUnits = await tokenContract.allowance.call(ownerAddress, spenderAddress); let allowanceInBaseUnits = await tokenContract.allowance.call(ownerAddress, spenderAddress);

View File

@ -176,7 +176,6 @@ describe('TokenWrapper', () => {
before(async () => { before(async () => {
const hasAddresses = false; const hasAddresses = false;
const web3WithoutAccounts = web3Factory.create(hasAddresses); const web3WithoutAccounts = web3Factory.create(hasAddresses);
web3WithoutAccounts.eth.getAccounts(console.log);
zeroExWithoutAccounts = new ZeroEx(web3WithoutAccounts.currentProvider); zeroExWithoutAccounts = new ZeroEx(web3WithoutAccounts.currentProvider);
}); });
it('should return balance even when called with Web3 provider instance without addresses', async () => { it('should return balance even when called with Web3 provider instance without addresses', async () => {
@ -208,25 +207,49 @@ describe('TokenWrapper', () => {
}); });
}); });
describe('#getAllowanceAsync', () => { describe('#getAllowanceAsync', () => {
it('should get the proxy allowance', async () => { describe('With web3 provider with accounts', () => {
const token = tokens[0]; it('should get the proxy allowance', async () => {
const ownerAddress = coinbase; const token = tokens[0];
const spenderAddress = addressWithoutFunds; const ownerAddress = coinbase;
const spenderAddress = addressWithoutFunds;
const amountInBaseUnits = new BigNumber(50); const amountInBaseUnits = new BigNumber(50);
await zeroEx.token.setAllowanceAsync(token.address, ownerAddress, spenderAddress, amountInBaseUnits); await zeroEx.token.setAllowanceAsync(token.address, ownerAddress, spenderAddress, amountInBaseUnits);
const allowance = await zeroEx.token.getAllowanceAsync(token.address, ownerAddress, spenderAddress); const allowance = await zeroEx.token.getAllowanceAsync(token.address, ownerAddress, spenderAddress);
const expectedAllowance = amountInBaseUnits; const expectedAllowance = amountInBaseUnits;
return expect(allowance).to.be.bignumber.equal(expectedAllowance); return expect(allowance).to.be.bignumber.equal(expectedAllowance);
});
it('should return 0 if no allowance set yet', async () => {
const token = tokens[0];
const ownerAddress = coinbase;
const spenderAddress = addressWithoutFunds;
const allowance = await zeroEx.token.getAllowanceAsync(token.address, ownerAddress, spenderAddress);
const expectedAllowance = new BigNumber(0);
return expect(allowance).to.be.bignumber.equal(expectedAllowance);
});
}); });
it('should return 0 if no allowance set yet', async () => { describe('With web3 provider without accounts', () => {
const token = tokens[0]; let zeroExWithoutAccounts: ZeroEx;
const ownerAddress = coinbase; before(async () => {
const spenderAddress = addressWithoutFunds; const hasAddresses = false;
const allowance = await zeroEx.token.getAllowanceAsync(token.address, ownerAddress, spenderAddress); const web3WithoutAccounts = web3Factory.create(hasAddresses);
const expectedAllowance = new BigNumber(0); zeroExWithoutAccounts = new ZeroEx(web3WithoutAccounts.currentProvider);
return expect(allowance).to.be.bignumber.equal(expectedAllowance); });
it('should get the proxy allowance', async () => {
const token = tokens[0];
const ownerAddress = coinbase;
const spenderAddress = addressWithoutFunds;
const amountInBaseUnits = new BigNumber(50);
await zeroEx.token.setAllowanceAsync(token.address, ownerAddress, spenderAddress, amountInBaseUnits);
const allowance = await zeroExWithoutAccounts.token.getAllowanceAsync(
token.address, ownerAddress, spenderAddress,
);
const expectedAllowance = amountInBaseUnits;
return expect(allowance).to.be.bignumber.equal(expectedAllowance);
});
}); });
}); });
describe('#getProxyAllowanceAsync', () => { describe('#getProxyAllowanceAsync', () => {