Skip to content

[SDK] Optimize 4337 signature performance #7693

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 24, 2025

Conversation

joaquim-verges
Copy link
Member

@joaquim-verges joaquim-verges commented Jul 24, 2025


PR-Codex overview

This PR focuses on optimizing the handling of token prices by replacing bracket notation with dot notation for accessing USD prices. It also removes redundant code related to signature verification in smartAccountSignMessage and smartAccountSignTypedData.

Detailed summary

  • Changed price access from prices["USD"] to prices.USD in multiple files.
  • Removed redundant signature verification logic from smartAccountSignMessage and smartAccountSignTypedData.
  • Eliminated an unused function checkFor712Factory in smart/lib/signing.ts.
  • Updated test cases to reflect the removal of factory address usage.

✨ Ask PR-Codex anything about this PR by commenting with /codex {your question}

Summary by CodeRabbit

  • Performance Improvements

    • Optimized the process for generating 4337 signatures, resulting in improved performance for related wallet operations.
  • Chores

    • Added a changeset documenting the performance optimization for the "thirdweb" package.
  • Bug Fixes

    • Updated price data access to improve consistency across payment and token-related features.
  • Tests

    • Removed a test case related to factory usage without replay protection and adjusted timing in parallel transaction tests.

Copy link

vercel bot commented Jul 24, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
docs-v2 ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 24, 2025 7:39am
nebula ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 24, 2025 7:39am
thirdweb_playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 24, 2025 7:39am
thirdweb-www ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 24, 2025 7:39am
wallet-ui ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 24, 2025 7:39am

Copy link

changeset-bot bot commented Jul 24, 2025

🦋 Changeset detected

Latest commit: b38e85a

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
thirdweb Patch
@thirdweb-dev/nebula Patch
@thirdweb-dev/wagmi-adapter Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Contributor

coderabbitai bot commented Jul 24, 2025

Walkthrough

A changeset was added documenting a performance optimization for the "4337 signature" in the "thirdweb" package. In the signing library, the verification step using verifyHash was removed from two signature-generating functions, and related imports were cleaned up. Multiple files in the payment and crypto modules were updated to access USD prices via dot notation instead of bracket notation. In the smart wallet integration tests, a test case related to a different factory without replay protection was removed, along with some related configuration cleanup and a timing adjustment.

Changes

File(s) Change Summary
.changeset/thirty-eels-decide.md Added a changeset file describing a patch for "thirdweb" related to 4337 signature performance.
packages/thirdweb/src/wallets/smart/lib/signing.ts Removed verifyHash import and usage; eliminated post-signature verification; removed checkFor712Factory; formatting cleanup.
packages/thirdweb/src/pay/buyWithCrypto/getQuote.ts Replaced all prices["USD"] with prices.USD for USD price access; no logic changes.
packages/thirdweb/src/pay/buyWithCrypto/getTransfer.ts Replaced all prices["USD"] with prices.USD for USD price access; no logic changes.
packages/thirdweb/src/pay/buyWithFiat/getQuote.ts Replaced all prices["USD"] with prices.USD for USD price access; no logic changes.
packages/thirdweb/src/react/core/hooks/usePaymentMethods.ts Replaced all prices["USD"] with prices.USD for USD price access; no logic changes.
packages/thirdweb/src/wallets/smart/smart-wallet-integration.test.ts Removed test case "can use a different factory without replay protection"; removed factoryAddress constant; adjusted timing in a parallel tx test; removed factoryAddress from paymaster test config.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.

Warning

Review ran into problems

🔥 Problems

Errors were encountered while retrieving linked issues.

Errors (1)
  • TEAM-0000: Entity not found: Issue - Could not find referenced Issue.
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch _SDK_Optimize_4337_signature_performance

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions bot added packages SDK Involves changes to the thirdweb SDK labels Jul 24, 2025
Copy link
Member Author


How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • merge-queue - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
packages/thirdweb/src/wallets/smart/lib/signing.ts (1)

68-98: Excellent optimization that improves both performance and correctness.

