Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: adjust tests for failure to start due to network mismatch #3274

Merged
merged 3 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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