mirror of
https://github.com/Instadapp/aave-protocol-v2.git
synced 2024-07-29 21:47:30 +00:00
Merge branch 'fix/46' into 'master'
Resolve "improve test coverage of the AddressesProviderRegistry" Closes #46 See merge request aave-tech/protocol-v2!55
This commit is contained in:
commit
8901646f3c
1
coverage.json
Normal file
1
coverage.json
Normal file
File diff suppressed because one or more lines are too long
|
@ -317,6 +317,15 @@ export const getLendingPoolAddressesProvider = async (address?: tEthereumAddress
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const getLendingPoolAddressesProviderRegistry = async (address?: tEthereumAddress) => {
|
||||||
|
return await getContract<LendingPoolAddressesProviderRegistry>(
|
||||||
|
eContractid.LendingPoolAddressesProviderRegistry,
|
||||||
|
address ||
|
||||||
|
(await getDb().get(`${eContractid.LendingPoolAddressesProviderRegistry}.${BRE.network.name}`).value())
|
||||||
|
.address
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
export const getLendingPoolConfiguratorProxy = async (address?: tEthereumAddress) => {
|
export const getLendingPoolConfiguratorProxy = async (address?: tEthereumAddress) => {
|
||||||
return await getContract<LendingPoolConfigurator>(
|
return await getContract<LendingPoolConfigurator>(
|
||||||
eContractid.LendingPoolConfigurator,
|
eContractid.LendingPoolConfigurator,
|
||||||
|
|
|
@ -363,7 +363,7 @@ const buildTestEnv = async (deployer: Signer, secondaryWallet: Signer) => {
|
||||||
|
|
||||||
const addressesProviderRegistry = await deployLendingPoolAddressesProviderRegistry();
|
const addressesProviderRegistry = await deployLendingPoolAddressesProviderRegistry();
|
||||||
await waitForTx(
|
await waitForTx(
|
||||||
await addressesProviderRegistry.registerAddressesProvider(addressesProvider.address, 0)
|
await addressesProviderRegistry.registerAddressesProvider(addressesProvider.address, 1)
|
||||||
);
|
);
|
||||||
|
|
||||||
const lendingPoolImpl = await deployLendingPool();
|
const lendingPoolImpl = await deployLendingPool();
|
||||||
|
|
93
test/addresses-provider-registry.spec.ts
Normal file
93
test/addresses-provider-registry.spec.ts
Normal file
|
@ -0,0 +1,93 @@
|
||||||
|
import {TestEnv, makeSuite} from './helpers/make-suite';
|
||||||
|
import {RAY, APPROVAL_AMOUNT_LENDING_POOL, ZERO_ADDRESS} from '../helpers/constants';
|
||||||
|
import {convertToCurrencyDecimals} from '../helpers/contracts-helpers';
|
||||||
|
import {ProtocolErrors} from '../helpers/types';
|
||||||
|
|
||||||
|
const {expect} = require('chai');
|
||||||
|
|
||||||
|
makeSuite('AddressesProviderRegistry', (testEnv: TestEnv) => {
|
||||||
|
|
||||||
|
it('Checks the addresses provider is added to the registry', async () => {
|
||||||
|
|
||||||
|
const {addressesProvider, registry} = testEnv;
|
||||||
|
|
||||||
|
const providers = await registry.getAddressesProvidersList();
|
||||||
|
|
||||||
|
expect(providers.length).to.be.equal(1, "Invalid length of the addresses providers list");
|
||||||
|
expect(providers[0].toString()).to.be.equal(addressesProvider.address, " Invalid addresses provider added to the list");
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
it('Registers a new mock addresses provider', async () => {
|
||||||
|
|
||||||
|
const {users, registry} = testEnv;
|
||||||
|
|
||||||
|
//simulating an addresses provider using the users[1] wallet address
|
||||||
|
await registry.registerAddressesProvider(users[1].address, "2");
|
||||||
|
|
||||||
|
const providers = await registry.getAddressesProvidersList();
|
||||||
|
|
||||||
|
expect(providers.length).to.be.equal(2, "Invalid length of the addresses providers list");
|
||||||
|
expect(providers[1].toString()).to.be.equal(users[1].address, " Invalid addresses provider added to the list");
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Removes the mock addresses provider', async () => {
|
||||||
|
|
||||||
|
const {users, registry, addressesProvider} = testEnv;
|
||||||
|
|
||||||
|
//checking the isAddressesProviderRegistered function
|
||||||
|
const id = await registry.isAddressesProviderRegistered(users[1].address);
|
||||||
|
|
||||||
|
expect(id).to.be.equal("2", "Invalid isRegistered return value");
|
||||||
|
|
||||||
|
await registry.unregisterAddressesProvider(users[1].address);
|
||||||
|
|
||||||
|
const providers = await registry.getAddressesProvidersList();
|
||||||
|
|
||||||
|
expect(providers.length).to.be.equal(2, "Invalid length of the addresses providers list");
|
||||||
|
expect(providers[0].toString()).to.be.equal(addressesProvider.address, " Invalid addresses provider added to the list");
|
||||||
|
expect(providers[1].toString()).to.be.equal(ZERO_ADDRESS, " Invalid addresses");
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Tries to remove a unregistered addressesProvider', async () => {
|
||||||
|
|
||||||
|
const {PROVIDER_NOT_REGISTERED} = ProtocolErrors;
|
||||||
|
|
||||||
|
const {users, registry} = testEnv;
|
||||||
|
|
||||||
|
await expect(registry.unregisterAddressesProvider(users[2].address)).to.be.revertedWith(PROVIDER_NOT_REGISTERED);
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Tries to remove a unregistered addressesProvider', async () => {
|
||||||
|
|
||||||
|
const {PROVIDER_NOT_REGISTERED} = ProtocolErrors;
|
||||||
|
|
||||||
|
const {users, registry} = testEnv;
|
||||||
|
|
||||||
|
await expect(registry.unregisterAddressesProvider(users[2].address)).to.be.revertedWith(PROVIDER_NOT_REGISTERED);
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Tries to add an already added addressesProvider with a different id. Should overwrite the previous id', async () => {
|
||||||
|
|
||||||
|
const {users, registry, addressesProvider} = testEnv;
|
||||||
|
|
||||||
|
await registry.registerAddressesProvider(addressesProvider.address,"2");
|
||||||
|
|
||||||
|
const providers = await registry.getAddressesProvidersList();
|
||||||
|
|
||||||
|
const id = await registry.isAddressesProviderRegistered(addressesProvider.address);
|
||||||
|
|
||||||
|
expect(providers.length).to.be.equal(2, "Invalid length of the addresses providers list");
|
||||||
|
|
||||||
|
expect(providers[0].toString()).to.be.equal(addressesProvider.address, " Invalid addresses provider added to the list");
|
||||||
|
expect(providers[1].toString()).to.be.equal(ZERO_ADDRESS, " Invalid addresses");
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
|
@ -9,7 +9,7 @@ import {
|
||||||
getMintableErc20,
|
getMintableErc20,
|
||||||
getLendingPoolConfiguratorProxy,
|
getLendingPoolConfiguratorProxy,
|
||||||
getPriceOracle,
|
getPriceOracle,
|
||||||
getMockSwapAdapter,
|
getMockSwapAdapter, getLendingPoolAddressesProviderRegistry
|
||||||
} from '../../helpers/contracts-helpers';
|
} from '../../helpers/contracts-helpers';
|
||||||
import {tEthereumAddress} from '../../helpers/types';
|
import {tEthereumAddress} from '../../helpers/types';
|
||||||
import {LendingPool} from '../../types/LendingPool';
|
import {LendingPool} from '../../types/LendingPool';
|
||||||
|
@ -25,6 +25,7 @@ import {almostEqual} from './almost-equal';
|
||||||
import {PriceOracle} from '../../types/PriceOracle';
|
import {PriceOracle} from '../../types/PriceOracle';
|
||||||
import {LendingPoolAddressesProvider} from '../../types/LendingPoolAddressesProvider';
|
import {LendingPoolAddressesProvider} from '../../types/LendingPoolAddressesProvider';
|
||||||
import { MockSwapAdapter } from '../../types/MockSwapAdapter';
|
import { MockSwapAdapter } from '../../types/MockSwapAdapter';
|
||||||
|
import { LendingPoolAddressesProviderRegistry } from '../../types/LendingPoolAddressesProviderRegistry';
|
||||||
chai.use(bignumberChai());
|
chai.use(bignumberChai());
|
||||||
chai.use(almostEqual());
|
chai.use(almostEqual());
|
||||||
|
|
||||||
|
@ -47,6 +48,7 @@ export interface TestEnv {
|
||||||
lend: MintableErc20;
|
lend: MintableErc20;
|
||||||
addressesProvider: LendingPoolAddressesProvider;
|
addressesProvider: LendingPoolAddressesProvider;
|
||||||
mockSwapAdapter: MockSwapAdapter;
|
mockSwapAdapter: MockSwapAdapter;
|
||||||
|
registry: LendingPoolAddressesProviderRegistry;
|
||||||
}
|
}
|
||||||
|
|
||||||
let buidlerevmSnapshotId: string = '0x1';
|
let buidlerevmSnapshotId: string = '0x1';
|
||||||
|
@ -70,7 +72,8 @@ const testEnv: TestEnv = {
|
||||||
usdc: {} as MintableErc20,
|
usdc: {} as MintableErc20,
|
||||||
lend: {} as MintableErc20,
|
lend: {} as MintableErc20,
|
||||||
addressesProvider: {} as LendingPoolAddressesProvider,
|
addressesProvider: {} as LendingPoolAddressesProvider,
|
||||||
mockSwapAdapter: {} as MockSwapAdapter
|
mockSwapAdapter: {} as MockSwapAdapter,
|
||||||
|
registry: {} as LendingPoolAddressesProviderRegistry
|
||||||
} as TestEnv;
|
} as TestEnv;
|
||||||
|
|
||||||
export async function initializeMakeSuite() {
|
export async function initializeMakeSuite() {
|
||||||
|
@ -95,6 +98,7 @@ export async function initializeMakeSuite() {
|
||||||
|
|
||||||
testEnv.oracle = await getPriceOracle();
|
testEnv.oracle = await getPriceOracle();
|
||||||
testEnv.addressesProvider = await getLendingPoolAddressesProvider();
|
testEnv.addressesProvider = await getLendingPoolAddressesProvider();
|
||||||
|
testEnv.registry = await getLendingPoolAddressesProviderRegistry();
|
||||||
|
|
||||||
testEnv.helpersContract = await getAaveProtocolTestHelpers();
|
testEnv.helpersContract = await getAaveProtocolTestHelpers();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user