Skip to content

Commit bc3ee87

Browse files
committed
FAB-1683 configtx.Items() doesn't set header type
Items() was not setting the type of the chain header properly as was configured in the inner fields of the template. Since this code works only for configuration items, I just set it to HeaderType_CONFIGURATION_ITEM. Also changed the template_test to accomodate the change. Signed-off-by: Yacov Manevich <[email protected]> Change-Id: I24ea3ada0e3df34fd2fbe0250cafd37f068f23e8
1 parent 8a22850 commit bc3ee87

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

common/configtx/template.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func NewSimpleTemplate(items ...*cb.ConfigurationItem) Template {
5353
func (st *simpleTemplate) Items(chainID string) ([]*cb.SignedConfigurationItem, error) {
5454
signedItems := make([]*cb.SignedConfigurationItem, len(st.items))
5555
for i := range st.items {
56-
st.items[i].Header = &cb.ChainHeader{ChainID: chainID}
56+
st.items[i].Header = &cb.ChainHeader{ChainID: chainID, Type: int32(cb.HeaderType_CONFIGURATION_ITEM)}
5757
mItem, err := proto.Marshal(st.items[i])
5858
if err != nil {
5959
return nil, err

common/configtx/template_test.go

+11-9
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222

2323
cb "github.com/hyperledger/fabric/protos/common"
2424
"github.com/hyperledger/fabric/protos/utils"
25+
"github.com/stretchr/testify/assert"
2526
)
2627

2728
func verifyItemsResult(t *testing.T, template Template, count int) {
@@ -38,21 +39,22 @@ func verifyItemsResult(t *testing.T, template Template, count int) {
3839

3940
for i, signedItem := range result {
4041
item := utils.UnmarshalConfigurationItemOrPanic(signedItem.ConfigurationItem)
41-
if item.Header.ChainID != newChainID {
42-
t.Errorf("Should have appropriately set new chainID")
43-
}
44-
if expected := fmt.Sprintf("%d", i); string(item.Value) != expected {
45-
t.Errorf("Expected %s but got %s", expected, item.Value)
46-
}
42+
assert.Equal(t, newChainID, item.Header.ChainID, "Should have appropriately set new chainID")
43+
expected := fmt.Sprintf("%d", i)
44+
assert.Equal(t, expected, string(item.Value), "Expected %s but got %s", expected, item.Value)
45+
assert.Equal(t, int32(cb.HeaderType_CONFIGURATION_ITEM), item.Header.Type)
4746
}
4847
}
4948

5049
func TestSimpleTemplate(t *testing.T) {
50+
hdr := &cb.ChainHeader{
51+
ChainID: "foo",
52+
Type: int32(cb.HeaderType_CONFIGURATION_ITEM),
53+
}
5154
simple := NewSimpleTemplate(
52-
&cb.ConfigurationItem{Value: []byte("0")},
53-
&cb.ConfigurationItem{Value: []byte("1")},
55+
&cb.ConfigurationItem{Value: []byte("0"), Header: hdr},
56+
&cb.ConfigurationItem{Value: []byte("1"), Header: hdr},
5457
)
55-
5658
verifyItemsResult(t, simple, 2)
5759
}
5860

0 commit comments

Comments
 (0)