-
Notifications
You must be signed in to change notification settings - Fork 11
/
mockselection.go
41 lines (31 loc) · 1 KB
/
mockselection.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/*
Copyright SecureKey Technologies Inc. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package mocks
import (
"github.com/VoneChain-CS/fabric-sdk-go-gm/pkg/common/options"
"github.com/VoneChain-CS/fabric-sdk-go-gm/pkg/common/providers/fab"
)
// MockSelectionService implements mock selection service
type MockSelectionService struct {
Error error
Peers []fab.Peer
}
// NewMockSelectionService returns mock selection service
func NewMockSelectionService(err error, peers ...fab.Peer) *MockSelectionService {
return &MockSelectionService{Error: err, Peers: peers}
}
// GetEndorsersForChaincode mockcore retrieving endorsing peers
func (ds *MockSelectionService) GetEndorsersForChaincode(chaincodes []*fab.ChaincodeCall, opts ...options.Opt) ([]fab.Peer, error) {
if ds.Error != nil {
return nil, ds.Error
}
if ds.Peers == nil {
mockPeer := NewMockPeer("Peer1", "http://peer1.com")
peers := make([]fab.Peer, 0)
peers = append(peers, mockPeer)
ds.Peers = peers
}
return ds.Peers, nil
}