|
| 1 | +// SPDX-License-Identifier: MIT |
| 2 | +pragma solidity 0.8.1; |
| 3 | + |
| 4 | +import {Test} from "forge-std/Test.sol"; |
| 5 | +import {ERC721MarketplaceFacet} from "../../contracts/Aavegotchi/facets/ERC721MarketplaceFacet.sol"; |
| 6 | + |
| 7 | +contract MockERC721ListingToken { |
| 8 | + mapping(uint256 => address) internal owners; |
| 9 | + mapping(address => mapping(address => bool)) internal operatorApprovals; |
| 10 | + mapping(uint256 => address) internal tokenApprovals; |
| 11 | + |
| 12 | + function mint(address _to, uint256 _tokenId) external { |
| 13 | + owners[_tokenId] = _to; |
| 14 | + } |
| 15 | + |
| 16 | + function ownerOf(uint256 _tokenId) external view returns (address) { |
| 17 | + return owners[_tokenId]; |
| 18 | + } |
| 19 | + |
| 20 | + function setApprovalForAll(address _operator, bool _approved) external { |
| 21 | + operatorApprovals[msg.sender][_operator] = _approved; |
| 22 | + } |
| 23 | + |
| 24 | + function isApprovedForAll(address _owner, address _operator) external view returns (bool) { |
| 25 | + return operatorApprovals[_owner][_operator]; |
| 26 | + } |
| 27 | + |
| 28 | + function approve(address _to, uint256 _tokenId) external { |
| 29 | + require(msg.sender == owners[_tokenId], "MockERC721ListingToken: not owner"); |
| 30 | + tokenApprovals[_tokenId] = _to; |
| 31 | + } |
| 32 | + |
| 33 | + function getApproved(uint256 _tokenId) external view returns (address) { |
| 34 | + return tokenApprovals[_tokenId]; |
| 35 | + } |
| 36 | +} |
| 37 | + |
| 38 | +contract ERC721ListingAddEventTimestampTest is Test { |
| 39 | + event ERC721ListingAdd( |
| 40 | + uint256 indexed listingId, |
| 41 | + address indexed seller, |
| 42 | + address erc721TokenAddress, |
| 43 | + uint256 erc721TokenId, |
| 44 | + uint256 indexed category, |
| 45 | + uint256 time |
| 46 | + ); |
| 47 | + |
| 48 | + ERC721MarketplaceFacet internal marketplaceFacet; |
| 49 | + MockERC721ListingToken internal mockToken; |
| 50 | + |
| 51 | + address internal constant SELLER = address(0xBEEF); |
| 52 | + uint256 internal constant TOKEN_ID = 11; |
| 53 | + uint256 internal constant CATEGORY = 0; |
| 54 | + uint256 internal constant PRICE = 1 ether; |
| 55 | + |
| 56 | + function setUp() public { |
| 57 | + marketplaceFacet = new ERC721MarketplaceFacet(); |
| 58 | + mockToken = new MockERC721ListingToken(); |
| 59 | + |
| 60 | + mockToken.mint(SELLER, TOKEN_ID); |
| 61 | + |
| 62 | + vm.prank(SELLER); |
| 63 | + mockToken.setApprovalForAll(address(marketplaceFacet), true); |
| 64 | + } |
| 65 | + |
| 66 | + function testListingAddEventUsesTimestampFieldForTime() public { |
| 67 | + uint256 expectedTime = block.timestamp; |
| 68 | + |
| 69 | + vm.startPrank(SELLER); |
| 70 | + vm.expectEmit(true, true, false, true, address(marketplaceFacet)); |
| 71 | + emit ERC721ListingAdd(1, SELLER, address(mockToken), TOKEN_ID, CATEGORY, expectedTime); |
| 72 | + |
| 73 | + marketplaceFacet.addERC721Listing(address(mockToken), TOKEN_ID, CATEGORY, PRICE); |
| 74 | + vm.stopPrank(); |
| 75 | + } |
| 76 | +} |
0 commit comments