Skip to content

Commit

Permalink
Add test for VPs with mixed context VCs.
Browse files Browse the repository at this point in the history
  • Loading branch information
aljones15 committed Apr 26, 2024
1 parent cf61f1e commit 67ac8a9
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
28 changes: 28 additions & 0 deletions test/10-verify.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -765,6 +765,34 @@ for(const [version, mockCredential] of versionedCredentials) {
credential.credentialId.should.be.a('string');
}
});
it.only('should not cause error when credentials have mixed contexts',
async () => {
const challenge = uuid();
const {presentation, suite: vcSuite, documentLoader} =
await _generatePresentation({
challenge,
credentialsCount: count,
mockCredential: mockData.credentials.mixed,
version
});
const result = await vc.verify({
documentLoader,
presentation,
suite: vcSuite,
unsignedPresentation: true
});
const credentialResults = result.credentialResults;

result.verified.should.be.a('boolean');
result.verified.should.be.true;

for(const credential of credentialResults) {
credential.verified.should.be.a('boolean');
credential.verified.should.be.true;
should.exist(credential.credentialId);
credential.credentialId.should.be.a('string');
}
});
}
});

Expand Down
22 changes: 22 additions & 0 deletions test/mocks/mock.data.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* eslint-disable quotes, quote-props, max-len */
import constants from '../constants.js';
import {versionedCredentials} from './credential.js';

export const mock = {};

Expand All @@ -8,7 +9,28 @@ const didContexts = [
constants.VERES_ONE_CONTEXT_URL
];

/**
* @private
* stores an initial count used to toggle between VC versions.
*
*
* @returns {Function} - A VC generator function.
*/
const _mixedCredential = () => {
let count = 0;
// return a generator function.
return () => {
if((count % 2) === 0) {
count++;
return versionedCredentials.get(1.0)();
}
count ++;
return versionedCredentials.get(2.0)();
};
};

const credentials = mock.credentials = {};
credentials.mixed = _mixedCredential();

credentials.alpha = {
"@context": [
Expand Down

0 comments on commit 67ac8a9

Please sign in to comment.