-
-
Save stonegao/54132a5f590e4054f2cf1072ac7a3139 to your computer and use it in GitHub Desktop.
Testing the Metaverse Marketplace contract
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* test/sample-test.js */ | |
describe("NFTMarket", function() { | |
it("Should create and execute market sales", async function() { | |
/* deploy the marketplace */ | |
const Market = await ethers.getContractFactory("NFTMarket") | |
const market = await Market.deploy() | |
await market.deployed() | |
const marketAddress = market.address | |
/* deploy the NFT contract */ | |
const NFT = await ethers.getContractFactory("NFT") | |
const nft = await NFT.deploy(marketAddress) | |
await nft.deployed() | |
const nftContractAddress = nft.address | |
let listingPrice = await market.getListingPrice() | |
listingPrice = listingPrice.toString() | |
const auctionPrice = ethers.utils.parseUnits('1', 'ether') | |
/* create two tokens */ | |
await nft.createToken("https://www.mytokenlocation.com") | |
await nft.createToken("https://www.mytokenlocation2.com") | |
/* put both tokens for sale */ | |
await market.createMarketItem(nftContractAddress, 1, auctionPrice, { value: listingPrice }) | |
await market.createMarketItem(nftContractAddress, 2, auctionPrice, { value: listingPrice }) | |
const [_, buyerAddress] = await ethers.getSigners() | |
/* execute sale of token to another user */ | |
await market.connect(buyerAddress).createMarketSale(nftContractAddress, 1, { value: auctionPrice}) | |
/* query for and return the unsold items */ | |
let items = await market.fetchMarketItems() | |
items = await Promise.all(items.map(async i => { | |
const tokenUri = await nft.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) | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment