- Ported LendingPoolAddressesProvider test.

This commit is contained in:
eboado 2020-06-03 12:44:10 +02:00
parent 87a75065e3
commit 03a6249875
6 changed files with 65 additions and 39 deletions

View File

@ -1,7 +1,9 @@
import { Contract, Signer, utils } from "ethers";
import {Contract, Signer, utils} from "ethers";
import { getDb, BRE } from "./misc-utils";
import { tEthereumAddress, eContractid } from "./types";
import {getDb, BRE} from "./misc-utils";
import {tEthereumAddress, eContractid} from "./types";
import {Example} from "../types/Example";
import {LendingPoolAddressesProvider} from "../types/LendingPoolAddressesProvider";
export const registerContractInJsonDb = async (
contractId: string,
@ -34,7 +36,9 @@ export const registerContractInJsonDb = async (
export const getEthersSigners = async (): Promise<Signer[]> =>
await Promise.all(await BRE.ethers.signers());
export const getEthersSignersAddresses = async (): Promise<tEthereumAddress[]> =>
export const getEthersSignersAddresses = async (): Promise<
tEthereumAddress[]
> =>
await Promise.all(
(await BRE.ethers.signers()).map((signer) => signer.getAddress())
);
@ -63,16 +67,19 @@ const getContract = async <ContractType extends Contract>(
)) as ContractType;
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) => {
return await getContract<any>(
return await getContract<Example>(
eContractid.Example,
address ||
(
await getDb()
.get(`${eContractid.Example}.${BRE.network.name}`)
.value()
).address
(await getDb().get(`${eContractid.Example}.${BRE.network.name}`).value())
.address
);
};

View File

@ -2,8 +2,9 @@ import BigNumber from "bignumber.js";
import BN = require("bn.js");
import low from "lowdb";
import FileSync from "lowdb/adapters/FileSync";
import { WAD } from "./constants";
import { BuidlerRuntimeEnvironment } from "@nomiclabs/buidler/types";
import {WAD} from "./constants";
import {Wallet} from "ethers";
import {BuidlerRuntimeEnvironment} from "@nomiclabs/buidler/types";
export const toWad = (value: string | number) =>
new BigNumber(value).times(WAD).toFixed();
@ -23,3 +24,5 @@ export const setBRE = (_BRE: BuidlerRuntimeEnvironment) => {
export const sleep = (milliseconds: number) => {
return new Promise((resolve) => setTimeout(resolve, milliseconds));
};
export const createRandomAddress = () => Wallet.createRandom().address;

View File

@ -8,7 +8,8 @@ export enum eEthereumNetwork {
}
export enum eContractid {
Example = "Example"
Example = "Example",
LendingPoolAddressesProvider = "LendingPoolAddressesProvider"
}
export type tEthereumAddress = string;

View File

@ -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"
);
});
});

View 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
);
}
});
});