Skip to content

Commit 57baf77

Browse files
authored
Merge pull request ProjectOpenSea#504 from ProjectOpenSea/test-native-offer-fulfill-reverts
Test that "fulfill" methods revert on Orders with Native offer items
2 parents 06bf918 + ebee871 commit 57baf77

File tree

4 files changed

+294
-0
lines changed

4 files changed

+294
-0
lines changed

test/foundry/FulfillAdvancedOrder.t.sol

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,64 @@ contract FulfillAdvancedOrder is BaseOrderTest {
8282
}
8383
}
8484

85+
function testNoNativeOffersFulfillAdvanced(uint8[8] memory itemTypes)
86+
public
87+
{
88+
uint256 tokenId;
89+
for (uint256 i; i < 8; i++) {
90+
ItemType itemType = ItemType(itemTypes[i] % 4);
91+
if (itemType == ItemType.NATIVE) {
92+
addEthOfferItem(1);
93+
} else if (itemType == ItemType.ERC20) {
94+
addErc20OfferItem(1);
95+
} else if (itemType == ItemType.ERC1155) {
96+
test1155_1.mint(alice, tokenId, 1);
97+
addErc1155OfferItem(tokenId, 1);
98+
} else {
99+
test721_1.mint(alice, tokenId);
100+
addErc721OfferItem(tokenId);
101+
}
102+
tokenId++;
103+
}
104+
addEthOfferItem(1);
105+
106+
addEthConsiderationItem(alice, 1);
107+
108+
test(
109+
this.noNativeOfferItemsFulfillAdvanced,
110+
Context(consideration, empty, 0, 0)
111+
);
112+
test(
113+
this.noNativeOfferItemsFulfillAdvanced,
114+
Context(referenceConsideration, empty, 0, 0)
115+
);
116+
}
117+
118+
function noNativeOfferItemsFulfillAdvanced(Context memory context)
119+
external
120+
stateless
121+
{
122+
configureOrderParameters(alice);
123+
uint256 counter = context.consideration.getCounter(alice);
124+
_configureOrderComponents(counter);
125+
bytes32 orderHash = context.consideration.getOrderHash(
126+
baseOrderComponents
127+
);
128+
bytes memory signature = signOrder(
129+
context.consideration,
130+
alicePk,
131+
orderHash
132+
);
133+
134+
vm.expectRevert(abi.encodeWithSignature("InvalidNativeOfferItem()"));
135+
context.consideration.fulfillAdvancedOrder(
136+
AdvancedOrder(baseOrderParameters, 1, 1, signature, ""),
137+
new CriteriaResolver[](0),
138+
bytes32(0),
139+
address(0)
140+
);
141+
}
142+
85143
function testAdvancedPartialAscendingOfferAmount1155(
86144
FuzzInputs memory args,
87145
uint128 tokenAmount,

test/foundry/FulfillAvailableAdvancedOrder.t.sol

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,100 @@ contract FulfillAvailableAdvancedOrder is BaseOrderTest {
8181
}
8282
}
8383

