Skip to content
This repository was archived by the owner on Dec 23, 2024. It is now read-only.

Commit 2b38980

Browse files
committed
standardize tests
1 parent 60da4f4 commit 2b38980

File tree

3 files changed

+136
-4
lines changed

3 files changed

+136
-4
lines changed

contracts/test/modules/Asks/Omnibus/AsksDataStorage.t.sol

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,6 @@ contract StorageTestBaseMinimal is AsksDataStorage {
8080
}
8181
}
8282

83-
/// @title
84-
/// @notice
8583
contract AsksDataStorageTest is DSTest {
8684
VM internal vm;
8785

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
// SPDX-License-Identifier: GPL-3.0
2+
pragma solidity 0.8.10;
3+
4+
import {DSTest} from "ds-test/test.sol";
5+
6+
import {OffersDataStorage} from "../../../../modules/Offers/Omnibus/OffersDataStorage.sol";
7+
import {VM} from "../../../utils/VM.sol";
8+
9+
contract StorageTestBaseFull is OffersDataStorage {
10+
uint256 offerCounter;
11+
12+
function newOffer(address tokenContract, uint256 tokenId) public {
13+
StoredOffer storage offer = offers[tokenContract][tokenId][++offerCounter];
14+
offer.maker = address(0x111);
15+
offer.amount = 0.4 ether;
16+
_setETHorERC20Currency(offer, address(0x113));
17+
_setListingFee(offer, 1, address(0x115));
18+
_setFindersFee(offer, 2);
19+
_setExpiry(offer, uint96(block.timestamp + 1_000));
20+
}
21+
22+
function getExpectedActiveFeatures() public pure returns (uint32) {
23+
return FEATURE_MASK_LISTING_FEE | FEATURE_MASK_FINDERS_FEE | FEATURE_MASK_EXPIRY | FEATURE_MASK_ERC20_CURRENCY;
24+
}
25+
26+
function hasFeature(
27+
address tokenContract,
28+
uint256 tokenId,
29+
uint32 feature,
30+
uint256 offerId
31+
) public view returns (bool) {
32+
StoredOffer storage offer = offers[tokenContract][tokenId][offerId];
33+
return _hasFeature(offer.features, feature);
34+
}
35+
36+
function getFullOffer(
37+
address tokenContract,
38+
uint256 tokenId,
39+
uint256 offerId
40+
) public view returns (FullOffer memory) {
41+
return _getFullOffer(offers[tokenContract][tokenId][offerId]);
42+
}
43+
44+
function updatePrice(
45+
address tokenContract,
46+
uint256 tokenId,
47+
address currency,
48+
uint256 amount,
49+
uint256 offerId
50+
) public {
51+
StoredOffer storage offer = offers[tokenContract][tokenId][offerId];
52+
_setETHorERC20Currency(offer, currency);
53+
offer.amount = amount;
54+
}
55+
}
56+
57+
contract StorageTestBaseMinimal is OffersDataStorage {
58+
uint256 offerCounter;
59+
60+
function newOffer(address tokenContract, uint256 tokenId) public {
61+
StoredOffer storage offer = offers[tokenContract][tokenId][++offerCounter];
62+
offer.maker = address(0x111);
63+
offer.amount = 0.4 ether;
64+
offer.features = 0;
65+
}
66+
67+
function getExpectedActiveFeatures() public pure returns (uint32) {
68+
return 0;
69+
}
70+
71+
function hasFeature(
72+
address tokenContract,
73+
uint256 tokenId,
74+
uint32 feature,
75+
uint256 offerId
76+
) public view returns (bool) {
77+
StoredOffer storage offer = offers[tokenContract][tokenId][offerId];
78+
return _hasFeature(offer.features, feature);
79+
}
80+
81+
function getFullOffer(
82+
address tokenContract,
83+
uint256 tokenId,
84+
uint256 offerId
85+
) public view returns (FullOffer memory) {
86+
return _getFullOffer(offers[tokenContract][tokenId][offerId]);
87+
}
88+
}
89+
90+
contract OffersDataStorageTest is DSTest {
91+
VM internal vm;
92+
93+
uint32 constant FEATURE_MASK_LISTING_FEE = 1 << 3;
94+
uint32 constant FEATURE_MASK_FINDERS_FEE = 1 << 4;
95+
uint32 constant FEATURE_MASK_EXPIRY = 1 << 5;
96+
uint32 constant FEATURE_MASK_ERC20_CURRENCY = 1 << 6;
97+
98+
function test_OfferStorageMinimalInit() public {
99+
StorageTestBaseMinimal dataStorage = new StorageTestBaseMinimal();
100+
dataStorage.newOffer(address(0x112), 21);
101+
OffersDataStorage.FullOffer memory offer = dataStorage.getFullOffer(address(0x112), 21, 1);
102+
assertEq(offer.amount, 0.4 ether, "price wrong");
103+
assertEq(offer.maker, address(0x111), "seller wrong");
104+
assertEq(offer.expiry, 0, "incorrect expiry");
105+
assertEq(offer.currency, address(0), "incorrect currency");
106+
assertEq(offer.findersFeeBps, 0, "incorrect finders fee");
107+
assertEq(offer.listingFeeBps, 0, "incorrect listing fee");
108+
assertEq(offer.listingFeeRecipient, address(0), "incorrect listing fee");
109+
}
110+
111+
function test_OfferStorageInit() public {
112+
StorageTestBaseFull dataStorage = new StorageTestBaseFull();
113+
dataStorage.newOffer(address(0x121), 21);
114+
OffersDataStorage.FullOffer memory offer = dataStorage.getFullOffer(address(0x121), 21, 1);
115+
assertEq(offer.amount, 0.4 ether, "price wrong");
116+
assertEq(offer.maker, address(0x111), "seller wrong");
117+
assertEq(offer.expiry, block.timestamp + 1_000, "incorrect expiry");
118+
assertEq(offer.currency, address(0x113), "incorrect currency");
119+
assertEq(offer.findersFeeBps, 2, "incorrect finders fee");
120+
assertEq(offer.listingFeeBps, 1, "incorrect listing fee");
121+
assertEq(offer.listingFeeRecipient, address(0x115), "incorrect listing fee");
122+
}
123+
124+
function test_OfferStorageUpdatePrice() public {
125+
StorageTestBaseFull dataStorage = new StorageTestBaseFull();
126+
dataStorage.newOffer(address(0x121), 21);
127+
OffersDataStorage.FullOffer memory offer = dataStorage.getFullOffer(address(0x121), 21, 1);
128+
assertEq(offer.amount, 0.4 ether, "price wrong");
129+
assertEq(offer.currency, address(0x113), "incorrect currency");
130+
dataStorage.updatePrice(address(0x121), 21, address(0), 1 ether, 1);
131+
offer = dataStorage.getFullOffer(address(0x121), 21, 1);
132+
assertEq(offer.amount, 1 ether, "price wrong");
133+
assertEq(offer.currency, address(0), "incorrect currency");
134+
assertTrue(!dataStorage.hasFeature(address(0x121), 21, FEATURE_MASK_ERC20_CURRENCY, 1));
135+
}
136+
}

contracts/test/modules/ReserveAuction/Omnibus/ReserveAuctionDataStorage.t.sol

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,6 @@ contract StorageTestBaseMinimal is ReserveAuctionDataStorage {
5656
}
5757
}
5858

59-
/// @title
60-
/// @notice
6159
contract AuctionDataStorageTest is DSTest {
6260
uint32 constant FEATURE_MASK_LISTING_FEE = 1 << 3;
6361
uint32 constant FEATURE_MASK_FINDERS_FEE = 1 << 4;

0 commit comments

Comments
 (0)