Skip to content

Commit

Permalink
feat: send js-ceramic and ceramic-one versions to CAS when creating r…
Browse files Browse the repository at this point in the history
…equests
  • Loading branch information
stbrody committed Jun 24, 2024
1 parent f612756 commit 83d94cb
Show file tree
Hide file tree
Showing 16 changed files with 235 additions and 118 deletions.
4 changes: 2 additions & 2 deletions packages/cli/src/__tests__/ceramic-error.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import getPort from 'get-port'
import { IpfsApi, LogLevel } from '@ceramicnetwork/common'
import * as tmp from 'tmp-promise'
import { createIPFS } from '@ceramicnetwork/ipfs-daemon'
import { Ceramic } from '@ceramicnetwork/core'
import { Ceramic, VersionInfo } from '@ceramicnetwork/core'
import * as random from '@stablelib/random'
import { CeramicDaemon, makeCeramicConfig } from '../ceramic-daemon.js'
import { CeramicClient } from '@ceramicnetwork/http-client'
Expand Down Expand Up @@ -58,7 +58,7 @@ beforeAll(async () => {

const ceramicConfig = makeCeramicConfig(daemonConfig)
ceramicConfig.enableAnchorPollingLoop = false
core = await Ceramic.create(ipfs, ceramicConfig)
core = await Ceramic.create(ipfs, ceramicConfig, {} as VersionInfo)
daemon = new CeramicDaemon(core, daemonConfig)
await daemon.listen()
const apiUrl = `http://localhost:${daemonPort}`
Expand Down
24 changes: 14 additions & 10 deletions packages/cli/src/__tests__/ceramic-multi-daemon.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { jest } from '@jest/globals'
import { Ceramic } from '@ceramicnetwork/core'
import { Ceramic, VersionInfo } from '@ceramicnetwork/core'
import { CeramicClient } from '@ceramicnetwork/http-client'
import * as tmp from 'tmp-promise'
import { CeramicDaemon } from '../ceramic-daemon.js'
Expand All @@ -16,16 +16,20 @@ const seed = 'SEED'
const TOPIC = '/ceramic'

const makeCeramicCore = async (ipfs: IpfsApi, stateStoreDirectory: string): Promise<Ceramic> => {
const core = await Ceramic.create(ipfs, {
pubsubTopic: TOPIC,
stateStoreDirectory,
anchorOnRequest: false,
indexing: {
db: `sqlite://${stateStoreDirectory}/ceramic.sqlite`,
disableComposedb: false,
const core = await Ceramic.create(
ipfs,
{
pubsubTopic: TOPIC,
stateStoreDirectory,
anchorOnRequest: false,
indexing: {
db: `sqlite://${stateStoreDirectory}/ceramic.sqlite`,
disableComposedb: false,
},
anchorLoopMinDurationMs: 0,
},
anchorLoopMinDurationMs: 0,
})
{} as VersionInfo
)

const handler = new TileDocumentHandler()
handler.verifyJWS = (): Promise<void> => {
Expand Down
28 changes: 16 additions & 12 deletions packages/cli/src/__tests__/make-ceramic-core.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
import { IpfsApi } from '@ceramicnetwork/common'
import { Ceramic } from '@ceramicnetwork/core'
import { Ceramic, VersionInfo } from '@ceramicnetwork/core'
import { TileDocumentHandler } from '@ceramicnetwork/stream-tile-handler'

export async function makeCeramicCore(
ipfs: IpfsApi,
stateStoreDirectory: string
): Promise<Ceramic> {
const core = await Ceramic.create(ipfs, {
pubsubTopic: '/ceramic',
stateStoreDirectory,
anchorOnRequest: false,
indexing: {
db: `sqlite://${stateStoreDirectory}/ceramic.sqlite`,
allowQueriesBeforeHistoricalSync: true,
disableComposedb: false,
enableHistoricalSync: false,
const core = await Ceramic.create(
ipfs,
{
pubsubTopic: '/ceramic',
stateStoreDirectory,
anchorOnRequest: false,
indexing: {
db: `sqlite://${stateStoreDirectory}/ceramic.sqlite`,
allowQueriesBeforeHistoricalSync: true,
disableComposedb: false,
enableHistoricalSync: false,
},
anchorLoopMinDurationMs: 0,
},
anchorLoopMinDurationMs: 0,
})
{} as VersionInfo
)

const handler = new TileDocumentHandler()
;(handler as any).verifyJWS = (): Promise<void> => {
Expand Down
10 changes: 7 additions & 3 deletions packages/cli/src/ceramic-daemon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,9 +282,14 @@ export class CeramicDaemon {
ceramicConfig.loggerProvider.getDiagnosticsLogger(),
opts.ipfs?.host
)
const ipfsId = await ipfs.id()

const [modules, params] = Ceramic._processConfig(ipfs, ceramicConfig)
params.versionInfo = { cliPackageVersion: version, gitHash: commitHash }
const versionInfo = {
cliPackageVersion: version,
gitHash: commitHash,
ceramicOneVersion: ipfsId.agentVersion,
}
const [modules, params] = Ceramic._processConfig(ipfs, ceramicConfig, versionInfo)
const diagnosticsLogger = modules.loggerProvider.getDiagnosticsLogger()
diagnosticsLogger.imp(
`Starting Ceramic Daemon with @ceramicnetwork/cli package version ${version}, with js-ceramic repo git hash ${commitHash}, and with config: \n${JSON.stringify(
Expand All @@ -293,7 +298,6 @@ export class CeramicDaemon {
2
)}`
)
const ipfsId = await ipfs.id()
diagnosticsLogger.imp(
`Connecting to IPFS node with version "${ipfsId.agentVersion}" available as ${ipfsId.addresses
.map(String)
Expand Down
28 changes: 16 additions & 12 deletions packages/core/src/__tests__/ceramic-pinning.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { jest, describe, expect, beforeEach, afterEach } from '@jest/globals'
import { Ceramic } from '../ceramic.js'
import { Ceramic, VersionInfo } from '../ceramic.js'
import { Ed25519Provider } from 'key-did-provider-ed25519'
import tmp from 'tmp-promise'
import { IpfsApi, SyncOptions } from '@ceramicnetwork/common'
Expand Down Expand Up @@ -47,18 +47,22 @@ const createCeramic = async (

const databaseFolder = await tmp.dir({ unsafeCleanup: true })
const connectionString = new URL(`sqlite://${databaseFolder.path}/ceramic.sqlite`)
const ceramic = await Ceramic.create(ipfs, {
stateStoreDirectory,
anchorOnRequest,
indexing: {
db: connectionString.href,
allowQueriesBeforeHistoricalSync: true,
disableComposedb: true,
enableHistoricalSync: false,
const ceramic = await Ceramic.create(
ipfs,
{
stateStoreDirectory,
anchorOnRequest,
indexing: {
db: connectionString.href,
allowQueriesBeforeHistoricalSync: true,
disableComposedb: true,
enableHistoricalSync: false,
},
pubsubTopic: '/ceramic/inmemory/test', // necessary so Ceramic instances can talk to each other
anchorLoopMinDurationMs: 0,
},
pubsubTopic: '/ceramic/inmemory/test', // necessary so Ceramic instances can talk to each other
anchorLoopMinDurationMs: 0,
})
{} as VersionInfo
)
ceramic.did = makeDID(seed, ceramic)
await ceramic.did.authenticate()

Expand Down
4 changes: 3 additions & 1 deletion packages/core/src/__tests__/create-ceramic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import * as KeyDidResolver from 'key-did-resolver'
import { Resolver } from 'did-resolver'
import { DID } from 'dids'

const VERSION_INFO = { cliPackageVersion: '', gitHash: '', ceramicOneVersion: '' }

export async function createCeramic(
ipfs: IpfsApi,
config?: CeramicConfig & {
Expand All @@ -33,7 +35,7 @@ export async function createCeramic(
anchorLoopMinDurationMs: 0,
...config,
}
const ceramic = await Ceramic.create(ipfs, appliedConfig)
const ceramic = await Ceramic.create(ipfs, appliedConfig, VERSION_INFO)
const seed = sha256.hash(uint8arrays.fromString(appliedConfig.seed || 'SEED'))
const provider = new Ed25519Provider(seed)
const keyDidResolver = KeyDidResolver.getResolver()
Expand Down
78 changes: 50 additions & 28 deletions packages/core/src/__tests__/initialization.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { Networks } from '@ceramicnetwork/common'
import { createIPFS } from '@ceramicnetwork/ipfs-daemon'
import { InMemoryAnchorService } from '../anchor/memory/in-memory-anchor-service.js'

const VERSION_INFO = { cliPackageVersion: '', gitHash: '', ceramicOneVersion: '' }

describe('Ceramic integration', () => {
jest.setTimeout(60000)
let ipfs1: IpfsApi
Expand All @@ -21,11 +23,15 @@ describe('Ceramic integration', () => {
it('can create Ceramic instance on default network', async () => {
const stateStoreDirectory = await tmp.tmpName()
const databaseConnectionString = new URL(`sqlite://${stateStoreDirectory}/ceramic.sqlite`)
const ceramic = await Ceramic.create(ipfs1, {
stateStoreDirectory,
indexing: { db: databaseConnectionString.href, models: [] },
anchorLoopMinDurationMs: 0,
})
const ceramic = await Ceramic.create(
ipfs1,
{
stateStoreDirectory,
indexing: { db: databaseConnectionString.href },
anchorLoopMinDurationMs: 0,
},
VERSION_INFO
)
const supportedChains = await ceramic.getSupportedChains()
expect(supportedChains).toEqual(['inmemory:12345'])
await ceramic.close()
Expand All @@ -34,12 +40,16 @@ describe('Ceramic integration', () => {
it('can create Ceramic instance explicitly on inmemory network', async () => {
const stateStoreDirectory = await tmp.tmpName()
const databaseConnectionString = new URL(`sqlite://${stateStoreDirectory}/ceramic.sqlite`)
const ceramic = await Ceramic.create(ipfs1, {
networkName: 'inmemory',
stateStoreDirectory,
indexing: { db: databaseConnectionString.href, models: [] },
anchorLoopMinDurationMs: 0,
})
const ceramic = await Ceramic.create(
ipfs1,
{
networkName: 'inmemory',
stateStoreDirectory,
indexing: { db: databaseConnectionString.href },
anchorLoopMinDurationMs: 0,
},
VERSION_INFO
)
const supportedChains = await ceramic.getSupportedChains()
expect(supportedChains).toEqual(['inmemory:12345'])
await ceramic.close()
Expand All @@ -48,11 +58,15 @@ describe('Ceramic integration', () => {
it('cannot create Ceramic instance on network not supported by our anchor service', async () => {
const tmpDirectory = await tmp.tmpName()
const databaseConnectionString = new URL(`sqlite://${tmpDirectory}/ceramic.sqlite`)
const [modules, params] = Ceramic._processConfig(ipfs1, {
networkName: 'local',
indexing: { db: databaseConnectionString.href, models: [] },
anchorLoopMinDurationMs: 0,
})
const [modules, params] = Ceramic._processConfig(
ipfs1,
{
networkName: 'local',
indexing: { db: databaseConnectionString.href },
anchorLoopMinDurationMs: 0,
},
VERSION_INFO
)
modules.anchorService = new InMemoryAnchorService(
{},
modules.loggerProvider.getDiagnosticsLogger()
Expand All @@ -67,12 +81,16 @@ describe('Ceramic integration', () => {
const stateStoreDirectory = await tmp.tmpName()
const databaseConnectionString = new URL(`sqlite://${stateStoreDirectory}/ceramic.sqlite`)
await expect(
Ceramic.create(ipfs1, {
networkName: 'fakenetwork',
stateStoreDirectory,
indexing: { db: databaseConnectionString.href, models: [] },
anchorLoopMinDurationMs: 0,
})
Ceramic.create(
ipfs1,
{
networkName: 'fakenetwork',
stateStoreDirectory,
indexing: { db: databaseConnectionString.href },
anchorLoopMinDurationMs: 0,
},
VERSION_INFO
)
).rejects.toThrow(
"Unrecognized Ceramic network name: 'fakenetwork'. Supported networks are: 'mainnet', 'testnet-clay', 'dev-unstable', 'local', 'inmemory'"
)
Expand All @@ -81,12 +99,16 @@ describe('Ceramic integration', () => {
test('init dispatcher', async () => {
const tmpDirectory = await tmp.tmpName()
const databaseConnectionString = new URL(`sqlite://${tmpDirectory}/ceramic.sqlite`)
const [modules, params] = await Ceramic._processConfig(ipfs1, {
networkName: Networks.INMEMORY,
stateStoreDirectory: tmpDirectory,
indexing: { db: databaseConnectionString.href, models: [] },
anchorLoopMinDurationMs: 0,
})
const [modules, params] = await Ceramic._processConfig(
ipfs1,
{
networkName: Networks.INMEMORY,
stateStoreDirectory: tmpDirectory,
indexing: { db: databaseConnectionString.href },
anchorLoopMinDurationMs: 0,
},
VERSION_INFO
)
const dispatcher = modules.dispatcher
const ceramic = new Ceramic(modules, params)
const dispatcherInitSpy = jest.spyOn(dispatcher, 'init')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ import { createDidAnchorServiceAuth } from '../../../__tests__/create-did-anchor
import { AuthenticatedEthereumAnchorService } from '../ethereum-anchor-service.js'
import { AnchorRequestStore } from '../../../store/anchor-request-store.js'
import type { AnchorLoopHandler } from '../../anchor-service.js'
import { CARFactory, type CAR } from 'cartonne'
import { Ceramic } from '../../../ceramic.js'
import { Ceramic, VersionInfo } from '../../../ceramic.js'
import { BaseTestUtils } from '@ceramicnetwork/base-test-utils'

const FAUX_ANCHOR_STORE = {
Expand All @@ -28,6 +27,7 @@ const FAUX_HANDLER: AnchorLoopHandler = {
}

const diagnosticsLogger = new LoggerProvider().getDiagnosticsLogger()
const VERSION_INFO: VersionInfo = { cliPackageVersion: '', gitHash: '', ceramicOneVersion: '' }

describe('AuthenticatedEthereumAnchorServiceTest', () => {
let ipfs: IpfsApi
Expand All @@ -53,7 +53,13 @@ describe('AuthenticatedEthereumAnchorServiceTest', () => {

const auth = createDidAnchorServiceAuth(url, ceramic.signer, diagnosticsLogger, fauxFetchJson)
const signRequestSpy = jest.spyOn(auth, 'signRequest')
const anchorService = new AuthenticatedEthereumAnchorService(auth, url, url, diagnosticsLogger)
const anchorService = new AuthenticatedEthereumAnchorService(
auth,
url,
url,
diagnosticsLogger,
VERSION_INFO
)

jest.spyOn(anchorService.validator, 'init').mockImplementation(async () => {
// Do Nothing
Expand Down Expand Up @@ -82,7 +88,13 @@ describe('AuthenticatedEthereumAnchorServiceTest', () => {

const auth = createDidAnchorServiceAuth(url, ceramic.signer, diagnosticsLogger, fauxFetchJson)
const signRequestSpy = jest.spyOn(auth, 'signRequest')
const anchorService = new AuthenticatedEthereumAnchorService(auth, url, url, diagnosticsLogger)
const anchorService = new AuthenticatedEthereumAnchorService(
auth,
url,
url,
diagnosticsLogger,
VERSION_INFO
)
jest.spyOn(anchorService.validator, 'init').mockImplementation(async () => {
// Do Nothing
})
Expand Down
Loading

0 comments on commit 83d94cb

Please sign in to comment.