Skip to content

Commit

Permalink
1545 compose db (passportxyz#2045)
Browse files Browse the repository at this point in the history
* feat(app): writing to ComposeDB

* feat(database-client): updating dependencies

* feat[schrmeas]: adding graphql model, composite & definition

* fix[schema, database-client]: remove ceramic client, fix faiilng tests

* chore(schemas, database-client): setup compose db

* feat(app, database-client, iam, indetitiy, platforms): remove metaPointer and make queries to new compose db schema

* feat(database-client): read and write to compose

* chore: sudo code patch request

* feat(database-client): match existing scorer interface

* chore(database-client): testing compose interactions

* feat[identidy]: adjusting credentials

* Revert "feat[identidy]: adjusting credentials"

This reverts commit 7655f30.

* feat[schemas]: adjusting the graphql schemas

- rename _id => id in credentialSubject
- make expirationDate expirationDate
- make _context optional in GitcoinPassportVcProof and GitcoinPassportVcCredentialSubject
- remove _id from VerifiableCredentialSubject

* fix[schemas]: fix type in command in package.json

* feat[schemas]: adding new compiled composites

* feat[schemas]: adding passport-schemas workspace to the build command in the root

* feat[database-client]: WIP - correct import for schemas

* feat[database-client]: adding back integration tests for patch

* chore(database-client): wip test client

* chore(database-client): integration crud tests

* chore(schemas): schema update

* chore(databasae-client): integration tests

* feat[database-client]: reading all fields + transforming back the VC loaded from ceramic to be indentical to the input when it was saved

* feat[app]: accept multiple valid issuers & set ceramic URL from env var in ComposeDatabase

* feat[app,database-client]: pass in the logger to the ComposeDatabase

* chore(database-client): chore wip unit testing and error handling

* chore(database-client): unit test compose db

* fix(app): update ceramic context tests to match updated interface

* chore(ci): use node 20 in CI

* chore(ci): use node 20 in all cis

* fix(database-client): pull definition from package

* fix(app, database-client): allow usage of node 20 and fix ceramic build issues

* fix[app]: fixing build errors, upgrading dependencies

* fix[app]: fix build issues

* fix: fixing build errors

* feat(app): wip compose upgrade

* fix: remove *.tsbuildinfo files

* fix[iam]: set the skipLibCheck flag in tsconfig.json

* feat(app): replace self.id

* fix[database-client]: enabling back the integration tests

* fix[schemas,database-client]: fix chemas build and integration tests in database-client

* fix[passport]: fixing pre* commands

* fix(app, identity, platforms): linting

* chore(ci): add compose client url to ci

* debug[ci]: debugging ci ...

* fix[ci]: add ceramic config for integration tests

* fix[ci]: add ceramic config for integration tests

* fix[ci]: add ceramic config for integration tests

* fix[ci]: add ceramic config for integration tests

* fix[ci]: add ceramic config for integration tests

* fix[ci]: add ceramic config for integration tests

* fix[ci]: add ceramic config for integration tests

---------

Co-authored-by: Lucian Hymer <[email protected]>
Co-authored-by: schultztimothy <[email protected]>
  • Loading branch information
3 people authored Jan 23, 2024
1 parent ad31bc8 commit 2891d7d
Show file tree
Hide file tree
Showing 98 changed files with 6,683 additions and 2,875 deletions.
42 changes: 37 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,52 @@ on:
branches: [main]

jobs:
# ceramic-config:
# runs-on: ubuntu-latest

# steps:
# - name: Ceramic Config
# run: |
# echo ${GITHUB_WORKSPACE}
# echo "List files in GITHUB_WORKSPACE"
# ls ${GITHUB_WORKSPACE}
# echo "Pwd"
# pwd
# echo '{"anchor": {"auth-method": "did"}, "http-api": {"cors-allowed-origins": [".*"], "admin-dids": ["did:key:z6MkgUzNYV8J1yw43wj9K2CbhTZoN25uZ6TJ3Gi4cYVpZyDb"]}, "ipfs": {"mode": "bundled", "disable-peer-data-sync": false}, "logger": {"log-level": 2, "log-to-files": false}, "metrics": {"metrics-exporter-enabled": false}, "network": {"name": "testnet-clay"}, "node": {}, "state-store": {"mode": "fs", "local-directory": "/home/root/.ceramic/statestore/"}, "indexing": {"db": "sqlite:///home/root/.ceramic/indexing.sqlite", "allow-queries-before-historical-sync": true, "disable-composedb": false, "enable-historical-sync": false}}' > ${GITHUB_WORKSPACE}/daemon.config.json

# debug:
# runs-on: ubuntu-latest

# steps:
# - name: Debug
# run: |
# echo ${GITHUB_WORKSPACE}
# echo "List files in GITHUB_WORKSPACE"
# ls ${GITHUB_WORKSPACE}
# echo "Pwd"
# cat ${GITHUB_WORKSPACE}/daemon.config.json

build:
# needs: [ceramic-config]
runs-on: ubuntu-latest

# Run a local ceramic nod to test against
services:
ceramic:
image: ceramicnetwork/js-ceramic:2.20.0
image: ceramicnetwork/js-ceramic:3.2.0
ports:
- 7007:7007

# volumes:
# # TODO: use GITHUB_WORKSPACE var here ..
# - /home/runner/work/passport/passport/daemon.config.json:/root/.ceramic/daemon.config.json

steps:
- uses: actions/checkout@v3
- name: Use Node.js 18
- name: Use Node.js 20
uses: actions/setup-node@v3
with:
node-version: 18.18
node-version: 20.8.1
cache: "yarn"
- name: Install Packages
run: yarn install
Expand All @@ -36,15 +66,17 @@ jobs:
run: yarn build
- name: Run Ceramic Integration Tests
run: yarn test:ceramic-integration
env:
CERAMIC_CLIENT_URL: ${{secrets.CERAMIC_CLIENT_URL}}

check-provider-bitmap:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Use Node.js 18
- name: Use Node.js 20
uses: actions/setup-node@v3
with:
node-version: 18.18
node-version: 20.8
cache: "yarn"
- name: Install Packages
run: yarn install
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/iam-cd-review.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ jobs:
steps:
- uses: actions/checkout@v3
# run tests
- name: Use Node.js 18
- name: Use Node.js 20
uses: actions/setup-node@v3
with:
node-version: 18
node-version: 20.8
cache: "yarn"
- name: Install Packages
run: yarn install
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/iam-promote-production.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ jobs:
with:
ref: ${{ github.event.inputs.commit }}
# run tests
- name: Use Node.js 16
- name: Use Node.js 20
uses: actions/setup-node@v3
with:
node-version: 16
node-version: 20.8
cache: "yarn"
- name: Install Packages
run: yarn install
Expand Down Expand Up @@ -67,10 +67,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Use Node.js 18
- name: Use Node.js 20
uses: actions/setup-node@v3
with:
node-version: 18.18
node-version: 20.8
cache: "yarn"
- name: Install Packages
run: yarn install
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/iam-promote-staging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ jobs:
with:
ref: ${{ github.event.inputs.commit }}
# run tests
- name: Use Node.js 18
- name: Use Node.js 20
uses: actions/setup-node@v3
with:
node-version: 18
node-version: 20.8
cache: "yarn"
- name: Install Packages
run: yarn install
Expand Down Expand Up @@ -67,10 +67,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Use Node.js 18
- name: Use Node.js 20
uses: actions/setup-node@v3
with:
node-version: 18.18
node-version: 20.8
cache: "yarn"
- name: Install Packages
run: yarn install
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,6 @@ lerna-debug.log*
*.ntvs*
*.njsproj
*.sln
*.sw?
*.sw?

schemas/.env.yarn
4 changes: 2 additions & 2 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
module.exports = {
overrides: [
{
files: ['**/*.js', '**/*.ts', '**/*.tsx'],
files: ["**/*.js", "**/*.ts", "**/*.tsx"],
options: {
bracketSpacing: true,
trailingComma: 'es5',
trailingComma: "es5",
tabWidth: 2,
printWidth: 120,
singleQuote: false,
Expand Down
68 changes: 29 additions & 39 deletions app/__tests__/context/ceramicContext.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,21 @@ import {
CeramicContextState,
cleanPassport,
} from "../../context/ceramicContext";
import { CeramicDatabase, PassportDatabase } from "@gitcoin/passport-database-client";
import { ComposeDatabase, PassportDatabase } from "@gitcoin/passport-database-client";
import {
googleStampFixture,
discordStampFixture,
brightidStampFixture,
} from "../../__test-fixtures__/databaseStorageFixtures";
import { Passport } from "@gitcoin/passport-types";
import {
DatastoreConnectionContext,
DatastoreConnectionContextProvider,
} from "../../context/datastoreConnectionContext";
import { DatastoreConnectionContext } from "../../context/datastoreConnectionContext";
import { DID } from "dids";

const viewerConnection = {
status: "connected",
selfID: "did:3:abc",
};

jest.mock("@self.id/framework", () => {
return {
useViewerConnection: () => [viewerConnection],
};
});

jest.mock("@didtools/cacao", () => ({
Cacao: {
fromBlockBytes: jest.fn(),
Expand Down Expand Up @@ -93,14 +85,26 @@ const ceramicDbMocks = {
addStamps: dbAddStampsMock,
deleteStamp: dbDeleteStampMock,
deleteStamps: dbDeleteStampsMock,
patchStamps: jest.fn(),
did: "test-user-did",
};

jest.mock("@gitcoin/passport-database-client", () => {
return {
ComposeDatabase: jest.fn().mockImplementation(() => ceramicDbMocks),
PassportDatabase: jest.fn().mockImplementation(() => passportDbMocks),
};
});

const mockComponent = () => (
<DatastoreConnectionContext.Provider
value={{
dbAccessToken: "token",
dbAccessTokenStatus: "idle",
did: {
id: "did:3:abc",
parent: "did:3:abc",
} as unknown as DID,
connect: async () => {},
disconnect: async () => {},
}}
Expand All @@ -124,7 +128,7 @@ const mockComponent = () => (

describe("CeramicContextProvider syncs stamp state with ceramic", () => {
beforeEach(() => {
(CeramicDatabase as jest.Mock).mockImplementation(() => ceramicDbMocks);
(ComposeDatabase as jest.Mock).mockImplementation(() => ceramicDbMocks);
});

it("should return passport and stamps after successful fetch", async () => {
Expand Down Expand Up @@ -210,7 +214,7 @@ describe("CeramicContextProvider syncs stamp state with ceramic", () => {
}),
};
});
(CeramicDatabase as jest.Mock).mockImplementationOnce(() => {
(ComposeDatabase as jest.Mock).mockImplementationOnce(() => {
return {
...ceramicDbMocks,
getPassport: jest.fn().mockImplementation(async () => {
Expand All @@ -235,7 +239,7 @@ describe("CeramicContextProvider syncs stamp state with ceramic", () => {
console.log = jest.fn();

const addStampsMock = jest.fn();
const setStampMock = jest.fn().mockRejectedValue(new Error("Error"));
const addStampMock = jest.fn().mockRejectedValue(new Error("Error"));
(PassportDatabase as jest.Mock).mockImplementationOnce(() => {
return {
...passportDbMocks,
Expand All @@ -257,10 +261,9 @@ describe("CeramicContextProvider syncs stamp state with ceramic", () => {
status: "Success",
};
}),
setStamps: setStampMock,
};
});
(CeramicDatabase as jest.Mock).mockImplementationOnce(() => {
(ComposeDatabase as jest.Mock).mockImplementationOnce(() => {
return {
...ceramicDbMocks,
getPassport: jest.fn().mockImplementation(async () => {
Expand All @@ -272,15 +275,15 @@ describe("CeramicContextProvider syncs stamp state with ceramic", () => {
status: "Success",
};
}),
setStamps: setStampMock,
addStamps: addStampMock,
};
});
render(mockComponent());

await waitFor(() => fireEvent.click(screen.getByText("handleAddStamps")));
await waitFor(() => {
expect(addStampsMock).toHaveBeenCalled();
expect(setStampMock).toHaveBeenCalledWith(stamps);
expect(addStampMock).toHaveBeenCalledWith(stamps);
expect(console.log).toHaveBeenCalledWith("error setting ceramic stamps", new Error("Error"));
});
} finally {
Expand All @@ -291,8 +294,7 @@ describe("CeramicContextProvider syncs stamp state with ceramic", () => {
const oldConsoleLog = console.log;
try {
console.log = jest.fn();
const deleteStampsMock = jest.fn();
const setStampMock = jest.fn().mockRejectedValue(new Error("Error"));
const deleteStampsMock = jest.fn().mockRejectedValue("Error");
(PassportDatabase as jest.Mock).mockImplementationOnce(() => {
return {
...passportDbMocks,
Expand All @@ -316,27 +318,18 @@ describe("CeramicContextProvider syncs stamp state with ceramic", () => {
}),
};
});
(CeramicDatabase as jest.Mock).mockImplementationOnce(() => {
(ComposeDatabase as jest.Mock).mockImplementationOnce(() => {
return {
...ceramicDbMocks,
getPassport: jest.fn().mockImplementation(async () => {
return {
passport: {
stamps: [],
},
errorDetails: {},
status: "Success",
};
}),
setStamps: setStampMock,
deleteStamps: deleteStampsMock,
};
});
render(mockComponent());

await waitFor(() => fireEvent.click(screen.getByText("handleDeleteStamps")));
await waitFor(() => {
expect(deleteStampsMock).toHaveBeenCalled();
expect(setStampMock).toHaveBeenCalledWith([]);
expect(deleteStampsMock).toHaveBeenCalledWith(stamps.map((stamp) => stamp.provider));
});
} finally {
console.log = oldConsoleLog;
Expand All @@ -345,7 +338,6 @@ describe("CeramicContextProvider syncs stamp state with ceramic", () => {

it("should patch stamps in database and delete + add stamps in ceramic", async () => {
const added = stampPatches.filter(({ credential }) => credential);
const deletedProviders = stampPatches.filter(({ credential }) => !credential).map(({ provider }) => provider);

const patchStampsMock = jest.fn();
(PassportDatabase as jest.Mock).mockImplementationOnce(() => {
Expand Down Expand Up @@ -375,10 +367,9 @@ describe("CeramicContextProvider syncs stamp state with ceramic", () => {
const setStampMock = jest.fn();
const deleteStampsMock = jest.fn();

(CeramicDatabase as jest.Mock).mockImplementationOnce(() => {
(ComposeDatabase as jest.Mock).mockImplementationOnce(() => {
return {
...ceramicDbMocks,
setStamps: setStampMock,
deleteStampIDs: deleteStampsMock,
};
});
Expand All @@ -388,8 +379,6 @@ describe("CeramicContextProvider syncs stamp state with ceramic", () => {
await waitFor(() => fireEvent.click(screen.getByText("handlePatchStamps")));
await waitFor(() => {
expect(patchStampsMock).toHaveBeenCalledWith(stampPatches);
expect(deleteStampsMock).toHaveBeenCalledWith(deletedProviders);
expect(setStampMock).toHaveBeenCalledWith(added);
});
});

Expand All @@ -398,7 +387,7 @@ describe("CeramicContextProvider syncs stamp state with ceramic", () => {
try {
console.log = jest.fn();

const patchStampsMock = jest.fn();
const patchStampsMock = jest.fn().mockRejectedValue(new Error("Error"));
(PassportDatabase as jest.Mock).mockImplementationOnce(() => {
return {
...passportDbMocks,
Expand Down Expand Up @@ -426,11 +415,12 @@ describe("CeramicContextProvider syncs stamp state with ceramic", () => {
const setStampMock = jest.fn().mockRejectedValue(new Error("Error"));
const deleteStampsMock = jest.fn();

(CeramicDatabase as jest.Mock).mockImplementationOnce(() => {
(ComposeDatabase as jest.Mock).mockImplementationOnce(() => {
return {
...ceramicDbMocks,
setStamps: setStampMock,
deleteStampIDs: deleteStampsMock,
patchStamps: patchStampsMock,
};
});

Expand Down
Loading

0 comments on commit 2891d7d

Please sign in to comment.