function list(uint256 _tokenId, uint32 _price) external onlyWhitelisted {
require(_price >= MIN_PRICE, "Price must be at least 1 USDC");
require(ownerOf(_tokenId) == msg.sender, "Not owner of NFT");
require(s_listings[_tokenId].isActive == false, "NFT is already listed");
require(_price > 0, "Price must be greater than 0");
@> listingsCounter++;
activeListingsCounter++;
@> s_listings[_tokenId] =
Listing({seller: msg.sender, price: _price, nft: address(this), tokenId: _tokenId, isActive: true});
emit NFT_Dealers_Listed(msg.sender, listingsCounter);
}
pragma solidity ^0.8.34;
import "forge-std/Test.sol";
import "../src/NFTDealers.sol";
import "../src/MockUSDC.sol";
contract NFTDealersTest is Test {
NFTDealers public dealers;
MockUSDC public usdc;
address public owner = address(0x1);
address public alice = address(0x2);
address public bob = address(0x3);
function setUp() public {
usdc = new MockUSDC();
dealers = new NFTDealers(
owner,
address(usdc),
"Dealers",
"NFTD",
"ipfs://",
20e6
);
vm.startPrank(owner);
dealers.revealCollection();
dealers.whitelistWallet(alice);
vm.stopPrank();
usdc.mint(alice, 1000e6);
usdc.mint(bob, 1000e6);
vm.prank(alice);
usdc.approve(address(dealers), type(uint256).max);
vm.prank(bob);
usdc.approve(address(dealers), type(uint256).max);
}
function test_PoC_ListingMismatch() public {
vm.startPrank(alice);
dealers.mintNft();
dealers.mintNft();
dealers.list(2, 100e6);
vm.stopPrank();
vm.startPrank(bob);
vm.expectRevert();
dealers.buy(1);
vm.stopPrank();
(,,,uint256 tid, bool active) = dealers.s_listings(2);
assertEq(tid, 2);
assertTrue(active, "Listing is at wrong index!");
}
}