Background of Problem:
I am developing an NFT Marketplace. In its workflow, the admin (deployer of the smart contract) adds NFTs to the marketplace, and at that time these NFTs are owned by the Marketplace smart contract.
Now when a user comes to buy a particular NFT we have to transfer the ownership from the smart contract address to the signer/wallet address.
Actual Problem:
While writing chai tests, I need to call the function buyFromMarketplace
written in marketplace contract, which transfers the ownership of nft there. I am trying connecting the marketplace smart contract address (But I can't find any way to do it)
I've tried to do it this way (But I knew this won't work)
await nft.connect(marketplace).approve(addr1.address, 0);
Also tried to send a raw address while connecting to the NFT smart contract before calling approve
by calling marketplace.address
.
In this thread, something similar is being done but NOT in testing
While a similar thing is done with ERC20 tokens here.
Edit: I found the solution and posted in answers, maybe it helps someone in the future!