wallets: throw error for testnet in prod, auto-convert mainnet in staging#1584
wallets: throw error for testnet in prod, auto-convert mainnet in staging#1584albertoelias-crossmint wants to merge 2 commits intomainfrom
Conversation
…net in staging Co-Authored-By: Alberto Elias <alberto.elias@paella.dev>
Original prompt from Alberto Elias |
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
🦋 Changeset detectedLatest commit: 1a8c0c5 The changes in this PR will be included in the next version bump. This PR includes changesets to release 9 packages
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 |
| 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; |
There was a problem hiding this 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
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.Co-Authored-By: Alberto Elias <alberto.elias@paella.dev>
🔥 Smoke Test Results✅ Status: Passed Statistics
✅ All smoke tests passed!All critical flows are working correctly. This is a non-blocking smoke test. Full regression tests run separately. |
Description
Upgrades chain environment validation from warning-only to enforcing behavior:
InvalidEnvironmentErrorinstead of logging a warning. This is a breaking change for any consumers currently passing testnet chains with production API keys.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.validateChainEnvironmentnow returns the (potentially converted) chain, and all three callers (getOrCreateWallet,getWallet,createWallet) apply the returned value.Things for reviewer to verify
return testnetEquivalent as unknown as C— the genericCwill 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.ethereumis absent — confirm it's not inPRODUCTION_AA_CHAINS).Test plan
InvalidEnvironmentErrorthrown; mainnet-in-staging/dev tests expect auto-conversion with warning log; new test for mainnet with no testnet equivalent (arbitrumnova)biome check)Package updates
Changeset still needs to be added via
pnpm change:add.Link to Devin run | Requested by @albertoelias-crossmint