Skip to content

Commit

Permalink
test: more fixed tests
Browse files Browse the repository at this point in the history
Signed-off-by: Ariel Gentile <[email protected]>
  • Loading branch information
genaris committed Dec 20, 2024
1 parent 17b2674 commit 618b975
Show file tree
Hide file tree
Showing 19 changed files with 131 additions and 181 deletions.
6 changes: 5 additions & 1 deletion packages/action-menu/src/__tests__/ActionMenuModule.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { FeatureRegistry } from '@credo-ts/didcomm'

import { Protocol } from '@credo-ts/didcomm'

import { getAgentContext } from '../../../core/tests'
import { ActionMenuModule } from '../ActionMenuModule'
import { ActionMenuRole } from '../ActionMenuRole'
import { ActionMenuRepository } from '../repository'
Expand All @@ -20,13 +21,16 @@ const dependencyManager = {
} as unknown as DependencyManager

describe('ActionMenuModule', () => {
test('registers dependencies on the dependency manager', () => {
test('registers dependencies on the dependency manager', async () => {
const actionMenuModule = new ActionMenuModule()
actionMenuModule.register(dependencyManager)

expect(dependencyManager.registerSingleton).toHaveBeenCalledTimes(2)
expect(dependencyManager.registerSingleton).toHaveBeenCalledWith(ActionMenuService)
expect(dependencyManager.registerSingleton).toHaveBeenCalledWith(ActionMenuRepository)
expect(featureRegistry.register).toHaveBeenCalledTimes(0)

await actionMenuModule.initialize(getAgentContext({ dependencyManager }))

expect(featureRegistry.register).toHaveBeenCalledTimes(1)
expect(featureRegistry.register).toHaveBeenCalledWith(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { EventReplaySubject } from '../../../../../../core/tests'
import type { AnonCredsTestsAgent } from '../../../../../tests/legacyAnonCredsSetup'

import { ProofState, ProofExchangeRecord } from '../../../../../../core/src'
import { testLogger, waitForProofExchangeRecord } from '../../../../../../core/tests'
import { ProofState, ProofExchangeRecord } from '../../../../../../didcomm/src'
import { issueLegacyAnonCredsCredential, setupAnonCredsTests } from '../../../../../tests/legacyAnonCredsSetup'
import { V1ProposePresentationMessage, V1RequestPresentationMessage, V1PresentationMessage } from '../messages'

Expand Down Expand Up @@ -63,7 +63,7 @@ describe('Present Proof', () => {
state: ProofState.ProposalReceived,
})

let aliceProofExchangeRecord = await aliceAgent.proofs.proposeProof({
let aliceProofExchangeRecord = await aliceAgent.modules.proofs.proposeProof({
connectionId: aliceConnectionId,
protocolVersion: 'v1',
proofFormats: {
Expand Down Expand Up @@ -91,7 +91,7 @@ describe('Present Proof', () => {
// Faber waits for a presentation proposal from Alice
testLogger.test('Faber waits for a presentation proposal from Alice')
let faberProofExchangeRecord = await faberProofExchangeRecordPromise
const proposal = await faberAgent.proofs.findProposalMessage(faberProofExchangeRecord.id)
const proposal = await faberAgent.modules.proofs.findProposalMessage(faberProofExchangeRecord.id)
expect(proposal).toMatchObject({
type: 'https://didcomm.org/present-proof/1.0/propose-presentation',
id: expect.any(String),
Expand Down Expand Up @@ -129,15 +129,15 @@ describe('Present Proof', () => {

// Faber accepts the presentation proposal from Alice
testLogger.test('Faber accepts presentation proposal from Alice')
faberProofExchangeRecord = await faberAgent.proofs.acceptProposal({
faberProofExchangeRecord = await faberAgent.modules.proofs.acceptProposal({
proofRecordId: faberProofExchangeRecord.id,
})

// Alice waits for presentation request from Faber
testLogger.test('Alice waits for presentation request from Faber')
aliceProofExchangeRecord = await aliceProofExchangeRecordPromise

const request = await faberAgent.proofs.findRequestMessage(faberProofExchangeRecord.id)
const request = await faberAgent.modules.proofs.findRequestMessage(faberProofExchangeRecord.id)
expect(request).toMatchObject({
type: 'https://didcomm.org/present-proof/1.0/request-presentation',
id: expect.any(String),
Expand All @@ -158,7 +158,7 @@ describe('Present Proof', () => {
// Alice retrieves the requested credentials and accepts the presentation request
testLogger.test('Alice accepts presentation request from Faber')

const requestedCredentials = await aliceAgent.proofs.selectCredentialsForRequest({
const requestedCredentials = await aliceAgent.modules.proofs.selectCredentialsForRequest({
proofRecordId: aliceProofExchangeRecord.id,
})

Expand All @@ -167,7 +167,7 @@ describe('Present Proof', () => {
state: ProofState.PresentationReceived,
})

await aliceAgent.proofs.acceptRequest({
await aliceAgent.modules.proofs.acceptRequest({
proofRecordId: aliceProofExchangeRecord.id,
proofFormats: { indy: requestedCredentials.proofFormats.indy },
})
Expand All @@ -176,7 +176,7 @@ describe('Present Proof', () => {
testLogger.test('Faber waits for presentation from Alice')
faberProofExchangeRecord = await faberProofExchangeRecordPromise

const presentation = await faberAgent.proofs.findPresentationMessage(faberProofExchangeRecord.id)
const presentation = await faberAgent.modules.proofs.findPresentationMessage(faberProofExchangeRecord.id)
expect(presentation).toMatchObject({
type: 'https://didcomm.org/present-proof/1.0/presentation',
id: expect.any(String),
Expand Down Expand Up @@ -208,7 +208,7 @@ describe('Present Proof', () => {

// Faber accepts the presentation provided by Alice
testLogger.test('Faber accepts the presentation provided by Alice')
await faberAgent.proofs.acceptPresentation({ proofRecordId: faberProofExchangeRecord.id })
await faberAgent.modules.proofs.acceptPresentation({ proofRecordId: faberProofExchangeRecord.id })

// Alice waits until she received a presentation acknowledgement
testLogger.test('Alice waits until she receives a presentation acknowledgement')
Expand All @@ -233,15 +233,15 @@ describe('Present Proof', () => {
state: ProofState.Done,
})

const proposalMessage = await aliceAgent.proofs.findProposalMessage(aliceProofExchangeRecord.id)
const requestMessage = await aliceAgent.proofs.findRequestMessage(aliceProofExchangeRecord.id)
const presentationMessage = await aliceAgent.proofs.findPresentationMessage(aliceProofExchangeRecord.id)
const proposalMessage = await aliceAgent.modules.proofs.findProposalMessage(aliceProofExchangeRecord.id)
const requestMessage = await aliceAgent.modules.proofs.findRequestMessage(aliceProofExchangeRecord.id)
const presentationMessage = await aliceAgent.modules.proofs.findPresentationMessage(aliceProofExchangeRecord.id)

expect(proposalMessage).toBeInstanceOf(V1ProposePresentationMessage)
expect(requestMessage).toBeInstanceOf(V1RequestPresentationMessage)
expect(presentationMessage).toBeInstanceOf(V1PresentationMessage)

const formatData = await aliceAgent.proofs.getFormatData(aliceProofExchangeRecord.id)
const formatData = await aliceAgent.modules.proofs.getFormatData(aliceProofExchangeRecord.id)

const proposalPredicateKey = Object.keys(formatData.proposal?.indy?.requested_predicates || {})[0]
const requestPredicateKey = Object.keys(formatData.request?.indy?.requested_predicates || {})[0]
Expand Down Expand Up @@ -312,7 +312,7 @@ describe('Present Proof', () => {

// Faber sends a presentation request to Alice
testLogger.test('Faber sends a presentation request to Alice')
let faberProofExchangeRecord = await faberAgent.proofs.requestProof({
let faberProofExchangeRecord = await faberAgent.modules.proofs.requestProof({
protocolVersion: 'v1',
connectionId: faberConnectionId,
proofFormats: {
Expand Down Expand Up @@ -349,7 +349,7 @@ describe('Present Proof', () => {
testLogger.test('Alice waits for presentation request from Faber')
let aliceProofExchangeRecord = await aliceProofExchangeRecordPromise

const request = await faberAgent.proofs.findRequestMessage(faberProofExchangeRecord.id)
const request = await faberAgent.modules.proofs.findRequestMessage(faberProofExchangeRecord.id)
expect(request).toMatchObject({
type: 'https://didcomm.org/present-proof/1.0/request-presentation',
id: expect.any(String),
Expand All @@ -374,7 +374,7 @@ describe('Present Proof', () => {
// Alice retrieves the requested credentials and accepts the presentation request
testLogger.test('Alice accepts presentation request from Faber')

const requestedCredentials = await aliceAgent.proofs.selectCredentialsForRequest({
const requestedCredentials = await aliceAgent.modules.proofs.selectCredentialsForRequest({
proofRecordId: aliceProofExchangeRecord.id,
})

Expand All @@ -383,7 +383,7 @@ describe('Present Proof', () => {
state: ProofState.PresentationReceived,
})

await aliceAgent.proofs.acceptRequest({
await aliceAgent.modules.proofs.acceptRequest({
proofRecordId: aliceProofExchangeRecord.id,
proofFormats: { indy: requestedCredentials.proofFormats.indy },
})
Expand All @@ -392,7 +392,7 @@ describe('Present Proof', () => {
testLogger.test('Faber waits for presentation from Alice')
faberProofExchangeRecord = await faberProofExchangeRecordPromise

const presentation = await faberAgent.proofs.findPresentationMessage(faberProofExchangeRecord.id)
const presentation = await faberAgent.modules.proofs.findPresentationMessage(faberProofExchangeRecord.id)
expect(presentation).toMatchObject({
type: 'https://didcomm.org/present-proof/1.0/presentation',
id: expect.any(String),
Expand Down Expand Up @@ -424,7 +424,7 @@ describe('Present Proof', () => {

// Faber accepts the presentation
testLogger.test('Faber accept the presentation from Alice')
await faberAgent.proofs.acceptPresentation({ proofRecordId: faberProofExchangeRecord.id })
await faberAgent.modules.proofs.acceptPresentation({ proofRecordId: faberProofExchangeRecord.id })

// Alice waits until she receives a presentation acknowledgement
testLogger.test('Alice waits for acceptance by Faber')
Expand Down Expand Up @@ -452,7 +452,7 @@ describe('Present Proof', () => {

test('an attribute group name matches with a predicate group name so an error is thrown', async () => {
await expect(
faberAgent.proofs.requestProof({
faberAgent.modules.proofs.requestProof({
protocolVersion: 'v1',
connectionId: faberConnectionId,
proofFormats: {
Expand Down Expand Up @@ -494,7 +494,7 @@ describe('Present Proof', () => {

// Faber sends a presentation request to Alice
testLogger.test('Faber sends a presentation request to Alice')
let faberProofExchangeRecord = await faberAgent.proofs.requestProof({
let faberProofExchangeRecord = await faberAgent.modules.proofs.requestProof({
protocolVersion: 'v1',
connectionId: faberConnectionId,
proofFormats: {
Expand Down Expand Up @@ -531,7 +531,7 @@ describe('Present Proof', () => {
testLogger.test('Alice waits for presentation request from Faber')
let aliceProofExchangeRecord = await aliceProofExchangeRecordPromise

const request = await faberAgent.proofs.findRequestMessage(faberProofExchangeRecord.id)
const request = await faberAgent.modules.proofs.findRequestMessage(faberProofExchangeRecord.id)
expect(request).toMatchObject({
type: 'https://didcomm.org/present-proof/1.0/request-presentation',
id: expect.any(String),
Expand All @@ -558,7 +558,7 @@ describe('Present Proof', () => {
state: ProofState.Abandoned,
})

aliceProofExchangeRecord = await aliceAgent.proofs.sendProblemReport({
aliceProofExchangeRecord = await aliceAgent.modules.proofs.sendProblemReport({
proofRecordId: aliceProofExchangeRecord.id,
description: 'Problem inside proof request',
})
Expand Down
25 changes: 11 additions & 14 deletions packages/anoncreds/tests/legacyAnonCredsSetup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,11 @@ import type {
RegisterCredentialDefinitionReturnStateFinished,
RegisterSchemaReturnStateFinished,
} from '../src'
import type { AutoAcceptProof, ConnectionRecord } from '@credo-ts/core'
import type { AutoAcceptProof, ConnectionRecord } from '@credo-ts/didcomm'

import { TypedArrayEncoder, CacheModule, InMemoryLruCache, Agent, CredoError, DidsModule } from '@credo-ts/core'
import {
AgentEventTypes,
TypedArrayEncoder,
CacheModule,
InMemoryLruCache,
Agent,
CredoError,
AutoAcceptCredential,
CredentialEventTypes,
CredentialsModule,
Expand All @@ -27,8 +23,7 @@ import {
ProofState,
V2CredentialProtocol,
V2ProofProtocol,
DidsModule,
} from '@credo-ts/core'
} from '@credo-ts/didcomm'
import { randomUUID } from 'crypto'

import { sleep } from '../../core/src/utils/sleep'
Expand All @@ -42,6 +37,7 @@ import {
waitForProofExchangeRecordSubject,
} from '../../core/tests/helpers'
import testLogger from '../../core/tests/logger'
import { getDefaultDidcommModules } from '../../didcomm/src/util/modules'
import {
IndyVdrAnonCredsRegistry,
IndyVdrSovDidResolver,
Expand Down Expand Up @@ -99,6 +95,7 @@ export const getAnonCredsIndyModules = ({
const legacyIndyProofFormatService = new LegacyIndyProofFormatService()

const modules = {
...getDefaultDidcommModules(),
credentials: new CredentialsModule({
autoAcceptCredentials,
credentialProtocols: [
Expand Down Expand Up @@ -165,7 +162,7 @@ export async function presentLegacyAnonCredsProof({
state: ProofState.RequestReceived,
})

let verifierProofExchangeRecord = await verifierAgent.proofs.requestProof({
let verifierProofExchangeRecord = await verifierAgent.modules.proofs.requestProof({
connectionId: verifierHolderConnectionId,
proofFormats: {
indy: {
Expand All @@ -180,7 +177,7 @@ export async function presentLegacyAnonCredsProof({

let holderProofExchangeRecord = await holderProofExchangeRecordPromise

const selectedCredentials = await holderAgent.proofs.selectCredentialsForRequest({
const selectedCredentials = await holderAgent.modules.proofs.selectCredentialsForRequest({
proofRecordId: holderProofExchangeRecord.id,
})

Expand All @@ -189,7 +186,7 @@ export async function presentLegacyAnonCredsProof({
state: ProofState.PresentationReceived,
})

await holderAgent.proofs.acceptRequest({
await holderAgent.modules.proofs.acceptRequest({
proofRecordId: holderProofExchangeRecord.id,
proofFormats: { indy: selectedCredentials.proofFormats.indy },
})
Expand All @@ -204,7 +201,7 @@ export async function presentLegacyAnonCredsProof({
state: ProofState.Done,
})

verifierProofExchangeRecord = await verifierAgent.proofs.acceptPresentation({
verifierProofExchangeRecord = await verifierAgent.modules.proofs.acceptPresentation({
proofRecordId: verifierProofExchangeRecord.id,
})
holderProofExchangeRecord = await holderProofExchangeRecordPromise
Expand Down Expand Up @@ -234,7 +231,7 @@ export async function issueLegacyAnonCredsCredential({
issuerHolderConnectionId: string
offer: AnonCredsOfferCredentialFormat
}) {
let issuerCredentialExchangeRecord = await issuerAgent.credentials.offerCredential({
let issuerCredentialExchangeRecord = await issuerAgent.modules.credentials.offerCredential({
comment: 'some comment about credential',
connectionId: issuerHolderConnectionId,
protocolVersion: 'v1',
Expand All @@ -249,7 +246,7 @@ export async function issueLegacyAnonCredsCredential({
state: CredentialState.OfferReceived,
})

await holderAgent.credentials.acceptOffer({
await holderAgent.modules.credentials.acceptOffer({
credentialRecordId: holderCredentialExchangeRecord.id,
autoAcceptCredential: AutoAcceptCredential.ContentApproved,
})
Expand Down
Loading

0 comments on commit 618b975

Please sign in to comment.