@@ -523,84 +523,137 @@ var _ bool = Describe("PrivateData", func() {
523
523
})
524
524
525
525
Describe ("Collection Config Endorsement Policy" , func () {
526
- BeforeEach (func () {
527
- testChaincode = chaincode {
528
- Chaincode : newLifecycleChaincode ,
529
- isLegacy : false ,
530
- }
531
- nwo .EnableCapabilities (network , "testchannel" , "Application" , "V2_0" , orderer , network .Peers ... )
532
- })
533
-
534
- When ("a peer specified in the chaincode endorsement policy but not in the collection config endorsement policy is used to invoke the chaincode" , func () {
535
- It ("fails validation" , func () {
526
+ When ("using legacy lifecycle chaincode" , func () {
527
+ It ("ignores the collection config endorsement policy and successfully invokes the chaincode" , func () {
528
+ testChaincode = chaincode {
529
+ Chaincode : legacyChaincode ,
530
+ isLegacy : true ,
531
+ }
536
532
By ("setting the collection config endorsement policy to org2 or org3 peers" )
537
533
testChaincode .CollectionsConfig = collectionConfig ("collections_config4.json" )
538
534
539
- By ("deploying new lifecycle chaincode" )
540
- // set collection endorsement policy to org2 or org3
535
+ By ("deploying legacy chaincode" )
541
536
deployChaincode (network , orderer , testChaincode )
542
537
543
- By ("adding marble1 with an org1 peer as endorser" )
538
+ By ("adding marble1 with an org 1 peer as endorser" )
544
539
peer := network .Peer ("Org1" , "peer0" )
545
540
marbleDetails := `{"name":"marble1", "color":"blue", "size":35, "owner":"tom", "price":99}`
546
- marbleDetailsBase64 := base64 .StdEncoding .EncodeToString ([]byte (marbleDetails ))
547
-
548
- command := commands.ChaincodeInvoke {
549
- ChannelID : channelID ,
550
- Orderer : network .OrdererAddress (orderer , nwo .ListenPort ),
551
- Name : testChaincode .Name ,
552
- Ctor : fmt .Sprintf (`{"Args":["initMarble"]}` ),
553
- Transient : fmt .Sprintf (`{"marble":"%s"}` , marbleDetailsBase64 ),
554
- PeerAddresses : []string {
555
- network .PeerAddress (peer , nwo .ListenPort ),
556
- },
557
- WaitForEvent : true ,
558
- }
559
-
560
- sess , err := network .PeerUserSession (peer , "User1" , command )
561
- Expect (err ).NotTo (HaveOccurred ())
562
- Eventually (sess , network .EventuallyTimeout ).Should (gexec .Exit ())
563
- Expect (sess .Err ).To (gbytes .Say ("ENDORSEMENT_POLICY_FAILURE" ))
541
+ addMarble (network , orderer , testChaincode .Name , marbleDetails , peer )
564
542
})
565
543
})
566
544
567
- When ("a peer specified in the collection endorsement policy but not in the chaincode endorsement policy is used to invoke the chaincode" , func () {
568
- When ("the collection endorsement policy is a signature policy" , func () {
569
- It ("successfully invokes the chaincode" , func () {
570
- // collection config endorsement policy specifies org2 or org3 peers for endorsement
571
- By ("setting the collection config endorsement policy to use a signature policy" )
572
- testChaincode .CollectionsConfig = collectionConfig ("collections_config4.json" )
545
+ When ("using new lifecycle chaincode" , func () {
546
+ BeforeEach (func () {
547
+ testChaincode = chaincode {
548
+ Chaincode : newLifecycleChaincode ,
549
+ isLegacy : false ,
550
+ }
551
+ nwo .EnableCapabilities (network , "testchannel" , "Application" , "V2_0" , orderer , network .Peers ... )
552
+ })
573
553
574
- By ("setting the chaincode endorsement policy to org1 or org2 peers" )
575
- testChaincode .SignaturePolicy = `OR ('Org1MSP.member','Org2MSP.member')`
554
+ When ("a peer specified in the chaincode endorsement policy but not in the collection config endorsement policy is used to invoke the chaincode" , func () {
555
+ It ("fails validation" , func () {
556
+ By ("setting the collection config endorsement policy to org2 or org3 peers" )
557
+ testChaincode .CollectionsConfig = collectionConfig ("collections_config4.json" )
576
558
577
559
By ("deploying new lifecycle chaincode" )
578
560
// set collection endorsement policy to org2 or org3
579
561
deployChaincode (network , orderer , testChaincode )
580
562
581
- By ("adding marble1 with an org3 peer as endorser" )
582
- peer := network .Peer ("Org3 " , "peer0" )
563
+ By ("adding marble1 with an org1 peer as endorser" )
564
+ peer := network .Peer ("Org1 " , "peer0" )
583
565
marbleDetails := `{"name":"marble1", "color":"blue", "size":35, "owner":"tom", "price":99}`
584
- addMarble (network , orderer , testChaincode .Name , marbleDetails , peer )
566
+ marbleDetailsBase64 := base64 .StdEncoding .EncodeToString ([]byte (marbleDetails ))
567
+
568
+ command := commands.ChaincodeInvoke {
569
+ ChannelID : channelID ,
570
+ Orderer : network .OrdererAddress (orderer , nwo .ListenPort ),
571
+ Name : testChaincode .Name ,
572
+ Ctor : fmt .Sprintf (`{"Args":["initMarble"]}` ),
573
+ Transient : fmt .Sprintf (`{"marble":"%s"}` , marbleDetailsBase64 ),
574
+ PeerAddresses : []string {
575
+ network .PeerAddress (peer , nwo .ListenPort ),
576
+ },
577
+ WaitForEvent : true ,
578
+ }
579
+
580
+ sess , err := network .PeerUserSession (peer , "User1" , command )
581
+ Expect (err ).NotTo (HaveOccurred ())
582
+ Eventually (sess , network .EventuallyTimeout ).Should (gexec .Exit ())
583
+ Expect (sess .Err ).To (gbytes .Say ("ENDORSEMENT_POLICY_FAILURE" ))
585
584
})
586
585
})
587
586
588
- When ("the collection endorsement policy is a channel config policy reference" , func () {
589
- It ("successfully invokes the chaincode" , func () {
590
- // collection config endorsement policy specifies channel config policy reference /Channel/Application/Readers
591
- By ("setting the collection config endorsement policy to use a channel config policy reference" )
592
- testChaincode .CollectionsConfig = collectionConfig ("collections_config5.json" )
587
+ When ("a peer specified in the collection endorsement policy but not in the chaincode endorsement policy is used to invoke the chaincode" , func () {
588
+ When ("the collection endorsement policy is a signature policy" , func () {
589
+ It ("successfully invokes the chaincode" , func () {
590
+ // collection config endorsement policy specifies org2 or org3 peers for endorsement
591
+ By ("setting the collection config endorsement policy to use a signature policy" )
592
+ testChaincode .CollectionsConfig = collectionConfig ("collections_config4.json" )
593
+
594
+ By ("setting the chaincode endorsement policy to org1 or org2 peers" )
595
+ testChaincode .SignaturePolicy = `OR ('Org1MSP.member','Org2MSP.member')`
596
+
597
+ By ("deploying new lifecycle chaincode" )
598
+ // set collection endorsement policy to org2 or org3
599
+ deployChaincode (network , orderer , testChaincode )
600
+
601
+ By ("adding marble1 with an org3 peer as endorser" )
602
+ peer := network .Peer ("Org3" , "peer0" )
603
+ marbleDetails := `{"name":"marble1", "color":"blue", "size":35, "owner":"tom", "price":99}`
604
+ addMarble (network , orderer , testChaincode .Name , marbleDetails , peer )
605
+ })
606
+ })
607
+
608
+ When ("the collection endorsement policy is a channel config policy reference" , func () {
609
+ It ("successfully invokes the chaincode" , func () {
610
+ // collection config endorsement policy specifies channel config policy reference /Channel/Application/Readers
611
+ By ("setting the collection config endorsement policy to use a channel config policy reference" )
612
+ testChaincode .CollectionsConfig = collectionConfig ("collections_config5.json" )
613
+
614
+ By ("setting the channel endorsement policy to org1 or org2 peers" )
615
+ testChaincode .SignaturePolicy = `OR ('Org1MSP.member','Org2MSP.member')`
616
+
617
+ By ("deploying new lifecycle chaincode" )
618
+ deployChaincode (network , orderer , testChaincode )
619
+
620
+ By ("adding marble1 with an org3 peer as endorser" )
621
+ peer := network .Peer ("Org3" , "peer0" )
622
+ marbleDetails := `{"name":"marble1", "color":"blue", "size":35, "owner":"tom", "price":99}`
623
+ addMarble (network , orderer , testChaincode .Name , marbleDetails , peer )
624
+ })
625
+ })
626
+ })
593
627
594
- By ("setting the channel endorsement policy to org1 or org2 peers" )
595
- testChaincode .SignaturePolicy = `OR ('Org1MSP.member','Org2MSP.member')`
628
+ When ("the collection config endorsement policy specifies a semantically wrong, but well formed signature policy" , func () {
629
+ It ("fails to invoke the chaincode with an endorsement policy failure" , func () {
630
+ By ("setting the collection config endorsement policy to non existent org4 peers" )
631
+ testChaincode .CollectionsConfig = collectionConfig ("collections_config6.json" )
596
632
597
633
By ("deploying new lifecycle chaincode" )
598
634
deployChaincode (network , orderer , testChaincode )
599
635
600
- By ("adding marble1 with an org3 peer as endorser" )
601
- peer := network .Peer ("Org3 " , "peer0" )
636
+ By ("adding marble1 with an org1 peer as endorser" )
637
+ peer := network .Peer ("Org1 " , "peer0" )
602
638
marbleDetails := `{"name":"marble1", "color":"blue", "size":35, "owner":"tom", "price":99}`
603
- addMarble (network , orderer , testChaincode .Name , marbleDetails , peer )
639
+ marbleDetailsBase64 := base64 .StdEncoding .EncodeToString ([]byte (marbleDetails ))
640
+
641
+ command := commands.ChaincodeInvoke {
642
+ ChannelID : channelID ,
643
+ Orderer : network .OrdererAddress (orderer , nwo .ListenPort ),
644
+ Name : testChaincode .Name ,
645
+ Ctor : fmt .Sprintf (`{"Args":["initMarble"]}` ),
646
+ Transient : fmt .Sprintf (`{"marble":"%s"}` , marbleDetailsBase64 ),
647
+ PeerAddresses : []string {
648
+ network .PeerAddress (peer , nwo .ListenPort ),
649
+ },
650
+ WaitForEvent : true ,
651
+ }
652
+
653
+ sess , err := network .PeerUserSession (peer , "User1" , command )
654
+ Expect (err ).NotTo (HaveOccurred ())
655
+ Eventually (sess , network .EventuallyTimeout ).Should (gexec .Exit ())
656
+ Expect (sess .Err ).To (gbytes .Say ("ENDORSEMENT_POLICY_FAILURE" ))
604
657
})
605
658
})
606
659
})
0 commit comments