From 4ab98efb585738ea44bf9562a373223e5142f161 Mon Sep 17 00:00:00 2001 From: David Estes Date: Tue, 30 Jul 2024 09:57:30 -0600 Subject: [PATCH 1/3] fix: don't NRE if close is called without init the handling of clean up after exceptions during ceramic start is error prone. This helps keep tests happy so we don't get 'tried to access undefined' errors but see a real message --- packages/core/src/anchor/memory/in-memory-anchor-service.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/core/src/anchor/memory/in-memory-anchor-service.ts b/packages/core/src/anchor/memory/in-memory-anchor-service.ts index e1fcb6c859..cc6e3db88e 100644 --- a/packages/core/src/anchor/memory/in-memory-anchor-service.ts +++ b/packages/core/src/anchor/memory/in-memory-anchor-service.ts @@ -146,7 +146,7 @@ export class InMemoryAnchorService implements AnchorService { async close(): Promise { await this.#cas.close() - await this.#store.close() - await this.#loop.stop() + await this.#store?.close() + await this.#loop?.stop() } } From b2ca08fcd920333e91bd473ae69ff37eedec4173 Mon Sep 17 00:00:00 2001 From: David Estes Date: Tue, 30 Jul 2024 10:15:18 -0600 Subject: [PATCH 2/3] fix: adjust test to handle earlier network error when using c1 --- .../core/src/__tests__/initialization.test.ts | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/packages/core/src/__tests__/initialization.test.ts b/packages/core/src/__tests__/initialization.test.ts index 84d5689074..26f1295709 100644 --- a/packages/core/src/__tests__/initialization.test.ts +++ b/packages/core/src/__tests__/initialization.test.ts @@ -2,7 +2,7 @@ import { expect, jest, describe, test, it, beforeEach, afterEach } from '@jest/g import { Ceramic } from '../ceramic.js' import tmp from 'tmp-promise' import type { IpfsApi } from '@ceramicnetwork/common' -import { Networks } from '@ceramicnetwork/common' +import { EnvironmentUtils, Networks } from '@ceramicnetwork/common' import { createIPFS } from '@ceramicnetwork/ipfs-daemon' import { InMemoryAnchorService } from '../anchor/memory/in-memory-anchor-service.js' @@ -55,7 +55,7 @@ describe('Ceramic integration', () => { await ceramic.close() }) - it('cannot create Ceramic instance on network not supported by our anchor service', async () => { + it('cannot create Ceramic instance on network different from ceramic one or cas', async () => { const tmpDirectory = await tmp.tmpName() const databaseConnectionString = new URL(`sqlite://${tmpDirectory}/ceramic.sqlite`) const [modules, params] = Ceramic._processConfig( @@ -72,9 +72,15 @@ describe('Ceramic integration', () => { modules.loggerProvider.getDiagnosticsLogger() ) const ceramic = new Ceramic(modules, params) - await expect(ceramic._init(false)).rejects.toThrow( - "No usable chainId for anchoring was found. The ceramic network 'local' supports the chains: ['eip155:1337'], but the configured anchor service '' only supports the chains: ['inmemory:12345']" - ) + if (EnvironmentUtils.useRustCeramic()) { + await expect(ceramic._init(false)).rejects.toThrow( + "Recon: failed to verify network as js-ceramic is using local but ceramic-one is on inmemory. Pass --network to the js-ceramic or ceramic-one daemon to make them match." + ) + } else { + await expect(ceramic._init(false)).rejects.toThrow( + "No usable chainId for anchoring was found. The ceramic network 'local' supports the chains: ['eip155:1337'], but the configured anchor service '' only supports the chains: ['inmemory:12345']" + ) + } }) it('cannot create Ceramic instance on invalid network', async () => { From 5900320bbcc34e27638ae47f52a5bfb867c43e3c Mon Sep 17 00:00:00 2001 From: David Estes Date: Tue, 30 Jul 2024 10:24:54 -0600 Subject: [PATCH 3/3] chore: fmt --- packages/core/src/__tests__/initialization.test.ts | 2 +- packages/core/src/recon.ts | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/packages/core/src/__tests__/initialization.test.ts b/packages/core/src/__tests__/initialization.test.ts index 26f1295709..47eb14146f 100644 --- a/packages/core/src/__tests__/initialization.test.ts +++ b/packages/core/src/__tests__/initialization.test.ts @@ -74,7 +74,7 @@ describe('Ceramic integration', () => { const ceramic = new Ceramic(modules, params) if (EnvironmentUtils.useRustCeramic()) { await expect(ceramic._init(false)).rejects.toThrow( - "Recon: failed to verify network as js-ceramic is using local but ceramic-one is on inmemory. Pass --network to the js-ceramic or ceramic-one daemon to make them match." + 'Recon: failed to verify network as js-ceramic is using local but ceramic-one is on inmemory. Pass --network to the js-ceramic or ceramic-one daemon to make them match.' ) } else { await expect(ceramic._init(false)).rejects.toThrow( diff --git a/packages/core/src/recon.ts b/packages/core/src/recon.ts index a0ca917527..cbea6878b3 100644 --- a/packages/core/src/recon.ts +++ b/packages/core/src/recon.ts @@ -146,8 +146,10 @@ export class ReconApi extends Observable implements IRec // in the network, or don't use it at all and just rely on c1, we're okay ignoring that piece if (!response.name.includes(this.#config.network)) { throw new Error( - `Recon: failed to verify network as js-ceramic is using ${this.#config.network - } but ceramic-one is on ${response.name + `Recon: failed to verify network as js-ceramic is using ${ + this.#config.network + } but ceramic-one is on ${ + response.name }. Pass --network to the js-ceramic or ceramic-one daemon to make them match.` ) } @@ -268,7 +270,8 @@ export class ReconApi extends Observable implements IRec retry({ delay: (err) => { this.#logger.warn( - `Recon: event feed failed, due to error ${err}; attempting to retry in ${this.#pollInterval + `Recon: event feed failed, due to error ${err}; attempting to retry in ${ + this.#pollInterval }ms` ) return timer(this.#pollInterval)