2020-07-13 08:54:08 +00:00
|
|
|
import {expect} from 'chai';
|
|
|
|
import {createRandomAddress} from '../helpers/misc-utils';
|
|
|
|
import {makeSuite, TestEnv} from './helpers/make-suite';
|
|
|
|
import {ProtocolErrors} from '../helpers/types';
|
2020-09-29 14:31:21 +00:00
|
|
|
import {ethers} from 'ethers';
|
|
|
|
import {ZERO_ADDRESS} from '../helpers/constants';
|
2020-10-08 13:41:48 +00:00
|
|
|
import {waitForTx} from '../helpers/misc-utils';
|
2020-10-16 09:27:09 +00:00
|
|
|
import {deployLendingPool} from '../helpers/contracts-deployments';
|
2020-09-29 14:31:21 +00:00
|
|
|
|
|
|
|
const {utils} = ethers;
|
2020-06-03 10:44:10 +00:00
|
|
|
|
2020-07-13 08:54:08 +00:00
|
|
|
makeSuite('LendingPoolAddressesProvider', (testEnv: TestEnv) => {
|
|
|
|
it('Test the accessibility of the LendingPoolAddressesProvider', async () => {
|
2020-06-10 15:01:32 +00:00
|
|
|
const {addressesProvider, users} = testEnv;
|
2020-06-03 10:44:10 +00:00
|
|
|
const mockAddress = createRandomAddress();
|
2020-06-12 08:39:42 +00:00
|
|
|
const {INVALID_OWNER_REVERT_MSG} = ProtocolErrors;
|
2020-06-10 15:01:32 +00:00
|
|
|
|
|
|
|
await addressesProvider.transferOwnership(users[1].address);
|
2020-06-03 10:44:10 +00:00
|
|
|
|
|
|
|
for (const contractFunction of [
|
|
|
|
addressesProvider.setLendingPoolImpl,
|
|
|
|
addressesProvider.setLendingPoolConfiguratorImpl,
|
2020-09-16 10:41:12 +00:00
|
|
|
addressesProvider.setLendingPoolCollateralManager,
|
2020-11-05 11:35:50 +00:00
|
|
|
addressesProvider.setPoolAdmin,
|
2020-06-03 10:44:10 +00:00
|
|
|
addressesProvider.setPriceOracle,
|
|
|
|
addressesProvider.setLendingRateOracle,
|
|
|
|
]) {
|
2020-07-13 08:54:08 +00:00
|
|
|
await expect(contractFunction(mockAddress)).to.be.revertedWith(INVALID_OWNER_REVERT_MSG);
|
2020-06-03 10:44:10 +00:00
|
|
|
}
|
2020-09-29 14:31:21 +00:00
|
|
|
|
|
|
|
await expect(
|
|
|
|
addressesProvider.setAddress(
|
|
|
|
utils.keccak256(utils.toUtf8Bytes('RANDOM_ID')),
|
2020-11-10 13:57:09 +00:00
|
|
|
mockAddress
|
2020-09-29 14:31:21 +00:00
|
|
|
)
|
|
|
|
).to.be.revertedWith(INVALID_OWNER_REVERT_MSG);
|
2020-11-10 13:57:09 +00:00
|
|
|
|
|
|
|
await expect(
|
|
|
|
addressesProvider.setAddressAsProxy(
|
|
|
|
utils.keccak256(utils.toUtf8Bytes('RANDOM_ID')),
|
|
|
|
mockAddress
|
|
|
|
)
|
|
|
|
).to.be.revertedWith(INVALID_OWNER_REVERT_MSG);
|
|
|
|
|
2020-06-03 10:44:10 +00:00
|
|
|
});
|
2020-09-29 15:00:51 +00:00
|
|
|
|
2020-11-10 13:57:09 +00:00
|
|
|
it('Tests adding a proxied address with `setAddressAsProxy()`', async () => {
|
2020-09-29 15:00:51 +00:00
|
|
|
const {addressesProvider, users} = testEnv;
|
|
|
|
const {INVALID_OWNER_REVERT_MSG} = ProtocolErrors;
|
|
|
|
|
|
|
|
const currentAddressesProviderOwner = users[1];
|
|
|
|
|
|
|
|
|
|
|
|
const mockLendingPool = await deployLendingPool();
|
|
|
|
const proxiedAddressId = utils.keccak256(utils.toUtf8Bytes('RANDOM_PROXIED'));
|
|
|
|
|
2020-11-10 13:57:09 +00:00
|
|
|
const proxiedAddressSetReceipt = await waitForTx(
|
|
|
|
await addressesProvider
|
|
|
|
.connect(currentAddressesProviderOwner.signer)
|
|
|
|
.setAddressAsProxy(proxiedAddressId, mockLendingPool.address)
|
|
|
|
);
|
|
|
|
|
|
|
|
if (!proxiedAddressSetReceipt.events || proxiedAddressSetReceipt.events?.length < 1) {
|
|
|
|
throw new Error('INVALID_EVENT_EMMITED');
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(proxiedAddressSetReceipt.events[0].event).to.be.equal('ProxyCreated');
|
|
|
|
expect(proxiedAddressSetReceipt.events[1].event).to.be.equal('AddressSet');
|
|
|
|
expect(proxiedAddressSetReceipt.events[1].args?.id).to.be.equal(proxiedAddressId);
|
|
|
|
expect(proxiedAddressSetReceipt.events[1].args?.newAddress).to.be.equal(
|
|
|
|
mockLendingPool.address
|
|
|
|
);
|
|
|
|
expect(proxiedAddressSetReceipt.events[1].args?.hasProxy).to.be.equal(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it('Tests adding a non proxied address with `setAddress()`', async () => {
|
|
|
|
const {addressesProvider, users} = testEnv;
|
|
|
|
const {INVALID_OWNER_REVERT_MSG} = ProtocolErrors;
|
|
|
|
|
|
|
|
const currentAddressesProviderOwner = users[1];
|
|
|
|
const mockNonProxiedAddress = createRandomAddress();
|
|
|
|
const nonProxiedAddressId = utils.keccak256(utils.toUtf8Bytes('RANDOM_NON_PROXIED'));
|
|
|
|
|
2020-09-29 15:00:51 +00:00
|
|
|
const nonProxiedAddressSetReceipt = await waitForTx(
|
|
|
|
await addressesProvider
|
|
|
|
.connect(currentAddressesProviderOwner.signer)
|
2020-11-10 13:57:09 +00:00
|
|
|
.setAddress(nonProxiedAddressId, mockNonProxiedAddress)
|
2020-09-29 15:00:51 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
expect(mockNonProxiedAddress.toLowerCase()).to.be.equal(
|
|
|
|
(await addressesProvider.getAddress(nonProxiedAddressId)).toLowerCase()
|
|
|
|
);
|
|
|
|
|
|
|
|
if (!nonProxiedAddressSetReceipt.events || nonProxiedAddressSetReceipt.events?.length < 1) {
|
|
|
|
throw new Error('INVALID_EVENT_EMMITED');
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(nonProxiedAddressSetReceipt.events[0].event).to.be.equal('AddressSet');
|
|
|
|
expect(nonProxiedAddressSetReceipt.events[0].args?.id).to.be.equal(nonProxiedAddressId);
|
|
|
|
expect(nonProxiedAddressSetReceipt.events[0].args?.newAddress).to.be.equal(
|
|
|
|
mockNonProxiedAddress
|
|
|
|
);
|
|
|
|
expect(nonProxiedAddressSetReceipt.events[0].args?.hasProxy).to.be.equal(false);
|
|
|
|
|
2020-06-03 10:44:10 +00:00
|
|
|
});
|
|
|
|
});
|