Skip to content

Commit

Permalink
regenerate ledger testdata using release-1.1
Browse files Browse the repository at this point in the history
we need to regenerate the testdata using fabric-release v1.1 with the full
definition of collection configs including MembersOrgsPolicy. This is necessary
as one of the stateUpdate listener (i.e., collElgNotifier) compares the existing
MembersOrgsPolicy with the new MembersOrgsPolicy (during upgrade tx) to perform
certain tasks in the ledger. As the existing test data does not contain
MembersOrgsPolicy in the used collectionConfigPkg, it leads to nil pointer
exception.

This CR creates a new testdata with fabric-release v1.1 using
https://gerrit.hyperledger.org/r/#/c/22749/ (which is updated to include
the MembersOrgsPolicy in the collectionConfigPkg)

This CR also enables the v11 ledger test.

FAB-12969 #done

Change-Id: I3d8353145ca7f753f82805b7802d7a68fde9d638
Signed-off-by: senthil <cendhu@gmail.com>
Signed-off-by: manish <manish.sethi@gmail.com>
(cherry picked from commit aefa370)
  • Loading branch information
cendhu authored and manish-sethi committed Dec 12, 2018
1 parent e485f77 commit 05d99ad
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 46 deletions.
14 changes: 7 additions & 7 deletions core/ledger/kvledger/tests/sample_data_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,17 +249,17 @@ func (d *sampleDataHelper) sampleVal(val, ledgerid string) string {

func (d *sampleDataHelper) sampleCollConf1(ledgerid, ccName string) []*collConf {
return []*collConf{
{name: "coll1"},
{name: ledgerid},
{name: ccName},
{name: "coll1", members: []string{"org1", "org2"}},
{name: ledgerid, members: []string{"org1", "org2"}},
{name: ccName, members: []string{"org1", "org2"}},
}
}

func (d *sampleDataHelper) sampleCollConf2(ledgerid string, ccName string) []*collConf {
return []*collConf{
{name: "coll1"},
{name: "coll2"},
{name: ledgerid},
{name: ccName},
{name: "coll1", members: []string{"org1", "org2"}},
{name: "coll2", members: []string{"org1", "org2"}},
{name: ledgerid, members: []string{"org1", "org2"}},
{name: ccName, members: []string{"org1", "org2"}},
}
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
55 changes: 34 additions & 21 deletions core/ledger/kvledger/tests/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ var logger = flogging.MustGetLogger("test2")
// use 'collConf' as parameters and return values and transform back and forth to/from proto
// message internally (using func 'convertToCollConfigProtoBytes' and 'convertFromCollConfigProto')
type collConf struct {
name string
btl uint64
name string
btl uint64
members []string
}

type txAndPvtdata struct {
Expand All @@ -39,41 +40,53 @@ type txAndPvtdata struct {
func convertToCollConfigProtoBytes(collConfs []*collConf) ([]byte, error) {
var protoConfArray []*common.CollectionConfig
for _, c := range collConfs {
protoConf := &common.CollectionConfig{Payload: &common.CollectionConfig_StaticCollectionConfig{
StaticCollectionConfig: &common.StaticCollectionConfig{
Name: c.name,
BlockToLive: c.btl,
MemberOrgsPolicy: getAccessPolicy([]string{"peer0", "peer1"})}}}
protoConf := &common.CollectionConfig{
Payload: &common.CollectionConfig_StaticCollectionConfig{
StaticCollectionConfig: &common.StaticCollectionConfig{
Name: c.name,
BlockToLive: c.btl,
MemberOrgsPolicy: convertToMemberOrgsPolicy(c.members),
},
},
}
protoConfArray = append(protoConfArray, protoConf)
}
return proto.Marshal(&common.CollectionConfigPackage{Config: protoConfArray})
}

func getAccessPolicy(signers []string) *common.CollectionPolicyConfig {
func convertToMemberOrgsPolicy(members []string) *common.CollectionPolicyConfig {
var data [][]byte
for _, signer := range signers {
data = append(data, []byte(signer))
for _, member := range members {
data = append(data, []byte(member))
}
return &common.CollectionPolicyConfig{
Payload: &common.CollectionPolicyConfig_SignaturePolicy{
SignaturePolicy: cauthdsl.Envelope(cauthdsl.Or(cauthdsl.SignedBy(0), cauthdsl.SignedBy(1)), data),
},
}
policyEnvelope := cauthdsl.Envelope(cauthdsl.Or(cauthdsl.SignedBy(0), cauthdsl.SignedBy(1)), data)
return createCollectionPolicyConfig(policyEnvelope)
}

func createCollectionPolicyConfig(accessPolicy *common.SignaturePolicyEnvelope) *common.CollectionPolicyConfig {
cpcSp := &common.CollectionPolicyConfig_SignaturePolicy{
SignaturePolicy: accessPolicy,
}
cpc := &common.CollectionPolicyConfig{
Payload: cpcSp,
func convertFromMemberOrgsPolicy(policy *common.CollectionPolicyConfig) []string {
ids := policy.GetSignaturePolicy().Identities
var members []string
for _, id := range ids {
members = append(members, string(id.Principal))
}
return cpc
return members
}

func convertFromCollConfigProto(collConfPkg *common.CollectionConfigPackage) []*collConf {
var collConfs []*collConf
protoConfArray := collConfPkg.Config
for _, protoConf := range protoConfArray {
name, btl := protoConf.GetStaticCollectionConfig().Name, protoConf.GetStaticCollectionConfig().BlockToLive
collConfs = append(collConfs, &collConf{name, btl})
p := protoConf.GetStaticCollectionConfig()
collConfs = append(collConfs,
&collConf{
name: p.Name,
btl: p.BlockToLive,
members: convertFromMemberOrgsPolicy(p.MemberOrgsPolicy),
},
)
}
return collConfs
}
Expand Down
26 changes: 8 additions & 18 deletions core/ledger/kvledger/tests/v11_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,8 @@ import (

// TestV11 tests that a ledgersData folder created by v1.1 can be used with future releases in a backward compatible way
func TestV11(t *testing.T) {
// TODO: FAB-12969
// we need to regenerate the testdata using fabric-release v1.1 with the full
// definition of collection configs including MembersOrgsPolicy. This is
// necessary as one of the stateUpdate listener compares the existing
// MembersOrgsPolicy with the new MembersOrgsPolicy (during upgrade tx) to
// perform certain tasks in the ledger. As the existing test data does not
// contain MembersOrgsPolicy in the used collectionConfigPkg, it leads to
// nil pointer exception during execution of this test. Hence, this
// test is skipped for now.
t.Skip()
fsPath := defaultConfig["peer.fileSystemPath"].(string)
// this test data was generated by v1.1 code https://gerrit.hyperledger.org/r/#/c/22749/1/core/ledger/kvledger/tests/v11_generate_test.go@22
// this test data was generated by v1.1 code https://gerrit.hyperledger.org/r/#/c/22749/6/core/ledger/kvledger/tests/v11_generate_test.go@22
testutil.CopyDir("testdata/v11/sample_ledgers/ledgersData", fsPath)
env := newEnv(defaultConfig, t)
defer env.cleanup()
Expand Down Expand Up @@ -134,17 +124,17 @@ func (d *v11SampleDataHelper) sampleVal(val, ledgerid string) string {

func (d *v11SampleDataHelper) sampleCollConf1(ledgerid, ccName string) []*collConf {
return []*collConf{
{name: "coll1"},
{name: ledgerid},
{name: ccName},
{name: "coll1", members: []string{"org1", "org2"}},
{name: ledgerid, members: []string{"org1", "org2"}},
{name: ccName, members: []string{"org1", "org2"}},
}
}

func (d *v11SampleDataHelper) sampleCollConf2(ledgerid string, ccName string) []*collConf {
return []*collConf{
{name: "coll1"},
{name: "coll2"},
{name: ledgerid},
{name: ccName},
{name: "coll1", members: []string{"org1", "org2"}},
{name: "coll2", members: []string{"org1", "org2"}},
{name: ledgerid, members: []string{"org1", "org2"}},
{name: ccName, members: []string{"org1", "org2"}},
}
}

0 comments on commit 05d99ad

Please sign in to comment.