Skip to content

Commit

Permalink
test(core): failing test cases for contract signature verification
Browse files Browse the repository at this point in the history
Signed-off-by: sanket shevkar <[email protected]>
  • Loading branch information
sanketshevkar authored and jeromesimeon committed Oct 28, 2021
1 parent e88b61d commit 554ee04
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
3 changes: 0 additions & 3 deletions packages/cicero-core/src/contractinstance.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,6 @@ class ContractInstance extends Instance {
*/
static async fromArchive(buffer, options) {
const instance = await InstanceLoader.fromArchive(ContractInstance, buffer, options);
if (instance.contractSignatures.length !== 0) {
instance.verifySignatures();
}
return instance;
}

Expand Down
19 changes: 17 additions & 2 deletions packages/cicero-core/test/contractinstance.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ chai.should();
chai.use(require('chai-things'));
chai.use(require('chai-as-promised'));


/* eslint-disable */

function sign(instanceHash, timestamp, p12File, passphrase){
Expand Down Expand Up @@ -109,7 +110,15 @@ describe('ContractInstance', () => {
instance.sign(p12File, 'password', timestamp, signatory);
const partySignature = instance.contractSignatures[1];
const { signatoryCert, signature } = partySignature;
instance.verify(signature, timestamp, signatoryCert).should.not.throw();
(() => instance.verify(signature, timestamp, signatoryCert)).should.not.throw();
});

it('should throw error for failed signature verification', async() => {
const buffer = fs.readFileSync('./test/data/signContract/latedeliveryandpenalty@0.17.0-a3d6e61ddfe056ec65e240053e1f13e4f95a3e7804027ca6bb5652d0d65ac8ba.slc');
const instance = await ContractInstance.fromArchive(buffer);
const partySignature = instance.contractSignatures[1];
const { signatoryCert, signature, timestamp } = partySignature;
return instance.verify(signature, timestamp, signatoryCert).should.be.rejectedWith('Contract signature is invalid!');
});
});

Expand All @@ -121,7 +130,13 @@ describe('ContractInstance', () => {
const signatory = 'party1';
const p12File = fs.readFileSync('./test/data/signContract/keystore.p12', { encoding: 'base64' });
instance.sign(p12File, 'password', timestamp, signatory);
return instance.verifySignatures().should.not.throw();
(() => instance.verifySignatures()).should.not.throw();
});

it('should throw error while verifying the contract signatures', async() => {
const buffer = fs.readFileSync('./test/data/signContract/latedeliveryandpenalty@0.17.0-a3d6e61ddfe056ec65e240053e1f13e4f95a3e7804027ca6bb5652d0d65ac8ba.slc');
const instance = await ContractInstance.fromArchive(buffer);
return instance.verifySignatures().should.be.rejectedWith('Contract signature is invalid!');
});
});

Expand Down
Binary file not shown.

0 comments on commit 554ee04

Please sign in to comment.