@@ -66,6 +66,14 @@ func getSignedPropWithCHIdAndArgs(chid, ccid, ccver string, ccargs [][]byte, t *
66
66
return & pb.SignedProposal {ProposalBytes : propBytes , Signature : signature }
67
67
}
68
68
69
+ func newMockTxSim () * mockccprovider.MockTxSim {
70
+ return & mockccprovider.MockTxSim {
71
+ GetTxSimulationResultsRv : & ledger.TxSimulationResults {
72
+ PubSimulationResults : & rwset.TxReadWriteSet {},
73
+ },
74
+ }
75
+ }
76
+
69
77
func TestEndorserNilProp (t * testing.T ) {
70
78
es := endorser .NewEndorserServer (pvtEmptyDistributor , & em.MockSupport {
71
79
GetApplicationConfigBoolRv : true ,
@@ -172,6 +180,7 @@ func TestEndorserSysCC(t *testing.T) {
172
180
m := & mock.Mock {}
173
181
m .On ("Sign" , mock .Anything ).Return ([]byte {1 , 2 , 3 , 4 , 5 }, nil )
174
182
m .On ("Serialize" ).Return ([]byte {1 , 1 , 1 }, nil )
183
+ m .On ("GetTxSimulator" , mock .Anything , mock .Anything ).Return (newMockTxSim (), nil )
175
184
support := & em.MockSupport {
176
185
Mock : m ,
177
186
GetApplicationConfigBoolRv : true ,
@@ -180,11 +189,6 @@ func TestEndorserSysCC(t *testing.T) {
180
189
IsSysCCRv : true ,
181
190
ChaincodeDefinitionRv : & ccprovider.ChaincodeData {Escc : "ESCC" },
182
191
ExecuteResp : & pb.Response {Status : 200 , Payload : utils .MarshalOrPanic (& pb.ProposalResponse {Response : & pb.Response {}})},
183
- GetTxSimulatorRv : & mockccprovider.MockTxSim {
184
- GetTxSimulationResultsRv : & ledger.TxSimulationResults {
185
- PubSimulationResults : & rwset.TxReadWriteSet {},
186
- },
187
- },
188
192
}
189
193
attachPluginEndorser (support )
190
194
es := endorser .NewEndorserServer (pvtEmptyDistributor , support )
@@ -448,6 +452,7 @@ func TestEndorserGoodPathWEvents(t *testing.T) {
448
452
m := & mock.Mock {}
449
453
m .On ("Sign" , mock .Anything ).Return ([]byte {1 , 2 , 3 , 4 , 5 }, nil )
450
454
m .On ("Serialize" ).Return ([]byte {1 , 1 , 1 }, nil )
455
+ m .On ("GetTxSimulator" , mock .Anything , mock .Anything ).Return (newMockTxSim (), nil )
451
456
support := & em.MockSupport {
452
457
Mock : m ,
453
458
GetApplicationConfigBoolRv : true ,
@@ -456,11 +461,6 @@ func TestEndorserGoodPathWEvents(t *testing.T) {
456
461
ChaincodeDefinitionRv : & ccprovider.ChaincodeData {Escc : "ESCC" },
457
462
ExecuteResp : & pb.Response {Status : 200 , Payload : utils .MarshalOrPanic (& pb.ProposalResponse {Response : & pb.Response {}})},
458
463
ExecuteEvent : & pb.ChaincodeEvent {},
459
- GetTxSimulatorRv : & mockccprovider.MockTxSim {
460
- GetTxSimulationResultsRv : & ledger.TxSimulationResults {
461
- PubSimulationResults : & rwset.TxReadWriteSet {},
462
- },
463
- },
464
464
}
465
465
attachPluginEndorser (support )
466
466
es := endorser .NewEndorserServer (pvtEmptyDistributor , support )
@@ -498,18 +498,14 @@ func TestEndorserGoodPath(t *testing.T) {
498
498
m := & mock.Mock {}
499
499
m .On ("Sign" , mock .Anything ).Return ([]byte {1 , 2 , 3 , 4 , 5 }, nil )
500
500
m .On ("Serialize" ).Return ([]byte {1 , 1 , 1 }, nil )
501
+ m .On ("GetTxSimulator" , mock .Anything , mock .Anything ).Return (newMockTxSim (), nil )
501
502
support := & em.MockSupport {
502
503
Mock : m ,
503
504
GetApplicationConfigBoolRv : true ,
504
505
GetApplicationConfigRv : & mc.MockApplication {CapabilitiesRv : & mc.MockApplicationCapabilities {}},
505
506
GetTransactionByIDErr : errors .New ("" ),
506
507
ChaincodeDefinitionRv : & ccprovider.ChaincodeData {Escc : "ESCC" },
507
508
ExecuteResp : & pb.Response {Status : 200 , Payload : utils .MarshalOrPanic (& pb.ProposalResponse {Response : & pb.Response {}})},
508
- GetTxSimulatorRv : & mockccprovider.MockTxSim {
509
- GetTxSimulationResultsRv : & ledger.TxSimulationResults {
510
- PubSimulationResults : & rwset.TxReadWriteSet {},
511
- },
512
- },
513
509
}
514
510
attachPluginEndorser (support )
515
511
es := endorser .NewEndorserServer (pvtEmptyDistributor , support )
@@ -525,18 +521,14 @@ func TestEndorserLSCC(t *testing.T) {
525
521
m := & mock.Mock {}
526
522
m .On ("Sign" , mock .Anything ).Return ([]byte {1 , 2 , 3 , 4 , 5 }, nil )
527
523
m .On ("Serialize" ).Return ([]byte {1 , 1 , 1 }, nil )
524
+ m .On ("GetTxSimulator" , mock .Anything , mock .Anything ).Return (newMockTxSim (), nil )
528
525
support := & em.MockSupport {
529
526
Mock : m ,
530
527
GetApplicationConfigBoolRv : true ,
531
528
GetApplicationConfigRv : & mc.MockApplication {CapabilitiesRv : & mc.MockApplicationCapabilities {}},
532
529
GetTransactionByIDErr : errors .New ("" ),
533
530
ChaincodeDefinitionRv : & ccprovider.ChaincodeData {Escc : "ESCC" },
534
531
ExecuteResp : & pb.Response {Status : 200 , Payload : utils .MarshalOrPanic (& pb.ProposalResponse {Response : & pb.Response {}})},
535
- GetTxSimulatorRv : & mockccprovider.MockTxSim {
536
- GetTxSimulationResultsRv : & ledger.TxSimulationResults {
537
- PubSimulationResults : & rwset.TxReadWriteSet {},
538
- },
539
- },
540
532
}
541
533
attachPluginEndorser (support )
542
534
es := endorser .NewEndorserServer (pvtEmptyDistributor , support )
@@ -576,18 +568,14 @@ func TestEndorseWithPlugin(t *testing.T) {
576
568
m := & mock.Mock {}
577
569
m .On ("Sign" , mock .Anything ).Return ([]byte {1 , 2 , 3 , 4 , 5 }, nil )
578
570
m .On ("Serialize" ).Return ([]byte {1 , 1 , 1 }, nil )
571
+ m .On ("GetTxSimulator" , mock .Anything , mock .Anything ).Return (newMockTxSim (), nil )
579
572
support := & em.MockSupport {
580
573
Mock : m ,
581
574
GetApplicationConfigBoolRv : true ,
582
575
GetApplicationConfigRv : & mc.MockApplication {CapabilitiesRv : & mc.MockApplicationCapabilities {}},
583
576
GetTransactionByIDErr : errors .New ("can't find this transaction in the index" ),
584
577
ChaincodeDefinitionRv : & resourceconfig.MockChaincodeDefinition {EndorsementStr : "ESCC" },
585
578
ExecuteResp : & pb.Response {Status : 200 , Payload : []byte {1 }},
586
- GetTxSimulatorRv : & mockccprovider.MockTxSim {
587
- GetTxSimulationResultsRv : & ledger.TxSimulationResults {
588
- PubSimulationResults : & rwset.TxReadWriteSet {},
589
- },
590
- },
591
579
}
592
580
attachPluginEndorser (support )
593
581
@@ -648,6 +636,55 @@ func TestEndorserJavaChecks(t *testing.T) {
648
636
assert .Error (t , err )
649
637
}
650
638
639
+ func TestEndorserAcquireTxSimulator (t * testing.T ) {
640
+ tc := []struct {
641
+ name string
642
+ chainID string
643
+ chaincodeName string
644
+ simAcquired bool
645
+ }{
646
+ {"empty channel" , "" , "ignored" , false },
647
+ {"query scc" , util .GetTestChainID (), "qscc" , false },
648
+ {"config scc" , util .GetTestChainID (), "cscc" , false },
649
+ {"mainline" , util .GetTestChainID (), "chaincode" , true },
650
+ }
651
+
652
+ expectedResponse := & pb.Response {Status : 200 , Payload : utils .MarshalOrPanic (& pb.ProposalResponse {Response : & pb.Response {}})}
653
+ for _ , tt := range tc {
654
+ tt := tt
655
+ t .Run (tt .name , func (t * testing.T ) {
656
+ m := & mock.Mock {}
657
+ m .On ("Sign" , mock .Anything ).Return ([]byte {1 , 2 , 3 , 4 , 5 }, nil )
658
+ m .On ("Serialize" ).Return ([]byte {1 , 1 , 1 }, nil )
659
+ m .On ("GetTxSimulator" , mock .Anything , mock .Anything ).Return (newMockTxSim (), nil )
660
+ support := & em.MockSupport {
661
+ Mock : m ,
662
+ GetApplicationConfigBoolRv : true ,
663
+ GetApplicationConfigRv : & mc.MockApplication {CapabilitiesRv : & mc.MockApplicationCapabilities {}},
664
+ GetTransactionByIDErr : errors .New ("" ),
665
+ ChaincodeDefinitionRv : & ccprovider.ChaincodeData {Escc : "ESCC" },
666
+ ExecuteResp : expectedResponse ,
667
+ }
668
+ attachPluginEndorser (support )
669
+ es := endorser .NewEndorserServer (pvtEmptyDistributor , support )
670
+
671
+ t .Parallel ()
672
+ args := [][]byte {[]byte ("args" )}
673
+ signedProp := getSignedPropWithCHIdAndArgs (tt .chainID , tt .chaincodeName , "version" , args , t )
674
+
675
+ resp , err := es .ProcessProposal (context .Background (), signedProp )
676
+ assert .NoError (t , err )
677
+ assert .Equal (t , expectedResponse , resp .Response )
678
+
679
+ if tt .simAcquired {
680
+ m .AssertCalled (t , "GetTxSimulator" , mock .Anything , mock .Anything )
681
+ } else {
682
+ m .AssertNotCalled (t , "GetTxSimulator" , mock .Anything , mock .Anything )
683
+ }
684
+ })
685
+ }
686
+ }
687
+
651
688
var signer msp.SigningIdentity
652
689
653
690
func TestMain (m * testing.M ) {
0 commit comments