Skip to content

Commit df734ba

Browse files
[SDK] Fix: Improve enclave and userop error messages (#5653)
1 parent 015293e commit df734ba

File tree

8 files changed

+43
-25
lines changed

8 files changed

+43
-25
lines changed

.changeset/curly-cycles-hammer.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"thirdweb": patch
3+
---
4+
5+
More helpful error messages for enclave and userop errors

packages/thirdweb/src/utils/encoding/hex.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ import { describe, expect, it } from "vitest";
22
import { numberToHex } from "./hex.js";
33

44
describe("hex.ts", () => {
5+
it("should convert number with no padding", () => {
6+
const result = numberToHex(1);
7+
expect(result).toBe("0x1");
8+
});
9+
510
it("should convert", () => {
611
const result = numberToHex(100n, { size: 32, signed: false });
712
expect(result).toBe(

packages/thirdweb/src/wallets/in-app/core/actions/generate-wallet.enclave.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ export async function generateWallet({
3131
);
3232

3333
if (!response.ok) {
34-
throw new Error("Failed to generate wallet");
34+
throw new Error(
35+
`Failed to generate wallet - ${response.status} ${response.statusText}`,
36+
);
3537
}
3638

3739
const { wallet } = (await response.json()) as {

packages/thirdweb/src/wallets/in-app/core/actions/sign-message.enclave.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ export async function signMessage({
4343
);
4444

4545
if (!response.ok) {
46-
throw new Error("Failed to sign message");
46+
throw new Error(
47+
`Failed to sign message - ${response.status} ${response.statusText}`,
48+
);
4749
}
4850

4951
const signedMessage = (await response.json()) as {

packages/thirdweb/src/wallets/in-app/core/actions/sign-transaction.enclave.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ export async function signTransaction({
3838
);
3939

4040
if (!response.ok) {
41-
throw new Error("Failed to sign transaction");
41+
throw new Error(
42+
`Failed to sign transaction - ${response.status} ${response.statusText}`,
43+
);
4244
}
4345

4446
const signedTransaction = (await response.json()) as {

packages/thirdweb/src/wallets/in-app/core/actions/sign-typed-data.enclave.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ export async function signTypedData<
4141
);
4242

4343
if (!response.ok) {
44-
throw new Error("Failed to sign typed data");
44+
throw new Error(
45+
`Failed to sign typed data - ${response.status} ${response.statusText}`,
46+
);
4547
}
4648

4749
const signedTypedData = (await response.json()) as {

packages/thirdweb/src/wallets/smart/lib/userop.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,9 @@ export async function waitForUserOpReceipt(
103103
}
104104
await new Promise((resolve) => setTimeout(resolve, interval));
105105
}
106-
throw new Error("Timeout waiting for userOp to be mined");
106+
throw new Error(
107+
`Timeout waiting for userOp to be mined on chain ${args.chain.id} with UserOp hash: ${args.userOpHash}`,
108+
);
107109
}
108110

109111
/**

packages/thirdweb/src/wallets/smart/smart-wallet-dev.test.ts

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { beforeAll, describe, expect, it } from "vitest";
22
import { TEST_CLIENT } from "../../../test/src/test-clients.js";
3-
import { TEST_ACCOUNT_A } from "../../../test/src/test-wallets.js";
4-
import { defineChain } from "../../chains/utils.js";
3+
import { arbitrumSepolia } from "../../chains/chain-definitions/arbitrum.js";
54
import { type ThirdwebContract, getContract } from "../../contract/contract.js";
65
import { balanceOf } from "../../extensions/erc1155/__generated__/IERC1155/read/balanceOf.js";
76
import { claimTo } from "../../extensions/erc1155/drops/write/claimTo.js";
@@ -11,40 +10,38 @@ import { sendTransaction } from "../../transaction/actions/send-transaction.js";
1110
import { prepareTransaction } from "../../transaction/prepare-transaction.js";
1211
import type { Address } from "../../utils/address.js";
1312
import { isContractDeployed } from "../../utils/bytecode/is-contract-deployed.js";
14-
import { setThirdwebDomains } from "../../utils/domains.js";
1513
import type { Account, Wallet } from "../interfaces/wallet.js";
14+
import { generateAccount } from "../utils/generateAccount.js";
1615
import { smartWallet } from "./smart-wallet.js";
17-
1816
let wallet: Wallet;
1917
let smartAccount: Account;
2018
let smartWalletAddress: Address;
2119
let personalAccount: Account;
2220
let accountContract: ThirdwebContract;
2321

24-
const chain = defineChain(531050104);
22+
const chain = arbitrumSepolia;
2523
const client = TEST_CLIENT;
2624
const contract = getContract({
2725
client,
2826
chain,
2927
address: "0x6A7a26c9a595E6893C255C9dF0b593e77518e0c3",
3028
});
3129
describe.runIf(process.env.TW_SECRET_KEY).skip.sequential(
32-
"SmartWallet policy tests",
30+
"SmartWallet dev tests",
3331
{
3432
retry: 0,
3533
timeout: 240_000,
3634
},
3735
() => {
3836
beforeAll(async () => {
39-
setThirdwebDomains({
40-
rpc: "rpc.thirdweb-dev.com",
41-
storage: "storage.thirdweb-dev.com",
42-
bundler: "bundler.thirdweb-dev.com",
43-
});
44-
personalAccount = TEST_ACCOUNT_A;
45-
// personalAccount = await generateAccount({
46-
// client,
37+
// setThirdwebDomains({
38+
// rpc: "rpc.thirdweb-dev.com",
39+
// storage: "storage.thirdweb-dev.com",
40+
// bundler: "bundler.thirdweb-dev.com",
4741
// });
42+
personalAccount = await generateAccount({
43+
client,
44+
});
4845
wallet = smartWallet({
4946
chain,
5047
gasless: true,
@@ -65,13 +62,14 @@ describe.runIf(process.env.TW_SECRET_KEY).skip.sequential(
6562
expect(smartWalletAddress).toHaveLength(42);
6663
});
6764

68-
it.skip("can sign a msg", async () => {
69-
await smartAccount.signMessage({ message: "hello world" });
70-
const isDeployed = await isContractDeployed(accountContract);
71-
expect(isDeployed).toEqual(true);
65+
it("can sign a msg", async () => {
66+
const signature = await smartAccount.signMessage({
67+
message: "hello world",
68+
});
69+
expect(signature.length).toBeGreaterThan(0);
7270
});
7371

74-
it.skip("should send a transaction", async () => {
72+
it("should send a transaction", async () => {
7573
const tx = prepareTransaction({
7674
client,
7775
chain,
@@ -106,7 +104,7 @@ describe.runIf(process.env.TW_SECRET_KEY).skip.sequential(
106104
expect(balance).toEqual(1n);
107105
});
108106

109-
it("should deploy a published autofactory contract", async () => {
107+
it.skip("should deploy a published autofactory contract", async () => {
110108
const address = await deployPublishedContract({
111109
client: TEST_CLIENT,
112110
chain,

0 commit comments

Comments
 (0)