Skip to content

Commit

Permalink
specific tests
Browse files Browse the repository at this point in the history
Signed-off-by: annelein <[email protected]>
  • Loading branch information
Annelein committed Feb 28, 2022
1 parent 7422ae3 commit 784cc9b
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 211 deletions.
40 changes: 0 additions & 40 deletions packages/core/src/modules/proofs/__tests__/ProofService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,11 @@ import { ProofRecord } from '../repository/ProofRecord'
import { ProofRepository } from '../repository/ProofRepository'
import { ProofService } from '../services'

import { checkProofRequestForDuplicates } from './../../../utils'
import { IndyVerifierService } from './../../indy/services/IndyVerifierService'
import { PresentationProblemReportMessage } from './../messages/PresentationProblemReportMessage'
import { RequestPresentationMessage } from './../messages/RequestPresentationMessage'
import { credDef } from './fixtures'

import { AriesFrameworkError, AttributeFilter, ProofAttributeInfo, ProofRequest } from '@aries-framework/core'

// Mock classes
jest.mock('../repository/ProofRepository')
jest.mock('../../../modules/ledger/services/IndyLedgerService')
Expand Down Expand Up @@ -264,42 +261,5 @@ describe('ProofService', () => {
expect(updatedCredentialRecord).toMatchObject(expectedCredentialRecord)
expect(returnedCredentialRecord).toMatchObject(expectedCredentialRecord)
})

