Skip to content
This repository was archived by the owner on Mar 10, 2025. It is now read-only.
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
2 changes: 1 addition & 1 deletion tests/c1-integration/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export async function waitForEventState(
event_cid: CID,
) {
await flightClient.preparedQuery(
'SELECT "index" FROM event_states_feed WHERE event_cid = $event_cid LIMIT 1',
'SELECT event_state_order FROM event_states_feed WHERE event_cid = $event_cid LIMIT 1',
new Array(['$event_cid', event_cid.toString(base64.encoder)]),
)
}
6 changes: 3 additions & 3 deletions tests/c1-integration/test/model-mid-setType.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ describe('model integration test for list model and MID', () => {
test('creates instance and obtains correct state', async () => {
const documentStream = await modelInstanceClient.createInstance({
model: modelStream,
content: { test: 'hello' },
content: null,
shouldIndex: true,
})
// Use the flightsql stream behavior to ensure the events states have been process before querying their states.
Expand All @@ -100,12 +100,12 @@ describe('model integration test for list model and MID', () => {
const currentState = await modelInstanceClient.getDocumentState(
documentStream.baseID,
)
expect(currentState.content).toEqual({ test: 'hello' })
expect(currentState.content).toBeNull()
})
test('updates document and obtains correct state', async () => {
const documentStream = await modelInstanceClient.createInstance({
model: modelStream,
content: { test: 'hello' },
content: null,
shouldIndex: true,
})
// Use the flightsql stream behavior to ensure the events states have been process before querying their states.
Expand Down
38 changes: 28 additions & 10 deletions tests/c1-integration/test/stream-client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import {
} from '@ceramic-sdk/flight-sql-client'
import { CeramicClient } from '@ceramic-sdk/http-client'
import { StreamID } from '@ceramic-sdk/identifiers'
import { ModelClient } from '@ceramic-sdk/model-client'
import type { ModelDefinition } from '@ceramic-sdk/model-protocol'
import { StreamClient } from '@ceramic-sdk/stream-client'
import { asDIDString } from '@didtools/codecs'
import { getAuthenticatedDID } from '@didtools/key-did'
Expand Down Expand Up @@ -33,10 +35,21 @@ const OPTIONS: ClientOptions = {
port: CONTAINER_OPTS.flightSqlPort,
}

async function getClient(): Promise<FlightSqlClient> {
return createFlightSqlClient(OPTIONS)
const testModel: ModelDefinition = {
version: '2.0',
name: 'SingleTestModel',
description: 'Single Test model',
accountRelation: { type: 'single' },
interface: false,
implements: [],
schema: {
type: 'object',
properties: {
test: { type: 'string', maxLength: 10 },
},
additionalProperties: false,
},
}

describe('stream client', () => {
let c1Container: CeramicOneContainer
const ceramicClient = new CeramicClient({
Expand All @@ -46,28 +59,33 @@ describe('stream client', () => {
let cid: CID
beforeAll(async () => {
c1Container = await CeramicOneContainer.startContainer(CONTAINER_OPTS)
const client = new CeramicClient({
url: `http://127.0.0.1:${CONTAINER_OPTS.apiPort}`,
})

// create a new event
const model = StreamID.fromString(
'kjzl6hvfrbw6c5he7fxl3oakeckm2kchkqboqug08inkh1tmfqpd8v3oceriml2',
)
const modelClient = new ModelClient({
ceramic: client,
did: authenticatedDID,
})
const model = await modelClient.createDefinition(testModel)
const eventPayload: InitEventPayload = {
data: {
body: 'This is a simple message',
test: 'test message',
},
header: {
controllers: [asDIDString(authenticatedDID.id)],
model,
sep: 'test',
sep: 'model',
},
}
const encodedPayload = InitEventPayload.encode(eventPayload)
const signedEvent = await signEvent(authenticatedDID, encodedPayload)
cid = await ceramicClient.postEventType(SignedEvent, signedEvent)

// obtain the stream ID by waiting for the event state to be populated
const client = await getClient()
const buffer = await client.query(
const flightClient = await createFlightSqlClient(OPTIONS)
const buffer = await flightClient.query(
'SELECT stream_cid FROM event_states_feed LIMIT 1',
)
const data = tableFromIPC(buffer)
Expand Down