Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/curly-cycles-hammer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"thirdweb": patch
---

More helpful error messages for enclave and userop errors
5 changes: 5 additions & 0 deletions packages/thirdweb/src/utils/encoding/hex.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 3 additions & 1 deletion packages/thirdweb/src/wallets/smart/lib/userop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,9 @@
}
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}`,
);

Check warning on line 108 in packages/thirdweb/src/wallets/smart/lib/userop.ts

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/wallets/smart/lib/userop.ts#L106-L108

Added lines #L106 - L108 were not covered by tests
}

/**
Expand Down
38 changes: 18 additions & 20 deletions packages/thirdweb/src/wallets/smart/smart-wallet-dev.test.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -11,40 +10,38 @@ 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,
chain,
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,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
Loading