test('attribute names match, same cred def filter', async () => {
const attributes = {
name: new ProofAttributeInfo({
name: 'age',
restrictions: [
new AttributeFilter({
credentialDefinitionId: credDef.id,
}),
],
}),
age: new ProofAttributeInfo({
name: 'age',
restrictions: [
new AttributeFilter({
credentialDefinitionId: credDef.id,
}),
],
}),
}

const proofRequestOptions = {
name: 'test-proof-request',
requestedAttributes: attributes,
}

const nonce = 'testtesttest12345'

const proofRequest = new ProofRequest({
name: 'proof-request',
version: '1.0',
nonce,
requestedAttributes: proofRequestOptions.requestedAttributes,
})

expect(() => checkProofRequestForDuplicates(proofRequest)).toThrowError(AriesFrameworkError)
})
})
})
2 changes: 2 additions & 0 deletions packages/core/src/utils/indyProofRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,7 @@ export function predicatesToArray(proofRequest: ProofRequest) {
export function checkProofRequestForDuplicates(proofRequest: ProofRequest) {
const attributes = attributesToArray(proofRequest)
const predicates = predicatesToArray(proofRequest)
assertNoDuplicatesInArray(attributes)
assertNoDuplicatesInArray(predicates)
assertNoDuplicatesInArray(attributes.concat(predicates))
}
205 changes: 34 additions & 171 deletions packages/core/tests/proofs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ describe('Present Proof', () => {
requestedAttributes: attributes,
}

const nonce = 'testtesttest123456'
const nonce = 'testtesttest12345'

const proofRequest = new ProofRequest({
name: 'proof-request',
Expand All @@ -411,7 +411,7 @@ describe('Present Proof', () => {
expect(() => checkProofRequestForDuplicates(proofRequest)).toThrowError(AriesFrameworkError)
})

test('attribute name matches with predicate name, same cred def filter', async () => {
test('attribute names match with predicates name, same cred def filter', async () => {
const attributes = {
name: new ProofAttributeInfo({
name: 'age',
Expand All @@ -436,81 +436,23 @@ describe('Present Proof', () => {
}),
}

await expect(
faberAgent.proofs.requestProof(faberConnection.id, {
name: 'test-proof-request',
requestedAttributes: attributes,
requestedPredicates: predicates,
})
).rejects.toThrowError(`The proof request contains duplicate items: age`)
})
const nonce = 'testtesttest12345'

test('attribute names match, different cred def filter', async () => {
const attributes = {
age: new ProofAttributeInfo({
name: 'age',
restrictions: [
new AttributeFilter({
credentialDefinitionId: credDefId,
}),
],
}),
name: new ProofAttributeInfo({
name: 'age',
restrictions: [
new AttributeFilter({
credentialDefinitionId: secCredDefId,
}),
],
}),
}

await expect(
faberAgent.proofs.requestProof(faberConnection.id, {
name: 'test-proof-request',
requestedAttributes: attributes,
})
).rejects.toThrowError(`The proof request contains duplicate items: age`)
})

test('attribute name matches with predicate name, different cred def filter', async () => {
const attributes = {
age: new ProofAttributeInfo({
name: 'age',
restrictions: [
new AttributeFilter({
credentialDefinitionId: credDefId,
}),
],
}),
}

const predicates = {
name: new ProofPredicateInfo({
name: 'age',
predicateType: PredicateType.GreaterThanOrEqualTo,
predicateValue: 50,
restrictions: [
new AttributeFilter({
credentialDefinitionId: secCredDefId,
}),
],
}),
}
const proofRequest = new ProofRequest({
name: 'proof-request',
version: '1.0',
nonce,
requestedAttributes: attributes,
requestedPredicates: predicates,
})

await expect(
faberAgent.proofs.requestProof(faberConnection.id, {
name: 'test-proof-request',
requestedAttributes: attributes,
requestedPredicates: predicates,
})
).rejects.toThrowError(`The proof request contains duplicate items: age`)
expect(() => checkProofRequestForDuplicates(proofRequest)).toThrowError(AriesFrameworkError)
})

test('correctly formatted attribute and predicate, different cred def filter', async () => {
test('attribute names match, different cred def filter', async () => {
const attributes = {
name: new ProofAttributeInfo({
name: 'name',
name: 'age',
restrictions: [
new AttributeFilter({
credentialDefinitionId: credDefId,
Expand All @@ -532,65 +474,28 @@ describe('Present Proof', () => {
}),
}

const faberProofRecord = await faberAgent.proofs.requestProof(faberConnection.id, {
const proofRequestOptions = {
name: 'test-proof-request',
requestedAttributes: attributes,
requestedPredicates: predicates,
})

const aliceProofRecord = await waitForProofRecord(aliceAgent, {
threadId: faberProofRecord.threadId,
state: ProofState.RequestReceived,
})

const retrievedCredentials = await aliceAgent.proofs.getRequestedCredentialsForProofRequest(aliceProofRecord.id, {
filterByPresentationPreview: true,
})
const requestedCredentials = aliceAgent.proofs.autoSelectCredentialsForProofRequest(retrievedCredentials)
await expect(aliceAgent.proofs.acceptRequest(aliceProofRecord.id, requestedCredentials)).resolves
})

test('correctly formatted attribute, different cred def filter', async () => {
const attributes = {
name: new ProofAttributeInfo({
name: 'name',
restrictions: [
new AttributeFilter({
credentialDefinitionId: credDefId,
}),
],
}),
age: new ProofAttributeInfo({
name: 'age',
restrictions: [
new AttributeFilter({
credentialDefinitionId: secCredDefId,
}),
],
}),
predicates: predicates,
}

const faberProofRecord = await faberAgent.proofs.requestProof(faberConnection.id, {
name: 'test-proof-request',
requestedAttributes: attributes,
})
const nonce = 'testtesttest12345'

const aliceProofRecord = await waitForProofRecord(aliceAgent, {
threadId: faberProofRecord.threadId,
state: ProofState.RequestReceived,
const proofRequest = new ProofRequest({
name: 'proof-request',
version: '1.0',
nonce,
requestedAttributes: proofRequestOptions.requestedAttributes,
})

const retrievedCredentials = await aliceAgent.proofs.getRequestedCredentialsForProofRequest(aliceProofRecord.id, {
filterByPresentationPreview: true,
})
const requestedCredentials = aliceAgent.proofs.autoSelectCredentialsForProofRequest(retrievedCredentials)
await expect(aliceAgent.proofs.acceptRequest(aliceProofRecord.id, requestedCredentials)).resolves
expect(() => checkProofRequestForDuplicates(proofRequest)).resolves
})

test('correctly formatted attribute and predicate, same cred def filter', async () => {
test('attribute name matches with predicate name, different cred def filter', async () => {
const attributes = {
age: new ProofAttributeInfo({
name: 'name',
name: new ProofAttributeInfo({
name: 'age',
restrictions: [
new AttributeFilter({
credentialDefinitionId: credDefId,
Expand All @@ -600,70 +505,28 @@ describe('Present Proof', () => {
}

const predicates = {
name: new ProofPredicateInfo({
age: new ProofPredicateInfo({
name: 'age',
predicateType: PredicateType.GreaterThanOrEqualTo,
predicateValue: 50,
restrictions: [
new AttributeFilter({
credentialDefinitionId: credDefId,
credentialDefinitionId: secCredDefId,
}),
],
}),
}

const faberProofRecord = await faberAgent.proofs.requestProof(faberConnection.id, {
name: 'test-proof-request',
requestedAttributes: attributes,
requestedPredicates: predicates,
})

const aliceProofRecord = await waitForProofRecord(aliceAgent, {
threadId: faberProofRecord.threadId,
state: ProofState.RequestReceived,
})

const retrievedCredentials = await aliceAgent.proofs.getRequestedCredentialsForProofRequest(aliceProofRecord.id, {
filterByPresentationPreview: true,
})
const requestedCredentials = aliceAgent.proofs.autoSelectCredentialsForProofRequest(retrievedCredentials)
await expect(aliceAgent.proofs.acceptRequest(aliceProofRecord.id, requestedCredentials)).resolves
})

test('correctly formatted attribute, same cred def filter', async () => {
const attributes = {
name: new ProofAttributeInfo({
name: 'name',
restrictions: [
new AttributeFilter({
credentialDefinitionId: credDefId,
}),
],
}),
age: new ProofAttributeInfo({
name: 'age',
restrictions: [
new AttributeFilter({
credentialDefinitionId: credDefId,
}),
],
}),
}
const nonce = 'testtesttest12345'

const faberProofRecord = await faberAgent.proofs.requestProof(faberConnection.id, {
name: 'test-proof-request',
const proofRequest = new ProofRequest({
name: 'proof-request',
version: '1.0',
nonce,
requestedAttributes: attributes,
requestedPredicates: predicates,
})

const aliceProofRecord = await waitForProofRecord(aliceAgent, {
threadId: faberProofRecord.threadId,
state: ProofState.RequestReceived,
})

const retrievedCredentials = await aliceAgent.proofs.getRequestedCredentialsForProofRequest(aliceProofRecord.id, {
filterByPresentationPreview: true,
})
const requestedCredentials = aliceAgent.proofs.autoSelectCredentialsForProofRequest(retrievedCredentials)
await expect(aliceAgent.proofs.acceptRequest(aliceProofRecord.id, requestedCredentials)).resolves
expect(() => checkProofRequestForDuplicates(proofRequest)).resolves
})
})

0 comments on commit 784cc9b

Please sign in to comment.