mirror of
https://github.com/Instadapp/aave-protocol-v2.git
synced 2024-07-29 21:47:30 +00:00
add tests on liquiditySwap validation logic
This commit is contained in:
parent
214c51f365
commit
1b61edc6ff
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"MintableERC20": {
|
||||
"buidlerevm": {
|
||||
"address": "0x2D8553F9ddA85A9B3259F6Bf26911364B85556F5",
|
||||
"address": "0x58F132FBB86E21545A4Bace3C19f1C05d86d7A22",
|
||||
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
|
||||
},
|
||||
"localhost": {
|
||||
|
|
|
@ -67,6 +67,7 @@ export enum ProtocolErrors {
|
|||
NO_VARIABLE_RATE_LOAN_IN_RESERVE = '18', // 'User does not have a variable rate loan in progress on this reserve'
|
||||
UNDERLYING_BALANCE_NOT_GREATER_THAN_0 = '19', // 'The underlying balance needs to be greater than 0'
|
||||
DEPOSIT_ALREADY_IN_USE = '20', // 'User deposit is already being used as collateral'
|
||||
INVALID_EQUAL_ASSETS_TO_SWAP = '56', // User can't use same reserve as destination of liquidity swap
|
||||
|
||||
// require error messages - LendingPool
|
||||
NOT_ENOUGH_STABLE_BORROW_BALANCE = '21', // 'User does not have any stable rate loan for this reserve'
|
||||
|
|
|
@ -13,12 +13,63 @@ const {expect} = require('chai');
|
|||
|
||||
makeSuite('LendingPool SwapDeposit function', (testEnv: TestEnv) => {
|
||||
let _mockSwapAdapter = {} as MockSwapAdapter;
|
||||
const {HEALTH_FACTOR_LOWER_THAN_LIQUIDATION_THRESHOLD} = ProtocolErrors;
|
||||
const {
|
||||
HEALTH_FACTOR_LOWER_THAN_LIQUIDATION_THRESHOLD,
|
||||
NO_UNFREEZED_RESERVE,
|
||||
NO_ACTIVE_RESERVE,
|
||||
INVALID_EQUAL_ASSETS_TO_SWAP,
|
||||
} = ProtocolErrors;
|
||||
|
||||
before(async () => {
|
||||
_mockSwapAdapter = await getMockSwapAdapter();
|
||||
});
|
||||
|
||||
it('Should not allow to swap if from equal to', async () => {
|
||||
const {pool, weth} = testEnv;
|
||||
|
||||
await expect(
|
||||
pool.swapLiquidity(
|
||||
_mockSwapAdapter.address,
|
||||
weth.address,
|
||||
weth.address,
|
||||
'1'.toString(),
|
||||
'0x10'
|
||||
)
|
||||
).to.be.revertedWith(INVALID_EQUAL_ASSETS_TO_SWAP);
|
||||
});
|
||||
|
||||
it('Should not allow to swap if from or to reserves are not active', async () => {
|
||||
const {pool, weth, dai, configurator} = testEnv;
|
||||
|
||||
await configurator.deactivateReserve(weth.address);
|
||||
|
||||
await expect(
|
||||
pool.swapLiquidity(
|
||||
_mockSwapAdapter.address,
|
||||
weth.address,
|
||||
dai.address,
|
||||
'1'.toString(),
|
||||
'0x10'
|
||||
)
|
||||
).to.be.revertedWith(NO_ACTIVE_RESERVE);
|
||||
await configurator.activateReserve(weth.address);
|
||||
|
||||
await configurator.deactivateReserve(dai.address);
|
||||
|
||||
await expect(
|
||||
pool.swapLiquidity(
|
||||
_mockSwapAdapter.address,
|
||||
weth.address,
|
||||
dai.address,
|
||||
'1'.toString(),
|
||||
'0x10'
|
||||
)
|
||||
).to.be.revertedWith(NO_ACTIVE_RESERVE);
|
||||
|
||||
//cleanup state
|
||||
await configurator.activateReserve(dai.address);
|
||||
});
|
||||
|
||||
it('Deposits WETH into the reserve', async () => {
|
||||
const {pool, weth, users} = testEnv;
|
||||
const amountToDeposit = ethers.utils.parseEther('1');
|
||||
|
@ -151,7 +202,7 @@ makeSuite('LendingPool SwapDeposit function', (testEnv: TestEnv) => {
|
|||
});
|
||||
|
||||
it('Should set usage as collateral to false if no leftovers after swap', async () => {
|
||||
const {pool, weth, dai, aEth, users} = testEnv;
|
||||
const {pool, weth, dai, users} = testEnv;
|
||||
const userAddress = await pool.signer.getAddress();
|
||||
|
||||
// add more liquidity to allow user 0 to swap everything he has
|
||||
|
@ -195,4 +246,22 @@ makeSuite('LendingPool SwapDeposit function', (testEnv: TestEnv) => {
|
|||
'usageAsCollateralEnabled are not set to false'
|
||||
);
|
||||
});
|
||||
it('Should not allow to swap if to reserve are freezed', async () => {
|
||||
const {pool, weth, dai, configurator} = testEnv;
|
||||
|
||||
await configurator.freezeReserve(dai.address);
|
||||
|
||||
await expect(
|
||||
pool.swapLiquidity(
|
||||
_mockSwapAdapter.address,
|
||||
weth.address,
|
||||
dai.address,
|
||||
'1'.toString(),
|
||||
'0x10'
|
||||
)
|
||||
).to.be.revertedWith(NO_UNFREEZED_RESERVE);
|
||||
|
||||
//cleanup state
|
||||
await configurator.unfreezeReserve(dai.address);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue
Block a user