Skip to content

Commit

Permalink
feat: fix tests & add another one
Browse files Browse the repository at this point in the history
  • Loading branch information
sakulstra committed Mar 22, 2023
1 parent 51d876e commit b252276
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions test-suites/ltv-validation.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,40 @@ makeSuite('LTV validation', (testEnv: TestEnv) => {
expect(userData.totalDebtBase).to.be.eq(0);
});

it('User 1 deposit dai as collateral, ltv drops to 0, tries to enable as collateral (nothing should happen)', async () => {
await evmRevert(snap);
const {
pool,
dai,
users: [user1],
configurator,
helpersContract,
} = testEnv;

const daiAmount = await convertToCurrencyDecimals(dai.address, '10');

await dai.connect(user1.signer).approve(pool.address, MAX_UINT_AMOUNT);

await dai.connect(user1.signer)['mint(uint256)'](daiAmount);

await pool.connect(user1.signer).supply(dai.address, daiAmount, user1.address, 0);

// Set DAI LTV = 0
expect(await configurator.configureReserveAsCollateral(dai.address, 0, 8000, 10500))
.to.emit(configurator, 'CollateralConfigurationChanged')
.withArgs(dai.address, 0, 8000, 10500);
const ltv = (await helpersContract.getReserveConfigurationData(dai.address)).ltv;
expect(ltv).to.be.equal(0);

const userDataBefore = await helpersContract.getUserReserveData(dai.address, user1.address);
expect(userDataBefore.usageAsCollateralEnabled).to.be.eq(true);

await pool.connect(user1.signer).setUserUseReserveAsCollateral(dai.address, true);

const userDataAfter = await helpersContract.getUserReserveData(dai.address, user1.address);
expect(userDataAfter.usageAsCollateralEnabled).to.be.eq(true);
});

it('User 1 deposit zero ltv dai, tries to enable as collateral (revert expected)', async () => {
await evmRevert(snap);
const {
Expand All @@ -158,6 +192,9 @@ makeSuite('LTV validation', (testEnv: TestEnv) => {
helpersContract,
} = testEnv;

// Clean user's state by withdrawing all aDAI
await pool.connect(user1.signer).withdraw(dai.address, MAX_UINT_AMOUNT, user1.address);

// Set DAI LTV = 0
expect(await configurator.configureReserveAsCollateral(dai.address, 0, 8000, 10500))
.to.emit(configurator, 'CollateralConfigurationChanged')
Expand Down

0 comments on commit b252276

Please sign in to comment.