updated testcases

This commit is contained in:
Shriya Tyagi 2022-08-25 05:27:24 +05:30
parent e0882cb830
commit eab97baeff

View File

@ -5,7 +5,7 @@ import { addresses } from "../../../scripts/tests/mainnet/addresses";
import { deployAndEnableConnector } from "../../../scripts/tests/deployAndEnableConnector"; import { deployAndEnableConnector } from "../../../scripts/tests/deployAndEnableConnector";
import { getMasterSigner } from "../../../scripts/tests/getMasterSigner"; import { getMasterSigner } from "../../../scripts/tests/getMasterSigner";
import { buildDSAv2 } from "../../../scripts/tests/buildDSAv2"; import { buildDSAv2 } from "../../../scripts/tests/buildDSAv2";
import { ConnectV2EulerImport__factory, ConnectV2Euler__factory, IERC20__factory } from "../../../typechain"; import { ConnectV2EulerImport__factory, IERC20__factory } from "../../../typechain";
import { parseEther, parseUnits } from "@ethersproject/units"; import { parseEther, parseUnits } from "@ethersproject/units";
import { encodeSpells } from "../../../scripts/tests/encodeSpells"; import { encodeSpells } from "../../../scripts/tests/encodeSpells";
const { ethers } = hre; const { ethers } = hre;
@ -38,6 +38,9 @@ const token_weth = new ethers.Contract(
"function balanceOf(address account) public view returns (uint256)", "function balanceOf(address account) public view returns (uint256)",
"function allowance(address, address) public returns (uint256)", "function allowance(address, address) public returns (uint256)",
"function deposit(uint256,uint256) public", "function deposit(uint256,uint256) public",
"function balanceOfUnderlying(address) public view returns (uint256)",
"function mint(uint256,uint256) public",
"function approveSubAccount(uint256, address, uint256) public"
]; ];
const dTokensABI = [ const dTokensABI = [
@ -70,6 +73,7 @@ describe("Euler", function () {
let dsaWallet0: any; let dsaWallet0: any;
let instaConnectorsV2: Contract; let instaConnectorsV2: Contract;
let masterSigner: Signer; let masterSigner: Signer;
let walletAddr: any;
before(async () => { before(async () => {
await hre.network.provider.request({ await hre.network.provider.request({
@ -79,7 +83,7 @@ describe("Euler", function () {
forking: { forking: {
// @ts-ignore // @ts-ignore
jsonRpcUrl: hre.config.networks.hardhat.forking.url, jsonRpcUrl: hre.config.networks.hardhat.forking.url,
blockNumber: 15178000, blockNumber: 15179000,
}, },
}, },
], ],
@ -114,6 +118,7 @@ describe("Euler", function () {
connectors: instaConnectorsV2, connectors: instaConnectorsV2,
}); });
console.log("Connector address", connector.address); console.log("Connector address", connector.address);
walletAddr = (await wallet0.getAddress()).toString()
}); });
it("should have contracts deployed", async () => { it("should have contracts deployed", async () => {
@ -138,7 +143,7 @@ describe("Euler", function () {
); );
}); });
describe("Create Euler position", async () => { describe("Create Euler position in SUBACCOUNT 0", async () => {
it("Should create Euler position of WETH(collateral) and DAI(debt)", async () => { it("Should create Euler position of WETH(collateral) and DAI(debt)", async () => {
// approve WETH to euler // approve WETH to euler
await token_weth.connect(wallet0).approve(euler_mainnet, Weth); await token_weth.connect(wallet0).approve(euler_mainnet, Weth);
@ -147,6 +152,8 @@ describe("Euler", function () {
// deposit WETH in euler // deposit WETH in euler
await eWethContract.connect(wallet0).deposit("0", parseUnits('2', 18));//todo: check balance await eWethContract.connect(wallet0).deposit("0", parseUnits('2', 18));//todo: check balance
console.log("Supplied WETH on Euler"); console.log("Supplied WETH on Euler");
console.log("eWETH balance underlying: ", await eWethContract.connect(wallet0).balanceOfUnderlying(wallet0.getAddress()))
// enter WETH market // enter WETH market
await marketsContract.connect(wallet0).enterMarket("0", WETH); await marketsContract.connect(wallet0).enterMarket("0", WETH);
@ -164,25 +171,87 @@ describe("Euler", function () {
}); });
}); });
describe("Create Euler position in SUBACCOUNT 1", async () => {
let sub1addr = ethers.BigNumber.from(walletAddr).xor(1).toHexString()
it("Should create Euler self-position of WETH(collateral) and WETH(debt)", async () => {
// approve WETH to euler
await token_weth.connect(wallet0).approve(euler_mainnet, Weth);
console.log("Approved WETH");
// deposit WETH in euler
await eWethContract.connect(wallet0).deposit("1", parseUnits('2', 18));//todo: check balance
console.log("Supplied WETH on Euler");
// enter WETH market
await marketsContract.connect(wallet0).enterMarket("1", WETH);
console.log("Entered market for weth");
// mint WETH from Euler
await eWethContract.connect(wallet0).mint("1", parseUnits('1', 18));
console.log("Minted WETH from Euler");
console.log("eWETH balance underlying: ", await eWethContract.connect(wallet0).balanceOfUnderlying(sub1addr))
});
it("Should check created position of user", async () => {
expect(await eWethContract.connect(wallet0).balanceOfUnderlying(sub1addr)).to.be.gte(parseEther("3"));
});
});
describe("Euler position migration", async () => { describe("Euler position migration", async () => {
it("Should migrate euler position", async () => { it("Approve sub-account0 eTokens for import to DSA sub-account 0", async () => {
let balance = await eWethContract.connect(wallet0).balanceOf(walletAddr)
await eWethContract.connect(wallet0).approve(dsaWallet0.address, balance);
});
it("Approve sub-account1 eTokens for import to DSA sub-account 2", async () => {
let balance = await eWethContract.connect(wallet0).balanceOf(ethers.BigNumber.from(walletAddr).xor(1).toHexString())
await eWethContract.connect(wallet0).approveSubAccount("1", dsaWallet0.address, balance);
});
it("Should migrate euler position of sub-account 0", async () => {
console.log("walletAddr: ", walletAddr)
const spells = [ const spells = [
{ {
connector: "EULER-IMPORT-TEST-A", connector: "EULER-IMPORT-TEST-A",
method: "importEuler", method: "importEuler",
args: [ args: [
(await wallet0.getAddress()).toString(), walletAddr,
"0", "0",
"0", "0",
[[WETH], [DAI]], [[WETH],[DAI],["true"]]
["true"]
] ]
}, },
]; ];
const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet0.getAddress()); const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet0.getAddress());
const receipt = await tx.wait(); const receipt = await tx.wait();
}); });
it("Should check migration", async () => {
expect(await eWethContract.connect(wallet0).balanceOfUnderlying(dsaWallet0.address)).to.be.gte(parseEther("2"));
});
it("Should migrate euler position of sub-account 1", async () => {
const spells = [
{
connector: "EULER-IMPORT-TEST-A",
method: "importEuler",
args: [
walletAddr,
"1",
"2",
[[WETH],[WETH],["true"]]
]
},
];
const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet0.getAddress());
const receipt = await tx.wait();
});
it("Should check migration", async () => {
expect(await eWethContract.connect(wallet0).balanceOfUnderlying(ethers.BigNumber.from(dsaWallet0.address).xor(2).toHexString())).to.be.gte(parseEther("3"));
});
}) })
}); });
}) })