mirror of
https://github.com/Instadapp/aave-protocol-v2.git
synced 2024-07-29 21:47:30 +00:00
Fixes #124
This commit is contained in:
parent
ce62734786
commit
ce76335078
|
@ -28,24 +28,30 @@ contract LendingPoolAddressesProvider is Ownable, ILendingPoolAddressesProvider
|
|||
bytes32 private constant LENDING_RATE_ORACLE = 'LENDING_RATE_ORACLE';
|
||||
|
||||
/**
|
||||
* @dev Sets an address for an id, allowing to cover it or not with a proxy
|
||||
* @dev Sets an address for an id by updating a proxy implementation
|
||||
* @param id The id
|
||||
* @param newAddress The address to set, pass address(0) if a proxy is needed
|
||||
* @param implementationAddress The address of the implementation if we want it covered by a proxy
|
||||
* address(0) if we don't want a proxy covering
|
||||
*/
|
||||
function setAddress(
|
||||
function setAddressAsProxy(
|
||||
bytes32 id,
|
||||
address newAddress,
|
||||
address implementationAddress
|
||||
) external override onlyOwner {
|
||||
if (implementationAddress != address(0)) {
|
||||
_updateImpl(id, implementationAddress);
|
||||
emit AddressSet(id, implementationAddress, true);
|
||||
} else {
|
||||
_addresses[id] = newAddress;
|
||||
emit AddressSet(id, newAddress, false);
|
||||
}
|
||||
_updateImpl(id, implementationAddress);
|
||||
emit AddressSet(id, implementationAddress, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Sets an address for an id replacing the address saved in the addresses map
|
||||
* @param id The id
|
||||
* @param newAddress The address to set, pass address(0) if a proxy is needed
|
||||
*/
|
||||
function setAddress(
|
||||
bytes32 id,
|
||||
address newAddress
|
||||
) external override onlyOwner {
|
||||
_addresses[id] = newAddress;
|
||||
emit AddressSet(id, newAddress, false);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -20,7 +20,11 @@ interface ILendingPoolAddressesProvider {
|
|||
|
||||
function setAddress(
|
||||
bytes32 id,
|
||||
address newAddress,
|
||||
address newAddress
|
||||
) external;
|
||||
|
||||
function setAddressAsProxy(
|
||||
bytes32 id,
|
||||
address impl
|
||||
) external;
|
||||
|
||||
|
|
|
@ -31,28 +31,61 @@ makeSuite('LendingPoolAddressesProvider', (testEnv: TestEnv) => {
|
|||
await expect(
|
||||
addressesProvider.setAddress(
|
||||
utils.keccak256(utils.toUtf8Bytes('RANDOM_ID')),
|
||||
mockAddress,
|
||||
ZERO_ADDRESS
|
||||
mockAddress
|
||||
)
|
||||
).to.be.revertedWith(INVALID_OWNER_REVERT_MSG);
|
||||
|
||||
await expect(
|
||||
addressesProvider.setAddressAsProxy(
|
||||
utils.keccak256(utils.toUtf8Bytes('RANDOM_ID')),
|
||||
mockAddress
|
||||
)
|
||||
).to.be.revertedWith(INVALID_OWNER_REVERT_MSG);
|
||||
|
||||
});
|
||||
|
||||
it('Tests adding both a proxied and non-proxied addres with `setAddress()`', async () => {
|
||||
it('Tests adding a proxied address with `setAddressAsProxy()`', 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'));
|
||||
|
||||
const mockLendingPool = await deployLendingPool();
|
||||
const proxiedAddressId = utils.keccak256(utils.toUtf8Bytes('RANDOM_PROXIED'));
|
||||
|
||||
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'));
|
||||
|
||||
const nonProxiedAddressSetReceipt = await waitForTx(
|
||||
await addressesProvider
|
||||
.connect(currentAddressesProviderOwner.signer)
|
||||
.setAddress(nonProxiedAddressId, mockNonProxiedAddress, ZERO_ADDRESS)
|
||||
.setAddress(nonProxiedAddressId, mockNonProxiedAddress)
|
||||
);
|
||||
|
||||
expect(mockNonProxiedAddress.toLowerCase()).to.be.equal(
|
||||
|
@ -70,22 +103,5 @@ makeSuite('LendingPoolAddressesProvider', (testEnv: TestEnv) => {
|
|||
);
|
||||
expect(nonProxiedAddressSetReceipt.events[0].args?.hasProxy).to.be.equal(false);
|
||||
|
||||
const proxiedAddressSetReceipt = await waitForTx(
|
||||
await addressesProvider
|
||||
.connect(currentAddressesProviderOwner.signer)
|
||||
.setAddress(proxiedAddressId, ZERO_ADDRESS, mockLendingPool.address)
|
||||
);
|
||||
|
||||
if (!proxiedAddressSetReceipt.events || proxiedAddressSetReceipt.events?.length < 2) {
|
||||
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);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue
Block a user