问题描述
我正在使用 openzeppelin 的库来构建 erc721 智能合约,但遇到以下问题:
在运行我的测试以查看智能合约是否正确设置了 IPFS 时,它已因此挂起。以下是摩卡测试:
it('Upon minting receives a IPFS CID from minter'),async() => {
await contract.mint("Episode 1","https://ipfs.io/ipfs/QmXnesnJy8tHNtH1S2wQT2k2zTSg8BNWzvtPZ6ca69nL4n?filename=battle%20scene%20example.jpg")
var result= await episodes(0).tokenURI(1);
var expected= "https://ipfs.io/ipfs/QmXnesnJy8tHNtH1S2wQT2k2zTSg8BNWzvtPZ6ca69nL4n?filename=battle%20scene%20example.jpg";
assert.equal(result,expected)
}
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol";
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol";
import "@openzeppelin/contracts/utils/Counters.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
contract TheCondemned_Episode is ERC721URIStorage,ERC721Enumerable,Ownable {
using Counters for Counters.Counter;
Counters.Counter private _tokenIds;
string[] public episodes;
mapping(string => bool) _episodeExists;
event episodeCreated (string _episodeName,string _tokenURI);
constructor() ERC721("TheCondemned_e1","TCe1") {
}
function tokenURI(uint256 tokenId) public view override(ERC721,ERC721URIStorage) returns (string memory _tokenURI) {
super.tokenURI(tokenId);
}
function _burn(uint256 tokenId) internal override(ERC721,ERC721URIStorage) {
super._burn(tokenId);
}
function _beforetokenTransfer(address from,address to,uint256 tokenId) internal override(ERC721,ERC721Enumerable) {
super._beforetokenTransfer(from,to,tokenId);
}
function supportsInterface(bytes4 interfaceId)
public
view
override(ERC721,ERC721Enumerable)
returns (bool)
{
return super.supportsInterface(interfaceId);
}
function mint(string memory _episodeName,string memory _tokenURI) external onlyOwner {
require(!_episodeExists[_episodeName]);
require(episodes.length < 13,"Cannot make more than 13 episodes");
episodes.push(_episodeName);
_tokenIds.increment();
uint256 newNftTokenId = _tokenIds.current();
address receiver= msg.sender;
_mint(receiver,newNftTokenId);
_setTokenURI(newNftTokenId,_tokenURI);
_episodeExists[_episodeName]= true;
emit episodeCreated(_episodeName,tokenURI(newNftTokenId));
}
}
在尝试编译智能合约时,我不断收到错误消息,指出我必须覆盖上面代码中显示为已覆盖的函数。我怀疑测试结果未决的原因是因为智能合约正在运行过多的运行时试图执行 tokenURI 函数。我在正确的轨道上吗?如果是这样,通过测试的可能解决方案是什么?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)