github.com/yacovm/fabric@v2.0.0-alpha.0.20191128145320-c5d4087dc723+incompatible/common/capabilities/application_test.go (about)

     1  /*
     2  Copyright IBM Corp. All Rights Reserved.
     3  
     4  SPDX-License-Identifier: Apache-2.0
     5  */
     6  
     7  package capabilities
     8  
     9  import (
    10  	"testing"
    11  
    12  	cb "github.com/hyperledger/fabric-protos-go/common"
    13  	"github.com/stretchr/testify/assert"
    14  )
    15  
    16  func TestApplicationV10(t *testing.T) {
    17  	ap := NewApplicationProvider(map[string]*cb.Capability{})
    18  	assert.NoError(t, ap.Supported())
    19  }
    20  
    21  func TestApplicationV11(t *testing.T) {
    22  	ap := NewApplicationProvider(map[string]*cb.Capability{
    23  		ApplicationV1_1: {},
    24  	})
    25  	assert.NoError(t, ap.Supported())
    26  	assert.True(t, ap.ForbidDuplicateTXIdInBlock())
    27  	assert.True(t, ap.V1_1Validation())
    28  }
    29  
    30  func TestApplicationV12(t *testing.T) {
    31  	ap := NewApplicationProvider(map[string]*cb.Capability{
    32  		ApplicationV1_2: {},
    33  	})
    34  	assert.NoError(t, ap.Supported())
    35  	assert.True(t, ap.ForbidDuplicateTXIdInBlock())
    36  	assert.True(t, ap.V1_1Validation())
    37  	assert.True(t, ap.V1_2Validation())
    38  	assert.True(t, ap.ACLs())
    39  	assert.True(t, ap.CollectionUpgrade())
    40  	assert.True(t, ap.PrivateChannelData())
    41  }
    42  
    43  func TestApplicationV13(t *testing.T) {
    44  	ap := NewApplicationProvider(map[string]*cb.Capability{
    45  		ApplicationV1_3: {},
    46  	})
    47  	assert.NoError(t, ap.Supported())
    48  	assert.True(t, ap.ForbidDuplicateTXIdInBlock())
    49  	assert.True(t, ap.V1_1Validation())
    50  	assert.True(t, ap.V1_2Validation())
    51  	assert.True(t, ap.V1_3Validation())
    52  	assert.True(t, ap.KeyLevelEndorsement())
    53  	assert.True(t, ap.ACLs())
    54  	assert.True(t, ap.CollectionUpgrade())
    55  	assert.True(t, ap.PrivateChannelData())
    56  }
    57  
    58  func TestApplicationV142(t *testing.T) {
    59  	ap := NewApplicationProvider(map[string]*cb.Capability{
    60  		ApplicationV1_4_2: {},
    61  	})
    62  	assert.NoError(t, ap.Supported())
    63  	assert.True(t, ap.ForbidDuplicateTXIdInBlock())
    64  	assert.True(t, ap.V1_1Validation())
    65  	assert.True(t, ap.V1_2Validation())
    66  	assert.True(t, ap.V1_3Validation())
    67  	assert.True(t, ap.KeyLevelEndorsement())
    68  	assert.True(t, ap.ACLs())
    69  	assert.True(t, ap.CollectionUpgrade())
    70  	assert.True(t, ap.PrivateChannelData())
    71  	assert.True(t, ap.StorePvtDataOfInvalidTx())
    72  }
    73  
    74  func TestApplicationV20(t *testing.T) {
    75  	ap := NewApplicationProvider(map[string]*cb.Capability{
    76  		ApplicationV2_0: {},
    77  	})
    78  	assert.NoError(t, ap.Supported())
    79  	assert.True(t, ap.ForbidDuplicateTXIdInBlock())
    80  	assert.True(t, ap.V1_1Validation())
    81  	assert.True(t, ap.V1_2Validation())
    82  	assert.True(t, ap.V1_3Validation())
    83  	assert.True(t, ap.V2_0Validation())
    84  	assert.True(t, ap.KeyLevelEndorsement())
    85  	assert.True(t, ap.ACLs())
    86  	assert.True(t, ap.CollectionUpgrade())
    87  	assert.True(t, ap.PrivateChannelData())
    88  	assert.True(t, ap.LifecycleV20())
    89  	assert.True(t, ap.StorePvtDataOfInvalidTx())
    90  }
    91  
    92  func TestApplicationPvtDataExperimental(t *testing.T) {
    93  	ap := NewApplicationProvider(map[string]*cb.Capability{
    94  		ApplicationPvtDataExperimental: {},
    95  	})
    96  	assert.True(t, ap.PrivateChannelData())
    97  }
    98  
    99  func TestHasCapability(t *testing.T) {
   100  	ap := NewApplicationProvider(map[string]*cb.Capability{})
   101  	assert.True(t, ap.HasCapability(ApplicationV1_1))
   102  	assert.True(t, ap.HasCapability(ApplicationV1_2))
   103  	assert.True(t, ap.HasCapability(ApplicationV1_3))
   104  	assert.True(t, ap.HasCapability(ApplicationV2_0))
   105  	assert.True(t, ap.HasCapability(ApplicationPvtDataExperimental))
   106  	assert.True(t, ap.HasCapability(ApplicationResourcesTreeExperimental))
   107  	assert.False(t, ap.HasCapability("default"))
   108  }