@@ -287,8 +287,8 @@ function instantiateChaincodeWithId(userOrg, chaincode_id, chaincode_path, versi
287287 let success = false ;
288288 if ( proposalResponses && proposalResponses . length > 0 ) {
289289 proposalResponses . forEach ( ( response ) => {
290- if ( response &&
291- response . response . message . indexOf ( 'Did not find expected key "test" in the transient map of the proposal' ) ) {
290+ if ( response && response instanceof Error &&
291+ response . message . includes ( 'Did not find expected key "test" in the transient map of the proposal' ) ) {
292292 success = true ;
293293 } else {
294294 success = false ;
@@ -577,28 +577,38 @@ function invokeChaincode(userOrg, version, chaincodeId, t, useStore, fcn, args,
577577 for ( let i in proposalResponses ) {
578578 let one_good = false ;
579579 let proposal_response = proposalResponses [ i ] ;
580- logger . debug ( 'invoke chaincode, proposal response: ' + util . inspect ( proposal_response , { depth : null } ) ) ;
581- if ( proposal_response . response && proposal_response . response . status === 200 ) {
582- t . pass ( 'transaction proposal has response status of good' ) ;
583- one_good = channel . verifyProposalResponse ( proposal_response ) ;
584- if ( one_good ) {
585- t . pass ( 'transaction proposal signature and endorser are valid' ) ;
586- }
587580
588- // check payload
589- let payload = proposal_response . response . payload . toString ( ) ;
590- // verify payload is equal to expectedResult
591- if ( payload === expectedResult ) {
592- t . pass ( 'transaction proposal payloads are valid' ) ;
581+ if ( expectedResult instanceof Error ) {
582+ t . true ( ( proposal_response instanceof Error ) , 'proposal response should be an instance of error' ) ;
583+ t . true ( proposal_response . message . includes ( expectedResult . message ) , 'error should contain the correct message: ' + expectedResult . message ) ;
584+ } else {
585+ logger . debug ( 'invoke chaincode, proposal response: ' + util . inspect ( proposal_response , { depth : null } ) ) ;
586+ if ( proposal_response . response && proposal_response . response . status === 200 ) {
587+ t . pass ( 'transaction proposal has response status of good' ) ;
588+ one_good = channel . verifyProposalResponse ( proposal_response ) ;
589+ if ( one_good ) {
590+ t . pass ( 'transaction proposal signature and endorser are valid' ) ;
591+ }
592+
593+ // check payload
594+ let payload = proposal_response . response . payload . toString ( ) ;
595+ // verify payload is equal to expectedResult
596+ if ( payload === expectedResult ) {
597+ t . pass ( 'transaction proposal payloads are valid' ) ;
598+ } else {
599+ one_good = false ;
600+ t . fail ( 'transaction proposal payloads are invalid, expect ' + expectedResult + ', but got ' + payload ) ;
601+ }
593602 } else {
594- one_good = false ;
595- t . fail ( 'transaction proposal payloads are invalid, expect ' + expectedResult + ', but got ' + payload ) ;
603+ t . fail ( 'invokeChaincode: transaction proposal was bad' ) ;
596604 }
597- } else {
598- t . fail ( 'invokeChaincode: transaction proposal was bad' ) ;
605+ all_good = all_good & one_good ;
599606 }
600- all_good = all_good & one_good ;
601607 }
608+ if ( expectedResult instanceof Error ) {
609+ return ;
610+ }
611+
602612 if ( all_good ) {
603613 // check all the read/write sets to see if the same, verify that each peer
604614 // got the same results on the proposal
@@ -679,6 +689,11 @@ function invokeChaincode(userOrg, version, chaincodeId, t, useStore, fcn, args,
679689 throw new Error ( 'Failed to send proposal due to error: ' + err . stack ? err . stack : err ) ;
680690
681691 } ) . then ( ( response ) => {
692+ if ( expectedResult instanceof Error ) {
693+ channel . close ( ) ;
694+ t . pass ( 'Successfully closed all connections' ) ;
695+ return true ;
696+ }
682697
683698 if ( response . status === 'SUCCESS' ) {
684699 t . pass ( 'Successfully sent transaction to the orderer.' ) ;
0 commit comments