From 2d042a4e00f6ea8ddf62b9ebaeb547ab1d048cb6 Mon Sep 17 00:00:00 2001 From: Raymond Z Date: Thu, 15 Aug 2024 07:16:29 -0400 Subject: [PATCH] fix tests --- .github/workflows/CI.yml | 8 ++++++-- libs/shared/src/canvas/runtime/contract.ts | 14 ++++++++------ libs/shared/src/canvas/runtime/node.ts | 14 ++++++-------- 3 files changed, 20 insertions(+), 16 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index c92052a9a49..5f9c1aec400 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -41,6 +41,7 @@ jobs: POSTGRES_USER: commonwealth POSTGRES_DB: common_test POSTGRES_PASSWORD: edgeware + POSTGRES_FEDERATION_DB_URL: postgresql://commonwealth:edgeware@localhost/common_test # Set health checks to wait until postgres has started options: >- --health-cmd pg_isready @@ -99,6 +100,7 @@ jobs: POSTGRES_USER: commonwealth POSTGRES_DB: common_test POSTGRES_PASSWORD: edgeware + POSTGRES_FEDERATION_DB_URL: postgresql://commonwealth:edgeware@localhost/common_test # Set health checks to wait until postgres has started options: >- --health-cmd pg_isready @@ -158,6 +160,7 @@ jobs: POSTGRES_USER: commonwealth POSTGRES_DB: common_test POSTGRES_PASSWORD: edgeware + POSTGRES_FEDERATION_DB_URL: postgresql://commonwealth:edgeware@localhost/common_test # Set health checks to wait until postgres has started options: >- --health-cmd pg_isready @@ -274,6 +277,7 @@ jobs: POSTGRES_USER: commonwealth POSTGRES_DB: common_test POSTGRES_PASSWORD: edgeware + POSTGRES_FEDERATION_DB_URL: postgresql://commonwealth:edgeware@localhost/common_test # Set health checks to wait until postgres has started options: >- --health-cmd pg_isready @@ -350,6 +354,7 @@ jobs: POSTGRES_USER: commonwealth POSTGRES_DB: common_test POSTGRES_PASSWORD: edgeware + POSTGRES_FEDERATION_DB_URL: postgresql://commonwealth:edgeware@localhost/common_test # Set health checks to wait until postgres has started options: >- --health-cmd pg_isready @@ -398,6 +403,7 @@ jobs: POSTGRES_USER: commonwealth POSTGRES_DB: common_test POSTGRES_PASSWORD: edgeware + POSTGRES_FEDERATION_DB_URL: postgresql://commonwealth:edgeware@localhost/common_test # Set health checks to wait until postgres has started options: >- --health-cmd pg_isready @@ -481,5 +487,3 @@ jobs: with: parallel-finished: true carryforward: "cosmos-devnet-test-coverage" - - diff --git a/libs/shared/src/canvas/runtime/contract.ts b/libs/shared/src/canvas/runtime/contract.ts index 7600b6bb473..8f29266aaa5 100644 --- a/libs/shared/src/canvas/runtime/contract.ts +++ b/libs/shared/src/canvas/runtime/contract.ts @@ -55,14 +55,16 @@ export const contract = { }); }, // TODO: not implemented (packages/commonwealth/server/routes/threads/update_thread_handler.ts) - async updateThread(db, { thread_id, title, body, link, topic }, { did, id, timestamp }) { + async updateThread(db, { thread_id, title, body, link, topic }, { did, timestamp }) { const t = await db.get("threads", thread_id); if (!t || !t.id) throw new Error("invalid thread"); + if (t.author !== did) throw new Error("invalid thread"); db.set('threads', { id: t.id as string, author: t.author, community: t.community, title, body, link, topic, updated_at: timestamp }); }, async deleteThread(db, { thread_id }, { did, id }) { const t = await db.get("threads", thread_id); if (!t || !t.id) throw new Error("invalid thread"); + if (t.author !== did) throw new Error("invalid thread"); db.delete("threads", t.id as string); }, async comment(db, { thread_id, body, parent_comment_id }, { did, id, timestamp }) { @@ -84,9 +86,9 @@ export const contract = { async deleteComment(db, { comment_id }, { did, id }) { const c = await db.get("comments", comment_id); if (!c || !c.id) throw new Error("invalid comment"); - db.delete("comments", c.id); + db.delete("comments", c.id as string); }, - async reactThread(db, { thread_id, value }, { did, id, timestamp }) { + async reactThread(db, { thread_id, value }, { did, timestamp }) { if (value !== 'like' && value !== 'dislike') { throw new Error('Invalid reaction'); } @@ -98,7 +100,7 @@ export const contract = { updated_at: timestamp, }); }, - async unreactThread(db, { thread_id, value }, { did, id, timestamp }) { + async unreactThread(db, { thread_id }, { did, timestamp }) { db.set("thread_reactions", { id: `${thread_id}/${did}`, author: did, @@ -107,7 +109,7 @@ export const contract = { updated_at: timestamp }); }, - async reactComment(db, { comment_id, value }, { did, id, timestamp }) { + async reactComment(db, { comment_id, value }, { did, timestamp }) { if (value !== 'like' && value !== 'dislike') { throw new Error('Invalid reaction'); } @@ -119,7 +121,7 @@ export const contract = { updated_at: timestamp, }); }, - async unreactComment(db, { comment_id, value }, { did, id, timestamp }) { + async unreactComment(db, { comment_id }, { did, timestamp }) { db.set("comment_reactions", { id: `${comment_id}/${did}`, author: did, diff --git a/libs/shared/src/canvas/runtime/node.ts b/libs/shared/src/canvas/runtime/node.ts index 63245d0e9ea..b8bbe19a2a0 100644 --- a/libs/shared/src/canvas/runtime/node.ts +++ b/libs/shared/src/canvas/runtime/node.ts @@ -8,19 +8,17 @@ export const CANVAS_TOPIC = topic; export const startCanvasNode = async () => { console.log('canvas: starting'); + + const path = + process.env.POSTGRES_FEDERATION_DB_URL ?? + 'postgresql://commonwealth:edgeware@localhost/federation'; const app = await Canvas.initialize({ topic, - path: - process.env.DATABASE_URL_CANVAS ?? - 'postgresql://commonwealth:edgeware@localhost/canvas', + path, contract, signers: getSessionSigners(), - bootstrapList: [], // TODO + bootstrapList: [], // TODO: app.libp2p.start() }); - - // TODO - // app.libp2p.start() - return app; };