diff --git a/.c8rc b/.c8rc index 049df4ad..ac9275ea 100644 --- a/.c8rc +++ b/.c8rc @@ -1,5 +1,5 @@ { "reporter": ["lcov", "text"], "src": ["src"], - "exclude": ["hardhat.config.ts", "src/__tests__/*", "src/abi/*"] + "exclude": ["hardhat.config.ts", "src/abi/*"] } diff --git a/hardhat.config.ts b/hardhat.config.ts index 6e6fe3b1..4538c9c4 100644 --- a/hardhat.config.ts +++ b/hardhat.config.ts @@ -43,7 +43,7 @@ const config: HardhatUserConfig = { target: "ethers-v5", }, paths: { - tests: "src/__tests__", + tests: "test", artifacts: "src/artifacts", sources: "src/contracts", }, diff --git a/package.json b/package.json index d2bf1988..c1f71845 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ }, "scripts": { "build": "hardhat compile && tsc -p tsconfig.build.json", - "check-types": "tsc --noEmit -p src/__tests__/tsconfig.json", + "check-types": "tsc --noEmit ", "check-types:incremental": "npm run check-types --incremental", "coverage": "c8 yarn test", "eslint:check": "eslint . --max-warnings 0 --ext .js,.jsx,.ts,.tsx", diff --git a/src/__tests__/tsconfig.json b/src/__tests__/tsconfig.json deleted file mode 100644 index 2a5567d8..00000000 --- a/src/__tests__/tsconfig.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "extends": "../../tsconfig.json", - "compilerOptions": { - "rootDir": "../../" - }, - "files": ["../../hardhat.config.ts"] -} diff --git a/src/seaport.ts b/src/seaport.ts index e45f3332..61d3f2d6 100644 --- a/src/seaport.ts +++ b/src/seaport.ts @@ -65,7 +65,6 @@ import { deductFees, feeToConsiderationItem, generateRandomSalt, - generateRandomSaltWithDomain, mapInputItemToOfferItem, totalItemsAmount, } from "./utils/order"; @@ -356,8 +355,9 @@ export class Seaport { ]; const saltFollowingConditional = - salt || - (domain ? generateRandomSaltWithDomain(domain) : generateRandomSalt()); + salt !== undefined + ? `0x${BigNumber.from(salt).toHexString().slice(2).padStart(64, "0")}` + : generateRandomSalt(domain); const orderComponents: OrderComponents = { offerer, @@ -739,7 +739,10 @@ export class Seaport { .slice(2) .padStart(64, "0"), orderComponents.zoneHash.slice(2), - orderComponents.salt.slice(2).padStart(64, "0"), + BigNumber.from(orderComponents.salt) + .toHexString() + .slice(2) + .padStart(64, "0"), orderComponents.conduitKey.slice(2).padStart(64, "0"), ethers.BigNumber.from(orderComponents.counter) .toHexString() @@ -781,7 +784,7 @@ export class Seaport { accountAddress, conduitKey = this.defaultConduitKey, recipientAddress = ethers.constants.AddressZero, - domain = "", + domain, exactApproval = false, }: { order: OrderWithCounter; @@ -939,7 +942,7 @@ export class Seaport { accountAddress, conduitKey = this.defaultConduitKey, recipientAddress = ethers.constants.AddressZero, - domain = "", + domain, exactApproval = false, }: { fulfillOrderDetails: { @@ -1066,7 +1069,7 @@ export class Seaport { fulfillments, overrides, accountAddress, - domain = "", + domain, }: { orders: (OrderWithCounter | Order)[]; fulfillments: MatchOrdersFulfillment[]; diff --git a/src/types.ts b/src/types.ts index 6dfb547c..7e933603 100644 --- a/src/types.ts +++ b/src/types.ts @@ -159,17 +159,16 @@ export type Fee = { export type CreateOrderInput = { conduitKey?: string; zone?: string; - startTime?: string; - endTime?: string; + startTime?: BigNumberish; + endTime?: BigNumberish; offer: readonly CreateInputItem[]; consideration: readonly ConsiderationInputItem[]; counter?: BigNumberish; fees?: readonly Fee[]; allowPartialFills?: boolean; restrictedByZone?: boolean; - useProxy?: boolean; domain?: string; - salt?: string; + salt?: BigNumberish; }; export type InputCriteria = { diff --git a/src/utils/order.ts b/src/utils/order.ts index 196d1ebb..54d54461 100644 --- a/src/utils/order.ts +++ b/src/utils/order.ts @@ -272,18 +272,17 @@ export const mapOrderAmountsFromUnitsToFill = ( }; }; -export const generateRandomSalt = () => { - return `0x${Buffer.from(randomBytes(8)).toString("hex").padStart(24, "0")}`; -}; - -export const generateRandomSaltWithDomain = (domain: string) => { - return `0x${Buffer.from( - concat([ - keccak256(toUtf8Bytes(domain)).slice(0, 10), - Uint8Array.from(Array(20).fill(0)), - randomBytes(8), - ]) - ).toString("hex")}`; +export const generateRandomSalt = (domain?: string) => { + if (domain) { + return `0x${Buffer.from( + concat([ + keccak256(toUtf8Bytes(domain)).slice(0, 10), + Uint8Array.from(Array(20).fill(0)), + randomBytes(8), + ]) + ).toString("hex")}`; + } + return `0x${Buffer.from(randomBytes(8)).toString("hex").padStart(64, "0")}`; }; export const shouldUseMatchForFulfill = () => true; diff --git a/src/utils/usecase.ts b/src/utils/usecase.ts index d591db83..b71fe49d 100644 --- a/src/utils/usecase.ts +++ b/src/utils/usecase.ts @@ -68,7 +68,7 @@ export const getTransactionMethods = < contract: T, method: U, args: Parameters, - domain: string = "" + domain?: string ): TransactionMethods> => { const lastArg = args[args.length - 1]; diff --git a/src/__tests__/ascending-descending-amounts.spec.ts b/test/ascending-descending-amounts.spec.ts similarity index 98% rename from src/__tests__/ascending-descending-amounts.spec.ts rename to test/ascending-descending-amounts.spec.ts index 5a8022fc..637a530f 100644 --- a/src/__tests__/ascending-descending-amounts.spec.ts +++ b/test/ascending-descending-amounts.spec.ts @@ -4,11 +4,11 @@ import { expect } from "chai"; import { BigNumber } from "ethers"; import { parseEther } from "ethers/lib/utils"; import { ethers } from "hardhat"; -import { ItemType, MAX_INT, OrderType } from "../constants"; -import { CreateOrderInput, CurrencyItem } from "../types"; -import * as fulfill from "../utils/fulfill"; -import { generateRandomSalt } from "../utils/order"; -import { getTagFromDomain } from "../utils/usecase"; +import { ItemType, MAX_INT, OrderType } from "../src/constants"; +import { CreateOrderInput, CurrencyItem } from "../src/types"; +import * as fulfill from "../src/utils/fulfill"; +import { generateRandomSalt } from "../src/utils/order"; +import { getTagFromDomain } from "../src/utils/usecase"; import { getBalancesForFulfillOrder, verifyBalancesAfterFulfill, diff --git a/src/__tests__/basic-fulfill.spec.ts b/test/basic-fulfill.spec.ts similarity index 99% rename from src/__tests__/basic-fulfill.spec.ts rename to test/basic-fulfill.spec.ts index c12ca705..aa9e697c 100644 --- a/src/__tests__/basic-fulfill.spec.ts +++ b/test/basic-fulfill.spec.ts @@ -4,9 +4,9 @@ import { expect } from "chai"; import { BigNumber } from "ethers"; import { parseEther } from "ethers/lib/utils"; import { ethers } from "hardhat"; -import { ItemType, MAX_INT } from "../constants"; -import { CreateOrderInput, CurrencyItem } from "../types"; -import * as fulfill from "../utils/fulfill"; +import { ItemType, MAX_INT } from "../src/constants"; +import { CreateOrderInput, CurrencyItem } from "../src/types"; +import * as fulfill from "../src/utils/fulfill"; import { getBalancesForFulfillOrder, verifyBalancesAfterFulfill, diff --git a/src/__tests__/bundle.spec.ts b/test/bundle.spec.ts similarity index 99% rename from src/__tests__/bundle.spec.ts rename to test/bundle.spec.ts index f2dd4c48..7358af20 100644 --- a/src/__tests__/bundle.spec.ts +++ b/test/bundle.spec.ts @@ -4,15 +4,15 @@ import { expect } from "chai"; import { BigNumber } from "ethers"; import { parseEther } from "ethers/lib/utils"; import { ethers } from "hardhat"; -import { ItemType, MAX_INT } from "../constants"; -import { TestERC1155, TestERC721 } from "../typechain-types"; -import { CreateOrderInput, CurrencyItem } from "../types"; -import * as fulfill from "../utils/fulfill"; +import { ItemType, MAX_INT } from "../src/constants"; +import { TestERC1155, TestERC721 } from "../src/typechain-types"; +import { CreateOrderInput, CurrencyItem } from "../src/types"; +import * as fulfill from "../src/utils/fulfill"; import { getBalancesForFulfillOrder, verifyBalancesAfterFulfill, } from "./utils/balance"; -import { getTagFromDomain } from "../utils/usecase"; +import { getTagFromDomain } from "../src/utils/usecase"; import { describeWithFixture } from "./utils/setup"; const sinon = require("sinon"); diff --git a/src/__tests__/cancel.spec.ts b/test/cancel.spec.ts similarity index 97% rename from src/__tests__/cancel.spec.ts rename to test/cancel.spec.ts index ce7f9c3f..eb8c3dd7 100644 --- a/src/__tests__/cancel.spec.ts +++ b/test/cancel.spec.ts @@ -2,8 +2,8 @@ import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers"; import { expect } from "chai"; import { parseEther } from "ethers/lib/utils"; import { ethers } from "hardhat"; -import { ItemType } from "../constants"; -import { CreateOrderInput } from "../types"; +import { ItemType } from "../src/constants"; +import { CreateOrderInput } from "../src/types"; import { describeWithFixture } from "./utils/setup"; describeWithFixture("As a user I want to cancel an order", (fixture) => { diff --git a/src/__tests__/create-bulk-orders.spec.ts b/test/create-bulk-orders.spec.ts similarity index 96% rename from src/__tests__/create-bulk-orders.spec.ts rename to test/create-bulk-orders.spec.ts index 2f092112..3c5a75cf 100644 --- a/src/__tests__/create-bulk-orders.spec.ts +++ b/test/create-bulk-orders.spec.ts @@ -1,12 +1,12 @@ import { expect } from "chai"; import { ethers } from "hardhat"; -import { ItemType, MAX_INT, NO_CONDUIT, OrderType } from "../constants"; +import { ItemType, MAX_INT, NO_CONDUIT, OrderType } from "../src/constants"; import { ApprovalAction, BasicErc721Item, CreateBulkOrdersAction, -} from "../types"; -import { generateRandomSalt } from "../utils/order"; +} from "../src/types"; +import { generateRandomSalt } from "../src/utils/order"; import { describeWithFixture } from "./utils/setup"; describeWithFixture( diff --git a/src/__tests__/create-order.spec.ts b/test/create-order.spec.ts similarity index 98% rename from src/__tests__/create-order.spec.ts rename to test/create-order.spec.ts index 5af1ae7c..0eec98e5 100644 --- a/src/__tests__/create-order.spec.ts +++ b/test/create-order.spec.ts @@ -1,9 +1,9 @@ import { expect } from "chai"; import { parseEther } from "ethers/lib/utils"; import { ethers } from "hardhat"; -import { ItemType, MAX_INT, NO_CONDUIT, OrderType } from "../constants"; -import { ApprovalAction, CreateOrderAction } from "../types"; -import { generateRandomSalt } from "../utils/order"; +import { ItemType, MAX_INT, NO_CONDUIT, OrderType } from "../src/constants"; +import { ApprovalAction, CreateOrderAction } from "../src/types"; +import { generateRandomSalt } from "../src/utils/order"; import { describeWithFixture } from "./utils/setup"; describeWithFixture("As a user I want to create an order", (fixture) => { @@ -826,7 +826,7 @@ describeWithFixture("As a user I want to create an order", (fixture) => { await testErc721.mint(offerer.address, nftId); const startTime = "0"; const endTime = MAX_INT.toString(); - const salt = "0xabc"; + const salt = "0xabcd"; const { executeAllActions } = await seaport.createOrder({ startTime, @@ -858,6 +858,6 @@ describeWithFixture("As a user I want to create an order", (fixture) => { const localOrderHash = seaport.getOrderHash(order.parameters); expect(contractOrderHash).eq(localOrderHash); - expect(order.parameters.salt).eq("0xabc"); + expect(order.parameters.salt).eq(`0x${"0".repeat(60)}abcd`); }); }); diff --git a/src/__tests__/criteria-based.spec.ts b/test/criteria-based.spec.ts similarity index 99% rename from src/__tests__/criteria-based.spec.ts rename to test/criteria-based.spec.ts index 43d02532..cef28c16 100644 --- a/src/__tests__/criteria-based.spec.ts +++ b/test/criteria-based.spec.ts @@ -4,10 +4,10 @@ import { expect } from "chai"; import { BigNumber } from "ethers"; import { parseEther } from "ethers/lib/utils"; import { ethers } from "hardhat"; -import { ItemType, MAX_INT } from "../constants"; -import { CreateOrderInput, CurrencyItem, OrderWithCounter } from "../types"; -import * as fulfill from "../utils/fulfill"; -import { MerkleTree } from "../utils/merkletree"; +import { ItemType, MAX_INT } from "../src/constants"; +import { CreateOrderInput, CurrencyItem, OrderWithCounter } from "../src/types"; +import * as fulfill from "../src/utils/fulfill"; +import { MerkleTree } from "../src/utils/merkletree"; import { getBalancesForFulfillOrder, verifyBalancesAfterFulfill, diff --git a/src/__tests__/domain-registry.spec.ts b/test/domain-registry.spec.ts similarity index 100% rename from src/__tests__/domain-registry.spec.ts rename to test/domain-registry.spec.ts diff --git a/src/__tests__/fulfill-orders.spec.ts b/test/fulfill-orders.spec.ts similarity index 99% rename from src/__tests__/fulfill-orders.spec.ts rename to test/fulfill-orders.spec.ts index 92568e5e..623196a5 100644 --- a/src/__tests__/fulfill-orders.spec.ts +++ b/test/fulfill-orders.spec.ts @@ -3,11 +3,11 @@ import { expect } from "chai"; import { BigNumber } from "ethers"; import { parseEther } from "ethers/lib/utils"; import { ethers } from "hardhat"; -import { ItemType, MAX_INT } from "../constants"; -import { TestERC1155, TestERC721 } from "../typechain-types"; -import { CreateOrderInput, CurrencyItem } from "../types"; -import * as fulfill from "../utils/fulfill"; -import { getTagFromDomain } from "../utils/usecase"; +import { ItemType, MAX_INT } from "../src/constants"; +import { TestERC1155, TestERC721 } from "../src/typechain-types"; +import { CreateOrderInput, CurrencyItem } from "../src/types"; +import * as fulfill from "../src/utils/fulfill"; +import { getTagFromDomain } from "../src/utils/usecase"; import { describeWithFixture } from "./utils/setup"; const sinon = require("sinon"); diff --git a/src/__tests__/gifting.spec.ts b/test/gifting.spec.ts similarity index 98% rename from src/__tests__/gifting.spec.ts rename to test/gifting.spec.ts index d96a5605..7017451f 100644 --- a/src/__tests__/gifting.spec.ts +++ b/test/gifting.spec.ts @@ -3,8 +3,8 @@ import { expect } from "chai"; import { BigNumber } from "ethers"; import { parseEther } from "ethers/lib/utils"; import { ethers } from "hardhat"; -import { ItemType, MAX_INT } from "../constants"; -import { CreateOrderInput, CurrencyItem } from "../types"; +import { ItemType, MAX_INT } from "../src/constants"; +import { CreateOrderInput, CurrencyItem } from "../src/types"; import { describeWithFixture } from "./utils/setup"; describeWithFixture( diff --git a/src/__tests__/match-orders.spec.ts b/test/match-orders.spec.ts similarity index 98% rename from src/__tests__/match-orders.spec.ts rename to test/match-orders.spec.ts index 7802b421..baa28e8f 100644 --- a/src/__tests__/match-orders.spec.ts +++ b/test/match-orders.spec.ts @@ -4,8 +4,8 @@ import { BigNumber } from "ethers"; import { parseEther } from "ethers/lib/utils"; import { ethers } from "hardhat"; -import { ItemType, MAX_INT } from "../constants"; -import { CreateOrderInput, CurrencyItem } from "../types"; +import { ItemType, MAX_INT } from "../src/constants"; +import { CreateOrderInput, CurrencyItem } from "../src/types"; import { getBalancesForFulfillOrder, verifyBalancesAfterFulfill, @@ -15,7 +15,7 @@ import { getPrivateListingFulfillments, } from "./utils/examples/privateListings"; import { describeWithFixture } from "./utils/setup"; -import { getTransactionMethods } from "../utils/usecase"; +import { getTransactionMethods } from "../src/utils/usecase"; import { expect } from "chai"; describeWithFixture("As a user I want to match an order", (fixture) => { diff --git a/src/__tests__/partial-fulfill.spec.ts b/test/partial-fulfill.spec.ts similarity index 99% rename from src/__tests__/partial-fulfill.spec.ts rename to test/partial-fulfill.spec.ts index 31590364..a3bfa7b0 100644 --- a/src/__tests__/partial-fulfill.spec.ts +++ b/test/partial-fulfill.spec.ts @@ -4,10 +4,10 @@ import { expect } from "chai"; import { BigNumber } from "ethers"; import { parseEther, parseUnits } from "ethers/lib/utils"; import { ethers } from "hardhat"; -import { ItemType, MAX_INT, OrderType } from "../constants"; -import { TestERC1155 } from "../typechain-types"; -import { CreateOrderInput, CurrencyItem } from "../types"; -import * as fulfill from "../utils/fulfill"; +import { ItemType, MAX_INT, OrderType } from "../src/constants"; +import { TestERC1155 } from "../src/typechain-types"; +import { CreateOrderInput, CurrencyItem } from "../src/types"; +import * as fulfill from "../src/utils/fulfill"; import { getBalancesForFulfillOrder, verifyBalancesAfterFulfill, diff --git a/src/__tests__/sign-order.spec.ts b/test/sign-order.spec.ts similarity index 92% rename from src/__tests__/sign-order.spec.ts rename to test/sign-order.spec.ts index 742b2019..64bbe752 100644 --- a/src/__tests__/sign-order.spec.ts +++ b/test/sign-order.spec.ts @@ -1,8 +1,8 @@ import { expect } from "chai"; import { ethers } from "hardhat"; -import { ItemType, MAX_INT, NO_CONDUIT, OrderType } from "../constants"; -import { ConsiderationItem, OfferItem } from "../types"; -import { generateRandomSalt } from "../utils/order"; +import { ItemType, MAX_INT, NO_CONDUIT, OrderType } from "../src/constants"; +import { ConsiderationItem, OfferItem } from "../src/types"; +import { generateRandomSalt } from "../src/utils/order"; import { describeWithFixture } from "./utils/setup"; describeWithFixture("As a user I want to sign an order", (fixture) => { diff --git a/src/__tests__/swap.spec.ts b/test/swap.spec.ts similarity index 98% rename from src/__tests__/swap.spec.ts rename to test/swap.spec.ts index f85d0ae7..507bfabe 100644 --- a/src/__tests__/swap.spec.ts +++ b/test/swap.spec.ts @@ -3,10 +3,14 @@ import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers"; import { expect } from "chai"; import { parseEther } from "ethers/lib/utils"; import { ethers } from "hardhat"; -import { ItemType, MAX_INT } from "../constants"; -import { TestERC1155, TestERC721 } from "../typechain-types"; -import { ApprovalAction, CreateOrderAction, CreateOrderInput } from "../types"; -import * as fulfill from "../utils/fulfill"; +import { ItemType, MAX_INT } from "../src/constants"; +import { TestERC1155, TestERC721 } from "../src/typechain-types"; +import { + ApprovalAction, + CreateOrderAction, + CreateOrderInput, +} from "../src/types"; +import * as fulfill from "../src/utils/fulfill"; import { getBalancesForFulfillOrder, verifyBalancesAfterFulfill, diff --git a/src/__tests__/utils/balance.ts b/test/utils/balance.ts similarity index 96% rename from src/__tests__/utils/balance.ts rename to test/utils/balance.ts index 9d7aa1ae..beff934c 100644 --- a/src/__tests__/utils/balance.ts +++ b/test/utils/balance.ts @@ -1,16 +1,19 @@ import { BigNumber, BigNumberish, ContractReceipt, providers } from "ethers"; import { parseEther } from "ethers/lib/utils"; -import { Item, Order, OrderStatus } from "../../types"; -import { balanceOf } from "../../utils/balance"; +import { Item, Order, OrderStatus } from "../../src/types"; +import { balanceOf } from "../../src/utils/balance"; -import { getPresentItemAmount, TimeBasedItemParams } from "../../utils/item"; +import { + getPresentItemAmount, + TimeBasedItemParams, +} from "../../src/utils/item"; import { providers as multicallProviders } from "@0xsequence/multicall"; import { expect } from "chai"; import { ethers } from "hardhat"; import { mapOrderAmountsFromFilledStatus, mapOrderAmountsFromUnitsToFill, -} from "../../utils/order"; +} from "../../src/utils/order"; export const setBalance = async ( address: string, diff --git a/src/__tests__/utils/examples/privateListings.ts b/test/utils/examples/privateListings.ts similarity index 96% rename from src/__tests__/utils/examples/privateListings.ts rename to test/utils/examples/privateListings.ts index c7213f51..63e1d089 100644 --- a/src/__tests__/utils/examples/privateListings.ts +++ b/test/utils/examples/privateListings.ts @@ -3,9 +3,9 @@ import { MatchOrdersFulfillment, Order, OrderWithCounter, -} from "../../../types"; -import { isCurrencyItem } from "../../../utils/item"; -import { generateRandomSalt } from "../../../utils/order"; +} from "../../../src/types"; +import { isCurrencyItem } from "../../../src/utils/item"; +import { generateRandomSalt } from "../../../src/utils/order"; export const constructPrivateListingCounterOrder = ( order: OrderWithCounter, diff --git a/src/__tests__/utils/setup.ts b/test/utils/setup.ts similarity index 97% rename from src/__tests__/utils/setup.ts rename to test/utils/setup.ts index d06bbde4..4c7329be 100644 --- a/src/__tests__/utils/setup.ts +++ b/test/utils/setup.ts @@ -1,5 +1,5 @@ import { ethers } from "hardhat"; -import { Seaport } from "../../seaport"; +import { Seaport } from "../../src/seaport"; import type { TestERC721, TestERC20, @@ -7,7 +7,7 @@ import type { Seaport as SeaportContract, DomainRegistry, TestERC20USDC, -} from "../../typechain-types"; +} from "../../src/typechain-types"; const chai = require("chai"); const chaiAsPromised = require("chai-as-promised"); diff --git a/tsconfig.build.json b/tsconfig.build.json index 627f51ae..604e6d65 100644 --- a/tsconfig.build.json +++ b/tsconfig.build.json @@ -1,9 +1,12 @@ { "extends": "./tsconfig.json", + "compilerOptions": { + "rootDir": "./src" + }, "exclude": [ - "./src/__tests__/**/*", "./src/artifacts/**/*", "./src/typechain-types/**/*", + "./test", "./hardhat.config.ts", ".eslintrc.js" ] diff --git a/tsconfig.json b/tsconfig.json index 747ae107..4ad78c9f 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -17,8 +17,7 @@ "module": "commonjs", "moduleResolution": "node", "resolveJsonModule": true, - "isolatedModules": true, - "rootDir": "./src" + "isolatedModules": true }, - "include": ["./src", "./hardhat.config.ts", ".eslintrc.js"] + "include": ["./src", "./test", "./hardhat.config.ts", ".eslintrc.js"] }