mirror of
https://github.com/Instadapp/aave-protocol-v2.git
synced 2024-07-29 21:47:30 +00:00
- Changes on make-suite and refactoring on tests
This commit is contained in:
parent
268dcdead8
commit
2e72a55c78
|
@ -1,24 +1,17 @@
|
|||
import {expect} from "chai";
|
||||
import {MockProvider} from "ethereum-waffle";
|
||||
import {
|
||||
getAToken,
|
||||
getAaveProtocolTestHelpers,
|
||||
} from "../helpers/contracts-helpers";
|
||||
import {evmRevert} from "../helpers/misc-utils";
|
||||
import {getAToken} from "../helpers/contracts-helpers";
|
||||
import {AToken} from "../types/AToken";
|
||||
import {TEST_SNAPSHOT_ID} from "../helpers/constants";
|
||||
import { makeSuite } from './helpers/make-suite';
|
||||
import {makeSuite, TestEnv} from "./helpers/make-suite";
|
||||
|
||||
makeSuite("AToken: Modifiers", () => {
|
||||
const [deployer, ...restWallets] = new MockProvider().getWallets();
|
||||
makeSuite("AToken: Modifiers", (testEnv: TestEnv) => {
|
||||
let _aDAI = {} as AToken;
|
||||
const NOT_LENDING_POOL_MSG =
|
||||
"The caller of this function must be a lending pool";
|
||||
|
||||
before(async () => {
|
||||
const testHelpers = await getAaveProtocolTestHelpers();
|
||||
const {helpersContract} = testEnv;
|
||||
|
||||
const aDAIAddress = (await testHelpers.getAllATokens()).find(
|
||||
const aDAIAddress = (await helpersContract.getAllATokens()).find(
|
||||
(aToken) => aToken.symbol === "aDAI"
|
||||
)?.tokenAddress;
|
||||
if (!aDAIAddress) {
|
||||
|
@ -29,20 +22,23 @@ makeSuite("AToken: Modifiers", () => {
|
|||
});
|
||||
|
||||
it("Tries to invoke mintOnDeposit not being the LendingPool", async () => {
|
||||
const {deployer} = testEnv;
|
||||
await expect(_aDAI.mintOnDeposit(deployer.address, "1")).to.be.revertedWith(
|
||||
NOT_LENDING_POOL_MSG
|
||||
);
|
||||
});
|
||||
|
||||
it("Tries to invoke burnOnLiquidation not being the LendingPool", async () => {
|
||||
const {deployer} = testEnv;
|
||||
await expect(
|
||||
_aDAI.burnOnLiquidation(deployer.address, "1")
|
||||
).to.be.revertedWith(NOT_LENDING_POOL_MSG);
|
||||
});
|
||||
|
||||
it("Tries to invoke transferOnLiquidation not being the LendingPool", async () => {
|
||||
const {deployer, users} = testEnv;
|
||||
await expect(
|
||||
_aDAI.transferOnLiquidation(deployer.address, restWallets[0].address, "1")
|
||||
_aDAI.transferOnLiquidation(deployer.address, users[0].address, "1")
|
||||
).to.be.revertedWith(NOT_LENDING_POOL_MSG);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -5,72 +5,23 @@ import {
|
|||
MAX_UINT_AMOUNT,
|
||||
ZERO_ADDRESS,
|
||||
} from "../helpers/constants";
|
||||
import {AToken} from "../types/AToken";
|
||||
import {MintableErc20} from "../types/MintableErc20";
|
||||
import {LendingPool} from "../types/LendingPool";
|
||||
import {LendingPoolCore} from "../types/LendingPoolCore";
|
||||
import {
|
||||
getAaveProtocolTestHelpers,
|
||||
getMintableErc20,
|
||||
getAToken,
|
||||
convertToCurrencyDecimals,
|
||||
getEthersSigners,
|
||||
getLendingPoolCore,
|
||||
getLendingPool,
|
||||
} from "../helpers/contracts-helpers";
|
||||
import {convertToCurrencyDecimals} from "../helpers/contracts-helpers";
|
||||
import {expect} from "chai";
|
||||
import {Signer, ethers} from "ethers";
|
||||
import {ethers} from "ethers";
|
||||
import {RateMode} from "../helpers/types";
|
||||
import { makeSuite } from './helpers/make-suite';
|
||||
|
||||
|
||||
|
||||
makeSuite("AToken: Transfer", () => {
|
||||
let deployer: Signer;
|
||||
let users: Signer[];
|
||||
let _aDai: AToken;
|
||||
let _dai: MintableErc20;
|
||||
let _lendingPool: LendingPool;
|
||||
let _lendingPoolCore: LendingPoolCore;
|
||||
|
||||
before(async () => {
|
||||
const [_deployer, ..._users] = await getEthersSigners();
|
||||
deployer = _deployer;
|
||||
users = _users;
|
||||
|
||||
_lendingPool = await getLendingPool();
|
||||
_lendingPoolCore = await getLendingPoolCore();
|
||||
|
||||
const testHelpers = await getAaveProtocolTestHelpers();
|
||||
|
||||
const aDaiAddress = (await testHelpers.getAllATokens()).find(
|
||||
(aToken) => aToken.symbol === "aDAI"
|
||||
)?.tokenAddress;
|
||||
|
||||
const daiAddress = (await testHelpers.getAllReservesTokens()).find(
|
||||
(token) => token.symbol === "DAI"
|
||||
)?.tokenAddress;
|
||||
if (!aDaiAddress) {
|
||||
console.log(`atoken-modifiers.spec: aDAI not correctly initialized`);
|
||||
process.exit(1);
|
||||
}
|
||||
if (!daiAddress) {
|
||||
console.log(`atoken-modifiers.spec: DAI not correctly initialized`);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
_aDai = await getAToken(aDaiAddress);
|
||||
_dai = await getMintableErc20(daiAddress);
|
||||
});
|
||||
import {makeSuite, TestEnv} from "./helpers/make-suite";
|
||||
|
||||
makeSuite("AToken: Transfer", (testEnv: TestEnv) => {
|
||||
it("User 0 deposits 1000 DAI, transfers to user 1", async () => {
|
||||
const {users, pool, core, _dai, _aDai} = testEnv;
|
||||
|
||||
await _dai
|
||||
.connect(users[0])
|
||||
.connect(users[0].signer)
|
||||
.mint(await convertToCurrencyDecimals(_dai.address, "1000"));
|
||||
|
||||
await _dai
|
||||
.connect(users[0])
|
||||
.approve(_lendingPoolCore.address, APPROVAL_AMOUNT_LENDING_POOL_CORE);
|
||||
.connect(users[0].signer)
|
||||
.approve(core.address, APPROVAL_AMOUNT_LENDING_POOL_CORE);
|
||||
|
||||
//user 1 deposits 1000 DAI
|
||||
const amountDAItoDeposit = await convertToCurrencyDecimals(
|
||||
|
@ -78,16 +29,16 @@ makeSuite("AToken: Transfer", () => {
|
|||
"1000"
|
||||
);
|
||||
|
||||
await _lendingPool
|
||||
.connect(users[0])
|
||||
await pool
|
||||
.connect(users[0].signer)
|
||||
.deposit(_dai.address, amountDAItoDeposit, "0");
|
||||
|
||||
await _aDai
|
||||
.connect(users[0])
|
||||
.transfer(await users[1].getAddress(), amountDAItoDeposit);
|
||||
.connect(users[0].signer)
|
||||
.transfer(users[1].address, amountDAItoDeposit);
|
||||
|
||||
const fromBalance = await _aDai.balanceOf(await users[0].getAddress());
|
||||
const toBalance = await _aDai.balanceOf(await users[1].getAddress());
|
||||
const fromBalance = await _aDai.balanceOf(users[0].address);
|
||||
const toBalance = await _aDai.balanceOf(users[1].address);
|
||||
|
||||
expect(fromBalance.toString()).to.be.equal(
|
||||
"0",
|
||||
|
@ -100,9 +51,10 @@ makeSuite("AToken: Transfer", () => {
|
|||
});
|
||||
|
||||
it("User 1 redirects interest to user 2, transfers 500 DAI back to user 0", async () => {
|
||||
const {users, _aDai, _dai} = testEnv;
|
||||
await _aDai
|
||||
.connect(users[1])
|
||||
.redirectInterestStream(await users[2].getAddress());
|
||||
.connect(users[1].signer)
|
||||
.redirectInterestStream(users[2].address);
|
||||
|
||||
const aDAIRedirected = await convertToCurrencyDecimals(
|
||||
_dai.address,
|
||||
|
@ -112,7 +64,7 @@ makeSuite("AToken: Transfer", () => {
|
|||
const aDAItoTransfer = await convertToCurrencyDecimals(_dai.address, "500");
|
||||
|
||||
const user2RedirectedBalanceBefore = await _aDai.getRedirectedBalance(
|
||||
await users[2].getAddress()
|
||||
users[2].address
|
||||
);
|
||||
expect(user2RedirectedBalanceBefore.toString()).to.be.equal(
|
||||
aDAIRedirected,
|
||||
|
@ -120,14 +72,14 @@ makeSuite("AToken: Transfer", () => {
|
|||
);
|
||||
|
||||
await _aDai
|
||||
.connect(users[1])
|
||||
.transfer(await users[0].getAddress(), aDAItoTransfer);
|
||||
.connect(users[1].signer)
|
||||
.transfer(users[0].address, aDAItoTransfer);
|
||||
|
||||
const user2RedirectedBalanceAfter = await _aDai.getRedirectedBalance(
|
||||
await users[2].getAddress()
|
||||
users[2].address
|
||||
);
|
||||
const user1RedirectionAddress = await _aDai.getInterestRedirectionAddress(
|
||||
await users[1].getAddress()
|
||||
users[1].address
|
||||
);
|
||||
|
||||
expect(user2RedirectedBalanceAfter.toString()).to.be.equal(
|
||||
|
@ -135,25 +87,24 @@ makeSuite("AToken: Transfer", () => {
|
|||
"Invalid redirected balance for user 2 after transfer"
|
||||
);
|
||||
expect(user1RedirectionAddress.toString()).to.be.equal(
|
||||
await users[2].getAddress(),
|
||||
users[2].address,
|
||||
"Invalid redirection address for user 1"
|
||||
);
|
||||
});
|
||||
|
||||
it("User 0 transfers back to user 1", async () => {
|
||||
const {users, _aDai, _dai} = testEnv;
|
||||
const aDAItoTransfer = await convertToCurrencyDecimals(_dai.address, "500");
|
||||
|
||||
await _aDai
|
||||
.connect(users[0])
|
||||
.transfer(await users[1].getAddress(), aDAItoTransfer);
|
||||
.connect(users[0].signer)
|
||||
.transfer(users[1].address, aDAItoTransfer);
|
||||
|
||||
const user2RedirectedBalanceAfter = await _aDai.getRedirectedBalance(
|
||||
await users[2].getAddress()
|
||||
users[2].address
|
||||
);
|
||||
|
||||
const user1BalanceAfter = await _aDai.balanceOf(
|
||||
await users[1].getAddress()
|
||||
);
|
||||
const user1BalanceAfter = await _aDai.balanceOf(users[1].address);
|
||||
|
||||
expect(user2RedirectedBalanceAfter.toString()).to.be.equal(
|
||||
user1BalanceAfter.toString(),
|
||||
|
@ -162,14 +113,16 @@ makeSuite("AToken: Transfer", () => {
|
|||
});
|
||||
|
||||
it("User 0 deposits 1 ETH and user tries to borrow, but the aTokens received as a transfer are not available as collateral (revert expected)", async () => {
|
||||
await _lendingPool
|
||||
.connect(users[0])
|
||||
const {users, pool} = testEnv;
|
||||
|
||||
await pool
|
||||
.connect(users[0].signer)
|
||||
.deposit(MOCK_ETH_ADDRESS, ethers.utils.parseEther("1.0"), "0", {
|
||||
value: ethers.utils.parseEther("1.0"),
|
||||
});
|
||||
await expect(
|
||||
_lendingPool
|
||||
.connect(users[1])
|
||||
pool
|
||||
.connect(users[1].signer)
|
||||
.borrow(
|
||||
MOCK_ETH_ADDRESS,
|
||||
ethers.utils.parseEther("0.1"),
|
||||
|
@ -181,8 +134,9 @@ makeSuite("AToken: Transfer", () => {
|
|||
});
|
||||
|
||||
it("User 1 sets the DAI as collateral and borrows, tries to transfer everything back to user 0 (revert expected)", async () => {
|
||||
await _lendingPool
|
||||
.connect(users[1])
|
||||
const {users, pool, _aDai, _dai} = testEnv;
|
||||
await pool
|
||||
.connect(users[1].signer)
|
||||
.setUserUseReserveAsCollateral(_dai.address, true);
|
||||
|
||||
const aDAItoTransfer = await convertToCurrencyDecimals(
|
||||
|
@ -190,8 +144,8 @@ makeSuite("AToken: Transfer", () => {
|
|||
"1000"
|
||||
);
|
||||
|
||||
await _lendingPool
|
||||
.connect(users[1])
|
||||
await pool
|
||||
.connect(users[1].signer)
|
||||
.borrow(
|
||||
MOCK_ETH_ADDRESS,
|
||||
ethers.utils.parseEther("0.1"),
|
||||
|
@ -200,24 +154,24 @@ makeSuite("AToken: Transfer", () => {
|
|||
);
|
||||
|
||||
await expect(
|
||||
_aDai
|
||||
.connect(users[1])
|
||||
.transfer(await users[0].getAddress(), aDAItoTransfer),
|
||||
_aDai.connect(users[1].signer).transfer(users[0].address, aDAItoTransfer),
|
||||
"Transfer cannot be allowed."
|
||||
).to.be.revertedWith("Transfer cannot be allowed.");
|
||||
});
|
||||
|
||||
it("User 0 tries to transfer 0 balance (revert expected)", async () => {
|
||||
const {users, pool, _aDai, _dai} = testEnv;
|
||||
await expect(
|
||||
_aDai.connect(users[0]).transfer(await users[1].getAddress(), "0"),
|
||||
_aDai.connect(users[0].signer).transfer(users[1].address, "0"),
|
||||
"Transferred amount needs to be greater than zero"
|
||||
).to.be.revertedWith("Transferred amount needs to be greater than zero");
|
||||
});
|
||||
|
||||
it("User 1 repays the borrow, transfers aDAI back to user 0", async () => {
|
||||
await _lendingPool
|
||||
.connect(users[1])
|
||||
.repay(MOCK_ETH_ADDRESS, MAX_UINT_AMOUNT, await users[1].getAddress(), {
|
||||
const {users, pool, _aDai, _dai} = testEnv;
|
||||
await pool
|
||||
.connect(users[1].signer)
|
||||
.repay(MOCK_ETH_ADDRESS, MAX_UINT_AMOUNT, users[1].address, {
|
||||
value: ethers.utils.parseEther("1"),
|
||||
});
|
||||
|
||||
|
@ -227,15 +181,15 @@ makeSuite("AToken: Transfer", () => {
|
|||
);
|
||||
|
||||
await _aDai
|
||||
.connect(users[1])
|
||||
.transfer(await users[0].getAddress(), aDAItoTransfer);
|
||||
.connect(users[1].signer)
|
||||
.transfer(users[0].address, aDAItoTransfer);
|
||||
|
||||
const user2RedirectedBalanceAfter = await _aDai.getRedirectedBalance(
|
||||
await users[2].getAddress()
|
||||
users[2].address
|
||||
);
|
||||
|
||||
const user1RedirectionAddress = await _aDai.getInterestRedirectionAddress(
|
||||
await users[1].getAddress()
|
||||
users[1].address
|
||||
);
|
||||
|
||||
expect(user2RedirectedBalanceAfter.toString()).to.be.equal(
|
||||
|
@ -250,31 +204,33 @@ makeSuite("AToken: Transfer", () => {
|
|||
});
|
||||
|
||||
it("User 0 redirects interest to user 2, transfers 500 aDAI to user 1. User 1 redirects to user 3. User 0 transfers another 100 aDAI", async () => {
|
||||
const {users, pool, _aDai, _dai} = testEnv;
|
||||
|
||||
let aDAItoTransfer = await convertToCurrencyDecimals(_aDai.address, "500");
|
||||
|
||||
await _aDai
|
||||
.connect(users[0])
|
||||
.redirectInterestStream(await users[2].getAddress());
|
||||
.connect(users[0].signer)
|
||||
.redirectInterestStream(users[2].address);
|
||||
|
||||
await _aDai
|
||||
.connect(users[0])
|
||||
.transfer(await users[1].getAddress(), aDAItoTransfer);
|
||||
.connect(users[0].signer)
|
||||
.transfer(users[1].address, aDAItoTransfer);
|
||||
|
||||
await _aDai
|
||||
.connect(users[1])
|
||||
.redirectInterestStream(await users[3].getAddress());
|
||||
.connect(users[1].signer)
|
||||
.redirectInterestStream(users[3].address);
|
||||
|
||||
aDAItoTransfer = await convertToCurrencyDecimals(_aDai.address, "100");
|
||||
|
||||
await _aDai
|
||||
.connect(users[0])
|
||||
.transfer(await users[1].getAddress(), aDAItoTransfer);
|
||||
.connect(users[0].signer)
|
||||
.transfer(users[1].address, aDAItoTransfer);
|
||||
|
||||
const user2RedirectedBalanceAfter = await _aDai.getRedirectedBalance(
|
||||
await users[2].getAddress()
|
||||
users[2].address
|
||||
);
|
||||
const user3RedirectedBalanceAfter = await _aDai.getRedirectedBalance(
|
||||
await users[3].getAddress()
|
||||
users[3].address
|
||||
);
|
||||
|
||||
const expectedUser2Redirected = await convertToCurrencyDecimals(
|
||||
|
|
|
@ -1,12 +1,87 @@
|
|||
import { evmRevert, evmSnapshot } from '../../helpers/misc-utils';
|
||||
import { TEST_SNAPSHOT_ID } from '../../helpers/constants';
|
||||
import {evmRevert, evmSnapshot} from "../../helpers/misc-utils";
|
||||
import {TEST_SNAPSHOT_ID} from "../../helpers/constants";
|
||||
import {Signer} from "ethers";
|
||||
import {
|
||||
getEthersSigners,
|
||||
getLendingPool,
|
||||
getLendingPoolCore,
|
||||
getLendingPoolAddressesProvider,
|
||||
getAaveProtocolTestHelpers,
|
||||
getAToken,
|
||||
getMintableErc20,
|
||||
} from "../../helpers/contracts-helpers";
|
||||
import {tEthereumAddress} from "../../helpers/types";
|
||||
import {LendingPool} from "../../types/LendingPool";
|
||||
import {LendingPoolCore} from "../../types/LendingPoolCore";
|
||||
import {LendingPoolAddressesProvider} from "../../types/LendingPoolAddressesProvider";
|
||||
import {AaveProtocolTestHelpers} from "../../types/AaveProtocolTestHelpers";
|
||||
import {MintableErc20} from "../../types/MintableErc20";
|
||||
import {AToken} from "../../types/AToken";
|
||||
|
||||
export function makeSuite(name: string, tests: () => void) {
|
||||
describe(name, function () {
|
||||
export interface SignerWithAddress {
|
||||
signer: Signer;
|
||||
address: tEthereumAddress;
|
||||
}
|
||||
export type TestEnv = {
|
||||
deployer: SignerWithAddress;
|
||||
users: SignerWithAddress[];
|
||||
pool: LendingPool;
|
||||
core: LendingPoolCore;
|
||||
addressesProvider: LendingPoolAddressesProvider;
|
||||
helpersContract: AaveProtocolTestHelpers;
|
||||
_dai: MintableErc20;
|
||||
_aDai: AToken;
|
||||
};
|
||||
|
||||
export function makeSuite(name: string, tests: (testEnv: TestEnv) => void) {
|
||||
describe(name, () => {
|
||||
const testEnv: TestEnv = {
|
||||
deployer: {} as SignerWithAddress,
|
||||
users: [] as SignerWithAddress[],
|
||||
pool: {} as LendingPool,
|
||||
core: {} as LendingPoolCore,
|
||||
} as TestEnv;
|
||||
before(async () => {
|
||||
console.time("makeSuite");
|
||||
await evmSnapshot();
|
||||
const [_deployer, ...restSigners] = await getEthersSigners();
|
||||
const deployer: SignerWithAddress = {
|
||||
address: await _deployer.getAddress(),
|
||||
signer: _deployer,
|
||||
};
|
||||
|
||||
for (const signer of restSigners) {
|
||||
testEnv.users.push({
|
||||
signer,
|
||||
address: await signer.getAddress(),
|
||||
});
|
||||
}
|
||||
testEnv.deployer = deployer;
|
||||
testEnv.pool = await getLendingPool();
|
||||
testEnv.core = await getLendingPoolCore();
|
||||
testEnv.addressesProvider = await getLendingPoolAddressesProvider();
|
||||
testEnv.helpersContract = await getAaveProtocolTestHelpers();
|
||||
const aDaiAddress = (await testEnv.helpersContract.getAllATokens()).find(
|
||||
(aToken) => aToken.symbol === "aDAI"
|
||||
)?.tokenAddress;
|
||||
|
||||
const daiAddress = (
|
||||
await await testEnv.helpersContract.getAllReservesTokens()
|
||||
).find((token) => token.symbol === "DAI")?.tokenAddress;
|
||||
if (!aDaiAddress) {
|
||||
console.log(`atoken-modifiers.spec: aDAI not correctly initialized`);
|
||||
process.exit(1);
|
||||
}
|
||||
if (!daiAddress) {
|
||||
console.log(`atoken-modifiers.spec: DAI not correctly initialized`);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
testEnv._aDai = await getAToken(aDaiAddress);
|
||||
testEnv._dai = await getMintableErc20(daiAddress);
|
||||
console.timeEnd("makeSuite");
|
||||
});
|
||||
tests();
|
||||
tests(testEnv);
|
||||
after(async () => {
|
||||
await evmRevert(TEST_SNAPSHOT_ID);
|
||||
});
|
||||
|
|
|
@ -1,18 +1,14 @@
|
|||
import {expect} from "chai";
|
||||
import {MockProvider} from "ethereum-waffle";
|
||||
import {getLendingPoolAddressesProvider} from "../helpers/contracts-helpers";
|
||||
import {createRandomAddress, evmRevert} from "../helpers/misc-utils";
|
||||
import {TEST_SNAPSHOT_ID} from "../helpers/constants";
|
||||
import { makeSuite } from './helpers/make-suite';
|
||||
|
||||
makeSuite("LendingPoolAddressesProvider", () => {
|
||||
const wallets = new MockProvider().getWallets();
|
||||
import {createRandomAddress} from "../helpers/misc-utils";
|
||||
import {makeSuite, TestEnv} from "./helpers/make-suite";
|
||||
|
||||
makeSuite("LendingPoolAddressesProvider", (testEnv: TestEnv) => {
|
||||
it("Test the accessibility of the LendingPoolAddressesProvider", async () => {
|
||||
const {addressesProvider, users} = testEnv;
|
||||
const mockAddress = createRandomAddress();
|
||||
const INVALID_OWNER_REVERT_MSG = "Ownable: caller is not the owner";
|
||||
const addressesProvider = await getLendingPoolAddressesProvider();
|
||||
await addressesProvider.transferOwnership(wallets[1].address);
|
||||
|
||||
await addressesProvider.transferOwnership(users[1].address);
|
||||
|
||||
for (const contractFunction of [
|
||||
addressesProvider.setFeeProviderImpl,
|
||||
|
|
Loading…
Reference in New Issue
Block a user