From 622ffba094227b2b4c89d0fcc7822c932cc6f192 Mon Sep 17 00:00:00 2001 From: sanket shevkar Date: Tue, 17 Aug 2021 21:29:31 +0530 Subject: [PATCH] test(cli): test for signing contract Signed-off-by: sanket shevkar --- packages/cicero-cli/index.js | 20 +++---- packages/cicero-cli/lib/commands.js | 17 +++--- packages/cicero-cli/test/cli.js | 50 ++++++------------ .../test/data/contractsigning/keystore.p12 | Bin 0 -> 2635 bytes ...30af3b5a75bee1ab788a15736e603b88a6312c.slc | Bin 0 -> 14795 bytes 5 files changed, 39 insertions(+), 48 deletions(-) create mode 100644 packages/cicero-cli/test/data/contractsigning/keystore.p12 create mode 100644 packages/cicero-cli/test/data/contractsigning/latedeliveryandpenalty@0.17.0-d0c1a14e8a7af52e0927a23b8b30af3b5a75bee1ab788a15736e603b88a6312c.slc diff --git a/packages/cicero-cli/index.js b/packages/cicero-cli/index.js index ae86d7d9a..6361b242a 100755 --- a/packages/cicero-cli/index.js +++ b/packages/cicero-cli/index.js @@ -609,6 +609,9 @@ require('yargs') default: false }); }, (argv) => { + if (argv.verbose) { + Logger.info(`verifying signatures of contract ${argv.contract}`); + } try { argv = Commands.validateVerifyArgs(argv); @@ -631,15 +634,6 @@ require('yargs') describe: 'path to a smart legal contract slc file', type: 'string' }); - yargs.option('template', { - describe: 'path to a template', - type: 'string' - }); - yargs.option('warnings', { - describe: 'print warnings', - type: 'boolean', - default: false - }); yargs.option('keystore', { describe: 'p12 keystore path', type: 'string', @@ -660,7 +654,15 @@ require('yargs') type: 'string', default: null }); + yargs.option('warnings', { + describe: 'print warnings', + type: 'boolean', + default: false + }); }, (argv) => { + if (argv.verbose) { + Logger.info(`sign contract ${argv.contract} for signatory ${argv.signatory}`); + } try { argv = Commands.validateSignArgs(argv); diff --git a/packages/cicero-cli/lib/commands.js b/packages/cicero-cli/lib/commands.js index ce2f531b9..fff29032b 100644 --- a/packages/cicero-cli/lib/commands.js +++ b/packages/cicero-cli/lib/commands.js @@ -655,13 +655,18 @@ class Commands { */ static validateSignArgs(argv) { argv = Commands.validateCommonArgs(argv); - if (argv.template) { - argv = Commands.validateDataArgs(argv); - } - if(!argv.target){ - Logger.info('Using ergo as the default target for the archive.'); - argv.target = 'ergo'; + if (!argv.keystore) { + throw new Error('please define path of the keystore using --keystore'); + } + if (!argv.passphrase) { + throw new Error('please define the passphrase of the keystore using --pasphrase'); + } + if (!argv.signatory) { + throw new Error('please define the signatory signing the contract using --signatory'); + } + if(argv.verbose) { + Logger.info(`verifying signatures of contract ${argv.contract}`); } return argv; diff --git a/packages/cicero-cli/test/cli.js b/packages/cicero-cli/test/cli.js index 9f0a1cfd6..6566c3d9b 100644 --- a/packages/cicero-cli/test/cli.js +++ b/packages/cicero-cli/test/cli.js @@ -28,6 +28,7 @@ chai.use(require('chai-things')); chai.use(require('chai-as-promised')); const Commands = require('../lib/commands'); +const { ContractInstance } = require('@accordproject/cicero-core'); const template = path.resolve(__dirname, 'data/latedeliveryandpenalty/'); const templateJs = path.resolve(__dirname, 'data/latedeliveryandpenalty_js/'); @@ -1308,37 +1309,16 @@ describe('#archive', async () => { }); describe('#validateSignArgs', () => { - it('no args specified', () => { - process.chdir(path.resolve(__dirname, 'data/signContract/')); + it('all args specified', () => { + process.chdir(path.resolve(__dirname, 'data/contractsigning/')); const args = Commands.validateSignArgs({ + contract: 'latedeliveryandpenalty@0.17.0-d0c1a14e8a7af52e0927a23b8b30af3b5a75bee1ab788a15736e603b88a6312c.slc', + keystore: 'keystore.p12', + passphrase: 'password', + signatory: 'partyA', _: ['sign'] }); - args.template.should.match(/cicero-cli[/\\]test[/\\]data[/\\]signContract$/); - args.target.should.match(/ergo/); - }); - it('only target arg specified', () => { - process.chdir(path.resolve(__dirname, 'data/signContract/')); - const args = Commands.validateSignArgs({ - _: ['sign'], - target: 'ergo' - }); - args.template.should.match(/cicero-cli[/\\]test[/\\]data[/\\]signContract$/); - args.target.should.match(/ergo/); - }); - it('template arg specified', () => { - process.chdir(path.resolve(__dirname)); - const args = Commands.validateSignArgs({ - _: ['sign', 'data/signContract/'] - }); - args.template.should.match(/cicero-cli[/\\]test[/\\]data[/\\]signContract$/); - args.target.should.match(/ergo/); - }); - it('verbose flag specified', () => { - process.chdir(path.resolve(__dirname, 'data/signContract/')); - Commands.validateSignArgs({ - _: ['sign'], - verbose: true - }); + args.contract.should.match(/.slc$/); }); it('bad package.json', () => { process.chdir(path.resolve(__dirname, 'data/')); @@ -1350,12 +1330,16 @@ describe('#validateSignArgs', () => { describe('#sign', async () => { it('should sign the contract for a party/individual', async () => { - const slcPath = path.resolve(__dirname, 'data/signContract/latedeliveryandpenalty@0.17.0-d0c1a14e8a7af52e0927a23b8b30af3b5a75bee1ab788a15736e603b88a6312c.slc'); - const keystore = path.resolve(__dirname, 'data/keystore.p12'); + const archiveName = 'test.slc'; + const slcPath = path.resolve(__dirname, 'data/contractsigning/latedeliveryandpenalty@0.17.0-d0c1a14e8a7af52e0927a23b8b30af3b5a75bee1ab788a15736e603b88a6312c.slc'); + const keystore = path.resolve(__dirname, 'data/contractsigning/keystore.p12'); const signatory = 'partyA'; - const outputPath = path.resolve(__dirname, 'data/'); - const result = await Commands.sign(slcPath, keystore, 'password', signatory, outputPath); - result.should.be.true; + const result = await Commands.sign(slcPath, keystore, 'password', signatory, archiveName); + result.should.eql(true); + const newInstance = await ContractInstance.fromArchive(fs.readFileSync(archiveName)); + newInstance.should.not.be.null; + newInstance.contractSignatures.should.have.lengthOf(1); + fs.unlinkSync(archiveName); }); }); diff --git a/packages/cicero-cli/test/data/contractsigning/keystore.p12 b/packages/cicero-cli/test/data/contractsigning/keystore.p12 new file mode 100644 index 0000000000000000000000000000000000000000..893134f14c1065ac701cb85e336fc4c6a00171cd GIT binary patch literal 2635 zcmcguYdDna8lG>yZ^j%9#wmxKnoyDXW^yW{ka9@Wj1mN?YWZ#Knmbf|^ z`>NdZB^V_^>R3m-%RNF)Hj|2znwPzX4Hq6o{Q!5t8&fM*?LhJ*#Pj6%cx zD0mpVz@in9I~W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mE-p;M-Wh%;(ed0*o7dE`ATpvG|;i>tfVXyU3*d@2&X1BR?*tY)jskqVW zFS1;VPbLoD+J1Vh(=*74CsWPu>%Y_P)~y`vtOU<9HbkXQ%*=jh?7dI+9kPEn*7>q6 zyoQxYH!kk_T-n2pKG*eNCNI!1Wl(&A7(Ul}q6Z_s#fP`*nOuf%tWM8%s;S4IMeA@f zszv4Rgz9az514UFa>u?Nb{ih4)i))(RQ;rvYslZF{XSunZVmUA6cJ4s#H#h4`jhx$BvJj@2m?hyjEsPedM$Jl)n?U)!+ite^`M-)r zi`gMKU0I67BiBn$m)zz*%Q5OnJwvG9x#g+hog&TGrUGo5aCv5T|EkUNr{-t7yb@J} zerE3e^Ow0AXR4Q)&7_}&jRs~5?v;JM@tX0afpXeCZMxdWpC88Wt)kj7NEp3WzR@Q9 zg3TSZX6&`uOD^cwD75$ooXqY^xq&1cZ>xA6r|pHmn%4Y4pdZKxxWQO)XSlk2ib@Ug ztNyMRjM@CP^W+}u+Ej3TM&(ERs7jep>qjrEj^{Ravd*d z`S7SHEjk}`+;x6Dgm)n`#+h8i7ibUfKFnh2ZpnUEG_Jk2pyrNS_w=WnM^ej3FFXhC zxwdC%roOTCyz87viNAhgGQhQNRDEk#$VljwnhRcv4W9((=6-yG0#>$}`V_`>S%|{! zsX)`CJiO1q-DMLu9LZDg%xbj=!ZYaxs?`z0N0V2;|J8XZu#V)%3uPb!BGpg`NO50t i0X{UAXnrp>PRi2V;=O;o9}~i`!hY~I?!@LTnCYL~V>omG literal 0 HcmV?d00001 diff --git a/packages/cicero-cli/test/data/contractsigning/latedeliveryandpenalty@0.17.0-d0c1a14e8a7af52e0927a23b8b30af3b5a75bee1ab788a15736e603b88a6312c.slc b/packages/cicero-cli/test/data/contractsigning/latedeliveryandpenalty@0.17.0-d0c1a14e8a7af52e0927a23b8b30af3b5a75bee1ab788a15736e603b88a6312c.slc new file mode 100644 index 0000000000000000000000000000000000000000..b9c3776ca16effd30aa25aaa02a98d818ca890a2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