forked from hyperledger/fabric-sdk-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mockchannel.go
75 lines (59 loc) · 1.88 KB
/
mockchannel.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/*
Copyright SecureKey Technologies Inc. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package mocks
import (
"github.com/pkg/errors"
"github.com/hyperledger/fabric-sdk-go/pkg/common/providers/context"
"github.com/hyperledger/fabric-sdk-go/pkg/common/providers/fab"
"github.com/hyperledger/fabric-sdk-go/pkg/common/providers/msp"
mspmocks "github.com/hyperledger/fabric-sdk-go/pkg/msp/test/mockmsp"
)
//Channel supplies the configuration for channel context client
type Channel struct {
context.Client
channelService fab.ChannelService
channelID string
}
//Providers returns core providers
func (c *Channel) Providers() context.Client {
return c
}
//ChannelService returns channel service
func (c *Channel) ChannelService() fab.ChannelService {
return c.channelService
}
//ChannelID returns channel ID
func (c *Channel) ChannelID() string {
return c.channelID
}
type mockClientContext struct {
context.Providers
msp.SigningIdentity
}
//NewMockChannel creates new mock channel
func NewMockChannel(channelID string) (*Channel, error) {
ctx := &mockClientContext{
Providers: NewMockProviderContext(),
SigningIdentity: mspmocks.NewMockSigningIdentity("user", "Org1MSP"),
}
// Set up mock channel service
chProvider, err := NewMockChannelProvider(ctx)
if err != nil {
return nil, errors.WithMessage(err, "new mock channel provider failed")
}
channelService, err := chProvider.ChannelService(ctx, channelID)
if err != nil {
return nil, errors.WithMessage(err, "failed to create mock channel service")
}
peer := NewMockPeer("Peer1", "example.com")
channelService.(*MockChannelService).SetDiscovery(NewMockDiscoveryService(nil, peer))
channelService.(*MockChannelService).SetSelection(NewMockSelectionService(nil, peer))
channel := &Channel{
Client: ctx,
channelService: channelService,
channelID: channelID,
}
return channel, nil
}