Skip to content

wallets: throw error for testnet in prod, auto-convert mainnet in staging#1584

Open
albertoelias-crossmint wants to merge 2 commits intomainfrom
devin/1771024291-chain-env-validation-upgrade
Open

wallets: throw error for testnet in prod, auto-convert mainnet in staging#1584
albertoelias-crossmint wants to merge 2 commits intomainfrom
devin/1771024291-chain-env-validation-upgrade

Conversation

@albertoelias-crossmint
Copy link
Collaborator

@albertoelias-crossmint albertoelias-crossmint commented Feb 13, 2026

Description

Upgrades chain environment validation from warning-only to enforcing behavior:

  • Testnet in production: Now throws InvalidEnvironmentError instead of logging a warning. This is a breaking change for any consumers currently passing testnet chains with production API keys.
  • Mainnet in non-production (staging/dev): Automatically converts to the testnet equivalent using a new MAINNET_TO_TESTNET_MAP (15 chains mapped). Logs a warning about the conversion. If no testnet mapping exists, falls back to a warning without conversion.

validateChainEnvironment now returns the (potentially converted) chain, and all three callers (getOrCreateWallet, getWallet, createWallet) apply the returned value.

Things for reviewer to verify

  • Type cast: return testnetEquivalent as unknown as C — the generic C will still reflect the original mainnet type at the call site even though the runtime value is now a testnet chain. Confirm this doesn't cause issues downstream.
  • Map completeness: 15 mainnet→testnet mappings are included. Verify no expected AA chains are missing (e.g., ethereum is absent — confirm it's not in PRODUCTION_AA_CHAINS).

Test plan

  • Unit tests updated: testnet-in-prod tests now expect InvalidEnvironmentError thrown; mainnet-in-staging/dev tests expect auto-conversion with warning log; new test for mainnet with no testnet equivalent (arbitrumnova)
  • All 33 wallet-factory tests pass
  • Lint passes (biome check)

Package updates

Changeset still needs to be added via pnpm change:add.


Link to Devin run | Requested by @albertoelias-crossmint


Open with Devin

…net in staging

Co-Authored-By: Alberto Elias <alberto.elias@paella.dev>
@devin-ai-integration
Copy link
Contributor

Original prompt from Alberto Elias
in these 2 prs:

https://github.com/Crossmint/crossmint-sdk/pull/1565/changes#diff-cc1f073b7b2d8ca4905b2faca08758f53d88122ef1b721dae9c6098cf852b9d1

https://github.com/Paella-Labs/crossbit-main/pull/23183/changes

i added some logs when developers use the wrong chain for that environment. I now want to make a pr that:

- when using a testnet in production, it throws an error
- when using a mainnet in staging, it automatically converts it to the mainnet equivalent

@devin-ai-integration
Copy link
Contributor

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR that start with 'DevinAI' or '@devin'.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

@changeset-bot
Copy link

changeset-bot bot commented Feb 13, 2026

🦋 Changeset detected

Latest commit: 1a8c0c5

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

This PR includes changesets to release 9 packages
Name Type
@crossmint/wallets-sdk Minor
expo-demo Patch
@crossmint/client-sdk-react-base Patch
@crossmint/client-sdk-react-native-ui Patch
@crossmint/client-sdk-react-ui Patch
@crossmint/auth-ssr-nextjs-demo Patch
@crossmint/client-sdk-nextjs-starter Patch
@crossmint/wallets-quickstart-devkit Patch
@crossmint/client-sdk-smart-wallet-next-starter 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

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

3 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

environment,
message: `Chain "${chain}" is a mainnet chain and cannot be used in ${environment} environment. Automatically converted to "${testnetEquivalent}".`,
});
return testnetEquivalent as unknown as C;
Copy link
Contributor

Choose a reason for hiding this comment

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

Type cast is safe - both mainnet and testnet are EVM chains, and downstream code (getChainType(), assembleSigner()) only distinguishes solana/stellar/evm, not specific EVM chains

Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/wallets/src/wallets/wallet-factory.ts
Line: 425:425

Comment:
Type cast is safe - both mainnet and testnet are EVM chains, and downstream code (`getChainType()`, `assembleSigner()`) only distinguishes solana/stellar/evm, not specific EVM chains

How can I resolve this? If you propose a fix, please make it concise.

Copy link
Contributor

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

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

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 5 additional findings.

Open in Devin Review

Co-Authored-By: Alberto Elias <alberto.elias@paella.dev>
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

4 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

@github-actions
Copy link
Contributor

🔥 Smoke Test Results

Status: Passed

Statistics

  • Total Tests: 5
  • Passed: 5 ✅
  • Failed: 0
  • Skipped: 0
  • Duration: 4.72 min

✅ All smoke tests passed!

All critical flows are working correctly.


This is a non-blocking smoke test. Full regression tests run separately.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant