Skip to content
This repository has been archived by the owner on Jan 1, 2025. It is now read-only.

Commit

Permalink
WIP add test to ensure wallet will start up with pluto instances
Browse files Browse the repository at this point in the history
  • Loading branch information
mixmix committed Feb 1, 2024
1 parent c1971f7 commit f368410
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/database/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"@pluto-encrypted/leveldb": "1.12.1"
},
"devDependencies": {
"@atala/prism-wallet-sdk": "^4.0.0",
"@pluto-encrypted/encryption": "1.11.0",
"@pluto-encrypted/indexdb": "1.12.1",
"@pluto-encrypted/inmemory": "1.12.1",
Expand All @@ -51,7 +52,6 @@
"level": "^6.0.1"
},
"dependencies": {
"@atala/prism-wallet-sdk": "^4.0.0",
"@pluto-encrypted/encryption": "1.11.0",
"@pluto-encrypted/shared": "1.11.3",
"@pluto-encrypted/schemas": "^1.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/leveldb/tests/init.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const defaultPassword = Buffer.from(keyData);

describe("Testing suite", () => {

it('should be able to instanciate multiple databases in the same thread', async ({ expect }) => {
it('should be able to instantiate multiple databases in the same thread', async ({ expect }) => {
if (fs.existsSync("./db1")) {
fs.rmdirSync("./db1", { recursive: true })
}
Expand Down
4 changes: 2 additions & 2 deletions packages/leveldb/tests/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ import "fake-indexeddb/auto";
import { TextEncoder, TextDecoder } from "util";
import { addRxPlugin } from "rxdb";
import { RxDBDevModePlugin } from "rxdb/plugins/dev-mode";
import nodeCrypto from "crypto";
import { getRandomValues } from "crypto";

if (process.env.NODE_ENV === "debug") {
addRxPlugin(RxDBDevModePlugin);
}

Object.defineProperty(globalThis, "crypto", {
value: {
getRandomValues: (arr) => nodeCrypto.getRandomValues(arr),
getRandomValues: (arr) => getRandomValues(arr),
},
});

Expand Down
47 changes: 46 additions & 1 deletion packages/test-suite/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@
* @description This package can be used as a compliance test to validate a new storage created by you or the community.
*/
import { type FilledMangoQuery, type RxDocumentData, type RxDocumentWriteData, type RxJsonSchema, type RxStorage, type RxStorageBulkWriteResponse, type RxStorageInstance, type RxStorageInstanceCreationParams, clone, createRevision, ensureNotFalsy, fillWithDefaultSettings, flatCloneDocWithMeta, getPseudoSchemaForVersion, getQueryMatcher, getSortComparator, newRxError, now, parseRevision, randomCouchString, shuffleArray } from 'rxdb'
import { randomString } from 'async-test-util'
import SDK from '@atala/prism-wallet-sdk'
import { Database } from '@pluto-encrypted/database'
import { getDefaultCollections } from "@pluto-encrypted/schemas";

import { EXAMPLE_REVISION_1, EXAMPLE_REVISION_2, EXAMPLE_REVISION_3, EXAMPLE_REVISION_4, type NestedDoc, type OptionalValueTestDoc, type RandomDoc, type RxTestStorage, type TestDocType, type TestSuite, getNestedDocSchema, getTestDataSchema, getWriteData, prepareQuery, testContext, testCorrectQueries, withIndexes } from './helper'
import * as schemas from './helper/schemas'
import { type HeroArrayDocumentType, type NestedHumanDocumentType, type SimpleHumanV3DocumentType, human, nestedHuman, simpleHumanV3 } from './helper/schema-objects'
import { type HumanDocumentType } from './helper/schemas'
import { randomString } from 'async-test-util'

let storage: RxStorage<any, any>
let storageInstance: RxStorageInstance<any, any, any, any>
Expand Down Expand Up @@ -2584,5 +2588,46 @@ export function runTestSuite(suite: TestSuite, testStorage: RxTestStorage): void
}
]
})

describe('@atala/prism-sdk-wallet will start with this pluto', async ({ expect }) => {
const defaultPassword = new Uint8Array(32).fill(1)
const pluto = await Database.createEncrypted({
name: 'my-db',
encryptionKey: defaultPassword,
storage,
collections: getDefaultCollections()
})

const mediatorDIDString = 'did:peer:2.Ez6LSghwSE437wnDE1pt3X6hVDUQzSjsHzinpX3XFvMjRAm7y.Vz6Mkhh1e5CEYYq6JBUcTZ6Cp2ranCWRrv7Yax3Le4N59R6dd.SeyJ0IjoiZG0iLCJzIjoiaHR0cDovL2xvY2FsaG9zdDo4MDgwIiwiciI6W10sImEiOlsiZGlkY29tbS92MiJdfQ'
const mediatorDID = SDK.Domain.DID.fromString(mediatorDIDString)

const apollo = new SDK.Apollo()
const api = new SDK.ApiImpl()
const castor = new SDK.Castor(apollo)

const didcomm = new SDK.DIDCommWrapper(apollo, castor, pluto)
const mercury = new SDK.Mercury(castor, didcomm, api)
const store = new SDK.PublicMediatorStore(pluto)
const handler = new SDK.BasicMediatorHandler(mediatorDID, mercury, store)
const manager = new SDK.ConnectionsManager(castor, mercury, pluto, handler)

const seed = apollo.createRandomSeed()
// TODO persist this?

const agent = new SDK.Agent(
apollo,
castor,
pluto,
mercury,
handler,
manager,
seed.seed
)

const result = await agent.start()
.catch(console.error)

expect(result).not.toBe(undefined)
})
})
}

0 comments on commit f368410

Please sign in to comment.