diff --git a/reference/lib/ReferenceReentrancyGuard.sol b/reference/lib/ReferenceReentrancyGuard.sol index fbca597..d58dff1 100644 --- a/reference/lib/ReferenceReentrancyGuard.sol +++ b/reference/lib/ReferenceReentrancyGuard.sol @@ -10,9 +10,9 @@ import { } from "seaport-types/src/interfaces/ReentrancyErrors.sol"; import { - _ENTERED_AND_ACCEPTING_NATIVE_TOKENS, - _ENTERED, - _NOT_ENTERED + _ENTERED_AND_ACCEPTING_NATIVE_TOKENS_SSTORE, + _ENTERED_SSTORE, + _NOT_ENTERED_SSTORE } from "seaport-types/src/lib/ConsiderationConstants.sol"; /** @@ -33,7 +33,7 @@ contract ReferenceReentrancyGuard is */ constructor() { // Initialize the reentrancy guard in a cleared state. - _reentrancyGuard = _NOT_ENTERED; + _reentrancyGuard = _NOT_ENTERED_SSTORE; } /** @@ -41,7 +41,7 @@ contract ReferenceReentrancyGuard is * is not currently set by a previous call. */ modifier notEntered() { - if (_reentrancyGuard != _NOT_ENTERED) { + if (_reentrancyGuard != _NOT_ENTERED_SSTORE) { revert NoReentrantCalls(); } @@ -56,19 +56,19 @@ contract ReferenceReentrancyGuard is * be received during execution or not. */ modifier nonReentrant(bool acceptNativeTokens) { - if (_reentrancyGuard != _NOT_ENTERED) { + if (_reentrancyGuard != _NOT_ENTERED_SSTORE) { revert NoReentrantCalls(); } if (acceptNativeTokens) { - _reentrancyGuard = _ENTERED_AND_ACCEPTING_NATIVE_TOKENS; + _reentrancyGuard = _ENTERED_AND_ACCEPTING_NATIVE_TOKENS_SSTORE; } else { - _reentrancyGuard = _ENTERED; + _reentrancyGuard = _ENTERED_SSTORE; } _; - _reentrancyGuard = _NOT_ENTERED; + _reentrancyGuard = _NOT_ENTERED_SSTORE; } /** @@ -77,7 +77,7 @@ contract ReferenceReentrancyGuard is */ function _assertAcceptingNativeTokens() internal view { // Ensure that the reentrancy guard is not currently set. - if (_reentrancyGuard != _ENTERED_AND_ACCEPTING_NATIVE_TOKENS) { + if (_reentrancyGuard != _ENTERED_AND_ACCEPTING_NATIVE_TOKENS_SSTORE) { revert InvalidMsgValue(msg.value); } } diff --git a/src/core/lib/BasicOrderFulfiller.sol b/src/core/lib/BasicOrderFulfiller.sol index fff9a7e..743aca7 100644 --- a/src/core/lib/BasicOrderFulfiller.sol +++ b/src/core/lib/BasicOrderFulfiller.sol @@ -24,7 +24,7 @@ import { AdditionalRecipient_size_shift, AdditionalRecipient_size, BasicOrder_additionalRecipients_data_cdPtr, - BasicOrder_additionalRecipients_length_cdPtr, + BasicOrder_addlRecipients_length_cdPtr, BasicOrder_basicOrderType_cdPtr, BasicOrder_common_params_size, BasicOrder_considerationAmount_cdPtr, @@ -474,7 +474,7 @@ contract BasicOrderFulfiller is OrderValidator { // Ensure consideration array length isn't less than total original. if lt( - calldataload(BasicOrder_additionalRecipients_length_cdPtr), + calldataload(BasicOrder_addlRecipients_length_cdPtr), calldataload(BasicOrder_totalOriginalAdditionalRecipients_cdPtr) ) { // Store left-padded selector with push4 (reduces bytecode), @@ -567,7 +567,7 @@ contract BasicOrderFulfiller is OrderValidator { // This variable will later be repurposed to track the total // original additional recipients instead of the total supplied. let totalAdditionalRecipients := - calldataload(BasicOrder_additionalRecipients_length_cdPtr) + calldataload(BasicOrder_addlRecipients_length_cdPtr) // Calculate pointer to length of OrderFulfilled consideration // array. Note that this is based on total original additional @@ -753,7 +753,7 @@ contract BasicOrderFulfiller is OrderValidator { // Overwrite length to length of the additionalRecipients array. totalAdditionalRecipients := - calldataload(BasicOrder_additionalRecipients_length_cdPtr) + calldataload(BasicOrder_addlRecipients_length_cdPtr) for { } lt(i, totalAdditionalRecipients) { i := add(i, 1) } { // Retrieve calldata pointer for additional recipient. @@ -1046,7 +1046,7 @@ contract BasicOrderFulfiller is OrderValidator { OrderFulfilled_baseSize, mul( calldataload( - BasicOrder_additionalRecipients_length_cdPtr + BasicOrder_addlRecipients_length_cdPtr ), ReceivedItem_size ) @@ -1250,7 +1250,7 @@ contract BasicOrderFulfiller is OrderValidator { totalAdditionalRecipientsDataSize := shl( AdditionalRecipient_size_shift, - calldataload(BasicOrder_additionalRecipients_length_cdPtr) + calldataload(BasicOrder_addlRecipients_length_cdPtr) ) } @@ -1391,7 +1391,7 @@ contract BasicOrderFulfiller is OrderValidator { totalAdditionalRecipientsDataSize := shl( AdditionalRecipient_size_shift, - calldataload(BasicOrder_additionalRecipients_length_cdPtr) + calldataload(BasicOrder_addlRecipients_length_cdPtr) ) } diff --git a/src/core/lib/ConsiderationEncoder.sol b/src/core/lib/ConsiderationEncoder.sol index 0f7965c..d1f61e1 100644 --- a/src/core/lib/ConsiderationEncoder.sol +++ b/src/core/lib/ConsiderationEncoder.sol @@ -7,7 +7,7 @@ import { authorizeOrder_selector_offset, authorizeOrder_selector, authorizeOrder_zoneParameters_offset, - BasicOrder_additionalRecipients_length_cdPtr, + BasicOrder_addlRecipients_length_cdPtr, BasicOrder_common_params_size, BasicOrder_consideration_offset_from_offer, BasicOrder_offerer_cdPtr, @@ -632,7 +632,7 @@ contract ConsiderationEncoder { // Retrieve the length of additional recipients. uint256 additionalRecipientsLength = CalldataPointer.wrap( - BasicOrder_additionalRecipients_length_cdPtr + BasicOrder_addlRecipients_length_cdPtr ).readUint256(); // Derive size of offer and consideration data. diff --git a/src/core/lib/CriteriaResolution.sol b/src/core/lib/CriteriaResolution.sol index 091a4ea..9478843 100644 --- a/src/core/lib/CriteriaResolution.sol +++ b/src/core/lib/CriteriaResolution.sol @@ -339,7 +339,7 @@ contract CriteriaResolution is CriteriaResolutionErrors { ItemType newItemType; assembly { // Item type 4 becomes 2 and item type 5 becomes 3. - newItemType := sub(3, eq(itemType, 4)) + newItemType := sub(itemType, 2) } offerItem.itemType = newItemType; diff --git a/src/core/lib/ReentrancyGuard.sol b/src/core/lib/ReentrancyGuard.sol index 8365ebd..b1f1296 100644 --- a/src/core/lib/ReentrancyGuard.sol +++ b/src/core/lib/ReentrancyGuard.sol @@ -1,8 +1,9 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.24; -import { ReentrancyErrors } from - "seaport-types/src/interfaces/ReentrancyErrors.sol"; +import { + ReentrancyErrors +} from "seaport-types/src/interfaces/ReentrancyErrors.sol"; import { LowLevelHelpers } from "./LowLevelHelpers.sol"; @@ -12,11 +13,17 @@ import { } from "seaport-types/src/lib/ConsiderationErrors.sol"; import { + _ENTERED_AND_ACCEPTING_NATIVE_TOKENS_SSTORE, + _ENTERED_SSTORE, + _NOT_ENTERED_SSTORE, + _ENTERED_AND_ACCEPTING_NATIVE_TOKENS_TSTORE, + _ENTERED_TSTORE, + _NOT_ENTERED_TSTORE, + _TSTORE_ENABLED_SSTORE, _REENTRANCY_GUARD_SLOT, _TLOAD_TEST_PAYLOAD, _TLOAD_TEST_PAYLOAD_OFFSET, - _TLOAD_TEST_PAYLOAD_LENGTH, - _TSTORE_SUPPORTED_SLOT + _TLOAD_TEST_PAYLOAD_LENGTH } from "seaport-types/src/lib/ConsiderationConstants.sol"; import { @@ -28,12 +35,6 @@ import { Error_selector_offset } from "seaport-types/src/lib/ConsiderationErrorConstants.sol"; -import { - _ENTERED_AND_ACCEPTING_NATIVE_TOKENS, - _ENTERED, - _NOT_ENTERED -} from "seaport-types/src/lib/ConsiderationConstants.sol"; - /** * @title ReentrancyGuard * @author 0age @@ -58,20 +59,29 @@ contract ReentrancyGuard is ReentrancyErrors, LowLevelHelpers { constructor() { // Deploy the contract testing TLOAD support and store the address. address tloadTestContract = _prepareTloadTest(); - + // Ensure the deployment was successful. if (tloadTestContract == address(0)) { revert TloadTestContractDeploymentFailed(); } - // Determine if TSTORE is supported & store the result as an immutable. - _tstoreInitialSupport = _testTload(tloadTestContract); + // Determine if TSTORE is supported. + bool tstoreInitialSupport = _testTload(tloadTestContract); + + // Store the result as an immutable. + _tstoreInitialSupport = tstoreInitialSupport; // Set the address of the deployed TLOAD test contract as an immutable. _tloadTestContract = tloadTestContract; - // Initialize the reentrancy guard in a cleared state. - _clearReentrancyGuard(); + // If not using TSTORE (where _NOT_ENTERED_TSTORE = 0), set initial + // sentinel value (where _NOT_ENTERED_SSTORE = 1). + if (!tstoreInitialSupport) { + // Initialize storage for the reentrancy guard in a cleared state. + assembly { + sstore(_REENTRANCY_GUARD_SLOT, _NOT_ENTERED_SSTORE) + } + } } /** @@ -82,17 +92,19 @@ contract ReentrancyGuard is ReentrancyErrors, LowLevelHelpers { * guard is currently set. */ function __activateTstore() external { - // Ensure that the reentrancy guard is not currently set. - _assertNonReentrant(); - - // Determine if TSTORE is already activated. - bool tstoreSupported; + // Determine if TSTORE can potentially be activated. If it has already + // been activated, or if the reentrancy guard is currently set, then + // it cannot be activated. + bool tstoreActivatable; assembly { - tstoreSupported := sload(_TSTORE_SUPPORTED_SLOT) + tstoreActivatable := eq( + sload(_REENTRANCY_GUARD_SLOT), + _NOT_ENTERED_SSTORE + ) } - // Revert if TSTORE is already activated. - if (_tstoreInitialSupport || tstoreSupported) { + // Revert if TSTORE is already activated or not activatable. + if (_tstoreInitialSupport || !tstoreActivatable) { revert TStoreAlreadyActivated(); } @@ -103,7 +115,7 @@ contract ReentrancyGuard is ReentrancyErrors, LowLevelHelpers { // Mark TSTORE as activated. assembly { - sstore(_TSTORE_SUPPORTED_SLOT, 1) + sstore(_REENTRANCY_GUARD_SLOT, _TSTORE_ENABLED_SSTORE) } } @@ -125,11 +137,15 @@ contract ReentrancyGuard is ReentrancyErrors, LowLevelHelpers { // "Loop" over three possible cases for setting the reentrancy guard // based on tstore support and state, exiting once the respective // state has been identified and a corresponding guard has been set. - for {} 1 {} { + for { + + } 1 { + + } { // 1: handle case where tstore is supported from the start. if tstoreInitialSupport { // Ensure that the reentrancy guard is not already set. - if iszero(eq(tload(_REENTRANCY_GUARD_SLOT), _NOT_ENTERED)) { + if tload(_REENTRANCY_GUARD_SLOT) { // Store left-padded selector with push4, // mem[28:32] = selector mstore(0, NoReentrantCalls_error_selector) @@ -141,23 +157,26 @@ contract ReentrancyGuard is ReentrancyErrors, LowLevelHelpers { ) } - // Set the reentrancy guard. A value of 2 indicates that + // Set the reentrancy guard. A value of 1 indicates that // native tokens may not be accepted during execution, - // whereas a value of 3 indicates that they will be accepted + // whereas a value of 2 indicates that they will be accepted // (returning any remaining native tokens to the caller). tstore( _REENTRANCY_GUARD_SLOT, - add(_ENTERED, acceptNativeTokens) + add(_ENTERED_TSTORE, acceptNativeTokens) ) // Exit the loop. break } + // Retrieve the reentrancy guard sentinel value. + let reentrancyGuard := sload(_REENTRANCY_GUARD_SLOT) + // 2: handle tstore support that was activated post-deployment. - if sload(_TSTORE_SUPPORTED_SLOT) { + if iszero(reentrancyGuard) { // Ensure that the reentrancy guard is not already set. - if iszero(eq(tload(_REENTRANCY_GUARD_SLOT), _NOT_ENTERED)) { + if tload(_REENTRANCY_GUARD_SLOT) { // Store left-padded selector with push4, // mem[28:32] = selector mstore(0, NoReentrantCalls_error_selector) @@ -169,13 +188,13 @@ contract ReentrancyGuard is ReentrancyErrors, LowLevelHelpers { ) } - // Set the reentrancy guard. A value of 2 indicates that + // Set the reentrancy guard. A value of 1 indicates that // native tokens may not be accepted during execution, - // whereas a value of 3 indicates that they will be accepted + // whereas a value of 2 indicates that they will be accepted // (returning any remaining native tokens to the caller). tstore( _REENTRANCY_GUARD_SLOT, - add(_ENTERED, acceptNativeTokens) + add(_ENTERED_TSTORE, acceptNativeTokens) ) // Exit the loop. @@ -184,7 +203,7 @@ contract ReentrancyGuard is ReentrancyErrors, LowLevelHelpers { // 3: handle case where tstore support has not been activated. // Ensure that the reentrancy guard is not already set. - if iszero(eq(sload(_REENTRANCY_GUARD_SLOT), _NOT_ENTERED)) { + if iszero(eq(reentrancyGuard, _NOT_ENTERED_SSTORE)) { // Store left-padded selector with push4 (reduces bytecode), // mem[28:32] = selector mstore(0, NoReentrantCalls_error_selector) @@ -199,7 +218,7 @@ contract ReentrancyGuard is ReentrancyErrors, LowLevelHelpers { // native tokens returned to the caller). sstore( _REENTRANCY_GUARD_SLOT, - add(_ENTERED, acceptNativeTokens) + add(_ENTERED_SSTORE, acceptNativeTokens) ) // Exit the loop. @@ -220,20 +239,27 @@ contract ReentrancyGuard is ReentrancyErrors, LowLevelHelpers { // "Loop" over three possible cases for clearing reentrancy guard // based on tstore support and state, exiting once the respective // state has been identified and corresponding guard cleared. - for {} 1 {} { + for { + + } 1 { + + } { // 1: handle case where tstore is supported from the start. if tstoreInitialSupport { // Clear the reentrancy guard. - tstore(_REENTRANCY_GUARD_SLOT, _NOT_ENTERED) + tstore(_REENTRANCY_GUARD_SLOT, _NOT_ENTERED_TSTORE) // Exit the loop. break } + // Retrieve the reentrancy guard sentinel value. + let reentrancyGuard := sload(_REENTRANCY_GUARD_SLOT) + // 2: handle tstore support that was activated post-deployment. - if sload(_TSTORE_SUPPORTED_SLOT) { + if iszero(reentrancyGuard) { // Clear the reentrancy guard. - tstore(_REENTRANCY_GUARD_SLOT, _NOT_ENTERED) + tstore(_REENTRANCY_GUARD_SLOT, _NOT_ENTERED_TSTORE) // Exit the loop. break @@ -241,7 +267,7 @@ contract ReentrancyGuard is ReentrancyErrors, LowLevelHelpers { // 3: handle case where tstore support has not been activated. // Clear the reentrancy guard. - sstore(_REENTRANCY_GUARD_SLOT, _NOT_ENTERED) + sstore(_REENTRANCY_GUARD_SLOT, _NOT_ENTERED_SSTORE) // Exit the loop. break @@ -259,33 +285,31 @@ contract ReentrancyGuard is ReentrancyErrors, LowLevelHelpers { // Utilize assembly to check reentrancy guard based on tstore support. assembly { - // "Loop" over three possible cases for setting the reentrancy guard - // based on tstore support and state, exiting once the respective - // state has been identified and a corresponding guard checked. - for {} 1 {} { - // 1: handle case where tstore is supported from the start. - if tstoreInitialSupport { - // Ensure that the reentrancy guard is not currently set. - if iszero(eq(tload(_REENTRANCY_GUARD_SLOT), _NOT_ENTERED)) { - // Store left-padded selector with push4, - // mem[28:32] = selector - mstore(0, NoReentrantCalls_error_selector) - - // revert(abi.encodeWithSignature("NoReentrantCalls()")) - revert( - Error_selector_offset, - NoReentrantCalls_error_length - ) - } + // 1: handle case where tstore is supported from the start. + if tstoreInitialSupport { + // Ensure that the reentrancy guard is not currently set. + if tload(_REENTRANCY_GUARD_SLOT) { + // Store left-padded selector with push4, + // mem[28:32] = selector + mstore(0, NoReentrantCalls_error_selector) - // Exit the loop. - break + // revert(abi.encodeWithSignature("NoReentrantCalls()")) + revert( + Error_selector_offset, + NoReentrantCalls_error_length + ) } + } + + // Handle cases where tstore is not initially supported. + if iszero(tstoreInitialSupport) { + // Retrieve the reentrancy guard sentinel value. + let reentrancyGuard := sload(_REENTRANCY_GUARD_SLOT) // 2: handle tstore support that was activated post-deployment. - if sload(_TSTORE_SUPPORTED_SLOT) { + if iszero(reentrancyGuard) { // Ensure that the reentrancy guard is not currently set. - if iszero(eq(tload(_REENTRANCY_GUARD_SLOT), _NOT_ENTERED)) { + if tload(_REENTRANCY_GUARD_SLOT) { // Store left-padded selector with push4, // mem[28:32] = selector mstore(0, NoReentrantCalls_error_selector) @@ -296,14 +320,11 @@ contract ReentrancyGuard is ReentrancyErrors, LowLevelHelpers { NoReentrantCalls_error_length ) } - - // Exit the loop. - break } // 3: handle case where tstore support has not been activated. // Ensure that the reentrancy guard is not currently set. - if iszero(eq(sload(_REENTRANCY_GUARD_SLOT), _NOT_ENTERED)) { + if gt(reentrancyGuard, _NOT_ENTERED_SSTORE) { // Store left-padded selector with push4 (reduces bytecode), // mem[28:32] = selector mstore(0, NoReentrantCalls_error_selector) @@ -311,9 +332,6 @@ contract ReentrancyGuard is ReentrancyErrors, LowLevelHelpers { // revert(abi.encodeWithSignature("NoReentrantCalls()")) revert(Error_selector_offset, NoReentrantCalls_error_length) } - - // Exit the loop. - break } } } @@ -328,46 +346,44 @@ contract ReentrancyGuard is ReentrancyErrors, LowLevelHelpers { // Utilize assembly to check reentrancy guard based on tstore support. assembly { - // "Loop" over three possible cases for setting the reentrancy guard - // based on tstore support and state, exiting once the respective - // state has been identified and a corresponding guard has been set. - for {} 1 {} { - // 1: handle case where tstore is supported from the start. - if tstoreInitialSupport { - // Ensure reentrancy guard is set to accept native tokens. - if iszero( - eq( - tload(_REENTRANCY_GUARD_SLOT), - _ENTERED_AND_ACCEPTING_NATIVE_TOKENS - ) - ) { - // Store left-padded selector with push4, - // mem[28:32] = selector - mstore(0, InvalidMsgValue_error_selector) - - // Store argument. - mstore(InvalidMsgValue_error_value_ptr, callvalue()) + // 1: handle case where tstore is supported from the start. + if tstoreInitialSupport { + // Ensure reentrancy guard is set to accept native tokens. + if iszero( + eq( + tload(_REENTRANCY_GUARD_SLOT), + _ENTERED_AND_ACCEPTING_NATIVE_TOKENS_TSTORE + ) + ) { + // Store left-padded selector with push4, + // mem[28:32] = selector + mstore(0, InvalidMsgValue_error_selector) - // revert(abi.encodeWithSignature( - // "InvalidMsgValue(uint256)", value) - // ) - revert( - Error_selector_offset, - InvalidMsgValue_error_length - ) - } + // Store argument. + mstore(InvalidMsgValue_error_value_ptr, callvalue()) - // Exit the loop. - break + // revert(abi.encodeWithSignature( + // "InvalidMsgValue(uint256)", value) + // ) + revert( + Error_selector_offset, + InvalidMsgValue_error_length + ) } + } + + // Handle cases where tstore is not initially supported. + if iszero(tstoreInitialSupport) { + // Retrieve the reentrancy guard sentinel value. + let reentrancyGuard := sload(_REENTRANCY_GUARD_SLOT) // 2: handle tstore support that was activated post-deployment. - if sload(_TSTORE_SUPPORTED_SLOT) { + if iszero(reentrancyGuard) { // Ensure reentrancy guard is set to accept native tokens. if iszero( eq( tload(_REENTRANCY_GUARD_SLOT), - _ENTERED_AND_ACCEPTING_NATIVE_TOKENS + _ENTERED_AND_ACCEPTING_NATIVE_TOKENS_TSTORE ) ) { // Store left-padded selector with push4, @@ -385,17 +401,17 @@ contract ReentrancyGuard is ReentrancyErrors, LowLevelHelpers { InvalidMsgValue_error_length ) } - - // Exit the loop. - break } // 3: handle case where tstore support has not been activated. // Ensure reentrancy guard is set to accepting native tokens. - if iszero( - eq( - sload(_REENTRANCY_GUARD_SLOT), - _ENTERED_AND_ACCEPTING_NATIVE_TOKENS + if and( + iszero(iszero(reentrancyGuard)), + iszero( + eq( + reentrancyGuard, + _ENTERED_AND_ACCEPTING_NATIVE_TOKENS_SSTORE + ) ) ) { // Store left-padded selector with push4 (reduces bytecode), @@ -410,15 +426,12 @@ contract ReentrancyGuard is ReentrancyErrors, LowLevelHelpers { // ) revert(Error_selector_offset, InvalidMsgValue_error_length) } - - // Exit the loop. - break } } } /** - * @dev Internal function to deploy a test contract that utilizes TLOAD as + * @dev Private function to deploy a test contract that utilizes TLOAD as * part of its fallback logic. */ function _prepareTloadTest() private returns (address contractAddress) { @@ -429,22 +442,24 @@ contract ReentrancyGuard is ReentrancyErrors, LowLevelHelpers { // Deploy the contract. contractAddress := create( - 0, - _TLOAD_TEST_PAYLOAD_OFFSET, - _TLOAD_TEST_PAYLOAD_LENGTH - ) + 0, + _TLOAD_TEST_PAYLOAD_OFFSET, + _TLOAD_TEST_PAYLOAD_LENGTH + ) } } /** - * @dev Internal function to determine if TSTORE/TLOAD are supported by the - * current EVM implementation by attempting to call the test contract, - * which utilizes TLOAD as part of its fallback logic. + * @dev Private view function to determine if TSTORE/TLOAD are supported by + * the current EVM implementation by attempting to call the test + * contract, which utilizes TLOAD as part of its fallback logic. */ - function _testTload(address tloadTestContract) private returns (bool ok) { + function _testTload( + address tloadTestContract + ) private view returns (bool ok) { // Call the test contract, which will perform a TLOAD test. If the call // does not revert, then TLOAD/TSTORE is supported. Do not forward all // available gas, as all forwarded gas will be consumed on revert. - (ok, ) = tloadTestContract.call{gas: gasleft() / 10}(""); + (ok, ) = tloadTestContract.staticcall{ gas: gasleft() / 10 }(""); } } diff --git a/src/types/lib/ConsiderationConstants.sol b/src/types/lib/ConsiderationConstants.sol index 81c42b0..12b688f 100644 --- a/src/types/lib/ConsiderationConstants.sol +++ b/src/types/lib/ConsiderationConstants.sol @@ -49,14 +49,34 @@ uint256 constant information_versionLengthPtr = 0x63; uint256 constant information_versionWithLength = 0x03312e36; // 1.6 uint256 constant information_length = 0xa0; +// uint256(uint32(bytes4(keccak256("_REENTRANCY_GUARD_SLOT")))) uint256 constant _REENTRANCY_GUARD_SLOT = 0x929eee14; -uint256 constant _TSTORE_SUPPORTED_SLOT = 0x54778ab1; -uint256 constant _TLOAD_TEST_PAYLOAD = 0x6002601e613d5c3d52f3; + +/* + * + * --------------------------------------------------------------------------+ + * Opcode | Mnemonic | Stack | Memory | + * --------------------------------------------------------------------------| + * 60 0x02 | PUSH1 0x02 | 0x02 | | + * 60 0x1e | PUSH1 0x1e | 0x1e 0x02 | | + * 61 0x3d5c | PUSH2 0x3d5c | 0x3d5c 0x1e 0x02 | | + * 3d | RETURNDATASIZE | 0 0x3d5c 0x1e 0x02 | | + * | + * ::: store deployed bytecode in memory: (3d) RETURNDATASIZE (5c) TLOAD ::: | + * 52 | MSTORE | 0x1e 0x02 | [0..0x20): 0x3d5c | + * f3 | RETURN | | [0..0x20): 0x3d5c | + * --------------------------------------------------------------------------+ + */ +uint256 constant _TLOAD_TEST_PAYLOAD = 0x6002_601e_613d5c_3d_52_f3; uint256 constant _TLOAD_TEST_PAYLOAD_LENGTH = 0x0a; uint256 constant _TLOAD_TEST_PAYLOAD_OFFSET = 0x16; -uint256 constant _NOT_ENTERED = 0; -uint256 constant _ENTERED = 1; -uint256 constant _ENTERED_AND_ACCEPTING_NATIVE_TOKENS = 2; +uint256 constant _NOT_ENTERED_TSTORE = 0; +uint256 constant _ENTERED_TSTORE = 1; +uint256 constant _ENTERED_AND_ACCEPTING_NATIVE_TOKENS_TSTORE = 2; +uint256 constant _TSTORE_ENABLED_SSTORE = 0; +uint256 constant _NOT_ENTERED_SSTORE = 1; +uint256 constant _ENTERED_SSTORE = 2; +uint256 constant _ENTERED_AND_ACCEPTING_NATIVE_TOKENS_SSTORE = 3; uint256 constant Offset_fulfillAdvancedOrder_criteriaResolvers = 0x20; uint256 constant Offset_fulfillAvailableOrders_offerFulfillments = 0x20; @@ -363,7 +383,6 @@ uint256 constant BasicOrder_fulfillerConduit_cdPtr = 0x1e4; uint256 constant BasicOrder_totalOriginalAdditionalRecipients_cdPtr = 0x204; uint256 constant BasicOrder_additionalRecipients_head_cdPtr = 0x224; uint256 constant BasicOrder_signature_cdPtr = 0x244; -uint256 constant BasicOrder_additionalRecipients_length_cdPtr = 0x264; uint256 constant BasicOrder_addlRecipients_length_cdPtr = 0x264; uint256 constant BasicOrder_additionalRecipients_data_cdPtr = 0x284; uint256 constant BasicOrder_parameters_ptr = 0x20; diff --git a/test/foundry/new/BaseOrderTest.sol b/test/foundry/new/BaseOrderTest.sol index 56b8785..c5f9092 100644 --- a/test/foundry/new/BaseOrderTest.sol +++ b/test/foundry/new/BaseOrderTest.sol @@ -5,11 +5,13 @@ import { Strings } from "@openzeppelin/contracts/utils/Strings.sol"; import { LibString } from "solady/src/utils/LibString.sol"; -import { FulfillAvailableHelper } from - "seaport-sol/src/fulfillments/available/FulfillAvailableHelper.sol"; +import { + FulfillAvailableHelper +} from "seaport-sol/src/fulfillments/available/FulfillAvailableHelper.sol"; -import { MatchFulfillmentHelper } from - "seaport-sol/src/fulfillments/match/MatchFulfillmentHelper.sol"; +import { + MatchFulfillmentHelper +} from "seaport-sol/src/fulfillments/match/MatchFulfillmentHelper.sol"; import { AdvancedOrderLib, @@ -172,59 +174,103 @@ contract BaseOrderTest is * tests. */ function _configureStructDefaults() internal { - OfferItemLib.empty().withItemType(ItemType.ERC721).withStartAmount(1) - .withEndAmount(1).saveDefault(SINGLE_ERC721); - ConsiderationItemLib.empty().withItemType(ItemType.ERC721) - .withStartAmount(1).withEndAmount(1).saveDefault(SINGLE_ERC721); - - OrderComponentsLib.empty().withOrderType(OrderType.FULL_OPEN) - .withStartTime(block.timestamp).withEndTime(block.timestamp + 100) + OfferItemLib + .empty() + .withItemType(ItemType.ERC721) + .withStartAmount(1) + .withEndAmount(1) + .saveDefault(SINGLE_ERC721); + ConsiderationItemLib + .empty() + .withItemType(ItemType.ERC721) + .withStartAmount(1) + .withEndAmount(1) + .saveDefault(SINGLE_ERC721); + + OrderComponentsLib + .empty() + .withOrderType(OrderType.FULL_OPEN) + .withStartTime(block.timestamp) + .withEndTime(block.timestamp + 100) .saveDefault(STANDARD); - OrderComponentsLib.fromDefault(STANDARD).withConduitKey(conduitKey) + OrderComponentsLib + .fromDefault(STANDARD) + .withConduitKey(conduitKey) .saveDefault(STANDARD_CONDUIT); - AdvancedOrderLib.empty().withNumerator(1).withDenominator(1).saveDefault( - FULL - ); + AdvancedOrderLib + .empty() + .withNumerator(1) + .withDenominator(1) + .saveDefault(FULL); - FulfillmentComponentLib.empty().withOrderIndex(0).withItemIndex(0) + FulfillmentComponentLib + .empty() + .withOrderIndex(0) + .withItemIndex(0) .saveDefault(FIRST_FIRST); - FulfillmentComponentLib.empty().withOrderIndex(0).withItemIndex(1) + FulfillmentComponentLib + .empty() + .withOrderIndex(0) + .withItemIndex(1) .saveDefault(FIRST_SECOND); - FulfillmentComponentLib.empty().withOrderIndex(1).withItemIndex(0) + FulfillmentComponentLib + .empty() + .withOrderIndex(1) + .withItemIndex(0) .saveDefault(SECOND_FIRST); - FulfillmentComponentLib.empty().withOrderIndex(1).withItemIndex(1) + FulfillmentComponentLib + .empty() + .withOrderIndex(1) + .withItemIndex(1) .saveDefault(SECOND_SECOND); - SeaportArrays.FulfillmentComponents( - FulfillmentComponentLib.fromDefault(FIRST_FIRST) - ).saveDefaultMany(FIRST_FIRST); - SeaportArrays.FulfillmentComponents( - FulfillmentComponentLib.fromDefault(FIRST_SECOND) - ).saveDefaultMany(FIRST_SECOND); - SeaportArrays.FulfillmentComponents( - FulfillmentComponentLib.fromDefault(SECOND_FIRST) - ).saveDefaultMany(SECOND_FIRST); - SeaportArrays.FulfillmentComponents( - FulfillmentComponentLib.fromDefault(SECOND_SECOND) - ).saveDefaultMany(SECOND_SECOND); - - FulfillmentLib.empty().withOfferComponents( - FulfillmentComponentLib.fromDefaultMany(SECOND_FIRST) - ).withConsiderationComponents( - FulfillmentComponentLib.fromDefaultMany(FIRST_FIRST) - ).saveDefault(SF_FF); - FulfillmentLib.empty().withOfferComponents( - FulfillmentComponentLib.fromDefaultMany(FIRST_FIRST) - ).withConsiderationComponents( - FulfillmentComponentLib.fromDefaultMany(SECOND_FIRST) - ).saveDefault(FF_SF); + SeaportArrays + .FulfillmentComponents( + FulfillmentComponentLib.fromDefault(FIRST_FIRST) + ) + .saveDefaultMany(FIRST_FIRST); + SeaportArrays + .FulfillmentComponents( + FulfillmentComponentLib.fromDefault(FIRST_SECOND) + ) + .saveDefaultMany(FIRST_SECOND); + SeaportArrays + .FulfillmentComponents( + FulfillmentComponentLib.fromDefault(SECOND_FIRST) + ) + .saveDefaultMany(SECOND_FIRST); + SeaportArrays + .FulfillmentComponents( + FulfillmentComponentLib.fromDefault(SECOND_SECOND) + ) + .saveDefaultMany(SECOND_SECOND); + + FulfillmentLib + .empty() + .withOfferComponents( + FulfillmentComponentLib.fromDefaultMany(SECOND_FIRST) + ) + .withConsiderationComponents( + FulfillmentComponentLib.fromDefaultMany(FIRST_FIRST) + ) + .saveDefault(SF_FF); + FulfillmentLib + .empty() + .withOfferComponents( + FulfillmentComponentLib.fromDefaultMany(FIRST_FIRST) + ) + .withConsiderationComponents( + FulfillmentComponentLib.fromDefaultMany(SECOND_FIRST) + ) + .saveDefault(FF_SF); } - function test(function(Context memory) external fn, Context memory context) - internal - { + function test( + function(Context memory) external fn, + Context memory context + ) internal { try fn(context) { fail("Differential test should have reverted with failure status"); } catch (bytes memory reason) { @@ -237,10 +283,9 @@ contract BaseOrderTest is * instead of internal visibility, so that we can access it in * libraries. */ - function makeAccountWrapper(string memory name) - public - returns (Account memory) - { + function makeAccountWrapper( + string memory name + ) public returns (Account memory) { return makeAccount(name); } @@ -248,10 +293,9 @@ contract BaseOrderTest is * @dev Convenience wrapper for makeAddrAndKey that also allocates tokens, * ether, and approvals. */ - function makeAndAllocateAccount(string memory name) - internal - returns (Account memory) - { + function makeAndAllocateAccount( + string memory name + ) internal returns (Account memory) { Account memory account = makeAccountWrapper(name); allocateTokensAndApprovals(account.addr, type(uint128).max); return account; @@ -260,10 +304,9 @@ contract BaseOrderTest is /** * @dev Sets up a new address and sets up token approvals for it. */ - function makeAddrWithAllocationsAndApprovals(string memory label) - internal - returns (address) - { + function makeAddrWithAllocationsAndApprovals( + string memory label + ) internal returns (address) { address addr = makeAddr(label); allocateTokensAndApprovals(addr, type(uint128).max); return addr; @@ -300,7 +343,10 @@ contract BaseOrderTest is i = erc721s.length; TestERC721 token = new TestERC721(); erc721s.push(token); - setLabel(address(token), string.concat("ERC721", LibString.toString(i))); + setLabel( + address(token), + string.concat("ERC721", LibString.toString(i)) + ); } /** @@ -312,7 +358,8 @@ contract BaseOrderTest is TestERC1155 token = new TestERC1155(); erc1155s.push(token); setLabel( - address(token), string.concat("ERC1155", LibString.toString(i)) + address(token), + string.concat("ERC1155", LibString.toString(i)) ); } @@ -357,5 +404,5 @@ contract BaseOrderTest is vm.stopPrank(); } - receive() external payable virtual { } + receive() external payable virtual {} } diff --git a/test/foundry/new/ExpectedBalances.t.sol b/test/foundry/new/ExpectedBalances.t.sol index f39f805..390d041 100644 --- a/test/foundry/new/ExpectedBalances.t.sol +++ b/test/foundry/new/ExpectedBalances.t.sol @@ -45,27 +45,45 @@ contract ExpectedBalancesTest is Test { offerer: alice, conduitKey: bytes32(0), item: ReceivedItem( - ItemType.NATIVE, address(0), 0, 0.5 ether, payable(bob) - ) + ItemType.NATIVE, + address(0), + 0, + 0.5 ether, + payable(bob) + ) }); executions[1] = Execution({ offerer: alice, conduitKey: bytes32(0), - item: ReceivedItem(ItemType.ERC20, address(erc20), 0, 250, payable(bob)) + item: ReceivedItem( + ItemType.ERC20, + address(erc20), + 0, + 250, + payable(bob) + ) }); executions[2] = Execution({ offerer: bob, conduitKey: bytes32(0), item: ReceivedItem( - ItemType.ERC721, address(erc721), 1, 1, payable(alice) - ) + ItemType.ERC721, + address(erc721), + 1, + 1, + payable(alice) + ) }); executions[3] = Execution({ offerer: bob, conduitKey: bytes32(0), item: ReceivedItem( - ItemType.ERC1155, address(erc1155), 1, 50, payable(alice) - ) + ItemType.ERC1155, + address(erc1155), + 1, + 50, + payable(alice) + ) }); balances.addTransfers(executions); vm.prank(alice); @@ -94,8 +112,12 @@ contract ExpectedBalancesTest is Test { offerer: alice, conduitKey: bytes32(0), item: ReceivedItem( - ItemType.NATIVE, address(0), 0, 0.5 ether, payable(bob) - ) + ItemType.NATIVE, + address(0), + 0, + 0.5 ether, + payable(bob) + ) }) ); balances.addTransfer( @@ -103,8 +125,12 @@ contract ExpectedBalancesTest is Test { offerer: alice, conduitKey: bytes32(0), item: ReceivedItem( - ItemType.ERC20, address(erc20), 0, 250, payable(bob) - ) + ItemType.ERC20, + address(erc20), + 0, + 250, + payable(bob) + ) }) ); balances.addTransfer( @@ -112,8 +138,12 @@ contract ExpectedBalancesTest is Test { offerer: bob, conduitKey: bytes32(0), item: ReceivedItem( - ItemType.ERC721, address(erc721), 1, 1, payable(alice) - ) + ItemType.ERC721, + address(erc721), + 1, + 1, + payable(alice) + ) }) ); balances.addTransfer( @@ -121,8 +151,12 @@ contract ExpectedBalancesTest is Test { offerer: bob, conduitKey: bytes32(0), item: ReceivedItem( - ItemType.ERC1155, address(erc1155), 1, 50, payable(alice) - ) + ItemType.ERC1155, + address(erc1155), + 1, + 50, + payable(alice) + ) }) ); vm.prank(alice); @@ -148,7 +182,11 @@ contract ExpectedBalancesTest is Test { vm.expectRevert( bytes( BalanceErrorMessages.insufficientNativeBalance( - alice, bob, 0, 1, false + alice, + bob, + 0, + 1, + false ) ) ); @@ -157,8 +195,12 @@ contract ExpectedBalancesTest is Test { offerer: alice, conduitKey: bytes32(0), item: ReceivedItem( - ItemType.NATIVE, address(0), 0, alice.balance + 1, payable(bob) - ) + ItemType.NATIVE, + address(0), + 0, + alice.balance + 1, + payable(bob) + ) }) ); } @@ -170,15 +212,21 @@ contract ExpectedBalancesTest is Test { offerer: alice, conduitKey: bytes32(0), item: ReceivedItem( - ItemType.NATIVE, address(0), 0, 0.5 ether, payable(bob) - ) + ItemType.NATIVE, + address(0), + 0, + 0.5 ether, + payable(bob) + ) }) ); vm.deal(bob, 0.5 ether); vm.expectRevert( bytes( BalanceErrorMessages.nativeUnexpectedBalance( - alice, 0, 0.5 ether + alice, + 0, + 0.5 ether ) ) ); @@ -193,8 +241,12 @@ contract ExpectedBalancesTest is Test { offerer: alice, conduitKey: bytes32(0), item: ReceivedItem( - ItemType.NATIVE, address(0), 0, 0.5 ether, payable(bob) - ) + ItemType.NATIVE, + address(0), + 0, + 0.5 ether, + payable(bob) + ) }) ); vm.prank(alice); @@ -216,7 +268,12 @@ contract ExpectedBalancesTest is Test { vm.expectRevert( bytes( BalanceErrorMessages.insufficientERC20Balance( - address(erc20), alice, bob, 0, 200, false + address(erc20), + alice, + bob, + 0, + 200, + false ) ) ); @@ -225,8 +282,12 @@ contract ExpectedBalancesTest is Test { offerer: alice, conduitKey: bytes32(0), item: ReceivedItem( - ItemType.ERC20, address(erc20), 0, 200, payable(bob) - ) + ItemType.ERC20, + address(erc20), + 0, + 200, + payable(bob) + ) }) ); } @@ -238,8 +299,12 @@ contract ExpectedBalancesTest is Test { offerer: alice, conduitKey: bytes32(0), item: ReceivedItem( - ItemType.ERC20, address(erc20), 0, 5, payable(bob) - ) + ItemType.ERC20, + address(erc20), + 0, + 5, + payable(bob) + ) }) ); vm.prank(alice); @@ -249,7 +314,10 @@ contract ExpectedBalancesTest is Test { vm.expectRevert( bytes( BalanceErrorMessages.erc20UnexpectedBalance( - address(erc20), alice, 5, 6 + address(erc20), + alice, + 5, + 6 ) ) ); @@ -263,15 +331,22 @@ contract ExpectedBalancesTest is Test { offerer: alice, conduitKey: bytes32(0), item: ReceivedItem( - ItemType.ERC20, address(erc20), 0, 5, payable(bob) - ) + ItemType.ERC20, + address(erc20), + 0, + 5, + payable(bob) + ) }) ); vm.expectRevert( bytes( BalanceErrorMessages.erc20UnexpectedBalance( - address(erc20), alice, 5, 10 + address(erc20), + alice, + 5, + 10 ) ) ); @@ -286,8 +361,12 @@ contract ExpectedBalancesTest is Test { offerer: alice, conduitKey: bytes32(0), item: ReceivedItem( - ItemType.ERC20, address(erc20), 0, 50, payable(bob) - ) + ItemType.ERC20, + address(erc20), + 0, + 50, + payable(bob) + ) }) ); balances.addTransfer( @@ -295,8 +374,12 @@ contract ExpectedBalancesTest is Test { offerer: bob, conduitKey: bytes32(0), item: ReceivedItem( - ItemType.ERC20, address(erc20), 0, 50, payable(alice) - ) + ItemType.ERC20, + address(erc20), + 0, + 50, + payable(alice) + ) }) ); balances.checkBalances(); @@ -314,8 +397,12 @@ contract ExpectedBalancesTest is Test { offerer: alice, conduitKey: bytes32(0), item: ReceivedItem( - ItemType.ERC721, address(erc721), 1, 1, payable(bob) - ) + ItemType.ERC721, + address(erc721), + 1, + 1, + payable(bob) + ) }) ); } @@ -327,8 +414,12 @@ contract ExpectedBalancesTest is Test { offerer: alice, conduitKey: bytes32(0), item: ReceivedItem( - ItemType.ERC721, address(erc721), 1, 1, payable(bob) - ) + ItemType.ERC721, + address(erc721), + 1, + 1, + payable(bob) + ) }) ); erc721.mint(alice, 2); @@ -336,7 +427,10 @@ contract ExpectedBalancesTest is Test { vm.expectRevert( bytes( BalanceErrorMessages.erc721UnexpectedBalance( - address(erc721), alice, 0, 2 + address(erc721), + alice, + 0, + 2 ) ) ); @@ -350,14 +444,20 @@ contract ExpectedBalancesTest is Test { offerer: alice, conduitKey: bytes32(0), item: ReceivedItem( - ItemType.ERC721, address(erc721), 1, 1, payable(bob) - ) + ItemType.ERC721, + address(erc721), + 1, + 1, + payable(bob) + ) }) ); erc721.mint(bob, 2); vm.prank(alice); erc721.transferFrom(alice, address(1000), 1); - vm.expectRevert("ExpectedBalances: account does not own expected token"); + vm.expectRevert( + "ExpectedBalances: account does not own expected token" + ); balances.checkBalances(); } @@ -369,8 +469,12 @@ contract ExpectedBalancesTest is Test { offerer: alice, conduitKey: bytes32(0), item: ReceivedItem( - ItemType.ERC721, address(erc721), 1, 1, payable(bob) - ) + ItemType.ERC721, + address(erc721), + 1, + 1, + payable(bob) + ) }) ); balances.addTransfer( @@ -378,8 +482,12 @@ contract ExpectedBalancesTest is Test { offerer: alice, conduitKey: bytes32(0), item: ReceivedItem( - ItemType.ERC721, address(erc721), 2, 1, payable(bob) - ) + ItemType.ERC721, + address(erc721), + 2, + 1, + payable(bob) + ) }) ); vm.prank(alice); @@ -397,7 +505,13 @@ contract ExpectedBalancesTest is Test { vm.expectRevert( bytes( BalanceErrorMessages.insufficientERC1155Balance( - address(erc1155), 0, alice, bob, 0, 200, false + address(erc1155), + 0, + alice, + bob, + 0, + 200, + false ) ) ); @@ -406,8 +520,12 @@ contract ExpectedBalancesTest is Test { offerer: alice, conduitKey: bytes32(0), item: ReceivedItem( - ItemType.ERC1155, address(erc1155), 0, 200, payable(bob) - ) + ItemType.ERC1155, + address(erc1155), + 0, + 200, + payable(bob) + ) }) ); } @@ -419,8 +537,12 @@ contract ExpectedBalancesTest is Test { offerer: alice, conduitKey: bytes32(0), item: ReceivedItem( - ItemType.ERC1155, address(erc1155), 1, 5, payable(bob) - ) + ItemType.ERC1155, + address(erc1155), + 1, + 5, + payable(bob) + ) }) ); vm.prank(alice); @@ -430,7 +552,11 @@ contract ExpectedBalancesTest is Test { vm.expectRevert( bytes( BalanceErrorMessages.erc1155UnexpectedBalance( - address(erc1155), alice, 1, 5, 6 + address(erc1155), + alice, + 1, + 5, + 6 ) ) ); @@ -444,8 +570,12 @@ contract ExpectedBalancesTest is Test { offerer: alice, conduitKey: bytes32(0), item: ReceivedItem( - ItemType.ERC1155, address(erc1155), 1, 5, payable(bob) - ) + ItemType.ERC1155, + address(erc1155), + 1, + 5, + payable(bob) + ) }) ); vm.prank(alice); @@ -453,7 +583,11 @@ contract ExpectedBalancesTest is Test { vm.expectRevert( bytes( BalanceErrorMessages.erc1155UnexpectedBalance( - address(erc1155), bob, 1, 5, 0 + address(erc1155), + bob, + 1, + 5, + 0 ) ) ); diff --git a/test/foundry/new/FractionUtil.t.sol b/test/foundry/new/FractionUtil.t.sol index 25d1cf3..1647046 100644 --- a/test/foundry/new/FractionUtil.t.sol +++ b/test/foundry/new/FractionUtil.t.sol @@ -22,19 +22,25 @@ contract FractionUtilTest is Test { denominatorToFill ); - assertEq(results.realizedNumerator, 3, "Realized numerator should be 3"); assertEq( - results.realizedDenominator, 12, "Realized denominator should be 12" + results.realizedNumerator, + 3, + "Realized numerator should be 3" + ); + assertEq( + results.realizedDenominator, + 12, + "Realized denominator should be 12" ); assertEq( results.finalFilledNumerator, - 11, - "Final filled numerator should be 11" + 33, + "Final filled numerator should be 33" ); assertEq( results.finalFilledDenominator, - 12, - "Final filled denominator should be 12" + 36, + "Final filled denominator should be 36" ); assertEq( uint256(results.status), @@ -58,20 +64,24 @@ contract FractionUtilTest is Test { ); assertEq( - results1.realizedNumerator, 2, "Realized numerator should be 2" + results1.realizedNumerator, + 2, + "Realized numerator should be 2" ); assertEq( - results1.realizedDenominator, 6, "Realized denominator should be 6" + results1.realizedDenominator, + 6, + "Realized denominator should be 6" ); assertEq( results1.finalFilledNumerator, - 6, - "Final filled numerator should be 6" + 18, + "Final filled numerator should be 18" ); assertEq( results1.finalFilledDenominator, - 6, - "Final filled denominator should be 6" + 18, + "Final filled denominator should be 18" ); assertEq( uint256(results1.status), @@ -82,8 +92,8 @@ contract FractionUtilTest is Test { function testGetWholeFillResultsGCD() public { // Test for WHOLE_FILL_GCD - uint120 currentStatusDenominator = - type(uint120).max - (type(uint120).max % 3); + uint120 currentStatusDenominator = type(uint120).max - + (type(uint120).max % 3); uint120 currentStatusNumerator = (currentStatusDenominator / 3) * 2; uint120 numeratorToFill = 2; @@ -97,20 +107,24 @@ contract FractionUtilTest is Test { ); assertEq( - results2.realizedNumerator, 1, "Realized numerator should be 1" + results2.realizedNumerator, + 1, + "Realized numerator should be 1" ); assertEq( - results2.realizedDenominator, 3, "Realized denominator should be 3" + results2.realizedDenominator, + 3, + "Realized denominator should be 3" ); assertEq( results2.finalFilledNumerator, - 3, - "Final filled numerator should be 3" + 1, + "Final filled numerator should be 1" ); assertEq( results2.finalFilledDenominator, - 3, - "Final filled denominator should be 3" + 1, + "Final filled denominator should be 1" ); assertEq( uint256(results2.status), @@ -121,8 +135,8 @@ contract FractionUtilTest is Test { function testGetPartialFillResultsGCD() public { // Test for PARTIAL_FILL_GCD - uint120 currentStatusDenominator = - type(uint120).max - (type(uint120).max % 3); + uint120 currentStatusDenominator = type(uint120).max - + (type(uint120).max % 3); uint120 currentStatusNumerator = (currentStatusDenominator / 3) * 2; uint120 numeratorToFill = 1; @@ -136,20 +150,24 @@ contract FractionUtilTest is Test { ); assertEq( - results3.realizedNumerator, 1, "Realized numerator should be 1" + results3.realizedNumerator, + 1, + "Realized numerator should be 1" ); assertEq( - results3.realizedDenominator, 3, "Realized denominator should be 3" + results3.realizedDenominator, + 3, + "Realized denominator should be 3" ); assertEq( results3.finalFilledNumerator, - 3, - "Final filled numerator should be 3" + 1, + "Final filled numerator should be 1" ); assertEq( results3.finalFilledDenominator, - 3, - "Final filled denominator should be 3" + 1, + "Final filled denominator should be 1" ); assertEq( uint256(results3.status), @@ -176,10 +194,14 @@ contract FractionUtilTest is Test { ); assertEq( - results4.realizedNumerator, 0, "Realized numerator should be 0" + results4.realizedNumerator, + 0, + "Realized numerator should be 0" ); assertEq( - results4.realizedDenominator, 0, "Realized denominator should be 0" + results4.realizedDenominator, + 0, + "Realized denominator should be 0" ); assertEq( results4.finalFilledNumerator, diff --git a/test/foundry/new/FuzzCoverage.t.sol b/test/foundry/new/FuzzCoverage.t.sol index 263c5df..d2bdecf 100644 --- a/test/foundry/new/FuzzCoverage.t.sol +++ b/test/foundry/new/FuzzCoverage.t.sol @@ -121,8 +121,11 @@ contract FuzzCoverageTestSuite is FuzzEngine { maxOfferItems: bound(maxOfferItems, 0, 10), maxConsiderationItems: bound(maxConsiderationItems, 0, 10), seedInput: abi.encodePacked( - seed, totalOrders, maxOfferItems, maxConsiderationItems - ) + seed, + totalOrders, + maxOfferItems, + maxConsiderationItems + ) }) ); } diff --git a/test/foundry/new/FuzzEngine.t.sol b/test/foundry/new/FuzzEngine.t.sol index 14caa8b..175e7d2 100644 --- a/test/foundry/new/FuzzEngine.t.sol +++ b/test/foundry/new/FuzzEngine.t.sol @@ -31,11 +31,13 @@ import { UnavailableReason } from "seaport-sol/src/SpaceEnums.sol"; import { SeaportInterface } from "seaport-sol/src/SeaportInterface.sol"; -import { HashValidationZoneOfferer } from - "../../../src/main/test/HashValidationZoneOfferer.sol"; +import { + HashValidationZoneOfferer +} from "../../../src/main/test/HashValidationZoneOfferer.sol"; -import { TestCalldataHashContractOfferer } from - "../../../src/main/test/TestCalldataHashContractOfferer.sol"; +import { + TestCalldataHashContractOfferer +} from "../../../src/main/test/TestCalldataHashContractOfferer.sol"; import { FuzzEngine, @@ -75,8 +77,9 @@ contract FuzzEngineTest is FuzzEngine { function setUp() public virtual override { super.setUp(); - OrderParameters memory standardOrderParameters = - OrderComponentsLib.fromDefault(STANDARD).toOrderParameters(); + OrderParameters memory standardOrderParameters = OrderComponentsLib + .fromDefault(STANDARD) + .toOrderParameters(); OrderLib.empty().withParameters(standardOrderParameters).saveDefault( STANDARD ); @@ -95,24 +98,31 @@ contract FuzzEngineTest is FuzzEngine { expectedActions[0] = SeaportInterface.fulfillOrder.selector; expectedActions[1] = SeaportInterface.fulfillAdvancedOrder.selector; expectedActions[2] = SeaportInterface.fulfillAvailableOrders.selector; - expectedActions[3] = - SeaportInterface.fulfillAvailableAdvancedOrders.selector; - - FuzzTestContext memory context = FuzzTestContextLib.from({ - orders: orders, - seaport: getSeaport(), - caller: address(this) - }).withFuzzParams( - FuzzParams({ - seed: 0, - totalOrders: 0, - maxOfferItems: 0, - maxConsiderationItems: 0, - seedInput: abi.encodePacked( - uint256(0), uint256(0), uint256(0), uint256(0) - ) + expectedActions[3] = SeaportInterface + .fulfillAvailableAdvancedOrders + .selector; + + FuzzTestContext memory context = FuzzTestContextLib + .from({ + orders: orders, + seaport: getSeaport(), + caller: address(this) }) - ).withMaximumFulfilled(1); + .withFuzzParams( + FuzzParams({ + seed: 0, + totalOrders: 0, + maxOfferItems: 0, + maxConsiderationItems: 0, + seedInput: abi.encodePacked( + uint256(0), + uint256(0), + uint256(0), + uint256(0) + ) + }) + ) + .withMaximumFulfilled(1); assertEq(context.actions(), expectedActions); } @@ -125,40 +135,53 @@ contract FuzzEngineTest is FuzzEngine { extraData: bytes("") }); - FuzzTestContext memory context = FuzzTestContextLib.from({ - orders: orders, - seaport: getSeaport(), - caller: address(this) - }).withFuzzParams( - FuzzParams({ - seed: 0, - totalOrders: 0, - maxOfferItems: 0, - maxConsiderationItems: 0, - seedInput: abi.encodePacked( - uint256(0), uint256(0), uint256(0), uint256(0) - ) + FuzzTestContext memory context = FuzzTestContextLib + .from({ + orders: orders, + seaport: getSeaport(), + caller: address(this) }) - ).withMaximumFulfilled(1); + .withFuzzParams( + FuzzParams({ + seed: 0, + totalOrders: 0, + maxOfferItems: 0, + maxConsiderationItems: 0, + seedInput: abi.encodePacked( + uint256(0), + uint256(0), + uint256(0), + uint256(0) + ) + }) + ) + .withMaximumFulfilled(1); assertEq(context.action(), SeaportInterface.fulfillOrder.selector); - context = FuzzTestContextLib.from({ - orders: orders, - seaport: getSeaport(), - caller: address(this) - }).withFuzzParams( - FuzzParams({ - seed: 1, - totalOrders: 0, - maxOfferItems: 0, - maxConsiderationItems: 0, - seedInput: abi.encodePacked( - uint256(0), uint256(0), uint256(0), uint256(0) - ) + context = FuzzTestContextLib + .from({ + orders: orders, + seaport: getSeaport(), + caller: address(this) }) - ).withMaximumFulfilled(1); + .withFuzzParams( + FuzzParams({ + seed: 1, + totalOrders: 0, + maxOfferItems: 0, + maxConsiderationItems: 0, + seedInput: abi.encodePacked( + uint256(0), + uint256(0), + uint256(0), + uint256(0) + ) + }) + ) + .withMaximumFulfilled(1); assertEq( - context.action(), SeaportInterface.fulfillAdvancedOrder.selector + context.action(), + SeaportInterface.fulfillAdvancedOrder.selector ); } @@ -173,24 +196,31 @@ contract FuzzEngineTest is FuzzEngine { bytes4[] memory expectedActions = new bytes4[](2); expectedActions[0] = SeaportInterface.fulfillAdvancedOrder.selector; - expectedActions[1] = - SeaportInterface.fulfillAvailableAdvancedOrders.selector; - - FuzzTestContext memory context = FuzzTestContextLib.from({ - orders: orders, - seaport: getSeaport(), - caller: address(this) - }).withFuzzParams( - FuzzParams({ - seed: 0, - totalOrders: 0, - maxOfferItems: 0, - maxConsiderationItems: 0, - seedInput: abi.encodePacked( - uint256(0), uint256(0), uint256(0), uint256(0) - ) + expectedActions[1] = SeaportInterface + .fulfillAvailableAdvancedOrders + .selector; + + FuzzTestContext memory context = FuzzTestContextLib + .from({ + orders: orders, + seaport: getSeaport(), + caller: address(this) }) - ).withMaximumFulfilled(orders.length); + .withFuzzParams( + FuzzParams({ + seed: 0, + totalOrders: 0, + maxOfferItems: 0, + maxConsiderationItems: 0, + seedInput: abi.encodePacked( + uint256(0), + uint256(0), + uint256(0), + uint256(0) + ) + }) + ) + .withMaximumFulfilled(orders.length); assertEq(context.actions(), expectedActions); } @@ -203,23 +233,30 @@ contract FuzzEngineTest is FuzzEngine { extraData: bytes("extra data") }); - FuzzTestContext memory context = FuzzTestContextLib.from({ - orders: orders, - seaport: getSeaport(), - caller: address(this) - }).withFuzzParams( - FuzzParams({ - seed: 0, - totalOrders: 0, - maxOfferItems: 0, - maxConsiderationItems: 0, - seedInput: abi.encodePacked( - uint256(0), uint256(0), uint256(0), uint256(0) - ) + FuzzTestContext memory context = FuzzTestContextLib + .from({ + orders: orders, + seaport: getSeaport(), + caller: address(this) }) - ).withMaximumFulfilled(1); + .withFuzzParams( + FuzzParams({ + seed: 0, + totalOrders: 0, + maxOfferItems: 0, + maxConsiderationItems: 0, + seedInput: abi.encodePacked( + uint256(0), + uint256(0), + uint256(0), + uint256(0) + ) + }) + ) + .withMaximumFulfilled(1); assertEq( - context.action(), SeaportInterface.fulfillAdvancedOrder.selector + context.action(), + SeaportInterface.fulfillAdvancedOrder.selector ); } @@ -227,38 +264,50 @@ contract FuzzEngineTest is FuzzEngine { function test_action_Single_Basic() public { AdvancedOrder[] memory orders = _setUpBasicOrder(); - FuzzTestContext memory context = FuzzTestContextLib.from({ - orders: orders, - seaport: getSeaport(), - caller: address(this) - }).withFuzzParams( - FuzzParams({ - seed: 2, - totalOrders: 0, - maxOfferItems: 0, - maxConsiderationItems: 0, - seedInput: abi.encodePacked( - uint256(2), uint256(0), uint256(0), uint256(0) - ) + FuzzTestContext memory context = FuzzTestContextLib + .from({ + orders: orders, + seaport: getSeaport(), + caller: address(this) }) - ).withMaximumFulfilled(1); + .withFuzzParams( + FuzzParams({ + seed: 2, + totalOrders: 0, + maxOfferItems: 0, + maxConsiderationItems: 0, + seedInput: abi.encodePacked( + uint256(2), + uint256(0), + uint256(0), + uint256(0) + ) + }) + ) + .withMaximumFulfilled(1); assertEq(context.action(), SeaportInterface.fulfillBasicOrder.selector); - context = FuzzTestContextLib.from({ - orders: orders, - seaport: getSeaport(), - caller: address(this) - }).withFuzzParams( - FuzzParams({ - seed: 3, - totalOrders: 0, - maxOfferItems: 0, - maxConsiderationItems: 0, - seedInput: abi.encodePacked( - uint256(3), uint256(0), uint256(0), uint256(0) - ) + context = FuzzTestContextLib + .from({ + orders: orders, + seaport: getSeaport(), + caller: address(this) }) - ).withMaximumFulfilled(1); + .withFuzzParams( + FuzzParams({ + seed: 3, + totalOrders: 0, + maxOfferItems: 0, + maxConsiderationItems: 0, + seedInput: abi.encodePacked( + uint256(3), + uint256(0), + uint256(0), + uint256(0) + ) + }) + ) + .withMaximumFulfilled(1); assertEq( context.action(), getSeaport().fulfillBasicOrder_efficient_6GL6yc.selector @@ -273,27 +322,35 @@ contract FuzzEngineTest is FuzzEngine { expectedActions[0] = SeaportInterface.fulfillOrder.selector; expectedActions[1] = SeaportInterface.fulfillAdvancedOrder.selector; expectedActions[2] = SeaportInterface.fulfillBasicOrder.selector; - expectedActions[3] = - SeaportInterface.fulfillBasicOrder_efficient_6GL6yc.selector; + expectedActions[3] = SeaportInterface + .fulfillBasicOrder_efficient_6GL6yc + .selector; expectedActions[4] = SeaportInterface.fulfillAvailableOrders.selector; - expectedActions[5] = - SeaportInterface.fulfillAvailableAdvancedOrders.selector; - - FuzzTestContext memory context = FuzzTestContextLib.from({ - orders: orders, - seaport: getSeaport(), - caller: address(this) - }).withFuzzParams( - FuzzParams({ - seed: 0, - totalOrders: 0, - maxOfferItems: 0, - maxConsiderationItems: 0, - seedInput: abi.encodePacked( - uint256(0), uint256(0), uint256(0), uint256(0) - ) + expectedActions[5] = SeaportInterface + .fulfillAvailableAdvancedOrders + .selector; + + FuzzTestContext memory context = FuzzTestContextLib + .from({ + orders: orders, + seaport: getSeaport(), + caller: address(this) }) - ).withMaximumFulfilled(orders.length); + .withFuzzParams( + FuzzParams({ + seed: 0, + totalOrders: 0, + maxOfferItems: 0, + maxConsiderationItems: 0, + seedInput: abi.encodePacked( + uint256(0), + uint256(0), + uint256(0), + uint256(0) + ) + }) + ) + .withMaximumFulfilled(orders.length); assertEq(context.actions(), expectedActions); } @@ -313,8 +370,9 @@ contract FuzzEngineTest is FuzzEngine { bytes4[] memory expectedActions = new bytes4[](4); expectedActions[0] = SeaportInterface.fulfillAvailableOrders.selector; - expectedActions[1] = - SeaportInterface.fulfillAvailableAdvancedOrders.selector; + expectedActions[1] = SeaportInterface + .fulfillAvailableAdvancedOrders + .selector; expectedActions[2] = SeaportInterface.matchOrders.selector; expectedActions[3] = SeaportInterface.matchAdvancedOrders.selector; // TODO: undo pended actions (cancel, validate) @@ -323,21 +381,27 @@ contract FuzzEngineTest is FuzzEngine { * expectedActions[5] = SeaportInterface.validate.selector; */ - FuzzTestContext memory context = FuzzTestContextLib.from({ - orders: orders, - seaport: getSeaport(), - caller: address(this) - }).withFuzzParams( - FuzzParams({ - seed: 0, - totalOrders: 0, - maxOfferItems: 0, - maxConsiderationItems: 0, - seedInput: abi.encodePacked( - uint256(0), uint256(0), uint256(0), uint256(0) - ) + FuzzTestContext memory context = FuzzTestContextLib + .from({ + orders: orders, + seaport: getSeaport(), + caller: address(this) }) - ).withMaximumFulfilled(orders.length); + .withFuzzParams( + FuzzParams({ + seed: 0, + totalOrders: 0, + maxOfferItems: 0, + maxConsiderationItems: 0, + seedInput: abi.encodePacked( + uint256(0), + uint256(0), + uint256(0), + uint256(0) + ) + }) + ) + .withMaximumFulfilled(orders.length); assertEq(context.actions(), expectedActions); } @@ -355,79 +419,105 @@ contract FuzzEngineTest is FuzzEngine { extraData: bytes("") }); - FuzzTestContext memory context = FuzzTestContextLib.from({ - orders: orders, - seaport: getSeaport(), - caller: address(this) - }).withFuzzParams( - FuzzParams({ - seed: 0, - totalOrders: 0, - maxOfferItems: 0, - maxConsiderationItems: 0, - seedInput: abi.encodePacked( - uint256(0), uint256(0), uint256(0), uint256(0) - ) + FuzzTestContext memory context = FuzzTestContextLib + .from({ + orders: orders, + seaport: getSeaport(), + caller: address(this) }) - ).withMaximumFulfilled(2); + .withFuzzParams( + FuzzParams({ + seed: 0, + totalOrders: 0, + maxOfferItems: 0, + maxConsiderationItems: 0, + seedInput: abi.encodePacked( + uint256(0), + uint256(0), + uint256(0), + uint256(0) + ) + }) + ) + .withMaximumFulfilled(2); assertEq( - context.action(), SeaportInterface.fulfillAvailableOrders.selector + context.action(), + SeaportInterface.fulfillAvailableOrders.selector ); - context = FuzzTestContextLib.from({ - orders: orders, - seaport: getSeaport(), - caller: address(this) - }).withFuzzParams( - FuzzParams({ - seed: 1, - totalOrders: 0, - maxOfferItems: 0, - maxConsiderationItems: 0, - seedInput: abi.encodePacked( - uint256(1), uint256(0), uint256(0), uint256(0) - ) + context = FuzzTestContextLib + .from({ + orders: orders, + seaport: getSeaport(), + caller: address(this) }) - ).withMaximumFulfilled(2); + .withFuzzParams( + FuzzParams({ + seed: 1, + totalOrders: 0, + maxOfferItems: 0, + maxConsiderationItems: 0, + seedInput: abi.encodePacked( + uint256(1), + uint256(0), + uint256(0), + uint256(0) + ) + }) + ) + .withMaximumFulfilled(2); assertEq( context.action(), getSeaport().fulfillAvailableAdvancedOrders.selector ); - context = FuzzTestContextLib.from({ - orders: orders, - seaport: getSeaport(), - caller: address(this) - }).withFuzzParams( - FuzzParams({ - seed: 2, - totalOrders: 0, - maxOfferItems: 0, - maxConsiderationItems: 0, - seedInput: abi.encodePacked( - uint256(2), uint256(0), uint256(0), uint256(0) - ) + context = FuzzTestContextLib + .from({ + orders: orders, + seaport: getSeaport(), + caller: address(this) }) - ).withMaximumFulfilled(2); + .withFuzzParams( + FuzzParams({ + seed: 2, + totalOrders: 0, + maxOfferItems: 0, + maxConsiderationItems: 0, + seedInput: abi.encodePacked( + uint256(2), + uint256(0), + uint256(0), + uint256(0) + ) + }) + ) + .withMaximumFulfilled(2); assertEq(context.action(), SeaportInterface.matchOrders.selector); - context = FuzzTestContextLib.from({ - orders: orders, - seaport: getSeaport(), - caller: address(this) - }).withFuzzParams( - FuzzParams({ - seed: 3, - totalOrders: 0, - maxOfferItems: 0, - maxConsiderationItems: 0, - seedInput: abi.encodePacked( - uint256(3), uint256(0), uint256(0), uint256(0) - ) + context = FuzzTestContextLib + .from({ + orders: orders, + seaport: getSeaport(), + caller: address(this) }) - ).withMaximumFulfilled(2); + .withFuzzParams( + FuzzParams({ + seed: 3, + totalOrders: 0, + maxOfferItems: 0, + maxConsiderationItems: 0, + seedInput: abi.encodePacked( + uint256(3), + uint256(0), + uint256(0), + uint256(0) + ) + }) + ) + .withMaximumFulfilled(2); assertEq( - context.action(), SeaportInterface.matchAdvancedOrders.selector + context.action(), + SeaportInterface.matchAdvancedOrders.selector ); // TODO: undo pended actions (match, cancel, validate) @@ -452,8 +542,9 @@ contract FuzzEngineTest is FuzzEngine { /// @dev Call exec for a single standard order. function test_exec_StandardOrder() public { - OrderComponents memory orderComponents = - OrderComponentsLib.fromDefault(STANDARD).withOfferer(offerer1.addr); + OrderComponents memory orderComponents = OrderComponentsLib + .fromDefault(STANDARD) + .withOfferer(offerer1.addr); bytes memory signature = signOrder( getSeaport(), @@ -461,9 +552,10 @@ contract FuzzEngineTest is FuzzEngine { getSeaport().getOrderHash(orderComponents) ); - Order memory order = OrderLib.fromDefault(STANDARD).withParameters( - orderComponents.toOrderParameters() - ).withSignature(signature); + Order memory order = OrderLib + .fromDefault(STANDARD) + .withParameters(orderComponents.toOrderParameters()) + .withSignature(signature); AdvancedOrder[] memory orders = new AdvancedOrder[](1); orders[0] = order.toAdvancedOrder({ @@ -472,21 +564,27 @@ contract FuzzEngineTest is FuzzEngine { extraData: bytes("") }); - FuzzTestContext memory context = FuzzTestContextLib.from({ - orders: orders, - seaport: getSeaport(), - caller: address(this) - }).withFuzzParams( - FuzzParams({ - seed: 0, - totalOrders: 0, - maxOfferItems: 0, - maxConsiderationItems: 0, - seedInput: abi.encodePacked( - uint256(0), uint256(0), uint256(0), uint256(0) - ) + FuzzTestContext memory context = FuzzTestContextLib + .from({ + orders: orders, + seaport: getSeaport(), + caller: address(this) }) - ).withMaximumFulfilled(orders.length); + .withFuzzParams( + FuzzParams({ + seed: 0, + totalOrders: 0, + maxOfferItems: 0, + maxConsiderationItems: 0, + seedInput: abi.encodePacked( + uint256(0), + uint256(0), + uint256(0), + uint256(0) + ) + }) + ) + .withMaximumFulfilled(orders.length); exec(context); assertEq(context.returnValues.fulfilled, true); @@ -494,8 +592,9 @@ contract FuzzEngineTest is FuzzEngine { /// @dev Call exec for a single advanced order. function test_exec_AdvancedOrder() public { - OrderComponents memory orderComponents = - OrderComponentsLib.fromDefault(STANDARD).withOfferer(offerer1.addr); + OrderComponents memory orderComponents = OrderComponentsLib + .fromDefault(STANDARD) + .withOfferer(offerer1.addr); bytes memory signature = signOrder( getSeaport(), @@ -503,9 +602,10 @@ contract FuzzEngineTest is FuzzEngine { getSeaport().getOrderHash(orderComponents) ); - Order memory order = OrderLib.fromDefault(STANDARD).withParameters( - orderComponents.toOrderParameters() - ).withSignature(signature); + Order memory order = OrderLib + .fromDefault(STANDARD) + .withParameters(orderComponents.toOrderParameters()) + .withSignature(signature); AdvancedOrder[] memory orders = new AdvancedOrder[](1); orders[0] = order.toAdvancedOrder({ @@ -514,21 +614,28 @@ contract FuzzEngineTest is FuzzEngine { extraData: bytes("extra data") }); - FuzzTestContext memory context = FuzzTestContextLib.from({ - orders: orders, - seaport: getSeaport(), - caller: address(this) - }).withFuzzParams( - FuzzParams({ - seed: 0, - totalOrders: 0, - maxOfferItems: 0, - maxConsiderationItems: 0, - seedInput: abi.encodePacked( - uint256(0), uint256(0), uint256(0), uint256(0) - ) + FuzzTestContext memory context = FuzzTestContextLib + .from({ + orders: orders, + seaport: getSeaport(), + caller: address(this) }) - ).withMaximumFulfilled(orders.length).withRecipient(address(0xbeef)); + .withFuzzParams( + FuzzParams({ + seed: 0, + totalOrders: 0, + maxOfferItems: 0, + maxConsiderationItems: 0, + seedInput: abi.encodePacked( + uint256(0), + uint256(0), + uint256(0), + uint256(0) + ) + }) + ) + .withMaximumFulfilled(orders.length) + .withRecipient(address(0xbeef)); exec(context); assertEq(context.returnValues.fulfilled, true); @@ -538,29 +645,32 @@ contract FuzzEngineTest is FuzzEngine { erc721s[0].mint(offerer1.addr, 1); OfferItem[] memory offerItems = new OfferItem[](1); - OfferItem memory offerItem = OfferItemLib.empty().withItemType( - ItemType.ERC721 - ).withToken(address(erc721s[0])).withIdentifierOrCriteria(1).withAmount( - 1 - ); + OfferItem memory offerItem = OfferItemLib + .empty() + .withItemType(ItemType.ERC721) + .withToken(address(erc721s[0])) + .withIdentifierOrCriteria(1) + .withAmount(1); offerItems[0] = offerItem; ConsiderationItem[] memory considerationItems = new ConsiderationItem[]( 1 ); - ConsiderationItem memory considerationItem = ConsiderationItemLib.empty( - ).withItemType(ItemType.ERC20).withToken(address(erc20s[0])).withAmount( - 1 - ).withRecipient(offerer1.addr); + ConsiderationItem memory considerationItem = ConsiderationItemLib + .empty() + .withItemType(ItemType.ERC20) + .withToken(address(erc20s[0])) + .withAmount(1) + .withRecipient(offerer1.addr); considerationItems[0] = considerationItem; - OrderComponents memory orderComponents = OrderComponentsLib.fromDefault( - STANDARD - ).withOfferer(offerer1.addr).withOffer(offerItems).withConsideration( - considerationItems - ); + OrderComponents memory orderComponents = OrderComponentsLib + .fromDefault(STANDARD) + .withOfferer(offerer1.addr) + .withOffer(offerItems) + .withConsideration(considerationItems); bytes memory signature = signOrder( getSeaport(), @@ -568,11 +678,14 @@ contract FuzzEngineTest is FuzzEngine { getSeaport().getOrderHash(orderComponents) ); - Order memory order = OrderLib.fromDefault(STANDARD).withParameters( - orderComponents.toOrderParameters().withOrderType( - OrderType.FULL_OPEN + Order memory order = OrderLib + .fromDefault(STANDARD) + .withParameters( + orderComponents.toOrderParameters().withOrderType( + OrderType.FULL_OPEN + ) ) - ).withSignature(signature); + .withSignature(signature); AdvancedOrder[] memory orders = new AdvancedOrder[](1); orders[0] = order.toAdvancedOrder({ @@ -592,23 +705,30 @@ contract FuzzEngineTest is FuzzEngine { bytes4[] memory checks = new bytes4[](1); checks[0] = this.check_orderFulfilled.selector; - FuzzTestContext memory context = FuzzTestContextLib.from({ - orders: orders, - seaport: getSeaport(), - caller: address(offerer1.addr) - }).withFuzzParams( - FuzzParams({ - seed: 2, - totalOrders: 0, - maxOfferItems: 0, - maxConsiderationItems: 0, - seedInput: abi.encodePacked( - uint256(2), uint256(0), uint256(0), uint256(0) - ) + FuzzTestContext memory context = FuzzTestContextLib + .from({ + orders: orders, + seaport: getSeaport(), + caller: address(offerer1.addr) }) - ).withMaximumFulfilled(orders.length).withBasicOrderParameters( - orders[0].toBasicOrderParameters(orders[0].getBasicOrderType()) - ); + .withFuzzParams( + FuzzParams({ + seed: 2, + totalOrders: 0, + maxOfferItems: 0, + maxConsiderationItems: 0, + seedInput: abi.encodePacked( + uint256(2), + uint256(0), + uint256(0), + uint256(0) + ) + }) + ) + .withMaximumFulfilled(orders.length) + .withBasicOrderParameters( + orders[0].toBasicOrderParameters(orders[0].getBasicOrderType()) + ); exec(context); } @@ -621,23 +741,30 @@ contract FuzzEngineTest is FuzzEngine { bytes4[] memory checks = new bytes4[](1); checks[0] = this.check_orderFulfilled.selector; - FuzzTestContext memory context = FuzzTestContextLib.from({ - orders: orders, - seaport: getSeaport(), - caller: address(offerer1.addr) - }).withFuzzParams( - FuzzParams({ - seed: 3, - totalOrders: 0, - maxOfferItems: 0, - maxConsiderationItems: 0, - seedInput: abi.encodePacked( - uint256(3), uint256(0), uint256(0), uint256(0) - ) + FuzzTestContext memory context = FuzzTestContextLib + .from({ + orders: orders, + seaport: getSeaport(), + caller: address(offerer1.addr) }) - ).withMaximumFulfilled(orders.length).withBasicOrderParameters( - orders[0].toBasicOrderParameters(orders[0].getBasicOrderType()) - ); + .withFuzzParams( + FuzzParams({ + seed: 3, + totalOrders: 0, + maxOfferItems: 0, + maxConsiderationItems: 0, + seedInput: abi.encodePacked( + uint256(3), + uint256(0), + uint256(0), + uint256(0) + ) + }) + ) + .withMaximumFulfilled(orders.length) + .withBasicOrderParameters( + orders[0].toBasicOrderParameters(orders[0].getBasicOrderType()) + ); exec(context); } @@ -647,42 +774,51 @@ contract FuzzEngineTest is FuzzEngine { function test_exec_Combined_FulfillAvailable() public { // Offer ERC20 OfferItem[] memory offerItems = new OfferItem[](1); - OfferItem memory offerItem = OfferItemLib.empty().withItemType( - ItemType.ERC20 - ).withToken(address(erc20s[0])).withStartAmount(1).withEndAmount(1); + OfferItem memory offerItem = OfferItemLib + .empty() + .withItemType(ItemType.ERC20) + .withToken(address(erc20s[0])) + .withStartAmount(1) + .withEndAmount(1); offerItems[0] = offerItem; // Consider single ERC721 to offerer1 erc721s[0].mint(address(this), 1); - ConsiderationItem[] memory considerationItems1 = - new ConsiderationItem[](1); - ConsiderationItem memory considerationItem = ConsiderationItemLib.empty( - ).withRecipient(offerer1.addr).withItemType(ItemType.ERC721).withToken( - address(erc721s[0]) - ).withIdentifierOrCriteria(1).withAmount(1); + ConsiderationItem[] + memory considerationItems1 = new ConsiderationItem[](1); + ConsiderationItem memory considerationItem = ConsiderationItemLib + .empty() + .withRecipient(offerer1.addr) + .withItemType(ItemType.ERC721) + .withToken(address(erc721s[0])) + .withIdentifierOrCriteria(1) + .withAmount(1); considerationItems1[0] = considerationItem; // Consider single ERC721 to offerer1 erc721s[0].mint(address(this), 2); - ConsiderationItem[] memory considerationItems2 = - new ConsiderationItem[](1); - considerationItem = ConsiderationItemLib.empty().withRecipient( - offerer1.addr - ).withItemType(ItemType.ERC721).withToken(address(erc721s[0])) - .withIdentifierOrCriteria(2).withAmount(1); + ConsiderationItem[] + memory considerationItems2 = new ConsiderationItem[](1); + considerationItem = ConsiderationItemLib + .empty() + .withRecipient(offerer1.addr) + .withItemType(ItemType.ERC721) + .withToken(address(erc721s[0])) + .withIdentifierOrCriteria(2) + .withAmount(1); considerationItems2[0] = considerationItem; - OrderComponents memory orderComponents1 = OrderComponentsLib.fromDefault( - STANDARD - ).withOfferer(offerer1.addr).withOffer(offerItems).withConsideration( - considerationItems1 - ); + OrderComponents memory orderComponents1 = OrderComponentsLib + .fromDefault(STANDARD) + .withOfferer(offerer1.addr) + .withOffer(offerItems) + .withConsideration(considerationItems1); - OrderComponents memory orderComponents2 = OrderComponentsLib.fromDefault( - STANDARD - ).withOfferer(offerer1.addr).withOffer(offerItems).withConsideration( - considerationItems2 - ); + OrderComponents memory orderComponents2 = OrderComponentsLib + .fromDefault(STANDARD) + .withOfferer(offerer1.addr) + .withOffer(offerItems) + .withConsideration(considerationItems2); bytes memory signature1 = signOrder( getSeaport(), @@ -690,9 +826,10 @@ contract FuzzEngineTest is FuzzEngine { getSeaport().getOrderHash(orderComponents1) ); - Order memory order1 = OrderLib.fromDefault(STANDARD).withParameters( - orderComponents1.toOrderParameters() - ).withSignature(signature1); + Order memory order1 = OrderLib + .fromDefault(STANDARD) + .withParameters(orderComponents1.toOrderParameters()) + .withSignature(signature1); bytes memory signature2 = signOrder( getSeaport(), @@ -700,9 +837,10 @@ contract FuzzEngineTest is FuzzEngine { getSeaport().getOrderHash(orderComponents2) ); - Order memory order2 = OrderLib.fromDefault(STANDARD).withParameters( - orderComponents2.toOrderParameters() - ).withSignature(signature2); + Order memory order2 = OrderLib + .fromDefault(STANDARD) + .withParameters(orderComponents2.toOrderParameters()) + .withSignature(signature2); Order[] memory orders = new Order[](2); orders[0] = order1; @@ -725,23 +863,29 @@ contract FuzzEngineTest is FuzzEngine { FulfillmentComponent[][] memory considerationComponents ) = getNaiveFulfillmentComponents(orders); - FuzzTestContext memory context = FuzzTestContextLib.from({ - orders: advancedOrders, - seaport: getSeaport(), - caller: address(this) - }).withFuzzParams( - FuzzParams({ - seed: 0, - totalOrders: 0, - maxOfferItems: 0, - maxConsiderationItems: 0, - seedInput: abi.encodePacked( - uint256(0), uint256(0), uint256(0), uint256(0) - ) + FuzzTestContext memory context = FuzzTestContextLib + .from({ + orders: advancedOrders, + seaport: getSeaport(), + caller: address(this) }) - ).withMaximumFulfilled(advancedOrders.length).withOfferFulfillments( - offerComponents - ).withConsiderationFulfillments(considerationComponents) + .withFuzzParams( + FuzzParams({ + seed: 0, + totalOrders: 0, + maxOfferItems: 0, + maxConsiderationItems: 0, + seedInput: abi.encodePacked( + uint256(0), + uint256(0), + uint256(0), + uint256(0) + ) + }) + ) + .withMaximumFulfilled(advancedOrders.length) + .withOfferFulfillments(offerComponents) + .withConsiderationFulfillments(considerationComponents) .withMaximumFulfilled(2); exec(context); @@ -752,51 +896,63 @@ contract FuzzEngineTest is FuzzEngine { assertEq(context.returnValues.executions.length, 4); assertEq( - context.returnValues.executions[0].item.itemType, ItemType.ERC20 + context.returnValues.executions[0].item.itemType, + ItemType.ERC20 ); assertEq( - context.returnValues.executions[0].item.token, address(erc20s[0]) + context.returnValues.executions[0].item.token, + address(erc20s[0]) ); assertEq(context.returnValues.executions[0].item.identifier, 0); assertEq(context.returnValues.executions[0].item.amount, 1); assertEq( - context.returnValues.executions[0].item.recipient, address(this) + context.returnValues.executions[0].item.recipient, + address(this) ); assertEq( - context.returnValues.executions[1].item.itemType, ItemType.ERC20 + context.returnValues.executions[1].item.itemType, + ItemType.ERC20 ); assertEq( - context.returnValues.executions[1].item.token, address(erc20s[0]) + context.returnValues.executions[1].item.token, + address(erc20s[0]) ); assertEq(context.returnValues.executions[1].item.identifier, 0); assertEq(context.returnValues.executions[1].item.amount, 1); assertEq( - context.returnValues.executions[1].item.recipient, address(this) + context.returnValues.executions[1].item.recipient, + address(this) ); assertEq( - context.returnValues.executions[2].item.itemType, ItemType.ERC721 + context.returnValues.executions[2].item.itemType, + ItemType.ERC721 ); assertEq( - context.returnValues.executions[2].item.token, address(erc721s[0]) + context.returnValues.executions[2].item.token, + address(erc721s[0]) ); assertEq(context.returnValues.executions[2].item.identifier, 1); assertEq(context.returnValues.executions[2].item.amount, 1); assertEq( - context.returnValues.executions[2].item.recipient, offerer1.addr + context.returnValues.executions[2].item.recipient, + offerer1.addr ); assertEq( - context.returnValues.executions[3].item.itemType, ItemType.ERC721 + context.returnValues.executions[3].item.itemType, + ItemType.ERC721 ); assertEq( - context.returnValues.executions[3].item.token, address(erc721s[0]) + context.returnValues.executions[3].item.token, + address(erc721s[0]) ); assertEq(context.returnValues.executions[3].item.identifier, 2); assertEq(context.returnValues.executions[3].item.amount, 1); assertEq( - context.returnValues.executions[3].item.recipient, offerer1.addr + context.returnValues.executions[3].item.recipient, + offerer1.addr ); assertEq(context.returnValues.executions[0].offerer, offerer1.addr); @@ -829,65 +985,77 @@ contract FuzzEngineTest is FuzzEngine { { OfferItem[] memory offerItems = new OfferItem[](1); - ConsiderationItem[] memory considerationItems1 = - new ConsiderationItem[](1); - ConsiderationItem[] memory considerationItems2 = - new ConsiderationItem[](1); + ConsiderationItem[] + memory considerationItems1 = new ConsiderationItem[](1); + ConsiderationItem[] + memory considerationItems2 = new ConsiderationItem[](1); { // Offer ERC20 - OfferItem memory offerItem = OfferItemLib.empty().withItemType( - ItemType.ERC20 - ).withToken(address(erc20s[0])).withStartAmount(1).withEndAmount( - 1 - ); + OfferItem memory offerItem = OfferItemLib + .empty() + .withItemType(ItemType.ERC20) + .withToken(address(erc20s[0])) + .withStartAmount(1) + .withEndAmount(1); offerItems[0] = offerItem; // Consider single ERC721 to offerer1 erc721s[0].mint(address(this), 1); - ConsiderationItem memory considerationItem = - ConsiderationItemLib.empty().withRecipient(offerer1.addr) - .withItemType(ItemType.ERC721).withToken(address(erc721s[0])) - .withIdentifierOrCriteria(1).withAmount(1); + ConsiderationItem + memory considerationItem = ConsiderationItemLib + .empty() + .withRecipient(offerer1.addr) + .withItemType(ItemType.ERC721) + .withToken(address(erc721s[0])) + .withIdentifierOrCriteria(1) + .withAmount(1); considerationItems1[0] = considerationItem; // Consider single ERC721 to offerer1 erc721s[0].mint(address(this), 2); - considerationItem = ConsiderationItemLib.empty().withRecipient( - offerer1.addr - ).withItemType(ItemType.ERC721).withToken(address(erc721s[0])) - .withIdentifierOrCriteria(2).withAmount(1); + considerationItem = ConsiderationItemLib + .empty() + .withRecipient(offerer1.addr) + .withItemType(ItemType.ERC721) + .withToken(address(erc721s[0])) + .withIdentifierOrCriteria(2) + .withAmount(1); considerationItems2[0] = considerationItem; } OrderComponents memory orderComponents1 = OrderComponentsLib - .fromDefault(STANDARD).withOfferer(offerer1.addr).withOffer( - offerItems - ).withConsideration(considerationItems1); + .fromDefault(STANDARD) + .withOfferer(offerer1.addr) + .withOffer(offerItems) + .withConsideration(considerationItems1); OrderComponents memory orderComponents2 = OrderComponentsLib - .fromDefault(STANDARD).withOfferer(offerer1.addr).withOffer( - offerItems - ).withConsideration(considerationItems2); - - Order memory order1 = OrderLib.fromDefault(STANDARD).withParameters( - orderComponents1.toOrderParameters() - ).withSignature( - signOrder( - getSeaport(), - offerer1.key, - getSeaport().getOrderHash(orderComponents1) - ) - ); + .fromDefault(STANDARD) + .withOfferer(offerer1.addr) + .withOffer(offerItems) + .withConsideration(considerationItems2); - Order memory order2 = OrderLib.fromDefault(STANDARD).withParameters( - orderComponents2.toOrderParameters() - ).withSignature( - signOrder( - getSeaport(), - offerer1.key, - getSeaport().getOrderHash(orderComponents2) - ) - ); + Order memory order1 = OrderLib + .fromDefault(STANDARD) + .withParameters(orderComponents1.toOrderParameters()) + .withSignature( + signOrder( + getSeaport(), + offerer1.key, + getSeaport().getOrderHash(orderComponents1) + ) + ); + + Order memory order2 = OrderLib + .fromDefault(STANDARD) + .withParameters(orderComponents2.toOrderParameters()) + .withSignature( + signOrder( + getSeaport(), + offerer1.key, + getSeaport().getOrderHash(orderComponents2) + ) + ); advancedOrders[0] = order1.toAdvancedOrder({ numerator: 1, @@ -910,25 +1078,32 @@ contract FuzzEngineTest is FuzzEngine { checks[0] = this.check_allOrdersFilled.selector; checks[1] = this.check_executionsPresent.selector; - FuzzTestContext memory context = FuzzTestContextLib.from({ - orders: advancedOrders, - seaport: getSeaport(), - caller: address(this) - }).withFuzzParams( - FuzzParams({ - seed: 1, - totalOrders: 0, - maxOfferItems: 0, - maxConsiderationItems: 0, - seedInput: abi.encodePacked( - uint256(1), uint256(0), uint256(0), uint256(0) - ) + FuzzTestContext memory context = FuzzTestContextLib + .from({ + orders: advancedOrders, + seaport: getSeaport(), + caller: address(this) }) - ).withMaximumFulfilled(advancedOrders.length); + .withFuzzParams( + FuzzParams({ + seed: 1, + totalOrders: 0, + maxOfferItems: 0, + maxConsiderationItems: 0, + seedInput: abi.encodePacked( + uint256(1), + uint256(0), + uint256(0), + uint256(0) + ) + }) + ) + .withMaximumFulfilled(advancedOrders.length); - context = context.withChecks(checks).withOfferFulfillments( - offerComponents - ).withConsiderationFulfillments(considerationComponents) + context = context + .withChecks(checks) + .withOfferFulfillments(offerComponents) + .withConsiderationFulfillments(considerationComponents) .withMaximumFulfilled(2); exec(context); @@ -942,60 +1117,71 @@ contract FuzzEngineTest is FuzzEngine { { OfferItem[] memory offerItemsPrime = new OfferItem[](1); OfferItem[] memory offerItemsMirror = new OfferItem[](1); - ConsiderationItem[] memory considerationItemsPrime = - new ConsiderationItem[](1); - ConsiderationItem[] memory considerationItemsMirror = - new ConsiderationItem[](1); + ConsiderationItem[] + memory considerationItemsPrime = new ConsiderationItem[](1); + ConsiderationItem[] + memory considerationItemsMirror = new ConsiderationItem[](1); { // Offer ERC20 - OfferItem memory offerItemPrime = OfferItemLib.empty() - .withItemType(ItemType.ERC20).withToken(address(erc20s[0])) - .withStartAmount(1).withEndAmount(1); + OfferItem memory offerItemPrime = OfferItemLib + .empty() + .withItemType(ItemType.ERC20) + .withToken(address(erc20s[0])) + .withStartAmount(1) + .withEndAmount(1); offerItemsPrime[0] = offerItemPrime; // Consider single ERC721 to offerer1 erc721s[0].mint(offerer2.addr, 1); - ConsiderationItem memory considerationItemPrime = - ConsiderationItemLib.empty().withRecipient(offerer1.addr) - .withItemType(ItemType.ERC721).withToken(address(erc721s[0])) - .withIdentifierOrCriteria(1).withAmount(1); + ConsiderationItem + memory considerationItemPrime = ConsiderationItemLib + .empty() + .withRecipient(offerer1.addr) + .withItemType(ItemType.ERC721) + .withToken(address(erc721s[0])) + .withIdentifierOrCriteria(1) + .withAmount(1); considerationItemsPrime[0] = considerationItemPrime; offerItemsMirror[0] = considerationItemsPrime[0].toOfferItem(); - considerationItemsMirror[0] = - offerItemsPrime[0].toConsiderationItem(offerer2.addr); + considerationItemsMirror[0] = offerItemsPrime[0] + .toConsiderationItem(offerer2.addr); } OrderComponents memory orderComponentsPrime = OrderComponentsLib - .fromDefault(STANDARD).withOfferer(offerer1.addr).withOffer( - offerItemsPrime - ).withConsideration(considerationItemsPrime); + .fromDefault(STANDARD) + .withOfferer(offerer1.addr) + .withOffer(offerItemsPrime) + .withConsideration(considerationItemsPrime); OrderComponents memory orderComponentsMirror = OrderComponentsLib - .fromDefault(STANDARD).withOfferer(offerer2.addr).withOffer( - offerItemsMirror - ).withConsideration(considerationItemsMirror); + .fromDefault(STANDARD) + .withOfferer(offerer2.addr) + .withOffer(offerItemsMirror) + .withConsideration(considerationItemsMirror); - Order memory orderPrime = OrderLib.fromDefault(STANDARD) + Order memory orderPrime = OrderLib + .fromDefault(STANDARD) .withParameters(orderComponentsPrime.toOrderParameters()) .withSignature( - signOrder( - getSeaport(), - offerer1.key, - getSeaport().getOrderHash(orderComponentsPrime) - ) - ); + signOrder( + getSeaport(), + offerer1.key, + getSeaport().getOrderHash(orderComponentsPrime) + ) + ); - Order memory orderMirror = OrderLib.fromDefault(STANDARD) + Order memory orderMirror = OrderLib + .fromDefault(STANDARD) .withParameters(orderComponentsMirror.toOrderParameters()) .withSignature( - signOrder( - getSeaport(), - offerer2.key, - getSeaport().getOrderHash(orderComponentsMirror) - ) - ); + signOrder( + getSeaport(), + offerer2.key, + getSeaport().getOrderHash(orderComponentsMirror) + ) + ); orders[0] = orderPrime.toAdvancedOrder({ numerator: 0, @@ -1015,10 +1201,11 @@ contract FuzzEngineTest is FuzzEngine { { CriteriaResolver[] memory resolvers; - bytes32[] memory orderHashes = - orders.getOrderHashes(address(seaport)); + bytes32[] memory orderHashes = orders.getOrderHashes( + address(seaport) + ); - (fulfillments,,) = matcher.getMatchedFulfillments( + (fulfillments, , ) = matcher.getMatchedFulfillments( orders, resolvers, orderHashes, @@ -1029,21 +1216,24 @@ contract FuzzEngineTest is FuzzEngine { bytes4[] memory checks = new bytes4[](1); checks[0] = this.check_executionsPresent.selector; - FuzzTestContext memory context = FuzzTestContextLib.from({ - orders: orders, - seaport: seaport, - caller: offerer1.addr - }).withFuzzParams( - FuzzParams({ - seed: 2, - totalOrders: 0, - maxOfferItems: 0, - maxConsiderationItems: 0, - seedInput: abi.encodePacked( - uint256(2), uint256(0), uint256(0), uint256(0) + FuzzTestContext memory context = FuzzTestContextLib + .from({ orders: orders, seaport: seaport, caller: offerer1.addr }) + .withFuzzParams( + FuzzParams({ + seed: 2, + totalOrders: 0, + maxOfferItems: 0, + maxConsiderationItems: 0, + seedInput: abi.encodePacked( + uint256(2), + uint256(0), + uint256(0), + uint256(0) ) - }) - ).withMaximumFulfilled(orders.length).withChecks(checks) + }) + ) + .withMaximumFulfilled(orders.length) + .withChecks(checks) .withFulfillments(fulfillments); exec(context); @@ -1057,60 +1247,71 @@ contract FuzzEngineTest is FuzzEngine { { OfferItem[] memory offerItemsPrime = new OfferItem[](1); OfferItem[] memory offerItemsMirror = new OfferItem[](1); - ConsiderationItem[] memory considerationItemsPrime = - new ConsiderationItem[](1); - ConsiderationItem[] memory considerationItemsMirror = - new ConsiderationItem[](1); + ConsiderationItem[] + memory considerationItemsPrime = new ConsiderationItem[](1); + ConsiderationItem[] + memory considerationItemsMirror = new ConsiderationItem[](1); { // Offer ERC20 - OfferItem memory offerItemPrime = OfferItemLib.empty() - .withItemType(ItemType.ERC20).withToken(address(erc20s[0])) - .withStartAmount(1).withEndAmount(1); + OfferItem memory offerItemPrime = OfferItemLib + .empty() + .withItemType(ItemType.ERC20) + .withToken(address(erc20s[0])) + .withStartAmount(1) + .withEndAmount(1); offerItemsPrime[0] = offerItemPrime; // Consider single ERC721 to offerer1 erc721s[0].mint(offerer2.addr, 1); - ConsiderationItem memory considerationItemPrime = - ConsiderationItemLib.empty().withRecipient(offerer1.addr) - .withItemType(ItemType.ERC721).withToken(address(erc721s[0])) - .withIdentifierOrCriteria(1).withAmount(1); + ConsiderationItem + memory considerationItemPrime = ConsiderationItemLib + .empty() + .withRecipient(offerer1.addr) + .withItemType(ItemType.ERC721) + .withToken(address(erc721s[0])) + .withIdentifierOrCriteria(1) + .withAmount(1); considerationItemsPrime[0] = considerationItemPrime; offerItemsMirror[0] = considerationItemsPrime[0].toOfferItem(); - considerationItemsMirror[0] = - offerItemsPrime[0].toConsiderationItem(offerer2.addr); + considerationItemsMirror[0] = offerItemsPrime[0] + .toConsiderationItem(offerer2.addr); } OrderComponents memory orderComponentsPrime = OrderComponentsLib - .fromDefault(STANDARD).withOfferer(offerer1.addr).withOffer( - offerItemsPrime - ).withConsideration(considerationItemsPrime); + .fromDefault(STANDARD) + .withOfferer(offerer1.addr) + .withOffer(offerItemsPrime) + .withConsideration(considerationItemsPrime); OrderComponents memory orderComponentsMirror = OrderComponentsLib - .fromDefault(STANDARD).withOfferer(offerer2.addr).withOffer( - offerItemsMirror - ).withConsideration(considerationItemsMirror); + .fromDefault(STANDARD) + .withOfferer(offerer2.addr) + .withOffer(offerItemsMirror) + .withConsideration(considerationItemsMirror); - Order memory orderPrime = OrderLib.fromDefault(STANDARD) + Order memory orderPrime = OrderLib + .fromDefault(STANDARD) .withParameters(orderComponentsPrime.toOrderParameters()) .withSignature( - signOrder( - getSeaport(), - offerer1.key, - getSeaport().getOrderHash(orderComponentsPrime) - ) - ); + signOrder( + getSeaport(), + offerer1.key, + getSeaport().getOrderHash(orderComponentsPrime) + ) + ); - Order memory orderMirror = OrderLib.fromDefault(STANDARD) + Order memory orderMirror = OrderLib + .fromDefault(STANDARD) .withParameters(orderComponentsMirror.toOrderParameters()) .withSignature( - signOrder( - getSeaport(), - offerer2.key, - getSeaport().getOrderHash(orderComponentsMirror) - ) - ); + signOrder( + getSeaport(), + offerer2.key, + getSeaport().getOrderHash(orderComponentsMirror) + ) + ); advancedOrders[0] = orderPrime.toAdvancedOrder({ numerator: 1, @@ -1129,11 +1330,12 @@ contract FuzzEngineTest is FuzzEngine { SeaportInterface seaport = getSeaport(); { - bytes32[] memory orderHashes = - advancedOrders.getOrderHashes(address(seaport)); + bytes32[] memory orderHashes = advancedOrders.getOrderHashes( + address(seaport) + ); CriteriaResolver[] memory resolvers; - (fulfillments,,) = matcher.getMatchedFulfillments( + (fulfillments, , ) = matcher.getMatchedFulfillments( advancedOrders, resolvers, orderHashes, @@ -1144,21 +1346,28 @@ contract FuzzEngineTest is FuzzEngine { bytes4[] memory checks = new bytes4[](1); checks[0] = this.check_executionsPresent.selector; - FuzzTestContext memory context = FuzzTestContextLib.from({ - orders: advancedOrders, - seaport: seaport, - caller: offerer1.addr - }).withFuzzParams( - FuzzParams({ - seed: 3, - totalOrders: 0, - maxOfferItems: 0, - maxConsiderationItems: 0, - seedInput: abi.encodePacked( - uint256(3), uint256(0), uint256(0), uint256(0) - ) + FuzzTestContext memory context = FuzzTestContextLib + .from({ + orders: advancedOrders, + seaport: seaport, + caller: offerer1.addr }) - ).withMaximumFulfilled(advancedOrders.length).withChecks(checks) + .withFuzzParams( + FuzzParams({ + seed: 3, + totalOrders: 0, + maxOfferItems: 0, + maxConsiderationItems: 0, + seedInput: abi.encodePacked( + uint256(3), + uint256(0), + uint256(0), + uint256(0) + ) + }) + ) + .withMaximumFulfilled(advancedOrders.length) + .withChecks(checks) .withFulfillments(fulfillments); exec(context); @@ -1168,8 +1377,9 @@ contract FuzzEngineTest is FuzzEngine { /// @dev Call exec for a combined order. Stub the fuzz seed so that it /// always calls Seaport.validate. function xtest_exec_Combined_Validate() public { - OrderComponents memory orderComponents = - OrderComponentsLib.fromDefault(STANDARD).withOfferer(offerer1.addr); + OrderComponents memory orderComponents = OrderComponentsLib + .fromDefault(STANDARD) + .withOfferer(offerer1.addr); bytes memory signature = signOrder( getSeaport(), @@ -1177,9 +1387,10 @@ contract FuzzEngineTest is FuzzEngine { getSeaport().getOrderHash(orderComponents) ); - Order memory order = OrderLib.fromDefault(STANDARD).withParameters( - orderComponents.toOrderParameters() - ).withSignature(signature); + Order memory order = OrderLib + .fromDefault(STANDARD) + .withParameters(orderComponents.toOrderParameters()) + .withSignature(signature); AdvancedOrder[] memory orders = new AdvancedOrder[](2); orders[0] = order.toAdvancedOrder({ @@ -1196,21 +1407,28 @@ contract FuzzEngineTest is FuzzEngine { bytes4[] memory checks = new bytes4[](1); checks[0] = this.check_orderValidated.selector; - FuzzTestContext memory context = FuzzTestContextLib.from({ - orders: orders, - seaport: getSeaport(), - caller: address(this) - }).withFuzzParams( - FuzzParams({ - seed: 5, - totalOrders: 0, - maxOfferItems: 0, - maxConsiderationItems: 0, - seedInput: abi.encodePacked( - uint256(5), uint256(0), uint256(0), uint256(0) - ) + FuzzTestContext memory context = FuzzTestContextLib + .from({ + orders: orders, + seaport: getSeaport(), + caller: address(this) }) - ).withMaximumFulfilled(orders.length).withChecks(checks); + .withFuzzParams( + FuzzParams({ + seed: 5, + totalOrders: 0, + maxOfferItems: 0, + maxConsiderationItems: 0, + seedInput: abi.encodePacked( + uint256(5), + uint256(0), + uint256(0), + uint256(0) + ) + }) + ) + .withMaximumFulfilled(orders.length) + .withChecks(checks); exec(context); checkAll(context); @@ -1219,8 +1437,9 @@ contract FuzzEngineTest is FuzzEngine { /// @dev Call exec for a combined order. Stub the fuzz seed so that it /// always calls Seaport.cancel. function xtest_exec_Combined_Cancel() public { - OrderComponents memory orderComponents = - OrderComponentsLib.fromDefault(STANDARD).withOfferer(offerer1.addr); + OrderComponents memory orderComponents = OrderComponentsLib + .fromDefault(STANDARD) + .withOfferer(offerer1.addr); bytes memory signature = signOrder( getSeaport(), @@ -1228,9 +1447,10 @@ contract FuzzEngineTest is FuzzEngine { getSeaport().getOrderHash(orderComponents) ); - Order memory order = OrderLib.fromDefault(STANDARD).withParameters( - orderComponents.toOrderParameters() - ).withSignature(signature); + Order memory order = OrderLib + .fromDefault(STANDARD) + .withParameters(orderComponents.toOrderParameters()) + .withSignature(signature); AdvancedOrder[] memory orders = new AdvancedOrder[](2); orders[0] = order.toAdvancedOrder({ @@ -1247,21 +1467,28 @@ contract FuzzEngineTest is FuzzEngine { bytes4[] memory checks = new bytes4[](1); checks[0] = this.check_orderCancelled.selector; - FuzzTestContext memory context = FuzzTestContextLib.from({ - orders: orders, - seaport: getSeaport(), - caller: offerer1.addr - }).withFuzzParams( - FuzzParams({ - seed: 4, - totalOrders: 0, - maxOfferItems: 0, - maxConsiderationItems: 0, - seedInput: abi.encodePacked( - uint256(4), uint256(0), uint256(0), uint256(0) - ) + FuzzTestContext memory context = FuzzTestContextLib + .from({ + orders: orders, + seaport: getSeaport(), + caller: offerer1.addr }) - ).withMaximumFulfilled(orders.length).withChecks(checks); + .withFuzzParams( + FuzzParams({ + seed: 4, + totalOrders: 0, + maxOfferItems: 0, + maxConsiderationItems: 0, + seedInput: abi.encodePacked( + uint256(4), + uint256(0), + uint256(0), + uint256(0) + ) + }) + ) + .withMaximumFulfilled(orders.length) + .withChecks(checks); exec(context); checkAll(context); @@ -1269,8 +1496,9 @@ contract FuzzEngineTest is FuzzEngine { /// @dev Call checkAll to run a simple check that always reverts. function test_check_StandardOrder_SimpleCheck() public { - OrderComponents memory orderComponents = - OrderComponentsLib.fromDefault(STANDARD).withOfferer(offerer1.addr); + OrderComponents memory orderComponents = OrderComponentsLib + .fromDefault(STANDARD) + .withOfferer(offerer1.addr); bytes memory signature = signOrder( getSeaport(), @@ -1278,9 +1506,10 @@ contract FuzzEngineTest is FuzzEngine { getSeaport().getOrderHash(orderComponents) ); - Order memory order = OrderLib.fromDefault(STANDARD).withParameters( - orderComponents.toOrderParameters() - ).withSignature(signature); + Order memory order = OrderLib + .fromDefault(STANDARD) + .withParameters(orderComponents.toOrderParameters()) + .withSignature(signature); AdvancedOrder[] memory orders = new AdvancedOrder[](1); orders[0] = order.toAdvancedOrder({ @@ -1292,21 +1521,28 @@ contract FuzzEngineTest is FuzzEngine { bytes4[] memory checks = new bytes4[](1); checks[0] = this.check_alwaysRevert.selector; - FuzzTestContext memory context = FuzzTestContextLib.from({ - orders: orders, - seaport: getSeaport(), - caller: address(this) - }).withFuzzParams( - FuzzParams({ - seed: 0, - totalOrders: 0, - maxOfferItems: 0, - maxConsiderationItems: 0, - seedInput: abi.encodePacked( - uint256(0), uint256(0), uint256(0), uint256(0) - ) + FuzzTestContext memory context = FuzzTestContextLib + .from({ + orders: orders, + seaport: getSeaport(), + caller: address(this) }) - ).withMaximumFulfilled(orders.length).withChecks(checks); + .withFuzzParams( + FuzzParams({ + seed: 0, + totalOrders: 0, + maxOfferItems: 0, + maxConsiderationItems: 0, + seedInput: abi.encodePacked( + uint256(0), + uint256(0), + uint256(0), + uint256(0) + ) + }) + ) + .withMaximumFulfilled(orders.length) + .withChecks(checks); exec(context); @@ -1316,8 +1552,9 @@ contract FuzzEngineTest is FuzzEngine { /// @dev Call checkAll to run a check that uses the FuzzTestContext. function test_check_StandardOrder_checkWithContext() public { - OrderComponents memory orderComponents = - OrderComponentsLib.fromDefault(STANDARD).withOfferer(offerer1.addr); + OrderComponents memory orderComponents = OrderComponentsLib + .fromDefault(STANDARD) + .withOfferer(offerer1.addr); bytes memory signature = signOrder( getSeaport(), @@ -1325,9 +1562,10 @@ contract FuzzEngineTest is FuzzEngine { getSeaport().getOrderHash(orderComponents) ); - Order memory order = OrderLib.fromDefault(STANDARD).withParameters( - orderComponents.toOrderParameters() - ).withSignature(signature); + Order memory order = OrderLib + .fromDefault(STANDARD) + .withParameters(orderComponents.toOrderParameters()) + .withSignature(signature); AdvancedOrder[] memory orders = new AdvancedOrder[](1); orders[0] = order.toAdvancedOrder({ @@ -1339,21 +1577,28 @@ contract FuzzEngineTest is FuzzEngine { bytes4[] memory checks = new bytes4[](1); checks[0] = this.check_revertWithContextData.selector; - FuzzTestContext memory context = FuzzTestContextLib.from({ - orders: orders, - seaport: getSeaport(), - caller: address(this) - }).withFuzzParams( - FuzzParams({ - seed: 0, - totalOrders: 0, - maxOfferItems: 0, - maxConsiderationItems: 0, - seedInput: abi.encodePacked( - uint256(0), uint256(0), uint256(0), uint256(0) - ) + FuzzTestContext memory context = FuzzTestContextLib + .from({ + orders: orders, + seaport: getSeaport(), + caller: address(this) }) - ).withMaximumFulfilled(orders.length).withChecks(checks); + .withFuzzParams( + FuzzParams({ + seed: 0, + totalOrders: 0, + maxOfferItems: 0, + maxConsiderationItems: 0, + seedInput: abi.encodePacked( + uint256(0), + uint256(0), + uint256(0), + uint256(0) + ) + }) + ) + .withMaximumFulfilled(orders.length) + .withChecks(checks); exec(context); @@ -1378,39 +1623,52 @@ contract FuzzEngineTest is FuzzEngine { ); // Offer ERC20 OfferItem[] memory offerItems = new OfferItem[](1); - OfferItem memory offerItem = OfferItemLib.empty().withItemType( - ItemType.ERC20 - ).withToken(address(erc20s[0])).withStartAmount(1).withEndAmount(1); + OfferItem memory offerItem = OfferItemLib + .empty() + .withItemType(ItemType.ERC20) + .withToken(address(erc20s[0])) + .withStartAmount(1) + .withEndAmount(1); offerItems[0] = offerItem; // Consider single ERC721 to offerer1 - ConsiderationItem[] memory considerationItems1 = - new ConsiderationItem[](1); + ConsiderationItem[] + memory considerationItems1 = new ConsiderationItem[](1); ConsiderationItem memory considerationItem = ConsiderationItemLib - .empty().withRecipient(offerer1.addr).withItemType(ItemType.ERC721) - .withToken(address(erc721s[0])).withIdentifierOrCriteria(1) + .empty() + .withRecipient(offerer1.addr) + .withItemType(ItemType.ERC721) + .withToken(address(erc721s[0])) + .withIdentifierOrCriteria(1) .withAmount(1); considerationItems1[0] = considerationItem; // Consider single ERC721 to offerer1 - ConsiderationItem[] memory considerationItems2 = - new ConsiderationItem[](1); - considerationItem = ConsiderationItemLib.empty().withRecipient( - offerer1.addr - ).withItemType(ItemType.ERC721).withToken(address(erc721s[0])) - .withIdentifierOrCriteria(2).withAmount(1); + ConsiderationItem[] + memory considerationItems2 = new ConsiderationItem[](1); + considerationItem = ConsiderationItemLib + .empty() + .withRecipient(offerer1.addr) + .withItemType(ItemType.ERC721) + .withToken(address(erc721s[0])) + .withIdentifierOrCriteria(2) + .withAmount(1); considerationItems2[0] = considerationItem; OrderComponents memory orderComponents1 = OrderComponentsLib - .fromDefault(STANDARD).withOfferer(offerer1.addr).withOffer( - offerItems - ).withZone(address(zone)).withOrderType(OrderType.FULL_RESTRICTED) + .fromDefault(STANDARD) + .withOfferer(offerer1.addr) + .withOffer(offerItems) + .withZone(address(zone)) + .withOrderType(OrderType.FULL_RESTRICTED) .withConsideration(considerationItems1); OrderComponents memory orderComponents2 = OrderComponentsLib - .fromDefault(STANDARD).withOfferer(offerer1.addr).withOffer( - offerItems - ).withZone(address(zone)).withOrderType(OrderType.FULL_RESTRICTED) + .fromDefault(STANDARD) + .withOfferer(offerer1.addr) + .withOffer(offerItems) + .withZone(address(zone)) + .withOrderType(OrderType.FULL_RESTRICTED) .withConsideration(considerationItems2); bytes memory signature1 = signOrder( @@ -1419,9 +1677,10 @@ contract FuzzEngineTest is FuzzEngine { getSeaport().getOrderHash(orderComponents1) ); - Order memory order1 = OrderLib.fromDefault(STANDARD).withParameters( - orderComponents1.toOrderParameters() - ).withSignature(signature1); + Order memory order1 = OrderLib + .fromDefault(STANDARD) + .withParameters(orderComponents1.toOrderParameters()) + .withSignature(signature1); bytes memory signature2 = signOrder( getSeaport(), @@ -1429,9 +1688,10 @@ contract FuzzEngineTest is FuzzEngine { getSeaport().getOrderHash(orderComponents2) ); - Order memory order2 = OrderLib.fromDefault(STANDARD).withParameters( - orderComponents2.toOrderParameters() - ).withSignature(signature2); + Order memory order2 = OrderLib + .fromDefault(STANDARD) + .withParameters(orderComponents2.toOrderParameters()) + .withSignature(signature2); orders[0] = order1; orders[1] = order2; @@ -1456,22 +1716,25 @@ contract FuzzEngineTest is FuzzEngine { bytes4[] memory checks = new bytes4[](1); checks[0] = this.check_validateOrderExpectedDataHash.selector; - FuzzTestContext memory context = FuzzTestContextLib.from({ - orders: advancedOrders, - seaport: getSeaport(), - caller: address(this) - }).withOfferFulfillments(offerComponents).withConsiderationFulfillments( - considerationComponents - ).withChecks(checks).withMaximumFulfilled(2); + FuzzTestContext memory context = FuzzTestContextLib + .from({ + orders: advancedOrders, + seaport: getSeaport(), + caller: address(this) + }) + .withOfferFulfillments(offerComponents) + .withConsiderationFulfillments(considerationComponents) + .withChecks(checks) + .withMaximumFulfilled(2); context.expectations.expectedZoneValidateCalldataHashes = advancedOrders .getExpectedZoneValidateCalldataHash( - address(getSeaport()), - address(this), - new CriteriaResolver[](0), - 2, - new UnavailableReason[](advancedOrders.length) - ); + address(getSeaport()), + address(this), + new CriteriaResolver[](0), + 2, + new UnavailableReason[](advancedOrders.length) + ); run(context); } @@ -1515,28 +1778,36 @@ contract FuzzEngineTest is FuzzEngine { AdvancedOrder[] memory orders; { OrderComponents memory orderComponents1 = OrderComponentsLib - .fromDefault(STANDARD).withOfferer(address(contractOfferer1)) + .fromDefault(STANDARD) + .withOfferer(address(contractOfferer1)) .withOrderType(OrderType.CONTRACT); { TestCalldataHashContractOfferer _temp = contractOfferer1; { - ConsiderationItem[] memory considerationItems = - SeaportArrays.ConsiderationItems( - ConsiderationItemLib.empty().withRecipient( - address(_temp) - ).withItemType(ItemType.ERC721).withToken( - address(erc721s[0]) - ).withIdentifierOrCriteria(1).withAmount(1) + ConsiderationItem[] + memory considerationItems = SeaportArrays + .ConsiderationItems( + ConsiderationItemLib + .empty() + .withRecipient(address(_temp)) + .withItemType(ItemType.ERC721) + .withToken(address(erc721s[0])) + .withIdentifierOrCriteria(1) + .withAmount(1) + ); + orderComponents1 = orderComponents1.withConsideration( + considerationItems ); - orderComponents1 = - orderComponents1.withConsideration(considerationItems); } // Offer ERC20 { OfferItem[] memory offerItems = SeaportArrays.OfferItems( - OfferItemLib.empty().withItemType(ItemType.ERC20) - .withToken(address(erc20s[0])).withStartAmount(1) + OfferItemLib + .empty() + .withItemType(ItemType.ERC20) + .withToken(address(erc20s[0])) + .withStartAmount(1) .withEndAmount(1) ); orderComponents1 = orderComponents1.withOffer(offerItems); @@ -1551,17 +1822,21 @@ contract FuzzEngineTest is FuzzEngine { // Overwrite existing ConsiderationItem[] for order2 ConsiderationItem[] memory considerationItems = SeaportArrays .ConsiderationItems( - ConsiderationItemLib.empty().withRecipient(address(_temp)) - .withItemType(ItemType.ERC721).withToken( - address(erc721s[0]) - ).withIdentifierOrCriteria(2).withAmount(1) - ); + ConsiderationItemLib + .empty() + .withRecipient(address(_temp)) + .withItemType(ItemType.ERC721) + .withToken(address(erc721s[0])) + .withIdentifierOrCriteria(2) + .withAmount(1) + ); - orderComponents2 = OrderComponentsLib.fromDefault(STANDARD) - .withOfferer(address(_temp)).withOffer(orderComponents1.offer) - .withOrderType(OrderType.CONTRACT).withConsideration( - considerationItems - ); + orderComponents2 = OrderComponentsLib + .fromDefault(STANDARD) + .withOfferer(address(_temp)) + .withOffer(orderComponents1.offer) + .withOrderType(OrderType.CONTRACT) + .withConsideration(considerationItems); } orders = SeaportArrays.AdvancedOrders( AdvancedOrderLib.fromDefault(FULL).withParameters( @@ -1606,42 +1881,53 @@ contract FuzzEngineTest is FuzzEngine { FulfillmentComponent[][] memory offerComponents; FulfillmentComponent[][] memory considerationComponents; - (advancedOrders, offerComponents, considerationComponents) = - _getAdvancedOrdersAndFulfillmentComponents( - contractOfferer1, contractOfferer2 + ( + advancedOrders, + offerComponents, + considerationComponents + ) = _getAdvancedOrdersAndFulfillmentComponents( + contractOfferer1, + contractOfferer2 ); { bytes4[] memory checks = new bytes4[](1); checks[0] = this.check_contractOrderExpectedDataHashes.selector; - FuzzTestContext memory context = FuzzTestContextLib.from({ - orders: advancedOrders, - seaport: getSeaport(), - caller: address(this) - }).withFuzzParams( - FuzzParams({ - seed: 0, - totalOrders: 0, - maxOfferItems: 0, - maxConsiderationItems: 0, - seedInput: abi.encodePacked( - uint256(0), uint256(0), uint256(0), uint256(0) - ) + FuzzTestContext memory context = FuzzTestContextLib + .from({ + orders: advancedOrders, + seaport: getSeaport(), + caller: address(this) }) - ); + .withFuzzParams( + FuzzParams({ + seed: 0, + totalOrders: 0, + maxOfferItems: 0, + maxConsiderationItems: 0, + seedInput: abi.encodePacked( + uint256(0), + uint256(0), + uint256(0), + uint256(0) + ) + }) + ); - context = context.withMaximumFulfilled(advancedOrders.length) + context = context + .withMaximumFulfilled(advancedOrders.length) .withOfferFulfillments(offerComponents) - .withConsiderationFulfillments(considerationComponents).withChecks( - checks - ).withMaximumFulfilled(2); + .withConsiderationFulfillments(considerationComponents) + .withChecks(checks) + .withMaximumFulfilled(2); bytes32[2][] memory expectedContractOrderCalldataHashes; - expectedContractOrderCalldataHashes = - context.getExpectedContractOffererCalldataHashes(); - context.expectations.expectedContractOrderCalldataHashes = - expectedContractOrderCalldataHashes; + expectedContractOrderCalldataHashes = context + .getExpectedContractOffererCalldataHashes(); + context + .expectations + .expectedContractOrderCalldataHashes = expectedContractOrderCalldataHashes; run(context); } @@ -1650,8 +1936,9 @@ contract FuzzEngineTest is FuzzEngine { /// @dev Call run for a combined order. Stub the fuzz seed so that it /// always calls Seaport.cancel. function xtest_run_Combined_Cancel() public { - OrderComponents memory orderComponents = - OrderComponentsLib.fromDefault(STANDARD).withOfferer(offerer1.addr); + OrderComponents memory orderComponents = OrderComponentsLib + .fromDefault(STANDARD) + .withOfferer(offerer1.addr); bytes memory signature = signOrder( getSeaport(), @@ -1659,9 +1946,10 @@ contract FuzzEngineTest is FuzzEngine { getSeaport().getOrderHash(orderComponents) ); - Order memory order = OrderLib.fromDefault(STANDARD).withParameters( - orderComponents.toOrderParameters() - ).withSignature(signature); + Order memory order = OrderLib + .fromDefault(STANDARD) + .withParameters(orderComponents.toOrderParameters()) + .withSignature(signature); AdvancedOrder[] memory orders = new AdvancedOrder[](2); orders[0] = order.toAdvancedOrder({ @@ -1678,21 +1966,28 @@ contract FuzzEngineTest is FuzzEngine { bytes4[] memory checks = new bytes4[](1); checks[0] = this.check_orderCancelled.selector; - FuzzTestContext memory context = FuzzTestContextLib.from({ - orders: orders, - seaport: getSeaport(), - caller: offerer1.addr - }).withFuzzParams( - FuzzParams({ - seed: 4, - totalOrders: 0, - maxOfferItems: 0, - maxConsiderationItems: 0, - seedInput: abi.encodePacked( - uint256(4), uint256(0), uint256(0), uint256(0) - ) + FuzzTestContext memory context = FuzzTestContextLib + .from({ + orders: orders, + seaport: getSeaport(), + caller: offerer1.addr }) - ).withMaximumFulfilled(orders.length).withChecks(checks); + .withFuzzParams( + FuzzParams({ + seed: 4, + totalOrders: 0, + maxOfferItems: 0, + maxConsiderationItems: 0, + seedInput: abi.encodePacked( + uint256(4), + uint256(0), + uint256(0), + uint256(0) + ) + }) + ) + .withMaximumFulfilled(orders.length) + .withChecks(checks); run(context); } @@ -1703,10 +1998,9 @@ contract FuzzEngineTest is FuzzEngine { } /// @dev Example of a "check" function that uses the test context. - function check_revertWithContextData(FuzzTestContext memory context) - public - pure - { + function check_revertWithContextData( + FuzzTestContext memory context + ) public pure { revert ExampleErrorWithContextData( context.executionState.orders[0].signature ); diff --git a/test/foundry/new/FuzzGenerators.t.sol b/test/foundry/new/FuzzGenerators.t.sol index 55de880..d5254e5 100644 --- a/test/foundry/new/FuzzGenerators.t.sol +++ b/test/foundry/new/FuzzGenerators.t.sol @@ -47,11 +47,13 @@ import { TestHelpers } from "./helpers/FuzzTestContextLib.sol"; import { EIP1271Offerer } from "../new/helpers/EIP1271Offerer.sol"; -import { HashValidationZoneOfferer } from - "../../../src/main/test/HashValidationZoneOfferer.sol"; +import { + HashValidationZoneOfferer +} from "../../../src/main/test/HashValidationZoneOfferer.sol"; -import { HashCalldataContractOfferer } from - "../../../src/main/test/HashCalldataContractOfferer.sol"; +import { + HashCalldataContractOfferer +} from "../../../src/main/test/HashCalldataContractOfferer.sol"; import { DefaultFulfillmentGeneratorLib, @@ -73,38 +75,42 @@ contract FuzzGeneratorsTest is BaseOrderTest { potential1155TokenIds[1] = 2; potential1155TokenIds[2] = 3; - return FuzzGeneratorContext({ - vm: vm, - testHelpers: TestHelpers(address(this)), - prng: prng, - timestamp: block.timestamp, - seaport: getSeaport(), - conduitController: getConduitController(), - validatorZone: new HashValidationZoneOfferer(address(0)), - contractOfferer: new HashCalldataContractOfferer(address(0)), - eip1271Offerer: new EIP1271Offerer(), - erc20s: erc20s, - erc721s: erc721s, - erc1155s: erc1155s, - self: address(this), - caller: address(this), - alice: makeAccountWrapper("alice"), - bob: makeAccountWrapper("bob"), - carol: makeAccountWrapper("carol"), - dillon: makeAccountWrapper("dillon"), - eve: makeAccountWrapper("eve"), - frank: makeAccountWrapper("frank"), - starting721offerIndex: 1, - starting721considerationIndex: 1, - potential1155TokenIds: potential1155TokenIds, - conduits: new TestConduit[](2), - basicOrderCategory: BasicOrderCategory.NONE, - basicOfferSpace: OfferItemSpace( - ItemType.NATIVE, TokenIndex.ONE, Criteria.MERKLE, Amount.FIXED + return + FuzzGeneratorContext({ + vm: vm, + testHelpers: TestHelpers(address(this)), + prng: prng, + timestamp: block.timestamp, + seaport: getSeaport(), + conduitController: getConduitController(), + validatorZone: new HashValidationZoneOfferer(address(0)), + contractOfferer: new HashCalldataContractOfferer(address(0)), + eip1271Offerer: new EIP1271Offerer(), + erc20s: erc20s, + erc721s: erc721s, + erc1155s: erc1155s, + self: address(this), + caller: address(this), + alice: makeAccountWrapper("alice"), + bob: makeAccountWrapper("bob"), + carol: makeAccountWrapper("carol"), + dillon: makeAccountWrapper("dillon"), + eve: makeAccountWrapper("eve"), + frank: makeAccountWrapper("frank"), + starting721offerIndex: 1, + starting721considerationIndex: 1, + potential1155TokenIds: potential1155TokenIds, + conduits: new TestConduit[](2), + basicOrderCategory: BasicOrderCategory.NONE, + basicOfferSpace: OfferItemSpace( + ItemType.NATIVE, + TokenIndex.ONE, + Criteria.MERKLE, + Amount.FIXED ), - counter: 0, - contractOffererNonce: 0 - }); + counter: 0, + contractOffererNonce: 0 + }); } // NOTE: empty order space is not supported for now @@ -117,18 +123,21 @@ contract FuzzGeneratorsTest is BaseOrderTest { recipient: FulfillmentRecipient.ZERO, conduit: ConduitChoice.NONE, caller: Caller.TEST_CONTRACT, - strategy: DefaultFulfillmentGeneratorLib.getDefaultFulfillmentStrategy() + strategy: DefaultFulfillmentGeneratorLib + .getDefaultFulfillmentStrategy() }); - AdvancedOrder[] memory orders = - AdvancedOrdersSpaceGenerator.generate(space, context); + AdvancedOrder[] memory orders = AdvancedOrdersSpaceGenerator.generate( + space, + context + ); assertEq(orders.length, 0); } function test_emptyOfferConsideration() public { FuzzGeneratorContext memory context = createContext(); OfferItemSpace[] memory offer = new OfferItemSpace[](0); - ConsiderationItemSpace[] memory consideration = - new ConsiderationItemSpace[](0); + ConsiderationItemSpace[] + memory consideration = new ConsiderationItemSpace[](0); OrderComponentsSpace memory component = OrderComponentsSpace({ offerer: Offerer.ALICE, @@ -161,10 +170,13 @@ contract FuzzGeneratorsTest is BaseOrderTest { recipient: FulfillmentRecipient.ZERO, conduit: ConduitChoice.NONE, caller: Caller.TEST_CONTRACT, - strategy: DefaultFulfillmentGeneratorLib.getDefaultFulfillmentStrategy() + strategy: DefaultFulfillmentGeneratorLib + .getDefaultFulfillmentStrategy() }); - AdvancedOrder[] memory orders = - AdvancedOrdersSpaceGenerator.generate(space, context); + AdvancedOrder[] memory orders = AdvancedOrdersSpaceGenerator.generate( + space, + context + ); assertEq(orders.length, 1); assertEq(orders[0].parameters.offer.length, 0); // Empty order groups have a consideration item inserted on some order @@ -180,8 +192,8 @@ contract FuzzGeneratorsTest is BaseOrderTest { criteria: Criteria.MERKLE, amount: Amount.FIXED }); - ConsiderationItemSpace[] memory consideration = - new ConsiderationItemSpace[](0); + ConsiderationItemSpace[] + memory consideration = new ConsiderationItemSpace[](0); OrderComponentsSpace memory component = OrderComponentsSpace({ offerer: Offerer.ALICE, @@ -214,10 +226,13 @@ contract FuzzGeneratorsTest is BaseOrderTest { recipient: FulfillmentRecipient.ZERO, conduit: ConduitChoice.NONE, caller: Caller.TEST_CONTRACT, - strategy: DefaultFulfillmentGeneratorLib.getDefaultFulfillmentStrategy() + strategy: DefaultFulfillmentGeneratorLib + .getDefaultFulfillmentStrategy() }); - AdvancedOrder[] memory orders = - AdvancedOrdersSpaceGenerator.generate(space, context); + AdvancedOrder[] memory orders = AdvancedOrdersSpaceGenerator.generate( + space, + context + ); assertEq(orders.length, 1); assertEq(orders[0].parameters.offer.length, 1); @@ -237,8 +252,8 @@ contract FuzzGeneratorsTest is BaseOrderTest { function test_emptyOffer_singleConsideration() public { FuzzGeneratorContext memory context = createContext(); OfferItemSpace[] memory offer = new OfferItemSpace[](0); - ConsiderationItemSpace[] memory consideration = - new ConsiderationItemSpace[](1); + ConsiderationItemSpace[] + memory consideration = new ConsiderationItemSpace[](1); consideration[0] = ConsiderationItemSpace({ itemType: ItemType.ERC20, tokenIndex: TokenIndex.ONE, @@ -278,10 +293,13 @@ contract FuzzGeneratorsTest is BaseOrderTest { recipient: FulfillmentRecipient.ZERO, conduit: ConduitChoice.NONE, caller: Caller.TEST_CONTRACT, - strategy: DefaultFulfillmentGeneratorLib.getDefaultFulfillmentStrategy() + strategy: DefaultFulfillmentGeneratorLib + .getDefaultFulfillmentStrategy() }); - AdvancedOrder[] memory orders = - AdvancedOrdersSpaceGenerator.generate(space, context); + AdvancedOrder[] memory orders = AdvancedOrdersSpaceGenerator.generate( + space, + context + ); assertEq(orders.length, 1); assertEq(orders[0].parameters.offer.length, 0); assertEq(orders[0].parameters.consideration.length, 1); @@ -296,7 +314,10 @@ contract FuzzGeneratorsTest is BaseOrderTest { orders[0].parameters.offerer ); - assertEq(orders[0].parameters.consideration[0].itemType, ItemType.ERC20); + assertEq( + orders[0].parameters.consideration[0].itemType, + ItemType.ERC20 + ); } function assertEq(ItemType a, ItemType b) internal { diff --git a/test/foundry/new/FuzzHelpers.t.sol b/test/foundry/new/FuzzHelpers.t.sol index 721bcc9..c26bb61 100644 --- a/test/foundry/new/FuzzHelpers.t.sol +++ b/test/foundry/new/FuzzHelpers.t.sol @@ -58,8 +58,9 @@ contract FuzzHelpersTest is BaseOrderTest { function setUp() public virtual override { super.setUp(); - OrderParameters memory standardOrderParameters = - OrderComponentsLib.fromDefault(STANDARD).toOrderParameters(); + OrderParameters memory standardOrderParameters = OrderComponentsLib + .fromDefault(STANDARD) + .toOrderParameters(); OrderLib.empty().withParameters(standardOrderParameters).saveDefault( STANDARD @@ -68,8 +69,13 @@ contract FuzzHelpersTest is BaseOrderTest { /// @dev An order with no advanced order parameters is STANDARD function test_getStructure_Standard() public { - AdvancedOrder memory order = OrderLib.fromDefault(STANDARD) - .toAdvancedOrder({ numerator: 0, denominator: 0, extraData: bytes("") }); + AdvancedOrder memory order = OrderLib + .fromDefault(STANDARD) + .toAdvancedOrder({ + numerator: 0, + denominator: 0, + extraData: bytes("") + }); assertEq(order.getStructure(address(getSeaport())), Structure.STANDARD); } @@ -80,35 +86,41 @@ contract FuzzHelpersTest is BaseOrderTest { erc721s[0].mint(offerer1.addr, 1); OfferItem[] memory offerItems = new OfferItem[](1); - OfferItem memory offerItem = OfferItemLib.empty().withItemType( - ItemType.ERC721 - ).withToken(address(erc721s[0])).withIdentifierOrCriteria(1).withAmount( - 1 - ); + OfferItem memory offerItem = OfferItemLib + .empty() + .withItemType(ItemType.ERC721) + .withToken(address(erc721s[0])) + .withIdentifierOrCriteria(1) + .withAmount(1); offerItems[0] = offerItem; ConsiderationItem[] memory considerationItems = new ConsiderationItem[]( 1 ); - ConsiderationItem memory considerationItem = ConsiderationItemLib.empty( - ).withItemType(ItemType.ERC20).withToken(address(erc20s[0])).withAmount( - 1 - ).withRecipient(offerer1.addr); + ConsiderationItem memory considerationItem = ConsiderationItemLib + .empty() + .withItemType(ItemType.ERC20) + .withToken(address(erc20s[0])) + .withAmount(1) + .withRecipient(offerer1.addr); considerationItems[0] = considerationItem; - OrderComponents memory orderComponents = OrderComponentsLib.fromDefault( - STANDARD - ).withOfferer(offerer1.addr).withOffer(offerItems).withConsideration( - considerationItems - ); - - Order memory order = OrderLib.fromDefault(STANDARD).withParameters( - orderComponents.toOrderParameters().withOrderType( - OrderType.FULL_OPEN + OrderComponents memory orderComponents = OrderComponentsLib + .fromDefault(STANDARD) + .withOfferer(offerer1.addr) + .withOffer(offerItems) + .withConsideration(considerationItems); + + Order memory order = OrderLib + .fromDefault(STANDARD) + .withParameters( + orderComponents.toOrderParameters().withOrderType( + OrderType.FULL_OPEN + ) ) - ).withSignature(""); + .withSignature(""); AdvancedOrder memory advancedOrder = order.toAdvancedOrder({ numerator: 0, @@ -117,7 +129,8 @@ contract FuzzHelpersTest is BaseOrderTest { }); assertEq( - advancedOrder.getStructure(address(getSeaport())), Structure.BASIC + advancedOrder.getStructure(address(getSeaport())), + Structure.BASIC ); } @@ -131,12 +144,13 @@ contract FuzzHelpersTest is BaseOrderTest { vm.assume(denominator != 0); vm.assume(extraData.length != 0); - AdvancedOrder memory order = OrderLib.fromDefault(STANDARD) + AdvancedOrder memory order = OrderLib + .fromDefault(STANDARD) .toAdvancedOrder({ - numerator: numerator, - denominator: denominator, - extraData: extraData - }); + numerator: numerator, + denominator: denominator, + extraData: extraData + }); assertEq(order.getStructure(address(getSeaport())), Structure.ADVANCED); } @@ -144,19 +158,23 @@ contract FuzzHelpersTest is BaseOrderTest { /// @dev A non-contract order with offer item criteria is ADVANCED function test_getStructure_Advanced_OfferERC721Criteria() public { OfferItem[] memory offer = new OfferItem[](1); - offer[0] = - OfferItemLib.empty().withItemType(ItemType.ERC721_WITH_CRITERIA); + offer[0] = OfferItemLib.empty().withItemType( + ItemType.ERC721_WITH_CRITERIA + ); - OrderParameters memory orderParameters = OrderComponentsLib.fromDefault( - STANDARD - ).toOrderParameters().withOffer(offer); + OrderParameters memory orderParameters = OrderComponentsLib + .fromDefault(STANDARD) + .toOrderParameters() + .withOffer(offer); - AdvancedOrder memory order = OrderLib.fromDefault(STANDARD) - .withParameters(orderParameters).toAdvancedOrder({ - numerator: 0, - denominator: 0, - extraData: bytes("") - }); + AdvancedOrder memory order = OrderLib + .fromDefault(STANDARD) + .withParameters(orderParameters) + .toAdvancedOrder({ + numerator: 0, + denominator: 0, + extraData: bytes("") + }); assertEq(order.getStructure(address(getSeaport())), Structure.ADVANCED); } @@ -164,19 +182,23 @@ contract FuzzHelpersTest is BaseOrderTest { /// @dev A non-contract order with offer item criteria is ADVANCED function test_getStructure_Advanced_OfferERC1155Criteria() public { OfferItem[] memory offer = new OfferItem[](1); - offer[0] = - OfferItemLib.empty().withItemType(ItemType.ERC1155_WITH_CRITERIA); + offer[0] = OfferItemLib.empty().withItemType( + ItemType.ERC1155_WITH_CRITERIA + ); - OrderParameters memory orderParameters = OrderComponentsLib.fromDefault( - STANDARD - ).toOrderParameters().withOffer(offer); + OrderParameters memory orderParameters = OrderComponentsLib + .fromDefault(STANDARD) + .toOrderParameters() + .withOffer(offer); - AdvancedOrder memory order = OrderLib.fromDefault(STANDARD) - .withParameters(orderParameters).toAdvancedOrder({ - numerator: 0, - denominator: 0, - extraData: bytes("") - }); + AdvancedOrder memory order = OrderLib + .fromDefault(STANDARD) + .withParameters(orderParameters) + .toAdvancedOrder({ + numerator: 0, + denominator: 0, + extraData: bytes("") + }); assertEq(order.getStructure(address(getSeaport())), Structure.ADVANCED); } @@ -188,16 +210,19 @@ contract FuzzHelpersTest is BaseOrderTest { ItemType.ERC721_WITH_CRITERIA ); - OrderParameters memory orderParameters = OrderComponentsLib.fromDefault( - STANDARD - ).toOrderParameters().withConsideration(consideration); + OrderParameters memory orderParameters = OrderComponentsLib + .fromDefault(STANDARD) + .toOrderParameters() + .withConsideration(consideration); - AdvancedOrder memory order = OrderLib.fromDefault(STANDARD) - .withParameters(orderParameters).toAdvancedOrder({ - numerator: 0, - denominator: 0, - extraData: bytes("") - }); + AdvancedOrder memory order = OrderLib + .fromDefault(STANDARD) + .withParameters(orderParameters) + .toAdvancedOrder({ + numerator: 0, + denominator: 0, + extraData: bytes("") + }); assertEq(order.getStructure(address(getSeaport())), Structure.ADVANCED); } @@ -209,16 +234,19 @@ contract FuzzHelpersTest is BaseOrderTest { ItemType.ERC1155_WITH_CRITERIA ); - OrderParameters memory orderParameters = OrderComponentsLib.fromDefault( - STANDARD - ).toOrderParameters().withConsideration(consideration); + OrderParameters memory orderParameters = OrderComponentsLib + .fromDefault(STANDARD) + .toOrderParameters() + .withConsideration(consideration); - AdvancedOrder memory order = OrderLib.fromDefault(STANDARD) - .withParameters(orderParameters).toAdvancedOrder({ - numerator: 0, - denominator: 0, - extraData: bytes("") - }); + AdvancedOrder memory order = OrderLib + .fromDefault(STANDARD) + .withParameters(orderParameters) + .toAdvancedOrder({ + numerator: 0, + denominator: 0, + extraData: bytes("") + }); assertEq(order.getStructure(address(getSeaport())), Structure.ADVANCED); } @@ -233,18 +261,20 @@ contract FuzzHelpersTest is BaseOrderTest { ItemType.ERC721_WITH_CRITERIA ); - OrderParameters memory orderParameters = OrderComponentsLib.fromDefault( - STANDARD - ).toOrderParameters().withConsideration(consideration).withOrderType( - OrderType.CONTRACT - ); + OrderParameters memory orderParameters = OrderComponentsLib + .fromDefault(STANDARD) + .toOrderParameters() + .withConsideration(consideration) + .withOrderType(OrderType.CONTRACT); - AdvancedOrder memory order = OrderLib.fromDefault(STANDARD) - .withParameters(orderParameters).toAdvancedOrder({ - numerator: 0, - denominator: 0, - extraData: bytes("") - }); + AdvancedOrder memory order = OrderLib + .fromDefault(STANDARD) + .withParameters(orderParameters) + .toAdvancedOrder({ + numerator: 0, + denominator: 0, + extraData: bytes("") + }); assertEq(order.getStructure(address(getSeaport())), Structure.STANDARD); } @@ -255,102 +285,120 @@ contract FuzzHelpersTest is BaseOrderTest { public { ConsiderationItem[] memory consideration = new ConsiderationItem[](1); - consideration[0] = ConsiderationItemLib.empty().withItemType( - ItemType.ERC721_WITH_CRITERIA - ).withIdentifierOrCriteria(1); - - OrderParameters memory orderParameters = OrderComponentsLib.fromDefault( - STANDARD - ).toOrderParameters().withConsideration(consideration).withOrderType( - OrderType.CONTRACT - ); - - AdvancedOrder memory order = OrderLib.fromDefault(STANDARD) - .withParameters(orderParameters).toAdvancedOrder({ - numerator: 0, - denominator: 0, - extraData: bytes("") - }); + consideration[0] = ConsiderationItemLib + .empty() + .withItemType(ItemType.ERC721_WITH_CRITERIA) + .withIdentifierOrCriteria(1); + + OrderParameters memory orderParameters = OrderComponentsLib + .fromDefault(STANDARD) + .toOrderParameters() + .withConsideration(consideration) + .withOrderType(OrderType.CONTRACT); + + AdvancedOrder memory order = OrderLib + .fromDefault(STANDARD) + .withParameters(orderParameters) + .toAdvancedOrder({ + numerator: 0, + denominator: 0, + extraData: bytes("") + }); assertEq(order.getStructure(address(getSeaport())), Structure.ADVANCED); } /// @dev An order with type FULL_OPEN is OPEN function test_getType_FullOpen() public { - OrderParameters memory orderParameters = OrderComponentsLib.fromDefault( - STANDARD - ).toOrderParameters().withOrderType(OrderType.FULL_OPEN); - - AdvancedOrder memory order = OrderLib.fromDefault(STANDARD) - .withParameters(orderParameters).toAdvancedOrder({ - numerator: 0, - denominator: 0, - extraData: bytes("") - }); + OrderParameters memory orderParameters = OrderComponentsLib + .fromDefault(STANDARD) + .toOrderParameters() + .withOrderType(OrderType.FULL_OPEN); + + AdvancedOrder memory order = OrderLib + .fromDefault(STANDARD) + .withParameters(orderParameters) + .toAdvancedOrder({ + numerator: 0, + denominator: 0, + extraData: bytes("") + }); assertEq(order.getType(), Type.OPEN); } /// @dev An order with type PARTIAL_OPEN is OPEN function test_getType_PartialOpen() public { - OrderParameters memory orderParameters = OrderComponentsLib.fromDefault( - STANDARD - ).toOrderParameters().withOrderType(OrderType.PARTIAL_OPEN); - - AdvancedOrder memory order = OrderLib.fromDefault(STANDARD) - .withParameters(orderParameters).toAdvancedOrder({ - numerator: 0, - denominator: 0, - extraData: bytes("") - }); + OrderParameters memory orderParameters = OrderComponentsLib + .fromDefault(STANDARD) + .toOrderParameters() + .withOrderType(OrderType.PARTIAL_OPEN); + + AdvancedOrder memory order = OrderLib + .fromDefault(STANDARD) + .withParameters(orderParameters) + .toAdvancedOrder({ + numerator: 0, + denominator: 0, + extraData: bytes("") + }); assertEq(order.getType(), Type.OPEN); } /// @dev An order with type FULL_RESTRICTED is RESTRICTED function test_getType_FullRestricted() public { - OrderParameters memory orderParameters = OrderComponentsLib.fromDefault( - STANDARD - ).toOrderParameters().withOrderType(OrderType.FULL_RESTRICTED); - - AdvancedOrder memory order = OrderLib.fromDefault(STANDARD) - .withParameters(orderParameters).toAdvancedOrder({ - numerator: 0, - denominator: 0, - extraData: bytes("") - }); + OrderParameters memory orderParameters = OrderComponentsLib + .fromDefault(STANDARD) + .toOrderParameters() + .withOrderType(OrderType.FULL_RESTRICTED); + + AdvancedOrder memory order = OrderLib + .fromDefault(STANDARD) + .withParameters(orderParameters) + .toAdvancedOrder({ + numerator: 0, + denominator: 0, + extraData: bytes("") + }); assertEq(order.getType(), Type.RESTRICTED); } /// @dev An order with type PARTIAL_RESTRICTED is RESTRICTED function test_getType_PartialRestricted() public { - OrderParameters memory orderParameters = OrderComponentsLib.fromDefault( - STANDARD - ).toOrderParameters().withOrderType(OrderType.PARTIAL_RESTRICTED); - - AdvancedOrder memory order = OrderLib.fromDefault(STANDARD) - .withParameters(orderParameters).toAdvancedOrder({ - numerator: 0, - denominator: 0, - extraData: bytes("") - }); + OrderParameters memory orderParameters = OrderComponentsLib + .fromDefault(STANDARD) + .toOrderParameters() + .withOrderType(OrderType.PARTIAL_RESTRICTED); + + AdvancedOrder memory order = OrderLib + .fromDefault(STANDARD) + .withParameters(orderParameters) + .toAdvancedOrder({ + numerator: 0, + denominator: 0, + extraData: bytes("") + }); assertEq(order.getType(), Type.RESTRICTED); } /// @dev An order with type CONTRACT is CONTRACT function test_getType_Contract() public { - OrderParameters memory orderParameters = OrderComponentsLib.fromDefault( - STANDARD - ).toOrderParameters().withOrderType(OrderType.CONTRACT); - - AdvancedOrder memory order = OrderLib.fromDefault(STANDARD) - .withParameters(orderParameters).toAdvancedOrder({ - numerator: 0, - denominator: 0, - extraData: bytes("") - }); + OrderParameters memory orderParameters = OrderComponentsLib + .fromDefault(STANDARD) + .toOrderParameters() + .withOrderType(OrderType.CONTRACT); + + AdvancedOrder memory order = OrderLib + .fromDefault(STANDARD) + .withParameters(orderParameters) + .toAdvancedOrder({ + numerator: 0, + denominator: 0, + extraData: bytes("") + }); assertEq(order.getType(), Type.CONTRACT); } @@ -358,19 +406,21 @@ contract FuzzHelpersTest is BaseOrderTest { /// @dev A validated order is in state VALIDATED function test_getState_ValidatedOrder() public { uint256 counter = getSeaport().getCounter(offerer1.addr); - OrderParameters memory orderParameters = OrderComponentsLib.fromDefault( - STANDARD - ).withOfferer(offerer1.addr).withCounter(counter).withOrderType( - OrderType.FULL_OPEN - ).toOrderParameters(); + OrderParameters memory orderParameters = OrderComponentsLib + .fromDefault(STANDARD) + .withOfferer(offerer1.addr) + .withCounter(counter) + .withOrderType(OrderType.FULL_OPEN) + .toOrderParameters(); bytes32 orderHash = getSeaport().getOrderHash( orderParameters.toOrderComponents(counter) ); Order[] memory orders = new Order[](1); - orders[0] = OrderLib.fromDefault(STANDARD).withParameters( - orderParameters - ).withSignature(signOrder(getSeaport(), offerer1.key, orderHash)); + orders[0] = OrderLib + .fromDefault(STANDARD) + .withParameters(orderParameters) + .withSignature(signOrder(getSeaport(), offerer1.key, orderHash)); assertEq(getSeaport().validate(orders), true); @@ -386,19 +436,21 @@ contract FuzzHelpersTest is BaseOrderTest { /// @dev A cancelled order is in state CANCELLED function test_getState_CancelledOrder() public { uint256 counter = getSeaport().getCounter(offerer1.addr); - OrderParameters memory orderParameters = OrderComponentsLib.fromDefault( - STANDARD - ).withOfferer(offerer1.addr).withCounter(counter).withOrderType( - OrderType.FULL_OPEN - ).toOrderParameters(); + OrderParameters memory orderParameters = OrderComponentsLib + .fromDefault(STANDARD) + .withOfferer(offerer1.addr) + .withCounter(counter) + .withOrderType(OrderType.FULL_OPEN) + .toOrderParameters(); bytes32 orderHash = getSeaport().getOrderHash( orderParameters.toOrderComponents(counter) ); Order[] memory orders = new Order[](1); - orders[0] = OrderLib.fromDefault(STANDARD).withParameters( - orderParameters - ).withSignature(signOrder(getSeaport(), offerer1.key, orderHash)); + orders[0] = OrderLib + .fromDefault(STANDARD) + .withParameters(orderParameters) + .withSignature(signOrder(getSeaport(), offerer1.key, orderHash)); OrderComponents[] memory orderComponents = new OrderComponents[](1); orderComponents[0] = orderParameters.toOrderComponents(counter); @@ -419,8 +471,13 @@ contract FuzzHelpersTest is BaseOrderTest { /// @dev A new order is in state UNUSED function test_getState_NewOrder() public { - AdvancedOrder memory order = OrderLib.fromDefault(STANDARD) - .toAdvancedOrder({ numerator: 0, denominator: 0, extraData: bytes("") }); + AdvancedOrder memory order = OrderLib + .fromDefault(STANDARD) + .toAdvancedOrder({ + numerator: 0, + denominator: 0, + extraData: bytes("") + }); assertEq(order.getState(getSeaport()), State.UNUSED); } @@ -474,36 +531,45 @@ contract FuzzHelpersTest is BaseOrderTest { ItemType considerationItemType, OrderType orderType ) internal view returns (AdvancedOrder memory order) { - bool nftOffered = offerItemType == ItemType.ERC721 - || offerItemType == ItemType.ERC1155; + bool nftOffered = offerItemType == ItemType.ERC721 || + offerItemType == ItemType.ERC1155; OfferItem[] memory offerItems = new OfferItem[](1); - OfferItem memory offerItem = OfferItemLib.empty().withItemType( - offerItemType - ).withToken(nftOffered ? address(erc721s[0]) : address(0)) - .withIdentifierOrCriteria(nftOffered ? 1 : 0).withAmount(1); + OfferItem memory offerItem = OfferItemLib + .empty() + .withItemType(offerItemType) + .withToken(nftOffered ? address(erc721s[0]) : address(0)) + .withIdentifierOrCriteria(nftOffered ? 1 : 0) + .withAmount(1); offerItems[0] = offerItem; ConsiderationItem[] memory considerationItems = new ConsiderationItem[]( 1 ); - ConsiderationItem memory considerationItem = ConsiderationItemLib.empty( - ).withItemType(considerationItemType).withIdentifierOrCriteria( - nftOffered ? 0 : 1 - ).withAmount(1); + ConsiderationItem memory considerationItem = ConsiderationItemLib + .empty() + .withItemType(considerationItemType) + .withIdentifierOrCriteria(nftOffered ? 0 : 1) + .withAmount(1); considerationItems[0] = considerationItem; - OrderComponents memory orderComponents = OrderComponentsLib.fromDefault( - STANDARD - ).withOfferer(offerer1.addr).withOffer(offerItems).withConsideration( - considerationItems - ).withOrderType(orderType); + OrderComponents memory orderComponents = OrderComponentsLib + .fromDefault(STANDARD) + .withOfferer(offerer1.addr) + .withOffer(offerItems) + .withConsideration(considerationItems) + .withOrderType(orderType); - order = OrderLib.fromDefault(STANDARD).withParameters( - orderComponents.toOrderParameters() - ).toAdvancedOrder({ numerator: 0, denominator: 0, extraData: bytes("") }); + order = OrderLib + .fromDefault(STANDARD) + .withParameters(orderComponents.toOrderParameters()) + .toAdvancedOrder({ + numerator: 0, + denominator: 0, + extraData: bytes("") + }); } /** @@ -511,12 +577,16 @@ contract FuzzHelpersTest is BaseOrderTest { * item. No partial fills, anyone can execute. */ function test_getBasicOrderType_ETH_TO_ERC721_FULL_OPEN() public { - AdvancedOrder memory order = - _createOrder(ItemType.ERC721, ItemType.NATIVE, OrderType.FULL_OPEN); + AdvancedOrder memory order = _createOrder( + ItemType.ERC721, + ItemType.NATIVE, + OrderType.FULL_OPEN + ); order.getBasicOrderTypeEligibility(address(getSeaport())); assertEq( - order.getBasicOrderType(), BasicOrderType.ETH_TO_ERC721_FULL_OPEN + order.getBasicOrderType(), + BasicOrderType.ETH_TO_ERC721_FULL_OPEN ); } @@ -526,12 +596,15 @@ contract FuzzHelpersTest is BaseOrderTest { */ function test_getBasicOrderType_ETH_TO_ERC721_PARTIAL_OPEN() public { AdvancedOrder memory order = _createOrder( - ItemType.ERC721, ItemType.NATIVE, OrderType.PARTIAL_OPEN + ItemType.ERC721, + ItemType.NATIVE, + OrderType.PARTIAL_OPEN ); order.getBasicOrderTypeEligibility(address(getSeaport())); assertEq( - order.getBasicOrderType(), BasicOrderType.ETH_TO_ERC721_PARTIAL_OPEN + order.getBasicOrderType(), + BasicOrderType.ETH_TO_ERC721_PARTIAL_OPEN ); } @@ -541,7 +614,9 @@ contract FuzzHelpersTest is BaseOrderTest { */ function test_getBasicOrderType_ETH_TO_ERC721_FULL_RESTRICTED() public { AdvancedOrder memory order = _createOrder( - ItemType.ERC721, ItemType.NATIVE, OrderType.FULL_RESTRICTED + ItemType.ERC721, + ItemType.NATIVE, + OrderType.FULL_RESTRICTED ); order.getBasicOrderTypeEligibility(address(getSeaport())); @@ -557,7 +632,9 @@ contract FuzzHelpersTest is BaseOrderTest { */ function test_getBasicOrderType_ETH_TO_ERC721_PARTIAL_RESTRICTED() public { AdvancedOrder memory order = _createOrder( - ItemType.ERC721, ItemType.NATIVE, OrderType.PARTIAL_RESTRICTED + ItemType.ERC721, + ItemType.NATIVE, + OrderType.PARTIAL_RESTRICTED ); order.getBasicOrderTypeEligibility(address(getSeaport())); @@ -572,12 +649,16 @@ contract FuzzHelpersTest is BaseOrderTest { * item. No partial fills, anyone can execute. */ function test_getBasicOrderType_ETH_TO_ERC1155_FULL_OPEN() public { - AdvancedOrder memory order = - _createOrder(ItemType.ERC1155, ItemType.NATIVE, OrderType.FULL_OPEN); + AdvancedOrder memory order = _createOrder( + ItemType.ERC1155, + ItemType.NATIVE, + OrderType.FULL_OPEN + ); order.getBasicOrderTypeEligibility(address(getSeaport())); assertEq( - order.getBasicOrderType(), BasicOrderType.ETH_TO_ERC1155_FULL_OPEN + order.getBasicOrderType(), + BasicOrderType.ETH_TO_ERC1155_FULL_OPEN ); } @@ -587,7 +668,9 @@ contract FuzzHelpersTest is BaseOrderTest { */ function test_getBasicOrderType_ETH_TO_ERC1155_PARTIAL_OPEN() public { AdvancedOrder memory order = _createOrder( - ItemType.ERC1155, ItemType.NATIVE, OrderType.PARTIAL_OPEN + ItemType.ERC1155, + ItemType.NATIVE, + OrderType.PARTIAL_OPEN ); order.getBasicOrderTypeEligibility(address(getSeaport())); @@ -603,7 +686,9 @@ contract FuzzHelpersTest is BaseOrderTest { */ function test_getBasicOrderType_ETH_TO_ERC1155_FULL_RESTRICTED() public { AdvancedOrder memory order = _createOrder( - ItemType.ERC1155, ItemType.NATIVE, OrderType.FULL_RESTRICTED + ItemType.ERC1155, + ItemType.NATIVE, + OrderType.FULL_RESTRICTED ); order.getBasicOrderTypeEligibility(address(getSeaport())); @@ -617,11 +702,11 @@ contract FuzzHelpersTest is BaseOrderTest { * @dev Provide Ether (or other native token) to receive offered ERC1155 * item. Partial fills supported, only offerer or zone can execute. */ - function test_getBasicOrderType_ETH_TO_ERC1155_PARTIAL_RESTRICTED() - public - { + function test_getBasicOrderType_ETH_TO_ERC1155_PARTIAL_RESTRICTED() public { AdvancedOrder memory order = _createOrder( - ItemType.ERC1155, ItemType.NATIVE, OrderType.PARTIAL_RESTRICTED + ItemType.ERC1155, + ItemType.NATIVE, + OrderType.PARTIAL_RESTRICTED ); order.getBasicOrderTypeEligibility(address(getSeaport())); @@ -636,12 +721,16 @@ contract FuzzHelpersTest is BaseOrderTest { * anyone can execute. */ function test_getBasicOrderType_ERC20_TO_ERC721_FULL_OPEN() public { - AdvancedOrder memory order = - _createOrder(ItemType.ERC721, ItemType.ERC20, OrderType.FULL_OPEN); + AdvancedOrder memory order = _createOrder( + ItemType.ERC721, + ItemType.ERC20, + OrderType.FULL_OPEN + ); order.getBasicOrderTypeEligibility(address(getSeaport())); assertEq( - order.getBasicOrderType(), BasicOrderType.ERC20_TO_ERC721_FULL_OPEN + order.getBasicOrderType(), + BasicOrderType.ERC20_TO_ERC721_FULL_OPEN ); } @@ -651,7 +740,9 @@ contract FuzzHelpersTest is BaseOrderTest { */ function test_getBasicOrderType_ERC20_TO_ERC721_PARTIAL_OPEN() public { AdvancedOrder memory order = _createOrder( - ItemType.ERC721, ItemType.ERC20, OrderType.PARTIAL_OPEN + ItemType.ERC721, + ItemType.ERC20, + OrderType.PARTIAL_OPEN ); order.getBasicOrderTypeEligibility(address(getSeaport())); @@ -667,7 +758,9 @@ contract FuzzHelpersTest is BaseOrderTest { */ function test_getBasicOrderType_ERC20_TO_ERC721_FULL_RESTRICTED() public { AdvancedOrder memory order = _createOrder( - ItemType.ERC721, ItemType.ERC20, OrderType.FULL_RESTRICTED + ItemType.ERC721, + ItemType.ERC20, + OrderType.FULL_RESTRICTED ); order.getBasicOrderTypeEligibility(address(getSeaport())); @@ -685,7 +778,9 @@ contract FuzzHelpersTest is BaseOrderTest { public { AdvancedOrder memory order = _createOrder( - ItemType.ERC721, ItemType.ERC20, OrderType.PARTIAL_RESTRICTED + ItemType.ERC721, + ItemType.ERC20, + OrderType.PARTIAL_RESTRICTED ); order.getBasicOrderTypeEligibility(address(getSeaport())); @@ -700,12 +795,16 @@ contract FuzzHelpersTest is BaseOrderTest { * fills, anyone can execute. */ function test_getBasicOrderType_ERC20_TO_ERC1155_FULL_OPEN() public { - AdvancedOrder memory order = - _createOrder(ItemType.ERC1155, ItemType.ERC20, OrderType.FULL_OPEN); + AdvancedOrder memory order = _createOrder( + ItemType.ERC1155, + ItemType.ERC20, + OrderType.FULL_OPEN + ); order.getBasicOrderTypeEligibility(address(getSeaport())); assertEq( - order.getBasicOrderType(), BasicOrderType.ERC20_TO_ERC1155_FULL_OPEN + order.getBasicOrderType(), + BasicOrderType.ERC20_TO_ERC1155_FULL_OPEN ); } @@ -715,7 +814,9 @@ contract FuzzHelpersTest is BaseOrderTest { */ function test_getBasicOrderType_ERC20_TO_ERC1155_PARTIAL_OPEN() public { AdvancedOrder memory order = _createOrder( - ItemType.ERC1155, ItemType.ERC20, OrderType.PARTIAL_OPEN + ItemType.ERC1155, + ItemType.ERC20, + OrderType.PARTIAL_OPEN ); order.getBasicOrderTypeEligibility(address(getSeaport())); @@ -731,7 +832,9 @@ contract FuzzHelpersTest is BaseOrderTest { */ function test_getBasicOrderType_ERC20_TO_ERC1155_FULL_RESTRICTED() public { AdvancedOrder memory order = _createOrder( - ItemType.ERC1155, ItemType.ERC20, OrderType.FULL_RESTRICTED + ItemType.ERC1155, + ItemType.ERC20, + OrderType.FULL_RESTRICTED ); order.getBasicOrderTypeEligibility(address(getSeaport())); @@ -749,7 +852,9 @@ contract FuzzHelpersTest is BaseOrderTest { public { AdvancedOrder memory order = _createOrder( - ItemType.ERC1155, ItemType.ERC20, OrderType.PARTIAL_RESTRICTED + ItemType.ERC1155, + ItemType.ERC20, + OrderType.PARTIAL_RESTRICTED ); order.getBasicOrderTypeEligibility(address(getSeaport())); @@ -764,12 +869,16 @@ contract FuzzHelpersTest is BaseOrderTest { * anyone can execute. */ function test_getBasicOrderType_ERC721_TO_ERC20_FULL_OPEN() public { - AdvancedOrder memory order = - _createOrder(ItemType.ERC20, ItemType.ERC721, OrderType.FULL_OPEN); + AdvancedOrder memory order = _createOrder( + ItemType.ERC20, + ItemType.ERC721, + OrderType.FULL_OPEN + ); order.getBasicOrderTypeEligibility(address(getSeaport())); assertEq( - order.getBasicOrderType(), BasicOrderType.ERC721_TO_ERC20_FULL_OPEN + order.getBasicOrderType(), + BasicOrderType.ERC721_TO_ERC20_FULL_OPEN ); } @@ -779,7 +888,9 @@ contract FuzzHelpersTest is BaseOrderTest { */ function test_getBasicOrderType_ERC721_TO_ERC20_PARTIAL_OPEN() public { AdvancedOrder memory order = _createOrder( - ItemType.ERC20, ItemType.ERC721, OrderType.PARTIAL_OPEN + ItemType.ERC20, + ItemType.ERC721, + OrderType.PARTIAL_OPEN ); order.getBasicOrderTypeEligibility(address(getSeaport())); @@ -795,7 +906,9 @@ contract FuzzHelpersTest is BaseOrderTest { */ function test_getBasicOrderType_ERC721_TO_ERC20_FULL_RESTRICTED() public { AdvancedOrder memory order = _createOrder( - ItemType.ERC20, ItemType.ERC721, OrderType.FULL_RESTRICTED + ItemType.ERC20, + ItemType.ERC721, + OrderType.FULL_RESTRICTED ); order.getBasicOrderTypeEligibility(address(getSeaport())); @@ -813,7 +926,9 @@ contract FuzzHelpersTest is BaseOrderTest { public { AdvancedOrder memory order = _createOrder( - ItemType.ERC20, ItemType.ERC721, OrderType.PARTIAL_RESTRICTED + ItemType.ERC20, + ItemType.ERC721, + OrderType.PARTIAL_RESTRICTED ); order.getBasicOrderTypeEligibility(address(getSeaport())); @@ -828,12 +943,16 @@ contract FuzzHelpersTest is BaseOrderTest { * fills, anyone can execute. */ function test_getBasicOrderType_ERC1155_TO_ERC20_FULL_OPEN() public { - AdvancedOrder memory order = - _createOrder(ItemType.ERC20, ItemType.ERC1155, OrderType.FULL_OPEN); + AdvancedOrder memory order = _createOrder( + ItemType.ERC20, + ItemType.ERC1155, + OrderType.FULL_OPEN + ); order.getBasicOrderTypeEligibility(address(getSeaport())); assertEq( - order.getBasicOrderType(), BasicOrderType.ERC1155_TO_ERC20_FULL_OPEN + order.getBasicOrderType(), + BasicOrderType.ERC1155_TO_ERC20_FULL_OPEN ); } @@ -843,7 +962,9 @@ contract FuzzHelpersTest is BaseOrderTest { */ function test_getBasicOrderType_ERC1155_TO_ERC20_PARTIAL_OPEN() public { AdvancedOrder memory order = _createOrder( - ItemType.ERC20, ItemType.ERC1155, OrderType.PARTIAL_OPEN + ItemType.ERC20, + ItemType.ERC1155, + OrderType.PARTIAL_OPEN ); order.getBasicOrderTypeEligibility(address(getSeaport())); @@ -859,7 +980,9 @@ contract FuzzHelpersTest is BaseOrderTest { */ function test_getBasicOrderType_ERC1155_TO_ERC20_FULL_RESTRICTED() public { AdvancedOrder memory order = _createOrder( - ItemType.ERC20, ItemType.ERC1155, OrderType.FULL_RESTRICTED + ItemType.ERC20, + ItemType.ERC1155, + OrderType.FULL_RESTRICTED ); order.getBasicOrderTypeEligibility(address(getSeaport())); @@ -877,7 +1000,9 @@ contract FuzzHelpersTest is BaseOrderTest { public { AdvancedOrder memory order = _createOrder( - ItemType.ERC20, ItemType.ERC1155, OrderType.PARTIAL_RESTRICTED + ItemType.ERC20, + ItemType.ERC1155, + OrderType.PARTIAL_RESTRICTED ); order.getBasicOrderTypeEligibility(address(getSeaport())); @@ -889,18 +1014,22 @@ contract FuzzHelpersTest is BaseOrderTest { function test_getBasicOrderTypeEligibility_failure_criteria() public { AdvancedOrder memory order = _createOrder( - ItemType.ERC20, ItemType.ERC1155, OrderType.PARTIAL_RESTRICTED + ItemType.ERC20, + ItemType.ERC1155, + OrderType.PARTIAL_RESTRICTED ); - order.parameters.consideration[0].itemType = - ItemType.ERC1155_WITH_CRITERIA; + order.parameters.consideration[0].itemType = ItemType + .ERC1155_WITH_CRITERIA; assertFalse(order.getBasicOrderTypeEligibility(address(getSeaport()))); } function test_getBasicOrderTypeEligibility_failure_extraData() public { AdvancedOrder memory order = _createOrder( - ItemType.ERC20, ItemType.ERC1155, OrderType.PARTIAL_RESTRICTED + ItemType.ERC20, + ItemType.ERC1155, + OrderType.PARTIAL_RESTRICTED ); order.extraData = bytes("extraData"); @@ -912,7 +1041,9 @@ contract FuzzHelpersTest is BaseOrderTest { public { AdvancedOrder memory order = _createOrder( - ItemType.ERC20, ItemType.ERC1155, OrderType.PARTIAL_RESTRICTED + ItemType.ERC20, + ItemType.ERC1155, + OrderType.PARTIAL_RESTRICTED ); OfferItem[] memory offer = new OfferItem[](2); @@ -933,7 +1064,9 @@ contract FuzzHelpersTest is BaseOrderTest { public { AdvancedOrder memory order = _createOrder( - ItemType.ERC20, ItemType.ERC1155, OrderType.PARTIAL_RESTRICTED + ItemType.ERC20, + ItemType.ERC1155, + OrderType.PARTIAL_RESTRICTED ); order.parameters.consideration = new ConsiderationItem[](0); @@ -943,7 +1076,9 @@ contract FuzzHelpersTest is BaseOrderTest { function test_getBasicOrderTypeEligibility_failure_nftCount() public { AdvancedOrder memory order = _createOrder( - ItemType.ERC20, ItemType.ERC1155, OrderType.PARTIAL_RESTRICTED + ItemType.ERC20, + ItemType.ERC1155, + OrderType.PARTIAL_RESTRICTED ); OfferItem[] memory offer = new OfferItem[](1); diff --git a/test/foundry/new/FuzzInscribers.t.sol b/test/foundry/new/FuzzInscribers.t.sol index b65cf82..a0304b9 100644 --- a/test/foundry/new/FuzzInscribers.t.sol +++ b/test/foundry/new/FuzzInscribers.t.sol @@ -89,7 +89,10 @@ contract FuzzHelpersTest is BaseOrderTest { // Populate the raw synthetic storage values. These are the storage // values produced by using the inscription helpers. _setRawSyntheticStorageValues( - orderHash, context, advancedOrder, rawStorageValues + orderHash, + context, + advancedOrder, + rawStorageValues ); _compareOrganicAndSyntheticRawStorageValues(rawStorageValues); @@ -103,19 +106,27 @@ contract FuzzHelpersTest is BaseOrderTest { caller: address(this) }); - bytes32 contractNonceStorageSlot = - _getStorageSlotForContractNonce(address(this), context); - bytes32 rawContractOffererNonceValue = - vm.load(address(context.seaport), contractNonceStorageSlot); + bytes32 contractNonceStorageSlot = _getStorageSlotForContractNonce( + address(this), + context + ); + bytes32 rawContractOffererNonceValue = vm.load( + address(context.seaport), + contractNonceStorageSlot + ); assertEq(rawContractOffererNonceValue, bytes32(0)); FuzzInscribers.inscribeContractOffererNonce( - address(this), 1, context.seaport + address(this), + 1, + context.seaport ); - bytes32 newContractOffererNonceValue = - vm.load(address(context.seaport), contractNonceStorageSlot); + bytes32 newContractOffererNonceValue = vm.load( + address(context.seaport), + contractNonceStorageSlot + ); assertEq(newContractOffererNonceValue, bytes32(uint256(1))); } @@ -127,17 +138,23 @@ contract FuzzHelpersTest is BaseOrderTest { caller: address(this) }); - bytes32 counterStorageSlot = - _getStorageSlotForCounter(address(this), context); - bytes32 rawCounterValue = - vm.load(address(context.seaport), counterStorageSlot); + bytes32 counterStorageSlot = _getStorageSlotForCounter( + address(this), + context + ); + bytes32 rawCounterValue = vm.load( + address(context.seaport), + counterStorageSlot + ); assertEq(rawCounterValue, bytes32(0)); FuzzInscribers.inscribeCounter(address(this), 1, context.seaport); - bytes32 newCounterValue = - vm.load(address(context.seaport), counterStorageSlot); + bytes32 newCounterValue = vm.load( + address(context.seaport), + counterStorageSlot + ); assertEq(newCounterValue, bytes32(uint256(1))); } @@ -153,24 +170,32 @@ contract FuzzHelpersTest is BaseOrderTest { { // Set up the order. OfferItem[] memory offerItems = new OfferItem[](1); - OfferItem memory offerItem = OfferItemLib.empty().withItemType( - ItemType.ERC20 - ).withToken(address(erc20s[0])).withAmount(10e34); + OfferItem memory offerItem = OfferItemLib + .empty() + .withItemType(ItemType.ERC20) + .withToken(address(erc20s[0])) + .withAmount(10e34); offerItems[0] = offerItem; ConsiderationItem[] memory considerationItems = new ConsiderationItem[]( 1 ); - ConsiderationItem memory considerationItem = ConsiderationItemLib.empty( - ).withItemType(ItemType.NATIVE).withAmount(10e34); + ConsiderationItem memory considerationItem = ConsiderationItemLib + .empty() + .withItemType(ItemType.NATIVE) + .withAmount(10e34); considerationItems[0] = considerationItem; - OrderComponents memory orderComponents = OrderComponentsLib.empty() - .withStartTime(block.timestamp).withEndTime(block.timestamp + 100) - .withOrderType(OrderType.PARTIAL_OPEN).withOfferer(offerer1.addr) - .withOffer(offerItems).withConsideration(considerationItems); + OrderComponents memory orderComponents = OrderComponentsLib + .empty() + .withStartTime(block.timestamp) + .withEndTime(block.timestamp + 100) + .withOrderType(OrderType.PARTIAL_OPEN) + .withOfferer(offerer1.addr) + .withOffer(offerItems) + .withConsideration(considerationItems); // Set this up to use later for canceling. OrderComponents[] memory orderComponentsArray = new OrderComponents[]( @@ -216,15 +241,21 @@ contract FuzzHelpersTest is BaseOrderTest { ) internal { // Populate the raw organic storage values. These are the storage // values produced by actualy calling Seaport. - bytes32 orderHashStorageSlot = - _getStorageSlotForOrderHash(orderHash, context); - rawStorageValues.rawOrganicOrderStatusBeforeCalls = - vm.load(address(context.seaport), orderHashStorageSlot); + bytes32 orderHashStorageSlot = _getStorageSlotForOrderHash( + orderHash, + context + ); + rawStorageValues.rawOrganicOrderStatusBeforeCalls = vm.load( + address(context.seaport), + orderHashStorageSlot + ); advancedOrder.validateTipNeutralizedOrder(context); - rawStorageValues.rawOrganicOrderStatusAfterValidation = - vm.load(address(context.seaport), orderHashStorageSlot); + rawStorageValues.rawOrganicOrderStatusAfterValidation = vm.load( + address(context.seaport), + orderHashStorageSlot + ); context.seaport.fulfillAdvancedOrder{ value: 10e34 / 2 }({ advancedOrder: advancedOrder, @@ -233,8 +264,10 @@ contract FuzzHelpersTest is BaseOrderTest { recipient: address(this) }); - rawStorageValues.rawOrganicOrderStatusAfterPartialFulfillment = - vm.load(address(context.seaport), orderHashStorageSlot); + rawStorageValues.rawOrganicOrderStatusAfterPartialFulfillment = vm.load( + address(context.seaport), + orderHashStorageSlot + ); context.seaport.fulfillAdvancedOrder{ value: 10e34 / 2 }({ advancedOrder: advancedOrder, @@ -243,14 +276,18 @@ contract FuzzHelpersTest is BaseOrderTest { recipient: address(this) }); - rawStorageValues.rawOrganicOrderStatusAfterFullFulfillment = - vm.load(address(context.seaport), orderHashStorageSlot); + rawStorageValues.rawOrganicOrderStatusAfterFullFulfillment = vm.load( + address(context.seaport), + orderHashStorageSlot + ); vm.prank(address(offerer1.addr)); context.seaport.cancel(orderComponentsArray); - rawStorageValues.rawOrganicOrderStatusAfterCancellation = - vm.load(address(context.seaport), orderHashStorageSlot); + rawStorageValues.rawOrganicOrderStatusAfterCancellation = vm.load( + address(context.seaport), + orderHashStorageSlot + ); } function _setRawSyntheticStorageValues( @@ -261,32 +298,42 @@ contract FuzzHelpersTest is BaseOrderTest { ) internal { // Populate the raw organic storage values. These are the storage // values produced by actualy calling Seaport. - bytes32 orderHashStorageSlot = - _getStorageSlotForOrderHash(orderHash, context); - rawStorageValues.rawSyntheticOrderStatusBeforeCalls = - vm.load(address(context.seaport), orderHashStorageSlot); + bytes32 orderHashStorageSlot = _getStorageSlotForOrderHash( + orderHash, + context + ); + rawStorageValues.rawSyntheticOrderStatusBeforeCalls = vm.load( + address(context.seaport), + orderHashStorageSlot + ); advancedOrder.inscribeOrderStatusValidated(true, context.seaport); - rawStorageValues.rawSyntheticOrderStatusAfterValidation = - vm.load(address(context.seaport), orderHashStorageSlot); + rawStorageValues.rawSyntheticOrderStatusAfterValidation = vm.load( + address(context.seaport), + orderHashStorageSlot + ); advancedOrder.inscribeOrderStatusNumerator(10e34 / 2, context.seaport); advancedOrder.inscribeOrderStatusDenominator(10e34, context.seaport); - rawStorageValues.rawSyntheticOrderStatusAfterPartialFulfillment = - vm.load(address(context.seaport), orderHashStorageSlot); + rawStorageValues.rawSyntheticOrderStatusAfterPartialFulfillment = vm + .load(address(context.seaport), orderHashStorageSlot); advancedOrder.inscribeOrderStatusNumerator(10e34, context.seaport); advancedOrder.inscribeOrderStatusDenominator(10e34, context.seaport); - rawStorageValues.rawSyntheticOrderStatusAfterFullFulfillment = - vm.load(address(context.seaport), orderHashStorageSlot); + rawStorageValues.rawSyntheticOrderStatusAfterFullFulfillment = vm.load( + address(context.seaport), + orderHashStorageSlot + ); advancedOrder.inscribeOrderStatusCancelled(true, context.seaport); - rawStorageValues.rawSyntheticOrderStatusAfterCancellation = - vm.load(address(context.seaport), orderHashStorageSlot); + rawStorageValues.rawSyntheticOrderStatusAfterCancellation = vm.load( + address(context.seaport), + orderHashStorageSlot + ); } function _compareOrganicAndSyntheticRawStorageValues( @@ -326,21 +373,26 @@ contract FuzzHelpersTest is BaseOrderTest { ) internal returns (bytes32) { vm.record(); context.seaport.getOrderStatus(orderHash); - (bytes32[] memory readAccesses,) = vm.accesses(address(context.seaport)); + (bytes32[] memory readAccesses, ) = vm.accesses( + address(context.seaport) + ); uint256 expectedReadAccessCount = 4; - string memory profile = vm.envOr("FOUNDRY_PROFILE", string("optimized")); + string memory profile = vm.envOr( + "FOUNDRY_PROFILE", + string("optimized") + ); if ( - keccak256(abi.encodePacked(profile)) - == keccak256(abi.encodePacked("optimized")) - || keccak256(abi.encodePacked(profile)) - == keccak256(abi.encodePacked("test")) - || keccak256(abi.encodePacked(profile)) - == keccak256(abi.encodePacked("lite")) - || keccak256(abi.encodePacked(profile)) - == keccak256(abi.encodePacked("reference")) + keccak256(abi.encodePacked(profile)) == + keccak256(abi.encodePacked("optimized")) || + keccak256(abi.encodePacked(profile)) == + keccak256(abi.encodePacked("test")) || + keccak256(abi.encodePacked(profile)) == + keccak256(abi.encodePacked("lite")) || + keccak256(abi.encodePacked(profile)) == + keccak256(abi.encodePacked("reference")) ) { expectedReadAccessCount = 1; } @@ -359,7 +411,9 @@ contract FuzzHelpersTest is BaseOrderTest { ) private returns (bytes32) { vm.record(); context.seaport.getContractOffererNonce(contractOfferer); - (bytes32[] memory readAccesses,) = vm.accesses(address(context.seaport)); + (bytes32[] memory readAccesses, ) = vm.accesses( + address(context.seaport) + ); require(readAccesses.length == 1, "Expected 1 read access."); @@ -372,7 +426,9 @@ contract FuzzHelpersTest is BaseOrderTest { ) private returns (bytes32) { vm.record(); context.seaport.getCounter(offerer); - (bytes32[] memory readAccesses,) = vm.accesses(address(context.seaport)); + (bytes32[] memory readAccesses, ) = vm.accesses( + address(context.seaport) + ); require(readAccesses.length == 1, "Expected 1 read access."); diff --git a/test/foundry/new/FuzzMain.t.sol b/test/foundry/new/FuzzMain.t.sol index 539a19c..3e4006b 100644 --- a/test/foundry/new/FuzzMain.t.sol +++ b/test/foundry/new/FuzzMain.t.sol @@ -23,13 +23,17 @@ contract FuzzMainTest is FuzzEngine { seed: seed, totalOrders: bound(orders, 1, 10), maxOfferItems: bound(maxOfferItemsPerOrder, 0, 10), - maxConsiderationItems: bound(maxConsiderationItemsPerOrder, 0, 10), + maxConsiderationItems: bound( + maxConsiderationItemsPerOrder, + 0, + 10 + ), seedInput: abi.encodePacked( seed, orders, maxOfferItemsPerOrder, maxConsiderationItemsPerOrder - ) + ) }) ); } @@ -39,13 +43,13 @@ contract FuzzMainTest is FuzzEngine { * Copy/paste fuzz run parameters into the tuple below and remove the * leading "x" to run a fuzz failure as a concrete test. */ - function xtest_concrete() public { + function test_concrete() public { ( uint256 seed, uint256 orders, uint256 maxOfferItemsPerOrder, uint256 maxConsiderationItemsPerOrder - ) = (0, 0, 0, 0); + ) = (29604057, 4371734480978016729729, 1, 115791978809374646774550386052594111420862745447897009313272701407525548851199); bytes memory callData = abi.encodeCall( this.test_fuzz_generateOrders, (seed, orders, maxOfferItemsPerOrder, maxConsiderationItemsPerOrder) diff --git a/test/foundry/new/FuzzSetup.t.sol b/test/foundry/new/FuzzSetup.t.sol index d7c10e2..ae73add 100644 --- a/test/foundry/new/FuzzSetup.t.sol +++ b/test/foundry/new/FuzzSetup.t.sol @@ -17,7 +17,8 @@ import { OrderComponentsSpace } from "seaport-sol/src/StructSpace.sol"; import { OrderDetails } from "seaport-sol/src/fulfillments/lib/Structs.sol"; import { - OrderStatusEnum, UnavailableReason + OrderStatusEnum, + UnavailableReason } from "seaport-sol/src/SpaceEnums.sol"; import { @@ -71,16 +72,24 @@ contract FuzzSetupTest is BaseOrderTest, FuzzSetup { assertEq(erc20s[0].allowance(charlie.addr, address(getSeaport())), 0); OfferItem[] memory offerItems = new OfferItem[](2); - offerItems[0] = OfferItemLib.empty().withItemType(ItemType.ERC20) - .withToken(address(erc20s[0])).withAmount(100); - - offerItems[1] = OfferItemLib.empty().withItemType(ItemType.ERC20) - .withToken(address(erc20s[0])).withAmount(100); - - OrderParameters memory orderParams = OrderParametersLib.empty() - .withOfferer(charlie.addr).withOffer(offerItems).withStartTime( - block.timestamp - ).withEndTime(block.timestamp + 1); + offerItems[0] = OfferItemLib + .empty() + .withItemType(ItemType.ERC20) + .withToken(address(erc20s[0])) + .withAmount(100); + + offerItems[1] = OfferItemLib + .empty() + .withItemType(ItemType.ERC20) + .withToken(address(erc20s[0])) + .withAmount(100); + + OrderParameters memory orderParams = OrderParametersLib + .empty() + .withOfferer(charlie.addr) + .withOffer(offerItems) + .withStartTime(block.timestamp) + .withEndTime(block.timestamp + 1); Order memory order = OrderLib.empty().withParameters(orderParams); AdvancedOrder[] memory orders = new AdvancedOrder[](1); @@ -105,8 +114,10 @@ contract FuzzSetupTest is BaseOrderTest, FuzzSetup { // Do some surgery on the context so that the setup function thinks // that the order is available and worth providing balance and approvals // for. - context.executionState.orderDetails[0].unavailableReason = - UnavailableReason.AVAILABLE; + context + .executionState + .orderDetails[0] + .unavailableReason = UnavailableReason.AVAILABLE; setUpOfferItems(context); @@ -119,13 +130,19 @@ contract FuzzSetupTest is BaseOrderTest, FuzzSetup { assertEq(erc20s[0].allowance(charlie.addr, address(getSeaport())), 0); OfferItem[] memory offerItems = new OfferItem[](1); - offerItems[0] = OfferItemLib.empty().withItemType(ItemType.ERC20) - .withToken(address(erc20s[0])).withStartAmount(500).withEndAmount(1000); - - OrderParameters memory orderParams = OrderParametersLib.empty() - .withOfferer(charlie.addr).withOffer(offerItems).withStartTime( - block.timestamp - ).withEndTime(block.timestamp + 1000); + offerItems[0] = OfferItemLib + .empty() + .withItemType(ItemType.ERC20) + .withToken(address(erc20s[0])) + .withStartAmount(500) + .withEndAmount(1000); + + OrderParameters memory orderParams = OrderParametersLib + .empty() + .withOfferer(charlie.addr) + .withOffer(offerItems) + .withStartTime(block.timestamp) + .withEndTime(block.timestamp + 1000); Order memory order = OrderLib.empty().withParameters(orderParams); AdvancedOrder[] memory orders = new AdvancedOrder[](1); @@ -152,8 +169,10 @@ contract FuzzSetupTest is BaseOrderTest, FuzzSetup { // Do some surgery on the context so that the setup function thinks // that the order is available and worth providing balance and approvals // for. - context.executionState.orderDetails[0].unavailableReason = - UnavailableReason.AVAILABLE; + context + .executionState + .orderDetails[0] + .unavailableReason = UnavailableReason.AVAILABLE; setUpOfferItems(context); @@ -166,13 +185,19 @@ contract FuzzSetupTest is BaseOrderTest, FuzzSetup { assertEq(erc20s[0].allowance(charlie.addr, address(getSeaport())), 0); OfferItem[] memory offerItems = new OfferItem[](1); - offerItems[0] = OfferItemLib.empty().withItemType(ItemType.ERC20) - .withToken(address(erc20s[0])).withStartAmount(1000).withEndAmount(500); - - OrderParameters memory orderParams = OrderParametersLib.empty() - .withOfferer(charlie.addr).withOffer(offerItems).withStartTime( - block.timestamp - ).withEndTime(block.timestamp + 1000); + offerItems[0] = OfferItemLib + .empty() + .withItemType(ItemType.ERC20) + .withToken(address(erc20s[0])) + .withStartAmount(1000) + .withEndAmount(500); + + OrderParameters memory orderParams = OrderParametersLib + .empty() + .withOfferer(charlie.addr) + .withOffer(offerItems) + .withStartTime(block.timestamp) + .withEndTime(block.timestamp + 1000); Order memory order = OrderLib.empty().withParameters(orderParams); AdvancedOrder[] memory orders = new AdvancedOrder[](1); @@ -199,8 +224,10 @@ contract FuzzSetupTest is BaseOrderTest, FuzzSetup { // Do some surgery on the context so that the setup function thinks // that the order is available and worth providing balance and approvals // for. - context.executionState.orderDetails[0].unavailableReason = - UnavailableReason.AVAILABLE; + context + .executionState + .orderDetails[0] + .unavailableReason = UnavailableReason.AVAILABLE; setUpOfferItems(context); @@ -219,20 +246,26 @@ contract FuzzSetupTest is BaseOrderTest, FuzzSetup { ); OfferItem[] memory offerItems = new OfferItem[](2); - offerItems[0] = OfferItemLib.empty().withItemType(ItemType.ERC721) - .withToken(address(erc721s[0])).withIdentifierOrCriteria(1).withAmount( - 1 - ); - - offerItems[1] = OfferItemLib.empty().withItemType(ItemType.ERC721) - .withToken(address(erc721s[1])).withIdentifierOrCriteria(2).withAmount( - 1 - ); - - OrderParameters memory orderParams = OrderParametersLib.empty() - .withOfferer(charlie.addr).withOffer(offerItems).withStartTime( - block.timestamp - ).withEndTime(block.timestamp + 1); + offerItems[0] = OfferItemLib + .empty() + .withItemType(ItemType.ERC721) + .withToken(address(erc721s[0])) + .withIdentifierOrCriteria(1) + .withAmount(1); + + offerItems[1] = OfferItemLib + .empty() + .withItemType(ItemType.ERC721) + .withToken(address(erc721s[1])) + .withIdentifierOrCriteria(2) + .withAmount(1); + + OrderParameters memory orderParams = OrderParametersLib + .empty() + .withOfferer(charlie.addr) + .withOffer(offerItems) + .withStartTime(block.timestamp) + .withEndTime(block.timestamp + 1); Order memory order = OrderLib.empty().withParameters(orderParams); AdvancedOrder[] memory orders = new AdvancedOrder[](1); @@ -257,8 +290,10 @@ contract FuzzSetupTest is BaseOrderTest, FuzzSetup { // Do some surgery on the context so that the setup function thinks // that the order is available and worth providing balance and approvals // for. - context.executionState.orderDetails[0].unavailableReason = - UnavailableReason.AVAILABLE; + context + .executionState + .orderDetails[0] + .unavailableReason = UnavailableReason.AVAILABLE; setUpOfferItems(context); @@ -279,20 +314,26 @@ contract FuzzSetupTest is BaseOrderTest, FuzzSetup { ); OfferItem[] memory offerItems = new OfferItem[](2); - offerItems[0] = OfferItemLib.empty().withItemType(ItemType.ERC1155) - .withToken(address(erc1155s[0])).withIdentifierOrCriteria(1).withAmount( - 100 - ); - - offerItems[1] = OfferItemLib.empty().withItemType(ItemType.ERC1155) - .withToken(address(erc1155s[0])).withIdentifierOrCriteria(1).withAmount( - 100 - ); - - OrderParameters memory orderParams = OrderParametersLib.empty() - .withOfferer(charlie.addr).withOffer(offerItems).withStartTime( - block.timestamp - ).withEndTime(block.timestamp + 1); + offerItems[0] = OfferItemLib + .empty() + .withItemType(ItemType.ERC1155) + .withToken(address(erc1155s[0])) + .withIdentifierOrCriteria(1) + .withAmount(100); + + offerItems[1] = OfferItemLib + .empty() + .withItemType(ItemType.ERC1155) + .withToken(address(erc1155s[0])) + .withIdentifierOrCriteria(1) + .withAmount(100); + + OrderParameters memory orderParams = OrderParametersLib + .empty() + .withOfferer(charlie.addr) + .withOffer(offerItems) + .withStartTime(block.timestamp) + .withEndTime(block.timestamp + 1); Order memory order = OrderLib.empty().withParameters(orderParams); AdvancedOrder[] memory orders = new AdvancedOrder[](1); @@ -317,8 +358,10 @@ contract FuzzSetupTest is BaseOrderTest, FuzzSetup { // Do some surgery on the context so that the setup function thinks // that the order is available and worth providing balance and approvals // for. - context.executionState.orderDetails[0].unavailableReason = - UnavailableReason.AVAILABLE; + context + .executionState + .orderDetails[0] + .unavailableReason = UnavailableReason.AVAILABLE; setUpOfferItems(context); @@ -335,14 +378,20 @@ contract FuzzSetupTest is BaseOrderTest, FuzzSetup { ); OfferItem[] memory offerItems = new OfferItem[](1); - offerItems[0] = OfferItemLib.empty().withItemType(ItemType.ERC1155) - .withToken(address(erc1155s[0])).withIdentifierOrCriteria(1) - .withStartAmount(500).withStartAmount(1000); - - OrderParameters memory orderParams = OrderParametersLib.empty() - .withOfferer(charlie.addr).withOffer(offerItems).withStartTime( - block.timestamp - ).withEndTime(block.timestamp + 1000); + offerItems[0] = OfferItemLib + .empty() + .withItemType(ItemType.ERC1155) + .withToken(address(erc1155s[0])) + .withIdentifierOrCriteria(1) + .withStartAmount(500) + .withStartAmount(1000); + + OrderParameters memory orderParams = OrderParametersLib + .empty() + .withOfferer(charlie.addr) + .withOffer(offerItems) + .withStartTime(block.timestamp) + .withEndTime(block.timestamp + 1000); Order memory order = OrderLib.empty().withParameters(orderParams); AdvancedOrder[] memory orders = new AdvancedOrder[](1); @@ -369,8 +418,10 @@ contract FuzzSetupTest is BaseOrderTest, FuzzSetup { // Do some surgery on the context so that the setup function thinks // that the order is available and worth providing balance and approvals // for. - context.executionState.orderDetails[0].unavailableReason = - UnavailableReason.AVAILABLE; + context + .executionState + .orderDetails[0] + .unavailableReason = UnavailableReason.AVAILABLE; setUpOfferItems(context); @@ -387,17 +438,24 @@ contract FuzzSetupTest is BaseOrderTest, FuzzSetup { ConsiderationItem[] memory considerationItems = new ConsiderationItem[]( 2 ); - considerationItems[0] = ConsiderationItemLib.empty().withItemType( - ItemType.ERC20 - ).withToken(address(erc20s[0])).withAmount(100); - - considerationItems[1] = ConsiderationItemLib.empty().withItemType( - ItemType.ERC20 - ).withToken(address(erc20s[0])).withAmount(100); - - OrderParameters memory orderParams = OrderParametersLib.empty() - .withOfferer(charlie.addr).withConsideration(considerationItems) - .withStartTime(block.timestamp).withEndTime(block.timestamp + 1); + considerationItems[0] = ConsiderationItemLib + .empty() + .withItemType(ItemType.ERC20) + .withToken(address(erc20s[0])) + .withAmount(100); + + considerationItems[1] = ConsiderationItemLib + .empty() + .withItemType(ItemType.ERC20) + .withToken(address(erc20s[0])) + .withAmount(100); + + OrderParameters memory orderParams = OrderParametersLib + .empty() + .withOfferer(charlie.addr) + .withConsideration(considerationItems) + .withStartTime(block.timestamp) + .withEndTime(block.timestamp + 1); Order memory order = OrderLib.empty().withParameters(orderParams); AdvancedOrder[] memory orders = new AdvancedOrder[](1); @@ -422,8 +480,10 @@ contract FuzzSetupTest is BaseOrderTest, FuzzSetup { // Do some surgery on the context so that the setup function thinks // that the order is available and worth providing balance and approvals // for. - context.executionState.orderDetails[0].unavailableReason = - UnavailableReason.AVAILABLE; + context + .executionState + .orderDetails[0] + .unavailableReason = UnavailableReason.AVAILABLE; setUpConsiderationItems(context); @@ -441,21 +501,26 @@ contract FuzzSetupTest is BaseOrderTest, FuzzSetup { ConsiderationItem[] memory considerationItems = new ConsiderationItem[]( 2 ); - considerationItems[0] = ConsiderationItemLib.empty().withItemType( - ItemType.ERC721 - ).withToken(address(erc721s[0])).withIdentifierOrCriteria(1).withAmount( - 1 - ); - - considerationItems[1] = ConsiderationItemLib.empty().withItemType( - ItemType.ERC721 - ).withToken(address(erc721s[0])).withIdentifierOrCriteria(2).withAmount( - 1 - ); - - OrderParameters memory orderParams = OrderParametersLib.empty() - .withOfferer(charlie.addr).withConsideration(considerationItems) - .withStartTime(block.timestamp).withEndTime(block.timestamp + 1); + considerationItems[0] = ConsiderationItemLib + .empty() + .withItemType(ItemType.ERC721) + .withToken(address(erc721s[0])) + .withIdentifierOrCriteria(1) + .withAmount(1); + + considerationItems[1] = ConsiderationItemLib + .empty() + .withItemType(ItemType.ERC721) + .withToken(address(erc721s[0])) + .withIdentifierOrCriteria(2) + .withAmount(1); + + OrderParameters memory orderParams = OrderParametersLib + .empty() + .withOfferer(charlie.addr) + .withConsideration(considerationItems) + .withStartTime(block.timestamp) + .withEndTime(block.timestamp + 1); Order memory order = OrderLib.empty().withParameters(orderParams); AdvancedOrder[] memory orders = new AdvancedOrder[](1); @@ -480,8 +545,10 @@ contract FuzzSetupTest is BaseOrderTest, FuzzSetup { // Do some surgery on the context so that the setup function thinks // that the order is available and worth providing balance and approvals // for. - context.executionState.orderDetails[0].unavailableReason = - UnavailableReason.AVAILABLE; + context + .executionState + .orderDetails[0] + .unavailableReason = UnavailableReason.AVAILABLE; setUpConsiderationItems(context); @@ -501,21 +568,26 @@ contract FuzzSetupTest is BaseOrderTest, FuzzSetup { ConsiderationItem[] memory considerationItems = new ConsiderationItem[]( 2 ); - considerationItems[0] = ConsiderationItemLib.empty().withItemType( - ItemType.ERC1155 - ).withToken(address(erc1155s[0])).withIdentifierOrCriteria(1).withAmount( - 100 - ); - - considerationItems[1] = ConsiderationItemLib.empty().withItemType( - ItemType.ERC1155 - ).withToken(address(erc1155s[0])).withIdentifierOrCriteria(1).withAmount( - 100 - ); - - OrderParameters memory orderParams = OrderParametersLib.empty() - .withOfferer(charlie.addr).withConsideration(considerationItems) - .withStartTime(block.timestamp).withEndTime(block.timestamp + 1); + considerationItems[0] = ConsiderationItemLib + .empty() + .withItemType(ItemType.ERC1155) + .withToken(address(erc1155s[0])) + .withIdentifierOrCriteria(1) + .withAmount(100); + + considerationItems[1] = ConsiderationItemLib + .empty() + .withItemType(ItemType.ERC1155) + .withToken(address(erc1155s[0])) + .withIdentifierOrCriteria(1) + .withAmount(100); + + OrderParameters memory orderParams = OrderParametersLib + .empty() + .withOfferer(charlie.addr) + .withConsideration(considerationItems) + .withStartTime(block.timestamp) + .withEndTime(block.timestamp + 1); Order memory order = OrderLib.empty().withParameters(orderParams); AdvancedOrder[] memory orders = new AdvancedOrder[](1); @@ -540,8 +612,10 @@ contract FuzzSetupTest is BaseOrderTest, FuzzSetup { // Do some surgery on the context so that the setup function thinks // that the order is available and worth providing balance and approvals // for. - context.executionState.orderDetails[0].unavailableReason = - UnavailableReason.AVAILABLE; + context + .executionState + .orderDetails[0] + .unavailableReason = UnavailableReason.AVAILABLE; setUpConsiderationItems(context); diff --git a/test/foundry/new/SeaportNavigator.t.sol b/test/foundry/new/SeaportNavigator.t.sol index 890bcc8..145abab 100644 --- a/test/foundry/new/SeaportNavigator.t.sol +++ b/test/foundry/new/SeaportNavigator.t.sol @@ -36,16 +36,18 @@ import { SeaportNavigator } from "../../../src/main/helpers/navigator/SeaportNavigator.sol"; -import { TokenIdNotFound } from - "../../../src/main/helpers/navigator/lib/CriteriaHelperLib.sol"; +import { + TokenIdNotFound +} from "../../../src/main/helpers/navigator/lib/CriteriaHelperLib.sol"; import { NavigatorAdvancedOrder, NavigatorAdvancedOrderLib } from "../../../src/main/helpers/navigator/lib/NavigatorAdvancedOrderLib.sol"; -import { OrderStructureLib } from - "../../../src/main/helpers/navigator/lib/OrderStructureLib.sol"; +import { + OrderStructureLib +} from "../../../src/main/helpers/navigator/lib/OrderStructureLib.sol"; import { BaseOrderTest } from "./BaseOrderTest.sol"; @@ -76,45 +78,59 @@ contract SeaportNavigatorTestSuite is function setUp() public override(BaseOrderTest, SeaportValidatorTest) { super.setUp(); - OrderLib.empty().withParameters( - OrderComponentsLib.fromDefault(STANDARD).toOrderParameters() - ).saveDefault(STANDARD); + OrderLib + .empty() + .withParameters( + OrderComponentsLib.fromDefault(STANDARD).toOrderParameters() + ) + .saveDefault(STANDARD); // Set up and store order with single ERC721 offer item OfferItem[] memory offer = new OfferItem[](1); - offer[0] = OfferItemLib.empty().withItemType(ItemType.ERC721).withToken( - address(erc721s[0]) - ).withIdentifierOrCriteria(1).withAmount(1); - OrderParameters memory parameters = OrderComponentsLib.fromDefault( - STANDARD - ).withStartTime(block.timestamp).withEndTime(block.timestamp + 1) - .toOrderParameters().withOffer(offer); + offer[0] = OfferItemLib + .empty() + .withItemType(ItemType.ERC721) + .withToken(address(erc721s[0])) + .withIdentifierOrCriteria(1) + .withAmount(1); + OrderParameters memory parameters = OrderComponentsLib + .fromDefault(STANDARD) + .withStartTime(block.timestamp) + .withEndTime(block.timestamp + 1) + .toOrderParameters() + .withOffer(offer); parameters.saveDefault(SINGLE_ERC721); OrderLib.empty().withParameters(parameters).saveDefault(SINGLE_ERC721); ConsiderationItem[] memory _consideration = new ConsiderationItem[](1); - _consideration[0] = ConsiderationItemLib.empty().withItemType( - ItemType.ERC20 - ).withToken(address(erc20s[0])).withAmount(1); - parameters = OrderParametersLib.fromDefault(SINGLE_ERC721) - .withConsideration(_consideration).withTotalOriginalConsiderationItems( - 1 - ); + _consideration[0] = ConsiderationItemLib + .empty() + .withItemType(ItemType.ERC20) + .withToken(address(erc20s[0])) + .withAmount(1); + parameters = OrderParametersLib + .fromDefault(SINGLE_ERC721) + .withConsideration(_consideration) + .withTotalOriginalConsiderationItems(1); OrderLib.empty().withParameters(parameters).saveDefault( SINGLE_ERC721_SINGLE_ERC20 ); - offer[0] = OfferItemLib.empty().withItemType( - ItemType.ERC721_WITH_CRITERIA - ).withToken(address(erc721s[0])).withAmount(1); - _consideration[0] = ConsiderationItemLib.empty().withItemType( - ItemType.ERC721_WITH_CRITERIA - ).withToken(address(erc721s[0])).withAmount(1); - parameters = OrderParametersLib.fromDefault(SINGLE_ERC721).withOffer( - offer - ).withConsideration(_consideration).withTotalOriginalConsiderationItems( - 1 - ); + offer[0] = OfferItemLib + .empty() + .withItemType(ItemType.ERC721_WITH_CRITERIA) + .withToken(address(erc721s[0])) + .withAmount(1); + _consideration[0] = ConsiderationItemLib + .empty() + .withItemType(ItemType.ERC721_WITH_CRITERIA) + .withToken(address(erc721s[0])) + .withAmount(1); + parameters = OrderParametersLib + .fromDefault(SINGLE_ERC721) + .withOffer(offer) + .withConsideration(_consideration) + .withTotalOriginalConsiderationItems(1); parameters.saveDefault( SINGLE_ERC721_WITH_CRITERIA_SINGLE_ERC721_WITH_CRITERIA ); @@ -127,9 +143,9 @@ contract SeaportNavigatorTestSuite is NavigatorAdvancedOrder[] memory orders = new NavigatorAdvancedOrder[]( 1 ); - AdvancedOrder memory advancedOrder = OrderLib.fromDefault( - SINGLE_ERC721_SINGLE_ERC20 - ).toAdvancedOrder(1, 1, ""); + AdvancedOrder memory advancedOrder = OrderLib + .fromDefault(SINGLE_ERC721_SINGLE_ERC20) + .toAdvancedOrder(1, 1, ""); orders[0] = NavigatorAdvancedOrderLib.fromAdvancedOrder(advancedOrder); FulfillmentStrategy memory fulfillmentStrategy = FulfillmentStrategy({ @@ -170,14 +186,18 @@ contract SeaportNavigatorTestSuite is ), "unexpected suggested calldata" ); + assertEq( - res.validationErrors.length, 1, "unexpected validationErrors length" + res.validationErrors.length, + 1, + "unexpected validationErrors length" ); assertEq( res.validationErrors[0].errors.length, 4, "unexpected validationErrors[0].errors length" ); + assertEq( res.validationErrors[0].warnings.length, 1, @@ -236,8 +256,9 @@ contract SeaportNavigatorTestSuite is NavigatorAdvancedOrder[] memory orders = new NavigatorAdvancedOrder[]( 1 ); - AdvancedOrder memory advancedOrder = - OrderLib.fromDefault(SINGLE_ERC721).toAdvancedOrder(1, 1, ""); + AdvancedOrder memory advancedOrder = OrderLib + .fromDefault(SINGLE_ERC721) + .toAdvancedOrder(1, 1, ""); orders[0] = NavigatorAdvancedOrderLib.fromAdvancedOrder(advancedOrder); FulfillmentStrategy memory fulfillmentStrategy = FulfillmentStrategy({ @@ -275,7 +296,9 @@ contract SeaportNavigatorTestSuite is "unexpected suggested calldata" ); assertEq( - res.validationErrors.length, 1, "unexpected validationErrors length" + res.validationErrors.length, + 1, + "unexpected validationErrors length" ); assertEq( res.validationErrors[0].errors.length, @@ -342,8 +365,11 @@ contract SeaportNavigatorTestSuite is ); Order memory order = OrderLib.fromDefault(SINGLE_ERC721).copy(); - AdvancedOrder memory advancedOrder = - order.toAdvancedOrder(1, 1, "dummy"); + AdvancedOrder memory advancedOrder = order.toAdvancedOrder( + 1, + 1, + "dummy" + ); address offerer = offerer1.addr; OfferItem memory item = advancedOrder.parameters.offer[0]; @@ -352,13 +378,17 @@ contract SeaportNavigatorTestSuite is TestERC721(item.token).setApprovalForAll(address(seaport), true); ConsiderationItem[] memory consideration = new ConsiderationItem[](1); - consideration[0] = ConsiderationItemLib.empty().withItemType( - ItemType.NATIVE - ).withToken(address(0)).withAmount(1 ether).withRecipient(offerer); + consideration[0] = ConsiderationItemLib + .empty() + .withItemType(ItemType.NATIVE) + .withToken(address(0)) + .withAmount(1 ether) + .withRecipient(offerer); advancedOrder.parameters = advancedOrder .parameters - .withTotalConsideration(consideration).withOfferer(offerer); + .withTotalConsideration(consideration) + .withOfferer(offerer); uint256 counter = getSeaport().getCounter(offerer1.addr); bytes32 orderHash = getSeaport().getOrderHash( @@ -411,14 +441,23 @@ contract SeaportNavigatorTestSuite is ), "unexpected suggested calldata" ); - assertEq( - res.validationErrors.length, 1, "unexpected validationErrors length" - ); - assertEq( - res.validationErrors[0].errors.length, - 0, - "unexpected validationErrors[0].errors length" - ); + + if ( + keccak256(bytes(vm.envOr("FOUNDRY_PROFILE", string("test")))) != + keccak256(bytes(string("reference"))) + ) { + assertEq( + res.validationErrors.length, + 1, + "unexpected validationErrors length" + ); + assertEq( + res.validationErrors[0].errors.length, + 0, + "unexpected validationErrors[0].errors length" + ); + } + assertEq(res.orderDetails.length, 1, "unexpected orderDetails length"); assertEq( res.offerFulfillments.length, @@ -481,9 +520,11 @@ contract SeaportNavigatorTestSuite is NavigatorAdvancedOrder[] memory orders = new NavigatorAdvancedOrder[]( 1 ); - AdvancedOrder memory advancedOrder = OrderLib.fromDefault( - SINGLE_ERC721_WITH_CRITERIA_SINGLE_ERC721_WITH_CRITERIA - ).toAdvancedOrder(1, 1, ""); + AdvancedOrder memory advancedOrder = OrderLib + .fromDefault( + SINGLE_ERC721_WITH_CRITERIA_SINGLE_ERC721_WITH_CRITERIA + ) + .toAdvancedOrder(1, 1, ""); orders[0] = NavigatorAdvancedOrderLib.fromAdvancedOrder(advancedOrder); uint256[] memory offerIds = new uint256[](3); @@ -497,8 +538,10 @@ contract SeaportNavigatorTestSuite is considerationIds[0] = 4; considerationIds[1] = 5; considerationIds[2] = 6; - orders[0].parameters.consideration[0].candidateIdentifiers = - considerationIds; + orders[0] + .parameters + .consideration[0] + .candidateIdentifiers = considerationIds; orders[0].parameters.consideration[0].identifier = 4; FulfillmentStrategy memory fulfillmentStrategy = FulfillmentStrategy({ diff --git a/test/foundry/new/SeaportNavigatorTest.sol b/test/foundry/new/SeaportNavigatorTest.sol index a766e8e..5e8f88a 100644 --- a/test/foundry/new/SeaportNavigatorTest.sol +++ b/test/foundry/new/SeaportNavigatorTest.sol @@ -1,32 +1,41 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.17; -import { CriteriaHelper } from - "../../../src/main/helpers/navigator/lib/CriteriaHelper.sol"; +import { + CriteriaHelper +} from "../../../src/main/helpers/navigator/lib/CriteriaHelper.sol"; -import { ExecutionsHelper } from - "../../../src/main/helpers/navigator/lib/ExecutionsHelper.sol"; +import { + ExecutionsHelper +} from "../../../src/main/helpers/navigator/lib/ExecutionsHelper.sol"; -import { FulfillmentsHelper } from - "../../../src/main/helpers/navigator/lib/FulfillmentsHelper.sol"; +import { + FulfillmentsHelper +} from "../../../src/main/helpers/navigator/lib/FulfillmentsHelper.sol"; -import { HelperInterface } from - "../../../src/main/helpers/navigator/lib/HelperInterface.sol"; +import { + HelperInterface +} from "../../../src/main/helpers/navigator/lib/HelperInterface.sol"; -import { OrderDetailsHelper } from - "../../../src/main/helpers/navigator/lib/OrderDetailsHelper.sol"; +import { + OrderDetailsHelper +} from "../../../src/main/helpers/navigator/lib/OrderDetailsHelper.sol"; -import { RequestValidator } from - "../../../src/main/helpers/navigator/lib/RequestValidator.sol"; +import { + RequestValidator +} from "../../../src/main/helpers/navigator/lib/RequestValidator.sol"; -import { SeaportNavigator } from - "../../../src/main/helpers/navigator/SeaportNavigator.sol"; +import { + SeaportNavigator +} from "../../../src/main/helpers/navigator/SeaportNavigator.sol"; -import { SuggestedActionHelper } from - "../../../src/main/helpers/navigator/lib/SuggestedActionHelper.sol"; +import { + SuggestedActionHelper +} from "../../../src/main/helpers/navigator/lib/SuggestedActionHelper.sol"; -import { ValidatorHelper } from - "../../../src/main/helpers/navigator/lib/ValidatorHelper.sol"; +import { + ValidatorHelper +} from "../../../src/main/helpers/navigator/lib/ValidatorHelper.sol"; contract SeaportNavigatorTest { HelperInterface internal requestValidator = new RequestValidator(); @@ -34,11 +43,13 @@ contract SeaportNavigatorTest { HelperInterface internal validatorHelper = new ValidatorHelper(); HelperInterface internal orderDetailsHelper = new OrderDetailsHelper(); HelperInterface internal fulfillmentsHelper = new FulfillmentsHelper(); - HelperInterface internal suggestedActionHelper = new SuggestedActionHelper(); + HelperInterface internal suggestedActionHelper = + new SuggestedActionHelper(); HelperInterface internal executionsHelper = new ExecutionsHelper(); // Initialize the navigator with all its constituent helpers. - SeaportNavigator internal navigator = new SeaportNavigator( + SeaportNavigator internal navigator = + new SeaportNavigator( address(requestValidator), address(criteriaHelper), address(validatorHelper), diff --git a/test/foundry/new/SeaportValidator.t.sol b/test/foundry/new/SeaportValidator.t.sol index c73fc31..1c946be 100644 --- a/test/foundry/new/SeaportValidator.t.sol +++ b/test/foundry/new/SeaportValidator.t.sol @@ -19,14 +19,17 @@ import { NativeIssue } from "../../../src/main/helpers/order-validator/SeaportValidator.sol"; -import { ConduitControllerInterface } from - "seaport-sol/src/ConduitControllerInterface.sol"; +import { + ConduitControllerInterface +} from "seaport-sol/src/ConduitControllerInterface.sol"; -import { SeaportValidatorHelper } from - "../../../src/main/helpers/order-validator/lib/SeaportValidatorHelper.sol"; +import { + SeaportValidatorHelper +} from "../../../src/main/helpers/order-validator/lib/SeaportValidatorHelper.sol"; -import { IssueStringHelpers } from - "../../../src/main/helpers/order-validator/lib/SeaportValidatorTypes.sol"; +import { + IssueStringHelpers +} from "../../../src/main/helpers/order-validator/lib/SeaportValidatorTypes.sol"; import { ConsiderationItemLib, @@ -84,71 +87,96 @@ contract SeaportValidatorTestSuite is BaseOrderTest, SeaportValidatorTest { function setUp() public override(BaseOrderTest, SeaportValidatorTest) { super.setUp(); - OrderLib.empty().withParameters( - OrderComponentsLib.fromDefault(STANDARD).toOrderParameters() - ).saveDefault(STANDARD); + OrderLib + .empty() + .withParameters( + OrderComponentsLib.fromDefault(STANDARD).toOrderParameters() + ) + .saveDefault(STANDARD); // Set up and store order with single ERC20 offer item OfferItem[] memory offer = new OfferItem[](1); - offer[0] = OfferItemLib.empty().withItemType(ItemType.ERC20).withToken( - address(erc20s[0]) - ).withAmount(1); - OrderParameters memory parameters = OrderComponentsLib.fromDefault( - STANDARD - ).toOrderParameters().withOffer(offer); + offer[0] = OfferItemLib + .empty() + .withItemType(ItemType.ERC20) + .withToken(address(erc20s[0])) + .withAmount(1); + OrderParameters memory parameters = OrderComponentsLib + .fromDefault(STANDARD) + .toOrderParameters() + .withOffer(offer); OrderLib.empty().withParameters(parameters).saveDefault(SINGLE_ERC20); // Set up and store order with single ERC721 offer item offer = new OfferItem[](1); - offer[0] = OfferItemLib.empty().withItemType(ItemType.ERC721).withToken( - address(erc721s[0]) - ).withIdentifierOrCriteria(1).withAmount(1); - parameters = OrderComponentsLib.fromDefault(STANDARD).toOrderParameters( - ).withOffer(offer); + offer[0] = OfferItemLib + .empty() + .withItemType(ItemType.ERC721) + .withToken(address(erc721s[0])) + .withIdentifierOrCriteria(1) + .withAmount(1); + parameters = OrderComponentsLib + .fromDefault(STANDARD) + .toOrderParameters() + .withOffer(offer); parameters.saveDefault(SINGLE_ERC721); OrderLib.empty().withParameters(parameters).saveDefault(SINGLE_ERC721); // Set up and store order with single ERC1155 offer item offer = new OfferItem[](1); - offer[0] = OfferItemLib.empty().withItemType(ItemType.ERC1155).withToken( - address(erc1155s[0]) - ).withIdentifierOrCriteria(1).withAmount(1); - parameters = OrderComponentsLib.fromDefault(STANDARD).toOrderParameters( - ).withOffer(offer); + offer[0] = OfferItemLib + .empty() + .withItemType(ItemType.ERC1155) + .withToken(address(erc1155s[0])) + .withIdentifierOrCriteria(1) + .withAmount(1); + parameters = OrderComponentsLib + .fromDefault(STANDARD) + .toOrderParameters() + .withOffer(offer); OrderLib.empty().withParameters(parameters).saveDefault(SINGLE_ERC1155); // Set up and store order with single native offer item offer = new OfferItem[](1); - offer[0] = OfferItemLib.empty().withItemType(ItemType.NATIVE).withToken( - address(0) - ).withIdentifierOrCriteria(0).withAmount(1); - parameters = OrderComponentsLib.fromDefault(STANDARD).toOrderParameters( - ).withOffer(offer); + offer[0] = OfferItemLib + .empty() + .withItemType(ItemType.NATIVE) + .withToken(address(0)) + .withIdentifierOrCriteria(0) + .withAmount(1); + parameters = OrderComponentsLib + .fromDefault(STANDARD) + .toOrderParameters() + .withOffer(offer); OrderLib.empty().withParameters(parameters).saveDefault(SINGLE_NATIVE); // Set up and store order with single ERC721 offer item // and single native consideration item ConsiderationItem[] memory _consideration = new ConsiderationItem[](1); - _consideration[0] = ConsiderationItemLib.empty().withItemType( - ItemType.NATIVE - ).withToken(address(0)).withAmount(1); - parameters = OrderParametersLib.fromDefault(SINGLE_ERC721) - .withConsideration(_consideration).withTotalOriginalConsiderationItems( - 1 - ); + _consideration[0] = ConsiderationItemLib + .empty() + .withItemType(ItemType.NATIVE) + .withToken(address(0)) + .withAmount(1); + parameters = OrderParametersLib + .fromDefault(SINGLE_ERC721) + .withConsideration(_consideration) + .withTotalOriginalConsiderationItems(1); OrderLib.empty().withParameters(parameters).saveDefault( SINGLE_ERC721_SINGLE_NATIVE ); // Set up and store order with single ERC721 offer item // and single ERC20 consideration item - _consideration[0] = ConsiderationItemLib.empty().withItemType( - ItemType.ERC20 - ).withToken(address(erc20s[0])).withAmount(1); - parameters = OrderParametersLib.fromDefault(SINGLE_ERC721) - .withConsideration(_consideration).withTotalOriginalConsiderationItems( - 1 - ); + _consideration[0] = ConsiderationItemLib + .empty() + .withItemType(ItemType.ERC20) + .withToken(address(erc20s[0])) + .withAmount(1); + parameters = OrderParametersLib + .fromDefault(SINGLE_ERC721) + .withConsideration(_consideration) + .withTotalOriginalConsiderationItems(1); OrderLib.empty().withParameters(parameters).saveDefault( SINGLE_ERC721_SINGLE_ERC20 ); @@ -156,43 +184,51 @@ contract SeaportValidatorTestSuite is BaseOrderTest, SeaportValidatorTest { // Set up and store order with single ERC721 offer item // and single ERC721 consideration item _consideration = new ConsiderationItem[](1); - _consideration[0] = ConsiderationItemLib.empty().withItemType( - ItemType.ERC721 - ).withToken(address(erc721s[0])).withIdentifierOrCriteria(2).withAmount( - 1 - ).withRecipient(offerer1.addr); - parameters = OrderParametersLib.fromDefault(SINGLE_ERC721) - .withConsideration(_consideration).withTotalOriginalConsiderationItems( - 1 - ); + _consideration[0] = ConsiderationItemLib + .empty() + .withItemType(ItemType.ERC721) + .withToken(address(erc721s[0])) + .withIdentifierOrCriteria(2) + .withAmount(1) + .withRecipient(offerer1.addr); + parameters = OrderParametersLib + .fromDefault(SINGLE_ERC721) + .withConsideration(_consideration) + .withTotalOriginalConsiderationItems(1); OrderLib.empty().withParameters(parameters).saveDefault( SINGLE_ERC721_SINGLE_ERC721 ); } function test_empty_isValidOrder() public { - ErrorsAndWarnings memory actual = - validator.isValidOrder(OrderLib.empty(), address(seaport)); + ErrorsAndWarnings memory actual = validator.isValidOrder( + OrderLib.empty(), + address(seaport) + ); - ErrorsAndWarnings memory expected = ErrorsAndWarningsLib.empty() - .addError(TimeIssue.EndTimeBeforeStartTime).addError( - SignatureIssue.Invalid - ).addError(GenericIssue.InvalidOrderFormat).addWarning( - OfferIssue.ZeroItems - ).addWarning(ConsiderationIssue.ZeroItems); + ErrorsAndWarnings memory expected = ErrorsAndWarningsLib + .empty() + .addError(TimeIssue.EndTimeBeforeStartTime) + .addError(SignatureIssue.Invalid) + .addError(GenericIssue.InvalidOrderFormat) + .addWarning(OfferIssue.ZeroItems) + .addWarning(ConsiderationIssue.ZeroItems); assertEq(actual, expected); } function test_default_full_isValidOrder() public { ErrorsAndWarnings memory actual = validator.isValidOrder( - OrderLib.fromDefault(STANDARD), address(seaport) + OrderLib.fromDefault(STANDARD), + address(seaport) ); - ErrorsAndWarnings memory expected = ErrorsAndWarningsLib.empty() - .addError(SignatureIssue.Invalid).addError( - GenericIssue.InvalidOrderFormat - ).addWarning(TimeIssue.ShortOrder).addWarning(OfferIssue.ZeroItems) + ErrorsAndWarnings memory expected = ErrorsAndWarningsLib + .empty() + .addError(SignatureIssue.Invalid) + .addError(GenericIssue.InvalidOrderFormat) + .addWarning(TimeIssue.ShortOrder) + .addWarning(OfferIssue.ZeroItems) .addWarning(ConsiderationIssue.ZeroItems); assertEq(actual, expected); @@ -202,14 +238,18 @@ contract SeaportValidatorTestSuite is BaseOrderTest, SeaportValidatorTest { Order memory order = OrderLib.fromDefault(SINGLE_ERC20); order.parameters.offer[0].identifierOrCriteria = 1; - ErrorsAndWarnings memory actual = - validator.isValidOrder(order, address(seaport)); + ErrorsAndWarnings memory actual = validator.isValidOrder( + order, + address(seaport) + ); - ErrorsAndWarnings memory expected = ErrorsAndWarningsLib.empty() - .addError(ERC20Issue.IdentifierNonZero).addError(SignatureIssue.Invalid) - .addError(GenericIssue.InvalidOrderFormat).addWarning( - TimeIssue.ShortOrder - ).addWarning(ConsiderationIssue.ZeroItems); + ErrorsAndWarnings memory expected = ErrorsAndWarningsLib + .empty() + .addError(ERC20Issue.IdentifierNonZero) + .addError(SignatureIssue.Invalid) + .addError(GenericIssue.InvalidOrderFormat) + .addWarning(TimeIssue.ShortOrder) + .addWarning(ConsiderationIssue.ZeroItems); assertEq(actual, expected); } @@ -218,14 +258,18 @@ contract SeaportValidatorTestSuite is BaseOrderTest, SeaportValidatorTest { Order memory order = OrderLib.fromDefault(SINGLE_ERC20); order.parameters.offer[0].token = address(0); - ErrorsAndWarnings memory actual = - validator.isValidOrder(order, address(seaport)); + ErrorsAndWarnings memory actual = validator.isValidOrder( + order, + address(seaport) + ); - ErrorsAndWarnings memory expected = ErrorsAndWarningsLib.empty() - .addError(ERC20Issue.InvalidToken).addError(SignatureIssue.Invalid) - .addError(GenericIssue.InvalidOrderFormat).addWarning( - TimeIssue.ShortOrder - ).addWarning(ConsiderationIssue.ZeroItems); + ErrorsAndWarnings memory expected = ErrorsAndWarningsLib + .empty() + .addError(ERC20Issue.InvalidToken) + .addError(SignatureIssue.Invalid) + .addError(GenericIssue.InvalidOrderFormat) + .addWarning(TimeIssue.ShortOrder) + .addWarning(ConsiderationIssue.ZeroItems); assertEq(actual, expected); } @@ -235,15 +279,18 @@ contract SeaportValidatorTestSuite is BaseOrderTest, SeaportValidatorTest { order.parameters.offerer = noTokens; erc20s[0].mint(noTokens, 1); - ErrorsAndWarnings memory actual = - validator.isValidOrder(order, address(seaport)); + ErrorsAndWarnings memory actual = validator.isValidOrder( + order, + address(seaport) + ); - ErrorsAndWarnings memory expected = ErrorsAndWarningsLib.empty() - .addError(ERC20Issue.InsufficientAllowance).addError( - SignatureIssue.Invalid - ).addError(GenericIssue.InvalidOrderFormat).addWarning( - TimeIssue.ShortOrder - ).addWarning(ConsiderationIssue.ZeroItems); + ErrorsAndWarnings memory expected = ErrorsAndWarningsLib + .empty() + .addError(ERC20Issue.InsufficientAllowance) + .addError(SignatureIssue.Invalid) + .addError(GenericIssue.InvalidOrderFormat) + .addWarning(TimeIssue.ShortOrder) + .addWarning(ConsiderationIssue.ZeroItems); assertEq(actual, expected); } @@ -252,18 +299,20 @@ contract SeaportValidatorTestSuite is BaseOrderTest, SeaportValidatorTest { Order memory order = OrderLib.fromDefault(SINGLE_ERC20); order.parameters.offerer = noTokens; - ErrorsAndWarnings memory actual = - validator.isValidOrder(order, address(seaport)); - - ErrorsAndWarnings memory expected = ErrorsAndWarningsLib.empty() - .addError(ERC20Issue.InsufficientAllowance).addError( - ERC20Issue.InsufficientBalance - ).addError(SignatureIssue.Invalid).addError( - GenericIssue.InvalidOrderFormat - ).addWarning(TimeIssue.ShortOrder).addWarning( - ConsiderationIssue.ZeroItems + ErrorsAndWarnings memory actual = validator.isValidOrder( + order, + address(seaport) ); + ErrorsAndWarnings memory expected = ErrorsAndWarningsLib + .empty() + .addError(ERC20Issue.InsufficientAllowance) + .addError(ERC20Issue.InsufficientBalance) + .addError(SignatureIssue.Invalid) + .addError(GenericIssue.InvalidOrderFormat) + .addWarning(TimeIssue.ShortOrder) + .addWarning(ConsiderationIssue.ZeroItems); + assertEq(actual, expected); } @@ -272,14 +321,18 @@ contract SeaportValidatorTestSuite is BaseOrderTest, SeaportValidatorTest { order.parameters.offer[0].startAmount = 3; order.parameters.offer[0].endAmount = 3; - ErrorsAndWarnings memory actual = - validator.isValidOrder(order, address(seaport)); + ErrorsAndWarnings memory actual = validator.isValidOrder( + order, + address(seaport) + ); - ErrorsAndWarnings memory expected = ErrorsAndWarningsLib.empty() - .addError(ERC721Issue.AmountNotOne).addError(SignatureIssue.Invalid) - .addError(GenericIssue.InvalidOrderFormat).addWarning( - TimeIssue.ShortOrder - ).addWarning(ConsiderationIssue.ZeroItems); + ErrorsAndWarnings memory expected = ErrorsAndWarningsLib + .empty() + .addError(ERC721Issue.AmountNotOne) + .addError(SignatureIssue.Invalid) + .addError(GenericIssue.InvalidOrderFormat) + .addWarning(TimeIssue.ShortOrder) + .addWarning(ConsiderationIssue.ZeroItems); assertEq(actual, expected); } @@ -288,32 +341,41 @@ contract SeaportValidatorTestSuite is BaseOrderTest, SeaportValidatorTest { Order memory order = OrderLib.fromDefault(SINGLE_ERC721); order.parameters.offer[0].token = address(0); - ErrorsAndWarnings memory actual = - validator.isValidOrder(order, address(seaport)); + ErrorsAndWarnings memory actual = validator.isValidOrder( + order, + address(seaport) + ); - ErrorsAndWarnings memory expected = ErrorsAndWarningsLib.empty() - .addError(ERC721Issue.InvalidToken).addError(SignatureIssue.Invalid) - .addError(GenericIssue.InvalidOrderFormat).addWarning( - TimeIssue.ShortOrder - ).addWarning(ConsiderationIssue.ZeroItems); + ErrorsAndWarnings memory expected = ErrorsAndWarningsLib + .empty() + .addError(ERC721Issue.InvalidToken) + .addError(SignatureIssue.Invalid) + .addError(GenericIssue.InvalidOrderFormat) + .addWarning(TimeIssue.ShortOrder) + .addWarning(ConsiderationIssue.ZeroItems); assertEq(actual, expected); } function test_isValidOrder_erc721_identifierDNE() public { Order memory order = OrderLib.fromDefault(SINGLE_ERC721_SINGLE_ERC721); - order.parameters.consideration[0].identifierOrCriteria = - type(uint256).max; + order.parameters.consideration[0].identifierOrCriteria = type(uint256) + .max; - ErrorsAndWarnings memory actual = - validator.isValidOrder(order, address(seaport)); + ErrorsAndWarnings memory actual = validator.isValidOrder( + order, + address(seaport) + ); - ErrorsAndWarnings memory expected = ErrorsAndWarningsLib.empty() - .addError(ERC721Issue.NotOwner).addError(ERC721Issue.NotApproved) - .addError(ERC721Issue.IdentifierDNE).addError(SignatureIssue.Invalid) - .addError(GenericIssue.InvalidOrderFormat).addWarning( - TimeIssue.ShortOrder - ).addWarning(ConsiderationIssue.OffererNotReceivingAtLeastOneItem); + ErrorsAndWarnings memory expected = ErrorsAndWarningsLib + .empty() + .addError(ERC721Issue.NotOwner) + .addError(ERC721Issue.NotApproved) + .addError(ERC721Issue.IdentifierDNE) + .addError(SignatureIssue.Invalid) + .addError(GenericIssue.InvalidOrderFormat) + .addWarning(TimeIssue.ShortOrder) + .addWarning(ConsiderationIssue.OffererNotReceivingAtLeastOneItem); assertEq(actual, expected); } @@ -322,17 +384,20 @@ contract SeaportValidatorTestSuite is BaseOrderTest, SeaportValidatorTest { Order memory order = OrderLib.fromDefault(SINGLE_ERC721); order.parameters.offerer = noTokens; - ErrorsAndWarnings memory actual = - validator.isValidOrder(order, address(seaport)); - - ErrorsAndWarnings memory expected = ErrorsAndWarningsLib.empty() - .addError(ERC721Issue.NotOwner).addError(ERC721Issue.NotApproved) - .addError(SignatureIssue.Invalid).addError( - GenericIssue.InvalidOrderFormat - ).addWarning(TimeIssue.ShortOrder).addWarning( - ConsiderationIssue.ZeroItems + ErrorsAndWarnings memory actual = validator.isValidOrder( + order, + address(seaport) ); + ErrorsAndWarnings memory expected = ErrorsAndWarningsLib + .empty() + .addError(ERC721Issue.NotOwner) + .addError(ERC721Issue.NotApproved) + .addError(SignatureIssue.Invalid) + .addError(GenericIssue.InvalidOrderFormat) + .addWarning(TimeIssue.ShortOrder) + .addWarning(ConsiderationIssue.ZeroItems); + assertEq(actual, expected); } @@ -341,14 +406,18 @@ contract SeaportValidatorTestSuite is BaseOrderTest, SeaportValidatorTest { order.parameters.offerer = noTokens; erc721s[0].mint(noTokens, 1); - ErrorsAndWarnings memory actual = - validator.isValidOrder(order, address(seaport)); + ErrorsAndWarnings memory actual = validator.isValidOrder( + order, + address(seaport) + ); - ErrorsAndWarnings memory expected = ErrorsAndWarningsLib.empty() - .addError(ERC721Issue.NotApproved).addError(SignatureIssue.Invalid) - .addError(GenericIssue.InvalidOrderFormat).addWarning( - TimeIssue.ShortOrder - ).addWarning(ConsiderationIssue.ZeroItems); + ErrorsAndWarnings memory expected = ErrorsAndWarningsLib + .empty() + .addError(ERC721Issue.NotApproved) + .addError(SignatureIssue.Invalid) + .addError(GenericIssue.InvalidOrderFormat) + .addWarning(TimeIssue.ShortOrder) + .addWarning(ConsiderationIssue.ZeroItems); assertEq(actual, expected); } @@ -359,17 +428,20 @@ contract SeaportValidatorTestSuite is BaseOrderTest, SeaportValidatorTest { order.parameters.offer[0].startAmount = 2; order.parameters.offer[0].endAmount = 10; - ErrorsAndWarnings memory actual = - validator.isValidOrder(order, address(seaport)); + ErrorsAndWarnings memory actual = validator.isValidOrder( + order, + address(seaport) + ); - ErrorsAndWarnings memory expected = ErrorsAndWarningsLib.empty() - .addError(OfferIssue.AmountVelocityHigh).addError( - ERC721Issue.CriteriaNotPartialFill - ).addError(SignatureIssue.Invalid).addError( - GenericIssue.InvalidOrderFormat - ).addWarning(TimeIssue.ShortOrder).addWarning( - OfferIssue.AmountStepLarge - ).addWarning(ConsiderationIssue.ZeroItems); + ErrorsAndWarnings memory expected = ErrorsAndWarningsLib + .empty() + .addError(OfferIssue.AmountVelocityHigh) + .addError(ERC721Issue.CriteriaNotPartialFill) + .addError(SignatureIssue.Invalid) + .addError(GenericIssue.InvalidOrderFormat) + .addWarning(TimeIssue.ShortOrder) + .addWarning(OfferIssue.AmountStepLarge) + .addWarning(ConsiderationIssue.ZeroItems); assertEq(actual, expected); } @@ -378,14 +450,18 @@ contract SeaportValidatorTestSuite is BaseOrderTest, SeaportValidatorTest { Order memory order = OrderLib.fromDefault(SINGLE_ERC1155); order.parameters.offer[0].token = address(0); - ErrorsAndWarnings memory actual = - validator.isValidOrder(order, address(seaport)); + ErrorsAndWarnings memory actual = validator.isValidOrder( + order, + address(seaport) + ); - ErrorsAndWarnings memory expected = ErrorsAndWarningsLib.empty() - .addError(ERC1155Issue.InvalidToken).addError(SignatureIssue.Invalid) - .addError(GenericIssue.InvalidOrderFormat).addWarning( - TimeIssue.ShortOrder - ).addWarning(ConsiderationIssue.ZeroItems); + ErrorsAndWarnings memory expected = ErrorsAndWarningsLib + .empty() + .addError(ERC1155Issue.InvalidToken) + .addError(SignatureIssue.Invalid) + .addError(GenericIssue.InvalidOrderFormat) + .addWarning(TimeIssue.ShortOrder) + .addWarning(ConsiderationIssue.ZeroItems); assertEq(actual, expected); } @@ -395,14 +471,18 @@ contract SeaportValidatorTestSuite is BaseOrderTest, SeaportValidatorTest { order.parameters.offerer = noTokens; erc1155s[0].mint(noTokens, 1, 1); - ErrorsAndWarnings memory actual = - validator.isValidOrder(order, address(seaport)); + ErrorsAndWarnings memory actual = validator.isValidOrder( + order, + address(seaport) + ); - ErrorsAndWarnings memory expected = ErrorsAndWarningsLib.empty() - .addError(ERC1155Issue.NotApproved).addError(SignatureIssue.Invalid) - .addError(GenericIssue.InvalidOrderFormat).addWarning( - TimeIssue.ShortOrder - ).addWarning(ConsiderationIssue.ZeroItems); + ErrorsAndWarnings memory expected = ErrorsAndWarningsLib + .empty() + .addError(ERC1155Issue.NotApproved) + .addError(SignatureIssue.Invalid) + .addError(GenericIssue.InvalidOrderFormat) + .addWarning(TimeIssue.ShortOrder) + .addWarning(ConsiderationIssue.ZeroItems); assertEq(actual, expected); } @@ -411,18 +491,20 @@ contract SeaportValidatorTestSuite is BaseOrderTest, SeaportValidatorTest { Order memory order = OrderLib.fromDefault(SINGLE_ERC1155); order.parameters.offerer = noTokens; - ErrorsAndWarnings memory actual = - validator.isValidOrder(order, address(seaport)); - - ErrorsAndWarnings memory expected = ErrorsAndWarningsLib.empty() - .addError(ERC1155Issue.NotApproved).addError( - ERC1155Issue.InsufficientBalance - ).addError(SignatureIssue.Invalid).addError( - GenericIssue.InvalidOrderFormat - ).addWarning(TimeIssue.ShortOrder).addWarning( - ConsiderationIssue.ZeroItems + ErrorsAndWarnings memory actual = validator.isValidOrder( + order, + address(seaport) ); + ErrorsAndWarnings memory expected = ErrorsAndWarningsLib + .empty() + .addError(ERC1155Issue.NotApproved) + .addError(ERC1155Issue.InsufficientBalance) + .addError(SignatureIssue.Invalid) + .addError(GenericIssue.InvalidOrderFormat) + .addWarning(TimeIssue.ShortOrder) + .addWarning(ConsiderationIssue.ZeroItems); + assertEq(actual, expected); } @@ -436,18 +518,21 @@ contract SeaportValidatorTestSuite is BaseOrderTest, SeaportValidatorTest { vm.prank(order.parameters.offerer); seaport.cancel(orderComponents); - ErrorsAndWarnings memory actual = - validator.isValidOrder(order, address(seaport)); - - ErrorsAndWarnings memory expected = ErrorsAndWarningsLib.empty() - .addError(StatusIssue.Cancelled).addError(ERC721Issue.NotOwner).addError( - ERC721Issue.NotApproved - ).addError(SignatureIssue.Invalid).addError( - GenericIssue.InvalidOrderFormat - ).addWarning(TimeIssue.ShortOrder).addWarning( - ConsiderationIssue.ZeroItems + ErrorsAndWarnings memory actual = validator.isValidOrder( + order, + address(seaport) ); + ErrorsAndWarnings memory expected = ErrorsAndWarningsLib + .empty() + .addError(StatusIssue.Cancelled) + .addError(ERC721Issue.NotOwner) + .addError(ERC721Issue.NotApproved) + .addError(SignatureIssue.Invalid) + .addError(GenericIssue.InvalidOrderFormat) + .addWarning(TimeIssue.ShortOrder) + .addWarning(ConsiderationIssue.ZeroItems); + assertEq(actual, expected); } @@ -455,16 +540,20 @@ contract SeaportValidatorTestSuite is BaseOrderTest, SeaportValidatorTest { Order memory order = OrderLib.fromDefault(SINGLE_ERC721); order.parameters.orderType = OrderType.CONTRACT; - ErrorsAndWarnings memory actual = - validator.isValidOrder(order, address(seaport)); + ErrorsAndWarnings memory actual = validator.isValidOrder( + order, + address(seaport) + ); - ErrorsAndWarnings memory expected = ErrorsAndWarningsLib.empty() - .addError(ERC721Issue.NotOwner).addError(ERC721Issue.NotApproved) - .addError(GenericIssue.InvalidOrderFormat).addWarning( - TimeIssue.ShortOrder - ).addWarning(StatusIssue.ContractOrder).addWarning( - ConsiderationIssue.ZeroItems - ).addWarning(SignatureIssue.ContractOrder); + ErrorsAndWarnings memory expected = ErrorsAndWarningsLib + .empty() + .addError(ERC721Issue.NotOwner) + .addError(ERC721Issue.NotApproved) + .addError(GenericIssue.InvalidOrderFormat) + .addWarning(TimeIssue.ShortOrder) + .addWarning(StatusIssue.ContractOrder) + .addWarning(ConsiderationIssue.ZeroItems) + .addWarning(SignatureIssue.ContractOrder); assertEq(actual, expected); } @@ -474,17 +563,20 @@ contract SeaportValidatorTestSuite is BaseOrderTest, SeaportValidatorTest { order.parameters.startTime = block.timestamp; order.parameters.endTime = block.timestamp - 1; - ErrorsAndWarnings memory actual = - validator.isValidOrder(order, address(seaport)); - - ErrorsAndWarnings memory expected = ErrorsAndWarningsLib.empty() - .addError(TimeIssue.EndTimeBeforeStartTime).addError( - ERC721Issue.NotOwner - ).addError(ERC721Issue.NotApproved).addError(SignatureIssue.Invalid) - .addError(GenericIssue.InvalidOrderFormat).addWarning( - ConsiderationIssue.ZeroItems + ErrorsAndWarnings memory actual = validator.isValidOrder( + order, + address(seaport) ); + ErrorsAndWarnings memory expected = ErrorsAndWarningsLib + .empty() + .addError(TimeIssue.EndTimeBeforeStartTime) + .addError(ERC721Issue.NotOwner) + .addError(ERC721Issue.NotApproved) + .addError(SignatureIssue.Invalid) + .addError(GenericIssue.InvalidOrderFormat) + .addWarning(ConsiderationIssue.ZeroItems); + assertEq(actual, expected); } @@ -494,15 +586,19 @@ contract SeaportValidatorTestSuite is BaseOrderTest, SeaportValidatorTest { order.parameters.startTime = block.timestamp - 2; order.parameters.endTime = block.timestamp - 1; - ErrorsAndWarnings memory actual = - validator.isValidOrder(order, address(seaport)); + ErrorsAndWarnings memory actual = validator.isValidOrder( + order, + address(seaport) + ); - ErrorsAndWarnings memory expected = ErrorsAndWarningsLib.empty() - .addError(TimeIssue.Expired).addError(ERC721Issue.NotOwner).addError( - ERC721Issue.NotApproved - ).addError(SignatureIssue.Invalid).addError( - GenericIssue.InvalidOrderFormat - ).addWarning(ConsiderationIssue.ZeroItems); + ErrorsAndWarnings memory expected = ErrorsAndWarningsLib + .empty() + .addError(TimeIssue.Expired) + .addError(ERC721Issue.NotOwner) + .addError(ERC721Issue.NotApproved) + .addError(SignatureIssue.Invalid) + .addError(GenericIssue.InvalidOrderFormat) + .addWarning(ConsiderationIssue.ZeroItems); assertEq(actual, expected); } @@ -512,17 +608,20 @@ contract SeaportValidatorTestSuite is BaseOrderTest, SeaportValidatorTest { order.parameters.startTime = block.timestamp; order.parameters.endTime = type(uint256).max; - ErrorsAndWarnings memory actual = - validator.isValidOrder(order, address(seaport)); - - ErrorsAndWarnings memory expected = ErrorsAndWarningsLib.empty() - .addError(ERC721Issue.NotOwner).addError(ERC721Issue.NotApproved) - .addError(SignatureIssue.Invalid).addError( - GenericIssue.InvalidOrderFormat - ).addWarning(TimeIssue.DistantExpiration).addWarning( - ConsiderationIssue.ZeroItems + ErrorsAndWarnings memory actual = validator.isValidOrder( + order, + address(seaport) ); + ErrorsAndWarnings memory expected = ErrorsAndWarningsLib + .empty() + .addError(ERC721Issue.NotOwner) + .addError(ERC721Issue.NotApproved) + .addError(SignatureIssue.Invalid) + .addError(GenericIssue.InvalidOrderFormat) + .addWarning(TimeIssue.DistantExpiration) + .addWarning(ConsiderationIssue.ZeroItems); + assertEq(actual, expected); } @@ -531,14 +630,19 @@ contract SeaportValidatorTestSuite is BaseOrderTest, SeaportValidatorTest { order.parameters.startTime = block.timestamp + 1; order.parameters.endTime = block.timestamp + 2; - ErrorsAndWarnings memory actual = - validator.isValidOrder(order, address(seaport)); + ErrorsAndWarnings memory actual = validator.isValidOrder( + order, + address(seaport) + ); - ErrorsAndWarnings memory expected = ErrorsAndWarningsLib.empty() - .addError(ERC721Issue.NotOwner).addError(ERC721Issue.NotApproved) - .addError(SignatureIssue.Invalid).addError( - GenericIssue.InvalidOrderFormat - ).addWarning(TimeIssue.NotActive).addWarning(TimeIssue.ShortOrder) + ErrorsAndWarnings memory expected = ErrorsAndWarningsLib + .empty() + .addError(ERC721Issue.NotOwner) + .addError(ERC721Issue.NotApproved) + .addError(SignatureIssue.Invalid) + .addError(GenericIssue.InvalidOrderFormat) + .addWarning(TimeIssue.NotActive) + .addWarning(TimeIssue.ShortOrder) .addWarning(ConsiderationIssue.ZeroItems); assertEq(actual, expected); @@ -548,14 +652,18 @@ contract SeaportValidatorTestSuite is BaseOrderTest, SeaportValidatorTest { Order memory order = OrderLib.fromDefault(SINGLE_ERC721); order.parameters.conduitKey = keccak256("invalid conduit key"); - ErrorsAndWarnings memory actual = - validator.isValidOrder(order, address(seaport)); + ErrorsAndWarnings memory actual = validator.isValidOrder( + order, + address(seaport) + ); - ErrorsAndWarnings memory expected = ErrorsAndWarningsLib.empty() - .addError(ConduitIssue.KeyInvalid).addError(SignatureIssue.Invalid) - .addError(GenericIssue.InvalidOrderFormat).addWarning( - TimeIssue.ShortOrder - ).addWarning(ConsiderationIssue.ZeroItems); + ErrorsAndWarnings memory expected = ErrorsAndWarningsLib + .empty() + .addError(ConduitIssue.KeyInvalid) + .addError(SignatureIssue.Invalid) + .addError(GenericIssue.InvalidOrderFormat) + .addWarning(TimeIssue.ShortOrder) + .addWarning(ConsiderationIssue.ZeroItems); assertEq(actual, expected); } @@ -565,17 +673,20 @@ contract SeaportValidatorTestSuite is BaseOrderTest, SeaportValidatorTest { function test_isValidOrder_signatureIssue_invalid() public { Order memory order = OrderLib.fromDefault(SINGLE_ERC721); - ErrorsAndWarnings memory actual = - validator.isValidOrder(order, address(seaport)); - - ErrorsAndWarnings memory expected = ErrorsAndWarningsLib.empty() - .addError(ERC721Issue.NotOwner).addError(ERC721Issue.NotApproved) - .addError(SignatureIssue.Invalid).addError( - GenericIssue.InvalidOrderFormat - ).addWarning(TimeIssue.ShortOrder).addWarning( - ConsiderationIssue.ZeroItems + ErrorsAndWarnings memory actual = validator.isValidOrder( + order, + address(seaport) ); + ErrorsAndWarnings memory expected = ErrorsAndWarningsLib + .empty() + .addError(ERC721Issue.NotOwner) + .addError(ERC721Issue.NotApproved) + .addError(SignatureIssue.Invalid) + .addError(GenericIssue.InvalidOrderFormat) + .addWarning(TimeIssue.ShortOrder) + .addWarning(ConsiderationIssue.ZeroItems); + assertEq(actual, expected); } @@ -583,13 +694,17 @@ contract SeaportValidatorTestSuite is BaseOrderTest, SeaportValidatorTest { Order memory order = OrderLib.fromDefault(SINGLE_ERC721); order.parameters.offer = new OfferItem[](0); - ErrorsAndWarnings memory actual = - validator.isValidOrder(order, address(seaport)); + ErrorsAndWarnings memory actual = validator.isValidOrder( + order, + address(seaport) + ); - ErrorsAndWarnings memory expected = ErrorsAndWarningsLib.empty() - .addError(SignatureIssue.Invalid).addError( - GenericIssue.InvalidOrderFormat - ).addWarning(TimeIssue.ShortOrder).addWarning(OfferIssue.ZeroItems) + ErrorsAndWarnings memory expected = ErrorsAndWarningsLib + .empty() + .addError(SignatureIssue.Invalid) + .addError(GenericIssue.InvalidOrderFormat) + .addWarning(TimeIssue.ShortOrder) + .addWarning(OfferIssue.ZeroItems) .addWarning(ConsiderationIssue.ZeroItems); assertEq(actual, expected); @@ -605,21 +720,27 @@ contract SeaportValidatorTestSuite is BaseOrderTest, SeaportValidatorTest { OfferItem[] memory offer = new OfferItem[](2); offer[0] = order.parameters.offer[0]; - offer[1] = OfferItemLib.empty().withItemType(ItemType.ERC721).withToken( - address(erc721s[0]) - ).withIdentifierOrCriteria(2).withAmount(1); + offer[1] = OfferItemLib + .empty() + .withItemType(ItemType.ERC721) + .withToken(address(erc721s[0])) + .withIdentifierOrCriteria(2) + .withAmount(1); order.parameters.offer = offer; - ErrorsAndWarnings memory actual = - validator.isValidOrder(order, address(seaport)); + ErrorsAndWarnings memory actual = validator.isValidOrder( + order, + address(seaport) + ); - ErrorsAndWarnings memory expected = ErrorsAndWarningsLib.empty() - .addError(SignatureIssue.Invalid).addError( - GenericIssue.InvalidOrderFormat - ).addWarning(TimeIssue.ShortOrder).addWarning( - OfferIssue.MoreThanOneItem - ).addWarning(ConsiderationIssue.ZeroItems); + ErrorsAndWarnings memory expected = ErrorsAndWarningsLib + .empty() + .addError(SignatureIssue.Invalid) + .addError(GenericIssue.InvalidOrderFormat) + .addWarning(TimeIssue.ShortOrder) + .addWarning(OfferIssue.MoreThanOneItem) + .addWarning(ConsiderationIssue.ZeroItems); assertEq(actual, expected); } @@ -629,14 +750,18 @@ contract SeaportValidatorTestSuite is BaseOrderTest, SeaportValidatorTest { order.parameters.offer[0].startAmount = 0; order.parameters.offer[0].endAmount = 0; - ErrorsAndWarnings memory actual = - validator.isValidOrder(order, address(seaport)); + ErrorsAndWarnings memory actual = validator.isValidOrder( + order, + address(seaport) + ); - ErrorsAndWarnings memory expected = ErrorsAndWarningsLib.empty() - .addError(OfferIssue.AmountZero).addError(SignatureIssue.Invalid) - .addError(GenericIssue.InvalidOrderFormat).addWarning( - TimeIssue.ShortOrder - ).addWarning(ConsiderationIssue.ZeroItems); + ErrorsAndWarnings memory expected = ErrorsAndWarningsLib + .empty() + .addError(OfferIssue.AmountZero) + .addError(SignatureIssue.Invalid) + .addError(GenericIssue.InvalidOrderFormat) + .addWarning(TimeIssue.ShortOrder) + .addWarning(ConsiderationIssue.ZeroItems); assertEq(actual, expected); } @@ -647,13 +772,17 @@ contract SeaportValidatorTestSuite is BaseOrderTest, SeaportValidatorTest { vm.deal(address(this), 1 ether); - ErrorsAndWarnings memory actual = - validator.isValidOrder(order, address(seaport)); + ErrorsAndWarnings memory actual = validator.isValidOrder( + order, + address(seaport) + ); - ErrorsAndWarnings memory expected = ErrorsAndWarningsLib.empty() - .addError(SignatureIssue.Invalid).addError( - GenericIssue.InvalidOrderFormat - ).addWarning(TimeIssue.ShortOrder).addWarning(OfferIssue.NativeItem) + ErrorsAndWarnings memory expected = ErrorsAndWarningsLib + .empty() + .addError(SignatureIssue.Invalid) + .addError(GenericIssue.InvalidOrderFormat) + .addWarning(TimeIssue.ShortOrder) + .addWarning(OfferIssue.NativeItem) .addWarning(ConsiderationIssue.ZeroItems); assertEq(actual, expected); @@ -668,23 +797,29 @@ contract SeaportValidatorTestSuite is BaseOrderTest, SeaportValidatorTest { OfferItem[] memory offer = new OfferItem[](2); offer[0] = order.parameters.offer[0]; - offer[1] = OfferItemLib.empty().withItemType(ItemType.ERC721).withToken( - address(erc721s[0]) - ).withIdentifierOrCriteria(1).withAmount(1); + offer[1] = OfferItemLib + .empty() + .withItemType(ItemType.ERC721) + .withToken(address(erc721s[0])) + .withIdentifierOrCriteria(1) + .withAmount(1); order.parameters.offer = offer; - ErrorsAndWarnings memory actual = - validator.isValidOrder(order, address(seaport)); - - ErrorsAndWarnings memory expected = ErrorsAndWarningsLib.empty() - .addError(OfferIssue.DuplicateItem).addError(SignatureIssue.Invalid) - .addError(GenericIssue.InvalidOrderFormat).addWarning( - TimeIssue.ShortOrder - ).addWarning(OfferIssue.MoreThanOneItem).addWarning( - ConsiderationIssue.ZeroItems + ErrorsAndWarnings memory actual = validator.isValidOrder( + order, + address(seaport) ); + ErrorsAndWarnings memory expected = ErrorsAndWarningsLib + .empty() + .addError(OfferIssue.DuplicateItem) + .addError(SignatureIssue.Invalid) + .addError(GenericIssue.InvalidOrderFormat) + .addWarning(TimeIssue.ShortOrder) + .addWarning(OfferIssue.MoreThanOneItem) + .addWarning(ConsiderationIssue.ZeroItems); + assertEq(actual, expected); } @@ -692,21 +827,28 @@ contract SeaportValidatorTestSuite is BaseOrderTest, SeaportValidatorTest { Order memory order = OrderLib.fromDefault(SINGLE_ERC20); OfferItem[] memory offer = new OfferItem[](1); - offer[0] = OfferItemLib.empty().withItemType(ItemType.ERC20).withToken( - address(erc20s[0]) - ).withIdentifierOrCriteria(0).withStartAmount(1e16).withEndAmount(1e25); + offer[0] = OfferItemLib + .empty() + .withItemType(ItemType.ERC20) + .withToken(address(erc20s[0])) + .withIdentifierOrCriteria(0) + .withStartAmount(1e16) + .withEndAmount(1e25); order.parameters.offer = offer; - ErrorsAndWarnings memory actual = - validator.isValidOrder(order, address(seaport)); + ErrorsAndWarnings memory actual = validator.isValidOrder( + order, + address(seaport) + ); - ErrorsAndWarnings memory expected = ErrorsAndWarningsLib.empty() - .addError(OfferIssue.AmountVelocityHigh).addError( - SignatureIssue.Invalid - ).addError(GenericIssue.InvalidOrderFormat).addWarning( - TimeIssue.ShortOrder - ).addWarning(ConsiderationIssue.ZeroItems); + ErrorsAndWarnings memory expected = ErrorsAndWarningsLib + .empty() + .addError(OfferIssue.AmountVelocityHigh) + .addError(SignatureIssue.Invalid) + .addError(GenericIssue.InvalidOrderFormat) + .addWarning(TimeIssue.ShortOrder) + .addWarning(ConsiderationIssue.ZeroItems); assertEq(actual, expected); } @@ -718,22 +860,28 @@ contract SeaportValidatorTestSuite is BaseOrderTest, SeaportValidatorTest { order.parameters.endTime = block.timestamp + 60 * 60 * 24; OfferItem[] memory offer = new OfferItem[](1); - offer[0] = OfferItemLib.empty().withItemType(ItemType.ERC20).withToken( - address(erc20s[0]) - ).withIdentifierOrCriteria(0).withStartAmount(1e10).withEndAmount(1e11); + offer[0] = OfferItemLib + .empty() + .withItemType(ItemType.ERC20) + .withToken(address(erc20s[0])) + .withIdentifierOrCriteria(0) + .withStartAmount(1e10) + .withEndAmount(1e11); order.parameters.offer = offer; - ErrorsAndWarnings memory actual = - validator.isValidOrder(order, address(seaport)); - - ErrorsAndWarnings memory expected = ErrorsAndWarningsLib.empty() - .addError(SignatureIssue.Invalid).addError( - GenericIssue.InvalidOrderFormat - ).addWarning(OfferIssue.AmountStepLarge).addWarning( - ConsiderationIssue.ZeroItems + ErrorsAndWarnings memory actual = validator.isValidOrder( + order, + address(seaport) ); + ErrorsAndWarnings memory expected = ErrorsAndWarningsLib + .empty() + .addError(SignatureIssue.Invalid) + .addError(GenericIssue.InvalidOrderFormat) + .addWarning(OfferIssue.AmountStepLarge) + .addWarning(ConsiderationIssue.ZeroItems); + assertEq(actual, expected); } diff --git a/test/foundry/new/SelfRestricted.t.sol b/test/foundry/new/SelfRestricted.t.sol index e0dacc6..38e36a8 100644 --- a/test/foundry/new/SelfRestricted.t.sol +++ b/test/foundry/new/SelfRestricted.t.sol @@ -190,7 +190,9 @@ contract SelfRestrictedTest is BaseOrderTest { ); } - function setUpSelfFulfillRestricted(ContextOverride memory context) + function setUpSelfFulfillRestricted( + ContextOverride memory context + ) internal returns ( AdvancedOrder[] memory orders, @@ -206,15 +208,20 @@ contract SelfRestrictedTest is BaseOrderTest { uint256 considerAmount = 10; zone = new ValidationOffererZone(considerAmount + 1); - uint256 matchAmount = - context.exactAmount ? considerAmount : considerAmount + 1; + uint256 matchAmount = context.exactAmount + ? considerAmount + : considerAmount + 1; - advancedOrder = - createOpenConsiderErc20(context, offerer1, considerAmount); + advancedOrder = createOpenConsiderErc20( + context, + offerer1, + considerAmount + ); advancedOrder2 = createRestrictedOfferErc20(context, matchAmount); fulfillments = SeaportArrays.Fulfillments( - FulfillmentLib.fromDefault(FF_SF), FulfillmentLib.fromDefault(SF_FF) + FulfillmentLib.fromDefault(FF_SF), + FulfillmentLib.fromDefault(SF_FF) ); orders = SeaportArrays.AdvancedOrders(advancedOrder, advancedOrder2); @@ -231,32 +238,40 @@ contract SelfRestrictedTest is BaseOrderTest { // consider: 10 ERC20 OfferItem[] memory offer = SeaportArrays.OfferItems( - OfferItemLib.fromDefault(SINGLE_ERC721).withToken( - address(erc721s[0]) - ).withIdentifierOrCriteria(1) + OfferItemLib + .fromDefault(SINGLE_ERC721) + .withToken(address(erc721s[0])) + .withIdentifierOrCriteria(1) ); ConsiderationItem[] memory consideration = SeaportArrays .ConsiderationItems( - ConsiderationItemLib.empty().withItemType(ItemType.ERC20).withToken( - address(erc20s[0]) - ).withRecipient(account.addr).withStartAmount(considerAmount) - .withEndAmount(considerAmount) - ); - - OrderComponents memory components = OrderComponentsLib.fromDefault( - STANDARD - ).withOfferer(account.addr).withOffer(offer).withConsideration( - consideration - ).withCounter(context.seaport.getCounter(account.addr)).withConduitKey( - context.conduitKey - ); + ConsiderationItemLib + .empty() + .withItemType(ItemType.ERC20) + .withToken(address(erc20s[0])) + .withRecipient(account.addr) + .withStartAmount(considerAmount) + .withEndAmount(considerAmount) + ); + + OrderComponents memory components = OrderComponentsLib + .fromDefault(STANDARD) + .withOfferer(account.addr) + .withOffer(offer) + .withConsideration(consideration) + .withCounter(context.seaport.getCounter(account.addr)) + .withConduitKey(context.conduitKey); bytes32 orderHash = seaport.getOrderHash(components); - bytes memory signature = - signOrder(context.seaport, account.key, orderHash); - advancedOrder = AdvancedOrderLib.fromDefault(FULL).withParameters( - components.toOrderParameters() - ).withSignature(signature); + bytes memory signature = signOrder( + context.seaport, + account.key, + orderHash + ); + advancedOrder = AdvancedOrderLib + .fromDefault(FULL) + .withParameters(components.toOrderParameters()) + .withSignature(signature); } function createRestrictedOfferErc20( @@ -264,31 +279,42 @@ contract SelfRestrictedTest is BaseOrderTest { uint256 amount ) internal view returns (AdvancedOrder memory advancedOrder) { OfferItem[] memory offer = SeaportArrays.OfferItems( - OfferItemLib.empty().withItemType(ItemType.ERC20).withToken( - address(erc20s[0]) - ).withStartAmount(amount).withEndAmount(amount) + OfferItemLib + .empty() + .withItemType(ItemType.ERC20) + .withToken(address(erc20s[0])) + .withStartAmount(amount) + .withEndAmount(amount) ); ConsiderationItem[] memory consideration = SeaportArrays .ConsiderationItems( - ConsiderationItemLib.fromDefault(SINGLE_ERC721).withToken( - address(erc721s[0]) - ).withRecipient(context.offerer.addr).withIdentifierOrCriteria(1) - ); + ConsiderationItemLib + .fromDefault(SINGLE_ERC721) + .withToken(address(erc721s[0])) + .withRecipient(context.offerer.addr) + .withIdentifierOrCriteria(1) + ); Account memory _offerer = context.offerer; - OrderComponents memory components = OrderComponentsLib.fromDefault( - STANDARD - ).withOfferer(_offerer.addr).withOffer(offer).withConsideration( - consideration - ).withCounter(context.seaport.getCounter(_offerer.addr)).withConduitKey( - context.conduitKey - ).withOrderType(OrderType.FULL_RESTRICTED).withZone(address(zone)); + OrderComponents memory components = OrderComponentsLib + .fromDefault(STANDARD) + .withOfferer(_offerer.addr) + .withOffer(offer) + .withConsideration(consideration) + .withCounter(context.seaport.getCounter(_offerer.addr)) + .withConduitKey(context.conduitKey) + .withOrderType(OrderType.FULL_RESTRICTED) + .withZone(address(zone)); bytes32 orderHash = seaport.getOrderHash(components); - bytes memory signature = - signOrder(context.seaport, _offerer.key, orderHash); - advancedOrder = AdvancedOrderLib.fromDefault(FULL).withParameters( - components.toOrderParameters() - ).withSignature(signature); + bytes memory signature = signOrder( + context.seaport, + _offerer.key, + orderHash + ); + advancedOrder = AdvancedOrderLib + .fromDefault(FULL) + .withParameters(components.toOrderParameters()) + .withSignature(signature); } function setUpSelfFulfillRestrictedMultiOffer( @@ -309,27 +335,33 @@ contract SelfRestrictedTest is BaseOrderTest { uint256 considerAmount = 10; zone = new ValidationOffererZone(considerAmount + 1); - uint256 matchAmount = - context.exactAmount ? considerAmount : considerAmount - 1; + uint256 matchAmount = context.exactAmount + ? considerAmount + : considerAmount - 1; - advancedOrder = - createOpenConsiderErc20(context, offerer1, considerAmount); + advancedOrder = createOpenConsiderErc20( + context, + offerer1, + considerAmount + ); advancedOrder2 = createRestrictedOffersErc20(context, matchAmount); fulfillments = SeaportArrays.Fulfillments( FulfillmentLib.fromDefault(FF_SF), Fulfillment({ offerComponents: SeaportArrays.FulfillmentComponents( - FulfillmentComponentLib.empty().withOrderIndex(1).withItemIndex( - 0 - ), - FulfillmentComponentLib.empty().withOrderIndex(1).withItemIndex( - 1 - ) - ), + FulfillmentComponentLib + .empty() + .withOrderIndex(1) + .withItemIndex(0), + FulfillmentComponentLib + .empty() + .withOrderIndex(1) + .withItemIndex(1) + ), considerationComponents: SeaportArrays.FulfillmentComponents( FulfillmentComponentLib.empty() - ) + ) }) ); orders = SeaportArrays.AdvancedOrders(advancedOrder, advancedOrder2); @@ -337,17 +369,17 @@ contract SelfRestrictedTest is BaseOrderTest { return (orders, resolvers, fulfillments); } - function execMultiOffer(ContextOverride memory context) - external - stateless - { + function execMultiOffer(ContextOverride memory context) external stateless { ( AdvancedOrder[] memory orders, CriteriaResolver[] memory resolvers, Fulfillment[] memory fulfillments ) = setUpSelfFulfillRestrictedMultiOffer(context); context.seaport.matchAdvancedOrders( - orders, resolvers, fulfillments, address(0x1234) + orders, + resolvers, + fulfillments, + address(0x1234) ); } @@ -356,40 +388,53 @@ contract SelfRestrictedTest is BaseOrderTest { uint256 amountLessOne ) internal view returns (AdvancedOrder memory advancedOrder) { OfferItem[] memory offer = SeaportArrays.OfferItems( - OfferItemLib.empty().withItemType(ItemType.ERC20).withToken( - address(erc20s[0]) - ).withStartAmount(amountLessOne).withEndAmount(amountLessOne), - OfferItemLib.empty().withItemType(ItemType.ERC20).withToken( - address(erc20s[0]) - ).withStartAmount(amountLessOne).withEndAmount(amountLessOne) + OfferItemLib + .empty() + .withItemType(ItemType.ERC20) + .withToken(address(erc20s[0])) + .withStartAmount(amountLessOne) + .withEndAmount(amountLessOne), + OfferItemLib + .empty() + .withItemType(ItemType.ERC20) + .withToken(address(erc20s[0])) + .withStartAmount(amountLessOne) + .withEndAmount(amountLessOne) ); ConsiderationItem[] memory consideration = SeaportArrays .ConsiderationItems( - ConsiderationItemLib.fromDefault(SINGLE_ERC721).withToken( - address(erc721s[0]) - ).withRecipient(context.offerer.addr).withIdentifierOrCriteria(1) - ); + ConsiderationItemLib + .fromDefault(SINGLE_ERC721) + .withToken(address(erc721s[0])) + .withRecipient(context.offerer.addr) + .withIdentifierOrCriteria(1) + ); Account memory _offerer = context.offerer; - OrderComponents memory components = OrderComponentsLib.fromDefault( - STANDARD - ).withOfferer(_offerer.addr).withOffer(offer).withConsideration( - consideration - ).withCounter(context.seaport.getCounter(_offerer.addr)).withConduitKey( - context.conduitKey - ).withOrderType(OrderType.FULL_RESTRICTED).withZone(address(zone)); + OrderComponents memory components = OrderComponentsLib + .fromDefault(STANDARD) + .withOfferer(_offerer.addr) + .withOffer(offer) + .withConsideration(consideration) + .withCounter(context.seaport.getCounter(_offerer.addr)) + .withConduitKey(context.conduitKey) + .withOrderType(OrderType.FULL_RESTRICTED) + .withZone(address(zone)); bytes32 orderHash = seaport.getOrderHash(components); - bytes memory signature = - signOrder(context.seaport, _offerer.key, orderHash); - advancedOrder = AdvancedOrderLib.fromDefault(FULL).withParameters( - components.toOrderParameters() - ).withSignature(signature); + bytes memory signature = signOrder( + context.seaport, + _offerer.key, + orderHash + ); + advancedOrder = AdvancedOrderLib + .fromDefault(FULL) + .withParameters(components.toOrderParameters()) + .withSignature(signature); } - function execSelfFulfillRestricted(ContextOverride memory context) - external - stateless - { + function execSelfFulfillRestricted( + ContextOverride memory context + ) external stateless { ( AdvancedOrder[] memory orders, CriteriaResolver[] memory resolvers, @@ -397,7 +442,10 @@ contract SelfRestrictedTest is BaseOrderTest { ) = setUpSelfFulfillRestricted(context); context.seaport.matchAdvancedOrders( - orders, resolvers, fulfillments, address(0x1234) + orders, + resolvers, + fulfillments, + address(0x1234) ); } } diff --git a/test/foundry/new/SelfRestrictedContractOfferer.t.sol b/test/foundry/new/SelfRestrictedContractOfferer.t.sol index ee87ef8..5e0ca97 100644 --- a/test/foundry/new/SelfRestrictedContractOfferer.t.sol +++ b/test/foundry/new/SelfRestrictedContractOfferer.t.sol @@ -145,7 +145,9 @@ contract SelfRestrictedContractOffererTest is BaseOrderTest { ); } - function setUpSelfFulfillRestricted(ContextOverride memory context) + function setUpSelfFulfillRestricted( + ContextOverride memory context + ) internal returns ( AdvancedOrder[] memory orders, @@ -168,29 +170,36 @@ contract SelfRestrictedContractOffererTest is BaseOrderTest { allocateTokensAndApprovals(address(offerer), type(uint128).max); - uint256 matchAmount = - context.exactAmount ? considerAmount : considerAmount + 1; + uint256 matchAmount = context.exactAmount + ? considerAmount + : considerAmount + 1; // create the first order // offer: 1 ERC721 // consider: 10 ERC20 { consideration = SeaportArrays.ConsiderationItems( - ConsiderationItemLib.fromDefault(SINGLE_ERC721).withToken( - address(erc721s[0]) - ).withIdentifierOrCriteria(1).withRecipient(address(offerer)) + ConsiderationItemLib + .fromDefault(SINGLE_ERC721) + .withToken(address(erc721s[0])) + .withIdentifierOrCriteria(1) + .withRecipient(address(offerer)) ); offer = SeaportArrays.OfferItems( - OfferItemLib.empty().withItemType(ItemType.ERC20).withToken( - address(erc20s[0]) - ).withStartAmount(matchAmount).withEndAmount(matchAmount) + OfferItemLib + .empty() + .withItemType(ItemType.ERC20) + .withToken(address(erc20s[0])) + .withStartAmount(matchAmount) + .withEndAmount(matchAmount) ); - components = OrderComponentsLib.fromDefault(STANDARD).withOfferer( - address(offerer) - ).withOffer(offer).withConsideration(consideration).withOrderType( - OrderType.CONTRACT - ); + components = OrderComponentsLib + .fromDefault(STANDARD) + .withOfferer(address(offerer)) + .withOffer(offer) + .withConsideration(consideration) + .withOrderType(OrderType.CONTRACT); // orderHash = seaport.getOrderHash(components); // signature = signOrder(context.seaport, offerer1.key, orderHash); @@ -204,20 +213,26 @@ contract SelfRestrictedContractOffererTest is BaseOrderTest { // consider: 1 ERC721 { consideration = SeaportArrays.ConsiderationItems( - ConsiderationItemLib.empty().withItemType(ItemType.ERC20) - .withToken(address(erc20s[0])).withStartAmount(considerAmount) - .withEndAmount(considerAmount).withRecipient(address(offerer)) + ConsiderationItemLib + .empty() + .withItemType(ItemType.ERC20) + .withToken(address(erc20s[0])) + .withStartAmount(considerAmount) + .withEndAmount(considerAmount) + .withRecipient(address(offerer)) ); offer = SeaportArrays.OfferItems( - OfferItemLib.fromDefault(SINGLE_ERC721).withToken( - address(erc721s[0]) - ).withIdentifierOrCriteria(1) + OfferItemLib + .fromDefault(SINGLE_ERC721) + .withToken(address(erc721s[0])) + .withIdentifierOrCriteria(1) ); - components = components.copy().withOffer(offer).withConsideration( - consideration - ).withOrderType(OrderType.FULL_OPEN).withCounter( - context.seaport.getCounter(address(offerer)) - ); //.withZone(address(zone)) + components = components + .copy() + .withOffer(offer) + .withConsideration(consideration) + .withOrderType(OrderType.FULL_OPEN) + .withCounter(context.seaport.getCounter(address(offerer))); //.withZone(address(zone)) // .withConduitKey(bytes32(0)); orderHash = seaport.getOrderHash(components); @@ -230,23 +245,24 @@ contract SelfRestrictedContractOffererTest is BaseOrderTest { vm.prank(address(offerer)); context.seaport.validate(SeaportArrays.Orders(order)); - advancedOrder2 = AdvancedOrderLib.fromDefault(FULL).withParameters( - components.toOrderParameters() - ).withSignature(signature); + advancedOrder2 = AdvancedOrderLib + .fromDefault(FULL) + .withParameters(components.toOrderParameters()) + .withSignature(signature); } fulfillments = SeaportArrays.Fulfillments( - FulfillmentLib.fromDefault(FF_SF), FulfillmentLib.fromDefault(SF_FF) + FulfillmentLib.fromDefault(FF_SF), + FulfillmentLib.fromDefault(SF_FF) ); orders = SeaportArrays.AdvancedOrders(advancedOrder2, advancedOrder); return (orders, resolvers, fulfillments); } - function execSelfFulfillRestricted(ContextOverride memory context) - external - stateless - { + function execSelfFulfillRestricted( + ContextOverride memory context + ) external stateless { ( AdvancedOrder[] memory orders, CriteriaResolver[] memory resolvers, @@ -254,7 +270,10 @@ contract SelfRestrictedContractOffererTest is BaseOrderTest { ) = setUpSelfFulfillRestricted(context); context.seaport.matchAdvancedOrders( - orders, resolvers, fulfillments, address(this) + orders, + resolvers, + fulfillments, + address(this) ); } } diff --git a/test/foundry/new/helpers/BaseSeaportTest.sol b/test/foundry/new/helpers/BaseSeaportTest.sol index 6b6bc4c..c7cbbde 100644 --- a/test/foundry/new/helpers/BaseSeaportTest.sol +++ b/test/foundry/new/helpers/BaseSeaportTest.sol @@ -5,22 +5,27 @@ import { stdStorage, StdStorage } from "forge-std/Test.sol"; import { DifferentialTest } from "./DifferentialTest.sol"; -import { ConduitControllerInterface } from - "seaport-sol/src/ConduitControllerInterface.sol"; +import { + ConduitControllerInterface +} from "seaport-sol/src/ConduitControllerInterface.sol"; -import { ConduitController } from - "seaport-core/src/conduit/ConduitController.sol"; +import { + ConduitController +} from "seaport-core/src/conduit/ConduitController.sol"; -import { ReferenceConduitController } from - "../../../../reference/conduit/ReferenceConduitController.sol"; +import { + ReferenceConduitController +} from "../../../../reference/conduit/ReferenceConduitController.sol"; -import { ConsiderationInterface } from - "seaport-types/src/interfaces/ConsiderationInterface.sol"; +import { + ConsiderationInterface +} from "seaport-types/src/interfaces/ConsiderationInterface.sol"; import { Consideration } from "seaport-core/src/lib/Consideration.sol"; -import { ReferenceConsideration } from - "../../../../reference/ReferenceConsideration.sol"; +import { + ReferenceConsideration +} from "../../../../reference/ReferenceConsideration.sol"; import { Conduit } from "seaport-core/src/conduit/Conduit.sol"; @@ -40,11 +45,10 @@ contract BaseSeaportTest is DifferentialTest { ConsiderationInterface referenceSeaport; ConsiderationInterface seaport; - function stringEq(string memory a, string memory b) - internal - pure - returns (bool) - { + function stringEq( + string memory a, + string memory b + ) internal pure returns (bool) { return keccak256(abi.encodePacked(a)) == keccak256(abi.encodePacked(b)); } @@ -72,7 +76,8 @@ contract BaseSeaportTest is DifferentialTest { setLabel(address(seaport), "seaport"); setLabel(address(conduit), "conduit"); setLabel( - address(referenceConduitController), "referenceConduitController" + address(referenceConduitController), + "referenceConduitController" ); setLabel(address(referenceSeaport), "referenceSeaport"); setLabel(address(referenceConduit), "referenceConduit"); @@ -129,10 +134,13 @@ contract BaseSeaportTest is DifferentialTest { seaport = new Consideration(address(conduitController)); } //create conduit, update channel - conduit = - Conduit(conduitController.createConduit(conduitKey, address(this))); + conduit = Conduit( + conduitController.createConduit(conduitKey, address(this)) + ); conduitController.updateChannel( - address(conduit), address(seaport), true + address(conduit), + address(seaport), + true ); } @@ -164,7 +172,9 @@ contract BaseSeaportTest is DifferentialTest { referenceConduitController.createConduit(conduitKey, address(this)) ); referenceConduitController.updateChannel( - address(referenceConduit), address(referenceSeaport), true + address(referenceConduit), + address(referenceSeaport), + true ); } @@ -173,8 +183,11 @@ contract BaseSeaportTest is DifferentialTest { uint256 _pkOfSigner, bytes32 _orderHash ) internal view returns (bytes memory) { - (bytes32 r, bytes32 s, uint8 v) = - getSignatureComponents(_consideration, _pkOfSigner, _orderHash); + (bytes32 r, bytes32 s, uint8 v) = getSignatureComponents( + _consideration, + _pkOfSigner, + _orderHash + ); return abi.encodePacked(r, s, v); } @@ -183,7 +196,7 @@ contract BaseSeaportTest is DifferentialTest { uint256 _pkOfSigner, bytes32 _orderHash ) internal view returns (bytes32, bytes32, uint8) { - (, bytes32 domainSeparator,) = _consideration.information(); + (, bytes32 domainSeparator, ) = _consideration.information(); (uint8 v, bytes32 r, bytes32 s) = vm.sign( _pkOfSigner, keccak256( diff --git a/test/foundry/new/helpers/CriteriaResolverHelper.sol b/test/foundry/new/helpers/CriteriaResolverHelper.sol index 09e9c11..0fd3582 100644 --- a/test/foundry/new/helpers/CriteriaResolverHelper.sol +++ b/test/foundry/new/helpers/CriteriaResolverHelper.sol @@ -32,32 +32,29 @@ contract CriteriaResolverHelper { uint256 identifier; } - mapping(uint256 => CriteriaMetadata) internal - _resolvableIdentifierForGivenCriteria; + mapping(uint256 => CriteriaMetadata) + internal _resolvableIdentifierForGivenCriteria; - mapping(bytes32 => WildcardIdentifier) internal - _wildcardIdentifierForGivenItemHash; + mapping(bytes32 => WildcardIdentifier) + internal _wildcardIdentifierForGivenItemHash; constructor(uint256 maxLeaves) { MAX_LEAVES = maxLeaves; MERKLE = new Merkle(); } - function resolvableIdentifierForGivenCriteria(uint256 criteria) - public - view - returns (CriteriaMetadata memory) - { + function resolvableIdentifierForGivenCriteria( + uint256 criteria + ) public view returns (CriteriaMetadata memory) { return _resolvableIdentifierForGivenCriteria[criteria]; } - function wildcardIdentifierForGivenItemHash(bytes32 itemHash) - public - view - returns (uint256) - { - WildcardIdentifier memory id = - _wildcardIdentifierForGivenItemHash[itemHash]; + function wildcardIdentifierForGivenItemHash( + bytes32 itemHash + ) public view returns (uint256) { + WildcardIdentifier memory id = _wildcardIdentifierForGivenItemHash[ + itemHash + ]; if (!id.set) { revert( @@ -68,19 +65,15 @@ contract CriteriaResolverHelper { return id.identifier; } - function deriveCriteriaResolvers(AdvancedOrder[] memory orders) - public - view - returns (CriteriaResolver[] memory criteriaResolvers) - { + function deriveCriteriaResolvers( + AdvancedOrder[] memory orders + ) public view returns (CriteriaResolver[] memory criteriaResolvers) { uint256 maxLength; for (uint256 i; i < orders.length; i++) { AdvancedOrder memory order = orders[i]; - maxLength += ( - order.parameters.offer.length - + order.parameters.consideration.length - ); + maxLength += (order.parameters.offer.length + + order.parameters.consideration.length); } criteriaResolvers = new CriteriaResolver[](maxLength); uint256 index; @@ -91,15 +84,18 @@ contract CriteriaResolverHelper { for (uint256 j; j < order.parameters.offer.length; j++) { OfferItem memory offerItem = order.parameters.offer[j]; if ( - offerItem.itemType == ItemType.ERC721_WITH_CRITERIA - || offerItem.itemType == ItemType.ERC1155_WITH_CRITERIA + offerItem.itemType == ItemType.ERC721_WITH_CRITERIA || + offerItem.itemType == ItemType.ERC1155_WITH_CRITERIA ) { if (offerItem.identifierOrCriteria == 0) { - bytes32 itemHash = - keccak256(abi.encodePacked(i, j, Side.OFFER)); + bytes32 itemHash = keccak256( + abi.encodePacked(i, j, Side.OFFER) + ); - WildcardIdentifier memory id = - _wildcardIdentifierForGivenItemHash[itemHash]; + WildcardIdentifier + memory id = _wildcardIdentifierForGivenItemHash[ + itemHash + ]; if (!id.set) { revert( "CriteriaResolverHelper: no wildcard identifier located for offer item" @@ -114,9 +110,10 @@ contract CriteriaResolverHelper { criteriaProof: new bytes32[](0) }); } else { - CriteriaMetadata memory criteriaMetadata = - _resolvableIdentifierForGivenCriteria[offerItem - .identifierOrCriteria]; + CriteriaMetadata + memory criteriaMetadata = _resolvableIdentifierForGivenCriteria[ + offerItem.identifierOrCriteria + ]; // Store the criteria resolver in the mapping criteriaResolvers[index] = CriteriaResolver({ @@ -132,20 +129,23 @@ contract CriteriaResolverHelper { } for (uint256 j; j < order.parameters.consideration.length; j++) { - ConsiderationItem memory considerationItem = - order.parameters.consideration[j]; + ConsiderationItem memory considerationItem = order + .parameters + .consideration[j]; if ( - considerationItem.itemType == ItemType.ERC721_WITH_CRITERIA - || considerationItem.itemType - == ItemType.ERC1155_WITH_CRITERIA + considerationItem.itemType == + ItemType.ERC721_WITH_CRITERIA || + considerationItem.itemType == ItemType.ERC1155_WITH_CRITERIA ) { if (considerationItem.identifierOrCriteria == 0) { bytes32 itemHash = keccak256( abi.encodePacked(i, j, Side.CONSIDERATION) ); - WildcardIdentifier memory id = - _wildcardIdentifierForGivenItemHash[itemHash]; + WildcardIdentifier + memory id = _wildcardIdentifierForGivenItemHash[ + itemHash + ]; if (!id.set) { revert( "CriteriaResolverHelper: no wildcard identifier located for consideration item" @@ -160,9 +160,10 @@ contract CriteriaResolverHelper { criteriaProof: new bytes32[](0) }); } else { - CriteriaMetadata memory criteriaMetadata = - _resolvableIdentifierForGivenCriteria[considerationItem - .identifierOrCriteria]; + CriteriaMetadata + memory criteriaMetadata = _resolvableIdentifierForGivenCriteria[ + considerationItem.identifierOrCriteria + ]; // Store the criteria resolver in the mapping criteriaResolvers[index] = CriteriaResolver({ @@ -206,8 +207,10 @@ contract CriteriaResolverHelper { // TODO: Base Murky impl is very memory-inefficient (O(n^2)) uint256 resolvedIdentifier = selectedIdentifier; criteria = uint256(MERKLE.getRoot(leaves)); - bytes32[] memory proof = - MERKLE.getProof(leaves, selectedIdentifierIndex); + bytes32[] memory proof = MERKLE.getProof( + leaves, + selectedIdentifierIndex + ); _resolvableIdentifierForGivenCriteria[criteria] = CriteriaMetadata({ resolvedIdentifier: resolvedIdentifier, @@ -224,14 +227,18 @@ contract CriteriaResolverHelper { ) public returns (uint256 criteria) { criteria = (desiredId == type(uint256).max) ? prng.next() : desiredId; - bytes32 itemHash = - keccak256(abi.encodePacked(orderIndex, itemIndex, side)); + bytes32 itemHash = keccak256( + abi.encodePacked(orderIndex, itemIndex, side) + ); - WildcardIdentifier storage id = - (_wildcardIdentifierForGivenItemHash[itemHash]); + WildcardIdentifier storage id = ( + _wildcardIdentifierForGivenItemHash[itemHash] + ); if (id.set) { - revert("CriteriaResolverHelper: wildcard already set for this item"); + revert( + "CriteriaResolverHelper: wildcard already set for this item" + ); } id.set = true; @@ -245,22 +252,26 @@ contract CriteriaResolverHelper { uint256 originalLength ) public { for (uint256 i = originalLength; i > insertionIndex; --i) { - bytes32 itemHash = - keccak256(abi.encodePacked(orderIndex, i - 1, side)); + bytes32 itemHash = keccak256( + abi.encodePacked(orderIndex, i - 1, side) + ); - WildcardIdentifier storage id = - (_wildcardIdentifierForGivenItemHash[itemHash]); + WildcardIdentifier storage id = ( + _wildcardIdentifierForGivenItemHash[itemHash] + ); if (id.set) { uint256 identifier = id.identifier; id.set = false; id.identifier = 0; - bytes32 shiftedItemHash = - keccak256(abi.encodePacked(orderIndex, i, side)); + bytes32 shiftedItemHash = keccak256( + abi.encodePacked(orderIndex, i, side) + ); - WildcardIdentifier storage shiftedId = - (_wildcardIdentifierForGivenItemHash[shiftedItemHash]); + WildcardIdentifier storage shiftedId = ( + _wildcardIdentifierForGivenItemHash[shiftedItemHash] + ); if (shiftedId.set) { revert("CriteriaResolverHelper: shifting into a set item"); @@ -277,17 +288,15 @@ contract CriteriaResolverHelper { * leaves in a Merkle tree * @param prng PRNG to use to generate the identifiers */ - function generateIdentifiers(LibPRNG.PRNG memory prng) - public - view - returns (uint256[] memory identifiers) - { + function generateIdentifiers( + LibPRNG.PRNG memory prng + ) public view returns (uint256[] memory identifiers) { uint256 numIdentifiers = (prng.next() % (2 ** MAX_LEAVES)); if (numIdentifiers <= 1) { numIdentifiers = 2; } identifiers = new uint256[](numIdentifiers); - for (uint256 i = 0; i < numIdentifiers;) { + for (uint256 i = 0; i < numIdentifiers; ) { identifiers[i] = prng.next(); unchecked { ++i; @@ -304,15 +313,13 @@ contract CriteriaResolverHelper { * Merkle tree * @param identifiers Identifiers to hash */ - function hashIdentifiersToLeaves(uint256[] memory identifiers) - public - pure - returns (bytes32[] memory leaves) - { + function hashIdentifiersToLeaves( + uint256[] memory identifiers + ) public pure returns (bytes32[] memory leaves) { assembly { leaves := identifiers } - for (uint256 i = 0; i < identifiers.length;) { + for (uint256 i = 0; i < identifiers.length; ) { bytes32 identifier = leaves[i]; assembly { mstore(0x0, identifier) diff --git a/test/foundry/new/helpers/DebugUtil.sol b/test/foundry/new/helpers/DebugUtil.sol index 7ab33bf..77bc392 100644 --- a/test/foundry/new/helpers/DebugUtil.sol +++ b/test/foundry/new/helpers/DebugUtil.sol @@ -14,7 +14,8 @@ import { console2 } from "forge-std/console2.sol"; import { ArrayHelpers, MemoryPointer } from "seaport/helpers/ArrayHelpers.sol"; import { - OrderStatusEnum, UnavailableReason + OrderStatusEnum, + UnavailableReason } from "seaport-sol/src/SpaceEnums.sol"; import { ForgeEventsLib } from "./event-utils/ForgeEventsLib.sol"; @@ -84,7 +85,9 @@ function dumpContext( jsonOut = vm.serializeString("root", "_action", context.actionName()); if (outputSelection.seaport) { jsonOut = Searializer.tojsonAddress( - "root", "seaport", address(context.seaport) + "root", + "seaport", + address(context.seaport) ); } // if (outputSelection.conduitController) { @@ -96,22 +99,30 @@ function dumpContext( // } if (outputSelection.caller) { jsonOut = Searializer.tojsonAddress( - "root", "caller", context.executionState.caller + "root", + "caller", + context.executionState.caller ); } if (outputSelection.recipient) { jsonOut = Searializer.tojsonAddress( - "root", "recipient", context.executionState.recipient + "root", + "recipient", + context.executionState.recipient ); } if (outputSelection.callValue) { jsonOut = Searializer.tojsonUint256( - "root", "callValue", context.executionState.value + "root", + "callValue", + context.executionState.value ); } if (outputSelection.maximumFulfilled) { jsonOut = Searializer.tojsonUint256( - "root", "maximumFulfilled", context.executionState.maximumFulfilled + "root", + "maximumFulfilled", + context.executionState.maximumFulfilled ); } // if (outputSelection.fuzzParams) { @@ -119,7 +130,9 @@ function dumpContext( // } if (outputSelection.orders) { jsonOut = Searializer.tojsonDynArrayAdvancedOrder( - "root", "orders", context.executionState.orders + "root", + "orders", + context.executionState.orders ); } if (outputSelection.orderHashes) { @@ -127,18 +140,25 @@ function dumpContext( context.executionState.orderDetails.length ); - for (uint256 i = 0; i < context.executionState.orderDetails.length; i++) - { + for ( + uint256 i = 0; + i < context.executionState.orderDetails.length; + i++ + ) { orderHashes[i] = context.executionState.orderDetails[i].orderHash; } jsonOut = Searializer.tojsonDynArrayBytes32( - "root", "orderHashes", orderHashes + "root", + "orderHashes", + orderHashes ); } if (outputSelection.previewedOrders) { jsonOut = Searializer.tojsonDynArrayAdvancedOrder( - "root", "previewedOrders", context.executionState.previewedOrders + "root", + "previewedOrders", + context.executionState.previewedOrders ); } // if (outputSelection.counter) { @@ -282,14 +302,20 @@ function dumpContext( context.executionState.orderDetails.length ); - for (uint256 i = 0; i < context.executionState.orderDetails.length; i++) - { - expectedAvailableOrders[i] = context.executionState.orderDetails[i] - .unavailableReason == UnavailableReason.AVAILABLE; + for ( + uint256 i = 0; + i < context.executionState.orderDetails.length; + i++ + ) { + expectedAvailableOrders[i] = + context.executionState.orderDetails[i].unavailableReason == + UnavailableReason.AVAILABLE; } jsonOut = Searializer.tojsonDynArrayBool( - "root", "expectedAvailableOrders", expectedAvailableOrders + "root", + "expectedAvailableOrders", + expectedAvailableOrders ); } // =====================================================================// @@ -303,8 +329,10 @@ function dumpContext( // ); // } if (outputSelection.actualEvents) { - jsonOut = - context.actualEvents.serializeTransferLogs("root", "actualEvents"); + jsonOut = context.actualEvents.serializeTransferLogs( + "root", + "actualEvents" + ); } if (outputSelection.expectedEvents) { jsonOut = context @@ -330,7 +358,9 @@ function dumpContext( } if (outputSelection.erc20ExpectedBalances) { jsonOut = Searializer.tojsonDynArrayERC20TokenDump( - "root", "erc20ExpectedBalances", balanceChecker.dumpERC20Balances() + "root", + "erc20ExpectedBalances", + balanceChecker.dumpERC20Balances() ); } // if (outputSelection.erc721ExpectedBalances) { @@ -349,7 +379,9 @@ function dumpContext( // } if (outputSelection.validationErrors) { jsonOut = Searializer.tojsonDynArrayValidationErrorsAndWarnings( - "root", "validationErrors", context.executionState.validationErrors + "root", + "validationErrors", + context.executionState.validationErrors ); } vm.writeJson(jsonOut, "./fuzz_debug.json"); @@ -361,8 +393,9 @@ function dumpContext( function pureDumpContext() pure returns ( - function(FuzzTestContext memory, ContextOutputSelection memory) internal pure - pureFn + function(FuzzTestContext memory, ContextOutputSelection memory) + internal + pure pureFn ) { function(FuzzTestContext memory, ContextOutputSelection memory) @@ -382,7 +415,7 @@ function cast(OrderStatusEnum[] memory a) pure returns (uint256[] memory b) { * @dev Serialize and write transfer related fields from FuzzTestContext to a * `fuzz_debug.json` file. */ -function dumpTransfers(FuzzTestContext memory context) pure { +function dumpTransfers(FuzzTestContext memory context) view { ContextOutputSelection memory selection; selection.allExpectedExecutions = true; selection.expectedEvents = true; @@ -395,7 +428,7 @@ function dumpTransfers(FuzzTestContext memory context) pure { * @dev Serialize and write execution related fields from FuzzTestContext to a * `fuzz_debug.json` file. */ -function dumpExecutions(FuzzTestContext memory context) pure { +function dumpExecutions(FuzzTestContext memory context) view { ContextOutputSelection memory selection; selection.orders = true; selection.orderHashes = true; @@ -421,22 +454,23 @@ function dumpExecutions(FuzzTestContext memory context) pure { library ExecutionFilterCast { using ExecutionFilterCast for *; - function filter(Execution[] memory executions, ItemType itemType) - internal - pure - returns (Execution[] memory) - { + function filter( + Execution[] memory executions, + ItemType itemType + ) internal pure returns (Execution[] memory) { if (uint256(itemType) > 3) return executions; - return ArrayHelpers.filterWithArg.asExecutionsFilterByItemType()( - executions, ExecutionFilterCast.isItemType, itemType - ); + return + ArrayHelpers.filterWithArg.asExecutionsFilterByItemType()( + executions, + ExecutionFilterCast.isItemType, + itemType + ); } - function isItemType(Execution memory execution, ItemType itemType) - internal - pure - returns (bool) - { + function isItemType( + Execution memory execution, + ItemType itemType + ) internal pure returns (bool) { return execution.item.itemType == itemType; } @@ -450,8 +484,14 @@ library ExecutionFilterCast { internal pure returns ( - function(Execution[] memory, function(Execution memory, ItemType) internal pure returns (bool), ItemType ) internal pure returns (Execution[] memory) - fnOut + function( + Execution[] memory, + function(Execution memory, ItemType) + internal + pure + returns (bool), + ItemType + ) internal pure returns (Execution[] memory) fnOut ) { assembly { diff --git a/test/foundry/new/helpers/DifferentialTest.sol b/test/foundry/new/helpers/DifferentialTest.sol index 6403e2d..38e5616 100644 --- a/test/foundry/new/helpers/DifferentialTest.sol +++ b/test/foundry/new/helpers/DifferentialTest.sol @@ -12,9 +12,10 @@ contract DifferentialTest is Test { bytes32 HEVM_FAILED_SLOT = bytes32("failed"); // hash of the bytes surfaced by `revert RevertWithFailureStatus(false)` - bytes32 PASSING_HASH = keccak256( - abi.encodeWithSelector(RevertWithFailureStatus.selector, false) - ); + bytes32 PASSING_HASH = + keccak256( + abi.encodeWithSelector(RevertWithFailureStatus.selector, false) + ); ///@dev reverts after function body with HEVM failure status, which clears all state changes /// but still surfaces assertion failure status. diff --git a/test/foundry/new/helpers/EIP1271Offerer.sol b/test/foundry/new/helpers/EIP1271Offerer.sol index bb00941..abc9424 100644 --- a/test/foundry/new/helpers/EIP1271Offerer.sol +++ b/test/foundry/new/helpers/EIP1271Offerer.sol @@ -16,11 +16,10 @@ contract EIP1271Offerer is ERC1155Recipient { digestToSignatureHash[digest] = keccak256(signature); } - function isValidSignature(bytes32 digest, bytes memory signature) - external - view - returns (bytes4) - { + function isValidSignature( + bytes32 digest, + bytes memory signature + ) external view returns (bytes4) { if (_returnEmpty) { return bytes4(0x00000000); } @@ -44,5 +43,5 @@ contract EIP1271Offerer is ERC1155Recipient { return true; } - receive() external payable { } + receive() external payable {} } diff --git a/test/foundry/new/helpers/EIP712MerkleTree.sol b/test/foundry/new/helpers/EIP712MerkleTree.sol index 3e7ce5d..52fc553 100644 --- a/test/foundry/new/helpers/EIP712MerkleTree.sol +++ b/test/foundry/new/helpers/EIP712MerkleTree.sol @@ -11,20 +11,19 @@ import { OrderComponents } from "seaport-sol/src/SeaportStructs.sol"; import { SeaportInterface } from "seaport-sol/src/SeaportInterface.sol"; -import { TypehashDirectory } from - "../../../../src/main/test/TypehashDirectory.sol"; +import { + TypehashDirectory +} from "../../../../src/main/test/TypehashDirectory.sol"; /** * @dev Seaport doesn't sort leaves when hashing for bulk orders, but Murky * does, so implement a custom hashLeafPairs function */ contract MerkleUnsorted is MurkyBase { - function hashLeafPairs(bytes32 left, bytes32 right) - public - pure - override - returns (bytes32 _hash) - { + function hashLeafPairs( + bytes32 left, + bytes32 right + ) public pure override returns (bytes32 _hash) { assembly { mstore(0x0, left) mstore(0x20, right) @@ -59,8 +58,9 @@ contract EIP712MerkleTree is Test { ) public view returns (bytes memory) { // cache the hash of an empty order components struct to fill out any // nodes required to make the length a power of 2 - bytes32 emptyComponentsHash = - consideration.getOrderHash(emptyOrderComponents); + bytes32 emptyComponentsHash = consideration.getOrderHash( + emptyOrderComponents + ); // declare vars here to avoid stack too deep errors bytes32[] memory leaves; bytes32 bulkOrderTypehash; @@ -92,15 +92,16 @@ contract EIP712MerkleTree is Test { bytes32[] memory proof = merkle.getProof(leaves, orderIndex); bytes32 root = merkle.getRoot(leaves); - return _getSignature( - consideration, - privateKey, - bulkOrderTypehash, - root, - proof, - orderIndex, - useCompact2098 - ); + return + _getSignature( + consideration, + privateKey, + bulkOrderTypehash, + root, + proof, + orderIndex, + useCompact2098 + ); } /** @@ -121,8 +122,9 @@ contract EIP712MerkleTree is Test { // get hash of actual order bytes32 orderHash = consideration.getOrderHash(orderComponents); // get initial empty order components hash - bytes32 emptyComponentsHash = - consideration.getOrderHash(emptyOrderComponents); + bytes32 emptyComponentsHash = consideration.getOrderHash( + emptyOrderComponents + ); // calculate intermediate hashes of a sparse order tree // this will also serve as our proof @@ -173,25 +175,24 @@ contract EIP712MerkleTree is Test { hashIndex /= 2; } - return _getSignature( - consideration, - privateKey, - _lookupBulkOrderTypehash(height), - root, - emptyHashes, - orderIndex, - useCompact2098 - ); + return + _getSignature( + consideration, + privateKey, + _lookupBulkOrderTypehash(height), + root, + emptyHashes, + orderIndex, + useCompact2098 + ); } /** * @dev same lookup seaport optimized does */ - function _lookupBulkOrderTypehash(uint256 treeHeight) - internal - view - returns (bytes32 typeHash) - { + function _lookupBulkOrderTypehash( + uint256 treeHeight + ) internal view returns (bytes32 typeHash) { TypehashDirectory directory = _typehashDirectory; assembly { let typeHashOffset := add(1, shl(0x5, sub(treeHeight, 1))) @@ -214,7 +215,7 @@ contract EIP712MerkleTree is Test { bytes32 bulkOrderHash = keccak256(abi.encode(bulkOrderTypehash, root)); // get domain separator from the particular seaport instance - (, bytes32 domainSeparator,) = consideration.information(); + (, bytes32 domainSeparator, ) = consideration.information(); // declare out here to avoid stack too deep errors bytes memory signature; @@ -224,7 +225,9 @@ contract EIP712MerkleTree is Test { privateKey, keccak256( abi.encodePacked( - bytes2(0x1901), domainSeparator, bulkOrderHash + bytes2(0x1901), + domainSeparator, + bulkOrderHash ) ) ); diff --git a/test/foundry/new/helpers/ERC1155Recipient.sol b/test/foundry/new/helpers/ERC1155Recipient.sol index 3e3344f..8a8313b 100644 --- a/test/foundry/new/helpers/ERC1155Recipient.sol +++ b/test/foundry/new/helpers/ERC1155Recipient.sol @@ -1,8 +1,9 @@ // SPDX-License-Identifier: AGPL-3.0-only pragma solidity ^0.8.17; -import { ERC1155TokenReceiver } from - "@rari-capital/solmate/src/tokens/ERC1155.sol"; +import { + ERC1155TokenReceiver +} from "@rari-capital/solmate/src/tokens/ERC1155.sol"; contract ERC1155Recipient is ERC1155TokenReceiver { function onERC1155Received( diff --git a/test/foundry/new/helpers/ERC721Recipient.sol b/test/foundry/new/helpers/ERC721Recipient.sol index 9cf83f4..255775a 100644 --- a/test/foundry/new/helpers/ERC721Recipient.sol +++ b/test/foundry/new/helpers/ERC721Recipient.sol @@ -1,16 +1,17 @@ // SPDX-License-Identifier: AGPL-3.0-only pragma solidity ^0.8.17; -import { ERC721TokenReceiver } from - "@rari-capital/solmate/src/tokens/ERC721.sol"; +import { + ERC721TokenReceiver +} from "@rari-capital/solmate/src/tokens/ERC721.sol"; contract ERC721Recipient is ERC721TokenReceiver { - function onERC721Received(address, address, uint256, bytes calldata) - public - virtual - override - returns (bytes4) - { + function onERC721Received( + address, + address, + uint256, + bytes calldata + ) public virtual override returns (bytes4) { return ERC721TokenReceiver.onERC721Received.selector; } } diff --git a/test/foundry/new/helpers/ExpectedBalances.sol b/test/foundry/new/helpers/ExpectedBalances.sol index 670f3cf..49cccb1 100644 --- a/test/foundry/new/helpers/ExpectedBalances.sol +++ b/test/foundry/new/helpers/ExpectedBalances.sol @@ -1,10 +1,12 @@ // SPDX-License-Identifier: MIT pragma solidity >=0.8.17; -import { EnumerableSet } from - "@openzeppelin/contracts/utils/structs/EnumerableSet.sol"; -import { EnumerableMap } from - "@openzeppelin/contracts/utils/structs/EnumerableMap.sol"; +import { + EnumerableSet +} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol"; +import { + EnumerableMap +} from "@openzeppelin/contracts/utils/structs/EnumerableMap.sol"; import { IERC20 } from "@openzeppelin/contracts/interfaces/IERC20.sol"; @@ -86,18 +88,19 @@ library BalanceErrorMessages { uint256 expected, uint256 actual ) internal pure returns (string memory) { - return string.concat( - errorSummary, - "\n token: ", - withLabel(token), - "\n account: ", - withLabel(account), - "\n expected: ", - LibString.toString(expected), - "\n actual: ", - LibString.toString(actual), - "\n" - ); + return + string.concat( + errorSummary, + "\n token: ", + withLabel(token), + "\n account: ", + withLabel(account), + "\n expected: ", + LibString.toString(expected), + "\n actual: ", + LibString.toString(actual), + "\n" + ); } function unexpectedAmountErrorMessage( @@ -108,20 +111,21 @@ library BalanceErrorMessages { uint256 expected, uint256 actual ) internal pure returns (string memory) { - return string.concat( - errorSummary, - "\n token: ", - withLabel(token), - "\n identifier: ", - LibString.toString(identifier), - "\n account: ", - withLabel(account), - "\n expected: ", - LibString.toString(expected), - "\n actual: ", - LibString.toString(actual), - "\n" - ); + return + string.concat( + errorSummary, + "\n token: ", + withLabel(token), + "\n identifier: ", + LibString.toString(identifier), + "\n account: ", + withLabel(account), + "\n expected: ", + LibString.toString(expected), + "\n actual: ", + LibString.toString(actual), + "\n" + ); } function nativeUnexpectedBalance( @@ -129,13 +133,14 @@ library BalanceErrorMessages { uint256 expectedBalance, uint256 actualBalance ) internal pure returns (string memory) { - return unexpectedAmountErrorMessage( - "ExpectedBalances: Unexpected native balance", - address(0), - account, - expectedBalance, - actualBalance - ); + return + unexpectedAmountErrorMessage( + "ExpectedBalances: Unexpected native balance", + address(0), + account, + expectedBalance, + actualBalance + ); } function erc20UnexpectedBalance( @@ -144,13 +149,14 @@ library BalanceErrorMessages { uint256 expectedBalance, uint256 actualBalance ) internal pure returns (string memory) { - return unexpectedAmountErrorMessage( - "ExpectedBalances: Unexpected ERC20 balance", - token, - account, - expectedBalance, - actualBalance - ); + return + unexpectedAmountErrorMessage( + "ExpectedBalances: Unexpected ERC20 balance", + token, + account, + expectedBalance, + actualBalance + ); } function erc721UnexpectedBalance( @@ -159,13 +165,14 @@ library BalanceErrorMessages { uint256 expectedBalance, uint256 actualBalance ) internal pure returns (string memory) { - return unexpectedAmountErrorMessage( - "ExpectedBalances: Unexpected ERC721 balance", - token, - account, - expectedBalance, - actualBalance - ); + return + unexpectedAmountErrorMessage( + "ExpectedBalances: Unexpected ERC721 balance", + token, + account, + expectedBalance, + actualBalance + ); } function erc1155UnexpectedBalance( @@ -175,14 +182,15 @@ library BalanceErrorMessages { uint256 expectedBalance, uint256 actualBalance ) internal pure returns (string memory) { - return unexpectedAmountErrorMessage( - "ExpectedBalances: Unexpected ERC1155 balance for ID", - token, - identifier, - account, - expectedBalance, - actualBalance - ); + return + unexpectedAmountErrorMessage( + "ExpectedBalances: Unexpected ERC1155 balance for ID", + token, + identifier, + account, + expectedBalance, + actualBalance + ); } function insufficientBalance( @@ -193,18 +201,19 @@ library BalanceErrorMessages { uint256 amount, bool derived ) internal pure returns (string memory) { - return string.concat( - prefix, - "\n from: ", - withLabel(account), - derived ? "\n balance (derived): " : "\n balance (actual): ", - LibString.toString(balance), - "\n transfer amount: ", - LibString.toString(amount), - "\n to: ", - withLabel(recipient), - "\n" - ); + return + string.concat( + prefix, + "\n from: ", + withLabel(account), + derived ? "\n balance (derived): " : "\n balance (actual): ", + LibString.toString(balance), + "\n transfer amount: ", + LibString.toString(amount), + "\n to: ", + withLabel(recipient), + "\n" + ); } function insufficientNativeBalance( @@ -214,14 +223,15 @@ library BalanceErrorMessages { uint256 amount, bool derived ) internal pure returns (string memory) { - return insufficientBalance( - "ExpectedBalances: Insufficient native balance for transfer", - account, - recipient, - balance, - amount, - derived - ); + return + insufficientBalance( + "ExpectedBalances: Insufficient native balance for transfer", + account, + recipient, + balance, + amount, + derived + ); } function insufficientERC20Balance( @@ -232,17 +242,18 @@ library BalanceErrorMessages { uint256 amount, bool derived ) internal pure returns (string memory) { - return insufficientBalance( - string.concat( - "ExpectedBalances: Insufficient ERC20 balance for transfer\n token: ", - withLabel(token) - ), - account, - recipient, - balance, - amount, - derived - ); + return + insufficientBalance( + string.concat( + "ExpectedBalances: Insufficient ERC20 balance for transfer\n token: ", + withLabel(token) + ), + account, + recipient, + balance, + amount, + derived + ); } function insufficientERC1155Balance( @@ -254,19 +265,20 @@ library BalanceErrorMessages { uint256 amount, bool derived ) internal pure returns (string memory) { - return insufficientBalance( - string.concat( - "ExpectedBalances: Insufficient ERC1155 balance for transfer\n token: ", - withLabel(token), - "\n identifier: ", - LibString.toString(identifier) - ), - account, - recipient, - balance, - amount, - derived - ); + return + insufficientBalance( + string.concat( + "ExpectedBalances: Insufficient ERC1155 balance for transfer\n token: ", + withLabel(token), + "\n identifier: ", + LibString.toString(identifier) + ), + account, + recipient, + balance, + amount, + derived + ); } } @@ -296,16 +308,22 @@ contract NativeBalances { if (balance < amount) { revert( BalanceErrorMessages.insufficientNativeBalance( - account, recipient, balance, amount, derived + account, + recipient, + balance, + amount, + derived ) ); } return balance - amount; } - function addNativeTransfer(address from, address to, uint256 amount) - public - { + function addNativeTransfer( + address from, + address to, + uint256 amount + ) public { (bool fromExists, uint256 fromBalance) = accountsMap.tryGet(from); if (!fromExists) { fromBalance = from.balance; @@ -329,7 +347,9 @@ contract NativeBalances { if (expectedBalance != actualBalance) { revert( BalanceErrorMessages.nativeUnexpectedBalance( - account, expectedBalance, actualBalance + account, + expectedBalance, + actualBalance ) ); } @@ -345,8 +365,10 @@ contract NativeBalances { accountBalances = new NativeAccountDump[](accounts.length); for (uint256 i; i < accounts.length; i++) { address account = accounts[i]; - accountBalances[i] = - NativeAccountDump(account, accountsMap.get(account)); + accountBalances[i] = NativeAccountDump( + account, + accountsMap.get(account) + ); } } } @@ -372,7 +394,12 @@ contract ERC20Balances { if (balance < amount) { revert( BalanceErrorMessages.insufficientERC20Balance( - token, account, recipient, balance, amount, derived + token, + account, + recipient, + balance, + amount, + derived ) ); } @@ -393,7 +420,8 @@ contract ERC20Balances { fromBalance = IERC20(token).balanceOf(from); } accounts.set( - from, sub(token, from, to, fromBalance, amount, fromExists) + from, + sub(token, from, to, fromBalance, amount, fromExists) ); (bool toExists, uint256 toBalance) = accounts.tryGet(to); @@ -407,8 +435,9 @@ contract ERC20Balances { uint256 length = tokens.length(); for (uint256 i; i < length; i++) { address token = tokens.at(i); - EnumerableMap.AddressToUintMap storage accountsMap = - tokenAccounts[token]; + EnumerableMap.AddressToUintMap storage accountsMap = tokenAccounts[ + token + ]; address[] memory accounts = accountsMap.keys(); uint256 accountsLength = accounts.length; for (uint256 j; j < accountsLength; j++) { @@ -418,7 +447,10 @@ contract ERC20Balances { if (expectedBalance != actualBalance) { revert( BalanceErrorMessages.erc20UnexpectedBalance( - token, account, expectedBalance, actualBalance + token, + account, + expectedBalance, + actualBalance ) ); } @@ -435,8 +467,9 @@ contract ERC20Balances { tokenDumps = new ERC20TokenDump[](length); for (uint256 i; i < length; i++) { address token = tokens.at(i); - EnumerableMap.AddressToUintMap storage accountsMap = - tokenAccounts[token]; + EnumerableMap.AddressToUintMap storage accountsMap = tokenAccounts[ + token + ]; address[] memory accounts = accountsMap.keys(); ERC20TokenDump memory tokenDump = ERC20TokenDump({ token: token, @@ -478,8 +511,9 @@ contract ERC721Balances { tokens.add(token); TokenData721 storage tokenData = tokenDatas[token]; - (bool fromExists, uint256 fromBalance) = - tokenData.accountBalances.tryGet(from); + (bool fromExists, uint256 fromBalance) = tokenData + .accountBalances + .tryGet(from); if (!fromExists) { fromBalance = IERC721(token).balanceOf(from); } @@ -490,8 +524,9 @@ contract ERC721Balances { tokenData.accountBalances.set(from, fromBalance - 1); - (bool toExists, uint256 toBalance) = - tokenData.accountBalances.tryGet(to); + (bool toExists, uint256 toBalance) = tokenData.accountBalances.tryGet( + to + ); if (!toExists) { toBalance = IERC721(token).balanceOf(to); } @@ -534,20 +569,25 @@ contract ERC721Balances { address account = accounts[j]; { - uint256 expectedBalance = - tokenData.accountBalances.get(account); + uint256 expectedBalance = tokenData.accountBalances.get( + account + ); uint256 actualBalance = IERC721(token).balanceOf(account); if (actualBalance != expectedBalance) { revert( BalanceErrorMessages.erc721UnexpectedBalance( - token, account, expectedBalance, actualBalance + token, + account, + expectedBalance, + actualBalance ) ); } } - uint256[] memory identifiers = - tokenData.accountIdentifiers[account].values(); + uint256[] memory identifiers = tokenData + .accountIdentifiers[account] + .values(); uint256 identifiersLength = identifiers.length; @@ -575,11 +615,9 @@ contract ERC721Balances { } } - function dumpERC721Token(address token) - internal - view - returns (ERC721TokenDump memory dump) - { + function dumpERC721Token( + address token + ) internal view returns (ERC721TokenDump memory dump) { TokenData721 storage tokenData = tokenDatas[token]; dump.accounts = tokenData.accountBalances.keys(); @@ -589,8 +627,9 @@ contract ERC721Balances { for (uint256 i; i < accountsLength; i++) { address account = dump.accounts[i]; - dump.accountIdentifiers[i] = - tokenData.accountIdentifiers[account].values(); + dump.accountIdentifiers[i] = tokenData + .accountIdentifiers[account] + .values(); } } } @@ -649,28 +688,33 @@ contract ERC1155Balances { tokenData.accounts.add(details.to); { - EnumerableMap.UintToUintMap storage fromIdentifiers = - tokenData.accountIdentifiers[details.from]; - (bool fromExists, uint256 fromBalance) = - fromIdentifiers.tryGet(details.identifier); + EnumerableMap.UintToUintMap storage fromIdentifiers = tokenData + .accountIdentifiers[details.from]; + (bool fromExists, uint256 fromBalance) = fromIdentifiers.tryGet( + details.identifier + ); if (!fromExists) { fromBalance = IERC1155(details.token).balanceOf( - details.from, details.identifier + details.from, + details.identifier ); } fromIdentifiers.set( - details.identifier, sub(details, fromBalance, fromExists) + details.identifier, + sub(details, fromBalance, fromExists) ); } { - EnumerableMap.UintToUintMap storage toIdentifiers = - tokenData.accountIdentifiers[details.to]; - (bool toExists, uint256 toBalance) = - toIdentifiers.tryGet(details.identifier); + EnumerableMap.UintToUintMap storage toIdentifiers = tokenData + .accountIdentifiers[details.to]; + (bool toExists, uint256 toBalance) = toIdentifiers.tryGet( + details.identifier + ); if (!toExists) { toBalance = IERC1155(details.token).balanceOf( - details.to, details.identifier + details.to, + details.identifier ); } toIdentifiers.set(details.identifier, toBalance + details.amount); @@ -696,8 +740,10 @@ contract ERC1155Balances { for (uint256 j; j < accountsLength; j++) { address account = accounts[j]; - EnumerableMap.UintToUintMap storage accountIdentifiers = - tokenData.accountIdentifiers[account]; + EnumerableMap.UintToUintMap + storage accountIdentifiers = tokenData.accountIdentifiers[ + account + ]; uint256[] memory identifiers = accountIdentifiers.keys(); @@ -707,9 +753,13 @@ contract ERC1155Balances { // assert their balance matches the expected balance. for (uint256 k; k < identifiersLength; k++) { uint256 identifier = identifiers[k]; - uint256 expectedBalance = accountIdentifiers.get(identifier); - uint256 actualBalance = - IERC1155(token).balanceOf(account, identifier); + uint256 expectedBalance = accountIdentifiers.get( + identifier + ); + uint256 actualBalance = IERC1155(token).balanceOf( + account, + identifier + ); if (expectedBalance != actualBalance) { revert( BalanceErrorMessages.erc1155UnexpectedBalance( @@ -750,8 +800,10 @@ contract ERC1155Balances { for (uint256 j; j < accountsLength; j++) { address account = tokenData.accounts.at(j); - EnumerableMap.UintToUintMap storage accountIdentifiers = - tokenData.accountIdentifiers[account]; + EnumerableMap.UintToUintMap + storage accountIdentifiers = tokenData.accountIdentifiers[ + account + ]; uint256[] memory identifiers = accountIdentifiers.keys(); @@ -767,7 +819,9 @@ contract ERC1155Balances { for (uint256 k; k < identifiersLength; k++) { uint256 identifier = identifiers[k]; accountDump.identifiers[k] = identifier; - accountDump.balances[k] = accountIdentifiers.get(identifier); + accountDump.balances[k] = accountIdentifiers.get( + identifier + ); } } } @@ -786,30 +840,42 @@ contract ExpectedBalances is function addTransfer(Execution calldata execution) public { ReceivedItem memory item = execution.item; if (item.itemType == ItemType.NATIVE) { - return addNativeTransfer( - execution.offerer, item.recipient, item.amount - ); + return + addNativeTransfer( + execution.offerer, + item.recipient, + item.amount + ); } if (item.itemType == ItemType.ERC20) { - return addERC20Transfer( - item.token, execution.offerer, item.recipient, item.amount - ); + return + addERC20Transfer( + item.token, + execution.offerer, + item.recipient, + item.amount + ); } if (item.itemType == ItemType.ERC721) { - return addERC721Transfer( - item.token, execution.offerer, item.recipient, item.identifier - ); - } - if (item.itemType == ItemType.ERC1155) { - return addERC1155Transfer( - ERC1155TransferDetails( + return + addERC721Transfer( item.token, execution.offerer, item.recipient, - item.identifier, - item.amount - ) - ); + item.identifier + ); + } + if (item.itemType == ItemType.ERC1155) { + return + addERC1155Transfer( + ERC1155TransferDetails( + item.token, + execution.offerer, + item.recipient, + item.identifier, + item.amount + ) + ); } } diff --git a/test/foundry/new/helpers/FractionUtil.sol b/test/foundry/new/helpers/FractionUtil.sol index 822de62..ac01397 100644 --- a/test/foundry/new/helpers/FractionUtil.sol +++ b/test/foundry/new/helpers/FractionUtil.sol @@ -77,14 +77,16 @@ library FractionUtil { // Ensure fractional amounts are below max uint120. if ( - filledNumerator > type(uint120).max - || denominator > type(uint120).max + filledNumerator > type(uint120).max || + denominator > type(uint120).max ) { applyGcd = true; // Derive greatest common divisor using euclidean algorithm. - uint256 scaleDown = - _gcd(numerator, _gcd(filledNumerator, denominator)); + uint256 scaleDown = _gcd( + numerator, + _gcd(filledNumerator, denominator) + ); // Scale all fractional values down by gcd. numerator = numerator / scaleDown; @@ -93,17 +95,18 @@ library FractionUtil { } if (denominator > type(uint120).max) { - return FractionResults({ - realizedNumerator: 0, - realizedDenominator: 0, - finalFilledNumerator: 0, - finalFilledDenominator: 0, - originalStatusNumerator: currentStatusNumerator, - originalStatusDenominator: currentStatusDenominator, - requestedNumerator: numeratorToFill, - requestedDenominator: denominatorToFill, - status: FractionStatus.INVALID - }); + return + FractionResults({ + realizedNumerator: 0, + realizedDenominator: 0, + finalFilledNumerator: 0, + finalFilledDenominator: 0, + originalStatusNumerator: currentStatusNumerator, + originalStatusDenominator: currentStatusDenominator, + requestedNumerator: numeratorToFill, + requestedDenominator: denominatorToFill, + status: FractionStatus.INVALID + }); } FractionStatus status; if (partialFill && applyGcd) { @@ -116,16 +119,51 @@ library FractionUtil { status = FractionStatus.WHOLE_FILL; } - return FractionResults({ - realizedNumerator: uint120(numerator), - realizedDenominator: uint120(denominator), - finalFilledNumerator: uint120(filledNumerator), - finalFilledDenominator: uint120(denominator), - originalStatusNumerator: currentStatusNumerator, - originalStatusDenominator: currentStatusDenominator, - requestedNumerator: numeratorToFill, - requestedDenominator: denominatorToFill, - status: status - }); + uint120 realizedNumerator = uint120(numerator); + uint120 realizedDenominator = uint120(denominator); + + filledNumerator = currentStatusNumerator; + + // if supplied denominator differs from current one... + if (currentStatusDenominator != denominator) { + // scale current numerator by the supplied denominator, then... + filledNumerator *= denominator; + + // the supplied numerator & denominator by current denominator. + numerator *= currentStatusDenominator; + denominator *= currentStatusDenominator; + } + + // Increment the filled numerator by the new numerator. + filledNumerator += numerator; + + // Ensure fractional amounts are below max uint120. + if ( + filledNumerator > type(uint120).max || + denominator > type(uint120).max + ) { + // Derive greatest common divisor using euclidean algorithm. + uint256 scaleDown = _gcd( + filledNumerator, + denominator + ); + + // Scale new filled fractional values down by gcd. + filledNumerator = filledNumerator / scaleDown; + denominator = denominator / scaleDown; + } + + return + FractionResults({ + realizedNumerator: realizedNumerator, + realizedDenominator: realizedDenominator, + finalFilledNumerator: uint120(filledNumerator), + finalFilledDenominator: uint120(denominator), + originalStatusNumerator: currentStatusNumerator, + originalStatusDenominator: currentStatusDenominator, + requestedNumerator: numeratorToFill, + requestedDenominator: denominatorToFill, + status: status + }); } } diff --git a/test/foundry/new/helpers/FuzzAmendments.sol b/test/foundry/new/helpers/FuzzAmendments.sol index f38e033..29ed4d7 100644 --- a/test/foundry/new/helpers/FuzzAmendments.sol +++ b/test/foundry/new/helpers/FuzzAmendments.sol @@ -33,17 +33,21 @@ import { ContractOrderRebate } from "seaport-sol/src/SpaceEnums.sol"; -import { HashCalldataContractOfferer } from - "../../../../src/main/test/HashCalldataContractOfferer.sol"; +import { + HashCalldataContractOfferer +} from "../../../../src/main/test/HashCalldataContractOfferer.sol"; -import { OffererZoneFailureReason } from - "../../../../src/main/test/OffererZoneFailureReason.sol"; +import { + OffererZoneFailureReason +} from "../../../../src/main/test/OffererZoneFailureReason.sol"; import { FuzzGeneratorContext } from "./FuzzGeneratorContextLib.sol"; import { PRNGHelpers } from "./FuzzGenerators.sol"; import { - FractionResults, FractionStatus, FractionUtil + FractionResults, + FractionStatus, + FractionUtil } from "./FractionUtil.sol"; /** @@ -73,15 +77,17 @@ abstract contract FuzzAmendments is Test { // TODO: make it so it adds / removes / modifies more than a single thing // and create arbitrary new items. for (uint256 i = 0; i < context.executionState.orders.length; ++i) { - OrderParameters memory orderParams = - (context.executionState.orders[i].parameters); + OrderParameters memory orderParams = ( + context.executionState.orders[i].parameters + ); if (orderParams.orderType == OrderType.CONTRACT) { uint256 contractNonce; HashCalldataContractOfferer offerer; { - ContractOrderRebate rebate = - (context.advancedOrdersSpace.orders[i].rebate); + ContractOrderRebate rebate = ( + context.advancedOrdersSpace.orders[i].rebate + ); if (rebate == ContractOrderRebate.NONE) { continue; @@ -93,8 +99,10 @@ abstract contract FuzzAmendments is Test { ) ); - bytes32 orderHash = - context.executionState.orderDetails[i].orderHash; + bytes32 orderHash = context + .executionState + .orderDetails[i] + .orderHash; if (rebate == ContractOrderRebate.MORE_OFFER_ITEMS) { offerer.addExtraItemMutation( @@ -111,8 +119,9 @@ abstract contract FuzzAmendments is Test { } else if ( rebate == ContractOrderRebate.MORE_OFFER_ITEM_AMOUNTS ) { - uint256 itemIdx = - _findFirstNon721Index(orderParams.offer); + uint256 itemIdx = _findFirstNon721Index( + orderParams.offer + ); offerer.addItemAmountMutation( Side.OFFER, itemIdx, @@ -128,11 +137,12 @@ abstract contract FuzzAmendments is Test { orderHash ); } else if ( - rebate - == ContractOrderRebate.LESS_CONSIDERATION_ITEM_AMOUNTS + rebate == + ContractOrderRebate.LESS_CONSIDERATION_ITEM_AMOUNTS ) { - uint256 itemIdx = - _findFirstNon721Index(orderParams.consideration); + uint256 itemIdx = _findFirstNon721Index( + orderParams.consideration + ); offerer.addItemAmountMutation( Side.CONSIDERATION, itemIdx, @@ -143,8 +153,9 @@ abstract contract FuzzAmendments is Test { revert("FuzzAmendments: unknown rebate type"); } - uint256 shiftedOfferer = - (uint256(uint160(orderParams.offerer)) << 96); + uint256 shiftedOfferer = (uint256( + uint160(orderParams.offerer) + ) << 96); contractNonce = uint256(orderHash) ^ shiftedOfferer; } @@ -154,25 +165,34 @@ abstract contract FuzzAmendments is Test { // Temporarily adjust the contract nonce and reset it after. orderParams.offerer.inscribeContractOffererNonce( - contractNonce, context.seaport + contractNonce, + context.seaport ); - (SpentItem[] memory offer, ReceivedItem[] memory consideration) - = offerer.previewOrder( - address(context.seaport), - context.executionState.caller, - _toSpent(orderParams.offer), - _toSpent(orderParams.consideration), - context.executionState.orders[i].extraData - ); + ( + SpentItem[] memory offer, + ReceivedItem[] memory consideration + ) = offerer.previewOrder( + address(context.seaport), + context.executionState.caller, + _toSpent(orderParams.offer), + _toSpent(orderParams.consideration), + context.executionState.orders[i].extraData + ); orderParams.offerer.inscribeContractOffererNonce( - originalContractNonce, context.seaport + originalContractNonce, + context.seaport ); - context.executionState.previewedOrders[i].parameters.offer = - _toOffer(offer); - context.executionState.previewedOrders[i] + context + .executionState + .previewedOrders[i] + .parameters + .offer = _toOffer(offer); + context + .executionState + .previewedOrders[i] .parameters .consideration = _toConsideration(consideration); } @@ -184,19 +204,21 @@ abstract contract FuzzAmendments is Test { * * @param context The test context. */ - function validateOrdersAndRegisterCheck(FuzzTestContext memory context) - public - { + function validateOrdersAndRegisterCheck( + FuzzTestContext memory context + ) public { for ( uint256 i = 0; i < context.executionState.preExecOrderStatuses.length; ++i ) { if ( - context.executionState.preExecOrderStatuses[i] - == OrderStatusEnum.VALIDATED + context.executionState.preExecOrderStatuses[i] == + OrderStatusEnum.VALIDATED ) { - bool validated = context.executionState.orders[i] + bool validated = context + .executionState + .orders[i] .validateTipNeutralizedOrder(context); require(validated, "Failed to validate orders."); @@ -214,8 +236,8 @@ abstract contract FuzzAmendments is Test { function setPartialFills(FuzzTestContext memory context) public { for (uint256 i = 0; i < context.executionState.orders.length; ++i) { if ( - context.executionState.preExecOrderStatuses[i] - != OrderStatusEnum.PARTIAL + context.executionState.preExecOrderStatuses[i] != + OrderStatusEnum.PARTIAL ) { continue; } @@ -223,16 +245,17 @@ abstract contract FuzzAmendments is Test { AdvancedOrder memory order = context.executionState.orders[i]; if ( - order.parameters.orderType != OrderType.PARTIAL_OPEN - && order.parameters.orderType != OrderType.PARTIAL_RESTRICTED + order.parameters.orderType != OrderType.PARTIAL_OPEN && + order.parameters.orderType != OrderType.PARTIAL_RESTRICTED ) { revert( "FuzzAmendments: invalid order type for partial fill state" ); } - (uint256 denominator, bool canScaleUp) = - order.parameters.getSmallestDenominator(); + (uint256 denominator, bool canScaleUp) = order + .parameters + .getSmallestDenominator(); // If the denominator is 0 or 1, the order cannot have a partial // fill fraction applied. @@ -241,27 +264,34 @@ abstract contract FuzzAmendments is Test { order.inscribeOrderStatusValidated(true, context.seaport); uint256 numerator = context.generatorContext.randRange( - 1, canScaleUp ? (denominator - 1) : 1 + 1, + canScaleUp ? (denominator - 1) : 1 ); uint256 maxScaleFactor = type(uint120).max / denominator; - uint256 scaleFactor = - context.generatorContext.randRange(1, maxScaleFactor); + uint256 scaleFactor = context.generatorContext.randRange( + 1, + maxScaleFactor + ); numerator *= scaleFactor; denominator *= scaleFactor; if ( - numerator == 0 || denominator < 2 - || numerator >= denominator || numerator > type(uint120).max - || denominator > type(uint120).max + numerator == 0 || + denominator < 2 || + numerator >= denominator || + numerator > type(uint120).max || + denominator > type(uint120).max ) { revert("FuzzAmendments: partial fill sanity check failed"); } order.inscribeOrderStatusNumeratorAndDenominator( - uint120(numerator), uint120(denominator), context.seaport + uint120(numerator), + uint120(denominator), + context.seaport ); // Derive the realized and final fill fractions and status. @@ -279,14 +309,17 @@ abstract contract FuzzAmendments is Test { // Update "previewed" orders with the realized numerator and // denominator so orderDetails derivation is based on realized. - context.executionState.previewedOrders[i].numerator = - (fractionResults.realizedNumerator); - context.executionState.previewedOrders[i].denominator = - (fractionResults.realizedDenominator); + context.executionState.previewedOrders[i].numerator = ( + fractionResults.realizedNumerator + ); + context.executionState.previewedOrders[i].denominator = ( + fractionResults.realizedDenominator + ); } else { // TODO: log these occurrences? - context.executionState.preExecOrderStatuses[i] = - (OrderStatusEnum.AVAILABLE); + context.executionState.preExecOrderStatuses[i] = ( + OrderStatusEnum.AVAILABLE + ); } } } @@ -296,62 +329,76 @@ abstract contract FuzzAmendments is Test { * * @param context The test context. */ - function conformOnChainStatusToExpected(FuzzTestContext memory context) - public - { + function conformOnChainStatusToExpected( + FuzzTestContext memory context + ) public { for ( uint256 i = 0; i < context.executionState.preExecOrderStatuses.length; ++i ) { if ( - context.executionState.preExecOrderStatuses[i] - == OrderStatusEnum.VALIDATED + context.executionState.preExecOrderStatuses[i] == + OrderStatusEnum.VALIDATED ) { validateOrdersAndRegisterCheck(context); } else if ( - context.executionState.preExecOrderStatuses[i] - == OrderStatusEnum.CANCELLED_EXPLICIT + context.executionState.preExecOrderStatuses[i] == + OrderStatusEnum.CANCELLED_EXPLICIT ) { context.executionState.orders[i].inscribeOrderStatusCancelled( - true, context.seaport + true, + context.seaport ); } else if ( - context.executionState.preExecOrderStatuses[i] - == OrderStatusEnum.FULFILLED + context.executionState.preExecOrderStatuses[i] == + OrderStatusEnum.FULFILLED ) { - context.executionState.orders[i] + context + .executionState + .orders[i] .inscribeOrderStatusNumeratorAndDenominator( - 1, 1, context.seaport - ); + 1, + 1, + context.seaport + ); } else if ( - context.executionState.preExecOrderStatuses[i] - == OrderStatusEnum.AVAILABLE + context.executionState.preExecOrderStatuses[i] == + OrderStatusEnum.AVAILABLE ) { - context.executionState.orders[i] + context + .executionState + .orders[i] .inscribeOrderStatusNumeratorAndDenominator( - 0, 0, context.seaport - ); + 0, + 0, + context.seaport + ); context.executionState.orders[i].inscribeOrderStatusCancelled( - false, context.seaport + false, + context.seaport ); } else if ( - context.executionState.preExecOrderStatuses[i] - == OrderStatusEnum.REVERT + context.executionState.preExecOrderStatuses[i] == + OrderStatusEnum.REVERT ) { - OrderParameters memory orderParams = - context.executionState.orders[i].parameters; - bytes32 orderHash = - context.executionState.orderDetails[i].orderHash; + OrderParameters memory orderParams = context + .executionState + .orders[i] + .parameters; + bytes32 orderHash = context + .executionState + .orderDetails[i] + .orderHash; if (orderParams.orderType != OrderType.CONTRACT) { revert("FuzzAmendments: bad pre-exec order status"); } HashCalldataContractOfferer(payable(orderParams.offerer)) .setFailureReason( - orderHash, - OffererZoneFailureReason.ContractOfferer_generateReverts - ); + orderHash, + OffererZoneFailureReason.ContractOfferer_generateReverts + ); } } } @@ -363,18 +410,20 @@ abstract contract FuzzAmendments is Test { */ function setCounter(FuzzTestContext memory context) public { for (uint256 i = 0; i < context.executionState.orders.length; ++i) { - OrderParameters memory order = - (context.executionState.orders[i].parameters); + OrderParameters memory order = ( + context.executionState.orders[i].parameters + ); if (order.orderType == OrderType.CONTRACT) { continue; } - uint256 offererSpecificCounter = - context.executionState.counter + uint256(uint160(order.offerer)); + uint256 offererSpecificCounter = context.executionState.counter + + uint256(uint160(order.offerer)); order.offerer.inscribeCounter( - offererSpecificCounter, context.seaport + offererSpecificCounter, + context.seaport ); } } @@ -386,8 +435,9 @@ abstract contract FuzzAmendments is Test { */ function setContractOffererNonce(FuzzTestContext memory context) public { for (uint256 i = 0; i < context.executionState.orders.length; ++i) { - OrderParameters memory order = - (context.executionState.orders[i].parameters); + OrderParameters memory order = ( + context.executionState.orders[i].parameters + ); if (order.orderType != OrderType.CONTRACT) { continue; @@ -398,21 +448,20 @@ abstract contract FuzzAmendments is Test { .contractOffererNonce + uint256(uint160(order.offerer)); order.offerer.inscribeContractOffererNonce( - contractOffererSpecificContractNonce, context.seaport + contractOffererSpecificContractNonce, + context.seaport ); } } - function _findFirstNon721Index(OfferItem[] memory items) - internal - pure - returns (uint256) - { + function _findFirstNon721Index( + OfferItem[] memory items + ) internal pure returns (uint256) { for (uint256 i = 0; i < items.length; ++i) { ItemType itemType = items[i].itemType; if ( - itemType != ItemType.ERC721 - && itemType != ItemType.ERC721_WITH_CRITERIA + itemType != ItemType.ERC721 && + itemType != ItemType.ERC721_WITH_CRITERIA ) { return i; } @@ -421,16 +470,14 @@ abstract contract FuzzAmendments is Test { revert("FuzzAmendments: could not locate non-721 offer item index"); } - function _findFirstNon721Index(ConsiderationItem[] memory items) - internal - pure - returns (uint256) - { + function _findFirstNon721Index( + ConsiderationItem[] memory items + ) internal pure returns (uint256) { for (uint256 i = 0; i < items.length; ++i) { ItemType itemType = items[i].itemType; if ( - itemType != ItemType.ERC721 - && itemType != ItemType.ERC721_WITH_CRITERIA + itemType != ItemType.ERC721 && + itemType != ItemType.ERC721_WITH_CRITERIA ) { return i; } @@ -441,11 +488,9 @@ abstract contract FuzzAmendments is Test { ); } - function _toSpent(OfferItem[] memory offer) - internal - pure - returns (SpentItem[] memory spent) - { + function _toSpent( + OfferItem[] memory offer + ) internal pure returns (SpentItem[] memory spent) { spent = new SpentItem[](offer.length); for (uint256 i = 0; i < offer.length; ++i) { OfferItem memory item = offer[i]; @@ -458,11 +503,9 @@ abstract contract FuzzAmendments is Test { } } - function _toSpent(ConsiderationItem[] memory consideration) - internal - pure - returns (SpentItem[] memory spent) - { + function _toSpent( + ConsiderationItem[] memory consideration + ) internal pure returns (SpentItem[] memory spent) { spent = new SpentItem[](consideration.length); for (uint256 i = 0; i < consideration.length; ++i) { ConsiderationItem memory item = consideration[i]; @@ -475,11 +518,9 @@ abstract contract FuzzAmendments is Test { } } - function _toOffer(SpentItem[] memory spent) - internal - pure - returns (OfferItem[] memory offer) - { + function _toOffer( + SpentItem[] memory spent + ) internal pure returns (OfferItem[] memory offer) { offer = new OfferItem[](spent.length); for (uint256 i = 0; i < spent.length; ++i) { SpentItem memory item = spent[i]; @@ -493,11 +534,9 @@ abstract contract FuzzAmendments is Test { } } - function _toConsideration(ReceivedItem[] memory received) - internal - pure - returns (ConsiderationItem[] memory consideration) - { + function _toConsideration( + ReceivedItem[] memory received + ) internal pure returns (ConsiderationItem[] memory consideration) { consideration = new ConsiderationItem[](received.length); for (uint256 i = 0; i < received.length; ++i) { ReceivedItem memory item = received[i]; diff --git a/test/foundry/new/helpers/FuzzChecks.sol b/test/foundry/new/helpers/FuzzChecks.sol index 76b738a..082bc5c 100644 --- a/test/foundry/new/helpers/FuzzChecks.sol +++ b/test/foundry/new/helpers/FuzzChecks.sol @@ -15,7 +15,8 @@ import { } from "seaport-sol/src/SeaportStructs.sol"; import { - OrderStatusEnum, UnavailableReason + OrderStatusEnum, + UnavailableReason } from "seaport-sol/src/SpaceEnums.sol"; import { FuzzHelpers } from "./FuzzHelpers.sol"; @@ -24,11 +25,13 @@ import { FuzzTestContext } from "./FuzzTestContextLib.sol"; import { FuzzEngineLib } from "./FuzzEngineLib.sol"; -import { TestCalldataHashContractOfferer } from - "../../../../src/main/test/TestCalldataHashContractOfferer.sol"; +import { + TestCalldataHashContractOfferer +} from "../../../../src/main/test/TestCalldataHashContractOfferer.sol"; -import { HashValidationZoneOfferer } from - "../../../../src/main/test/HashValidationZoneOfferer.sol"; +import { + HashValidationZoneOfferer +} from "../../../../src/main/test/HashValidationZoneOfferer.sol"; /** * @dev Check functions are the post-execution assertions we want to validate. @@ -101,8 +104,8 @@ abstract contract FuzzChecks is Test { for (uint256 i; i < context.executionState.orderDetails.length; i++) { if ( - context.executionState.orderDetails[i].unavailableReason - == UnavailableReason.AVAILABLE + context.executionState.orderDetails[i].unavailableReason == + UnavailableReason.AVAILABLE ) { assertEq( context.returnValues.availableOrders[i], @@ -113,34 +116,38 @@ abstract contract FuzzChecks is Test { } } - /** + /** * @dev Check that the zone is getting the right calldata in authorizeOrder. * * @param context A Fuzz test context. */ - function check_authorizeOrderExpectedDataHash(FuzzTestContext memory context) - public - { + function check_authorizeOrderExpectedDataHash( + FuzzTestContext memory context + ) public { // Iterate over the orders. for (uint256 i; i < context.executionState.orders.length; i++) { - OrderParameters memory order = - context.executionState.orders[i].parameters; - + OrderParameters memory order = context + .executionState + .orders[i] + .parameters; // If the order is restricted, check the calldata. if ( - order.orderType == OrderType.FULL_RESTRICTED - || order.orderType == OrderType.PARTIAL_RESTRICTED + order.orderType == OrderType.FULL_RESTRICTED || + order.orderType == OrderType.PARTIAL_RESTRICTED ) { testZone = payable(order.zone); // Each order has a calldata hash, indexed to orders, that is // expected to be returned by the zone. - bytes32 expectedCalldataHash = - context.expectations.expectedZoneAuthorizeCalldataHashes[i]; + bytes32 expectedCalldataHash = context + .expectations + .expectedZoneAuthorizeCalldataHashes[i]; - bytes32 orderHash = - context.executionState.orderDetails[i].orderHash; + bytes32 orderHash = context + .executionState + .orderDetails[i] + .orderHash; // Use order hash to get the expected calldata hash from zone. // TODO: fix this in cases where contract orders are part of @@ -164,28 +171,33 @@ abstract contract FuzzChecks is Test { * * @param context A Fuzz test context. */ - function check_validateOrderExpectedDataHash(FuzzTestContext memory context) - public - { + function check_validateOrderExpectedDataHash( + FuzzTestContext memory context + ) public { // Iterate over the orders. for (uint256 i; i < context.executionState.orders.length; i++) { - OrderParameters memory order = - context.executionState.orders[i].parameters; + OrderParameters memory order = context + .executionState + .orders[i] + .parameters; // If the order is restricted, check the calldata. if ( - order.orderType == OrderType.FULL_RESTRICTED - || order.orderType == OrderType.PARTIAL_RESTRICTED + order.orderType == OrderType.FULL_RESTRICTED || + order.orderType == OrderType.PARTIAL_RESTRICTED ) { testZone = payable(order.zone); // Each order has a calldata hash, indexed to orders, that is // expected to be returned by the zone. - bytes32 expectedCalldataHash = - context.expectations.expectedZoneValidateCalldataHashes[i]; + bytes32 expectedCalldataHash = context + .expectations + .expectedZoneValidateCalldataHashes[i]; - bytes32 orderHash = - context.executionState.orderDetails[i].orderHash; + bytes32 orderHash = context + .executionState + .orderDetails[i] + .orderHash; // Use order hash to get the expected calldata hash from zone. // TODO: fix this in cases where contract orders are part of @@ -213,31 +225,36 @@ abstract contract FuzzChecks is Test { function check_contractOrderExpectedDataHashes( FuzzTestContext memory context ) public { - bytes32[2][] memory expectedCalldataHashes = - context.expectations.expectedContractOrderCalldataHashes; + bytes32[2][] memory expectedCalldataHashes = context + .expectations + .expectedContractOrderCalldataHashes; for (uint256 i; i < context.executionState.orders.length; i++) { AdvancedOrder memory order = context.executionState.orders[i]; if (order.parameters.orderType == OrderType.CONTRACT) { - bytes32 orderHash = - context.executionState.orderDetails[i].orderHash; + bytes32 orderHash = context + .executionState + .orderDetails[i] + .orderHash; - bytes32 expectedGenerateOrderCalldataHash = - expectedCalldataHashes[i][0]; + bytes32 expectedGenerateOrderCalldataHash = expectedCalldataHashes[ + i + ][0]; - bytes32 expectedRatifyOrderCalldataHash = - expectedCalldataHashes[i][1]; + bytes32 expectedRatifyOrderCalldataHash = expectedCalldataHashes[ + i + ][1]; contractOfferer = payable(order.parameters.offerer); - bytes32 actualGenerateOrderCalldataHash = - TestCalldataHashContractOfferer(contractOfferer) - .orderHashToGenerateOrderDataHash(orderHash); + bytes32 actualGenerateOrderCalldataHash = TestCalldataHashContractOfferer( + contractOfferer + ).orderHashToGenerateOrderDataHash(orderHash); - bytes32 actualRatifyOrderCalldataHash = - TestCalldataHashContractOfferer(contractOfferer) - .orderHashToRatifyOrderDataHash(orderHash); + bytes32 actualRatifyOrderCalldataHash = TestCalldataHashContractOfferer( + contractOfferer + ).orderHashToRatifyOrderDataHash(orderHash); assertEq( expectedGenerateOrderCalldataHash, @@ -279,15 +296,14 @@ abstract contract FuzzChecks is Test { for ( uint256 i; - ( - i < context.expectations.expectedExplicitExecutions.length - && i < context.returnValues.executions.length - ); + (i < context.expectations.expectedExplicitExecutions.length && + i < context.returnValues.executions.length); i++ ) { Execution memory actual = context.returnValues.executions[i]; - Execution memory expected = - context.expectations.expectedExplicitExecutions[i]; + Execution memory expected = context + .expectations + .expectedExplicitExecutions[i]; assertEq( uint256(actual.item.itemType), uint256(expected.item.itemType), @@ -319,7 +335,9 @@ abstract contract FuzzChecks is Test { "check_executions: conduitKey" ); assertEq( - actual.offerer, expected.offerer, "check_executions: offerer" + actual.offerer, + expected.offerer, + "check_executions: offerer" ); } } @@ -329,9 +347,9 @@ abstract contract FuzzChecks is Test { * * @param context A Fuzz test context. */ - function check_expectedTransferEventsEmitted(FuzzTestContext memory context) - public - { + function check_expectedTransferEventsEmitted( + FuzzTestContext memory context + ) public { ExpectedEventsUtil.checkExpectedTransferEvents(context); } @@ -340,9 +358,9 @@ abstract contract FuzzChecks is Test { * * @param context A Fuzz test context. */ - function check_expectedSeaportEventsEmitted(FuzzTestContext memory context) - public - { + function check_expectedSeaportEventsEmitted( + FuzzTestContext memory context + ) public { ExpectedEventsUtil.checkExpectedSeaportEvents(context); } @@ -351,10 +369,9 @@ abstract contract FuzzChecks is Test { * * @param context A Fuzz test context. */ - function check_expectedBalances(FuzzTestContext memory context) - public - view - { + function check_expectedBalances( + FuzzTestContext memory context + ) public view { context.testHelpers.balanceChecker().checkBalances(); } @@ -363,20 +380,24 @@ abstract contract FuzzChecks is Test { * * @param context A Fuzz test context. */ - function check_orderStatusFullyFilled(FuzzTestContext memory context) - public - { + function check_orderStatusFullyFilled( + FuzzTestContext memory context + ) public { for (uint256 i; i < context.executionState.orders.length; i++) { AdvancedOrder memory order = context.executionState.orders[i]; - bytes32 orderHash = context.executionState.orderDetails[i].orderHash; + bytes32 orderHash = context + .executionState + .orderDetails[i] + .orderHash; - (,, uint256 totalFilled, uint256 totalSize) = - context.seaport.getOrderStatus(orderHash); + (, , uint256 totalFilled, uint256 totalSize) = context + .seaport + .getOrderStatus(orderHash); if ( - context.executionState.preExecOrderStatuses[i] - == OrderStatusEnum.FULFILLED + context.executionState.preExecOrderStatuses[i] == + OrderStatusEnum.FULFILLED ) { assertEq( totalFilled, @@ -384,45 +405,55 @@ abstract contract FuzzChecks is Test { "check_orderStatusFullyFilled: totalFilled != 1" ); assertEq( - totalSize, 1, "check_orderStatusFullyFilled: totalSize != 1" + totalSize, + 1, + "check_orderStatusFullyFilled: totalSize != 1" ); } else if ( - context.executionState.preExecOrderStatuses[i] - == OrderStatusEnum.PARTIAL + context.executionState.preExecOrderStatuses[i] == + OrderStatusEnum.PARTIAL ) { if ( - context.executionState.orderDetails[i].unavailableReason - == UnavailableReason.AVAILABLE + context.executionState.orderDetails[i].unavailableReason == + UnavailableReason.AVAILABLE ) { assertEq( totalFilled, - context.expectations.expectedFillFractions[i] + context + .expectations + .expectedFillFractions[i] .finalFilledNumerator, "check_orderStatusFullyFilled: totalFilled != expected partial" ); assertEq( totalSize, - context.expectations.expectedFillFractions[i] + context + .expectations + .expectedFillFractions[i] .finalFilledDenominator, "check_orderStatusFullyFilled: totalSize != expected partial" ); } else { assertEq( totalFilled, - context.expectations.expectedFillFractions[i] + context + .expectations + .expectedFillFractions[i] .originalStatusNumerator, "check_orderStatusFullyFilled: totalFilled != expected partial (skipped)" ); assertEq( totalSize, - context.expectations.expectedFillFractions[i] + context + .expectations + .expectedFillFractions[i] .originalStatusDenominator, "check_orderStatusFullyFilled: totalSize != expected partial (skipped)" ); } } else if ( - context.executionState.orderDetails[i].unavailableReason - == UnavailableReason.AVAILABLE + context.executionState.orderDetails[i].unavailableReason == + UnavailableReason.AVAILABLE ) { if (order.parameters.orderType == OrderType.CONTRACT) { // TODO: This just checks the nonce has been incremented @@ -436,8 +467,8 @@ abstract contract FuzzChecks is Test { uint256 contractOffererSpecificContractNonce = context .executionState - .contractOffererNonce - + uint256(uint160(order.parameters.offerer)); + .contractOffererNonce + + uint256(uint160(order.parameters.offerer)); assertTrue( currentNonce - contractOffererSpecificContractNonce > 0, @@ -455,7 +486,10 @@ abstract contract FuzzChecks is Test { "FuzzChecks: totalSize != denominator" ); assertTrue(totalSize != 0, "FuzzChecks: totalSize != 0"); - assertTrue(totalFilled != 0, "FuzzChecks: totalFilled != 0"); + assertTrue( + totalFilled != 0, + "FuzzChecks: totalFilled != 0" + ); } } else { assertTrue( @@ -482,12 +516,16 @@ abstract contract FuzzChecks is Test { ) { // Only check orders that were validated pre-execution. if ( - context.executionState.preExecOrderStatuses[i] - == OrderStatusEnum.VALIDATED + context.executionState.preExecOrderStatuses[i] == + OrderStatusEnum.VALIDATED ) { - bytes32 orderHash = - context.executionState.orderDetails[i].orderHash; - (bool isValid,,,) = context.seaport.getOrderStatus(orderHash); + bytes32 orderHash = context + .executionState + .orderDetails[i] + .orderHash; + (bool isValid, , , ) = context.seaport.getOrderStatus( + orderHash + ); assertTrue(isValid, "check_ordersValidated: !isValid"); } } diff --git a/test/foundry/new/helpers/FuzzDerivers.sol b/test/foundry/new/helpers/FuzzDerivers.sol index 7d6ce6a..45e62b8 100644 --- a/test/foundry/new/helpers/FuzzDerivers.sol +++ b/test/foundry/new/helpers/FuzzDerivers.sol @@ -28,10 +28,13 @@ import { ItemType, OrderType } from "seaport-sol/src/SeaportEnums.sol"; import { ItemType } from "seaport-sol/src/SeaportEnums.sol"; import { - OrderStatusEnum, UnavailableReason + OrderStatusEnum, + UnavailableReason } from "seaport-sol/src/SpaceEnums.sol"; -import { ExecutionHelper } from "seaport-sol/src/executions/ExecutionHelper.sol"; +import { + ExecutionHelper +} from "seaport-sol/src/executions/ExecutionHelper.sol"; import { FulfillmentDetails, @@ -46,8 +49,9 @@ import { FuzzHelpers } from "./FuzzHelpers.sol"; import { CriteriaResolverHelper } from "./CriteriaResolverHelper.sol"; -import { FulfillmentGeneratorLib } from - "seaport-sol/src/fulfillments/lib/FulfillmentLib.sol"; +import { + FulfillmentGeneratorLib +} from "seaport-sol/src/fulfillments/lib/FulfillmentLib.sol"; /** * @dev "Derivers" examine generated orders and calculate additional @@ -75,10 +79,9 @@ library FuzzDerivers { * * @param context A Fuzz test context. */ - function withDerivedCallValue(FuzzTestContext memory context) - internal - returns (FuzzTestContext memory) - { + function withDerivedCallValue( + FuzzTestContext memory context + ) internal returns (FuzzTestContext memory) { (uint256 value, uint256 minimum) = context.getNativeTokensToSupply(); context.executionState.value = value; @@ -92,13 +95,12 @@ library FuzzDerivers { * * @param context A Fuzz test context. */ - function withDerivedCriteriaResolvers(FuzzTestContext memory context) - internal - view - returns (FuzzTestContext memory) - { - CriteriaResolverHelper criteriaResolverHelper = - context.testHelpers.criteriaResolverHelper(); + function withDerivedCriteriaResolvers( + FuzzTestContext memory context + ) internal view returns (FuzzTestContext memory) { + CriteriaResolverHelper criteriaResolverHelper = context + .testHelpers + .criteriaResolverHelper(); CriteriaResolver[] memory criteriaResolvers = criteriaResolverHelper .deriveCriteriaResolvers(context.executionState.orders); @@ -113,18 +115,18 @@ library FuzzDerivers { * * @param context A Fuzz test context. */ - function withDerivedOrderDetails(FuzzTestContext memory context) - internal - view - returns (FuzzTestContext memory) - { + function withDerivedOrderDetails( + FuzzTestContext memory context + ) internal view returns (FuzzTestContext memory) { UnavailableReason[] memory unavailableReasons = new UnavailableReason[]( context.advancedOrdersSpace.orders.length ); for (uint256 i; i < context.advancedOrdersSpace.orders.length; ++i) { - unavailableReasons[i] = - context.advancedOrdersSpace.orders[i].unavailableReason; + unavailableReasons[i] = context + .advancedOrdersSpace + .orders[i] + .unavailableReason; } bytes32[] memory orderHashes = context @@ -136,10 +138,10 @@ library FuzzDerivers { .executionState .previewedOrders .getOrderDetails( - context.executionState.criteriaResolvers, - orderHashes, - unavailableReasons - ); + context.executionState.criteriaResolvers, + orderHashes, + unavailableReasons + ); context.executionState.orderDetails = orderDetails; @@ -149,41 +151,59 @@ library FuzzDerivers { // unavailable reason in orderDetails, update orderDetails. This could // probably be removed at some point. for (uint256 i; i < context.executionState.orders.length; ++i) { - OrderParameters memory order = - context.executionState.orders[i].parameters; - OrderStatusEnum status = - context.executionState.preExecOrderStatuses[i]; + OrderParameters memory order = context + .executionState + .orders[i] + .parameters; + OrderStatusEnum status = context + .executionState + .preExecOrderStatuses[i]; // The only one of these that should get hit is the max fulfilled // branch. The rest are just for safety for now and should be // removed at some point. if ( - context.executionState.orderDetails[i].unavailableReason - == UnavailableReason.AVAILABLE + context.executionState.orderDetails[i].unavailableReason == + UnavailableReason.AVAILABLE ) { if (!(block.timestamp < order.endTime)) { - context.executionState.orderDetails[i].unavailableReason = - UnavailableReason.EXPIRED; + context + .executionState + .orderDetails[i] + .unavailableReason = UnavailableReason.EXPIRED; } else if (!(block.timestamp >= order.startTime)) { - context.executionState.orderDetails[i].unavailableReason = - UnavailableReason.STARTS_IN_FUTURE; + context + .executionState + .orderDetails[i] + .unavailableReason = UnavailableReason.STARTS_IN_FUTURE; } else if ( - status == OrderStatusEnum.CANCELLED_EXPLICIT - || status == OrderStatusEnum.CANCELLED_COUNTER + status == OrderStatusEnum.CANCELLED_EXPLICIT || + status == OrderStatusEnum.CANCELLED_COUNTER ) { - context.executionState.orderDetails[i].unavailableReason = - UnavailableReason.CANCELLED; + context + .executionState + .orderDetails[i] + .unavailableReason = UnavailableReason.CANCELLED; } else if (status == OrderStatusEnum.FULFILLED) { - context.executionState.orderDetails[i].unavailableReason = - UnavailableReason.ALREADY_FULFILLED; + context + .executionState + .orderDetails[i] + .unavailableReason = UnavailableReason + .ALREADY_FULFILLED; } else if (status == OrderStatusEnum.REVERT) { - context.executionState.orderDetails[i].unavailableReason = - UnavailableReason.GENERATE_ORDER_FAILURE; + context + .executionState + .orderDetails[i] + .unavailableReason = UnavailableReason + .GENERATE_ORDER_FAILURE; } else if ( !(totalAvailable < context.executionState.maximumFulfilled) ) { - context.executionState.orderDetails[i].unavailableReason = - UnavailableReason.MAX_FULFILLED_SATISFIED; + context + .executionState + .orderDetails[i] + .unavailableReason = UnavailableReason + .MAX_FULFILLED_SATISFIED; } else { totalAvailable += 1; } @@ -224,6 +244,7 @@ library FuzzDerivers { considerationFulfillments, fulfillments, remainingOfferComponents, + ) = orderDetails.getFulfillments( context.advancedOrdersSpace.strategy, context.executionState.caller, @@ -239,29 +260,33 @@ library FuzzDerivers { * * @param context A Fuzz test context. */ - function withDerivedFulfillments(FuzzTestContext memory context) - internal - pure - returns (FuzzTestContext memory) - { + function withDerivedFulfillments( + FuzzTestContext memory context + ) internal pure returns (FuzzTestContext memory) { // Derive the required fulfillment arrays. ( FulfillmentComponent[][] memory offerFulfillments, FulfillmentComponent[][] memory considerationFulfillments, Fulfillment[] memory fulfillments, MatchComponent[] memory remainingOfferComponents - ) = getDerivedFulfillments(context, context.executionState.orderDetails); + ) = getDerivedFulfillments( + context, + context.executionState.orderDetails + ); // For the fulfillAvailable functions, set the offerFullfillments // and considerationFulfillments arrays. context.executionState.offerFulfillments = offerFulfillments; - context.executionState.considerationFulfillments = - considerationFulfillments; + context + .executionState + .considerationFulfillments = considerationFulfillments; // For match, set fulfillment and remaining offer component arrays. context.executionState.fulfillments = fulfillments; - context.executionState.remainingOfferComponents = - remainingOfferComponents.toFulfillmentComponents(); + context + .executionState + .remainingOfferComponents = remainingOfferComponents + .toFulfillmentComponents(); return context; } @@ -288,29 +313,31 @@ library FuzzDerivers { bytes4 action = context.action(); if ( - action == context.seaport.fulfillOrder.selector - || action == context.seaport.fulfillAdvancedOrder.selector + action == context.seaport.fulfillOrder.selector || + action == context.seaport.fulfillAdvancedOrder.selector ) { // For the fulfill functions, derive the expected implicit // (standard) executions. There are no explicit executions here // because the caller doesn't pass in fulfillments for these // functions. (implicitExecutionsPost, nativeTokensReturned) = context - .toFulfillmentDetails(nativeTokensSupplied).getStandardExecutions(); + .toFulfillmentDetails(nativeTokensSupplied) + .getStandardExecutions(); } else if ( - action == context.seaport.fulfillBasicOrder.selector - || action - == context.seaport.fulfillBasicOrder_efficient_6GL6yc.selector + action == context.seaport.fulfillBasicOrder.selector || + action == + context.seaport.fulfillBasicOrder_efficient_6GL6yc.selector ) { // For the fulfillBasic functions, derive the expected implicit // (basic) executions. There are no explicit executions here // because the caller doesn't pass in fulfillments for these // functions. (implicitExecutionsPost, nativeTokensReturned) = context - .toFulfillmentDetails(nativeTokensSupplied).getBasicExecutions(); + .toFulfillmentDetails(nativeTokensSupplied) + .getBasicExecutions(); } else if ( - action == context.seaport.fulfillAvailableOrders.selector - || action == context.seaport.fulfillAvailableAdvancedOrders.selector + action == context.seaport.fulfillAvailableOrders.selector || + action == context.seaport.fulfillAvailableAdvancedOrders.selector ) { // For the fulfillAvailable functions, derive the expected implicit // and explicit executions. @@ -319,12 +346,13 @@ library FuzzDerivers { implicitExecutionsPre, implicitExecutionsPost, nativeTokensReturned - ) = context.toFulfillmentDetails(nativeTokensSupplied) + ) = context + .toFulfillmentDetails(nativeTokensSupplied) .getFulfillAvailableExecutions( - context.executionState.offerFulfillments, - context.executionState.considerationFulfillments, - context.executionState.orderDetails - ); + context.executionState.offerFulfillments, + context.executionState.considerationFulfillments, + context.executionState.orderDetails + ); // TEMP (TODO: handle upstream) assume( @@ -338,8 +366,8 @@ library FuzzDerivers { ); } } else if ( - action == context.seaport.matchOrders.selector - || action == context.seaport.matchAdvancedOrders.selector + action == context.seaport.matchOrders.selector || + action == context.seaport.matchAdvancedOrders.selector ) { // For the match functions, derive the expected implicit and // explicit executions. @@ -348,7 +376,8 @@ library FuzzDerivers { implicitExecutionsPre, implicitExecutionsPost, nativeTokensReturned - ) = context.toFulfillmentDetails(nativeTokensSupplied) + ) = context + .toFulfillmentDetails(nativeTokensSupplied) .getMatchExecutions(context.executionState.fulfillments); } } @@ -369,30 +398,31 @@ library FuzzDerivers { ) { if ( - context.action() == context.seaport.fulfillOrder.selector - || context.action() == context.seaport.fulfillAdvancedOrder.selector + context.action() == context.seaport.fulfillOrder.selector || + context.action() == context.seaport.fulfillAdvancedOrder.selector ) { // For the fulfill functions, derive the expected implicit // (standard) executions. There are no explicit executions here // because the caller doesn't pass in fulfillments for these // functions. - (implicitExecutionsPost, nativeTokensReturned) = - details.getStandardExecutions(); + (implicitExecutionsPost, nativeTokensReturned) = details + .getStandardExecutions(); } else if ( - context.action() == context.seaport.fulfillBasicOrder.selector - || context.action() - == context.seaport.fulfillBasicOrder_efficient_6GL6yc.selector + context.action() == context.seaport.fulfillBasicOrder.selector || + context.action() == + context.seaport.fulfillBasicOrder_efficient_6GL6yc.selector ) { // For the fulfillBasic functions, derive the expected implicit // (basic) executions. There are no explicit executions here // because the caller doesn't pass in fulfillments for these // functions. - (implicitExecutionsPost, nativeTokensReturned) = - details.getBasicExecutions(); + (implicitExecutionsPost, nativeTokensReturned) = details + .getBasicExecutions(); } else if ( - context.action() == context.seaport.fulfillAvailableOrders.selector - || context.action() - == context.seaport.fulfillAvailableAdvancedOrders.selector + context.action() == + context.seaport.fulfillAvailableOrders.selector || + context.action() == + context.seaport.fulfillAvailableAdvancedOrders.selector ) { // For the fulfillAvailable functions, derive the expected implicit // and explicit executions. @@ -419,8 +449,8 @@ library FuzzDerivers { ); } } else if ( - context.action() == context.seaport.matchOrders.selector - || context.action() == context.seaport.matchAdvancedOrders.selector + context.action() == context.seaport.matchOrders.selector || + context.action() == context.seaport.matchAdvancedOrders.selector ) { // For the match functions, derive the expected implicit and // explicit executions. @@ -460,15 +490,17 @@ library FuzzDerivers { FulfillmentComponent[][] memory offerFulfillments, FulfillmentComponent[][] memory considerationFulfillments, Fulfillment[] memory fulfillments, + ) = getDerivedFulfillments(context, details.orders); - return getDerivedExecutionsFromDirectInputs( - context, - details, - offerFulfillments, - considerationFulfillments, - fulfillments - ); + return + getDerivedExecutionsFromDirectInputs( + context, + details, + offerFulfillments, + considerationFulfillments, + fulfillments + ); } /** @@ -477,29 +509,32 @@ library FuzzDerivers { * * @param context A Fuzz test context. */ - function withDerivedExecutions(FuzzTestContext memory context) - internal - returns (FuzzTestContext memory) - { + function withDerivedExecutions( + FuzzTestContext memory context + ) internal returns (FuzzTestContext memory) { ( Execution[] memory explicitExecutions, Execution[] memory implicitExecutionsPre, Execution[] memory implicitExecutionsPost, uint256 nativeTokensReturned ) = getDerivedExecutions(context, context.executionState.value); - context.expectations.expectedImplicitPreExecutions = - implicitExecutionsPre; - context.expectations.expectedImplicitPostExecutions = - implicitExecutionsPost; + context + .expectations + .expectedImplicitPreExecutions = implicitExecutionsPre; + context + .expectations + .expectedImplicitPostExecutions = implicitExecutionsPost; context.expectations.expectedExplicitExecutions = explicitExecutions; - context.expectations.expectedNativeTokensReturned = nativeTokensReturned; + context + .expectations + .expectedNativeTokensReturned = nativeTokensReturned; bytes4 action = context.action(); if ( - action == context.seaport.fulfillAvailableOrders.selector - || action == context.seaport.fulfillAvailableAdvancedOrders.selector - || action == context.seaport.matchOrders.selector - || action == context.seaport.matchAdvancedOrders.selector + action == context.seaport.fulfillAvailableOrders.selector || + action == context.seaport.fulfillAvailableAdvancedOrders.selector || + action == context.seaport.matchOrders.selector || + action == context.seaport.matchAdvancedOrders.selector ) { uint256 expectedImpliedNativeExecutions = 0; @@ -515,7 +550,8 @@ library FuzzDerivers { } context.expectations.expectedImpliedNativeExecutions = - expectedImpliedNativeExecutions - nativeTokensReturned; + expectedImpliedNativeExecutions - + nativeTokensReturned; } return context; @@ -536,13 +572,14 @@ library FulfillmentDetailsHelper { ? caller : context.executionState.recipient; - return FulfillmentDetails({ - orders: context.executionState.orderDetails, - recipient: payable(recipient), - fulfiller: payable(caller), - nativeTokensSupplied: nativeTokensSupplied, - fulfillerConduitKey: context.executionState.fulfillerConduitKey, - seaport: address(context.seaport) - }); + return + FulfillmentDetails({ + orders: context.executionState.orderDetails, + recipient: payable(recipient), + fulfiller: payable(caller), + nativeTokensSupplied: nativeTokensSupplied, + fulfillerConduitKey: context.executionState.fulfillerConduitKey, + seaport: address(context.seaport) + }); } } diff --git a/test/foundry/new/helpers/FuzzEngine.sol b/test/foundry/new/helpers/FuzzEngine.sol index 2e69b6b..02d0d9f 100644 --- a/test/foundry/new/helpers/FuzzEngine.sol +++ b/test/foundry/new/helpers/FuzzEngine.sol @@ -29,11 +29,13 @@ import { import { SeaportInterface } from "seaport-sol/src/SeaportInterface.sol"; -import { ConduitControllerInterface } from - "seaport-sol/src/ConduitControllerInterface.sol"; +import { + ConduitControllerInterface +} from "seaport-sol/src/ConduitControllerInterface.sol"; -import { ConduitControllerInterface } from - "seaport-sol/src/ConduitControllerInterface.sol"; +import { + ConduitControllerInterface +} from "seaport-sol/src/ConduitControllerInterface.sol"; import { BaseOrderTest } from "../BaseOrderTest.sol"; import { SeaportValidatorTest } from "../SeaportValidatorTest.sol"; @@ -86,14 +88,17 @@ import { ValidationConfiguration } from "../../../../src/main/helpers/order-validator/SeaportValidator.sol"; -import { IssueStringHelpers } from - "../../../../src/main/helpers/order-validator/lib/SeaportValidatorTypes.sol"; +import { + IssueStringHelpers +} from "../../../../src/main/helpers/order-validator/lib/SeaportValidatorTypes.sol"; -import { NavigatorRequest } from - "../../../../src/main/helpers/navigator/lib/SeaportNavigatorTypes.sol"; +import { + NavigatorRequest +} from "../../../../src/main/helpers/navigator/lib/SeaportNavigatorTypes.sol"; -import { NavigatorAdvancedOrderLib } from - "../../../../src/main/helpers/navigator/lib/NavigatorAdvancedOrderLib.sol"; +import { + NavigatorAdvancedOrderLib +} from "../../../../src/main/helpers/navigator/lib/NavigatorAdvancedOrderLib.sol"; import { FulfillmentStrategy, @@ -289,10 +294,9 @@ contract FuzzEngine is * * @param fuzzParams A FuzzParams struct containing fuzzed values. */ - function generate(FuzzParams memory fuzzParams) - internal - returns (FuzzTestContext memory) - { + function generate( + FuzzParams memory fuzzParams + ) internal returns (FuzzTestContext memory) { // JAN_1_2023_UTC vm.warp(1672531200); @@ -305,13 +309,13 @@ contract FuzzEngine is // the rest of the lifecycle. FuzzGeneratorContext memory generatorContext = FuzzGeneratorContextLib .from({ - vm: vm, - seaport: getSeaport(), - conduitController: conduitController_, - erc20s: erc20s, - erc721s: erc721s, - erc1155s: erc1155s - }); + vm: vm, + seaport: getSeaport(), + conduitController: conduitController_, + erc20s: erc20s, + erc721s: erc721s, + erc1155s: erc1155s + }); // Generate a pseudorandom order space. The `AdvancedOrdersSpace` is // made up of an `OrderComponentsSpace` array and an `isMatchable` bool. @@ -327,39 +331,49 @@ contract FuzzEngine is generatorContext ); - generatorContext.caller = - AdvancedOrdersSpaceGenerator.generateCaller(space, generatorContext); + generatorContext.caller = AdvancedOrdersSpaceGenerator.generateCaller( + space, + generatorContext + ); // Generate orders from the space. These are the actual orders that will // be used in the test. - AdvancedOrder[] memory orders = - AdvancedOrdersSpaceGenerator.generate(space, generatorContext); - - FuzzTestContext memory context = FuzzTestContextLib.from({ - orders: orders, - seaport: getSeaport() - }).withConduitController(conduitController_).withSeaportValidator( - validator - ).withSeaportNavigator(navigator).withFuzzParams(fuzzParams) - .withMaximumFulfilled(space.maximumFulfilled).withPreExecOrderStatuses( - space + AdvancedOrder[] memory orders = AdvancedOrdersSpaceGenerator.generate( + space, + generatorContext ); + FuzzTestContext memory context = FuzzTestContextLib + .from({ orders: orders, seaport: getSeaport() }) + .withConduitController(conduitController_) + .withSeaportValidator(validator) + .withSeaportNavigator(navigator) + .withFuzzParams(fuzzParams) + .withMaximumFulfilled(space.maximumFulfilled) + .withPreExecOrderStatuses(space); + // This is on a separate line to avoid stack too deep. - context = context.withCounter(generatorContext.counter) + context = context + .withCounter(generatorContext.counter) .withContractOffererNonce(generatorContext.contractOffererNonce) - .withCaller(generatorContext.caller).withFulfillerConduitKey( - AdvancedOrdersSpaceGenerator.generateFulfillerConduitKey( - space, generatorContext + .withCaller(generatorContext.caller) + .withFulfillerConduitKey( + AdvancedOrdersSpaceGenerator.generateFulfillerConduitKey( + space, + generatorContext + ) ) - ).withGeneratorContext(generatorContext).withSpace(space); + .withGeneratorContext(generatorContext) + .withSpace(space); // If it's an advanced order, generate and add a top-level recipient. - if (orders.getStructure(address(context.seaport)) == Structure.ADVANCED) - { + if ( + orders.getStructure(address(context.seaport)) == Structure.ADVANCED + ) { context = context.withRecipient( AdvancedOrdersSpaceGenerator.generateRecipient( - space, generatorContext + space, + generatorContext ) ); } @@ -398,10 +412,14 @@ contract FuzzEngine is * @param context A Fuzz test context. */ function runDerivers(FuzzTestContext memory context) internal { - context = context.withDerivedCriteriaResolvers().withDerivedOrderDetails( - ).withDetectedRemainders().withDerivedFulfillments() - .withDerivedCallValue().withDerivedExecutions().withDerivedOrderDetails( - ); + context = context + .withDerivedCriteriaResolvers() + .withDerivedOrderDetails() + .withDetectedRemainders() + .withDerivedFulfillments() + .withDerivedCallValue() + .withDerivedExecutions() + .withDerivedOrderDetails(); } /** @@ -462,18 +480,22 @@ contract FuzzEngine is logMutation(name); - bytes memory callData = - abi.encodeWithSelector(mutationSelector, context, mutationState); + bytes memory callData = abi.encodeWithSelector( + mutationSelector, + context, + mutationState + ); (bool success, bytes memory data) = address(mutations).call(callData); assertFalse( - success, string.concat("Mutation ", name, " did not revert") + success, + string.concat("Mutation ", name, " did not revert") ); if ( - data.length == 4 - && abi.decode(abi.encodePacked(data, uint224(0)), (bytes4)) - == MutationEligibilityLib.NoEligibleIndexFound.selector + data.length == 4 && + abi.decode(abi.encodePacked(data, uint224(0)), (bytes4)) == + MutationEligibilityLib.NoEligibleIndexFound.selector ) { assertTrue( false, @@ -515,17 +537,17 @@ contract FuzzEngine is context.executionState.validationErrors[i] = context .seaportValidator .isValidOrderWithConfiguration( - ValidationConfiguration({ - seaport: address(context.seaport), - primaryFeeRecipient: address(0), - primaryFeeBips: 0, - checkCreatorFee: false, - skipStrictValidation: true, - shortOrderDuration: 30 minutes, - distantOrderExpiration: 26 weeks - }), - order - ); + ValidationConfiguration({ + seaport: address(context.seaport), + primaryFeeRecipient: address(0), + primaryFeeBips: 0, + checkCreatorFee: false, + skipStrictValidation: true, + shortOrderDuration: 30 minutes, + distantOrderExpiration: 26 weeks + }), + order + ); } } } @@ -541,8 +563,8 @@ contract FuzzEngine is bool isContractOrder; for (uint256 i; i < context.executionState.orders.length; i++) { if ( - context.executionState.orders[i].parameters.orderType - == OrderType.CONTRACT + context.executionState.orders[i].parameters.orderType == + OrderType.CONTRACT ) { isContractOrder = true; break; @@ -550,30 +572,34 @@ contract FuzzEngine is } if (!isContractOrder) { - FulfillmentStrategy memory fulfillmentStrategy = - FulfillmentStrategy({ - aggregationStrategy: AggregationStrategy.RANDOM, - fulfillAvailableStrategy: FulfillAvailableStrategy - .DROP_RANDOM_OFFER, - matchStrategy: MatchStrategy.MAX_INCLUSION - }); + FulfillmentStrategy + memory fulfillmentStrategy = FulfillmentStrategy({ + aggregationStrategy: AggregationStrategy.RANDOM, + fulfillAvailableStrategy: FulfillAvailableStrategy + .DROP_RANDOM_OFFER, + matchStrategy: MatchStrategy.MAX_INCLUSION + }); context.seaportNavigator.prepare( NavigatorRequest({ seaport: context.seaport, validator: context.seaportValidator, orders: NavigatorAdvancedOrderLib.fromAdvancedOrders( context.executionState.orders - ), + ), caller: context.executionState.caller, nativeTokensSupplied: context.executionState.value, fulfillerConduitKey: context .executionState .fulfillerConduitKey, recipient: context.executionState.recipient, - maximumFulfilled: context.executionState.maximumFulfilled, + maximumFulfilled: context + .executionState + .maximumFulfilled, seed: context.fuzzParams.seed, fulfillmentStrategy: fulfillmentStrategy, - criteriaResolvers: context.executionState.criteriaResolvers, + criteriaResolvers: context + .executionState + .criteriaResolvers, preferMatch: true }) ); diff --git a/test/foundry/new/helpers/FuzzEngineLib.sol b/test/foundry/new/helpers/FuzzEngineLib.sol index d9aaaf1..816fb5e 100644 --- a/test/foundry/new/helpers/FuzzEngineLib.sol +++ b/test/foundry/new/helpers/FuzzEngineLib.sol @@ -38,8 +38,9 @@ import { FuzzTestContext } from "./FuzzTestContextLib.sol"; import { FuzzDerivers } from "./FuzzDerivers.sol"; -import { DefaultFulfillmentGeneratorLib } from - "seaport-sol/src/fulfillments/lib/FulfillmentLib.sol"; +import { + DefaultFulfillmentGeneratorLib +} from "seaport-sol/src/fulfillments/lib/FulfillmentLib.sol"; /** * @notice Stateless helpers for FuzzEngine. The FuzzEngine uses functions in @@ -66,18 +67,15 @@ library FuzzEngineLib { * @param context A Fuzz test context. * @return bytes4 selector of a SeaportInterface function. */ - function action(FuzzTestContext memory context) - internal - view - returns (bytes4) - { + function action( + FuzzTestContext memory context + ) internal view returns (bytes4) { if (context.actionSelected) return context._action; bytes4[] memory _actions = actions(context); context.actionSelected = true; - return ( - context._action = - _actions[context.fuzzParams.seed % _actions.length] - ); + return (context._action = _actions[ + context.fuzzParams.seed % _actions.length + ]); } /** @@ -86,11 +84,9 @@ library FuzzEngineLib { * @param context A Fuzz test context. * @return string name of the selected action. */ - function actionName(FuzzTestContext memory context) - internal - view - returns (string memory) - { + function actionName( + FuzzTestContext memory context + ) internal view returns (string memory) { bytes4 selector = action(context); if (selector == 0xe7acab24) return "fulfillAdvancedOrder"; if (selector == 0x87201b41) return "fulfillAvailableAdvancedOrders"; @@ -112,25 +108,27 @@ library FuzzEngineLib { * @param context A Fuzz test context. * @return bytes4[] of SeaportInterface function selectors. */ - function actions(FuzzTestContext memory context) - internal - view - returns (bytes4[] memory) - { + function actions( + FuzzTestContext memory context + ) internal view returns (bytes4[] memory) { Family family = context.executionState.orders.getFamily(); bool containsOrderThatDemandsMatch = mustUseMatch(context); - Structure structure = - context.executionState.orders.getStructure(address(context.seaport)); + Structure structure = context.executionState.orders.getStructure( + address(context.seaport) + ); - bool hasUnavailable = context.executionState.maximumFulfilled - < context.executionState.orders.length; - for (uint256 i = 0; i < context.executionState.orderDetails.length; ++i) - { + bool hasUnavailable = context.executionState.maximumFulfilled < + context.executionState.orders.length; + for ( + uint256 i = 0; + i < context.executionState.orderDetails.length; + ++i + ) { if ( - context.executionState.orderDetails[i].unavailableReason - != UnavailableReason.AVAILABLE + context.executionState.orderDetails[i].unavailableReason != + UnavailableReason.AVAILABLE ) { hasUnavailable = true; break; @@ -146,14 +144,18 @@ library FuzzEngineLib { if (structure == Structure.ADVANCED) { bytes4[] memory selectors = new bytes4[](1); - selectors[0] = - context.seaport.fulfillAvailableAdvancedOrders.selector; + selectors[0] = context + .seaport + .fulfillAvailableAdvancedOrders + .selector; return selectors; } else { bytes4[] memory selectors = new bytes4[](2); selectors[0] = context.seaport.fulfillAvailableOrders.selector; - selectors[1] = - context.seaport.fulfillAvailableAdvancedOrders.selector; + selectors[1] = context + .seaport + .fulfillAvailableAdvancedOrders + .selector; return selectors; } } @@ -164,11 +166,15 @@ library FuzzEngineLib { selectors[0] = context.seaport.fulfillOrder.selector; selectors[1] = context.seaport.fulfillAdvancedOrder.selector; selectors[2] = context.seaport.fulfillBasicOrder.selector; - selectors[3] = - context.seaport.fulfillBasicOrder_efficient_6GL6yc.selector; + selectors[3] = context + .seaport + .fulfillBasicOrder_efficient_6GL6yc + .selector; selectors[4] = context.seaport.fulfillAvailableOrders.selector; - selectors[5] = - context.seaport.fulfillAvailableAdvancedOrders.selector; + selectors[5] = context + .seaport + .fulfillAvailableAdvancedOrders + .selector; return selectors; } @@ -177,22 +183,26 @@ library FuzzEngineLib { selectors[0] = context.seaport.fulfillOrder.selector; selectors[1] = context.seaport.fulfillAdvancedOrder.selector; selectors[2] = context.seaport.fulfillAvailableOrders.selector; - selectors[3] = - context.seaport.fulfillAvailableAdvancedOrders.selector; + selectors[3] = context + .seaport + .fulfillAvailableAdvancedOrders + .selector; return selectors; } if (structure == Structure.ADVANCED) { bytes4[] memory selectors = new bytes4[](2); selectors[0] = context.seaport.fulfillAdvancedOrder.selector; - selectors[1] = - context.seaport.fulfillAvailableAdvancedOrders.selector; + selectors[1] = context + .seaport + .fulfillAvailableAdvancedOrders + .selector; return selectors; } } - bool cannotMatch = - (context.executionState.hasRemainders || hasUnavailable); + bool cannotMatch = (context.executionState.hasRemainders || + hasUnavailable); if (cannotMatch && containsOrderThatDemandsMatch) { revert("FuzzEngineLib: cannot fulfill provided combined order"); @@ -201,14 +211,18 @@ library FuzzEngineLib { if (cannotMatch) { if (structure == Structure.ADVANCED) { bytes4[] memory selectors = new bytes4[](1); - selectors[0] = - context.seaport.fulfillAvailableAdvancedOrders.selector; + selectors[0] = context + .seaport + .fulfillAvailableAdvancedOrders + .selector; return selectors; } else { bytes4[] memory selectors = new bytes4[](2); selectors[0] = context.seaport.fulfillAvailableOrders.selector; - selectors[1] = - context.seaport.fulfillAvailableAdvancedOrders.selector; + selectors[1] = context + .seaport + .fulfillAvailableAdvancedOrders + .selector; //selectors[2] = context.seaport.cancel.selector; //selectors[3] = context.seaport.validate.selector; return selectors; @@ -227,15 +241,19 @@ library FuzzEngineLib { } else { if (structure == Structure.ADVANCED) { bytes4[] memory selectors = new bytes4[](2); - selectors[0] = - context.seaport.fulfillAvailableAdvancedOrders.selector; + selectors[0] = context + .seaport + .fulfillAvailableAdvancedOrders + .selector; selectors[1] = context.seaport.matchAdvancedOrders.selector; return selectors; } else { bytes4[] memory selectors = new bytes4[](4); selectors[0] = context.seaport.fulfillAvailableOrders.selector; - selectors[1] = - context.seaport.fulfillAvailableAdvancedOrders.selector; + selectors[1] = context + .seaport + .fulfillAvailableAdvancedOrders + .selector; selectors[2] = context.seaport.matchOrders.selector; selectors[3] = context.seaport.matchAdvancedOrders.selector; //selectors[4] = context.seaport.cancel.selector; @@ -253,11 +271,9 @@ library FuzzEngineLib { * @param context A Fuzz test context. * @return bool whether a matching function will be called. */ - function mustUseMatch(FuzzTestContext memory context) - internal - pure - returns (bool) - { + function mustUseMatch( + FuzzTestContext memory context + ) internal pure returns (bool) { OrderDetails[] memory orders = context.executionState.orderDetails; for (uint256 i = 0; i < orders.length; ++i) { @@ -295,13 +311,13 @@ library FuzzEngineLib { l < comparisonOrder.consideration.length; ++l ) { - ReceivedItem memory considerationItem = - comparisonOrder.consideration[l]; + ReceivedItem memory considerationItem = comparisonOrder + .consideration[l]; if ( - considerationItem.itemType == ItemType.ERC721 - && considerationItem.identifier == item.identifier - && considerationItem.token == item.token + considerationItem.itemType == ItemType.ERC721 && + considerationItem.identifier == item.identifier && + considerationItem.token == item.token ) { return true; } @@ -320,29 +336,33 @@ library FuzzEngineLib { * @return value The amount of native tokens to supply. * @return minimum The minimum amount of native tokens to supply. */ - function getNativeTokensToSupply(FuzzTestContext memory context) - internal - returns (uint256 value, uint256 minimum) - { - bool isMatch = action(context) - == context.seaport.matchAdvancedOrders.selector - || action(context) == context.seaport.matchOrders.selector; + function getNativeTokensToSupply( + FuzzTestContext memory context + ) internal returns (uint256 value, uint256 minimum) { + bool isMatch = action(context) == + context.seaport.matchAdvancedOrders.selector || + action(context) == context.seaport.matchOrders.selector; uint256 valueToCreditBack = 0; - for (uint256 i = 0; i < context.executionState.orderDetails.length; ++i) - { + for ( + uint256 i = 0; + i < context.executionState.orderDetails.length; + ++i + ) { OrderDetails memory order = context.executionState.orderDetails[i]; - OrderParameters memory orderParams = - context.executionState.previewedOrders[i].parameters; + OrderParameters memory orderParams = context + .executionState + .previewedOrders[i] + .parameters; if (isMatch) { for (uint256 j = 0; j < order.offer.length; ++j) { SpentItem memory item = order.offer[j]; if ( - item.itemType == ItemType.NATIVE - && orderParams.orderType != OrderType.CONTRACT + item.itemType == ItemType.NATIVE && + orderParams.orderType != OrderType.CONTRACT ) { value += item.amount; } @@ -382,20 +402,19 @@ library FuzzEngineLib { } } - function getMinimumNativeTokensToSupply(FuzzTestContext memory context) - internal - returns (uint256) - { + function getMinimumNativeTokensToSupply( + FuzzTestContext memory context + ) internal returns (uint256) { bytes4 _action = action(context); if ( - _action == context.seaport.fulfillBasicOrder.selector - || _action - == context.seaport.fulfillBasicOrder_efficient_6GL6yc.selector + _action == context.seaport.fulfillBasicOrder.selector || + _action == + context.seaport.fulfillBasicOrder_efficient_6GL6yc.selector ) { // TODO: handle OOR orders or items just in case if ( - context.executionState.orderDetails[0].offer[0].itemType - == ItemType.ERC20 + context.executionState.orderDetails[0].offer[0].itemType == + ItemType.ERC20 ) { // Basic order bids cannot supply any native tokens return 0; @@ -403,8 +422,9 @@ library FuzzEngineLib { } uint256 hugeCallValue = uint256(type(uint128).max); - (,,, uint256 nativeTokensReturned) = - context.getDerivedExecutions(hugeCallValue); + (, , , uint256 nativeTokensReturned) = context.getDerivedExecutions( + hugeCallValue + ); if (nativeTokensReturned > hugeCallValue) { return 0; @@ -416,13 +436,13 @@ library FuzzEngineLib { /** * @dev Determine whether or not an order configuration has remainders. */ - function withDetectedRemainders(FuzzTestContext memory context) - internal - pure - returns (FuzzTestContext memory) - { - (,, MatchComponent[] memory remainders) = - context.executionState.orderDetails.getMatchedFulfillments(); + function withDetectedRemainders( + FuzzTestContext memory context + ) internal pure returns (FuzzTestContext memory) { + (, , MatchComponent[] memory remainders) = context + .executionState + .orderDetails + .getMatchedFulfillments(); context.executionState.hasRemainders = remainders.length != 0; diff --git a/test/foundry/new/helpers/FuzzExecutor.sol b/test/foundry/new/helpers/FuzzExecutor.sol index f6ef9bd..cf449d0 100644 --- a/test/foundry/new/helpers/FuzzExecutor.sol +++ b/test/foundry/new/helpers/FuzzExecutor.sol @@ -104,12 +104,14 @@ abstract contract FuzzExecutor is Test { BasicOrderParameters memory basicOrderParameters = context .executionState - .orders[0].toBasicOrderParameters( - context.executionState.orders[0].getBasicOrderType() - ); + .orders[0] + .toBasicOrderParameters( + context.executionState.orders[0].getBasicOrderType() + ); - basicOrderParameters.fulfillerConduitKey = - context.executionState.fulfillerConduitKey; + basicOrderParameters.fulfillerConduitKey = context + .executionState + .fulfillerConduitKey; if (context.executionState.caller != address(0)) { vm.prank(context.executionState.caller); @@ -118,19 +120,21 @@ abstract contract FuzzExecutor is Test { value: context.executionState.value }(basicOrderParameters); } else if ( - _action - == context.seaport.fulfillBasicOrder_efficient_6GL6yc.selector + _action == + context.seaport.fulfillBasicOrder_efficient_6GL6yc.selector ) { logCall("fulfillBasicOrder_efficient", logCalls); BasicOrderParameters memory basicOrderParameters = context .executionState - .orders[0].toBasicOrderParameters( - context.executionState.orders[0].getBasicOrderType() - ); + .orders[0] + .toBasicOrderParameters( + context.executionState.orders[0].getBasicOrderType() + ); - basicOrderParameters.fulfillerConduitKey = - context.executionState.fulfillerConduitKey; + basicOrderParameters.fulfillerConduitKey = context + .executionState + .fulfillerConduitKey; if (context.executionState.caller != address(0)) { vm.prank(context.executionState.caller); @@ -145,16 +149,18 @@ abstract contract FuzzExecutor is Test { if (context.executionState.caller != address(0)) { vm.prank(context.executionState.caller); } - (bool[] memory availableOrders, Execution[] memory executions) = - context.seaport.fulfillAvailableOrders{ - value: context.executionState.value - }( - context.executionState.orders.toOrders(), - context.executionState.offerFulfillments, - context.executionState.considerationFulfillments, - context.executionState.fulfillerConduitKey, - context.executionState.maximumFulfilled - ); + ( + bool[] memory availableOrders, + Execution[] memory executions + ) = context.seaport.fulfillAvailableOrders{ + value: context.executionState.value + }( + context.executionState.orders.toOrders(), + context.executionState.offerFulfillments, + context.executionState.considerationFulfillments, + context.executionState.fulfillerConduitKey, + context.executionState.maximumFulfilled + ); context.returnValues.availableOrders = availableOrders; context.returnValues.executions = executions; @@ -165,18 +171,20 @@ abstract contract FuzzExecutor is Test { if (context.executionState.caller != address(0)) { vm.prank(context.executionState.caller); } - (bool[] memory availableOrders, Execution[] memory executions) = - context.seaport.fulfillAvailableAdvancedOrders{ - value: context.executionState.value - }( - context.executionState.orders, - context.executionState.criteriaResolvers, - context.executionState.offerFulfillments, - context.executionState.considerationFulfillments, - context.executionState.fulfillerConduitKey, - context.executionState.recipient, - context.executionState.maximumFulfilled - ); + ( + bool[] memory availableOrders, + Execution[] memory executions + ) = context.seaport.fulfillAvailableAdvancedOrders{ + value: context.executionState.value + }( + context.executionState.orders, + context.executionState.criteriaResolvers, + context.executionState.offerFulfillments, + context.executionState.considerationFulfillments, + context.executionState.fulfillerConduitKey, + context.executionState.recipient, + context.executionState.maximumFulfilled + ); context.returnValues.availableOrders = availableOrders; context.returnValues.executions = executions; @@ -217,7 +225,8 @@ abstract contract FuzzExecutor is Test { for (uint256 i; i < orders.length; ++i) { AdvancedOrder memory order = orders[i]; - orderComponents[i] = order.toOrder() + orderComponents[i] = order + .toOrder() .parameters .toOrderComponents(context.executionState.counter); } @@ -225,8 +234,9 @@ abstract contract FuzzExecutor is Test { if (context.executionState.caller != address(0)) { vm.prank(context.executionState.caller); } - context.returnValues.cancelled = - context.seaport.cancel(orderComponents); + context.returnValues.cancelled = context.seaport.cancel( + orderComponents + ); } else if (_action == context.seaport.validate.selector) { logCall("validate", logCalls); if (context.executionState.caller != address(0)) { diff --git a/test/foundry/new/helpers/FuzzGeneratorContextLib.sol b/test/foundry/new/helpers/FuzzGeneratorContextLib.sol index dbded40..f08993c 100644 --- a/test/foundry/new/helpers/FuzzGeneratorContextLib.sol +++ b/test/foundry/new/helpers/FuzzGeneratorContextLib.sol @@ -24,8 +24,9 @@ import { SeaportInterface } from "seaport-sol/src/SeaportInterface.sol"; import { EIP1271Offerer } from "./EIP1271Offerer.sol"; -import { ConduitControllerInterface } from - "seaport-sol/src/ConduitControllerInterface.sol"; +import { + ConduitControllerInterface +} from "seaport-sol/src/ConduitControllerInterface.sol"; import { TestHelpers } from "./FuzzTestContextLib.sol"; @@ -35,16 +36,19 @@ import { TestERC721 } from "../../../../src/main/test/TestERC721.sol"; import { TestERC1155 } from "../../../../src/main/test/TestERC1155.sol"; -import { HashValidationZoneOfferer } from - "../../../../src/main/test/HashValidationZoneOfferer.sol"; +import { + HashValidationZoneOfferer +} from "../../../../src/main/test/HashValidationZoneOfferer.sol"; -import { HashCalldataContractOfferer } from - "../../../../src/main/test/HashCalldataContractOfferer.sol"; +import { + HashCalldataContractOfferer +} from "../../../../src/main/test/HashCalldataContractOfferer.sol"; import { Conduit } from "seaport-core/src/conduit/Conduit.sol"; -import { HashValidationZoneOfferer } from - "../../../../src/main/test/HashValidationZoneOfferer.sol"; +import { + HashValidationZoneOfferer +} from "../../../../src/main/test/HashValidationZoneOfferer.sol"; import { setLabel } from "./Labeler.sol"; @@ -99,38 +103,42 @@ library FuzzGeneratorContextLib { TestHelpers testHelpers = TestHelpers(address(this)); - return FuzzGeneratorContext({ - vm: Vm(address(0)), - seaport: SeaportInterface(address(0)), - conduitController: ConduitControllerInterface(address(0)), - erc20s: new TestERC20[](0), - erc721s: new TestERC721[](0), - erc1155s: new TestERC1155[](0), - prng: prng, - testHelpers: testHelpers, - timestamp: block.timestamp, - validatorZone: new HashValidationZoneOfferer(address(0)), - contractOfferer: new HashCalldataContractOfferer(address(0)), - eip1271Offerer: new EIP1271Offerer(), - self: address(this), - caller: address(this), - alice: testHelpers.makeAccountWrapper("alice"), - bob: testHelpers.makeAccountWrapper("bob"), - carol: testHelpers.makeAccountWrapper("carol"), - dillon: testHelpers.makeAccountWrapper("dillon"), - eve: testHelpers.makeAccountWrapper("eve"), - frank: testHelpers.makeAccountWrapper("frank"), - conduits: new TestConduit[](2), - starting721offerIndex: 0, - starting721considerationIndex: 0, - potential1155TokenIds: potential1155TokenIds, - basicOrderCategory: BasicOrderCategory.NONE, - basicOfferSpace: OfferItemSpace( - ItemType.NATIVE, TokenIndex.ONE, Criteria.MERKLE, Amount.FIXED + return + FuzzGeneratorContext({ + vm: Vm(address(0)), + seaport: SeaportInterface(address(0)), + conduitController: ConduitControllerInterface(address(0)), + erc20s: new TestERC20[](0), + erc721s: new TestERC721[](0), + erc1155s: new TestERC1155[](0), + prng: prng, + testHelpers: testHelpers, + timestamp: block.timestamp, + validatorZone: new HashValidationZoneOfferer(address(0)), + contractOfferer: new HashCalldataContractOfferer(address(0)), + eip1271Offerer: new EIP1271Offerer(), + self: address(this), + caller: address(this), + alice: testHelpers.makeAccountWrapper("alice"), + bob: testHelpers.makeAccountWrapper("bob"), + carol: testHelpers.makeAccountWrapper("carol"), + dillon: testHelpers.makeAccountWrapper("dillon"), + eve: testHelpers.makeAccountWrapper("eve"), + frank: testHelpers.makeAccountWrapper("frank"), + conduits: new TestConduit[](2), + starting721offerIndex: 0, + starting721considerationIndex: 0, + potential1155TokenIds: potential1155TokenIds, + basicOrderCategory: BasicOrderCategory.NONE, + basicOfferSpace: OfferItemSpace( + ItemType.NATIVE, + TokenIndex.ONE, + Criteria.MERKLE, + Amount.FIXED ), - counter: 0, - contractOffererNonce: 0 - }); + counter: 0, + contractOffererNonce: 0 + }); } /** @@ -165,8 +173,7 @@ library FuzzGeneratorContextLib { HashValidationZoneOfferer validatorZone = new HashValidationZoneOfferer( address(0) ); - HashCalldataContractOfferer contractOfferer = - new HashCalldataContractOfferer( + HashCalldataContractOfferer contractOfferer = new HashCalldataContractOfferer( address(seaport) ); EIP1271Offerer eip1271Offerer = new EIP1271Offerer(); @@ -175,38 +182,42 @@ library FuzzGeneratorContextLib { setLabel(address(contractOfferer), "contractOfferer"); setLabel(address(eip1271Offerer), "eip1271Offerer"); - return FuzzGeneratorContext({ - vm: vm, - seaport: seaport, - conduitController: conduitController, - erc20s: erc20s, - erc721s: erc721s, - erc1155s: erc1155s, - prng: prng, - testHelpers: testHelpers, - timestamp: block.timestamp, - validatorZone: validatorZone, - contractOfferer: contractOfferer, - eip1271Offerer: eip1271Offerer, - self: address(this), - caller: address(this), - alice: testHelpers.makeAccountWrapper("alice"), - bob: testHelpers.makeAccountWrapper("bob"), - carol: testHelpers.makeAccountWrapper("carol"), - dillon: testHelpers.makeAccountWrapper("dillon"), - eve: testHelpers.makeAccountWrapper("eve"), - frank: testHelpers.makeAccountWrapper("frank"), - conduits: conduits, - starting721offerIndex: 0, - starting721considerationIndex: 0, - potential1155TokenIds: potential1155TokenIds, - basicOrderCategory: BasicOrderCategory.NONE, - basicOfferSpace: OfferItemSpace( - ItemType.NATIVE, TokenIndex.ONE, Criteria.MERKLE, Amount.FIXED + return + FuzzGeneratorContext({ + vm: vm, + seaport: seaport, + conduitController: conduitController, + erc20s: erc20s, + erc721s: erc721s, + erc1155s: erc1155s, + prng: prng, + testHelpers: testHelpers, + timestamp: block.timestamp, + validatorZone: validatorZone, + contractOfferer: contractOfferer, + eip1271Offerer: eip1271Offerer, + self: address(this), + caller: address(this), + alice: testHelpers.makeAccountWrapper("alice"), + bob: testHelpers.makeAccountWrapper("bob"), + carol: testHelpers.makeAccountWrapper("carol"), + dillon: testHelpers.makeAccountWrapper("dillon"), + eve: testHelpers.makeAccountWrapper("eve"), + frank: testHelpers.makeAccountWrapper("frank"), + conduits: conduits, + starting721offerIndex: 0, + starting721considerationIndex: 0, + potential1155TokenIds: potential1155TokenIds, + basicOrderCategory: BasicOrderCategory.NONE, + basicOfferSpace: OfferItemSpace( + ItemType.NATIVE, + TokenIndex.ONE, + Criteria.MERKLE, + Amount.FIXED ), - counter: 0, - contractOffererNonce: 0 - }); + counter: 0, + contractOffererNonce: 0 + }); } /** @@ -217,12 +228,17 @@ library FuzzGeneratorContextLib { SeaportInterface seaport, uint96 conduitSalt ) internal returns (TestConduit memory) { - bytes32 conduitKey = - abi.decode(abi.encodePacked(address(this), conduitSalt), (bytes32)); - Conduit conduit = - Conduit(conduitController.createConduit(conduitKey, address(this))); + bytes32 conduitKey = abi.decode( + abi.encodePacked(address(this), conduitSalt), + (bytes32) + ); + Conduit conduit = Conduit( + conduitController.createConduit(conduitKey, address(this)) + ); conduitController.updateChannel( - address(conduit), address(seaport), true + address(conduit), + address(seaport), + true ); return TestConduit({ addr: address(conduit), key: conduitKey }); } diff --git a/test/foundry/new/helpers/FuzzGenerators.sol b/test/foundry/new/helpers/FuzzGenerators.sol index 7209ae3..5458109 100644 --- a/test/foundry/new/helpers/FuzzGenerators.sol +++ b/test/foundry/new/helpers/FuzzGenerators.sol @@ -54,8 +54,9 @@ import { import { SeaportInterface } from "seaport-sol/src/SeaportInterface.sol"; -import { ConduitControllerInterface } from - "seaport-sol/src/ConduitControllerInterface.sol"; +import { + ConduitControllerInterface +} from "seaport-sol/src/ConduitControllerInterface.sol"; import { AdvancedOrdersSpace, @@ -67,10 +68,15 @@ import { import { EIP712MerkleTree } from "../../utils/EIP712MerkleTree.sol"; import { - FuzzGeneratorContext, TestConduit + FuzzGeneratorContext, + TestConduit } from "./FuzzGeneratorContextLib.sol"; -import { _locateCurrentAmount, FuzzHelpers, Structure } from "./FuzzHelpers.sol"; +import { + _locateCurrentAmount, + FuzzHelpers, + Structure +} from "./FuzzHelpers.sol"; import { FuzzInscribers } from "./FuzzInscribers.sol"; @@ -155,8 +161,7 @@ library TestStateGenerator { for (uint256 i; i < totalOrders; ++i) { UnavailableReason reason = ( context.randRange(0, 1) == 0 - ? UnavailableReason.AVAILABLE // Don't fuzz 5 (maxfulfilled satisfied), since it's a more // of a consequence (to be handled in derivers) than a - // target. + ? UnavailableReason.AVAILABLE // Don't fuzz 5 (maxfulfilled satisfied), since it's a more // of a consequence (to be handled in derivers) than a // target. : UnavailableReason( context.choice(Solarray.uint256s(1, 2, 3, 4, 6)) ) @@ -173,15 +178,17 @@ library TestStateGenerator { zone: Zone(context.randEnum(0, 1)), offer: generateOffer(maxOfferItemsPerOrder, context), consideration: generateConsideration( - maxConsiderationItemsPerOrder, context, false - ), + maxConsiderationItemsPerOrder, + context, + false + ), orderType: BroadOrderType(context.randEnum(0, 2)), // NOTE: unavailable times are inserted downstream. time: Time(context.randEnum(1, 2)), zoneHash: ZoneHash(context.randEnum(0, 2)), signatureMethod: SignatureMethod( context.choice(Solarray.uint256s(0, 1, 4)) - ), + ), eoaSignatureType: EOASignature(context.randEnum(0, 3)), bulkSigHeight: bulkSigHeight, bulkSigIndex: context.randRange(0, 2 ** bulkSigHeight - 1), @@ -198,10 +205,10 @@ library TestStateGenerator { components[i].signatureMethod == SignatureMethod.CONTRACT; components[i].tips = Tips.NONE; if ( - components[i].unavailableReason - == UnavailableReason.ALREADY_FULFILLED - || components[i].unavailableReason - == UnavailableReason.CANCELLED + components[i].unavailableReason == + UnavailableReason.ALREADY_FULFILLED || + components[i].unavailableReason == + UnavailableReason.CANCELLED ) { components[i].unavailableReason = UnavailableReason( context.choice(Solarray.uint256s(1, 2, 6)) @@ -216,32 +223,35 @@ library TestStateGenerator { components[i].offer[j].criteria = Criteria.MERKLE; } - for (uint256 j = 0; j < components[i].consideration.length; ++j) - { + for ( + uint256 j = 0; + j < components[i].consideration.length; + ++j + ) { components[i].consideration[j].amount = Amount.FIXED; // TODO: support offerer returning other recipients. - components[i].consideration[j].recipient = Recipient.OFFERER; + components[i].consideration[j].recipient = Recipient + .OFFERER; // TODO: support wildcard resolution (note that the // contract offerer needs to resolve these itself) components[i].consideration[j].criteria = Criteria.MERKLE; } if ( - components[i].consideration.length == 0 - && ( - components[i].rebate - == ContractOrderRebate.LESS_CONSIDERATION_ITEMS - || components[i].rebate - == ContractOrderRebate.LESS_CONSIDERATION_ITEM_AMOUNTS - ) + components[i].consideration.length == 0 && + (components[i].rebate == + ContractOrderRebate.LESS_CONSIDERATION_ITEMS || + components[i].rebate == + ContractOrderRebate.LESS_CONSIDERATION_ITEM_AMOUNTS) ) { - components[i].rebate = - ContractOrderRebate(context.randEnum(0, 2)); + components[i].rebate = ContractOrderRebate( + context.randEnum(0, 2) + ); } if ( - components[i].rebate - == ContractOrderRebate.LESS_CONSIDERATION_ITEM_AMOUNTS + components[i].rebate == + ContractOrderRebate.LESS_CONSIDERATION_ITEM_AMOUNTS ) { bool canReduceAmounts; for ( @@ -249,11 +259,12 @@ library TestStateGenerator { j < components[i].consideration.length; ++j ) { - ItemType itemType = - components[i].consideration[j].itemType; + ItemType itemType = components[i] + .consideration[j] + .itemType; if ( - itemType != ItemType.ERC721 - && itemType != ItemType.ERC721_WITH_CRITERIA + itemType != ItemType.ERC721 && + itemType != ItemType.ERC721_WITH_CRITERIA ) { // NOTE: theoretically there could still be items with amount 1 // that would not be eligible for reducing consideration amounts. @@ -263,21 +274,22 @@ library TestStateGenerator { } if (!canReduceAmounts) { - components[i].rebate = - ContractOrderRebate(context.randEnum(0, 3)); + components[i].rebate = ContractOrderRebate( + context.randEnum(0, 3) + ); } } if ( - components[i].rebate - == ContractOrderRebate.MORE_OFFER_ITEM_AMOUNTS + components[i].rebate == + ContractOrderRebate.MORE_OFFER_ITEM_AMOUNTS ) { bool canIncreaseAmounts; for (uint256 j = 0; j < components[i].offer.length; ++j) { ItemType itemType = components[i].offer[j].itemType; if ( - itemType != ItemType.ERC721 - && itemType != ItemType.ERC721_WITH_CRITERIA + itemType != ItemType.ERC721 && + itemType != ItemType.ERC721_WITH_CRITERIA ) { canIncreaseAmounts = true; break; @@ -296,26 +308,28 @@ library TestStateGenerator { // TODO: figure out how to support removing criteria items // (just need to filter removed items out of resolvers) if ( - components[i].rebate - == ContractOrderRebate.LESS_CONSIDERATION_ITEMS + components[i].rebate == + ContractOrderRebate.LESS_CONSIDERATION_ITEMS ) { - ItemType itemType = components[i].consideration[components[i] - .consideration - .length - 1].itemType; + ItemType itemType = components[i] + .consideration[components[i].consideration.length - 1] + .itemType; if ( - itemType == ItemType.ERC721_WITH_CRITERIA - || itemType == ItemType.ERC1155_WITH_CRITERIA + itemType == ItemType.ERC721_WITH_CRITERIA || + itemType == ItemType.ERC1155_WITH_CRITERIA ) { - components[i].rebate = - ContractOrderRebate(context.randEnum(0, 1)); + components[i].rebate = ContractOrderRebate( + context.randEnum(0, 1) + ); } } } else if ( - components[i].unavailableReason - == UnavailableReason.GENERATE_ORDER_FAILURE + components[i].unavailableReason == + UnavailableReason.GENERATE_ORDER_FAILURE ) { - components[i].unavailableReason = - UnavailableReason(context.randEnum(1, 4)); + components[i].unavailableReason = UnavailableReason( + context.randEnum(1, 4) + ); } if (components[i].offerer == Offerer.EIP1271) { @@ -324,16 +338,18 @@ library TestStateGenerator { } if (!someAvailable) { - components[context.randRange(0, totalOrders - 1)].unavailableReason - = UnavailableReason.AVAILABLE; + components[context.randRange(0, totalOrders - 1)] + .unavailableReason = UnavailableReason.AVAILABLE; } - FulfillmentStrategy memory strategy = - (DefaultFulfillmentGeneratorLib.getDefaultFulfillmentStrategy()); + FulfillmentStrategy memory strategy = ( + DefaultFulfillmentGeneratorLib.getDefaultFulfillmentStrategy() + ); { - strategy.aggregationStrategy = - AggregationStrategy(context.randEnum(0, 2)); + strategy.aggregationStrategy = AggregationStrategy( + context.randEnum(0, 2) + ); strategy.fulfillAvailableStrategy = FulfillAvailableStrategy( context.randEnum(0, 3) // TODO: fuzz on filterable as well @@ -344,15 +360,16 @@ library TestStateGenerator { ); } - return AdvancedOrdersSpace({ - orders: components, - isMatchable: isMatchable, - maximumFulfilled: maximumFulfilled, - recipient: FulfillmentRecipient(context.randEnum(0, 3)), - conduit: ConduitChoice(context.randEnum(0, 2)), - caller: Caller(context.randEnum(0, 6)), - strategy: strategy - }); + return + AdvancedOrdersSpace({ + orders: components, + isMatchable: isMatchable, + maximumFulfilled: maximumFulfilled, + recipient: FulfillmentRecipient(context.randEnum(0, 3)), + conduit: ConduitChoice(context.randEnum(0, 2)), + caller: Caller(context.randEnum(0, 6)), + strategy: strategy + }); } function generateOffer( @@ -369,7 +386,7 @@ library TestStateGenerator { context.randRange(0, 10) != 0 ? context.randEnum(0, 3) : context.randEnum(4, 5) - ), + ), tokenIndex: TokenIndex(context.randEnum(0, 2)), criteria: Criteria(context.randEnum(0, 1)), amount: Amount(context.randEnum(0, 2)) @@ -384,7 +401,7 @@ library TestStateGenerator { context.basicOrderCategory == BasicOrderCategory.LISTING ? context.randEnum(2, 3) : 1 - ), + ), tokenIndex: TokenIndex(context.randEnum(0, 2)), criteria: Criteria(0), amount: Amount(context.randEnum(0, 2)) @@ -410,8 +427,8 @@ library TestStateGenerator { : maxConsiderationItemsPerOrder ); - ConsiderationItemSpace[] memory consideration = - new ConsiderationItemSpace[](len); + ConsiderationItemSpace[] + memory consideration = new ConsiderationItemSpace[](len); if (!isBasic) { for (uint256 i; i < len; ++i) { @@ -420,7 +437,7 @@ library TestStateGenerator { context.randRange(0, 10) != 0 ? context.randEnum(0, 3) : context.randEnum(4, 5) - ), + ), tokenIndex: TokenIndex(context.randEnum(0, 2)), criteria: Criteria(context.randEnum(0, 1)), amount: atLeastOne @@ -437,12 +454,12 @@ library TestStateGenerator { context.basicOrderCategory == BasicOrderCategory.BID ? context.randEnum(2, 3) : context.randEnum(0, 1) - ), + ), tokenIndex: TokenIndex(context.randEnum(0, 2)), criteria: Criteria(0), amount: Amount.FIXED, // Always fixed recipient: Recipient.OFFERER // Always offerer - }); + }); for (uint256 i = 1; i < len; ++i) { consideration[i] = ConsiderationItemSpace({ @@ -462,15 +479,17 @@ library TestStateGenerator { } function empty() internal pure returns (AdvancedOrdersSpace memory) { - return AdvancedOrdersSpace({ - orders: new OrderComponentsSpace[](0), - isMatchable: false, - maximumFulfilled: 0, - recipient: FulfillmentRecipient.ZERO, - conduit: ConduitChoice.NONE, - caller: Caller.TEST_CONTRACT, - strategy: DefaultFulfillmentGeneratorLib.getDefaultFulfillmentStrategy() - }); + return + AdvancedOrdersSpace({ + orders: new OrderComponentsSpace[](0), + isMatchable: false, + maximumFulfilled: 0, + recipient: FulfillmentRecipient.ZERO, + conduit: ConduitChoice.NONE, + caller: Caller.TEST_CONTRACT, + strategy: DefaultFulfillmentGeneratorLib + .getDefaultFulfillmentStrategy() + }); } } @@ -544,15 +563,17 @@ library AdvancedOrdersSpaceGenerator { OrderParameters memory orderParams = order.parameters; if ( - space.orders[i].tips == Tips.NONE - || orderParams.orderType == OrderType.CONTRACT + space.orders[i].tips == Tips.NONE || + orderParams.orderType == OrderType.CONTRACT ) { - orders[i].parameters.totalOriginalConsiderationItems = - (orders[i].parameters.consideration.length); + orders[i].parameters.totalOriginalConsiderationItems = ( + orders[i].parameters.consideration.length + ); } if (orderParams.orderType == OrderType.CONTRACT) { - order.parameters = orderParams.withOrderType(OrderType.CONTRACT) + order.parameters = orderParams + .withOrderType(OrderType.CONTRACT) .withOfferer(address(context.contractOfferer)); for (uint256 j = 0; j < orderParams.offer.length; ++j) { @@ -565,11 +586,12 @@ library AdvancedOrdersSpaceGenerator { } if ( - uint256(item.itemType) > 3 - && item.identifierOrCriteria == 0 + uint256(item.itemType) > 3 && + item.identifierOrCriteria == 0 ) { - order.parameters.offer[j].itemType = - ItemType(uint256(item.itemType) - 2); + order.parameters.offer[j].itemType = ItemType( + uint256(item.itemType) - 2 + ); bytes32 itemHash = keccak256( abi.encodePacked(uint256(i), uint256(j), Side.OFFER) ); @@ -581,36 +603,47 @@ library AdvancedOrdersSpaceGenerator { } for (uint256 j = 0; j < orderParams.consideration.length; ++j) { - ConsiderationItem memory item = - (orderParams.consideration[j]); + ConsiderationItem memory item = ( + orderParams.consideration[j] + ); if (item.startAmount != 0) { - order.parameters.consideration[j].endAmount = - (item.startAmount); + order.parameters.consideration[j].endAmount = ( + item.startAmount + ); } else { - order.parameters.consideration[j].startAmount = - (item.endAmount); + order.parameters.consideration[j].startAmount = ( + item.endAmount + ); } if ( - uint256(item.itemType) > 3 - && item.identifierOrCriteria == 0 + uint256(item.itemType) > 3 && + item.identifierOrCriteria == 0 ) { - order.parameters.consideration[j].itemType = - ItemType(uint256(item.itemType) - 2); + order.parameters.consideration[j].itemType = ItemType( + uint256(item.itemType) - 2 + ); bytes32 itemHash = keccak256( abi.encodePacked( - uint256(i), uint256(j), Side.CONSIDERATION + uint256(i), + uint256(j), + Side.CONSIDERATION ) ); - order.parameters.consideration[j].identifierOrCriteria = - context.testHelpers.criteriaResolverHelper() + order + .parameters + .consideration[j] + .identifierOrCriteria = context + .testHelpers + .criteriaResolverHelper() .wildcardIdentifierForGivenItemHash(itemHash); } // TODO: support offerer returning other recipients. - order.parameters.consideration[j].recipient = - payable(address(context.contractOfferer)); + order.parameters.consideration[j].recipient = payable( + address(context.contractOfferer) + ); } } } @@ -663,17 +696,18 @@ library AdvancedOrdersSpaceGenerator { OfferItem memory item = order.offer[j]; if (item.itemType == ItemType.NATIVE) { // Generate a new offer and make sure it has no native items - orders[i].parameters.offer[j] = - space.orders[i].offer[j].generate(context, true, i, j); + orders[i].parameters.offer[j] = space + .orders[i] + .offer[j] + .generate(context, true, i, j); } } } } - function _ensureAllAvailable(AdvancedOrdersSpace memory space) - internal - pure - { + function _ensureAllAvailable( + AdvancedOrdersSpace memory space + ) internal pure { for (uint256 i = 0; i < space.orders.length; ++i) { space.orders[i].unavailableReason = UnavailableReason.AVAILABLE; } @@ -690,12 +724,15 @@ library AdvancedOrdersSpaceGenerator { false, // ensureDirectSupport false: allow native offer items i ); - orders[i] = OrderLib.empty().withParameters(orderParameters) + orders[i] = OrderLib + .empty() + .withParameters(orderParameters) .toAdvancedOrder({ - numerator: 1, - denominator: 1, - extraData: bytes("") - }).withBroadOrderType(space.orders[i].orderType, context) + numerator: 1, + denominator: 1, + extraData: bytes("") + }) + .withBroadOrderType(space.orders[i].orderType, context) .withGeneratedExtraData(space.orders[i].extraData, context); } } @@ -707,7 +744,9 @@ library AdvancedOrdersSpaceGenerator { ) internal pure { for (uint256 i = 0; i < orders.length; ++i) { _adjustUnavailable( - orders[i], space.orders[i].unavailableReason, context + orders[i], + space.orders[i].unavailableReason, + context ); } } @@ -726,11 +765,14 @@ library AdvancedOrdersSpaceGenerator { // UnavailableReason.GENERATE_ORDER_FAILURE => handled downstream if (reason == UnavailableReason.EXPIRED) { parameters = parameters.withGeneratedTime( - Time(context.randEnum(3, 4)), context + Time(context.randEnum(3, 4)), + context ); } else if (reason == UnavailableReason.STARTS_IN_FUTURE) { - parameters = - parameters.withGeneratedTime(Time.STARTS_IN_FUTURE, context); + parameters = parameters.withGeneratedTime( + Time.STARTS_IN_FUTURE, + context + ); } } @@ -771,17 +813,22 @@ library AdvancedOrdersSpaceGenerator { } { - infra.resolvers = context.testHelpers.criteriaResolverHelper() + infra.resolvers = context + .testHelpers + .criteriaResolverHelper() .deriveCriteriaResolvers(orders); - bytes32[] memory orderHashes = - orders.getOrderHashes(address(context.seaport)); + bytes32[] memory orderHashes = orders.getOrderHashes( + address(context.seaport) + ); OrderDetails[] memory details = orders.getOrderDetails( - infra.resolvers, orderHashes, unavailableReasons + infra.resolvers, + orderHashes, + unavailableReasons ); // Get the remainders. - (,, infra.remainders) = details.getMatchedFulfillments(); + (, , infra.remainders) = details.getMatchedFulfillments(); } // Iterate over the remainders and insert them into the orders. @@ -792,21 +839,24 @@ library AdvancedOrdersSpaceGenerator { // Unpack the remainder from the MatchComponent into its // constituent parts. - (infra.amount, orderIndex, itemIndex) = - infra.remainders[i].unpack(); + (infra.amount, orderIndex, itemIndex) = infra + .remainders[i] + .unpack(); // Get the consideration item with the remainder. - infra.item = - orders[orderIndex].parameters.consideration[itemIndex]; + infra.item = orders[orderIndex].parameters.consideration[ + itemIndex + ]; infra.resolvedIdentifier = infra.item.identifierOrCriteria; infra.resolvedItemType = infra.item.itemType; if ( - infra.item.itemType == ItemType.ERC721_WITH_CRITERIA - || infra.item.itemType == ItemType.ERC1155_WITH_CRITERIA + infra.item.itemType == ItemType.ERC721_WITH_CRITERIA || + infra.item.itemType == ItemType.ERC1155_WITH_CRITERIA ) { - infra.resolvedItemType = - _convertCriteriaItemType(infra.item.itemType); + infra.resolvedItemType = _convertCriteriaItemType( + infra.item.itemType + ); if (infra.item.identifierOrCriteria == 0) { bytes32 itemHash = keccak256( abi.encodePacked( @@ -824,15 +874,18 @@ library AdvancedOrdersSpaceGenerator { .testHelpers .criteriaResolverHelper() .resolvableIdentifierForGivenCriteria( - infra.item.identifierOrCriteria - ).resolvedIdentifier; + infra.item.identifierOrCriteria + ) + .resolvedIdentifier; } } } // Pick a random order to insert the remainder into. - uint256 orderInsertionIndex = - context.randRange(0, orders.length - 1); + uint256 orderInsertionIndex = context.randRange( + 0, + orders.length - 1 + ); OfferItem memory newItem; { @@ -864,15 +917,17 @@ library AdvancedOrdersSpaceGenerator { // If the targeted order has an offer, pick a random index to // insert the remainder into. uint256 itemInsertionIndex = context.randRange( - 0, orders[orderInsertionIndex].parameters.offer.length - 1 + 0, + orders[orderInsertionIndex].parameters.offer.length - 1 ); // Copy the offer items from the targeted order into the new // offer array. This loop handles everything before the // insertion index. for (uint256 j = 0; j < itemInsertionIndex; ++j) { - newOffer[j] = - orders[orderInsertionIndex].parameters.offer[j]; + newOffer[j] = orders[orderInsertionIndex].parameters.offer[ + j + ]; } // Insert the remainder into the new offer array at the @@ -882,10 +937,13 @@ library AdvancedOrdersSpaceGenerator { // Copy the offer items after the insertion index into the new // offer array. for ( - uint256 j = itemInsertionIndex + 1; j < newOffer.length; ++j + uint256 j = itemInsertionIndex + 1; + j < newOffer.length; + ++j ) { - newOffer[j] = - orders[orderInsertionIndex].parameters.offer[j - 1]; + newOffer[j] = orders[orderInsertionIndex].parameters.offer[ + j - 1 + ]; } // shift any wildcard offer items. @@ -918,15 +976,20 @@ library AdvancedOrdersSpaceGenerator { // TODO: remove this check once high confidence in the mechanic has been // established (this just fails fast to rule out downstream issues) if (infra.remainders.length > 0) { - infra.resolvers = context.testHelpers.criteriaResolverHelper() + infra.resolvers = context + .testHelpers + .criteriaResolverHelper() .deriveCriteriaResolvers(orders); - bytes32[] memory orderHashes = - orders.getOrderHashes(address(context.seaport)); + bytes32[] memory orderHashes = orders.getOrderHashes( + address(context.seaport) + ); OrderDetails[] memory details = orders.getOrderDetails( - infra.resolvers, orderHashes, unavailableReasons + infra.resolvers, + orderHashes, + unavailableReasons ); // Get the remainders. - (,, infra.remainders) = details.getMatchedFulfillments(); + (, , infra.remainders) = details.getMatchedFulfillments(); if (infra.remainders.length > 0) { // NOTE: this may be caused by inserting offer items into orders @@ -937,11 +1000,9 @@ library AdvancedOrdersSpaceGenerator { } } - function _convertCriteriaItemType(ItemType itemType) - internal - pure - returns (ItemType) - { + function _convertCriteriaItemType( + ItemType itemType + ) internal pure returns (ItemType) { if (itemType == ItemType.ERC721_WITH_CRITERIA) { return ItemType.ERC721; } else if (itemType == ItemType.ERC1155_WITH_CRITERIA) { @@ -964,11 +1025,11 @@ library AdvancedOrdersSpaceGenerator { uint256 newAmountSansRounding = (amount * denominator) / numerator; - newAmount = newAmountSansRounding - + ( - (denominator - ((newAmountSansRounding * numerator) % denominator)) - / numerator - ); + newAmount = + newAmountSansRounding + + ((denominator - + ((newAmountSansRounding * numerator) % denominator)) / + numerator); if ((newAmount * numerator) % denominator != 0) { revert("AdvancedOrdersSpaceGenerator: inverse change failed"); @@ -990,8 +1051,9 @@ library AdvancedOrdersSpaceGenerator { // allEmpty to false and break out of the loop. for (uint256 i = 0; i < orders.length; ++i) { OrderParameters memory orderParams = orders[i].parameters; - if (orderParams.offer.length + orderParams.consideration.length > 0) - { + if ( + orderParams.offer.length + orderParams.consideration.length > 0 + ) { allEmpty = false; break; } @@ -1000,17 +1062,23 @@ library AdvancedOrdersSpaceGenerator { // If all the orders are empty, insert a consideration item into a // random order. if (allEmpty) { - uint256 orderInsertionIndex = - context.randRange(0, orders.length - 1); - OrderParameters memory orderParams = - orders[orderInsertionIndex].parameters; + uint256 orderInsertionIndex = context.randRange( + 0, + orders.length - 1 + ); + OrderParameters memory orderParams = orders[orderInsertionIndex] + .parameters; ConsiderationItem[] memory consideration = new ConsiderationItem[]( 1 ); - consideration[0] = TestStateGenerator.generateConsideration( - 1, context, true - )[0].generate(context, orderParams.offerer, orderInsertionIndex, 0); + consideration[0] = TestStateGenerator + .generateConsideration(1, context, true)[0].generate( + context, + orderParams.offerer, + orderInsertionIndex, + 0 + ); orderParams.consideration = consideration; } @@ -1036,17 +1104,23 @@ library AdvancedOrdersSpaceGenerator { // If all the orders are empty, insert a consideration item into a // random order. if (allEmpty) { - uint256 orderInsertionIndex = - context.randRange(0, orders.length - 1); - OrderParameters memory orderParams = - orders[orderInsertionIndex].parameters; + uint256 orderInsertionIndex = context.randRange( + 0, + orders.length - 1 + ); + OrderParameters memory orderParams = orders[orderInsertionIndex] + .parameters; ConsiderationItem[] memory consideration = new ConsiderationItem[]( 1 ); - consideration[0] = TestStateGenerator.generateConsideration( - 1, context, true - )[0].generate(context, orderParams.offerer, orderInsertionIndex, 0); + consideration[0] = TestStateGenerator + .generateConsideration(1, context, true)[0].generate( + context, + orderParams.offerer, + orderInsertionIndex, + 0 + ); orderParams.consideration = consideration; } @@ -1067,8 +1141,9 @@ library AdvancedOrdersSpaceGenerator { AdvancedOrdersSpace memory space ) internal { bool allFilterable = true; - address caller = - context.caller == address(0) ? address(this) : context.caller; + address caller = context.caller == address(0) + ? address(this) + : context.caller; // Iterate over the orders and check if there's a single instance of a // non-filterable consideration item. If there is, set allFilterable to @@ -1110,13 +1185,17 @@ library AdvancedOrdersSpaceGenerator { // consideration items. There's chance that no order will have // consideration items, in which case the orderParams variable will // be set to those of the last order iterated over. - uint256 orderInsertionIndex = - context.randRange(0, orders.length - 1); + uint256 orderInsertionIndex = context.randRange( + 0, + orders.length - 1 + ); for ( - ; orderInsertionIndex < orders.length * 2; ++orderInsertionIndex + ; + orderInsertionIndex < orders.length * 2; + ++orderInsertionIndex ) { - orderParams = - orders[orderInsertionIndex % orders.length].parameters; + orderParams = orders[orderInsertionIndex % orders.length] + .parameters; if (orderParams.consideration.length != 0) { break; @@ -1135,38 +1214,45 @@ library AdvancedOrdersSpaceGenerator { // Provision a new consideration item array with a single // element. - ConsiderationItem[] memory consideration = - new ConsiderationItem[](1); + ConsiderationItem[] + memory consideration = new ConsiderationItem[](1); // Generate a consideration item and add it to the consideration // item array. The `true` argument indicates that the // consideration item will be unfilterable. - consideration[0] = TestStateGenerator.generateConsideration( - 1, context, true - )[0].generate( - context, orderParams.offerer, orderInsertionIndex, 0 - ); + consideration[0] = TestStateGenerator + .generateConsideration(1, context, true)[0].generate( + context, + orderParams.offerer, + orderInsertionIndex, + 0 + ); // Set the consideration item array on the order parameters. orderParams.consideration = consideration; } - space.orders[orderInsertionIndex % orders.length].unavailableReason - = UnavailableReason.AVAILABLE; + space + .orders[orderInsertionIndex % orders.length] + .unavailableReason = UnavailableReason.AVAILABLE; // Pick a random consideration item to modify. - uint256 itemIndex = - context.randRange(0, orderParams.consideration.length - 1); + uint256 itemIndex = context.randRange( + 0, + orderParams.consideration.length - 1 + ); // Make the recipient an address other than the caller so that // it produces a non-filterable transfer. if (orderParams.orderType != OrderType.CONTRACT) { if (caller != context.alice.addr) { - orderParams.consideration[itemIndex].recipient = - payable(context.alice.addr); + orderParams.consideration[itemIndex].recipient = payable( + context.alice.addr + ); } else { - orderParams.consideration[itemIndex].recipient = - payable(context.bob.addr); + orderParams.consideration[itemIndex].recipient = payable( + context.bob.addr + ); } } } @@ -1191,12 +1277,15 @@ library AdvancedOrdersSpaceGenerator { // consideration items, in which case the orderParams variable will // be set to those of the last order iterated over. for ( - uint256 orderInsertionIndex = - context.randRange(0, orders.length - 1); + uint256 orderInsertionIndex = context.randRange( + 0, + orders.length - 1 + ); orderInsertionIndex < orders.length * 2; ++orderInsertionIndex ) { - orderParams = orders[orderInsertionIndex % orders.length].parameters; + orderParams = orders[orderInsertionIndex % orders.length] + .parameters; if (orderParams.consideration.length != 0) { break; @@ -1207,8 +1296,10 @@ library AdvancedOrdersSpaceGenerator { // add a consideration item to a random order. if (orderParams.consideration.length == 0) { // Pick a random order to insert the consideration item into. - uint256 orderInsertionIndex = - context.randRange(0, orders.length - 1); + uint256 orderInsertionIndex = context.randRange( + 0, + orders.length - 1 + ); // Set the orderParams variable to the parameters of the order // that was picked. @@ -1223,17 +1314,23 @@ library AdvancedOrdersSpaceGenerator { // Generate a consideration item and add it to the consideration // item array. The `true` argument indicates that the // consideration item will be unfilterable. - consideration[0] = TestStateGenerator.generateConsideration( - 1, context, true - )[0].generate(context, orderParams.offerer, orderInsertionIndex, 0); + consideration[0] = TestStateGenerator + .generateConsideration(1, context, true)[0].generate( + context, + orderParams.offerer, + orderInsertionIndex, + 0 + ); // Set the consideration item array on the order parameters. orderParams.consideration = consideration; } // Pick a random consideration item to modify. - uint256 itemIndex = - context.randRange(0, orderParams.consideration.length - 1); + uint256 itemIndex = context.randRange( + 0, + orderParams.consideration.length - 1 + ); // Make the recipient an address other than any offerer so that // it produces a non-filterable transfer. @@ -1257,8 +1354,8 @@ library AdvancedOrdersSpaceGenerator { // Skip contract orders since they do not have signatures if (order.parameters.orderType == OrderType.CONTRACT) { uint256 contractOffererSpecificContractNonce = context - .contractOffererNonce - + uint256(uint160(order.parameters.offerer)); + .contractOffererNonce + + uint256(uint160(order.parameters.offerer)); // Just for convenience of having them both in one place. FuzzInscribers.inscribeContractOffererNonce( order.parameters.offerer, @@ -1269,8 +1366,8 @@ library AdvancedOrdersSpaceGenerator { } // Get the counter for the offerer. - uint256 offererSpecificCounter = - context.counter + uint256(uint160(order.parameters.offerer)); + uint256 offererSpecificCounter = context.counter + + uint256(uint160(order.parameters.offerer)); FuzzInscribers.inscribeCounter( order.parameters.offerer, @@ -1279,7 +1376,8 @@ library AdvancedOrdersSpaceGenerator { ); bytes32 orderHash = order.getTipNeutralizedOrderHash( - context.seaport, offererSpecificCounter + context.seaport, + offererSpecificCounter ); // Replace the unsigned order with a signed order. @@ -1296,11 +1394,9 @@ library AdvancedOrdersSpaceGenerator { } } - function _hasInvalidNativeOfferItems(AdvancedOrder[] memory orders) - internal - pure - returns (bool) - { + function _hasInvalidNativeOfferItems( + AdvancedOrder[] memory orders + ) internal pure returns (bool) { for (uint256 i = 0; i < orders.length; ++i) { OrderParameters memory orderParams = orders[i].parameters; if (orderParams.orderType == OrderType.CONTRACT) { @@ -1341,8 +1437,8 @@ library OrderComponentsSpaceGenerator { uint256 orderIndex ) internal returns (OrderParameters memory) { if ( - space.offerer == Offerer.EIP1271 - && space.signatureMethod == SignatureMethod.EOA + space.offerer == Offerer.EIP1271 && + space.signatureMethod == SignatureMethod.EOA ) { space.signatureMethod = SignatureMethod.EIP1271; } @@ -1356,25 +1452,36 @@ library OrderComponentsSpaceGenerator { offerer = space.offerer.generate(context); } - params = OrderParametersLib.empty().withOfferer(offerer).withOffer( - space.offer.generate(context, ensureDirectSupport, orderIndex) - ).withConsideration( - space.consideration.generate(context, offerer, orderIndex) - ).withConduitKey(space.conduit.generate(context).key); + params = OrderParametersLib + .empty() + .withOfferer(offerer) + .withOffer( + space.offer.generate( + context, + ensureDirectSupport, + orderIndex + ) + ) + .withConsideration( + space.consideration.generate(context, offerer, orderIndex) + ) + .withConduitKey(space.conduit.generate(context).key); } // Choose an arbitrary number of tips based on the tip space // (TODO: refactor as a library function) params.totalOriginalConsiderationItems = ( (space.tips == Tips.TIPS && params.consideration.length != 0) - ? params.consideration.length - - context.randRange(1, params.consideration.length) + ? params.consideration.length - + context.randRange(1, params.consideration.length) : params.consideration.length ); - return params.withGeneratedTime(space.time, context).withGeneratedZone( - space.zone, context - ).withSalt(context.randRange(0, type(uint256).max)); + return + params + .withGeneratedTime(space.time, context) + .withGeneratedZone(space.zone, context) + .withSalt(context.randRange(0, type(uint256).max)); } } @@ -1388,7 +1495,10 @@ library ConduitGenerator { ) internal pure returns (TestConduit memory) { if (conduit == ConduitChoice.NONE) { return - TestConduit({ key: bytes32(0), addr: address(context.seaport) }); + TestConduit({ + key: bytes32(0), + addr: address(context.seaport) + }); } else if (conduit == ConduitChoice.ONE) { return context.conduits[0]; } else if (conduit == ConduitChoice.TWO) { @@ -1419,20 +1529,26 @@ library BroadOrderTypeGenerator { if (broadOrderType == BroadOrderType.PARTIAL) { // Adjust the order type based on whether it is restricted if (orderParams.orderType == OrderType.FULL_RESTRICTED) { - order.parameters = - orderParams.withOrderType(OrderType.PARTIAL_RESTRICTED); + order.parameters = orderParams.withOrderType( + OrderType.PARTIAL_RESTRICTED + ); } else if (orderParams.orderType == OrderType.FULL_OPEN) { - order.parameters = - orderParams.withOrderType(OrderType.PARTIAL_OPEN); + order.parameters = orderParams.withOrderType( + OrderType.PARTIAL_OPEN + ); } // TODO: get more sophisticated about this down the line uint120 numerator = uint120(context.randRange(1, type(uint80).max)); - uint120 denominator = - uint120(numerator * context.randRange(1, type(uint40).max)); + uint120 denominator = uint120( + numerator * context.randRange(1, type(uint40).max) + ); - return order.withNumerator(numerator).withDenominator(denominator) - .withCoercedAmountsForPartialFulfillment(); + return + order + .withNumerator(numerator) + .withDenominator(denominator) + .withCoercedAmountsForPartialFulfillment(); } else if (broadOrderType == BroadOrderType.CONTRACT) { order.parameters = orderParams.withOrderType(OrderType.CONTRACT); } @@ -1509,9 +1625,11 @@ library ZoneGenerator { } else if (zone == Zone.PASS) { // generate random zone hash bytes32 zoneHash = bytes32(context.randRange(0, type(uint256).max)); - return order.withOrderType(OrderType.FULL_RESTRICTED).withZone( - address(context.validatorZone) - ).withZoneHash(zoneHash); + return + order + .withOrderType(OrderType.FULL_RESTRICTED) + .withZone(address(context.validatorZone)) + .withZoneHash(zoneHash); } else { revert("ZoneGenerator: invalid Zone"); } @@ -1541,8 +1659,13 @@ library OfferItemSpaceGenerator { OfferItem[] memory offerItems = new OfferItem[](len); for (uint256 i; i < len; ++i) { - offerItems[i] = - generate(space[i], context, ensureDirectSupport, orderIndex, i); + offerItems[i] = generate( + space[i], + context, + ensureDirectSupport, + orderIndex, + i + ); } return offerItems; } @@ -1560,13 +1683,20 @@ library OfferItemSpaceGenerator { itemType = ItemType(context.randRange(1, 5)); } - OfferItem memory offerItem = OfferItemLib.empty().withItemType(itemType) + OfferItem memory offerItem = OfferItemLib + .empty() + .withItemType(itemType) .withToken(space.tokenIndex.generate(itemType, context)) .withGeneratedAmount(space.amount, context); - return offerItem.withGeneratedIdentifierOrCriteria( - itemType, space.criteria, context, orderIndex, itemIndex - ); + return + offerItem.withGeneratedIdentifierOrCriteria( + itemType, + space.criteria, + context, + orderIndex, + itemIndex + ); } } @@ -1595,8 +1725,13 @@ library ConsiderationItemSpaceGenerator { ); for (uint256 i; i < len; ++i) { - considerationItems[i] = - generate(space[i], context, offerer, orderIndex, i); + considerationItems[i] = generate( + space[i], + context, + offerer, + orderIndex, + i + ); } return considerationItems; @@ -1609,16 +1744,21 @@ library ConsiderationItemSpaceGenerator { uint256 orderIndex, uint256 itemIndex ) internal returns (ConsiderationItem memory) { - ConsiderationItem memory considerationItem = ConsiderationItemLib.empty( - ).withItemType(space.itemType).withToken( - space.tokenIndex.generate(space.itemType, context) - ).withGeneratedAmount(space.amount, context).withRecipient( - space.recipient.generate(context, offerer) - ); - - return considerationItem.withGeneratedIdentifierOrCriteria( - space.itemType, space.criteria, context, orderIndex, itemIndex - ); + ConsiderationItem memory considerationItem = ConsiderationItemLib + .empty() + .withItemType(space.itemType) + .withToken(space.tokenIndex.generate(space.itemType, context)) + .withGeneratedAmount(space.amount, context) + .withRecipient(space.recipient.generate(context, offerer)); + + return + considerationItem.withGeneratedIdentifierOrCriteria( + space.itemType, + space.criteria, + context, + orderIndex, + itemIndex + ); } } @@ -1660,26 +1800,39 @@ library SignatureGenerator { bytes memory signature; - SigInfra memory infra = - SigInfra({ digest: bytes32(0), v: 0, r: bytes32(0), s: bytes32(0) }); + SigInfra memory infra = SigInfra({ + digest: bytes32(0), + v: 0, + r: bytes32(0), + s: bytes32(0) + }); if (method == SignatureMethod.EOA) { uint256 offererKey = offerer.getKey(context); if (eoaSignatureType == EOASignature.STANDARD) { infra.digest = _getDigest(orderHash, context); - (infra.v, infra.r, infra.s) = - context.vm.sign(offererKey, infra.digest); + (infra.v, infra.r, infra.s) = context.vm.sign( + offererKey, + infra.digest + ); signature = abi.encodePacked(infra.r, infra.s, infra.v); _checkSig( - infra.digest, infra.v, infra.r, infra.s, offerer, context + infra.digest, + infra.v, + infra.r, + infra.s, + offerer, + context ); return order.withSignature(signature); } else if (eoaSignatureType == EOASignature.EIP2098) { infra.digest = _getDigest(orderHash, context); - (infra.v, infra.r, infra.s) = - context.vm.sign(offererKey, infra.digest); + (infra.v, infra.r, infra.s) = context.vm.sign( + offererKey, + infra.digest + ); { uint256 yParity; @@ -1693,7 +1846,12 @@ library SignatureGenerator { } _checkSig( - infra.digest, infra.v, infra.r, infra.s, offerer, context + infra.digest, + infra.v, + infra.r, + infra.s, + offerer, + context ); return order.withSignature(signature); } else if (eoaSignatureType == EOASignature.BULK) { @@ -1728,12 +1886,13 @@ library SignatureGenerator { if (method == SignatureMethod.EIP1271) { infra.digest = _getDigest(orderHash, context); EIP1271Offerer(payable(offererAddress)).registerSignature( - infra.digest, signature + infra.digest, + signature ); } else if ( - method != SignatureMethod.SELF_AD_HOC - && method != SignatureMethod.CONTRACT - && method != SignatureMethod.VALIDATE + method != SignatureMethod.SELF_AD_HOC && + method != SignatureMethod.CONTRACT && + method != SignatureMethod.VALIDATE ) { revert("SignatureGenerator: Invalid signature method"); } @@ -1742,14 +1901,16 @@ library SignatureGenerator { } } - function _getDigest(bytes32 orderHash, FuzzGeneratorContext memory context) - internal - view - returns (bytes32 digest) - { - (, bytes32 domainSeparator,) = context.seaport.information(); - bytes memory message = - abi.encodePacked(bytes2(0x1901), domainSeparator, orderHash); + function _getDigest( + bytes32 orderHash, + FuzzGeneratorContext memory context + ) internal view returns (bytes32 digest) { + (, bytes32 domainSeparator, ) = context.seaport.information(); + bytes memory message = abi.encodePacked( + bytes2(0x1901), + domainSeparator, + orderHash + ); digest = keccak256(message); } @@ -1811,13 +1972,13 @@ library TokenIndexGenerator { if (itemType == ItemType.ERC20) { return address(context.erc20s[i]); } else if ( - itemType == ItemType.ERC721 - || itemType == ItemType.ERC721_WITH_CRITERIA + itemType == ItemType.ERC721 || + itemType == ItemType.ERC721_WITH_CRITERIA ) { return address(context.erc721s[i]); } else if ( - itemType == ItemType.ERC1155 - || itemType == ItemType.ERC1155_WITH_CRITERIA + itemType == ItemType.ERC1155 || + itemType == ItemType.ERC1155_WITH_CRITERIA ) { return address(context.erc1155s[i]); } else { @@ -1843,10 +2004,14 @@ library TimeGenerator { if (time == Time.STARTS_IN_FUTURE) { uint256 a = bound( - context.prng.next(), context.timestamp + 1, type(uint40).max + context.prng.next(), + context.timestamp + 1, + type(uint40).max ); uint256 b = bound( - context.prng.next(), context.timestamp + 1, type(uint40).max + context.prng.next(), + context.timestamp + 1, + type(uint40).max ); low = a < b ? a : b; high = a > b ? a : b; @@ -1854,13 +2019,17 @@ library TimeGenerator { if (time == Time.EXACT_START) { low = context.timestamp; high = bound( - context.prng.next(), context.timestamp + 1, type(uint40).max + context.prng.next(), + context.timestamp + 1, + type(uint40).max ); } if (time == Time.ONGOING) { low = bound(context.prng.next(), 0, context.timestamp - 1); high = bound( - context.prng.next(), context.timestamp + 1, type(uint40).max + context.prng.next(), + context.timestamp + 1, + type(uint40).max ); } if (time == Time.EXACT_END) { @@ -1893,8 +2062,8 @@ library AmountGenerator { ) internal pure returns (OfferItem memory) { // Assumes ordering, might be dangerous if ( - item.itemType == ItemType.ERC721 - || item.itemType == ItemType.ERC721_WITH_CRITERIA + item.itemType == ItemType.ERC721 || + item.itemType == ItemType.ERC721_WITH_CRITERIA ) { return item.withStartAmount(1).withEndAmount(1); } @@ -1912,8 +2081,8 @@ library AmountGenerator { uint256 low = a < b ? a : b; if ( - amount == Amount.FIXED - || context.basicOrderCategory != BasicOrderCategory.NONE + amount == Amount.FIXED || + context.basicOrderCategory != BasicOrderCategory.NONE ) { return item.withStartAmount(high).withEndAmount(high); } @@ -1933,8 +2102,8 @@ library AmountGenerator { ) internal pure returns (ConsiderationItem memory) { // Assumes ordering, might be dangerous if ( - item.itemType == ItemType.ERC721 - || item.itemType == ItemType.ERC721_WITH_CRITERIA + item.itemType == ItemType.ERC721 || + item.itemType == ItemType.ERC721_WITH_CRITERIA ) { return item.withStartAmount(1).withEndAmount(1); } @@ -1946,8 +2115,8 @@ library AmountGenerator { uint256 low = a < b ? a : b; if ( - amount == Amount.FIXED - || context.basicOrderCategory != BasicOrderCategory.NONE + amount == Amount.FIXED || + context.basicOrderCategory != BasicOrderCategory.NONE ) { return item.withStartAmount(high).withEndAmount(high); } @@ -1973,8 +2142,8 @@ library RecipientGenerator { address offerer ) internal pure returns (address) { if ( - recipient == Recipient.OFFERER - || context.basicOrderCategory != BasicOrderCategory.NONE + recipient == Recipient.OFFERER || + context.basicOrderCategory != BasicOrderCategory.NONE ) { return offerer; } else if (recipient == Recipient.RECIPIENT) { @@ -2011,26 +2180,31 @@ library CriteriaGenerator { if (itemType == ItemType.NATIVE || itemType == ItemType.ERC20) { return item.withIdentifierOrCriteria(0); } else if (itemType == ItemType.ERC721) { - item = - item.withIdentifierOrCriteria(context.starting721offerIndex++); + item = item.withIdentifierOrCriteria( + context.starting721offerIndex++ + ); return item; } else if (itemType == ItemType.ERC1155) { - return item.withIdentifierOrCriteria( - context.potential1155TokenIds[context.prng.next() - % context.potential1155TokenIds.length] - ); + return + item.withIdentifierOrCriteria( + context.potential1155TokenIds[ + context.prng.next() % + context.potential1155TokenIds.length + ] + ); // Else, item is a criteria-based item } else { if (criteria == Criteria.MERKLE) { // Resolve a random tokenId from a random number of random tokenIds uint256 derivedCriteria = context .testHelpers - .criteriaResolverHelper().generateCriteriaMetadata( - context.prng, - itemType == ItemType.ERC721_WITH_CRITERIA - ? context.starting721offerIndex++ - : type(uint256).max - ); + .criteriaResolverHelper() + .generateCriteriaMetadata( + context.prng, + itemType == ItemType.ERC721_WITH_CRITERIA + ? context.starting721offerIndex++ + : type(uint256).max + ); // NOTE: resolvable identifier and proof are now registrated on CriteriaResolverHelper // Return the item with the Merkle root of the random tokenId @@ -2065,25 +2239,30 @@ library CriteriaGenerator { if (itemType == ItemType.NATIVE || itemType == ItemType.ERC20) { return item.withIdentifierOrCriteria(0); } else if (itemType == ItemType.ERC721) { - item = - item.withIdentifierOrCriteria(context.starting721offerIndex++); + item = item.withIdentifierOrCriteria( + context.starting721offerIndex++ + ); return item; } else if (itemType == ItemType.ERC1155) { - return item.withIdentifierOrCriteria( - context.potential1155TokenIds[context.prng.next() - % context.potential1155TokenIds.length] - ); + return + item.withIdentifierOrCriteria( + context.potential1155TokenIds[ + context.prng.next() % + context.potential1155TokenIds.length + ] + ); } else { if (criteria == Criteria.MERKLE) { // Resolve a random tokenId from a random number of random tokenIds uint256 derivedCriteria = context .testHelpers - .criteriaResolverHelper().generateCriteriaMetadata( - context.prng, - itemType == ItemType.ERC721_WITH_CRITERIA - ? context.starting721offerIndex++ - : type(uint256).max - ); + .criteriaResolverHelper() + .generateCriteriaMetadata( + context.prng, + itemType == ItemType.ERC721_WITH_CRITERIA + ? context.starting721offerIndex++ + : type(uint256).max + ); // NOTE: resolvable identifier and proof are now registrated on CriteriaResolverHelper // Return the item with the Merkle root of the random tokenId @@ -2112,11 +2291,10 @@ library CriteriaGenerator { * @dev Generate offerer address and key. */ library OffererGenerator { - function generate(Offerer offerer, FuzzGeneratorContext memory context) - internal - pure - returns (address) - { + function generate( + Offerer offerer, + FuzzGeneratorContext memory context + ) internal pure returns (address) { if (offerer == Offerer.TEST_CONTRACT) { return context.self; } else if (offerer == Offerer.ALICE) { @@ -2132,11 +2310,10 @@ library OffererGenerator { } } - function getKey(Offerer offerer, FuzzGeneratorContext memory context) - internal - pure - returns (uint256) - { + function getKey( + Offerer offerer, + FuzzGeneratorContext memory context + ) internal pure returns (uint256) { if (offerer == Offerer.TEST_CONTRACT) { return 0; } else if (offerer == Offerer.ALICE) { @@ -2177,11 +2354,10 @@ library FulfillmentRecipientGenerator { * @dev Generate a caller address. */ library CallerGenerator { - function generate(Caller caller, FuzzGeneratorContext memory context) - internal - view - returns (address) - { + function generate( + Caller caller, + FuzzGeneratorContext memory context + ) internal view returns (address) { if (caller == Caller.TEST_CONTRACT) { return address(this); } else if (caller == Caller.ALICE) { @@ -2208,11 +2384,11 @@ library CallerGenerator { library PRNGHelpers { using LibPRNG for LibPRNG.PRNG; - function randEnum(FuzzGeneratorContext memory context, uint8 min, uint8 max) - internal - pure - returns (uint8) - { + function randEnum( + FuzzGeneratorContext memory context, + uint8 min, + uint8 max + ) internal pure returns (uint8) { return uint8(bound(context.prng.next(), min, max)); } @@ -2224,19 +2400,16 @@ library PRNGHelpers { return bound(context.prng.next(), min, max); } - function rand(FuzzGeneratorContext memory context) - internal - pure - returns (uint256) - { + function rand( + FuzzGeneratorContext memory context + ) internal pure returns (uint256) { return context.prng.next(); } - function choice(FuzzGeneratorContext memory context, uint256[] memory arr) - internal - pure - returns (uint256) - { + function choice( + FuzzGeneratorContext memory context, + uint256[] memory arr + ) internal pure returns (uint256) { return arr[context.prng.next() % arr.length]; } } @@ -2244,10 +2417,11 @@ library PRNGHelpers { /** * @dev Implementation cribbed from forge-std bound */ -function bound(uint256 x, uint256 min, uint256 max) - pure - returns (uint256 result) -{ +function bound( + uint256 x, + uint256 min, + uint256 max +) pure returns (uint256 result) { require(min <= max, "Max is less than min."); // If x is between min and max, return x directly. This is to ensure that // dictionary values do not get shifted if the min is nonzero. diff --git a/test/foundry/new/helpers/FuzzHelpers.sol b/test/foundry/new/helpers/FuzzHelpers.sol index 8582427..afdb59d 100644 --- a/test/foundry/new/helpers/FuzzHelpers.sol +++ b/test/foundry/new/helpers/FuzzHelpers.sol @@ -38,8 +38,9 @@ import { import { UnavailableReason } from "seaport-sol/src/SpaceEnums.sol"; -import { ContractOffererInterface } from - "seaport-sol/src/ContractOffererInterface.sol"; +import { + ContractOffererInterface +} from "seaport-sol/src/ContractOffererInterface.sol"; import { SeaportInterface } from "seaport-sol/src/SeaportInterface.sol"; @@ -145,10 +146,11 @@ library FuzzHelpers { } } - function _lcm(uint256 a, uint256 b, uint256 gcdValue) - internal - returns (uint256 result) - { + function _lcm( + uint256 a, + uint256 b, + uint256 gcdValue + ) internal returns (uint256 result) { bool success; (success, result) = _tryMul(a, b); @@ -177,11 +179,10 @@ library FuzzHelpers { return result / gcdValue; } - function _tryMul(uint256 a, uint256 b) - internal - pure - returns (bool, uint256) - { + function _tryMul( + uint256 a, + uint256 b + ) internal pure returns (bool, uint256) { unchecked { if (a == 0) { return (true, 0); @@ -197,12 +198,12 @@ library FuzzHelpers { } } - function findSmallestDenominator(uint256[] memory numbers) - internal - returns (uint256 denominator) - { + function findSmallestDenominator( + uint256[] memory numbers + ) internal returns (uint256 denominator) { require( - numbers.length > 0, "FuzzHelpers: Input array must not be empty" + numbers.length > 0, + "FuzzHelpers: Input array must not be empty" ); bool initialValueSet = false; @@ -241,14 +242,12 @@ library FuzzHelpers { } } - function getTotalFractionalizableAmounts(OrderParameters memory order) - internal - pure - returns (uint256) - { + function getTotalFractionalizableAmounts( + OrderParameters memory order + ) internal pure returns (uint256) { if ( - order.orderType == OrderType.PARTIAL_OPEN - || order.orderType == OrderType.PARTIAL_RESTRICTED + order.orderType == OrderType.PARTIAL_OPEN || + order.orderType == OrderType.PARTIAL_RESTRICTED ) { return 2 * (order.offer.length + order.consideration.length); } @@ -256,14 +255,14 @@ library FuzzHelpers { return 0; } - function getSmallestDenominator(OrderParameters memory order) - internal - returns (uint256 smallestDenominator, bool canScaleUp) - { + function getSmallestDenominator( + OrderParameters memory order + ) internal returns (uint256 smallestDenominator, bool canScaleUp) { canScaleUp = true; - uint256 totalFractionalizableAmounts = - (getTotalFractionalizableAmounts(order)); + uint256 totalFractionalizableAmounts = ( + getTotalFractionalizableAmounts(order) + ); if (totalFractionalizableAmounts != 0) { uint256[] memory numbers = new uint256[]( @@ -277,8 +276,8 @@ library FuzzHelpers { numbers[numberIndex++] = item.startAmount; numbers[numberIndex++] = item.endAmount; if ( - item.itemType == ItemType.ERC721 - || item.itemType == ItemType.ERC721_WITH_CRITERIA + item.itemType == ItemType.ERC721 || + item.itemType == ItemType.ERC721_WITH_CRITERIA ) { canScaleUp = false; } @@ -289,8 +288,8 @@ library FuzzHelpers { numbers[numberIndex++] = item.startAmount; numbers[numberIndex++] = item.endAmount; if ( - item.itemType == ItemType.ERC721 - || item.itemType == ItemType.ERC721_WITH_CRITERIA + item.itemType == ItemType.ERC721 || + item.itemType == ItemType.ERC721_WITH_CRITERIA ) { canScaleUp = false; } @@ -310,11 +309,9 @@ library FuzzHelpers { * * @custom:return quantity of orders to process. */ - function getQuantity(AdvancedOrder[] memory orders) - internal - pure - returns (uint256) - { + function getQuantity( + AdvancedOrder[] memory orders + ) internal pure returns (uint256) { return orders.length; } @@ -325,11 +322,9 @@ library FuzzHelpers { * * @custom:return family of method that can fulfill these orders. */ - function getFamily(AdvancedOrder[] memory orders) - internal - pure - returns (Family) - { + function getFamily( + AdvancedOrder[] memory orders + ) internal pure returns (Family) { uint256 quantity = getQuantity(orders); if (quantity > 1) { return Family.COMBINED; @@ -345,14 +340,14 @@ library FuzzHelpers { * * @custom:return state of the given order. */ - function getState(AdvancedOrder memory order, SeaportInterface seaport) - internal - view - returns (State) - { + function getState( + AdvancedOrder memory order, + SeaportInterface seaport + ) internal view returns (State) { uint256 counter = seaport.getCounter(order.parameters.offerer); - bytes32 orderHash = - seaport.getOrderHash(order.parameters.toOrderComponents(counter)); + bytes32 orderHash = seaport.getOrderHash( + order.parameters.toOrderComponents(counter) + ); ( bool isValidated, bool isCancelled, @@ -380,13 +375,13 @@ library FuzzHelpers { function getType(AdvancedOrder memory order) internal pure returns (Type) { OrderType orderType = order.parameters.orderType; if ( - orderType == OrderType.FULL_OPEN - || orderType == OrderType.PARTIAL_OPEN + orderType == OrderType.FULL_OPEN || + orderType == OrderType.PARTIAL_OPEN ) { return Type.OPEN; } else if ( - orderType == OrderType.FULL_RESTRICTED - || orderType == OrderType.PARTIAL_RESTRICTED + orderType == OrderType.FULL_RESTRICTED || + orderType == OrderType.PARTIAL_RESTRICTED ) { return Type.RESTRICTED; } else if (orderType == OrderType.CONTRACT) { @@ -404,11 +399,10 @@ library FuzzHelpers { * * @custom:return structure of the given order. */ - function getStructure(AdvancedOrder memory order, address seaport) - internal - view - returns (Structure) - { + function getStructure( + AdvancedOrder memory order, + address seaport + ) internal view returns (Structure) { // If the order has extraData, it's advanced if (order.extraData.length > 0) return Structure.ADVANCED; @@ -442,11 +436,10 @@ library FuzzHelpers { return Structure.STANDARD; } - function getStructure(AdvancedOrder[] memory orders, address seaport) - internal - view - returns (Structure) - { + function getStructure( + AdvancedOrder[] memory orders, + address seaport + ) internal view returns (Structure) { if (orders.length == 1) { return getStructure(orders[0], seaport); } @@ -476,8 +469,9 @@ library FuzzHelpers { address seaport ) internal view returns (bool) { uint256 i; - ConsiderationItem[] memory consideration = - order.parameters.consideration; + ConsiderationItem[] memory consideration = order + .parameters + .consideration; OfferItem[] memory offer = order.parameters.offer; // Order must contain exactly one offer item and one or more @@ -486,8 +480,8 @@ library FuzzHelpers { return false; } if ( - consideration.length == 0 - || order.parameters.totalOriginalConsiderationItems == 0 + consideration.length == 0 || + order.parameters.totalOriginalConsiderationItems == 0 ) { return false; } @@ -511,11 +505,12 @@ library FuzzHelpers { // Order cannot be partially filled. SeaportInterface seaportInterface = SeaportInterface(seaport); uint256 counter = seaportInterface.getCounter(order.parameters.offerer); - OrderComponents memory orderComponents = - order.parameters.toOrderComponents(counter); + OrderComponents memory orderComponents = order + .parameters + .toOrderComponents(counter); bytes32 orderHash = seaportInterface.getOrderHash(orderComponents); - (,, uint256 totalFilled, uint256 totalSize) = - seaportInterface.getOrderStatus(orderHash); + (, , uint256 totalFilled, uint256 totalSize) = seaportInterface + .getOrderStatus(orderHash); if (totalFilled != totalSize) { return false; @@ -524,16 +519,16 @@ library FuzzHelpers { // Order cannot contain any criteria-based items. for (i = 0; i < consideration.length; ++i) { if ( - consideration[i].itemType == ItemType.ERC721_WITH_CRITERIA - || consideration[i].itemType == ItemType.ERC1155_WITH_CRITERIA + consideration[i].itemType == ItemType.ERC721_WITH_CRITERIA || + consideration[i].itemType == ItemType.ERC1155_WITH_CRITERIA ) { return false; } } if ( - offer[0].itemType == ItemType.ERC721_WITH_CRITERIA - || offer[0].itemType == ItemType.ERC1155_WITH_CRITERIA + offer[0].itemType == ItemType.ERC721_WITH_CRITERIA || + offer[0].itemType == ItemType.ERC1155_WITH_CRITERIA ) { return false; } @@ -546,15 +541,15 @@ library FuzzHelpers { // Order must contain exactly one NFT item. uint256 totalNFTs; if ( - offer[0].itemType == ItemType.ERC721 - || offer[0].itemType == ItemType.ERC1155 + offer[0].itemType == ItemType.ERC721 || + offer[0].itemType == ItemType.ERC1155 ) { totalNFTs += 1; } for (i = 0; i < consideration.length; ++i) { if ( - consideration[i].itemType == ItemType.ERC721 - || consideration[i].itemType == ItemType.ERC1155 + consideration[i].itemType == ItemType.ERC721 || + consideration[i].itemType == ItemType.ERC1155 ) { totalNFTs += 1; } @@ -567,10 +562,10 @@ library FuzzHelpers { // The one NFT must appear either as the offer item or as the first // consideration item. if ( - offer[0].itemType != ItemType.ERC721 - && offer[0].itemType != ItemType.ERC1155 - && consideration[0].itemType != ItemType.ERC721 - && consideration[0].itemType != ItemType.ERC1155 + offer[0].itemType != ItemType.ERC721 && + offer[0].itemType != ItemType.ERC1155 && + consideration[0].itemType != ItemType.ERC721 && + consideration[0].itemType != ItemType.ERC1155 ) { return false; } @@ -578,8 +573,8 @@ library FuzzHelpers { // All items that are not the NFT must share the same item type and // token (and the identifier must be zero). if ( - offer[0].itemType == ItemType.ERC721 - || offer[0].itemType == ItemType.ERC1155 + offer[0].itemType == ItemType.ERC721 || + offer[0].itemType == ItemType.ERC1155 ) { ItemType expectedItemType = consideration[0].itemType; address expectedToken = consideration[0].token; @@ -600,8 +595,8 @@ library FuzzHelpers { } if ( - consideration[0].itemType == ItemType.ERC721 - || consideration[0].itemType == ItemType.ERC1155 + consideration[0].itemType == ItemType.ERC721 || + consideration[0].itemType == ItemType.ERC1155 ) { if (consideration.length >= 2) { ItemType expectedItemType = offer[0].itemType; @@ -631,8 +626,8 @@ library FuzzHelpers { // all the other consideration items cannot exceed the amount of the // offer item. if ( - consideration[0].itemType == ItemType.ERC721 - || consideration[0].itemType == ItemType.ERC1155 + consideration[0].itemType == ItemType.ERC721 || + consideration[0].itemType == ItemType.ERC1155 ) { uint256 totalConsiderationAmount; for (i = 1; i < consideration.length; ++i) { @@ -675,11 +670,9 @@ library FuzzHelpers { * * @return basicOrderType The BasicOrderType. */ - function getBasicOrderType(AdvancedOrder memory order) - internal - pure - returns (BasicOrderType basicOrderType) - { + function getBasicOrderType( + AdvancedOrder memory order + ) internal pure returns (BasicOrderType basicOrderType) { // Get the route (ETH ⇒ ERC721, etc.) for the order. BasicOrderRouteType route = getBasicOrderRouteType(order); @@ -700,11 +693,9 @@ library FuzzHelpers { * * @return route The BasicOrderRouteType. */ - function getBasicOrderRouteType(AdvancedOrder memory order) - internal - pure - returns (BasicOrderRouteType route) - { + function getBasicOrderRouteType( + AdvancedOrder memory order + ) internal pure returns (BasicOrderRouteType route) { // Get the route (ETH ⇒ ERC721, etc.) for the order. ItemType providingItemType = order.parameters.consideration[0].itemType; ItemType offeredItemType = order.parameters.offer[0].itemType; @@ -756,18 +747,22 @@ library FuzzHelpers { ) internal view returns (bytes32[] memory calldataHashes) { calldataHashes = new bytes32[](orders.length); - ZoneParameters[] memory zoneParameters = orders.getZoneAuthorizeParameters( - fulfiller, - maximumFulfilled, - seaport, - criteriaResolvers, - unavailableReasons - ); + ZoneParameters[] memory zoneParameters = orders + .getZoneAuthorizeParameters( + fulfiller, + maximumFulfilled, + seaport, + criteriaResolvers, + unavailableReasons + ); for (uint256 i; i < zoneParameters.length; ++i) { // Derive the expected calldata hash for the call to authorizeOrder calldataHashes[i] = keccak256( - abi.encodeCall(ZoneInterface.authorizeOrder, (zoneParameters[i])) + abi.encodeCall( + ZoneInterface.authorizeOrder, + (zoneParameters[i]) + ) ); } } @@ -796,13 +791,14 @@ library FuzzHelpers { ) internal view returns (bytes32[] memory calldataHashes) { calldataHashes = new bytes32[](orders.length); - ZoneParameters[] memory zoneParameters = orders.getZoneValidateParameters( - fulfiller, - maximumFulfilled, - seaport, - criteriaResolvers, - unavailableReasons - ); + ZoneParameters[] memory zoneParameters = orders + .getZoneValidateParameters( + fulfiller, + maximumFulfilled, + seaport, + criteriaResolvers, + unavailableReasons + ); for (uint256 i; i < zoneParameters.length; ++i) { // Derive the expected calldata hash for the call to validateOrder @@ -825,13 +821,15 @@ library FuzzHelpers { bytes32[] memory orderHashes = new bytes32[](orders.length); for (uint256 i = 0; i < orderHashes.length; ++i) { if ( - context.executionState.orderDetails[i].unavailableReason - != UnavailableReason.AVAILABLE + context.executionState.orderDetails[i].unavailableReason != + UnavailableReason.AVAILABLE ) { orderHashes[i] = bytes32(0); } else { - orderHashes[i] = - context.executionState.orderDetails[i].orderHash; + orderHashes[i] = context + .executionState + .orderDetails[i] + .orderHash; } } @@ -846,28 +844,43 @@ library FuzzHelpers { continue; } - SpentItem[] memory minimumReceived = - order.parameters.offer.toSpentItemArray(); + SpentItem[] memory minimumReceived = order + .parameters + .offer + .toSpentItemArray(); - SpentItem[] memory maximumSpent = - order.parameters.consideration.toSpentItemArray(); + SpentItem[] memory maximumSpent = order + .parameters + .consideration + .toSpentItemArray(); // apply criteria resolvers before hashing - for (uint256 j = 0; j < context.executionState.criteriaResolvers.length; ++j) { - CriteriaResolver memory resolver = - context.executionState.criteriaResolvers[j]; + for ( + uint256 j = 0; + j < context.executionState.criteriaResolvers.length; + ++j + ) { + CriteriaResolver memory resolver = context + .executionState + .criteriaResolvers[j]; if (resolver.orderIndex != i) { continue; } - + // NOTE: assumes that all provided resolvers are valid - if (resolver.side == Side.OFFER) { - minimumReceived[resolver.index].itemType = ItemType(uint256(minimumReceived[resolver.index].itemType) - 2); - minimumReceived[resolver.index].identifier = resolver.identifier; + if (resolver.side == Side.OFFER) { + minimumReceived[resolver.index].itemType = ItemType( + uint256(minimumReceived[resolver.index].itemType) - 2 + ); + minimumReceived[resolver.index].identifier = resolver + .identifier; } else { - maximumSpent[resolver.index].itemType = ItemType(uint256(maximumSpent[resolver.index].itemType) - 2); - maximumSpent[resolver.index].identifier = resolver.identifier; + maximumSpent[resolver.index].itemType = ItemType( + uint256(maximumSpent[resolver.index].itemType) - 2 + ); + maximumSpent[resolver.index].identifier = resolver + .identifier; } } @@ -879,8 +892,9 @@ library FuzzHelpers { ) ); - uint256 shiftedOfferer = - uint256(uint160(order.parameters.offerer)) << 96; + uint256 shiftedOfferer = uint256( + uint160(order.parameters.offerer) + ) << 96; // Get counter of the order offerer uint256 counter = shiftedOfferer ^ uint256(orderHashes[i]); @@ -942,38 +956,35 @@ library FuzzHelpers { * @return hasNonzeroCriteria Whether any offer or consideration item has * nonzero criteria. */ - function _checkCriteria(AdvancedOrder memory order) - internal - pure - returns (bool hasCriteria, bool hasNonzeroCriteria) - { + function _checkCriteria( + AdvancedOrder memory order + ) internal pure returns (bool hasCriteria, bool hasNonzeroCriteria) { // Check if any offer item has criteria OfferItem[] memory offer = order.parameters.offer; for (uint256 i; i < offer.length; ++i) { OfferItem memory offerItem = offer[i]; ItemType itemType = offerItem.itemType; - hasCriteria = ( - itemType == ItemType.ERC721_WITH_CRITERIA - || itemType == ItemType.ERC1155_WITH_CRITERIA - ); + hasCriteria = (itemType == ItemType.ERC721_WITH_CRITERIA || + itemType == ItemType.ERC1155_WITH_CRITERIA); if (hasCriteria) { return (hasCriteria, offerItem.identifierOrCriteria != 0); } } // Check if any consideration item has criteria - ConsiderationItem[] memory consideration = - order.parameters.consideration; + ConsiderationItem[] memory consideration = order + .parameters + .consideration; for (uint256 i; i < consideration.length; ++i) { ConsiderationItem memory considerationItem = consideration[i]; ItemType itemType = considerationItem.itemType; - hasCriteria = ( - itemType == ItemType.ERC721_WITH_CRITERIA - || itemType == ItemType.ERC1155_WITH_CRITERIA - ); + hasCriteria = (itemType == ItemType.ERC721_WITH_CRITERIA || + itemType == ItemType.ERC1155_WITH_CRITERIA); if (hasCriteria) { - return - (hasCriteria, considerationItem.identifierOrCriteria != 0); + return ( + hasCriteria, + considerationItem.identifierOrCriteria != 0 + ); } } @@ -1008,23 +1019,22 @@ function _locateCurrentAmount( } // Aggregate new amounts weighted by time with rounding factor. - uint256 totalBeforeDivision = - ((startAmount * remaining) + (endAmount * elapsed)); + uint256 totalBeforeDivision = ((startAmount * remaining) + + (endAmount * elapsed)); // Use assembly to combine operations and skip divide-by-zero check. assembly { // Multiply by iszero(iszero(totalBeforeDivision)) to ensure // amount is set to zero if totalBeforeDivision is zero, // as intermediate overflow can occur if it is zero. - amount := - mul( - iszero(iszero(totalBeforeDivision)), - // Subtract 1 from the numerator and add 1 to the result if - // roundUp is true to get the proper rounding direction. - // Division is performed with no zero check as duration - // cannot be zero as long as startTime < endTime. - add(div(sub(totalBeforeDivision, roundUp), duration), roundUp) - ) + amount := mul( + iszero(iszero(totalBeforeDivision)), + // Subtract 1 from the numerator and add 1 to the result if + // roundUp is true to get the proper rounding direction. + // Division is performed with no zero check as duration + // cannot be zero as long as startTime < endTime. + add(div(sub(totalBeforeDivision, roundUp), duration), roundUp) + ) } // Return the current amount. diff --git a/test/foundry/new/helpers/FuzzInscribers.sol b/test/foundry/new/helpers/FuzzInscribers.sol index dd5bd27..1ddd2b2 100644 --- a/test/foundry/new/helpers/FuzzInscribers.sol +++ b/test/foundry/new/helpers/FuzzInscribers.sol @@ -77,9 +77,14 @@ library FuzzInscribers { // Get the order hash. bytes32 orderHash = order.getTipNeutralizedOrderHash(seaport); - bytes32 orderHashStorageSlot = - _getStorageSlotForOrderHash(orderHash, seaport); - bytes32 rawOrderStatus = vm.load(address(seaport), orderHashStorageSlot); + bytes32 orderHashStorageSlot = _getStorageSlotForOrderHash( + orderHash, + seaport + ); + bytes32 rawOrderStatus = vm.load( + address(seaport), + orderHashStorageSlot + ); // NOTE: This will permit putting an order in a 0x0...0101 state. // In other words, it will allow you to inscribe an order as @@ -87,18 +92,19 @@ library FuzzInscribers { // possible in actual Seaport. assembly { - rawOrderStatus := - and( - sub(0, add(1, iszero(isValidated))), - or(isValidated, rawOrderStatus) - ) + rawOrderStatus := and( + sub(0, add(1, iszero(isValidated))), + or(isValidated, rawOrderStatus) + ) } // Store the new raw order status. vm.store(address(seaport), orderHashStorageSlot, rawOrderStatus); // Get the fresh baked order status straight from Seaport. - (bool isValidatedOrganicValue,,,) = seaport.getOrderStatus(orderHash); + (bool isValidatedOrganicValue, , , ) = seaport.getOrderStatus( + orderHash + ); if (isValidated != isValidatedOrganicValue) { revert("FuzzInscribers/inscribeOrderStatusValidated: Mismatch"); @@ -128,38 +134,48 @@ library FuzzInscribers { bool isCancelled, SeaportInterface seaport ) internal { - bytes32 orderHashStorageSlot = - _getStorageSlotForOrderHash(orderHash, seaport); - bytes32 rawOrderStatus = vm.load(address(seaport), orderHashStorageSlot); + bytes32 orderHashStorageSlot = _getStorageSlotForOrderHash( + orderHash, + seaport + ); + bytes32 rawOrderStatus = vm.load( + address(seaport), + orderHashStorageSlot + ); // NOTE: This will not permit putting an order in a 0x0...0101 state. If // An order that's validated is inscribed as cancelled, it will // be devalidated also. assembly { - rawOrderStatus := - and( - sub(sub(0, 1), mul(iszero(isCancelled), 0x100)), - or( - shl(8, isCancelled), - and(mul(sub(0, 0x102), isCancelled), rawOrderStatus) - ) + rawOrderStatus := and( + sub(sub(0, 1), mul(iszero(isCancelled), 0x100)), + or( + shl(8, isCancelled), + and(mul(sub(0, 0x102), isCancelled), rawOrderStatus) ) + ) } // Store the new raw order status. vm.store(address(seaport), orderHashStorageSlot, rawOrderStatus); // Get the fresh baked order status straight from Seaport. - (bool isValidatedOrganicValue, bool isCancelledOrganicValue,,) = - seaport.getOrderStatus(orderHash); + ( + bool isValidatedOrganicValue, + bool isCancelledOrganicValue, + , + + ) = seaport.getOrderStatus(orderHash); if (isCancelled != isCancelledOrganicValue) { revert("FuzzInscribers/inscribeOrderStatusCancelled: Mismatch"); } if (isCancelledOrganicValue && isValidatedOrganicValue) { - revert("FuzzInscribers/inscribeOrderStatusCancelled: Invalid state"); + revert( + "FuzzInscribers/inscribeOrderStatusCancelled: Invalid state" + ); } } @@ -178,9 +194,14 @@ library FuzzInscribers { ) internal { // Get the order hash, storage slot, and raw order status. bytes32 orderHash = order.getTipNeutralizedOrderHash(seaport); - bytes32 orderHashStorageSlot = - _getStorageSlotForOrderHash(orderHash, seaport); - bytes32 rawOrderStatus = vm.load(address(seaport), orderHashStorageSlot); + bytes32 orderHashStorageSlot = _getStorageSlotForOrderHash( + orderHash, + seaport + ); + bytes32 rawOrderStatus = vm.load( + address(seaport), + orderHashStorageSlot + ); // Convert the numerator to bytes. bytes32 numeratorBytes = bytes32(uint256(numerator)); @@ -214,9 +235,14 @@ library FuzzInscribers { ) internal { // Get the order hash, storage slot, and raw order status. bytes32 orderHash = order.getTipNeutralizedOrderHash(seaport); - bytes32 orderHashStorageSlot = - _getStorageSlotForOrderHash(orderHash, seaport); - bytes32 rawOrderStatus = vm.load(address(seaport), orderHashStorageSlot); + bytes32 orderHashStorageSlot = _getStorageSlotForOrderHash( + orderHash, + seaport + ); + bytes32 rawOrderStatus = vm.load( + address(seaport), + orderHashStorageSlot + ); // Convert the denominator to bytes. bytes32 denominatorBytes = bytes32(uint256(denominator)); @@ -249,12 +275,16 @@ library FuzzInscribers { SeaportInterface seaport ) internal { // Get the storage slot for the contract offerer's nonce. - bytes32 contractOffererNonceStorageSlot = - _getStorageSlotForContractNonce(contractOfferer, seaport); + bytes32 contractOffererNonceStorageSlot = _getStorageSlotForContractNonce( + contractOfferer, + seaport + ); // Store the new nonce. vm.store( - address(seaport), contractOffererNonceStorageSlot, bytes32(nonce) + address(seaport), + contractOffererNonceStorageSlot, + bytes32(nonce) ); } @@ -272,7 +302,10 @@ library FuzzInscribers { SeaportInterface seaport ) internal { // Get the storage slot for the counter. - bytes32 counterStorageSlot = _getStorageSlotForCounter(offerer, seaport); + bytes32 counterStorageSlot = _getStorageSlotForCounter( + offerer, + seaport + ); // Store the new counter. vm.store(address(seaport), counterStorageSlot, bytes32(counter)); @@ -284,21 +317,24 @@ library FuzzInscribers { ) private returns (bytes32) { vm.record(); seaport.getOrderStatus(orderHash); - (bytes32[] memory readAccesses,) = vm.accesses(address(seaport)); + (bytes32[] memory readAccesses, ) = vm.accesses(address(seaport)); uint256 expectedReadAccessCount = 4; - string memory profile = vm.envOr("FOUNDRY_PROFILE", string("optimized")); + string memory profile = vm.envOr( + "FOUNDRY_PROFILE", + string("optimized") + ); if ( - keccak256(abi.encodePacked(profile)) - == keccak256(abi.encodePacked("optimized")) - || keccak256(abi.encodePacked(profile)) - == keccak256(abi.encodePacked("test")) - || keccak256(abi.encodePacked(profile)) - == keccak256(abi.encodePacked("lite")) - || keccak256(abi.encodePacked(profile)) - == keccak256(abi.encodePacked("reference")) + keccak256(abi.encodePacked(profile)) == + keccak256(abi.encodePacked("optimized")) || + keccak256(abi.encodePacked(profile)) == + keccak256(abi.encodePacked("test")) || + keccak256(abi.encodePacked(profile)) == + keccak256(abi.encodePacked("lite")) || + keccak256(abi.encodePacked(profile)) == + keccak256(abi.encodePacked("reference")) ) { expectedReadAccessCount = 1; } @@ -317,7 +353,7 @@ library FuzzInscribers { ) private returns (bytes32) { vm.record(); seaport.getContractOffererNonce(contractOfferer); - (bytes32[] memory readAccesses,) = vm.accesses(address(seaport)); + (bytes32[] memory readAccesses, ) = vm.accesses(address(seaport)); require(readAccesses.length == 1, "Expected 1 read access."); @@ -330,7 +366,7 @@ library FuzzInscribers { ) private returns (bytes32) { vm.record(); seaport.getCounter(offerer); - (bytes32[] memory readAccesses,) = vm.accesses(address(seaport)); + (bytes32[] memory readAccesses, ) = vm.accesses(address(seaport)); require(readAccesses.length == 1, "Expected 1 read access."); diff --git a/test/foundry/new/helpers/FuzzMutationHelpers.sol b/test/foundry/new/helpers/FuzzMutationHelpers.sol index e19c0f8..79866c0 100644 --- a/test/foundry/new/helpers/FuzzMutationHelpers.sol +++ b/test/foundry/new/helpers/FuzzMutationHelpers.sol @@ -125,8 +125,9 @@ library FailureEligibilityLib { Failure ineligibleFailure ) internal pure { // Set the respective boolean for the ineligible failure. - context.expectations.ineligibleFailures[uint256(ineligibleFailure)] = - true; + context.expectations.ineligibleFailures[ + uint256(ineligibleFailure) + ] = true; } function setIneligibleFailures( @@ -135,17 +136,15 @@ library FailureEligibilityLib { ) internal pure { for (uint256 i = 0; i < ineligibleFailures.length; ++i) { // Set the respective boolean for each ineligible failure. - context.expectations.ineligibleFailures[uint256( - ineligibleFailures[i] - )] = true; + context.expectations.ineligibleFailures[ + uint256(ineligibleFailures[i]) + ] = true; } } - function getEligibleFailures(FuzzTestContext memory context) - internal - pure - returns (Failure[] memory eligibleFailures) - { + function getEligibleFailures( + FuzzTestContext memory context + ) internal pure returns (Failure[] memory eligibleFailures) { eligibleFailures = new Failure[](uint256(Failure.length)); uint256 totalEligibleFailures = 0; @@ -166,10 +165,9 @@ library FailureEligibilityLib { } } - function selectEligibleFailure(FuzzTestContext memory context) - internal - returns (Failure eligibleFailure) - { + function selectEligibleFailure( + FuzzTestContext memory context + ) internal returns (Failure eligibleFailure) { LibPRNG.PRNG memory prng = LibPRNG.PRNG(context.fuzzParams.seed ^ 0xff); Failure[] memory eligibleFailures = getEligibleFailures(context); @@ -221,11 +219,12 @@ library MutationEligibilityLib { internal returns (bool) ineligibilityFilter ) internal pure returns (IneligibilityFilter memory) { - return IneligibilityFilter( - failure.one(), - MutationContextDerivation.ORDER, - fn(ineligibilityFilter) - ); + return + IneligibilityFilter( + failure.one(), + MutationContextDerivation.ORDER, + fn(ineligibilityFilter) + ); } function withOrder( @@ -234,9 +233,12 @@ library MutationEligibilityLib { internal returns (bool) ineligibilityFilter ) internal pure returns (IneligibilityFilter memory) { - return IneligibilityFilter( - failures, MutationContextDerivation.ORDER, fn(ineligibilityFilter) - ); + return + IneligibilityFilter( + failures, + MutationContextDerivation.ORDER, + fn(ineligibilityFilter) + ); } function withCriteria( @@ -245,11 +247,12 @@ library MutationEligibilityLib { internal returns (bool) ineligibilityFilter ) internal pure returns (IneligibilityFilter memory) { - return IneligibilityFilter( - failure.one(), - MutationContextDerivation.CRITERIA_RESOLVER, - fn(ineligibilityFilter) - ); + return + IneligibilityFilter( + failure.one(), + MutationContextDerivation.CRITERIA_RESOLVER, + fn(ineligibilityFilter) + ); } function withCriteria( @@ -258,11 +261,12 @@ library MutationEligibilityLib { internal returns (bool) ineligibilityFilter ) internal pure returns (IneligibilityFilter memory) { - return IneligibilityFilter( - failures, - MutationContextDerivation.CRITERIA_RESOLVER, - fn(ineligibilityFilter) - ); + return + IneligibilityFilter( + failures, + MutationContextDerivation.CRITERIA_RESOLVER, + fn(ineligibilityFilter) + ); } function withGeneric( @@ -271,11 +275,12 @@ library MutationEligibilityLib { internal returns (bool) ineligibilityFilter ) internal pure returns (IneligibilityFilter memory) { - return IneligibilityFilter( - failure.one(), - MutationContextDerivation.GENERIC, - fn(ineligibilityFilter) - ); + return + IneligibilityFilter( + failure.one(), + MutationContextDerivation.GENERIC, + fn(ineligibilityFilter) + ); } function withGeneric( @@ -284,9 +289,12 @@ library MutationEligibilityLib { internal returns (bool) ineligibilityFilter ) internal pure returns (IneligibilityFilter memory) { - return IneligibilityFilter( - failures, MutationContextDerivation.GENERIC, fn(ineligibilityFilter) - ); + return + IneligibilityFilter( + failures, + MutationContextDerivation.GENERIC, + fn(ineligibilityFilter) + ); } function setAllIneligibleFailures( @@ -294,12 +302,13 @@ library MutationEligibilityLib { IneligibilityFilter[] memory failuresAndFilters ) internal { for (uint256 i = 0; i < failuresAndFilters.length; ++i) { - IneligibilityFilter memory failuresAndFilter = - (failuresAndFilters[i]); + IneligibilityFilter memory failuresAndFilter = ( + failuresAndFilters[i] + ); if ( - failuresAndFilter.derivationMethod - == MutationContextDerivation.GENERIC + failuresAndFilter.derivationMethod == + MutationContextDerivation.GENERIC ) { setIneligibleFailures( context, @@ -309,8 +318,8 @@ library MutationEligibilityLib { failuresAndFilter.failures ); } else if ( - failuresAndFilter.derivationMethod - == MutationContextDerivation.ORDER + failuresAndFilter.derivationMethod == + MutationContextDerivation.ORDER ) { setIneligibleFailures( context, @@ -320,8 +329,8 @@ library MutationEligibilityLib { failuresAndFilter.failures ); } else if ( - failuresAndFilter.derivationMethod - == MutationContextDerivation.CRITERIA_RESOLVER + failuresAndFilter.derivationMethod == + MutationContextDerivation.CRITERIA_RESOLVER ) { setIneligibleFailures( context, @@ -384,7 +393,9 @@ library MutationEligibilityLib { // Once an eligible order is found, return false. if ( !ineligibleCondition( - context.executionState.orders[i], i, context + context.executionState.orders[i], + i, + context ) ) { return false; @@ -401,12 +412,16 @@ library MutationEligibilityLib { returns (bool) ineligibleCondition ) internal returns (bool) { for ( - uint256 i; i < context.executionState.criteriaResolvers.length; i++ + uint256 i; + i < context.executionState.criteriaResolvers.length; + i++ ) { // Once an eligible criteria resolver is found, return false. if ( !ineligibleCondition( - context.executionState.criteriaResolvers[i], i, context + context.executionState.criteriaResolvers[i], + i, + context ) ) { return false; @@ -454,8 +469,9 @@ library MutationEligibilityLib { view returns (bool) condition ) internal view returns (bool[] memory ineligibleCriteriaResolvers) { - CriteriaResolver[] memory resolvers = - (context.executionState.criteriaResolvers); + CriteriaResolver[] memory resolvers = ( + context.executionState.criteriaResolvers + ); ineligibleCriteriaResolvers = new bool[](resolvers.length); for (uint256 i; i < resolvers.length; i++) { if (condition(resolvers[i], i, context)) { @@ -528,8 +544,9 @@ library MutationEligibilityLib { ); criteriaResolverIndex = getEligibleIndex(context, eligibleResolvers); - eligibleCriteriaResolver = - context.executionState.criteriaResolvers[criteriaResolverIndex]; + eligibleCriteriaResolver = context.executionState.criteriaResolvers[ + criteriaResolverIndex + ]; } function fn( @@ -562,12 +579,16 @@ library MutationEligibilityLib { } } - function asIneligibleGenericMutationFilter(bytes32 ptr) + function asIneligibleGenericMutationFilter( + bytes32 ptr + ) internal pure returns ( - function(FuzzTestContext memory) internal view returns (bool) - ineligibleMutationFilter + function(FuzzTestContext memory) + internal + view + returns (bool) ineligibleMutationFilter ) { assembly { @@ -575,12 +596,16 @@ library MutationEligibilityLib { } } - function asIneligibleOrderBasedMutationFilter(bytes32 ptr) + function asIneligibleOrderBasedMutationFilter( + bytes32 ptr + ) internal pure returns ( - function(AdvancedOrder memory, uint256, FuzzTestContext memory) internal view returns (bool) - ineligibleMutationFilter + function(AdvancedOrder memory, uint256, FuzzTestContext memory) + internal + view + returns (bool) ineligibleMutationFilter ) { assembly { @@ -588,12 +613,16 @@ library MutationEligibilityLib { } } - function asIneligibleCriteriaBasedMutationFilter(bytes32 ptr) + function asIneligibleCriteriaBasedMutationFilter( + bytes32 ptr + ) internal pure returns ( - function(CriteriaResolver memory, uint256, FuzzTestContext memory) internal view returns (bool) - ineligibleMutationFilter + function(CriteriaResolver memory, uint256, FuzzTestContext memory) + internal + view + returns (bool) ineligibleMutationFilter ) { assembly { @@ -612,13 +641,15 @@ library MutationContextDeriverLib { bytes32 ineligibilityFilter // use a function pointer ) internal view returns (MutationState memory mutationState) { if (derivationMethod == MutationContextDerivation.ORDER) { - (AdvancedOrder memory order, uint256 orderIndex) = - context.selectEligibleOrder(ineligibilityFilter); + (AdvancedOrder memory order, uint256 orderIndex) = context + .selectEligibleOrder(ineligibilityFilter); mutationState.selectedOrder = order; mutationState.selectedOrderIndex = orderIndex; - mutationState.selectedOrderHash = - context.executionState.orderDetails[orderIndex].orderHash; + mutationState.selectedOrderHash = context + .executionState + .orderDetails[orderIndex] + .orderHash; mutationState.side = Side(context.generatorContext.randEnum(0, 1)); mutationState.selectedArbitraryAddress = address( uint160( @@ -628,8 +659,8 @@ library MutationContextDeriverLib { } else if ( derivationMethod == MutationContextDerivation.CRITERIA_RESOLVER ) { - (CriteriaResolver memory resolver, uint256 resolverIndex) = - context.selectEligibleCriteriaResolver(ineligibilityFilter); + (CriteriaResolver memory resolver, uint256 resolverIndex) = context + .selectEligibleCriteriaResolver(ineligibilityFilter); mutationState.selectedCriteriaResolver = resolver; mutationState.selectedCriteriaResolverIndex = resolverIndex; @@ -645,13 +676,14 @@ library FailureDetailsHelperLib { string memory name, bytes4 mutationSelector ) internal pure returns (FailureDetails memory details) { - return FailureDetails( - name, - mutationSelector, - errorSelector, - MutationContextDerivation.ORDER, - fn(defaultReason) - ); + return + FailureDetails( + name, + mutationSelector, + errorSelector, + MutationContextDerivation.ORDER, + fn(defaultReason) + ); } function withOrder( @@ -663,13 +695,14 @@ library FailureDetailsHelperLib { view returns (bytes memory) revertReasonDeriver ) internal pure returns (FailureDetails memory details) { - return FailureDetails( - name, - mutationSelector, - errorSelector, - MutationContextDerivation.ORDER, - fn(revertReasonDeriver) - ); + return + FailureDetails( + name, + mutationSelector, + errorSelector, + MutationContextDerivation.ORDER, + fn(revertReasonDeriver) + ); } function withCriteria( @@ -677,13 +710,14 @@ library FailureDetailsHelperLib { string memory name, bytes4 mutationSelector ) internal pure returns (FailureDetails memory details) { - return FailureDetails( - name, - mutationSelector, - errorSelector, - MutationContextDerivation.CRITERIA_RESOLVER, - fn(defaultReason) - ); + return + FailureDetails( + name, + mutationSelector, + errorSelector, + MutationContextDerivation.CRITERIA_RESOLVER, + fn(defaultReason) + ); } function withCriteria( @@ -695,13 +729,14 @@ library FailureDetailsHelperLib { view returns (bytes memory) revertReasonDeriver ) internal pure returns (FailureDetails memory details) { - return FailureDetails( - name, - mutationSelector, - errorSelector, - MutationContextDerivation.CRITERIA_RESOLVER, - fn(revertReasonDeriver) - ); + return + FailureDetails( + name, + mutationSelector, + errorSelector, + MutationContextDerivation.CRITERIA_RESOLVER, + fn(revertReasonDeriver) + ); } function withGeneric( @@ -709,13 +744,14 @@ library FailureDetailsHelperLib { string memory name, bytes4 mutationSelector ) internal pure returns (FailureDetails memory details) { - return FailureDetails( - name, - mutationSelector, - errorSelector, - MutationContextDerivation.GENERIC, - fn(defaultReason) - ); + return + FailureDetails( + name, + mutationSelector, + errorSelector, + MutationContextDerivation.GENERIC, + fn(defaultReason) + ); } function withGeneric( @@ -727,13 +763,14 @@ library FailureDetailsHelperLib { view returns (bytes memory) revertReasonDeriver ) internal pure returns (FailureDetails memory details) { - return FailureDetails( - name, - mutationSelector, - errorSelector, - MutationContextDerivation.GENERIC, - fn(revertReasonDeriver) - ); + return + FailureDetails( + name, + mutationSelector, + errorSelector, + MutationContextDerivation.GENERIC, + fn(revertReasonDeriver) + ); } function fn( @@ -753,17 +790,24 @@ library FailureDetailsHelperLib { bytes4 errorSelector, bytes32 revertReasonDeriver ) internal view returns (bytes memory) { - return asRevertReasonGenerator(revertReasonDeriver)( - context, mutationState, errorSelector - ); + return + asRevertReasonGenerator(revertReasonDeriver)( + context, + mutationState, + errorSelector + ); } - function asRevertReasonGenerator(bytes32 ptr) + function asRevertReasonGenerator( + bytes32 ptr + ) private pure returns ( - function(FuzzTestContext memory, MutationState memory, bytes4) internal view returns (bytes memory) - revertReasonGenerator + function(FuzzTestContext memory, MutationState memory, bytes4) + internal + view + returns (bytes memory) revertReasonGenerator ) { assembly { @@ -772,7 +816,7 @@ library FailureDetailsHelperLib { } function defaultReason( - FuzzTestContext memory, /* context */ + FuzzTestContext memory /* context */, MutationState memory, bytes4 errorSelector ) internal pure returns (bytes memory) { @@ -798,13 +842,14 @@ library MutationHelpersLib { i < context.expectations.expectedExplicitExecutions.length; ++i ) { - Execution memory execution = - context.expectations.expectedExplicitExecutions[i]; + Execution memory execution = context + .expectations + .expectedExplicitExecutions[i]; if ( - execution.offerer == offerer - && execution.conduitKey == conduitKey - && execution.item.itemType == item.itemType - && execution.item.token == item.token + execution.offerer == offerer && + execution.conduitKey == conduitKey && + execution.item.itemType == item.itemType && + execution.item.token == item.token ) { return false; } @@ -816,13 +861,14 @@ library MutationHelpersLib { i < context.expectations.expectedImplicitPreExecutions.length; ++i ) { - Execution memory execution = - context.expectations.expectedImplicitPreExecutions[i]; + Execution memory execution = context + .expectations + .expectedImplicitPreExecutions[i]; if ( - execution.offerer == offerer - && execution.conduitKey == conduitKey - && execution.item.itemType == item.itemType - && execution.item.token == item.token + execution.offerer == offerer && + execution.conduitKey == conduitKey && + execution.item.itemType == item.itemType && + execution.item.token == item.token ) { return false; } @@ -834,13 +880,14 @@ library MutationHelpersLib { i < context.expectations.expectedImplicitPostExecutions.length; ++i ) { - Execution memory execution = - context.expectations.expectedImplicitPostExecutions[i]; + Execution memory execution = context + .expectations + .expectedImplicitPostExecutions[i]; if ( - execution.offerer == offerer - && execution.conduitKey == conduitKey - && execution.item.itemType == item.itemType - && execution.item.token == item.token + execution.offerer == offerer && + execution.conduitKey == conduitKey && + execution.item.itemType == item.itemType && + execution.item.token == item.token ) { return false; } @@ -866,13 +913,14 @@ library MutationHelpersLib { i < context.expectations.expectedExplicitExecutions.length; ++i ) { - Execution memory execution = - context.expectations.expectedExplicitExecutions[i]; + Execution memory execution = context + .expectations + .expectedExplicitExecutions[i]; if ( - execution.offerer == caller - && execution.conduitKey == conduitKey - && execution.item.itemType == item.itemType - && execution.item.token == item.token + execution.offerer == caller && + execution.conduitKey == conduitKey && + execution.item.itemType == item.itemType && + execution.item.token == item.token ) { return false; } @@ -884,13 +932,14 @@ library MutationHelpersLib { i < context.expectations.expectedImplicitPreExecutions.length; ++i ) { - Execution memory execution = - context.expectations.expectedImplicitPreExecutions[i]; + Execution memory execution = context + .expectations + .expectedImplicitPreExecutions[i]; if ( - execution.offerer == caller - && execution.conduitKey == conduitKey - && execution.item.itemType == item.itemType - && execution.item.token == item.token + execution.offerer == caller && + execution.conduitKey == conduitKey && + execution.item.itemType == item.itemType && + execution.item.token == item.token ) { return false; } @@ -902,13 +951,14 @@ library MutationHelpersLib { i < context.expectations.expectedImplicitPostExecutions.length; ++i ) { - Execution memory execution = - context.expectations.expectedImplicitPostExecutions[i]; + Execution memory execution = context + .expectations + .expectedImplicitPostExecutions[i]; if ( - execution.offerer == caller - && execution.conduitKey == conduitKey - && execution.item.itemType == item.itemType - && execution.item.token == item.token + execution.offerer == caller && + execution.conduitKey == conduitKey && + execution.item.itemType == item.itemType && + execution.item.token == item.token ) { return false; } @@ -925,22 +975,21 @@ library Failarray { return arr; } - function and(Failure a, Failure b) - internal - pure - returns (Failure[] memory) - { + function and( + Failure a, + Failure b + ) internal pure returns (Failure[] memory) { Failure[] memory arr = new Failure[](2); arr[0] = a; arr[1] = b; return arr; } - function and(Failure a, Failure b, Failure c) - internal - pure - returns (Failure[] memory) - { + function and( + Failure a, + Failure b, + Failure c + ) internal pure returns (Failure[] memory) { Failure[] memory arr = new Failure[](3); arr[0] = a; arr[1] = b; @@ -948,11 +997,12 @@ library Failarray { return arr; } - function and(Failure a, Failure b, Failure c, Failure d) - internal - pure - returns (Failure[] memory) - { + function and( + Failure a, + Failure b, + Failure c, + Failure d + ) internal pure returns (Failure[] memory) { Failure[] memory arr = new Failure[](4); arr[0] = a; arr[1] = b; @@ -961,11 +1011,13 @@ library Failarray { return arr; } - function and(Failure a, Failure b, Failure c, Failure d, Failure e) - internal - pure - returns (Failure[] memory) - { + function and( + Failure a, + Failure b, + Failure c, + Failure d, + Failure e + ) internal pure returns (Failure[] memory) { Failure[] memory arr = new Failure[](5); arr[0] = a; arr[1] = b; @@ -1013,11 +1065,10 @@ library Failarray { return arr; } - function and(Failure[] memory originalArr, Failure a) - internal - pure - returns (Failure[] memory) - { + function and( + Failure[] memory originalArr, + Failure a + ) internal pure returns (Failure[] memory) { Failure[] memory arr = new Failure[](originalArr.length + 1); for (uint256 i = 0; i < originalArr.length; ++i) { @@ -1029,11 +1080,11 @@ library Failarray { return arr; } - function and(Failure[] memory originalArr, Failure a, Failure b) - internal - pure - returns (Failure[] memory) - { + function and( + Failure[] memory originalArr, + Failure a, + Failure b + ) internal pure returns (Failure[] memory) { Failure[] memory arr = new Failure[](originalArr.length + 2); for (uint256 i = 0; i < originalArr.length; ++i) { @@ -1046,11 +1097,12 @@ library Failarray { return arr; } - function and(Failure[] memory originalArr, Failure a, Failure b, Failure c) - internal - pure - returns (Failure[] memory) - { + function and( + Failure[] memory originalArr, + Failure a, + Failure b, + Failure c + ) internal pure returns (Failure[] memory) { Failure[] memory arr = new Failure[](originalArr.length + 3); for (uint256 i = 0; i < originalArr.length; ++i) { diff --git a/test/foundry/new/helpers/FuzzMutationSelectorLib.sol b/test/foundry/new/helpers/FuzzMutationSelectorLib.sol index e063660..0d8e299 100644 --- a/test/foundry/new/helpers/FuzzMutationSelectorLib.sol +++ b/test/foundry/new/helpers/FuzzMutationSelectorLib.sol @@ -26,32 +26,41 @@ import { import { LibPRNG } from "solady/src/utils/LibPRNG.sol"; -import { SignatureVerificationErrors } from - "seaport-types/src/interfaces/SignatureVerificationErrors.sol"; +import { + SignatureVerificationErrors +} from "seaport-types/src/interfaces/SignatureVerificationErrors.sol"; -import { ConsiderationEventsAndErrors } from - "seaport-types/src/interfaces/ConsiderationEventsAndErrors.sol"; +import { + ConsiderationEventsAndErrors +} from "seaport-types/src/interfaces/ConsiderationEventsAndErrors.sol"; -import { FulfillmentApplicationErrors } from - "seaport-types/src/interfaces/FulfillmentApplicationErrors.sol"; +import { + FulfillmentApplicationErrors +} from "seaport-types/src/interfaces/FulfillmentApplicationErrors.sol"; -import { CriteriaResolutionErrors } from - "seaport-types/src/interfaces/CriteriaResolutionErrors.sol"; +import { + CriteriaResolutionErrors +} from "seaport-types/src/interfaces/CriteriaResolutionErrors.sol"; -import { TokenTransferrerErrors } from - "seaport-types/src/interfaces/TokenTransferrerErrors.sol"; +import { + TokenTransferrerErrors +} from "seaport-types/src/interfaces/TokenTransferrerErrors.sol"; -import { ZoneInteractionErrors } from - "seaport-types/src/interfaces/ZoneInteractionErrors.sol"; +import { + ZoneInteractionErrors +} from "seaport-types/src/interfaces/ZoneInteractionErrors.sol"; -import { AmountDerivationErrors } from - "seaport-types/src/interfaces/AmountDerivationErrors.sol"; +import { + AmountDerivationErrors +} from "seaport-types/src/interfaces/AmountDerivationErrors.sol"; -import { HashCalldataContractOfferer } from - "../../../../src/main/test/HashCalldataContractOfferer.sol"; +import { + HashCalldataContractOfferer +} from "../../../../src/main/test/HashCalldataContractOfferer.sol"; -import { HashValidationZoneOfferer } from - "../../../../src/main/test/HashValidationZoneOfferer.sol"; +import { + HashValidationZoneOfferer +} from "../../../../src/main/test/HashValidationZoneOfferer.sol"; /////////////////////// UPDATE THIS TO ADD FAILURE TESTS /////////////////////// enum Failure { @@ -147,13 +156,15 @@ library FuzzMutationSelectorLib { MutationFilters.ineligibleForInvalidSignature ); - failuresAndFilters[i++] = Failure.InvalidSigner_BadSignature.and( - Failure.InvalidSigner_ModifiedOrder - ).withOrder(MutationFilters.ineligibleForInvalidSigner); + failuresAndFilters[i++] = Failure + .InvalidSigner_BadSignature + .and(Failure.InvalidSigner_ModifiedOrder) + .withOrder(MutationFilters.ineligibleForInvalidSigner); - failuresAndFilters[i++] = Failure.InvalidTime_NotStarted.and( - Failure.InvalidTime_Expired - ).withOrder(MutationFilters.ineligibleForInvalidTime); + failuresAndFilters[i++] = Failure + .InvalidTime_NotStarted + .and(Failure.InvalidTime_Expired) + .withOrder(MutationFilters.ineligibleForInvalidTime); failuresAndFilters[i++] = Failure.InvalidConduit.withOrder( MutationFilters.ineligibleForInvalidConduit @@ -165,7 +176,9 @@ library FuzzMutationSelectorLib { failuresAndFilters[i++] = Failure .BadFraction_PartialContractOrder - .withOrder(MutationFilters.ineligibleForBadFractionPartialContractOrder); + .withOrder( + MutationFilters.ineligibleForBadFractionPartialContractOrder + ); failuresAndFilters[i++] = Failure.BadFraction_Overfill.withOrder( MutationFilters.ineligibleForBadFraction @@ -187,65 +200,65 @@ library FuzzMutationSelectorLib { MutationFilters.ineligibleForOrderAlreadyFilled ); - failuresAndFilters[i++] = Failure.BadContractSignature_BadSignature.and( - Failure.BadContractSignature_ModifiedOrder - ).and(Failure.BadContractSignature_MissingMagic).withOrder( - MutationFilters.ineligibleForBadContractSignature - ); + failuresAndFilters[i++] = Failure + .BadContractSignature_BadSignature + .and(Failure.BadContractSignature_ModifiedOrder) + .and(Failure.BadContractSignature_MissingMagic) + .withOrder(MutationFilters.ineligibleForBadContractSignature); failuresAndFilters[i++] = Failure .MissingOriginalConsiderationItems .withOrder( - MutationFilters.ineligibleForMissingOriginalConsiderationItems - ); + MutationFilters.ineligibleForMissingOriginalConsiderationItems + ); failuresAndFilters[i++] = Failure .ConsiderationLengthNotEqualToTotalOriginal_ExtraItems .withOrder( - MutationFilters - .ineligibleForConsiderationLengthNotEqualToTotalOriginal - ); + MutationFilters + .ineligibleForConsiderationLengthNotEqualToTotalOriginal + ); failuresAndFilters[i++] = Failure .ConsiderationLengthNotEqualToTotalOriginal_MissingItems .withOrder( - MutationFilters - .ineligibleForConsiderationLengthNotEqualToTotalOriginal - ); + MutationFilters + .ineligibleForConsiderationLengthNotEqualToTotalOriginal + ); failuresAndFilters[i++] = Failure .InvalidFulfillmentComponentData .withGeneric( - MutationFilters.ineligibleForInvalidFulfillmentComponentData - ); + MutationFilters.ineligibleForInvalidFulfillmentComponentData + ); failuresAndFilters[i++] = Failure .MissingFulfillmentComponentOnAggregation .withGeneric( - MutationFilters - .ineligibleForMissingFulfillmentComponentOnAggregation - ); + MutationFilters + .ineligibleForMissingFulfillmentComponentOnAggregation + ); failuresAndFilters[i++] = Failure .OfferAndConsiderationRequiredOnFulfillment .withGeneric( - MutationFilters - .ineligibleForOfferAndConsiderationRequiredOnFulfillment - ); + MutationFilters + .ineligibleForOfferAndConsiderationRequiredOnFulfillment + ); failuresAndFilters[i++] = Failure .MismatchedFulfillmentOfferAndConsiderationComponents_Modified .withGeneric( - MutationFilters - .ineligibleForMismatchedFulfillmentOfferAndConsiderationComponents_Modified - ); + MutationFilters + .ineligibleForMismatchedFulfillmentOfferAndConsiderationComponents_Modified + ); failuresAndFilters[i++] = Failure .MismatchedFulfillmentOfferAndConsiderationComponents_Swapped .withGeneric( - MutationFilters - .ineligibleForMismatchedFulfillmentOfferAndConsiderationComponents_Swapped - ); + MutationFilters + .ineligibleForMismatchedFulfillmentOfferAndConsiderationComponents_Swapped + ); failuresAndFilters[i++] = Failure .Error_OfferItemMissingApproval @@ -266,8 +279,8 @@ library FuzzMutationSelectorLib { failuresAndFilters[i++] = Failure .NativeTokenTransferGenericFailure .withGeneric( - MutationFilters.ineligibleForNativeTokenTransferGenericFailure - ); + MutationFilters.ineligibleForNativeTokenTransferGenericFailure + ); failuresAndFilters[i++] = Failure.CriteriaNotEnabledForItem.withGeneric( MutationFilters.ineligibleForCriteriaNotEnabledForItem @@ -285,24 +298,27 @@ library FuzzMutationSelectorLib { .OrderCriteriaResolverOutOfRange .withGeneric(MutationFilters.ineligibleWhenNotAdvanced); - failuresAndFilters[i++] = Failure.OfferCriteriaResolverOutOfRange.and( - Failure.UnresolvedOfferCriteria - ).withCriteria( - MutationFilters.ineligibleForOfferCriteriaResolverFailure - ); + failuresAndFilters[i++] = Failure + .OfferCriteriaResolverOutOfRange + .and(Failure.UnresolvedOfferCriteria) + .withCriteria( + MutationFilters.ineligibleForOfferCriteriaResolverFailure + ); failuresAndFilters[i++] = Failure .ConsiderationCriteriaResolverOutOfRange - .and(Failure.UnresolvedConsiderationCriteria).withCriteria( - MutationFilters.ineligibleForConsiderationCriteriaResolverFailure - ); + .and(Failure.UnresolvedConsiderationCriteria) + .withCriteria( + MutationFilters + .ineligibleForConsiderationCriteriaResolverFailure + ); failuresAndFilters[i++] = Failure .MissingItemAmount_OfferItem_FulfillAvailable .withGeneric( - MutationFilters - .ineligibleForMissingItemAmount_OfferItem_FulfillAvailable - ); + MutationFilters + .ineligibleForMissingItemAmount_OfferItem_FulfillAvailable + ); failuresAndFilters[i++] = Failure.MissingItemAmount_OfferItem.withOrder( MutationFilters.ineligibleForMissingItemAmount_OfferItem @@ -311,55 +327,58 @@ library FuzzMutationSelectorLib { failuresAndFilters[i++] = Failure .MissingItemAmount_ConsiderationItem .withOrder( - MutationFilters.ineligibleForMissingItemAmount_ConsiderationItem - ); + MutationFilters.ineligibleForMissingItemAmount_ConsiderationItem + ); failuresAndFilters[i++] = Failure .InvalidContractOrder_generateReturnsInvalidEncoding - .and(Failure.InvalidContractOrder_generateReverts).withOrder( - MutationFilters.ineligibleWhenNotContractOrderOrFulfillAvailable - ); + .and(Failure.InvalidContractOrder_generateReverts) + .withOrder( + MutationFilters.ineligibleWhenNotContractOrderOrFulfillAvailable + ); - failuresAndFilters[i++] = Failure.InvalidContractOrder_ratifyReverts.and( - Failure.InvalidContractOrder_InvalidMagicValue - ).withOrder( - MutationFilters.ineligibleWhenNotAvailableOrNotContractOrder - ); + failuresAndFilters[i++] = Failure + .InvalidContractOrder_ratifyReverts + .and(Failure.InvalidContractOrder_InvalidMagicValue) + .withOrder( + MutationFilters.ineligibleWhenNotAvailableOrNotContractOrder + ); failuresAndFilters[i++] = Failure .InvalidContractOrder_InsufficientMinimumReceived - .and( - Failure.InvalidContractOrder_IncorrectMinimumReceived - ).withOrder( - MutationFilters - .ineligibleWhenNotActiveTimeOrNotContractOrderOrNoOffer - ); + .and(Failure.InvalidContractOrder_IncorrectMinimumReceived) + .withOrder( + MutationFilters + .ineligibleWhenNotActiveTimeOrNotContractOrderOrNoOffer + ); failuresAndFilters[i++] = Failure .InvalidContractOrder_ExcessMaximumSpent .withOrder( - MutationFilters.ineligibleWhenNotActiveTimeOrNotContractOrder - ); + MutationFilters.ineligibleWhenNotActiveTimeOrNotContractOrder + ); failuresAndFilters[i++] = Failure .InvalidContractOrder_IncorrectMaximumSpent .withOrder( - MutationFilters - .ineligibleWhenNotActiveTimeOrNotContractOrderOrNoConsideration - ); + MutationFilters + .ineligibleWhenNotActiveTimeOrNotContractOrderOrNoConsideration + ); failuresAndFilters[i++] = Failure .InvalidRestrictedOrder_authorizeReverts_matchReverts .withOrder( - MutationFilters.ineligibleWhenFulfillAvailableOrNotAvailableOrNotRestricted - ); + MutationFilters + .ineligibleWhenFulfillAvailableOrNotAvailableOrNotRestricted + ); - failuresAndFilters[i++] = Failure.InvalidRestrictedOrder_authorizeInvalidMagicValue.and( - Failure.InvalidRestrictedOrder_validateReverts) - .and(Failure.InvalidRestrictedOrder_validateInvalidMagicValue - ).withOrder( - MutationFilters.ineligibleWhenNotAvailableOrNotRestrictedOrder - ); + failuresAndFilters[i++] = Failure + .InvalidRestrictedOrder_authorizeInvalidMagicValue + .and(Failure.InvalidRestrictedOrder_validateReverts) + .and(Failure.InvalidRestrictedOrder_validateInvalidMagicValue) + .withOrder( + MutationFilters.ineligibleWhenNotAvailableOrNotRestrictedOrder + ); failuresAndFilters[i++] = Failure.NoContract.withGeneric( MutationFilters.ineligibleForNoContract @@ -371,7 +390,9 @@ library FuzzMutationSelectorLib { failuresAndFilters[i++] = Failure .UnusedItemParameters_Identifier - .withOrder(MutationFilters.ineligibleForUnusedItemParameters_Identifier); + .withOrder( + MutationFilters.ineligibleForUnusedItemParameters_Identifier + ); failuresAndFilters[i++] = Failure.InvalidERC721TransferAmount.withOrder( MutationFilters.ineligibleForInvalidERC721TransferAmount @@ -383,7 +404,9 @@ library FuzzMutationSelectorLib { failuresAndFilters[i++] = Failure .PartialFillsNotEnabledForOrder - .withOrder(MutationFilters.ineligibleForPartialFillsNotEnabledForOrder); + .withOrder( + MutationFilters.ineligibleForPartialFillsNotEnabledForOrder + ); failuresAndFilters[i++] = Failure.InexactFraction.withOrder( MutationFilters.ineligibleForInexactFraction @@ -393,9 +416,11 @@ library FuzzMutationSelectorLib { MutationFilters.ineligibleForPanic_PartialFillOverflow ); - failuresAndFilters[i++] = Failure.NoSpecifiedOrdersAvailable.withGeneric( - MutationFilters.ineligibleForNoSpecifiedOrdersAvailable - ); + failuresAndFilters[i++] = Failure + .NoSpecifiedOrdersAvailable + .withGeneric( + MutationFilters.ineligibleForNoSpecifiedOrdersAvailable + ); //////////////////////////////////////////////////////////////////////// // Set the actual length of the array. @@ -404,7 +429,9 @@ library FuzzMutationSelectorLib { } } - function selectMutation(FuzzTestContext memory context) + function selectMutation( + FuzzTestContext memory context + ) public returns ( string memory name, @@ -423,7 +450,10 @@ library FuzzMutationSelectorLib { context.setAllIneligibleFailures(failuresAndFilters); (name, mutationSelector, expectedRevertReason, mutationState) = context - .failureDetails(context.selectEligibleFailure(), failuresAndFilters); + .failureDetails( + context.selectEligibleFailure(), + failuresAndFilters + ); } } @@ -452,213 +482,222 @@ library FailureDetailsLib { .InvalidSignature .selector .withOrder( - "InvalidSignature", FuzzMutations.mutation_invalidSignature.selector - ); + "InvalidSignature", + FuzzMutations.mutation_invalidSignature.selector + ); failureDetailsArray[i++] = SignatureVerificationErrors .InvalidSigner .selector .withOrder( - "InvalidSigner_BadSignature", - FuzzMutations.mutation_invalidSigner_BadSignature.selector - ); + "InvalidSigner_BadSignature", + FuzzMutations.mutation_invalidSigner_BadSignature.selector + ); failureDetailsArray[i++] = SignatureVerificationErrors .InvalidSigner .selector .withOrder( - "InvalidSigner_ModifiedOrder", - FuzzMutations.mutation_invalidSigner_ModifiedOrder.selector - ); + "InvalidSigner_ModifiedOrder", + FuzzMutations.mutation_invalidSigner_ModifiedOrder.selector + ); failureDetailsArray[i++] = SignatureVerificationErrors .BadSignatureV .selector .withOrder( - "BadSignatureV", - FuzzMutations.mutation_badSignatureV.selector, - details_BadSignatureV - ); + "BadSignatureV", + FuzzMutations.mutation_badSignatureV.selector, + details_BadSignatureV + ); failureDetailsArray[i++] = SignatureVerificationErrors .BadContractSignature .selector .withOrder( - "BadContractSignature_BadSignature", - FuzzMutations.mutation_badContractSignature_BadSignature.selector - ); + "BadContractSignature_BadSignature", + FuzzMutations + .mutation_badContractSignature_BadSignature + .selector + ); failureDetailsArray[i++] = SignatureVerificationErrors .BadContractSignature .selector .withOrder( - "BadContractSignature_ModifiedOrder", - FuzzMutations.mutation_badContractSignature_ModifiedOrder.selector - ); + "BadContractSignature_ModifiedOrder", + FuzzMutations + .mutation_badContractSignature_ModifiedOrder + .selector + ); failureDetailsArray[i++] = SignatureVerificationErrors .BadContractSignature .selector .withOrder( - "BadContractSignature_MissingMagic", - FuzzMutations.mutation_badContractSignature_MissingMagic.selector - ); + "BadContractSignature_MissingMagic", + FuzzMutations + .mutation_badContractSignature_MissingMagic + .selector + ); failureDetailsArray[i++] = ConsiderationEventsAndErrors .ConsiderationLengthNotEqualToTotalOriginal .selector .withOrder( - "ConsiderationLengthNotEqualToTotalOriginal_ExtraItems", - FuzzMutations - .mutation_considerationLengthNotEqualToTotalOriginal_ExtraItems - .selector - ); + "ConsiderationLengthNotEqualToTotalOriginal_ExtraItems", + FuzzMutations + .mutation_considerationLengthNotEqualToTotalOriginal_ExtraItems + .selector + ); failureDetailsArray[i++] = ConsiderationEventsAndErrors .ConsiderationLengthNotEqualToTotalOriginal .selector .withOrder( - "ConsiderationLengthNotEqualToTotalOriginal_MissingItens", - FuzzMutations - .mutation_considerationLengthNotEqualToTotalOriginal_MissingItems - .selector - ); + "ConsiderationLengthNotEqualToTotalOriginal_MissingItens", + FuzzMutations + .mutation_considerationLengthNotEqualToTotalOriginal_MissingItems + .selector + ); failureDetailsArray[i++] = ConsiderationEventsAndErrors .MissingOriginalConsiderationItems .selector .withOrder( - "MissingOriginalConsiderationItems", - FuzzMutations.mutation_missingOriginalConsiderationItems.selector - ); + "MissingOriginalConsiderationItems", + FuzzMutations + .mutation_missingOriginalConsiderationItems + .selector + ); failureDetailsArray[i++] = ConsiderationEventsAndErrors .InvalidTime .selector .withOrder( - "InvalidTime_NotStarted", - FuzzMutations.mutation_invalidTime_NotStarted.selector, - details_InvalidTime_NotStarted - ); + "InvalidTime_NotStarted", + FuzzMutations.mutation_invalidTime_NotStarted.selector, + details_InvalidTime_NotStarted + ); failureDetailsArray[i++] = ConsiderationEventsAndErrors .InvalidTime .selector .withOrder( - "InvalidTime_Expired", - FuzzMutations.mutation_invalidTime_Expired.selector, - details_InvalidTime_Expired - ); + "InvalidTime_Expired", + FuzzMutations.mutation_invalidTime_Expired.selector, + details_InvalidTime_Expired + ); failureDetailsArray[i++] = ConsiderationEventsAndErrors .InvalidConduit .selector .withOrder( - "InvalidConduit", - FuzzMutations.mutation_invalidConduit.selector, - details_InvalidConduit - ); + "InvalidConduit", + FuzzMutations.mutation_invalidConduit.selector, + details_InvalidConduit + ); failureDetailsArray[i++] = ConsiderationEventsAndErrors .BadFraction .selector .withOrder( - "BadFraction_PartialContractOrder", - FuzzMutations.mutation_badFraction_partialContractOrder.selector - ); + "BadFraction_PartialContractOrder", + FuzzMutations.mutation_badFraction_partialContractOrder.selector + ); failureDetailsArray[i++] = ConsiderationEventsAndErrors .BadFraction .selector .withOrder( - "BadFraction_NoFill", - FuzzMutations.mutation_badFraction_NoFill.selector - ); + "BadFraction_NoFill", + FuzzMutations.mutation_badFraction_NoFill.selector + ); failureDetailsArray[i++] = ConsiderationEventsAndErrors .BadFraction .selector .withOrder( - "BadFraction_Overfill", - FuzzMutations.mutation_badFraction_Overfill.selector - ); + "BadFraction_Overfill", + FuzzMutations.mutation_badFraction_Overfill.selector + ); failureDetailsArray[i++] = ConsiderationEventsAndErrors .CannotCancelOrder .selector .withOrder( - "CannotCancelOrder", - FuzzMutations.mutation_cannotCancelOrder.selector - ); + "CannotCancelOrder", + FuzzMutations.mutation_cannotCancelOrder.selector + ); failureDetailsArray[i++] = ConsiderationEventsAndErrors .OrderIsCancelled .selector .withOrder( - "OrderIsCancelled", - FuzzMutations.mutation_orderIsCancelled.selector, - details_withOrderHash - ); + "OrderIsCancelled", + FuzzMutations.mutation_orderIsCancelled.selector, + details_withOrderHash + ); failureDetailsArray[i++] = ConsiderationEventsAndErrors .OrderAlreadyFilled .selector .withOrder( - "OrderAlreadyFilled", - FuzzMutations.mutation_orderAlreadyFilled.selector, - details_OrderAlreadyFilled - ); + "OrderAlreadyFilled", + FuzzMutations.mutation_orderAlreadyFilled.selector, + details_OrderAlreadyFilled + ); failureDetailsArray[i++] = FulfillmentApplicationErrors .InvalidFulfillmentComponentData .selector .withGeneric( - "InvalidFulfillmentComponentData", - FuzzMutations.mutation_invalidFulfillmentComponentData.selector - ); + "InvalidFulfillmentComponentData", + FuzzMutations.mutation_invalidFulfillmentComponentData.selector + ); failureDetailsArray[i++] = FulfillmentApplicationErrors .MissingFulfillmentComponentOnAggregation .selector .withGeneric( - "MissingFulfillmentComponentOnAggregation", - FuzzMutations - .mutation_missingFulfillmentComponentOnAggregation - .selector, - details_MissingFulfillmentComponentOnAggregation - ); + "MissingFulfillmentComponentOnAggregation", + FuzzMutations + .mutation_missingFulfillmentComponentOnAggregation + .selector, + details_MissingFulfillmentComponentOnAggregation + ); failureDetailsArray[i++] = FulfillmentApplicationErrors .OfferAndConsiderationRequiredOnFulfillment .selector .withGeneric( - "OfferAndConsiderationRequiredOnFulfillment", - FuzzMutations - .mutation_offerAndConsiderationRequiredOnFulfillment - .selector - ); + "OfferAndConsiderationRequiredOnFulfillment", + FuzzMutations + .mutation_offerAndConsiderationRequiredOnFulfillment + .selector + ); failureDetailsArray[i++] = FulfillmentApplicationErrors .MismatchedFulfillmentOfferAndConsiderationComponents .selector .withGeneric( - "MismatchedFulfillmentOfferAndConsiderationComponents_Modified", - FuzzMutations - .mutation_mismatchedFulfillmentOfferAndConsiderationComponents_Modified - .selector, - details_MismatchedFulfillmentOfferAndConsiderationComponents - ); + "MismatchedFulfillmentOfferAndConsiderationComponents_Modified", + FuzzMutations + .mutation_mismatchedFulfillmentOfferAndConsiderationComponents_Modified + .selector, + details_MismatchedFulfillmentOfferAndConsiderationComponents + ); failureDetailsArray[i++] = FulfillmentApplicationErrors .MismatchedFulfillmentOfferAndConsiderationComponents .selector .withGeneric( - "MismatchedFulfillmentOfferAndConsiderationComponents_Swapped", - FuzzMutations - .mutation_mismatchedFulfillmentOfferAndConsiderationComponents_Swapped - .selector, - details_MismatchedFulfillmentOfferAndConsiderationComponents - ); + "MismatchedFulfillmentOfferAndConsiderationComponents_Swapped", + FuzzMutations + .mutation_mismatchedFulfillmentOfferAndConsiderationComponents_Swapped + .selector, + details_MismatchedFulfillmentOfferAndConsiderationComponents + ); failureDetailsArray[i++] = ERROR_STRING.withOrder( "Error_OfferItemMissingApproval", @@ -676,304 +715,311 @@ library FailureDetailsLib { .InvalidMsgValue .selector .withGeneric( - "InvalidMsgValue", - FuzzMutations.mutation_invalidMsgValue.selector, - details_InvalidMsgValue - ); + "InvalidMsgValue", + FuzzMutations.mutation_invalidMsgValue.selector, + details_InvalidMsgValue + ); failureDetailsArray[i++] = ConsiderationEventsAndErrors .InsufficientNativeTokensSupplied .selector .withGeneric( - "InsufficientNativeTokensSupplied", - FuzzMutations.mutation_insufficientNativeTokensSupplied.selector - ); + "InsufficientNativeTokensSupplied", + FuzzMutations.mutation_insufficientNativeTokensSupplied.selector + ); failureDetailsArray[i++] = ConsiderationEventsAndErrors .NativeTokenTransferGenericFailure .selector .withGeneric( - "NativeTokenTransferGenericFailure", - FuzzMutations.mutation_insufficientNativeTokensSupplied.selector, - details_NativeTokenTransferGenericFailure - ); + "NativeTokenTransferGenericFailure", + FuzzMutations + .mutation_insufficientNativeTokensSupplied + .selector, + details_NativeTokenTransferGenericFailure + ); failureDetailsArray[i++] = CriteriaResolutionErrors .CriteriaNotEnabledForItem .selector .withGeneric( - "CriteriaNotEnabledForItem", - FuzzMutations.mutation_criteriaNotEnabledForItem.selector - ); + "CriteriaNotEnabledForItem", + FuzzMutations.mutation_criteriaNotEnabledForItem.selector + ); failureDetailsArray[i++] = CriteriaResolutionErrors .InvalidProof .selector .withCriteria( - "InvalidProof_Merkle", - FuzzMutations.mutation_invalidMerkleProof.selector - ); + "InvalidProof_Merkle", + FuzzMutations.mutation_invalidMerkleProof.selector + ); failureDetailsArray[i++] = CriteriaResolutionErrors .InvalidProof .selector .withCriteria( - "InvalidProof_Wildcard", - FuzzMutations.mutation_invalidWildcardProof.selector - ); + "InvalidProof_Wildcard", + FuzzMutations.mutation_invalidWildcardProof.selector + ); failureDetailsArray[i++] = CriteriaResolutionErrors .OrderCriteriaResolverOutOfRange .selector .withGeneric( - "OrderCriteriaResolverOutOfRange", - FuzzMutations.mutation_orderCriteriaResolverOutOfRange.selector, - details_withZero - ); + "OrderCriteriaResolverOutOfRange", + FuzzMutations.mutation_orderCriteriaResolverOutOfRange.selector, + details_withZero + ); failureDetailsArray[i++] = CriteriaResolutionErrors .OfferCriteriaResolverOutOfRange .selector .withCriteria( - "OfferCriteriaResolverOutOfRange", - FuzzMutations.mutation_offerCriteriaResolverOutOfRange.selector - ); + "OfferCriteriaResolverOutOfRange", + FuzzMutations.mutation_offerCriteriaResolverOutOfRange.selector + ); failureDetailsArray[i++] = CriteriaResolutionErrors .ConsiderationCriteriaResolverOutOfRange .selector .withCriteria( - "ConsiderationCriteriaResolverOutOfRange", - FuzzMutations - .mutation_considerationCriteriaResolverOutOfRange - .selector - ); + "ConsiderationCriteriaResolverOutOfRange", + FuzzMutations + .mutation_considerationCriteriaResolverOutOfRange + .selector + ); failureDetailsArray[i++] = CriteriaResolutionErrors .UnresolvedOfferCriteria .selector .withCriteria( - "UnresolvedOfferCriteria", - FuzzMutations.mutation_unresolvedCriteria.selector, - details_unresolvedCriteria - ); + "UnresolvedOfferCriteria", + FuzzMutations.mutation_unresolvedCriteria.selector, + details_unresolvedCriteria + ); failureDetailsArray[i++] = CriteriaResolutionErrors .UnresolvedConsiderationCriteria .selector .withCriteria( - "UnresolvedConsiderationCriteria", - FuzzMutations.mutation_unresolvedCriteria.selector, - details_unresolvedCriteria - ); + "UnresolvedConsiderationCriteria", + FuzzMutations.mutation_unresolvedCriteria.selector, + details_unresolvedCriteria + ); failureDetailsArray[i++] = TokenTransferrerErrors .MissingItemAmount .selector .withGeneric( - "MissingItemAmount_OfferItem_FulfillAvailable", - FuzzMutations - .mutation_missingItemAmount_OfferItem_FulfillAvailable - .selector - ); + "MissingItemAmount_OfferItem_FulfillAvailable", + FuzzMutations + .mutation_missingItemAmount_OfferItem_FulfillAvailable + .selector + ); failureDetailsArray[i++] = TokenTransferrerErrors .MissingItemAmount .selector .withOrder( - "MissingItemAmount_OfferItem", - FuzzMutations.mutation_missingItemAmount_OfferItem.selector - ); + "MissingItemAmount_OfferItem", + FuzzMutations.mutation_missingItemAmount_OfferItem.selector + ); failureDetailsArray[i++] = TokenTransferrerErrors .MissingItemAmount .selector .withOrder( - "MissingItemAmount_ConsiderationItem", - FuzzMutations.mutation_missingItemAmount_ConsiderationItem.selector - ); + "MissingItemAmount_ConsiderationItem", + FuzzMutations + .mutation_missingItemAmount_ConsiderationItem + .selector + ); failureDetailsArray[i++] = ZoneInteractionErrors .InvalidContractOrder .selector .withOrder( - "InvalidContractOrder_generateReturnsInvalidEncoding", - FuzzMutations - .mutation_invalidContractOrderGenerateReturnsInvalidEncoding - .selector, - details_withOrderHash - ); + "InvalidContractOrder_generateReturnsInvalidEncoding", + FuzzMutations + .mutation_invalidContractOrderGenerateReturnsInvalidEncoding + .selector, + details_withOrderHash + ); failureDetailsArray[i++] = HashCalldataContractOfferer .HashCalldataContractOffererGenerateOrderReverts .selector .withOrder( - "InvalidContractOrder_generateReverts", - FuzzMutations - .mutation_invalidContractOrderGenerateReverts - .selector - ); + "InvalidContractOrder_generateReverts", + FuzzMutations + .mutation_invalidContractOrderGenerateReverts + .selector + ); failureDetailsArray[i++] = HashCalldataContractOfferer .HashCalldataContractOffererRatifyOrderReverts .selector .withOrder( - "InvalidContractOrder_ratifyReverts", - FuzzMutations.mutation_invalidContractOrderRatifyReverts.selector - ); + "InvalidContractOrder_ratifyReverts", + FuzzMutations + .mutation_invalidContractOrderRatifyReverts + .selector + ); failureDetailsArray[i++] = ZoneInteractionErrors .InvalidContractOrder .selector .withOrder( - "InvalidContractOrder_InsufficientMinimumReceived", - FuzzMutations - .mutation_invalidContractOrderInsufficientMinimumReceived - .selector, - details_withOrderHash - ); + "InvalidContractOrder_InsufficientMinimumReceived", + FuzzMutations + .mutation_invalidContractOrderInsufficientMinimumReceived + .selector, + details_withOrderHash + ); failureDetailsArray[i++] = ZoneInteractionErrors .InvalidContractOrder .selector .withOrder( - "InvalidContractOrder_IncorrectMinimumReceived", - FuzzMutations - .mutation_invalidContractOrderIncorrectMinimumReceived - .selector, - details_withOrderHash - ); + "InvalidContractOrder_IncorrectMinimumReceived", + FuzzMutations + .mutation_invalidContractOrderIncorrectMinimumReceived + .selector, + details_withOrderHash + ); failureDetailsArray[i++] = ZoneInteractionErrors .InvalidContractOrder .selector .withOrder( - "InvalidContractOrder_ExcessMaximumSpent", - FuzzMutations - .mutation_invalidContractOrderExcessMaximumSpent - .selector, - details_withOrderHash - ); + "InvalidContractOrder_ExcessMaximumSpent", + FuzzMutations + .mutation_invalidContractOrderExcessMaximumSpent + .selector, + details_withOrderHash + ); failureDetailsArray[i++] = ZoneInteractionErrors .InvalidContractOrder .selector .withOrder( - "InvalidContractOrder_IncorrectMaximumSpent", - FuzzMutations - .mutation_invalidContractOrderIncorrectMaximumSpent - .selector, - details_withOrderHash - ); + "InvalidContractOrder_IncorrectMaximumSpent", + FuzzMutations + .mutation_invalidContractOrderIncorrectMaximumSpent + .selector, + details_withOrderHash + ); failureDetailsArray[i++] = ZoneInteractionErrors .InvalidContractOrder .selector .withOrder( - "InvalidContractOrder_InvalidMagicValue", - FuzzMutations - .mutation_invalidContractOrderInvalidMagicValue - .selector, - details_withOrderHash - ); + "InvalidContractOrder_InvalidMagicValue", + FuzzMutations + .mutation_invalidContractOrderInvalidMagicValue + .selector, + details_withOrderHash + ); failureDetailsArray[i++] = HashValidationZoneOfferer .HashValidationZoneOffererAuthorizeOrderReverts .selector .withOrder( - "InvalidRestrictedOrder_authorizeReverts_matchReverts", - FuzzMutations - .mutation_invalidRestrictedOrderAuthorizeRevertsMatchReverts - .selector - ); + "InvalidRestrictedOrder_authorizeReverts_matchReverts", + FuzzMutations + .mutation_invalidRestrictedOrderAuthorizeRevertsMatchReverts + .selector + ); failureDetailsArray[i++] = HashValidationZoneOfferer .HashValidationZoneOffererValidateOrderReverts .selector .withOrder( - "InvalidRestrictedOrder_validateReverts", - FuzzMutations.mutation_invalidRestrictedOrderReverts.selector - ); + "InvalidRestrictedOrder_validateReverts", + FuzzMutations.mutation_invalidRestrictedOrderReverts.selector + ); failureDetailsArray[i++] = ZoneInteractionErrors .InvalidRestrictedOrder .selector .withOrder( - "InvalidRestrictedOrder_authorizeInvalidMagicValue", - FuzzMutations - .mutation_invalidRestrictedOrderAuthorizeInvalidMagicValue - .selector, - details_withOrderHash - ); + "InvalidRestrictedOrder_authorizeInvalidMagicValue", + FuzzMutations + .mutation_invalidRestrictedOrderAuthorizeInvalidMagicValue + .selector, + details_withOrderHash + ); failureDetailsArray[i++] = ZoneInteractionErrors .InvalidRestrictedOrder .selector .withOrder( - "InvalidRestrictedOrder_validateInvalidMagicValue", - FuzzMutations - .mutation_invalidRestrictedOrderValidateInvalidMagicValue - .selector, - details_withOrderHash - ); + "InvalidRestrictedOrder_validateInvalidMagicValue", + FuzzMutations + .mutation_invalidRestrictedOrderValidateInvalidMagicValue + .selector, + details_withOrderHash + ); failureDetailsArray[i++] = TokenTransferrerErrors .NoContract .selector .withGeneric( - "NoContract", - FuzzMutations.mutation_noContract.selector, - details_NoContract - ); + "NoContract", + FuzzMutations.mutation_noContract.selector, + details_NoContract + ); failureDetailsArray[i++] = TokenTransferrerErrors .UnusedItemParameters .selector .withOrder( - "UnusedItemParameters_Token", - FuzzMutations.mutation_unusedItemParameters_Token.selector - ); + "UnusedItemParameters_Token", + FuzzMutations.mutation_unusedItemParameters_Token.selector + ); failureDetailsArray[i++] = TokenTransferrerErrors .UnusedItemParameters .selector .withOrder( - "UnusedItemParameters_Identifier", - FuzzMutations.mutation_unusedItemParameters_Identifier.selector - ); + "UnusedItemParameters_Identifier", + FuzzMutations.mutation_unusedItemParameters_Identifier.selector + ); failureDetailsArray[i++] = TokenTransferrerErrors .InvalidERC721TransferAmount .selector .withOrder( - "InvalidERC721TransferAmount", - FuzzMutations.mutation_invalidERC721TransferAmount.selector, - details_InvalidERC721TransferAmount - ); + "InvalidERC721TransferAmount", + FuzzMutations.mutation_invalidERC721TransferAmount.selector, + details_InvalidERC721TransferAmount + ); failureDetailsArray[i++] = ConsiderationEventsAndErrors .ConsiderationNotMet .selector .withOrder( - "ConsiderationNotMet", - FuzzMutations.mutation_considerationNotMet.selector, - details_ConsiderationNotMet - ); + "ConsiderationNotMet", + FuzzMutations.mutation_considerationNotMet.selector, + details_ConsiderationNotMet + ); failureDetailsArray[i++] = ConsiderationEventsAndErrors .PartialFillsNotEnabledForOrder .selector .withOrder( - "PartialFillsNotEnabledForOrder", - FuzzMutations.mutation_partialFillsNotEnabledForOrder.selector - ); + "PartialFillsNotEnabledForOrder", + FuzzMutations.mutation_partialFillsNotEnabledForOrder.selector + ); failureDetailsArray[i++] = AmountDerivationErrors .InexactFraction .selector .withOrder( - "InexactFraction", FuzzMutations.mutation_inexactFraction.selector - ); + "InexactFraction", + FuzzMutations.mutation_inexactFraction.selector + ); failureDetailsArray[i++] = PANIC.withOrder( "Panic_PartialFillOverflow", @@ -985,9 +1031,9 @@ library FailureDetailsLib { .NoSpecifiedOrdersAvailable .selector .withGeneric( - "NoSpecifiedOrderAvailable", - FuzzMutations.mutation_noSpecifiedOrdersAvailable.selector - ); + "NoSpecifiedOrderAvailable", + FuzzMutations.mutation_noSpecifiedOrdersAvailable.selector + ); //////////////////////////////////////////////////////////////////////// if (i != uint256(Failure.length)) { @@ -1002,70 +1048,81 @@ library FailureDetailsLib { //////////////////// ADD NEW FUNCTIONS HERE WHEN NEEDED //////////////////// function details_NotAuthorized( - FuzzTestContext memory, /* context */ - MutationState memory, /* mutationState */ + FuzzTestContext memory /* context */, + MutationState memory /* mutationState */, bytes4 errorSelector ) internal pure returns (bytes memory expectedRevertReason) { - expectedRevertReason = - abi.encodeWithSelector(errorSelector, "NOT_AUTHORIZED"); + expectedRevertReason = abi.encodeWithSelector( + errorSelector, + "NOT_AUTHORIZED" + ); } function details_PanicOverflow( - FuzzTestContext memory, /* context */ - MutationState memory, /* mutationState */ + FuzzTestContext memory /* context */, + MutationState memory /* mutationState */, bytes4 errorSelector ) internal pure returns (bytes memory expectedRevertReason) { expectedRevertReason = abi.encodeWithSelector(errorSelector, 0x11); } function details_BadSignatureV( - FuzzTestContext memory, /* context */ - MutationState memory, /* mutationState */ + FuzzTestContext memory /* context */, + MutationState memory /* mutationState */, bytes4 errorSelector ) internal pure returns (bytes memory expectedRevertReason) { expectedRevertReason = abi.encodeWithSelector(errorSelector, 0xff); } function details_InvalidTime_NotStarted( - FuzzTestContext memory, /* context */ - MutationState memory, /* mutationState */ + FuzzTestContext memory /* context */, + MutationState memory /* mutationState */, bytes4 errorSelector ) internal view returns (bytes memory expectedRevertReason) { expectedRevertReason = abi.encodeWithSelector( - errorSelector, block.timestamp + 1, block.timestamp + 2 + errorSelector, + block.timestamp + 1, + block.timestamp + 2 ); } function details_InvalidTime_Expired( - FuzzTestContext memory, /* context */ - MutationState memory, /* mutationState */ + FuzzTestContext memory /* context */, + MutationState memory /* mutationState */, bytes4 errorSelector ) internal view returns (bytes memory expectedRevertReason) { expectedRevertReason = abi.encodeWithSelector( - errorSelector, block.timestamp - 1, block.timestamp + errorSelector, + block.timestamp - 1, + block.timestamp ); } function details_InvalidConduit( FuzzTestContext memory context, - MutationState memory, /* mutationState */ + MutationState memory /* mutationState */, bytes4 errorSelector ) internal view returns (bytes memory expectedRevertReason) { bytes32 conduitKey = keccak256("invalid conduit"); - (address conduitAddr,) = - context.conduitController.getConduit(conduitKey); + (address conduitAddr, ) = context.conduitController.getConduit( + conduitKey + ); - expectedRevertReason = - abi.encodeWithSelector(errorSelector, conduitKey, conduitAddr); + expectedRevertReason = abi.encodeWithSelector( + errorSelector, + conduitKey, + conduitAddr + ); } function details_withOrderHash( - FuzzTestContext memory, /* context */ + FuzzTestContext memory /* context */, MutationState memory mutationState, bytes4 errorSelector ) internal pure returns (bytes memory expectedRevertReason) { expectedRevertReason = abi.encodeWithSelector( - errorSelector, mutationState.selectedOrderHash + errorSelector, + mutationState.selectedOrderHash ); } @@ -1076,39 +1133,49 @@ library FailureDetailsLib { ) internal pure returns (bytes memory expectedRevertReason) { expectedRevertReason = abi.encodeWithSelector( errorSelector, - context.executionState.orderDetails[mutationState.selectedOrderIndex] + context + .executionState + .orderDetails[mutationState.selectedOrderIndex] .orderHash ); } function details_MissingFulfillmentComponentOnAggregation( - FuzzTestContext memory, /* context */ + FuzzTestContext memory /* context */, MutationState memory mutationState, bytes4 errorSelector ) internal pure returns (bytes memory expectedRevertReason) { - expectedRevertReason = - abi.encodeWithSelector(errorSelector, uint8(mutationState.side)); + expectedRevertReason = abi.encodeWithSelector( + errorSelector, + uint8(mutationState.side) + ); } function details_MismatchedFulfillmentOfferAndConsiderationComponents( - FuzzTestContext memory, /* context */ - MutationState memory, /* mutationState */ + FuzzTestContext memory /* context */, + MutationState memory /* mutationState */, bytes4 errorSelector ) internal pure returns (bytes memory expectedRevertReason) { - expectedRevertReason = abi.encodeWithSelector(errorSelector, uint256(0)); + expectedRevertReason = abi.encodeWithSelector( + errorSelector, + uint256(0) + ); } function details_withZero( - FuzzTestContext memory, /* context */ - MutationState memory, /* mutationState */ + FuzzTestContext memory /* context */, + MutationState memory /* mutationState */, bytes4 errorSelector ) internal pure returns (bytes memory expectedRevertReason) { - expectedRevertReason = abi.encodeWithSelector(errorSelector, uint256(0)); + expectedRevertReason = abi.encodeWithSelector( + errorSelector, + uint256(0) + ); } function details_InvalidMsgValue( FuzzTestContext memory context, - MutationState memory, /* mutationState */ + MutationState memory /* mutationState */, bytes4 errorSelector ) internal pure returns (bytes memory expectedRevertReason) { uint256 value = context.executionState.value == 0 ? 1 : 0; @@ -1117,11 +1184,12 @@ library FailureDetailsLib { function details_NativeTokenTransferGenericFailure( FuzzTestContext memory context, - MutationState memory, /* mutationState */ + MutationState memory /* mutationState */, bytes4 errorSelector ) internal pure returns (bytes memory expectedRevertReason) { - uint256 totalImplicitExecutions = - (context.expectations.expectedImplicitPostExecutions.length); + uint256 totalImplicitExecutions = ( + context.expectations.expectedImplicitPostExecutions.length + ); ReceivedItem memory item; if (context.expectations.expectedNativeTokensReturned == 0) { if (totalImplicitExecutions == 0) { @@ -1132,8 +1200,10 @@ library FailureDetailsLib { bool foundNative; for (uint256 i = totalImplicitExecutions - 1; i >= 0; --i) { - item = - context.expectations.expectedImplicitPostExecutions[i].item; + item = context + .expectations + .expectedImplicitPostExecutions[i] + .item; if (item.itemType == ItemType.NATIVE) { foundNative = true; break; @@ -1158,7 +1228,9 @@ library FailureDetailsLib { bool foundNative; for (uint256 i = totalImplicitExecutions - 1; i > 0; --i) { - item = context.expectations.expectedImplicitPostExecutions[i - 1] + item = context + .expectations + .expectedImplicitPostExecutions[i - 1] .item; if (item.itemType == ItemType.NATIVE) { @@ -1184,27 +1256,29 @@ library FailureDetailsLib { } function details_unresolvedCriteria( - FuzzTestContext memory, /* context */ + FuzzTestContext memory /* context */, MutationState memory mutationState, bytes4 errorSelector ) internal pure returns (bytes memory expectedRevertReason) { - CriteriaResolver memory resolver = - mutationState.selectedCriteriaResolver; + CriteriaResolver memory resolver = mutationState + .selectedCriteriaResolver; expectedRevertReason = abi.encodeWithSelector( - errorSelector, resolver.orderIndex, resolver.index + errorSelector, + resolver.orderIndex, + resolver.index ); } function details_InvalidERC721TransferAmount( - FuzzTestContext memory, /* context */ - MutationState memory, /* mutationState */ + FuzzTestContext memory /* context */, + MutationState memory /* mutationState */, bytes4 errorSelector ) internal pure returns (bytes memory expectedRevertReason) { expectedRevertReason = abi.encodeWithSelector(errorSelector, 2); } function details_ConsiderationNotMet( - FuzzTestContext memory, /* context */ + FuzzTestContext memory /* context */, MutationState memory mutationState, bytes4 errorSelector ) internal pure returns (bytes memory expectedRevertReason) { @@ -1217,25 +1291,31 @@ library FailureDetailsLib { } function details_NoContract( - FuzzTestContext memory, /* context */ + FuzzTestContext memory /* context */, MutationState memory mutationState, bytes4 errorSelector ) internal pure returns (bytes memory expectedRevertReason) { expectedRevertReason = abi.encodeWithSelector( - errorSelector, mutationState.selectedArbitraryAddress + errorSelector, + mutationState.selectedArbitraryAddress ); } - function errorString(string memory errorMessage) + function errorString( + string memory errorMessage + ) internal pure returns ( - function(FuzzTestContext memory, MutationState memory, bytes4) internal pure returns (bytes memory) + function(FuzzTestContext memory, MutationState memory, bytes4) + internal + pure + returns (bytes memory) ) { if ( - keccak256(abi.encodePacked(errorMessage)) - == keccak256(abi.encodePacked("NOT_AUTHORIZED")) + keccak256(abi.encodePacked(errorMessage)) == + keccak256(abi.encodePacked("NOT_AUTHORIZED")) ) { return details_NotAuthorized; } @@ -1259,8 +1339,9 @@ library FailureDetailsLib { MutationState memory ) { - FailureDetails memory details = - (declareFailureDetails()[uint256(failure)]); + FailureDetails memory details = ( + declareFailureDetails()[uint256(failure)] + ); MutationState memory mutationState = context.deriveMutationContext( details.derivationMethod, @@ -1274,7 +1355,7 @@ library FailureDetailsLib { mutationState, details.errorSelector, details.revertReasonDeriver - ), + ), mutationState ); } diff --git a/test/foundry/new/helpers/FuzzMutations.sol b/test/foundry/new/helpers/FuzzMutations.sol index bc374ab..4825256 100644 --- a/test/foundry/new/helpers/FuzzMutations.sol +++ b/test/foundry/new/helpers/FuzzMutations.sol @@ -66,14 +66,17 @@ import { import { EIP1271Offerer } from "./EIP1271Offerer.sol"; -import { HashCalldataContractOfferer } from - "../../../../src/main/test/HashCalldataContractOfferer.sol"; +import { + HashCalldataContractOfferer +} from "../../../../src/main/test/HashCalldataContractOfferer.sol"; -import { HashValidationZoneOfferer } from - "../../../../src/main/test/HashValidationZoneOfferer.sol"; +import { + HashValidationZoneOfferer +} from "../../../../src/main/test/HashValidationZoneOfferer.sol"; -import { OffererZoneFailureReason } from - "../../../../src/main/test/OffererZoneFailureReason.sol"; +import { + OffererZoneFailureReason +} from "../../../../src/main/test/OffererZoneFailureReason.sol"; interface TestERC20 { function approve(address spender, uint256 amount) external; @@ -101,20 +104,19 @@ library MutationFilters { FuzzTestContext memory context, uint256 orderIndex ) internal pure returns (bool) { - return context.executionState.orderDetails[orderIndex].unavailableReason - != UnavailableReason.AVAILABLE; + return + context.executionState.orderDetails[orderIndex].unavailableReason != + UnavailableReason.AVAILABLE; } - function ineligibleWhenBasic(FuzzTestContext memory context) - internal - view - returns (bool) - { + function ineligibleWhenBasic( + FuzzTestContext memory context + ) internal view returns (bool) { bytes4 action = context.action(); if ( - action == context.seaport.fulfillBasicOrder.selector - || action - == context.seaport.fulfillBasicOrder_efficient_6GL6yc.selector + action == context.seaport.fulfillBasicOrder.selector || + action == + context.seaport.fulfillBasicOrder_efficient_6GL6yc.selector ) { return true; } @@ -122,16 +124,14 @@ library MutationFilters { return false; } - function ineligibleWhenFulfillAvailable(FuzzTestContext memory context) - internal - view - returns (bool) - { + function ineligibleWhenFulfillAvailable( + FuzzTestContext memory context + ) internal view returns (bool) { bytes4 action = context.action(); if ( - action == context.seaport.fulfillAvailableOrders.selector - || action == context.seaport.fulfillAvailableAdvancedOrders.selector + action == context.seaport.fulfillAvailableOrders.selector || + action == context.seaport.fulfillAvailableAdvancedOrders.selector ) { return true; } @@ -139,15 +139,13 @@ library MutationFilters { return false; } - function ineligibleWhenMatch(FuzzTestContext memory context) - internal - view - returns (bool) - { + function ineligibleWhenMatch( + FuzzTestContext memory context + ) internal view returns (bool) { bytes4 action = context.action(); if ( - action == context.seaport.matchOrders.selector - || action == context.seaport.matchAdvancedOrders.selector + action == context.seaport.matchOrders.selector || + action == context.seaport.matchAdvancedOrders.selector ) { return true; } @@ -155,15 +153,13 @@ library MutationFilters { return false; } - function ineligibleWhenNotMatch(FuzzTestContext memory context) - internal - view - returns (bool) - { + function ineligibleWhenNotMatch( + FuzzTestContext memory context + ) internal view returns (bool) { bytes4 action = context.action(); if ( - action != context.seaport.matchOrders.selector - && action != context.seaport.matchAdvancedOrders.selector + action != context.seaport.matchOrders.selector && + action != context.seaport.matchAdvancedOrders.selector ) { return true; } @@ -171,18 +167,16 @@ library MutationFilters { return false; } - function ineligibleWhenNotAdvanced(FuzzTestContext memory context) - internal - view - returns (bool) - { + function ineligibleWhenNotAdvanced( + FuzzTestContext memory context + ) internal view returns (bool) { bytes4 action = context.action(); if ( - action == context.seaport.fulfillAvailableOrders.selector - || action == context.seaport.fulfillOrder.selector - || action == context.seaport.matchOrders.selector - || ineligibleWhenBasic(context) + action == context.seaport.fulfillAvailableOrders.selector || + action == context.seaport.fulfillOrder.selector || + action == context.seaport.matchOrders.selector || + ineligibleWhenBasic(context) ) { return true; } @@ -205,11 +199,9 @@ library MutationFilters { return false; } - function ineligibleWhenContractOrder(AdvancedOrder memory order) - internal - pure - returns (bool) - { + function ineligibleWhenContractOrder( + AdvancedOrder memory order + ) internal pure returns (bool) { return order.parameters.orderType == OrderType.CONTRACT; } @@ -225,23 +217,17 @@ library MutationFilters { return ineligibleWhenUnavailable(context, orderIndex); } - function ineligibleWhenNotContractOrder(AdvancedOrder memory order) - internal - pure - returns (bool) - { + function ineligibleWhenNotContractOrder( + AdvancedOrder memory order + ) internal pure returns (bool) { return order.parameters.orderType != OrderType.CONTRACT; } - function ineligibleWhenNotRestrictedOrder(AdvancedOrder memory order) - internal - pure - returns (bool) - { - return ( - order.parameters.orderType != OrderType.FULL_RESTRICTED - && order.parameters.orderType != OrderType.PARTIAL_RESTRICTED - ); + function ineligibleWhenNotRestrictedOrder( + AdvancedOrder memory order + ) internal pure returns (bool) { + return (order.parameters.orderType != OrderType.FULL_RESTRICTED && + order.parameters.orderType != OrderType.PARTIAL_RESTRICTED); } function ineligibleWhenNotAvailableOrNotContractOrder( @@ -258,7 +244,7 @@ library MutationFilters { function ineligibleWhenNotContractOrderOrFulfillAvailable( AdvancedOrder memory order, - uint256, /* orderIndex */ + uint256 /* orderIndex */, FuzzTestContext memory context ) internal view returns (bool) { if (ineligibleWhenNotContractOrder(order)) { @@ -295,22 +281,16 @@ library MutationFilters { return ineligibleWhenUnavailable(context, orderIndex); } - function ineligibleWhenNotActiveTime(AdvancedOrder memory order) - internal - view - returns (bool) - { - return ( - order.parameters.startTime > block.timestamp - || order.parameters.endTime <= block.timestamp - ); + function ineligibleWhenNotActiveTime( + AdvancedOrder memory order + ) internal view returns (bool) { + return (order.parameters.startTime > block.timestamp || + order.parameters.endTime <= block.timestamp); } - function ineligibleWhenNoConsiderationLength(AdvancedOrder memory order) - internal - pure - returns (bool) - { + function ineligibleWhenNoConsiderationLength( + AdvancedOrder memory order + ) internal pure returns (bool) { return order.parameters.consideration.length == 0; } @@ -324,11 +304,14 @@ library MutationFilters { return true; } - for (uint256 i = 0; i < context.executionState.orderDetails.length; ++i) - { + for ( + uint256 i = 0; + i < context.executionState.orderDetails.length; + ++i + ) { if ( - context.executionState.orderDetails[i].unavailableReason - == UnavailableReason.AVAILABLE + context.executionState.orderDetails[i].unavailableReason == + UnavailableReason.AVAILABLE ) { remainingFulfillable -= 1; } @@ -348,8 +331,8 @@ library MutationFilters { ) internal view returns (bool) { // TODO: get more precise about when this is allowed or not if ( - context.advancedOrdersSpace.orders[orderIndex].rebate - != ContractOrderRebate.NONE + context.advancedOrdersSpace.orders[orderIndex].rebate != + ContractOrderRebate.NONE ) { return true; } @@ -369,13 +352,11 @@ library MutationFilters { OffererZoneFailureReason failureReason = HashCalldataContractOfferer( payable(order.parameters.offerer) ).failureReasons( - context.executionState.orderDetails[orderIndex].orderHash - ); + context.executionState.orderDetails[orderIndex].orderHash + ); - return ( - failureReason - == OffererZoneFailureReason.ContractOfferer_generateReverts - ); + return (failureReason == + OffererZoneFailureReason.ContractOfferer_generateReverts); } function ineligibleWhenNotActiveTimeOrNotContractOrderOrNoOffer( @@ -387,9 +368,12 @@ library MutationFilters { return true; } - return ineligibleWhenNotActiveTimeOrNotContractOrder( - order, orderIndex, context - ); + return + ineligibleWhenNotActiveTimeOrNotContractOrder( + order, + orderIndex, + context + ); } function ineligibleWhenNotActiveTimeOrNotContractOrderOrNoConsideration( @@ -401,9 +385,12 @@ library MutationFilters { return true; } - return ineligibleWhenNotActiveTimeOrNotContractOrder( - order, orderIndex, context - ); + return + ineligibleWhenNotActiveTimeOrNotContractOrder( + order, + orderIndex, + context + ); } function ineligibleWhenOrderHasRebates( @@ -413,11 +400,14 @@ library MutationFilters { ) internal pure returns (bool) { if (order.parameters.orderType == OrderType.CONTRACT) { if ( - context.executionState.orderDetails[orderIndex].offer.length - != order.parameters.offer.length - || context.executionState.orderDetails[orderIndex] - .consideration - .length != order.parameters.consideration.length + context.executionState.orderDetails[orderIndex].offer.length != + order.parameters.offer.length || + context + .executionState + .orderDetails[orderIndex] + .consideration + .length != + order.parameters.consideration.length ) { return true; } @@ -433,7 +423,9 @@ library MutationFilters { ) internal view returns (bool) { if ( ineligibleWhenNotAvailableOrContractOrder( - order, orderIndex, context + order, + orderIndex, + context ) ) { return true; @@ -443,7 +435,7 @@ library MutationFilters { return true; } - (bool isValidated,,,) = context.seaport.getOrderStatus( + (bool isValidated, , , ) = context.seaport.getOrderStatus( context.executionState.orderDetails[orderIndex].orderHash ); @@ -461,7 +453,9 @@ library MutationFilters { ) internal view returns (bool) { if ( ineligibleWhenAnySignatureFailureRequired( - order, orderIndex, context + order, + orderIndex, + context ) ) { return true; @@ -480,9 +474,9 @@ library MutationFilters { bytes4 action = context.action(); if ( - action == context.seaport.fulfillAdvancedOrder.selector - || action == context.seaport.fulfillOrder.selector - || ineligibleWhenBasic(context) + action == context.seaport.fulfillAdvancedOrder.selector || + action == context.seaport.fulfillOrder.selector || + ineligibleWhenBasic(context) ) { return true; } @@ -516,7 +510,9 @@ library MutationFilters { OfferItem memory item = order.parameters.offer[i]; if ( !context.isFilteredOrNative( - item, order.parameters.offerer, order.parameters.conduitKey + item, + order.parameters.offerer, + order.parameters.conduitKey ) ) { locatedEligibleOfferItem = true; @@ -580,19 +576,17 @@ library MutationFilters { return false; } - function ineligibleForInvalidMsgValue(FuzzTestContext memory context) - internal - view - returns (bool) - { + function ineligibleForInvalidMsgValue( + FuzzTestContext memory context + ) internal view returns (bool) { // The target failure can't be triggered when calling a non-basic // function because only the BasicOrderFiller checks the msg.value and // enforces payable and non-payable routes. Exception: reentrancy. bytes4 action = context.action(); if ( - action != context.seaport.fulfillBasicOrder.selector - && action - != context.seaport.fulfillBasicOrder_efficient_6GL6yc.selector + action != context.seaport.fulfillBasicOrder.selector && + action != + context.seaport.fulfillBasicOrder_efficient_6GL6yc.selector ) { return true; } @@ -660,8 +654,8 @@ library MutationFilters { AdvancedOrder memory order = context.executionState.orders[i]; - uint256 items = order.parameters.offer.length - + order.parameters.consideration.length; + uint256 items = order.parameters.offer.length + + order.parameters.consideration.length; if (items != 0) { locatedItem = true; @@ -678,7 +672,7 @@ library MutationFilters { function ineligibleForInvalidProof_Merkle( CriteriaResolver memory criteriaResolver, - uint256, /* criteriaResolverIndex */ + uint256 /* criteriaResolverIndex */, FuzzTestContext memory context ) internal view returns (bool) { // The target failure can't be reached unless the function call is an @@ -687,7 +681,8 @@ library MutationFilters { // resolver must point to an available order. if ( ineligibleWhenUnavailableOrNotAdvanced( - context, criteriaResolver.orderIndex + context, + criteriaResolver.orderIndex ) ) { return true; @@ -705,7 +700,7 @@ library MutationFilters { function ineligibleForInvalidProof_Wildcard( CriteriaResolver memory criteriaResolver, - uint256, /* criteriaResolverIndex */ + uint256 /* criteriaResolverIndex */, FuzzTestContext memory context ) internal view returns (bool) { // The target failure can't be reached unless the function call is an @@ -714,7 +709,8 @@ library MutationFilters { // resolver must point to an available order. if ( ineligibleWhenUnavailableOrNotAdvanced( - context, criteriaResolver.orderIndex + context, + criteriaResolver.orderIndex ) ) { return true; @@ -732,7 +728,7 @@ library MutationFilters { function ineligibleForOfferCriteriaResolverFailure( CriteriaResolver memory criteriaResolver, - uint256, /* criteriaResolverIndex */ + uint256 /* criteriaResolverIndex */, FuzzTestContext memory context ) internal view returns (bool) { // The target failure can't be reached unless the function call is an @@ -741,7 +737,8 @@ library MutationFilters { // resolver must point to an available order. if ( ineligibleWhenUnavailableOrNotAdvanced( - context, criteriaResolver.orderIndex + context, + criteriaResolver.orderIndex ) ) { return true; @@ -757,8 +754,19 @@ library MutationFilters { // The target failure can't be triggered if the criteria resolver is // referring to a collection-level criteria item on a contract order. if ( - context.executionState.orders[criteriaResolver.orderIndex].parameters.orderType == OrderType.CONTRACT && - context.executionState.orders[criteriaResolver.orderIndex].parameters.offer[criteriaResolver.index].identifierOrCriteria == 0 + context + .executionState + .orders[criteriaResolver.orderIndex] + .parameters + .orderType == + OrderType.CONTRACT && + context + .executionState + .orders[criteriaResolver.orderIndex] + .parameters + .offer[criteriaResolver.index] + .identifierOrCriteria == + 0 ) { return true; } @@ -768,7 +776,7 @@ library MutationFilters { function ineligibleForConsiderationCriteriaResolverFailure( CriteriaResolver memory criteriaResolver, - uint256, /* criteriaResolverIndex */ + uint256 /* criteriaResolverIndex */, FuzzTestContext memory context ) internal view returns (bool) { // The target failure can't be reached unless the function call is an @@ -777,7 +785,8 @@ library MutationFilters { // resolver must point to an available order. if ( ineligibleWhenUnavailableOrNotAdvanced( - context, criteriaResolver.orderIndex + context, + criteriaResolver.orderIndex ) ) { return true; @@ -792,8 +801,19 @@ library MutationFilters { // The target failure can't be triggered if the criteria resolver is // referring to a collection-level criteria item on a contract order. if ( - context.executionState.orders[criteriaResolver.orderIndex].parameters.orderType == OrderType.CONTRACT && - context.executionState.orders[criteriaResolver.orderIndex].parameters.consideration[criteriaResolver.index].identifierOrCriteria == 0 + context + .executionState + .orders[criteriaResolver.orderIndex] + .parameters + .orderType == + OrderType.CONTRACT && + context + .executionState + .orders[criteriaResolver.orderIndex] + .parameters + .consideration[criteriaResolver.index] + .identifierOrCriteria == + 0 ) { return true; } @@ -868,7 +888,9 @@ library MutationFilters { // offerer is the caller. if ( ineligibleWhenAnySignatureFailureRequired( - order, orderIndex, context + order, + orderIndex, + context ) ) { return true; @@ -967,8 +989,8 @@ library MutationFilters { } function ineligibleForInvalidTime( - AdvancedOrder memory, /* order */ - uint256, /* orderIndex */ + AdvancedOrder memory /* order */, + uint256 /* orderIndex */, FuzzTestContext memory context ) internal view returns (bool) { // The target failure can't be triggered if the function call allows @@ -1002,8 +1024,9 @@ library MutationFilters { // only checked when there's an execution. // Get the fulfillment details. - FulfillmentDetails memory details = - context.toFulfillmentDetails(context.executionState.value); + FulfillmentDetails memory details = context.toFulfillmentDetails( + context.executionState.value + ); // Note: We're speculatively applying the mutation here and slightly // breaking the rules. Make sure to undo this mutation. @@ -1013,14 +1036,16 @@ library MutationFilters { Execution[] memory explicitExecutions, , Execution[] memory implicitExecutionsPost, + ) = context.getExecutionsFromRegeneratedFulfillments(details); // Look for invalid executions in explicit executions bool locatedInvalidConduitExecution; for (uint256 i; i < explicitExecutions.length; ++i) { if ( - explicitExecutions[i].conduitKey == keccak256("invalid conduit") - && explicitExecutions[i].item.itemType != ItemType.NATIVE + explicitExecutions[i].conduitKey == + keccak256("invalid conduit") && + explicitExecutions[i].item.itemType != ItemType.NATIVE ) { locatedInvalidConduitExecution = true; break; @@ -1031,10 +1056,9 @@ library MutationFilters { if (!locatedInvalidConduitExecution) { for (uint256 i = 0; i < implicitExecutionsPost.length; ++i) { if ( - implicitExecutionsPost[i].conduitKey - == keccak256("invalid conduit") - && implicitExecutionsPost[i].item.itemType - != ItemType.NATIVE + implicitExecutionsPost[i].conduitKey == + keccak256("invalid conduit") && + implicitExecutionsPost[i].item.itemType != ItemType.NATIVE ) { locatedInvalidConduitExecution = true; break; @@ -1069,9 +1093,12 @@ library MutationFilters { // fraction error. We want to exclude cases where the time is wrong or // maximum fulfilled has already been met. (So this check is // over-excluding potentially eligible orders). - return ineligibleWhenNotAvailableOrContractOrder( - order, orderIndex, context - ); + return + ineligibleWhenNotAvailableOrContractOrder( + order, + orderIndex, + context + ); } function ineligibleForBadFraction_noFill( @@ -1091,8 +1118,8 @@ library MutationFilters { } function ineligibleForCannotCancelOrder( - AdvancedOrder memory, /* order */ - uint256, /* orderIndex */ + AdvancedOrder memory /* order */, + uint256 /* orderIndex */, FuzzTestContext memory context ) internal view returns (bool) { // The target failure can't be reached unless the function call is @@ -1109,7 +1136,7 @@ library MutationFilters { function ineligibleForOrderIsCancelled( AdvancedOrder memory order, - uint256, /* orderIndex */ + uint256 /* orderIndex */, FuzzTestContext memory context ) internal view returns (bool) { // The target failure can't be reached if the function call is one of @@ -1131,7 +1158,7 @@ library MutationFilters { function ineligibleForOrderAlreadyFilled( AdvancedOrder memory order, - uint256, /* orderIndex */ + uint256 /* orderIndex */, FuzzTestContext memory context ) internal view returns (bool) { // The target failure can't be reached if the function call is one of @@ -1144,8 +1171,8 @@ library MutationFilters { // of right now, it's not possible to consistently hit the target // failure on a partially filled order when calling a basic function. if ( - ineligibleWhenFulfillAvailable(context) - || ineligibleWhenBasic(context) + ineligibleWhenFulfillAvailable(context) || + ineligibleWhenBasic(context) ) { return true; } @@ -1254,8 +1281,9 @@ library MutationFilters { // special, but it's the only one that needs to be checked, because it's // the only one that will be modified in the mutation. This is just a // simplification/convenience. - FulfillmentComponent[] memory firstOfferComponents = - (context.executionState.fulfillments[0].offerComponents); + FulfillmentComponent[] memory firstOfferComponents = ( + context.executionState.fulfillments[0].offerComponents + ); // Iterate over the offer components and check if any of them have an // item index that is out of bounds for the order. The mutation modifies @@ -1266,7 +1294,9 @@ library MutationFilters { for (uint256 i = 0; i < firstOfferComponents.length; ++i) { FulfillmentComponent memory component = (firstOfferComponents[i]); if ( - context.executionState.orders[component.orderIndex] + context + .executionState + .orders[component.orderIndex] .parameters .offer .length <= component.itemIndex @@ -1298,30 +1328,38 @@ library MutationFilters { // nothing special about the first fulfillment or the first offer // components, but they're the only ones that need to be checked, // because they're the only ones that will be modified in the mutation. - FulfillmentComponent memory firstOfferComponent = - (context.executionState.fulfillments[0].offerComponents[0]); + FulfillmentComponent memory firstOfferComponent = ( + context.executionState.fulfillments[0].offerComponents[0] + ); // Get the item pointed to by the first offer component. - SpentItem memory item = context.executionState.orderDetails[firstOfferComponent - .orderIndex].offer[firstOfferComponent.itemIndex]; + SpentItem memory item = context + .executionState + .orderDetails[firstOfferComponent.orderIndex] + .offer[firstOfferComponent.itemIndex]; // Iterate over the remaining fulfillments and check that the offer item // can be paired with a consideration item that's incompatible with it // in such a way that the target failure can be triggered. - for (uint256 i = 1; i < context.executionState.fulfillments.length; ++i) - { + for ( + uint256 i = 1; + i < context.executionState.fulfillments.length; + ++i + ) { FulfillmentComponent memory considerationComponent = ( - context.executionState.fulfillments[i].considerationComponents[0] + context.executionState.fulfillments[i].considerationComponents[ + 0 + ] ); ReceivedItem memory compareItem = context .executionState - .orderDetails[considerationComponent.orderIndex].consideration[considerationComponent - .itemIndex]; + .orderDetails[considerationComponent.orderIndex] + .consideration[considerationComponent.itemIndex]; if ( - item.itemType != compareItem.itemType - || item.token != compareItem.token - || item.identifier != compareItem.identifier + item.itemType != compareItem.itemType || + item.token != compareItem.token || + item.identifier != compareItem.identifier ) { return false; } @@ -1337,25 +1375,30 @@ library MutationFilters { // fulfillAvailable functions. bytes4 action = context.action(); if ( - action != context.seaport.fulfillAvailableAdvancedOrders.selector - && action != context.seaport.fulfillAvailableOrders.selector + action != context.seaport.fulfillAvailableAdvancedOrders.selector && + action != context.seaport.fulfillAvailableOrders.selector ) { return true; } // Iterate over offer fulfillments. for ( - uint256 i; i < context.executionState.offerFulfillments.length; i++ + uint256 i; + i < context.executionState.offerFulfillments.length; + i++ ) { // Get the first fulfillment component from the current offer // fulfillment. - FulfillmentComponent memory fulfillmentComponent = - context.executionState.offerFulfillments[i][0]; + FulfillmentComponent memory fulfillmentComponent = context + .executionState + .offerFulfillments[i][0]; // If the item index is out of bounds, then the mutation can't be // applied. if ( - context.executionState.orders[fulfillmentComponent.orderIndex] + context + .executionState + .orders[fulfillmentComponent.orderIndex] .parameters .offer .length <= fulfillmentComponent.itemIndex @@ -1370,14 +1413,17 @@ library MutationFilters { // order being unavailable is ruled out because the order needs to // be processed for the target failure to be hit. if ( - context.executionState.orderDetails[fulfillmentComponent - .orderIndex].offer[fulfillmentComponent.itemIndex].itemType - != ItemType.ERC721 + context + .executionState + .orderDetails[fulfillmentComponent.orderIndex] + .offer[fulfillmentComponent.itemIndex] + .itemType != ItemType.ERC721 ) { if ( - context.executionState.orderDetails[fulfillmentComponent - .orderIndex].unavailableReason - == UnavailableReason.AVAILABLE + context + .executionState + .orderDetails[fulfillmentComponent.orderIndex] + .unavailableReason == UnavailableReason.AVAILABLE ) { return false; } @@ -1396,15 +1442,15 @@ library MutationFilters { function ineligibleForMissingItemAmount_OfferItem( AdvancedOrder memory order, - uint256, /* orderIndex */ + uint256 /* orderIndex */, FuzzTestContext memory context ) internal view returns (bool) { // The fulfillAvailable functions are ruled out because they're handled // separately. Match functions are ruled out because they need to be // handled separately, too (but are not yet). if ( - ineligibleWhenFulfillAvailable(context) - || ineligibleWhenMatch(context) + ineligibleWhenFulfillAvailable(context) || + ineligibleWhenMatch(context) ) { return true; } @@ -1415,13 +1461,10 @@ library MutationFilters { // result in an underflow when attempting to reduce that offer amount as // part of paying out additional recipient items. if ( - ineligibleWhenBasic(context) - && order.parameters.consideration.length > 1 - && ( - order.parameters.consideration[0].itemType == ItemType.ERC721 - || order.parameters.consideration[0].itemType - == ItemType.ERC1155 - ) + ineligibleWhenBasic(context) && + order.parameters.consideration.length > 1 && + (order.parameters.consideration[0].itemType == ItemType.ERC721 || + order.parameters.consideration[0].itemType == ItemType.ERC1155) ) { return true; } @@ -1437,8 +1480,8 @@ library MutationFilters { for (uint256 i; i < order.parameters.offer.length; i++) { OfferItem memory item = order.parameters.offer[i]; if ( - item.itemType != ItemType.ERC721 - && item.itemType != ItemType.ERC721_WITH_CRITERIA + item.itemType != ItemType.ERC721 && + item.itemType != ItemType.ERC721_WITH_CRITERIA ) { hasValidItem = true; break; @@ -1467,7 +1510,7 @@ library MutationFilters { } function ineligibleForMissingItemAmount_ConsiderationItem( - AdvancedOrder memory, /* order */ + AdvancedOrder memory /* order */, uint256 orderIndex, FuzzTestContext memory context ) internal pure returns (bool) { @@ -1479,7 +1522,9 @@ library MutationFilters { // Order must have at least one offer item if ( - context.executionState.previewedOrders[orderIndex] + context + .executionState + .previewedOrders[orderIndex] .parameters .offer .length < 1 @@ -1491,19 +1536,23 @@ library MutationFilters { bool hasValidItem; for ( uint256 i; - i - < context.executionState.previewedOrders[orderIndex] - .parameters - .consideration - .length; + i < + context + .executionState + .previewedOrders[orderIndex] + .parameters + .consideration + .length; i++ ) { ConsiderationItem memory item = context .executionState - .previewedOrders[orderIndex].parameters.consideration[i]; + .previewedOrders[orderIndex] + .parameters + .consideration[i]; if ( - item.itemType != ItemType.ERC721 - && item.itemType != ItemType.ERC721_WITH_CRITERIA + item.itemType != ItemType.ERC721 && + item.itemType != ItemType.ERC721_WITH_CRITERIA ) { hasValidItem = true; break; @@ -1516,11 +1565,9 @@ library MutationFilters { return false; } - function ineligibleForNoContract(FuzzTestContext memory context) - internal - view - returns (bool) - { + function ineligibleForNoContract( + FuzzTestContext memory context + ) internal view returns (bool) { // Can't be one of the fulfillAvailable actions, or else the orders will // just be skipped and the target failure will not be hit. It'll pass or // revert with NoSpecifiedOrdersAvailable or something instead. @@ -1537,8 +1584,8 @@ library MutationFilters { i++ ) { if ( - context.expectations.expectedExplicitExecutions[i].item.token - != address(0) + context.expectations.expectedExplicitExecutions[i].item.token != + address(0) ) { return false; } @@ -1552,14 +1599,24 @@ library MutationFilters { uint256 orderIndex, FuzzTestContext memory context ) internal view returns (bool) { - // The target failure cannot be triggered in the fulfillAvailable cases - // because it gets skipped instead. And the match cases cause a - // MismatchedFulfillmentOfferAndConsiderationComponents(uint256) - // instead. - if ( - ineligibleWhenFulfillAvailable(context) - || ineligibleWhenMatch(context) - ) { + // The target failure can't be triggered if the order isn't available. + if (ineligibleWhenUnavailable(context, orderIndex)) { + return true; + } + + // The target failure cannot be triggered in fulfillAvailable cases — + // they trip a InvalidFulfillmentComponentData error instead. TODO: + // perform the mutation on all items that are part of a single + // fulfillment element. + if (ineligibleWhenFulfillAvailable(context)) { + return true; + } + + // The target failure cannot be triggered in match cases — they trip a + // MismatchedFulfillmentOfferAndConsiderationComponents(uint256) error + // instead. TODO: perform the mutation on all items that are part of a + // single fulfillment element. + if (ineligibleWhenMatch(context)) { return true; } @@ -1595,14 +1652,24 @@ library MutationFilters { uint256 orderIndex, FuzzTestContext memory context ) internal view returns (bool) { - // The target failure cannot be triggered in the fulfillAvailable cases - // because it gets skipped instead. And the match cases cause a - // MismatchedFulfillmentOfferAndConsiderationComponents(uint256) - // instead. - if ( - ineligibleWhenFulfillAvailable(context) - || ineligibleWhenMatch(context) - ) { + // The target failure can't be triggered if the order isn't available. + if (ineligibleWhenUnavailable(context, orderIndex)) { + return true; + } + + // The target failure cannot be triggered in fulfillAvailable cases — + // they trip a InvalidFulfillmentComponentData error instead. TODO: + // perform the mutation on all items that are part of a single + // fulfillment element. + if (ineligibleWhenFulfillAvailable(context)) { + return true; + } + + // The target failure cannot be triggered in match cases — they trip a + // MismatchedFulfillmentOfferAndConsiderationComponents(uint256) error + // instead. TODO: perform the mutation on all items that are part of a + // single fulfillment element. + if (ineligibleWhenMatch(context)) { return true; } @@ -1621,8 +1688,8 @@ library MutationFilters { for (uint256 i; i < order.parameters.consideration.length; i++) { ConsiderationItem memory item = order.parameters.consideration[i]; if ( - item.itemType == ItemType.ERC20 - || item.itemType == ItemType.NATIVE + item.itemType == ItemType.ERC20 || + item.itemType == ItemType.NATIVE ) { return false; } @@ -1640,9 +1707,9 @@ library MutationFilters { // executions are checked. Also deals with partial fills bytes4 action = context.action(); if ( - action == context.seaport.fulfillAdvancedOrder.selector - || ineligibleWhenFulfillAvailable(context) - || ineligibleWhenMatch(context) + action == context.seaport.fulfillAdvancedOrder.selector || + ineligibleWhenFulfillAvailable(context) || + ineligibleWhenMatch(context) ) { return true; } @@ -1667,8 +1734,8 @@ library MutationFilters { for (uint256 i; i < order.parameters.offer.length; i++) { OfferItem memory item = order.parameters.offer[i]; if ( - item.itemType == ItemType.ERC721 - || item.itemType == ItemType.ERC721_WITH_CRITERIA + item.itemType == ItemType.ERC721 || + item.itemType == ItemType.ERC721_WITH_CRITERIA ) { return false; } @@ -1677,8 +1744,8 @@ library MutationFilters { for (uint256 i; i < order.parameters.consideration.length; i++) { ConsiderationItem memory item = order.parameters.consideration[i]; if ( - item.itemType == ItemType.ERC721 - || item.itemType == ItemType.ERC721_WITH_CRITERIA + item.itemType == ItemType.ERC721 || + item.itemType == ItemType.ERC721_WITH_CRITERIA ) { return false; } @@ -1697,10 +1764,10 @@ library MutationFilters { // only reached by those top level function calls. bytes4 action = context.action(); if ( - action != context.seaport.fulfillAvailableAdvancedOrders.selector - && action != context.seaport.fulfillAvailableOrders.selector - && action != context.seaport.matchAdvancedOrders.selector - && action != context.seaport.matchOrders.selector + action != context.seaport.fulfillAvailableAdvancedOrders.selector && + action != context.seaport.fulfillAvailableOrders.selector && + action != context.seaport.matchAdvancedOrders.selector && + action != context.seaport.matchOrders.selector ) { return true; } @@ -1748,9 +1815,9 @@ library MutationFilters { // the target failure on an order that supports partial fills. Contract // orders give a different revert. if ( - order.parameters.orderType == OrderType.PARTIAL_OPEN - || order.parameters.orderType == OrderType.PARTIAL_RESTRICTED - || ineligibleWhenContractOrder(order) + order.parameters.orderType == OrderType.PARTIAL_OPEN || + order.parameters.orderType == OrderType.PARTIAL_RESTRICTED || + ineligibleWhenContractOrder(order) ) { return true; } @@ -1772,9 +1839,9 @@ library MutationFilters { ) internal view returns (bool) { bytes4 action = context.action(); if ( - action != context.seaport.fulfillAvailableAdvancedOrders.selector - && action != context.seaport.matchAdvancedOrders.selector - && action != context.seaport.fulfillAdvancedOrder.selector + action != context.seaport.fulfillAvailableAdvancedOrders.selector && + action != context.seaport.matchAdvancedOrders.selector && + action != context.seaport.fulfillAdvancedOrder.selector ) { return true; } @@ -1784,10 +1851,8 @@ library MutationFilters { return true; } - return ( - order.parameters.orderType != OrderType.PARTIAL_OPEN - && order.parameters.orderType != OrderType.PARTIAL_RESTRICTED - ); + return (order.parameters.orderType != OrderType.PARTIAL_OPEN && + order.parameters.orderType != OrderType.PARTIAL_RESTRICTED); } function ineligibleForInexactFraction( @@ -1795,14 +1860,16 @@ library MutationFilters { uint256 orderIndex, FuzzTestContext memory context ) internal view returns (bool) { - if (ineligibleForPanic_PartialFillOverflow(order, orderIndex, context)) - { + if ( + ineligibleForPanic_PartialFillOverflow(order, orderIndex, context) + ) { return true; } if ( - order.parameters.offer.length - + order.parameters.consideration.length == 0 + order.parameters.offer.length + + order.parameters.consideration.length == + 0 ) { return true; } @@ -1822,20 +1889,20 @@ library MutationFilters { itemAmount = 664613997892457936451903530140172392; } - (,, uint256 totalFilled, uint256 totalSize) = ( + (, , uint256 totalFilled, uint256 totalSize) = ( context.seaport.getOrderStatus( context.executionState.orderDetails[orderIndex].orderHash ) ); - return ( - FractionUtil.getPartialFillResults( + return (FractionUtil + .getPartialFillResults( uint120(totalFilled), uint120(totalSize), 1, uint120(itemAmount + 1) - ).status == FractionStatus.INVALID - ); + ) + .status == FractionStatus.INVALID); } function ineligibleForNoSpecifiedOrdersAvailable( @@ -1846,8 +1913,8 @@ library MutationFilters { // fulfillAvaialable*-specific code paths. bytes4 action = context.action(); if ( - action != context.seaport.fulfillAvailableAdvancedOrders.selector - && action != context.seaport.fulfillAvailableOrders.selector + action != context.seaport.fulfillAvailableAdvancedOrders.selector && + action != context.seaport.fulfillAvailableOrders.selector ) { return true; } @@ -1887,8 +1954,9 @@ contract FuzzMutations is Test, FuzzExecutor { // stored in the HashCalldataContractOfferer. HashCalldataContractOfferer(payable(order.parameters.offerer)) .setFailureReason( - orderHash, OffererZoneFailureReason.ContractOfferer_generateReverts - ); + orderHash, + OffererZoneFailureReason.ContractOfferer_generateReverts + ); exec(context); } @@ -1904,10 +1972,10 @@ contract FuzzMutations is Test, FuzzExecutor { // stored in the HashCalldataContractOfferer. HashCalldataContractOfferer(payable(order.parameters.offerer)) .setFailureReason( - orderHash, - OffererZoneFailureReason - .ContractOfferer_generateReturnsInvalidEncoding - ); + orderHash, + OffererZoneFailureReason + .ContractOfferer_generateReturnsInvalidEncoding + ); exec(context); } @@ -1923,8 +1991,9 @@ contract FuzzMutations is Test, FuzzExecutor { // stored in the HashCalldataContractOfferer. HashCalldataContractOfferer(payable(order.parameters.offerer)) .setFailureReason( - orderHash, OffererZoneFailureReason.ContractOfferer_ratifyReverts - ); + orderHash, + OffererZoneFailureReason.ContractOfferer_ratifyReverts + ); exec(context); } @@ -1940,9 +2009,9 @@ contract FuzzMutations is Test, FuzzExecutor { // stored in the HashCalldataContractOfferer. HashCalldataContractOfferer(payable(order.parameters.offerer)) .setFailureReason( - orderHash, - OffererZoneFailureReason.ContractOfferer_InvalidMagicValue - ); + orderHash, + OffererZoneFailureReason.ContractOfferer_InvalidMagicValue + ); exec(context); } @@ -1960,8 +2029,9 @@ contract FuzzMutations is Test, FuzzExecutor { // zone reverts on authorize. HashValidationZoneOfferer(payable(order.parameters.zone)) .setAuthorizeFailureReason( - orderHash, OffererZoneFailureReason.Zone_authorizeRevertsMatchReverts - ); + orderHash, + OffererZoneFailureReason.Zone_authorizeRevertsMatchReverts + ); exec(context); } @@ -1976,7 +2046,10 @@ contract FuzzMutations is Test, FuzzExecutor { // This mutation triggers a revert by setting a failure reason that gets // stored in the HashValidationZoneOfferer. HashValidationZoneOfferer(payable(order.parameters.zone)) - .setValidateFailureReason(orderHash, OffererZoneFailureReason.Zone_validateReverts); + .setValidateFailureReason( + orderHash, + OffererZoneFailureReason.Zone_validateReverts + ); exec(context); } @@ -1992,8 +2065,9 @@ contract FuzzMutations is Test, FuzzExecutor { // stored in the HashValidationZone. HashValidationZoneOfferer(payable(order.parameters.zone)) .setAuthorizeFailureReason( - orderHash, OffererZoneFailureReason.Zone_authorizeInvalidMagicValue - ); + orderHash, + OffererZoneFailureReason.Zone_authorizeInvalidMagicValue + ); exec(context); } @@ -2009,8 +2083,9 @@ contract FuzzMutations is Test, FuzzExecutor { // stored in the HashValidationZone. HashValidationZoneOfferer(payable(order.parameters.zone)) .setValidateFailureReason( - orderHash, OffererZoneFailureReason.Zone_validateInvalidMagicValue - ); + orderHash, + OffererZoneFailureReason.Zone_validateInvalidMagicValue + ); exec(context); } @@ -2022,8 +2097,9 @@ contract FuzzMutations is Test, FuzzExecutor { AdvancedOrder memory order = mutationState.selectedOrder; bytes32 orderHash = mutationState.selectedOrderHash; - HashCalldataContractOfferer offerer = - HashCalldataContractOfferer(payable(order.parameters.offerer)); + HashCalldataContractOfferer offerer = HashCalldataContractOfferer( + payable(order.parameters.offerer) + ); // This mutation triggers a revert by setting a failure reason that gets // stored in the HashCalldataContractOfferer and by mutating the amount @@ -2035,7 +2111,10 @@ contract FuzzMutations is Test, FuzzExecutor { // TODO: operate on a fuzzed item (this is always the first item) offerer.addItemAmountMutation( - Side.OFFER, 0, order.parameters.offer[0].startAmount - 1, orderHash + Side.OFFER, + 0, + order.parameters.offer[0].startAmount - 1, + orderHash ); exec(context); @@ -2065,8 +2144,9 @@ contract FuzzMutations is Test, FuzzExecutor { AdvancedOrder memory order = mutationState.selectedOrder; bytes32 orderHash = mutationState.selectedOrderHash; - HashCalldataContractOfferer offerer = - HashCalldataContractOfferer(payable(order.parameters.offerer)); + HashCalldataContractOfferer offerer = HashCalldataContractOfferer( + payable(order.parameters.offerer) + ); // This mutation triggers a revert by setting a failure reason that gets // stored in the HashCalldataContractOfferer and by calling a function @@ -2079,7 +2159,9 @@ contract FuzzMutations is Test, FuzzExecutor { // TODO: operate on a fuzzed item (this always operates on last item) offerer.addDropItemMutation( - Side.OFFER, order.parameters.offer.length - 1, orderHash + Side.OFFER, + order.parameters.offer.length - 1, + orderHash ); exec(context); @@ -2096,7 +2178,8 @@ contract FuzzMutations is Test, FuzzExecutor { // amount of a contract order consideration item must be equal to the // end amount. order.parameters.consideration[0].startAmount = - order.parameters.consideration[0].endAmount + 1; + order.parameters.consideration[0].endAmount + + 1; exec(context); } @@ -2108,8 +2191,9 @@ contract FuzzMutations is Test, FuzzExecutor { AdvancedOrder memory order = mutationState.selectedOrder; bytes32 orderHash = mutationState.selectedOrderHash; - HashCalldataContractOfferer offerer = - HashCalldataContractOfferer(payable(order.parameters.offerer)); + HashCalldataContractOfferer offerer = HashCalldataContractOfferer( + payable(order.parameters.offerer) + ); // This mutation triggers a revert by setting a failure reason that gets // stored in the HashCalldataContractOfferer and by calling a function @@ -2143,8 +2227,9 @@ contract FuzzMutations is Test, FuzzExecutor { AdvancedOrder memory order = mutationState.selectedOrder; bytes32 orderHash = mutationState.selectedOrderHash; - HashCalldataContractOfferer offerer = - HashCalldataContractOfferer(payable(order.parameters.offerer)); + HashCalldataContractOfferer offerer = HashCalldataContractOfferer( + payable(order.parameters.offerer) + ); // This mutation triggers a revert by setting a failure reason that gets // stored in the HashCalldataContractOfferer and by calling a function @@ -2183,7 +2268,9 @@ contract FuzzMutations is Test, FuzzExecutor { item = order.parameters.offer[i]; if ( !context.isFilteredOrNative( - item, order.parameters.offerer, order.parameters.conduitKey + item, + order.parameters.offerer, + order.parameters.conduitKey ) ) { break; @@ -2282,8 +2369,9 @@ contract FuzzMutations is Test, FuzzExecutor { // add a criteria resolver for an item that is not a *WithCriteria type. // Grab the old resolvers. - CriteriaResolver[] memory oldResolvers = - context.executionState.criteriaResolvers; + CriteriaResolver[] memory oldResolvers = context + .executionState + .criteriaResolvers; // Make a new array with one more slot. CriteriaResolver[] memory newResolvers = new CriteriaResolver[]( oldResolvers.length + 1 @@ -2297,16 +2385,20 @@ contract FuzzMutations is Test, FuzzExecutor { Side side; // Iterate over orders. - for (; orderIndex < context.executionState.orders.length; ++orderIndex) - { + for ( + ; + orderIndex < context.executionState.orders.length; + ++orderIndex + ) { // Skip unavailable orders. if (context.ineligibleWhenUnavailable(orderIndex)) { continue; } // Grab the order at the current index. - AdvancedOrder memory order = - context.executionState.orders[orderIndex]; + AdvancedOrder memory order = context.executionState.orders[ + orderIndex + ]; // If it has an offer, set the side to offer and break, otherwise // if it has a consideration, set the side to consideration and @@ -2469,7 +2561,8 @@ contract FuzzMutations is Test, FuzzExecutor { // the length of the consideration array. order.parameters.totalOriginalConsiderationItems = - order.parameters.consideration.length - 1; + order.parameters.consideration.length - + 1; exec(context); } @@ -2488,7 +2581,8 @@ contract FuzzMutations is Test, FuzzExecutor { // the length of the consideration array. order.parameters.totalOriginalConsiderationItems = - order.parameters.consideration.length + 1; + order.parameters.consideration.length + + 1; exec(context); } @@ -2507,7 +2601,8 @@ contract FuzzMutations is Test, FuzzExecutor { // consideration array. order.parameters.totalOriginalConsiderationItems = - order.parameters.consideration.length + 1; + order.parameters.consideration.length + + 1; exec(context); } @@ -2562,13 +2657,16 @@ contract FuzzMutations is Test, FuzzExecutor { _signOrValidateMutatedOrder(context, orderIndex); - context.executionState.previewedOrders[orderIndex].parameters.conduitKey - = keccak256("invalid conduit"); + context + .executionState + .previewedOrders[orderIndex] + .parameters + .conduitKey = keccak256("invalid conduit"); context = context.withDerivedOrderDetails().withDerivedFulfillments(); if ( - context.advancedOrdersSpace.orders[orderIndex].signatureMethod - == SignatureMethod.VALIDATE + context.advancedOrdersSpace.orders[orderIndex].signatureMethod == + SignatureMethod.VALIDATE ) { order.inscribeOrderStatusValidated(true, context.seaport); } @@ -2620,7 +2718,9 @@ contract FuzzMutations is Test, FuzzExecutor { // cannot be filled. FuzzInscribers.inscribeOrderStatusCancelled( - orderHash, true, context.seaport + orderHash, + true, + context.seaport ); exec(context); @@ -2650,8 +2750,9 @@ contract FuzzMutations is Test, FuzzExecutor { // This mutation triggers a revert by setting the caller as an address // that is not the offerer. Only the offerer can cancel an order. - context.executionState.caller = - address(uint160(order.parameters.offerer) - 1); + context.executionState.caller = address( + uint160(order.parameters.offerer) - 1 + ); exec(context); } @@ -2684,40 +2785,63 @@ contract FuzzMutations is Test, FuzzExecutor { // If there's already one or more fulfillments, just set the order index // for the first fulfillment's consideration component to an invalid // value. - context.executionState.fulfillments[0].considerationComponents[0] + context + .executionState + .fulfillments[0] + .considerationComponents[0] .orderIndex = context.executionState.orders.length; } else { // Otherwise, create a new, empty fulfillment. context.executionState.fulfillments = new Fulfillment[](1); - context.executionState.fulfillments[0].offerComponents = - new FulfillmentComponent[](1); + context + .executionState + .fulfillments[0] + .offerComponents = new FulfillmentComponent[](1); - context.executionState.fulfillments[0].considerationComponents = - new FulfillmentComponent[](1); + context + .executionState + .fulfillments[0] + .considerationComponents = new FulfillmentComponent[](1); - context.executionState.fulfillments[0].considerationComponents[0] + context + .executionState + .fulfillments[0] + .considerationComponents[0] .orderIndex = context.executionState.orders.length; } // Do the same sort of thing for offer fulfillments and consideration // fulfillments. if (context.executionState.offerFulfillments.length != 0) { - context.executionState.offerFulfillments[0][0].orderIndex = - context.executionState.orders.length; - } else if (context.executionState.considerationFulfillments.length != 0) - { - context.executionState.considerationFulfillments[0][0].orderIndex = - context.executionState.orders.length; + context.executionState.offerFulfillments[0][0].orderIndex = context + .executionState + .orders + .length; + } else if ( + context.executionState.considerationFulfillments.length != 0 + ) { + context + .executionState + .considerationFulfillments[0][0].orderIndex = context + .executionState + .orders + .length; } else { - context.executionState.considerationFulfillments = - (new FulfillmentComponent[][](1)); + context.executionState.considerationFulfillments = ( + new FulfillmentComponent[][](1) + ); - context.executionState.considerationFulfillments[0] = - (new FulfillmentComponent[](1)); + context.executionState.considerationFulfillments[0] = ( + new FulfillmentComponent[](1) + ); - context.executionState.considerationFulfillments[0][0].orderIndex = - context.executionState.orders.length; + context + .executionState + .considerationFulfillments[0][0].orderIndex = context + .executionState + .orders + .length; } exec(context); @@ -2738,15 +2862,18 @@ contract FuzzMutations is Test, FuzzExecutor { // fulfillment to an empty FulfillmentComponent array. if (mutationState.side == Side.OFFER) { if (context.executionState.offerFulfillments.length == 0) { - context.executionState.offerFulfillments = - new FulfillmentComponent[][](1); + context + .executionState + .offerFulfillments = new FulfillmentComponent[][](1); } else { - context.executionState.offerFulfillments[0] = - new FulfillmentComponent[](0); + context.executionState.offerFulfillments[ + 0 + ] = new FulfillmentComponent[](0); } } else if (mutationState.side == Side.CONSIDERATION) { - context.executionState.considerationFulfillments[0] = - new FulfillmentComponent[](0); + context.executionState.considerationFulfillments[ + 0 + ] = new FulfillmentComponent[](0); } exec(context); @@ -2777,8 +2904,9 @@ contract FuzzMutations is Test, FuzzExecutor { // each target the same item. // Get the first fulfillment's offer components. - FulfillmentComponent[] memory firstOfferComponents = - (context.executionState.fulfillments[0].offerComponents); + FulfillmentComponent[] memory firstOfferComponents = ( + context.executionState.fulfillments[0].offerComponents + ); // Iterate over the offer components and modify the token address of // each corresponding offer item. This preserves the intended @@ -2786,12 +2914,19 @@ contract FuzzMutations is Test, FuzzExecutor { // consideration components to have mismatched token addresses. for (uint256 i = 0; i < firstOfferComponents.length; ++i) { FulfillmentComponent memory component = (firstOfferComponents[i]); - address token = context.executionState.orders[component.orderIndex] + address token = context + .executionState + .orders[component.orderIndex] .parameters - .offer[component.itemIndex].token; + .offer[component.itemIndex] + .token; address modifiedToken = address(uint160(token) ^ 1); - context.executionState.orders[component.orderIndex].parameters.offer[component - .itemIndex].token = modifiedToken; + context + .executionState + .orders[component.orderIndex] + .parameters + .offer[component.itemIndex] + .token = modifiedToken; } // "Resign" the orders. @@ -2814,16 +2949,20 @@ contract FuzzMutations is Test, FuzzExecutor { // Store a reference to the first fulfillment's offer components for // later use. - FulfillmentComponent[] memory firstOfferComponents = - (context.executionState.fulfillments[0].offerComponents); + FulfillmentComponent[] memory firstOfferComponents = ( + context.executionState.fulfillments[0].offerComponents + ); // Get the first fulfillment's first offer component. - FulfillmentComponent memory firstOfferComponent = - (firstOfferComponents[0]); + FulfillmentComponent memory firstOfferComponent = ( + firstOfferComponents[0] + ); // Use the indexes in the first offer component to get the item. - SpentItem memory item = context.executionState.orderDetails[firstOfferComponent - .orderIndex].offer[firstOfferComponent.itemIndex]; + SpentItem memory item = context + .executionState + .orderDetails[firstOfferComponent.orderIndex] + .offer[firstOfferComponent.itemIndex]; // Start iterating at the second fulfillment, since the first is the one // that gets mutated. @@ -2831,29 +2970,32 @@ contract FuzzMutations is Test, FuzzExecutor { for (; i < context.executionState.fulfillments.length; ++i) { // Get the first consideration component of the current fulfillment. FulfillmentComponent memory considerationComponent = ( - context.executionState.fulfillments[i].considerationComponents[0] + context.executionState.fulfillments[i].considerationComponents[ + 0 + ] ); // Use the indexes in the first consideration component to get the // item that needs to be compared against. ReceivedItem memory compareItem = context .executionState - .orderDetails[considerationComponent.orderIndex].consideration[considerationComponent - .itemIndex]; + .orderDetails[considerationComponent.orderIndex] + .consideration[considerationComponent.itemIndex]; // If it's not a match, then it works for the mutation, so break. if ( - item.itemType != compareItem.itemType - || item.token != compareItem.token - || item.identifier != compareItem.identifier + item.itemType != compareItem.itemType || + item.token != compareItem.token || + item.identifier != compareItem.identifier ) { break; } } // Swap offer components of the first and current fulfillments. - FulfillmentComponent[] memory swappedOfferComponents = - (context.executionState.fulfillments[i].offerComponents); + FulfillmentComponent[] memory swappedOfferComponents = ( + context.executionState.fulfillments[i].offerComponents + ); // Set up a pointer that will be used temporarily in the shuffle. bytes32 swappedPointer; @@ -2870,13 +3012,17 @@ contract FuzzMutations is Test, FuzzExecutor { // Set the offer components of the first fulfillment to the mutated // firstOfferComponents. - context.executionState.fulfillments[0].offerComponents = - firstOfferComponents; + context + .executionState + .fulfillments[0] + .offerComponents = firstOfferComponents; // Set the offer components of the current fulfillment to the offer // components that were originally in the first fulfillment. - context.executionState.fulfillments[i].offerComponents = - swappedOfferComponents; + context + .executionState + .fulfillments[i] + .offerComponents = swappedOfferComponents; exec(context); } @@ -2885,10 +3031,11 @@ contract FuzzMutations is Test, FuzzExecutor { FuzzTestContext memory context, MutationState memory mutationState ) external { - uint256 criteriaResolverIndex = - mutationState.selectedCriteriaResolverIndex; - CriteriaResolver memory resolver = - context.executionState.criteriaResolvers[criteriaResolverIndex]; + uint256 criteriaResolverIndex = mutationState + .selectedCriteriaResolverIndex; + CriteriaResolver memory resolver = context + .executionState + .criteriaResolvers[criteriaResolverIndex]; // This mutation works by jamming in a proof for the selected criteria // resolver, but only operates on criteria resolvers that aren't @@ -2905,10 +3052,11 @@ contract FuzzMutations is Test, FuzzExecutor { FuzzTestContext memory context, MutationState memory mutationState ) external { - uint256 criteriaResolverIndex = - mutationState.selectedCriteriaResolverIndex; - CriteriaResolver memory resolver = - context.executionState.criteriaResolvers[criteriaResolverIndex]; + uint256 criteriaResolverIndex = mutationState + .selectedCriteriaResolverIndex; + CriteriaResolver memory resolver = context + .executionState + .criteriaResolvers[criteriaResolverIndex]; // This mutation triggers a revert by modifying the first proof element // in a criteria resolver's proof array. Seaport will reject a criteria @@ -2929,8 +3077,9 @@ contract FuzzMutations is Test, FuzzExecutor { // order index that's out of range. The order index on a criteria // resolver must be within the range of the orders array. - CriteriaResolver[] memory oldResolvers = - context.executionState.criteriaResolvers; + CriteriaResolver[] memory oldResolvers = context + .executionState + .criteriaResolvers; CriteriaResolver[] memory newResolvers = new CriteriaResolver[]( oldResolvers.length + 1 ); @@ -2960,13 +3109,15 @@ contract FuzzMutations is Test, FuzzExecutor { // resolver must be within the range of the order's offer array if the // criteria resolver's side is OFFER, as is the case for this mutation. - uint256 criteriaResolverIndex = - mutationState.selectedCriteriaResolverIndex; - CriteriaResolver memory resolver = - context.executionState.criteriaResolvers[criteriaResolverIndex]; + uint256 criteriaResolverIndex = mutationState + .selectedCriteriaResolverIndex; + CriteriaResolver memory resolver = context + .executionState + .criteriaResolvers[criteriaResolverIndex]; - OrderDetails memory order = - context.executionState.orderDetails[resolver.orderIndex]; + OrderDetails memory order = context.executionState.orderDetails[ + resolver.orderIndex + ]; resolver.index = order.offer.length; exec(context); @@ -2982,13 +3133,15 @@ contract FuzzMutations is Test, FuzzExecutor { // array if the criteria resolver's side is CONSIDERATION, as is the // case for this mutation. - uint256 criteriaResolverIndex = - mutationState.selectedCriteriaResolverIndex; - CriteriaResolver memory resolver = - context.executionState.criteriaResolvers[criteriaResolverIndex]; + uint256 criteriaResolverIndex = mutationState + .selectedCriteriaResolverIndex; + CriteriaResolver memory resolver = context + .executionState + .criteriaResolvers[criteriaResolverIndex]; - AdvancedOrder memory order = - context.executionState.orders[resolver.orderIndex]; + AdvancedOrder memory order = context.executionState.orders[ + resolver.orderIndex + ]; resolver.index = order.parameters.consideration.length; exec(context); @@ -3004,11 +3157,12 @@ contract FuzzMutations is Test, FuzzExecutor { // by the end of the _applyCriteriaResolvers* functions, which is not // permitted. - uint256 criteriaResolverIndex = - mutationState.selectedCriteriaResolverIndex; + uint256 criteriaResolverIndex = mutationState + .selectedCriteriaResolverIndex; - CriteriaResolver[] memory oldResolvers = - context.executionState.criteriaResolvers; + CriteriaResolver[] memory oldResolvers = context + .executionState + .criteriaResolvers; CriteriaResolver[] memory newResolvers = new CriteriaResolver[]( oldResolvers.length - 1 ); @@ -3022,7 +3176,9 @@ contract FuzzMutations is Test, FuzzExecutor { // Iterate from the selected criteria resolver index + 1 to the end and // copy resolvers. for ( - uint256 i = criteriaResolverIndex + 1; i < oldResolvers.length; ++i + uint256 i = criteriaResolverIndex + 1; + i < oldResolvers.length; + ++i ) { newResolvers[i - 1] = oldResolvers[i]; } @@ -3044,31 +3200,42 @@ contract FuzzMutations is Test, FuzzExecutor { // fulfillment that points to the item serves as a proxy that the item's // transfer won't be filtered. for ( - uint256 i; i < context.executionState.offerFulfillments.length; i++ + uint256 i; + i < context.executionState.offerFulfillments.length; + i++ ) { - FulfillmentComponent memory fulfillmentComponent = - context.executionState.offerFulfillments[i][0]; + FulfillmentComponent memory fulfillmentComponent = context + .executionState + .offerFulfillments[i][0]; - AdvancedOrder memory order = - context.executionState.orders[fulfillmentComponent.orderIndex]; + AdvancedOrder memory order = context.executionState.orders[ + fulfillmentComponent.orderIndex + ]; // The item cannot be a 721, because setting the amount of a 721 to // 0 triggers a different revert. if ( - context.executionState.orderDetails[fulfillmentComponent - .orderIndex].offer[fulfillmentComponent.itemIndex].itemType - != ItemType.ERC721 + context + .executionState + .orderDetails[fulfillmentComponent.orderIndex] + .offer[fulfillmentComponent.itemIndex] + .itemType != ItemType.ERC721 ) { // The order must be available. if ( - context.executionState.orderDetails[fulfillmentComponent - .orderIndex].unavailableReason - == UnavailableReason.AVAILABLE + context + .executionState + .orderDetails[fulfillmentComponent.orderIndex] + .unavailableReason == UnavailableReason.AVAILABLE ) { // For all orders, set the start and end amounts to 0. - order.parameters.offer[fulfillmentComponent.itemIndex] + order + .parameters + .offer[fulfillmentComponent.itemIndex] .startAmount = 0; - order.parameters.offer[fulfillmentComponent.itemIndex] + order + .parameters + .offer[fulfillmentComponent.itemIndex] .endAmount = 0; // For contract orders, tell the test contract about the @@ -3077,16 +3244,21 @@ contract FuzzMutations is Test, FuzzExecutor { HashCalldataContractOfferer( payable(order.parameters.offerer) ).addItemAmountMutation( - Side.OFFER, - fulfillmentComponent.itemIndex, - 0, - context.executionState.orderDetails[fulfillmentComponent - .orderIndex].orderHash - ); + Side.OFFER, + fulfillmentComponent.itemIndex, + 0, + context + .executionState + .orderDetails[ + fulfillmentComponent.orderIndex + ] + .orderHash + ); } _signOrValidateMutatedOrder( - context, fulfillmentComponent.orderIndex + context, + fulfillmentComponent.orderIndex ); break; @@ -3111,8 +3283,8 @@ contract FuzzMutations is Test, FuzzExecutor { for (uint256 i; i < order.parameters.offer.length; i++) { OfferItem memory item = order.parameters.offer[i]; if ( - item.itemType != ItemType.ERC721 - && item.itemType != ItemType.ERC721_WITH_CRITERIA + item.itemType != ItemType.ERC721 && + item.itemType != ItemType.ERC721_WITH_CRITERIA ) { firstNon721OfferItem = i; break; @@ -3143,27 +3315,31 @@ contract FuzzMutations is Test, FuzzExecutor { for (uint256 i; i < order.parameters.consideration.length; i++) { ConsiderationItem memory item = order.parameters.consideration[i]; if ( - item.itemType != ItemType.ERC721 - && item.itemType != ItemType.ERC721_WITH_CRITERIA + item.itemType != ItemType.ERC721 && + item.itemType != ItemType.ERC721_WITH_CRITERIA ) { firstNon721ConsiderationItem = i; break; } } - order.parameters.consideration[firstNon721ConsiderationItem].startAmount - = 0; - order.parameters.consideration[firstNon721ConsiderationItem].endAmount = - 0; + order + .parameters + .consideration[firstNon721ConsiderationItem] + .startAmount = 0; + order + .parameters + .consideration[firstNon721ConsiderationItem] + .endAmount = 0; if (order.parameters.orderType == OrderType.CONTRACT) { HashCalldataContractOfferer(payable(order.parameters.offerer)) .addItemAmountMutation( - Side.CONSIDERATION, - firstNon721ConsiderationItem, - 0, - mutationState.selectedOrderHash - ); + Side.CONSIDERATION, + firstNon721ConsiderationItem, + 0, + mutationState.selectedOrderHash + ); } _signOrValidateMutatedOrder(context, orderIndex); @@ -3189,8 +3365,11 @@ contract FuzzMutations is Test, FuzzExecutor { i < context.expectations.expectedExplicitExecutions.length; i++ ) { - address candidate = - context.expectations.expectedExplicitExecutions[i].item.token; + address candidate = context + .expectations + .expectedExplicitExecutions[i] + .item + .token; if (candidate != address(0)) { targetContract = candidate; @@ -3204,8 +3383,9 @@ contract FuzzMutations is Test, FuzzExecutor { AdvancedOrder memory order = context.executionState.orders[i]; for (uint256 j; j < order.parameters.consideration.length; j++) { - ConsiderationItem memory item = - order.parameters.consideration[j]; + ConsiderationItem memory item = order.parameters.consideration[ + j + ]; if (item.token == targetContract) { item.token = mutationState.selectedArbitraryAddress; } @@ -3248,8 +3428,9 @@ contract FuzzMutations is Test, FuzzExecutor { if (!nativeItemFound) { for (uint256 i; i < order.parameters.consideration.length; i++) { - ConsiderationItem memory item = - order.parameters.consideration[i]; + ConsiderationItem memory item = order.parameters.consideration[ + i + ]; if (item.itemType == ItemType.NATIVE) { item.token = address(1); @@ -3259,6 +3440,25 @@ contract FuzzMutations is Test, FuzzExecutor { } } + // For basic orders, the additional recipient items also need to be + // modified. + bytes4 action = context.action(); + if ( + action == context.seaport.fulfillBasicOrder.selector || + action == + context.seaport.fulfillBasicOrder_efficient_6GL6yc.selector + ) { + for (uint256 i = 1; i < order.parameters.consideration.length; i++) { + ConsiderationItem memory item = order.parameters.consideration[ + i + ]; + + if (item.itemType == ItemType.NATIVE) { + item.token = address(1); + } + } + } + _signOrValidateMutatedOrder(context, orderIndex); exec(context); @@ -3280,8 +3480,8 @@ contract FuzzMutations is Test, FuzzExecutor { for (uint256 i; i < order.parameters.offer.length; i++) { OfferItem memory item = order.parameters.offer[i]; if ( - item.itemType == ItemType.ERC20 - || item.itemType == ItemType.NATIVE + item.itemType == ItemType.ERC20 || + item.itemType == ItemType.NATIVE ) { item.identifierOrCriteria = 1; validItemFound = true; @@ -3291,11 +3491,12 @@ contract FuzzMutations is Test, FuzzExecutor { if (!validItemFound) { for (uint256 i; i < order.parameters.consideration.length; i++) { - ConsiderationItem memory item = - order.parameters.consideration[i]; + ConsiderationItem memory item = order.parameters.consideration[ + i + ]; if ( - item.itemType == ItemType.ERC20 - || item.itemType == ItemType.NATIVE + item.itemType == ItemType.ERC20 || + item.itemType == ItemType.NATIVE ) { item.identifierOrCriteria = 1; validItemFound = true; @@ -3304,6 +3505,9 @@ contract FuzzMutations is Test, FuzzExecutor { } } + // Note that additional recipients do not need to be modified as + // identifiers for them are automatically set to 0. + _signOrValidateMutatedOrder(context, orderIndex); exec(context); @@ -3325,8 +3529,8 @@ contract FuzzMutations is Test, FuzzExecutor { for (uint256 i; i < order.parameters.offer.length; i++) { OfferItem memory item = order.parameters.offer[i]; if ( - item.itemType == ItemType.ERC721 - || item.itemType == ItemType.ERC721_WITH_CRITERIA + item.itemType == ItemType.ERC721 || + item.itemType == ItemType.ERC721_WITH_CRITERIA ) { item.startAmount = 2; item.endAmount = 2; @@ -3337,11 +3541,12 @@ contract FuzzMutations is Test, FuzzExecutor { if (!validItemFound) { for (uint256 i; i < order.parameters.consideration.length; i++) { - ConsiderationItem memory item = - order.parameters.consideration[i]; + ConsiderationItem memory item = order.parameters.consideration[ + i + ]; if ( - item.itemType == ItemType.ERC721 - || item.itemType == ItemType.ERC721_WITH_CRITERIA + item.itemType == ItemType.ERC721 || + item.itemType == ItemType.ERC721_WITH_CRITERIA ) { item.startAmount = 2; item.endAmount = 2; @@ -3376,10 +3581,12 @@ contract FuzzMutations is Test, FuzzExecutor { for (uint256 i; i < order.parameters.consideration.length; i++) { newConsideration[i] = order.parameters.consideration[i]; } - newConsideration[order.parameters.consideration.length] = - ConsiderationItemLib.empty().withItemType(ItemType.NATIVE).withAmount( - 100 - ); + newConsideration[ + order.parameters.consideration.length + ] = ConsiderationItemLib + .empty() + .withItemType(ItemType.NATIVE) + .withAmount(100); order.parameters.consideration = newConsideration; exec(context); @@ -3443,7 +3650,9 @@ contract FuzzMutations is Test, FuzzExecutor { order.denominator = 664613997892457936451903530140172393; order.inscribeOrderStatusNumeratorAndDenominator( - 1, 664613997892457936451903530140172297, context.seaport + 1, + 664613997892457936451903530140172297, + context.seaport ); exec(context); @@ -3501,8 +3710,8 @@ contract FuzzMutations is Test, FuzzExecutor { // validated too so that we're conforming the failure paths as closely // as possible to the success paths. if ( - context.advancedOrdersSpace.orders[orderIndex].signatureMethod - == SignatureMethod.VALIDATE + context.advancedOrdersSpace.orders[orderIndex].signatureMethod == + SignatureMethod.VALIDATE ) { order.inscribeOrderStatusValidated(true, context.seaport); } else if (context.executionState.caller != order.parameters.offerer) { diff --git a/test/foundry/new/helpers/FuzzSetup.sol b/test/foundry/new/helpers/FuzzSetup.sol index 8d71ff6..886f802 100644 --- a/test/foundry/new/helpers/FuzzSetup.sol +++ b/test/foundry/new/helpers/FuzzSetup.sol @@ -3,7 +3,10 @@ pragma solidity ^0.8.17; import { Test } from "forge-std/Test.sol"; -import { ExecutionLib, ZoneParametersLib } from "seaport-sol/src/SeaportSol.sol"; +import { + ExecutionLib, + ZoneParametersLib +} from "seaport-sol/src/SeaportSol.sol"; import { AdvancedOrder, @@ -24,8 +27,9 @@ import { FuzzTestContext } from "./FuzzTestContextLib.sol"; import { CriteriaResolverHelper } from "./CriteriaResolverHelper.sol"; -import { AmountDeriverHelper } from - "seaport-sol/src/lib/fulfillment/AmountDeriverHelper.sol"; +import { + AmountDeriverHelper +} from "seaport-sol/src/lib/fulfillment/AmountDeriverHelper.sol"; import { ExpectedEventsUtil } from "./event-utils/ExpectedEventsUtil.sol"; @@ -73,11 +77,10 @@ library CheckHelpers { * * @return The updated test context. */ - function registerCheck(FuzzTestContext memory context, bytes4 check) - internal - pure - returns (FuzzTestContext memory) - { + function registerCheck( + FuzzTestContext memory context, + bytes4 check + ) internal pure returns (FuzzTestContext memory) { bytes4[] memory checks = context.checks; bytes4[] memory newChecks = new bytes4[](checks.length + 1); for (uint256 i; i < checks.length; ++i) { @@ -93,11 +96,9 @@ library CheckHelpers { * * @param context The test context. */ - function getApproveTo(FuzzTestContext memory context) - internal - view - returns (address) - { + function getApproveTo( + FuzzTestContext memory context + ) internal view returns (address) { if (context.executionState.fulfillerConduitKey == bytes32(0)) { return address(context.seaport); } else { @@ -125,8 +126,9 @@ library CheckHelpers { if (orderParams.conduitKey == bytes32(0)) { return address(context.seaport); } else { - (address conduit, bool exists) = - context.conduitController.getConduit(orderParams.conduitKey); + (address conduit, bool exists) = context + .conduitController + .getConduit(orderParams.conduitKey); if (exists) { return conduit; } else { @@ -148,8 +150,9 @@ library CheckHelpers { if (orderDetails.conduitKey == bytes32(0)) { return address(context.seaport); } else { - (address conduit, bool exists) = - context.conduitController.getConduit(orderDetails.conduitKey); + (address conduit, bool exists) = context + .conduitController + .getConduit(orderDetails.conduitKey); if (exists) { return conduit; } else { @@ -189,8 +192,10 @@ abstract contract FuzzSetup is Test, AmountDeriverHelper { ); for (uint256 i; i < context.executionState.orderDetails.length; ++i) { - unavailableReasons[i] = - context.executionState.orderDetails[i].unavailableReason; + unavailableReasons[i] = context + .executionState + .orderDetails[i] + .unavailableReason; } // Get the expected zone calldata hashes for each order. @@ -198,23 +203,23 @@ abstract contract FuzzSetup is Test, AmountDeriverHelper { .executionState .orders .getExpectedZoneAuthorizeCalldataHash( - address(context.seaport), - context.executionState.caller, - context.executionState.criteriaResolvers, - context.executionState.maximumFulfilled, - unavailableReasons - ); + address(context.seaport), + context.executionState.caller, + context.executionState.criteriaResolvers, + context.executionState.maximumFulfilled, + unavailableReasons + ); bytes32[] memory validateCalldataHashes = context .executionState .orders .getExpectedZoneValidateCalldataHash( - address(context.seaport), - context.executionState.caller, - context.executionState.criteriaResolvers, - context.executionState.maximumFulfilled, - unavailableReasons - ); + address(context.seaport), + context.executionState.caller, + context.executionState.criteriaResolvers, + context.executionState.maximumFulfilled, + unavailableReasons + ); // Provision the expected zone calldata hash arrays. bytes32[] memory expectedZoneAuthorizeCalldataHashes = new bytes32[]( @@ -230,24 +235,32 @@ abstract contract FuzzSetup is Test, AmountDeriverHelper { // expected zone calldata hash. If any of the orders is restricted, // flip the flag to register the hash validation check. for (uint256 i = 0; i < context.executionState.orders.length; ++i) { - OrderParameters memory order = - context.executionState.orders[i].parameters; + OrderParameters memory order = context + .executionState + .orders[i] + .parameters; if ( - context.executionState.orderDetails[i].unavailableReason - == UnavailableReason.AVAILABLE - && ( - order.orderType == OrderType.FULL_RESTRICTED - || order.orderType == OrderType.PARTIAL_RESTRICTED - ) + context.executionState.orderDetails[i].unavailableReason == + UnavailableReason.AVAILABLE && + (order.orderType == OrderType.FULL_RESTRICTED || + order.orderType == OrderType.PARTIAL_RESTRICTED) ) { registerChecks = true; - expectedZoneAuthorizeCalldataHashes[i] = authorizeCalldataHashes[i]; - expectedZoneValidateCalldataHashes[i] = validateCalldataHashes[i]; + expectedZoneAuthorizeCalldataHashes[ + i + ] = authorizeCalldataHashes[i]; + expectedZoneValidateCalldataHashes[i] = validateCalldataHashes[ + i + ]; } } - context.expectations.expectedZoneAuthorizeCalldataHashes = expectedZoneAuthorizeCalldataHashes; - context.expectations.expectedZoneValidateCalldataHashes = expectedZoneValidateCalldataHashes; + context + .expectations + .expectedZoneAuthorizeCalldataHashes = expectedZoneAuthorizeCalldataHashes; + context + .expectations + .expectedZoneValidateCalldataHashes = expectedZoneValidateCalldataHashes; if (registerChecks) { context.registerCheck( @@ -259,38 +272,40 @@ abstract contract FuzzSetup is Test, AmountDeriverHelper { } } - function setUpContractOfferers(FuzzTestContext memory context) - public - pure - { - bytes32[2][] memory contractOrderCalldataHashes = - context.getExpectedContractOffererCalldataHashes(); + function setUpContractOfferers(FuzzTestContext memory context) public pure { + bytes32[2][] memory contractOrderCalldataHashes = context + .getExpectedContractOffererCalldataHashes(); - bytes32[2][] memory expectedContractOrderCalldataHashes = - new bytes32[2][]( + bytes32[2][] + memory expectedContractOrderCalldataHashes = new bytes32[2][]( context.executionState.orders.length ); bool registerChecks; for (uint256 i = 0; i < context.executionState.orders.length; ++i) { - OrderParameters memory order = - context.executionState.orders[i].parameters; + OrderParameters memory order = context + .executionState + .orders[i] + .parameters; if ( - context.executionState.orderDetails[i].unavailableReason - == UnavailableReason.AVAILABLE - && order.orderType == OrderType.CONTRACT + context.executionState.orderDetails[i].unavailableReason == + UnavailableReason.AVAILABLE && + order.orderType == OrderType.CONTRACT ) { registerChecks = true; - expectedContractOrderCalldataHashes[i][0] = - contractOrderCalldataHashes[i][0]; - expectedContractOrderCalldataHashes[i][1] = - contractOrderCalldataHashes[i][1]; + expectedContractOrderCalldataHashes[i][ + 0 + ] = contractOrderCalldataHashes[i][0]; + expectedContractOrderCalldataHashes[i][ + 1 + ] = contractOrderCalldataHashes[i][1]; } } - context.expectations.expectedContractOrderCalldataHashes = - expectedContractOrderCalldataHashes; + context + .expectations + .expectedContractOrderCalldataHashes = expectedContractOrderCalldataHashes; if (registerChecks) { context.registerCheck( @@ -306,9 +321,9 @@ abstract contract FuzzSetup is Test, AmountDeriverHelper { * @param context The test context. */ function setUpOfferItems(FuzzTestContext memory context) public { - bool isMatchable = context.action() - == context.seaport.matchAdvancedOrders.selector - || context.action() == context.seaport.matchOrders.selector; + bool isMatchable = context.action() == + context.seaport.matchAdvancedOrders.selector || + context.action() == context.seaport.matchOrders.selector; // Iterate over orders and mint/approve as necessary. for (uint256 i; i < context.executionState.orderDetails.length; ++i) { @@ -326,8 +341,8 @@ abstract contract FuzzSetup is Test, AmountDeriverHelper { if (item.itemType == ItemType.NATIVE) { if ( - context.executionState.orders[i].parameters.orderType - == OrderType.CONTRACT + context.executionState.orders[i].parameters.orderType == + OrderType.CONTRACT ) { vm.deal(offerer, offerer.balance + item.amount); } else if (isMatchable) { @@ -342,7 +357,8 @@ abstract contract FuzzSetup is Test, AmountDeriverHelper { TestERC20(item.token).mint(offerer, item.amount); vm.prank(offerer); TestERC20(item.token).increaseAllowance( - approveTo, item.amount + approveTo, + item.amount ); } @@ -354,7 +370,9 @@ abstract contract FuzzSetup is Test, AmountDeriverHelper { if (item.itemType == ItemType.ERC1155) { TestERC1155(item.token).mint( - offerer, item.identifier, item.amount + offerer, + item.identifier, + item.amount ); vm.prank(offerer); TestERC1155(item.token).setApprovalForAll(approveTo, true); @@ -372,8 +390,8 @@ abstract contract FuzzSetup is Test, AmountDeriverHelper { function setUpConsiderationItems(FuzzTestContext memory context) public { // Skip creating consideration items if we're calling a match function if ( - context.action() == context.seaport.matchAdvancedOrders.selector - || context.action() == context.seaport.matchOrders.selector + context.action() == context.seaport.matchAdvancedOrders.selector || + context.action() == context.seaport.matchOrders.selector ) return; // In all cases, deal balance to caller if consideration item is native @@ -394,22 +412,24 @@ abstract contract FuzzSetup is Test, AmountDeriverHelper { // Special handling for basic orders that are bids; only first item // needs to be approved if ( - ( - context.action() == context.seaport.fulfillBasicOrder.selector - || context.action() - == context.seaport.fulfillBasicOrder_efficient_6GL6yc.selector - ) - && context.executionState.orders[0].parameters.offer[0].itemType - == ItemType.ERC20 + (context.action() == context.seaport.fulfillBasicOrder.selector || + context.action() == + context.seaport.fulfillBasicOrder_efficient_6GL6yc.selector) && + context.executionState.orders[0].parameters.offer[0].itemType == + ItemType.ERC20 ) { - ConsiderationItem memory item = - context.executionState.orders[0].parameters.consideration[0]; + ConsiderationItem memory item = context + .executionState + .orders[0] + .parameters + .consideration[0]; address approveTo = context.getApproveTo(); if (item.itemType == ItemType.ERC721) { TestERC721(item.token).mint( - context.executionState.caller, item.identifierOrCriteria + context.executionState.caller, + item.identifierOrCriteria ); vm.prank(context.executionState.caller); TestERC721(item.token).setApprovalForAll(approveTo, true); @@ -445,16 +465,17 @@ abstract contract FuzzSetup is Test, AmountDeriverHelper { TestERC20(item.token).mint(owner, item.amount); vm.prank(owner); TestERC20(item.token).increaseAllowance( - approveTo, item.amount + approveTo, + item.amount ); } if (item.itemType == ItemType.ERC721) { bool shouldMint = true; if ( - context.executionState.caller - == context.executionState.recipient - || context.executionState.recipient == address(0) + context.executionState.caller == + context.executionState.recipient || + context.executionState.recipient == address(0) ) { for ( uint256 k; @@ -462,21 +483,24 @@ abstract contract FuzzSetup is Test, AmountDeriverHelper { ++k ) { if ( - context.executionState.orderDetails[k] - .unavailableReason - != UnavailableReason.AVAILABLE + context + .executionState + .orderDetails[k] + .unavailableReason != + UnavailableReason.AVAILABLE ) { continue; } - SpentItem[] memory spentItems = - context.executionState.orderDetails[k].offer; + SpentItem[] memory spentItems = context + .executionState + .orderDetails[k] + .offer; for (uint256 l; l < spentItems.length; ++l) { if ( - spentItems[l].itemType == ItemType.ERC721 - && spentItems[l].token == item.token - && spentItems[l].identifier - == item.identifier + spentItems[l].itemType == ItemType.ERC721 && + spentItems[l].token == item.token && + spentItems[l].identifier == item.identifier ) { shouldMint = false; break; @@ -494,7 +518,9 @@ abstract contract FuzzSetup is Test, AmountDeriverHelper { if (item.itemType == ItemType.ERC1155) { TestERC1155(item.token).mint( - owner, item.identifier, item.amount + owner, + item.identifier, + item.amount ); vm.prank(owner); TestERC1155(item.token).setApprovalForAll(approveTo, true); @@ -503,19 +529,21 @@ abstract contract FuzzSetup is Test, AmountDeriverHelper { } } - function registerExpectedEventsAndBalances(FuzzTestContext memory context) - public - { + function registerExpectedEventsAndBalances( + FuzzTestContext memory context + ) public { ExecutionsFlattener.flattenExecutions(context); context.registerCheck(FuzzChecks.check_expectedBalances.selector); ExpectedBalances balanceChecker = context.testHelpers.balanceChecker(); - Execution[] memory _executions = - context.expectations.allExpectedExecutions; + Execution[] memory _executions = context + .expectations + .allExpectedExecutions; Execution[] memory executions = _executions; - try balanceChecker.addTransfers(executions) { } - catch (bytes memory reason) { + try balanceChecker.addTransfers(executions) {} catch ( + bytes memory reason + ) { context.expectations.allExpectedExecutions = executions; dumpExecutions(context); assembly { @@ -549,10 +577,9 @@ abstract contract FuzzSetup is Test, AmountDeriverHelper { * * @param context The test context. */ - function registerFunctionSpecificChecks(FuzzTestContext memory context) - public - view - { + function registerFunctionSpecificChecks( + FuzzTestContext memory context + ) public view { bytes4 _action = context.action(); if (_action == context.seaport.fulfillOrder.selector) { context.registerCheck(FuzzChecks.check_orderFulfilled.selector); @@ -561,8 +588,8 @@ abstract contract FuzzSetup is Test, AmountDeriverHelper { } else if (_action == context.seaport.fulfillBasicOrder.selector) { context.registerCheck(FuzzChecks.check_orderFulfilled.selector); } else if ( - _action - == context.seaport.fulfillBasicOrder_efficient_6GL6yc.selector + _action == + context.seaport.fulfillBasicOrder_efficient_6GL6yc.selector ) { context.registerCheck(FuzzChecks.check_orderFulfilled.selector); } else if (_action == context.seaport.fulfillAvailableOrders.selector) { diff --git a/test/foundry/new/helpers/FuzzTestContextLib.sol b/test/foundry/new/helpers/FuzzTestContextLib.sol index 39f9ae3..22ee706 100644 --- a/test/foundry/new/helpers/FuzzTestContextLib.sol +++ b/test/foundry/new/helpers/FuzzTestContextLib.sol @@ -36,11 +36,13 @@ import { AdvancedOrdersSpace } from "seaport-sol/src/StructSpace.sol"; import { OrderDetails } from "seaport-sol/src/fulfillments/lib/Structs.sol"; -import { AmountDeriverHelper } from - "seaport-sol/src/lib/fulfillment/AmountDeriverHelper.sol"; +import { + AmountDeriverHelper +} from "seaport-sol/src/lib/fulfillment/AmountDeriverHelper.sol"; -import { ConduitControllerInterface } from - "seaport-sol/src/ConduitControllerInterface.sol"; +import { + ConduitControllerInterface +} from "seaport-sol/src/ConduitControllerInterface.sol"; import { SeaportInterface } from "seaport-sol/src/SeaportInterface.sol"; @@ -66,28 +68,27 @@ import { SeaportValidatorInterface } from "../../../../src/main/helpers/order-validator/SeaportValidator.sol"; -import { SeaportNavigatorInterface } from - "../../../../src/main/helpers/navigator/SeaportNavigator.sol"; +import { + SeaportNavigatorInterface +} from "../../../../src/main/helpers/navigator/SeaportNavigator.sol"; interface TestHelpers { function balanceChecker() external view returns (ExpectedBalances); - function amountDeriverHelper() - external - view - returns (AmountDeriverHelper); + function amountDeriverHelper() external view returns (AmountDeriverHelper); function criteriaResolverHelper() external view returns (CriteriaResolverHelper); - function makeAccountWrapper(string memory name) - external - view - returns (StdCheats.Account memory); + function makeAccountWrapper( + string memory name + ) external view returns (StdCheats.Account memory); - function getNaiveFulfillmentComponents(OrderDetails[] memory orderDetails) + function getNaiveFulfillmentComponents( + OrderDetails[] memory orderDetails + ) external returns ( FulfillmentComponent[][] memory offer, @@ -105,7 +106,9 @@ interface TestHelpers { MatchComponent[] memory remainingConsiderationComponents ); - function getMatchedFulfillments(OrderDetails[] memory orders) + function getMatchedFulfillments( + OrderDetails[] memory orders + ) external returns ( Fulfillment[] memory fulfillments, @@ -113,8 +116,7 @@ interface TestHelpers { MatchComponent[] memory remainingConsiderationComponents ); - function allocateTokensAndApprovals(address _to, uint128 _amount) - external; + function allocateTokensAndApprovals(address _to, uint128 _amount) external; } struct FuzzParams { @@ -423,55 +425,56 @@ library FuzzTestContextLib { }); } - return FuzzTestContext({ - _action: bytes4(0), - actionSelected: false, - seaport: SeaportInterface(address(0)), - conduitController: ConduitControllerInterface(address(0)), - seaportValidator: SeaportValidatorInterface(address(0)), - seaportNavigator: SeaportNavigatorInterface(address(0)), - fuzzParams: FuzzParams({ - seed: 0, - totalOrders: 0, - maxOfferItems: 0, - maxConsiderationItems: 0, - seedInput: "" - }), - checks: new bytes4[](0), - returnValues: ReturnValues({ - fulfilled: false, - cancelled: false, - validated: false, - availableOrders: available, - executions: executions - }), - expectations: expectations, - executionState: ExecutionState({ - caller: address(0), - contractOffererNonce: 0, - recipient: address(0), - counter: 0, - fulfillerConduitKey: bytes32(0), - basicOrderParameters: BasicOrderParametersLib.empty(), - preExecOrderStatuses: new OrderStatusEnum[](0), - previewedOrders: orders, - orders: orders, - orderDetails: new OrderDetails[](0), - criteriaResolvers: resolvers, - fulfillments: fulfillments, - remainingOfferComponents: components, - hasRemainders: false, - offerFulfillments: componentsArray, - considerationFulfillments: componentsArray, - maximumFulfilled: 0, - value: 0, - validationErrors: new ErrorsAndWarnings[](orders.length) - }), - actualEvents: actualEvents, - testHelpers: TestHelpers(address(this)), - generatorContext: FuzzGeneratorContextLib.empty(), - advancedOrdersSpace: TestStateGenerator.empty() - }); + return + FuzzTestContext({ + _action: bytes4(0), + actionSelected: false, + seaport: SeaportInterface(address(0)), + conduitController: ConduitControllerInterface(address(0)), + seaportValidator: SeaportValidatorInterface(address(0)), + seaportNavigator: SeaportNavigatorInterface(address(0)), + fuzzParams: FuzzParams({ + seed: 0, + totalOrders: 0, + maxOfferItems: 0, + maxConsiderationItems: 0, + seedInput: "" + }), + checks: new bytes4[](0), + returnValues: ReturnValues({ + fulfilled: false, + cancelled: false, + validated: false, + availableOrders: available, + executions: executions + }), + expectations: expectations, + executionState: ExecutionState({ + caller: address(0), + contractOffererNonce: 0, + recipient: address(0), + counter: 0, + fulfillerConduitKey: bytes32(0), + basicOrderParameters: BasicOrderParametersLib.empty(), + preExecOrderStatuses: new OrderStatusEnum[](0), + previewedOrders: orders, + orders: orders, + orderDetails: new OrderDetails[](0), + criteriaResolvers: resolvers, + fulfillments: fulfillments, + remainingOfferComponents: components, + hasRemainders: false, + offerFulfillments: componentsArray, + considerationFulfillments: componentsArray, + maximumFulfilled: 0, + value: 0, + validationErrors: new ErrorsAndWarnings[](orders.length) + }), + actualEvents: actualEvents, + testHelpers: TestHelpers(address(this)), + generatorContext: FuzzGeneratorContextLib.empty(), + advancedOrdersSpace: TestStateGenerator.empty() + }); } /** @@ -487,9 +490,14 @@ library FuzzTestContextLib { SeaportInterface seaport, address caller ) internal returns (FuzzTestContext memory) { - return empty().withOrders(orders).withSeaport(seaport).withOrderHashes() - .withCaller(caller).withPreviewedOrders(orders.copy()) - .withProvisionedIneligbleOrdersArray(); + return + empty() + .withOrders(orders) + .withSeaport(seaport) + .withOrderHashes() + .withCaller(caller) + .withPreviewedOrders(orders.copy()) + .withProvisionedIneligbleOrdersArray(); } /** @@ -499,13 +507,17 @@ library FuzzTestContextLib { * @param seaport the SeaportInterface to set * @custom:return _context the FuzzTestContext */ - function from(AdvancedOrder[] memory orders, SeaportInterface seaport) - internal - returns (FuzzTestContext memory) - { - return empty().withOrders(orders).withSeaport(seaport).withOrderHashes() - .withPreviewedOrders(orders.copy()).withProvisionedIneligbleOrdersArray( - ); + function from( + AdvancedOrder[] memory orders, + SeaportInterface seaport + ) internal returns (FuzzTestContext memory) { + return + empty() + .withOrders(orders) + .withSeaport(seaport) + .withOrderHashes() + .withPreviewedOrders(orders.copy()) + .withProvisionedIneligbleOrdersArray(); } /** @@ -531,31 +543,35 @@ library FuzzTestContextLib { orders.length ); for (uint256 i = 0; i < orders.length; ++i) { - context.executionState.orderDetails[i].unavailableReason = - UnavailableReason.AVAILABLE; + context + .executionState + .orderDetails[i] + .unavailableReason = UnavailableReason.AVAILABLE; } } - context.expectations.expectedFillFractions = - (new FractionResults[](orders.length)); + context.expectations.expectedFillFractions = ( + new FractionResults[](orders.length) + ); return context; } // NOTE: expects context.executionState.orders and context.seaport to // already be set. - function withOrderHashes(FuzzTestContext memory context) - internal - view - returns (FuzzTestContext memory) - { + function withOrderHashes( + FuzzTestContext memory context + ) internal view returns (FuzzTestContext memory) { bytes32[] memory orderHashes = context .executionState .orders .getOrderHashes(address(context.seaport)); - for (uint256 i = 0; i < context.executionState.orderDetails.length; ++i) - { + for ( + uint256 i = 0; + i < context.executionState.orderDetails.length; + ++i + ) { context.executionState.orderDetails[i].orderHash = orderHashes[i]; } @@ -570,11 +586,9 @@ library FuzzTestContextLib { return context; } - function withProvisionedIneligbleOrdersArray(FuzzTestContext memory context) - internal - pure - returns (FuzzTestContext memory) - { + function withProvisionedIneligbleOrdersArray( + FuzzTestContext memory context + ) internal pure returns (FuzzTestContext memory) { context.expectations.ineligibleOrders = new bool[]( context.executionState.orders.length ); @@ -659,11 +673,10 @@ library FuzzTestContextLib { * * @return _context the FuzzTestContext with the caller set */ - function withCaller(FuzzTestContext memory context, address caller) - internal - pure - returns (FuzzTestContext memory) - { + function withCaller( + FuzzTestContext memory context, + address caller + ) internal pure returns (FuzzTestContext memory) { context.executionState.caller = caller; return context; } @@ -692,11 +705,10 @@ library FuzzTestContextLib { * * @return _context the FuzzTestContext with the checks set */ - function withChecks(FuzzTestContext memory context, bytes4[] memory checks) - internal - pure - returns (FuzzTestContext memory) - { + function withChecks( + FuzzTestContext memory context, + bytes4[] memory checks + ) internal pure returns (FuzzTestContext memory) { context.checks = _copyBytes4(checks); return context; } @@ -709,11 +721,10 @@ library FuzzTestContextLib { * * @return _context the FuzzTestContext with the counter set */ - function withCounter(FuzzTestContext memory context, uint256 counter) - internal - pure - returns (FuzzTestContext memory) - { + function withCounter( + FuzzTestContext memory context, + uint256 counter + ) internal pure returns (FuzzTestContext memory) { context.executionState.counter = counter; return context; } @@ -778,8 +789,9 @@ library FuzzTestContextLib { FuzzTestContext memory context, CriteriaResolver[] memory criteriaResolvers ) internal pure returns (FuzzTestContext memory) { - context.executionState.criteriaResolvers = - _copyCriteriaResolvers(criteriaResolvers); + context.executionState.criteriaResolvers = _copyCriteriaResolvers( + criteriaResolvers + ); return context; } @@ -791,11 +803,10 @@ library FuzzTestContextLib { * * @return _context the FuzzTestContext with the recipient set */ - function withRecipient(FuzzTestContext memory context, address recipient) - internal - pure - returns (FuzzTestContext memory) - { + function withRecipient( + FuzzTestContext memory context, + address recipient + ) internal pure returns (FuzzTestContext memory) { context.executionState.recipient = recipient; return context; } @@ -828,8 +839,9 @@ library FuzzTestContextLib { FuzzTestContext memory context, FulfillmentComponent[][] memory offerFulfillments ) internal pure returns (FuzzTestContext memory) { - context.executionState.offerFulfillments = - _copyFulfillmentComponents(offerFulfillments); + context.executionState.offerFulfillments = _copyFulfillmentComponents( + offerFulfillments + ); return context; } @@ -848,8 +860,11 @@ library FuzzTestContextLib { FuzzTestContext memory context, FulfillmentComponent[][] memory considerationFulfillments ) internal pure returns (FuzzTestContext memory) { - context.executionState.considerationFulfillments = - _copyFulfillmentComponents(considerationFulfillments); + context + .executionState + .considerationFulfillments = _copyFulfillmentComponents( + considerationFulfillments + ); return context; } @@ -907,58 +922,62 @@ library FuzzTestContextLib { for (uint256 i = 0; i < context.executionState.orders.length; i++) { if (space.orders[i].orderType == BroadOrderType.CONTRACT) { if ( - space.orders[i].unavailableReason - == UnavailableReason.GENERATE_ORDER_FAILURE + space.orders[i].unavailableReason == + UnavailableReason.GENERATE_ORDER_FAILURE ) { - context.executionState.preExecOrderStatuses[i] = - OrderStatusEnum.REVERT; + context.executionState.preExecOrderStatuses[ + i + ] = OrderStatusEnum.REVERT; } else { - context.executionState.preExecOrderStatuses[i] = - OrderStatusEnum.AVAILABLE; + context.executionState.preExecOrderStatuses[ + i + ] = OrderStatusEnum.AVAILABLE; } } else if ( space.orders[i].unavailableReason == UnavailableReason.CANCELLED ) { // TODO: support cases where order is both cancelled and has // been partially fulfilled. - context.executionState.preExecOrderStatuses[i] = - OrderStatusEnum.CANCELLED_EXPLICIT; + context.executionState.preExecOrderStatuses[i] = OrderStatusEnum + .CANCELLED_EXPLICIT; } else if ( - space.orders[i].unavailableReason - == UnavailableReason.ALREADY_FULFILLED + space.orders[i].unavailableReason == + UnavailableReason.ALREADY_FULFILLED ) { - context.executionState.preExecOrderStatuses[i] = - OrderStatusEnum.FULFILLED; + context.executionState.preExecOrderStatuses[i] = OrderStatusEnum + .FULFILLED; } else if ( space.orders[i].signatureMethod == SignatureMethod.VALIDATE ) { // NOTE: this assumes that the order has not been partially // filled (partially filled orders are de-facto validated). - context.executionState.preExecOrderStatuses[i] = - OrderStatusEnum.VALIDATED; + context.executionState.preExecOrderStatuses[i] = OrderStatusEnum + .VALIDATED; } else { if ( - space.orders[i].unavailableReason - == UnavailableReason.GENERATE_ORDER_FAILURE + space.orders[i].unavailableReason == + UnavailableReason.GENERATE_ORDER_FAILURE ) { revert( "FuzzTestContextLib: bad location for generate order failure" ); } - OrderType orderType = - (context.executionState.orders[i].parameters.orderType); + OrderType orderType = ( + context.executionState.orders[i].parameters.orderType + ); // TODO: figure out a way to do this for orders with 721 items - OrderParameters memory orderParams = - (context.executionState.orders[i].parameters); + OrderParameters memory orderParams = ( + context.executionState.orders[i].parameters + ); bool has721 = false; for (uint256 j = 0; j < orderParams.offer.length; ++j) { if ( - orderParams.offer[j].itemType == ItemType.ERC721 - || orderParams.offer[j].itemType - == ItemType.ERC721_WITH_CRITERIA + orderParams.offer[j].itemType == ItemType.ERC721 || + orderParams.offer[j].itemType == + ItemType.ERC721_WITH_CRITERIA ) { has721 = true; break; @@ -967,13 +986,15 @@ library FuzzTestContextLib { if (!has721) { for ( - uint256 j = 0; j < orderParams.consideration.length; ++j + uint256 j = 0; + j < orderParams.consideration.length; + ++j ) { if ( - orderParams.consideration[j].itemType - == ItemType.ERC721 - || orderParams.consideration[j].itemType - == ItemType.ERC721_WITH_CRITERIA + orderParams.consideration[j].itemType == + ItemType.ERC721 || + orderParams.consideration[j].itemType == + ItemType.ERC721_WITH_CRITERIA ) { has721 = true; break; @@ -981,27 +1002,24 @@ library FuzzTestContextLib { } } - uint256 upperBound = ( - !has721 - && ( - orderType == OrderType.PARTIAL_OPEN - || orderType == OrderType.PARTIAL_RESTRICTED - ) - ) ? 2 : 1; + uint256 upperBound = (!has721 && + (orderType == OrderType.PARTIAL_OPEN || + orderType == OrderType.PARTIAL_RESTRICTED)) + ? 2 + : 1; - context.executionState.preExecOrderStatuses[i] = - OrderStatusEnum(uint8(bound(prng.next(), 0, upperBound))); + context.executionState.preExecOrderStatuses[ + i + ] = OrderStatusEnum(uint8(bound(prng.next(), 0, upperBound))); } } return context; } - function _copyBytes4(bytes4[] memory selectors) - private - pure - returns (bytes4[] memory) - { + function _copyBytes4( + bytes4[] memory selectors + ) private pure returns (bytes4[] memory) { bytes4[] memory copy = new bytes4[](selectors.length); for (uint256 i = 0; i < selectors.length; i++) { copy[i] = selectors[i]; @@ -1012,13 +1030,13 @@ library FuzzTestContextLib { function _copyFulfillmentComponents( FulfillmentComponent[][] memory fulfillmentComponents ) private pure returns (FulfillmentComponent[][] memory) { - FulfillmentComponent[][] memory outerCopy = - new FulfillmentComponent[][]( + FulfillmentComponent[][] + memory outerCopy = new FulfillmentComponent[][]( fulfillmentComponents.length ); for (uint256 i = 0; i < fulfillmentComponents.length; i++) { - FulfillmentComponent[] memory innerCopy = - new FulfillmentComponent[]( + FulfillmentComponent[] + memory innerCopy = new FulfillmentComponent[]( fulfillmentComponents[i].length ); for (uint256 j = 0; j < fulfillmentComponents[i].length; j++) { @@ -1029,11 +1047,9 @@ library FuzzTestContextLib { return outerCopy; } - function _copyCriteriaResolvers(CriteriaResolver[] memory criteriaResolvers) - private - pure - returns (CriteriaResolver[] memory) - { + function _copyCriteriaResolvers( + CriteriaResolver[] memory criteriaResolvers + ) private pure returns (CriteriaResolver[] memory) { CriteriaResolver[] memory copy = new CriteriaResolver[]( criteriaResolvers.length ); @@ -1043,26 +1059,26 @@ library FuzzTestContextLib { return copy; } - function _copyFuzzParams(FuzzParams memory params) - private - pure - returns (FuzzParams memory) - { - return FuzzParams({ - seed: params.seed, - totalOrders: params.totalOrders, - maxOfferItems: params.maxOfferItems, - maxConsiderationItems: params.maxConsiderationItems, - seedInput: bytes.concat(params.seedInput) - }); + function _copyFuzzParams( + FuzzParams memory params + ) private pure returns (FuzzParams memory) { + return + FuzzParams({ + seed: params.seed, + totalOrders: params.totalOrders, + maxOfferItems: params.maxOfferItems, + maxConsiderationItems: params.maxConsiderationItems, + seedInput: bytes.concat(params.seedInput) + }); } } // @dev Implementation cribbed from forge-std bound -function bound(uint256 x, uint256 min, uint256 max) - pure - returns (uint256 result) -{ +function bound( + uint256 x, + uint256 min, + uint256 max +) pure returns (uint256 result) { require(min <= max, "Max is less than min."); // If x is between min and max, return x directly. This is to ensure that // dictionary values do not get shifted if the min is nonzero. diff --git a/test/foundry/new/helpers/Labeler.sol b/test/foundry/new/helpers/Labeler.sol index 9b10012..89b22b2 100644 --- a/test/foundry/new/helpers/Labeler.sol +++ b/test/foundry/new/helpers/Labeler.sol @@ -4,8 +4,9 @@ pragma solidity ^0.8.17; import { vm } from "./VmUtils.sol"; import { LibString } from "solady/src/utils/LibString.sol"; -address constant LABELER_ADDRESS = - address(uint160(uint256(keccak256(".labeler")))); +address constant LABELER_ADDRESS = address( + uint160(uint256(keccak256(".labeler"))) +); function setLabel(address account, string memory _label) { vm.store( @@ -32,8 +33,10 @@ function getLabel(address account) pure returns (string memory) { } function getLabelView(address account) view returns (string memory _label) { - bytes32 storedLabel = - vm.load(LABELER_ADDRESS, bytes32(uint256(uint160(account)))); + bytes32 storedLabel = vm.load( + LABELER_ADDRESS, + bytes32(uint256(uint160(account))) + ); if (storedLabel != bytes32(0)) { return LibString.unpackOne(storedLabel); } diff --git a/test/foundry/new/helpers/PreapprovedERC721.sol b/test/foundry/new/helpers/PreapprovedERC721.sol index fc0e8d0..b5b3074 100644 --- a/test/foundry/new/helpers/PreapprovedERC721.sol +++ b/test/foundry/new/helpers/PreapprovedERC721.sol @@ -17,13 +17,12 @@ contract PreapprovedERC721 is CustomERC721 { return true; } - function isApprovedForAll(address owner, address operator) - public - view - override - returns (bool) - { - return preapprovals[operator] || super.isApprovedForAll(owner, operator); + function isApprovedForAll( + address owner, + address operator + ) public view override returns (bool) { + return + preapprovals[operator] || super.isApprovedForAll(owner, operator); } function tokenURI(uint256) public pure override returns (string memory) { diff --git a/test/foundry/new/helpers/Searializer.sol b/test/foundry/new/helpers/Searializer.sol index bed2616..c967bb3 100644 --- a/test/foundry/new/helpers/Searializer.sol +++ b/test/foundry/new/helpers/Searializer.sol @@ -27,7 +27,9 @@ import { import { Result } from "./FuzzHelpers.sol"; import { - FuzzParams, FuzzTestContext, ReturnValues + FuzzParams, + FuzzTestContext, + ReturnValues } from "./FuzzTestContextLib.sol"; import { @@ -41,11 +43,13 @@ import { import { withLabel } from "./Labeler.sol"; -import { ErrorsAndWarnings } from - "../../../../src/main/helpers/order-validator/SeaportValidator.sol"; +import { + ErrorsAndWarnings +} from "../../../../src/main/helpers/order-validator/SeaportValidator.sol"; -import { IssueStringHelpers } from - "../../../../src/main/helpers/order-validator/lib/SeaportValidatorTypes.sol"; +import { + IssueStringHelpers +} from "../../../../src/main/helpers/order-validator/lib/SeaportValidatorTypes.sol"; /** * @notice A helper library to seralize test data as JSON. @@ -85,7 +89,9 @@ library Searializer { tojsonUint256(obj, "totalOrders", value.totalOrders); tojsonUint256(obj, "maxOfferItems", value.maxOfferItems); string memory finalJson = tojsonUint256( - obj, "maxConsiderationItems", value.maxConsiderationItems + obj, + "maxConsiderationItems", + value.maxConsiderationItems ); return vm.serializeString(objectKey, valueKey, finalJson); } @@ -117,8 +123,11 @@ library Searializer { tojsonAddress(obj, "token", value.token); tojsonUint256(obj, "identifierOrCriteria", value.identifierOrCriteria); tojsonUint256(obj, "startAmount", value.startAmount); - string memory finalJson = - tojsonUint256(obj, "endAmount", value.endAmount); + string memory finalJson = tojsonUint256( + obj, + "endAmount", + value.endAmount + ); return vm.serializeString(objectKey, valueKey, finalJson); } @@ -147,8 +156,11 @@ library Searializer { tojsonUint256(obj, "identifierOrCriteria", value.identifierOrCriteria); tojsonUint256(obj, "startAmount", value.startAmount); tojsonUint256(obj, "endAmount", value.endAmount); - string memory finalJson = - tojsonAddress(obj, "recipient", value.recipient); + string memory finalJson = tojsonAddress( + obj, + "recipient", + value.recipient + ); return vm.serializeString(objectKey, valueKey, finalJson); } @@ -192,7 +204,9 @@ library Searializer { tojsonAddress(obj, "zone", value.zone); tojsonDynArrayOfferItem(obj, "offer", value.offer); tojsonDynArrayConsiderationItem( - obj, "consideration", value.consideration + obj, + "consideration", + value.consideration ); tojsonOrderType(obj, "orderType", value.orderType); tojsonUint256(obj, "startTime", value.startTime); @@ -226,7 +240,11 @@ library Searializer { tojsonUint256(obj, "numerator", value.numerator); tojsonUint256(obj, "denominator", value.denominator); tojsonBytes(obj, "signature", value.signature); - string memory finalJson = tojsonBytes(obj, "extraData", value.extraData); + string memory finalJson = tojsonBytes( + obj, + "extraData", + value.extraData + ); return vm.serializeString(objectKey, valueKey, finalJson); } @@ -272,8 +290,11 @@ library Searializer { tojsonSide(obj, "side", value.side); tojsonUint256(obj, "index", value.index); tojsonUint256(obj, "identifier", value.identifier); - string memory finalJson = - tojsonDynArrayBytes32(obj, "criteriaProof", value.criteriaProof); + string memory finalJson = tojsonDynArrayBytes32( + obj, + "criteriaProof", + value.criteriaProof + ); return vm.serializeString(objectKey, valueKey, finalJson); } @@ -298,8 +319,11 @@ library Searializer { ) internal returns (string memory) { string memory obj = string.concat(objectKey, valueKey); tojsonUint256(obj, "orderIndex", value.orderIndex); - string memory finalJson = - tojsonUint256(obj, "itemIndex", value.itemIndex); + string memory finalJson = tojsonUint256( + obj, + "itemIndex", + value.itemIndex + ); return vm.serializeString(objectKey, valueKey, finalJson); } @@ -324,10 +348,14 @@ library Searializer { ) internal returns (string memory) { string memory obj = string.concat(objectKey, valueKey); tojsonDynArrayFulfillmentComponent( - obj, "offerComponents", value.offerComponents + obj, + "offerComponents", + value.offerComponents ); string memory finalJson = tojsonDynArrayFulfillmentComponent( - obj, "considerationComponents", value.considerationComponents + obj, + "considerationComponents", + value.considerationComponents ); return vm.serializeString(objectKey, valueKey, finalJson); } @@ -356,7 +384,9 @@ library Searializer { string memory out; for (uint256 i; i < length; i++) { out = tojsonDynArrayFulfillmentComponent( - obj, vm.toString(i), value[i] + obj, + vm.toString(i), + value[i] ); } return vm.serializeString(objectKey, valueKey, out); @@ -404,8 +434,11 @@ library Searializer { ) internal returns (string memory) { string memory obj = string.concat(objectKey, valueKey); tojsonUint256(obj, "amount", value.amount); - string memory finalJson = - tojsonAddress(obj, "recipient", value.recipient); + string memory finalJson = tojsonAddress( + obj, + "recipient", + value.recipient + ); return vm.serializeString(objectKey, valueKey, finalJson); } @@ -431,7 +464,9 @@ library Searializer { string memory obj = string.concat(objectKey, valueKey); tojsonAddress(obj, "considerationToken", value.considerationToken); tojsonUint256( - obj, "considerationIdentifier", value.considerationIdentifier + obj, + "considerationIdentifier", + value.considerationIdentifier ); tojsonUint256(obj, "considerationAmount", value.considerationAmount); tojsonAddress(obj, "offerer", value.offerer); @@ -452,9 +487,15 @@ library Searializer { value.totalOriginalAdditionalRecipients ); tojsonDynArrayAdditionalRecipient( - obj, "additionalRecipients", value.additionalRecipients + obj, + "additionalRecipients", + value.additionalRecipients + ); + string memory finalJson = tojsonBytes( + obj, + "signature", + value.signature ); - string memory finalJson = tojsonBytes(obj, "signature", value.signature); return vm.serializeString(objectKey, valueKey, finalJson); } @@ -505,8 +546,12 @@ library Searializer { string memory valueKey, Result value ) internal returns (string memory) { - string[4] memory members = - ["FULFILLMENT", "UNAVAILABLE", "VALIDATE", "CANCEL"]; + string[4] memory members = [ + "FULFILLMENT", + "UNAVAILABLE", + "VALIDATE", + "CANCEL" + ]; uint256 index = uint256(value); return vm.serializeString(objectKey, valueKey, members[index]); } @@ -535,8 +580,11 @@ library Searializer { tojsonAddress(obj, "token", value.token); tojsonUint256(obj, "identifier", value.identifier); tojsonUint256(obj, "amount", value.amount); - string memory finalJson = - tojsonAddress(obj, "recipient", value.recipient); + string memory finalJson = tojsonAddress( + obj, + "recipient", + value.recipient + ); return vm.serializeString(objectKey, valueKey, finalJson); } @@ -548,8 +596,11 @@ library Searializer { string memory obj = string.concat(objectKey, valueKey); tojsonReceivedItem(obj, "item", value.item); tojsonAddress(obj, "offerer", value.offerer); - string memory finalJson = - tojsonBytes32(obj, "conduitKey", value.conduitKey); + string memory finalJson = tojsonBytes32( + obj, + "conduitKey", + value.conduitKey + ); return vm.serializeString(objectKey, valueKey, finalJson); } @@ -619,8 +670,11 @@ library Searializer { tojsonBool(obj, "cancelled", value.cancelled); tojsonBool(obj, "validated", value.validated); tojsonDynArrayBool(obj, "availableOrders", value.availableOrders); - string memory finalJson = - tojsonDynArrayExecution(obj, "executions", value.executions); + string memory finalJson = tojsonDynArrayExecution( + obj, + "executions", + value.executions + ); return vm.serializeString(objectKey, valueKey, finalJson); } @@ -633,24 +687,34 @@ library Searializer { tojsonBytes32(obj, "_action", value._action); tojsonAddress(obj, "seaport", address(value.seaport)); tojsonAddress( - obj, "conduitController", address(value.conduitController) + obj, + "conduitController", + address(value.conduitController) ); tojsonAddress(obj, "caller", value.executionState.caller); tojsonAddress(obj, "recipient", value.executionState.recipient); tojsonFuzzParams(obj, "fuzzParams", value.fuzzParams); tojsonDynArrayAdvancedOrder(obj, "orders", value.executionState.orders); tojsonDynArrayAdvancedOrder( - obj, "previewedOrders", value.executionState.previewedOrders + obj, + "previewedOrders", + value.executionState.previewedOrders ); tojsonUint256(obj, "counter", value.executionState.counter); tojsonBytes32( - obj, "fulfillerConduitKey", value.executionState.fulfillerConduitKey + obj, + "fulfillerConduitKey", + value.executionState.fulfillerConduitKey ); tojsonDynArrayCriteriaResolver( - obj, "criteriaResolvers", value.executionState.criteriaResolvers + obj, + "criteriaResolvers", + value.executionState.criteriaResolvers ); tojsonDynArrayFulfillment( - obj, "fulfillments", value.executionState.fulfillments + obj, + "fulfillments", + value.executionState.fulfillments ); tojsonDynArrayFulfillmentComponent( obj, @@ -658,7 +722,9 @@ library Searializer { value.executionState.remainingOfferComponents ); tojsonDynArrayDynArrayFulfillmentComponent( - obj, "offerFulfillments", value.executionState.offerFulfillments + obj, + "offerFulfillments", + value.executionState.offerFulfillments ); tojsonDynArrayDynArrayFulfillmentComponent( obj, @@ -666,7 +732,9 @@ library Searializer { value.executionState.considerationFulfillments ); tojsonUint256( - obj, "maximumFulfilled", value.executionState.maximumFulfilled + obj, + "maximumFulfilled", + value.executionState.maximumFulfilled ); tojsonBasicOrderParameters( obj, @@ -691,7 +759,9 @@ library Searializer { value.expectations.expectedContractOrderCalldataHashes ); tojsonDynArrayResult( - obj, "expectedResults", value.expectations.expectedResults + obj, + "expectedResults", + value.expectations.expectedResults ); tojsonDynArrayExecution( obj, @@ -724,8 +794,11 @@ library Searializer { value.expectations.expectedSeaportEventHashes ); tojsonDynArrayLog(obj, "actualEvents", value.actualEvents); - string memory finalJson = - tojsonReturnValues(obj, "returnValues", value.returnValues); + string memory finalJson = tojsonReturnValues( + obj, + "returnValues", + value.returnValues + ); return vm.serializeString(objectKey, valueKey, finalJson); } @@ -778,8 +851,11 @@ library Searializer { string memory obj = string.concat(objectKey, valueKey); tojsonAddress(obj, "token", value.token); tojsonDynArrayAddress(obj, "accounts", value.accounts); - string memory finalJson = - tojsonDynArrayUint256(obj, "balances", value.balances); + string memory finalJson = tojsonDynArrayUint256( + obj, + "balances", + value.balances + ); return vm.serializeString(objectKey, valueKey, finalJson); } @@ -806,7 +882,9 @@ library Searializer { tojsonAddress(obj, "token", value.token); tojsonDynArrayAddress(obj, "accounts", value.accounts); string memory finalJson = tojsonDynArrayDynArrayUint256( - obj, "accountIdentifiers", value.accountIdentifiers + obj, + "accountIdentifiers", + value.accountIdentifiers ); return vm.serializeString(objectKey, valueKey, finalJson); } @@ -819,8 +897,11 @@ library Searializer { string memory obj = string.concat(objectKey, valueKey); tojsonAddress(obj, "account", value.account); tojsonDynArrayUint256(obj, "identifiers", value.identifiers); - string memory finalJson = - tojsonDynArrayUint256(obj, "balances", value.balances); + string memory finalJson = tojsonDynArrayUint256( + obj, + "balances", + value.balances + ); return vm.serializeString(objectKey, valueKey, finalJson); } @@ -845,8 +926,11 @@ library Searializer { ) internal returns (string memory) { string memory obj = string.concat(objectKey, valueKey); tojsonAddress(obj, "token", value.token); - string memory finalJson = - tojsonDynArrayERC1155AccountDump(obj, "accounts", value.accounts); + string memory finalJson = tojsonDynArrayERC1155AccountDump( + obj, + "accounts", + value.accounts + ); return vm.serializeString(objectKey, valueKey, finalJson); } @@ -900,8 +984,11 @@ library Searializer { string memory obj = string.concat(objectKey, valueKey); tojsonDynArrayERC20TokenDump(obj, "erc20", value.erc20); tojsonDynArrayERC721TokenDump(obj, "erc721", value.erc721); - string memory finalJson = - tojsonDynArrayERC1155TokenDump(obj, "erc1155", value.erc1155); + string memory finalJson = tojsonDynArrayERC1155TokenDump( + obj, + "erc1155", + value.erc1155 + ); return vm.serializeString(objectKey, valueKey, finalJson); } @@ -916,7 +1003,9 @@ library Searializer { for (uint256 i; i < length; i++) { if (value[i].errors.length > 0) { out = tojsonDynArrayValidationErrorMessages( - obj, vm.toString(i), value[i].errors + obj, + vm.toString(i), + value[i].errors ); } } diff --git a/test/foundry/new/helpers/VmUtils.sol b/test/foundry/new/helpers/VmUtils.sol index a706164..fcf6ede 100644 --- a/test/foundry/new/helpers/VmUtils.sol +++ b/test/foundry/new/helpers/VmUtils.sol @@ -4,8 +4,9 @@ pragma solidity ^0.8.17; import { Vm } from "forge-std/Vm.sol"; import { logAssume } from "./Metrics.sol"; -address constant VM_ADDRESS = - address(uint160(uint256(keccak256("hevm cheat code")))); +address constant VM_ADDRESS = address( + uint160(uint256(keccak256("hevm cheat code"))) +); Vm constant vm = Vm(VM_ADDRESS); /** diff --git a/test/foundry/new/helpers/event-utils/EventHashes.sol b/test/foundry/new/helpers/event-utils/EventHashes.sol index 2e59297..84d05da81 100644 --- a/test/foundry/new/helpers/event-utils/EventHashes.sol +++ b/test/foundry/new/helpers/event-utils/EventHashes.sol @@ -15,17 +15,18 @@ function getTopicsHash( topicsHash = keccak256(abi.encode(topic0, topic1, topic2, topic3)); } -function getTopicsHash(bytes32 topic0, bytes32 topic1, bytes32 topic2) - pure - returns (bytes32 topicsHash) -{ +function getTopicsHash( + bytes32 topic0, + bytes32 topic1, + bytes32 topic2 +) pure returns (bytes32 topicsHash) { topicsHash = keccak256(abi.encode(topic0, topic1, topic2)); } -function getTopicsHash(bytes32 topic0, bytes32 topic1) - pure - returns (bytes32 topicsHash) -{ +function getTopicsHash( + bytes32 topic0, + bytes32 topic1 +) pure returns (bytes32 topicsHash) { topicsHash = keccak256(abi.encode(topic0, topic1)); } @@ -37,10 +38,11 @@ function getTopicsHash() pure returns (bytes32 topicsHash) { topicsHash = keccak256(""); } -function getEventHash(address emitter, bytes32 topicsHash, bytes32 dataHash) - pure - returns (bytes32 eventHash) -{ +function getEventHash( + address emitter, + bytes32 topicsHash, + bytes32 dataHash +) pure returns (bytes32 eventHash) { return keccak256(abi.encode(emitter, topicsHash, dataHash)); } @@ -86,10 +88,10 @@ function getEventHashWithTopics( return getEventHash(emitter, topicsHash, dataHash); } -function getEventHashWithTopics(address emitter, bytes32 dataHash) - pure - returns (bytes32 eventHash) -{ +function getEventHashWithTopics( + address emitter, + bytes32 dataHash +) pure returns (bytes32 eventHash) { bytes32 topicsHash = getTopicsHash(); return getEventHash(emitter, topicsHash, dataHash); } diff --git a/test/foundry/new/helpers/event-utils/EventSerializer.sol b/test/foundry/new/helpers/event-utils/EventSerializer.sol index 6bf13dd..e09e962 100644 --- a/test/foundry/new/helpers/event-utils/EventSerializer.sol +++ b/test/foundry/new/helpers/event-utils/EventSerializer.sol @@ -160,8 +160,11 @@ library EventSerializer { serializeAddress(obj, "token", value.token); serializeAddress(obj, "from", value.from); serializeAddress(obj, "to", value.to); - string memory finalJson = - serializeUint256(obj, "identifier", value.identifier); + string memory finalJson = serializeUint256( + obj, + "identifier", + value.identifier + ); // serializeUint256(obj, "identifier", value.identifier); // serializeBytes32(obj, "topicHash", value.topicHash); // serializeBytes32(obj, "dataHash", value.dataHash); diff --git a/test/foundry/new/helpers/event-utils/ExecutionsFlattener.sol b/test/foundry/new/helpers/event-utils/ExecutionsFlattener.sol index 8e2a8e8..d79cd6d 100644 --- a/test/foundry/new/helpers/event-utils/ExecutionsFlattener.sol +++ b/test/foundry/new/helpers/event-utils/ExecutionsFlattener.sol @@ -17,19 +17,19 @@ library ExecutionsFlattener { context.expectations.allExpectedExecutions = ArrayHelpers .flattenThree .asExecutionsFlatten()( - context.expectations.expectedImplicitPreExecutions, - ArrayHelpers.mapWithArg.asMap()( - context.expectations.expectedExplicitExecutions, - fixExplicitExecution, - context - ), - context.expectations.expectedImplicitPostExecutions - ); + context.expectations.expectedImplicitPreExecutions, + ArrayHelpers.mapWithArg.asMap()( + context.expectations.expectedExplicitExecutions, + fixExplicitExecution, + context + ), + context.expectations.expectedImplicitPostExecutions + ); require( - context.expectations.allExpectedExecutions.length - == context.expectations.expectedImplicitPreExecutions.length - + context.expectations.expectedExplicitExecutions.length - + context.expectations.expectedImplicitPostExecutions.length, + context.expectations.allExpectedExecutions.length == + context.expectations.expectedImplicitPreExecutions.length + + context.expectations.expectedExplicitExecutions.length + + context.expectations.expectedImplicitPostExecutions.length, "LENGTHS OF EXECUTIONS DO NOT MATCH" ); uint256 e; @@ -38,13 +38,15 @@ library ExecutionsFlattener { i < context.expectations.expectedImplicitPreExecutions.length; i++ ) { - Execution memory execution1 = - context.expectations.expectedImplicitPreExecutions[i]; - Execution memory execution2 = - context.expectations.allExpectedExecutions[e++]; + Execution memory execution1 = context + .expectations + .expectedImplicitPreExecutions[i]; + Execution memory execution2 = context + .expectations + .allExpectedExecutions[e++]; require( - keccak256(abi.encode(execution1)) - == keccak256(abi.encode(execution2)), + keccak256(abi.encode(execution1)) == + keccak256(abi.encode(execution2)), "IMPLICIT PRE EXECUTIONS DO NOT MATCH" ); } @@ -53,25 +55,27 @@ library ExecutionsFlattener { i < context.expectations.expectedExplicitExecutions.length; i++ ) { - Execution memory execution1 = - context.expectations.expectedExplicitExecutions[i]; - Execution memory execution2 = - context.expectations.allExpectedExecutions[e++]; + Execution memory execution1 = context + .expectations + .expectedExplicitExecutions[i]; + Execution memory execution2 = context + .expectations + .allExpectedExecutions[e++]; if (execution1.item.itemType == ItemType.NATIVE) { require( execution2.offerer == address(context.seaport), "SEAPORT NOT SET ON EXECUTION" ); require( - execution1.conduitKey == execution2.conduitKey - && keccak256(abi.encode(execution1.item)) - == keccak256(abi.encode(execution2.item)), + execution1.conduitKey == execution2.conduitKey && + keccak256(abi.encode(execution1.item)) == + keccak256(abi.encode(execution2.item)), "EXPLICIT EXECUTIONS DO NOT MATCH" ); } else { require( - keccak256(abi.encode(execution1)) - == keccak256(abi.encode(execution2)), + keccak256(abi.encode(execution1)) == + keccak256(abi.encode(execution2)), "EXPLICIT EXECUTIONS DO NOT MATCH" ); } @@ -81,13 +85,15 @@ library ExecutionsFlattener { i < context.expectations.expectedImplicitPostExecutions.length; i++ ) { - Execution memory execution1 = - context.expectations.expectedImplicitPostExecutions[i]; - Execution memory execution2 = - context.expectations.allExpectedExecutions[e++]; + Execution memory execution1 = context + .expectations + .expectedImplicitPostExecutions[i]; + Execution memory execution2 = context + .expectations + .allExpectedExecutions[e++]; require( - keccak256(abi.encode(execution1)) - == keccak256(abi.encode(execution2)), + keccak256(abi.encode(execution1)) == + keccak256(abi.encode(execution2)), "IMPLICIT PRE EXECUTIONS DO NOT MATCH" ); } @@ -112,8 +118,10 @@ library ExecutionsFlattener { internal pure returns ( - function(MemoryPointer, MemoryPointer) internal pure returns (MemoryPointer) - fnOut + function(MemoryPointer, MemoryPointer) + internal + pure + returns (MemoryPointer) fnOut ) { assembly { @@ -134,8 +142,14 @@ library ExecutionsFlattener { internal pure returns ( - function( Execution[] memory, function(Execution memory, FuzzTestContext memory) internal pure returns (Execution memory), FuzzTestContext memory) internal pure returns (Execution[] memory) - fnOut + function( + Execution[] memory, + function(Execution memory, FuzzTestContext memory) + internal + pure + returns (Execution memory), + FuzzTestContext memory + ) internal pure returns (Execution[] memory) fnOut ) { assembly { @@ -152,8 +166,10 @@ library ExecutionsFlattener { internal pure returns ( - function(Execution[] memory, Execution[] memory) internal pure returns (Execution[] memory) - fnOut + function(Execution[] memory, Execution[] memory) + internal + pure + returns (Execution[] memory) fnOut ) { assembly { @@ -170,8 +186,10 @@ library ExecutionsFlattener { internal pure returns ( - function(Execution[] memory, Execution[] memory, Execution[] memory) internal pure returns (Execution[] memory) - fnOut + function(Execution[] memory, Execution[] memory, Execution[] memory) + internal + pure + returns (Execution[] memory) fnOut ) { assembly { diff --git a/test/foundry/new/helpers/event-utils/ExpectedEventsUtil.sol b/test/foundry/new/helpers/event-utils/ExpectedEventsUtil.sol index f730013..d550433 100644 --- a/test/foundry/new/helpers/event-utils/ExpectedEventsUtil.sol +++ b/test/foundry/new/helpers/event-utils/ExpectedEventsUtil.sol @@ -28,10 +28,8 @@ import { OrdersMatchedEventsLib } from "./OrdersMatchedEventsLib.sol"; import { dumpTransfers } from "../DebugUtil.sol"; -bytes32 constant Topic0_ERC20_ERC721_Transfer = - 0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef; -bytes32 constant Topic0_ERC1155_TransferSingle = - 0xc3d58168c5ae7397731d063d5bbf3d657854427343f4c083240f7aacaa2d0f62; +bytes32 constant Topic0_ERC20_ERC721_Transfer = 0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef; +bytes32 constant Topic0_ERC1155_TransferSingle = 0xc3d58168c5ae7397731d063d5bbf3d657854427343f4c083240f7aacaa2d0f62; struct ReduceInput { Vm.Log[] logsArray; @@ -104,27 +102,28 @@ library ExpectedEventsUtil { * * @param context The test context */ - function setExpectedTransferEventHashes(FuzzTestContext memory context) - internal - { - Execution[] memory executions = - context.expectations.allExpectedExecutions; + function setExpectedTransferEventHashes( + FuzzTestContext memory context + ) internal { + Execution[] memory executions = context + .expectations + .allExpectedExecutions; require( - executions.length - == context.expectations.expectedImplicitPreExecutions.length - + context.expectations.expectedExplicitExecutions.length - + context.expectations.expectedImplicitPostExecutions.length, + executions.length == + context.expectations.expectedImplicitPreExecutions.length + + context.expectations.expectedExplicitExecutions.length + + context.expectations.expectedImplicitPostExecutions.length, "ExpectedEventsUtil: executions length mismatch" ); - Execution[] memory filteredExecutions = new Execution[](executions.length); + Execution[] memory filteredExecutions = new Execution[]( + executions.length + ); uint256 filteredExecutionIndex = 0; for (uint256 i = 0; i < executions.length; ++i) { - if ( - executions[i].item.amount > 0 - ) { + if (executions[i].item.amount > 0) { filteredExecutions[filteredExecutionIndex++] = executions[i]; } } @@ -136,8 +135,10 @@ library ExpectedEventsUtil { context.expectations.expectedTransferEventHashes = ArrayHelpers .filterMapWithArg .asExecutionsFilterMap()( - filteredExecutions, TransferEventsLib.getTransferEventHash, context - ); + filteredExecutions, + TransferEventsLib.getTransferEventHash, + context + ); vm.serializeBytes32( "root", @@ -146,19 +147,22 @@ library ExpectedEventsUtil { ); } - function setExpectedSeaportEventHashes(FuzzTestContext memory context) - internal - { - bool isMatch = context.action() - == context.seaport.matchAdvancedOrders.selector - || context.action() == context.seaport.matchOrders.selector; + function setExpectedSeaportEventHashes( + FuzzTestContext memory context + ) internal { + bool isMatch = context.action() == + context.seaport.matchAdvancedOrders.selector || + context.action() == context.seaport.matchOrders.selector; uint256 totalExpectedEventHashes = isMatch ? 1 : 0; - for (uint256 i = 0; i < context.executionState.orderDetails.length; ++i) - { + for ( + uint256 i = 0; + i < context.executionState.orderDetails.length; + ++i + ) { if ( - context.executionState.orderDetails[i].unavailableReason - == UnavailableReason.AVAILABLE + context.executionState.orderDetails[i].unavailableReason == + UnavailableReason.AVAILABLE ) { ++totalExpectedEventHashes; } @@ -171,17 +175,19 @@ library ExpectedEventsUtil { totalExpectedEventHashes = 0; for (uint256 i = 0; i < context.executionState.orders.length; ++i) { if ( - context.executionState.orderDetails[i].unavailableReason - == UnavailableReason.AVAILABLE + context.executionState.orderDetails[i].unavailableReason == + UnavailableReason.AVAILABLE ) { - context.expectations.expectedSeaportEventHashes[totalExpectedEventHashes++] - = context.getOrderFulfilledEventHash(i); + context.expectations.expectedSeaportEventHashes[ + totalExpectedEventHashes++ + ] = context.getOrderFulfilledEventHash(i); } } if (isMatch) { - context.expectations.expectedSeaportEventHashes[totalExpectedEventHashes] - = context.getOrdersMatchedEventHash(); + context.expectations.expectedSeaportEventHashes[ + totalExpectedEventHashes + ] = context.getOrdersMatchedEventHash(); } vm.serializeBytes32( @@ -204,19 +210,20 @@ library ExpectedEventsUtil { * * @param context The test context */ - function checkExpectedTransferEvents(FuzzTestContext memory context) - internal - { + function checkExpectedTransferEvents( + FuzzTestContext memory context + ) internal { Vm.Log[] memory logs = vm.getRecordedLogs(); bytes memory callData = abi.encodeCall(FuzzEngine.setLogs, (logs)); - (bool ok,) = address(this).call(callData); + (bool ok, ) = address(this).call(callData); if (!ok) { revert("ExpectedEventsUtil: log registration failed"); } // MemoryPointer expectedEvents = toMemoryPointer(eventHashes); - bytes32[] memory expectedTransferEventHashes = - context.expectations.expectedTransferEventHashes; + bytes32[] memory expectedTransferEventHashes = context + .expectations + .expectedTransferEventHashes; // For each expected event, verify that it matches the next log // in `logs` that has a topic0 matching one of the watched events. @@ -240,9 +247,9 @@ library ExpectedEventsUtil { } } - function checkExpectedSeaportEvents(FuzzTestContext memory context) - internal - { + function checkExpectedSeaportEvents( + FuzzTestContext memory context + ) internal { // TODO: set these upstream (this expects checkExpectedTransferEvents to run first) bytes memory callData = abi.encodeCall(FuzzEngine.getLogs, ()); (, bytes memory returnData) = address(this).call(callData); @@ -260,8 +267,9 @@ library ExpectedEventsUtil { } // MemoryPointer expectedEvents = toMemoryPointer(eventHashes); - bytes32[] memory expectedSeaportEventHashes = - context.expectations.expectedSeaportEventHashes; + bytes32[] memory expectedSeaportEventHashes = context + .expectations + .expectedSeaportEventHashes; // For each expected event, verify that it matches the next log // in `logs` that has a topic0 matching one of the watched events. @@ -292,24 +300,22 @@ library ExpectedEventsUtil { * * @return True if the log is a watched event, false otherwise */ - function isWatchedTransferEvent(Vm.Log memory log) - internal - pure - returns (bool) - { + function isWatchedTransferEvent( + Vm.Log memory log + ) internal pure returns (bool) { bytes32 topic0 = log.getTopic0(); - return topic0 == Topic0_ERC20_ERC721_Transfer - || topic0 == Topic0_ERC1155_TransferSingle; + return + topic0 == Topic0_ERC20_ERC721_Transfer || + topic0 == Topic0_ERC1155_TransferSingle; } - function isWatchedSeaportEvent(Vm.Log memory log) - internal - pure - returns (bool) - { + function isWatchedSeaportEvent( + Vm.Log memory log + ) internal pure returns (bool) { bytes32 topic0 = log.getTopic0(); - return topic0 == OrderFulfilled.selector - || topic0 == OrdersMatched.selector; + return + topic0 == OrderFulfilled.selector || + topic0 == OrdersMatched.selector; } /** @@ -330,14 +336,18 @@ library ExpectedEventsUtil { int256 nextWatchedEventIndex = ArrayHelpers .findIndexFrom .asLogsFindIndex()( - input.logsArray, isWatchedTransferEvent, lastLogIndex - ); + input.logsArray, + isWatchedTransferEvent, + lastLogIndex + ); // Dump the events data and revert if there are no remaining transfer events if (nextWatchedEventIndex == -1) { vm.serializeUint("root", "failingIndex", lastLogIndex - 1); vm.serializeBytes32( - "root", "expectedEventHash", bytes32(expectedEventHash) + "root", + "expectedEventHash", + bytes32(expectedEventHash) ); dumpTransfers(input.context); revert( @@ -379,13 +389,19 @@ library ExpectedEventsUtil { // Get the index of the next watched event in the logs array int256 nextWatchedEventIndex = ArrayHelpers .findIndexFrom - .asLogsFindIndex()(input.logsArray, isWatchedSeaportEvent, lastLogIndex); + .asLogsFindIndex()( + input.logsArray, + isWatchedSeaportEvent, + lastLogIndex + ); // Dump the events data and revert if there are no remaining transfer events if (nextWatchedEventIndex == -1) { vm.serializeUint("root", "failingIndex", lastLogIndex - 1); vm.serializeBytes32( - "root", "expectedEventHash", bytes32(expectedEventHash) + "root", + "expectedEventHash", + bytes32(expectedEventHash) ); revert( "ExpectedEvents: seaport event not found - info written to fuzz_debug.json" @@ -424,8 +440,11 @@ library Casts { internal pure returns ( - function( Vm.Log[] memory, function(Vm.Log memory) internal pure returns (bool), uint256) internal pure returns (int256) - fnOut + function( + Vm.Log[] memory, + function(Vm.Log memory) internal pure returns (bool), + uint256 + ) internal pure returns (int256) fnOut ) { assembly { @@ -446,8 +465,14 @@ library Casts { internal pure returns ( - function(bytes32[] memory, function( uint256, uint256, ReduceInput memory) internal returns (uint256), uint256, ReduceInput memory) internal returns (uint256) - fnOut + function( + bytes32[] memory, + function(uint256, uint256, ReduceInput memory) + internal + returns (uint256), + uint256, + ReduceInput memory + ) internal returns (uint256) fnOut ) { assembly { @@ -468,8 +493,13 @@ library Casts { internal pure returns ( - function(Execution[] memory, function(Execution memory, FuzzTestContext memory) internal returns (bytes32), FuzzTestContext memory) internal pure returns (bytes32[] memory) - fnOut + function( + Execution[] memory, + function(Execution memory, FuzzTestContext memory) + internal + returns (bytes32), + FuzzTestContext memory + ) internal pure returns (bytes32[] memory) fnOut ) { assembly { @@ -477,41 +507,33 @@ library Casts { } } - function toMemoryPointer(Execution[] memory arr) - internal - pure - returns (MemoryPointer ptr) - { + function toMemoryPointer( + Execution[] memory arr + ) internal pure returns (MemoryPointer ptr) { assembly { ptr := arr } } - function toMemoryPointer(FuzzTestContext memory context) - internal - pure - returns (MemoryPointer ptr) - { + function toMemoryPointer( + FuzzTestContext memory context + ) internal pure returns (MemoryPointer ptr) { assembly { ptr := context } } - function toMemoryPointer(Vm.Log[] memory arr) - internal - pure - returns (MemoryPointer ptr) - { + function toMemoryPointer( + Vm.Log[] memory arr + ) internal pure returns (MemoryPointer ptr) { assembly { ptr := arr } } - function toMemoryPointer(bytes32[] memory arr) - internal - pure - returns (MemoryPointer ptr) - { + function toMemoryPointer( + bytes32[] memory arr + ) internal pure returns (MemoryPointer ptr) { assembly { ptr := arr } diff --git a/test/foundry/new/helpers/event-utils/ForgeEventsLib.sol b/test/foundry/new/helpers/event-utils/ForgeEventsLib.sol index 28f53d3..5b3d94b 100644 --- a/test/foundry/new/helpers/event-utils/ForgeEventsLib.sol +++ b/test/foundry/new/helpers/event-utils/ForgeEventsLib.sol @@ -17,10 +17,8 @@ import { vm } from "./EventSerializer.sol"; -bytes32 constant Topic0_ERC20_ERC721_Transfer = - 0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef; -bytes32 constant Topic0_ERC1155_TransferSingle = - 0xc3d58168c5ae7397731d063d5bbf3d657854427343f4c083240f7aacaa2d0f62; +bytes32 constant Topic0_ERC20_ERC721_Transfer = 0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef; +bytes32 constant Topic0_ERC1155_TransferSingle = 0xc3d58168c5ae7397731d063d5bbf3d657854427343f4c083240f7aacaa2d0f62; library ForgeEventsLib { using { ifTrue } for bytes32; @@ -29,11 +27,9 @@ library ForgeEventsLib { /** * @dev Returns the hash of the event emitted by Forge. */ - function getForgeEventHash(Vm.Log memory log) - internal - pure - returns (bytes32) - { + function getForgeEventHash( + Vm.Log memory log + ) internal pure returns (bytes32) { bytes32 topicsHash = getForgeTopicsHash(log); bytes32 dataHash = getDataHash(log); return getEventHash(log.emitter, topicsHash, dataHash); @@ -42,11 +38,9 @@ library ForgeEventsLib { /** * @dev Returns the memory pointer for a given log. */ - function toMemoryPointer(Vm.Log memory log) - internal - pure - returns (MemoryPointer ptr) - { + function toMemoryPointer( + Vm.Log memory log + ) internal pure returns (MemoryPointer ptr) { assembly { ptr := log } @@ -76,16 +70,34 @@ library ForgeEventsLib { function reEmit(Vm.Log memory log) internal { MemoryPointer topics = toMemoryPointer(log).pptr(); uint256 topicsCount = topics.readUint256(); - (bytes32 topic0,, bytes32 topic1,, bytes32 topic2,, bytes32 topic3,) = - getTopics(log); + ( + bytes32 topic0, + , + bytes32 topic1, + , + bytes32 topic2, + , + bytes32 topic3, + + ) = getTopics(log); MemoryPointer data = toMemoryPointer(log).pptrOffset(32); assembly { switch topicsCount - case 4 { log4(data, mload(data), topic0, topic1, topic2, topic3) } - case 3 { log3(data, mload(data), topic0, topic1, topic2) } - case 2 { log2(data, mload(data), topic0, topic1) } - case 1 { log1(data, mload(data), topic0) } - default { log0(data, mload(data)) } + case 4 { + log4(data, mload(data), topic0, topic1, topic2, topic3) + } + case 3 { + log3(data, mload(data), topic0, topic1, topic2) + } + case 2 { + log2(data, mload(data), topic0, topic1) + } + case 1 { + log1(data, mload(data), topic0) + } + default { + log0(data, mload(data)) + } } } @@ -109,25 +121,26 @@ library ForgeEventsLib { ) = getTopics(log); if (topic0 == Topic0_ERC20_ERC721_Transfer) { if (hasTopic3) { - return ERC721TransferEvent( - "ERC721", - log.emitter, - address(uint160(uint256(topic1))), - address(uint160(uint256(topic2))), - uint256(topic3) - ) - // getForgeTopicsHash(log), - // getDataHash(log), - // getForgeEventHash(log) - .serializeERC721TransferEvent(objectKey, valueKey); + return + ERC721TransferEvent( + "ERC721", + log.emitter, + address(uint160(uint256(topic1))), + address(uint160(uint256(topic2))), + uint256(topic3) + ).serializeERC721TransferEvent(objectKey, valueKey); + // getForgeTopicsHash(log), + // getDataHash(log), + // getForgeEventHash(log) } else { ERC20TransferEvent memory eventData; eventData.kind = "ERC20"; eventData.token = log.emitter; eventData.from = address(uint160(uint256(topic1))); eventData.to = address(uint160(uint256(topic2))); - eventData.amount = - log.data.length >= 32 ? abi.decode(log.data, (uint256)) : 0; + eventData.amount = log.data.length >= 32 + ? abi.decode(log.data, (uint256)) + : 0; if (log.data.length == 0) { string memory obj = string.concat(objectKey, valueKey); string memory finalJson = vm.serializeString( @@ -147,8 +160,10 @@ library ForgeEventsLib { eventData.operator = address(uint160(uint256(topic1))); eventData.from = address(uint160(uint256(topic2))); eventData.to = address(uint160(uint256(topic3))); - (eventData.identifier, eventData.amount) = - abi.decode(log.data, (uint256, uint256)); + (eventData.identifier, eventData.amount) = abi.decode( + log.data, + (uint256, uint256) + ); // eventData.topicHash = getForgeTopicsHash(log); // eventData.dataHash = getDataHash(log); // eventData.eventHash = getForgeEventHash(log); @@ -172,7 +187,9 @@ library ForgeEventsLib { string memory out; for (uint256 i; i < length; i++) { string memory _log = serializeTransferLog( - value[i], obj, string.concat("event", vm.toString(i)) + value[i], + obj, + string.concat("event", vm.toString(i)) ); uint256 len; assembly { @@ -188,7 +205,9 @@ library ForgeEventsLib { /** * @dev Gets the topics for a log. */ - function getTopics(Vm.Log memory log) + function getTopics( + Vm.Log memory log + ) internal pure returns ( @@ -220,11 +239,9 @@ library ForgeEventsLib { /** * @dev Gets the hash for a log's topics. */ - function getForgeTopicsHash(Vm.Log memory log) - internal - pure - returns (bytes32 topicHash) - { + function getForgeTopicsHash( + Vm.Log memory log + ) internal pure returns (bytes32 topicHash) { // ( // bytes32 topic0, // bool hasTopic0, diff --git a/test/foundry/new/helpers/event-utils/OrderFulfilledEventsLib.sol b/test/foundry/new/helpers/event-utils/OrderFulfilledEventsLib.sol index d5174ea..932a5e7 100644 --- a/test/foundry/new/helpers/event-utils/OrderFulfilledEventsLib.sol +++ b/test/foundry/new/helpers/event-utils/OrderFulfilledEventsLib.sol @@ -1,7 +1,9 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.13; -import { MemoryPointer } from "../../../../../src/main/helpers/ArrayHelpers.sol"; +import { + MemoryPointer +} from "../../../../../src/main/helpers/ArrayHelpers.sol"; import { AdvancedOrder, @@ -22,7 +24,11 @@ import { AdvancedOrderLib } from "seaport-sol/src/lib/AdvancedOrderLib.sol"; import { OrderParametersLib } from "seaport-sol/src/lib/OrderParametersLib.sol"; -import { OrderFulfilledEvent, EventSerializer, vm } from "./EventSerializer.sol"; +import { + OrderFulfilledEvent, + EventSerializer, + vm +} from "./EventSerializer.sol"; library OrderFulfilledEventsLib { using { toBytes32 } for address; @@ -72,28 +78,32 @@ library OrderFulfilledEventsLib { FuzzTestContext memory context, uint256 orderIndex ) internal pure returns (bytes32 eventHash) { - OrderParameters memory orderParams = - context.executionState.orders[orderIndex].parameters; - - OrderDetails memory details = - (context.executionState.orderDetails[orderIndex]); - - return getEventHashWithTopics( - address(context.seaport), // emitter - OrderFulfilled.selector, // topic0 - orderParams.offerer.toBytes32(), // topic1 - offerer - orderParams.zone.toBytes32(), // topic2 - zone - keccak256( - abi.encode( - details.orderHash, - context.executionState.recipient == address(0) - ? context.executionState.caller - : context.executionState.recipient, - details.offer, - details.consideration - ) - ) // dataHash + OrderParameters memory orderParams = context + .executionState + .orders[orderIndex] + .parameters; + + OrderDetails memory details = ( + context.executionState.orderDetails[orderIndex] ); + + return + getEventHashWithTopics( + address(context.seaport), // emitter + OrderFulfilled.selector, // topic0 + orderParams.offerer.toBytes32(), // topic1 - offerer + orderParams.zone.toBytes32(), // topic2 - zone + keccak256( + abi.encode( + details.orderHash, + context.executionState.recipient == address(0) + ? context.executionState.caller + : context.executionState.recipient, + details.offer, + details.consideration + ) + ) // dataHash + ); } } diff --git a/test/foundry/new/helpers/event-utils/OrdersMatchedEventsLib.sol b/test/foundry/new/helpers/event-utils/OrdersMatchedEventsLib.sol index 3dabf3b..c575063 100644 --- a/test/foundry/new/helpers/event-utils/OrdersMatchedEventsLib.sol +++ b/test/foundry/new/helpers/event-utils/OrdersMatchedEventsLib.sol @@ -10,17 +10,18 @@ import { UnavailableReason } from "seaport-sol/src/SpaceEnums.sol"; library OrdersMatchedEventsLib { event OrdersMatched(bytes32[] orderHashes); - function getOrdersMatchedEventHash(FuzzTestContext memory context) - internal - pure - returns (bytes32 eventHash) - { + function getOrdersMatchedEventHash( + FuzzTestContext memory context + ) internal pure returns (bytes32 eventHash) { uint256 totalAvailableOrders = 0; - for (uint256 i = 0; i < context.executionState.orderDetails.length; ++i) - { + for ( + uint256 i = 0; + i < context.executionState.orderDetails.length; + ++i + ) { if ( - context.executionState.orderDetails[i].unavailableReason - == UnavailableReason.AVAILABLE + context.executionState.orderDetails[i].unavailableReason == + UnavailableReason.AVAILABLE ) { ++totalAvailableOrders; } @@ -29,21 +30,27 @@ library OrdersMatchedEventsLib { bytes32[] memory orderHashes = new bytes32[](totalAvailableOrders); totalAvailableOrders = 0; - for (uint256 i = 0; i < context.executionState.orderDetails.length; ++i) - { + for ( + uint256 i = 0; + i < context.executionState.orderDetails.length; + ++i + ) { if ( - context.executionState.orderDetails[i].unavailableReason - == UnavailableReason.AVAILABLE + context.executionState.orderDetails[i].unavailableReason == + UnavailableReason.AVAILABLE ) { - orderHashes[totalAvailableOrders++] = - context.executionState.orderDetails[i].orderHash; + orderHashes[totalAvailableOrders++] = context + .executionState + .orderDetails[i] + .orderHash; } } - return getEventHashWithTopics( - address(context.seaport), // emitter - OrdersMatched.selector, // topic0 - keccak256(abi.encode(orderHashes)) // dataHash - ); + return + getEventHashWithTopics( + address(context.seaport), // emitter + OrdersMatched.selector, // topic0 + keccak256(abi.encode(orderHashes)) // dataHash + ); } } diff --git a/test/foundry/new/helpers/event-utils/TransferEventsLib.sol b/test/foundry/new/helpers/event-utils/TransferEventsLib.sol index fafcc02..54a2624 100644 --- a/test/foundry/new/helpers/event-utils/TransferEventsLib.sol +++ b/test/foundry/new/helpers/event-utils/TransferEventsLib.sol @@ -1,7 +1,9 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.13; -import { MemoryPointer } from "../../../../../src/main/helpers/ArrayHelpers.sol"; +import { + MemoryPointer +} from "../../../../../src/main/helpers/ArrayHelpers.sol"; import { Execution, @@ -30,7 +32,9 @@ library TransferEventsLib { // for ERC721, the third parameter (identifier) is indexed. // The topic0 does not change based on which parameters are indexed. event Transfer( - address indexed from, address indexed to, uint256 valueOrIdentifier + address indexed from, + address indexed to, + uint256 valueOrIdentifier ); event TransferSingle( @@ -75,22 +79,22 @@ library TransferEventsLib { if (itemType == ItemType.ERC721) { ReceivedItem memory item = execution.item; - return ERC721TransferEvent( - "ERC721", - item.token, - execution.offerer, - address(item.recipient), - item.identifier - ) - // getTopicsHash( - // Transfer.selector, // topic0 - // execution.offerer.toBytes32(), // topic1 - // toBytes32(item.recipient), // topic2 - // bytes32(item.identifier) // topic3 - // ), - // keccak256(""), - // getERC721TransferEventHash(execution) - .serializeERC721TransferEvent(objectKey, valueKey); + return + ERC721TransferEvent( + "ERC721", + item.token, + execution.offerer, + address(item.recipient), + item.identifier + ).serializeERC721TransferEvent(objectKey, valueKey); + // getTopicsHash( + // Transfer.selector, // topic0 + // execution.offerer.toBytes32(), // topic1 + // toBytes32(item.recipient), // topic2 + // bytes32(item.identifier) // topic3 + // ), + // keccak256(""), + // getERC721TransferEventHash(execution) } if (itemType == ItemType.ERC1155) { ReceivedItem memory item = execution.item; @@ -134,7 +138,10 @@ library TransferEventsLib { string memory out; for (uint256 i; i < length; i++) { string memory _log = serializeTransferLog( - value[i], obj, string.concat("event", vm.toString(i)), context + value[i], + obj, + string.concat("event", vm.toString(i)), + context ); uint256 len; assembly { @@ -169,35 +176,33 @@ library TransferEventsLib { } } - function getERC20TransferEventHash(Execution memory execution) - internal - pure - returns (bytes32) - { + function getERC20TransferEventHash( + Execution memory execution + ) internal pure returns (bytes32) { ReceivedItem memory item = execution.item; - return getEventHashWithTopics( - item.token, // emitter - Transfer.selector, // topic0 - execution.offerer.toBytes32(), // topic1 - toBytes32(item.recipient), // topic2 - keccak256(abi.encode(item.amount)) // dataHash - ); + return + getEventHashWithTopics( + item.token, // emitter + Transfer.selector, // topic0 + execution.offerer.toBytes32(), // topic1 + toBytes32(item.recipient), // topic2 + keccak256(abi.encode(item.amount)) // dataHash + ); } - function getERC721TransferEventHash(Execution memory execution) - internal - pure - returns (bytes32) - { + function getERC721TransferEventHash( + Execution memory execution + ) internal pure returns (bytes32) { ReceivedItem memory item = execution.item; - return getEventHashWithTopics( - item.token, // emitter - Transfer.selector, // topic0 - execution.offerer.toBytes32(), // topic1 - toBytes32(item.recipient), // topic2 - bytes32(item.identifier), // topic3 - keccak256("") // dataHash - ); + return + getEventHashWithTopics( + item.token, // emitter + Transfer.selector, // topic0 + execution.offerer.toBytes32(), // topic1 + toBytes32(item.recipient), // topic2 + bytes32(item.identifier), // topic3 + keccak256("") // dataHash + ); } function getERC1155TransferEventHash( @@ -205,24 +210,25 @@ library TransferEventsLib { FuzzTestContext memory context ) internal view returns (bytes32) { ReceivedItem memory item = execution.item; - return getEventHashWithTopics( - item.token, // emitter - TransferSingle.selector, // topic0 - _getConduit(execution.conduitKey, context).toBytes32(), // topic1 = operator - execution.offerer.toBytes32(), // topic2 = from - toBytes32(item.recipient), // topic3 = to - keccak256(abi.encode(item.identifier, item.amount)) // dataHash - ); + return + getEventHashWithTopics( + item.token, // emitter + TransferSingle.selector, // topic0 + _getConduit(execution.conduitKey, context).toBytes32(), // topic1 = operator + execution.offerer.toBytes32(), // topic2 = from + toBytes32(item.recipient), // topic3 = to + keccak256(abi.encode(item.identifier, item.amount)) // dataHash + ); } - function _getConduit(bytes32 conduitKey, FuzzTestContext memory context) - internal - view - returns (address) - { + function _getConduit( + bytes32 conduitKey, + FuzzTestContext memory context + ) internal view returns (address) { if (conduitKey == bytes32(0)) return address(context.seaport); - (address conduit, bool exists) = - context.conduitController.getConduit(conduitKey); + (address conduit, bool exists) = context.conduitController.getConduit( + conduitKey + ); if (exists) return conduit; revert("TransferEventsLib: bad conduit key"); } @@ -254,8 +260,14 @@ library TransferEventsLibCasts { internal pure returns ( - function(Execution[] memory, function(Execution memory, FuzzTestContext memory) internal view returns (bytes32), FuzzTestContext memory) internal pure returns (bytes32[] memory) - fnOut + function( + Execution[] memory, + function(Execution memory, FuzzTestContext memory) + internal + view + returns (bytes32), + FuzzTestContext memory + ) internal pure returns (bytes32[] memory) fnOut ) { assembly { diff --git a/test/foundry/new/helpers/sol/FulfillAvailableHelper.t.sol b/test/foundry/new/helpers/sol/FulfillAvailableHelper.t.sol index a97b1ac..309fbb9 100644 --- a/test/foundry/new/helpers/sol/FulfillAvailableHelper.t.sol +++ b/test/foundry/new/helpers/sol/FulfillAvailableHelper.t.sol @@ -19,8 +19,9 @@ import { import { ItemType } from "seaport-sol/src/SeaportEnums.sol"; -import { FulfillAvailableHelper } from - "seaport-sol/src/fulfillments/available/FulfillAvailableHelper.sol"; +import { + FulfillAvailableHelper +} from "seaport-sol/src/fulfillments/available/FulfillAvailableHelper.sol"; contract FulfillAvailableHelperTest is Test { using ConsiderationItemLib for ConsiderationItem; @@ -34,33 +35,42 @@ contract FulfillAvailableHelperTest is Test { } function testNaive() public { - OrderParameters memory orderParameters = OrderParametersLib.empty() + OrderParameters memory orderParameters = OrderParametersLib + .empty() .withOffer( - SeaportArrays.OfferItems( - OfferItemLib.empty().withItemType(ItemType.ERC721).withToken( - address(1234) - ), - OfferItemLib.empty().withItemType(ItemType.ERC20).withToken( - address(5678) + SeaportArrays.OfferItems( + OfferItemLib + .empty() + .withItemType(ItemType.ERC721) + .withToken(address(1234)), + OfferItemLib.empty().withItemType(ItemType.ERC20).withToken( + address(5678) + ) ) ) - ).withConsideration( - SeaportArrays.ConsiderationItems( - ConsiderationItemLib.empty().withItemType(ItemType.ERC721) - .withToken(address(1234)), - ConsiderationItemLib.empty().withItemType(ItemType.ERC20) - .withToken(address(5678)), - ConsiderationItemLib.empty().withItemType(ItemType.ERC1155) - .withToken(address(9101112)) - ) - ); + .withConsideration( + SeaportArrays.ConsiderationItems( + ConsiderationItemLib + .empty() + .withItemType(ItemType.ERC721) + .withToken(address(1234)), + ConsiderationItemLib + .empty() + .withItemType(ItemType.ERC20) + .withToken(address(5678)), + ConsiderationItemLib + .empty() + .withItemType(ItemType.ERC1155) + .withToken(address(9101112)) + ) + ); ( FulfillmentComponent[][] memory offer, FulfillmentComponent[][] memory consideration ) = test.getNaiveFulfillmentComponents( - SeaportArrays.OrderParametersArray(orderParameters) - ); + SeaportArrays.OrderParametersArray(orderParameters) + ); assertEq(offer.length, 2); assertEq(offer[0].length, 1); @@ -80,27 +90,35 @@ contract FulfillAvailableHelperTest is Test { assertEq(consideration[2][0].orderIndex, 0); assertEq(consideration[2][0].itemIndex, 2); - OrderParameters memory parameters2 = OrderParametersLib.empty() + OrderParameters memory parameters2 = OrderParametersLib + .empty() .withOffer( - SeaportArrays.OfferItems( - OfferItemLib.empty().withItemType(ItemType.ERC721).withToken( - address(1235) - ), - OfferItemLib.empty().withItemType(ItemType.ERC20).withToken( - address(5679) - ), - OfferItemLib.empty().withItemType(ItemType.ERC1155).withToken( - address(9101113) + SeaportArrays.OfferItems( + OfferItemLib + .empty() + .withItemType(ItemType.ERC721) + .withToken(address(1235)), + OfferItemLib.empty().withItemType(ItemType.ERC20).withToken( + address(5679) + ), + OfferItemLib + .empty() + .withItemType(ItemType.ERC1155) + .withToken(address(9101113)) ) ) - ).withConsideration( - SeaportArrays.ConsiderationItems( - ConsiderationItemLib.empty().withItemType(ItemType.ERC721) - .withToken(address(1235)), - ConsiderationItemLib.empty().withItemType(ItemType.ERC20) - .withToken(address(5679)) - ) - ); + .withConsideration( + SeaportArrays.ConsiderationItems( + ConsiderationItemLib + .empty() + .withItemType(ItemType.ERC721) + .withToken(address(1235)), + ConsiderationItemLib + .empty() + .withItemType(ItemType.ERC20) + .withToken(address(5679)) + ) + ); (offer, consideration) = test.getNaiveFulfillmentComponents( SeaportArrays.OrderParametersArray(orderParameters, parameters2) @@ -140,35 +158,45 @@ contract FulfillAvailableHelperTest is Test { } function testAggregated_single() public { - OrderParameters memory parameters = OrderParametersLib.empty().withOffer( - SeaportArrays.OfferItems( - OfferItemLib.empty().withItemType(ItemType.ERC20).withToken( - address(1234) - ), - OfferItemLib.empty().withItemType(ItemType.ERC721).withToken( - address(1235) - ), - OfferItemLib.empty().withItemType(ItemType.ERC20).withToken( - address(1234) + OrderParameters memory parameters = OrderParametersLib + .empty() + .withOffer( + SeaportArrays.OfferItems( + OfferItemLib.empty().withItemType(ItemType.ERC20).withToken( + address(1234) + ), + OfferItemLib + .empty() + .withItemType(ItemType.ERC721) + .withToken(address(1235)), + OfferItemLib.empty().withItemType(ItemType.ERC20).withToken( + address(1234) + ) ) ) - ).withConsideration( - SeaportArrays.ConsiderationItems( - ConsiderationItemLib.empty().withItemType(ItemType.ERC721) - .withToken(address(1234)), - ConsiderationItemLib.empty().withItemType(ItemType.ERC1155) - .withToken(address(5678)), - ConsiderationItemLib.empty().withItemType(ItemType.ERC1155) - .withToken(address(5678)) - ) - ); + .withConsideration( + SeaportArrays.ConsiderationItems( + ConsiderationItemLib + .empty() + .withItemType(ItemType.ERC721) + .withToken(address(1234)), + ConsiderationItemLib + .empty() + .withItemType(ItemType.ERC1155) + .withToken(address(5678)), + ConsiderationItemLib + .empty() + .withItemType(ItemType.ERC1155) + .withToken(address(5678)) + ) + ); ( FulfillmentComponent[][] memory offer, FulfillmentComponent[][] memory consideration ) = test.getAggregatedFulfillmentComponents( - SeaportArrays.OrderParametersArray(parameters) - ); + SeaportArrays.OrderParametersArray(parameters) + ); assertEq(offer.length, 2, "offer length incorrect"); assertEq(offer[0].length, 2, "offer index 0 length incorrect"); assertEq( @@ -205,7 +233,9 @@ contract FulfillAvailableHelperTest is Test { assertEq(consideration.length, 2, "consideration length incorrect"); assertEq( - consideration[0].length, 1, "consideration index 0 length incorrect" + consideration[0].length, + 1, + "consideration index 0 length incorrect" ); assertEq( consideration[0][0].orderIndex, @@ -218,7 +248,9 @@ contract FulfillAvailableHelperTest is Test { "consideration index 0 index 0 item index incorrect" ); assertEq( - consideration[1].length, 2, "consideration index 1 length incorrect" + consideration[1].length, + 2, + "consideration index 1 length incorrect" ); assertEq( consideration[1][0].orderIndex, @@ -243,53 +275,70 @@ contract FulfillAvailableHelperTest is Test { } function testAggregated_multi() public { - OrderParameters memory parameters = OrderParametersLib.empty().withOffer( - SeaportArrays.OfferItems( - OfferItemLib.empty().withItemType(ItemType.ERC20).withToken( - address(1234) - ), - OfferItemLib.empty().withItemType(ItemType.ERC721).withToken( - address(1235) - ), - OfferItemLib.empty().withItemType(ItemType.ERC20).withToken( - address(1234) + OrderParameters memory parameters = OrderParametersLib + .empty() + .withOffer( + SeaportArrays.OfferItems( + OfferItemLib.empty().withItemType(ItemType.ERC20).withToken( + address(1234) + ), + OfferItemLib + .empty() + .withItemType(ItemType.ERC721) + .withToken(address(1235)), + OfferItemLib.empty().withItemType(ItemType.ERC20).withToken( + address(1234) + ) ) ) - ).withConsideration( - SeaportArrays.ConsiderationItems( - ConsiderationItemLib.empty().withItemType(ItemType.ERC721) - .withToken(address(1234)), - ConsiderationItemLib.empty().withItemType(ItemType.ERC1155) - .withToken(address(5678)), - ConsiderationItemLib.empty().withItemType(ItemType.ERC1155) - .withToken(address(5678)) - ) - ); - OrderParameters memory parameters2 = OrderParametersLib.empty() + .withConsideration( + SeaportArrays.ConsiderationItems( + ConsiderationItemLib + .empty() + .withItemType(ItemType.ERC721) + .withToken(address(1234)), + ConsiderationItemLib + .empty() + .withItemType(ItemType.ERC1155) + .withToken(address(5678)), + ConsiderationItemLib + .empty() + .withItemType(ItemType.ERC1155) + .withToken(address(5678)) + ) + ); + OrderParameters memory parameters2 = OrderParametersLib + .empty() .withOffer( - SeaportArrays.OfferItems( - OfferItemLib.empty().withItemType(ItemType.ERC20).withToken( - address(1234) - ), - OfferItemLib.empty().withItemType(ItemType.ERC1155).withToken( - address(5678) + SeaportArrays.OfferItems( + OfferItemLib.empty().withItemType(ItemType.ERC20).withToken( + address(1234) + ), + OfferItemLib + .empty() + .withItemType(ItemType.ERC1155) + .withToken(address(5678)) ) ) - ).withConsideration( - SeaportArrays.ConsiderationItems( - ConsiderationItemLib.empty().withItemType(ItemType.ERC1155) - .withToken(address(5678)), - ConsiderationItemLib.empty().withItemType(ItemType.ERC1155) - .withToken(address(5678)) - ) - ); + .withConsideration( + SeaportArrays.ConsiderationItems( + ConsiderationItemLib + .empty() + .withItemType(ItemType.ERC1155) + .withToken(address(5678)), + ConsiderationItemLib + .empty() + .withItemType(ItemType.ERC1155) + .withToken(address(5678)) + ) + ); ( FulfillmentComponent[][] memory offer, FulfillmentComponent[][] memory consideration ) = test.getAggregatedFulfillmentComponents( - SeaportArrays.OrderParametersArray(parameters, parameters2) - ); + SeaportArrays.OrderParametersArray(parameters, parameters2) + ); assertEq(offer.length, 3, "offer length incorrect"); assertEq(offer[0].length, 3, "offer index 0 length incorrect"); @@ -350,7 +399,9 @@ contract FulfillAvailableHelperTest is Test { assertEq(consideration.length, 2, "consideration length incorrect"); assertEq( - consideration[0].length, 1, "consideration index 0 length incorrect" + consideration[0].length, + 1, + "consideration index 0 length incorrect" ); assertEq( consideration[0][0].orderIndex, @@ -364,7 +415,9 @@ contract FulfillAvailableHelperTest is Test { ); assertEq( - consideration[1].length, 4, "consideration index 1 length incorrect" + consideration[1].length, + 4, + "consideration index 1 length incorrect" ); assertEq( consideration[1][0].orderIndex, @@ -409,53 +462,71 @@ contract FulfillAvailableHelperTest is Test { } function testAggregated_multi_conduitKey() public { - OrderParameters memory parameters = OrderParametersLib.empty().withOffer( - SeaportArrays.OfferItems( - OfferItemLib.empty().withItemType(ItemType.ERC20).withToken( - address(1234) - ), - OfferItemLib.empty().withItemType(ItemType.ERC721).withToken( - address(1235) - ), - OfferItemLib.empty().withItemType(ItemType.ERC20).withToken( - address(1234) + OrderParameters memory parameters = OrderParametersLib + .empty() + .withOffer( + SeaportArrays.OfferItems( + OfferItemLib.empty().withItemType(ItemType.ERC20).withToken( + address(1234) + ), + OfferItemLib + .empty() + .withItemType(ItemType.ERC721) + .withToken(address(1235)), + OfferItemLib.empty().withItemType(ItemType.ERC20).withToken( + address(1234) + ) ) ) - ).withConsideration( - SeaportArrays.ConsiderationItems( - ConsiderationItemLib.empty().withItemType(ItemType.ERC721) - .withToken(address(1234)), - ConsiderationItemLib.empty().withItemType(ItemType.ERC1155) - .withToken(address(5678)), - ConsiderationItemLib.empty().withItemType(ItemType.ERC1155) - .withToken(address(5678)) - ) - ); - OrderParameters memory parameters2 = OrderParametersLib.empty() + .withConsideration( + SeaportArrays.ConsiderationItems( + ConsiderationItemLib + .empty() + .withItemType(ItemType.ERC721) + .withToken(address(1234)), + ConsiderationItemLib + .empty() + .withItemType(ItemType.ERC1155) + .withToken(address(5678)), + ConsiderationItemLib + .empty() + .withItemType(ItemType.ERC1155) + .withToken(address(5678)) + ) + ); + OrderParameters memory parameters2 = OrderParametersLib + .empty() .withOffer( - SeaportArrays.OfferItems( - OfferItemLib.empty().withItemType(ItemType.ERC20).withToken( - address(1234) - ), - OfferItemLib.empty().withItemType(ItemType.ERC1155).withToken( - address(5678) + SeaportArrays.OfferItems( + OfferItemLib.empty().withItemType(ItemType.ERC20).withToken( + address(1234) + ), + OfferItemLib + .empty() + .withItemType(ItemType.ERC1155) + .withToken(address(5678)) ) ) - ).withConsideration( - SeaportArrays.ConsiderationItems( - ConsiderationItemLib.empty().withItemType(ItemType.ERC1155) - .withToken(address(5678)), - ConsiderationItemLib.empty().withItemType(ItemType.ERC1155) - .withToken(address(5678)) + .withConsideration( + SeaportArrays.ConsiderationItems( + ConsiderationItemLib + .empty() + .withItemType(ItemType.ERC1155) + .withToken(address(5678)), + ConsiderationItemLib + .empty() + .withItemType(ItemType.ERC1155) + .withToken(address(5678)) + ) ) - ).withConduitKey(bytes32(uint256(1))); + .withConduitKey(bytes32(uint256(1))); ( FulfillmentComponent[][] memory offer, FulfillmentComponent[][] memory consideration ) = test.getAggregatedFulfillmentComponents( - SeaportArrays.OrderParametersArray(parameters, parameters2) - ); + SeaportArrays.OrderParametersArray(parameters, parameters2) + ); assertEq(offer.length, 4, "offer length incorrect"); assertEq(offer[0].length, 2, "offer index 0 length incorrect"); @@ -528,7 +599,9 @@ contract FulfillAvailableHelperTest is Test { assertEq(consideration.length, 2, "consideration length incorrect"); assertEq( - consideration[0].length, 1, "consideration index 0 length incorrect" + consideration[0].length, + 1, + "consideration index 0 length incorrect" ); assertEq( consideration[0][0].orderIndex, @@ -542,7 +615,9 @@ contract FulfillAvailableHelperTest is Test { ); assertEq( - consideration[1].length, 4, "consideration index 1 length incorrect" + consideration[1].length, + 4, + "consideration index 1 length incorrect" ); assertEq( consideration[1][0].orderIndex, diff --git a/test/foundry/new/helpers/sol/MatchFulfillmentHelper.t.sol b/test/foundry/new/helpers/sol/MatchFulfillmentHelper.t.sol index d991943..6fbe73f 100644 --- a/test/foundry/new/helpers/sol/MatchFulfillmentHelper.t.sol +++ b/test/foundry/new/helpers/sol/MatchFulfillmentHelper.t.sol @@ -27,8 +27,9 @@ import { ItemType } from "seaport-sol/src/SeaportEnums.sol"; import { UnavailableReason } from "seaport-sol/src/SpaceEnums.sol"; -import { MatchFulfillmentHelper } from - "seaport-sol/src/fulfillments/match/MatchFulfillmentHelper.sol"; +import { + MatchFulfillmentHelper +} from "seaport-sol/src/fulfillments/match/MatchFulfillmentHelper.sol"; import { MatchComponent, @@ -66,16 +67,24 @@ contract MatchFulfillmentHelperTest is BaseOrderTest { function testGetMatchedFulfillments_self() public { Order memory order = Order({ - parameters: OrderParametersLib.empty().withOffer( - SeaportArrays.OfferItems( - OfferItemLib.empty().withToken(address(erc20s[0])).withItemType( - ItemType.ERC20 - ).withAmount(100) + parameters: OrderParametersLib + .empty() + .withOffer( + SeaportArrays.OfferItems( + OfferItemLib + .empty() + .withToken(address(erc20s[0])) + .withItemType(ItemType.ERC20) + .withAmount(100) + ) ) - ).withTotalConsideration( + .withTotalConsideration( SeaportArrays.ConsiderationItems( - ConsiderationItemLib.empty().withToken(address(erc20s[0])) - .withItemType(ItemType.ERC20).withAmount(100) + ConsiderationItemLib + .empty() + .withToken(address(erc20s[0])) + .withItemType(ItemType.ERC20) + .withAmount(100) ) ), signature: "" @@ -86,17 +95,18 @@ contract MatchFulfillmentHelperTest is BaseOrderTest { Fulfillment memory expectedFulfillment = Fulfillment({ offerComponents: SeaportArrays.FulfillmentComponents( FulfillmentComponent({ orderIndex: 0, itemIndex: 0 }) - ), + ), considerationComponents: SeaportArrays.FulfillmentComponents( FulfillmentComponent({ orderIndex: 0, itemIndex: 0 }) - ) + ) }); - (Fulfillment[] memory fulfillments,,) = matcher.getMatchedFulfillments( - SeaportArrays.Orders(order), - new bytes32[](1), - new UnavailableReason[](1) - ); + (Fulfillment[] memory fulfillments, , ) = matcher + .getMatchedFulfillments( + SeaportArrays.Orders(order), + new bytes32[](1), + new UnavailableReason[](1) + ); assertEq(fulfillments.length, 1); assertEq(fulfillments[0], expectedFulfillment, "fulfillments[0]"); @@ -109,16 +119,24 @@ contract MatchFulfillmentHelperTest is BaseOrderTest { function testGetMatchedFulfillments_self_conduitDisparity() public { Order memory order = Order({ - parameters: OrderParametersLib.empty().withOffer( - SeaportArrays.OfferItems( - OfferItemLib.empty().withToken(address(erc20s[0])).withItemType( - ItemType.ERC20 - ).withAmount(100) + parameters: OrderParametersLib + .empty() + .withOffer( + SeaportArrays.OfferItems( + OfferItemLib + .empty() + .withToken(address(erc20s[0])) + .withItemType(ItemType.ERC20) + .withAmount(100) + ) ) - ).withTotalConsideration( + .withTotalConsideration( SeaportArrays.ConsiderationItems( - ConsiderationItemLib.empty().withToken(address(erc20s[0])) - .withItemType(ItemType.ERC20).withAmount(100) + ConsiderationItemLib + .empty() + .withToken(address(erc20s[0])) + .withItemType(ItemType.ERC20) + .withAmount(100) ) ), signature: "" @@ -127,18 +145,27 @@ contract MatchFulfillmentHelperTest is BaseOrderTest { order = _toMatchableOrder(order, offerer1, 0); Order memory otherOrder = Order({ - parameters: OrderParametersLib.empty().withOffer( - SeaportArrays.OfferItems( - OfferItemLib.empty().withToken(address(erc20s[0])).withItemType( - ItemType.ERC20 - ).withAmount(101) + parameters: OrderParametersLib + .empty() + .withOffer( + SeaportArrays.OfferItems( + OfferItemLib + .empty() + .withToken(address(erc20s[0])) + .withItemType(ItemType.ERC20) + .withAmount(101) + ) ) - ).withTotalConsideration( + .withTotalConsideration( SeaportArrays.ConsiderationItems( - ConsiderationItemLib.empty().withToken(address(erc20s[0])) - .withItemType(ItemType.ERC20).withAmount(101) + ConsiderationItemLib + .empty() + .withToken(address(erc20s[0])) + .withItemType(ItemType.ERC20) + .withAmount(101) ) - ).withConduitKey(conduitKey), + ) + .withConduitKey(conduitKey), signature: "" }); @@ -148,29 +175,30 @@ contract MatchFulfillmentHelperTest is BaseOrderTest { Fulfillment({ offerComponents: SeaportArrays.FulfillmentComponents( FulfillmentComponent({ orderIndex: 0, itemIndex: 0 }) - ), + ), considerationComponents: SeaportArrays.FulfillmentComponents( FulfillmentComponent({ orderIndex: 0, itemIndex: 0 }), FulfillmentComponent({ orderIndex: 1, itemIndex: 0 }) - ) + ) }), Fulfillment({ offerComponents: SeaportArrays.FulfillmentComponents( FulfillmentComponent({ orderIndex: 1, itemIndex: 0 }) - ), + ), considerationComponents: SeaportArrays.FulfillmentComponents( FulfillmentComponent({ orderIndex: 0, itemIndex: 0 }) - ) + ) }) ); bytes32[] memory orderHashes = new bytes32[](2); - (Fulfillment[] memory fulfillments,,) = matcher.getMatchedFulfillments( - SeaportArrays.Orders(order, otherOrder), - orderHashes, - new UnavailableReason[](2) - ); + (Fulfillment[] memory fulfillments, , ) = matcher + .getMatchedFulfillments( + SeaportArrays.Orders(order, otherOrder), + orderHashes, + new UnavailableReason[](2) + ); assertEq(fulfillments.length, 2); assertEq(fulfillments[0], expectedFulfillments[0], "fulfillments[0]"); @@ -187,37 +215,53 @@ contract MatchFulfillmentHelperTest is BaseOrderTest { execGetMatchedFulfillments_1ItemTo1Item(true); } - function execGetMatchedFulfillments_1ItemTo1Item(bool useDifferentConduits) - public - { + function execGetMatchedFulfillments_1ItemTo1Item( + bool useDifferentConduits + ) public { Order memory order = Order({ - parameters: OrderParametersLib.empty().withOffer( - SeaportArrays.OfferItems( - OfferItemLib.empty().withToken(address(erc20s[0])).withAmount( - 100 + parameters: OrderParametersLib + .empty() + .withOffer( + SeaportArrays.OfferItems( + OfferItemLib + .empty() + .withToken(address(erc20s[0])) + .withAmount(100) ) ) - ).withTotalConsideration( + .withTotalConsideration( SeaportArrays.ConsiderationItems( - ConsiderationItemLib.empty().withToken(address(erc20s[1])) + ConsiderationItemLib + .empty() + .withToken(address(erc20s[1])) .withAmount(100) ) ), signature: "" }); - order = _toMatchableOrder(order, offerer1, useDifferentConduits ? 1 : 0); + order = _toMatchableOrder( + order, + offerer1, + useDifferentConduits ? 1 : 0 + ); Order memory otherOrder = Order({ - parameters: OrderParametersLib.empty().withOffer( - SeaportArrays.OfferItems( - OfferItemLib.empty().withToken(address(erc20s[1])).withAmount( - 100 + parameters: OrderParametersLib + .empty() + .withOffer( + SeaportArrays.OfferItems( + OfferItemLib + .empty() + .withToken(address(erc20s[1])) + .withAmount(100) ) ) - ).withTotalConsideration( + .withTotalConsideration( SeaportArrays.ConsiderationItems( - ConsiderationItemLib.empty().withToken(address(erc20s[0])) + ConsiderationItemLib + .empty() + .withToken(address(erc20s[0])) .withAmount(100) ) ), @@ -228,40 +272,44 @@ contract MatchFulfillmentHelperTest is BaseOrderTest { // use different conduit keys, so just toggle it back and for to make // sure nothing goes wrong. if (useDifferentConduits) { - otherOrder.parameters = - otherOrder.parameters.withConduitKey(conduitKey); + otherOrder.parameters = otherOrder.parameters.withConduitKey( + conduitKey + ); } otherOrder = _toMatchableOrder( - otherOrder, offerer2, useDifferentConduits ? 1 : 0 + otherOrder, + offerer2, + useDifferentConduits ? 1 : 0 ); Fulfillment[] memory expectedFulfillments = SeaportArrays.Fulfillments( Fulfillment({ offerComponents: SeaportArrays.FulfillmentComponents( FulfillmentComponent({ orderIndex: 0, itemIndex: 0 }) - ), + ), considerationComponents: SeaportArrays.FulfillmentComponents( FulfillmentComponent({ orderIndex: 1, itemIndex: 0 }) - ) + ) }), Fulfillment({ offerComponents: SeaportArrays.FulfillmentComponents( FulfillmentComponent({ orderIndex: 1, itemIndex: 0 }) - ), + ), considerationComponents: SeaportArrays.FulfillmentComponents( FulfillmentComponent({ orderIndex: 0, itemIndex: 0 }) - ) + ) }) ); bytes32[] memory orderHashes = new bytes32[](2); - (Fulfillment[] memory fulfillments,,) = matcher.getMatchedFulfillments( - SeaportArrays.Orders(otherOrder, order), - orderHashes, - new UnavailableReason[](2) - ); + (Fulfillment[] memory fulfillments, , ) = matcher + .getMatchedFulfillments( + SeaportArrays.Orders(otherOrder, order), + orderHashes, + new UnavailableReason[](2) + ); assertEq(fulfillments.length, 2, "fulfillments.length"); assertEq(fulfillments[0], expectedFulfillments[1], "fulfillments[0]"); @@ -282,72 +330,98 @@ contract MatchFulfillmentHelperTest is BaseOrderTest { bool useDifferentConduits ) public { Order memory order = Order({ - parameters: OrderParametersLib.empty().withOffer( - SeaportArrays.OfferItems( - OfferItemLib.empty().withToken(address(erc20s[0])) - .withStartAmount(1).withEndAmount(100) + parameters: OrderParametersLib + .empty() + .withOffer( + SeaportArrays.OfferItems( + OfferItemLib + .empty() + .withToken(address(erc20s[0])) + .withStartAmount(1) + .withEndAmount(100) + ) ) - ).withTotalConsideration( + .withTotalConsideration( SeaportArrays.ConsiderationItems( - ConsiderationItemLib.empty().withToken(address(erc20s[1])) - .withStartAmount(1).withEndAmount(100) + ConsiderationItemLib + .empty() + .withToken(address(erc20s[1])) + .withStartAmount(1) + .withEndAmount(100) ) ), signature: "" }); - order = _toMatchableOrder(order, offerer1, useDifferentConduits ? 1 : 0); + order = _toMatchableOrder( + order, + offerer1, + useDifferentConduits ? 1 : 0 + ); Order memory otherOrder = Order({ - parameters: OrderParametersLib.empty().withOffer( - SeaportArrays.OfferItems( - OfferItemLib.empty().withToken(address(erc20s[1])) - .withStartAmount(1).withEndAmount(100) + parameters: OrderParametersLib + .empty() + .withOffer( + SeaportArrays.OfferItems( + OfferItemLib + .empty() + .withToken(address(erc20s[1])) + .withStartAmount(1) + .withEndAmount(100) + ) ) - ).withTotalConsideration( + .withTotalConsideration( SeaportArrays.ConsiderationItems( - ConsiderationItemLib.empty().withToken(address(erc20s[0])) - .withStartAmount(1).withEndAmount(100) + ConsiderationItemLib + .empty() + .withToken(address(erc20s[0])) + .withStartAmount(1) + .withEndAmount(100) ) ), signature: "" }); if (useDifferentConduits) { - otherOrder.parameters = - otherOrder.parameters.withConduitKey(conduitKey); + otherOrder.parameters = otherOrder.parameters.withConduitKey( + conduitKey + ); } otherOrder = _toMatchableOrder( - otherOrder, offerer2, useDifferentConduits ? 1 : 0 + otherOrder, + offerer2, + useDifferentConduits ? 1 : 0 ); Fulfillment[] memory expectedFulfillments = SeaportArrays.Fulfillments( Fulfillment({ offerComponents: SeaportArrays.FulfillmentComponents( FulfillmentComponent({ orderIndex: 0, itemIndex: 0 }) - ), + ), considerationComponents: SeaportArrays.FulfillmentComponents( FulfillmentComponent({ orderIndex: 1, itemIndex: 0 }) - ) + ) }), Fulfillment({ offerComponents: SeaportArrays.FulfillmentComponents( FulfillmentComponent({ orderIndex: 1, itemIndex: 0 }) - ), + ), considerationComponents: SeaportArrays.FulfillmentComponents( FulfillmentComponent({ orderIndex: 0, itemIndex: 0 }) - ) + ) }) ); bytes32[] memory orderHashes = new bytes32[](2); - (Fulfillment[] memory fulfillments,,) = matcher.getMatchedFulfillments( - SeaportArrays.Orders(otherOrder, order), - orderHashes, - new UnavailableReason[](2) - ); + (Fulfillment[] memory fulfillments, , ) = matcher + .getMatchedFulfillments( + SeaportArrays.Orders(otherOrder, order), + orderHashes, + new UnavailableReason[](2) + ); assertEq(fulfillments.length, 2, "fulfillments.length"); assertEq(fulfillments[0], expectedFulfillments[1], "fulfillments[0]"); @@ -368,72 +442,98 @@ contract MatchFulfillmentHelperTest is BaseOrderTest { bool useDifferentConduits ) public { Order memory order = Order({ - parameters: OrderParametersLib.empty().withOffer( - SeaportArrays.OfferItems( - OfferItemLib.empty().withToken(address(erc20s[0])) - .withStartAmount(100).withEndAmount(1) + parameters: OrderParametersLib + .empty() + .withOffer( + SeaportArrays.OfferItems( + OfferItemLib + .empty() + .withToken(address(erc20s[0])) + .withStartAmount(100) + .withEndAmount(1) + ) ) - ).withTotalConsideration( + .withTotalConsideration( SeaportArrays.ConsiderationItems( - ConsiderationItemLib.empty().withToken(address(erc20s[1])) - .withStartAmount(100).withEndAmount(1) + ConsiderationItemLib + .empty() + .withToken(address(erc20s[1])) + .withStartAmount(100) + .withEndAmount(1) ) ), signature: "" }); - order = _toMatchableOrder(order, offerer1, useDifferentConduits ? 1 : 0); + order = _toMatchableOrder( + order, + offerer1, + useDifferentConduits ? 1 : 0 + ); Order memory otherOrder = Order({ - parameters: OrderParametersLib.empty().withOffer( - SeaportArrays.OfferItems( - OfferItemLib.empty().withToken(address(erc20s[1])) - .withStartAmount(100).withEndAmount(1) + parameters: OrderParametersLib + .empty() + .withOffer( + SeaportArrays.OfferItems( + OfferItemLib + .empty() + .withToken(address(erc20s[1])) + .withStartAmount(100) + .withEndAmount(1) + ) ) - ).withTotalConsideration( + .withTotalConsideration( SeaportArrays.ConsiderationItems( - ConsiderationItemLib.empty().withToken(address(erc20s[0])) - .withStartAmount(100).withEndAmount(1) + ConsiderationItemLib + .empty() + .withToken(address(erc20s[0])) + .withStartAmount(100) + .withEndAmount(1) ) ), signature: "" }); if (useDifferentConduits) { - otherOrder.parameters = - otherOrder.parameters.withConduitKey(conduitKey); + otherOrder.parameters = otherOrder.parameters.withConduitKey( + conduitKey + ); } otherOrder = _toMatchableOrder( - otherOrder, offerer2, useDifferentConduits ? 1 : 0 + otherOrder, + offerer2, + useDifferentConduits ? 1 : 0 ); Fulfillment[] memory expectedFulfillments = SeaportArrays.Fulfillments( Fulfillment({ offerComponents: SeaportArrays.FulfillmentComponents( FulfillmentComponent({ orderIndex: 0, itemIndex: 0 }) - ), + ), considerationComponents: SeaportArrays.FulfillmentComponents( FulfillmentComponent({ orderIndex: 1, itemIndex: 0 }) - ) + ) }), Fulfillment({ offerComponents: SeaportArrays.FulfillmentComponents( FulfillmentComponent({ orderIndex: 1, itemIndex: 0 }) - ), + ), considerationComponents: SeaportArrays.FulfillmentComponents( FulfillmentComponent({ orderIndex: 0, itemIndex: 0 }) - ) + ) }) ); bytes32[] memory orderHashes = new bytes32[](2); - (Fulfillment[] memory fulfillments,,) = matcher.getMatchedFulfillments( - SeaportArrays.Orders(otherOrder, order), - orderHashes, - new UnavailableReason[](2) - ); + (Fulfillment[] memory fulfillments, , ) = matcher + .getMatchedFulfillments( + SeaportArrays.Orders(otherOrder, order), + orderHashes, + new UnavailableReason[](2) + ); assertEq(fulfillments.length, 2, "fulfillments.length"); assertEq(fulfillments[0], expectedFulfillments[1], "fulfillments[0]"); @@ -456,62 +556,87 @@ contract MatchFulfillmentHelperTest is BaseOrderTest { bool useDifferentConduits ) public { Order memory order = Order({ - parameters: OrderParametersLib.empty().withOffer( - SeaportArrays.OfferItems( - OfferItemLib.empty().withToken(address(erc20s[0])) - .withStartAmount(100).withEndAmount(1) + parameters: OrderParametersLib + .empty() + .withOffer( + SeaportArrays.OfferItems( + OfferItemLib + .empty() + .withToken(address(erc20s[0])) + .withStartAmount(100) + .withEndAmount(1) + ) ) - ).withTotalConsideration( + .withTotalConsideration( SeaportArrays.ConsiderationItems( - ConsiderationItemLib.empty().withToken(address(erc20s[1])) - .withStartAmount(1).withEndAmount(100) + ConsiderationItemLib + .empty() + .withToken(address(erc20s[1])) + .withStartAmount(1) + .withEndAmount(100) ) ), signature: "" }); - order = _toMatchableOrder(order, offerer1, useDifferentConduits ? 1 : 0); + order = _toMatchableOrder( + order, + offerer1, + useDifferentConduits ? 1 : 0 + ); Order memory otherOrder = Order({ - parameters: OrderParametersLib.empty().withOffer( - SeaportArrays.OfferItems( - OfferItemLib.empty().withToken(address(erc20s[1])) - .withStartAmount(1).withEndAmount(100) + parameters: OrderParametersLib + .empty() + .withOffer( + SeaportArrays.OfferItems( + OfferItemLib + .empty() + .withToken(address(erc20s[1])) + .withStartAmount(1) + .withEndAmount(100) + ) ) - ).withTotalConsideration( + .withTotalConsideration( SeaportArrays.ConsiderationItems( - ConsiderationItemLib.empty().withToken(address(erc20s[0])) - .withStartAmount(1).withEndAmount(100) + ConsiderationItemLib + .empty() + .withToken(address(erc20s[0])) + .withStartAmount(1) + .withEndAmount(100) ) ), signature: "" }); if (useDifferentConduits) { - otherOrder.parameters = - otherOrder.parameters.withConduitKey(conduitKey); + otherOrder.parameters = otherOrder.parameters.withConduitKey( + conduitKey + ); } otherOrder = _toMatchableOrder( - otherOrder, offerer2, useDifferentConduits ? 1 : 0 + otherOrder, + offerer2, + useDifferentConduits ? 1 : 0 ); Fulfillment[] memory expectedFulfillments = SeaportArrays.Fulfillments( Fulfillment({ offerComponents: SeaportArrays.FulfillmentComponents( FulfillmentComponent({ orderIndex: 0, itemIndex: 0 }) - ), + ), considerationComponents: SeaportArrays.FulfillmentComponents( FulfillmentComponent({ orderIndex: 1, itemIndex: 0 }) - ) + ) }), Fulfillment({ offerComponents: SeaportArrays.FulfillmentComponents( FulfillmentComponent({ orderIndex: 1, itemIndex: 0 }) - ), + ), considerationComponents: SeaportArrays.FulfillmentComponents( FulfillmentComponent({ orderIndex: 0, itemIndex: 0 }) - ) + ) }) ); @@ -522,10 +647,10 @@ contract MatchFulfillmentHelperTest is BaseOrderTest { MatchComponent[] memory leftoverOffer, MatchComponent[] memory leftoverConsideration ) = matcher.getMatchedFulfillments( - SeaportArrays.Orders(otherOrder, order), - orderHashes, - new UnavailableReason[](2) - ); + SeaportArrays.Orders(otherOrder, order), + orderHashes, + new UnavailableReason[](2) + ); assertEq(fulfillments.length, 2, "fulfillments.length"); assertEq(fulfillments[0], expectedFulfillments[1], "fulfillments[0]"); @@ -533,7 +658,9 @@ contract MatchFulfillmentHelperTest is BaseOrderTest { assertEq(leftoverOffer.length, 1, "leftoverOffer.length"); assertEq(leftoverOffer[0].getAmount(), 99, "leftoverOffer[0].amount()"); assertEq( - leftoverConsideration.length, 0, "leftoverConsideration.length" + leftoverConsideration.length, + 0, + "leftoverConsideration.length" ); seaport.matchOrders({ @@ -551,74 +678,96 @@ contract MatchFulfillmentHelperTest is BaseOrderTest { bool useDifferentConduits ) public { Order memory order = Order({ - parameters: OrderParametersLib.empty().withOffer( - SeaportArrays.OfferItems( - OfferItemLib.empty().withToken(address(erc20s[0])).withAmount( - 100 + parameters: OrderParametersLib + .empty() + .withOffer( + SeaportArrays.OfferItems( + OfferItemLib + .empty() + .withToken(address(erc20s[0])) + .withAmount(100) ) ) - ).withTotalConsideration( + .withTotalConsideration( SeaportArrays.ConsiderationItems( - ConsiderationItemLib.empty().withToken(address(erc20s[1])) + ConsiderationItemLib + .empty() + .withToken(address(erc20s[1])) .withAmount(100) ) - ).withOfferer(offerer1.addr), + ) + .withOfferer(offerer1.addr), signature: "" }); - order = _toMatchableOrder(order, offerer1, useDifferentConduits ? 1 : 0); + order = _toMatchableOrder( + order, + offerer1, + useDifferentConduits ? 1 : 0 + ); Order memory otherOrder = Order({ - parameters: OrderParametersLib.empty().withOffer( - SeaportArrays.OfferItems( - OfferItemLib.empty().withToken(address(erc20s[1])).withAmount( - 200 + parameters: OrderParametersLib + .empty() + .withOffer( + SeaportArrays.OfferItems( + OfferItemLib + .empty() + .withToken(address(erc20s[1])) + .withAmount(200) ) ) - ).withTotalConsideration( + .withTotalConsideration( SeaportArrays.ConsiderationItems( - ConsiderationItemLib.empty().withToken(address(erc20s[0])) + ConsiderationItemLib + .empty() + .withToken(address(erc20s[0])) .withAmount(100) ) - ).withOfferer(offerer2.addr), + ) + .withOfferer(offerer2.addr), signature: "" }); if (useDifferentConduits) { - otherOrder.parameters = - otherOrder.parameters.withConduitKey(conduitKey); + otherOrder.parameters = otherOrder.parameters.withConduitKey( + conduitKey + ); } otherOrder = _toMatchableOrder( - otherOrder, offerer2, useDifferentConduits ? 1 : 0 + otherOrder, + offerer2, + useDifferentConduits ? 1 : 0 ); Fulfillment[] memory expectedFulfillments = SeaportArrays.Fulfillments( Fulfillment({ offerComponents: SeaportArrays.FulfillmentComponents( FulfillmentComponent({ orderIndex: 0, itemIndex: 0 }) - ), + ), considerationComponents: SeaportArrays.FulfillmentComponents( FulfillmentComponent({ orderIndex: 1, itemIndex: 0 }) - ) + ) }), Fulfillment({ offerComponents: SeaportArrays.FulfillmentComponents( FulfillmentComponent({ orderIndex: 1, itemIndex: 0 }) - ), + ), considerationComponents: SeaportArrays.FulfillmentComponents( FulfillmentComponent({ orderIndex: 0, itemIndex: 0 }) - ) + ) }) ); bytes32[] memory orderHashes = new bytes32[](2); - (Fulfillment[] memory fulfillments,,) = matcher.getMatchedFulfillments( - SeaportArrays.Orders(otherOrder, order), - orderHashes, - new UnavailableReason[](2) - ); + (Fulfillment[] memory fulfillments, , ) = matcher + .getMatchedFulfillments( + SeaportArrays.Orders(otherOrder, order), + orderHashes, + new UnavailableReason[](2) + ); assertEq(fulfillments.length, 2, "fulfillments.length"); assertEq(fulfillments[0], expectedFulfillments[1], "fulfillments[0]"); @@ -635,89 +784,118 @@ contract MatchFulfillmentHelperTest is BaseOrderTest { execGetMatchedFulfillments_3ItemsTo1Item(true); } - function execGetMatchedFulfillments_3ItemsTo1Item(bool useDifferentConduits) - public - { + function execGetMatchedFulfillments_3ItemsTo1Item( + bool useDifferentConduits + ) public { Order memory order = Order({ - parameters: OrderParametersLib.empty().withOffer( - SeaportArrays.OfferItems( - OfferItemLib.empty().withToken(address(erc20s[0])).withAmount( - 100 + parameters: OrderParametersLib + .empty() + .withOffer( + SeaportArrays.OfferItems( + OfferItemLib + .empty() + .withToken(address(erc20s[0])) + .withAmount(100) ) ) - ).withTotalConsideration( + .withTotalConsideration( SeaportArrays.ConsiderationItems( - ConsiderationItemLib.empty().withToken(address(erc20s[1])) + ConsiderationItemLib + .empty() + .withToken(address(erc20s[1])) .withAmount(1), - ConsiderationItemLib.empty().withToken(address(erc20s[0])) + ConsiderationItemLib + .empty() + .withToken(address(erc20s[0])) .withAmount(10), - ConsiderationItemLib.empty().withToken(address(erc20s[0])) + ConsiderationItemLib + .empty() + .withToken(address(erc20s[0])) .withAmount(10) ) - ).withOfferer(offerer1.addr), + ) + .withOfferer(offerer1.addr), signature: "" }); - order = _toMatchableOrder(order, offerer1, useDifferentConduits ? 1 : 0); + order = _toMatchableOrder( + order, + offerer1, + useDifferentConduits ? 1 : 0 + ); Order memory otherOrder = Order({ - parameters: OrderParametersLib.empty().withOffer( - SeaportArrays.OfferItems( - OfferItemLib.empty().withToken(address(erc20s[1])).withAmount(1) + parameters: OrderParametersLib + .empty() + .withOffer( + SeaportArrays.OfferItems( + OfferItemLib + .empty() + .withToken(address(erc20s[1])) + .withAmount(1) + ) ) - ).withTotalConsideration( + .withTotalConsideration( SeaportArrays.ConsiderationItems( - ConsiderationItemLib.empty().withToken(address(erc20s[0])) - .withAmount(80).withRecipient(offerer2.addr) + ConsiderationItemLib + .empty() + .withToken(address(erc20s[0])) + .withAmount(80) + .withRecipient(offerer2.addr) ) - ).withOfferer(offerer2.addr), + ) + .withOfferer(offerer2.addr), signature: "" }); if (useDifferentConduits) { - otherOrder.parameters = - otherOrder.parameters.withConduitKey(conduitKey); + otherOrder.parameters = otherOrder.parameters.withConduitKey( + conduitKey + ); } otherOrder = _toMatchableOrder( - otherOrder, offerer2, useDifferentConduits ? 1 : 0 + otherOrder, + offerer2, + useDifferentConduits ? 1 : 0 ); Fulfillment[] memory expectedFulfillments = SeaportArrays.Fulfillments( Fulfillment({ offerComponents: SeaportArrays.FulfillmentComponents( FulfillmentComponent({ orderIndex: 0, itemIndex: 0 }) - ), + ), considerationComponents: SeaportArrays.FulfillmentComponents( FulfillmentComponent({ orderIndex: 1, itemIndex: 0 }) - ) + ) }), Fulfillment({ offerComponents: SeaportArrays.FulfillmentComponents( FulfillmentComponent({ orderIndex: 0, itemIndex: 0 }) - ), + ), considerationComponents: SeaportArrays.FulfillmentComponents( FulfillmentComponent({ orderIndex: 0, itemIndex: 1 }), FulfillmentComponent({ orderIndex: 0, itemIndex: 2 }) - ) + ) }), Fulfillment({ offerComponents: SeaportArrays.FulfillmentComponents( FulfillmentComponent({ orderIndex: 1, itemIndex: 0 }) - ), + ), considerationComponents: SeaportArrays.FulfillmentComponents( FulfillmentComponent({ orderIndex: 0, itemIndex: 0 }) - ) + ) }) ); bytes32[] memory orderHashes = new bytes32[](2); - (Fulfillment[] memory fulfillments,,) = matcher.getMatchedFulfillments( - SeaportArrays.Orders(order, otherOrder), - orderHashes, - new UnavailableReason[](2) - ); + (Fulfillment[] memory fulfillments, , ) = matcher + .getMatchedFulfillments( + SeaportArrays.Orders(order, otherOrder), + orderHashes, + new UnavailableReason[](2) + ); assertEq(fulfillments.length, 3, "fulfillments.length"); @@ -740,85 +918,114 @@ contract MatchFulfillmentHelperTest is BaseOrderTest { bool useDifferentConduits ) public { Order memory order = Order({ - parameters: OrderParametersLib.empty().withOffer( - SeaportArrays.OfferItems( - OfferItemLib.empty().withToken(address(erc20s[0])).withAmount( - 110 + parameters: OrderParametersLib + .empty() + .withOffer( + SeaportArrays.OfferItems( + OfferItemLib + .empty() + .withToken(address(erc20s[0])) + .withAmount(110) ) ) - ).withTotalConsideration( + .withTotalConsideration( SeaportArrays.ConsiderationItems( - ConsiderationItemLib.empty().withToken(address(erc20s[1])) + ConsiderationItemLib + .empty() + .withToken(address(erc20s[1])) .withAmount(1), - ConsiderationItemLib.empty().withToken(address(erc20s[0])) + ConsiderationItemLib + .empty() + .withToken(address(erc20s[0])) .withAmount(10), - ConsiderationItemLib.empty().withToken(address(erc20s[0])) + ConsiderationItemLib + .empty() + .withToken(address(erc20s[0])) .withAmount(10) ) - ).withOfferer(offerer1.addr), + ) + .withOfferer(offerer1.addr), signature: "" }); - order = _toMatchableOrder(order, offerer1, useDifferentConduits ? 1 : 0); + order = _toMatchableOrder( + order, + offerer1, + useDifferentConduits ? 1 : 0 + ); Order memory otherOrder = Order({ - parameters: OrderParametersLib.empty().withOffer( - SeaportArrays.OfferItems( - OfferItemLib.empty().withToken(address(erc20s[1])).withAmount(1) + parameters: OrderParametersLib + .empty() + .withOffer( + SeaportArrays.OfferItems( + OfferItemLib + .empty() + .withToken(address(erc20s[1])) + .withAmount(1) + ) ) - ).withTotalConsideration( + .withTotalConsideration( SeaportArrays.ConsiderationItems( - ConsiderationItemLib.empty().withToken(address(erc20s[0])) - .withAmount(80).withRecipient(offerer2.addr) + ConsiderationItemLib + .empty() + .withToken(address(erc20s[0])) + .withAmount(80) + .withRecipient(offerer2.addr) ) - ).withOfferer(offerer2.addr), + ) + .withOfferer(offerer2.addr), signature: "" }); if (useDifferentConduits) { - otherOrder.parameters = - otherOrder.parameters.withConduitKey(conduitKey); + otherOrder.parameters = otherOrder.parameters.withConduitKey( + conduitKey + ); } otherOrder = _toMatchableOrder( - otherOrder, offerer2, useDifferentConduits ? 1 : 0 + otherOrder, + offerer2, + useDifferentConduits ? 1 : 0 ); Fulfillment[] memory expectedFulfillments = SeaportArrays.Fulfillments( Fulfillment({ offerComponents: SeaportArrays.FulfillmentComponents( FulfillmentComponent({ orderIndex: 0, itemIndex: 0 }) - ), + ), considerationComponents: SeaportArrays.FulfillmentComponents( FulfillmentComponent({ orderIndex: 1, itemIndex: 0 }) - ) + ) }), Fulfillment({ offerComponents: SeaportArrays.FulfillmentComponents( FulfillmentComponent({ orderIndex: 0, itemIndex: 0 }) - ), + ), considerationComponents: SeaportArrays.FulfillmentComponents( FulfillmentComponent({ orderIndex: 0, itemIndex: 1 }), FulfillmentComponent({ orderIndex: 0, itemIndex: 2 }) - ) + ) }), Fulfillment({ offerComponents: SeaportArrays.FulfillmentComponents( FulfillmentComponent({ orderIndex: 1, itemIndex: 0 }) - ), + ), considerationComponents: SeaportArrays.FulfillmentComponents( FulfillmentComponent({ orderIndex: 0, itemIndex: 0 }) - ) + ) }) ); bytes32[] memory orderHashes = new bytes32[](2); - (Fulfillment[] memory fulfillments,,) = matcher.getMatchedFulfillments( - SeaportArrays.Orders(order, otherOrder), - orderHashes, - new UnavailableReason[](2) - ); + (Fulfillment[] memory fulfillments, , ) = matcher + .getMatchedFulfillments( + SeaportArrays.Orders(order, otherOrder), + orderHashes, + new UnavailableReason[](2) + ); assertEq(fulfillments.length, 3, "fulfillments.length"); @@ -841,89 +1048,119 @@ contract MatchFulfillmentHelperTest is BaseOrderTest { bool useDifferentConduits ) public { Order memory order = Order({ - parameters: OrderParametersLib.empty().withOffer( - SeaportArrays.OfferItems( - OfferItemLib.empty().withToken(address(erc20s[0])).withAmount( - 10 - ), - OfferItemLib.empty().withToken(address(erc20s[0])).withAmount( - 90 + parameters: OrderParametersLib + .empty() + .withOffer( + SeaportArrays.OfferItems( + OfferItemLib + .empty() + .withToken(address(erc20s[0])) + .withAmount(10), + OfferItemLib + .empty() + .withToken(address(erc20s[0])) + .withAmount(90) ) ) - ).withTotalConsideration( + .withTotalConsideration( SeaportArrays.ConsiderationItems( - ConsiderationItemLib.empty().withToken(address(erc20s[1])) + ConsiderationItemLib + .empty() + .withToken(address(erc20s[1])) .withAmount(1), - ConsiderationItemLib.empty().withToken(address(erc20s[0])) + ConsiderationItemLib + .empty() + .withToken(address(erc20s[0])) .withAmount(10), - ConsiderationItemLib.empty().withToken(address(erc20s[0])) + ConsiderationItemLib + .empty() + .withToken(address(erc20s[0])) .withAmount(10) ) - ).withOfferer(offerer1.addr), + ) + .withOfferer(offerer1.addr), signature: "" }); - order = _toMatchableOrder(order, offerer1, useDifferentConduits ? 1 : 0); + order = _toMatchableOrder( + order, + offerer1, + useDifferentConduits ? 1 : 0 + ); Order memory otherOrder = Order({ - parameters: OrderParametersLib.empty().withOffer( - SeaportArrays.OfferItems( - OfferItemLib.empty().withToken(address(erc20s[1])).withAmount(1) + parameters: OrderParametersLib + .empty() + .withOffer( + SeaportArrays.OfferItems( + OfferItemLib + .empty() + .withToken(address(erc20s[1])) + .withAmount(1) + ) ) - ).withTotalConsideration( + .withTotalConsideration( SeaportArrays.ConsiderationItems( - ConsiderationItemLib.empty().withToken(address(erc20s[0])) - .withAmount(80).withRecipient(offerer2.addr) + ConsiderationItemLib + .empty() + .withToken(address(erc20s[0])) + .withAmount(80) + .withRecipient(offerer2.addr) ) - ).withOfferer(offerer2.addr), + ) + .withOfferer(offerer2.addr), signature: "" }); if (useDifferentConduits) { - otherOrder.parameters = - otherOrder.parameters.withConduitKey(conduitKey); + otherOrder.parameters = otherOrder.parameters.withConduitKey( + conduitKey + ); } otherOrder = _toMatchableOrder( - otherOrder, offerer2, useDifferentConduits ? 1 : 0 + otherOrder, + offerer2, + useDifferentConduits ? 1 : 0 ); Fulfillment[] memory expectedFulfillments = SeaportArrays.Fulfillments( Fulfillment({ offerComponents: SeaportArrays.FulfillmentComponents( FulfillmentComponent({ orderIndex: 1, itemIndex: 0 }) - ), + ), considerationComponents: SeaportArrays.FulfillmentComponents( FulfillmentComponent({ orderIndex: 0, itemIndex: 0 }) - ) + ) }), Fulfillment({ offerComponents: SeaportArrays.FulfillmentComponents( FulfillmentComponent({ orderIndex: 0, itemIndex: 0 }), FulfillmentComponent({ orderIndex: 0, itemIndex: 1 }) - ), + ), considerationComponents: SeaportArrays.FulfillmentComponents( FulfillmentComponent({ orderIndex: 0, itemIndex: 1 }), FulfillmentComponent({ orderIndex: 0, itemIndex: 2 }) - ) + ) }), Fulfillment({ offerComponents: SeaportArrays.FulfillmentComponents( FulfillmentComponent({ orderIndex: 0, itemIndex: 0 }) - ), + ), considerationComponents: SeaportArrays.FulfillmentComponents( FulfillmentComponent({ orderIndex: 1, itemIndex: 0 }) - ) + ) }) ); bytes32[] memory orderHashes = new bytes32[](2); - (Fulfillment[] memory fulfillments,,) = matcher.getMatchedFulfillments( - SeaportArrays.Orders(order, otherOrder), - orderHashes, - new UnavailableReason[](2) - ); + (Fulfillment[] memory fulfillments, , ) = matcher + .getMatchedFulfillments( + SeaportArrays.Orders(order, otherOrder), + orderHashes, + new UnavailableReason[](2) + ); assertEq(fulfillments.length, 3, "fulfillments.length"); @@ -947,89 +1184,119 @@ contract MatchFulfillmentHelperTest is BaseOrderTest { bool useDifferentConduits ) public { Order memory order = Order({ - parameters: OrderParametersLib.empty().withOffer( - SeaportArrays.OfferItems( - OfferItemLib.empty().withToken(address(erc20s[0])).withAmount( - 90 - ), - OfferItemLib.empty().withToken(address(erc20s[0])).withAmount( - 10 + parameters: OrderParametersLib + .empty() + .withOffer( + SeaportArrays.OfferItems( + OfferItemLib + .empty() + .withToken(address(erc20s[0])) + .withAmount(90), + OfferItemLib + .empty() + .withToken(address(erc20s[0])) + .withAmount(10) ) ) - ).withTotalConsideration( + .withTotalConsideration( SeaportArrays.ConsiderationItems( - ConsiderationItemLib.empty().withToken(address(erc20s[1])) + ConsiderationItemLib + .empty() + .withToken(address(erc20s[1])) .withAmount(1), - ConsiderationItemLib.empty().withToken(address(erc20s[0])) + ConsiderationItemLib + .empty() + .withToken(address(erc20s[0])) .withAmount(10), - ConsiderationItemLib.empty().withToken(address(erc20s[0])) + ConsiderationItemLib + .empty() + .withToken(address(erc20s[0])) .withAmount(10) ) - ).withOfferer(offerer1.addr), + ) + .withOfferer(offerer1.addr), signature: "" }); - order = _toMatchableOrder(order, offerer1, useDifferentConduits ? 1 : 0); + order = _toMatchableOrder( + order, + offerer1, + useDifferentConduits ? 1 : 0 + ); Order memory otherOrder = Order({ - parameters: OrderParametersLib.empty().withOffer( - SeaportArrays.OfferItems( - OfferItemLib.empty().withToken(address(erc20s[1])).withAmount(1) + parameters: OrderParametersLib + .empty() + .withOffer( + SeaportArrays.OfferItems( + OfferItemLib + .empty() + .withToken(address(erc20s[1])) + .withAmount(1) + ) ) - ).withTotalConsideration( + .withTotalConsideration( SeaportArrays.ConsiderationItems( - ConsiderationItemLib.empty().withToken(address(erc20s[0])) - .withAmount(80).withRecipient(offerer2.addr) + ConsiderationItemLib + .empty() + .withToken(address(erc20s[0])) + .withAmount(80) + .withRecipient(offerer2.addr) ) - ).withOfferer(offerer2.addr), + ) + .withOfferer(offerer2.addr), signature: "" }); if (useDifferentConduits) { - otherOrder.parameters = - otherOrder.parameters.withConduitKey(conduitKey); + otherOrder.parameters = otherOrder.parameters.withConduitKey( + conduitKey + ); } otherOrder = _toMatchableOrder( - otherOrder, offerer2, useDifferentConduits ? 1 : 0 + otherOrder, + offerer2, + useDifferentConduits ? 1 : 0 ); Fulfillment[] memory expectedFulfillments = SeaportArrays.Fulfillments( Fulfillment({ offerComponents: SeaportArrays.FulfillmentComponents( FulfillmentComponent({ orderIndex: 1, itemIndex: 0 }) - ), + ), considerationComponents: SeaportArrays.FulfillmentComponents( FulfillmentComponent({ orderIndex: 0, itemIndex: 0 }) - ) + ) }), Fulfillment({ offerComponents: SeaportArrays.FulfillmentComponents( FulfillmentComponent({ orderIndex: 0, itemIndex: 0 }) - ), + ), considerationComponents: SeaportArrays.FulfillmentComponents( FulfillmentComponent({ orderIndex: 0, itemIndex: 1 }), FulfillmentComponent({ orderIndex: 0, itemIndex: 2 }) - ) + ) }), Fulfillment({ offerComponents: SeaportArrays.FulfillmentComponents( FulfillmentComponent({ orderIndex: 0, itemIndex: 0 }), FulfillmentComponent({ orderIndex: 0, itemIndex: 1 }) - ), + ), considerationComponents: SeaportArrays.FulfillmentComponents( FulfillmentComponent({ orderIndex: 1, itemIndex: 0 }) - ) + ) }) ); bytes32[] memory orderHashes = new bytes32[](2); - (Fulfillment[] memory fulfillments,,) = matcher.getMatchedFulfillments( - SeaportArrays.Orders(order, otherOrder), - orderHashes, - new UnavailableReason[](2) - ); + (Fulfillment[] memory fulfillments, , ) = matcher + .getMatchedFulfillments( + SeaportArrays.Orders(order, otherOrder), + orderHashes, + new UnavailableReason[](2) + ); assertEq(fulfillments.length, 3, "fulfillments.length"); @@ -1043,9 +1310,7 @@ contract MatchFulfillmentHelperTest is BaseOrderTest { }); } - function testGetMatchedFulfillments_DoubleOrderPairs_1ItemTo1Item() - public - { + function testGetMatchedFulfillments_DoubleOrderPairs_1ItemTo1Item() public { execGetMatchedFulfillments_DoubleOrderPairs_1ItemTo1Item(false, false); execGetMatchedFulfillments_DoubleOrderPairs_1ItemTo1Item(true, false); execGetMatchedFulfillments_DoubleOrderPairs_1ItemTo1Item(false, true); @@ -1057,15 +1322,21 @@ contract MatchFulfillmentHelperTest is BaseOrderTest { bool useDifferentConduitsBetweenOrderPairs ) public { Order memory orderOne = Order({ - parameters: OrderParametersLib.empty().withOffer( - SeaportArrays.OfferItems( - OfferItemLib.empty().withToken(address(erc20s[0])).withAmount( - 100 + parameters: OrderParametersLib + .empty() + .withOffer( + SeaportArrays.OfferItems( + OfferItemLib + .empty() + .withToken(address(erc20s[0])) + .withAmount(100) ) ) - ).withTotalConsideration( + .withTotalConsideration( SeaportArrays.ConsiderationItems( - ConsiderationItemLib.empty().withToken(address(erc20s[1])) + ConsiderationItemLib + .empty() + .withToken(address(erc20s[1])) .withAmount(100) ) ), @@ -1077,19 +1348,27 @@ contract MatchFulfillmentHelperTest is BaseOrderTest { offerer1, useDifferentConduitsBetweenPrimeAndMirror ? 0 - : useDifferentConduitsBetweenOrderPairs ? 1 : 2 + : useDifferentConduitsBetweenOrderPairs + ? 1 + : 2 ); Order memory otherOrderOne = Order({ - parameters: OrderParametersLib.empty().withOffer( - SeaportArrays.OfferItems( - OfferItemLib.empty().withToken(address(erc20s[1])).withAmount( - 100 + parameters: OrderParametersLib + .empty() + .withOffer( + SeaportArrays.OfferItems( + OfferItemLib + .empty() + .withToken(address(erc20s[1])) + .withAmount(100) ) ) - ).withTotalConsideration( + .withTotalConsideration( SeaportArrays.ConsiderationItems( - ConsiderationItemLib.empty().withToken(address(erc20s[0])) + ConsiderationItemLib + .empty() + .withToken(address(erc20s[0])) .withAmount(100) ) ), @@ -1097,8 +1376,9 @@ contract MatchFulfillmentHelperTest is BaseOrderTest { }); if (useDifferentConduitsBetweenPrimeAndMirror) { - otherOrderOne.parameters = - otherOrderOne.parameters.withConduitKey(conduitKey); + otherOrderOne.parameters = otherOrderOne.parameters.withConduitKey( + conduitKey + ); } otherOrderOne = _toMatchableOrder( @@ -1106,19 +1386,27 @@ contract MatchFulfillmentHelperTest is BaseOrderTest { offerer2, useDifferentConduitsBetweenPrimeAndMirror ? 0 - : useDifferentConduitsBetweenOrderPairs ? 1 : 2 + : useDifferentConduitsBetweenOrderPairs + ? 1 + : 2 ); Order memory orderTwo = Order({ - parameters: OrderParametersLib.empty().withOffer( - SeaportArrays.OfferItems( - OfferItemLib.empty().withToken(address(erc20s[0])).withAmount( - 101 + parameters: OrderParametersLib + .empty() + .withOffer( + SeaportArrays.OfferItems( + OfferItemLib + .empty() + .withToken(address(erc20s[0])) + .withAmount(101) ) ) - ).withTotalConsideration( + .withTotalConsideration( SeaportArrays.ConsiderationItems( - ConsiderationItemLib.empty().withToken(address(erc20s[1])) + ConsiderationItemLib + .empty() + .withToken(address(erc20s[1])) .withAmount(101) ) ), @@ -1126,7 +1414,9 @@ contract MatchFulfillmentHelperTest is BaseOrderTest { }); if (useDifferentConduitsBetweenOrderPairs) { - orderTwo.parameters = orderTwo.parameters.withConduitKey(conduitKey); + orderTwo.parameters = orderTwo.parameters.withConduitKey( + conduitKey + ); } orderTwo = _toMatchableOrder( @@ -1134,19 +1424,27 @@ contract MatchFulfillmentHelperTest is BaseOrderTest { offerer1, useDifferentConduitsBetweenPrimeAndMirror ? 0 - : useDifferentConduitsBetweenOrderPairs ? 1 : 2 + : useDifferentConduitsBetweenOrderPairs + ? 1 + : 2 ); Order memory otherOrderTwo = Order({ - parameters: OrderParametersLib.empty().withOffer( - SeaportArrays.OfferItems( - OfferItemLib.empty().withToken(address(erc20s[1])).withAmount( - 101 + parameters: OrderParametersLib + .empty() + .withOffer( + SeaportArrays.OfferItems( + OfferItemLib + .empty() + .withToken(address(erc20s[1])) + .withAmount(101) ) ) - ).withTotalConsideration( + .withTotalConsideration( SeaportArrays.ConsiderationItems( - ConsiderationItemLib.empty().withToken(address(erc20s[0])) + ConsiderationItemLib + .empty() + .withToken(address(erc20s[0])) .withAmount(101) ) ), @@ -1154,11 +1452,12 @@ contract MatchFulfillmentHelperTest is BaseOrderTest { }); if ( - useDifferentConduitsBetweenPrimeAndMirror - || useDifferentConduitsBetweenOrderPairs + useDifferentConduitsBetweenPrimeAndMirror || + useDifferentConduitsBetweenOrderPairs ) { - otherOrderTwo.parameters = - otherOrderTwo.parameters.withConduitKey(conduitKey); + otherOrderTwo.parameters = otherOrderTwo.parameters.withConduitKey( + conduitKey + ); } otherOrderTwo = _toMatchableOrder( @@ -1166,7 +1465,9 @@ contract MatchFulfillmentHelperTest is BaseOrderTest { offerer2, useDifferentConduitsBetweenPrimeAndMirror ? 0 - : useDifferentConduitsBetweenOrderPairs ? 1 : 2 + : useDifferentConduitsBetweenOrderPairs + ? 1 + : 2 ); Fulfillment[] memory expectedFulfillments; @@ -1177,20 +1478,34 @@ contract MatchFulfillmentHelperTest is BaseOrderTest { offerComponents: SeaportArrays.FulfillmentComponents( FulfillmentComponent({ orderIndex: 1, itemIndex: 0 }), FulfillmentComponent({ orderIndex: 3, itemIndex: 0 }) - ), - considerationComponents: SeaportArrays.FulfillmentComponents( - FulfillmentComponent({ orderIndex: 0, itemIndex: 0 }), - FulfillmentComponent({ orderIndex: 2, itemIndex: 0 }) + ), + considerationComponents: SeaportArrays + .FulfillmentComponents( + FulfillmentComponent({ + orderIndex: 0, + itemIndex: 0 + }), + FulfillmentComponent({ + orderIndex: 2, + itemIndex: 0 + }) ) }), Fulfillment({ offerComponents: SeaportArrays.FulfillmentComponents( FulfillmentComponent({ orderIndex: 0, itemIndex: 0 }), FulfillmentComponent({ orderIndex: 2, itemIndex: 0 }) - ), - considerationComponents: SeaportArrays.FulfillmentComponents( - FulfillmentComponent({ orderIndex: 1, itemIndex: 0 }), - FulfillmentComponent({ orderIndex: 3, itemIndex: 0 }) + ), + considerationComponents: SeaportArrays + .FulfillmentComponents( + FulfillmentComponent({ + orderIndex: 1, + itemIndex: 0 + }), + FulfillmentComponent({ + orderIndex: 3, + itemIndex: 0 + }) ) }) ); @@ -1205,35 +1520,57 @@ contract MatchFulfillmentHelperTest is BaseOrderTest { Fulfillment({ offerComponents: SeaportArrays.FulfillmentComponents( FulfillmentComponent({ orderIndex: 1, itemIndex: 0 }) - ), - considerationComponents: SeaportArrays.FulfillmentComponents( - FulfillmentComponent({ orderIndex: 0, itemIndex: 0 }), - FulfillmentComponent({ orderIndex: 2, itemIndex: 0 }) + ), + considerationComponents: SeaportArrays + .FulfillmentComponents( + FulfillmentComponent({ + orderIndex: 0, + itemIndex: 0 + }), + FulfillmentComponent({ + orderIndex: 2, + itemIndex: 0 + }) ) }), Fulfillment({ offerComponents: SeaportArrays.FulfillmentComponents( FulfillmentComponent({ orderIndex: 3, itemIndex: 0 }) - ), - considerationComponents: SeaportArrays.FulfillmentComponents( - FulfillmentComponent({ orderIndex: 0, itemIndex: 0 }) + ), + considerationComponents: SeaportArrays + .FulfillmentComponents( + FulfillmentComponent({ + orderIndex: 0, + itemIndex: 0 + }) ) }), Fulfillment({ offerComponents: SeaportArrays.FulfillmentComponents( FulfillmentComponent({ orderIndex: 0, itemIndex: 0 }) - ), - considerationComponents: SeaportArrays.FulfillmentComponents( - FulfillmentComponent({ orderIndex: 1, itemIndex: 0 }), - FulfillmentComponent({ orderIndex: 3, itemIndex: 0 }) + ), + considerationComponents: SeaportArrays + .FulfillmentComponents( + FulfillmentComponent({ + orderIndex: 1, + itemIndex: 0 + }), + FulfillmentComponent({ + orderIndex: 3, + itemIndex: 0 + }) ) }), Fulfillment({ offerComponents: SeaportArrays.FulfillmentComponents( FulfillmentComponent({ orderIndex: 2, itemIndex: 0 }) - ), - considerationComponents: SeaportArrays.FulfillmentComponents( - FulfillmentComponent({ orderIndex: 1, itemIndex: 0 }) + ), + considerationComponents: SeaportArrays + .FulfillmentComponents( + FulfillmentComponent({ + orderIndex: 1, + itemIndex: 0 + }) ) }) ); @@ -1241,42 +1578,61 @@ contract MatchFulfillmentHelperTest is BaseOrderTest { bytes32[] memory orderHashes = new bytes32[](4); - (Fulfillment[] memory fulfillments,,) = matcher.getMatchedFulfillments( - SeaportArrays.Orders( - orderOne, otherOrderOne, orderTwo, otherOrderTwo - ), - orderHashes, - new UnavailableReason[](4) - ); + (Fulfillment[] memory fulfillments, , ) = matcher + .getMatchedFulfillments( + SeaportArrays.Orders( + orderOne, + otherOrderOne, + orderTwo, + otherOrderTwo + ), + orderHashes, + new UnavailableReason[](4) + ); if (!useDifferentConduitsBetweenOrderPairs) { assertEq(fulfillments.length, 2, "fulfillments.length"); assertEq( - fulfillments[0], expectedFulfillments[0], "fulfillments[0]" + fulfillments[0], + expectedFulfillments[0], + "fulfillments[0]" ); assertEq( - fulfillments[1], expectedFulfillments[1], "fulfillments[1]" + fulfillments[1], + expectedFulfillments[1], + "fulfillments[1]" ); } else { assertEq(fulfillments.length, 4, "fulfillments.length"); assertEq( - fulfillments[0], expectedFulfillments[0], "fulfillments[0]" + fulfillments[0], + expectedFulfillments[0], + "fulfillments[0]" ); assertEq( - fulfillments[1], expectedFulfillments[1], "fulfillments[1]" + fulfillments[1], + expectedFulfillments[1], + "fulfillments[1]" ); assertEq( - fulfillments[2], expectedFulfillments[2], "fulfillments[2]" + fulfillments[2], + expectedFulfillments[2], + "fulfillments[2]" ); assertEq( - fulfillments[3], expectedFulfillments[3], "fulfillments[3]" + fulfillments[3], + expectedFulfillments[3], + "fulfillments[3]" ); } seaport.matchOrders({ orders: SeaportArrays.Orders( - orderOne, otherOrderOne, orderTwo, otherOrderTwo - ), + orderOne, + otherOrderOne, + orderTwo, + otherOrderTwo + ), fulfillments: fulfillments }); } @@ -1290,91 +1646,118 @@ contract MatchFulfillmentHelperTest is BaseOrderTest { bool useDifferentConduits ) public { Order memory order = Order({ - parameters: OrderParametersLib.empty().withOffer( - SeaportArrays.OfferItems( - OfferItemLib.empty().withToken(address(erc20s[0])).withAmount( - 90 - ), - OfferItemLib.empty().withToken(address(erc20s[1])).withAmount( - 10 + parameters: OrderParametersLib + .empty() + .withOffer( + SeaportArrays.OfferItems( + OfferItemLib + .empty() + .withToken(address(erc20s[0])) + .withAmount(90), + OfferItemLib + .empty() + .withToken(address(erc20s[1])) + .withAmount(10) ) ) - ).withConsideration( + .withConsideration( SeaportArrays.ConsiderationItems( - ConsiderationItemLib.empty().withToken(address(erc20s[0])) + ConsiderationItemLib + .empty() + .withToken(address(erc20s[0])) .withAmount(10), - ConsiderationItemLib.empty().withToken(address(erc20s[0])) + ConsiderationItemLib + .empty() + .withToken(address(erc20s[0])) .withAmount(90), - ConsiderationItemLib.empty().withToken(address(erc20s[0])) + ConsiderationItemLib + .empty() + .withToken(address(erc20s[0])) .withAmount(10) ) - ).withOfferer(offerer1.addr), + ) + .withOfferer(offerer1.addr), signature: "" }); - order = _toMatchableOrder(order, offerer1, useDifferentConduits ? 1 : 0); + order = _toMatchableOrder( + order, + offerer1, + useDifferentConduits ? 1 : 0 + ); Order memory otherOrder = Order({ - parameters: OrderParametersLib.empty().withOffer( - SeaportArrays.OfferItems( - OfferItemLib.empty().withToken(address(erc20s[0])).withAmount( - 30 + parameters: OrderParametersLib + .empty() + .withOffer( + SeaportArrays.OfferItems( + OfferItemLib + .empty() + .withToken(address(erc20s[0])) + .withAmount(30) ) ) - ).withConsideration( + .withConsideration( SeaportArrays.ConsiderationItems( - ConsiderationItemLib.empty().withToken(address(erc20s[1])) + ConsiderationItemLib + .empty() + .withToken(address(erc20s[1])) .withAmount(10) ) - ).withOfferer(offerer2.addr), + ) + .withOfferer(offerer2.addr), signature: "" }); if (useDifferentConduits) { - otherOrder.parameters = - otherOrder.parameters.withConduitKey(conduitKey); + otherOrder.parameters = otherOrder.parameters.withConduitKey( + conduitKey + ); } otherOrder = _toMatchableOrder( - otherOrder, offerer2, useDifferentConduits ? 2 : 0 + otherOrder, + offerer2, + useDifferentConduits ? 2 : 0 ); Fulfillment[] memory expectedFulfillments = SeaportArrays.Fulfillments( Fulfillment({ offerComponents: SeaportArrays.FulfillmentComponents( FulfillmentComponent({ orderIndex: 0, itemIndex: 0 }) - ), + ), considerationComponents: SeaportArrays.FulfillmentComponents( FulfillmentComponent({ orderIndex: 0, itemIndex: 0 }), FulfillmentComponent({ orderIndex: 0, itemIndex: 1 }), FulfillmentComponent({ orderIndex: 0, itemIndex: 2 }) - ) + ) }), Fulfillment({ offerComponents: SeaportArrays.FulfillmentComponents( FulfillmentComponent({ orderIndex: 1, itemIndex: 0 }) - ), + ), considerationComponents: SeaportArrays.FulfillmentComponents( FulfillmentComponent({ orderIndex: 0, itemIndex: 0 }) - ) + ) }), Fulfillment({ offerComponents: SeaportArrays.FulfillmentComponents( FulfillmentComponent({ orderIndex: 0, itemIndex: 1 }) - ), + ), considerationComponents: SeaportArrays.FulfillmentComponents( FulfillmentComponent({ orderIndex: 1, itemIndex: 0 }) - ) + ) }) ); bytes32[] memory orderHashes = new bytes32[](2); - (Fulfillment[] memory fulfillments,,) = matcher.getMatchedFulfillments( - SeaportArrays.Orders(order, otherOrder), - orderHashes, - new UnavailableReason[](2) - ); + (Fulfillment[] memory fulfillments, , ) = matcher + .getMatchedFulfillments( + SeaportArrays.Orders(order, otherOrder), + orderHashes, + new UnavailableReason[](2) + ); assertEq(fulfillments.length, 3, "fulfillments.length"); assertEq(fulfillments[0], expectedFulfillments[0], "fulfillments[0]"); @@ -1389,24 +1772,35 @@ contract MatchFulfillmentHelperTest is BaseOrderTest { function testRemainingItems_availableOrder() public { Order memory order1 = Order({ - parameters: OrderParametersLib.empty().withStartTime(block.timestamp) - .withEndTime(block.timestamp + 1).withOffer( - SeaportArrays.OfferItems( - OfferItemLib.empty().withToken(address(erc20s[0])).withAmount( - 10 - ), - OfferItemLib.empty().withToken(address(erc20s[0])).withAmount( - 11 + parameters: OrderParametersLib + .empty() + .withStartTime(block.timestamp) + .withEndTime(block.timestamp + 1) + .withOffer( + SeaportArrays.OfferItems( + OfferItemLib + .empty() + .withToken(address(erc20s[0])) + .withAmount(10), + OfferItemLib + .empty() + .withToken(address(erc20s[0])) + .withAmount(11) ) ) - ).withTotalConsideration( + .withTotalConsideration( SeaportArrays.ConsiderationItems( - ConsiderationItemLib.empty().withToken(address(erc20s[1])) + ConsiderationItemLib + .empty() + .withToken(address(erc20s[1])) .withAmount(1), - ConsiderationItemLib.empty().withToken(address(erc20s[1])) + ConsiderationItemLib + .empty() + .withToken(address(erc20s[1])) .withAmount(2) ) - ).withOfferer(offerer1.addr), + ) + .withOfferer(offerer1.addr), signature: "" }); @@ -1419,27 +1813,37 @@ contract MatchFulfillmentHelperTest is BaseOrderTest { MatchComponent[] memory remainingOffer, MatchComponent[] memory remainingConsideration ) = matcher.getMatchedFulfillments( - SeaportArrays.Orders(order1), - orderHashes, - new UnavailableReason[](1) - ); + SeaportArrays.Orders(order1), + orderHashes, + new UnavailableReason[](1) + ); assertEq(remainingOffer.length, 2, "remainingOffer.length"); assertEq( - remainingConsideration.length, 2, "remainingConsideration.length" + remainingConsideration.length, + 2, + "remainingConsideration.length" ); assertEq( - remainingOffer[0].getOrderIndex(), 0, "remainingOffer[0].orderIndex" + remainingOffer[0].getOrderIndex(), + 0, + "remainingOffer[0].orderIndex" ); assertEq( - remainingOffer[0].getItemIndex(), 0, "remainingOffer[0].itemIndex" + remainingOffer[0].getItemIndex(), + 0, + "remainingOffer[0].itemIndex" ); assertEq(remainingOffer[0].getAmount(), 10, "remainingOffer[0].amount"); assertEq( - remainingOffer[1].getOrderIndex(), 0, "remainingOffer[1].orderIndex" + remainingOffer[1].getOrderIndex(), + 0, + "remainingOffer[1].orderIndex" ); assertEq( - remainingOffer[1].getItemIndex(), 1, "remainingOffer[1].itemIndex" + remainingOffer[1].getItemIndex(), + 1, + "remainingOffer[1].itemIndex" ); assertEq(remainingOffer[1].getAmount(), 11, "remainingOffer[1].amount"); @@ -1477,23 +1881,33 @@ contract MatchFulfillmentHelperTest is BaseOrderTest { function testRemainingItems_unavailableOrder() public { Order memory order1 = Order({ - parameters: OrderParametersLib.empty().withOffer( - SeaportArrays.OfferItems( - OfferItemLib.empty().withToken(address(erc20s[0])).withAmount( - 10 - ), - OfferItemLib.empty().withToken(address(erc20s[0])).withAmount( - 11 + parameters: OrderParametersLib + .empty() + .withOffer( + SeaportArrays.OfferItems( + OfferItemLib + .empty() + .withToken(address(erc20s[0])) + .withAmount(10), + OfferItemLib + .empty() + .withToken(address(erc20s[0])) + .withAmount(11) ) ) - ).withTotalConsideration( + .withTotalConsideration( SeaportArrays.ConsiderationItems( - ConsiderationItemLib.empty().withToken(address(erc20s[1])) + ConsiderationItemLib + .empty() + .withToken(address(erc20s[1])) .withAmount(1), - ConsiderationItemLib.empty().withToken(address(erc20s[1])) + ConsiderationItemLib + .empty() + .withToken(address(erc20s[1])) .withAmount(2) ) - ).withOfferer(offerer1.addr), + ) + .withOfferer(offerer1.addr), signature: "" }); @@ -1506,10 +1920,10 @@ contract MatchFulfillmentHelperTest is BaseOrderTest { MatchComponent[] memory remainingOffer, MatchComponent[] memory remainingConsideration ) = matcher.getMatchedFulfillments( - SeaportArrays.Orders(order1), - orderHashes, - new UnavailableReason[](1) - ); + SeaportArrays.Orders(order1), + orderHashes, + new UnavailableReason[](1) + ); assertEq(remainingOffer.length, 0); assertEq(remainingConsideration.length, 0); @@ -1571,28 +1985,37 @@ contract MatchFulfillmentHelperTest is BaseOrderTest { uint256 salt ) internal view returns (Order memory) { for (uint256 i = 0; i < order.parameters.offer.length; i++) { - order.parameters.offer[i] = - order.parameters.offer[i].copy().withItemType(ItemType.ERC20); + order.parameters.offer[i] = order + .parameters + .offer[i] + .copy() + .withItemType(ItemType.ERC20); } for (uint256 i = 0; i < order.parameters.consideration.length; i++) { - order.parameters.consideration[i] = order.parameters.consideration[i] - .copy().withItemType(ItemType.ERC20); + order.parameters.consideration[i] = order + .parameters + .consideration[i] + .copy() + .withItemType(ItemType.ERC20); } - OrderParameters memory parameters = order.parameters.copy().withOfferer( - offerer.addr - ).withStartTime(block.timestamp).withEndTime(block.timestamp + 1) + OrderParameters memory parameters = order + .parameters + .copy() + .withOfferer(offerer.addr) + .withStartTime(block.timestamp) + .withEndTime(block.timestamp + 1) .withTotalOriginalConsiderationItems( - order.parameters.consideration.length - ) - // Bump the end time by 100 so that the test doesn't try to match the - // same order twice. + order.parameters.consideration.length + ) .withSalt(salt); + // Bump the end time by 100 so that the test doesn't try to match the + // same order twice. - OrderComponents memory orderComponents = parameters.toOrderComponents( - seaport.getCounter(offerer.addr) - ).withCounter(seaport.getCounter(offerer.addr)); + OrderComponents memory orderComponents = parameters + .toOrderComponents(seaport.getCounter(offerer.addr)) + .withCounter(seaport.getCounter(offerer.addr)); bytes32 orderHash = seaport.getOrderHash(orderComponents); diff --git a/test/foundry/new/helpers/sol/MatchFulfillmentPriv.t.sol b/test/foundry/new/helpers/sol/MatchFulfillmentPriv.t.sol index e22da77..4ed727d 100644 --- a/test/foundry/new/helpers/sol/MatchFulfillmentPriv.t.sol +++ b/test/foundry/new/helpers/sol/MatchFulfillmentPriv.t.sol @@ -50,8 +50,8 @@ contract MatchFulfillmentLibTest is Test { // copy to dynamic array MatchComponent[] memory toBeSorted = new MatchComponent[](10); for (uint256 i = 0; i < 10; i++) { - MatchComponent memory temp = - MatchComponentType.createMatchComponent(amounts[i], 0, 0); + MatchComponent memory temp = MatchComponentType + .createMatchComponent(amounts[i], 0, 0); toBeSorted[i] = temp; } // sort dynamic array in-place @@ -62,7 +62,8 @@ contract MatchFulfillmentLibTest is Test { } // call function MatchFulfillmentLib.consolidateComponents( - _components, _components.length + _components, + _components.length ); assertLt(_components.length, 2, "consolidateComponents length"); for (uint256 i; i < _components.length; ++i) { @@ -71,8 +72,8 @@ contract MatchFulfillmentLibTest is Test { } function testProcessOfferComponent() public { - FulfillmentComponent[] memory offerFulfillmentComponents = - MatchArrays.allocateFulfillmentComponents(2); + FulfillmentComponent[] memory offerFulfillmentComponents = MatchArrays + .allocateFulfillmentComponents(2); offer.push(MatchComponentType.createMatchComponent(1, 0, 0)); consideration.push(MatchComponentType.createMatchComponent(1, 0, 0)); @@ -85,7 +86,9 @@ contract MatchFulfillmentLibTest is Test { }); MatchFulfillmentLib.processOfferComponent(offer, consideration, params); assertEq( - params.offerItemIndex, 1, "processOfferComponent offerItemIndex" + params.offerItemIndex, + 1, + "processOfferComponent offerItemIndex" ); assertEq( offer[0].getAmount(), @@ -103,8 +106,9 @@ contract MatchFulfillmentLibTest is Test { "offerFulfillmentComponents length" ); - offerFulfillmentComponents = - MatchArrays.allocateFulfillmentComponents(2); + offerFulfillmentComponents = MatchArrays.allocateFulfillmentComponents( + 2 + ); consideration[0] = MatchComponentType.createMatchComponent(2, 0, 0); offer[0] = MatchComponentType.createMatchComponent(1, 0, 0); params = ProcessComponentParams({ @@ -116,7 +120,9 @@ contract MatchFulfillmentLibTest is Test { }); MatchFulfillmentLib.processOfferComponent(offer, consideration, params); assertEq( - params.offerItemIndex, 1, "processOfferComponent offerItemIndex" + params.offerItemIndex, + 1, + "processOfferComponent offerItemIndex" ); assertEq( offer[0].getAmount(), @@ -134,8 +140,9 @@ contract MatchFulfillmentLibTest is Test { "offerFulfillmentComponents length" ); - offerFulfillmentComponents = - MatchArrays.allocateFulfillmentComponents(2); + offerFulfillmentComponents = MatchArrays.allocateFulfillmentComponents( + 2 + ); consideration[0] = MatchComponentType.createMatchComponent(1, 0, 0); offer[0] = MatchComponentType.createMatchComponent(2, 0, 0); params = ProcessComponentParams({ @@ -147,7 +154,9 @@ contract MatchFulfillmentLibTest is Test { }); MatchFulfillmentLib.processOfferComponent(offer, consideration, params); assertEq( - params.offerItemIndex, 0, "processOfferComponent offerItemIndex" + params.offerItemIndex, + 0, + "processOfferComponent offerItemIndex" ); assertEq( params.offerFulfillmentComponents.length, @@ -166,8 +175,9 @@ contract MatchFulfillmentLibTest is Test { ); assertEq(params.offerFulfillmentComponents.length, 1); - offerFulfillmentComponents = - MatchArrays.allocateFulfillmentComponents(2); + offerFulfillmentComponents = MatchArrays.allocateFulfillmentComponents( + 2 + ); consideration[0] = MatchComponentType.createMatchComponent(1, 0, 0); offer[0] = MatchComponentType.createMatchComponent(1, 0, 0); @@ -180,20 +190,25 @@ contract MatchFulfillmentLibTest is Test { }); MatchFulfillmentLib.processOfferComponent(offer, consideration, params); assertEq( - consideration[0].getAmount(), 0, "consideration[0].getAmount() 4" + consideration[0].getAmount(), + 0, + "consideration[0].getAmount() 4" ); assertEq(offer[0].getAmount(), 0, "offer[0].getAmount()"); assertEq( - params.offerItemIndex, 1, "processOfferComponent offerItemIndex" + params.offerItemIndex, + 1, + "processOfferComponent offerItemIndex" ); assertEq(params.offerFulfillmentComponents.length, 1); } function testProcessConsiderationComponents() public { - FulfillmentComponent[] memory offerFulfillmentComponents = - MatchArrays.allocateFulfillmentComponents(2); - FulfillmentComponent[] memory considerationFulfillmentComponents = - MatchArrays.allocateFulfillmentComponents(2); + FulfillmentComponent[] memory offerFulfillmentComponents = MatchArrays + .allocateFulfillmentComponents(2); + FulfillmentComponent[] + memory considerationFulfillmentComponents = MatchArrays + .allocateFulfillmentComponents(2); offer.push(MatchComponentType.createMatchComponent(1, 0, 0)); consideration.push(MatchComponentType.createMatchComponent(1, 0, 0)); ProcessComponentParams memory params = ProcessComponentParams({ @@ -204,7 +219,9 @@ contract MatchFulfillmentLibTest is Test { midCredit: false }); MatchFulfillmentLib.processConsiderationComponent( - offer, consideration, params + offer, + consideration, + params ); assertEq( params.offerItemIndex, @@ -233,7 +250,9 @@ contract MatchFulfillmentLibTest is Test { midCredit: false }); MatchFulfillmentLib.processConsiderationComponent( - offer, consideration, params + offer, + consideration, + params ); assertEq( params.offerItemIndex, @@ -262,7 +281,9 @@ contract MatchFulfillmentLibTest is Test { midCredit: false }); MatchFulfillmentLib.processConsiderationComponent( - offer, consideration, params + offer, + consideration, + params ); assertEq( params.offerItemIndex, @@ -294,7 +315,9 @@ contract MatchFulfillmentLibTest is Test { // considerationFulfillmentIndex: 0 MatchFulfillmentLib.processConsiderationComponent( - offer, consideration, params + offer, + consideration, + params ); assertEq( params.offerItemIndex, @@ -309,13 +332,14 @@ contract MatchFulfillmentLibTest is Test { } } - function assertEq(MatchComponent memory left, MatchComponent memory right) - internal - { - FulfillmentComponent memory leftComponent = - left.toFulfillmentComponent(); - FulfillmentComponent memory rightComponent = - right.toFulfillmentComponent(); + function assertEq( + MatchComponent memory left, + MatchComponent memory right + ) internal { + FulfillmentComponent memory leftComponent = left + .toFulfillmentComponent(); + FulfillmentComponent memory rightComponent = right + .toFulfillmentComponent(); assertEq(leftComponent, rightComponent, "component"); assertEq(left.getAmount(), right.getAmount(), "amount"); } diff --git a/test/foundry/new/helpers/sol/lib/fulfillment/AmountDeriverHelper.t.sol b/test/foundry/new/helpers/sol/lib/fulfillment/AmountDeriverHelper.t.sol index 44ae643..881395a 100644 --- a/test/foundry/new/helpers/sol/lib/fulfillment/AmountDeriverHelper.t.sol +++ b/test/foundry/new/helpers/sol/lib/fulfillment/AmountDeriverHelper.t.sol @@ -2,8 +2,9 @@ pragma solidity ^0.8.17; import { Test } from "forge-std/Test.sol"; -import { AmountDeriverHelper } from - "seaport-sol/src/lib/fulfillment/AmountDeriverHelper.sol"; +import { + AmountDeriverHelper +} from "seaport-sol/src/lib/fulfillment/AmountDeriverHelper.sol"; contract TestAmountDeriverHelper is AmountDeriverHelper { function applyFraction( @@ -15,27 +16,29 @@ contract TestAmountDeriverHelper is AmountDeriverHelper { uint256 endAmount, bool roundUp ) public view returns (uint256) { - return _applyFraction({ - numerator: numerator, - denominator: denominator, - startAmount: startAmount, - endAmount: endAmount, - startTime: startTime, - endTime: endTime, - roundUp: roundUp // round up considerations - }); + return + _applyFraction({ + numerator: numerator, + denominator: denominator, + startAmount: startAmount, + endAmount: endAmount, + startTime: startTime, + endTime: endTime, + roundUp: roundUp // round up considerations + }); } - function getFraction(uint256 numerator, uint256 denominator, uint256 value) - public - pure - returns (uint256) - { - return _getFraction({ - numerator: numerator, - denominator: denominator, - value: value - }); + function getFraction( + uint256 numerator, + uint256 denominator, + uint256 value + ) public pure returns (uint256) { + return + _getFraction({ + numerator: numerator, + denominator: denominator, + value: value + }); } function locateCurrentAmount( @@ -45,13 +48,14 @@ contract TestAmountDeriverHelper is AmountDeriverHelper { uint256 endTime, bool roundUp ) public view returns (uint256) { - return _locateCurrentAmount({ - startAmount: startAmount, - endAmount: endAmount, - startTime: startTime, - endTime: endTime, - roundUp: roundUp - }); + return + _locateCurrentAmount({ + startAmount: startAmount, + endAmount: endAmount, + startTime: startTime, + endTime: endTime, + roundUp: roundUp + }); } } @@ -86,21 +90,23 @@ contract AmountDeriverHelperTest is Test { startTime = bound(startTime, 1, type(uint40).max - 2); endTime = bound(endTime, startTime + 1, type(uint40).max); - (numerator, denominator) = - coerceNumeratorAndDenominator(numerator, denominator); + (numerator, denominator) = coerceNumeratorAndDenominator( + numerator, + denominator + ); originalStartAmount = bound(originalStartAmount, 1, type(uint256).max); originalEndAmount = bound(originalEndAmount, 1, type(uint256).max); (uint256 newStartAmount, uint256 newEndAmount) = helper .deriveFractionCompatibleAmounts( - originalStartAmount, - originalEndAmount, - startTime, - endTime, - numerator, - denominator - ); + originalStartAmount, + originalEndAmount, + startTime, + endTime, + numerator, + denominator + ); currentTime = bound(currentTime, startTime, endTime - 1); diff --git a/test/foundry/new/helpers/sol/lib/types/MatchComponentType.t.sol b/test/foundry/new/helpers/sol/lib/types/MatchComponentType.t.sol index 5d41875..937791e 100644 --- a/test/foundry/new/helpers/sol/lib/types/MatchComponentType.t.sol +++ b/test/foundry/new/helpers/sol/lib/types/MatchComponentType.t.sol @@ -12,14 +12,14 @@ contract MatchComponentTypeTest is Test { using MatchComponentType for MatchComponent; function testCreateGetAndUnpack() public { - MatchComponent memory component = - MatchComponentType.createMatchComponent(1, 2, 3); + MatchComponent memory component = MatchComponentType + .createMatchComponent(1, 2, 3); assertEq(component.getAmount(), 1, "amount"); assertEq(component.getOrderIndex(), 2, "orderIndex"); assertEq(component.getItemIndex(), 3, "itemIndex"); - (uint256 amount, uint256 orderIndex, uint256 itemIndex) = - component.unpack(); + (uint256 amount, uint256 orderIndex, uint256 itemIndex) = component + .unpack(); assertEq(amount, 1, "unpacked amount"); assertEq(orderIndex, 2, "unpacked orderIndex"); assertEq(itemIndex, 3, "unpacked itemIndex"); @@ -47,8 +47,8 @@ contract MatchComponentTypeTest is Test { } function testSetters() public { - MatchComponent memory component = - MatchComponentType.createMatchComponent(1, 2, 3); + MatchComponent memory component = MatchComponentType + .createMatchComponent(1, 2, 3); MatchComponent memory newComponent = component.setAmount(4); assertEq(newComponent.getAmount(), 4, "amount"); @@ -66,11 +66,13 @@ contract MatchComponentTypeTest is Test { assertEq(newComponent.getItemIndex(), 6, "itemIndex"); } - function testSetters(uint240 amount, uint8 orderIndex, uint8 itemIndex) - public - { - MatchComponent memory component = - MatchComponentType.createMatchComponent(1, 2, 3); + function testSetters( + uint240 amount, + uint8 orderIndex, + uint8 itemIndex + ) public { + MatchComponent memory component = MatchComponentType + .createMatchComponent(1, 2, 3); MatchComponent memory newComponent = component.setAmount(amount); assertEq(newComponent.getAmount(), amount, "amount"); diff --git a/test/foundry/new/zones/ValidationOffererZone.sol b/test/foundry/new/zones/ValidationOffererZone.sol index ea95b6f..47357f2 100644 --- a/test/foundry/new/zones/ValidationOffererZone.sol +++ b/test/foundry/new/zones/ValidationOffererZone.sol @@ -10,8 +10,9 @@ import { ZoneParameters } from "seaport-sol/src/SeaportStructs.sol"; -import { ContractOffererInterface } from - "seaport-types/src/interfaces/ContractOffererInterface.sol"; +import { + ContractOffererInterface +} from "seaport-types/src/interfaces/ContractOffererInterface.sol"; import { ZoneInterface } from "seaport-types/src/interfaces/ZoneInterface.sol"; @@ -24,13 +25,11 @@ contract ValidationOffererZone is ContractOffererInterface, ZoneInterface { expectedMaxSpentAmount = expectedMax; } - receive() external payable { } + receive() external payable {} - function authorizeOrder(ZoneParameters calldata) - public - pure - returns (bytes4) - { + function authorizeOrder( + ZoneParameters calldata + ) public pure returns (bytes4) { return this.authorizeOrder.selector; } @@ -42,12 +41,9 @@ contract ValidationOffererZone is ContractOffererInterface, ZoneInterface { * * @return validOrderMagicValue The magic value to indicate things are OK. */ - function validateOrder(ZoneParameters calldata zoneParameters) - external - view - override - returns (bytes4 validOrderMagicValue) - { + function validateOrder( + ZoneParameters calldata zoneParameters + ) external view override returns (bytes4 validOrderMagicValue) { validate(zoneParameters.fulfiller, zoneParameters.offer); // Return the selector of validateOrder as the magic value. @@ -91,11 +87,9 @@ contract ValidationOffererZone is ContractOffererInterface, ZoneInterface { return (a, _convertSpentToReceived(b)); } - function _convertSpentToReceived(SpentItem[] calldata spentItems) - internal - view - returns (ReceivedItem[] memory) - { + function _convertSpentToReceived( + SpentItem[] calldata spentItems + ) internal view returns (ReceivedItem[] memory) { ReceivedItem[] memory receivedItems = new ReceivedItem[]( spentItems.length ); @@ -105,38 +99,39 @@ contract ValidationOffererZone is ContractOffererInterface, ZoneInterface { return receivedItems; } - function _convertSpentToReceived(SpentItem calldata spentItem) - internal - view - returns (ReceivedItem memory) - { - return ReceivedItem({ - itemType: spentItem.itemType, - token: spentItem.token, - identifier: spentItem.identifier, - amount: spentItem.amount, - recipient: payable(address(this)) - }); + function _convertSpentToReceived( + SpentItem calldata spentItem + ) internal view returns (ReceivedItem memory) { + return + ReceivedItem({ + itemType: spentItem.itemType, + token: spentItem.token, + identifier: spentItem.identifier, + amount: spentItem.amount, + recipient: payable(address(this)) + }); } function ratifyOrder( - SpentItem[] calldata spentItems, /* offer */ - ReceivedItem[] calldata, /* consideration */ - bytes calldata, /* context */ - bytes32[] calldata, /* orderHashes */ + SpentItem[] calldata spentItems /* offer */, + ReceivedItem[] calldata /* consideration */, + bytes calldata /* context */, + bytes32[] calldata /* orderHashes */, uint256 /* contractNonce */ - ) external view override returns (bytes4 /* ratifyOrderMagicValue */ ) { + ) external view override returns (bytes4 /* ratifyOrderMagicValue */) { validate(address(0), spentItems); return ValidationOffererZone.ratifyOrder.selector; } - function validate(address fulfiller, SpentItem[] calldata offer) - internal - view - { + function validate( + address fulfiller, + SpentItem[] calldata offer + ) internal view { if (offer[0].amount > expectedMaxSpentAmount) { revert IncorrectSpentAmount( - fulfiller, bytes32(offer[0].amount), expectedMaxSpentAmount + fulfiller, + bytes32(offer[0].amount), + expectedMaxSpentAmount ); } } @@ -154,14 +149,17 @@ contract ValidationOffererZone is ContractOffererInterface, ZoneInterface { schemas[0].metadata = new bytes(0); } - function supportsInterface(bytes4 interfaceId) + function supportsInterface( + bytes4 interfaceId + ) public view virtual override(ContractOffererInterface, ZoneInterface) returns (bool) { - return interfaceId == type(ContractOffererInterface).interfaceId - || interfaceId == type(ZoneInterface).interfaceId; + return + interfaceId == type(ContractOffererInterface).interfaceId || + interfaceId == type(ZoneInterface).interfaceId; } }