aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorFabio Berger <me@fabioberger.com>2017-06-01 23:17:32 +0800
committerFabio Berger <me@fabioberger.com>2017-06-01 23:17:32 +0800
commit5888a03a02254cfb0d2a8d5345699884a82cc7a5 (patch)
tree7e084849a8a928fea86ea2614a0a263a2263d9e6 /test
parentcc0d6411071cb36a224c8f4f0cb742edb4193482 (diff)
parentd1f352810f2228b2be143557f86e55c90193eea4 (diff)
downloaddexon-sol-tools-5888a03a02254cfb0d2a8d5345699884a82cc7a5.tar
dexon-sol-tools-5888a03a02254cfb0d2a8d5345699884a82cc7a5.tar.gz
dexon-sol-tools-5888a03a02254cfb0d2a8d5345699884a82cc7a5.tar.bz2
dexon-sol-tools-5888a03a02254cfb0d2a8d5345699884a82cc7a5.tar.lz
dexon-sol-tools-5888a03a02254cfb0d2a8d5345699884a82cc7a5.tar.xz
dexon-sol-tools-5888a03a02254cfb0d2a8d5345699884a82cc7a5.tar.zst
dexon-sol-tools-5888a03a02254cfb0d2a8d5345699884a82cc7a5.zip
Merge branch 'fillOrderAsync' of github.com:0xProject/0x.js into fillOrderAsync
# Conflicts: # test/exchange_wrapper_test.ts
Diffstat (limited to 'test')
-rw-r--r--test/exchange_wrapper_test.ts26
1 files changed, 18 insertions, 8 deletions
diff --git a/test/exchange_wrapper_test.ts b/test/exchange_wrapper_test.ts
index d6dca0a63..9c3683a98 100644
--- a/test/exchange_wrapper_test.ts
+++ b/test/exchange_wrapper_test.ts
@@ -104,6 +104,10 @@ describe('ExchangeWrapper', () => {
});
describe('#fillOrderAsync', () => {
let tokens: Token[];
+ const addressBySymbol: {[symbol: string]: string} = {};
+ let networkId: number;
+ const fillAmount = new BigNumber(5);
+ const shouldCheckTransfer = false;
let maker: string;
let taker: string;
let networkId: number;
@@ -128,9 +132,12 @@ describe('ExchangeWrapper', () => {
});
networkId = await promisify(web3.version.getNetwork)();
});
- beforeEach('setup', () => {
+ beforeEach('setup', async () => {
maker = userAddresses[0];
taker = userAddresses[1];
+ await setAllowanceAsync(maker, 5, addressBySymbol.MLN);
+ await setBalanceAsync(taker, 5, addressBySymbol.GNT);
+ await setAllowanceAsync(taker, 5, addressBySymbol.GNT);
});
afterEach('reset default account', () => {
zeroEx.setDefaultAccount(userAddresses[0]);
@@ -139,27 +146,30 @@ describe('ExchangeWrapper', () => {
it('should throw when the fill amount is zero', async () => {
const signedOrder = await orderFactory.createSignedOrderAsync(zeroEx, networkId, maker, taker,
5, addressBySymbol.MLN, 5, addressBySymbol.GNT);
- const fillAmount = new BigNumber(0);
+ const zeroFillAmount = new BigNumber(0);
zeroEx.setDefaultAccount(taker);
- expect(zeroEx.exchange.fillOrderAsync(signedOrder, fillAmount, shouldCheckTransfer))
+ expect(zeroEx.exchange.fillOrderAsync(signedOrder, zeroFillAmount, shouldCheckTransfer))
.to.be.rejectedWith(FillOrderValidationErrs.FILL_AMOUNT_IS_ZERO);
});
it('should throw when sender is not a taker', async () => {
const signedOrder = await orderFactory.createSignedOrderAsync(zeroEx, networkId, maker, taker,
5, addressBySymbol.MLN, 5, addressBySymbol.GNT);
- const fillAmount = new BigNumber(5);
expect(zeroEx.exchange.fillOrderAsync(signedOrder, fillAmount, shouldCheckTransfer))
.to.be.rejectedWith(FillOrderValidationErrs.NOT_A_TAKER);
});
+ it('should throw when order is expired', async () => {
+ const OLD_TIMESTAMP = new BigNumber(42);
+ const signedOrder = await orderFactory.createSignedOrderAsync(zeroEx, networkId, maker, taker,
+ 5, addressBySymbol.MLN, 5, addressBySymbol.GNT, OLD_TIMESTAMP);
+ zeroEx.setDefaultAccount(taker);
+ expect(zeroEx.exchange.fillOrderAsync(signedOrder, fillAmount, shouldCheckTransfer))
+ .to.be.rejectedWith(FillOrderValidationErrs.EXPIRED);
+ });
});
describe('successful fills', () => {
it('should fill the valid order', async () => {
- await setAllowanceAsync(maker, 5, addressBySymbol.MLN);
- await setBalanceAsync(taker, 5, addressBySymbol.GNT);
- await setAllowanceAsync(taker, 5, addressBySymbol.GNT);
const signedOrder = await orderFactory.createSignedOrderAsync(zeroEx, networkId, maker, taker,
5, addressBySymbol.MLN, 5, addressBySymbol.GNT);
- const fillAmount = new BigNumber(5);
zeroEx.setDefaultAccount(taker);
await zeroEx.exchange.fillOrderAsync(signedOrder, fillAmount, shouldCheckTransfer);
expect(await zeroEx.token.getBalanceAsync(addressBySymbol.MLN, taker)).to.be.bignumber.equal(5);