feat: update testcases

This commit is contained in:
Shriya Tyagi 2023-08-21 17:37:21 +05:30
parent ddaec8d11a
commit eae28b5553

View File

@ -93,7 +93,7 @@ describe("BASIC-D", function () {
value: ethers.utils.parseEther("10")
});
let txRes = await daiContract.connect(signer).transfer(dsaWallet0.address, ethers.utils.parseEther("10000"));
let txRes = await daiContract.connect(signer).transfer(dsaWallet0.address, ethers.utils.parseEther("1000"));
await txRes.wait();
// expect(await daiContract.balanceOf(dsaWallet0.address)).to.be.eq(ethers.utils.parseEther("10000"));
});
@ -108,15 +108,17 @@ describe("BASIC-D", function () {
// });
it("should deposit asset to ERC4626", async () => {
const assets = ethers.utils.parseEther("1");
// Returns the amount of shares for assets
const previewDeposit = await erc4626Contract.previewDeposit(assets);
console.log("previewDeposit :>> ", previewDeposit);
console.log("previewDeposit :>> ", previewDeposit.toString());
const maxDeposit = await erc4626Contract.maxDeposit(dsaWallet0.address);
let minSharesPerToken = ethers.utils.parseUnits("0.95");
const beforebalance = await erc4626Contract.balanceOf(dsaWallet0.address);
console.log("beforebalance :>> ", beforebalance);
console.log("Share before balance :>> ", beforebalance.toString());
let spells = [
{
@ -130,7 +132,9 @@ describe("BASIC-D", function () {
let receipt = await tx.wait();
const afterbalance = await erc4626Contract.balanceOf(dsaWallet0.address);
console.log("afterbalance :>> ", afterbalance);
console.log("Share after balance :>> ", afterbalance.toString());
expect(afterbalance.sub(beforebalance)).to.be.lte(previewDeposit)
// In case of not satisfying min rate
minSharesPerToken = ethers.utils.parseUnits("1");
@ -146,11 +150,15 @@ describe("BASIC-D", function () {
});
it("should mint asset to ERC4626", async () => {
// const daiBalance = await daiContract.balanceOf(dsaWallet0.address);
// console.log("daiBalance :>> ", daiBalance);
const shares = ethers.utils.parseEther("1.03");
const beforeBalance = await daiContract.balanceOf(dsaWallet0.address);
console.log("token balance before :>> ", beforeBalance.toString());
const beforeSharebalance = await erc4626Contract.balanceOf(dsaWallet0.address);
console.log("share balance before :>> ", beforeSharebalance.toString());
const shares = ethers.utils.parseEther("1");
// Returns token amount for shares
const previewMint = await erc4626Contract.previewMint(shares);
console.log("previewMint :>> ", previewMint);
console.log("Token amount preview Mint :>> ", previewMint.toString());
let maxTokenPerShares = ethers.utils.parseUnits("1.1");
@ -158,13 +166,18 @@ describe("BASIC-D", function () {
{
connector: connectorName,
method: "mint",
args: [sDAIaddress, previewMint, maxTokenPerShares, 0, 0]
args: [sDAIaddress, shares, maxTokenPerShares, 0, 0]
}
];
let tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet0.address);
let receipt = await tx.wait();
const afterbalance = await daiContract.balanceOf(dsaWallet0.address);
console.log("token balance after :>> ", afterbalance.toString());
const afterSharebalance = await erc4626Contract.balanceOf(dsaWallet0.address);
console.log("share balance after :>> ", afterSharebalance.toString());
// In case of not satisfying max rate
maxTokenPerShares = ethers.utils.parseUnits("1");
@ -172,26 +185,26 @@ describe("BASIC-D", function () {
{
connector: connectorName,
method: "mint",
args: [sDAIaddress, previewMint, maxTokenPerShares, 0, 0]
args: [sDAIaddress, shares, maxTokenPerShares, 0, 0]
}
];
await expect(dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet0.address)).to.be.reverted;
});
it("should redeem asset to ERC4626", async () => {
// const shares = new BigNumber(1).toString()
// const balance = await erc4626Contract.balanceOf(dsaWallet0.address);
// console.log("balance :>> ", balance);
it("should Max redeem", async () => {
const balance = await erc4626Contract.balanceOf(dsaWallet0.address);
console.log("Share balance :>> ", balance.toString());
// Returns max Shares
const maxRedeem: BigNumber = await erc4626Contract.maxRedeem(dsaWallet0.address);
console.log("maxRedeem :>> ", maxRedeem);
console.log("maxRedeem :>> ", maxRedeem.toString());
const beforeUnderbalance = await daiContract.balanceOf(wallet0.address);
console.log("beforeUnderbalance :>> ", beforeUnderbalance);
const beforeUnderbalance = await daiContract.balanceOf(dsaWallet0.address);
console.log("beforeUnderbalance :>> ", beforeUnderbalance.toString());
const beforeVaultbalance = await erc4626Contract.balanceOf(wallet0.address);
console.log("beforeVaultbalance :>> ", beforeVaultbalance);
const beforeVaultbalance = await erc4626Contract.balanceOf(dsaWallet0.address);
console.log("beforeVaultbalance :>> ", beforeVaultbalance.toString());
let minTokenPerShares = ethers.utils.parseUnits("1.01");
@ -200,72 +213,101 @@ describe("BASIC-D", function () {
{
connector: connectorName,
method: "redeem",
args: [sDAIaddress, maxRedeem.div(2), minTokenPerShares, wallet0.address, 0, setId]
args: [sDAIaddress, ethers.constants.MaxUint256, minTokenPerShares, dsaWallet0.address, 0, setId]
}
];
let tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet0.address);
let receipt = await tx.wait();
const afterUnderbalance = await daiContract.balanceOf(wallet0.address);
console.log("afterUnderbalance :>> ", afterUnderbalance);
const afterUnderbalance = await daiContract.balanceOf(dsaWallet0.address);
console.log("afterUnderbalance :>> ", afterUnderbalance.toString());
const afterVaultbalance = await erc4626Contract.balanceOf(wallet0.address);
console.log("afterVaultbalance :>> ", afterVaultbalance);
const afterVaultbalance = await erc4626Contract.balanceOf(dsaWallet0.address);
console.log("afterVaultbalance :>> ", afterVaultbalance.toString());
});
it("should Revert for not satisfying min redeem rate", async () => {
const balance = await erc4626Contract.balanceOf(dsaWallet0.address);
console.log("Share balance :>> ", balance.toString());
let spells = [
{
connector: connectorName,
method: "deposit",
args: [sDAIaddress, ethers.utils.parseEther("1"), ethers.utils.parseUnits("0.95"), 0, 0]
}
];
let tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet0.address);
let receipt = await tx.wait();
// Returns max Shares
const maxRedeem: BigNumber = await erc4626Contract.maxRedeem(dsaWallet0.address);
console.log("maxRedeem :>> ", maxRedeem.toString());
const beforeUnderbalance = await daiContract.balanceOf(dsaWallet0.address);
console.log("beforeUnderbalance :>> ", beforeUnderbalance.toString());
const beforeVaultbalance = await erc4626Contract.balanceOf(dsaWallet0.address);
console.log("beforeVaultbalance :>> ", beforeVaultbalance.toString());
expect(beforeVaultbalance).to.be.gte("950000000000000000")
// In case of not satisfying min rate
minTokenPerShares = ethers.utils.parseUnits("1.2");
let minTokenPerShares = ethers.utils.parseUnits("1.5");
spells = [
{
connector: connectorName,
method: "redeem",
args: [sDAIaddress, maxRedeem.div(2), minTokenPerShares, wallet0.address, 0, setId]
args: [sDAIaddress, ethers.constants.MaxUint256, minTokenPerShares, dsaWallet0.address, 0, 0]
}
];
await expect(dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet0.address)).to.be.reverted;
});
it("should withdraw asset to ERC4626", async () => {
const maxWithdraw: BigNumber = await erc4626Contract.maxWithdraw(dsaWallet0.address);
console.log("maxWithdraw :>> ", maxWithdraw);
console.log("maxWithdraw :>> ", maxWithdraw.toString());
const beforeUnderbalance = await daiContract.balanceOf(wallet0.address);
console.log("beforeUnderbalance :>> ", beforeUnderbalance);
const beforeUnderbalance = await daiContract.balanceOf(dsaWallet0.address);
console.log("beforeUnderbalance :>> ", beforeUnderbalance.toString());
const beforeVaultbalance = await erc4626Contract.balanceOf(wallet0.address);
console.log("beforeVaultbalance :>> ", beforeVaultbalance);
const beforeVaultbalance = await erc4626Contract.balanceOf(dsaWallet0.address);
console.log("beforeVaultbalance :>> ", beforeVaultbalance.toString());
let maxSharesPerToken = ethers.utils.parseUnits("0.95");
let maxSharesPerToken = ethers.utils.parseUnits("0.975");
const setId = "83478237";
let spells = [
{
connector: connectorName,
method: "withdraw",
args: [sDAIaddress, maxWithdraw, maxSharesPerToken, wallet0.address, 0, setId]
args: [sDAIaddress, maxWithdraw, maxSharesPerToken, dsaWallet0.address, 0, setId]
}
];
let tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet0.address);
let receipt = await tx.wait();
const afterUnderbalance = await daiContract.balanceOf(wallet0.address);
console.log("afterUnderbalance :>> ", afterUnderbalance);
const afterUnderbalance = await daiContract.balanceOf(dsaWallet0.address);
console.log("afterUnderbalance :>> ", afterUnderbalance.toString());
const afterVaultbalance = await erc4626Contract.balanceOf(wallet0.address);
console.log("afterVaultbalance :>> ", afterVaultbalance);
const afterVaultbalance = await erc4626Contract.balanceOf(dsaWallet0.address);
console.log("afterVaultbalance :>> ", afterVaultbalance.toString());
// In case of not satisfying min rate
maxSharesPerToken = ethers.utils.parseUnits("1");
maxSharesPerToken = ethers.utils.parseUnits("0.95");
spells = [
{
connector: connectorName,
method: "withdraw",
args: [sDAIaddress, maxWithdraw, maxSharesPerToken, wallet0.address, 0, setId]
args: [sDAIaddress, maxWithdraw, maxSharesPerToken, dsaWallet0.address, 0, setId]
}
];