Added test fixes to support latest stable fix

This commit is contained in:
David Racero 2021-01-21 00:42:39 +01:00
parent a72b73d804
commit c7a8f41d46
8 changed files with 194 additions and 190 deletions

View File

@ -13,7 +13,7 @@
"compile": "SKIP_LOAD=true hardhat compile", "compile": "SKIP_LOAD=true hardhat compile",
"console:fork": "MAINNET_FORK=true hardhat console", "console:fork": "MAINNET_FORK=true hardhat console",
"test": "TS_NODE_TRANSPILE_ONLY=1 hardhat test ./test/*.spec.ts", "test": "TS_NODE_TRANSPILE_ONLY=1 hardhat test ./test/*.spec.ts",
"test-scenarios": "npm run test -- test/__setup.spec.ts test/scenario.spec.ts", "test-scenarios": "npx hardhat test test/__setup.spec.ts test/scenario.spec.ts",
"test-repay-with-collateral": "hardhat test test/__setup.spec.ts test/repay-with-collateral.spec.ts", "test-repay-with-collateral": "hardhat test test/__setup.spec.ts test/repay-with-collateral.spec.ts",
"test-liquidate-with-collateral": "hardhat test test/__setup.spec.ts test/flash-liquidation-with-collateral.spec.ts", "test-liquidate-with-collateral": "hardhat test test/__setup.spec.ts test/flash-liquidation-with-collateral.spec.ts",
"test-liquidate-underlying": "hardhat test test/__setup.spec.ts test/liquidation-underlying.spec.ts", "test-liquidate-underlying": "hardhat test test/__setup.spec.ts test/liquidation-underlying.spec.ts",

View File

@ -208,6 +208,15 @@
}, },
"expected": "revert", "expected": "revert",
"revertMessage": "The collateral balance is 0" "revertMessage": "The collateral balance is 0"
},
{
"name": "withdraw",
"args": {
"reserve": "DAI",
"amount": "1000",
"user": "1"
},
"expected": "success"
} }
] ]
}, },

View File

@ -10,7 +10,7 @@
"args": { "args": {
"reserve": "WETH", "reserve": "WETH",
"amount": "1000", "amount": "1000",
"user": "0" "user": "3"
}, },
"expected": "success" "expected": "success"
}, },
@ -18,7 +18,7 @@
"name": "approve", "name": "approve",
"args": { "args": {
"reserve": "WETH", "reserve": "WETH",
"user": "0" "user": "3"
}, },
"expected": "success" "expected": "success"
}, },
@ -27,6 +27,32 @@
"args": { "args": {
"reserve": "WETH", "reserve": "WETH",
"amount": "1000", "amount": "1000",
"user": "3"
},
"expected": "success"
},
{
"name": "mint",
"args": {
"reserve": "DAI",
"amount": "1000",
"user": "0"
},
"expected": "success"
},
{
"name": "approve",
"args": {
"reserve": "DAI",
"user": "0"
},
"expected": "success"
},
{
"name": "deposit",
"args": {
"reserve": "DAI",
"amount": "1000",
"user": "0" "user": "0"
}, },
"expected": "success" "expected": "success"

View File

