Skip to content

Commit

Permalink
Updates to test (#146)
Browse files Browse the repository at this point in the history
* remove test filter on FlashMintLeveraged.

* chore: update current block

* test: updates to deployment of leverage module.

* Fix failing tests for AaveV3LeverageStrategyExtension (#147)

* Fix failing tests

* Adjust test message for ripcord test

---------

Co-authored-by: christn <[email protected]>
  • Loading branch information
snake-poison and ckoopmann authored Aug 14, 2023
1 parent 998fd21 commit 8ef6b7b
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 42 deletions.
81 changes: 41 additions & 40 deletions test/integration/ethereum/aaveV3LeverageStrategyExtension.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ import {
AaveV3LeverageModule,
AaveV3LeverageStrategyExtension,
ContractCallerMock,
Controller,
Controller__factory,
IAaveOracle,
IAaveOracle__factory,
IPoolConfigurator,
Expand All @@ -41,6 +39,7 @@ import {
IPool,
IPool__factory,
TradeAdapterMock,
AaveV3LeverageModule__factory,
} from "../../../typechain";
import DeployHelper from "@utils/deploys";
import {
Expand Down Expand Up @@ -84,6 +83,7 @@ const contractAddresses = {
interestRateStrategy: "0x76884cAFeCf1f7d4146DA6C4053B18B76bf6ED14",
aaveTreasury: "0x464C71f6c2F760DdA6093dCB91C24c39e5d6e18c",
aaveIncentivesController: "0x8164Cc65827dcFe994AB23944CBC90e0aa80bFcb",
aaveV3LeverageModule: "0x9d08CCeD85A68Bf8A19374ED4B5753aE3Be9F74f",
};

const tokenAddresses = {
Expand Down Expand Up @@ -112,14 +112,13 @@ const whales = {
};

if (process.env.INTEGRATIONTEST) {
describe("AaveV3LeverageStrategyExtension", () => {
describe.only("AaveV3LeverageStrategyExtension", () => {
let owner: Account;
let nonOwner: Account;
let methodologist: Account;

let deployer: DeployHelper;
let setToken: SetToken;
let controller: Controller;
let aaveLeverageModule: AaveV3LeverageModule;
let lendingPoolConfigurator: IPoolConfigurator;
let lendingPool: IPool;
Expand Down Expand Up @@ -163,18 +162,19 @@ if (process.env.INTEGRATIONTEST) {

lendingPool = IPool__factory.connect(contractAddresses.aaveV3Pool, owner.wallet);

// Deploy Aave leverage module and add to controller
aaveLeverageModule = await deployer.setV2.deployAaveV3LeverageModule(
contractAddresses.controller,
contractAddresses.aaveV3AddressProvider,
);
aaveLeverageModule = AaveV3LeverageModule__factory.connect(contractAddresses.aaveV3LeverageModule, owner.wallet);

manager = owner.address;
weth = IERC20__factory.connect(tokenAddresses.weth, owner.wallet);
await weth
.connect(await impersonateAccount(whales.weth))
.transfer(owner.address, await weth.balanceOf(whales.weth).then(b => b.div(10)));
wsteth = IERC20__factory.connect(tokenAddresses.wsteth, owner.wallet);
// whale needs eth for the transfer.
await network.provider.send("hardhat_setBalance", [
whales.wsteth,
ether(10).toHexString(),
]);
await wsteth
.connect(await impersonateAccount(whales.wsteth))
.transfer(owner.address, await wsteth.balanceOf(whales.wsteth).then(b => b.div(10)));
Expand All @@ -193,13 +193,6 @@ if (process.env.INTEGRATIONTEST) {
owner.wallet,
);

controller = Controller__factory.connect(contractAddresses.controller, owner.wallet);
const controllerOwner = await controller.owner();
const controllerOwnerSigner = await impersonateAccount(controllerOwner);
controller = controller.connect(controllerOwnerSigner);

await controller.addModule(aaveLeverageModule.address);

integrationRegistry = IntegrationRegistry__factory.connect(
contractAddresses.integrationRegistry,
owner.wallet,
Expand All @@ -209,19 +202,22 @@ if (process.env.INTEGRATIONTEST) {
await impersonateAccount(integrationRegistryOwner),
);

const replaceRegistry = async (integrationModuleAddress: string, name: string, adapterAddress: string) => {
const currentAdapterAddress = await integrationRegistry.getIntegrationAdapter(integrationModuleAddress, name);
if (!ethers.utils.isAddress(adapterAddress)) {
throw new Error("Invalid address: " + adapterAddress + " for " + name + " adapter");
}
if (ethers.utils.isAddress(currentAdapterAddress) && currentAdapterAddress != ADDRESS_ZERO) {
await integrationRegistry.editIntegration(integrationModuleAddress, name, adapterAddress);
} else {
await integrationRegistry.addIntegration(integrationModuleAddress, name, adapterAddress);
}
};
tradeAdapterMock = await deployer.mocks.deployTradeAdapterMock();
await integrationRegistry.addIntegration(
aaveLeverageModule.address,
exchangeName,
tradeAdapterMock.address,
);
replaceRegistry(aaveLeverageModule.address, exchangeName, tradeAdapterMock.address);
// Deploy mock trade adapter 2
tradeAdapterMock2 = await deployer.mocks.deployTradeAdapterMock();
await integrationRegistry.addIntegration(
aaveLeverageModule.address,
exchangeName2,
tradeAdapterMock2.address,
);
replaceRegistry(aaveLeverageModule.address, exchangeName2, tradeAdapterMock2.address);

setTokenCreator = SetTokenCreator__factory.connect(
contractAddresses.setTokenCreator,
Expand Down Expand Up @@ -250,16 +246,8 @@ if (process.env.INTEGRATIONTEST) {
owner.wallet,
);

await integrationRegistry.addIntegration(
aaveLeverageModule.address,
"DefaultIssuanceModule",
debtIssuanceModule.address,
);
await integrationRegistry.addIntegration(
debtIssuanceModule.address,
"AaveLeverageModuleV3",
aaveLeverageModule.address,
);
replaceRegistry(aaveLeverageModule.address, "DefaultIssuanceModule", debtIssuanceModule.address);
replaceRegistry(debtIssuanceModule.address, "AaveLeverageModuleV3", aaveLeverageModule.address);

// Deploy Chainlink mocks
chainlinkCollateralPriceMock = await deployer.mocks.deployChainlinkAggregatorMock();
Expand Down Expand Up @@ -298,8 +286,13 @@ if (process.env.INTEGRATIONTEST) {
[ether(1)],
[debtIssuanceModule.address, aaveLeverageModule.address],
);
await aaveLeverageModule.updateAnySetAllowed(true);

const ownerofLeveverageModule = await aaveLeverageModule.owner();
if (ownerofLeveverageModule != owner.address) {
await aaveLeverageModule.connect(await impersonateAccount(ownerofLeveverageModule)).updateAnySetAllowed(true);
}
else {
await aaveLeverageModule.updateAnySetAllowed(true);
}
// Initialize modules
await debtIssuanceModule.initialize(
setToken.address,
Expand Down Expand Up @@ -1169,7 +1162,7 @@ if (process.env.INTEGRATIONTEST) {
context("when methodology settings are increased beyond default maximum", () => {
let newMethodology: MethodologySettings;
let newIncentive: IncentiveSettings;
const leverageCutoff = ether(2.2); // Value of leverage that can only be exceeded with eMode activated
const leverageCutoff = ether(2.21); // Value of leverage that can only be exceeded with eMode activated
beforeEach(() => {
subjectCaller = owner;
});
Expand Down Expand Up @@ -1965,7 +1958,7 @@ if (process.env.INTEGRATIONTEST) {
.rebalance(subjectExchangeToUse);
}

describe("when leverage ratio is above max and it drops further between rebalances", async () => {
describe("when leverage ratio is above max and rises further between rebalances", async () => {
it("should set the global and exchange timestamps correctly", async () => {
await subject();
const timestamp1 = await getLastBlockTimestamp();
Expand Down Expand Up @@ -3541,6 +3534,14 @@ if (process.env.INTEGRATIONTEST) {
await chainlinkCollateralPriceMock.setPrice(initialCollateralPrice);

subjectCaller = owner;

const oldExecution = await leverageStrategyExtension.getExecution();
const newExecution: ExecutionSettings = {
unutilizedLeveragePercentage: oldExecution.unutilizedLeveragePercentage,
twapCooldownPeriod: oldExecution.twapCooldownPeriod,
slippageTolerance: ether(0.05),
};
await leverageStrategyExtension.setExecutionSettings(newExecution);
});

async function subject(): Promise<any> {
Expand Down
2 changes: 1 addition & 1 deletion test/integration/ethereum/flashMintLeveraged.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ type SwapData = {
};

if (process.env.INTEGRATIONTEST) {
describe.only("FlashMintLeveraged - Integration Test", async () => {
describe("FlashMintLeveraged - Integration Test", async () => {
const addresses = process.env.USE_STAGING_ADDRESSES ? STAGING_ADDRESSES : PRODUCTION_ADDRESSES;
let owner: Account;
let deployer: DeployHelper;
Expand Down
2 changes: 1 addition & 1 deletion utils/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const optimismForkingConfig = {

export const mainnetForkingConfig = {
url: "https://eth-mainnet.alchemyapi.io/v2/" + process.env.ALCHEMY_TOKEN,
blockNumber: process.env.LATESTBLOCK ? undefined : 17150000,
blockNumber: process.env.LATESTBLOCK ? undefined : 17895372,
};

export const forkingConfig =
Expand Down

0 comments on commit 8ef6b7b

Please sign in to comment.