github.com/yacovm/fabric@v2.0.0-alpha.0.20191128145320-c5d4087dc723+incompatible/core/peer/mock_helpers.go (about)

     1  /*
     2  Copyright IBM Corp. All Rights Reserved.
     3  
     4  SPDX-License-Identifier: Apache-2.0
     5  */
     6  
     7  package peer
     8  
     9  import (
    10  	"github.com/hyperledger/fabric/bccsp/sw"
    11  	configtxtest "github.com/hyperledger/fabric/common/configtx/test"
    12  	mockchannelconfig "github.com/hyperledger/fabric/common/mocks/config"
    13  	mockconfigtx "github.com/hyperledger/fabric/common/mocks/configtx"
    14  	"github.com/hyperledger/fabric/common/policies"
    15  	"github.com/hyperledger/fabric/core/ledger"
    16  )
    17  
    18  func CreateMockChannel(p *Peer, cid string, policyMgr policies.Manager) error {
    19  	var ledger ledger.PeerLedger
    20  	var err error
    21  
    22  	if ledger = p.GetLedger(cid); ledger == nil {
    23  		gb, _ := configtxtest.MakeGenesisBlock(cid)
    24  		if ledger, err = p.LedgerMgr.CreateLedger(cid, gb); err != nil {
    25  			return err
    26  		}
    27  	}
    28  
    29  	p.mutex.Lock()
    30  	defer p.mutex.Unlock()
    31  
    32  	if p.channels == nil {
    33  		p.channels = map[string]*Channel{}
    34  	}
    35  
    36  	cryptoProvider, err := sw.NewDefaultSecurityLevelWithKeystore(sw.NewDummyKeyStore())
    37  	if err != nil {
    38  		return err
    39  	}
    40  
    41  	p.channels[cid] = &Channel{
    42  		ledger: ledger,
    43  		resources: &mockchannelconfig.Resources{
    44  			PolicyManagerVal:     policyMgr,
    45  			ConfigtxValidatorVal: &mockconfigtx.Validator{},
    46  			ApplicationConfigVal: &mockchannelconfig.MockApplication{CapabilitiesRv: &mockchannelconfig.MockApplicationCapabilities{}},
    47  		},
    48  		cryptoProvider: cryptoProvider,
    49  	}
    50  
    51  	return nil
    52  }