Commit 6be352ae authored by Matthew Sykes's avatar Matthew Sykes Committed by Gari Singh
Browse files

[FAB-11130] add keys to unkeyed struct literals



Use of unkeyed struct literals is flagged as an issue by vet as
reordering the definition of fields in a struct can be problematic. It's
also an anti-pattern with respect to "useful" zero values in idiomatic
go.

Change-Id: I440484a5baf214364b964b157ecbd31df389a59f
Signed-off-by: default avatarMatthew Sykes <sykesmat@us.ibm.com>
parent 74f01e0b
...@@ -54,7 +54,9 @@ func (bh *MSPConfigHandler) ProposeMSP(mspConfig *mspprotos.MSPConfig) (msp.MSP, ...@@ -54,7 +54,9 @@ func (bh *MSPConfigHandler) ProposeMSP(mspConfig *mspprotos.MSPConfig) (msp.MSP,
} }
case int32(msp.IDEMIX): case int32(msp.IDEMIX):
// create the idemix msp instance // create the idemix msp instance
theMsp, err = msp.New(&msp.IdemixNewOpts{msp.NewBaseOpts{Version: bh.version}}) theMsp, err = msp.New(&msp.IdemixNewOpts{
NewBaseOpts: msp.NewBaseOpts{Version: bh.version},
})
if err != nil { if err != nil {
return nil, errors.WithMessage(err, "creating the MSP manager failed") return nil, errors.WithMessage(err, "creating the MSP manager failed")
} }
......
...@@ -461,15 +461,15 @@ func initializeCC(t *testing.T, chainID, ccname string, ccSide *mockpeer.MockCCC ...@@ -461,15 +461,15 @@ func initializeCC(t *testing.T, chainID, ccname string, ccSide *mockpeer.MockCCC
// full response // full response
// correct block number for ending sim // correct block number for ending sim
respSet = &mockpeer.MockResponseSet{errorFunc, nil, []*mockpeer.MockResponse{ respSet = &mockpeer.MockResponseSet{
{&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_TRANSACTION}, &pb.ChaincodeMessage{Type: pb.ChaincodeMessage_PUT_STATE, Payload: putils.MarshalOrPanic(&pb.PutState{Collection: "", Key: "A", Value: []byte("100")}), Txid: txid, ChannelId: chainID}}, DoneFunc: errorFunc,
{&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_RESPONSE}, &pb.ChaincodeMessage{Type: pb.ChaincodeMessage_PUT_STATE, Payload: putils.MarshalOrPanic(&pb.PutState{Collection: "", Key: "B", Value: []byte("200")}), Txid: txid, ChannelId: chainID}}, ErrorFunc: nil,
// The following private data parameters are disabled because Responses: []*mockpeer.MockResponse{
// this requires private data channel capability ON and hence should be present {&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_TRANSACTION}, &pb.ChaincodeMessage{Type: pb.ChaincodeMessage_PUT_STATE, Payload: putils.MarshalOrPanic(&pb.PutState{Collection: "", Key: "A", Value: []byte("100")}), Txid: txid, ChannelId: chainID}},
// in a dedicated test. One such test is present in file - executetransaction_pvtdata_test.go {&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_RESPONSE}, &pb.ChaincodeMessage{Type: pb.ChaincodeMessage_PUT_STATE, Payload: putils.MarshalOrPanic(&pb.PutState{Collection: "", Key: "B", Value: []byte("200")}), Txid: txid, ChannelId: chainID}},
// {&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_RESPONSE}, &pb.ChaincodeMessage{Type: pb.ChaincodeMessage_PUT_STATE, Payload: putils.MarshalOrPanic(&pb.PutState{Collection: "c1", Key: "C", Value: []byte("300")}), Txid: txid, ChannelId: chainID}}, {&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_RESPONSE}, &pb.ChaincodeMessage{Type: pb.ChaincodeMessage_COMPLETED, Payload: putils.MarshalOrPanic(&pb.Response{Status: shim.OK, Payload: []byte("OK")}), ChaincodeEvent: &pb.ChaincodeEvent{ChaincodeId: ccname}, Txid: txid, ChannelId: chainID}},
// {&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_RESPONSE}, &pb.ChaincodeMessage{Type: pb.ChaincodeMessage_PUT_STATE, Payload: putils.MarshalOrPanic(&pb.PutState{Collection: "c2", Key: "C", Value: []byte("300")}), Txid: txid, ChannelId: chainID}}, },
{&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_RESPONSE}, &pb.ChaincodeMessage{Type: pb.ChaincodeMessage_COMPLETED, Payload: putils.MarshalOrPanic(&pb.Response{Status: shim.OK, Payload: []byte("OK")}), ChaincodeEvent: &pb.ChaincodeEvent{ChaincodeId: ccname}, Txid: txid, ChannelId: chainID}}}} }
cccid.Version = "1" cccid.Version = "1"
execCC(t, ctxt, ccSide, cccid, false, false, done, cis, respSet, chaincodeSupport) execCC(t, ctxt, ccSide, cccid, false, false, done, cis, respSet, chaincodeSupport)
......
...@@ -17,7 +17,6 @@ import ( ...@@ -17,7 +17,6 @@ import (
"github.com/hyperledger/fabric/core/chaincode/platforms/ccmetadata" "github.com/hyperledger/fabric/core/chaincode/platforms/ccmetadata"
cutil "github.com/hyperledger/fabric/core/container/util" cutil "github.com/hyperledger/fabric/core/container/util"
pb "github.com/hyperledger/fabric/protos/peer" pb "github.com/hyperledger/fabric/protos/peer"
// "path/filepath"
) )
// Platform for java chaincodes in java // Platform for java chaincodes in java
......
This diff is collapsed.
...@@ -285,7 +285,9 @@ func (v *VsccValidatorImpl) getCDataForCC(chid, ccid string) (ccprovider.Chainco ...@@ -285,7 +285,9 @@ func (v *VsccValidatorImpl) getCDataForCC(chid, ccid string) (ccprovider.Chainco
bytes, err := qe.GetState("lscc", ccid) bytes, err := qe.GetState("lscc", ccid)
if err != nil { if err != nil {
return nil, &commonerrors.VSCCInfoLookupFailureError{fmt.Sprintf("Could not retrieve state for chaincode %s, error %s", ccid, err)} return nil, &commonerrors.VSCCInfoLookupFailureError{
Reason: fmt.Sprintf("Could not retrieve state for chaincode %s, error %s", ccid, err),
}
} }
if bytes == nil { if bytes == nil {
......
...@@ -34,7 +34,7 @@ func (c *mockStoreSupport) GetIdentityDeserializer(chainID string) msp.IdentityD ...@@ -34,7 +34,7 @@ func (c *mockStoreSupport) GetIdentityDeserializer(chainID string) msp.IdentityD
func TestCollectionStore(t *testing.T) { func TestCollectionStore(t *testing.T) {
wState := make(map[string]map[string][]byte) wState := make(map[string]map[string][]byte)
support := &mockStoreSupport{Qe: &lm.MockQueryExecutor{wState}} support := &mockStoreSupport{Qe: &lm.MockQueryExecutor{State: wState}}
cs := NewSimpleCollectionStore(support) cs := NewSimpleCollectionStore(support)
assert.NotNil(t, cs) assert.NotNil(t, cs)
...@@ -55,7 +55,9 @@ func TestCollectionStore(t *testing.T) { ...@@ -55,7 +55,9 @@ func TestCollectionStore(t *testing.T) {
_, err = cs.RetrieveCollection(ccr) _, err = cs.RetrieveCollection(ccr)
assert.Error(t, err) assert.Error(t, err)
cc := &common.CollectionConfig{Payload: &common.CollectionConfig_StaticCollectionConfig{&common.StaticCollectionConfig{Name: "mycollection"}}} cc := &common.CollectionConfig{Payload: &common.CollectionConfig_StaticCollectionConfig{
StaticCollectionConfig: &common.StaticCollectionConfig{Name: "mycollection"}},
}
ccp := &common.CollectionConfigPackage{Config: []*common.CollectionConfig{cc}} ccp := &common.CollectionConfigPackage{Config: []*common.CollectionConfig{cc}}
ccpBytes, err := proto.Marshal(ccp) ccpBytes, err := proto.Marshal(ccp)
assert.NoError(t, err) assert.NoError(t, err)
...@@ -70,8 +72,10 @@ func TestCollectionStore(t *testing.T) { ...@@ -70,8 +72,10 @@ func TestCollectionStore(t *testing.T) {
policyEnvelope := cauthdsl.Envelope(cauthdsl.Or(cauthdsl.SignedBy(0), cauthdsl.SignedBy(1)), signers) policyEnvelope := cauthdsl.Envelope(cauthdsl.Or(cauthdsl.SignedBy(0), cauthdsl.SignedBy(1)), signers)
accessPolicy := createCollectionPolicyConfig(policyEnvelope) accessPolicy := createCollectionPolicyConfig(policyEnvelope)
cc = &common.CollectionConfig{Payload: &common.CollectionConfig_StaticCollectionConfig{&common.StaticCollectionConfig{Name: "mycollection", MemberOrgsPolicy: accessPolicy}}} cc = &common.CollectionConfig{Payload: &common.CollectionConfig_StaticCollectionConfig{
ccp = &common.CollectionConfigPackage{[]*common.CollectionConfig{cc}} StaticCollectionConfig: &common.StaticCollectionConfig{Name: "mycollection", MemberOrgsPolicy: accessPolicy},
}}
ccp = &common.CollectionConfigPackage{Config: []*common.CollectionConfig{cc}}
ccpBytes, err = proto.Marshal(ccp) ccpBytes, err = proto.Marshal(ccp)
assert.NoError(t, err) assert.NoError(t, err)
assert.NotNil(t, ccpBytes) assert.NotNil(t, ccpBytes)
......
...@@ -91,7 +91,9 @@ func TestNewDeliverService(t *testing.T) { ...@@ -91,7 +91,9 @@ func TestNewDeliverService(t *testing.T) {
return blocksDeliverer, nil return blocksDeliverer, nil
} }
abcf := func(*grpc.ClientConn) orderer.AtomicBroadcastClient { abcf := func(*grpc.ClientConn) orderer.AtomicBroadcastClient {
return &mocks.MockAtomicBroadcastClient{blocksDeliverer} return &mocks.MockAtomicBroadcastClient{
BD: blocksDeliverer,
}
} }
connFactory := func(_ string) func(string) (*grpc.ClientConn, error) { connFactory := func(_ string) func(string) (*grpc.ClientConn, error) {
...@@ -109,10 +111,10 @@ func TestNewDeliverService(t *testing.T) { ...@@ -109,10 +111,10 @@ func TestNewDeliverService(t *testing.T) {
ConnFactory: connFactory, ConnFactory: connFactory,
}) })
assert.NoError(t, err) assert.NoError(t, err)
assert.NoError(t, service.StartDeliverForChannel("TEST_CHAINID", &mocks.MockLedgerInfo{0}, func() {})) assert.NoError(t, service.StartDeliverForChannel("TEST_CHAINID", &mocks.MockLedgerInfo{Height: 0}, func() {}))
// Lets start deliver twice // Lets start deliver twice
assert.Error(t, service.StartDeliverForChannel("TEST_CHAINID", &mocks.MockLedgerInfo{0}, func() {}), "can't start delivery") assert.Error(t, service.StartDeliverForChannel("TEST_CHAINID", &mocks.MockLedgerInfo{Height: 0}, func() {}), "can't start delivery")
// Lets stop deliver that not started // Lets stop deliver that not started
assert.Error(t, service.StopDeliverForChannel("TEST_CHAINID2"), "can't stop delivery") assert.Error(t, service.StopDeliverForChannel("TEST_CHAINID2"), "can't stop delivery")
...@@ -127,7 +129,7 @@ func TestNewDeliverService(t *testing.T) { ...@@ -127,7 +129,7 @@ func TestNewDeliverService(t *testing.T) {
assertBlockDissemination(0, gossipServiceAdapter.GossipBlockDisseminations, t) assertBlockDissemination(0, gossipServiceAdapter.GossipBlockDisseminations, t)
assert.Equal(t, atomic.LoadInt32(&blocksDeliverer.RecvCnt), atomic.LoadInt32(&gossipServiceAdapter.AddPayloadsCnt)) assert.Equal(t, atomic.LoadInt32(&blocksDeliverer.RecvCnt), atomic.LoadInt32(&gossipServiceAdapter.AddPayloadsCnt))
assert.Error(t, service.StartDeliverForChannel("TEST_CHAINID", &mocks.MockLedgerInfo{0}, func() {}), "Delivery service is stopping") assert.Error(t, service.StartDeliverForChannel("TEST_CHAINID", &mocks.MockLedgerInfo{Height: 0}, func() {}), "Delivery service is stopping")
assert.Error(t, service.StopDeliverForChannel("TEST_CHAINID"), "Delivery service is stopping") assert.Error(t, service.StopDeliverForChannel("TEST_CHAINID"), "Delivery service is stopping")
} }
......
...@@ -915,7 +915,7 @@ func TestValidateDeployWithCollection(t *testing.T) { ...@@ -915,7 +915,7 @@ func TestValidateDeployWithCollection(t *testing.T) {
coll2 := createCollectionConfig(collName2, policyEnvelope, requiredPeerCount, maximumPeerCount, blockToLive) coll2 := createCollectionConfig(collName2, policyEnvelope, requiredPeerCount, maximumPeerCount, blockToLive)
// Test 1: Deploy chaincode with a valid collection configs --> success // Test 1: Deploy chaincode with a valid collection configs --> success
ccp := &common.CollectionConfigPackage{[]*common.CollectionConfig{coll1, coll2}} ccp := &common.CollectionConfigPackage{Config: []*common.CollectionConfig{coll1, coll2}}
ccpBytes, err := proto.Marshal(ccp) ccpBytes, err := proto.Marshal(ccp)
assert.NoError(t, err) assert.NoError(t, err)
assert.NotNil(t, ccpBytes) assert.NotNil(t, ccpBytes)
...@@ -946,7 +946,7 @@ func TestValidateDeployWithCollection(t *testing.T) { ...@@ -946,7 +946,7 @@ func TestValidateDeployWithCollection(t *testing.T) {
// Test 2: Deploy the chaincode with duplicate collection configs --> no error as the // Test 2: Deploy the chaincode with duplicate collection configs --> no error as the
// peer is not in V1_2Validation mode // peer is not in V1_2Validation mode
ccp = &common.CollectionConfigPackage{[]*common.CollectionConfig{coll1, coll2, coll1}} ccp = &common.CollectionConfigPackage{Config: []*common.CollectionConfig{coll1, coll2, coll1}}
ccpBytes, err = proto.Marshal(ccp) ccpBytes, err = proto.Marshal(ccp)
assert.NoError(t, err) assert.NoError(t, err)
assert.NotNil(t, ccpBytes) assert.NotNil(t, ccpBytes)
...@@ -1308,7 +1308,7 @@ func validateUpgradeWithCollection(t *testing.T, V1_2Validation bool) { ...@@ -1308,7 +1308,7 @@ func validateUpgradeWithCollection(t *testing.T, V1_2Validation bool) {
// V1_2Validation enabled: success // V1_2Validation enabled: success
// V1_2Validation disable: fail (as no collection updates are allowed) // V1_2Validation disable: fail (as no collection updates are allowed)
// Note: We might change V1_2Validation with CollectionUpdate capability // Note: We might change V1_2Validation with CollectionUpdate capability
ccp := &common.CollectionConfigPackage{[]*common.CollectionConfig{coll1, coll2}} ccp := &common.CollectionConfigPackage{Config: []*common.CollectionConfig{coll1, coll2}}
ccpBytes, err := proto.Marshal(ccp) ccpBytes, err := proto.Marshal(ccp)
assert.NoError(t, err) assert.NoError(t, err)
assert.NotNil(t, ccpBytes) assert.NotNil(t, ccpBytes)
...@@ -1351,7 +1351,7 @@ func validateUpgradeWithCollection(t *testing.T, V1_2Validation bool) { ...@@ -1351,7 +1351,7 @@ func validateUpgradeWithCollection(t *testing.T, V1_2Validation bool) {
// Test 2: some existing collections are missing in the updated config and peer in // Test 2: some existing collections are missing in the updated config and peer in
// V1_2Validation mode --> error // V1_2Validation mode --> error
ccp = &common.CollectionConfigPackage{[]*common.CollectionConfig{coll3}} ccp = &common.CollectionConfigPackage{Config: []*common.CollectionConfig{coll3}}
ccpBytes, err = proto.Marshal(ccp) ccpBytes, err = proto.Marshal(ccp)
assert.NoError(t, err) assert.NoError(t, err)
assert.NotNil(t, ccpBytes) assert.NotNil(t, ccpBytes)
...@@ -1376,7 +1376,7 @@ func validateUpgradeWithCollection(t *testing.T, V1_2Validation bool) { ...@@ -1376,7 +1376,7 @@ func validateUpgradeWithCollection(t *testing.T, V1_2Validation bool) {
// Test 3: some existing collections are missing in the updated config and peer in // Test 3: some existing collections are missing in the updated config and peer in
// V1_2Validation mode --> error // V1_2Validation mode --> error
ccp = &common.CollectionConfigPackage{[]*common.CollectionConfig{coll1, coll3}} ccp = &common.CollectionConfigPackage{Config: []*common.CollectionConfig{coll1, coll3}}
ccpBytes, err = proto.Marshal(ccp) ccpBytes, err = proto.Marshal(ccp)
assert.NoError(t, err) assert.NoError(t, err)
assert.NotNil(t, ccpBytes) assert.NotNil(t, ccpBytes)
...@@ -1401,7 +1401,7 @@ func validateUpgradeWithCollection(t *testing.T, V1_2Validation bool) { ...@@ -1401,7 +1401,7 @@ func validateUpgradeWithCollection(t *testing.T, V1_2Validation bool) {
ccver = "3" ccver = "3"
// Test 4: valid collection config config and peer in V1_2Validation mode --> success // Test 4: valid collection config config and peer in V1_2Validation mode --> success
ccp = &common.CollectionConfigPackage{[]*common.CollectionConfig{coll1, coll2, coll3}} ccp = &common.CollectionConfigPackage{Config: []*common.CollectionConfig{coll1, coll2, coll3}}
ccpBytes, err = proto.Marshal(ccp) ccpBytes, err = proto.Marshal(ccp)
assert.NoError(t, err) assert.NoError(t, err)
assert.NotNil(t, ccpBytes) assert.NotNil(t, ccpBytes)
...@@ -1707,7 +1707,7 @@ func createCollectionConfig(collectionName string, signaturePolicyEnvelope *comm ...@@ -1707,7 +1707,7 @@ func createCollectionConfig(collectionName string, signaturePolicyEnvelope *comm
return &common.CollectionConfig{ return &common.CollectionConfig{
Payload: &common.CollectionConfig_StaticCollectionConfig{ Payload: &common.CollectionConfig_StaticCollectionConfig{
&common.StaticCollectionConfig{ StaticCollectionConfig: &common.StaticCollectionConfig{
Name: collectionName, Name: collectionName,
MemberOrgsPolicy: accessPolicy, MemberOrgsPolicy: accessPolicy,
RequiredPeerCount: requiredPeerCount, RequiredPeerCount: requiredPeerCount,
...@@ -1721,7 +1721,7 @@ func createCollectionConfig(collectionName string, signaturePolicyEnvelope *comm ...@@ -1721,7 +1721,7 @@ func createCollectionConfig(collectionName string, signaturePolicyEnvelope *comm
func testValidateCollection(t *testing.T, v *ValidatorOneValidSignature, collectionConfigs []*common.CollectionConfig, cdRWSet *ccprovider.ChaincodeData, func testValidateCollection(t *testing.T, v *ValidatorOneValidSignature, collectionConfigs []*common.CollectionConfig, cdRWSet *ccprovider.ChaincodeData,
lsccFunc string, ac channelconfig.ApplicationCapabilities, chid string, lsccFunc string, ac channelconfig.ApplicationCapabilities, chid string,
) error { ) error {
ccp := &common.CollectionConfigPackage{collectionConfigs} ccp := &common.CollectionConfigPackage{Config: collectionConfigs}
ccpBytes, err := proto.Marshal(ccp) ccpBytes, err := proto.Marshal(ccp)
assert.NoError(t, err) assert.NoError(t, err)
assert.NotNil(t, ccpBytes) assert.NotNil(t, ccpBytes)
...@@ -1849,7 +1849,7 @@ func TestValidateRWSetAndCollectionForDeploy(t *testing.T) { ...@@ -1849,7 +1849,7 @@ func TestValidateRWSetAndCollectionForDeploy(t *testing.T) {
assert.EqualError(t, err, "collection-name: mycollection3 -- error in member org policy: signature policy is not an OR concatenation, NOutOf 2") assert.EqualError(t, err, "collection-name: mycollection3 -- error in member org policy: signature policy is not an OR concatenation, NOutOf 2")
// Test 13: deploy with existing collection config on the ledger -> error // Test 13: deploy with existing collection config on the ledger -> error
ccp := &common.CollectionConfigPackage{[]*common.CollectionConfig{coll1}} ccp := &common.CollectionConfigPackage{Config: []*common.CollectionConfig{coll1}}
ccpBytes, err := proto.Marshal(ccp) ccpBytes, err := proto.Marshal(ccp)
assert.NoError(t, err) assert.NoError(t, err)
state["lscc"][privdata.BuildCollectionKVSKey(ccid)] = ccpBytes state["lscc"][privdata.BuildCollectionKVSKey(ccid)] = ccpBytes
...@@ -1888,7 +1888,7 @@ func TestValidateRWSetAndCollectionForUpgrade(t *testing.T) { ...@@ -1888,7 +1888,7 @@ func TestValidateRWSetAndCollectionForUpgrade(t *testing.T) {
coll2 := createCollectionConfig(collName2, policyEnvelope, requiredPeerCount, maximumPeerCount, blockToLive) coll2 := createCollectionConfig(collName2, policyEnvelope, requiredPeerCount, maximumPeerCount, blockToLive)
coll3 := createCollectionConfig(collName3, policyEnvelope, requiredPeerCount, maximumPeerCount, blockToLive) coll3 := createCollectionConfig(collName3, policyEnvelope, requiredPeerCount, maximumPeerCount, blockToLive)
ccp := &common.CollectionConfigPackage{[]*common.CollectionConfig{coll1, coll2}} ccp := &common.CollectionConfigPackage{Config: []*common.CollectionConfig{coll1, coll2}}
ccpBytes, err := proto.Marshal(ccp) ccpBytes, err := proto.Marshal(ccp)
assert.NoError(t, err) assert.NoError(t, err)
......
...@@ -74,7 +74,7 @@ func TestValidateAndPreparePvtBatch(t *testing.T) { ...@@ -74,7 +74,7 @@ func TestValidateAndPreparePvtBatch(t *testing.T) {
pubSimulationResults = append(pubSimulationResults, res) pubSimulationResults = append(pubSimulationResults, res)
// Add tx1 private rwset to the private data map // Add tx1 private rwset to the private data map
tx1PvtData := &ledger.TxPvtData{0, tx1SimulationResults.PvtSimulationResults} tx1PvtData := &ledger.TxPvtData{SeqInBlock: 0, WriteSet: tx1SimulationResults.PvtSimulationResults}
pvtDataMap[uint64(0)] = tx1PvtData pvtDataMap[uint64(0)] = tx1PvtData
// Tx 2 // Tx 2
...@@ -99,7 +99,7 @@ func TestValidateAndPreparePvtBatch(t *testing.T) { ...@@ -99,7 +99,7 @@ func TestValidateAndPreparePvtBatch(t *testing.T) {
pubSimulationResults = append(pubSimulationResults, res) pubSimulationResults = append(pubSimulationResults, res)
// Add tx3 private rwset to the private data map // Add tx3 private rwset to the private data map
tx3PvtData := &ledger.TxPvtData{2, tx3SimulationResults.PvtSimulationResults} tx3PvtData := &ledger.TxPvtData{SeqInBlock: 2, WriteSet: tx3SimulationResults.PvtSimulationResults}
pvtDataMap[uint64(2)] = tx3PvtData pvtDataMap[uint64(2)] = tx3PvtData
// Construct a block using all three transactions' simulation results // Construct a block using all three transactions' simulation results
......
...@@ -32,7 +32,14 @@ import ( ...@@ -32,7 +32,14 @@ import (
func TestCheckPolicyInvalidArgs(t *testing.T) { func TestCheckPolicyInvalidArgs(t *testing.T) {
policyManagerGetter := &mocks.MockChannelPolicyManagerGetter{ policyManagerGetter := &mocks.MockChannelPolicyManagerGetter{
Managers: map[string]policies.Manager{ Managers: map[string]policies.Manager{
"A": &mocks.MockChannelPolicyManager{&mocks.MockPolicy{&mocks.MockIdentityDeserializer{[]byte("Alice"), []byte("msg1")}}}, "A": &mocks.MockChannelPolicyManager{
MockPolicy: &mocks.MockPolicy{
Deserializer: &mocks.MockIdentityDeserializer{
Identity: []byte("Alice"),
Msg: []byte("msg1"),
},
},
},
}, },
} }
pc := &policyChecker{channelPolicyManagerGetter: policyManagerGetter} pc := &policyChecker{channelPolicyManagerGetter: policyManagerGetter}
...@@ -54,7 +61,14 @@ func TestRegisterPolicyCheckerFactoryInvalidArgs(t *testing.T) { ...@@ -54,7 +61,14 @@ func TestRegisterPolicyCheckerFactoryInvalidArgs(t *testing.T) {
func TestRegisterPolicyCheckerFactory(t *testing.T) { func TestRegisterPolicyCheckerFactory(t *testing.T) {
policyManagerGetter := &mocks.MockChannelPolicyManagerGetter{ policyManagerGetter := &mocks.MockChannelPolicyManagerGetter{
Managers: map[string]policies.Manager{ Managers: map[string]policies.Manager{
"A": &mocks.MockChannelPolicyManager{&mocks.MockPolicy{&mocks.MockIdentityDeserializer{[]byte("Alice"), []byte("msg1")}}}, "A": &mocks.MockChannelPolicyManager{
MockPolicy: &mocks.MockPolicy{
Deserializer: &mocks.MockIdentityDeserializer{
Identity: []byte("Alice"),
Msg: []byte("msg1"),
},
},
},
}, },
} }
pc := &policyChecker{channelPolicyManagerGetter: policyManagerGetter} pc := &policyChecker{channelPolicyManagerGetter: policyManagerGetter}
...@@ -70,7 +84,13 @@ func TestRegisterPolicyCheckerFactory(t *testing.T) { ...@@ -70,7 +84,13 @@ func TestRegisterPolicyCheckerFactory(t *testing.T) {
func TestCheckPolicyBySignedDataInvalidArgs(t *testing.T) { func TestCheckPolicyBySignedDataInvalidArgs(t *testing.T) {
policyManagerGetter := &mocks.MockChannelPolicyManagerGetter{ policyManagerGetter := &mocks.MockChannelPolicyManagerGetter{
Managers: map[string]policies.Manager{ Managers: map[string]policies.Manager{
"A": &mocks.MockChannelPolicyManager{&mocks.MockPolicy{&mocks.MockIdentityDeserializer{[]byte("Alice"), []byte("msg1")}}}, "A": &mocks.MockChannelPolicyManager{
MockPolicy: &mocks.MockPolicy{
Deserializer: &mocks.MockIdentityDeserializer{
Identity: []byte("Alice"),
Msg: []byte("msg1"),
}},
},
}, },
} }
pc := &policyChecker{channelPolicyManagerGetter: policyManagerGetter} pc := &policyChecker{channelPolicyManagerGetter: policyManagerGetter}
...@@ -98,13 +118,31 @@ func TestCheckPolicyBySignedDataInvalidArgs(t *testing.T) { ...@@ -98,13 +118,31 @@ func TestCheckPolicyBySignedDataInvalidArgs(t *testing.T) {
func TestPolicyCheckerInvalidArgs(t *testing.T) { func TestPolicyCheckerInvalidArgs(t *testing.T) {
policyManagerGetter := &mocks.MockChannelPolicyManagerGetter{ policyManagerGetter := &mocks.MockChannelPolicyManagerGetter{
map[string]policies.Manager{ Managers: map[string]policies.Manager{
"A": &mocks.MockChannelPolicyManager{&mocks.MockPolicy{&mocks.MockIdentityDeserializer{[]byte("Alice"), []byte("msg1")}}}, "A": &mocks.MockChannelPolicyManager{
"B": &mocks.MockChannelPolicyManager{&mocks.MockPolicy{&mocks.MockIdentityDeserializer{[]byte("Bob"), []byte("msg2")}}}, MockPolicy: &mocks.MockPolicy{Deserializer: &mocks.MockIdentityDeserializer{
"C": &mocks.MockChannelPolicyManager{&mocks.MockPolicy{&mocks.MockIdentityDeserializer{[]byte("Alice"), []byte("msg3")}}}, Identity: []byte("Alice"),
Msg: []byte("msg1"),
}},
},
"B": &mocks.MockChannelPolicyManager{
MockPolicy: &mocks.MockPolicy{Deserializer: &mocks.MockIdentityDeserializer{
Identity: []byte("Bob"),
Msg: []byte("msg2"),
}},
},
"C": &mocks.MockChannelPolicyManager{
MockPolicy: &mocks.MockPolicy{Deserializer: &mocks.MockIdentityDeserializer{
Identity: []byte("Alice"),
Msg: []byte("msg3"),
}},
},
}, },
} }
identityDeserializer := &mocks.MockIdentityDeserializer{[]byte("Alice"), []byte("msg1")} identityDeserializer := &mocks.MockIdentityDeserializer{
Identity: []byte("Alice"),
Msg: []byte("msg1"),
}
pc := NewPolicyChecker( pc := NewPolicyChecker(
policyManagerGetter, policyManagerGetter,
identityDeserializer, identityDeserializer,
...@@ -134,13 +172,34 @@ func TestPolicyCheckerInvalidArgs(t *testing.T) { ...@@ -134,13 +172,34 @@ func TestPolicyCheckerInvalidArgs(t *testing.T) {
func TestPolicyChecker(t *testing.T) { func TestPolicyChecker(t *testing.T) {
policyManagerGetter := &mocks.MockChannelPolicyManagerGetter{ policyManagerGetter := &mocks.MockChannelPolicyManagerGetter{
map[string]policies.Manager{ Managers: map[string]policies.Manager{
"A": &mocks.MockChannelPolicyManager{&mocks.MockPolicy{&mocks.MockIdentityDeserializer{[]byte("Alice"), []byte("msg1")}}}, "A": &mocks.MockChannelPolicyManager{
"B": &mocks.MockChannelPolicyManager{&mocks.MockPolicy{&mocks.MockIdentityDeserializer{[]byte("Bob"), []byte("msg2")}}}, MockPolicy: &mocks.MockPolicy{
"C": &mocks.MockChannelPolicyManager{&mocks.MockPolicy{&mocks.MockIdentityDeserializer{[]byte("Alice"), []byte("msg3")}}}, Deserializer: &mocks.MockIdentityDeserializer{Identity: []byte("Alice"), Msg: []byte("msg1")},
},
},
"B": &mocks.MockChannelPolicyManager{
MockPolicy: &mocks.MockPolicy{
Deserializer: &mocks.MockIdentityDeserializer{
Identity: []byte("Bob"),
Msg: []byte("msg2"),
},
},
},
"C": &mocks.MockChannelPolicyManager{
MockPolicy: &mocks.MockPolicy{
Deserializer: &mocks.MockIdentityDeserializer{
Identity: []byte("Alice"),
Msg: []byte("msg3"),
},
},
},
}, },
} }
identityDeserializer := &mocks.MockIdentityDeserializer{[]byte("Alice"), []byte("msg1")} identityDeserializer := &mocks.MockIdentityDeserializer{
Identity: []byte("Alice"),
Msg: []byte("msg1"),
}
pc := NewPolicyChecker( pc := NewPolicyChecker(
policyManagerGetter, policyManagerGetter,
identityDeserializer, identityDeserializer,
......
...@@ -137,7 +137,10 @@ func TestInstall(t *testing.T) { ...@@ -137,7 +137,10 @@ func TestInstall(t *testing.T) {
} }
func testInstall(t *testing.T, ccname string, version string, path string, createInvalidIndex bool, expectedErrorMsg string, caller string, scc *LifeCycleSysCC, stub *shim.MockStub) { func testInstall(t *testing.T, ccname string, version string, path string, createInvalidIndex bool, expectedErrorMsg string, caller string, scc *LifeCycleSysCC, stub *shim.MockStub) {
identityDeserializer := &policymocks.MockIdentityDeserializer{[]byte("Alice"), []byte("msg1")} identityDeserializer := &policymocks.MockIdentityDeserializer{
Identity: []byte("Alice"),
Msg: []byte("msg1"),
}
policyManagerGetter := &policymocks.MockChannelPolicyManagerGetter{ policyManagerGetter := &policymocks.MockChannelPolicyManagerGetter{
Managers: map[string]policies.Manager{ Managers: map[string]policies.Manager{
"test": &policymocks.MockChannelPolicyManager{MockPolicy: &policymocks.MockPolicy{Deserializer: identityDeserializer}}, "test": &policymocks.MockChannelPolicyManager{MockPolicy: &policymocks.MockPolicy{Deserializer: identityDeserializer}},
...@@ -263,7 +266,7 @@ func TestDeploy(t *testing.T) { ...@@ -263,7 +266,7 @@ func TestDeploy(t *testing.T) {
maximumPeerCount = 2 maximumPeerCount = 2
coll1 := createCollectionConfig(collName1, policyEnvelope, requiredPeerCount, maximumPeerCount) coll1 := createCollectionConfig(collName1, policyEnvelope, requiredPeerCount, maximumPeerCount)
ccp := &common.CollectionConfigPackage{[]*common.CollectionConfig{coll1}} ccp := &common.CollectionConfigPackage{Config: []*common.CollectionConfig{coll1}}
ccpBytes, err := proto.Marshal(ccp) ccpBytes, err := proto.Marshal(ccp)
assert.NoError(t, err) assert.NoError(t, err)
assert.NotNil(t, ccpBytes) assert.NotNil(t, ccpBytes)
...@@ -311,7 +314,7 @@ func createCollectionConfig(collectionName string, signaturePolicyEnvelope *comm ...@@ -311,7 +314,7 @@ func createCollectionConfig(collectionName string, signaturePolicyEnvelope *comm
return &common.CollectionConfig{ return &common.CollectionConfig{
Payload: &common.CollectionConfig_StaticCollectionConfig{ Payload: &common.CollectionConfig_StaticCollectionConfig{
&common.StaticCollectionConfig{ StaticCollectionConfig: &common.StaticCollectionConfig{
Name: collectionName, Name: collectionName,
MemberOrgsPolicy: accessPolicy, MemberOrgsPolicy: accessPolicy,
RequiredPeerCount: requiredPeerCount, RequiredPeerCount: requiredPeerCount,
...@@ -331,7 +334,7 @@ func testDeploy(t *testing.T, ccname string, version string, path string, forceB ...@@ -331,7 +334,7 @@ func testDeploy(t *testing.T, ccname string, version string, path string, forceB
} }
stub.ChannelID = chainid stub.ChannelID = chainid
identityDeserializer := &policymocks.MockIdentityDeserializer{[]byte("Alice"), []byte("msg1")} identityDeserializer := &policymocks.MockIdentityDeserializer{Identity: []byte("Alice"), Msg: []byte("msg1")}
policyManagerGetter := &policymocks.MockChannelPolicyManagerGetter{ policyManagerGetter := &policymocks.MockChannelPolicyManagerGetter{
Managers: map[string]policies.Manager{ Managers: map[string]policies.Manager{
"test": &policymocks.MockChannelPolicyManager{MockPolicy: &policymocks.MockPolicy{Deserializer: identityDeserializer}}, "test": &policymocks.MockChannelPolicyManager{MockPolicy: &policymocks.MockPolicy{Deserializer: identityDeserializer}},
...@@ -502,7 +505,7 @@ func TestUpgrade(t *testing.T) { ...@@ -502,7 +505,7 @@ func TestUpgrade(t *testing.T) {
maximumPeerCount = 2 maximumPeerCount = 2
coll1 := createCollectionConfig(collName1, policyEnvelope, requiredPeerCount, maximumPeerCount) coll1 := createCollectionConfig(collName1, policyEnvelope, requiredPeerCount, maximumPeerCount)
ccp := &common.CollectionConfigPackage{[]*common.CollectionConfig{coll1}} ccp := &common.CollectionConfigPackage{Config: []*common.CollectionConfig{coll1}}
ccpBytes, err := proto.Marshal(ccp) ccpBytes, err := proto.Marshal(ccp)
assert.NoError(t, err) assert.NoError(t, err)
assert.NotNil(t, ccpBytes) assert.NotNil(t, ccpBytes)
...@@ -626,7 +629,7 @@ func TestFunctionsWithAliases(t *testing.T) { ...@@ -626,7 +629,7 @@ func TestFunctionsWithAliases(t *testing.T) {
res := stub.MockInit("1", nil) res := stub.MockInit("1", nil)
assert.Equal(t, int32(shim.OK), res.Status, res.Message) assert.Equal(t, int32(shim.OK), res.Status, res.Message)