Merge pull request #132 from Instadapp/ubiquity-test

updated ubiquity tests
This commit is contained in:
Thrilok kumar 2021-12-13 04:10:12 +05:30 committed by GitHub
commit 121c5f72b4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 64 additions and 54 deletions

View File

@ -6,7 +6,7 @@ import { execScript } from "./command";
let start: number, end: number;
async function testRunner() {
const chain = ["avalanche", "mainnet", "polygon"];
const chain = ["avalanche", "mainnet", "polygon", "arbitrum"];
start = Date.now();
for (let ch of chain) {

View File

@ -25,7 +25,7 @@ async function testRunner() {
const { testName } = await inquirer.prompt([
{
name: "testName",
message: "For which resolver you want to run the tests?",
message: "For which connector you want to run the tests?",
type: "list",
choices: ["all", ...availableTests],
},

View File

@ -1,20 +1,20 @@
const { expect } = require("chai");
const hre = require("hardhat");
import { expect } from "chai";
import hre from "hardhat";
const { waffle, ethers } = hre;
const { provider } = waffle;
const { BigNumber, utils } = ethers;
const deployAndEnableConnector = require("../../scripts/deployAndEnableConnector.js");
const buildDSAv2 = require("../../scripts/buildDSAv2");
const encodeSpells = require("../../scripts/encodeSpells");
const addresses = require("../../scripts/constant/addresses");
const abis = require("../../scripts/constant/abis");
const impersonate = require("../../scripts/impersonate");
const { forkReset, sendEth, mineNBlock } = require("./utils");
import {deployAndEnableConnector} from "../../../scripts/tests/deployAndEnableConnector";
import {buildDSAv2} from "../../../scripts/tests/buildDSAv2";
import {encodeSpells} from "../../../scripts/tests/encodeSpells";
import {addresses} from "../../../scripts/tests/mainnet/addresses";
import {abis} from "../../../scripts/constant/abis";
import {impersonateAccounts} from "../../../scripts/tests/impersonate";
import type { Signer, Contract, BigNumberish } from "ethers";
import {forkReset, sendEth, mineNBlock} from "./utils";
import { ConnectV2Ubiquity__factory } from "../../../typechain";
const connectV2UbiquityArtifacts = require("../../artifacts/contracts/mainnet/connectors/ubiquity/main.sol/ConnectV2Ubiquity.json");
const { abi: implementationsABI } = require("../../scripts/constant/abi/core/InstaImplementations.json");
import { abi as implementationsABI } from "../../../scripts/constant/abi/core/InstaImplementations.json";
const implementationsMappingAddr = "0xCBA828153d3a85b30B5b912e1f2daCac5816aE9D";
describe("Ubiquity", function () {
@ -45,24 +45,24 @@ describe("Ubiquity", function () {
"function holderTokens(address) view returns (uint256[])",
"function getBond(uint256) view returns (tuple(address,uint256,uint256,uint256,uint256,uint256))"
];
let dsa;
let POOL3Contract;
let CRV3Contract;
let uAD3CRVfContract;
let uADContract;
let DAIContract;
let USDCContract;
let USDTContract;
let BONDContract;
let instaIndex;
let instaConnectorsV2;
let connector;
let dsa: Contract;
let POOL3Contract: Contract;
let CRV3Contract: Contract;
let uAD3CRVfContract: Contract;
let uADContract: Contract;
let DAIContract: Contract;
let USDCContract: Contract;
let USDTContract: Contract;
let BONDContract: Contract;
let instaIndex: Contract;
let instaConnectorsV2: Contract;
let connector: Contract;
let instaImplementationsMapping;
let InstaAccountV2DefaultImpl;
let uadWhale;
const bondingShare = async function (address) {
const bondingShare = async function (address: any) {
let lpAmount = BigNumber.from(0);
let lpAmountTotal = BigNumber.from(0);
let bondId = -1;
@ -71,8 +71,8 @@ describe("Ubiquity", function () {
const bondN = bondIds?.length || 0;
if (bondN) {
for await (_bondId of bondIds) {
lpAmountTotal = lpAmountTotal.add((await BONDContract.getBond(_bondId))[5]);
for await (bondId of bondIds) {
lpAmountTotal = lpAmountTotal.add((await BONDContract.getBond(bondId))[5]);
}
bondId = Number(bondIds[bondN - 1]);
lpAmount = (await BONDContract.getBond(bondId))[5];
@ -96,9 +96,20 @@ describe("Ubiquity", function () {
before(async () => {
// await forkReset(blockFork);
[uadWhale] = await impersonate([uadWhaleAddress]);
const [ethWhale] = await impersonate([ethWhaleAddress]);
await hre.network.provider.request({
method: "hardhat_reset",
params: [
{
forking: {
// @ts-ignore
jsonRpcUrl: hre.config.networks.hardhat.forking.url,
blockNumber: 13097100,
},
},
],
});
[uadWhale] = await impersonateAccounts([uadWhaleAddress]);
const [ethWhale] = await impersonateAccounts([ethWhaleAddress]);
await sendEth(ethWhale, uadWhaleAddress, 100);
POOL3Contract = new ethers.Contract(POOL3, ABI, uadWhale);
@ -116,22 +127,22 @@ describe("Ubiquity", function () {
instaIndex = new ethers.Contract(addresses.core.instaIndex, abis.core.instaIndex, ethWhale);
const masterAddress = await instaIndex.master();
const [master] = await impersonate([masterAddress]);
const [master] = await impersonateAccounts([masterAddress]);
await sendEth(ethWhale, masterAddress, 100);
instaConnectorsV2 = new ethers.Contract(addresses.core.connectorsV2, abis.core.connectorsV2);
instaImplementationsMapping = await ethers.getContractAt(implementationsABI, implementationsMappingAddr);
InstaAccountV2DefaultImpl = await ethers.getContractFactory("InstaDefaultImplementation");
instaAccountV2DefaultImpl = await InstaAccountV2DefaultImpl.deploy(addresses.core.instaIndex);
await instaAccountV2DefaultImpl.deployed();
InstaAccountV2DefaultImpl = await InstaAccountV2DefaultImpl.deploy(addresses.core.instaIndex);
await InstaAccountV2DefaultImpl.deployed();
await (
await instaImplementationsMapping.connect(master).setDefaultImplementation(instaAccountV2DefaultImpl.address)
await instaImplementationsMapping.connect(master).setDefaultImplementation(InstaAccountV2DefaultImpl.address)
).wait();
connector = await deployAndEnableConnector({
connectorName: ubiquityTest,
contractArtifact: connectV2UbiquityArtifacts,
contractArtifact: ConnectV2Ubiquity__factory,
signer: master,
connectors: instaConnectorsV2
});
@ -152,21 +163,21 @@ describe("Ubiquity", function () {
afterEach(logAll);
const dsaDepositUAD3CRVf = async (amount) => {
const dsaDepositUAD3CRVf = async (amount: BigNumberish) => {
await uAD3CRVfContract.transfer(dsa.address, one.mul(amount));
};
const dsaDepositUAD = async (amount) => {
const dsaDepositUAD = async (amount: BigNumberish) => {
await uAD3CRVfContract.remove_liquidity_one_coin(one.mul(amount).mul(110).div(100), 0, one.mul(amount));
await uADContract.transfer(dsa.address, one.mul(amount));
};
const dsaDepositCRV3 = async (amount) => {
const dsaDepositCRV3 = async (amount: BigNumberish) => {
await uAD3CRVfContract.remove_liquidity_one_coin(one.mul(amount).mul(110).div(100), 1, one.mul(amount));
await CRV3Contract.transfer(dsa.address, one.mul(amount));
};
const dsaDepositDAI = async (amount) => {
const dsaDepositDAI = async (amount: BigNumberish) => {
await uAD3CRVfContract.remove_liquidity_one_coin(
one.mul(amount).mul(120).div(100),
1,
@ -175,7 +186,7 @@ describe("Ubiquity", function () {
await POOL3Contract.remove_liquidity_one_coin(one.mul(amount).mul(110).div(100), 0, one.mul(amount));
await DAIContract.transfer(dsa.address, one.mul(amount));
};
const dsaDepositUSDC = async (amount) => {
const dsaDepositUSDC = async (amount: BigNumberish) => {
await uAD3CRVfContract.remove_liquidity_one_coin(
one.mul(amount).mul(120).div(100),
1,
@ -184,7 +195,7 @@ describe("Ubiquity", function () {
await POOL3Contract.remove_liquidity_one_coin(one.mul(amount).mul(110).div(100), 1, onep.mul(amount));
await USDCContract.transfer(dsa.address, onep.mul(amount));
};
const dsaDepositUSDT = async (amount) => {
const dsaDepositUSDT = async (amount: BigNumberish) => {
await uAD3CRVfContract.remove_liquidity_one_coin(
one.mul(amount).mul(120).div(100),
1,
@ -314,7 +325,7 @@ describe("Ubiquity", function () {
await logAll();
console.log("Mining 50 000 blocks for more than one week, please wait...");
await mineNBlock(50000);
await mineNBlock(50000, 1);
});
it("Should deposit and withdraw DAI", async function () {

View File

@ -1,12 +1,13 @@
const hre = require("hardhat");
const hardhatConfig = require("../../hardhat.config");
import hre, { ethers, network } from "hardhat";
import hardhatConfig from "../../../hardhat.config";
async function forkReset(blockNumber) {
export async function forkReset(blockNumber: any) {
await hre.network.provider.request({
method: "hardhat_reset",
params: [
{
forking: {
// @ts-ignore
jsonRpcUrl: hardhatConfig.networks.hardhat.forking.url,
blockNumber
}
@ -15,28 +16,28 @@ async function forkReset(blockNumber) {
});
}
async function mineBlock(timestamp) {
export async function mineBlock(timestamp: any) {
await network.provider.request({
method: "evm_mine",
params: [timestamp]
});
}
async function sendEth(from, to, amount) {
export async function sendEth(from: any, to: any, amount: any) {
await from.sendTransaction({
to: to,
value: ethers.BigNumber.from(10).pow(18).mul(amount)
});
}
async function mineNBlock(blockCount, secondsBetweenBlock) {
export async function mineNBlock(blockCount: any, secondsBetweenBlock: any) {
const blockBefore = await ethers.provider.getBlock("latest");
const maxMinedBlockPerBatch = 1000;
let blockToMine = blockCount;
let blockTime = blockBefore.timestamp;
while (blockToMine > maxMinedBlockPerBatch) {
// eslint-disable-next-line @typescript-eslint/no-loop-func
const minings = [...Array(maxMinedBlockPerBatch).keys()].map((_v, i) => {
const minings: any = [maxMinedBlockPerBatch].map((_v, i) => {
const newTs = blockTime + i + (secondsBetweenBlock || 1);
return mineBlock(newTs);
});
@ -45,12 +46,10 @@ async function mineNBlock(blockCount, secondsBetweenBlock) {
blockToMine -= maxMinedBlockPerBatch;
blockTime = blockTime + maxMinedBlockPerBatch - 1 + maxMinedBlockPerBatch * (secondsBetweenBlock || 1);
}
const minings = [...Array(blockToMine).keys()].map((_v, i) => {
const minings = [blockToMine].map((_v, i) => {
const newTs = blockTime + i + (secondsBetweenBlock || 1);
return mineBlock(newTs);
});
// eslint-disable-next-line no-await-in-loop
await Promise.all(minings);
}
module.exports = { forkReset, sendEth, mineNBlock };