From d6f1bbd2c37261548c79e34d69aa7bff8b175181 Mon Sep 17 00:00:00 2001 From: Nick Thomas Date: Sun, 21 Apr 2024 15:38:16 -0700 Subject: [PATCH] FEATURE: better tests --- package.json | 2 +- src/index.ts | 1 - test/index.ts | 18 ++++++++++++++++-- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 333f20d..69c8865 100644 --- a/package.json +++ b/package.json @@ -22,13 +22,13 @@ }, "dependencies": { "@bicycle-codes/identity": "^0.7.2", - "@bicycle-codes/message": "^0.7.2", "@nichoth/nanoid": "^5.0.8", "@nichoth/nanoid-dictionary": "^5.0.2", "partysocket": "^1.0.1", "uint8arrays": "^5.0.3" }, "devDependencies": { + "@bicycle-codes/message": "^0.7.2", "@bicycle-codes/tapzero": "^0.9.2", "@nichoth/components": "^0.16.9", "@nichoth/debug": "^0.6.7", diff --git a/src/index.ts b/src/index.ts index ca04b0a..206f75a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,5 +1,4 @@ import { PartySocket } from 'partysocket' -// import { toString } from '@bicycle-codes/identity' import { create as createMessage } from '@bicycle-codes/message' import Debug from '@nichoth/debug' import { diff --git a/test/index.ts b/test/index.ts index 621602d..202225c 100644 --- a/test/index.ts +++ b/test/index.ts @@ -1,6 +1,11 @@ import { test } from '@bicycle-codes/tapzero' +import { + create as createID, + writeKeyToDid, +} from '@bicycle-codes/identity' +import { verify } from '@bicycle-codes/message' import { Parent, Child, Certificate } from '../src/index.js' -import { create as createID } from '@bicycle-codes/identity' +import { Implementation } from '@oddjs/odd/lib/components/crypto/implementation' const odd = globalThis.webnative const createProgram = odd.program @@ -8,6 +13,8 @@ const createProgram = odd.program const HOST_URL = 'localhost:1999' let _certificate:Certificate|undefined +let _aliceComputerCrypto:Implementation +let _alicesCrypto:Implementation test('link 2 devices', async t => { t.plan(5) @@ -19,6 +26,7 @@ test('link 2 devices', async t => { } }) const { crypto: alicesCrypto } = alicesProgram.components + _alicesCrypto = alicesCrypto const alice = await createID(alicesCrypto, { humanName: 'alice', humanReadableDeviceName: 'phone' @@ -32,6 +40,8 @@ test('link 2 devices', async t => { }) const { crypto: alicesComputersCrypto } = alicesComputersProgram.components + _aliceComputerCrypto = alicesComputersCrypto + // parent must be called first Parent(alice, alicesCrypto, { host: HOST_URL, @@ -63,5 +73,9 @@ test('link 2 devices', async t => { }) test('the certificate', async t => { - t.equal(_certificate?.recipient) + t.equal(_certificate?.recipient, await writeKeyToDid(_aliceComputerCrypto), + 'should create a certificate for the new device') + t.ok(await verify(_certificate!), 'the cerificate should be valid') + t.equal(_certificate?.author, await writeKeyToDid(_alicesCrypto), + "the certificate should be signed by alice's original machine") })