Skip to content

Commit

Permalink
Fix tests and add a check
Browse files Browse the repository at this point in the history
  • Loading branch information
ly0va committed May 25, 2021
1 parent 004e04c commit 9241311
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
24 changes: 12 additions & 12 deletions core/tests/ts-tests/tests/swap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ Tester.prototype.testSwapNFT = async function (
tokenBuy: nft,
amount,
ratio: utils.weiRatio({
tokenSell: amount,
tokenBuy: 1
token: amount,
nft: 1
})
});

Expand All @@ -51,8 +51,8 @@ Tester.prototype.testSwapNFT = async function (
tokenBuy: token,
amount: 1,
ratio: utils.weiRatio({
tokenSell: 1,
tokenBuy: amount
token: amount,
nft: 1
})
});

Expand Down Expand Up @@ -86,8 +86,8 @@ Tester.prototype.testSwap = async function (
tokenBuy: tokenB,
amount,
ratio: utils.weiRatio({
tokenSell: 1,
tokenBuy: 2
tokenA: 1,
tokenB: 2
})
});

Expand All @@ -96,8 +96,8 @@ Tester.prototype.testSwap = async function (
tokenBuy: tokenA,
amount: amount.mul(2),
ratio: utils.weiRatio({
tokenSell: 2,
tokenBuy: 1
tokenA: 1,
tokenB: 2
})
});

Expand Down Expand Up @@ -149,17 +149,17 @@ Tester.prototype.testSwapBatch = async function (
tokenSell: tokenA,
tokenBuy: tokenB,
ratio: utils.weiRatio({
tokenSell: 2,
tokenBuy: 5
tokenA: 2,
tokenB: 5
})
});

const orderB = await walletB.getLimitOrder({
tokenSell: tokenB,
tokenBuy: tokenA,
ratio: utils.weiRatio({
tokenSell: 4,
tokenBuy: 1
tokenA: 1,
tokenB: 4
})
});

Expand Down
4 changes: 4 additions & 0 deletions sdk/zksync.js/src/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,10 @@ export class Wallet {
const sell = order.tokenSell;
const buy = order.tokenBuy;

if (!order.ratio[sell] || !order.ratio[buy]) {
throw new Error('Wrong tokens in the ratio object');
}

if (order.ratio.type == 'Wei') {
ratio = [order.ratio[sell], order.ratio[buy]];
} else if (order.ratio.type == 'Token') {
Expand Down

0 comments on commit 9241311

Please sign in to comment.