Skip to content

Commit

Permalink
test(browser): enable all integration test suites in the browser test
Browse files Browse the repository at this point in the history
  • Loading branch information
mirceanis committed Jun 2, 2022
1 parent 280891a commit 5574de2
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 95 deletions.
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
import { agent } from '../src/veramo/setup'
import { getAgent } from '../src/veramo/setup'

import keyManager from '../../../__tests__/shared/keyManager'
// import didManager from '../../../__tests__/shared/didManager'
import didManager from '../../../__tests__/shared/didManager'
import verifiableDataJWT from '../../../__tests__/shared/verifiableDataJWT'
import verifiableDataLD from '../../../__tests__/shared/verifiableDataLD'
import handleSdrMessage from '../../../__tests__/shared/handleSdrMessage'
// import resolveDid from '../../../__tests__/shared/resolveDid'
import resolveDid from '../../../__tests__/shared/resolveDid'
import webDidFlow from '../../../__tests__/shared/webDidFlow'
import saveClaims from '../../../__tests__/shared/saveClaims'
import documentationExamples from '../../../__tests__/shared/documentationExamples'
// import didCommPacking from '../../../__tests__/shared/didCommPacking'
import didCommPacking from '../../../__tests__/shared/didCommPacking'
import messageHandler from '../../../__tests__/shared/messageHandler'

jest.setTimeout(3 * 60 * 1000)

