aboutsummaryrefslogtreecommitdiffstats
path: root/test/exchange_wrapper_test.ts
diff options
context:
space:
mode:
authorLeonid Logvinov <logvinov.leon@gmail.com>2017-06-02 17:23:39 +0800
committerLeonid Logvinov <logvinov.leon@gmail.com>2017-06-02 17:23:39 +0800
commita740498c8061bc7a3dafae82929b358e61bac2d4 (patch)
treeabf66a0df929cee19b356bde959fcb7ff3b92b79 /test/exchange_wrapper_test.ts
parentf663a15c9b000d639bd0d58d0c177e6de9d47346 (diff)
downloaddexon-sol-tools-a740498c8061bc7a3dafae82929b358e61bac2d4.tar
dexon-sol-tools-a740498c8061bc7a3dafae82929b358e61bac2d4.tar.gz
dexon-sol-tools-a740498c8061bc7a3dafae82929b358e61bac2d4.tar.bz2
dexon-sol-tools-a740498c8061bc7a3dafae82929b358e61bac2d4.tar.lz
dexon-sol-tools-a740498c8061bc7a3dafae82929b358e61bac2d4.tar.xz
dexon-sol-tools-a740498c8061bc7a3dafae82929b358e61bac2d4.tar.zst
dexon-sol-tools-a740498c8061bc7a3dafae82929b358e61bac2d4.zip
Introduce coinBase account
Add makerAccount parameter Adjust tests Add more assertions to success test
Diffstat (limited to 'test/exchange_wrapper_test.ts')
-rw-r--r--test/exchange_wrapper_test.ts33
1 files changed, 20 insertions, 13 deletions
diff --git a/test/exchange_wrapper_test.ts b/test/exchange_wrapper_test.ts
index 77c78470b..716adb63a 100644
--- a/test/exchange_wrapper_test.ts
+++ b/test/exchange_wrapper_test.ts
@@ -108,16 +108,14 @@ describe('ExchangeWrapper', () => {
let makerTokenAddress: string;
let takerTokenAddress: string;
let fillScenarios: FillScenarios;
+ let coinBase: string;
+ let makerAddress: string;
let takerAddress: string;
const fillTakerAmountInBaseUnits = new BigNumber(5);
- const addressBySymbol: {[symbol: string]: string} = {};
const shouldCheckTransfer = false;
before('fetch tokens', async () => {
- takerAddress = userAddresses[1];
+ [coinBase, makerAddress, takerAddress] = userAddresses;
tokens = await zeroEx.tokenRegistry.getTokensAsync();
- _.forEach(tokens, token => {
- addressBySymbol[token.symbol] = token.address;
- });
const [makerToken, takerToken] = tokens;
makerTokenAddress = makerToken.address;
takerTokenAddress = takerToken.address;
@@ -130,7 +128,7 @@ describe('ExchangeWrapper', () => {
it('should throw when the fill amount is zero', async () => {
const fillableAmount = new BigNumber(5);
const signedOrder = await fillScenarios.createAFillableSignedOrderAsync(
- makerTokenAddress, takerTokenAddress, takerAddress, fillableAmount,
+ makerTokenAddress, takerTokenAddress, makerAddress, takerAddress, fillableAmount,
);
const zeroFillAmount = new BigNumber(0);
zeroEx.setTransactionSenderAccount(takerAddress);
@@ -140,7 +138,7 @@ describe('ExchangeWrapper', () => {
it('should throw when sender is not a taker', async () => {
const fillableAmount = new BigNumber(5);
const signedOrder = await fillScenarios.createAFillableSignedOrderAsync(
- makerTokenAddress, takerTokenAddress, takerAddress, fillableAmount,
+ makerTokenAddress, takerTokenAddress, makerAddress, takerAddress, fillableAmount,
);
expect(zeroEx.exchange.fillOrderAsync(signedOrder, fillTakerAmountInBaseUnits, shouldCheckTransfer))
.to.be.rejectedWith(FillOrderValidationErrs.NOT_A_TAKER);
@@ -149,7 +147,7 @@ describe('ExchangeWrapper', () => {
const expirationInPast = new BigNumber(42);
const fillableAmount = new BigNumber(5);
const signedOrder = await fillScenarios.createAFillableSignedOrderAsync(
- makerTokenAddress, takerTokenAddress, takerAddress, fillableAmount, expirationInPast,
+ makerTokenAddress, takerTokenAddress, makerAddress, takerAddress, fillableAmount, expirationInPast,
);
zeroEx.setTransactionSenderAccount(takerAddress);
expect(zeroEx.exchange.fillOrderAsync(signedOrder, fillTakerAmountInBaseUnits, shouldCheckTransfer))
@@ -158,7 +156,7 @@ describe('ExchangeWrapper', () => {
it('should throw when taker balance is less than fill amount', async () => {
const fillableAmount = new BigNumber(5);
const signedOrder = await fillScenarios.createAFillableSignedOrderAsync(
- makerTokenAddress, takerTokenAddress, takerAddress, fillableAmount,
+ makerTokenAddress, takerTokenAddress, makerAddress, takerAddress, fillableAmount,
);
zeroEx.setTransactionSenderAccount(takerAddress);
const moreThanTheBalance = new BigNumber(6);
@@ -170,18 +168,27 @@ describe('ExchangeWrapper', () => {
it('should fill the valid order', async () => {
const fillableAmount = new BigNumber(5);
const signedOrder = await fillScenarios.createAFillableSignedOrderAsync(
- makerTokenAddress, takerTokenAddress, takerAddress, fillableAmount,
+ makerTokenAddress, takerTokenAddress, makerAddress, takerAddress, fillableAmount,
);
- zeroEx.setTransactionSenderAccount(takerAddress);
+
+ expect(await zeroEx.token.getBalanceAsync(makerTokenAddress, makerAddress))
+ .to.be.bignumber.equal(fillableAmount);
+ expect(await zeroEx.token.getBalanceAsync(takerTokenAddress, makerAddress))
+ .to.be.bignumber.equal(0);
expect(await zeroEx.token.getBalanceAsync(makerTokenAddress, takerAddress))
.to.be.bignumber.equal(0);
expect(await zeroEx.token.getBalanceAsync(takerTokenAddress, takerAddress))
- .to.be.bignumber.equal(fillTakerAmountInBaseUnits);
+ .to.be.bignumber.equal(fillableAmount);
+ zeroEx.setTransactionSenderAccount(takerAddress);
await zeroEx.exchange.fillOrderAsync(signedOrder, fillTakerAmountInBaseUnits, shouldCheckTransfer);
+ expect(await zeroEx.token.getBalanceAsync(makerTokenAddress, makerAddress))
+ .to.be.bignumber.equal(fillableAmount.minus(fillTakerAmountInBaseUnits));
+ expect(await zeroEx.token.getBalanceAsync(takerTokenAddress, makerAddress))
+ .to.be.bignumber.equal(fillTakerAmountInBaseUnits);
expect(await zeroEx.token.getBalanceAsync(makerTokenAddress, takerAddress))
.to.be.bignumber.equal(fillTakerAmountInBaseUnits);
expect(await zeroEx.token.getBalanceAsync(takerTokenAddress, takerAddress))
- .to.be.bignumber.equal(0);
+ .to.be.bignumber.equal(fillableAmount.minus(fillTakerAmountInBaseUnits));
});
});
});