lesson-15 nftMarketplace.sol tests failed. #3277
Answered
by
TimeKeyRoll
TimeKeyRoll
asked this question in
Q&A
-
Does anyone know about this Error? repo- https://github.com/TimeKeyRoll/hardhat-nft-marketplace.git |
Beta Was this translation helpful? Give feedback.
Answered by
TimeKeyRoll
Oct 16, 2022
Replies: 2 comments 8 replies
-
@TimeKeyRoll Your custom errors do not match with the errors that are reverting from the contract. For example, this is your function; function listItem(
address nftAddress,
uint256 tokenId,
uint256 price
)
external
notListed(nftAddress, tokenId, msg.sender)
isOwner(nftAddress, tokenId, msg.sender)
{
if (price <= 0) {
revert NftMarketplace__PricemustbeAboveZero();
}
IERC721 nft = IERC721(nftAddress);
if (nft.getApproved(tokenId) != address(this)) {
revert NftMarketplace__NotApprovedForMArketPlace();
}
s_listings[nftAddress][tokenId] = Listing(price, msg.sender);
emit ItemListed(msg.sender, nftAddress, tokenId, price);
} here you can check what custom errors you are reverting. Similarly, here you are expecting to revert an error when listing is not available; it("reverts if there is no listing", async function () {
const error = `NftMarketplace__NotListed("${basicNft.address}", ${TOKEN_ID})`
await expect(
NftMarketplace.cancelListing(basicNft.address, TOKEN_ID)
).to.be.revertedWithCustomError(NftMarketplace, error)
}) But here you did not revert any custom error; function cancelListing(address nftAddress, uint256 tokenId)
external
isOwner(nftAddress, tokenId, msg.sender)
isListed(nftAddress, tokenId)
{
delete (s_listings[nftAddress][tokenId]);
emit ItemCancelled(msg.sender, nftAddress, tokenId);
} |
Beta Was this translation helpful? Give feedback.
1 reply
-
Beta Was this translation helpful? Give feedback.
7 replies
Answer selected by
TimeKeyRoll
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@abossofmyself