describe('Browser integration tests', () => {
describe('shared tests', () => {
const testContext = { getAgent: () => agent, setup: () => {}, tearDown: () => {} }
const testContext = { getAgent, setup: async () => true, tearDown: async () => true }
verifiableDataJWT(testContext)
// verifiableDataLD(testContext)
verifiableDataLD(testContext)
handleSdrMessage(testContext)
// resolveDid(testContext)
resolveDid(testContext)
webDidFlow(testContext)
saveClaims(testContext)
documentationExamples(testContext)
keyManager(testContext)
// didManager(testContext)
didManager(testContext)
messageHandler(testContext)
// didCommPacking(testContext)
didCommPacking(testContext)
})

describe('should intialize in the react app', () => {
Expand Down
4 changes: 3 additions & 1 deletion __browser_tests__/react-sample/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import React, { useEffect, useState } from 'react'
import './App.css'
import { agent } from './veramo/setup'
import { getAgent } from './veramo/setup'

function App() {
const [didDoc, setDidDoc] = useState<any>(null)
const [invalidDidDoc, setInvalidDidDoc] = useState<any>(null)

const agent = getAgent()

const resolve = async () => {
const doc = await agent.resolveDid({
didUrl: 'did:ethr:rinkeby:0x6acf3bb1ef0ee84559de2bc2bd9d91532062a730',
Expand Down
165 changes: 80 additions & 85 deletions __browser_tests__/react-sample/src/veramo/setup.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createAgent, IDataStore, IDataStoreORM, IDIDManager, IKeyManager, IResolver, TAgent } from '@veramo/core'
import { createAgent, IAgentOptions, IDataStore, IDataStoreORM, IDIDManager, IKeyManager, IMessageHandler, IResolver, TAgent } from '@veramo/core'

import { DIDResolverPlugin } from '@veramo/did-resolver'
import { Resolver } from 'did-resolver'
Expand All @@ -9,7 +9,8 @@ import { KeyManager } from '@veramo/key-manager'
import { DIDManager } from '@veramo/did-manager'
import { JwtMessageHandler } from '@veramo/did-jwt'
import { CredentialIssuer, ICredentialIssuer, W3cMessageHandler } from '@veramo/credential-w3c'
// import { getDidKeyResolver, KeyDIDProvider } from '@veramo/did-provider-key'
import { CredentialIssuerLD, ICredentialIssuerLD, LdDefaultContexts, VeramoEcdsaSecp256k1RecoverySignature2020, VeramoEd25519Signature2018 } from '@veramo/credential-ld'
import { getDidKeyResolver, KeyDIDProvider } from '@veramo/did-provider-key'
import { DIDComm, DIDCommMessageHandler, IDIDComm } from '@veramo/did-comm'
import { ISelectiveDisclosure, SdrMessageHandler, SelectiveDisclosure } from '@veramo/selective-disclosure'
import { KeyManagementSystem } from '@veramo/kms-local'
Expand All @@ -29,92 +30,86 @@ type InstalledPlugins =
& IKeyManager
& IDIDManager
& ICredentialIssuer
& ICredentialIssuerLD
& IDataStoreORM
& IDataStore
& IMessageHandler
& ISelectiveDisclosure
& IDIDComm

export const agent: TAgent<InstalledPlugins> = createAgent<InstalledPlugins>({
plugins: [
new DIDResolverPlugin({
resolver: new Resolver({
...ethrDidResolver({ infuraProjectId: INFURA_PROJECT_ID }),
...webDidResolver(),
/**
* `getDidKeyResolver` throws error:
* "Field 'browser' doesn't contain a valid alias configuration"
* Can't resolve 'stream'
* 'stream-browserify' can be installed for brower env
*/
// ...getDidKeyResolver(),
// ...new FakeDidResolver(() => agent).getDidFakeResolver(),
}),
}),
new KeyManager({
store: new KeyStoreJson(memoryJsonStore),
kms: {
local: new KeyManagementSystem(new PrivateKeyStoreJson(memoryJsonStore)),
},
}),
new DIDManager({
store: new DIDStoreJson(memoryJsonStore),
defaultProvider: 'did:ethr:rinkeby',
providers: {
'did:ethr': new EthrDIDProvider({
defaultKms: 'local',
network: 'mainnet',
rpcUrl: 'https://mainnet.infura.io/v3/' + INFURA_PROJECT_ID,
gas: 1000001,
ttl: 60 * 60 * 24 * 30 * 12 + 1,
}),
'did:ethr:rinkeby': new EthrDIDProvider({
defaultKms: 'local',
network: 'rinkeby',
rpcUrl: 'https://rinkeby.infura.io/v3/' + INFURA_PROJECT_ID,
gas: 1000001,
ttl: 60 * 60 * 24 * 30 * 12 + 1,
}),
'did:ethr:421611': new EthrDIDProvider({
defaultKms: 'local',
network: 421611,
rpcUrl: 'https://arbitrum-rinkeby.infura.io/v3/' + INFURA_PROJECT_ID,
registry: '0x8f54f62CA28D481c3C30b1914b52ef935C1dF820',
}),
'did:web': new WebDIDProvider({
defaultKms: 'local',
export function getAgent(options?: IAgentOptions): TAgent<InstalledPlugins> {

const agent: TAgent<InstalledPlugins> = createAgent<InstalledPlugins>({
...options,
plugins: [
new DIDResolverPlugin({
resolver: new Resolver({
...ethrDidResolver({ infuraProjectId: INFURA_PROJECT_ID }),
...webDidResolver(),
...getDidKeyResolver(),
...new FakeDidResolver(() => agent).getDidFakeResolver(),
}),
/**
* `KeyDIDProvider` throws error:
* "Field 'browser' doesn't contain a valid alias configuration"
* Can't resolve 'stream'
* 'stream-browserify' can be installed for browser env
*/
// 'did:key': new KeyDIDProvider({
// defaultKms: 'local',
// }),
// 'did:fake': new FakeDidProvider(),
},
}),
new DataStoreJson(memoryJsonStore),
new MessageHandler({
messageHandlers: [
new DIDCommMessageHandler(),
new JwtMessageHandler(),
new W3cMessageHandler(),
new SdrMessageHandler(),
],
}),
new DIDComm(),
new CredentialIssuer(),
/**
* `CredentialIssuerLD` throws error:
* Can't resolve 'path'
* 'path-browserify' can be installed for brower env
*/
// new CredentialIssuerLD({
// contextMaps: [LdDefaultContexts],
// suites: [new VeramoEcdsaSecp256k1RecoverySignature2020(), new VeramoEd25519Signature2018()],
// }),
new SelectiveDisclosure(),
],
})
}),
new KeyManager({
store: new KeyStoreJson(memoryJsonStore),
kms: {
local: new KeyManagementSystem(new PrivateKeyStoreJson(memoryJsonStore)),
},
}),
new DIDManager({
store: new DIDStoreJson(memoryJsonStore),
defaultProvider: 'did:ethr:rinkeby',
providers: {
'did:ethr': new EthrDIDProvider({
defaultKms: 'local',
network: 'mainnet',
rpcUrl: 'https://mainnet.infura.io/v3/' + INFURA_PROJECT_ID,
gas: 1000001,
ttl: 60 * 60 * 24 * 30 * 12 + 1,
}),
'did:ethr:rinkeby': new EthrDIDProvider({
defaultKms: 'local',
network: 'rinkeby',
rpcUrl: 'https://rinkeby.infura.io/v3/' + INFURA_PROJECT_ID,
gas: 1000001,
ttl: 60 * 60 * 24 * 30 * 12 + 1,
}),
'did:ethr:421611': new EthrDIDProvider({
defaultKms: 'local',
network: 421611,
rpcUrl: 'https://arbitrum-rinkeby.infura.io/v3/' + INFURA_PROJECT_ID,
registry: '0x8f54f62CA28D481c3C30b1914b52ef935C1dF820',
}),
'did:web': new WebDIDProvider({
defaultKms: 'local',
}),
'did:key': new KeyDIDProvider({
defaultKms: 'local',
}),
'did:fake': new FakeDidProvider(),
},
}),
new DataStoreJson(memoryJsonStore),
new MessageHandler({
messageHandlers: [
new DIDCommMessageHandler(),
new JwtMessageHandler(),
new W3cMessageHandler(),
new SdrMessageHandler(),
],
}),
new DIDComm(),
new CredentialIssuer(),
new CredentialIssuerLD({
contextMaps: [LdDefaultContexts],
suites: [
new VeramoEcdsaSecp256k1RecoverySignature2020(),
new VeramoEd25519Signature2018()
],
}),
new SelectiveDisclosure(),
...(options?.plugins || []),
],
})
return agent
}

0 comments on commit 5574de2

Please sign in to comment.