Skip to content

Commit

Permalink
polish test
Browse files Browse the repository at this point in the history
  • Loading branch information
shunjizhan committed Nov 28, 2023
1 parent 2c920d3 commit 5202fd8
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/__tests__/testUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,18 @@ export const mockXcmToRouter = async (
) => {
const token = ERC20__factory.connect(tokenAddr, signer);

expect((await token.balanceOf(routerAddr)).toNumber(), 'router already has balance!').to.eq(0);

const decimals = await token.decimals();

const routeAmount = parseUnits(String(amount), decimals);
if ((await token.balanceOf(signer.address)).lt(routeAmount)) {
throw new Error(`signer ${signer.address} has no enough token [${tokenAddr}] to transfer!`);
}
await (await token.transfer(routerAddr, routeAmount)).wait();

expect((await token.balanceOf(routerAddr)).toBigInt()).to.eq(routeAmount.toBigInt());
const routerBal = await token.balanceOf(routerAddr);
if (routerBal.gt(0)) {
expect(routerBal.toBigInt()).to.eq(routeAmount.toBigInt());
} else {
if ((await token.balanceOf(signer.address)).lt(routeAmount)) {
throw new Error(`signer ${signer.address} has no enough token [${tokenAddr}] to transfer!`);
}
await (await token.transfer(routerAddr, routeAmount)).wait();
}
};

export const expectError = (err: any, msg: any, code: number) => {
Expand Down

0 comments on commit 5202fd8

Please sign in to comment.