From f996c6928408953ab5b488b15e8aa7da65ee1181 Mon Sep 17 00:00:00 2001 From: Andrew Jones Date: Wed, 22 Nov 2023 20:37:31 +0000 Subject: [PATCH] Use jsonld.clone for consistency and to prevent test data mutation. --- test/10-verify.spec.js | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/test/10-verify.spec.js b/test/10-verify.spec.js index 667cf8a7..70d43d86 100644 --- a/test/10-verify.spec.js +++ b/test/10-verify.spec.js @@ -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) { @@ -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' }); @@ -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' }); @@ -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 }); @@ -239,7 +239,7 @@ for(const [version, mockCredential] of versionedCredentials) { }); const verifiableCredential = await vc.issue({ - credential: {...mockCredential}, + credential: jsonld.clone(mockCredential), suite: ecdsaSdSignSuite, documentLoader }); @@ -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 }); @@ -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 }); @@ -405,7 +405,7 @@ for(const [version, mockCredential] of versionedCredentials) { }); const verifiableCredential = await vc.issue({ - credential: {...mockCredential}, + credential: jsonld.clone(mockCredential), suite: ecdsaSdSignSuite, documentLoader }); @@ -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( @@ -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() {