github.com/myafeier/fabric@v1.0.1-0.20170722181825-3a4b1f2bce86/common/config/consortium_test.go (about)

     1  /*
     2  Copyright IBM Corp. 2017 All Rights Reserved.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8                   http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  package config
    17  
    18  import (
    19  	"testing"
    20  
    21  	"github.com/hyperledger/fabric/common/config/msp"
    22  	cb "github.com/hyperledger/fabric/protos/common"
    23  	"github.com/stretchr/testify/assert"
    24  )
    25  
    26  func TestConsortiumGroup(t *testing.T) {
    27  
    28  	cg := NewConsortiumGroup(msp.NewMSPConfigHandler())
    29  	og, err := cg.NewGroup("testGroup")
    30  	assert.NoError(t, err, "NewGroup should not have returned error")
    31  	assert.Equal(t, "testGroup", og.(*OrganizationGroup).Name(),
    32  		"Unexpected group name returned")
    33  
    34  	cc := cg.Allocate()
    35  	_, ok := cc.(*ConsortiumConfig)
    36  	assert.Equal(t, true, ok, "Allocate should have returned a ConsortiumConfig")
    37  
    38  	_, _, err = cg.BeginValueProposals(t, []string{"testGroup"})
    39  	assert.NoError(t, err, "BeginValueProposals should not have returned error")
    40  
    41  	err = cg.PreCommit(t)
    42  	assert.NoError(t, err, "PreCommit should not have returned error")
    43  	cg.CommitProposals(t)
    44  	cg.RollbackProposals(t)
    45  
    46  }
    47  
    48  func TestConsortiumConfig(t *testing.T) {
    49  	cg := NewConsortiumGroup(msp.NewMSPConfigHandler())
    50  	cc := NewConsortiumConfig(cg)
    51  	orgs := cc.Organizations()
    52  	assert.Equal(t, 0, len(orgs))
    53  
    54  	policy := cc.ChannelCreationPolicy()
    55  	assert.EqualValues(t, cb.Policy_UNKNOWN, policy.Type, "Expected policy type to be UNKNOWN")
    56  
    57  	cc.Commit()
    58  	assert.Equal(t, cg.ConsortiumConfig, cc, "Error committing ConsortiumConfig")
    59  
    60  	og, _ := cg.NewGroup("testGroup")
    61  	err := cc.Validate(t, map[string]ValueProposer{
    62  		"testGroup": og,
    63  	})
    64  	assert.NoError(t, err, "Validate returned unexpected error")
    65  	csg := NewConsortiumsGroup(nil)
    66  	err = cc.Validate(t, map[string]ValueProposer{
    67  		"testGroup": csg,
    68  	})
    69  	assert.Error(t, err, "Validate should have failed")
    70  
    71  }