Skip to content

Instantly share code, notes, and snippets.

@dabit3
Last active November 22, 2022 20:36
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dabit3/8d41d27c60b4f16b105bd2479013c172 to your computer and use it in GitHub Desktop.
Save dabit3/8d41d27c60b4f16b105bd2479013c172 to your computer and use it in GitHub Desktop.
NFTMarketplace V2 Test
/* test/sample-test.js */
describe("NFTMarket", function() {
it("Should create and execute market sales", async function() {
/* deploy the marketplace */
const NFTMarketplace = await ethers.getContractFactory("NFTMarketplace")
const nftMarketplace = await NFTMarketplace.deploy()
await nftMarketplace.deployed()
let listingPrice = await nftMarketplace.getListingPrice()
listingPrice = listingPrice.toString()
const auctionPrice = ethers.utils.parseUnits('1', 'ether')
/* create two tokens */
await nftMarketplace.createToken("https://www.mytokenlocation.com", auctionPrice, { value: listingPrice })
await nftMarketplace.createToken("https://www.mytokenlocation2.com", auctionPrice, { value: listingPrice })
const [_, buyerAddress] = await ethers.getSigners()
/* execute sale of token to another user */
await nftMarketplace.connect(buyerAddress).createMarketSale(1, { value: auctionPrice })
/* resell a token */
await nftMarketplace.connect(buyerAddress).resellToken(1, auctionPrice, { value: listingPrice })
/* query for and return the unsold items */
items = await nftMarketplace.fetchMarketItems()
items = await Promise.all(items.map(async i => {
const tokenUri = await nftMarketplace.tokenURI(i.tokenId)
let item = {
price: i.price.toString(),
tokenId: i.tokenId.toString(),
seller: i.seller,
owner: i.owner,
tokenUri
}
return item
}))
console.log('items: ', items)
})
})
@SkyWarrior123
Copy link

Hey, Nadir there's been an issue in the code

0 passing (729ms)
  1 failing

  1) NFTMarket
       Should create and execute market sales:
     TypeError: Cannot read properties of undefined (reading 'utils')
      at Context.<anonymous> (test/NftMarketplace.test.js:15:33)
      at processTicksAndRejections (node:internal/process/task_queues:96:5)
      at runNextTicks (node:internal/process/task_queues:65:3)
      at listOnTimeout (node:internal/timers:528:9)
      at processTimers (node:internal/timers:502:7)

It gives me this error on running the command

npx hardhat compile

Please look into the matter and reply fast.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment