func (b *BDDContext) PeersByChannel(channelID string) []*PeerConfig {
	b.mutex.RLock()
	defer b.mutex.RUnlock()
	return b.peersByChannel[channelID]
}
PeersByChannel returns the peers for the given channel
package bddtests
import (
	"fmt"
	"math/rand"
	"os"
	"strings"
	"sync"
	"github.com/hyperledger/fabric-sdk-go/pkg/client/common/selection/staticselection"
	"github.com/hyperledger/fabric-sdk-go/pkg/client/channel"
	"github.com/hyperledger/fabric-sdk-go/pkg/client/resmgmt"
	contextApi "github.com/hyperledger/fabric-sdk-go/pkg/common/providers/context"
	fabApi "github.com/hyperledger/fabric-sdk-go/pkg/common/providers/fab"
	"github.com/hyperledger/fabric-sdk-go/pkg/core/config"
	"github.com/hyperledger/fabric-sdk-go/pkg/fab"
	"github.com/hyperledger/fabric-sdk-go/pkg/fabsdk"
	sdkApi "github.com/hyperledger/fabric-sdk-go/pkg/fabsdk/api"
	"github.com/hyperledger/fabric-sdk-go/pkg/fabsdk/factory/defsvc"
)
var ADMIN = "admin"
var USER = "user"
type BDDContext struct {
	composition            *Composition
	clientConfig           fabApi.EndpointConfig
	mutex                  sync.RWMutex
	orgs                   []string
	ordererOrgID           string
	peersByChannel         map[string][]*PeerConfig
	orgsByChannel          map[string][]string
	collectionConfigs      map[string]*CollectionConfig
	resmgmtClients         map[string]*resmgmt.Client
	contexts               map[string]contextApi.Client
	orgChannelClients      map[string]*channel.Client
	peersMspID             map[string]string
	clientConfigFilePath   string
	clientConfigFileName   string
	snapsConfigFilePath    string
	testCCPath             string
	createdChannels        map[string]bool
	sdk                    *fabsdk.FabricSDK
	configCLI              *ConfigCLI
	serviceProviderFactory sdkApi.ServiceProviderFactory
}
type PeerConfig struct {
	OrgID  string
	Config fabApi.PeerConfig
	MspID  string
	PeerID string
}
type CollectionConfig struct {
	Name              string
	Policy            string
	RequiredPeerCount int32
	MaxPeerCount      int32
	BlocksToLive      uint64
}
func NewBDDContext(orgs []string, ordererOrgID string, clientConfigFilePath string, clientConfigFileName string,
	snapsConfigFilePath string, peersMspID map[string]string, testCCPath string, cliPath string) (*BDDContext, error) {
	configCli := NewConfigCLI(cliPath, clientConfigFilePath+clientConfigFileName, "User1")
	instance := BDDContext{
		orgs:                 orgs,
		peersByChannel:       make(map[string][]*PeerConfig),
		contexts:             make(map[string]contextApi.Client),
		orgsByChannel:        make(map[string][]string),
		resmgmtClients:       make(map[string]*resmgmt.Client),
		collectionConfigs:    make(map[string]*CollectionConfig),
		orgChannelClients:    make(map[string]*channel.Client),
		createdChannels:      make(map[string]bool),
		clientConfigFilePath: clientConfigFilePath,
		clientConfigFileName: clientConfigFileName,
		snapsConfigFilePath:  snapsConfigFilePath,
		peersMspID:           peersMspID,
		testCCPath:           testCCPath,
		ordererOrgID:         ordererOrgID,
		configCLI:            configCli,
	}
	return &instance, nil
}
func (b *BDDContext) BeforeScenario(scenarioOrScenarioOutline interface{}) {
	b.mutex.Lock()
	defer b.mutex.Unlock()
	if b.sdk != nil {
		return
	}
	var opts []fabsdk.Option
	if b.serviceProviderFactory != nil {
		opts = append(opts, fabsdk.WithServicePkg(b.serviceProviderFactory))
	}
	sdk, err := fabsdk.New(config.FromFile(b.clientConfigFilePath+b.clientConfigFileName), opts...)
	if err != nil {
		panic(fmt.Sprintf("Failed to create new SDK: %s", err))
	}
	b.sdk = sdk
	configBackend, err := sdk.Config()
	if err != nil {
		panic(fmt.Sprintf("Failed to get config: %s", err))
	}
	endpointConfig, err := fab.ConfigFromBackend(configBackend)
	if err != nil {
		panic(fmt.Sprintf("Failed to get config: %s", err))
	}
	b.clientConfig = endpointConfig
	for _, org := range b.orgs {
		orgAdmin := fmt.Sprintf("%s_%s", org, ADMIN)
		adminContextProv := sdk.Context(fabsdk.WithUser("Admin"), fabsdk.WithOrg(org))
		b.contexts[orgAdmin], err = adminContextProv()
		if err != nil {
			panic(fmt.Sprintf("Failed to get admin context: %s", err))
		}
		b.resmgmtClients[orgAdmin], err = resmgmt.New(adminContextProv)
		if err != nil {
			panic(fmt.Sprintf("Failed to get admin resmgmt: %s", err))
		}
		orgUser := fmt.Sprintf("%s_%s", org, USER)
		userContextProv := sdk.Context(fabsdk.WithUser("User1"), fabsdk.WithOrg(org))
		b.contexts[orgUser], err = userContextProv()
		if err != nil {
			panic(fmt.Sprintf("Failed to get user context: %s", err))
		}
		b.resmgmtClients[orgUser], err = resmgmt.New(userContextProv)
		if err != nil {
			panic(fmt.Sprintf("Failed to get user resmgmt: %s", err))
		}
	}
	b.populateChannelPeers()
}
func (b *BDDContext) AfterScenario(interface{}, error) {
	b.mutex.Lock()
	defer b.mutex.Unlock()
	if b.sdk != nil {
		b.sdk.Close()
		b.sdk = nil
	}
	b.peersByChannel = make(map[string][]*PeerConfig)
	b.contexts = make(map[string]contextApi.Client)
	b.orgsByChannel = make(map[string][]string)
	b.resmgmtClients = make(map[string]*resmgmt.Client)
	b.collectionConfigs = make(map[string]*CollectionConfig)
	b.orgChannelClients = make(map[string]*channel.Client)
	b.createdChannels = make(map[string]bool)
}
func FindPKCS11Lib(configuredLib string) string {
	logger.Debugf("PKCS library configurations paths  %s ", configuredLib)
	var lib string
	if configuredLib != "" {
		possibilities := strings.Split(configuredLib, ",")
		for _, path := range possibilities {
			trimpath := strings.TrimSpace(path)
			if _, err := os.Stat(trimpath); !os.IsNotExist(err) {
				lib = trimpath
				break
			}
		}
	}
	logger.Debugf("Found pkcs library '%s'", lib)
	return lib
}
func (b *BDDContext) SetServiceProviderFactory(factory sdkApi.ServiceProviderFactory) {
	b.mutex.Lock()
	defer b.mutex.Unlock()
	b.serviceProviderFactory = factory
}
func (b *BDDContext) Orgs() []string {
	b.mutex.RLock()
	defer b.mutex.RUnlock()
	return b.orgs
}