import { time, loadFixture } from "@nomicfoundation/hardhat-network-helpers"; import { ethers, network, upgrades } from "hardhat"; describe("NFT", function () { async function deployOneYearLockFixture() { // Contracts are deployed using the first signer/account by default const [owner, otherAccount] = await ethers.getSigners(); const FIL = await ethers.getContractFactory("FIL"); const fil = await FIL.deploy(); const NFT = await ethers.getContractFactory("NFT"); const nft = await NFT.deploy("MyNFT", "MNFT", "123"); const Pool = await ethers.getContractFactory("Pool"); const pool = await upgrades.deployProxy(Pool, [fil.target, nft.target]); const Pledge = await ethers.getContractFactory("Pledge"); const pledge = await await upgrades.deployProxy(Pledge, [ nft.target, pool.target, ]); // await nft.setPledgeAddress(pledge.target); // await pool.setPledgeContractAddress(pledge.target); // await pledge.setDayTime(ethers.toBigInt(1)); return { nft, owner, otherAccount, pool, pledge, fil }; } // 控制block.timestamp + 1天 async function setBlockTimestamp() { // Get current block timestamp const initialTimestamp = (await ethers.provider.getBlock("latest"))! .timestamp; // Set next block timestamp to 1 day later await network.provider.send("evm_setNextBlockTimestamp", [ initialTimestamp + 86400, ]); await network.provider.send("evm_mine"); } // describe("Test deploy", function () { // it("測試質押合約從Pool提現", async () => { // const {pool,owner,pledge,fil} = await loadFixture(deployOneYearLockFixture); // await fil.transfer(pool.target,ethers.parseEther('1000')) // console.log('賬戶餘額:',ethers.formatEther(await fil.balanceOf(owner.address))); // console.log('Pool餘額:',ethers.formatEther(await fil.balanceOf(pool.target))); // await pledge.withdrawPool(ethers.parseEther("1")) // console.log('賬戶餘額:',ethers.formatEther(await fil.balanceOf(owner.address))); // console.log('Pool餘額:',ethers.formatEther(await fil.balanceOf(pool.target))); // }); // }); describe("Test Contract", async function () { // it("测试NFT黑名单", async () => { // const { pledge, fil, pool, otherAccount, owner, nft } = await loadFixture(deployOneYearLockFixture); // await fil.approve(pool.target, ethers.parseEther("1000")); // await pledge.pledge(ethers.parseEther("1000"), "0x2", otherAccount.address); // // console.log(await pledge.getOwnerAllPledgeInfo(owner.address)); // await pledge.addNftBalcks(["0x1"]) // await nft.setApprovalForAll(pledge.target, true) // await pledge.destroyPledge("0x1") // }); it("测试安全计算", async function () { const { pool, owner, pledge, fil } = await loadFixture(deployOneYearLockFixture); console.log(await pledge.safeAdd(ethers.parseEther("10000000000000000000000000000"), ethers.parseEther("10000000000000000"))); }) // it("测试质押销毁",async ()=>{ // const {nft,pledge,pool,fil,owner,otherAccount} = await loadFixture(deployOneYearLockFixture) // await fil.approve(pool.target, ethers.parseEther("1000")); // const res = await pledge.pledge(ethers.parseEther("1000"), "0x2",otherAccount.address); // console.log("销毁前账户余额:",ethers.formatEther(await fil.balanceOf(owner.address))); // console.log("销毁前池子余额:",ethers.formatEther(await fil.balanceOf(pool.target))); // await nft.setApprovalForAll(pledge.target,true) // await pledge.destroyPledge("0x1") // console.log("销毁记录:",await pledge.getPledgeDestoryRecords(owner.address)); // console.log("销毁后账户余额:",ethers.formatEther(await fil.balanceOf(owner.address))); // console.log("销毁后池子余额:",ethers.formatEther(await fil.balanceOf(pool.target))); // console.log('质押合约NFT余额:',await nft.balanceOf(pledge.target)); // }) // it("测试修改质押信息",async function(){ // const {pledge} = await loadFixture(deployOneYearLockFixture) // console.log(await pledge.getProductInfo()); // await pledge.setProductInfo([ethers.toBigInt(179),ethers.toBigInt(279),ethers.toBigInt(359)],[ethers.toBigInt(17),ethers.toBigInt(18),ethers.toBigInt(19)]) // console.log(await pledge.getProductInfo()); // }) // success // it("質押及提取利息修改提現時間及生成記錄",async()=>{ // const { fil, nft, otherAccount, pledge, owner, pool } = await loadFixture( // deployOneYearLockFixture // ); // async function stop (){ // return new Promise((resolve)=>{ // setTimeout(()=>{ // resolve(0) // },2000) // }) // } // //質押及提取利息 // await fil.approve(pool.target, ethers.parseEther("1000")); // console.log("授權給池子合約的金額:",ethers.formatEther(await fil.allowance(owner.address,pool.target))) // const res = await pledge.pledge(ethers.parseEther("1000"), "0x2",otherAccount.address); // console.log('開始時間:',new Date().getSeconds()); // console.log(await pledge.getOwnerAllPledgeInfo(owner.address)); // console.log("池子的FIL餘額:",ethers.formatEther(await fil.balanceOf(pool.target))); // await stop() // await stop() // await stop() // await pledge.setDayTime(ethers.toBigInt(1)); // console.log('結束時間:',new Date().getSeconds()); // console.log('收益',ethers.formatEther(await pledge.getWithdrawbleAmount(owner.address))); // console.log(await pledge.getOwnerAllPledgeInfo(owner.address)); // console.log('賬戶餘額',ethers.formatEther(await fil.balanceOf(owner.address))); // await pledge.withdraAllInterest() // console.log('結束時間:',new Date().getSeconds()); // console.log('賬戶餘額',ethers.formatEther(await fil.balanceOf(owner.address))); // console.log(await pledge.getOwnerAllPledgeInfo(owner.address)); // console.log(await pledge.getPledgeWithdrawRecord(owner.address)); // console.log('邀请人的收益:',ethers.formatEther(await pledge.getOwnerAllInvitationWithdrawAmout(otherAccount.address))); // console.log(await pledge.getOwnerInvitationPledges(otherAccount.address)); // }) // it("Test Mint", async function () { // // console.log(ethers.utils.formatEther(await fil.balanceOf(owner.address))); // // await fil.transfer(otherAccount.address,ethers.utils.parseEther("1")) // // console.log(ethers.utils.formatEther(await fil.balanceOf(otherAccount.address))); // // console.log(owner.address); // // console.log(pool.address); // // await fil.approve(pool.address, ethers.utils.parseEther("2")); // // console.log(await pool.transfer("0x1")); // // console.log(await pledge.getProductInfo()); // // 1710317648n // // 1710317653n // // 質押體現利息 // // await pledge.withdraAllInterest(); // // console.log(await fil.balanceOf(owner.address)); // // console.log(await fil.balanceOf(otherAccount.address)); // // console.log("池子的FIL餘額:",ethers.utils.formatEther(await fil.balanceOf(pool.address))); // // 1 000 000 000 000 000 000 // // console.log('池子餘額',await fil.balanceOf(pool.address)) // // 推薦人的收益記錄 // // console.log('當前地址:'+owner.address); // // console.log('邀請地址:'+otherAccount.address); // // 獲取所有的邀請成員 // // console.log("所有被邀請成員",await pledge.getAllInvitationMember(otherAccount.address)) // // 獲取綁定信息 // // console.log("綁定信息",await pledge.recommendObj(owner.address)) // // 邀請: 獲取當前所有可提取的收益 // // console.log("獲取當前所有可提取的收益",await pledge.getOwnerAllInvitationWithdrawAmout(otherAccount.address)) // // 邀請: 獲取所有下級質押信息 // // console.log("所有被邀請人的質押信息",await pledge.getOwnerInvitationPledges(otherAccount.address)) // // 获取nft数量 // // console.log("NFT数量:+", await nft.balanceOf(owner.address)); // // 获取所有质押信息 // // console.log(await pledge.getOwnerAllPledgeInfo(owner.address)); // // 获取所有NFT tokenId // // console.log(await pledge.getOwnerAllTokens(owner.address)) // // 获取所有利息 // // console.log(await pledge.getWithdrawbleAmount(owner.address)); // // await setBlockTimestamp() // // console.log(await pledge.getWithdrawbleAmount(owner.address)); // // await setBlockTimestamp() // // console.log(await pledge.getWithdrawbleAmount(owner.address)); // // await setBlockTimestamp() // // console.log(await pledge.getWithdrawbleAmount(owner.address)); // // await setBlockTimestamp() // }); // it("Test Admin", async function () { // const { nft, otherAccount,pledge,owner } = await loadFixture(deployOneYearLockFixture); // // await nft.connect(otherAccount.address).setPledgeAddress(pledge.address); // // await nft.connect(otherAccount.address).addAdmin([otherAccount.address]); // // await nft.setPledgeAddress(pledge.address); // // await nft.addAdmin([otherAccount.address,nft.address]) // // console.log(await nft.getAdmin()); // // console.log(await nft.pledgeAddress()); // // await nft.deleteAdmin([owner.address]) // // console.log(await nft.getAdmin()); // }); }); });