forked from yuichiroaoki/poly-flash
-
Notifications
You must be signed in to change notification settings - Fork 0
/
uniswapError.test.ts
84 lines (72 loc) · 2.26 KB
/
uniswapError.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers";
import { expect } from "chai";
import { ethers } from "hardhat";
import {
ERC20Mock,
UniswapFork, UniswapFork__factory,
} from "../typechain";
import {
WETH_WHALE, erc20Address, uniswapRouter, USDC_WHALE
} from "../constants/addresses"
import { impersonateFundErc20 } from "../utils/token"
import { getBigNumber, getERC20ContractFromAddress } from "../utils"
describe("Swap on uniswap fork on polygon", () => {
let uniswapFork: UniswapFork;
let owner: SignerWithAddress;
let addr1: SignerWithAddress;
let addr2: SignerWithAddress;
let addrs: SignerWithAddress[];
let DAI: ERC20Mock;
let USDC: ERC20Mock;
let USDT: ERC20Mock;
let WETH: ERC20Mock;
let WMATIC: ERC20Mock;
let fixture: any;
before(async () => {
USDC = await getERC20ContractFromAddress(erc20Address.USDC)
USDT = await getERC20ContractFromAddress(erc20Address.USDT)
DAI = await getERC20ContractFromAddress(erc20Address.DAI)
WETH = await getERC20ContractFromAddress(erc20Address.WETH)
WMATIC = await getERC20ContractFromAddress(erc20Address.WMATIC)
})
before(async () => {
fixture = async () => {
[owner, addr2, addr2, ...addrs] = await ethers.getSigners();
const factory = (await ethers.getContractFactory(
"UniswapFork",
owner
)) as UniswapFork__factory;
uniswapFork = await factory.deploy();
};
});
beforeEach(async () => {
await fixture();
});
describe("quickswap", async () => {
it("should be reverted when you don't have a base token.", async () => {
await expect(
uniswapFork.uniswapFork(
uniswapRouter.POLYGON_QUICKSWAP,
erc20Address.DAI,
getBigNumber(1),
1,
[erc20Address.DAI, erc20Address.USDC],
uniswapFork.address
)
).to.be.revertedWith("TransferHelper: TRANSFER_FROM_FAILED");
});
it("should be reverted with `INSUFFICIENT_INPUT_AMOUNT`.", async () => {
await impersonateFundErc20(USDC, USDC_WHALE, uniswapFork.address, "100.0", 6);
await expect(
uniswapFork.uniswapFork(
uniswapRouter.POLYGON_QUICKSWAP,
erc20Address.USDC,
getBigNumber(1, 6),
getBigNumber(1),
[erc20Address.USDC, erc20Address.DAI],
uniswapFork.address
)
).to.be.revertedWith("UniswapV2Router: INSUFFICIENT_OUTPUT_AMOUNT");
});
});
});