Skip to content

Lesson 15: NftMarketplace.sol test #5925

@Spencer-Sch

Description

@Spencer-Sch

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions