Skip to content

Commit

Permalink
Merge branch 'main' into fix/oob-state-role-handling
Browse files Browse the repository at this point in the history
  • Loading branch information
berendsliedrecht authored May 23, 2022
2 parents 75d16d6 + 0c3cc49 commit 587898f
Showing 1 changed file with 17 additions and 22 deletions.
39 changes: 17 additions & 22 deletions packages/core/tests/oob.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable @typescript-eslint/no-non-null-assertion */
import type { SubjectMessage } from '../../../tests/transport/SubjectInboundTransport'
import type { OfferCredentialOptions } from '../src/modules/credentials/CredentialsModuleOptions'
import type { AgentMessage, AgentMessageReceivedEvent, CredentialExchangeRecord } from '@aries-framework/core'
import type { AgentMessage, AgentMessageReceivedEvent } from '@aries-framework/core'

import { Subject } from 'rxjs'

Expand All @@ -14,10 +14,9 @@ import { OutOfBandEventTypes } from '../src/modules/oob/domain/OutOfBandEvents'
import { OutOfBandRole } from '../src/modules/oob/domain/OutOfBandRole'
import { OutOfBandState } from '../src/modules/oob/domain/OutOfBandState'
import { OutOfBandInvitation } from '../src/modules/oob/messages'
import { sleep } from '../src/utils/sleep'

import { TestMessage } from './TestMessage'
import { getBaseConfig, prepareForIssuance } from './helpers'
import { getBaseConfig, prepareForIssuance, waitForCredentialRecord } from './helpers'

import {
AgentEventTypes,
Expand Down Expand Up @@ -340,17 +339,14 @@ describe('out of band', () => {

const urlMessage = outOfBandInvitation.toUrl({ domain: 'http://example.com' })

const aliceCredentialRecordPromise = waitForCredentialRecord(aliceAgent, {
state: CredentialState.OfferReceived,
threadId: message.threadId,
})
await aliceAgent.oob.receiveInvitationFromUrl(urlMessage, receiveInvitationConfig)

let credentials: CredentialExchangeRecord[] = []
while (credentials.length < 1) {
credentials = await aliceAgent.credentials.getAll()
await sleep(100)
}

expect(credentials).toHaveLength(1)
const [credential] = credentials
expect(credential.state).toBe(CredentialState.OfferReceived)
const aliceCredentialRecord = await aliceCredentialRecordPromise
expect(aliceCredentialRecord.state).toBe(CredentialState.OfferReceived)
})

test('do not process requests when a connection is not ready', async () => {
Expand Down Expand Up @@ -389,6 +385,13 @@ describe('out of band', () => {
}
)

const aliceCredentialRecordPromise = waitForCredentialRecord(aliceAgent, {
state: CredentialState.OfferReceived,
threadId: message.threadId,
// We need to create the connection beforehand so it can take a while to complete
timeoutMs: 20000,
})

// Accept connection invitation
let { connectionRecord: aliceFaberConnection } = await aliceAgent.oob.acceptInvitation(
aliceFaberOutOfBandRecord.id,
Expand All @@ -406,16 +409,8 @@ describe('out of band', () => {
expect(faberAliceConnection).toBeConnectedWith(aliceFaberConnection)
expect(aliceFaberConnection).toBeConnectedWith(faberAliceConnection)

// The credential should be processed when connection is made. It asynchronous so it can take a moment.
let credentials: CredentialExchangeRecord[] = []
while (credentials.length < 1) {
credentials = await aliceAgent.credentials.getAll()
await sleep(100)
}

expect(credentials).toHaveLength(1)
const [credential] = credentials
expect(credential.state).toBe(CredentialState.OfferReceived)
const aliceCredentialRecord = await aliceCredentialRecordPromise
expect(aliceCredentialRecord.state).toBe(CredentialState.OfferReceived)
})

test('do not create a new connection when no messages and handshake reuse succeeds', async () => {
Expand Down

0 comments on commit 587898f

Please sign in to comment.