mirror of
https://github.com/Instadapp/aave-protocol-v2.git
synced 2024-07-29 21:47:30 +00:00
- Ported LendingPoolAddressesProvider test.
This commit is contained in:
parent
87a75065e3
commit
03a6249875
|
@ -2,6 +2,8 @@ import { Contract, Signer, utils } from "ethers";
|
||||||
|
|
||||||
import {getDb, BRE} from "./misc-utils";
|
import {getDb, BRE} from "./misc-utils";
|
||||||
import {tEthereumAddress, eContractid} from "./types";
|
import {tEthereumAddress, eContractid} from "./types";
|
||||||
|
import {Example} from "../types/Example";
|
||||||
|
import {LendingPoolAddressesProvider} from "../types/LendingPoolAddressesProvider";
|
||||||
|
|
||||||
export const registerContractInJsonDb = async (
|
export const registerContractInJsonDb = async (
|
||||||
contractId: string,
|
contractId: string,
|
||||||
|
@ -34,7 +36,9 @@ export const registerContractInJsonDb = async (
|
||||||
export const getEthersSigners = async (): Promise<Signer[]> =>
|
export const getEthersSigners = async (): Promise<Signer[]> =>
|
||||||
await Promise.all(await BRE.ethers.signers());
|
await Promise.all(await BRE.ethers.signers());
|
||||||
|
|
||||||
export const getEthersSignersAddresses = async (): Promise<tEthereumAddress[]> =>
|
export const getEthersSignersAddresses = async (): Promise<
|
||||||
|
tEthereumAddress[]
|
||||||
|
> =>
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
(await BRE.ethers.signers()).map((signer) => signer.getAddress())
|
(await BRE.ethers.signers()).map((signer) => signer.getAddress())
|
||||||
);
|
);
|
||||||
|
@ -63,16 +67,19 @@ const getContract = async <ContractType extends Contract>(
|
||||||
)) as ContractType;
|
)) as ContractType;
|
||||||
|
|
||||||
export const deployExampleContract = async () =>
|
export const deployExampleContract = async () =>
|
||||||
await deployContract<any>(eContractid.Example, []);
|
await deployContract<Example>(eContractid.Example, []);
|
||||||
|
|
||||||
|
export const deployLendingPoolAddressesProvider = async () =>
|
||||||
|
await deployContract<LendingPoolAddressesProvider>(
|
||||||
|
eContractid.LendingPoolAddressesProvider,
|
||||||
|
[]
|
||||||
|
);
|
||||||
|
|
||||||
export const getExampleContract = async (address?: tEthereumAddress) => {
|
export const getExampleContract = async (address?: tEthereumAddress) => {
|
||||||
return await getContract<any>(
|
return await getContract<Example>(
|
||||||
eContractid.Example,
|
eContractid.Example,
|
||||||
address ||
|
address ||
|
||||||
(
|
(await getDb().get(`${eContractid.Example}.${BRE.network.name}`).value())
|
||||||
await getDb()
|
.address
|
||||||
.get(`${eContractid.Example}.${BRE.network.name}`)
|
|
||||||
.value()
|
|
||||||
).address
|
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
@ -3,6 +3,7 @@ import BN = require("bn.js");
|
||||||
import low from "lowdb";
|
import low from "lowdb";
|
||||||
import FileSync from "lowdb/adapters/FileSync";
|
import FileSync from "lowdb/adapters/FileSync";
|
||||||
import {WAD} from "./constants";
|
import {WAD} from "./constants";
|
||||||
|
import {Wallet} from "ethers";
|
||||||
import {BuidlerRuntimeEnvironment} from "@nomiclabs/buidler/types";
|
import {BuidlerRuntimeEnvironment} from "@nomiclabs/buidler/types";
|
||||||
|
|
||||||
export const toWad = (value: string | number) =>
|
export const toWad = (value: string | number) =>
|
||||||
|
@ -23,3 +24,5 @@ export const setBRE = (_BRE: BuidlerRuntimeEnvironment) => {
|
||||||
export const sleep = (milliseconds: number) => {
|
export const sleep = (milliseconds: number) => {
|
||||||
return new Promise((resolve) => setTimeout(resolve, milliseconds));
|
return new Promise((resolve) => setTimeout(resolve, milliseconds));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const createRandomAddress = () => Wallet.createRandom().address;
|
||||||
|
|
|
@ -8,7 +8,8 @@ export enum eEthereumNetwork {
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum eContractid {
|
export enum eContractid {
|
||||||
Example = "Example"
|
Example = "Example",
|
||||||
|
LendingPoolAddressesProvider = "LendingPoolAddressesProvider"
|
||||||
}
|
}
|
||||||
|
|
||||||
export type tEthereumAddress = string;
|
export type tEthereumAddress = string;
|
||||||
|
|
|
@ -1,25 +0,0 @@
|
||||||
import rawBRE from "@nomiclabs/buidler";
|
|
||||||
import { expect } from "chai";
|
|
||||||
import { MockProvider } from "ethereum-waffle";
|
|
||||||
import { BuidlerRuntimeEnvironment } from "@nomiclabs/buidler/types";
|
|
||||||
import { deployExampleContract } from "../helpers/contracts-helpers";
|
|
||||||
import { Example } from "../types/Example";
|
|
||||||
|
|
||||||
describe("Example test", () => {
|
|
||||||
const [wallet] = new MockProvider().getWallets();
|
|
||||||
let BRE: BuidlerRuntimeEnvironment;
|
|
||||||
|
|
||||||
before(async () => {
|
|
||||||
console.log("To execute once per 'describe'");
|
|
||||||
BRE = await rawBRE.run("set-bre");
|
|
||||||
});
|
|
||||||
|
|
||||||
it("test()", async () => {
|
|
||||||
const example = (await deployExampleContract()) as Example;
|
|
||||||
|
|
||||||
expect((await example.test()).toString()).to.equal(
|
|
||||||
"5",
|
|
||||||
"INVALID_TEST_VALUE"
|
|
||||||
);
|
|
||||||
});
|
|
||||||
});
|
|
40
test/lending-pool-addresses-provider.ts
Normal file
40
test/lending-pool-addresses-provider.ts
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
import rawBRE from "@nomiclabs/buidler";
|
||||||
|
import {expect} from "chai";
|
||||||
|
import {MockProvider} from "ethereum-waffle";
|
||||||
|
import {BuidlerRuntimeEnvironment} from "@nomiclabs/buidler/types";
|
||||||
|
import {deployLendingPoolAddressesProvider} from "../helpers/contracts-helpers";
|
||||||
|
import {LendingPoolAddressesProvider} from "../types/LendingPoolAddressesProvider";
|
||||||
|
import {createRandomAddress} from "../helpers/misc-utils";
|
||||||
|
|
||||||
|
describe("LendingPoolAddressesProvider", () => {
|
||||||
|
const wallets = new MockProvider().getWallets();
|
||||||
|
let BRE: BuidlerRuntimeEnvironment;
|
||||||
|
|
||||||
|
before(async () => {
|
||||||
|
BRE = await rawBRE.run("set-bre");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("Test the accessibility of the LendingPoolAddressesProvider", async () => {
|
||||||
|
const mockAddress = createRandomAddress();
|
||||||
|
const INVALID_OWNER_REVERT_MSG = "Ownable: caller is not the owner";
|
||||||
|
const addressesProvider = (await deployLendingPoolAddressesProvider()) as LendingPoolAddressesProvider;
|
||||||
|
await addressesProvider.transferOwnership(wallets[1].address);
|
||||||
|
|
||||||
|
for (const contractFunction of [
|
||||||
|
addressesProvider.setFeeProviderImpl,
|
||||||
|
addressesProvider.setLendingPoolImpl,
|
||||||
|
addressesProvider.setLendingPoolConfiguratorImpl,
|
||||||
|
addressesProvider.setLendingPoolCoreImpl,
|
||||||
|
addressesProvider.setLendingPoolDataProviderImpl,
|
||||||
|
addressesProvider.setLendingPoolLiquidationManager,
|
||||||
|
addressesProvider.setLendingPoolManager,
|
||||||
|
addressesProvider.setLendingPoolParametersProviderImpl,
|
||||||
|
addressesProvider.setPriceOracle,
|
||||||
|
addressesProvider.setLendingRateOracle,
|
||||||
|
]) {
|
||||||
|
await expect(contractFunction(mockAddress)).to.be.revertedWith(
|
||||||
|
INVALID_OWNER_REVERT_MSG
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
Loading…
Reference in New Issue
Block a user