Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristianBorst committed Aug 8, 2024
1 parent ba055d3 commit a8dbf9d
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 27 deletions.
21 changes: 19 additions & 2 deletions test/TestLiquidERC20.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
TestERC20C,
LiquidInfrastructureNFT,
LiquidInfrastructureERC20,
LiquidInfrastructureMulticlaim,
} from "../typechain-types/contracts";
import { ERC20 } from "../typechain-types/@openzeppelin/contracts/token/ERC20";
import { HardhatEthersSigner } from "@nomicfoundation/hardhat-ethers/signers";
Expand All @@ -23,6 +24,7 @@ const {
} = require("@nomicfoundation/hardhat-toolbox/network-helpers");
const { expect } = chai;

const DEPLOYED_MULTICLAIM = "0x0000000000000000000000000000000000000000";
const DEPLOYED_CONTRACT = "0x0000000000000000000000000000000000000000";
const ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
const ONE_ETH = 1000000000000000000;
Expand Down Expand Up @@ -62,6 +64,8 @@ export function fromQ64(val: bigint): BigNumber {

describe("TestLiquidERC20", () => {
let token: LiquidInfrastructureERC20;
let multiclaim: LiquidInfrastructureMulticlaim;
let multiclaimAddress: string;
let signers: HardhatEthersSigner[];
let holderAddresses: AddressLike[];
let erc20s: ERC20[];
Expand All @@ -77,6 +81,19 @@ describe("TestLiquidERC20", () => {
let tokens = await deployContracts(signers[0]);
erc20s = [tokens.testERC20A, tokens.testERC20B, tokens.testERC20C];

const multiclaimFactory = await ethers.getContractFactory(
"LiquidInfrastructureMulticlaim"
);
multiclaim = multiclaimFactory.attach(
DEPLOYED_MULTICLAIM
) as unknown as LiquidInfrastructureMulticlaim;
if ((await multiclaim.getDeployedCode()) == null) {
multiclaim =
(await multiclaimFactory.deploy()) as unknown as LiquidInfrastructureMulticlaim;
multiclaimAddress = await multiclaim.getAddress();
console.log("Deployed Multiclaim at ", multiclaimAddress);
}

const libFactory = await ethers.getContractFactory(
"LiquidInfrastructureERC20"
);
Expand Down Expand Up @@ -109,7 +126,7 @@ describe("TestLiquidERC20", () => {
"INFRA",
holderAddresses,
distributable,
ZERO_ADDRESS // No multiclaim
multiclaimAddress
)) as unknown as LiquidInfrastructureERC20;
console.log("Deployed ERC20 at ", await token.getAddress());
}
Expand Down Expand Up @@ -152,7 +169,7 @@ describe("TestLiquidERC20", () => {
erc20s as TestERC20A[],
erc20s.map((v) => BigNumber(randi(10) + 1).times(oneEth))
);
});
}).timeout(120000); // Increase the timeout to 120 seconds

it("Revenue Claim with Accounting", async () => {
let deployer = signers[0];
Expand Down
98 changes: 73 additions & 25 deletions test/TestLiquidInfraMulticlaim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ const {
} = require("@nomicfoundation/hardhat-toolbox/network-helpers");
const { expect } = chai;

const DEPLOYED_CONTRACT = "0x0000000000000000000000000000000000000000";
const DEPLOYED_MULTICLAIM = "0x0000000000000000000000000000000000000000";
const DEPLOYED_ERC20s: string[] = [];
const ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
const ONE_ETH = 1000000000000000000;

Expand Down Expand Up @@ -63,6 +64,7 @@ export function fromQ64(val: bigint): BigNumber {

describe("TestLiquidInfraMulticlaim", () => {
let multiclaim: LiquidInfrastructureMulticlaim;
let multiclaimAddress: string;
let tokens: LiquidInfrastructureERC20[] = [];
let signers: HardhatEthersSigner[];
let holderAddresses: AddressLike[];
Expand All @@ -82,33 +84,81 @@ describe("TestLiquidInfraMulticlaim", () => {
const multiclaimFactory = await ethers.getContractFactory(
"LiquidInfrastructureMulticlaim"
);
multiclaim =
(await multiclaimFactory.deploy()) as unknown as LiquidInfrastructureMulticlaim;
const multiclaimAddress = await multiclaim.getAddress();
console.log("Deployed Multiclaim at ", multiclaimAddress);
multiclaim = multiclaimFactory.attach(
DEPLOYED_MULTICLAIM
) as unknown as LiquidInfrastructureMulticlaim;
if ((await multiclaim.getDeployedCode()) == null) {
multiclaim =
(await multiclaimFactory.deploy()) as unknown as LiquidInfrastructureMulticlaim;
multiclaimAddress = await multiclaim.getAddress();
console.log("Deployed Multiclaim at ", multiclaimAddress);
}

const erc20Factory = await ethers.getContractFactory(
"LiquidInfrastructureERC20"
);
holderAddresses = signers.map((v) => v.address);
holderAddresses = signers.slice(0, 10).map((v) => v.address);
let distributable = await Promise.all(
erc20s.map(async (v) => await v.getAddress())
);

let numTokens = randi(5) + 1;
for (let i = 0; i < numTokens; i++) {
let token = (await erc20Factory.deploy(
"Infra" + i.toString(),
"INFRA" + i.toString(),
holderAddresses,
distributable,
multiclaimAddress
)) as unknown as LiquidInfrastructureERC20;
console.log("Deployed ERC20 %s at %s", i, await token.getAddress());
tokens.push(token);
const erc20Factory = await ethers.getContractFactory(
"LiquidInfrastructureERC20"
);
for (let token of DEPLOYED_ERC20s) {
let deployedErc20 = erc20Factory.attach(
token
) as unknown as LiquidInfrastructureERC20;
if ((await deployedErc20.getDeployedCode()) == null) {
deployedErc20 = (await erc20Factory.deploy(
"INFRA",
"INFRA",
holderAddresses,
distributable,
multiclaimAddress
)) as unknown as LiquidInfrastructureERC20;
const erc20Address = await deployedErc20.getAddress();
console.log("Deployed ERC20 at ", erc20Address);
}
tokens.push(deployedErc20);
}
});

it("test setup", async () => {
let deployer = signers[0];
for (let token of tokens) {
for (let holder of holderAddresses) {
if (!(await token.isApprovedHolder(holder))) {
await token.approveHolder(holder);
}
}
let numNFTs = 1;
let nfts = await deployLiquidNFTs(
deployer,
numNFTs,
erc20s,
erc20s.map((_) => 0)
);

await manageNFTs(deployer, token, nfts, true);

await fundNFTs(
deployer,
nfts,
erc20s as TestERC20A[],
erc20s.map((v) => BigNumber(100).times(oneEth))
);

await mintToHolders(
deployer,
token,
holderAddresses,
holderAddresses.map((_) => BigNumber(randi(1000) + 1).times(oneEth))
);

await stakeFromHolders(signers, token);

await token.withdrawFromAllManagedNFTs();
}
}).timeout(1200000);

it("Multi claim", async () => {
let deployer = signers[0];
for (let token of tokens) {
Expand Down Expand Up @@ -259,11 +309,9 @@ export async function stakeFromHolders(
let holder = holders[i];
let t = token.connect(holders[i]);
let balance = await t.balanceOf(holder.address);
expect(balance > 0).to.be.true;
await t.approve(await token.getAddress(), balance);
let allowance = await t.allowance(holder.address, await token.getAddress());
expect(allowance == balance).to.be.true;
await t.stake(balance);
if (balance > 0) {
await t.stake(balance);
}
}
}

Expand Down

0 comments on commit a8dbf9d

Please sign in to comment.