From 8df2926a1acf698f469deaf03a0de35e2179ddf2 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Tue, 30 May 2017 16:31:02 +0200 Subject: Add test for setProxyAllowanceAsync and additional test for getProxyAllowanceAsync --- test/token_wrapper_test.ts | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/test/token_wrapper_test.ts b/test/token_wrapper_test.ts index c9cd08028..3a1a3c3a5 100644 --- a/test/token_wrapper_test.ts +++ b/test/token_wrapper_test.ts @@ -53,12 +53,42 @@ describe('TokenWrapper', () => { }); }); describe('#getProxyAllowanceAsync', () => { + it('should get the proxy allowance', async () => { + const aToken = tokens[0]; + const aOwnerAddress = userAddresses[0]; + + const amountInUnits = new BigNumber('50'); + const amountInBaseUnits = ZeroEx.toBaseUnitAmount(amountInUnits, aToken.decimals); + await zeroEx.token.setProxyAllowanceAsync(aToken.address, aOwnerAddress, amountInBaseUnits); + + const allowance = await zeroEx.token.getProxyAllowanceAsync(aToken.address, aOwnerAddress); + const expectedAllowance = amountInBaseUnits; + expect(allowance).to.be.bignumber.equal(expectedAllowance); + }); it('should return 0 if no allowance set yet', async () => { const aToken = tokens[0]; - const aOwner = userAddresses[0]; - const allowance = await zeroEx.token.getProxyAllowanceAsync(aToken.address, aOwner); + const aOwnerAddress = userAddresses[0]; + const allowance = await zeroEx.token.getProxyAllowanceAsync(aToken.address, aOwnerAddress); const expectedAllowance = new BigNumber('0'); expect(allowance).to.be.bignumber.equal(expectedAllowance); }); }); + describe('#setProxyAllowanceAsync', () => { + it('should set the proxy allowance', async () => { + const aToken = tokens[0]; + const aOwnerAddress = userAddresses[0]; + + const allowanceBeforeSet = await zeroEx.token.getProxyAllowanceAsync(aToken.address, aOwnerAddress); + const expectedAllowanceBeforeAllowanceSet = new BigNumber('0'); + expect(allowanceBeforeSet).to.be.bignumber.equal(expectedAllowanceBeforeAllowanceSet); + + const amountInUnits = new BigNumber('50'); + const amountInBaseUnits = ZeroEx.toBaseUnitAmount(amountInUnits, aToken.decimals); + await zeroEx.token.setProxyAllowanceAsync(aToken.address, aOwnerAddress, amountInBaseUnits); + + const allowanceAfterSet = await zeroEx.token.getProxyAllowanceAsync(aToken.address, aOwnerAddress); + const expectedAllowanceAfterAllowanceSet = amountInBaseUnits; + expect(allowanceAfterSet).to.be.bignumber.equal(expectedAllowanceAfterAllowanceSet); + }); + }); }); -- cgit v1.2.3