-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Stream Client Package Upgrades (#35)
- Loading branch information
Showing
10 changed files
with
216 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import { InitEventPayload, SignedEvent, signEvent } from '@ceramic-sdk/events' | ||
import { | ||
type ClientOptions, | ||
type FlightSqlClient, | ||
createFlightSqlClient, | ||
} from '@ceramic-sdk/flight-sql-client' | ||
import { CeramicClient } from '@ceramic-sdk/http-client' | ||
import { StreamID } from '@ceramic-sdk/identifiers' | ||
import { StreamClient } from '@ceramic-sdk/stream-client' | ||
import { asDIDString } from '@didtools/codecs' | ||
import { getAuthenticatedDID } from '@didtools/key-did' | ||
import { tableFromIPC } from 'apache-arrow' | ||
import { CID } from 'multiformats' | ||
import type { EnvironmentOptions } from '../src' | ||
import CeramicOneContainer from '../src' | ||
|
||
const CONTAINER_OPTS: EnvironmentOptions = { | ||
containerName: 'ceramic-test-stream-client', | ||
apiPort: 5222, | ||
flightSqlPort: 5223, | ||
testPort: 5223, | ||
} | ||
|
||
const authenticatedDID = await getAuthenticatedDID(new Uint8Array(32)) | ||
|
||
const OPTIONS: ClientOptions = { | ||
headers: new Array(), | ||
username: undefined, | ||
password: undefined, | ||
token: undefined, | ||
tls: false, | ||
host: '127.0.0.1', | ||
port: CONTAINER_OPTS.flightSqlPort, | ||
} | ||
|
||
async function getClient(): Promise<FlightSqlClient> { | ||
return createFlightSqlClient(OPTIONS) | ||
} | ||
|
||
describe('stream client', () => { | ||
let c1Container: CeramicOneContainer | ||
const ceramicClient = new CeramicClient({ | ||
url: `http://127.0.0.1:${CONTAINER_OPTS.apiPort}`, | ||
}) | ||
let streamId: StreamID | ||
let cid: CID | ||
beforeAll(async () => { | ||
c1Container = await CeramicOneContainer.startContainer(CONTAINER_OPTS) | ||
|
||
// create a new event | ||
const model = StreamID.fromString( | ||
'kjzl6hvfrbw6c5he7fxl3oakeckm2kchkqboqug08inkh1tmfqpd8v3oceriml2', | ||
) | ||
const eventPayload: InitEventPayload = { | ||
data: { | ||
body: 'This is a simple message', | ||
}, | ||
header: { | ||
controllers: [asDIDString(authenticatedDID.id)], | ||
model, | ||
sep: 'test', | ||
}, | ||
} | ||
const encodedPayload = InitEventPayload.encode(eventPayload) | ||
const signedEvent = await signEvent(authenticatedDID, encodedPayload) | ||
cid = await ceramicClient.postEventType(SignedEvent, signedEvent) | ||
|
||
// obtain the stream ID | ||
const client = await getClient() | ||
const buffer = await client.query('SELECT * FROM conclusion_events LIMIT 1') | ||
const data = tableFromIPC(buffer) | ||
const row = data.get(0) | ||
const streamCid = CID.decode(row?.stream_cid).toString() | ||
streamId = new StreamID(3, streamCid) | ||
}, 10000) | ||
|
||
test('gets a stream', async () => { | ||
const client = new StreamClient({ ceramic: ceramicClient }) | ||
console.log(streamId.toString()) | ||
const streamState = await client.getStreamState(streamId.toString()) | ||
expect(streamState).toBeDefined() | ||
expect(streamState.id.toString()).toEqual(streamId.toString()) | ||
}, 10000) | ||
|
||
afterAll(async () => { | ||
await c1Container.teardown() | ||
}) | ||
}) |