How to test incrementation and decrementation for smart contracts using Foundry

I am currently in my final testing phase of testing my smart contract for my NFT Marketplace(using the sepolia test net) however there are two pieces of functionality that I have left to test and that is incrementation and decrementation. Since OpenZeppelin removed Counters.Sol, I now have no idea how to write out my tests for incrementing and decrementing variables/values in my contract. Here is my code taking my sellListing Function as an example(along with my test for it).

   function sell(
    uint256 _tokenId,
    uint256 _price,
    address _seller,
    address _owner,
    address _buyer
)external payable returns(
    address, 
    uint256, 
    uint256) 
{
require(balanceOf[_buyer] <= _price, "Insufficient funds to purchase NFT");
    balanceOf[_buyer] <= _price;
require(_seller == _owner, "Seller is not the current owner of the NFT");
    _seller == _owner;
require(msg.value == _price, "Price must be the correct selling price of the NFT");
    msg.value == _price;
require(_buyer == msg.sender, "Buyer not the caller of the transaction");
    _buyer ==msg.sender;

    itemsSold++;
    tokenIds++;
    _tokenSupply--;
    uint256 newItemsSold = currentItemsSold;

    owner = _owner;

    return(_owner, _tokenId, newItemsSold);

}

And here is my test for this function.

function testSellFunction() public payable{

    address ownerOfNft;
    uint256 priceOfNft;
    uint256 balanceOfBuyer;
       

    address seller = msg.sender; 
    assertEq(seller, msg.sender, "The address calling this function must be the seller of the NFT");
    address sellerOfNft = ownerOfNft;
    assertEq(sellerOfNft, ownerOfNft, "Seller must be the owner of this NFT");

    assertGe(balanceOfBuyer, priceOfNft, "Balance must be higher in order to purchase NFT");
       
    uint256 nftPrice = msg.value;
    assertEq(nftPrice, msg.value,"Price must be the correct selling price of the NFT");

}

If you guys have any other criticisms of my code please feel free to say something! I am always trying to learn and get as much feedback and tips as I can! Thank you all in advance:)

I tried to migrate from the Counters.sol contract functionality from OpenZeppelin which I believe I did, however I am not too sure on how to test this functionality using Foundry. So I am completely missing that part of my test.

Leave a Comment