mirror of
https://github.com/Instadapp/dsa-connectors.git
synced 2024-07-29 22:37:00 +00:00
updated ubiquity tests
This commit is contained in:
parent
1321cec354
commit
606f933eb7
|
@ -6,7 +6,7 @@ import { execScript } from "./command";
|
||||||
let start: number, end: number;
|
let start: number, end: number;
|
||||||
|
|
||||||
async function testRunner() {
|
async function testRunner() {
|
||||||
const chain = ["avalanche", "mainnet", "polygon"];
|
const chain = ["avalanche", "mainnet", "polygon", "arbitrum"];
|
||||||
start = Date.now();
|
start = Date.now();
|
||||||
|
|
||||||
for (let ch of chain) {
|
for (let ch of chain) {
|
||||||
|
|
|
@ -25,7 +25,7 @@ async function testRunner() {
|
||||||
const { testName } = await inquirer.prompt([
|
const { testName } = await inquirer.prompt([
|
||||||
{
|
{
|
||||||
name: "testName",
|
name: "testName",
|
||||||
message: "For which resolver you want to run the tests?",
|
message: "For which connector you want to run the tests?",
|
||||||
type: "list",
|
type: "list",
|
||||||
choices: ["all", ...availableTests],
|
choices: ["all", ...availableTests],
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,20 +1,20 @@
|
||||||
const { expect } = require("chai");
|
import { expect } from "chai";
|
||||||
const hre = require("hardhat");
|
import hre from "hardhat";
|
||||||
const { waffle, ethers } = hre;
|
const { waffle, ethers } = hre;
|
||||||
const { provider } = waffle;
|
const { provider } = waffle;
|
||||||
const { BigNumber, utils } = ethers;
|
const { BigNumber, utils } = ethers;
|
||||||
|
|
||||||
const deployAndEnableConnector = require("../../scripts/deployAndEnableConnector.js");
|
import {deployAndEnableConnector} from "../../../scripts/tests/deployAndEnableConnector";
|
||||||
const buildDSAv2 = require("../../scripts/buildDSAv2");
|
import {buildDSAv2} from "../../../scripts/tests/buildDSAv2";
|
||||||
const encodeSpells = require("../../scripts/encodeSpells");
|
import {encodeSpells} from "../../../scripts/tests/encodeSpells";
|
||||||
const addresses = require("../../scripts/constant/addresses");
|
import {addresses} from "../../../scripts/tests/mainnet/addresses";
|
||||||
const abis = require("../../scripts/constant/abis");
|
import {abis} from "../../../scripts/constant/abis";
|
||||||
const impersonate = require("../../scripts/impersonate");
|
import {impersonateAccounts} from "../../../scripts/tests/impersonate";
|
||||||
const { forkReset, sendEth, mineNBlock } = require("./utils");
|
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");
|
import { abi as implementationsABI } from "../../../scripts/constant/abi/core/InstaImplementations.json";
|
||||||
|
|
||||||
const { abi: implementationsABI } = require("../../scripts/constant/abi/core/InstaImplementations.json");
|
|
||||||
const implementationsMappingAddr = "0xCBA828153d3a85b30B5b912e1f2daCac5816aE9D";
|
const implementationsMappingAddr = "0xCBA828153d3a85b30B5b912e1f2daCac5816aE9D";
|
||||||
|
|
||||||
describe("Ubiquity", function () {
|
describe("Ubiquity", function () {
|
||||||
|
@ -45,24 +45,24 @@ describe("Ubiquity", function () {
|
||||||
"function holderTokens(address) view returns (uint256[])",
|
"function holderTokens(address) view returns (uint256[])",
|
||||||
"function getBond(uint256) view returns (tuple(address,uint256,uint256,uint256,uint256,uint256))"
|
"function getBond(uint256) view returns (tuple(address,uint256,uint256,uint256,uint256,uint256))"
|
||||||
];
|
];
|
||||||
let dsa;
|
let dsa: Contract;
|
||||||
let POOL3Contract;
|
let POOL3Contract: Contract;
|
||||||
let CRV3Contract;
|
let CRV3Contract: Contract;
|
||||||
let uAD3CRVfContract;
|
let uAD3CRVfContract: Contract;
|
||||||
let uADContract;
|
let uADContract: Contract;
|
||||||
let DAIContract;
|
let DAIContract: Contract;
|
||||||
let USDCContract;
|
let USDCContract: Contract;
|
||||||
let USDTContract;
|
let USDTContract: Contract;
|
||||||
let BONDContract;
|
let BONDContract: Contract;
|
||||||
let instaIndex;
|
let instaIndex: Contract;
|
||||||
let instaConnectorsV2;
|
let instaConnectorsV2: Contract;
|
||||||
let connector;
|
let connector: Contract;
|
||||||
let instaImplementationsMapping;
|
let instaImplementationsMapping;
|
||||||
let InstaAccountV2DefaultImpl;
|
let InstaAccountV2DefaultImpl;
|
||||||
|
|
||||||
let uadWhale;
|
let uadWhale;
|
||||||
|
|
||||||
const bondingShare = async function (address) {
|
const bondingShare = async function (address: any) {
|
||||||
let lpAmount = BigNumber.from(0);
|
let lpAmount = BigNumber.from(0);
|
||||||
let lpAmountTotal = BigNumber.from(0);
|
let lpAmountTotal = BigNumber.from(0);
|
||||||
let bondId = -1;
|
let bondId = -1;
|
||||||
|
@ -71,8 +71,8 @@ describe("Ubiquity", function () {
|
||||||
const bondN = bondIds?.length || 0;
|
const bondN = bondIds?.length || 0;
|
||||||
|
|
||||||
if (bondN) {
|
if (bondN) {
|
||||||
for await (_bondId of bondIds) {
|
for await (bondId of bondIds) {
|
||||||
lpAmountTotal = lpAmountTotal.add((await BONDContract.getBond(_bondId))[5]);
|
lpAmountTotal = lpAmountTotal.add((await BONDContract.getBond(bondId))[5]);
|
||||||
}
|
}
|
||||||
bondId = Number(bondIds[bondN - 1]);
|
bondId = Number(bondIds[bondN - 1]);
|
||||||
lpAmount = (await BONDContract.getBond(bondId))[5];
|
lpAmount = (await BONDContract.getBond(bondId))[5];
|
||||||
|
@ -96,9 +96,20 @@ describe("Ubiquity", function () {
|
||||||
|
|
||||||
before(async () => {
|
before(async () => {
|
||||||
// await forkReset(blockFork);
|
// await forkReset(blockFork);
|
||||||
|
await hre.network.provider.request({
|
||||||
[uadWhale] = await impersonate([uadWhaleAddress]);
|
method: "hardhat_reset",
|
||||||
const [ethWhale] = await impersonate([ethWhaleAddress]);
|
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);
|
await sendEth(ethWhale, uadWhaleAddress, 100);
|
||||||
POOL3Contract = new ethers.Contract(POOL3, ABI, uadWhale);
|
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);
|
instaIndex = new ethers.Contract(addresses.core.instaIndex, abis.core.instaIndex, ethWhale);
|
||||||
|
|
||||||
const masterAddress = await instaIndex.master();
|
const masterAddress = await instaIndex.master();
|
||||||
const [master] = await impersonate([masterAddress]);
|
const [master] = await impersonateAccounts([masterAddress]);
|
||||||
await sendEth(ethWhale, masterAddress, 100);
|
await sendEth(ethWhale, masterAddress, 100);
|
||||||
|
|
||||||
instaConnectorsV2 = new ethers.Contract(addresses.core.connectorsV2, abis.core.connectorsV2);
|
instaConnectorsV2 = new ethers.Contract(addresses.core.connectorsV2, abis.core.connectorsV2);
|
||||||
|
|
||||||
instaImplementationsMapping = await ethers.getContractAt(implementationsABI, implementationsMappingAddr);
|
instaImplementationsMapping = await ethers.getContractAt(implementationsABI, implementationsMappingAddr);
|
||||||
InstaAccountV2DefaultImpl = await ethers.getContractFactory("InstaDefaultImplementation");
|
InstaAccountV2DefaultImpl = await ethers.getContractFactory("InstaDefaultImplementation");
|
||||||
instaAccountV2DefaultImpl = await InstaAccountV2DefaultImpl.deploy(addresses.core.instaIndex);
|
InstaAccountV2DefaultImpl = await InstaAccountV2DefaultImpl.deploy(addresses.core.instaIndex);
|
||||||
await instaAccountV2DefaultImpl.deployed();
|
await InstaAccountV2DefaultImpl.deployed();
|
||||||
await (
|
await (
|
||||||
await instaImplementationsMapping.connect(master).setDefaultImplementation(instaAccountV2DefaultImpl.address)
|
await instaImplementationsMapping.connect(master).setDefaultImplementation(InstaAccountV2DefaultImpl.address)
|
||||||
).wait();
|
).wait();
|
||||||
|
|
||||||
connector = await deployAndEnableConnector({
|
connector = await deployAndEnableConnector({
|
||||||
connectorName: ubiquityTest,
|
connectorName: ubiquityTest,
|
||||||
contractArtifact: connectV2UbiquityArtifacts,
|
contractArtifact: ConnectV2Ubiquity__factory,
|
||||||
signer: master,
|
signer: master,
|
||||||
connectors: instaConnectorsV2
|
connectors: instaConnectorsV2
|
||||||
});
|
});
|
||||||
|
@ -152,21 +163,21 @@ describe("Ubiquity", function () {
|
||||||
|
|
||||||
afterEach(logAll);
|
afterEach(logAll);
|
||||||
|
|
||||||
const dsaDepositUAD3CRVf = async (amount) => {
|
const dsaDepositUAD3CRVf = async (amount: BigNumberish) => {
|
||||||
await uAD3CRVfContract.transfer(dsa.address, one.mul(amount));
|
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 uAD3CRVfContract.remove_liquidity_one_coin(one.mul(amount).mul(110).div(100), 0, one.mul(amount));
|
||||||
await uADContract.transfer(dsa.address, 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 uAD3CRVfContract.remove_liquidity_one_coin(one.mul(amount).mul(110).div(100), 1, one.mul(amount));
|
||||||
await CRV3Contract.transfer(dsa.address, 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(
|
await uAD3CRVfContract.remove_liquidity_one_coin(
|
||||||
one.mul(amount).mul(120).div(100),
|
one.mul(amount).mul(120).div(100),
|
||||||
1,
|
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 POOL3Contract.remove_liquidity_one_coin(one.mul(amount).mul(110).div(100), 0, one.mul(amount));
|
||||||
await DAIContract.transfer(dsa.address, 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(
|
await uAD3CRVfContract.remove_liquidity_one_coin(
|
||||||
one.mul(amount).mul(120).div(100),
|
one.mul(amount).mul(120).div(100),
|
||||||
1,
|
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 POOL3Contract.remove_liquidity_one_coin(one.mul(amount).mul(110).div(100), 1, onep.mul(amount));
|
||||||
await USDCContract.transfer(dsa.address, 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(
|
await uAD3CRVfContract.remove_liquidity_one_coin(
|
||||||
one.mul(amount).mul(120).div(100),
|
one.mul(amount).mul(120).div(100),
|
||||||
1,
|
1,
|
||||||
|
@ -314,7 +325,7 @@ describe("Ubiquity", function () {
|
||||||
|
|
||||||
await logAll();
|
await logAll();
|
||||||
console.log("Mining 50 000 blocks for more than one week, please wait...");
|
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 () {
|
it("Should deposit and withdraw DAI", async function () {
|
|
@ -1,12 +1,13 @@
|
||||||
const hre = require("hardhat");
|
import hre, { ethers, network } from "hardhat";
|
||||||
const hardhatConfig = require("../../hardhat.config");
|
import hardhatConfig from "../../../hardhat.config";
|
||||||
|
|
||||||
async function forkReset(blockNumber) {
|
export async function forkReset(blockNumber: any) {
|
||||||
await hre.network.provider.request({
|
await hre.network.provider.request({
|
||||||
method: "hardhat_reset",
|
method: "hardhat_reset",
|
||||||
params: [
|
params: [
|
||||||
{
|
{
|
||||||
forking: {
|
forking: {
|
||||||
|
// @ts-ignore
|
||||||
jsonRpcUrl: hardhatConfig.networks.hardhat.forking.url,
|
jsonRpcUrl: hardhatConfig.networks.hardhat.forking.url,
|
||||||
blockNumber
|
blockNumber
|
||||||
}
|
}
|
||||||
|
@ -15,28 +16,28 @@ async function forkReset(blockNumber) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async function mineBlock(timestamp) {
|
export async function mineBlock(timestamp: any) {
|
||||||
await network.provider.request({
|
await network.provider.request({
|
||||||
method: "evm_mine",
|
method: "evm_mine",
|
||||||
params: [timestamp]
|
params: [timestamp]
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async function sendEth(from, to, amount) {
|
export async function sendEth(from: any, to: any, amount: any) {
|
||||||
await from.sendTransaction({
|
await from.sendTransaction({
|
||||||
to: to,
|
to: to,
|
||||||
value: ethers.BigNumber.from(10).pow(18).mul(amount)
|
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 blockBefore = await ethers.provider.getBlock("latest");
|
||||||
const maxMinedBlockPerBatch = 1000;
|
const maxMinedBlockPerBatch = 1000;
|
||||||
let blockToMine = blockCount;
|
let blockToMine = blockCount;
|
||||||
let blockTime = blockBefore.timestamp;
|
let blockTime = blockBefore.timestamp;
|
||||||
while (blockToMine > maxMinedBlockPerBatch) {
|
while (blockToMine > maxMinedBlockPerBatch) {
|
||||||
// eslint-disable-next-line @typescript-eslint/no-loop-func
|
// 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);
|
const newTs = blockTime + i + (secondsBetweenBlock || 1);
|
||||||
return mineBlock(newTs);
|
return mineBlock(newTs);
|
||||||
});
|
});
|
||||||
|
@ -45,12 +46,10 @@ async function mineNBlock(blockCount, secondsBetweenBlock) {
|
||||||
blockToMine -= maxMinedBlockPerBatch;
|
blockToMine -= maxMinedBlockPerBatch;
|
||||||
blockTime = blockTime + maxMinedBlockPerBatch - 1 + maxMinedBlockPerBatch * (secondsBetweenBlock || 1);
|
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);
|
const newTs = blockTime + i + (secondsBetweenBlock || 1);
|
||||||
return mineBlock(newTs);
|
return mineBlock(newTs);
|
||||||
});
|
});
|
||||||
// eslint-disable-next-line no-await-in-loop
|
// eslint-disable-next-line no-await-in-loop
|
||||||
await Promise.all(minings);
|
await Promise.all(minings);
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = { forkReset, sendEth, mineNBlock };
|
|
Loading…
Reference in New Issue
Block a user