@ -8,7 +8,7 @@
{ {
"name": "rebalanceStableBorrowRate", "name": "rebalanceStableBorrowRate",
"args": { "args": {
"reserve": "DAI", "reserve": "USDC",
"user": "0", "user": "0",
"target": "1", "target": "1",
"borrowRateMode": "variable" "borrowRateMode": "variable"
@ -19,12 +19,12 @@
] ]
}, },
{ {
"description": "User 0 deposits 1000 DAI, user 1 deposits 5 ETH, borrows 600 DAI at a variable rate, user 0 rebalances user 1 (revert expected)", "description": "User 0 deposits 1000 USDC, user 1 deposits 5 ETH, borrows 600 DAI at a variable rate, user 0 rebalances user 1 (revert expected)",
"actions": [ "actions": [
{ {
"name": "mint", "name": "mint",
"args": { "args": {
"reserve": "DAI", "reserve": "USDC",
"amount": "1000", "amount": "1000",
"user": "0" "user": "0"
}, },
@ -33,7 +33,7 @@
{ {
"name": "approve", "name": "approve",
"args": { "args": {
"reserve": "DAI", "reserve": "USDC",
"user": "0" "user": "0"
}, },
"expected": "success" "expected": "success"
@ -41,7 +41,7 @@
{ {
"name": "deposit", "name": "deposit",
"args": { "args": {
"reserve": "DAI", "reserve": "USDC",
"amount": "1000", "amount": "1000",
"user": "0" "user": "0"
}, },
@ -51,7 +51,7 @@
"name": "mint", "name": "mint",
"args": { "args": {
"reserve": "WETH", "reserve": "WETH",
"amount": "5", "amount": "7",
"user": "1" "user": "1"
}, },
"expected": "success" "expected": "success"
@ -69,7 +69,7 @@
"args": { "args": {
"reserve": "WETH", "reserve": "WETH",
"amount": "5", "amount": "7",
"user": "1" "user": "1"
}, },
"expected": "success" "expected": "success"
@ -77,18 +77,17 @@
{ {
"name": "borrow", "name": "borrow",
"args": { "args": {
"reserve": "DAI", "reserve": "USDC",
"amount": "250", "amount": "250",
"borrowRateMode": "stable", "borrowRateMode": "stable",
"user": "1", "user": "1"
"timeTravel": "365"
}, },
"expected": "success" "expected": "success"
}, },
{ {
"name": "rebalanceStableBorrowRate", "name": "rebalanceStableBorrowRate",
"args": { "args": {
"reserve": "DAI", "reserve": "USDC",
"user": "0", "user": "0",
"target": "1" "target": "1"
}, },
@ -103,18 +102,17 @@
{ {
"name": "borrow", "name": "borrow",
"args": { "args": {
"reserve": "DAI", "reserve": "USDC",
"amount": "200", "amount": "200",
"borrowRateMode": "stable", "borrowRateMode": "variable",
"user": "1", "user": "1"
"timeTravel": "365"
}, },
"expected": "success" "expected": "success"
}, },
{ {
"name": "rebalanceStableBorrowRate", "name": "rebalanceStableBorrowRate",
"args": { "args": {
"reserve": "DAI", "reserve": "USDC",
"user": "0", "user": "0",
"target": "1" "target": "1"
}, },
@ -129,18 +127,17 @@
{ {
"name": "borrow", "name": "borrow",
"args": { "args": {
"reserve": "DAI", "reserve": "USDC",
"amount": "200", "amount": "200",
"borrowRateMode": "stable", "borrowRateMode": "variable",
"user": "1", "user": "1"
"timeTravel": "365"
}, },
"expected": "success" "expected": "success"
}, },
{ {
"name": "rebalanceStableBorrowRate", "name": "rebalanceStableBorrowRate",
"args": { "args": {
"reserve": "DAI", "reserve": "USDC",
"user": "0", "user": "0",
"target": "1" "target": "1"
}, },
@ -155,18 +152,17 @@
{ {
"name": "borrow", "name": "borrow",
"args": { "args": {
"reserve": "DAI", "reserve": "USDC",
"amount": "100", "amount": "280",
"borrowRateMode": "stable", "borrowRateMode": "variable",
"user": "1", "user": "1"
"timeTravel": "365"
}, },
"expected": "success" "expected": "success"
}, },
{ {
"name": "rebalanceStableBorrowRate", "name": "rebalanceStableBorrowRate",
"args": { "args": {
"reserve": "DAI", "reserve": "USDC",
"user": "0", "user": "0",
"target": "1" "target": "1"
}, },
@ -175,75 +171,24 @@
} }
] ]
}, },
{
"description": "User 2 deposits ETH and borrows the remaining DAI, causing the stable rates to rise (usage ratio = 94%). User 0 tries to rebalance user 1 (revert expected)",
"actions": [
{
"name": "mint",
"args": {
"reserve": "WETH",
"amount": "5",
"user": "2"
},
"expected": "success"
},
{
"name": "approve",
"args": {
"reserve": "WETH",
"user": "2"
},
"expected": "success"
},
{
"name": "deposit",
"args": {
"reserve": "WETH",
"amount": "5",
"user": "2"
},
"expected": "success"
},
{ {
"name": "borrow", "description": "User 0 borrows the remaining USDC (usage ratio = 100%). User 0 rebalances user 1",
"args": {
"reserve": "DAI",
"amount": "190",
"borrowRateMode": "variable",
"user": "2"
},
"expected": "success"
},
{
"name": "rebalanceStableBorrowRate",
"args": {
"reserve": "DAI",
"user": "0",
"target": "1"
},
"expected": "revert",
"revertMessage": "Interest rate rebalance conditions were not met"
}
]
},
{
"description": "User 2 borrows the remaining DAI (usage ratio = 100%). User 0 rebalances user 1",
"actions": [ "actions": [
{ {
"name": "borrow", "name": "borrow",
"args": { "args": {
"reserve": "DAI", "reserve": "USDC",
"amount": "60", "amount": "20",
"borrowRateMode": "variable", "borrowRateMode": "variable",
"user": "2" "user": "1"
}, },
"expected": "success" "expected": "success"
}, },
{ {
"name": "rebalanceStableBorrowRate", "name": "rebalanceStableBorrowRate",
"args": { "args": {
"reserve": "DAI", "reserve": "USDC",
"user": "0", "user": "0",
"target": "1" "target": "1"
}, },

View File

@ -15,7 +15,7 @@ const UNISWAP_ROUTER = '0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D';
makeSuite('Mainnet Check list', (testEnv: TestEnv) => { makeSuite('Mainnet Check list', (testEnv: TestEnv) => {
const zero = BigNumber.from('0'); const zero = BigNumber.from('0');
const depositSize = parseEther('5'); const depositSize = parseEther('5');
const daiSize = parseEther('10000');
it('Deposit WETH', async () => { it('Deposit WETH', async () => {
const { users, wethGateway, aWETH, pool } = testEnv; const { users, wethGateway, aWETH, pool } = testEnv;
@ -104,17 +104,21 @@ makeSuite('Mainnet Check list', (testEnv: TestEnv) => {
const repaySize = borrowSize.add(borrowSize.mul(5).div(100)); const repaySize = borrowSize.add(borrowSize.mul(5).div(100));
const user = users[1]; const user = users[1];
const {stableDebtTokenAddress} = await helpersContract.getReserveTokensAddresses(weth.address); const { stableDebtTokenAddress } = await helpersContract.getReserveTokensAddresses(
weth.address
);
const stableDebtToken = await getStableDebtToken(stableDebtTokenAddress); const stableDebtToken = await getStableDebtToken(stableDebtTokenAddress);
// Deposit with native ETH // Deposit 10000 DAI
await wethGateway.connect(user.signer).depositETH(user.address, '0', {value: depositSize}); await dai.connect(user.signer).mint(daiSize);
await dai.connect(user.signer).approve(pool.address, daiSize);
await pool.connect(user.signer).deposit(dai.address, daiSize, user.address, '0');
const aTokensBalance = await aWETH.balanceOf(user.address); const aTokensBalance = await aDai.balanceOf(user.address);
expect(aTokensBalance).to.be.gt(zero); expect(aTokensBalance).to.be.gt(zero);
expect(aTokensBalance).to.be.gte(depositSize); expect(aTokensBalance).to.be.gte(daiSize);
// Borrow WETH with WETH as collateral // Borrow WETH with WETH as collateral
await waitForTx( await waitForTx(
@ -345,7 +349,7 @@ makeSuite('Mainnet Check list', (testEnv: TestEnv) => {
const userBalanceAfterCall = await user.signer.getBalance(); const userBalanceAfterCall = await user.signer.getBalance();
expect(userBalanceAfterCall).to.be.eq(userBalancePriorCall.sub(amount).sub(gasFees), ''); expect(userBalanceAfterCall).to.be.eq(userBalancePriorCall.sub(amount).sub(gasFees), '');
'User should have lost the funds'; ('User should have lost the funds');
// Recover the funds from the contract and sends back to the user // Recover the funds from the contract and sends back to the user
await wethGateway.connect(deployer.signer).emergencyEtherTransfer(user.address, amount); await wethGateway.connect(deployer.signer).emergencyEtherTransfer(user.address, amount);

View File

@ -803,15 +803,15 @@ makeSuite('Uniswap adapters', (testEnv: TestEnv) => {
const userAddress = users[0].address; const userAddress = users[0].address;
// Add deposit for user // Add deposit for user
await dai.mint(parseEther('20')); await dai.mint(parseEther('30'));
await dai.approve(pool.address, parseEther('20')); await dai.approve(pool.address, parseEther('30'));
await pool.deposit(dai.address, parseEther('20'), userAddress, 0); await pool.deposit(dai.address, parseEther('30'), userAddress, 0);
const amountCollateralToSwap = parseEther('10'); const amountCollateralToSwap = parseEther('10');
const debtAmount = parseEther('10'); const debtAmount = parseEther('10');
// Open user Debt // Open user Debt
await pool.connect(user).borrow(dai.address, debtAmount, 1, 0, userAddress); await pool.connect(user).borrow(dai.address, debtAmount, 2, 0, userAddress);
const daiStableDebtTokenAddress = ( const daiStableDebtTokenAddress = (
await helpersContract.getReserveTokensAddresses(dai.address) await helpersContract.getReserveTokensAddresses(dai.address)
@ -1376,16 +1376,16 @@ makeSuite('Uniswap adapters', (testEnv: TestEnv) => {
const userAddress = users[0].address; const userAddress = users[0].address;
// Add deposit for user // Add deposit for user
await dai.mint(parseEther('20')); await dai.mint(parseEther('30'));
await dai.approve(pool.address, parseEther('20')); await dai.approve(pool.address, parseEther('30'));
await pool.deposit(dai.address, parseEther('20'), userAddress, 0); await pool.deposit(dai.address, parseEther('30'), userAddress, 0);
const amountCollateralToSwap = parseEther('4'); const amountCollateralToSwap = parseEther('4');
const debtAmount = parseEther('3'); const debtAmount = parseEther('3');
// Open user Debt // Open user Debt
await pool.connect(user).borrow(dai.address, debtAmount, 1, 0, userAddress); await pool.connect(user).borrow(dai.address, debtAmount, 2, 0, userAddress);
const daiStableDebtTokenAddress = ( const daiStableDebtTokenAddress = (
await helpersContract.getReserveTokensAddresses(dai.address) await helpersContract.getReserveTokensAddresses(dai.address)

View File

@ -12,11 +12,17 @@ const {expect} = require('chai');
makeSuite('Use native ETH at LendingPool via WETHGateway', (testEnv: TestEnv) => { makeSuite('Use native ETH at LendingPool via WETHGateway', (testEnv: TestEnv) => {
const zero = BigNumber.from('0'); const zero = BigNumber.from('0');
const depositSize = parseEther('5'); const depositSize = parseEther('5');
const daiSize = parseEther('10000');
it('Deposit WETH', async () => { it('Deposit WETH via WethGateway and DAI', async () => {
const {users, wethGateway, aWETH, pool} = testEnv; const { users, wethGateway, aWETH, dai, pool } = testEnv;
const user = users[1]; const user = users[1];
const depositor = users[0];
// Deposit liquidity with native ETH
await wethGateway
.connect(depositor.signer)
.depositETH(depositor.address, '0', { value: depositSize });
// Deposit with native ETH // Deposit with native ETH
await wethGateway.connect(user.signer).depositETH(user.address, '0', { value: depositSize }); await wethGateway.connect(user.signer).depositETH(user.address, '0', { value: depositSize });
@ -96,22 +102,32 @@ makeSuite('Use native ETH at LendingPool via WETHGateway', (testEnv: TestEnv) =>
}); });
it('Borrow stable WETH and Full Repay with ETH', async () => { it('Borrow stable WETH and Full Repay with ETH', async () => {
const {users, wethGateway, aWETH, weth, pool, helpersContract} = testEnv; const { users, wethGateway, aDai, weth, dai, pool, helpersContract } = testEnv;
const borrowSize = parseEther('1'); const borrowSize = parseEther('1');
const repaySize = borrowSize.add(borrowSize.mul(5).div(100)); const repaySize = borrowSize.add(borrowSize.mul(5).div(100));
const user = users[1]; const user = users[1];
const depositor = users[0];
const {stableDebtTokenAddress} = await helpersContract.getReserveTokensAddresses(weth.address); // Deposit with native ETH
await wethGateway
.connect(depositor.signer)
.depositETH(depositor.address, '0', { value: depositSize });
const { stableDebtTokenAddress } = await helpersContract.getReserveTokensAddresses(
weth.address
);
const stableDebtToken = await getStableDebtToken(stableDebtTokenAddress); const stableDebtToken = await getStableDebtToken(stableDebtTokenAddress);
// Deposit with native ETH // Deposit 10000 DAI
await wethGateway.connect(user.signer).depositETH(user.address, '0', {value: depositSize}); await dai.connect(user.signer).mint(daiSize);
await dai.connect(user.signer).approve(pool.address, daiSize);
await pool.connect(user.signer).deposit(dai.address, daiSize, user.address, '0');
const aTokensBalance = await aWETH.balanceOf(user.address); const aTokensBalance = await aDai.balanceOf(user.address);
expect(aTokensBalance).to.be.gt(zero); expect(aTokensBalance).to.be.gt(zero);
expect(aTokensBalance).to.be.gte(depositSize); expect(aTokensBalance).to.be.gte(daiSize);
// Borrow WETH with WETH as collateral // Borrow WETH with WETH as collateral
await waitForTx( await waitForTx(
@ -131,6 +147,10 @@ makeSuite('Use native ETH at LendingPool via WETHGateway', (testEnv: TestEnv) =>
const debtBalanceAfterRepay = await stableDebtToken.balanceOf(user.address); const debtBalanceAfterRepay = await stableDebtToken.balanceOf(user.address);
expect(debtBalanceAfterRepay).to.be.eq(zero); expect(debtBalanceAfterRepay).to.be.eq(zero);
// Withdraw DAI
await aDai.connect(user.signer).approve(pool.address, MAX_UINT_AMOUNT);
await pool.connect(user.signer).withdraw(dai.address, MAX_UINT_AMOUNT, user.address);
}); });
it('Borrow variable WETH and Full Repay with ETH', async () => { it('Borrow variable WETH and Full Repay with ETH', async () => {
@ -333,7 +353,7 @@ makeSuite('Use native ETH at LendingPool via WETHGateway', (testEnv: TestEnv) =>
const userBalanceAfterCall = await user.signer.getBalance(); const userBalanceAfterCall = await user.signer.getBalance();
expect(userBalanceAfterCall).to.be.eq(userBalancePriorCall.sub(amount).sub(gasFees), ''); expect(userBalanceAfterCall).to.be.eq(userBalancePriorCall.sub(amount).sub(gasFees), '');
'User should have lost the funds'; ('User should have lost the funds');
// Recover the funds from the contract and sends back to the user // Recover the funds from the contract and sends back to the user
await wethGateway.connect(deployer.signer).emergencyEtherTransfer(user.address, amount); await wethGateway.connect(deployer.signer).emergencyEtherTransfer(user.address, amount);