-
Notifications
You must be signed in to change notification settings - Fork 0
/
mock_helpers.go
60 lines (50 loc) · 1.53 KB
/
mock_helpers.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
/*
Copyright IBM Corp. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package peer
import (
configtxtest "github.com/hyperledger/fabric/common/configtx/test"
mockchannelconfig "github.com/hyperledger/fabric/common/mocks/config"
mockconfigtx "github.com/hyperledger/fabric/common/mocks/configtx"
mockpolicies "github.com/hyperledger/fabric/common/mocks/policies"
"github.com/hyperledger/fabric/core/ledger"
"github.com/hyperledger/fabric/core/ledger/ledgermgmt"
)
//MockInitialize resets chains for test env
func MockInitialize() {
ledgermgmt.InitializeTestEnvWithInitializer(
&ledgermgmt.Initializer{
CustomTxProcessors: ConfigTxProcessors,
},
)
chains.list = make(map[string]*chain)
chainInitializer = func(string) { return }
}
// MockCreateChain used for creating a ledger for a chain for tests
// without having to join
func MockCreateChain(cid string) error {
var ledger ledger.PeerLedger
var err error
if ledger = GetLedger(cid); ledger == nil {
gb, _ := configtxtest.MakeGenesisBlock(cid)
if ledger, err = ledgermgmt.CreateLedger(gb); err != nil {
return err
}
}
chains.Lock()
defer chains.Unlock()
chains.list[cid] = &chain{
cs: &chainSupport{
Resources: &mockchannelconfig.Resources{
PolicyManagerVal: &mockpolicies.Manager{
Policy: &mockpolicies.Policy{},
},
ConfigtxValidatorVal: &mockconfigtx.Validator{},
ApplicationConfigVal: &mockchannelconfig.MockApplication{CapabilitiesRv: &mockchannelconfig.MockApplicationCapabilities{}},
},
ledger: ledger,
},
}
return nil
}