From 127a5a0f249c9eb17b3cdce9d1b79e548e53a819 Mon Sep 17 00:00:00 2001 From: Shavina Chau Date: Mon, 6 Jun 2022 15:48:05 -0500 Subject: [PATCH] test(database-client): run integration tests against community testnet node (#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 --- .github/workflows/ci.yml | 2 ++ .husky/pre-push | 3 ++- app/README.md | 3 ++- .../integration-tests/ceramicDatabaseTest.ts | 4 ++- .../integration-test-model-aliases.json | 1 + .../integration-tests/run-ceramic-tests.sh | 26 +++++++++---------- database-client/src/ceramicClient.ts | 9 ++++--- docker-compose.yml | 5 ---- package.json | 2 +- 9 files changed, 28 insertions(+), 27 deletions(-) create mode 100644 database-client/integration-tests/integration-test-model-aliases.json diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index df80a90875..0cefbd8e32 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 diff --git a/.husky/pre-push b/.husky/pre-push index 65053c087e..dbc52f8ea7 100755 --- a/.husky/pre-push +++ b/.husky/pre-push @@ -1,4 +1,5 @@ #!/bin/sh . "$(dirname "$0")/_/husky.sh" -yarn run test \ No newline at end of file +yarn run test +yarn run test:ceramic-integration \ No newline at end of file diff --git a/app/README.md b/app/README.md index f1b3767966..5258f334dd 100644 --- a/app/README.md +++ b/app/README.md @@ -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. diff --git a/database-client/integration-tests/ceramicDatabaseTest.ts b/database-client/integration-tests/ceramicDatabaseTest.ts index 89d0972a22..2086da03d0 100644 --- a/database-client/integration-tests/ceramicDatabaseTest.ts +++ b/database-client/integration-tests/ceramicDatabaseTest.ts @@ -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; @@ -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 () => { diff --git a/database-client/integration-tests/integration-test-model-aliases.json b/database-client/integration-tests/integration-test-model-aliases.json new file mode 100644 index 0000000000..8284c83ac2 --- /dev/null +++ b/database-client/integration-tests/integration-test-model-aliases.json @@ -0,0 +1 @@ +{"definitions":{"Passport":"kjzl6cwe1jw145znqlxwwar1crvgsm3wf56vcnxo6bu87fqsi6519eypjnzs7mu","VerifiableCredential":"kjzl6cwe1jw149zuvayqa89nhmlvwm0pkdkj0awlxhmtbbay6i972xuwy14jg4f"},"schemas":{"Passport":"ceramic://k3y52l7qbv1fryatc5h4xpnusk6vw8pmle6duu11djx2dke2senbiecu1fw1wrif4","VerifiableCredential":"ceramic://k3y52l7qbv1fry8pdl0tpicir0jxfwktanqceca89gsvy9geg7o2cd4b6hdr33uv4"},"tiles":{}} \ No newline at end of file diff --git a/database-client/integration-tests/run-ceramic-tests.sh b/database-client/integration-tests/run-ceramic-tests.sh index 6fb30417f1..aade870aa7 100755 --- a/database-client/integration-tests/run-ceramic-tests.sh +++ b/database-client/integration-tests/run-ceramic-tests.sh @@ -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 \ No newline at end of file +yarn test:ceramic-integration \ No newline at end of file diff --git a/database-client/src/ceramicClient.ts b/database-client/src/ceramicClient.ts index 234a648791..fafb83e20f 100644 --- a/database-client/src/ceramicClient.ts +++ b/database-client/src/ceramicClient.ts @@ -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; @@ -42,14 +43,14 @@ export class CeramicDatabase implements DataStorageBase { model: DataModel; store: DIDDataStore; - 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 diff --git a/docker-compose.yml b/docker-compose.yml index c6c0bac79b..150a21bfa3 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -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: diff --git a/package.json b/package.json index 187d2bf713..9c48ce08ea 100644 --- a/package.json +++ b/package.json @@ -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",