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.

202 lines
9.6 KiB

7 months ago
7 months ago
7 months ago
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", "123");
  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 function () {
  56. const { pool, owner, pledge, fil } = await loadFixture(deployOneYearLockFixture);
  57. console.log(await pledge.safeAdd(ethers.parseEther("10000000000000000000000000000"), ethers.parseEther("10000000000000000")));
  58. })
  59. // it("测试质押销毁",async ()=>{
  60. // const {nft,pledge,pool,fil,owner,otherAccount} = await loadFixture(deployOneYearLockFixture)
  61. // await fil.approve(pool.target, ethers.parseEther("1000"));
  62. // const res = await pledge.pledge(ethers.parseEther("1000"), "0x2",otherAccount.address);
  63. // console.log("销毁前账户余额:",ethers.formatEther(await fil.balanceOf(owner.address)));
  64. // console.log("销毁前池子余额:",ethers.formatEther(await fil.balanceOf(pool.target)));
  65. // await nft.setApprovalForAll(pledge.target,true)
  66. // await pledge.destroyPledge("0x1")
  67. // console.log("销毁记录:",await pledge.getPledgeDestoryRecords(owner.address));
  68. // console.log("销毁后账户余额:",ethers.formatEther(await fil.balanceOf(owner.address)));
  69. // console.log("销毁后池子余额:",ethers.formatEther(await fil.balanceOf(pool.target)));
  70. // console.log('质押合约NFT余额:',await nft.balanceOf(pledge.target));
  71. // })
  72. // it("测试修改质押信息",async function(){
  73. // const {pledge} = await loadFixture(deployOneYearLockFixture)
  74. // console.log(await pledge.getProductInfo());
  75. // await pledge.setProductInfo([ethers.toBigInt(179),ethers.toBigInt(279),ethers.toBigInt(359)],[ethers.toBigInt(17),ethers.toBigInt(18),ethers.toBigInt(19)])
  76. // console.log(await pledge.getProductInfo());
  77. // })
  78. // success
  79. // it("質押及提取利息修改提現時間及生成記錄",async()=>{
  80. // const { fil, nft, otherAccount, pledge, owner, pool } = await loadFixture(
  81. // deployOneYearLockFixture
  82. // );
  83. // async function stop (){
  84. // return new Promise((resolve)=>{
  85. // setTimeout(()=>{
  86. // resolve(0)
  87. // },2000)
  88. // })
  89. // }
  90. // //質押及提取利息
  91. // await fil.approve(pool.target, ethers.parseEther("1000"));
  92. // console.log("授權給池子合約的金額:",ethers.formatEther(await fil.allowance(owner.address,pool.target)))
  93. // const res = await pledge.pledge(ethers.parseEther("1000"), "0x2",otherAccount.address);
  94. // console.log('開始時間:',new Date().getSeconds());
  95. // console.log(await pledge.getOwnerAllPledgeInfo(owner.address));
  96. // console.log("池子的FIL餘額:",ethers.formatEther(await fil.balanceOf(pool.target)));
  97. // await stop()
  98. // await stop()
  99. // await stop()
  100. // await pledge.setDayTime(ethers.toBigInt(1));
  101. // console.log('結束時間:',new Date().getSeconds());
  102. // console.log('收益',ethers.formatEther(await pledge.getWithdrawbleAmount(owner.address)));
  103. // console.log(await pledge.getOwnerAllPledgeInfo(owner.address));
  104. // console.log('賬戶餘額',ethers.formatEther(await fil.balanceOf(owner.address)));
  105. // await pledge.withdraAllInterest()
  106. // console.log('結束時間:',new Date().getSeconds());
  107. // console.log('賬戶餘額',ethers.formatEther(await fil.balanceOf(owner.address)));
  108. // console.log(await pledge.getOwnerAllPledgeInfo(owner.address));
  109. // console.log(await pledge.getPledgeWithdrawRecord(owner.address));
  110. // console.log('邀请人的收益:',ethers.formatEther(await pledge.getOwnerAllInvitationWithdrawAmout(otherAccount.address)));
  111. // console.log(await pledge.getOwnerInvitationPledges(otherAccount.address));
  112. // })
  113. // it("Test Mint", async function () {
  114. // // console.log(ethers.utils.formatEther(await fil.balanceOf(owner.address)));
  115. // // await fil.transfer(otherAccount.address,ethers.utils.parseEther("1"))
  116. // // console.log(ethers.utils.formatEther(await fil.balanceOf(otherAccount.address)));
  117. // // console.log(owner.address);
  118. // // console.log(pool.address);
  119. // // await fil.approve(pool.address, ethers.utils.parseEther("2"));
  120. // // console.log(await pool.transfer("0x1"));
  121. // // console.log(await pledge.getProductInfo());
  122. // // 1710317648n
  123. // // 1710317653n
  124. // // 質押體現利息
  125. // // await pledge.withdraAllInterest();
  126. // // console.log(await fil.balanceOf(owner.address));
  127. // // console.log(await fil.balanceOf(otherAccount.address));
  128. // // console.log("池子的FIL餘額:",ethers.utils.formatEther(await fil.balanceOf(pool.address)));
  129. // // 1 000 000 000 000 000 000
  130. // // console.log('池子餘額',await fil.balanceOf(pool.address))
  131. // // 推薦人的收益記錄
  132. // // console.log('當前地址:'+owner.address);
  133. // // console.log('邀請地址:'+otherAccount.address);
  134. // // 獲取所有的邀請成員
  135. // // console.log("所有被邀請成員",await pledge.getAllInvitationMember(otherAccount.address))
  136. // // 獲取綁定信息
  137. // // console.log("綁定信息",await pledge.recommendObj(owner.address))
  138. // // 邀請: 獲取當前所有可提取的收益
  139. // // console.log("獲取當前所有可提取的收益",await pledge.getOwnerAllInvitationWithdrawAmout(otherAccount.address))
  140. // // 邀請: 獲取所有下級質押信息
  141. // // console.log("所有被邀請人的質押信息",await pledge.getOwnerInvitationPledges(otherAccount.address))
  142. // // 获取nft数量
  143. // // console.log("NFT数量:+", await nft.balanceOf(owner.address));
  144. // // 获取所有质押信息
  145. // // console.log(await pledge.getOwnerAllPledgeInfo(owner.address));
  146. // // 获取所有NFT tokenId
  147. // // console.log(await pledge.getOwnerAllTokens(owner.address))
  148. // // 获取所有利息
  149. // // console.log(await pledge.getWithdrawbleAmount(owner.address));
  150. // // await setBlockTimestamp()
  151. // // console.log(await pledge.getWithdrawbleAmount(owner.address));
  152. // // await setBlockTimestamp()
  153. // // console.log(await pledge.getWithdrawbleAmount(owner.address));
  154. // // await setBlockTimestamp()
  155. // // console.log(await pledge.getWithdrawbleAmount(owner.address));
  156. // // await setBlockTimestamp()
  157. // });
  158. // it("Test Admin", async function () {
  159. // const { nft, otherAccount,pledge,owner } = await loadFixture(deployOneYearLockFixture);
  160. // // await nft.connect(otherAccount.address).setPledgeAddress(pledge.address);
  161. // // await nft.connect(otherAccount.address).addAdmin([otherAccount.address]);
  162. // // await nft.setPledgeAddress(pledge.address);
  163. // // await nft.addAdmin([otherAccount.address,nft.address])
  164. // // console.log(await nft.getAdmin());
  165. // // console.log(await nft.pledgeAddress());
  166. // // await nft.deleteAdmin([owner.address])
  167. // // console.log(await nft.getAdmin());
  168. // });
  169. });
  170. });