Skip to content

Commit

Permalink
fix: adjust tests for failure to start due to network mismatch (#3274)
Browse files Browse the repository at this point in the history
* fix: don't null reference exceptionif 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
* fix: adjust test to handle earlier network error when using c1
  • Loading branch information
dav1do authored Jul 30, 2024
1 parent f943ed9 commit bd04b65
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
16 changes: 11 additions & 5 deletions packages/core/src/__tests__/initialization.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -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(
Expand All @@ -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 '<inmemory>' 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 '<inmemory>' only supports the chains: ['inmemory:12345']"
)
}
})

it('cannot create Ceramic instance on invalid network', async () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/anchor/memory/in-memory-anchor-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ export class InMemoryAnchorService implements AnchorService {

async close(): Promise<void> {
await this.#cas.close()
await this.#store.close()
await this.#loop.stop()
await this.#store?.close()
await this.#loop?.stop()
}
}
9 changes: 6 additions & 3 deletions packages/core/src/recon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,10 @@ export class ReconApi extends Observable<ReconEventFeedResponse> 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.`
)
}
Expand Down Expand Up @@ -268,7 +270,8 @@ export class ReconApi extends Observable<ReconEventFeedResponse> 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)
Expand Down

0 comments on commit bd04b65

Please sign in to comment.