aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLeonid Logvinov <logvinov.leon@gmail.com>2017-05-31 23:45:15 +0800
committerLeonid Logvinov <logvinov.leon@gmail.com>2017-05-31 23:45:15 +0800
commit82a46b4938902009896bef1d296b887f66b284fd (patch)
tree1657214dc34381eb4314c32ed87aca47e7a1cd42
parent1955e90bbbfeb7d2aeebfd84132f684d20e17400 (diff)
downloaddexon-0x-contracts-82a46b4938902009896bef1d296b887f66b284fd.tar.gz
dexon-0x-contracts-82a46b4938902009896bef1d296b887f66b284fd.tar.zst
dexon-0x-contracts-82a46b4938902009896bef1d296b887f66b284fd.zip
Add setAllowance function
-rw-r--r--test/exchange_wrapper_test.ts22
1 files changed, 18 insertions, 4 deletions
diff --git a/test/exchange_wrapper_test.ts b/test/exchange_wrapper_test.ts
index 24383906f..5138e140f 100644
--- a/test/exchange_wrapper_test.ts
+++ b/test/exchange_wrapper_test.ts
@@ -21,6 +21,7 @@ describe('ExchangeWrapper', () => {
web3 = web3Factory.create();
zeroEx = new ZeroEx(web3);
userAddresses = await promisify(web3.eth.getAccounts)();
+ web3.eth.defaultAccount = userAddresses[0];
});
beforeEach(async () => {
await blockchainLifecycle.startAsync();
@@ -100,7 +101,7 @@ describe('ExchangeWrapper', () => {
});
describe('#fillOrderAsync', () => {
let tokens: Token[];
- const giveMeTokens = async (toAddress: string,
+ const setBalance = async (toAddress: string,
amountInBaseUnits: BigNumber.BigNumber|number,
symbol: string) => {
const amount = _.isNumber(amountInBaseUnits) ? new BigNumber(amountInBaseUnits) : amountInBaseUnits;
@@ -111,6 +112,17 @@ describe('ExchangeWrapper', () => {
await zeroEx.token.transferAsync(token.address, userAddresses[0], toAddress, amount);
}
};
+ const setAllowance = async (ownerAddress: string,
+ amountInBaseUnits: BigNumber.BigNumber|number,
+ symbol: string) => {
+ const amount = _.isNumber(amountInBaseUnits) ? new BigNumber(amountInBaseUnits) : amountInBaseUnits;
+ const token = _.find(tokens, {symbol});
+ if (_.isUndefined(token)) {
+ throw new Error(`Token ${symbol} not found`);
+ } else {
+ await zeroEx.token.setProxyAllowanceAsync(token.address, ownerAddress, amount);
+ }
+ };
before('fetch tokens', async () => {
tokens = await zeroEx.tokenRegistry.getTokensAsync();
});
@@ -127,11 +139,13 @@ describe('ExchangeWrapper', () => {
web3.eth.defaultAccount = userAddresses[0];
});
it('should fill the valid order', async () => {
+ await setAllowance(userAddresses[0], 5, 'MLN');
+ await setBalance(userAddresses[1], 5, 'GNT');
+ await setAllowance(userAddresses[1], 5, 'GNT');
const signedOrder = await createSignedOrder(zeroEx, tokens, 5, 'MLN', 5, 'GNT');
- await giveMeTokens(userAddresses[0], 5, 'GNT');
- const fillAmount = new BigNumber(0);
+ const fillAmount = new BigNumber(5);
web3.eth.defaultAccount = userAddresses[1];
- expect(zeroEx.exchange.fillOrderAsync(signedOrder, fillAmount)).to.become(undefined);
+ await zeroEx.exchange.fillOrderAsync(signedOrder, fillAmount);
});
});
});