Skip to content

Commit 6a7c188

Browse files
author
Jason Yellick
committed
[FAB-1960] Add peer test template
https://jira.hyperledger.org/browse/FAB-1960 Just like the orderer and MSP, the peer needs to supply a template so that the configtx/test can generate a valid genesis block for testing purposes. This change adds the peer template and adds a test which generates it. Change-Id: I3b3bb485c321abe41016d5428e582bf7fea23399 Signed-off-by: Jason Yellick <[email protected]>
1 parent d6d2250 commit 6a7c188

File tree

3 files changed

+41
-5
lines changed

3 files changed

+41
-5
lines changed

common/configtx/test/helper.go

+9-5
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,10 @@ import (
2222

2323
"github.com/hyperledger/fabric/common/configtx"
2424
"github.com/hyperledger/fabric/common/genesis"
25-
peersharedconfig "github.com/hyperledger/fabric/peer/sharedconfig"
2625
cb "github.com/hyperledger/fabric/protos/common"
2726
"github.com/hyperledger/fabric/protos/utils"
2827

2928
"github.com/golang/protobuf/proto"
30-
"github.com/hyperledger/fabric/protos/peer"
3129
logging "github.com/op/go-logging"
3230
)
3331

@@ -41,10 +39,12 @@ const (
4139
const (
4240
OrdererTemplateName = "orderer.template"
4341
MSPTemplateName = "msp.template"
42+
PeerTemplateName = "peer.template"
4443
)
4544

4645
var ordererTemplate configtx.Template
4746
var mspTemplate configtx.Template
47+
var peerTemplate configtx.Template
4848

4949
var genesisFactory genesis.Factory
5050

@@ -71,9 +71,8 @@ func readTemplate(name string) configtx.Template {
7171
func init() {
7272
ordererTemplate = readTemplate(OrdererTemplateName)
7373
mspTemplate = readTemplate(MSPTemplateName)
74-
anchorPeers := []*peer.AnchorPeer{{Host: "fakehost", Port: 2000, Cert: []byte{}}}
75-
gossTemplate := configtx.NewSimpleTemplate(peersharedconfig.TemplateAnchorPeers(anchorPeers))
76-
genesisFactory = genesis.NewFactoryImpl(configtx.NewCompositeTemplate(mspTemplate, ordererTemplate, gossTemplate))
74+
peerTemplate = readTemplate(PeerTemplateName)
75+
genesisFactory = genesis.NewFactoryImpl(configtx.NewCompositeTemplate(mspTemplate, ordererTemplate, peerTemplate))
7776
}
7877

7978
// WriteTemplate takes an output file and set of config items and writes them to that file as a marshaled ConfigurationTemplate
@@ -100,3 +99,8 @@ func GetOrdererTemplate() configtx.Template {
10099
func GetMSPTemplate() configtx.Template {
101100
return mspTemplate
102101
}
102+
103+
// GetMSPerTemplate returns the test peer template
104+
func GetPeerTemplate() configtx.Template {
105+
return peerTemplate
106+
}

common/configtx/test/peer.template

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
" AnchorPeers

peer/sharedconfig/template_test.go

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
Copyright IBM Corp. 2017 All Rights Reserved.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package sharedconfig
18+
19+
import (
20+
"testing"
21+
22+
configtxtest "github.com/hyperledger/fabric/common/configtx/test"
23+
)
24+
25+
func TestTemplate(t *testing.T) {
26+
configtxtest.WriteTemplate(
27+
"../../common/configtx/test/"+configtxtest.PeerTemplateName,
28+
DefaultAnchorPeers(),
29+
)
30+
}

0 commit comments

Comments
 (0)