Skip to content

Commit

Permalink
✅ modify test
Browse files Browse the repository at this point in the history
  • Loading branch information
zakrad committed Sep 28, 2023
1 parent d1cb9cf commit 08e66b5
Showing 1 changed file with 130 additions and 16 deletions.
146 changes: 130 additions & 16 deletions defi-strategies/test/AaveV2.Module.specs.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { expect } from "chai";
import { Contract } from "ethers";
import { decodeError } from "ethers-decode-error";
import hardhat, { ethers, deployments, waffle } from "hardhat";
import { buildEcdsaModuleAuthorizedStrategyTx } from "./utils/execution";
import { makeEcdsaModuleUserOp } from "./utils/userOp";
Expand Down Expand Up @@ -38,10 +39,25 @@ describe("Strategy Module", async () => {
let lendingPool: Contract;
let providerAddress: any;

Check warning on line 40 in defi-strategies/test/AaveV2.Module.specs.ts

View workflow job for this annotation

GitHub Actions / Lint sources (18.x)

Unexpected any. Specify a different type

Check warning on line 40 in defi-strategies/test/AaveV2.Module.specs.ts

View workflow job for this annotation

GitHub Actions / Lint sources (18.x)

Unexpected any. Specify a different type
let wethProviderAddress: any;

Check warning on line 41 in defi-strategies/test/AaveV2.Module.specs.ts

View workflow job for this annotation

GitHub Actions / Lint sources (18.x)

Unexpected any. Specify a different type

Check warning on line 41 in defi-strategies/test/AaveV2.Module.specs.ts

View workflow job for this annotation

GitHub Actions / Lint sources (18.x)

Unexpected any. Specify a different type
let fee: any;

Check warning on line 42 in defi-strategies/test/AaveV2.Module.specs.ts

View workflow job for this annotation

GitHub Actions / Lint sources (18.x)

Unexpected any. Specify a different type

Check warning on line 42 in defi-strategies/test/AaveV2.Module.specs.ts

View workflow job for this annotation

GitHub Actions / Lint sources (18.x)

Unexpected any. Specify a different type

const setupTests = deployments.createFixture(async ({ deployments }) => {
await deployments.fixture();

const errAbi = [
{
inputs: [
{
internalType: "uint256",
name: "",
type: "uint256",
},
],
name: "RevertEstimation",
type: "error",
},
];

provider = await ethers.getContractAt(
"ILendingPoolAddressesProviderV2",
AAVEPROTOCOL_V2_PROVIDER
Expand Down Expand Up @@ -121,6 +137,7 @@ describe("Strategy Module", async () => {
return {
ecdsaModule: ecdsaModule,
userSA: userSA,
errAbi: errAbi,
};
});

Expand All @@ -131,7 +148,7 @@ describe("Strategy Module", async () => {

describe("Deposit", function () {
it("deposit ETH normal", async function () {
const { userSA, ecdsaModule } = await setupTests();
const { userSA, ecdsaModule, errAbi } = await setupTests();
const value = ethers.utils.parseEther("1");
const handler = aaveV2handler.address;
const data = (
Expand All @@ -153,7 +170,19 @@ describe("Strategy Module", async () => {
userSA.address
);

await strategyModule.execStrategy(userSA.address, transaction, signature);
try {
await strategyModule.requiredTxFee(userSA.address, transaction);
} catch (error) {
fee = decodeError(error, errAbi).args;
fee = fee[0];
}

await strategyModule.execStrategy(
userSA.address,
transaction,
signature,
{ value: fee }
);

const afterExecBalance = await waffle.provider.getBalance(userSA.address);

Expand All @@ -169,7 +198,7 @@ describe("Strategy Module", async () => {
});

it("deposit ETH max amount", async function () {
const { userSA, ecdsaModule } = await setupTests();
const { userSA, ecdsaModule, errAbi } = await setupTests();
const value = ethers.utils.parseEther("1");
const handler = aaveV2handler.address;
const data = (
Expand All @@ -187,10 +216,22 @@ describe("Strategy Module", async () => {
value.toString()
);

try {
await strategyModule.requiredTxFee(userSA.address, transaction);
} catch (error) {
fee = decodeError(error, errAbi).args;
fee = fee[0];
}

const beforeExecBalance = await waffle.provider.getBalance(
userSA.address
);
await strategyModule.execStrategy(userSA.address, transaction, signature);
await strategyModule.execStrategy(
userSA.address,
transaction,
signature,
{ value: fee }
);

const afterExecBalance = await waffle.provider.getBalance(userSA.address);

Expand All @@ -210,7 +251,7 @@ describe("Strategy Module", async () => {
});

it("deposit token normal", async function () {
const { userSA, ecdsaModule } = await setupTests();
const { userSA, ecdsaModule, errAbi } = await setupTests();
const value = ethers.utils.parseEther("1");
const handler = aaveV2handler.address;

Expand All @@ -234,9 +275,21 @@ describe("Strategy Module", async () => {
0
);

try {
await strategyModule.requiredTxFee(userSA.address, transaction);
} catch (error) {
fee = decodeError(error, errAbi).args;
fee = fee[0];
}

const beforeExecBalance = await token.balanceOf(userSA.address);

await strategyModule.execStrategy(userSA.address, transaction, signature);
await strategyModule.execStrategy(
userSA.address,
transaction,
signature,
{ value: fee }
);

const afterExecBalance = await token.balanceOf(userSA.address);

Expand All @@ -250,7 +303,7 @@ describe("Strategy Module", async () => {
});

it("deposit token max amount", async function () {
const { userSA, ecdsaModule } = await setupTests();
const { userSA, ecdsaModule, errAbi } = await setupTests();
const value = ethers.utils.parseEther("10");
const handler = aaveV2handler.address;

Expand All @@ -274,9 +327,21 @@ describe("Strategy Module", async () => {
0
);

try {
await strategyModule.requiredTxFee(userSA.address, transaction);
} catch (error) {
fee = decodeError(error, errAbi).args;
fee = fee[0];
}

const beforeExecBalance = await token.balanceOf(userSA.address);

await strategyModule.execStrategy(userSA.address, transaction, signature);
await strategyModule.execStrategy(
userSA.address,
transaction,
signature,
{ value: fee }
);

const afterExecBalance = await token.balanceOf(userSA.address);

Expand All @@ -294,7 +359,7 @@ describe("Strategy Module", async () => {
let depositAmount = ethers.utils.parseEther("5");

it("withdraw ETH partial", async function () {
const { userSA, ecdsaModule } = await setupTests();
const { userSA, ecdsaModule, errAbi } = await setupTests();
await WrappedETH.connect(wethProviderAddress).approve(
lendingPool.address,
depositAmount
Expand Down Expand Up @@ -323,11 +388,23 @@ describe("Strategy Module", async () => {
0
);

try {
await strategyModule.requiredTxFee(userSA.address, transaction);
} catch (error) {
fee = decodeError(error, errAbi).args;
fee = fee[0];
}

const beforeExecBalance = await AWrappedETH.balanceOf(userSA.address);

const beforeExecETH = await waffle.provider.getBalance(userSA.address);

await strategyModule.execStrategy(userSA.address, transaction, signature);
await strategyModule.execStrategy(
userSA.address,
transaction,
signature,
{ value: fee }
);

const afterExecBalance = await AWrappedETH.balanceOf(userSA.address);

Expand All @@ -347,7 +424,7 @@ describe("Strategy Module", async () => {
});

it("withdraw ETH max amount", async function () {
const { userSA, ecdsaModule } = await setupTests();
const { userSA, ecdsaModule, errAbi } = await setupTests();
await WrappedETH.connect(wethProviderAddress).approve(
lendingPool.address,
depositAmount
Expand Down Expand Up @@ -379,7 +456,19 @@ describe("Strategy Module", async () => {

const beforeExecETH = await waffle.provider.getBalance(userSA.address);

await strategyModule.execStrategy(userSA.address, transaction, signature);
try {
await strategyModule.requiredTxFee(userSA.address, transaction);
} catch (error) {
fee = decodeError(error, errAbi).args;
fee = fee[0];
}

await strategyModule.execStrategy(
userSA.address,
transaction,
signature,
{ value: fee }
);

const afterExecBalance = await AWrappedETH.balanceOf(userSA.address);

Expand All @@ -399,7 +488,7 @@ describe("Strategy Module", async () => {
});

it("withdraw token partial", async function () {
const { userSA, ecdsaModule } = await setupTests();
const { userSA, ecdsaModule, errAbi } = await setupTests();
await token
.connect(providerAddress)
.approve(lendingPool.address, depositAmount);
Expand Down Expand Up @@ -430,10 +519,22 @@ describe("Strategy Module", async () => {
0
);

try {
await strategyModule.requiredTxFee(userSA.address, transaction);
} catch (error) {
fee = decodeError(error, errAbi).args;
fee = fee[0];
}

const beforeExecBalance = await aToken.balanceOf(userSA.address);
const beforeExecToken = await token.balanceOf(userSA.address);

await strategyModule.execStrategy(userSA.address, transaction, signature);
await strategyModule.execStrategy(
userSA.address,
transaction,
signature,
{ value: fee }
);

const afterExecBalance = await aToken.balanceOf(userSA.address);

Expand All @@ -451,10 +552,11 @@ describe("Strategy Module", async () => {
});

it("withdraw token max amount", async function () {
const { userSA, ecdsaModule } = await setupTests();
const { userSA, ecdsaModule, errAbi } = await setupTests();
await token
.connect(providerAddress)
.approve(lendingPool.address, depositAmount);

await lendingPool
.connect(providerAddress)
.deposit(token.address, depositAmount, userSA.address, 0);
Expand Down Expand Up @@ -485,7 +587,19 @@ describe("Strategy Module", async () => {

const beforeExecToken = await token.balanceOf(userSA.address);

await strategyModule.execStrategy(userSA.address, transaction, signature);
try {
await strategyModule.requiredTxFee(userSA.address, transaction);
} catch (error) {
fee = decodeError(error, errAbi).args;
fee = fee[0];
}

await strategyModule.execStrategy(
userSA.address,
transaction,
signature,
{ value: fee }
);

const afterExecBalance = await aToken.balanceOf(userSA.address);

Expand Down

0 comments on commit 08e66b5

Please sign in to comment.