Skip to content

Commit aa938cb

Browse files
committed
create fork-live tests looping cycles
1 parent 07720fd commit aa938cb

File tree

1 file changed

+114
-20
lines changed

1 file changed

+114
-20
lines changed

test/maker.test.js

+114-20
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,26 @@
1-
const Maker = artifacts.require("LiquidityMaker");
1+
const Token = artifacts.require("Token");
22
const Weth = artifacts.require("WrappedEther");
3+
const Maker = artifacts.require("LiquidityMaker");
4+
const Factory = artifacts.require("ISwapsFactory");
5+
const helpers = require("@nomicfoundation/hardhat-network-helpers");
36
// const catchRevert = require("./exceptionsHelpers.js").catchRevert;
47
const { expectRevert } = require('@openzeppelin/test-helpers');
58
require("./utils");
69

710
// const BN = web3.utils.BN;
811

9-
const ONE_ETH = web3.utils.toWei("1");
10-
const FOUR_ETH = web3.utils.toWei("4");
11-
const FIVE_ETH = web3.utils.toWei("5");
12-
const NINE_ETH = web3.utils.toWei("9");
12+
const tokens = (value) => {
13+
return web3.utils.toWei(value);
14+
}
15+
16+
const ONE_ETH = tokens("1");
17+
const FOUR_ETH = tokens("4");
18+
const FIVE_ETH = tokens("5");
19+
const NINE_ETH = tokens("9");
20+
21+
const HALF_ETH = tokens("0.5");
22+
23+
const testBlock = 17274000;
1324

1425
const getLastEvent = async (eventName, instance) => {
1526
const events = await instance.getPastEvents(eventName, {
@@ -19,15 +30,43 @@ const getLastEvent = async (eventName, instance) => {
1930
return events.pop().returnValues;
2031
};
2132

22-
contract("Maker", ([owner, alice, bob, random]) => {
2333

24-
const MAINNET_ROUTER = "0xB4B0ea46Fe0E9e8EAB4aFb765b527739F2718671";
25-
const MAINNET_FACTORY = "0xee3E9E46E34a27dC755a63e2849C9913Ee1A06E2";
26-
const MAINNET_WRAPPED_ETH = "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2";
27-
const MAINNET_VERSE_TOKEN = "0x249cA82617eC3DfB2589c4c17ab7EC9765350a18";
34+
const MAINNET_ROUTER = "0xB4B0ea46Fe0E9e8EAB4aFb765b527739F2718671";
35+
const MAINNET_FACTORY = "0xee3E9E46E34a27dC755a63e2849C9913Ee1A06E2";
36+
const MAINNET_WRAPPED_ETH = "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2";
37+
const MAINNET_VERSE_TOKEN = "0x249cA82617eC3DfB2589c4c17ab7EC9765350a18";
38+
const MAINNET_DAI_TOKEN = "0x6B175474E89094C44Da98b954EedeAC495271d0F";
39+
const MAINNET_DEV_ADDRESS = "0x641AD78BAca220C5BD28b51Ce8e0F495e85Fe689";
2840

29-
let maker;
41+
const getSomeDai = async (
42+
beneficiary,
43+
amount
44+
) => {
45+
await helpers.impersonateAccount(
46+
MAINNET_DEV_ADDRESS
47+
);
48+
49+
const impersonatedSigner = await ethers.getSigner(
50+
MAINNET_DEV_ADDRESS
51+
);
52+
53+
let daiEthers = await ethers.getContractAt(
54+
"Token",
55+
MAINNET_DAI_TOKEN
56+
);
57+
58+
await daiEthers.connect(impersonatedSigner).transfer(
59+
beneficiary,
60+
amount
61+
);
62+
}
63+
64+
contract("LiquidityMaker", ([owner, alice, bob, random]) => {
65+
66+
let dai;
3067
let weth;
68+
let maker;
69+
let verse;
3170

3271
beforeEach(async () => {
3372
maker = await Maker.new(
@@ -38,6 +77,14 @@ contract("Maker", ([owner, alice, bob, random]) => {
3877
weth = await Weth.at(
3978
MAINNET_WRAPPED_ETH
4079
);
80+
81+
dai = await Token.at(
82+
MAINNET_DAI_TOKEN
83+
);
84+
85+
verse = await Token.at(
86+
MAINNET_VERSE_TOKEN
87+
);
4188
});
4289

4390
describe("Initial deployment functionality", () => {
@@ -61,17 +108,18 @@ contract("Maker", ([owner, alice, bob, random]) => {
61108

62109
describe("Initial liquidity functionality", () => {
63110

64-
it("should be able to provide liquidity", async () => {
111+
it("should be able to provide liquidity (WETH/DAI) using WEHT", async () => {
65112

66113
const depositor = alice;
67-
const amount = FOUR_ETH;
114+
const depositAmountEth = ONE_ETH;
115+
const minDaiExpected = tokens("900");
68116

69117
const balanceBefore = await weth.balanceOf(
70118
depositor
71119
);
72120

73121
await weth.send(
74-
amount,
122+
depositAmountEth,
75123
{
76124
from: depositor
77125
}
@@ -87,22 +135,68 @@ contract("Maker", ([owner, alice, bob, random]) => {
87135

88136
assert.equal(
89137
balanceChange.toString(),
90-
amount.toString()
138+
depositAmountEth.toString()
91139
);
92140

93141
await weth.approve(
94142
maker.address,
95-
ONE_ETH,
143+
depositAmountEth,
144+
{
145+
from: depositor
146+
}
147+
);
148+
149+
await maker.makeLiquidityDual(
150+
MAINNET_WRAPPED_ETH,
151+
MAINNET_DAI_TOKEN,
152+
depositAmountEth,
153+
minDaiExpected,
154+
0,
155+
0,
156+
{
157+
from: depositor
158+
}
159+
);
160+
161+
const swapResultData = await getLastEvent(
162+
"SwapResults",
163+
maker
164+
);
165+
166+
console.log(swapResultData, 'swapResultData');
167+
168+
const liquidityData = await getLastEvent(
169+
"LiquidityAdded",
170+
maker
171+
);
172+
173+
console.log(liquidityData, 'liquidityData');
174+
});
175+
176+
it("should be able to provide liquidity (WETH/DAI) using DAI", async () => {
177+
178+
const depositor = alice;
179+
const depositAmountDai = tokens("1820");
180+
const minEthExpected = HALF_ETH;
181+
182+
await getSomeDai(
183+
depositor,
184+
depositAmountDai
185+
);
186+
187+
await dai.approve(
188+
maker.address,
189+
depositAmountDai,
96190
{
97191
from: depositor
98192
}
99193
);
100194

101-
await maker.makeLiquidity(
195+
await maker.makeLiquidityDual(
196+
MAINNET_DAI_TOKEN,
102197
MAINNET_WRAPPED_ETH,
103-
MAINNET_VERSE_TOKEN,
104-
ONE_ETH,
105-
1,
198+
depositAmountDai,
199+
minEthExpected,
106200
0,
107201
0,
108202
{

0 commit comments

Comments
 (0)