From bc3ee8779ae036de62a374f841ff918af6d4a0d2 Mon Sep 17 00:00:00 2001 From: YACOVM Date: Mon, 16 Jan 2017 22:45:08 +0200 Subject: [PATCH] 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 Change-Id: I24ea3ada0e3df34fd2fbe0250cafd37f068f23e8 --- common/configtx/template.go | 2 +- common/configtx/template_test.go | 20 +++++++++++--------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/common/configtx/template.go b/common/configtx/template.go index 56b6541e5dc..4aa9a7559db 100644 --- a/common/configtx/template.go +++ b/common/configtx/template.go @@ -53,7 +53,7 @@ func NewSimpleTemplate(items ...*cb.ConfigurationItem) Template { func (st *simpleTemplate) Items(chainID string) ([]*cb.SignedConfigurationItem, error) { signedItems := make([]*cb.SignedConfigurationItem, len(st.items)) for i := range st.items { - st.items[i].Header = &cb.ChainHeader{ChainID: chainID} + st.items[i].Header = &cb.ChainHeader{ChainID: chainID, Type: int32(cb.HeaderType_CONFIGURATION_ITEM)} mItem, err := proto.Marshal(st.items[i]) if err != nil { return nil, err diff --git a/common/configtx/template_test.go b/common/configtx/template_test.go index 77c8d52a5e0..0ebefa1cd8e 100644 --- a/common/configtx/template_test.go +++ b/common/configtx/template_test.go @@ -22,6 +22,7 @@ import ( cb "github.com/hyperledger/fabric/protos/common" "github.com/hyperledger/fabric/protos/utils" + "github.com/stretchr/testify/assert" ) func verifyItemsResult(t *testing.T, template Template, count int) { @@ -38,21 +39,22 @@ func verifyItemsResult(t *testing.T, template Template, count int) { for i, signedItem := range result { item := utils.UnmarshalConfigurationItemOrPanic(signedItem.ConfigurationItem) - if item.Header.ChainID != newChainID { - t.Errorf("Should have appropriately set new chainID") - } - if expected := fmt.Sprintf("%d", i); string(item.Value) != expected { - t.Errorf("Expected %s but got %s", expected, item.Value) - } + assert.Equal(t, newChainID, item.Header.ChainID, "Should have appropriately set new chainID") + expected := fmt.Sprintf("%d", i) + assert.Equal(t, expected, string(item.Value), "Expected %s but got %s", expected, item.Value) + assert.Equal(t, int32(cb.HeaderType_CONFIGURATION_ITEM), item.Header.Type) } } func TestSimpleTemplate(t *testing.T) { + hdr := &cb.ChainHeader{ + ChainID: "foo", + Type: int32(cb.HeaderType_CONFIGURATION_ITEM), + } simple := NewSimpleTemplate( - &cb.ConfigurationItem{Value: []byte("0")}, - &cb.ConfigurationItem{Value: []byte("1")}, + &cb.ConfigurationItem{Value: []byte("0"), Header: hdr}, + &cb.ConfigurationItem{Value: []byte("1"), Header: hdr}, ) - verifyItemsResult(t, simple, 2) }