Lesson 15 : Error: VM Exception while processing transaction: reverted with custom error 'NftMarketplace__PriceNotMet("0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512", 0, 100000000000000000)' #2599
Answered
by
othaime-en
khodehSoroush
asked this question in
Q&A
-
I got this error while I try to run the first test. contract : //my code here 👇
function buyItem(address nftAddress, uint256 tokenId)
external
payable
nonReentrant
isListed(nftAddress, tokenId)
{
Listing memory listedItem = s_listings[nftAddress][tokenId];
if (msg.value < listedItem.price) {
revert NftMarketplace__PriceNotMet(
nftAddress,
tokenId,
listedItem.price
);
}
s_proceeds[listedItem.seller] =
s_proceeds[listedItem.seller] +
msg.value;
delete (s_listings[nftAddress][tokenId]);
IERC721(nftAddress).safeTransferFrom(
listedItem.seller,
msg.sender,
tokenId
);
emit ItemBought(msg.sender, nftAddress, tokenId, listedItem.price);
}
} my test 👇 const { assert, expect } = require("chai");
const { network, deployments, ethers, getNamedAccounts } = require("hardhat");
const { developmentChains } = require("../../helper-hardhat-config");
!developmentChains.includes(network.name)
? describe.skip
: describe("Nft Marketplace Tests", function () {
let nftMarketplace, basicNft, deployer, player;
const PRICE = ethers.utils.parseEther("0.1");
const TOKEN_ID = 0;
beforeEach(async function () {
// deployer = (await getNamedAccounts()).deployer;
// player = (await getNamedAccounts()).player;
const accounts = await ethers.getSigners();
deployer = accounts[0];
player = accounts[1];
await deployments.fixture(["all"]);
nftMarketplace = await ethers.getContract("NftMarketplace");
basicNft = await ethers.getContract("BasicNft");
await basicNft.mintNft();
await basicNft.approve(nftMarketplace.address, TOKEN_ID);
});
it("lists and can be bought", async function () {
await nftMarketplace.listItem(basicNft.address, TOKEN_ID, PRICE);
const playerConnectedNftMarketplace = nftMarketplace.connect(player);
await playerConnectedNftMarketplace.buyItem(basicNft.address, TOKEN_ID,{ value: PRICE })
;
const newOwner = await basicNft.ownerOf(TOKEN_ID);
const deployerProceeds = await nftMarketplace.getProceeds(deployer);
assert( newOwner.toString() == player.address);
assert( deployerProceeds.toString() == PRICE.toString());
});
}); deploy script 👇 const { network } = require("hardhat");
const { developmentChains } = require("../helper-hardhat-config");
const { verify } = require("../utils/verify");
module.exports = async ({ getNamedAccounts, deployments }) => {
const { deploy, log } = deployments;
const { deployer } = await getNamedAccounts();
const args = [];
const nftMarketPlace = await deploy("NftMarketplace", {
from: deployer,
args: args,
log: true,
waitConfirmations: network.config.blockConfirmations || 1,
});
if (
!developmentChains.includes(network.name) &&
process.env.ETHERSCAN_API_KEY
) {
log("Verifying ...");
await verify(nftMarketPlace.address, args);
}
log("---------------------------------------");
};
module.exports.tags = ["all", "nftmarketplace"]; Error 👇 Nft Marketplace Tests
0 passing (1s)
my hardhat-config.js accounts sections 👇 namedAccounts: {
deployer: {
default: 0,
1: 0,
},
player: {
default: 1,
},
}, I'd be glad to help me with this problem 🫂 |
Beta Was this translation helpful? Give feedback.
Answered by
othaime-en
Sep 15, 2022
Replies: 1 comment 1 reply
-
Hey @khodehSoroush i see an error in this section
the
Try that and tell me if it works |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
khodehSoroush
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey @khodehSoroush i see an error in this section
the
{ value: PRICE}
should be inside the function call. It should be something like thisTry that and tell me if it works