Skip to content

Commit

Permalink
Merge "FAB-1683 configtx.Items() doesn't set header type"
Browse files Browse the repository at this point in the history
  • Loading branch information
JonathanLevi authored and Gerrit Code Review committed Jan 16, 2017
2 parents 28841b9 + bc3ee87 commit a158adb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
2 changes: 1 addition & 1 deletion common/configtx/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 11 additions & 9 deletions common/configtx/template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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)
}

Expand Down

0 comments on commit a158adb

Please sign in to comment.