This change correctly removes premature signature verification for undeployed accounts. The key insights:

  1. ERC-6492 signatures are specifically designed for undeployed contracts and cannot be properly verified until deployment
  2. Deployed accounts still maintain proper verification via verifyEip1271Signature (lines 70-78, 156-164)
  3. Performance gain by eliminating redundant verification that would likely fail or give misleading results
  4. Correctness improvement by following the ERC-6492 specification properly

The verification will happen at the appropriate time when the signature is actually used in a transaction.

Also applies to: 154-184

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 170b020 and e95e209.

📒 Files selected for processing (2)
  • .changeset/thirty-eels-decide.md (1 hunks)
  • packages/thirdweb/src/wallets/smart/lib/signing.ts (6 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
**/*.{ts,tsx}

📄 CodeRabbit Inference Engine (CLAUDE.md)

**/*.{ts,tsx}: Write idiomatic TypeScript with explicit function declarations and return types
Limit each file to one stateless, single-responsibility function for clarity
Re-use shared types from @/types or local types.ts barrels
Prefer type aliases over interface except for nominal shapes
Avoid any and unknown unless unavoidable; narrow generics when possible
Choose composition over inheritance; leverage utility types (Partial, Pick, etc.)
Comment only ambiguous logic; avoid restating TypeScript in prose

Files:

  • packages/thirdweb/src/wallets/smart/lib/signing.ts
**/*.{ts,tsx,js,jsx}

📄 CodeRabbit Inference Engine (CLAUDE.md)

Load heavy dependencies inside async paths to keep initial bundle lean (lazy loading)

Files:

  • packages/thirdweb/src/wallets/smart/lib/signing.ts
packages/thirdweb/src/wallets/**

📄 CodeRabbit Inference Engine (CLAUDE.md)

packages/thirdweb/src/wallets/**: Unified Wallet and Account interfaces in wallet architecture
Support for in-app wallets (social/email login)
Smart wallets with account abstraction
EIP-1193, EIP-5792, EIP-7702 standard support in wallet modules

Files:

  • packages/thirdweb/src/wallets/smart/lib/signing.ts
🧠 Learnings (3)
📓 Common learnings
Learnt from: CR
PR: thirdweb-dev/js#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-18T19:19:55.613Z
Learning: Applies to packages/thirdweb/src/wallets/** : EIP-1193, EIP-5792, EIP-7702 standard support in wallet modules
.changeset/thirty-eels-decide.md (1)

Learnt from: CR
PR: thirdweb-dev/js#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-18T19:19:55.613Z
Learning: Applies to packages/thirdweb/src/wallets/** : EIP-1193, EIP-5792, EIP-7702 standard support in wallet modules

packages/thirdweb/src/wallets/smart/lib/signing.ts (8)

Learnt from: CR
PR: thirdweb-dev/js#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-18T19:19:55.613Z
Learning: Applies to packages/thirdweb/src/wallets/** : EIP-1193, EIP-5792, EIP-7702 standard support in wallet modules

Learnt from: CR
PR: thirdweb-dev/js#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-18T19:19:55.613Z
Learning: Applies to packages/thirdweb/src/wallets/** : Smart wallets with account abstraction

Learnt from: CR
PR: thirdweb-dev/js#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-18T19:19:55.613Z
Learning: Applies to packages/thirdweb/src/wallets/** : Unified Wallet and Account interfaces in wallet architecture

Learnt from: CR
PR: thirdweb-dev/js#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-18T19:19:55.613Z
Learning: Applies to test/src/test-wallets.ts : Predefined test accounts are in test/src/test-wallets.ts

Learnt from: CR
PR: thirdweb-dev/js#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-18T19:19:55.613Z
Learning: Applies to src/extensions/** : Auto-generated contracts from ABI definitions in extensions

Learnt from: MananTank
PR: #7298
File: apps/dashboard/src/app/nebula-app/move-funds/move-funds.tsx:424-424
Timestamp: 2025-06-06T23:46:08.795Z
Learning: The thirdweb project has an ESLint rule that restricts direct usage of defineChain. When it's necessary to use defineChain directly, it's acceptable to disable the rule with // eslint-disable-next-line no-restricted-syntax.

Learnt from: CR
PR: thirdweb-dev/js#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-18T19:19:55.613Z
Learning: Applies to **/*.test.{ts,tsx} : Use FORKED_ETHEREUM_CHAIN for mainnet interactions and ANVIL_CHAIN for isolated tests

Learnt from: MananTank
PR: #7332
File: apps/dashboard/src/app/(app)/(dashboard)/(chain)/[chain_id]/[contractAddress]/public-pages/nft/overview/nft-drop-claim.tsx:82-90
Timestamp: 2025-06-13T13:03:41.732Z
Learning: The thirdweb contract object is serializable and can safely be used in contexts (e.g., React-Query keys) that require serializable values.

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: Size
  • GitHub Check: Unit Tests
  • GitHub Check: Analyze (javascript)
🔇 Additional comments (4)
.changeset/thirty-eels-decide.md (1)

1-6: LGTM! Changeset properly documents the performance optimization.

The changeset correctly identifies this as a patch-level change and accurately describes the 4337 signature performance optimization implemented in the codebase.

packages/thirdweb/src/wallets/smart/lib/signing.ts (3)

3-3: LGTM! Proper cleanup of unused import.

The removal of verifyHash from the import statement is consistent with the optimization that removes signature verification for undeployed accounts.


50-50: LGTM! Minor formatting improvements.

The removal of trailing commas and whitespace adjustments improve code consistency without affecting functionality.

Also applies to: 137-137, 199-199


96-96: Immediate verification removal is safe – no downstream dependencies found

Ripgrep searches confirm:

  • smartAccountSignMessage and smartAccountSignTypedData are only invoked in packages/thirdweb/src/wallets/smart/index.ts and defined in signing.ts
  • No references to "Failed to verify signature" or related error handling exist outside signing.ts

You can merge this performance optimization without breaking downstream consumers.

Copy link
Contributor

github-actions bot commented Jul 24, 2025

size-limit report 📦

Path Size Loading time (3g) Running time (snapdragon) Total time
thirdweb (esm) 63.33 KB (0%) 1.3 s (0%) 197 ms (+157.05% 🔺) 1.5 s
thirdweb (cjs) 353.15 KB (-0.02% 🔽) 7.1 s (-0.02% 🔽) 686 ms (+7.79% 🔺) 7.8 s
thirdweb (minimal + tree-shaking) 5.7 KB (0%) 114 ms (0%) 82 ms (+1478.1% 🔺) 196 ms
thirdweb/chains (tree-shaking) 526 B (0%) 11 ms (0%) 37 ms (+1474.08% 🔺) 48 ms
thirdweb/react (minimal + tree-shaking) 19.22 KB (-1.92% 🔽) 385 ms (-1.92% 🔽) 86 ms (+649.09% 🔺) 470 ms

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e95e209 and b38e85a.

📒 Files selected for processing (7)
  • .changeset/thirty-eels-decide.md (1 hunks)
  • packages/thirdweb/src/pay/buyWithCrypto/getQuote.ts (7 hunks)
  • packages/thirdweb/src/pay/buyWithCrypto/getTransfer.ts (3 hunks)
  • packages/thirdweb/src/pay/buyWithFiat/getQuote.ts (3 hunks)
  • packages/thirdweb/src/react/core/hooks/usePaymentMethods.ts (1 hunks)
  • packages/thirdweb/src/wallets/smart/lib/signing.ts (5 hunks)
  • packages/thirdweb/src/wallets/smart/smart-wallet-integration.test.ts (1 hunks)
✅ Files skipped from review due to trivial changes (4)
  • packages/thirdweb/src/react/core/hooks/usePaymentMethods.ts
  • packages/thirdweb/src/pay/buyWithCrypto/getQuote.ts
  • packages/thirdweb/src/pay/buyWithCrypto/getTransfer.ts
  • packages/thirdweb/src/pay/buyWithFiat/getQuote.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • .changeset/thirty-eels-decide.md
  • packages/thirdweb/src/wallets/smart/lib/signing.ts
🧰 Additional context used
📓 Path-based instructions (4)
**/*.{ts,tsx}

📄 CodeRabbit Inference Engine (CLAUDE.md)

**/*.{ts,tsx}: Write idiomatic TypeScript with explicit function declarations and return types
Limit each file to one stateless, single-responsibility function for clarity
Re-use shared types from @/types or local types.ts barrels
Prefer type aliases over interface except for nominal shapes
Avoid any and unknown unless unavoidable; narrow generics when possible
Choose composition over inheritance; leverage utility types (Partial, Pick, etc.)
Comment only ambiguous logic; avoid restating TypeScript in prose

Files:

  • packages/thirdweb/src/wallets/smart/smart-wallet-integration.test.ts
**/*.test.{ts,tsx}

📄 CodeRabbit Inference Engine (CLAUDE.md)

**/*.test.{ts,tsx}: Place tests alongside code: foo.tsfoo.test.ts
Use real function invocations with stub data in tests; avoid brittle mocks
Use Mock Service Worker (MSW) for fetch/HTTP call interception in tests
Keep tests deterministic and side-effect free
Use FORKED_ETHEREUM_CHAIN for mainnet interactions and ANVIL_CHAIN for isolated tests

Files:

  • packages/thirdweb/src/wallets/smart/smart-wallet-integration.test.ts
**/*.{ts,tsx,js,jsx}

📄 CodeRabbit Inference Engine (CLAUDE.md)

Load heavy dependencies inside async paths to keep initial bundle lean (lazy loading)

Files:

  • packages/thirdweb/src/wallets/smart/smart-wallet-integration.test.ts
packages/thirdweb/src/wallets/**

📄 CodeRabbit Inference Engine (CLAUDE.md)

packages/thirdweb/src/wallets/**: Unified Wallet and Account interfaces in wallet architecture
Support for in-app wallets (social/email login)
Smart wallets with account abstraction
EIP-1193, EIP-5792, EIP-7702 standard support in wallet modules

Files:

  • packages/thirdweb/src/wallets/smart/smart-wallet-integration.test.ts
🧠 Learnings (2)
📓 Common learnings
Learnt from: CR
PR: thirdweb-dev/js#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-18T19:19:55.613Z
Learning: Applies to packages/thirdweb/src/wallets/** : EIP-1193, EIP-5792, EIP-7702 standard support in wallet modules
Learnt from: CR
PR: thirdweb-dev/js#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-18T19:19:55.613Z
Learning: Applies to packages/thirdweb/src/wallets/** : Smart wallets with account abstraction
Learnt from: CR
PR: thirdweb-dev/js#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-18T19:19:55.613Z
Learning: Applies to packages/thirdweb/src/wallets/** : Unified `Wallet` and `Account` interfaces in wallet architecture
Learnt from: CR
PR: thirdweb-dev/js#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-18T19:19:55.613Z
Learning: Applies to packages/thirdweb/src/wallets/** : Support for in-app wallets (social/email login)
Learnt from: gregfromstl
PR: thirdweb-dev/js#7450
File: packages/thirdweb/src/bridge/Webhook.ts:57-81
Timestamp: 2025-06-26T19:46:04.024Z
Learning: In the onramp webhook schema (`packages/thirdweb/src/bridge/Webhook.ts`), the `currencyAmount` field is intentionally typed as `z.number()` while other amount fields use `z.string()` because `currencyAmount` represents fiat currency amounts in decimals (like $10.50), whereas other amount fields represent token amounts in wei (very large integers that benefit from bigint representation). The different naming convention (`currencyAmount` vs `amount`) reflects this intentional distinction.
packages/thirdweb/src/wallets/smart/smart-wallet-integration.test.ts (9)

Learnt from: CR
PR: thirdweb-dev/js#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-18T19:19:55.613Z
Learning: Applies to test/src/test-wallets.ts : Predefined test accounts are in test/src/test-wallets.ts

Learnt from: CR
PR: thirdweb-dev/js#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-18T19:19:55.613Z
Learning: Applies to packages/thirdweb/src/wallets/** : EIP-1193, EIP-5792, EIP-7702 standard support in wallet modules

Learnt from: CR
PR: thirdweb-dev/js#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-18T19:19:55.613Z
Learning: Applies to packages/thirdweb/src/wallets/** : Smart wallets with account abstraction

Learnt from: CR
PR: thirdweb-dev/js#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-18T19:19:55.613Z
Learning: Applies to **/*.test.{ts,tsx} : Use FORKED_ETHEREUM_CHAIN for mainnet interactions and ANVIL_CHAIN for isolated tests

Learnt from: CR
PR: thirdweb-dev/js#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-18T19:19:55.613Z
Learning: Applies to **/*.test.{ts,tsx} : Keep tests deterministic and side-effect free

Learnt from: CR
PR: thirdweb-dev/js#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-18T19:19:55.613Z
Learning: Applies to packages/thirdweb/src/wallets/** : Unified Wallet and Account interfaces in wallet architecture

Learnt from: joaquim-verges
PR: #7268
File: packages/thirdweb/src/wallets/in-app/core/wallet/in-app-core.ts:210-216
Timestamp: 2025-06-03T23:44:40.243Z
Learning: EIP7702 wallets do not need special handling for switching chains, unlike EIP4337 wallets which require reconnection when switching chains. In the switchChain method condition, EIP7702 should be intentionally excluded from the reconnection logic.

Learnt from: CR
PR: thirdweb-dev/js#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-18T19:19:55.613Z
Learning: Applies to packages/thirdweb/src/wallets/** : Support for in-app wallets (social/email login)

Learnt from: MananTank
PR: #7081
File: apps/dashboard/src/app/(app)/team/[team_slug]/[project_slug]/assets/create/create-token-page-impl.tsx:160-165
Timestamp: 2025-05-20T19:03:35.954Z
Learning: The claimTo function in Thirdweb's ERC20 extension does not require converting the quantity to the smallest units (using toUnits) as it handles unit conversion internally or works with the units as provided.

@@ -424,7 +350,7 @@ describe.runIf(process.env.TW_SECRET_KEY).sequential(
tokenId: 0n,
}),
}),
sleep(1000).then(() =>
sleep(1500).then(() =>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Verification agent

🧩 Analysis chain

Timing adjustment may indicate underlying race condition.

The increase from 1000ms to 1500ms suggests potential flakiness in the parallel transaction test. While this change may resolve immediate test stability issues, consider investigating the root cause of the timing dependency.


🏁 Script executed:

#!/bin/bash
# Description: Check for other timing-related adjustments or race condition patterns in smart wallet tests

# Search for other sleep/timing patterns in smart wallet tests
rg -A 3 -B 3 "sleep\(|setTimeout\(" packages/thirdweb/src/wallets/smart/ --type ts

# Look for race condition comments or TODO items related to timing
rg -i "race|timing|flaky|parallel" packages/thirdweb/src/wallets/smart/ --type ts

Length of output: 9897


Avoid arbitrary time-based waits in tests

Increasing the timeout to 1500 ms may suppress flakiness but doesn’t address the underlying race condition. Tests should rely on explicit waits (e.g. awaiting transaction confirmations or deployment events) rather than fixed delays.

Please update the following locations:

  • packages/thirdweb/src/wallets/smart/smart-wallet-integration.test.ts
    • Line 353: replace sleep(1500).then(() => …) with an explicit wait for the second TX’s confirmation or the account deployment.
    • Other instances of await new Promise(resolve => setTimeout(resolve, 1000)) (used to “prevent race condition”): replace these with deterministic checks (e.g. provider.waitForTransaction, polling isContractDeployed, or event listeners).

This aligns with our testing guideline to keep tests deterministic and side-effect free.

🤖 Prompt for AI Agents
In packages/thirdweb/src/wallets/smart/smart-wallet-integration.test.ts at line
353, replace the arbitrary sleep(1500).then(...) call with an explicit wait that
listens for the second transaction's confirmation or the account deployment
event. Similarly, locate other instances of await new Promise(resolve =>
setTimeout(resolve, 1000)) used to prevent race conditions and replace them with
deterministic waits such as provider.waitForTransaction, polling a contract
deployment status function like isContractDeployed, or using event listeners to
ensure the test only proceeds once the necessary blockchain state changes are
confirmed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
packages SDK Involves changes to the thirdweb SDK
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant