@@ -63,168 +63,168 @@ contract SellerWallet {
6363
6464
6565
66- // contract ImmutableSeaportOperationalTest is ImmutableSeaportBaseTest, ImmutableSeaportTestHelper {
67- // SellerWallet public sellerWallet;
68- // TestERC721 public erc721;
69- // uint256 public nftId;
66+ contract ImmutableSeaportOperationalTest is ImmutableSeaportBaseTest , ImmutableSeaportTestHelper {
67+ SellerWallet public sellerWallet;
68+ TestERC721 public erc721;
69+ uint256 public nftId;
70+
71+ function setUp () public override {
72+ super .setUp ();
73+ _setFulfillerAndZone (buyer, address (immutableSignedZone));
74+ sellerWallet = new SellerWallet ();
75+ nftId = 1 ;
76+ vm.deal (buyer, 10 ether);
77+ }
78+
79+
80+ function testFulfillFullRestrictedOrder () public {
81+ _checkFulfill (OrderType.FULL_RESTRICTED);
82+ }
83+
84+ function testFulfillPartialRestrictedOrder () public {
85+ _checkFulfill (OrderType.PARTIAL_RESTRICTED);
86+ }
87+
88+
89+ function testRejectUnsupportedZones () public {
90+ // Create order with random zone
91+ address randomZone = makeAddr ("randomZone " );
92+ AdvancedOrder memory order = _prepareCheckFulfill (randomZone);
93+
94+ vm.prank (buyer);
95+ vm.expectRevert (abi.encodeWithSelector (ImmutableSeaport.InvalidZone.selector , randomZone));
96+ immutableSeaport.fulfillAdvancedOrder {value: 10 ether }(order, new CriteriaResolver [](0 ), conduitKey, buyer);
97+ }
98+
99+ function testRejectFullOpenOrder () public {
100+ AdvancedOrder memory order = _prepareCheckFulfill (OrderType.FULL_OPEN);
101+
102+ vm.prank (buyer);
103+ vm.expectRevert (abi.encodeWithSelector (ImmutableSeaport.OrderNotRestricted.selector ));
104+ immutableSeaport.fulfillAdvancedOrder {value: 10 ether }(order, new CriteriaResolver [](0 ), conduitKey, buyer);
105+ }
106+
107+ function testRejectDisabledZone () public {
108+ AdvancedOrder memory order = _prepareCheckFulfill ();
109+
110+ vm.prank (owner);
111+ immutableSeaport.setAllowedZone (address (immutableSignedZone), false );
112+
113+ vm.prank (buyer);
114+ vm.expectRevert (abi.encodeWithSelector (ImmutableSeaport.InvalidZone.selector , address (immutableSignedZone)));
115+ immutableSeaport.fulfillAdvancedOrder {value: 10 ether }(order, new CriteriaResolver [](0 ), conduitKey, buyer);
116+ }
117+
118+ function testRejectWrongSigner () public {
119+ uint256 wrongSigner = 1 ;
120+ AdvancedOrder memory order = _prepareCheckFulfill (wrongSigner);
121+
122+ // The algorithm inside fulfillAdvancedOrder uses ecRecover to determine the signer. If the
123+ // information going in is wrong, then the wrong signer will be derived.
124+ address derivedBadSigner = 0x7E5F4552091A69125d5DfCb7b8C2659029395Bdf ;
70125
71- // function setUp() public override {
72- // super.setUp();
73- // _setFulfillerAndZone(buyer, address(immutableSignedZone));
74- // sellerWallet = new SellerWallet();
75- // nftId = 1;
76- // vm.deal(buyer, 10 ether);
77- // }
126+ vm.prank (buyer);
127+ vm.expectRevert (abi.encodeWithSelector (SIP7EventsAndErrors.SignerNotActive.selector , derivedBadSigner));
128+ immutableSeaport.fulfillAdvancedOrder {value: 10 ether }(order, new CriteriaResolver [](0 ), conduitKey, buyer);
129+ }
130+
131+ function testRejectInvalidExtraData () public {
132+ AdvancedOrder memory order = _prepareCheckFulfillWithBadExtraData ();
133+
134+ // The algorithm inside fulfillAdvancedOrder uses ecRecover to determine the signer. If the
135+ // information going in is wrong, then the wrong signer will be derived.
136+ address derivedBadSigner = 0xcE810B9B83082C93574784f403727369c3FE6955 ;
137+
138+ vm.prank (buyer);
139+ vm.expectRevert (abi.encodeWithSelector (SIP7EventsAndErrors.SignerNotActive.selector , derivedBadSigner));
140+ immutableSeaport.fulfillAdvancedOrder {value: 10 ether }(order, new CriteriaResolver [](0 ), conduitKey, buyer);
141+ }
78142
79143
80- // function testFulfillFullRestrictedOrder() public {
81- // _checkFulfill(OrderType.FULL_RESTRICTED);
82- // }
144+ function _checkFulfill (OrderType _orderType ) internal {
145+ AdvancedOrder memory order = _prepareCheckFulfill (_orderType);
83146
84- // function testFulfillPartialRestrictedOrder() public {
85- // _checkFulfill(OrderType.PARTIAL_RESTRICTED) ;
86- // }
147+ // Record balances before
148+ uint256 sellerBalanceBefore = address (sellerWallet).balance ;
149+ uint256 buyerBalanceBefore = address (buyer).balance;
87150
151+ // Fulfill order
152+ vm.prank (buyer);
153+ immutableSeaport.fulfillAdvancedOrder {value: 10 ether }(order, new CriteriaResolver [](0 ), conduitKey, buyer);
88154
89- // function testRejectUnsupportedZones() public {
90- // // Create order with random zone
91- // address randomZone = makeAddr("randomZone");
92- // AdvancedOrder memory order = _prepareCheckFulfill(randomZone);
155+ // Verify results
156+ assertEq (erc721.ownerOf (nftId), buyer, "Owner of NFT not buyer " );
157+ assertEq (address (sellerWallet).balance, sellerBalanceBefore + 10 ether, "Seller incorrect final balance " );
158+ assertEq (address (buyer).balance, buyerBalanceBefore - 10 ether, "Buyer incorrect final balance " );
159+ }
160+
161+ function _prepareCheckFulfill () internal returns (AdvancedOrder memory ) {
162+ return _prepareCheckFulfill (OrderType.PARTIAL_RESTRICTED, address (immutableSignedZone), immutableSignerPkey, false );
163+ }
164+
165+ function _prepareCheckFulfill (OrderType _orderType ) internal returns (AdvancedOrder memory ) {
166+ return _prepareCheckFulfill (_orderType, address (immutableSignedZone), immutableSignerPkey, false );
167+ }
93168
94- // vm.prank(buyer);
95- // vm.expectRevert(abi.encodeWithSelector(ImmutableSeaport.InvalidZone.selector, randomZone));
96- // immutableSeaport.fulfillAdvancedOrder{value: 10 ether}(order, new CriteriaResolver[](0), conduitKey, buyer);
97- // }
98-
99- // function testRejectFullOpenOrder() public {
100- // AdvancedOrder memory order = _prepareCheckFulfill(OrderType.FULL_OPEN);
101-
102- // vm.prank(buyer);
103- // vm.expectRevert(abi.encodeWithSelector(ImmutableSeaport.OrderNotRestricted.selector));
104- // immutableSeaport.fulfillAdvancedOrder{value: 10 ether}(order, new CriteriaResolver[](0), conduitKey, buyer);
105- // }
106-
107- // function testRejectDisabledZone() public {
108- // AdvancedOrder memory order = _prepareCheckFulfill();
109-
110- // vm.prank(owner);
111- // immutableSeaport.setAllowedZone(address(immutableSignedZone), false);
112-
113- // vm.prank(buyer);
114- // vm.expectRevert(abi.encodeWithSelector(ImmutableSeaport.InvalidZone.selector, address(immutableSignedZone)));
115- // immutableSeaport.fulfillAdvancedOrder{value: 10 ether}(order, new CriteriaResolver[](0), conduitKey, buyer);
116- // }
117-
118- // function testRejectWrongSigner() public {
119- // uint256 wrongSigner = 1;
120- // AdvancedOrder memory order = _prepareCheckFulfill(wrongSigner);
121-
122- // // The algorithm inside fulfillAdvancedOrder uses ecRecover to determine the signer. If the
123- // // information going in is wrong, then the wrong signer will be derived.
124- // address derivedBadSigner = 0x7E5F4552091A69125d5DfCb7b8C2659029395Bdf;
125-
126- // vm.prank(buyer);
127- // vm.expectRevert(abi.encodeWithSelector(SIP7EventsAndErrors.SignerNotActive.selector, derivedBadSigner));
128- // immutableSeaport.fulfillAdvancedOrder{value: 10 ether}(order, new CriteriaResolver[](0), conduitKey, buyer);
129- // }
130-
131- // function testRejectInvalidExtraData() public {
132- // AdvancedOrder memory order = _prepareCheckFulfillWithBadExtraData();
133-
134- // // The algorithm inside fulfillAdvancedOrder uses ecRecover to determine the signer. If the
135- // // information going in is wrong, then the wrong signer will be derived.
136- // address derivedBadSigner = 0xcE810B9B83082C93574784f403727369c3FE6955;
137-
138- // vm.prank(buyer);
139- // vm.expectRevert(abi.encodeWithSelector(SIP7EventsAndErrors.SignerNotActive.selector, derivedBadSigner));
140- // immutableSeaport.fulfillAdvancedOrder{value: 10 ether}(order, new CriteriaResolver[](0), conduitKey, buyer);
141- // }
142-
143-
144- // function _checkFulfill(OrderType _orderType) internal {
145- // AdvancedOrder memory order = _prepareCheckFulfill(_orderType);
146-
147- // // Record balances before
148- // uint256 sellerBalanceBefore = address(sellerWallet).balance;
149- // uint256 buyerBalanceBefore = address(buyer).balance;
150-
151- // // Fulfill order
152- // vm.prank(buyer);
153- // immutableSeaport.fulfillAdvancedOrder{value: 10 ether}(order, new CriteriaResolver[](0), conduitKey, buyer);
154-
155- // // Verify results
156- // assertEq(erc721.ownerOf(nftId), buyer, "Owner of NFT not buyer");
157- // assertEq(address(sellerWallet).balance, sellerBalanceBefore + 10 ether, "Seller incorrect final balance");
158- // assertEq(address(buyer).balance, buyerBalanceBefore - 10 ether, "Buyer incorrect final balance");
159- // }
160-
161- // function _prepareCheckFulfill() internal returns (AdvancedOrder memory) {
162- // return _prepareCheckFulfill(OrderType.PARTIAL_RESTRICTED, address(immutableSignedZone), immutableSignerPkey, false);
163- // }
164-
165- // function _prepareCheckFulfill(OrderType _orderType) internal returns (AdvancedOrder memory) {
166- // return _prepareCheckFulfill(_orderType, address(immutableSignedZone), immutableSignerPkey, false);
167- // }
168-
169-
170- // function _prepareCheckFulfill(address _zone) internal returns (AdvancedOrder memory) {
171- // return _prepareCheckFulfill(OrderType.PARTIAL_RESTRICTED, _zone, immutableSignerPkey, false);
172- // }
173-
174- // function _prepareCheckFulfill(uint256 _signer) internal returns (AdvancedOrder memory) {
175- // return _prepareCheckFulfill(OrderType.PARTIAL_RESTRICTED, address(immutableSignedZone), _signer, false);
176- // }
177-
178- // function _prepareCheckFulfillWithBadExtraData() internal returns (AdvancedOrder memory) {
179- // return _prepareCheckFulfill(OrderType.PARTIAL_RESTRICTED, address(immutableSignedZone), immutableSignerPkey, true);
180- // }
181-
182-
183- // function _prepareCheckFulfill(OrderType _orderType, address _zone, uint256 _signer, bool _useBadExtraData) internal returns (AdvancedOrder memory) {
184- // // Deploy test ERC721
185- // erc721 = new TestERC721();
186- // erc721.mint(address(sellerWallet), nftId);
187- // sellerWallet.setApprovalForAll(address(erc721), conduitAddress);
188- // uint64 expiration = uint64(block.timestamp + 90);
189-
190- // // Create order
191- // OrderParameters memory orderParams = OrderParameters({
192- // offerer: address(sellerWallet),
193- // zone: _zone,
194- // offer: _createOfferItems(address(erc721), nftId),
195- // consideration: _createConsiderationItems(address(sellerWallet), 10 ether),
196- // orderType: _orderType,
197- // startTime: 0,
198- // endTime: expiration,
199- // zoneHash: bytes32(0),
200- // salt: 0,
201- // conduitKey: conduitKey,
202- // totalOriginalConsiderationItems: 1
203- // });
204-
205- // OrderComponents memory orderComponents = OrderComponents({
206- // offerer: orderParams.offerer,
207- // zone: orderParams.zone,
208- // offer: orderParams.offer,
209- // consideration: orderParams.consideration,
210- // orderType: orderParams.orderType,
211- // startTime: orderParams.startTime,
212- // endTime: orderParams.endTime,
213- // zoneHash: orderParams.zoneHash,
214- // salt: orderParams.salt,
215- // conduitKey: orderParams.conduitKey,
216- // counter: 0
217- // });
218-
219- // bytes32 orderHash = immutableSeaport.getOrderHash(orderComponents);
220- // bytes memory extraData = _generateSip7Signature(orderHash, buyer, _signer, expiration, orderParams.consideration);
221- // if (_useBadExtraData) {
222- // orderParams.consideration[0].recipient = payable(buyer);
223- // extraData = _generateSip7Signature(orderHash, buyer, _signer, expiration, orderParams.consideration);
224- // }
225- // bytes memory signature = _signOrder(sellerPkey, orderHash);
226-
227- // AdvancedOrder memory order = AdvancedOrder(orderParams, 1, 1, signature, extraData);
228- // return order;
229- // }
230- // }
169+
170+ function _prepareCheckFulfill (address _zone ) internal returns (AdvancedOrder memory ) {
171+ return _prepareCheckFulfill (OrderType.PARTIAL_RESTRICTED, _zone, immutableSignerPkey, false );
172+ }
173+
174+ function _prepareCheckFulfill (uint256 _signer ) internal returns (AdvancedOrder memory ) {
175+ return _prepareCheckFulfill (OrderType.PARTIAL_RESTRICTED, address (immutableSignedZone), _signer, false );
176+ }
177+
178+ function _prepareCheckFulfillWithBadExtraData () internal returns (AdvancedOrder memory ) {
179+ return _prepareCheckFulfill (OrderType.PARTIAL_RESTRICTED, address (immutableSignedZone), immutableSignerPkey, true );
180+ }
181+
182+
183+ function _prepareCheckFulfill (OrderType _orderType , address _zone , uint256 _signer , bool _useBadExtraData ) internal returns (AdvancedOrder memory ) {
184+ // Deploy test ERC721
185+ erc721 = new TestERC721 ();
186+ erc721.mint (address (sellerWallet), nftId);
187+ sellerWallet.setApprovalForAll (address (erc721), conduitAddress);
188+ uint64 expiration = uint64 (block .timestamp + 90 );
189+
190+ // Create order
191+ OrderParameters memory orderParams = OrderParameters ({
192+ offerer: address (sellerWallet),
193+ zone: _zone,
194+ offer: _createOfferItems (address (erc721), nftId),
195+ consideration: _createConsiderationItems (address (sellerWallet), 10 ether),
196+ orderType: _orderType,
197+ startTime: 0 ,
198+ endTime: expiration,
199+ zoneHash: bytes32 (0 ),
200+ salt: 0 ,
201+ conduitKey: conduitKey,
202+ totalOriginalConsiderationItems: 1
203+ });
204+
205+ OrderComponents memory orderComponents = OrderComponents ({
206+ offerer: orderParams.offerer,
207+ zone: orderParams.zone,
208+ offer: orderParams.offer,
209+ consideration: orderParams.consideration,
210+ orderType: orderParams.orderType,
211+ startTime: orderParams.startTime,
212+ endTime: orderParams.endTime,
213+ zoneHash: orderParams.zoneHash,
214+ salt: orderParams.salt,
215+ conduitKey: orderParams.conduitKey,
216+ counter: 0
217+ });
218+
219+ bytes32 orderHash = immutableSeaport.getOrderHash (orderComponents);
220+ bytes memory extraData = _generateSip7Signature (orderHash, buyer, _signer, expiration, orderParams.consideration);
221+ if (_useBadExtraData) {
222+ orderParams.consideration[0 ].recipient = payable (buyer);
223+ extraData = _generateSip7Signature (orderHash, buyer, _signer, expiration, orderParams.consideration);
224+ }
225+ bytes memory signature = _signOrder (sellerPkey, orderHash);
226+
227+ AdvancedOrder memory order = AdvancedOrder (orderParams, 1 , 1 , signature, extraData);
228+ return order;
229+ }
230+ }
0 commit comments