mirror of
https://github.com/Instadapp/aave-protocol-v2.git
synced 2024-07-29 21:47:30 +00:00
Fixed tests. Add uniswap adapter test to package.json script
This commit is contained in:
parent
611605eebf
commit
16a7398574
|
@ -1,4 +1,4 @@
|
|||
import { Contract, Signer, utils, ethers , BigNumberish} from 'ethers';
|
||||
import { Contract, Signer, utils, ethers, BigNumberish } from 'ethers';
|
||||
import { signTypedData_v4 } from 'eth-sig-util';
|
||||
import { fromRpcSig, ECDSASignature } from 'ethereumjs-util';
|
||||
import BigNumber from 'bignumber.js';
|
||||
|
@ -241,7 +241,8 @@ export const buildLiquiditySwapParams = (
|
|||
deadlines: BigNumberish[],
|
||||
v: BigNumberish[],
|
||||
r: (string | Buffer)[],
|
||||
s: (string | Buffer)[]
|
||||
s: (string | Buffer)[],
|
||||
useEthPath: boolean[]
|
||||
) => {
|
||||
return ethers.utils.defaultAbiCoder.encode(
|
||||
[
|
||||
|
@ -253,8 +254,19 @@ export const buildLiquiditySwapParams = (
|
|||
'uint8[]',
|
||||
'bytes32[]',
|
||||
'bytes32[]',
|
||||
'bool[]',
|
||||
],
|
||||
[assetToSwapToList, minAmountsToReceive, swapAllBalances, permitAmounts, deadlines, v, r, s]
|
||||
[
|
||||
assetToSwapToList,
|
||||
minAmountsToReceive,
|
||||
swapAllBalances,
|
||||
permitAmounts,
|
||||
deadlines,
|
||||
v,
|
||||
r,
|
||||
s,
|
||||
useEthPath,
|
||||
]
|
||||
);
|
||||
};
|
||||
|
||||
|
@ -266,19 +278,11 @@ export const buildRepayAdapterParams = (
|
|||
deadline: BigNumberish,
|
||||
v: BigNumberish,
|
||||
r: string | Buffer,
|
||||
s: string | Buffer
|
||||
s: string | Buffer,
|
||||
useEthPath: boolean
|
||||
) => {
|
||||
return ethers.utils.defaultAbiCoder.encode(
|
||||
[
|
||||
'address',
|
||||
'uint256',
|
||||
'uint256',
|
||||
'uint256',
|
||||
'uint256',
|
||||
'uint8',
|
||||
'bytes32',
|
||||
'bytes32',
|
||||
],
|
||||
[collateralAsset, collateralAmount, rateMode, permitAmount, deadline, v, r, s]
|
||||
['address', 'uint256', 'uint256', 'uint256', 'uint256', 'uint8', 'bytes32', 'bytes32', 'bool'],
|
||||
[collateralAsset, collateralAmount, rateMode, permitAmount, deadline, v, r, s, useEthPath]
|
||||
);
|
||||
};
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
"test-stable-and-atokens": "hardhat test test/__setup.spec.ts test/atoken-transfer.spec.ts test/stable-token.spec.ts",
|
||||
"test-subgraph:scenarios": "hardhat --network hardhatevm_docker test test/__setup.spec.ts test/subgraph-scenarios.spec.ts",
|
||||
"test-weth": "hardhat test test/__setup.spec.ts test/weth-gateway.spec.ts",
|
||||
"test-uniswap": "hardhat test test/__setup.spec.ts test/uniswapAdapters*.spec.ts",
|
||||
"test:main:check-list": "MAINNET_FORK=true TS_NODE_TRANSPILE_ONLY=1 hardhat test test/__setup.spec.ts test/mainnet/check-list.spec.ts",
|
||||
"dev:coverage": "buidler compile --force && buidler coverage --network coverage",
|
||||
"aave:evm:dev:migration": "npm run compile && hardhat aave:dev",
|
||||
|
|
|
@ -121,7 +121,8 @@ makeSuite('Uniswap adapters', (testEnv: TestEnv) => {
|
|||
[0],
|
||||
[0],
|
||||
['0x0000000000000000000000000000000000000000000000000000000000000000'],
|
||||
['0x0000000000000000000000000000000000000000000000000000000000000000']
|
||||
['0x0000000000000000000000000000000000000000000000000000000000000000'],
|
||||
[false]
|
||||
);
|
||||
|
||||
await expect(
|
||||
|
@ -236,7 +237,8 @@ makeSuite('Uniswap adapters', (testEnv: TestEnv) => {
|
|||
[
|
||||
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
||||
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
||||
]
|
||||
],
|
||||
[false, false]
|
||||
);
|
||||
|
||||
await pool
|
||||
|
@ -382,7 +384,8 @@ makeSuite('Uniswap adapters', (testEnv: TestEnv) => {
|
|||
[deadline, deadline],
|
||||
[aWETHv, aUsdcv],
|
||||
[aWETHr, aUsdcr],
|
||||
[aWETHs, aUsdcs]
|
||||
[aWETHs, aUsdcs],
|
||||
[false, false]
|
||||
);
|
||||
|
||||
await pool
|
||||
|
@ -478,7 +481,8 @@ makeSuite('Uniswap adapters', (testEnv: TestEnv) => {
|
|||
[deadline],
|
||||
[v],
|
||||
[r],
|
||||
[s]
|
||||
[s],
|
||||
[false]
|
||||
);
|
||||
|
||||
await expect(
|
||||
|
@ -544,7 +548,8 @@ makeSuite('Uniswap adapters', (testEnv: TestEnv) => {
|
|||
[0],
|
||||
[0],
|
||||
['0x0000000000000000000000000000000000000000000000000000000000000000'],
|
||||
['0x0000000000000000000000000000000000000000000000000000000000000000']
|
||||
['0x0000000000000000000000000000000000000000000000000000000000000000'],
|
||||
[false]
|
||||
);
|
||||
|
||||
await expect(
|
||||
|
@ -569,7 +574,8 @@ makeSuite('Uniswap adapters', (testEnv: TestEnv) => {
|
|||
[0, 0],
|
||||
[0],
|
||||
['0x0000000000000000000000000000000000000000000000000000000000000000'],
|
||||
['0x0000000000000000000000000000000000000000000000000000000000000000']
|
||||
['0x0000000000000000000000000000000000000000000000000000000000000000'],
|
||||
[false]
|
||||
);
|
||||
|
||||
await expect(
|
||||
|
@ -594,7 +600,8 @@ makeSuite('Uniswap adapters', (testEnv: TestEnv) => {
|
|||
[0, 0],
|
||||
[0, 0],
|
||||
['0x0000000000000000000000000000000000000000000000000000000000000000'],
|
||||
['0x0000000000000000000000000000000000000000000000000000000000000000']
|
||||
['0x0000000000000000000000000000000000000000000000000000000000000000'],
|
||||
[false]
|
||||
);
|
||||
|
||||
await expect(
|
||||
|
@ -622,7 +629,8 @@ makeSuite('Uniswap adapters', (testEnv: TestEnv) => {
|
|||
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
||||
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
||||
],
|
||||
['0x0000000000000000000000000000000000000000000000000000000000000000']
|
||||
['0x0000000000000000000000000000000000000000000000000000000000000000'],
|
||||
[false]
|
||||
);
|
||||
|
||||
await expect(
|
||||
|
@ -650,7 +658,8 @@ makeSuite('Uniswap adapters', (testEnv: TestEnv) => {
|
|||
[
|
||||
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
||||
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
||||
]
|
||||
],
|
||||
[false]
|
||||
);
|
||||
|
||||
await expect(
|
||||
|
@ -675,7 +684,8 @@ makeSuite('Uniswap adapters', (testEnv: TestEnv) => {
|
|||
[0],
|
||||
[0],
|
||||
['0x0000000000000000000000000000000000000000000000000000000000000000'],
|
||||
['0x0000000000000000000000000000000000000000000000000000000000000000']
|
||||
['0x0000000000000000000000000000000000000000000000000000000000000000'],
|
||||
[false]
|
||||
);
|
||||
|
||||
await expect(
|
||||
|
@ -700,7 +710,8 @@ makeSuite('Uniswap adapters', (testEnv: TestEnv) => {
|
|||
[0],
|
||||
[0],
|
||||
['0x0000000000000000000000000000000000000000000000000000000000000000'],
|
||||
['0x0000000000000000000000000000000000000000000000000000000000000000']
|
||||
['0x0000000000000000000000000000000000000000000000000000000000000000'],
|
||||
[false]
|
||||
);
|
||||
|
||||
await expect(
|
||||
|
@ -725,7 +736,8 @@ makeSuite('Uniswap adapters', (testEnv: TestEnv) => {
|
|||
[0],
|
||||
[0],
|
||||
['0x0000000000000000000000000000000000000000000000000000000000000000'],
|
||||
['0x0000000000000000000000000000000000000000000000000000000000000000']
|
||||
['0x0000000000000000000000000000000000000000000000000000000000000000'],
|
||||
[false]
|
||||
);
|
||||
|
||||
await expect(
|
||||
|
@ -741,6 +753,32 @@ makeSuite('Uniswap adapters', (testEnv: TestEnv) => {
|
|||
0
|
||||
)
|
||||
).to.be.revertedWith('INCONSISTENT_PARAMS');
|
||||
|
||||
const params9 = buildLiquiditySwapParams(
|
||||
[dai.address],
|
||||
[expectedDaiAmount],
|
||||
[0],
|
||||
[0],
|
||||
[0],
|
||||
[0],
|
||||
['0x0000000000000000000000000000000000000000000000000000000000000000'],
|
||||
['0x0000000000000000000000000000000000000000000000000000000000000000'],
|
||||
[false, false]
|
||||
);
|
||||
|
||||
await expect(
|
||||
pool
|
||||
.connect(user)
|
||||
.flashLoan(
|
||||
uniswapLiquiditySwapAdapter.address,
|
||||
[weth.address],
|
||||
[flashloanAmount.toString()],
|
||||
[0],
|
||||
userAddress,
|
||||
params9,
|
||||
0
|
||||
)
|
||||
).to.be.revertedWith('INCONSISTENT_PARAMS');
|
||||
});
|
||||
|
||||
it('should revert if caller not lending pool', async () => {
|
||||
|
@ -773,7 +811,8 @@ makeSuite('Uniswap adapters', (testEnv: TestEnv) => {
|
|||
[0],
|
||||
[0],
|
||||
['0x0000000000000000000000000000000000000000000000000000000000000000'],
|
||||
['0x0000000000000000000000000000000000000000000000000000000000000000']
|
||||
['0x0000000000000000000000000000000000000000000000000000000000000000'],
|
||||
[false]
|
||||
);
|
||||
|
||||
await expect(
|
||||
|
@ -852,7 +891,8 @@ makeSuite('Uniswap adapters', (testEnv: TestEnv) => {
|
|||
[0],
|
||||
[0],
|
||||
['0x0000000000000000000000000000000000000000000000000000000000000000'],
|
||||
['0x0000000000000000000000000000000000000000000000000000000000000000']
|
||||
['0x0000000000000000000000000000000000000000000000000000000000000000'],
|
||||
[false]
|
||||
);
|
||||
|
||||
await expect(
|
||||
|
@ -916,7 +956,8 @@ makeSuite('Uniswap adapters', (testEnv: TestEnv) => {
|
|||
[0],
|
||||
[0],
|
||||
['0x0000000000000000000000000000000000000000000000000000000000000000'],
|
||||
['0x0000000000000000000000000000000000000000000000000000000000000000']
|
||||
['0x0000000000000000000000000000000000000000000000000000000000000000'],
|
||||
[false]
|
||||
);
|
||||
|
||||
await expect(
|
||||
|
@ -975,7 +1016,8 @@ makeSuite('Uniswap adapters', (testEnv: TestEnv) => {
|
|||
[0],
|
||||
[0],
|
||||
['0x0000000000000000000000000000000000000000000000000000000000000000'],
|
||||
['0x0000000000000000000000000000000000000000000000000000000000000000']
|
||||
['0x0000000000000000000000000000000000000000000000000000000000000000'],
|
||||
[false]
|
||||
);
|
||||
|
||||
// Flashloan + premium > aToken balance. Then it will only swap the balance - premium
|
||||
|
@ -1077,7 +1119,8 @@ makeSuite('Uniswap adapters', (testEnv: TestEnv) => {
|
|||
[deadline],
|
||||
[v],
|
||||
[r],
|
||||
[s]
|
||||
[s],
|
||||
[false]
|
||||
);
|
||||
|
||||
// Flashloan + premium > aToken balance. Then it will only swap the balance - premium
|
||||
|
@ -1490,7 +1533,7 @@ makeSuite('Uniswap adapters', (testEnv: TestEnv) => {
|
|||
s: '0x0000000000000000000000000000000000000000000000000000000000000000',
|
||||
},
|
||||
],
|
||||
[false]
|
||||
[false, false]
|
||||
);
|
||||
|
||||
const adapterWethBalance = await weth.balanceOf(uniswapLiquiditySwapAdapter.address);
|
||||
|
@ -1630,7 +1673,7 @@ makeSuite('Uniswap adapters', (testEnv: TestEnv) => {
|
|||
s: aUsdcs,
|
||||
},
|
||||
],
|
||||
[false]
|
||||
[false, false]
|
||||
);
|
||||
|
||||
const adapterWethBalance = await weth.balanceOf(uniswapLiquiditySwapAdapter.address);
|
||||
|
|
|
@ -162,7 +162,8 @@ makeSuite('Uniswap adapters', (testEnv: TestEnv) => {
|
|||
0,
|
||||
0,
|
||||
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
||||
'0x0000000000000000000000000000000000000000000000000000000000000000'
|
||||
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
||||
false
|
||||
);
|
||||
|
||||
await expect(
|
||||
|
@ -276,7 +277,8 @@ makeSuite('Uniswap adapters', (testEnv: TestEnv) => {
|
|||
deadline,
|
||||
v,
|
||||
r,
|
||||
s
|
||||
s,
|
||||
false
|
||||
);
|
||||
|
||||
await expect(
|
||||
|
@ -337,7 +339,8 @@ makeSuite('Uniswap adapters', (testEnv: TestEnv) => {
|
|||
0,
|
||||
0,
|
||||
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
||||
'0x0000000000000000000000000000000000000000000000000000000000000000'
|
||||
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
||||
false
|
||||
);
|
||||
|
||||
await expect(
|
||||
|
@ -385,7 +388,8 @@ makeSuite('Uniswap adapters', (testEnv: TestEnv) => {
|
|||
0,
|
||||
0,
|
||||
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
||||
'0x0000000000000000000000000000000000000000000000000000000000000000'
|
||||
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
||||
false
|
||||
);
|
||||
|
||||
await expect(
|
||||
|
@ -432,7 +436,8 @@ makeSuite('Uniswap adapters', (testEnv: TestEnv) => {
|
|||
0,
|
||||
0,
|
||||
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
||||
'0x0000000000000000000000000000000000000000000000000000000000000000'
|
||||
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
||||
false
|
||||
);
|
||||
|
||||
await expect(
|
||||
|
@ -490,7 +495,8 @@ makeSuite('Uniswap adapters', (testEnv: TestEnv) => {
|
|||
0,
|
||||
0,
|
||||
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
||||
'0x0000000000000000000000000000000000000000000000000000000000000000'
|
||||
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
||||
false
|
||||
);
|
||||
|
||||
await expect(
|
||||
|
@ -574,7 +580,8 @@ makeSuite('Uniswap adapters', (testEnv: TestEnv) => {
|
|||
0,
|
||||
0,
|
||||
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
||||
'0x0000000000000000000000000000000000000000000000000000000000000000'
|
||||
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
||||
false
|
||||
);
|
||||
|
||||
await expect(
|
||||
|
@ -670,7 +677,8 @@ makeSuite('Uniswap adapters', (testEnv: TestEnv) => {
|
|||
0,
|
||||
0,
|
||||
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
||||
'0x0000000000000000000000000000000000000000000000000000000000000000'
|
||||
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
||||
false
|
||||
);
|
||||
|
||||
await pool
|
||||
|
@ -762,7 +770,8 @@ makeSuite('Uniswap adapters', (testEnv: TestEnv) => {
|
|||
0,
|
||||
0,
|
||||
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
||||
'0x0000000000000000000000000000000000000000000000000000000000000000'
|
||||
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
||||
false
|
||||
);
|
||||
|
||||
await pool
|
||||
|
@ -835,7 +844,8 @@ makeSuite('Uniswap adapters', (testEnv: TestEnv) => {
|
|||
0,
|
||||
0,
|
||||
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
||||
'0x0000000000000000000000000000000000000000000000000000000000000000'
|
||||
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
||||
false
|
||||
);
|
||||
|
||||
await pool
|
||||
|
@ -1374,9 +1384,9 @@ makeSuite('Uniswap adapters', (testEnv: TestEnv) => {
|
|||
await dai.approve(pool.address, parseEther('20'));
|
||||
await pool.deposit(dai.address, parseEther('20'), userAddress, 0);
|
||||
|
||||
const amountCollateralToSwap = parseEther('10');
|
||||
const amountCollateralToSwap = parseEther('4');
|
||||
|
||||
const debtAmount = parseEther('10');
|
||||
const debtAmount = parseEther('3');
|
||||
|
||||
// Open user Debt
|
||||
await pool.connect(user).borrow(dai.address, debtAmount, 1, 0, userAddress);
|
||||
|
|
Loading…
Reference in New Issue
Block a user