diff --git a/configtx/consortiums.go b/configtx/consortiums.go index 1d19f9c..8be16c3 100644 --- a/configtx/consortiums.go +++ b/configtx/consortiums.go @@ -50,8 +50,8 @@ func (c *ConfigTx) Consortiums() *ConsortiumsGroup { } // Consortium returns a consortium group from the updated config. -func (c *ConsortiumsGroup) Consortium(name string) *ConsortiumGroup { - consortiumGroup, ok := c.consortiumsGroup.Groups[name] +func (c *ConfigTx) Consortium(name string) *ConsortiumGroup { + consortiumGroup, ok := c.updated.ChannelGroup.Groups[ConsortiumsGroupKey].Groups[name] if !ok { return nil } @@ -64,7 +64,7 @@ func (c *ConsortiumsGroup) SetConsortium(consortium Consortium) error { c.consortiumsGroup.Groups[consortium.Name] = newConfigGroup() for _, org := range consortium.Organizations { - err := c.Consortium(consortium.Name).SetOrganization(org) + err := c.consortium(consortium.Name).SetOrganization(org) if err != nil { return err } @@ -73,6 +73,11 @@ func (c *ConsortiumsGroup) SetConsortium(consortium Consortium) error { return nil } +func (c *ConsortiumsGroup) consortium(name string) *ConsortiumGroup { + consortiumGroup := c.consortiumsGroup.Groups[name] + return &ConsortiumGroup{name: name, consortiumGroup: consortiumGroup} +} + // RemoveConsortium removes a consortium from a channel configuration. // Removal will panic if the consortiums group does not exist. func (c *ConsortiumsGroup) RemoveConsortium(name string) { @@ -114,7 +119,7 @@ func (c *ConsortiumGroup) RemoveOrganization(name string) { func (c *ConsortiumsGroup) Configuration() ([]Consortium, error) { consortiums := []Consortium{} for consortiumName := range c.consortiumsGroup.Groups { - consortium, err := c.Consortium(consortiumName).Configuration() + consortium, err := c.consortium(consortiumName).Configuration() if err != nil { return nil, err } diff --git a/configtx/consortiums_test.go b/configtx/consortiums_test.go index e789d6d..fd49c8e 100644 --- a/configtx/consortiums_test.go +++ b/configtx/consortiums_test.go @@ -750,7 +750,7 @@ func TestSetConsortiumOrg(t *testing.T) { err = protolator.DeepUnmarshalJSON(bytes.NewBufferString(expectedConfigJSON), expectedConfigProto) gt.Expect(err).NotTo(HaveOccurred()) - err = c.Consortiums().Consortium("Consortium1").SetOrganization(orgToAdd) + err = c.Consortium("Consortium1").SetOrganization(orgToAdd) gt.Expect(err).NotTo(HaveOccurred()) gt.Expect(proto.Equal(c.updated, expectedConfigProto)).To(BeTrue()) @@ -797,7 +797,7 @@ func TestSetConsortiumOrgFailures(t *testing.T) { c := New(config) - err = c.Consortiums().Consortium(test.consortium).SetOrganization(test.org) + err = c.Consortium(test.consortium).SetOrganization(test.org) gt.Expect(err).To(MatchError(test.expectedErr)) }) } @@ -826,8 +826,7 @@ func TestRemoveConsortium(t *testing.T) { c.Consortiums().RemoveConsortium("Consortium1") - updatedConsortiumsGroup := c.Consortiums() - gt.Expect(updatedConsortiumsGroup.Consortium("Consortium1")).To(BeNil()) + gt.Expect(c.Consortium("Consortium1")).To(BeNil()) } func TestGetConsortiums(t *testing.T) { diff --git a/configtx/example_test.go b/configtx/example_test.go index 51e657c..f5d6ddb 100644 --- a/configtx/example_test.go +++ b/configtx/example_test.go @@ -87,7 +87,7 @@ func Example_basic() { baseConfig := fetchSystemChannelConfig() c := configtx.New(baseConfig) - err := c.Consortiums().Consortium("SampleConsortium").SetChannelCreationPolicy( + err := c.Consortium("SampleConsortium").SetChannelCreationPolicy( configtx.Policy{Type: configtx.ImplicitMetaPolicyType, Rule: "MAJORITY Admins"}) if err != nil { @@ -565,7 +565,7 @@ func ExampleConsortiumOrg_SetMSP() { baseConfig := fetchSystemChannelConfig() c := configtx.New(baseConfig) - sampleConsortiumOrg1 := c.Consortiums().Consortium("SampleConsortium").Organization("Org1") + sampleConsortiumOrg1 := c.Consortium("SampleConsortium").Organization("Org1") msp, err := sampleConsortiumOrg1.MSP() if err != nil { diff --git a/configtx/msp_test.go b/configtx/msp_test.go index 11d421d..2d3c7c8 100644 --- a/configtx/msp_test.go +++ b/configtx/msp_test.go @@ -116,7 +116,7 @@ func TestConsortiumMSP(t *testing.T) { c := New(config) - msp, err := c.Consortiums().Consortium("Consortium1").Organization("Org1").MSP() + msp, err := c.Consortium("Consortium1").Organization("Org1").MSP() gt.Expect(err).NotTo(HaveOccurred()) gt.Expect(msp).To(Equal(expectedMSP)) } @@ -288,7 +288,7 @@ func TestMSPConfigurationFailures(t *testing.T) { _, err := c.Orderer().Organization(tt.orgName).MSP() gt.Expect(err).To(MatchError(tt.expectedErr)) case ConsortiumsGroupKey: - _, err := c.Consortiums().Consortium(tt.consortiumName).Organization(tt.orgName).MSP() + _, err := c.Consortium(tt.consortiumName).Organization(tt.orgName).MSP() gt.Expect(err).To(MatchError(tt.expectedErr)) default: t.Fatalf("invalid org type %s", tt.orgType) @@ -432,7 +432,7 @@ func TestSetConsortiumMSP(t *testing.T) { } c := New(config) - consortium1 := c.Consortiums().Consortium("Consortium1") + consortium1 := c.Consortium("Consortium1") consortiumOrg1MSP, err := consortium1.Organization("Org1").MSP() gt.Expect(err).NotTo(HaveOccurred()) consortiumOrg2MSP, err := consortium1.Organization("Org2").MSP() @@ -809,7 +809,7 @@ func TestSetConsortiumMSPFailure(t *testing.T) { } c := New(config) - consortiumOrg1 := c.Consortiums().Consortium("Consortium1").Organization("Org1") + consortiumOrg1 := c.Consortium("Consortium1").Organization("Org1") consortiumOrg1MSP, err := consortiumOrg1.MSP() gt.Expect(err).NotTo(HaveOccurred()) diff --git a/configtx/organization_test.go b/configtx/organization_test.go index 6e219eb..1514245 100644 --- a/configtx/organization_test.go +++ b/configtx/organization_test.go @@ -206,7 +206,7 @@ func TestConsortiumOrg(t *testing.T) { t.Parallel() gt := NewGomegaWithT(t) - org, err := c.Consortiums().Consortium(tc.consortiumName).Organization(tc.orgName).Configuration() + org, err := c.Consortium(tc.consortiumName).Organization(tc.orgName).Configuration() if tc.expectedErr != "" { gt.Expect(Organization{}).To(Equal(org)) gt.Expect(err).To(MatchError(tc.expectedErr)) @@ -232,8 +232,8 @@ func TestRemoveConsortiumOrg(t *testing.T) { c := New(config) - c.Consortiums().Consortium("Consortium1").RemoveOrganization("Org1") - gt.Expect(c.Consortiums().Consortium("Consortium1").Organization("Org1")).To(BeNil()) + c.Consortium("Consortium1").RemoveOrganization("Org1") + gt.Expect(c.Consortium("Consortium1").Organization("Org1")).To(BeNil()) } func TestNewOrgConfigGroup(t *testing.T) { diff --git a/configtx/policies_test.go b/configtx/policies_test.go index e703838..18d3c6c 100644 --- a/configtx/policies_test.go +++ b/configtx/policies_test.go @@ -366,7 +366,7 @@ func TestSetConsortiumOrgPolicy(t *testing.T) { }, } - consortium1Org1 := c.Consortiums().Consortium("Consortium1").Organization("Org1") + consortium1Org1 := c.Consortium("Consortium1").Organization("Org1") err = consortium1Org1.SetPolicy("TestPolicy", Policy{Type: ImplicitMetaPolicyType, Rule: "MAJORITY Endorsement"}) gt.Expect(err).NotTo(HaveOccurred()) @@ -410,7 +410,7 @@ func TestSetConsortiumOrgPolicyFailures(t *testing.T) { expectedErr: "failed to set policy 'TestPolicy' to consortium org 'Org1': unknown policy type: ", }, } { - err := c.Consortiums().Consortium(test.consortium).Organization(test.org).SetPolicy("TestPolicy", test.policy) + err := c.Consortium(test.consortium).Organization(test.org).SetPolicy("TestPolicy", test.policy) gt.Expect(err).To(MatchError(test.expectedErr)) } } @@ -456,7 +456,7 @@ func TestRemoveConsortiumOrgPolicy(t *testing.T) { }, } - consortium1Org1 := c.Consortiums().Consortium("Consortium1").Organization("Org1") + consortium1Org1 := c.Consortium("Consortium1").Organization("Org1") consortium1Org1.RemovePolicy("TestPolicy") updatedPolicies, err := consortium1Org1.Policies() @@ -788,7 +788,7 @@ func TestSetConsortiumChannelCreationPolicy(t *testing.T) { updatedPolicy := Policy{Type: ImplicitMetaPolicyType, Rule: "MAJORITY Admins"} - consortium1 := c.Consortiums().Consortium("Consortium1") + consortium1 := c.Consortium("Consortium1") err = consortium1.SetChannelCreationPolicy(updatedPolicy) gt.Expect(err).NotTo(HaveOccurred()) @@ -841,7 +841,7 @@ func TestSetConsortiumChannelCreationPolicyFailures(t *testing.T) { tt := tt t.Run(tt.name, func(t *testing.T) { gt := NewGomegaWithT(t) - err := c.Consortiums().Consortium(tt.consortiumName).SetChannelCreationPolicy(tt.updatedpolicy) + err := c.Consortium(tt.consortiumName).SetChannelCreationPolicy(tt.updatedpolicy) gt.Expect(err).To(MatchError(tt.expectedErr)) }) } @@ -976,7 +976,7 @@ func TestConsortiumOrgPolicies(t *testing.T) { }, } - policies, err := c.Consortiums().Consortium("Consortium1").Organization("Org1").Policies() + policies, err := c.Consortium("Consortium1").Organization("Org1").Policies() gt.Expect(err).NotTo(HaveOccurred()) gt.Expect(policies).To(Equal(expectedPolicies)) }