84+
function testNoNativeOffersFulfillAvailableAdvanced(
85+
uint8[8] memory itemTypes
86+
) public {
87+
uint256 tokenId;
88+
for (uint256 i; i < 8; i++) {
89+
ItemType itemType = ItemType(itemTypes[i] % 4);
90+
if (itemType == ItemType.NATIVE) {
91+
addEthOfferItem(1);
92+
} else if (itemType == ItemType.ERC20) {
93+
addErc20OfferItem(1);
94+
} else if (itemType == ItemType.ERC1155) {
95+
test1155_1.mint(alice, tokenId, 1);
96+
addErc1155OfferItem(tokenId, 1);
97+
} else {
98+
test721_1.mint(alice, tokenId);
99+
addErc721OfferItem(tokenId);
100+
}
101+
tokenId++;
102+
offerComponents.push(FulfillmentComponent(1, i));
103+
}
104+
addEthOfferItem(1);
105+
106+
addEthConsiderationItem(alice, 1);
107+
considerationComponents.push(FulfillmentComponent(1, 0));
108+
109+
test(
110+
this.noNativeOfferItemsFulfillAvailableAdvanced,
111+
Context(consideration, empty, ItemType(0))
112+
);
113+
test(
114+
this.noNativeOfferItemsFulfillAvailableAdvanced,
115+
Context(referenceConsideration, empty, ItemType(0))
116+
);
117+
}
118+
119+
function noNativeOfferItemsFulfillAvailableAdvanced(Context memory context)
120+
external
121+
stateless
122+
{
123+
configureOrderParameters(alice);
124+
uint256 counter = context.consideration.getCounter(alice);
125+
_configureOrderComponents(counter);
126+
bytes32 orderHash = context.consideration.getOrderHash(
127+
baseOrderComponents
128+
);
129+
bytes memory signature = signOrder(
130+
context.consideration,
131+
alicePk,
132+
orderHash
133+
);
134+
135+
AdvancedOrder[] memory orders = new AdvancedOrder[](2);
136+
orders[1] = AdvancedOrder(baseOrderParameters, 1, 1, signature, "");
137+
offerComponentsArray.push(offerComponents);
138+
considerationComponentsArray.push(considerationComponents);
139+
140+
delete offerItems;
141+
delete considerationItems;
142+
delete offerComponents;
143+
delete considerationComponents;
144+
145+
token1.mint(alice, 100);
146+
addErc20OfferItem(100);
147+
addEthConsiderationItem(alice, 1);
148+
configureOrderParameters(alice);
149+
counter = context.consideration.getCounter(alice);
150+
_configureOrderComponents(counter);
151+
bytes32 orderHash2 = context.consideration.getOrderHash(
152+
baseOrderComponents
153+
);
154+
bytes memory signature2 = signOrder(
155+
context.consideration,
156+
alicePk,
157+
orderHash2
158+
);
159+
offerComponents.push(FulfillmentComponent(0, 0));
160+
considerationComponents.push(FulfillmentComponent(0, 0));
161+
offerComponentsArray.push(offerComponents);
162+
considerationComponentsArray.push(considerationComponents);
163+
164+
orders[0] = AdvancedOrder(baseOrderParameters, 1, 1, signature2, "");
165+
166+
vm.expectRevert(abi.encodeWithSignature("InvalidNativeOfferItem()"));
167+
context.consideration.fulfillAvailableAdvancedOrders{ value: 2 }(
168+
orders,
169+
new CriteriaResolver[](0),
170+
offerComponentsArray,
171+
considerationComponentsArray,
172+
bytes32(0),
173+
address(0),
174+
2
175+
);
176+
}
177+
84178
function testFulfillAvailableAdvancedOrderOverflow() public {
85179
for (uint256 i; i < 4; ++i) {
86180
// skip 721s

test/foundry/FulfillOrderTest.t.sol

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,55 @@ contract FulfillOrderTest is BaseOrderTest {
109109
_;
110110
}
111111

112+
function testNoNativeOffers(uint8[8] memory itemTypes) public {
113+
uint256 tokenId;
114+
for (uint256 i; i < 8; i++) {
115+
ItemType itemType = ItemType(itemTypes[i] % 4);
116+
if (itemType == ItemType.NATIVE) {
117+
addEthOfferItem(1);
118+
} else if (itemType == ItemType.ERC20) {
119+
addErc20OfferItem(1);
120+
} else if (itemType == ItemType.ERC1155) {
121+
test1155_1.mint(alice, tokenId, 1);
122+
addErc1155OfferItem(tokenId, 1);
123+
} else {
124+
test721_1.mint(alice, tokenId);
125+
addErc721OfferItem(tokenId);
126+
}
127+
tokenId++;
128+
}
129+
addEthOfferItem(1);
130+
131+
addEthConsiderationItem(alice, 1);
132+
133+
test(this.noNativeOfferItems, Context(consideration, empty, 0, 0, 0));
134+
test(
135+
this.noNativeOfferItems,
136+
Context(referenceConsideration, empty, 0, 0, 0)
137+
);
138+
}
139+
140+
function noNativeOfferItems(Context memory context) external stateless {
141+
configureOrderParameters(alice);
142+
uint256 counter = context.consideration.getCounter(alice);
143+
_configureOrderComponents(counter);
144+
bytes32 orderHash = context.consideration.getOrderHash(
145+
baseOrderComponents
146+
);
147+
bytes memory signature = signOrder(
148+
context.consideration,
149+
alicePk,
150+
orderHash
151+
);
152+
153+
vm.expectRevert(abi.encodeWithSignature("InvalidNativeOfferItem()"));
154+
155+
context.consideration.fulfillOrder(
156+
Order(baseOrderParameters, signature),
157+
bytes32(0)
158+
);
159+
}
160+
112161
function testNullAddressSpendReverts() public {
113162
// mint token to null address
114163
preapproved721.mint(address(0), 1);
@@ -142,6 +191,7 @@ contract FulfillOrderTest is BaseOrderTest {
142191
);
143192
// test that signature is recognized as invalid even though signer recovered is null address
144193
vm.expectRevert(abi.encodeWithSignature("InvalidSigner()"));
194+
145195
context.consideration.fulfillOrder(
146196
Order(baseOrderParameters, signature),
147197
bytes32(0)

test/foundry/FullfillAvailableOrder.t.sol

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,98 @@ contract FulfillAvailableOrder is BaseOrderTest {
5757
}
5858
}
5959

60+
function testNoNativeOffersFulfillAvailable(uint8[8] memory itemTypes)
61+
public
62+
{
63+
uint256 tokenId;
64+
for (uint256 i; i < 8; i++) {
65+
ItemType itemType = ItemType(itemTypes[i] % 4);
66+
if (itemType == ItemType.NATIVE) {
67+
addEthOfferItem(1);
68+
} else if (itemType == ItemType.ERC20) {
69+
addErc20OfferItem(1);
70+
} else if (itemType == ItemType.ERC1155) {
71+
test1155_1.mint(alice, tokenId, 1);
72+
addErc1155OfferItem(tokenId, 1);
73+
} else {
74+
test721_1.mint(alice, tokenId);
75+
addErc721OfferItem(tokenId);
76+
}
77+
tokenId++;
78+
offerComponents.push(FulfillmentComponent(1, i));
79+
}
80+
addEthOfferItem(1);
81+
82+
addEthConsiderationItem(alice, 1);
83+
considerationComponents.push(FulfillmentComponent(1, 0));
84+
85+
test(
86+
this.noNativeOfferItemsFulfillAvailable,
87+
Context(consideration, empty, ItemType(0))
88+
);
89+
test(
90+
this.noNativeOfferItemsFulfillAvailable,
91+
Context(referenceConsideration, empty, ItemType(0))
92+
);
93+
}
94+
95+
function noNativeOfferItemsFulfillAvailable(Context memory context)
96+
external
97+
stateless
98+
{
99+
configureOrderParameters(alice);
100+
uint256 counter = context.consideration.getCounter(alice);
101+
_configureOrderComponents(counter);
102+
bytes32 orderHash = context.consideration.getOrderHash(
103+
baseOrderComponents
104+
);
105+
bytes memory signature = signOrder(
106+
context.consideration,
107+
alicePk,
108+
orderHash
109+
);
110+
111+
Order[] memory orders = new Order[](2);
112+
orders[1] = Order(baseOrderParameters, signature);
113+
offerComponentsArray.push(offerComponents);
114+
considerationComponentsArray.push(considerationComponents);
115+
116+
delete offerItems;
117+
delete considerationItems;
118+
delete offerComponents;
119+
delete considerationComponents;
120+
121+
token1.mint(alice, 100);
122+
addErc20OfferItem(100);
123+
addEthConsiderationItem(alice, 1);
124+
configureOrderParameters(alice);
125+
counter = context.consideration.getCounter(alice);
126+
_configureOrderComponents(counter);
127+
bytes32 orderHash2 = context.consideration.getOrderHash(
128+
baseOrderComponents
129+
);
130+
bytes memory signature2 = signOrder(
131+
context.consideration,
132+
alicePk,
133+
orderHash2
134+
);
135+
offerComponents.push(FulfillmentComponent(0, 0));
136+
considerationComponents.push(FulfillmentComponent(0, 0));
137+
offerComponentsArray.push(offerComponents);
138+
considerationComponentsArray.push(considerationComponents);
139+
140+
orders[0] = Order(baseOrderParameters, signature2);
141+
142+
vm.expectRevert(abi.encodeWithSignature("InvalidNativeOfferItem()"));
143+
context.consideration.fulfillAvailableOrders{ value: 2 }(
144+
orders,
145+
offerComponentsArray,
146+
considerationComponentsArray,
147+
bytes32(0),
148+
2
149+
);
150+
}
151+
60152
function testFulfillAvailableOrdersOverflowOfferSide() public {
61153
// skip eth
62154
for (uint256 i = 1; i < 4; ++i) {

0 commit comments

Comments
 (0)