当前位置: 首页 > news >正文

DAPP开发【09】NFT交易市场开发(hardhat测试)

测试文件下新建market.js文件
在这里插入图片描述

扁平化,将所有依赖放在tmp.sol,可以去给他人使用
npx hardhat flatten > tmp.sol
在这里插入图片描述

测试文件

const {expect} = require('chai');
const {ethers} = require('hardhat');describe('Market',async function(){//定义三个合约,两个账户let usdt,nft,market,accountA,accountB;beforeEach(async () =>{  //hardhat提供两个账户[accountA,accountB] = await ethers.getSigners();//部署三个合约const USDT = await ethers.getContractFactory('cUSDT');usdt = await USDT.deploy();const MyNFT = await ethers.getContractFactory('NFTM');nft = await MyNFT.deploy(accountA.address);const Market = await ethers.getContractFactory('Market');market = await Market.deploy(usdt.target,nft.target);//给账户1挖1usdt的 erc20  部署erc20合约是就给账户A了1e26的erc20//给账户2挖两个nftawait nft.safeMint(accountB.address);await nft.safeMint(accountB.address);await nft.connect(accountB).setApprovalForAll(accountA.address,true);//给market授权花费A的钱(默认连接的就是第一个用户)//await usdt.connect(accountA).approve(market.target,"1e26");await usdt.approve(market.target,"100000000000000000000000000");});//验证erc20变量==usdt的地址it('its erc20 address should be usdt',async function(){expect(await market.erc20()).to.equal(usdt.target);});it('its erc721 address should be MyNft',async function(){expect(await market.erc721()).to.equal(nft.target);});it('accountB should have two nfts',async function(){expect(await nft.balanceOf(accountB.address)).to.equals(2);});it('accountA should have 1e26 usdt',async function(){expect(await usdt.balanceOf(accountA.address)).to.equals("100000000000000000000000000");});it('accountB can list 2 nft to market',async function(){const price = "0x0000000000000000000000000000000000000000000000000001c6bf52634000";//await nft.connect(accountB).safeTransferFrom(accountB.address,market.target,0,price);//报错//TypeError: ambiguous function description (i.e. matches "safeTransferFrom(address,address,uint256)", //"safeTransferFrom(address,address,uint256,bytes)") (argument="key", value="safeTransferFrom", code=INVALID_ARGUMENT, version=6.9.0)//ambiguous 混淆同名函数,即使参数不一样,也分不出来,所以用下面的方法,明确选择器的名字//这里应该是B来调用进行上架,但是默认是a,老师忘记怎么连接了//于是在上面定义  await nft.connect(accountB).setApprovalForAll(accountA.address,true);//b允许a使用它的nftexpect(await nft['safeTransferFrom(address,address,uint256,bytes)'](accountB.address,market.target,0,price)).to.emit(market,"NewOrder");expect(await nft['safeTransferFrom(address,address,uint256,bytes)'](accountB.address,market.target,1,price)).to.emit(market,"NewOrder");expect(await nft.balanceOf(accountB.address)).to.equal(0);expect(await nft.balanceOf(market.target)).to.equal(2);expect(await market.isListed(0)).to.equal(true);expect(await market.isListed(1)).to.equal(true);expect((await market.getAllNFTs())[0][0]).to.equal(accountB.address);expect((await market.getAllNFTs())[0][1]).to.equal(0);expect((await market.getAllNFTs())[0][2]).to.equal(price);expect((await market.getAllNFTs())[1][0]).to.equal(accountB.address);expect((await market.getAllNFTs())[1][1]).to.equal(1);expect((await market.getAllNFTs())[1][2]).to.equal(price);expect(await market.getOrderLength()).to.equal(2);expect((await market.connect(accountB).getMyNFTs())[0][0]).to.equal(accountB.address);expect((await market.connect(accountB).getMyNFTs())[0][1]).to.equal(0);expect((await market.connect(accountB).getMyNFTs())[0][2]).to.equal(price);expect((await market.connect(accountB).getMyNFTs())[1][0]).to.equal(accountB.address);expect((await market.connect(accountB).getMyNFTs())[1][1]).to.equal(1);expect((await market.connect(accountB).getMyNFTs())[1][2]).to.equal(price);});});
http://www.lryc.cn/news/253454.html

相关文章:

  • 【Spring Boot】如何通过RestTemplate获取另一个服务的接口返回信息
  • 文字识别(OCR)专题——基于NCNN轻量级PaddleOCRv4模型C++推理
  • ❀My学习Linux命令小记录(14)❀
  • SqlServer存储过程中使用in
  • Selenium+Unittest+HTMLTestRunner框架更改为Selenium+Pytest+Allure(二)
  • Kotlin Lambda使用
  • 华容道问题求解第一部分_思路即方案设计
  • 测试---UI自动化测试介绍
  • DHCP Host Name
  • uniapp到底用什么ui框架最合适-关于uni-app的ui库、ui框架、ui组件
  • Flask 最佳实践(二)
  • 【MATLAB源码-第93期】基于matlab的白鲸优化算法(BWO)和鲸鱼优化算法(WOA)机器人栅格路径规划对比。
  • nodejs微信小程序+python+PHP在线购票系统的设计与实现-计算机毕业设计推荐
  • 卷积神经网络训练情感分析
  • github新建项目
  • CRC(循环冗余校验)直接计算和查表法
  • 【算法思考记录】力扣2952. 需要添加的硬币的最小数量【C++,思路挖掘,贪心与证明】
  • 用友NC JiuQiClientReqDispatch反序列化RCE漏洞复现
  • Linux:docker镜像的创建(5)
  • 数据结构与算法-D2D3线性表之顺序表
  • 01_W5500简介
  • 异常 Exception 练习题 (未完成)
  • Linux系统编程:并发与信号总结
  • Jmeter 接口-加密信息发送(一百九十九)
  • 微信小程序nodejs+vue+uniapp视力保养眼镜店连锁预约系统
  • 掌握Vue侦听器(watch)的应用
  • SAP-PP:PP顾问管理系统的相关建议
  • Unity资源路径与读取
  • “大+小模型”赋能油气行业高质量发展
  • 【win32_004】字符串处理函数