diff --git a/.changeset/curly-cycles-hammer.md b/.changeset/curly-cycles-hammer.md new file mode 100644 index 00000000000..fc699a1631e --- /dev/null +++ b/.changeset/curly-cycles-hammer.md @@ -0,0 +1,5 @@ +--- +"thirdweb": patch +--- + +More helpful error messages for enclave and userop errors diff --git a/packages/thirdweb/src/utils/encoding/hex.test.ts b/packages/thirdweb/src/utils/encoding/hex.test.ts index 2a5f1bbf60c..c305c9d543c 100644 --- a/packages/thirdweb/src/utils/encoding/hex.test.ts +++ b/packages/thirdweb/src/utils/encoding/hex.test.ts @@ -2,6 +2,11 @@ import { describe, expect, it } from "vitest"; import { numberToHex } from "./hex.js"; describe("hex.ts", () => { + it("should convert number with no padding", () => { + const result = numberToHex(1); + expect(result).toBe("0x1"); + }); + it("should convert", () => { const result = numberToHex(100n, { size: 32, signed: false }); expect(result).toBe( diff --git a/packages/thirdweb/src/wallets/in-app/core/actions/generate-wallet.enclave.ts b/packages/thirdweb/src/wallets/in-app/core/actions/generate-wallet.enclave.ts index a136f37763f..02bfb292912 100644 --- a/packages/thirdweb/src/wallets/in-app/core/actions/generate-wallet.enclave.ts +++ b/packages/thirdweb/src/wallets/in-app/core/actions/generate-wallet.enclave.ts @@ -31,7 +31,9 @@ export async function generateWallet({ ); if (!response.ok) { - throw new Error("Failed to generate wallet"); + throw new Error( + `Failed to generate wallet - ${response.status} ${response.statusText}`, + ); } const { wallet } = (await response.json()) as { diff --git a/packages/thirdweb/src/wallets/in-app/core/actions/sign-message.enclave.ts b/packages/thirdweb/src/wallets/in-app/core/actions/sign-message.enclave.ts index cf605151f09..d2d1b88d590 100644 --- a/packages/thirdweb/src/wallets/in-app/core/actions/sign-message.enclave.ts +++ b/packages/thirdweb/src/wallets/in-app/core/actions/sign-message.enclave.ts @@ -43,7 +43,9 @@ export async function signMessage({ ); if (!response.ok) { - throw new Error("Failed to sign message"); + throw new Error( + `Failed to sign message - ${response.status} ${response.statusText}`, + ); } const signedMessage = (await response.json()) as { diff --git a/packages/thirdweb/src/wallets/in-app/core/actions/sign-transaction.enclave.ts b/packages/thirdweb/src/wallets/in-app/core/actions/sign-transaction.enclave.ts index 28a353c00b2..e638d64ec19 100644 --- a/packages/thirdweb/src/wallets/in-app/core/actions/sign-transaction.enclave.ts +++ b/packages/thirdweb/src/wallets/in-app/core/actions/sign-transaction.enclave.ts @@ -38,7 +38,9 @@ export async function signTransaction({ ); if (!response.ok) { - throw new Error("Failed to sign transaction"); + throw new Error( + `Failed to sign transaction - ${response.status} ${response.statusText}`, + ); } const signedTransaction = (await response.json()) as { diff --git a/packages/thirdweb/src/wallets/in-app/core/actions/sign-typed-data.enclave.ts b/packages/thirdweb/src/wallets/in-app/core/actions/sign-typed-data.enclave.ts index 4808ba33cc5..43e890d1743 100644 --- a/packages/thirdweb/src/wallets/in-app/core/actions/sign-typed-data.enclave.ts +++ b/packages/thirdweb/src/wallets/in-app/core/actions/sign-typed-data.enclave.ts @@ -41,7 +41,9 @@ export async function signTypedData< ); if (!response.ok) { - throw new Error("Failed to sign typed data"); + throw new Error( + `Failed to sign typed data - ${response.status} ${response.statusText}`, + ); } const signedTypedData = (await response.json()) as { diff --git a/packages/thirdweb/src/wallets/smart/lib/userop.ts b/packages/thirdweb/src/wallets/smart/lib/userop.ts index 0d3b46aa13f..db00983de90 100644 --- a/packages/thirdweb/src/wallets/smart/lib/userop.ts +++ b/packages/thirdweb/src/wallets/smart/lib/userop.ts @@ -103,7 +103,9 @@ export async function waitForUserOpReceipt( } await new Promise((resolve) => setTimeout(resolve, interval)); } - throw new Error("Timeout waiting for userOp to be mined"); + throw new Error( + `Timeout waiting for userOp to be mined on chain ${args.chain.id} with UserOp hash: ${args.userOpHash}`, + ); } /** diff --git a/packages/thirdweb/src/wallets/smart/smart-wallet-dev.test.ts b/packages/thirdweb/src/wallets/smart/smart-wallet-dev.test.ts index 18b50bb7674..8514febe29c 100644 --- a/packages/thirdweb/src/wallets/smart/smart-wallet-dev.test.ts +++ b/packages/thirdweb/src/wallets/smart/smart-wallet-dev.test.ts @@ -1,7 +1,6 @@ import { beforeAll, describe, expect, it } from "vitest"; import { TEST_CLIENT } from "../../../test/src/test-clients.js"; -import { TEST_ACCOUNT_A } from "../../../test/src/test-wallets.js"; -import { defineChain } from "../../chains/utils.js"; +import { arbitrumSepolia } from "../../chains/chain-definitions/arbitrum.js"; import { type ThirdwebContract, getContract } from "../../contract/contract.js"; import { balanceOf } from "../../extensions/erc1155/__generated__/IERC1155/read/balanceOf.js"; import { claimTo } from "../../extensions/erc1155/drops/write/claimTo.js"; @@ -11,17 +10,16 @@ import { sendTransaction } from "../../transaction/actions/send-transaction.js"; import { prepareTransaction } from "../../transaction/prepare-transaction.js"; import type { Address } from "../../utils/address.js"; import { isContractDeployed } from "../../utils/bytecode/is-contract-deployed.js"; -import { setThirdwebDomains } from "../../utils/domains.js"; import type { Account, Wallet } from "../interfaces/wallet.js"; +import { generateAccount } from "../utils/generateAccount.js"; import { smartWallet } from "./smart-wallet.js"; - let wallet: Wallet; let smartAccount: Account; let smartWalletAddress: Address; let personalAccount: Account; let accountContract: ThirdwebContract; -const chain = defineChain(531050104); +const chain = arbitrumSepolia; const client = TEST_CLIENT; const contract = getContract({ client, @@ -29,22 +27,21 @@ const contract = getContract({ address: "0x6A7a26c9a595E6893C255C9dF0b593e77518e0c3", }); describe.runIf(process.env.TW_SECRET_KEY).skip.sequential( - "SmartWallet policy tests", + "SmartWallet dev tests", { retry: 0, timeout: 240_000, }, () => { beforeAll(async () => { - setThirdwebDomains({ - rpc: "rpc.thirdweb-dev.com", - storage: "storage.thirdweb-dev.com", - bundler: "bundler.thirdweb-dev.com", - }); - personalAccount = TEST_ACCOUNT_A; - // personalAccount = await generateAccount({ - // client, + // setThirdwebDomains({ + // rpc: "rpc.thirdweb-dev.com", + // storage: "storage.thirdweb-dev.com", + // bundler: "bundler.thirdweb-dev.com", // }); + personalAccount = await generateAccount({ + client, + }); wallet = smartWallet({ chain, gasless: true, @@ -65,13 +62,14 @@ describe.runIf(process.env.TW_SECRET_KEY).skip.sequential( expect(smartWalletAddress).toHaveLength(42); }); - it.skip("can sign a msg", async () => { - await smartAccount.signMessage({ message: "hello world" }); - const isDeployed = await isContractDeployed(accountContract); - expect(isDeployed).toEqual(true); + it("can sign a msg", async () => { + const signature = await smartAccount.signMessage({ + message: "hello world", + }); + expect(signature.length).toBeGreaterThan(0); }); - it.skip("should send a transaction", async () => { + it("should send a transaction", async () => { const tx = prepareTransaction({ client, chain, @@ -106,7 +104,7 @@ describe.runIf(process.env.TW_SECRET_KEY).skip.sequential( expect(balance).toEqual(1n); }); - it("should deploy a published autofactory contract", async () => { + it.skip("should deploy a published autofactory contract", async () => { const address = await deployPublishedContract({ client: TEST_CLIENT, chain,