github.com/IBM-Blockchain/fabric-operator@v1.0.4/pkg/initializer/orderer/configtx/profile_test.go (about)

     1  /*
     2   * Copyright contributors to the Hyperledger Fabric Operator project
     3   *
     4   * SPDX-License-Identifier: Apache-2.0
     5   *
     6   * Licensed under the Apache License, Version 2.0 (the "License");
     7   * you may not use this file except in compliance with the License.
     8   * You may obtain a copy of the License at:
     9   *
    10   * 	  http://www.apache.org/licenses/LICENSE-2.0
    11   *
    12   * Unless required by applicable law or agreed to in writing, software
    13   * distributed under the License is distributed on an "AS IS" BASIS,
    14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    15   * See the License for the specific language governing permissions and
    16   * limitations under the License.
    17   */
    18  
    19  package configtx_test
    20  
    21  import (
    22  	"github.com/IBM-Blockchain/fabric-operator/pkg/initializer/orderer/configtx"
    23  	"github.com/hyperledger/fabric-protos-go/msp"
    24  	"github.com/hyperledger/fabric-protos-go/orderer/etcdraft"
    25  	"github.com/hyperledger/fabric/common/channelconfig"
    26  	. "github.com/onsi/ginkgo/v2"
    27  	. "github.com/onsi/gomega"
    28  )
    29  
    30  var _ = Describe("profile", func() {
    31  	var (
    32  		err       error
    33  		profile   *configtx.Profile
    34  		mspConfig map[string]*msp.MSPConfig
    35  	)
    36  
    37  	BeforeEach(func() {
    38  		configTx := configtx.New()
    39  		profile, err = configTx.GetProfile("Initial")
    40  		Expect(err).NotTo(HaveOccurred())
    41  
    42  		mspConfig = map[string]*msp.MSPConfig{
    43  			"testorg3": &msp.MSPConfig{},
    44  		}
    45  	})
    46  
    47  	Context("profile configuration updates", func() {
    48  		It("adds orderer address to profile", func() {
    49  			blockBytes, err := profile.GenerateBlock("channel1", mspConfig)
    50  			Expect(err).NotTo(HaveOccurred())
    51  			Expect(string(blockBytes)).NotTo(ContainSubstring("127.0.0.1:7051"))
    52  
    53  			profile.AddOrdererAddress("127.0.0.1:7051")
    54  			blockBytes, err = profile.GenerateBlock("channel1", mspConfig)
    55  			Expect(err).NotTo(HaveOccurred())
    56  
    57  			Expect(string(blockBytes)).To(ContainSubstring("127.0.0.1:7051"))
    58  		})
    59  
    60  		It("sets orderer type", func() {
    61  			profile.SetOrdererType("etcdraft")
    62  			blockBytes, err := profile.GenerateBlock("channel1", mspConfig)
    63  			Expect(err).NotTo(HaveOccurred())
    64  
    65  			Expect(string(blockBytes)).To(ContainSubstring("etcdraft"))
    66  		})
    67  
    68  		It("adds raft consenting node", func() {
    69  			consenter := &etcdraft.Consenter{
    70  				Host:          "testrafthost",
    71  				Port:          7050,
    72  				ClientTlsCert: []byte("../../../../testdata/tls/tls.crt"),
    73  				ServerTlsCert: []byte("../../../../testdata/tls/tls.crt"),
    74  			}
    75  
    76  			profile.SetOrdererType("etcdraft")
    77  			err := profile.AddRaftConsentingNode(consenter)
    78  			Expect(err).NotTo(HaveOccurred())
    79  
    80  			blockBytes, err := profile.GenerateBlock("channel1", mspConfig)
    81  			Expect(err).NotTo(HaveOccurred())
    82  
    83  			Expect(string(blockBytes)).To(ContainSubstring("testrafthost"))
    84  		})
    85  
    86  		It("adds consortium", func() {
    87  			profile.Policies = map[string]*configtx.Policy{
    88  				channelconfig.AdminsPolicyKey: &configtx.Policy{
    89  					Type: configtx.ImplicitMetaPolicyType,
    90  					Rule: "ALL bar",
    91  				},
    92  				channelconfig.ReadersPolicyKey: &configtx.Policy{
    93  					Type: configtx.ImplicitMetaPolicyType,
    94  					Rule: "ALL bar",
    95  				},
    96  				channelconfig.WritersPolicyKey: &configtx.Policy{
    97  					Type: configtx.ImplicitMetaPolicyType,
    98  					Rule: "ALL bar",
    99  				},
   100  			}
   101  
   102  			org := &configtx.Organization{
   103  				Name:           "testorg",
   104  				ID:             "testorg",
   105  				MSPType:        "bccsp",
   106  				MSPDir:         "../../../../testdata/init/orderer/msp",
   107  				AdminPrincipal: "Role.MEMBER",
   108  				Policies:       profile.Policies,
   109  			}
   110  
   111  			consortium := &configtx.Consortium{
   112  				Organizations: []*configtx.Organization{org},
   113  			}
   114  
   115  			profile.SetOrdererType("etcdraft")
   116  			err := profile.AddConsortium("testconsortium", consortium)
   117  			Expect(err).NotTo(HaveOccurred())
   118  
   119  			blockBytes, err := profile.GenerateBlock("channel1", mspConfig)
   120  			Expect(err).NotTo(HaveOccurred())
   121  
   122  			Expect(string(blockBytes)).To(ContainSubstring("testconsortium"))
   123  			Expect(string(blockBytes)).To(ContainSubstring("testorg"))
   124  		})
   125  
   126  		It("adds org to consortium", func() {
   127  			profile.Policies = map[string]*configtx.Policy{
   128  				channelconfig.AdminsPolicyKey: &configtx.Policy{
   129  					Type: configtx.ImplicitMetaPolicyType,
   130  					Rule: "ALL bar",
   131  				},
   132  				channelconfig.ReadersPolicyKey: &configtx.Policy{
   133  					Type: configtx.ImplicitMetaPolicyType,
   134  					Rule: "ALL bar",
   135  				},
   136  				channelconfig.WritersPolicyKey: &configtx.Policy{
   137  					Type: configtx.ImplicitMetaPolicyType,
   138  					Rule: "ALL bar",
   139  				},
   140  			}
   141  
   142  			org := &configtx.Organization{
   143  				Name:           "testorg",
   144  				ID:             "testorg",
   145  				MSPType:        "bccsp",
   146  				MSPDir:         "../../../../testdata/init/orderer/msp",
   147  				AdminPrincipal: "Role.MEMBER",
   148  				Policies:       profile.Policies,
   149  			}
   150  
   151  			consortium := &configtx.Consortium{
   152  				Organizations: []*configtx.Organization{org},
   153  			}
   154  
   155  			profile.SetOrdererType("etcdraft")
   156  			profile.AddConsortium("testconsortium", consortium)
   157  
   158  			org.Name = "testorg2"
   159  			err := profile.AddOrgToConsortium("testconsortium", org)
   160  			Expect(err).NotTo(HaveOccurred())
   161  
   162  			blockBytes, err := profile.GenerateBlock("channel1", mspConfig)
   163  			Expect(err).NotTo(HaveOccurred())
   164  
   165  			Expect(string(blockBytes)).To(ContainSubstring("testconsortium"))
   166  			Expect(string(blockBytes)).To(ContainSubstring("testorg2"))
   167  		})
   168  	})
   169  
   170  	It("adds org to orderer", func() {
   171  		org := &configtx.Organization{
   172  			Name:           "testorg3",
   173  			ID:             "testorg3",
   174  			MSPType:        "bccsp",
   175  			MSPDir:         "../../../../testdata/init/orderer/msp",
   176  			AdminPrincipal: "Role.MEMBER",
   177  		}
   178  
   179  		profile.SetOrdererType("etcdraft")
   180  		err := profile.AddOrgToOrderer(org)
   181  		Expect(err).NotTo(HaveOccurred())
   182  
   183  		blockBytes, err := profile.GenerateBlock("channel1", mspConfig)
   184  		Expect(err).NotTo(HaveOccurred())
   185  
   186  		Expect(string(blockBytes)).To(ContainSubstring("testorg3"))
   187  	})
   188  })