github.com/fnagchunpeng/fabric@v2.1.1+incompatible/core/endorser/pvtrwset_assembler_test.go (about)

     1  /*
     2   *
     3   * Copyright IBM Corp. All Rights Reserved.
     4   *
     5   * SPDX-License-Identifier: Apache-2.0
     6   * /
     7   *
     8   */
     9  
    10  package endorser
    11  
    12  import (
    13  	"testing"
    14  
    15  	"github.com/hyperledger/fabric-protos-go/ledger/rwset"
    16  	"github.com/hyperledger/fabric-protos-go/peer"
    17  	"github.com/hyperledger/fabric/core/ledger"
    18  	"github.com/hyperledger/fabric/core/ledger/mock"
    19  	"github.com/stretchr/testify/assert"
    20  )
    21  
    22  func TestAssemblePvtRWSet(t *testing.T) {
    23  	collectionsConfigCC1 := &peer.CollectionConfigPackage{
    24  		Config: []*peer.CollectionConfig{
    25  			{
    26  				Payload: &peer.CollectionConfig_StaticCollectionConfig{
    27  					StaticCollectionConfig: &peer.StaticCollectionConfig{
    28  						Name: "mycollection-1",
    29  					},
    30  				},
    31  			},
    32  			{
    33  				Payload: &peer.CollectionConfig_StaticCollectionConfig{
    34  					StaticCollectionConfig: &peer.StaticCollectionConfig{
    35  						Name: "mycollection-2",
    36  					},
    37  				},
    38  			},
    39  		},
    40  	}
    41  
    42  	mockDeployedCCInfoProvider := &mock.DeployedChaincodeInfoProvider{}
    43  	mockDeployedCCInfoProvider.ChaincodeInfoReturns(
    44  		&ledger.DeployedChaincodeInfo{
    45  			ExplicitCollectionConfigPkg: collectionsConfigCC1,
    46  			Name:                        "myCC",
    47  		},
    48  		nil,
    49  	)
    50  	mockDeployedCCInfoProvider.AllCollectionsConfigPkgReturns(collectionsConfigCC1, nil)
    51  
    52  	privData := &rwset.TxPvtReadWriteSet{
    53  		DataModel: rwset.TxReadWriteSet_KV,
    54  		NsPvtRwset: []*rwset.NsPvtReadWriteSet{
    55  			{
    56  				Namespace: "myCC",
    57  				CollectionPvtRwset: []*rwset.CollectionPvtReadWriteSet{
    58  					{
    59  						CollectionName: "mycollection-1",
    60  						Rwset:          []byte{1, 2, 3, 4, 5, 6, 7, 8},
    61  					},
    62  				},
    63  			},
    64  		},
    65  	}
    66  
    67  	pvtReadWriteSetWithConfigInfo, err := AssemblePvtRWSet("", privData, nil, mockDeployedCCInfoProvider)
    68  	assert.NoError(t, err)
    69  	assert.NotNil(t, pvtReadWriteSetWithConfigInfo)
    70  	assert.NotNil(t, pvtReadWriteSetWithConfigInfo.PvtRwset)
    71  	configPackages := pvtReadWriteSetWithConfigInfo.CollectionConfigs
    72  	assert.NotNil(t, configPackages)
    73  	configs, found := configPackages["myCC"]
    74  	assert.True(t, found)
    75  	assert.Equal(t, 1, len(configs.Config))
    76  	assert.NotNil(t, configs.Config[0])
    77  	assert.NotNil(t, configs.Config[0].GetStaticCollectionConfig())
    78  	assert.Equal(t, "mycollection-1", configs.Config[0].GetStaticCollectionConfig().Name)
    79  	assert.Equal(t, 1, len(pvtReadWriteSetWithConfigInfo.PvtRwset.NsPvtRwset))
    80  
    81  }