diff --git a/contracts/test/modules/Asks/Omnibus/AsksDataStorage.t.sol b/contracts/test/modules/Asks/Omnibus/AsksDataStorage.t.sol index f59356a6..8a69cb6f 100644 --- a/contracts/test/modules/Asks/Omnibus/AsksDataStorage.t.sol +++ b/contracts/test/modules/Asks/Omnibus/AsksDataStorage.t.sol @@ -80,8 +80,6 @@ contract StorageTestBaseMinimal is AsksDataStorage { } } -/// @title -/// @notice contract AsksDataStorageTest is DSTest { VM internal vm; diff --git a/contracts/test/modules/Offers/Omnibus/OffersDataStorage.t.sol b/contracts/test/modules/Offers/Omnibus/OffersDataStorage.t.sol new file mode 100644 index 00000000..a446cf92 --- /dev/null +++ b/contracts/test/modules/Offers/Omnibus/OffersDataStorage.t.sol @@ -0,0 +1,136 @@ +// SPDX-License-Identifier: GPL-3.0 +pragma solidity 0.8.10; + +import {DSTest} from "ds-test/test.sol"; + +import {OffersDataStorage} from "../../../../modules/Offers/Omnibus/OffersDataStorage.sol"; +import {VM} from "../../../utils/VM.sol"; + +contract StorageTestBaseFull is OffersDataStorage { + uint256 offerCounter; + + function newOffer(address tokenContract, uint256 tokenId) public { + StoredOffer storage offer = offers[tokenContract][tokenId][++offerCounter]; + offer.maker = address(0x111); + offer.amount = 0.4 ether; + _setETHorERC20Currency(offer, address(0x113)); + _setListingFee(offer, 1, address(0x115)); + _setFindersFee(offer, 2); + _setExpiry(offer, uint96(block.timestamp + 1_000)); + } + + function getExpectedActiveFeatures() public pure returns (uint32) { + return FEATURE_MASK_LISTING_FEE | FEATURE_MASK_FINDERS_FEE | FEATURE_MASK_EXPIRY | FEATURE_MASK_ERC20_CURRENCY; + } + + function hasFeature( + address tokenContract, + uint256 tokenId, + uint32 feature, + uint256 offerId + ) public view returns (bool) { + StoredOffer storage offer = offers[tokenContract][tokenId][offerId]; + return _hasFeature(offer.features, feature); + } + + function getFullOffer( + address tokenContract, + uint256 tokenId, + uint256 offerId + ) public view returns (FullOffer memory) { + return _getFullOffer(offers[tokenContract][tokenId][offerId]); + } + + function updatePrice( + address tokenContract, + uint256 tokenId, + address currency, + uint256 amount, + uint256 offerId + ) public { + StoredOffer storage offer = offers[tokenContract][tokenId][offerId]; + _setETHorERC20Currency(offer, currency); + offer.amount = amount; + } +} + +contract StorageTestBaseMinimal is OffersDataStorage { + uint256 offerCounter; + + function newOffer(address tokenContract, uint256 tokenId) public { + StoredOffer storage offer = offers[tokenContract][tokenId][++offerCounter]; + offer.maker = address(0x111); + offer.amount = 0.4 ether; + offer.features = 0; + } + + function getExpectedActiveFeatures() public pure returns (uint32) { + return 0; + } + + function hasFeature( + address tokenContract, + uint256 tokenId, + uint32 feature, + uint256 offerId + ) public view returns (bool) { + StoredOffer storage offer = offers[tokenContract][tokenId][offerId]; + return _hasFeature(offer.features, feature); + } + + function getFullOffer( + address tokenContract, + uint256 tokenId, + uint256 offerId + ) public view returns (FullOffer memory) { + return _getFullOffer(offers[tokenContract][tokenId][offerId]); + } +} + +contract OffersDataStorageTest is DSTest { + VM internal vm; + + uint32 constant FEATURE_MASK_LISTING_FEE = 1 << 3; + uint32 constant FEATURE_MASK_FINDERS_FEE = 1 << 4; + uint32 constant FEATURE_MASK_EXPIRY = 1 << 5; + uint32 constant FEATURE_MASK_ERC20_CURRENCY = 1 << 6; + + function test_OfferStorageMinimalInit() public { + StorageTestBaseMinimal dataStorage = new StorageTestBaseMinimal(); + dataStorage.newOffer(address(0x112), 21); + OffersDataStorage.FullOffer memory offer = dataStorage.getFullOffer(address(0x112), 21, 1); + assertEq(offer.amount, 0.4 ether, "price wrong"); + assertEq(offer.maker, address(0x111), "seller wrong"); + assertEq(offer.expiry, 0, "incorrect expiry"); + assertEq(offer.currency, address(0), "incorrect currency"); + assertEq(offer.findersFeeBps, 0, "incorrect finders fee"); + assertEq(offer.listingFeeBps, 0, "incorrect listing fee"); + assertEq(offer.listingFeeRecipient, address(0), "incorrect listing fee"); + } + + function test_OfferStorageInit() public { + StorageTestBaseFull dataStorage = new StorageTestBaseFull(); + dataStorage.newOffer(address(0x121), 21); + OffersDataStorage.FullOffer memory offer = dataStorage.getFullOffer(address(0x121), 21, 1); + assertEq(offer.amount, 0.4 ether, "price wrong"); + assertEq(offer.maker, address(0x111), "seller wrong"); + assertEq(offer.expiry, block.timestamp + 1_000, "incorrect expiry"); + assertEq(offer.currency, address(0x113), "incorrect currency"); + assertEq(offer.findersFeeBps, 2, "incorrect finders fee"); + assertEq(offer.listingFeeBps, 1, "incorrect listing fee"); + assertEq(offer.listingFeeRecipient, address(0x115), "incorrect listing fee"); + } + + function test_OfferStorageUpdatePrice() public { + StorageTestBaseFull dataStorage = new StorageTestBaseFull(); + dataStorage.newOffer(address(0x121), 21); + OffersDataStorage.FullOffer memory offer = dataStorage.getFullOffer(address(0x121), 21, 1); + assertEq(offer.amount, 0.4 ether, "price wrong"); + assertEq(offer.currency, address(0x113), "incorrect currency"); + dataStorage.updatePrice(address(0x121), 21, address(0), 1 ether, 1); + offer = dataStorage.getFullOffer(address(0x121), 21, 1); + assertEq(offer.amount, 1 ether, "price wrong"); + assertEq(offer.currency, address(0), "incorrect currency"); + assertTrue(!dataStorage.hasFeature(address(0x121), 21, FEATURE_MASK_ERC20_CURRENCY, 1)); + } +} diff --git a/contracts/test/modules/ReserveAuction/Omnibus/ReserveAuctionDataStorage.t.sol b/contracts/test/modules/ReserveAuction/Omnibus/ReserveAuctionDataStorage.t.sol index c554f23e..32b2ef58 100644 --- a/contracts/test/modules/ReserveAuction/Omnibus/ReserveAuctionDataStorage.t.sol +++ b/contracts/test/modules/ReserveAuction/Omnibus/ReserveAuctionDataStorage.t.sol @@ -56,8 +56,6 @@ contract StorageTestBaseMinimal is ReserveAuctionDataStorage { } } -/// @title -/// @notice contract AuctionDataStorageTest is DSTest { uint32 constant FEATURE_MASK_LISTING_FEE = 1 << 3; uint32 constant FEATURE_MASK_FINDERS_FEE = 1 << 4;