inheritance - Solidity 中被覆盖的函数会导致测试显示挂起吗?
问题描述
我正在使用 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)
}
与此测试一起运行的 Solidity 代码如下:
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 函数。我在正确的轨道上吗?如果是这样,有哪些可能的解决方案可以通过测试?
解决方案
推荐阅读
- python - 创建的 Pdf 文件引发以下错误,文件响应没有读取属性
- python - 模块 trax.fastmath 是否已弃用?
- c++ - 返回 9x9 网格数组中指定子网格的元素?
- javascript - 将客户端变量添加到 AMP 的 GTM 变量
- lua - 如何编写将值四舍五入到最接近 16 位的函数
- python-3.x - 你如何扩大行的大小?
- core-data - 使用“==”运算符时NSDate比较失败
- vue.js - 如果它是重定向 URL,则深层链接不起作用
- chatbot - 在保留上下文的语言之间切换
- arduino - 如何使用 esptool 将 tasmota(或任何东西)闪存到 M5Stack ATOM Lite(ESP32-PICO-D4)?