diff --git a/packages/core/src/initialization/__tests__/anchoring.test.ts b/packages/core/src/initialization/__tests__/anchoring.test.ts index 3f136465c2..c880b123cd 100644 --- a/packages/core/src/initialization/__tests__/anchoring.test.ts +++ b/packages/core/src/initialization/__tests__/anchoring.test.ts @@ -1,6 +1,5 @@ import { describe, expect, test } from '@jest/globals' import { - CustomMainnetCasError, DEFAULT_ANCHOR_SERVICE_URLS, makeAnchorService, makeAnchorServiceUrl, @@ -14,29 +13,23 @@ import { describe('makeAnchorServiceUrl', () => { const CUSTOM_URL = 'https://cas.com' + const logger = new LoggerProvider().getDiagnosticsLogger() test('pass from config', () => { - expect(makeAnchorServiceUrl('hello', Networks.INMEMORY)).toEqual('hello') + expect(makeAnchorServiceUrl('hello', Networks.INMEMORY, logger)).toEqual('hello') }) test('drop trailing slashes', () => { const trailingSlash = `${CUSTOM_URL}/` const doubleTrailingSlash = `${CUSTOM_URL}//` - expect(makeAnchorServiceUrl(CUSTOM_URL, Networks.INMEMORY)).toEqual(CUSTOM_URL) - expect(makeAnchorServiceUrl(trailingSlash, Networks.INMEMORY)).toEqual(CUSTOM_URL) - expect(makeAnchorServiceUrl(doubleTrailingSlash, Networks.INMEMORY)).toEqual(CUSTOM_URL) + expect(makeAnchorServiceUrl(CUSTOM_URL, Networks.INMEMORY, logger)).toEqual(CUSTOM_URL) + expect(makeAnchorServiceUrl(trailingSlash, Networks.INMEMORY, logger)).toEqual(CUSTOM_URL) + expect(makeAnchorServiceUrl(doubleTrailingSlash, Networks.INMEMORY, logger)).toEqual(CUSTOM_URL) }) test('pass default by network', () => { - expect(makeAnchorServiceUrl(undefined, Networks.MAINNET)).toEqual( + expect(makeAnchorServiceUrl(undefined, Networks.MAINNET, logger)).toEqual( DEFAULT_ANCHOR_SERVICE_URLS[Networks.MAINNET] ) }) - test('throw on custom CAS on mainnet', () => { - expect(() => makeAnchorServiceUrl(CUSTOM_URL, Networks.MAINNET)).toThrow(CustomMainnetCasError) - const casInternal = 'https://cas-internal.3boxlabs.com' - expect(makeAnchorServiceUrl(casInternal, Networks.MAINNET)).toEqual(casInternal) - const casDirect = 'https://cas-direct.3boxlabs.com' - expect(makeAnchorServiceUrl(casDirect, Networks.MAINNET)).toEqual(casDirect) - }) }) describe('makeAnchorService', () => { diff --git a/packages/core/src/initialization/anchoring.ts b/packages/core/src/initialization/anchoring.ts index 1b89bb0588..21d5c1be82 100644 --- a/packages/core/src/initialization/anchoring.ts +++ b/packages/core/src/initialization/anchoring.ts @@ -40,22 +40,24 @@ export class UnusableAnchorChainsError extends Error { } } -export class CustomMainnetCasError extends Error { - constructor() { - super('Cannot use custom anchor service on Ceramic mainnet') - } -} - const TRAILING_SLASH = new RegExp(/\/+$/g) // slash at the end of the string const MAINNET_CAS_URLS = [ 'https://cas-internal.3boxlabs.com', 'https://cas-direct.3boxlabs.com', + 'https://ceramic-prod-cas-api-gitcoin.3boxlabs.com', DEFAULT_ANCHOR_SERVICE_URLS[Networks.MAINNET], ] -export function makeAnchorServiceUrl(fromConfig: string | undefined, network: Networks): string { +export function makeAnchorServiceUrl( + fromConfig: string | undefined, + network: Networks, + logger: DiagnosticsLogger +): string { const casUrl = fromConfig?.replace(TRAILING_SLASH, '') || DEFAULT_ANCHOR_SERVICE_URLS[network] + // Log a warning when using a custom anchor service URL on mainnet if (isMainnet(network) && !MAINNET_CAS_URLS.includes(casUrl)) { - throw new CustomMainnetCasError() + logger.warn( + `${casUrl} is not a standard Anchor Service URL for Ceramic mainnet. Use a custom anchor service URL at your own risk. Note than an unreliable Ceramic Anchor Service can lead to data loss.` + ) } return casUrl } @@ -124,7 +126,7 @@ export function makeAnchorService( if (network === Networks.INMEMORY) { return new InMemoryAnchorService(config as any, logger) } - const anchorServiceUrl = makeAnchorServiceUrl(config.anchorServiceUrl, network) + const anchorServiceUrl = makeAnchorServiceUrl(config.anchorServiceUrl, network, logger) if (!config.readOnly) { const anchorServiceAuth = makeAnchorServiceAuth( config.anchorServiceAuthMethod,