Skip to content

Commit

Permalink
test(database-client): run integration tests against community testne…
Browse files Browse the repository at this point in the history
…t node (passportxyz#148)

- add `database-client/integration-tests/integration-test-model-aliases.json`
  so integration tests can run against testnet definitions
- change `database-client/src/ceramicClient.ts` constructor to use
  community node as default `ceramicHost`.
  also add optional `aliases` parameter in constructor
- add integration tests to pre-push hook and github ci workflow
  • Loading branch information
shavinac authored Jun 6, 2022
1 parent 5380435 commit 127a5a0
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 27 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,7 @@ jobs:
run: lerna bootstrap
- name: Run Tests
run: yarn test
- name: Run Ceramic Integration Tests
run: yarn test:ceramic-integration
- name: Run Linter
run: yarn lint
3 changes: 2 additions & 1 deletion .husky/pre-push
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

yarn run test
yarn run test
yarn run test:ceramic-integration
3 changes: 2 additions & 1 deletion app/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ This will be the web app allowing users to interact with their dpopp.
yarn start
```

Set the `NEXT_PUBLIC_CERAMIC_CLIENT_URL` environment variable to change the Ceramic node to run against - the Ceramic host defaults to `http://localhost:7007` if not provided.
Set the `NEXT_PUBLIC_CERAMIC_CLIENT_URL` environment variable to change the Ceramic node to run against - the Ceramic
host defaults to the community node `https://ceramic-clay.3boxlabs.com` if not provided.
4 changes: 3 additions & 1 deletion database-client/integration-tests/ceramicDatabaseTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { DID } from "dids";
import { Ed25519Provider } from "key-did-provider-ed25519";
import { getResolver } from "key-did-resolver";

import testnetAliases from "./integration-test-model-aliases.json";

import { CeramicDatabase } from "../src";

let testDID: DID;
Expand All @@ -21,7 +23,7 @@ beforeAll(async () => {
});
await testDID.authenticate();

ceramicDatabase = new CeramicDatabase(testDID);
ceramicDatabase = new CeramicDatabase(testDID, process.env.CERAMIC_CLIENT_URL, testnetAliases);
});

afterAll(async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"definitions":{"Passport":"kjzl6cwe1jw145znqlxwwar1crvgsm3wf56vcnxo6bu87fqsi6519eypjnzs7mu","VerifiableCredential":"kjzl6cwe1jw149zuvayqa89nhmlvwm0pkdkj0awlxhmtbbay6i972xuwy14jg4f"},"schemas":{"Passport":"ceramic://k3y52l7qbv1fryatc5h4xpnusk6vw8pmle6duu11djx2dke2senbiecu1fw1wrif4","VerifiableCredential":"ceramic://k3y52l7qbv1fry8pdl0tpicir0jxfwktanqceca89gsvy9geg7o2cd4b6hdr33uv4"},"tiles":{}}
26 changes: 12 additions & 14 deletions database-client/integration-tests/run-ceramic-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,20 @@
# === preliminary installs ===
yarn global add lerna
cd dpopp
lerna bootstrap # TODO - figure out how to speed this up if run in docker
lerna bootstrap -- --ignore-scripts # skipping pre/postinstall scripts
yarn build:database-client

# === start up ceramic in background ===
# TODO - how to kill this ceramic process at the end?
echo "Starting up Ceramic..."
(yarn workspace @dpopp/schemas ceramic &) | grep --max-count=1 "Ceramic API running on"
export CERAMIC_CLIENT_URL="https://ceramic-clay.3boxlabs.com"

# TODO alternatively figure out how to save the PID and kill at the end
# CERAMIC_PID = $(ceramic daemon)
# echo $CERAMIC_PID
# === start up ceramic in background ===
until $(curl --output /dev/null --silent --head --fail $CERAMIC_CLIENT_URL/api/v0/node/healthcheck); do
printf '... waiting for Ceramic daemon ...'
sleep 5
done

# TODO - not needed once we publish + persist our schemas to ceramic testnet
# === create & publish model to ceramic ===
export SEED="06be7d9853096fca06d6da9268a8a66ecaab2a7249ccd63c70fead97aafefa02" # TEST SEED, DO NOT USE IN PROD
yarn workspace @dpopp/schemas create-model
yarn workspace @dpopp/schemas publish-model
# === fetch passport and VC definitions ===
curl $CERAMIC_CLIENT_URL/api/v0/streams/kjzl6cwe1jw145znqlxwwar1crvgsm3wf56vcnxo6bu87fqsi6519eypjnzs7mu
curl $CERAMIC_CLIENT_URL/api/v0/streams/kjzl6cwe1jw149zuvayqa89nhmlvwm0pkdkj0awlxhmtbbay6i972xuwy14jg4f

# === run ceramic integration tests ===
yarn test:integration
yarn test:ceramic-integration
9 changes: 5 additions & 4 deletions database-client/src/ceramicClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import type { DID as CeramicDID } from "dids";

import { DataStorageBase } from "./types";

const LOCAL_CERAMIC_CLIENT_URL = "http://localhost:7007";
// const LOCAL_CERAMIC_CLIENT_URL = "http://localhost:7007";
const COMMUNITY_TESTNET_CERAMIC_CLIENT_URL = "https://ceramic-clay.3boxlabs.com"

type CeramicStamp = {
provider: string;
Expand Down Expand Up @@ -42,14 +43,14 @@ export class CeramicDatabase implements DataStorageBase {
model: DataModel<ModelTypes>;
store: DIDDataStore<ModelTypes>;

constructor(did?: CeramicDID, ceramicHost?: string) {
constructor(did?: CeramicDID, ceramicHost?: string, aliases?: any) {
// Create the Ceramic instance and inject the DID
const ceramic = new CeramicClient(ceramicHost ?? LOCAL_CERAMIC_CLIENT_URL);
const ceramic = new CeramicClient(ceramicHost ?? COMMUNITY_TESTNET_CERAMIC_CLIENT_URL);
ceramic.setDID(did);

// Create the loader, model and store
const loader = new TileLoader({ ceramic });
const model = new DataModel({ ceramic, aliases: publishedModel });
const model = new DataModel({ ceramic, aliases: aliases ?? publishedModel });
const store = new DIDDataStore({ loader, ceramic, model });

// Store the users did:pkh here to verify match on credential
Expand Down
5 changes: 0 additions & 5 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
version: "3.9"
services:
# ceramic-daemon:
# image: ceramicnetwork/go-ipfs-daemon:latest
# ports:
# - "5001:5001"
# - "8011:8011"
ceramic-integration-test:
image: node:16
volumes:
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"build:identity": "yarn workspace @dpopp/identity build",
"build:iam": "yarn workspace @dpopp/iam build",
"build:app": "yarn workspace @dpopp/app build",
"start": "concurrently --kill-others \"yarn start:iam\" \"yarn start:app\" \"yarn start:ceramic\"",
"start": "concurrently --kill-others \"yarn start:iam\" \"yarn start:app\"",
"start:iam": "yarn workspace @dpopp/iam start",
"start:app": "yarn workspace @dpopp/app start",
"start:ceramic": "yarn ceramic daemon",
Expand Down

0 comments on commit 127a5a0

Please sign in to comment.