diff --git a/packages/controller/src/__tests__/controllerDefaults.test.ts b/packages/controller/src/__tests__/controllerDefaults.test.ts index a1613dc2f4..7ad43b7cad 100644 --- a/packages/controller/src/__tests__/controllerDefaults.test.ts +++ b/packages/controller/src/__tests__/controllerDefaults.test.ts @@ -41,30 +41,30 @@ describe("ControllerProvider defaults", () => { ); }); - test("should throw error when using non-Cartridge RPC for mainnet", async () => { - const invalidChains = [ + test("should allow non-Cartridge RPC for mainnet", async () => { + const customChains = [ { rpcUrl: "https://some-other-provider.com/starknet/mainnet/rpc/v0_9" }, ]; expect(() => { new ControllerProvider({ - chains: invalidChains, + chains: customChains, defaultChainId: constants.StarknetChainId.SN_MAIN, }); - }).toThrow("Only Cartridge RPC providers are allowed for mainnet"); + }).not.toThrow(); }); - test("should throw error when using non-Cartridge RPC for sepolia", async () => { - const invalidChains = [ + test("should allow non-Cartridge RPC for sepolia", async () => { + const customChains = [ { rpcUrl: "https://some-other-provider.com/starknet/sepolia/rpc/v0_9" }, ]; expect(() => { new ControllerProvider({ - chains: invalidChains, + chains: customChains, defaultChainId: constants.StarknetChainId.SN_SEPOLIA, }); - }).toThrow("Only Cartridge RPC providers are allowed for sepolia"); + }).not.toThrow(); }); test("should allow non-Cartridge RPC for custom chains", () => { diff --git a/packages/controller/src/__tests__/parseChainId.test.ts b/packages/controller/src/__tests__/parseChainId.test.ts index df907d36b6..dc073fe902 100644 --- a/packages/controller/src/__tests__/parseChainId.test.ts +++ b/packages/controller/src/__tests__/parseChainId.test.ts @@ -42,17 +42,25 @@ describe("parseChainId", () => { }); }); + describe("Non-Cartridge hosts", () => { + test("returns placeholder chainId in Node", () => { + expect(parseChainId(new URL("http://dl:123123"))).toBe( + shortString.encodeShortString("LOCALHOST"), + ); + }); + }); + describe("Error cases", () => { test("throws error for unsupported URL format", () => { expect(() => - parseChainId(new URL("https://api.example.com/unsupported")), - ).toThrow("Chain https://api.example.com/unsupported not supported"); + parseChainId(new URL("https://api.cartridge.gg/unsupported")), + ).toThrow("Chain https://api.cartridge.gg/unsupported not supported"); }); test("throws error for URLs without proper chain identifiers", () => { expect(() => - parseChainId(new URL("https://api.example.com/v1/starknet")), - ).toThrow("Chain https://api.example.com/v1/starknet not supported"); + parseChainId(new URL("https://api.cartridge.gg/v1/starknet")), + ).toThrow("Chain https://api.cartridge.gg/v1/starknet not supported"); }); }); }); diff --git a/packages/controller/src/controller.ts b/packages/controller/src/controller.ts index c801df32f8..5f587e27f4 100644 --- a/packages/controller/src/controller.ts +++ b/packages/controller/src/controller.ts @@ -570,20 +570,6 @@ export default class ControllerProvider extends BaseProvider { const url = new URL(chain.rpcUrl); const chainId = parseChainId(url); - // Validate that mainnet and sepolia must use Cartridge RPC - const isMainnet = chainId === constants.StarknetChainId.SN_MAIN; - const isSepolia = chainId === constants.StarknetChainId.SN_SEPOLIA; - const isCartridgeRpc = url.hostname === "api.cartridge.gg"; - const isLocalhost = - url.hostname === "localhost" || url.hostname === "127.0.0.1"; - - if ((isMainnet || isSepolia) && !(isCartridgeRpc || isLocalhost)) { - throw new Error( - `Only Cartridge RPC providers are allowed for ${isMainnet ? "mainnet" : "sepolia"}. ` + - `Please use: https://api.cartridge.gg/x/starknet/${isMainnet ? "mainnet" : "sepolia"}/rpc/v0_9`, - ); - } - this.chains.set(chainId, chain); } catch (error) { console.error(`Failed to parse chainId for ${chain.rpcUrl}:`, error); diff --git a/packages/controller/src/utils.ts b/packages/controller/src/utils.ts index 4a9fff06a1..20de1f738e 100644 --- a/packages/controller/src/utils.ts +++ b/packages/controller/src/utils.ts @@ -138,17 +138,14 @@ export function humanizeString(str: string): string { export function parseChainId(url: URL): ChainId { const parts = url.pathname.split("/"); + const isCartridgeHost = url.hostname === "api.cartridge.gg"; - // Handle localhost URLs by making a synchronous call to getChainId - if ( - url.hostname === "localhost" || - url.hostname === "127.0.0.1" || - url.hostname === "0.0.0.0" - ) { + // Handle non-Cartridge hosts by making a synchronous call to getChainId + if (!isCartridgeHost) { // Check if we're in a browser environment if (typeof XMLHttpRequest === "undefined") { // In Node.js environment (like tests), we can't make synchronous HTTP calls - // For now, we'll use a placeholder chainId for localhost in tests + // For now, we'll use a placeholder chainId for non-Cartridge hosts in tests console.warn( `Cannot make synchronous HTTP call in Node.js environment for ${url.toString()}`, );