From e030281a6a683f5664ac70985b462a6458c5b39e Mon Sep 17 00:00:00 2001 From: jxom Date: Thu, 6 Jun 2024 17:20:23 +1000 Subject: [PATCH 1/5] fix: resolves https://github.com/wevm/viem/issues/2306 --- packages/thirdweb/package.json | 4 ++-- .../src/wallets/coinbase/coinbaseSDKWallet.ts | 13 +++++++------ packages/thirdweb/src/wallets/injected/index.ts | 13 +++++++------ .../src/wallets/wallet-connect/controller.ts | 13 +++++++------ 4 files changed, 23 insertions(+), 20 deletions(-) diff --git a/packages/thirdweb/package.json b/packages/thirdweb/package.json index e86c6cb6091..60ba3f02796 100644 --- a/packages/thirdweb/package.json +++ b/packages/thirdweb/package.json @@ -197,7 +197,7 @@ "mipd": "0.0.7", "node-libs-browser": "2.2.1", "uqr": "0.1.2", - "viem": "2.10.9" + "viem": "2.13.7" }, "peerDependencies": { "@aws-sdk/client-lambda": "^3", @@ -310,4 +310,4 @@ "shamir-secret-sharing": "0.0.3", "vitest": "1.5.0" } -} +} \ No newline at end of file diff --git a/packages/thirdweb/src/wallets/coinbase/coinbaseSDKWallet.ts b/packages/thirdweb/src/wallets/coinbase/coinbaseSDKWallet.ts index 437b15cc128..36cdfab1a94 100644 --- a/packages/thirdweb/src/wallets/coinbase/coinbaseSDKWallet.ts +++ b/packages/thirdweb/src/wallets/coinbase/coinbaseSDKWallet.ts @@ -6,9 +6,9 @@ import type { Address } from "abitype"; import { type SignTypedDataParameters, getTypesForEIP712Domain, + serializeTypedData, validateTypedData, } from "viem"; -import { stringify } from "../../utils/json.js"; import type { Account, Wallet } from "../interfaces/wallet.js"; import type { SendTransactionOption } from "../interfaces/wallet.js"; import type { AppMetadata, DisconnectFn, SwitchChainFn } from "../types.js"; @@ -22,7 +22,6 @@ import type { ThirdwebClient } from "../../client/client.js"; import { getAddress } from "../../utils/address.js"; import { type Hex, - isHex, numberToHex, stringToHex, uint8ArrayToHex, @@ -333,10 +332,12 @@ function createAccount(provider: ProviderInterface, address: string) { // as we can't statically check this with TypeScript. validateTypedData({ domain, message, primaryType, types }); - const stringifiedData = stringify( - { domain: domain ?? {}, message, primaryType, types }, - (_, value) => (isHex(value) ? value.toLowerCase() : value), - ); + const stringifiedData = serializeTypedData({ + domain: domain ?? {}, + message, + primaryType, + types, + }); return await provider.request({ method: "eth_signTypedData_v4", diff --git a/packages/thirdweb/src/wallets/injected/index.ts b/packages/thirdweb/src/wallets/injected/index.ts index 8e3478b4d1a..13e19ac739a 100644 --- a/packages/thirdweb/src/wallets/injected/index.ts +++ b/packages/thirdweb/src/wallets/injected/index.ts @@ -2,6 +2,7 @@ import type { Address } from "abitype"; import { type SignTypedDataParameters, getTypesForEIP712Domain, + serializeTypedData, validateTypedData, } from "viem"; import type { Chain } from "../../chains/types.js"; @@ -9,12 +10,10 @@ import { getCachedChain, getChainMetadata } from "../../chains/utils.js"; import { getAddress } from "../../utils/address.js"; import { type Hex, - isHex, numberToHex, stringToHex, uint8ArrayToHex, } from "../../utils/encoding/hex.js"; -import { stringify } from "../../utils/json.js"; import type { Ethereum } from "../interfaces/ethereum.js"; import type { Account, @@ -185,10 +184,12 @@ function createAccount(provider: Ethereum, address: string) { // as we can't statically check this with TypeScript. validateTypedData({ domain, message, primaryType, types }); - const stringifiedData = stringify( - { domain: domain ?? {}, message, primaryType, types }, - (_, value) => (isHex(value) ? value.toLowerCase() : value), - ); + const stringifiedData = serializeTypedData({ + domain: domain ?? {}, + message, + primaryType, + types, + }); return await provider.request({ method: "eth_signTypedData_v4", diff --git a/packages/thirdweb/src/wallets/wallet-connect/controller.ts b/packages/thirdweb/src/wallets/wallet-connect/controller.ts index cac65ca079d..9170b272937 100644 --- a/packages/thirdweb/src/wallets/wallet-connect/controller.ts +++ b/packages/thirdweb/src/wallets/wallet-connect/controller.ts @@ -6,6 +6,7 @@ import { SwitchChainError, UserRejectedRequestError, getTypesForEIP712Domain, + serializeTypedData, validateTypedData, } from "viem"; import type { Chain } from "../../chains/types.js"; @@ -16,12 +17,10 @@ import { } from "../../chains/utils.js"; import { type Hex, - isHex, numberToHex, stringToHex, uint8ArrayToHex, } from "../../utils/encoding/hex.js"; -import { stringify } from "../../utils/json.js"; import { isAndroid, isIOS, isMobile } from "../../utils/web/isMobile.js"; import { openWindow } from "../../utils/web/openWindow.js"; import { getWalletInfo } from "../__generated__/getWalletInfo.js"; @@ -374,10 +373,12 @@ function createAccount(provider: WCProvider, address: string) { // as we can't statically check this with TypeScript. validateTypedData({ domain, message, primaryType, types }); - const typedData = stringify( - { domain: domain ?? {}, message, primaryType, types }, - (_, value) => (isHex(value) ? value.toLowerCase() : value), - ); + const typedData = serializeTypedData({ + domain: domain ?? {}, + message, + primaryType, + types, + }); return await provider.request({ method: "eth_signTypedData_v4", From 6b404fff70a8769adfc17f6a9d1021a1937b97a1 Mon Sep 17 00:00:00 2001 From: Joaquim Verges Date: Fri, 7 Jun 2024 08:08:58 +1200 Subject: [PATCH 2/5] add mixed case test --- .../utils/signatures/sign-typed-data.test.ts | 42 ++++++++++++++++++- pnpm-lock.yaml | 8 ++-- 2 files changed, 45 insertions(+), 5 deletions(-) diff --git a/packages/thirdweb/src/utils/signatures/sign-typed-data.test.ts b/packages/thirdweb/src/utils/signatures/sign-typed-data.test.ts index 58e6cfea8c3..473f3682239 100644 --- a/packages/thirdweb/src/utils/signatures/sign-typed-data.test.ts +++ b/packages/thirdweb/src/utils/signatures/sign-typed-data.test.ts @@ -1,8 +1,9 @@ import { expect, test } from "vitest"; -import { ANVIL_PKEY_A } from "~test/test-wallets.js"; +import { ANVIL_PKEY_A, TEST_ACCOUNT_A } from "~test/test-wallets.js"; import { typedData } from "~test/typed-data.js"; +import type { Address } from "../address.js"; import { signTypedData } from "./sign-typed-data.js"; test("default", async () => { @@ -142,3 +143,42 @@ test("domain: salt", async () => { '"0x4b193383278fd3dcaa084952ea282cb9c8889c26c6caaa3f48aca7bde78c6e72028bd98c0328e40d067dbbab53733f99f241d8cf91a32580883f65264c2b72581b"', ); }); + +test("mixed-case strings and addresses", async () => { + const typedData = (name: string, addr: string) => + ({ + types: { + WalletData: [ + { name: "name", type: "string" }, + { name: "addr", type: "address" }, + ], + }, + message: { + name, + addr, + }, + primaryType: "WalletData", + }) as const; + + const name = "0xDEADBEEF"; + + const signature = signTypedData({ + ...typedData(name, TEST_ACCOUNT_A.address), + privateKey: ANVIL_PKEY_A, + }); + + // lowercase string + const signature_2 = signTypedData({ + ...typedData(name.toLowerCase(), TEST_ACCOUNT_A.address), + privateKey: ANVIL_PKEY_A, + }); + + // lowercase address + const signature_3 = signTypedData({ + ...typedData(name, TEST_ACCOUNT_A.address.toLowerCase()), + privateKey: ANVIL_PKEY_A, + }); + + expect(signature === signature_2).toBeFalsy(); + expect(signature === signature_3).toBeTruthy(); +}); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 43c8ba2cdeb..902075c4e96 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1676,8 +1676,8 @@ importers: specifier: 0.1.2 version: 0.1.2 viem: - specifier: 2.10.9 - version: 2.10.9(typescript@5.4.5)(zod@3.22.4) + specifier: 2.13.7 + version: 2.13.7(typescript@5.4.5)(zod@3.22.4) devDependencies: '@aws-sdk/client-lambda': specifier: 3.577.0 @@ -26249,8 +26249,8 @@ packages: semver: 7.6.2 dev: true - /viem@2.10.9(typescript@5.4.5)(zod@3.22.4): - resolution: {integrity: sha512-XsbEXhOcmQOkI80zDLW0EdksimNuYTS61HZ03vQYpHoug7gwVHDQ83nY+nuyT7punuFx0fmRG6+HZg3yVQhptQ==} + /viem@2.13.7(typescript@5.4.5)(zod@3.22.4): + resolution: {integrity: sha512-SZWn9LPrz40PHl4PM2iwkPTTtjWPDFsnLr32UwpqC/Z5f0AwxitjLyZdDKcImvbWZ3vLQ0oPggR1aLlqvTcUug==} peerDependencies: typescript: '>=5.0.4' peerDependenciesMeta: From 8aaf2a8296cc613d745cd8c90db7e373b19934df Mon Sep 17 00:00:00 2001 From: Joaquim Verges Date: Fri, 7 Jun 2024 09:41:33 +1200 Subject: [PATCH 3/5] fix ethers types --- packages/thirdweb/src/adapters/ethers5.ts | 8 +++++++- packages/thirdweb/src/adapters/ethers6.ts | 6 +++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/packages/thirdweb/src/adapters/ethers5.ts b/packages/thirdweb/src/adapters/ethers5.ts index 105a50d6a2e..0a13d5a11cb 100644 --- a/packages/thirdweb/src/adapters/ethers5.ts +++ b/packages/thirdweb/src/adapters/ethers5.ts @@ -484,7 +484,13 @@ function alignTxToEthers( } } - return { ...rest, gasLimit: gas, to, type }; + return { + ...rest, + gasLimit: gas, + to, + type, + accessList: tx.accessList as ethers5.utils.AccessListish | undefined, + }; } async function alignTxFromEthers( diff --git a/packages/thirdweb/src/adapters/ethers6.ts b/packages/thirdweb/src/adapters/ethers6.ts index 8799d694834..b9fef6237aa 100644 --- a/packages/thirdweb/src/adapters/ethers6.ts +++ b/packages/thirdweb/src/adapters/ethers6.ts @@ -447,7 +447,11 @@ function alignTxToEthers( break; } } - return { ...rest, type }; + return { + ...rest, + type, + accessList: tx.accessList as ethers6.AccessListish | null | undefined, + }; } async function alignTxFromEthers(options: { From 374799296e0d7770bb84ca6f6f2e034ecef13082 Mon Sep 17 00:00:00 2001 From: Joaquim Verges Date: Fri, 7 Jun 2024 09:50:34 +1200 Subject: [PATCH 4/5] dont run tests that need GH secret --- .../direct-listings/direct-listings.test.ts | 671 +++++++++--------- .../english-auctions/english-auctions.test.ts | 467 ++++++------ .../src/wallets/utils/getTokenBalance.test.ts | 2 +- 3 files changed, 574 insertions(+), 566 deletions(-) diff --git a/packages/thirdweb/src/extensions/marketplace/direct-listings/direct-listings.test.ts b/packages/thirdweb/src/extensions/marketplace/direct-listings/direct-listings.test.ts index dc0b5b9c3e9..041ee7df42d 100644 --- a/packages/thirdweb/src/extensions/marketplace/direct-listings/direct-listings.test.ts +++ b/packages/thirdweb/src/extensions/marketplace/direct-listings/direct-listings.test.ts @@ -32,131 +32,133 @@ import { isListingValid } from "./utils.js"; import { buyFromListing } from "./write/buyFromListing.js"; import { createListing } from "./write/createListing.js"; -describe("Marketplace: Direct Listings", () => { - describe("ERC721", () => { - let nftTokenId: bigint; - let marketplaceContract: ThirdwebContract; - let erc721Contract: ThirdwebContract; - beforeAll(async () => { - marketplaceContract = getContract({ - address: await deployMarketplaceContract({ - account: TEST_ACCOUNT_A, +describe.runIf(process.env.TW_SECRET_KEY)( + "Marketplace: Direct Listings", + () => { + describe("ERC721", () => { + let nftTokenId: bigint; + let marketplaceContract: ThirdwebContract; + let erc721Contract: ThirdwebContract; + beforeAll(async () => { + marketplaceContract = getContract({ + address: await deployMarketplaceContract({ + account: TEST_ACCOUNT_A, + chain: ANVIL_CHAIN, + client: TEST_CLIENT, + params: { + name: "TestMarketPlace", + }, + }), + client: TEST_CLIENT, chain: ANVIL_CHAIN, + }); + + // also deploy an ERC721 contract + erc721Contract = getContract({ + address: await deployERC721Contract({ + type: "TokenERC721", + account: TEST_ACCOUNT_A, + chain: ANVIL_CHAIN, + client: TEST_CLIENT, + params: { + name: "TestERC721", + }, + }), client: TEST_CLIENT, - params: { - name: "TestMarketPlace", - }, - }), - client: TEST_CLIENT, - chain: ANVIL_CHAIN, - }); + chain: ANVIL_CHAIN, + }); - // also deploy an ERC721 contract - erc721Contract = getContract({ - address: await deployERC721Contract({ - type: "TokenERC721", + const receipt = await sendAndConfirmTransaction({ + transaction: mintToErc721({ + contract: erc721Contract, + to: TEST_ACCOUNT_A.address, + nft: { name: "Test:ERC721:DirectListing" }, + }), account: TEST_ACCOUNT_A, - chain: ANVIL_CHAIN, - client: TEST_CLIENT, - params: { - name: "TestERC721", - }, - }), - client: TEST_CLIENT, - chain: ANVIL_CHAIN, - }); + }); - const receipt = await sendAndConfirmTransaction({ - transaction: mintToErc721({ - contract: erc721Contract, - to: TEST_ACCOUNT_A.address, - nft: { name: "Test:ERC721:DirectListing" }, - }), - account: TEST_ACCOUNT_A, - }); + const mintEvents = parseEventLogs({ + events: [tokensMintedEventErc721()], + logs: receipt.logs, + }); - const mintEvents = parseEventLogs({ - events: [tokensMintedEventErc721()], - logs: receipt.logs, - }); + expect(mintEvents.length).toBe(1); + expect(mintEvents[0]?.args.tokenIdMinted).toBeDefined(); - expect(mintEvents.length).toBe(1); - expect(mintEvents[0]?.args.tokenIdMinted).toBeDefined(); + nftTokenId = mintEvents[0]?.args.tokenIdMinted as bigint; + // does a lot of stuff, this may take a while + }, 120_000); - nftTokenId = mintEvents[0]?.args.tokenIdMinted as bigint; - // does a lot of stuff, this may take a while - }, 120_000); + it("should work for basic listings (Native Currency)", async () => { + // listings should be 0 length to start + const listings = await getAllListings({ + contract: marketplaceContract, + }); + expect(listings.length).toBe(0); + // oh and so should totalListings + expect(await totalListings({ contract: marketplaceContract })).toBe(0n); - it("should work for basic listings (Native Currency)", async () => { - // listings should be 0 length to start - const listings = await getAllListings({ - contract: marketplaceContract, - }); - expect(listings.length).toBe(0); - // oh and so should totalListings - expect(await totalListings({ contract: marketplaceContract })).toBe(0n); - - // approve first - const approveTx = approveErc721({ - contract: erc721Contract, - to: marketplaceContract.address, - tokenId: nftTokenId, - }); + // approve first + const approveTx = approveErc721({ + contract: erc721Contract, + to: marketplaceContract.address, + tokenId: nftTokenId, + }); - await sendAndConfirmTransaction({ - transaction: approveTx, - account: TEST_ACCOUNT_A, - }); + await sendAndConfirmTransaction({ + transaction: approveTx, + account: TEST_ACCOUNT_A, + }); - const transaction = createListing({ - contract: marketplaceContract, - assetContractAddress: erc721Contract.address, - tokenId: nftTokenId, - pricePerToken: "1", - }); - const receipt = await sendAndConfirmTransaction({ - transaction, - account: TEST_ACCOUNT_A, - }); + const transaction = createListing({ + contract: marketplaceContract, + assetContractAddress: erc721Contract.address, + tokenId: nftTokenId, + pricePerToken: "1", + }); + const receipt = await sendAndConfirmTransaction({ + transaction, + account: TEST_ACCOUNT_A, + }); - const listingEvents = parseEventLogs({ - events: [newListingEvent()], - logs: receipt.logs, - }); + const listingEvents = parseEventLogs({ + events: [newListingEvent()], + logs: receipt.logs, + }); - expect(listingEvents.length).toBe(1); + expect(listingEvents.length).toBe(1); - // biome-ignore lint/style/noNonNullAssertion: OK in tests - const listingEvent = listingEvents[0]!; + // biome-ignore lint/style/noNonNullAssertion: OK in tests + const listingEvent = listingEvents[0]!; - expect(listingEvent.args.listingCreator).toBe(TEST_ACCOUNT_A.address); - expect(listingEvent.args.assetContract).toBe(erc721Contract.address); + expect(listingEvent.args.listingCreator).toBe(TEST_ACCOUNT_A.address); + expect(listingEvent.args.assetContract).toBe(erc721Contract.address); - // at this point listings should be 1 - const listingsAfter = await getAllListings({ - contract: marketplaceContract, - }); - expect(listingsAfter.length).toBe(1); - // valid listings should also be 1! - const validListings = await getAllValidListings({ - contract: marketplaceContract, - }); - expect(validListings.length).toBe(1); - // and totalListings should be 1 - expect(await totalListings({ contract: marketplaceContract })).toBe(1n); - - // explicitly retrieve the listing! - const listing = await getListing({ - contract: marketplaceContract, - listingId: listingEvent.args.listingId, - }); + // at this point listings should be 1 + const listingsAfter = await getAllListings({ + contract: marketplaceContract, + }); + expect(listingsAfter.length).toBe(1); + // valid listings should also be 1! + const validListings = await getAllValidListings({ + contract: marketplaceContract, + }); + expect(validListings.length).toBe(1); + // and totalListings should be 1 + expect(await totalListings({ contract: marketplaceContract })).toBe(1n); - expect(listing).toBeDefined(); - expect(listing.status).toBe("ACTIVE"); - expect(listing.creatorAddress).toBe(TEST_ACCOUNT_A.address); - expect(listing.assetContractAddress).toBe(erc721Contract.address); - expect(listing.tokenId).toBe(nftTokenId); - expect(listing.currencyValuePerToken).toMatchInlineSnapshot(` + // explicitly retrieve the listing! + const listing = await getListing({ + contract: marketplaceContract, + listingId: listingEvent.args.listingId, + }); + + expect(listing).toBeDefined(); + expect(listing.status).toBe("ACTIVE"); + expect(listing.creatorAddress).toBe(TEST_ACCOUNT_A.address); + expect(listing.assetContractAddress).toBe(erc721Contract.address); + expect(listing.tokenId).toBe(nftTokenId); + expect(listing.currencyValuePerToken).toMatchInlineSnapshot(` { "decimals": 18, "displayValue": "1", @@ -165,7 +167,7 @@ describe("Marketplace: Direct Listings", () => { "value": 1000000000000000000n, } `); - expect(listing.asset).toMatchInlineSnapshot(` + expect(listing.asset).toMatchInlineSnapshot(` { "id": 0n, "metadata": { @@ -177,218 +179,218 @@ describe("Marketplace: Direct Listings", () => { } `); - // check the listing is valid - const listingValidity = await isListingValid({ - listing, - contract: marketplaceContract, - quantity: 1n, - }); + // check the listing is valid + const listingValidity = await isListingValid({ + listing, + contract: marketplaceContract, + quantity: 1n, + }); - expect(listingValidity).toMatchInlineSnapshot(` + expect(listingValidity).toMatchInlineSnapshot(` { "valid": true, } `); - // expect the buyer to have an initial balance of 0 - await expect( - balanceOfErc721({ - contract: erc721Contract, - owner: TEST_ACCOUNT_B.address, - }), - ).resolves.toBe(0n); - - const buyTx = buyFromListing({ - contract: marketplaceContract, - listingId: listingEvent.args.listingId, - recipient: TEST_ACCOUNT_B.address, - quantity: 1n, - }); + // expect the buyer to have an initial balance of 0 + await expect( + balanceOfErc721({ + contract: erc721Contract, + owner: TEST_ACCOUNT_B.address, + }), + ).resolves.toBe(0n); - await sendAndConfirmTransaction({ - transaction: buyTx, - account: TEST_ACCOUNT_B, + const buyTx = buyFromListing({ + contract: marketplaceContract, + listingId: listingEvent.args.listingId, + recipient: TEST_ACCOUNT_B.address, + quantity: 1n, + }); + + await sendAndConfirmTransaction({ + transaction: buyTx, + account: TEST_ACCOUNT_B, + }); + + // expect the buyer to have a new balance of 1 + await expect( + balanceOfErc721({ + contract: erc721Contract, + owner: TEST_ACCOUNT_B.address, + }), + ).resolves.toBe(1n); + // expect the seller to no longer have the token + await expect( + balanceOfErc721({ + contract: erc721Contract, + owner: TEST_ACCOUNT_A.address, + }), + ).resolves.toBe(0n); }); - - // expect the buyer to have a new balance of 1 - await expect( - balanceOfErc721({ - contract: erc721Contract, - owner: TEST_ACCOUNT_B.address, - }), - ).resolves.toBe(1n); - // expect the seller to no longer have the token - await expect( - balanceOfErc721({ - contract: erc721Contract, - owner: TEST_ACCOUNT_A.address, - }), - ).resolves.toBe(0n); }); - }); - - describe("ERC1155 Drop", () => { - let nftTokenId: bigint; - let marketplaceContract: ThirdwebContract; - let erc1155Contract: ThirdwebContract; - beforeAll(async () => { - marketplaceContract = getContract({ - address: await deployMarketplaceContract({ - account: TEST_ACCOUNT_A, - chain: ANVIL_CHAIN, - client: TEST_CLIENT, - params: { - name: "TestMarketPlace", - }, - }), - client: TEST_CLIENT, - chain: ANVIL_CHAIN, - }); - // also deploy an ERC721 contract - erc1155Contract = getContract({ - address: await deployERC1155Contract({ - type: "DropERC1155", - account: TEST_ACCOUNT_A, + describe("ERC1155 Drop", () => { + let nftTokenId: bigint; + let marketplaceContract: ThirdwebContract; + let erc1155Contract: ThirdwebContract; + beforeAll(async () => { + marketplaceContract = getContract({ + address: await deployMarketplaceContract({ + account: TEST_ACCOUNT_A, + chain: ANVIL_CHAIN, + client: TEST_CLIENT, + params: { + name: "TestMarketPlace", + }, + }), + client: TEST_CLIENT, chain: ANVIL_CHAIN, + }); + + // also deploy an ERC721 contract + erc1155Contract = getContract({ + address: await deployERC1155Contract({ + type: "DropERC1155", + account: TEST_ACCOUNT_A, + chain: ANVIL_CHAIN, + client: TEST_CLIENT, + params: { + name: "TestERC1155", + }, + }), client: TEST_CLIENT, - params: { - name: "TestERC1155", - }, - }), - client: TEST_CLIENT, - chain: ANVIL_CHAIN, - }); - - // lazy mint 10 tokens - await expect( - sendAndConfirmTransaction({ - transaction: lazyMint({ - contract: erc1155Contract, - nfts: [{ name: "Test:ERC1155:DirectListing" }], + chain: ANVIL_CHAIN, + }); + + // lazy mint 10 tokens + await expect( + sendAndConfirmTransaction({ + transaction: lazyMint({ + contract: erc1155Contract, + nfts: [{ name: "Test:ERC1155:DirectListing" }], + }), + account: TEST_ACCOUNT_A, }), - account: TEST_ACCOUNT_A, - }), - ).resolves.toBeDefined(); - - // set claim condition (just public is fine) - await expect( - sendAndConfirmTransaction({ - transaction: setClaimConditions({ - contract: erc1155Contract, - tokenId: 0n, - phases: [{}], + ).resolves.toBeDefined(); + + // set claim condition (just public is fine) + await expect( + sendAndConfirmTransaction({ + transaction: setClaimConditions({ + contract: erc1155Contract, + tokenId: 0n, + phases: [{}], + }), + account: TEST_ACCOUNT_A, }), - account: TEST_ACCOUNT_A, - }), - ).resolves.toBeDefined(); - - // claim 10 tokens - await expect( - sendAndConfirmTransaction({ - transaction: claimTo({ - contract: erc1155Contract, - tokenId: 0n, - to: TEST_ACCOUNT_A.address, - quantity: 10n, + ).resolves.toBeDefined(); + + // claim 10 tokens + await expect( + sendAndConfirmTransaction({ + transaction: claimTo({ + contract: erc1155Contract, + tokenId: 0n, + to: TEST_ACCOUNT_A.address, + quantity: 10n, + }), + account: TEST_ACCOUNT_A, }), - account: TEST_ACCOUNT_A, - }), - ).resolves.toBeDefined(); + ).resolves.toBeDefined(); - nftTokenId = 0n; - // does a lot of stuff, this may take a while - }, 120_000); + nftTokenId = 0n; + // does a lot of stuff, this may take a while + }, 120_000); - it("should work for basic listings (Native Currency)", async () => { - // listings should be 0 length to start - const listings = await getAllListings({ - contract: marketplaceContract, - }); - expect(listings.length).toBe(0); - // oh and so should totalListings - expect(await totalListings({ contract: marketplaceContract })).toBe(0n); - - // approve first - - await sendAndConfirmTransaction({ - transaction: setApprovalForAll({ - contract: erc1155Contract, - operator: marketplaceContract.address, - approved: true, - }), - account: TEST_ACCOUNT_A, - }); + it("should work for basic listings (Native Currency)", async () => { + // listings should be 0 length to start + const listings = await getAllListings({ + contract: marketplaceContract, + }); + expect(listings.length).toBe(0); + // oh and so should totalListings + expect(await totalListings({ contract: marketplaceContract })).toBe(0n); - // this should fail because we're listing more than we have - await expect( - sendAndConfirmTransaction({ - transaction: createListing({ - contract: marketplaceContract, - assetContractAddress: erc1155Contract.address, - tokenId: nftTokenId, - pricePerToken: "1", - quantity: 20n, + // approve first + + await sendAndConfirmTransaction({ + transaction: setApprovalForAll({ + contract: erc1155Contract, + operator: marketplaceContract.address, + approved: true, }), account: TEST_ACCOUNT_A, - }), - ).rejects.toThrowErrorMatchingInlineSnapshot(` + }); + + // this should fail because we're listing more than we have + await expect( + sendAndConfirmTransaction({ + transaction: createListing({ + contract: marketplaceContract, + assetContractAddress: erc1155Contract.address, + tokenId: nftTokenId, + pricePerToken: "1", + quantity: 20n, + }), + account: TEST_ACCOUNT_A, + }), + ).rejects.toThrowErrorMatchingInlineSnapshot(` [TransactionError: Error - Marketplace: not owner or approved tokens. contract: ${marketplaceContract.address} chainId: 31337] `); - // this should work because we're listing the correct amount - const receipt = await sendAndConfirmTransaction({ - transaction: createListing({ - contract: marketplaceContract, - assetContractAddress: erc1155Contract.address, - tokenId: nftTokenId, - pricePerToken: "0.01", - quantity: 1n, - }), - account: TEST_ACCOUNT_A, - }); + // this should work because we're listing the correct amount + const receipt = await sendAndConfirmTransaction({ + transaction: createListing({ + contract: marketplaceContract, + assetContractAddress: erc1155Contract.address, + tokenId: nftTokenId, + pricePerToken: "0.01", + quantity: 1n, + }), + account: TEST_ACCOUNT_A, + }); - const listingEvents = parseEventLogs({ - events: [newListingEvent()], - logs: receipt.logs, - }); + const listingEvents = parseEventLogs({ + events: [newListingEvent()], + logs: receipt.logs, + }); - expect(listingEvents.length).toBe(1); + expect(listingEvents.length).toBe(1); - // biome-ignore lint/style/noNonNullAssertion: OK in tests - const listingEvent = listingEvents[0]!; + // biome-ignore lint/style/noNonNullAssertion: OK in tests + const listingEvent = listingEvents[0]!; - expect(listingEvent.args.listingCreator).toBe(TEST_ACCOUNT_A.address); - expect(listingEvent.args.assetContract).toBe(erc1155Contract.address); + expect(listingEvent.args.listingCreator).toBe(TEST_ACCOUNT_A.address); + expect(listingEvent.args.assetContract).toBe(erc1155Contract.address); - // at this point listings should be 1 - const listingsAfter = await getAllListings({ - contract: marketplaceContract, - }); - expect(listingsAfter.length).toBe(1); - // valid listings should also be 1! - const validListings = await getAllValidListings({ - contract: marketplaceContract, - }); - expect(validListings.length).toBe(1); - // and totalListings should be 1 - expect(await totalListings({ contract: marketplaceContract })).toBe(1n); - - // explicitly retrieve the listing! - const listing = await getListing({ - contract: marketplaceContract, - listingId: listingEvent.args.listingId, - }); + // at this point listings should be 1 + const listingsAfter = await getAllListings({ + contract: marketplaceContract, + }); + expect(listingsAfter.length).toBe(1); + // valid listings should also be 1! + const validListings = await getAllValidListings({ + contract: marketplaceContract, + }); + expect(validListings.length).toBe(1); + // and totalListings should be 1 + expect(await totalListings({ contract: marketplaceContract })).toBe(1n); - expect(listing).toBeDefined(); - expect(listing.status).toBe("ACTIVE"); - expect(listing.creatorAddress).toBe(TEST_ACCOUNT_A.address); - expect(listing.assetContractAddress).toBe(erc1155Contract.address); - expect(listing.tokenId).toBe(nftTokenId); - expect(listing.currencyValuePerToken).toMatchInlineSnapshot(` + // explicitly retrieve the listing! + const listing = await getListing({ + contract: marketplaceContract, + listingId: listingEvent.args.listingId, + }); + + expect(listing).toBeDefined(); + expect(listing.status).toBe("ACTIVE"); + expect(listing.creatorAddress).toBe(TEST_ACCOUNT_A.address); + expect(listing.assetContractAddress).toBe(erc1155Contract.address); + expect(listing.tokenId).toBe(nftTokenId); + expect(listing.currencyValuePerToken).toMatchInlineSnapshot(` { "decimals": 18, "displayValue": "0.01", @@ -397,7 +399,7 @@ describe("Marketplace: Direct Listings", () => { "value": 10000000000000000n, } `); - expect(listing.asset).toMatchInlineSnapshot(` + expect(listing.asset).toMatchInlineSnapshot(` { "id": 0n, "metadata": { @@ -410,56 +412,57 @@ describe("Marketplace: Direct Listings", () => { } `); - // check the listing is valid - const listingValidity = await isListingValid({ - listing, - contract: marketplaceContract, - quantity: 1n, - }); + // check the listing is valid + const listingValidity = await isListingValid({ + listing, + contract: marketplaceContract, + quantity: 1n, + }); - expect(listingValidity).toMatchInlineSnapshot(` + expect(listingValidity).toMatchInlineSnapshot(` { "valid": true, } `); - // expect the buyer to have an initial balance of 0 - await expect( - balanceOfErc1155({ - contract: erc1155Contract, - owner: TEST_ACCOUNT_B.address, - tokenId: nftTokenId, - }), - ).resolves.toBe(0n); - - const buyTx = buyFromListing({ - contract: marketplaceContract, - listingId: listingEvent.args.listingId, - recipient: TEST_ACCOUNT_B.address, - quantity: 1n, - }); + // expect the buyer to have an initial balance of 0 + await expect( + balanceOfErc1155({ + contract: erc1155Contract, + owner: TEST_ACCOUNT_B.address, + tokenId: nftTokenId, + }), + ).resolves.toBe(0n); - await sendAndConfirmTransaction({ - transaction: buyTx, - account: TEST_ACCOUNT_B, - }); + const buyTx = buyFromListing({ + contract: marketplaceContract, + listingId: listingEvent.args.listingId, + recipient: TEST_ACCOUNT_B.address, + quantity: 1n, + }); - // expect the buyer to have a new balance of 1 - await expect( - balanceOfErc1155({ - contract: erc1155Contract, - owner: TEST_ACCOUNT_B.address, - tokenId: nftTokenId, - }), - ).resolves.toBe(1n); - // expect the seller to only have 9 of the tokens - await expect( - balanceOfErc1155({ - contract: erc1155Contract, - owner: TEST_ACCOUNT_A.address, - tokenId: nftTokenId, - }), - ).resolves.toBe(9n); + await sendAndConfirmTransaction({ + transaction: buyTx, + account: TEST_ACCOUNT_B, + }); + + // expect the buyer to have a new balance of 1 + await expect( + balanceOfErc1155({ + contract: erc1155Contract, + owner: TEST_ACCOUNT_B.address, + tokenId: nftTokenId, + }), + ).resolves.toBe(1n); + // expect the seller to only have 9 of the tokens + await expect( + balanceOfErc1155({ + contract: erc1155Contract, + owner: TEST_ACCOUNT_A.address, + tokenId: nftTokenId, + }), + ).resolves.toBe(9n); + }); }); - }); -}); + }, +); diff --git a/packages/thirdweb/src/extensions/marketplace/english-auctions/english-auctions.test.ts b/packages/thirdweb/src/extensions/marketplace/english-auctions/english-auctions.test.ts index 112e453165f..d647a83829f 100644 --- a/packages/thirdweb/src/extensions/marketplace/english-auctions/english-auctions.test.ts +++ b/packages/thirdweb/src/extensions/marketplace/english-auctions/english-auctions.test.ts @@ -26,135 +26,137 @@ import { bidInAuction } from "./write/bidInAuction.js"; import { buyoutAuction } from "./write/buyoutAuction.js"; import { createAuction } from "./write/createAuction.js"; -describe("Marketplace: English Auctions", () => { - let nftTokenId: bigint; - let marketplaceContract: ThirdwebContract; - let erc721Contract: ThirdwebContract; - beforeAll(async () => { - const marketplaceAddress = await deployMarketplaceContract({ - account: TEST_ACCOUNT_A, - chain: ANVIL_CHAIN, - client: TEST_CLIENT, - params: { - name: "TestMarketPlace", - }, - }); - marketplaceContract = getContract({ - address: marketplaceAddress, - client: TEST_CLIENT, - chain: ANVIL_CHAIN, - }); +describe.runIf(process.env.TW_SECRET_KEY)( + "Marketplace: English Auctions", + () => { + let nftTokenId: bigint; + let marketplaceContract: ThirdwebContract; + let erc721Contract: ThirdwebContract; + beforeAll(async () => { + const marketplaceAddress = await deployMarketplaceContract({ + account: TEST_ACCOUNT_A, + chain: ANVIL_CHAIN, + client: TEST_CLIENT, + params: { + name: "TestMarketPlace", + }, + }); + marketplaceContract = getContract({ + address: marketplaceAddress, + client: TEST_CLIENT, + chain: ANVIL_CHAIN, + }); - // also deploy an ERC721 contract - const erc721Address = await deployERC721Contract({ - type: "TokenERC721", - account: TEST_ACCOUNT_A, - chain: ANVIL_CHAIN, - client: TEST_CLIENT, - params: { - name: "TestERC721", - }, - }); + // also deploy an ERC721 contract + const erc721Address = await deployERC721Contract({ + type: "TokenERC721", + account: TEST_ACCOUNT_A, + chain: ANVIL_CHAIN, + client: TEST_CLIENT, + params: { + name: "TestERC721", + }, + }); - erc721Contract = getContract({ - address: erc721Address, - client: TEST_CLIENT, - chain: ANVIL_CHAIN, - }); + erc721Contract = getContract({ + address: erc721Address, + client: TEST_CLIENT, + chain: ANVIL_CHAIN, + }); - const mintTransaction = mintTo({ - contract: erc721Contract, - to: TEST_ACCOUNT_A.address, - nft: { name: "Test:ERC721:EnglishAuction" }, - }); - const receipt = await sendAndConfirmTransaction({ - transaction: mintTransaction, - account: TEST_ACCOUNT_A, - }); + const mintTransaction = mintTo({ + contract: erc721Contract, + to: TEST_ACCOUNT_A.address, + nft: { name: "Test:ERC721:EnglishAuction" }, + }); + const receipt = await sendAndConfirmTransaction({ + transaction: mintTransaction, + account: TEST_ACCOUNT_A, + }); - const mintEvents = parseEventLogs({ - events: [tokensMintedEvent()], - logs: receipt.logs, - }); + const mintEvents = parseEventLogs({ + events: [tokensMintedEvent()], + logs: receipt.logs, + }); - expect(mintEvents.length).toBe(1); - expect(mintEvents[0]?.args.tokenIdMinted).toBeDefined(); + expect(mintEvents.length).toBe(1); + expect(mintEvents[0]?.args.tokenIdMinted).toBeDefined(); - nftTokenId = mintEvents[0]?.args.tokenIdMinted as bigint; - // does a lot of stuff, this may take a while - }, 120_000); + nftTokenId = mintEvents[0]?.args.tokenIdMinted as bigint; + // does a lot of stuff, this may take a while + }, 120_000); - it("should work for basic auctions (Native Currency)", async () => { - // auctions should be 0 length to start - const auctions = await getAllAuctions({ - contract: marketplaceContract, - }); - expect(auctions.length).toBe(0); - // oh and so should totalAuctions - expect(await totalAuctions({ contract: marketplaceContract })).toBe(0n); + it("should work for basic auctions (Native Currency)", async () => { + // auctions should be 0 length to start + const auctions = await getAllAuctions({ + contract: marketplaceContract, + }); + expect(auctions.length).toBe(0); + // oh and so should totalAuctions + expect(await totalAuctions({ contract: marketplaceContract })).toBe(0n); - // approve first - const approveTx = approve({ - contract: erc721Contract, - to: marketplaceContract.address, - tokenId: nftTokenId, - }); + // approve first + const approveTx = approve({ + contract: erc721Contract, + to: marketplaceContract.address, + tokenId: nftTokenId, + }); - await sendAndConfirmTransaction({ - transaction: approveTx, - account: TEST_ACCOUNT_A, - }); + await sendAndConfirmTransaction({ + transaction: approveTx, + account: TEST_ACCOUNT_A, + }); - const transaction = createAuction({ - contract: marketplaceContract, - assetContractAddress: erc721Contract.address, - tokenId: nftTokenId, - minimumBidAmount: "1", - buyoutBidAmount: "10", - }); - const receipt = await sendAndConfirmTransaction({ - transaction, - account: TEST_ACCOUNT_A, - }); + const transaction = createAuction({ + contract: marketplaceContract, + assetContractAddress: erc721Contract.address, + tokenId: nftTokenId, + minimumBidAmount: "1", + buyoutBidAmount: "10", + }); + const receipt = await sendAndConfirmTransaction({ + transaction, + account: TEST_ACCOUNT_A, + }); - const listingEvents = parseEventLogs({ - events: [newAuctionEvent()], - logs: receipt.logs, - }); + const listingEvents = parseEventLogs({ + events: [newAuctionEvent()], + logs: receipt.logs, + }); - expect(listingEvents.length).toBe(1); + expect(listingEvents.length).toBe(1); - // biome-ignore lint/style/noNonNullAssertion: OK in tests - const listingEvent = listingEvents[0]!; + // biome-ignore lint/style/noNonNullAssertion: OK in tests + const listingEvent = listingEvents[0]!; - expect(listingEvent.args.auctionCreator).toBe(TEST_ACCOUNT_A.address); - expect(listingEvent.args.assetContract).toBe(erc721Contract.address); + expect(listingEvent.args.auctionCreator).toBe(TEST_ACCOUNT_A.address); + expect(listingEvent.args.assetContract).toBe(erc721Contract.address); - // at this point auctions should be 1 - const auctionsAfter = await getAllAuctions({ - contract: marketplaceContract, - }); - expect(auctionsAfter.length).toBe(1); - // valid auctions should also be 1! - const validAuctions = await getAllValidAuctions({ - contract: marketplaceContract, - }); - expect(validAuctions.length).toBe(1); - // and totalauctions should be 1 - expect(await totalAuctions({ contract: marketplaceContract })).toBe(1n); + // at this point auctions should be 1 + const auctionsAfter = await getAllAuctions({ + contract: marketplaceContract, + }); + expect(auctionsAfter.length).toBe(1); + // valid auctions should also be 1! + const validAuctions = await getAllValidAuctions({ + contract: marketplaceContract, + }); + expect(validAuctions.length).toBe(1); + // and totalauctions should be 1 + expect(await totalAuctions({ contract: marketplaceContract })).toBe(1n); - // explicitly retrieve the listing! - const listing = await getAuction({ - contract: marketplaceContract, - auctionId: listingEvent.args.auctionId, - }); + // explicitly retrieve the listing! + const listing = await getAuction({ + contract: marketplaceContract, + auctionId: listingEvent.args.auctionId, + }); - expect(listing).toBeDefined(); - expect(listing.status).toBe("ACTIVE"); - expect(listing.creatorAddress).toBe(TEST_ACCOUNT_A.address); - expect(listing.assetContractAddress).toBe(erc721Contract.address); - expect(listing.tokenId).toBe(nftTokenId); - expect(listing.minimumBidCurrencyValue).toMatchInlineSnapshot(` + expect(listing).toBeDefined(); + expect(listing.status).toBe("ACTIVE"); + expect(listing.creatorAddress).toBe(TEST_ACCOUNT_A.address); + expect(listing.assetContractAddress).toBe(erc721Contract.address); + expect(listing.tokenId).toBe(nftTokenId); + expect(listing.minimumBidCurrencyValue).toMatchInlineSnapshot(` { "decimals": 18, "displayValue": "1", @@ -163,7 +165,7 @@ describe("Marketplace: English Auctions", () => { "value": 1000000000000000000n, } `); - expect(listing.buyoutCurrencyValue).toMatchInlineSnapshot(` + expect(listing.buyoutCurrencyValue).toMatchInlineSnapshot(` { "decimals": 18, "displayValue": "10", @@ -172,7 +174,7 @@ describe("Marketplace: English Auctions", () => { "value": 10000000000000000000n, } `); - expect(listing.asset).toMatchInlineSnapshot(` + expect(listing.asset).toMatchInlineSnapshot(` { "id": 0n, "metadata": { @@ -184,71 +186,73 @@ describe("Marketplace: English Auctions", () => { } `); - // check for a winning bid - await expect( - getWinningBid({ - contract: marketplaceContract, - auctionId: listing.id, - }), - ).resolves.toBeUndefined(); - - // invalid bid amount 1: 0 bid (0 is not allowed) - await expect( - sendAndConfirmTransaction({ - account: TEST_ACCOUNT_B, - transaction: bidInAuction({ - auctionId: listing.id, + // check for a winning bid + await expect( + getWinningBid({ contract: marketplaceContract, - bidAmount: "0", - }), - }), - ).rejects.toThrowErrorMatchingInlineSnapshot("[Error: Bid amount is zero]"); - // invalid bid amount 2: 11 bid (over buyout) - await expect( - sendAndConfirmTransaction({ - account: TEST_ACCOUNT_B, - transaction: bidInAuction({ auctionId: listing.id, - contract: marketplaceContract, - bidAmount: "11", }), - }), - ).rejects.toThrowErrorMatchingInlineSnapshot( - "[Error: Bid amount is above the buyout amount]", - ); - // invalid bid amount 3: below minimum bid (but not 0) - await expect( - sendAndConfirmTransaction({ - account: TEST_ACCOUNT_B, - transaction: bidInAuction({ - auctionId: listing.id, - contract: marketplaceContract, - bidAmount: "0.5", + ).resolves.toBeUndefined(); + + // invalid bid amount 1: 0 bid (0 is not allowed) + await expect( + sendAndConfirmTransaction({ + account: TEST_ACCOUNT_B, + transaction: bidInAuction({ + auctionId: listing.id, + contract: marketplaceContract, + bidAmount: "0", + }), + }), + ).rejects.toThrowErrorMatchingInlineSnapshot( + "[Error: Bid amount is zero]", + ); + // invalid bid amount 2: 11 bid (over buyout) + await expect( + sendAndConfirmTransaction({ + account: TEST_ACCOUNT_B, + transaction: bidInAuction({ + auctionId: listing.id, + contract: marketplaceContract, + bidAmount: "11", + }), + }), + ).rejects.toThrowErrorMatchingInlineSnapshot( + "[Error: Bid amount is above the buyout amount]", + ); + // invalid bid amount 3: below minimum bid (but not 0) + await expect( + sendAndConfirmTransaction({ + account: TEST_ACCOUNT_B, + transaction: bidInAuction({ + auctionId: listing.id, + contract: marketplaceContract, + bidAmount: "0.5", + }), }), - }), - ).rejects.toThrowErrorMatchingInlineSnapshot( - "[Error: Bid amount is below the minimum bid amount]", - ); + ).rejects.toThrowErrorMatchingInlineSnapshot( + "[Error: Bid amount is below the minimum bid amount]", + ); - // valid bid amount: "2" - await expect( - sendAndConfirmTransaction({ - account: TEST_ACCOUNT_B, - transaction: bidInAuction({ - auctionId: listing.id, - contract: marketplaceContract, - bidAmount: "2", + // valid bid amount: "2" + await expect( + sendAndConfirmTransaction({ + account: TEST_ACCOUNT_B, + transaction: bidInAuction({ + auctionId: listing.id, + contract: marketplaceContract, + bidAmount: "2", + }), }), - }), - ).resolves.toBeDefined(); + ).resolves.toBeDefined(); - // check for a new winning bid - await expect( - getWinningBid({ - contract: marketplaceContract, - auctionId: listing.id, - }), - ).resolves.toMatchInlineSnapshot(` + // check for a new winning bid + await expect( + getWinningBid({ + contract: marketplaceContract, + auctionId: listing.id, + }), + ).resolves.toMatchInlineSnapshot(` { "bidAmountWei": 2000000000000000000n, "bidderAddress": "0x70997970C51812dc3A010C7d01b50e0d17dc79C8", @@ -263,54 +267,54 @@ describe("Marketplace: English Auctions", () => { } `); - // invalid bid amount, above minimum but below existing winning bid - await expect( - sendAndConfirmTransaction({ - account: TEST_ACCOUNT_B, - transaction: bidInAuction({ - auctionId: listing.id, - contract: marketplaceContract, - bidAmount: "1.5", + // invalid bid amount, above minimum but below existing winning bid + await expect( + sendAndConfirmTransaction({ + account: TEST_ACCOUNT_B, + transaction: bidInAuction({ + auctionId: listing.id, + contract: marketplaceContract, + bidAmount: "1.5", + }), }), - }), - ).rejects.toThrowErrorMatchingInlineSnapshot( - "[Error: Bid amount is too low to outbid the existing winning bid]", - ); + ).rejects.toThrowErrorMatchingInlineSnapshot( + "[Error: Bid amount is too low to outbid the existing winning bid]", + ); - // invalid bid amount, above winning bit but below bid + bidBuffer (default 500bps) - await expect( - sendAndConfirmTransaction({ - account: TEST_ACCOUNT_B, - transaction: bidInAuction({ - auctionId: listing.id, - contract: marketplaceContract, - // 2 * 1.05 = 2.1, so 2.05 is invalid - bidAmount: "2.05", + // invalid bid amount, above winning bit but below bid + bidBuffer (default 500bps) + await expect( + sendAndConfirmTransaction({ + account: TEST_ACCOUNT_B, + transaction: bidInAuction({ + auctionId: listing.id, + contract: marketplaceContract, + // 2 * 1.05 = 2.1, so 2.05 is invalid + bidAmount: "2.05", + }), }), - }), - ).rejects.toThrowErrorMatchingInlineSnapshot( - "[Error: Bid amount is too low to outbid the existing winning bid]", - ); + ).rejects.toThrowErrorMatchingInlineSnapshot( + "[Error: Bid amount is too low to outbid the existing winning bid]", + ); - // actually outbid the winning bid - await expect( - sendAndConfirmTransaction({ - account: TEST_ACCOUNT_B, - transaction: bidInAuction({ - auctionId: listing.id, - contract: marketplaceContract, - bidAmount: "3", + // actually outbid the winning bid + await expect( + sendAndConfirmTransaction({ + account: TEST_ACCOUNT_B, + transaction: bidInAuction({ + auctionId: listing.id, + contract: marketplaceContract, + bidAmount: "3", + }), }), - }), - ).resolves.toBeDefined(); + ).resolves.toBeDefined(); - // check for a new winning bid - await expect( - getWinningBid({ - contract: marketplaceContract, - auctionId: listing.id, - }), - ).resolves.toMatchInlineSnapshot(` + // check for a new winning bid + await expect( + getWinningBid({ + contract: marketplaceContract, + auctionId: listing.id, + }), + ).resolves.toMatchInlineSnapshot(` { "bidAmountWei": 3000000000000000000n, "bidderAddress": "0x70997970C51812dc3A010C7d01b50e0d17dc79C8", @@ -325,24 +329,24 @@ describe("Marketplace: English Auctions", () => { } `); - // buyout auction - await expect( - sendAndConfirmTransaction({ - account: TEST_ACCOUNT_B, - transaction: buyoutAuction({ + // buyout auction + await expect( + sendAndConfirmTransaction({ + account: TEST_ACCOUNT_B, + transaction: buyoutAuction({ + contract: marketplaceContract, + auctionId: listing.id, + }), + }), + ).resolves.toBeDefined(); + + // check for a new winning bid + await expect( + getWinningBid({ contract: marketplaceContract, auctionId: listing.id, }), - }), - ).resolves.toBeDefined(); - - // check for a new winning bid - await expect( - getWinningBid({ - contract: marketplaceContract, - auctionId: listing.id, - }), - ).resolves.toMatchInlineSnapshot(` + ).resolves.toMatchInlineSnapshot(` { "bidAmountWei": 10000000000000000000n, "bidderAddress": "0x70997970C51812dc3A010C7d01b50e0d17dc79C8", @@ -356,5 +360,6 @@ describe("Marketplace: English Auctions", () => { }, } `); - }); -}); + }); + }, +); diff --git a/packages/thirdweb/src/wallets/utils/getTokenBalance.test.ts b/packages/thirdweb/src/wallets/utils/getTokenBalance.test.ts index 93c79985c93..3c68e132867 100644 --- a/packages/thirdweb/src/wallets/utils/getTokenBalance.test.ts +++ b/packages/thirdweb/src/wallets/utils/getTokenBalance.test.ts @@ -9,7 +9,7 @@ import { deployERC20Contract } from "../../extensions/prebuilts/deploy-erc20.js" import { sendAndConfirmTransaction } from "../../transaction/actions/send-and-confirm-transaction.js"; import { getTokenBalance } from "./getTokenBalance.js"; -describe("getTokenBalance", () => { +describe.runIf(process.env.TW_SECRET_KEY)("getTokenBalance", () => { it("should work for native token", async () => { const result = await getTokenBalance({ account: TEST_ACCOUNT_A, From 89637f6cd4cd245c74f5eff834c7004f68f7daf7 Mon Sep 17 00:00:00 2001 From: Joaquim Verges Date: Fri, 7 Jun 2024 10:04:02 +1200 Subject: [PATCH 5/5] more test skip --- packages/thirdweb/src/contract/deployment/publisher.test.ts | 2 +- .../thirdweb/src/extensions/marketplace/offers/offers.test.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/thirdweb/src/contract/deployment/publisher.test.ts b/packages/thirdweb/src/contract/deployment/publisher.test.ts index e49b3afc543..630d80cecd9 100644 --- a/packages/thirdweb/src/contract/deployment/publisher.test.ts +++ b/packages/thirdweb/src/contract/deployment/publisher.test.ts @@ -7,7 +7,7 @@ vi.mock("../../../transaction/read-contract"); vi.mock("../../../storage/download"); // TODO: Add mocks to these tests instead of using live data -describe("fetchPublishedContract", () => { +describe.runIf(process.env.TW_SECRET_KEY)("fetchPublishedContract", () => { it("fetches the latest published contract when no version is specified", async () => { const result = await fetchPublishedContractMetadata({ publisher: "0x4a706de5CE9bfe2f9C37BA945805e396d1810824", diff --git a/packages/thirdweb/src/extensions/marketplace/offers/offers.test.ts b/packages/thirdweb/src/extensions/marketplace/offers/offers.test.ts index 86018cff83b..4996a717990 100644 --- a/packages/thirdweb/src/extensions/marketplace/offers/offers.test.ts +++ b/packages/thirdweb/src/extensions/marketplace/offers/offers.test.ts @@ -31,7 +31,7 @@ import { getOffer } from "./read/getOffer.js"; import { acceptOffer } from "./write/acceptOffer.js"; import { makeOffer } from "./write/makeOffer.js"; -describe("Marketplace: Offers", () => { +describe.runIf(process.env.TW_SECRET_KEY)("Marketplace: Offers", () => { let nftTokenId: bigint; let marketplaceContract: ThirdwebContract; let erc721Contract: ThirdwebContract;