update collateralSwap signature in the delegate call

This commit is contained in:
andyk 2020-09-15 09:46:24 +03:00
parent c4904bc41c
commit 65775ca3bf
2 changed files with 22 additions and 5 deletions

View File

@ -592,7 +592,7 @@ contract LendingPool is VersionedInitializable, ILendingPool {
//solium-disable-next-line
(bool success, bytes memory result) = liquidationManager.delegatecall(
abi.encodeWithSignature(
'collateralSwap(address,address,address,uint256,address,bytes)',
'collateralSwap(address,address,address,uint256,bytes)',
receiverAddress,
fromAsset,
toAsset,

View File

@ -27,10 +27,12 @@ makeSuite('LendingPool CollateralSwap function', (testEnv: TestEnv) => {
const connectedWETH = weth.connect(signer);
await connectedWETH.mint(amountToDeposit);
await connectedWETH.approve(pool.address, APPROVAL_AMOUNT_LENDING_POOL);
await pool.connect(signer).deposit(weth.address, amountToDeposit, await signer.getAddress(), '0',);
await pool
.connect(signer)
.deposit(weth.address, amountToDeposit, await signer.getAddress(), '0');
}
});
it('User tries to swap more then he can', async () => {
it('User tries to swap more then he can, revert expected', async () => {
const {pool, weth, dai} = testEnv;
await expect(
pool.collateralSwap(
@ -43,6 +45,19 @@ makeSuite('LendingPool CollateralSwap function', (testEnv: TestEnv) => {
).to.be.revertedWith('55');
});
it('User tries to swap asset on equal asset, revert expected', async () => {
const {pool, weth} = testEnv;
await expect(
pool.collateralSwap(
_mockSwapAdapter.address,
weth.address,
weth.address,
ethers.utils.parseEther('0.1'),
'0x10'
)
).to.be.revertedWith('56');
});
it('User tries to swap more then available on the reserve', async () => {
const {pool, weth, dai, users, aEth, deployer} = testEnv;
@ -61,7 +76,7 @@ makeSuite('LendingPool CollateralSwap function', (testEnv: TestEnv) => {
});
it('User tries to swap correct amount', async () => {
const {pool, weth, dai, aEth, aDai} = testEnv;
const {pool, weth, dai, aEth, aDai} = testEnv;
const userAddress = await pool.signer.getAddress();
const amountToSwap = ethers.utils.parseEther('0.25');
@ -141,7 +156,9 @@ makeSuite('LendingPool CollateralSwap function', (testEnv: TestEnv) => {
// add more liquidity to allow user 0 to swap everything he has
await weth.connect(users[2].signer).mint(ethers.utils.parseEther('1'));
await pool.connect(users[2].signer).deposit(weth.address, ethers.utils.parseEther('1'), users[2].address, '0');
await pool
.connect(users[2].signer)
.deposit(weth.address, ethers.utils.parseEther('1'), users[2].address, '0');
// cleanup borrowings, to be abe to swap whole weth
const amountToRepay = ethers.utils.parseEther('0.5');