github.com/kchristidis/fabric@v1.0.4-0.20171028114726-837acd08cde1/msp/mgmt/testtools/config.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  
    17  package msptesttools
    18  
    19  import (
    20  	"github.com/hyperledger/fabric/common/util"
    21  	"github.com/hyperledger/fabric/core/config"
    22  	"github.com/hyperledger/fabric/msp"
    23  	"github.com/hyperledger/fabric/msp/mgmt"
    24  )
    25  
    26  // LoadTestMSPSetup sets up the local MSP
    27  // and a chain MSP for the default chain
    28  func LoadMSPSetupForTesting() error {
    29  	dir, err := config.GetDevMspDir()
    30  	if err != nil {
    31  		return err
    32  	}
    33  	conf, err := msp.GetLocalMspConfig(dir, nil, "DEFAULT")
    34  	if err != nil {
    35  		return err
    36  	}
    37  
    38  	err = mgmt.GetLocalMSP().Setup(conf)
    39  	if err != nil {
    40  		return err
    41  	}
    42  
    43  	err = mgmt.GetManagerForChain(util.GetTestChainID()).Setup([]msp.MSP{mgmt.GetLocalMSP()})
    44  	if err != nil {
    45  		return err
    46  	}
    47  
    48  	return nil
    49  }