Skip to content

Commit

Permalink
Use jsonld.clone for consistency and to prevent test data mutation.
Browse files Browse the repository at this point in the history
  • Loading branch information
aljones15 committed Nov 22, 2023
1 parent 7716ddc commit f996c69
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions test/10-verify.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ for(const [version, mockCredential] of versionedCredentials) {
let error;
try {
await vc.issue({
credential: mockCredential,
credential: jsonld.clone(mockCredential),
suite
});
} catch(e) {
Expand All @@ -155,7 +155,7 @@ for(const [version, mockCredential] of versionedCredentials) {
describe('vc.createPresentation()', () => {
it('should create an unsigned presentation', () => {
const presentation = vc.createPresentation({
verifiableCredential: mockCredential,
verifiableCredential: jsonld.clone(mockCredential),
id: 'test:ebc6f1c2',
holder: 'did:ex:holder123'
});
Expand All @@ -171,7 +171,7 @@ for(const [version, mockCredential] of versionedCredentials) {
describe('vc.signPresentation()', () => {
it('should create a signed VP', async () => {
const presentation = vc.createPresentation({
verifiableCredential: mockCredential,
verifiableCredential: jsonld.clone(mockCredential),
id: 'test:ebc6f1c2',
holder: 'did:ex:holder123'
});
Expand All @@ -196,7 +196,7 @@ for(const [version, mockCredential] of versionedCredentials) {
describe('verify API (credentials)', () => {
it('should verify a vc', async () => {
const verifiableCredential = await vc.issue({
credential: mockCredential,
credential: jsonld.clone(mockCredential),
suite,
documentLoader
});
Expand Down Expand Up @@ -239,7 +239,7 @@ for(const [version, mockCredential] of versionedCredentials) {
});

const verifiableCredential = await vc.issue({
credential: {...mockCredential},
credential: jsonld.clone(mockCredential),
suite: ecdsaSdSignSuite,
documentLoader
});
Expand All @@ -263,7 +263,7 @@ for(const [version, mockCredential] of versionedCredentials) {

it('should verify a vc with a positive status check', async () => {
const verifiableCredential = await vc.issue({
credential: mockCredential,
credential: jsonld.clone(mockCredential),
suite,
documentLoader
});
Expand Down Expand Up @@ -362,7 +362,7 @@ for(const [version, mockCredential] of versionedCredentials) {
it('should fail to verify a vc with a negative status check',
async () => {
const verifiableCredential = await vc.issue({
credential: mockCredential,
credential: jsonld.clone(mockCredential),
suite,
documentLoader
});
Expand Down Expand Up @@ -405,7 +405,7 @@ for(const [version, mockCredential] of versionedCredentials) {
});

const verifiableCredential = await vc.issue({
credential: {...mockCredential},
credential: jsonld.clone(mockCredential),
suite: ecdsaSdSignSuite,
documentLoader
});
Expand Down Expand Up @@ -732,8 +732,9 @@ async function _generatePresentation({
credentials.push(credential);
}

const {documentLoader: dlc, suite: vcSuite} = await _generateCredential(
mockCredential);
const {
documentLoader: dlc,
suite: vcSuite} = await _generateCredential(mockCredential);
testLoader.addLoader(dlc);

const presentation = vc.createPresentation(
Expand All @@ -753,8 +754,11 @@ async function _generatePresentation({
documentLoader: testLoader.documentLoader.bind(testLoader)
});

return {presentation: vp, suite: [vcSuite, vpSuite],
documentLoader: testLoader.documentLoader.bind(testLoader)};
return {
presentation: vp,
suite: [vcSuite, vpSuite],
documentLoader: testLoader.documentLoader.bind(testLoader)
};
}

async function _loadDid() {
Expand Down

0 comments on commit f996c69

Please sign in to comment.