You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

195 lines
9.2 KiB

7 months ago
  1. import { time, loadFixture } from "@nomicfoundation/hardhat-network-helpers";
  2. import { ethers, network, upgrades } from "hardhat";
  3. describe("NFT", function () {
  4. async function deployOneYearLockFixture() {
  5. // Contracts are deployed using the first signer/account by default
  6. const [owner, otherAccount] = await ethers.getSigners();
  7. const FIL = await ethers.getContractFactory("FIL");
  8. const fil = await FIL.deploy();
  9. const NFT = await ethers.getContractFactory("NFT");
  10. const nft = await NFT.deploy("MyNFT", "MNFT");
  11. const Pool = await ethers.getContractFactory("Pool");
  12. const pool = await upgrades.deployProxy(Pool, [fil.target, nft.target]);
  13. const Pledge = await ethers.getContractFactory("Pledge");
  14. const pledge = await await upgrades.deployProxy(Pledge, [
  15. nft.target,
  16. pool.target,
  17. ]);
  18. await nft.setPledgeAddress(pledge.target);
  19. await pool.setPledgeContractAddress(pledge.target);
  20. await pledge.setDayTime(ethers.toBigInt(1));
  21. return { nft, owner, otherAccount, pool, pledge, fil };
  22. }
  23. // 控制block.timestamp + 1天
  24. async function setBlockTimestamp() {
  25. // Get current block timestamp
  26. const initialTimestamp = (await ethers.provider.getBlock("latest"))!
  27. .timestamp;
  28. // Set next block timestamp to 1 day later
  29. await network.provider.send("evm_setNextBlockTimestamp", [
  30. initialTimestamp + 86400,
  31. ]);
  32. await network.provider.send("evm_mine");
  33. }
  34. // describe("Test deploy", function () {
  35. // it("測試質押合約從Pool提現", async () => {
  36. // const {pool,owner,pledge,fil} = await loadFixture(deployOneYearLockFixture);
  37. // await fil.transfer(pool.target,ethers.parseEther('1000'))
  38. // console.log('賬戶餘額:',ethers.formatEther(await fil.balanceOf(owner.address)));
  39. // console.log('Pool餘額:',ethers.formatEther(await fil.balanceOf(pool.target)));
  40. // await pledge.withdrawPool(ethers.parseEther("1"))
  41. // console.log('賬戶餘額:',ethers.formatEther(await fil.balanceOf(owner.address)));
  42. // console.log('Pool餘額:',ethers.formatEther(await fil.balanceOf(pool.target)));
  43. // });
  44. // });
  45. describe("Test Contract", async function () {
  46. it("测试NFT黑名单", async () => {
  47. const { pledge,fil,pool,otherAccount,owner,nft } = await loadFixture(deployOneYearLockFixture);
  48. await fil.approve(pool.target, ethers.parseEther("1000"));
  49. await pledge.pledge(ethers.parseEther("1000"), "0x2",otherAccount.address);
  50. // console.log(await pledge.getOwnerAllPledgeInfo(owner.address));
  51. await pledge.addNftBalcks(["0x1"])
  52. await nft.setApprovalForAll(pledge.target,true)
  53. await pledge.destroyPledge("0x1")
  54. });
  55. // it("测试质押销毁",async ()=>{
  56. // const {nft,pledge,pool,fil,owner,otherAccount} = await loadFixture(deployOneYearLockFixture)
  57. // await fil.approve(pool.target, ethers.parseEther("1000"));
  58. // const res = await pledge.pledge(ethers.parseEther("1000"), "0x2",otherAccount.address);
  59. // console.log("销毁前账户余额:",ethers.formatEther(await fil.balanceOf(owner.address)));
  60. // console.log("销毁前池子余额:",ethers.formatEther(await fil.balanceOf(pool.target)));
  61. // await nft.setApprovalForAll(pledge.target,true)
  62. // await pledge.destroyPledge("0x1")
  63. // console.log("销毁记录:",await pledge.getPledgeDestoryRecords(owner.address));
  64. // console.log("销毁后账户余额:",ethers.formatEther(await fil.balanceOf(owner.address)));
  65. // console.log("销毁后池子余额:",ethers.formatEther(await fil.balanceOf(pool.target)));
  66. // console.log('质押合约NFT余额:',await nft.balanceOf(pledge.target));
  67. // })
  68. // it("测试修改质押信息",async function(){
  69. // const {pledge} = await loadFixture(deployOneYearLockFixture)
  70. // console.log(await pledge.getProductInfo());
  71. // await pledge.setProductInfo([ethers.toBigInt(179),ethers.toBigInt(279),ethers.toBigInt(359)],[ethers.toBigInt(17),ethers.toBigInt(18),ethers.toBigInt(19)])
  72. // console.log(await pledge.getProductInfo());
  73. // })
  74. // success
  75. // it("質押及提取利息修改提現時間及生成記錄",async()=>{
  76. // const { fil, nft, otherAccount, pledge, owner, pool } = await loadFixture(
  77. // deployOneYearLockFixture
  78. // );
  79. // async function stop (){
  80. // return new Promise((resolve)=>{
  81. // setTimeout(()=>{
  82. // resolve(0)
  83. // },2000)
  84. // })
  85. // }
  86. // //質押及提取利息
  87. // await fil.approve(pool.target, ethers.parseEther("1000"));
  88. // console.log("授權給池子合約的金額:",ethers.formatEther(await fil.allowance(owner.address,pool.target)))
  89. // const res = await pledge.pledge(ethers.parseEther("1000"), "0x2",otherAccount.address);
  90. // console.log('開始時間:',new Date().getSeconds());
  91. // console.log(await pledge.getOwnerAllPledgeInfo(owner.address));
  92. // console.log("池子的FIL餘額:",ethers.formatEther(await fil.balanceOf(pool.target)));
  93. // await stop()
  94. // await stop()
  95. // await stop()
  96. // await pledge.setDayTime(ethers.toBigInt(1));
  97. // console.log('結束時間:',new Date().getSeconds());
  98. // console.log('收益',ethers.formatEther(await pledge.getWithdrawbleAmount(owner.address)));
  99. // console.log(await pledge.getOwnerAllPledgeInfo(owner.address));
  100. // console.log('賬戶餘額',ethers.formatEther(await fil.balanceOf(owner.address)));
  101. // await pledge.withdraAllInterest()
  102. // console.log('結束時間:',new Date().getSeconds());
  103. // console.log('賬戶餘額',ethers.formatEther(await fil.balanceOf(owner.address)));
  104. // console.log(await pledge.getOwnerAllPledgeInfo(owner.address));
  105. // console.log(await pledge.getPledgeWithdrawRecord(owner.address));
  106. // console.log('邀请人的收益:',ethers.formatEther(await pledge.getOwnerAllInvitationWithdrawAmout(otherAccount.address)));
  107. // console.log(await pledge.getOwnerInvitationPledges(otherAccount.address));
  108. // })
  109. // it("Test Mint", async function () {
  110. // // console.log(ethers.utils.formatEther(await fil.balanceOf(owner.address)));
  111. // // await fil.transfer(otherAccount.address,ethers.utils.parseEther("1"))
  112. // // console.log(ethers.utils.formatEther(await fil.balanceOf(otherAccount.address)));
  113. // // console.log(owner.address);
  114. // // console.log(pool.address);
  115. // // await fil.approve(pool.address, ethers.utils.parseEther("2"));
  116. // // console.log(await pool.transfer("0x1"));
  117. // // console.log(await pledge.getProductInfo());
  118. // // 1710317648n
  119. // // 1710317653n
  120. // // 質押體現利息
  121. // // await pledge.withdraAllInterest();
  122. // // console.log(await fil.balanceOf(owner.address));
  123. // // console.log(await fil.balanceOf(otherAccount.address));
  124. // // console.log("池子的FIL餘額:",ethers.utils.formatEther(await fil.balanceOf(pool.address)));
  125. // // 1 000 000 000 000 000 000
  126. // // console.log('池子餘額',await fil.balanceOf(pool.address))
  127. // // 推薦人的收益記錄
  128. // // console.log('當前地址:'+owner.address);
  129. // // console.log('邀請地址:'+otherAccount.address);
  130. // // 獲取所有的邀請成員
  131. // // console.log("所有被邀請成員",await pledge.getAllInvitationMember(otherAccount.address))
  132. // // 獲取綁定信息
  133. // // console.log("綁定信息",await pledge.recommendObj(owner.address))
  134. // // 邀請: 獲取當前所有可提取的收益
  135. // // console.log("獲取當前所有可提取的收益",await pledge.getOwnerAllInvitationWithdrawAmout(otherAccount.address))
  136. // // 邀請: 獲取所有下級質押信息
  137. // // console.log("所有被邀請人的質押信息",await pledge.getOwnerInvitationPledges(otherAccount.address))
  138. // // 获取nft数量
  139. // // console.log("NFT数量:+", await nft.balanceOf(owner.address));
  140. // // 获取所有质押信息
  141. // // console.log(await pledge.getOwnerAllPledgeInfo(owner.address));
  142. // // 获取所有NFT tokenId
  143. // // console.log(await pledge.getOwnerAllTokens(owner.address))
  144. // // 获取所有利息
  145. // // console.log(await pledge.getWithdrawbleAmount(owner.address));
  146. // // await setBlockTimestamp()
  147. // // console.log(await pledge.getWithdrawbleAmount(owner.address));
  148. // // await setBlockTimestamp()
  149. // // console.log(await pledge.getWithdrawbleAmount(owner.address));
  150. // // await setBlockTimestamp()
  151. // // console.log(await pledge.getWithdrawbleAmount(owner.address));
  152. // // await setBlockTimestamp()
  153. // });
  154. // it("Test Admin", async function () {
  155. // const { nft, otherAccount,pledge,owner } = await loadFixture(deployOneYearLockFixture);
  156. // // await nft.connect(otherAccount.address).setPledgeAddress(pledge.address);
  157. // // await nft.connect(otherAccount.address).addAdmin([otherAccount.address]);
  158. // // await nft.setPledgeAddress(pledge.address);
  159. // // await nft.addAdmin([otherAccount.address,nft.address])
  160. // // console.log(await nft.getAdmin());
  161. // // console.log(await nft.pledgeAddress());
  162. // // await nft.deleteAdmin([owner.address])
  163. // // console.log(await nft.getAdmin());
  164. // });
  165. });
  166. });