PatrickAlphaC / hardhat-nft-marketplace-fcc

114 stars 97 forks source link

Lesson 15: NftMarketplace.sol Tests #31

Closed Spencer-Sch closed 1 year ago

Spencer-Sch commented 1 year ago

I am attempting to achieve 100% test coverage of the NftMarketplace.sol contract and I have one line left to test. This one: https://github.com/PatrickAlphaC/hardhat-nft-marketplace-fcc/blob/1a7e27a9e7a9a22c0045b05f4fb2d49552a7e185/contracts/NftMarketplace.sol#L206C74-L206C74 I need a way to get this line to return false.

This issue on stack exchange describes how to get the .call{} to fail by calling it from a contract (TestHelper.sol) that cannot receive funds. This is nearly the answer to my problem accept for an issue...

The withdrawProceeds() function in NftMarketplace.sol requires msg.sender to have a balance greater than 0 in the s_proceeds mapping mapped to the address being used to call withdrawProceeds().

Is there a way to give TestHelper a balance in s_proceeds using waffle/chai/ethers/hardhat?

In previous tests, the process to fund an account was:

  1. Have account A list an nft
  2. Have account B buy the nft (this funds s_proceeds[A.address])

I have been unsuccessful in having TestHelper:

  1. mint a token
  2. list a token
  3. approve a token on the marketplace So, the process of listing with TestHelper and buying with account B doesn't work to fund s_proceeds[TestHelper.address].

Perhaps there's another way to test this line that doesn't involve all of this, but I don't know what it is. Any advice is welcome. Thank you!

PatrickAlphaC commented 1 year ago

Love how you're going the extra mile here.

Can you:

  1. Make this a discusson on the full repo? https://github.com/smartcontractkit/full-blockchain-solidity-course-js/

Optionally, this might be a great stack exchange ETH question yourself!