Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions test/foundry/NonReentrant.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -80,17 +80,17 @@ contract NonReentrantTest is BaseOrderTest {
}

function testNonReentrant() public {
for (uint256 i; i < 7; ++i) {
for (uint256 j; j < 10; ++j) {
for (uint256 i; i < 8; ++i) {
for (uint256 j; j < 11; ++j) {
NonReentrantInputs memory inputs = NonReentrantInputs(
EntryPoint(i),
ReentryPoint(j)
);
test(this.nonReentrant, Context(consideration, inputs));
test(
this.nonReentrant,
Context(referenceConsideration, inputs)
);
test(this.nonReentrant, Context(consideration, inputs));
}
}
}
Expand Down Expand Up @@ -126,6 +126,24 @@ contract NonReentrantTest is BaseOrderTest {
}
currentConsideration.fulfillBasicOrder(_basicOrderParameters);
shouldReenter = false;
} else if (entryPoint == EntryPoint.FulfillBasicOrderEfficient) {
BasicOrderParameters
memory _basicOrderParameters = prepareBasicOrder(tokenId);
if (!reentering) {
shouldReenter = true;
vm.expectEmit(
true,
false,
false,
false,
address(address(this))
);
emit BytesReason(abi.encodeWithSignature("NoReentrantCalls()"));
}
currentConsideration.fulfillBasicOrder_efficient_6GL6yc(
_basicOrderParameters
);
shouldReenter = false;
} else if (entryPoint == EntryPoint.FulfillOrder) {
(
Order memory params,
Expand Down Expand Up @@ -587,7 +605,7 @@ contract NonReentrantTest is BaseOrderTest {
}

function _doReenter() internal {
if (uint256(reentryPoint) < 7) {
if (uint256(reentryPoint) < uint256(ReentryPoint.Cancel)) {
try
this._entryPoint(EntryPoint(uint256(reentryPoint)), 10, true)
{} catch (bytes memory reason) {
Expand Down
98 changes: 37 additions & 61 deletions test/foundry/offerers/TestPoolOffererTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import { TestPoolFactory, TestPoolOfferer } from "./impl/TestPoolFactory.sol";
import {
SpentItem,
AdvancedOrder,
ConsiderationItem,
CriteriaResolver,
OfferItem,
OrderType
} from "../../../contracts/lib/ConsiderationStructs.sol";

Expand Down Expand Up @@ -301,23 +303,15 @@ contract TestPoolOffererTest is BaseOrderTest {
}

function testBuyOneWildCard() public {
SpentItem[] memory minimumReceived = new SpentItem[](1);
minimumReceived[0] = SpentItem({
itemType: ItemType.ERC721_WITH_CRITERIA,
token: address(test721_1),
identifier: 0,
amount: 1
});

SpentItem[] memory maximumSpent = new SpentItem[](1);
maximumSpent[0] = SpentItem({
itemType: ItemType.ERC20,
token: address(token1),
identifier: 0,
amount: 300 // will not spend entire amount
});

addOfferItem(ItemType.ERC721, 101, 1);
addOfferItem(
OfferItem({
itemType: ItemType.ERC721_WITH_CRITERIA,
token: address(test721_1),
identifierOrCriteria: 0,
startAmount: 1,
endAmount: 1
})
);
addConsiderationItem(payable(address(offerer)), ItemType.ERC20, 0, 250);

_configureOrderParameters({
Expand Down Expand Up @@ -356,30 +350,24 @@ contract TestPoolOffererTest is BaseOrderTest {
}

function testBuyTwoWildCard() public {
SpentItem[] memory minimumReceived = new SpentItem[](2);
minimumReceived[0] = SpentItem({
itemType: ItemType.ERC721_WITH_CRITERIA,
token: address(test721_1),
identifier: 0,
amount: 1
});
minimumReceived[1] = SpentItem({
itemType: ItemType.ERC721_WITH_CRITERIA,
token: address(test721_1),
identifier: 0,
amount: 1
});

SpentItem[] memory maximumSpent = new SpentItem[](1);
maximumSpent[0] = SpentItem({
itemType: ItemType.ERC20,
token: address(token1),
identifier: 0,
amount: 1000000
});

addOfferItem(ItemType.ERC721, 101, 1);
addOfferItem(ItemType.ERC721, 102, 1);
addOfferItem(
OfferItem({
itemType: ItemType.ERC721_WITH_CRITERIA,
token: address(test721_1),
identifierOrCriteria: 0,
startAmount: 1,
endAmount: 1
})
);
addOfferItem(
OfferItem({
itemType: ItemType.ERC721_WITH_CRITERIA,
token: address(test721_1),
identifierOrCriteria: 0,
startAmount: 1,
endAmount: 1
})
);
addConsiderationItem(payable(address(offerer)), ItemType.ERC20, 0, 666);

_configureOrderParameters({
Expand Down Expand Up @@ -420,28 +408,16 @@ contract TestPoolOffererTest is BaseOrderTest {
function testSellOneWildCard() public {
test721_1.mint(address(this), 106);

SpentItem[] memory minimumReceived = new SpentItem[](1);
minimumReceived[0] = SpentItem({
itemType: ItemType.ERC20,
token: address(token1),
identifier: 0,
amount: 300
});

SpentItem[] memory maximumSpent = new SpentItem[](1);
maximumSpent[0] = SpentItem({
itemType: ItemType.ERC721_WITH_CRITERIA,
token: address(test721_1),
identifier: 0,
amount: 1
});

addOfferItem(ItemType.ERC20, 0, 166);
addConsiderationItem(
payable(address(offerer)),
ItemType.ERC721,
106,
1
ConsiderationItem({
itemType: ItemType.ERC721_WITH_CRITERIA,
token: address(test721_1),
identifierOrCriteria: 0,
startAmount: 1,
endAmount: 1,
recipient: payable(address(offerer))
})
);

_configureOrderParameters({
Expand Down
5 changes: 4 additions & 1 deletion test/foundry/offerers/impl/TestPoolOfferer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,10 @@ contract TestPoolOfferer is ContractOffererInterface, Ownable {
receivedItems[i] = ReceivedItem({
itemType: ItemType.ERC721,
token: erc721,
identifier: spentItem.identifier,
identifier: (spentItem.itemType ==
ItemType.ERC721_WITH_CRITERIA)
? 106
: spentItem.identifier,
amount: spentItem.amount,
recipient: payable(address(this))
});
Expand Down
2 changes: 2 additions & 0 deletions test/foundry/utils/reentrancy/ReentrantEnums.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ pragma solidity ^0.8.17;
*/
enum EntryPoint {
FulfillBasicOrder,
FulfillBasicOrderEfficient,
FulfillOrder,
FulfillAdvancedOrder,
FulfillAvailableOrders,
Expand All @@ -19,6 +20,7 @@ enum EntryPoint {
*/
enum ReentryPoint {
FulfillBasicOrder,
FulfillBasicOrderEfficient,
FulfillOrder,
FulfillAdvancedOrder,
FulfillAvailableOrders,
Expand Down