Skip to content

Commit

Permalink
[FAB-6088] Add v1.1 application capabilities flag
Browse files Browse the repository at this point in the history
This CR adds parsing of the V1.1 capabilities flag to the application
capabilities group.  It additionally fixes the orderer capabilities
group to be in line with the same pattern followed by the channel and
applications group as well as adds some additional unit tests for the
orderer capabilities.

Change-Id: Ic39d2fbbece96b74de7bfffec7df2729ab51453d
Signed-off-by: Jason Yellick <jyellick@us.ibm.com>
  • Loading branch information
Jason Yellick committed Oct 12, 2017
1 parent 376c2ca commit 978c48c
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 8 deletions.
23 changes: 18 additions & 5 deletions common/capabilities/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,43 @@ import (

const (
applicationTypeName = "Application"

// ApplicationV1_1 is the capabilties string for standard new non-backwards compatible fabric v1.1 application capabilities.
ApplicationV1_1 = "V1.1"
)

// ApplicationProvider provides capabilities information for application level config.
type ApplicationProvider struct {
*registry
v11 bool
}

// NewApplicationProvider creates a application capabilities provider.
func NewApplicationProvider(capabilities map[string]*cb.Capability) *ApplicationProvider {
cp := &ApplicationProvider{}
cp.registry = newRegistry(cp, capabilities)
return cp
ap := &ApplicationProvider{}
ap.registry = newRegistry(ap, capabilities)
_, ap.v11 = capabilities[ApplicationV1_1]
return ap
}

// Type returns a descriptive string for logging purposes.
func (cp *ApplicationProvider) Type() string {
func (ap *ApplicationProvider) Type() string {
return applicationTypeName
}

// HasCapability returns true if the capability is supported by this binary.
func (cp *ApplicationProvider) HasCapability(capability string) bool {
func (ap *ApplicationProvider) HasCapability(capability string) bool {
switch capability {
// Add new capability names here
case ApplicationV1_1:
return true
default:
return false
}
}

// LifecycleViaConfig returns true if chaincode lifecycle should be managed via the resources config
// tree rather than via the deprecated v1.0 endorser tx mechanism.
func (ap *ApplicationProvider) LifecycleViaConfig() bool {
return ap.v11
}
29 changes: 29 additions & 0 deletions common/capabilities/application_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
Copyright IBM Corp. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/

package capabilities

import (
"testing"

cb "github.com/hyperledger/fabric/protos/common"

"github.com/stretchr/testify/assert"
)

func TestApplicationV10(t *testing.T) {
op := NewApplicationProvider(map[string]*cb.Capability{})
assert.NoError(t, op.Supported())
assert.False(t, op.LifecycleViaConfig())
}

func TestApplicationV11(t *testing.T) {
op := NewApplicationProvider(map[string]*cb.Capability{
ApplicationV1_1: &cb.Capability{},
})
assert.NoError(t, op.Supported())
assert.True(t, op.LifecycleViaConfig())
}
8 changes: 6 additions & 2 deletions common/capabilities/orderer.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ import (

const (
ordererTypeName = "Orderer"
OrdererV11 = "V1.1"

// OrdererV1_1 is the capabilties string for standard new non-backwards compatible fabric v1.1 orderer capabilities.
OrdererV1_1 = "V1.1"
)

// OrdererProvider provides capabilities information for orderer level config.
Expand All @@ -25,7 +27,7 @@ type OrdererProvider struct {
func NewOrdererProvider(capabilities map[string]*cb.Capability) *OrdererProvider {
cp := &OrdererProvider{}
cp.registry = newRegistry(cp, capabilities)
_, cp.v11BugFixes = capabilities[OrdererV11]
_, cp.v11BugFixes = capabilities[OrdererV1_1]
return cp
}

Expand All @@ -38,6 +40,8 @@ func (cp *OrdererProvider) Type() string {
func (cp *OrdererProvider) HasCapability(capability string) bool {
switch capability {
// Add new capability names here
case OrdererV1_1:
return true
default:
return false
}
Expand Down
29 changes: 29 additions & 0 deletions common/capabilities/orderer_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
Copyright IBM Corp. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/

package capabilities

import (
"testing"

cb "github.com/hyperledger/fabric/protos/common"

"github.com/stretchr/testify/assert"
)

func TestOrdererV10(t *testing.T) {
op := NewOrdererProvider(map[string]*cb.Capability{})
assert.NoError(t, op.Supported())
assert.False(t, op.SetChannelModPolicyDuringCreate())
}

func TestOrdererV11(t *testing.T) {
op := NewOrdererProvider(map[string]*cb.Capability{
OrdererV1_1: &cb.Capability{},
})
assert.NoError(t, op.Supported())
assert.True(t, op.SetChannelModPolicyDuringCreate())
}
2 changes: 1 addition & 1 deletion orderer/common/msgprocessor/systemchannel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ func TestNewChannelConfig(t *testing.T) {
channelID := "foo"
gConf := genesisconfig.Load(genesisconfig.SampleSingleMSPSoloProfile)
gConf.Orderer.Capabilities = map[string]bool{
capabilities.OrdererV11: true,
capabilities.OrdererV1_1: true,
}
singleMSPGenesisBlock := provisional.New(gConf).GenesisBlockForChannel(channelID)
configEnv := configtx.UnmarshalConfigEnvelopeOrPanic(
Expand Down

0 comments on commit 978c48c

Please sign in to comment.