From d68294ccd3733a13ec4fa4efc2b2d14aa4fcd63d Mon Sep 17 00:00:00 2001 From: Matthew B White Date: Mon, 24 Oct 2022 14:29:31 +0100 Subject: [PATCH] Wire in the PurgePD capability check to the tx simulator Signed-off-by: Matthew B White --- CONTRIBUTING.md | 20 +++ common/channelconfig/api.go | 4 + core/chaincode/handler.go | 16 ++ core/chaincode/handler_test.go | 12 ++ .../mock/application_capabilities.go | 156 +++++++++++++----- .../mock/application_capabilities.go | 156 +++++++++++++----- core/chaincode/mock/application_config.go | 21 ++- .../mocks/application_capabilities.go | 31 +++- .../scc/lscc/mock/application_capabilities.go | 156 +++++++++++++----- gossip/privdata/coordinator_test.go | 26 +-- gossip/privdata/mocks/app_capabilities.go | 61 +++++-- gossip/state/state_test.go | 2 +- 12 files changed, 504 insertions(+), 157 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 2117c9ec9b5..0fb0c483203 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -7,5 +7,25 @@ Please visit the [contributors guide](http://hyperledger-fabric.readthedocs.io/en/latest/CONTRIBUTING.html) in the docs to learn how to make contributions to this exciting project. +## Running Unit tests + +An example of using the script as used in the CI pipeline to run Unit Tests + +``` +TEST_PKGS=github.com/hyperledger/fabric/core/chaincode/... ./scripts/run-unit-tests.sh +``` + +## Creating the mocks for unit tests + +A number of mock implementations of interfaces are used within the unit tests. For historical reasons there are two tools +with the repo to generate these mocks. [mockery](https://github.com/vektra/mockery) and [counterfeiter](https://github.com/maxbrunsfeld/counterfeiter) + +- look in the already created mock - the first line will indicate which tool it was created with +- for counterfieter, run `go generate .//...` in the where you want the mocks directory to be created + +- for mockery the command is `mockery --name ApplicationCapabilities --dir ~/github.com/hyperledger/fabric/common/channelconfig --filename application_capabilities.go` + - this will create the mock with the filename given in the mocks directory based of the cwd + - the `--name` and `--dir` indicate where the 'source' interface is to be mocked + Creative Commons License
This work is licensed under a Creative Commons Attribution 4.0 International License. s diff --git a/common/channelconfig/api.go b/common/channelconfig/api.go index d4f03933255..7de7fb74b3f 100644 --- a/common/channelconfig/api.go +++ b/common/channelconfig/api.go @@ -194,6 +194,10 @@ type ApplicationCapabilities interface { // KeyLevelEndorsement returns true if this channel supports endorsement // policies expressible at a ledger key granularity, as described in FAB-8812 KeyLevelEndorsement() bool + + // PurgePvtData returns true if this channel supports purging of private + // data entries + PurgePvtData() bool } // OrdererCapabilities defines the capabilities for the orderer portion of a channel diff --git a/core/chaincode/handler.go b/core/chaincode/handler.go index c7b1fb60b59..b2378fb9379 100644 --- a/core/chaincode/handler.go +++ b/core/chaincode/handler.go @@ -553,6 +553,18 @@ func (h *Handler) checkMetadataCap(msg *pb.ChaincodeMessage) error { return nil } +func (h *Handler) checkPurgePrivateDataCap(msg *pb.ChaincodeMessage) error { + ac, exists := h.AppConfig.GetApplicationConfig(msg.ChannelId) + if !exists { + return errors.Errorf("application config does not exist for %s", msg.ChannelId) + } + + if !ac.Capabilities().PurgePvtData() { + return errors.New("purge private data is not enabled, channel application capability of V2_5 or later is required") + } + return nil +} + func errorIfCreatorHasNoReadPermission(chaincodeName, collection string, txContext *TransactionContext) error { rwPermission, err := getReadWritePermission(chaincodeName, collection, txContext) if err != nil { @@ -1080,6 +1092,10 @@ func (h *Handler) HandleDelState(msg *pb.ChaincodeMessage, txContext *Transactio } func (h *Handler) HandlePurgePrivateData(msg *pb.ChaincodeMessage, txContext *TransactionContext) (*pb.ChaincodeMessage, error) { + err := h.checkPurgePrivateDataCap(msg) + if err != nil { + return nil, err + } delState := &pb.DelState{} if err := proto.Unmarshal(msg.Payload, delState); err != nil { return nil, errors.Wrap(err, "unmarshal failed") diff --git a/core/chaincode/handler_test.go b/core/chaincode/handler_test.go index 7190e641fe2..290fdd45843 100644 --- a/core/chaincode/handler_test.go +++ b/core/chaincode/handler_test.go @@ -87,6 +87,7 @@ var _ = Describe("Handler", func() { fakeApplicationConfig := &mock.ApplicationConfig{} fakeCapabilites = &mock.ApplicationCapabilities{} fakeCapabilites.KeyLevelEndorsementReturns(true) + fakeCapabilites.PurgePvtDataReturns(true) fakeApplicationConfig.CapabilitiesReturns(fakeCapabilites) fakeApplicationConfigRetriever = &fake.ApplicationConfigRetriever{} fakeApplicationConfigRetriever.GetApplicationConfigReturns(fakeApplicationConfig, true) @@ -680,6 +681,17 @@ var _ = Describe("Handler", func() { }) }) + Context("when purge private data is not supported", func() { + BeforeEach(func() { + fakeCapabilites.PurgePvtDataReturns(false) + }) + + It("returns an error", func() { + _, err := handler.HandlePurgePrivateData(incomingMessage, txContext) + Expect(err).To(MatchError("purge private data is not enabled, channel application capability of V2_5 or later is required")) + }) + }) + Context("when unmarshalling the request fails", func() { BeforeEach(func() { incomingMessage.Payload = []byte("this-is-a-bogus-payload") diff --git a/core/chaincode/lifecycle/mock/application_capabilities.go b/core/chaincode/lifecycle/mock/application_capabilities.go index 2ccdd6dfd83..69fff8dcbf9 100644 --- a/core/chaincode/lifecycle/mock/application_capabilities.go +++ b/core/chaincode/lifecycle/mock/application_capabilities.go @@ -76,6 +76,16 @@ type ApplicationCapabilities struct { privateChannelDataReturnsOnCall map[int]struct { result1 bool } + PurgePvtDataStub func() bool + purgePvtDataMutex sync.RWMutex + purgePvtDataArgsForCall []struct { + } + purgePvtDataReturns struct { + result1 bool + } + purgePvtDataReturnsOnCall map[int]struct { + result1 bool + } StorePvtDataOfInvalidTxStub func() bool storePvtDataOfInvalidTxMutex sync.RWMutex storePvtDataOfInvalidTxArgsForCall []struct { @@ -145,15 +155,16 @@ func (fake *ApplicationCapabilities) ACLs() bool { ret, specificReturn := fake.aCLsReturnsOnCall[len(fake.aCLsArgsForCall)] fake.aCLsArgsForCall = append(fake.aCLsArgsForCall, struct { }{}) + stub := fake.ACLsStub + fakeReturns := fake.aCLsReturns fake.recordInvocation("ACLs", []interface{}{}) fake.aCLsMutex.Unlock() - if fake.ACLsStub != nil { - return fake.ACLsStub() + if stub != nil { + return stub() } if specificReturn { return ret.result1 } - fakeReturns := fake.aCLsReturns return fakeReturns.result1 } @@ -197,15 +208,16 @@ func (fake *ApplicationCapabilities) CollectionUpgrade() bool { ret, specificReturn := fake.collectionUpgradeReturnsOnCall[len(fake.collectionUpgradeArgsForCall)] fake.collectionUpgradeArgsForCall = append(fake.collectionUpgradeArgsForCall, struct { }{}) + stub := fake.CollectionUpgradeStub + fakeReturns := fake.collectionUpgradeReturns fake.recordInvocation("CollectionUpgrade", []interface{}{}) fake.collectionUpgradeMutex.Unlock() - if fake.CollectionUpgradeStub != nil { - return fake.CollectionUpgradeStub() + if stub != nil { + return stub() } if specificReturn { return ret.result1 } - fakeReturns := fake.collectionUpgradeReturns return fakeReturns.result1 } @@ -249,15 +261,16 @@ func (fake *ApplicationCapabilities) ForbidDuplicateTXIdInBlock() bool { ret, specificReturn := fake.forbidDuplicateTXIdInBlockReturnsOnCall[len(fake.forbidDuplicateTXIdInBlockArgsForCall)] fake.forbidDuplicateTXIdInBlockArgsForCall = append(fake.forbidDuplicateTXIdInBlockArgsForCall, struct { }{}) + stub := fake.ForbidDuplicateTXIdInBlockStub + fakeReturns := fake.forbidDuplicateTXIdInBlockReturns fake.recordInvocation("ForbidDuplicateTXIdInBlock", []interface{}{}) fake.forbidDuplicateTXIdInBlockMutex.Unlock() - if fake.ForbidDuplicateTXIdInBlockStub != nil { - return fake.ForbidDuplicateTXIdInBlockStub() + if stub != nil { + return stub() } if specificReturn { return ret.result1 } - fakeReturns := fake.forbidDuplicateTXIdInBlockReturns return fakeReturns.result1 } @@ -301,15 +314,16 @@ func (fake *ApplicationCapabilities) KeyLevelEndorsement() bool { ret, specificReturn := fake.keyLevelEndorsementReturnsOnCall[len(fake.keyLevelEndorsementArgsForCall)] fake.keyLevelEndorsementArgsForCall = append(fake.keyLevelEndorsementArgsForCall, struct { }{}) + stub := fake.KeyLevelEndorsementStub + fakeReturns := fake.keyLevelEndorsementReturns fake.recordInvocation("KeyLevelEndorsement", []interface{}{}) fake.keyLevelEndorsementMutex.Unlock() - if fake.KeyLevelEndorsementStub != nil { - return fake.KeyLevelEndorsementStub() + if stub != nil { + return stub() } if specificReturn { return ret.result1 } - fakeReturns := fake.keyLevelEndorsementReturns return fakeReturns.result1 } @@ -353,15 +367,16 @@ func (fake *ApplicationCapabilities) LifecycleV20() bool { ret, specificReturn := fake.lifecycleV20ReturnsOnCall[len(fake.lifecycleV20ArgsForCall)] fake.lifecycleV20ArgsForCall = append(fake.lifecycleV20ArgsForCall, struct { }{}) + stub := fake.LifecycleV20Stub + fakeReturns := fake.lifecycleV20Returns fake.recordInvocation("LifecycleV20", []interface{}{}) fake.lifecycleV20Mutex.Unlock() - if fake.LifecycleV20Stub != nil { - return fake.LifecycleV20Stub() + if stub != nil { + return stub() } if specificReturn { return ret.result1 } - fakeReturns := fake.lifecycleV20Returns return fakeReturns.result1 } @@ -405,15 +420,16 @@ func (fake *ApplicationCapabilities) MetadataLifecycle() bool { ret, specificReturn := fake.metadataLifecycleReturnsOnCall[len(fake.metadataLifecycleArgsForCall)] fake.metadataLifecycleArgsForCall = append(fake.metadataLifecycleArgsForCall, struct { }{}) + stub := fake.MetadataLifecycleStub + fakeReturns := fake.metadataLifecycleReturns fake.recordInvocation("MetadataLifecycle", []interface{}{}) fake.metadataLifecycleMutex.Unlock() - if fake.MetadataLifecycleStub != nil { - return fake.MetadataLifecycleStub() + if stub != nil { + return stub() } if specificReturn { return ret.result1 } - fakeReturns := fake.metadataLifecycleReturns return fakeReturns.result1 } @@ -457,15 +473,16 @@ func (fake *ApplicationCapabilities) PrivateChannelData() bool { ret, specificReturn := fake.privateChannelDataReturnsOnCall[len(fake.privateChannelDataArgsForCall)] fake.privateChannelDataArgsForCall = append(fake.privateChannelDataArgsForCall, struct { }{}) + stub := fake.PrivateChannelDataStub + fakeReturns := fake.privateChannelDataReturns fake.recordInvocation("PrivateChannelData", []interface{}{}) fake.privateChannelDataMutex.Unlock() - if fake.PrivateChannelDataStub != nil { - return fake.PrivateChannelDataStub() + if stub != nil { + return stub() } if specificReturn { return ret.result1 } - fakeReturns := fake.privateChannelDataReturns return fakeReturns.result1 } @@ -504,20 +521,74 @@ func (fake *ApplicationCapabilities) PrivateChannelDataReturnsOnCall(i int, resu }{result1} } +func (fake *ApplicationCapabilities) PurgePvtData() bool { + fake.purgePvtDataMutex.Lock() + ret, specificReturn := fake.purgePvtDataReturnsOnCall[len(fake.purgePvtDataArgsForCall)] + fake.purgePvtDataArgsForCall = append(fake.purgePvtDataArgsForCall, struct { + }{}) + stub := fake.PurgePvtDataStub + fakeReturns := fake.purgePvtDataReturns + fake.recordInvocation("PurgePvtData", []interface{}{}) + fake.purgePvtDataMutex.Unlock() + if stub != nil { + return stub() + } + if specificReturn { + return ret.result1 + } + return fakeReturns.result1 +} + +func (fake *ApplicationCapabilities) PurgePvtDataCallCount() int { + fake.purgePvtDataMutex.RLock() + defer fake.purgePvtDataMutex.RUnlock() + return len(fake.purgePvtDataArgsForCall) +} + +func (fake *ApplicationCapabilities) PurgePvtDataCalls(stub func() bool) { + fake.purgePvtDataMutex.Lock() + defer fake.purgePvtDataMutex.Unlock() + fake.PurgePvtDataStub = stub +} + +func (fake *ApplicationCapabilities) PurgePvtDataReturns(result1 bool) { + fake.purgePvtDataMutex.Lock() + defer fake.purgePvtDataMutex.Unlock() + fake.PurgePvtDataStub = nil + fake.purgePvtDataReturns = struct { + result1 bool + }{result1} +} + +func (fake *ApplicationCapabilities) PurgePvtDataReturnsOnCall(i int, result1 bool) { + fake.purgePvtDataMutex.Lock() + defer fake.purgePvtDataMutex.Unlock() + fake.PurgePvtDataStub = nil + if fake.purgePvtDataReturnsOnCall == nil { + fake.purgePvtDataReturnsOnCall = make(map[int]struct { + result1 bool + }) + } + fake.purgePvtDataReturnsOnCall[i] = struct { + result1 bool + }{result1} +} + func (fake *ApplicationCapabilities) StorePvtDataOfInvalidTx() bool { fake.storePvtDataOfInvalidTxMutex.Lock() ret, specificReturn := fake.storePvtDataOfInvalidTxReturnsOnCall[len(fake.storePvtDataOfInvalidTxArgsForCall)] fake.storePvtDataOfInvalidTxArgsForCall = append(fake.storePvtDataOfInvalidTxArgsForCall, struct { }{}) + stub := fake.StorePvtDataOfInvalidTxStub + fakeReturns := fake.storePvtDataOfInvalidTxReturns fake.recordInvocation("StorePvtDataOfInvalidTx", []interface{}{}) fake.storePvtDataOfInvalidTxMutex.Unlock() - if fake.StorePvtDataOfInvalidTxStub != nil { - return fake.StorePvtDataOfInvalidTxStub() + if stub != nil { + return stub() } if specificReturn { return ret.result1 } - fakeReturns := fake.storePvtDataOfInvalidTxReturns return fakeReturns.result1 } @@ -561,15 +632,16 @@ func (fake *ApplicationCapabilities) Supported() error { ret, specificReturn := fake.supportedReturnsOnCall[len(fake.supportedArgsForCall)] fake.supportedArgsForCall = append(fake.supportedArgsForCall, struct { }{}) + stub := fake.SupportedStub + fakeReturns := fake.supportedReturns fake.recordInvocation("Supported", []interface{}{}) fake.supportedMutex.Unlock() - if fake.SupportedStub != nil { - return fake.SupportedStub() + if stub != nil { + return stub() } if specificReturn { return ret.result1 } - fakeReturns := fake.supportedReturns return fakeReturns.result1 } @@ -613,15 +685,16 @@ func (fake *ApplicationCapabilities) V1_1Validation() bool { ret, specificReturn := fake.v1_1ValidationReturnsOnCall[len(fake.v1_1ValidationArgsForCall)] fake.v1_1ValidationArgsForCall = append(fake.v1_1ValidationArgsForCall, struct { }{}) + stub := fake.V1_1ValidationStub + fakeReturns := fake.v1_1ValidationReturns fake.recordInvocation("V1_1Validation", []interface{}{}) fake.v1_1ValidationMutex.Unlock() - if fake.V1_1ValidationStub != nil { - return fake.V1_1ValidationStub() + if stub != nil { + return stub() } if specificReturn { return ret.result1 } - fakeReturns := fake.v1_1ValidationReturns return fakeReturns.result1 } @@ -665,15 +738,16 @@ func (fake *ApplicationCapabilities) V1_2Validation() bool { ret, specificReturn := fake.v1_2ValidationReturnsOnCall[len(fake.v1_2ValidationArgsForCall)] fake.v1_2ValidationArgsForCall = append(fake.v1_2ValidationArgsForCall, struct { }{}) + stub := fake.V1_2ValidationStub + fakeReturns := fake.v1_2ValidationReturns fake.recordInvocation("V1_2Validation", []interface{}{}) fake.v1_2ValidationMutex.Unlock() - if fake.V1_2ValidationStub != nil { - return fake.V1_2ValidationStub() + if stub != nil { + return stub() } if specificReturn { return ret.result1 } - fakeReturns := fake.v1_2ValidationReturns return fakeReturns.result1 } @@ -717,15 +791,16 @@ func (fake *ApplicationCapabilities) V1_3Validation() bool { ret, specificReturn := fake.v1_3ValidationReturnsOnCall[len(fake.v1_3ValidationArgsForCall)] fake.v1_3ValidationArgsForCall = append(fake.v1_3ValidationArgsForCall, struct { }{}) + stub := fake.V1_3ValidationStub + fakeReturns := fake.v1_3ValidationReturns fake.recordInvocation("V1_3Validation", []interface{}{}) fake.v1_3ValidationMutex.Unlock() - if fake.V1_3ValidationStub != nil { - return fake.V1_3ValidationStub() + if stub != nil { + return stub() } if specificReturn { return ret.result1 } - fakeReturns := fake.v1_3ValidationReturns return fakeReturns.result1 } @@ -769,15 +844,16 @@ func (fake *ApplicationCapabilities) V2_0Validation() bool { ret, specificReturn := fake.v2_0ValidationReturnsOnCall[len(fake.v2_0ValidationArgsForCall)] fake.v2_0ValidationArgsForCall = append(fake.v2_0ValidationArgsForCall, struct { }{}) + stub := fake.V2_0ValidationStub + fakeReturns := fake.v2_0ValidationReturns fake.recordInvocation("V2_0Validation", []interface{}{}) fake.v2_0ValidationMutex.Unlock() - if fake.V2_0ValidationStub != nil { - return fake.V2_0ValidationStub() + if stub != nil { + return stub() } if specificReturn { return ret.result1 } - fakeReturns := fake.v2_0ValidationReturns return fakeReturns.result1 } @@ -833,6 +909,8 @@ func (fake *ApplicationCapabilities) Invocations() map[string][][]interface{} { defer fake.metadataLifecycleMutex.RUnlock() fake.privateChannelDataMutex.RLock() defer fake.privateChannelDataMutex.RUnlock() + fake.purgePvtDataMutex.RLock() + defer fake.purgePvtDataMutex.RUnlock() fake.storePvtDataOfInvalidTxMutex.RLock() defer fake.storePvtDataOfInvalidTxMutex.RUnlock() fake.supportedMutex.RLock() diff --git a/core/chaincode/mock/application_capabilities.go b/core/chaincode/mock/application_capabilities.go index 2ccdd6dfd83..69fff8dcbf9 100644 --- a/core/chaincode/mock/application_capabilities.go +++ b/core/chaincode/mock/application_capabilities.go @@ -76,6 +76,16 @@ type ApplicationCapabilities struct { privateChannelDataReturnsOnCall map[int]struct { result1 bool } + PurgePvtDataStub func() bool + purgePvtDataMutex sync.RWMutex + purgePvtDataArgsForCall []struct { + } + purgePvtDataReturns struct { + result1 bool + } + purgePvtDataReturnsOnCall map[int]struct { + result1 bool + } StorePvtDataOfInvalidTxStub func() bool storePvtDataOfInvalidTxMutex sync.RWMutex storePvtDataOfInvalidTxArgsForCall []struct { @@ -145,15 +155,16 @@ func (fake *ApplicationCapabilities) ACLs() bool { ret, specificReturn := fake.aCLsReturnsOnCall[len(fake.aCLsArgsForCall)] fake.aCLsArgsForCall = append(fake.aCLsArgsForCall, struct { }{}) + stub := fake.ACLsStub + fakeReturns := fake.aCLsReturns fake.recordInvocation("ACLs", []interface{}{}) fake.aCLsMutex.Unlock() - if fake.ACLsStub != nil { - return fake.ACLsStub() + if stub != nil { + return stub() } if specificReturn { return ret.result1 } - fakeReturns := fake.aCLsReturns return fakeReturns.result1 } @@ -197,15 +208,16 @@ func (fake *ApplicationCapabilities) CollectionUpgrade() bool { ret, specificReturn := fake.collectionUpgradeReturnsOnCall[len(fake.collectionUpgradeArgsForCall)] fake.collectionUpgradeArgsForCall = append(fake.collectionUpgradeArgsForCall, struct { }{}) + stub := fake.CollectionUpgradeStub + fakeReturns := fake.collectionUpgradeReturns fake.recordInvocation("CollectionUpgrade", []interface{}{}) fake.collectionUpgradeMutex.Unlock() - if fake.CollectionUpgradeStub != nil { - return fake.CollectionUpgradeStub() + if stub != nil { + return stub() } if specificReturn { return ret.result1 } - fakeReturns := fake.collectionUpgradeReturns return fakeReturns.result1 } @@ -249,15 +261,16 @@ func (fake *ApplicationCapabilities) ForbidDuplicateTXIdInBlock() bool { ret, specificReturn := fake.forbidDuplicateTXIdInBlockReturnsOnCall[len(fake.forbidDuplicateTXIdInBlockArgsForCall)] fake.forbidDuplicateTXIdInBlockArgsForCall = append(fake.forbidDuplicateTXIdInBlockArgsForCall, struct { }{}) + stub := fake.ForbidDuplicateTXIdInBlockStub + fakeReturns := fake.forbidDuplicateTXIdInBlockReturns fake.recordInvocation("ForbidDuplicateTXIdInBlock", []interface{}{}) fake.forbidDuplicateTXIdInBlockMutex.Unlock() - if fake.ForbidDuplicateTXIdInBlockStub != nil { - return fake.ForbidDuplicateTXIdInBlockStub() + if stub != nil { + return stub() } if specificReturn { return ret.result1 } - fakeReturns := fake.forbidDuplicateTXIdInBlockReturns return fakeReturns.result1 } @@ -301,15 +314,16 @@ func (fake *ApplicationCapabilities) KeyLevelEndorsement() bool { ret, specificReturn := fake.keyLevelEndorsementReturnsOnCall[len(fake.keyLevelEndorsementArgsForCall)] fake.keyLevelEndorsementArgsForCall = append(fake.keyLevelEndorsementArgsForCall, struct { }{}) + stub := fake.KeyLevelEndorsementStub + fakeReturns := fake.keyLevelEndorsementReturns fake.recordInvocation("KeyLevelEndorsement", []interface{}{}) fake.keyLevelEndorsementMutex.Unlock() - if fake.KeyLevelEndorsementStub != nil { - return fake.KeyLevelEndorsementStub() + if stub != nil { + return stub() } if specificReturn { return ret.result1 } - fakeReturns := fake.keyLevelEndorsementReturns return fakeReturns.result1 } @@ -353,15 +367,16 @@ func (fake *ApplicationCapabilities) LifecycleV20() bool { ret, specificReturn := fake.lifecycleV20ReturnsOnCall[len(fake.lifecycleV20ArgsForCall)] fake.lifecycleV20ArgsForCall = append(fake.lifecycleV20ArgsForCall, struct { }{}) + stub := fake.LifecycleV20Stub + fakeReturns := fake.lifecycleV20Returns fake.recordInvocation("LifecycleV20", []interface{}{}) fake.lifecycleV20Mutex.Unlock() - if fake.LifecycleV20Stub != nil { - return fake.LifecycleV20Stub() + if stub != nil { + return stub() } if specificReturn { return ret.result1 } - fakeReturns := fake.lifecycleV20Returns return fakeReturns.result1 } @@ -405,15 +420,16 @@ func (fake *ApplicationCapabilities) MetadataLifecycle() bool { ret, specificReturn := fake.metadataLifecycleReturnsOnCall[len(fake.metadataLifecycleArgsForCall)] fake.metadataLifecycleArgsForCall = append(fake.metadataLifecycleArgsForCall, struct { }{}) + stub := fake.MetadataLifecycleStub + fakeReturns := fake.metadataLifecycleReturns fake.recordInvocation("MetadataLifecycle", []interface{}{}) fake.metadataLifecycleMutex.Unlock() - if fake.MetadataLifecycleStub != nil { - return fake.MetadataLifecycleStub() + if stub != nil { + return stub() } if specificReturn { return ret.result1 } - fakeReturns := fake.metadataLifecycleReturns return fakeReturns.result1 } @@ -457,15 +473,16 @@ func (fake *ApplicationCapabilities) PrivateChannelData() bool { ret, specificReturn := fake.privateChannelDataReturnsOnCall[len(fake.privateChannelDataArgsForCall)] fake.privateChannelDataArgsForCall = append(fake.privateChannelDataArgsForCall, struct { }{}) + stub := fake.PrivateChannelDataStub + fakeReturns := fake.privateChannelDataReturns fake.recordInvocation("PrivateChannelData", []interface{}{}) fake.privateChannelDataMutex.Unlock() - if fake.PrivateChannelDataStub != nil { - return fake.PrivateChannelDataStub() + if stub != nil { + return stub() } if specificReturn { return ret.result1 } - fakeReturns := fake.privateChannelDataReturns return fakeReturns.result1 } @@ -504,20 +521,74 @@ func (fake *ApplicationCapabilities) PrivateChannelDataReturnsOnCall(i int, resu }{result1} } +func (fake *ApplicationCapabilities) PurgePvtData() bool { + fake.purgePvtDataMutex.Lock() + ret, specificReturn := fake.purgePvtDataReturnsOnCall[len(fake.purgePvtDataArgsForCall)] + fake.purgePvtDataArgsForCall = append(fake.purgePvtDataArgsForCall, struct { + }{}) + stub := fake.PurgePvtDataStub + fakeReturns := fake.purgePvtDataReturns + fake.recordInvocation("PurgePvtData", []interface{}{}) + fake.purgePvtDataMutex.Unlock() + if stub != nil { + return stub() + } + if specificReturn { + return ret.result1 + } + return fakeReturns.result1 +} + +func (fake *ApplicationCapabilities) PurgePvtDataCallCount() int { + fake.purgePvtDataMutex.RLock() + defer fake.purgePvtDataMutex.RUnlock() + return len(fake.purgePvtDataArgsForCall) +} + +func (fake *ApplicationCapabilities) PurgePvtDataCalls(stub func() bool) { + fake.purgePvtDataMutex.Lock() + defer fake.purgePvtDataMutex.Unlock() + fake.PurgePvtDataStub = stub +} + +func (fake *ApplicationCapabilities) PurgePvtDataReturns(result1 bool) { + fake.purgePvtDataMutex.Lock() + defer fake.purgePvtDataMutex.Unlock() + fake.PurgePvtDataStub = nil + fake.purgePvtDataReturns = struct { + result1 bool + }{result1} +} + +func (fake *ApplicationCapabilities) PurgePvtDataReturnsOnCall(i int, result1 bool) { + fake.purgePvtDataMutex.Lock() + defer fake.purgePvtDataMutex.Unlock() + fake.PurgePvtDataStub = nil + if fake.purgePvtDataReturnsOnCall == nil { + fake.purgePvtDataReturnsOnCall = make(map[int]struct { + result1 bool + }) + } + fake.purgePvtDataReturnsOnCall[i] = struct { + result1 bool + }{result1} +} + func (fake *ApplicationCapabilities) StorePvtDataOfInvalidTx() bool { fake.storePvtDataOfInvalidTxMutex.Lock() ret, specificReturn := fake.storePvtDataOfInvalidTxReturnsOnCall[len(fake.storePvtDataOfInvalidTxArgsForCall)] fake.storePvtDataOfInvalidTxArgsForCall = append(fake.storePvtDataOfInvalidTxArgsForCall, struct { }{}) + stub := fake.StorePvtDataOfInvalidTxStub + fakeReturns := fake.storePvtDataOfInvalidTxReturns fake.recordInvocation("StorePvtDataOfInvalidTx", []interface{}{}) fake.storePvtDataOfInvalidTxMutex.Unlock() - if fake.StorePvtDataOfInvalidTxStub != nil { - return fake.StorePvtDataOfInvalidTxStub() + if stub != nil { + return stub() } if specificReturn { return ret.result1 } - fakeReturns := fake.storePvtDataOfInvalidTxReturns return fakeReturns.result1 } @@ -561,15 +632,16 @@ func (fake *ApplicationCapabilities) Supported() error { ret, specificReturn := fake.supportedReturnsOnCall[len(fake.supportedArgsForCall)] fake.supportedArgsForCall = append(fake.supportedArgsForCall, struct { }{}) + stub := fake.SupportedStub + fakeReturns := fake.supportedReturns fake.recordInvocation("Supported", []interface{}{}) fake.supportedMutex.Unlock() - if fake.SupportedStub != nil { - return fake.SupportedStub() + if stub != nil { + return stub() } if specificReturn { return ret.result1 } - fakeReturns := fake.supportedReturns return fakeReturns.result1 } @@ -613,15 +685,16 @@ func (fake *ApplicationCapabilities) V1_1Validation() bool { ret, specificReturn := fake.v1_1ValidationReturnsOnCall[len(fake.v1_1ValidationArgsForCall)] fake.v1_1ValidationArgsForCall = append(fake.v1_1ValidationArgsForCall, struct { }{}) + stub := fake.V1_1ValidationStub + fakeReturns := fake.v1_1ValidationReturns fake.recordInvocation("V1_1Validation", []interface{}{}) fake.v1_1ValidationMutex.Unlock() - if fake.V1_1ValidationStub != nil { - return fake.V1_1ValidationStub() + if stub != nil { + return stub() } if specificReturn { return ret.result1 } - fakeReturns := fake.v1_1ValidationReturns return fakeReturns.result1 } @@ -665,15 +738,16 @@ func (fake *ApplicationCapabilities) V1_2Validation() bool { ret, specificReturn := fake.v1_2ValidationReturnsOnCall[len(fake.v1_2ValidationArgsForCall)] fake.v1_2ValidationArgsForCall = append(fake.v1_2ValidationArgsForCall, struct { }{}) + stub := fake.V1_2ValidationStub + fakeReturns := fake.v1_2ValidationReturns fake.recordInvocation("V1_2Validation", []interface{}{}) fake.v1_2ValidationMutex.Unlock() - if fake.V1_2ValidationStub != nil { - return fake.V1_2ValidationStub() + if stub != nil { + return stub() } if specificReturn { return ret.result1 } - fakeReturns := fake.v1_2ValidationReturns return fakeReturns.result1 } @@ -717,15 +791,16 @@ func (fake *ApplicationCapabilities) V1_3Validation() bool { ret, specificReturn := fake.v1_3ValidationReturnsOnCall[len(fake.v1_3ValidationArgsForCall)] fake.v1_3ValidationArgsForCall = append(fake.v1_3ValidationArgsForCall, struct { }{}) + stub := fake.V1_3ValidationStub + fakeReturns := fake.v1_3ValidationReturns fake.recordInvocation("V1_3Validation", []interface{}{}) fake.v1_3ValidationMutex.Unlock() - if fake.V1_3ValidationStub != nil { - return fake.V1_3ValidationStub() + if stub != nil { + return stub() } if specificReturn { return ret.result1 } - fakeReturns := fake.v1_3ValidationReturns return fakeReturns.result1 } @@ -769,15 +844,16 @@ func (fake *ApplicationCapabilities) V2_0Validation() bool { ret, specificReturn := fake.v2_0ValidationReturnsOnCall[len(fake.v2_0ValidationArgsForCall)] fake.v2_0ValidationArgsForCall = append(fake.v2_0ValidationArgsForCall, struct { }{}) + stub := fake.V2_0ValidationStub + fakeReturns := fake.v2_0ValidationReturns fake.recordInvocation("V2_0Validation", []interface{}{}) fake.v2_0ValidationMutex.Unlock() - if fake.V2_0ValidationStub != nil { - return fake.V2_0ValidationStub() + if stub != nil { + return stub() } if specificReturn { return ret.result1 } - fakeReturns := fake.v2_0ValidationReturns return fakeReturns.result1 } @@ -833,6 +909,8 @@ func (fake *ApplicationCapabilities) Invocations() map[string][][]interface{} { defer fake.metadataLifecycleMutex.RUnlock() fake.privateChannelDataMutex.RLock() defer fake.privateChannelDataMutex.RUnlock() + fake.purgePvtDataMutex.RLock() + defer fake.purgePvtDataMutex.RUnlock() fake.storePvtDataOfInvalidTxMutex.RLock() defer fake.storePvtDataOfInvalidTxMutex.RUnlock() fake.supportedMutex.RLock() diff --git a/core/chaincode/mock/application_config.go b/core/chaincode/mock/application_config.go index 7a385f45efd..0fe6fe4feff 100644 --- a/core/chaincode/mock/application_config.go +++ b/core/chaincode/mock/application_config.go @@ -47,15 +47,16 @@ func (fake *ApplicationConfig) APIPolicyMapper() channelconfig.PolicyMapper { ret, specificReturn := fake.aPIPolicyMapperReturnsOnCall[len(fake.aPIPolicyMapperArgsForCall)] fake.aPIPolicyMapperArgsForCall = append(fake.aPIPolicyMapperArgsForCall, struct { }{}) + stub := fake.APIPolicyMapperStub + fakeReturns := fake.aPIPolicyMapperReturns fake.recordInvocation("APIPolicyMapper", []interface{}{}) fake.aPIPolicyMapperMutex.Unlock() - if fake.APIPolicyMapperStub != nil { - return fake.APIPolicyMapperStub() + if stub != nil { + return stub() } if specificReturn { return ret.result1 } - fakeReturns := fake.aPIPolicyMapperReturns return fakeReturns.result1 } @@ -99,15 +100,16 @@ func (fake *ApplicationConfig) Capabilities() channelconfig.ApplicationCapabilit ret, specificReturn := fake.capabilitiesReturnsOnCall[len(fake.capabilitiesArgsForCall)] fake.capabilitiesArgsForCall = append(fake.capabilitiesArgsForCall, struct { }{}) + stub := fake.CapabilitiesStub + fakeReturns := fake.capabilitiesReturns fake.recordInvocation("Capabilities", []interface{}{}) fake.capabilitiesMutex.Unlock() - if fake.CapabilitiesStub != nil { - return fake.CapabilitiesStub() + if stub != nil { + return stub() } if specificReturn { return ret.result1 } - fakeReturns := fake.capabilitiesReturns return fakeReturns.result1 } @@ -151,15 +153,16 @@ func (fake *ApplicationConfig) Organizations() map[string]channelconfig.Applicat ret, specificReturn := fake.organizationsReturnsOnCall[len(fake.organizationsArgsForCall)] fake.organizationsArgsForCall = append(fake.organizationsArgsForCall, struct { }{}) + stub := fake.OrganizationsStub + fakeReturns := fake.organizationsReturns fake.recordInvocation("Organizations", []interface{}{}) fake.organizationsMutex.Unlock() - if fake.OrganizationsStub != nil { - return fake.OrganizationsStub() + if stub != nil { + return stub() } if specificReturn { return ret.result1 } - fakeReturns := fake.organizationsReturns return fakeReturns.result1 } diff --git a/core/committer/txvalidator/mocks/application_capabilities.go b/core/committer/txvalidator/mocks/application_capabilities.go index 066594d65c7..ea3a3b4c583 100644 --- a/core/committer/txvalidator/mocks/application_capabilities.go +++ b/core/committer/txvalidator/mocks/application_capabilities.go @@ -1,4 +1,4 @@ -// Code generated by mockery v1.0.0. DO NOT EDIT. +// Code generated by mockery v2.14.0. DO NOT EDIT. package mocks @@ -107,6 +107,20 @@ func (_m *ApplicationCapabilities) PrivateChannelData() bool { return r0 } +// PurgePvtData provides a mock function with given fields: +func (_m *ApplicationCapabilities) PurgePvtData() bool { + ret := _m.Called() + + var r0 bool + if rf, ok := ret.Get(0).(func() bool); ok { + r0 = rf() + } else { + r0 = ret.Get(0).(bool) + } + + return r0 +} + // StorePvtDataOfInvalidTx provides a mock function with given fields: func (_m *ApplicationCapabilities) StorePvtDataOfInvalidTx() bool { ret := _m.Called() @@ -190,3 +204,18 @@ func (_m *ApplicationCapabilities) V2_0Validation() bool { return r0 } + +type mockConstructorTestingTNewApplicationCapabilities interface { + mock.TestingT + Cleanup(func()) +} + +// NewApplicationCapabilities creates a new instance of ApplicationCapabilities. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +func NewApplicationCapabilities(t mockConstructorTestingTNewApplicationCapabilities) *ApplicationCapabilities { + mock := &ApplicationCapabilities{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/core/scc/lscc/mock/application_capabilities.go b/core/scc/lscc/mock/application_capabilities.go index 2ccdd6dfd83..69fff8dcbf9 100644 --- a/core/scc/lscc/mock/application_capabilities.go +++ b/core/scc/lscc/mock/application_capabilities.go @@ -76,6 +76,16 @@ type ApplicationCapabilities struct { privateChannelDataReturnsOnCall map[int]struct { result1 bool } + PurgePvtDataStub func() bool + purgePvtDataMutex sync.RWMutex + purgePvtDataArgsForCall []struct { + } + purgePvtDataReturns struct { + result1 bool + } + purgePvtDataReturnsOnCall map[int]struct { + result1 bool + } StorePvtDataOfInvalidTxStub func() bool storePvtDataOfInvalidTxMutex sync.RWMutex storePvtDataOfInvalidTxArgsForCall []struct { @@ -145,15 +155,16 @@ func (fake *ApplicationCapabilities) ACLs() bool { ret, specificReturn := fake.aCLsReturnsOnCall[len(fake.aCLsArgsForCall)] fake.aCLsArgsForCall = append(fake.aCLsArgsForCall, struct { }{}) + stub := fake.ACLsStub + fakeReturns := fake.aCLsReturns fake.recordInvocation("ACLs", []interface{}{}) fake.aCLsMutex.Unlock() - if fake.ACLsStub != nil { - return fake.ACLsStub() + if stub != nil { + return stub() } if specificReturn { return ret.result1 } - fakeReturns := fake.aCLsReturns return fakeReturns.result1 } @@ -197,15 +208,16 @@ func (fake *ApplicationCapabilities) CollectionUpgrade() bool { ret, specificReturn := fake.collectionUpgradeReturnsOnCall[len(fake.collectionUpgradeArgsForCall)] fake.collectionUpgradeArgsForCall = append(fake.collectionUpgradeArgsForCall, struct { }{}) + stub := fake.CollectionUpgradeStub + fakeReturns := fake.collectionUpgradeReturns fake.recordInvocation("CollectionUpgrade", []interface{}{}) fake.collectionUpgradeMutex.Unlock() - if fake.CollectionUpgradeStub != nil { - return fake.CollectionUpgradeStub() + if stub != nil { + return stub() } if specificReturn { return ret.result1 } - fakeReturns := fake.collectionUpgradeReturns return fakeReturns.result1 } @@ -249,15 +261,16 @@ func (fake *ApplicationCapabilities) ForbidDuplicateTXIdInBlock() bool { ret, specificReturn := fake.forbidDuplicateTXIdInBlockReturnsOnCall[len(fake.forbidDuplicateTXIdInBlockArgsForCall)] fake.forbidDuplicateTXIdInBlockArgsForCall = append(fake.forbidDuplicateTXIdInBlockArgsForCall, struct { }{}) + stub := fake.ForbidDuplicateTXIdInBlockStub + fakeReturns := fake.forbidDuplicateTXIdInBlockReturns fake.recordInvocation("ForbidDuplicateTXIdInBlock", []interface{}{}) fake.forbidDuplicateTXIdInBlockMutex.Unlock() - if fake.ForbidDuplicateTXIdInBlockStub != nil { - return fake.ForbidDuplicateTXIdInBlockStub() + if stub != nil { + return stub() } if specificReturn { return ret.result1 } - fakeReturns := fake.forbidDuplicateTXIdInBlockReturns return fakeReturns.result1 } @@ -301,15 +314,16 @@ func (fake *ApplicationCapabilities) KeyLevelEndorsement() bool { ret, specificReturn := fake.keyLevelEndorsementReturnsOnCall[len(fake.keyLevelEndorsementArgsForCall)] fake.keyLevelEndorsementArgsForCall = append(fake.keyLevelEndorsementArgsForCall, struct { }{}) + stub := fake.KeyLevelEndorsementStub + fakeReturns := fake.keyLevelEndorsementReturns fake.recordInvocation("KeyLevelEndorsement", []interface{}{}) fake.keyLevelEndorsementMutex.Unlock() - if fake.KeyLevelEndorsementStub != nil { - return fake.KeyLevelEndorsementStub() + if stub != nil { + return stub() } if specificReturn { return ret.result1 } - fakeReturns := fake.keyLevelEndorsementReturns return fakeReturns.result1 } @@ -353,15 +367,16 @@ func (fake *ApplicationCapabilities) LifecycleV20() bool { ret, specificReturn := fake.lifecycleV20ReturnsOnCall[len(fake.lifecycleV20ArgsForCall)] fake.lifecycleV20ArgsForCall = append(fake.lifecycleV20ArgsForCall, struct { }{}) + stub := fake.LifecycleV20Stub + fakeReturns := fake.lifecycleV20Returns fake.recordInvocation("LifecycleV20", []interface{}{}) fake.lifecycleV20Mutex.Unlock() - if fake.LifecycleV20Stub != nil { - return fake.LifecycleV20Stub() + if stub != nil { + return stub() } if specificReturn { return ret.result1 } - fakeReturns := fake.lifecycleV20Returns return fakeReturns.result1 } @@ -405,15 +420,16 @@ func (fake *ApplicationCapabilities) MetadataLifecycle() bool { ret, specificReturn := fake.metadataLifecycleReturnsOnCall[len(fake.metadataLifecycleArgsForCall)] fake.metadataLifecycleArgsForCall = append(fake.metadataLifecycleArgsForCall, struct { }{}) + stub := fake.MetadataLifecycleStub + fakeReturns := fake.metadataLifecycleReturns fake.recordInvocation("MetadataLifecycle", []interface{}{}) fake.metadataLifecycleMutex.Unlock() - if fake.MetadataLifecycleStub != nil { - return fake.MetadataLifecycleStub() + if stub != nil { + return stub() } if specificReturn { return ret.result1 } - fakeReturns := fake.metadataLifecycleReturns return fakeReturns.result1 } @@ -457,15 +473,16 @@ func (fake *ApplicationCapabilities) PrivateChannelData() bool { ret, specificReturn := fake.privateChannelDataReturnsOnCall[len(fake.privateChannelDataArgsForCall)] fake.privateChannelDataArgsForCall = append(fake.privateChannelDataArgsForCall, struct { }{}) + stub := fake.PrivateChannelDataStub + fakeReturns := fake.privateChannelDataReturns fake.recordInvocation("PrivateChannelData", []interface{}{}) fake.privateChannelDataMutex.Unlock() - if fake.PrivateChannelDataStub != nil { - return fake.PrivateChannelDataStub() + if stub != nil { + return stub() } if specificReturn { return ret.result1 } - fakeReturns := fake.privateChannelDataReturns return fakeReturns.result1 } @@ -504,20 +521,74 @@ func (fake *ApplicationCapabilities) PrivateChannelDataReturnsOnCall(i int, resu }{result1} } +func (fake *ApplicationCapabilities) PurgePvtData() bool { + fake.purgePvtDataMutex.Lock() + ret, specificReturn := fake.purgePvtDataReturnsOnCall[len(fake.purgePvtDataArgsForCall)] + fake.purgePvtDataArgsForCall = append(fake.purgePvtDataArgsForCall, struct { + }{}) + stub := fake.PurgePvtDataStub + fakeReturns := fake.purgePvtDataReturns + fake.recordInvocation("PurgePvtData", []interface{}{}) + fake.purgePvtDataMutex.Unlock() + if stub != nil { + return stub() + } + if specificReturn { + return ret.result1 + } + return fakeReturns.result1 +} + +func (fake *ApplicationCapabilities) PurgePvtDataCallCount() int { + fake.purgePvtDataMutex.RLock() + defer fake.purgePvtDataMutex.RUnlock() + return len(fake.purgePvtDataArgsForCall) +} + +func (fake *ApplicationCapabilities) PurgePvtDataCalls(stub func() bool) { + fake.purgePvtDataMutex.Lock() + defer fake.purgePvtDataMutex.Unlock() + fake.PurgePvtDataStub = stub +} + +func (fake *ApplicationCapabilities) PurgePvtDataReturns(result1 bool) { + fake.purgePvtDataMutex.Lock() + defer fake.purgePvtDataMutex.Unlock() + fake.PurgePvtDataStub = nil + fake.purgePvtDataReturns = struct { + result1 bool + }{result1} +} + +func (fake *ApplicationCapabilities) PurgePvtDataReturnsOnCall(i int, result1 bool) { + fake.purgePvtDataMutex.Lock() + defer fake.purgePvtDataMutex.Unlock() + fake.PurgePvtDataStub = nil + if fake.purgePvtDataReturnsOnCall == nil { + fake.purgePvtDataReturnsOnCall = make(map[int]struct { + result1 bool + }) + } + fake.purgePvtDataReturnsOnCall[i] = struct { + result1 bool + }{result1} +} + func (fake *ApplicationCapabilities) StorePvtDataOfInvalidTx() bool { fake.storePvtDataOfInvalidTxMutex.Lock() ret, specificReturn := fake.storePvtDataOfInvalidTxReturnsOnCall[len(fake.storePvtDataOfInvalidTxArgsForCall)] fake.storePvtDataOfInvalidTxArgsForCall = append(fake.storePvtDataOfInvalidTxArgsForCall, struct { }{}) + stub := fake.StorePvtDataOfInvalidTxStub + fakeReturns := fake.storePvtDataOfInvalidTxReturns fake.recordInvocation("StorePvtDataOfInvalidTx", []interface{}{}) fake.storePvtDataOfInvalidTxMutex.Unlock() - if fake.StorePvtDataOfInvalidTxStub != nil { - return fake.StorePvtDataOfInvalidTxStub() + if stub != nil { + return stub() } if specificReturn { return ret.result1 } - fakeReturns := fake.storePvtDataOfInvalidTxReturns return fakeReturns.result1 } @@ -561,15 +632,16 @@ func (fake *ApplicationCapabilities) Supported() error { ret, specificReturn := fake.supportedReturnsOnCall[len(fake.supportedArgsForCall)] fake.supportedArgsForCall = append(fake.supportedArgsForCall, struct { }{}) + stub := fake.SupportedStub + fakeReturns := fake.supportedReturns fake.recordInvocation("Supported", []interface{}{}) fake.supportedMutex.Unlock() - if fake.SupportedStub != nil { - return fake.SupportedStub() + if stub != nil { + return stub() } if specificReturn { return ret.result1 } - fakeReturns := fake.supportedReturns return fakeReturns.result1 } @@ -613,15 +685,16 @@ func (fake *ApplicationCapabilities) V1_1Validation() bool { ret, specificReturn := fake.v1_1ValidationReturnsOnCall[len(fake.v1_1ValidationArgsForCall)] fake.v1_1ValidationArgsForCall = append(fake.v1_1ValidationArgsForCall, struct { }{}) + stub := fake.V1_1ValidationStub + fakeReturns := fake.v1_1ValidationReturns fake.recordInvocation("V1_1Validation", []interface{}{}) fake.v1_1ValidationMutex.Unlock() - if fake.V1_1ValidationStub != nil { - return fake.V1_1ValidationStub() + if stub != nil { + return stub() } if specificReturn { return ret.result1 } - fakeReturns := fake.v1_1ValidationReturns return fakeReturns.result1 } @@ -665,15 +738,16 @@ func (fake *ApplicationCapabilities) V1_2Validation() bool { ret, specificReturn := fake.v1_2ValidationReturnsOnCall[len(fake.v1_2ValidationArgsForCall)] fake.v1_2ValidationArgsForCall = append(fake.v1_2ValidationArgsForCall, struct { }{}) + stub := fake.V1_2ValidationStub + fakeReturns := fake.v1_2ValidationReturns fake.recordInvocation("V1_2Validation", []interface{}{}) fake.v1_2ValidationMutex.Unlock() - if fake.V1_2ValidationStub != nil { - return fake.V1_2ValidationStub() + if stub != nil { + return stub() } if specificReturn { return ret.result1 } - fakeReturns := fake.v1_2ValidationReturns return fakeReturns.result1 } @@ -717,15 +791,16 @@ func (fake *ApplicationCapabilities) V1_3Validation() bool { ret, specificReturn := fake.v1_3ValidationReturnsOnCall[len(fake.v1_3ValidationArgsForCall)] fake.v1_3ValidationArgsForCall = append(fake.v1_3ValidationArgsForCall, struct { }{}) + stub := fake.V1_3ValidationStub + fakeReturns := fake.v1_3ValidationReturns fake.recordInvocation("V1_3Validation", []interface{}{}) fake.v1_3ValidationMutex.Unlock() - if fake.V1_3ValidationStub != nil { - return fake.V1_3ValidationStub() + if stub != nil { + return stub() } if specificReturn { return ret.result1 } - fakeReturns := fake.v1_3ValidationReturns return fakeReturns.result1 } @@ -769,15 +844,16 @@ func (fake *ApplicationCapabilities) V2_0Validation() bool { ret, specificReturn := fake.v2_0ValidationReturnsOnCall[len(fake.v2_0ValidationArgsForCall)] fake.v2_0ValidationArgsForCall = append(fake.v2_0ValidationArgsForCall, struct { }{}) + stub := fake.V2_0ValidationStub + fakeReturns := fake.v2_0ValidationReturns fake.recordInvocation("V2_0Validation", []interface{}{}) fake.v2_0ValidationMutex.Unlock() - if fake.V2_0ValidationStub != nil { - return fake.V2_0ValidationStub() + if stub != nil { + return stub() } if specificReturn { return ret.result1 } - fakeReturns := fake.v2_0ValidationReturns return fakeReturns.result1 } @@ -833,6 +909,8 @@ func (fake *ApplicationCapabilities) Invocations() map[string][][]interface{} { defer fake.metadataLifecycleMutex.RUnlock() fake.privateChannelDataMutex.RLock() defer fake.privateChannelDataMutex.RUnlock() + fake.purgePvtDataMutex.RLock() + defer fake.purgePvtDataMutex.RUnlock() fake.storePvtDataOfInvalidTxMutex.RLock() defer fake.storePvtDataOfInvalidTxMutex.RUnlock() fake.supportedMutex.RLock() diff --git a/gossip/privdata/coordinator_test.go b/gossip/privdata/coordinator_test.go index e0ef54a3312..0022847b1da 100644 --- a/gossip/privdata/coordinator_test.go +++ b/gossip/privdata/coordinator_test.go @@ -623,7 +623,7 @@ func TestCoordinatorStoreInvalidBlock(t *testing.T) { pvtData := pdFactory.create() committer.On("DoesPvtDataInfoExistInLedger", mock.Anything).Return(false, nil) capabilityProvider := &privdatamocks.CapabilityProvider{} - appCapability := &privdatamocks.AppCapabilities{} + appCapability := &privdatamocks.ApplicationCapabilities{} capabilityProvider.On("Capabilities").Return(appCapability) appCapability.On("StorePvtDataOfInvalidTx").Return(true) coordinator := NewCoordinator(mspID, Support{ @@ -708,7 +708,7 @@ func TestCoordinatorStoreInvalidBlock(t *testing.T) { committer.On("DoesPvtDataInfoExistInLedger", mock.Anything).Return(false, nil) capabilityProvider = &privdatamocks.CapabilityProvider{} - appCapability = &privdatamocks.AppCapabilities{} + appCapability = &privdatamocks.ApplicationCapabilities{} capabilityProvider.On("Capabilities").Return(appCapability) appCapability.On("StorePvtDataOfInvalidTx").Return(false) coordinator = NewCoordinator(mspID, Support{ @@ -765,7 +765,7 @@ func TestCoordinatorStoreInvalidBlock(t *testing.T) { pvtData = pdFactory.addRWSet().addNSRWSet("ns1", "c1", "c2").create() committer.On("DoesPvtDataInfoExistInLedger", mock.Anything).Return(false, nil) capabilityProvider = &privdatamocks.CapabilityProvider{} - appCapability = &privdatamocks.AppCapabilities{} + appCapability = &privdatamocks.ApplicationCapabilities{} capabilityProvider.On("Capabilities").Return(appCapability) appCapability.On("StorePvtDataOfInvalidTx").Return(true) digKeys = []privdatacommon.DigKey{} @@ -957,7 +957,7 @@ func TestCoordinatorToFilterOutPvtRWSetsWithWrongHash(t *testing.T) { metrics := metrics.NewGossipMetrics(&disabled.Provider{}).PrivdataMetrics capabilityProvider := &privdatamocks.CapabilityProvider{} - appCapability := &privdatamocks.AppCapabilities{} + appCapability := &privdatamocks.ApplicationCapabilities{} capabilityProvider.On("Capabilities").Return(appCapability) appCapability.On("StorePvtDataOfInvalidTx").Return(true) coordinator := NewCoordinator(mspID, Support{ @@ -1079,7 +1079,7 @@ func TestCoordinatorStoreBlock(t *testing.T) { committer.On("DoesPvtDataInfoExistInLedger", mock.Anything).Return(false, nil) capabilityProvider := &privdatamocks.CapabilityProvider{} - appCapability := &privdatamocks.AppCapabilities{} + appCapability := &privdatamocks.ApplicationCapabilities{} capabilityProvider.On("Capabilities").Return(appCapability) appCapability.On("StorePvtDataOfInvalidTx").Return(true) coordinator := NewCoordinator(mspID, Support{ @@ -1353,7 +1353,7 @@ func TestCoordinatorStoreBlockWhenPvtDataExistInLedger(t *testing.T) { metrics := metrics.NewGossipMetrics(&disabled.Provider{}).PrivdataMetrics capabilityProvider := &privdatamocks.CapabilityProvider{} - appCapability := &privdatamocks.AppCapabilities{} + appCapability := &privdatamocks.ApplicationCapabilities{} capabilityProvider.On("Capabilities").Return(appCapability) appCapability.On("StorePvtDataOfInvalidTx").Return(true) coordinator := NewCoordinator(mspID, Support{ @@ -1465,7 +1465,7 @@ func TestProceedWithoutPrivateData(t *testing.T) { committer.On("DoesPvtDataInfoExistInLedger", mock.Anything).Return(false, nil) capabilityProvider := &privdatamocks.CapabilityProvider{} - appCapability := &privdatamocks.AppCapabilities{} + appCapability := &privdatamocks.ApplicationCapabilities{} capabilityProvider.On("Capabilities").Return(appCapability) appCapability.On("StorePvtDataOfInvalidTx").Return(true) coordinator := NewCoordinator(mspID, Support{ @@ -1540,7 +1540,7 @@ func TestProceedWithInEligiblePrivateData(t *testing.T) { metrics := metrics.NewGossipMetrics(&disabled.Provider{}).PrivdataMetrics capabilityProvider := &privdatamocks.CapabilityProvider{} - appCapability := &privdatamocks.AppCapabilities{} + appCapability := &privdatamocks.ApplicationCapabilities{} capabilityProvider.On("Capabilities").Return(appCapability) appCapability.On("StorePvtDataOfInvalidTx").Return(true) coordinator := NewCoordinator(mspID, Support{ @@ -1587,7 +1587,7 @@ func TestCoordinatorGetBlocks(t *testing.T) { committer.On("DoesPvtDataInfoExistInLedger", mock.Anything).Return(false, nil) capabilityProvider := &privdatamocks.CapabilityProvider{} - appCapability := &privdatamocks.AppCapabilities{} + appCapability := &privdatamocks.ApplicationCapabilities{} capabilityProvider.On("Capabilities").Return(appCapability) appCapability.On("StorePvtDataOfInvalidTx").Return(true) @@ -1713,7 +1713,7 @@ func TestPurgeBelowHeight(t *testing.T) { metrics := metrics.NewGossipMetrics(&disabled.Provider{}).PrivdataMetrics capabilityProvider := &privdatamocks.CapabilityProvider{} - appCapability := &privdatamocks.AppCapabilities{} + appCapability := &privdatamocks.ApplicationCapabilities{} capabilityProvider.On("Capabilities").Return(appCapability) appCapability.On("StorePvtDataOfInvalidTx").Return(true) coordinator := NewCoordinator(mspID, Support{ @@ -1760,7 +1760,7 @@ func TestCoordinatorStorePvtData(t *testing.T) { committer.On("DoesPvtDataInfoExistInLedger", mock.Anything).Return(false, nil) capabilityProvider := &privdatamocks.CapabilityProvider{} - appCapability := &privdatamocks.AppCapabilities{} + appCapability := &privdatamocks.ApplicationCapabilities{} capabilityProvider.On("Capabilities").Return(appCapability) appCapability.On("StorePvtDataOfInvalidTx").Return(true) coordinator := NewCoordinator(mspID, Support{ @@ -1859,7 +1859,7 @@ func TestIgnoreReadOnlyColRWSets(t *testing.T) { metrics := metrics.NewGossipMetrics(&disabled.Provider{}).PrivdataMetrics capabilityProvider := &privdatamocks.CapabilityProvider{} - appCapability := &privdatamocks.AppCapabilities{} + appCapability := &privdatamocks.ApplicationCapabilities{} capabilityProvider.On("Capabilities").Return(appCapability) appCapability.On("StorePvtDataOfInvalidTx").Return(true) coordinator := NewCoordinator(mspID, Support{ @@ -1944,7 +1944,7 @@ func TestCoordinatorMetrics(t *testing.T) { committer.On("DoesPvtDataInfoExistInLedger", mock.Anything).Return(false, nil) capabilityProvider := &privdatamocks.CapabilityProvider{} - appCapability := &privdatamocks.AppCapabilities{} + appCapability := &privdatamocks.ApplicationCapabilities{} capabilityProvider.On("Capabilities").Return(appCapability) appCapability.On("StorePvtDataOfInvalidTx").Return(true) coordinator := NewCoordinator(mspID, Support{ diff --git a/gossip/privdata/mocks/app_capabilities.go b/gossip/privdata/mocks/app_capabilities.go index 85f203512dd..ea3a3b4c583 100644 --- a/gossip/privdata/mocks/app_capabilities.go +++ b/gossip/privdata/mocks/app_capabilities.go @@ -1,16 +1,16 @@ -// Code generated by mockery v1.0.0. DO NOT EDIT. +// Code generated by mockery v2.14.0. DO NOT EDIT. package mocks import mock "github.com/stretchr/testify/mock" -// AppCapabilities is an autogenerated mock type for the AppCapabilities type -type AppCapabilities struct { +// ApplicationCapabilities is an autogenerated mock type for the ApplicationCapabilities type +type ApplicationCapabilities struct { mock.Mock } // ACLs provides a mock function with given fields: -func (_m *AppCapabilities) ACLs() bool { +func (_m *ApplicationCapabilities) ACLs() bool { ret := _m.Called() var r0 bool @@ -24,7 +24,7 @@ func (_m *AppCapabilities) ACLs() bool { } // CollectionUpgrade provides a mock function with given fields: -func (_m *AppCapabilities) CollectionUpgrade() bool { +func (_m *ApplicationCapabilities) CollectionUpgrade() bool { ret := _m.Called() var r0 bool @@ -38,7 +38,7 @@ func (_m *AppCapabilities) CollectionUpgrade() bool { } // ForbidDuplicateTXIdInBlock provides a mock function with given fields: -func (_m *AppCapabilities) ForbidDuplicateTXIdInBlock() bool { +func (_m *ApplicationCapabilities) ForbidDuplicateTXIdInBlock() bool { ret := _m.Called() var r0 bool @@ -52,7 +52,7 @@ func (_m *AppCapabilities) ForbidDuplicateTXIdInBlock() bool { } // KeyLevelEndorsement provides a mock function with given fields: -func (_m *AppCapabilities) KeyLevelEndorsement() bool { +func (_m *ApplicationCapabilities) KeyLevelEndorsement() bool { ret := _m.Called() var r0 bool @@ -66,7 +66,7 @@ func (_m *AppCapabilities) KeyLevelEndorsement() bool { } // LifecycleV20 provides a mock function with given fields: -func (_m *AppCapabilities) LifecycleV20() bool { +func (_m *ApplicationCapabilities) LifecycleV20() bool { ret := _m.Called() var r0 bool @@ -80,7 +80,7 @@ func (_m *AppCapabilities) LifecycleV20() bool { } // MetadataLifecycle provides a mock function with given fields: -func (_m *AppCapabilities) MetadataLifecycle() bool { +func (_m *ApplicationCapabilities) MetadataLifecycle() bool { ret := _m.Called() var r0 bool @@ -94,7 +94,21 @@ func (_m *AppCapabilities) MetadataLifecycle() bool { } // PrivateChannelData provides a mock function with given fields: -func (_m *AppCapabilities) PrivateChannelData() bool { +func (_m *ApplicationCapabilities) PrivateChannelData() bool { + ret := _m.Called() + + var r0 bool + if rf, ok := ret.Get(0).(func() bool); ok { + r0 = rf() + } else { + r0 = ret.Get(0).(bool) + } + + return r0 +} + +// PurgePvtData provides a mock function with given fields: +func (_m *ApplicationCapabilities) PurgePvtData() bool { ret := _m.Called() var r0 bool @@ -108,7 +122,7 @@ func (_m *AppCapabilities) PrivateChannelData() bool { } // StorePvtDataOfInvalidTx provides a mock function with given fields: -func (_m *AppCapabilities) StorePvtDataOfInvalidTx() bool { +func (_m *ApplicationCapabilities) StorePvtDataOfInvalidTx() bool { ret := _m.Called() var r0 bool @@ -122,7 +136,7 @@ func (_m *AppCapabilities) StorePvtDataOfInvalidTx() bool { } // Supported provides a mock function with given fields: -func (_m *AppCapabilities) Supported() error { +func (_m *ApplicationCapabilities) Supported() error { ret := _m.Called() var r0 error @@ -136,7 +150,7 @@ func (_m *AppCapabilities) Supported() error { } // V1_1Validation provides a mock function with given fields: -func (_m *AppCapabilities) V1_1Validation() bool { +func (_m *ApplicationCapabilities) V1_1Validation() bool { ret := _m.Called() var r0 bool @@ -150,7 +164,7 @@ func (_m *AppCapabilities) V1_1Validation() bool { } // V1_2Validation provides a mock function with given fields: -func (_m *AppCapabilities) V1_2Validation() bool { +func (_m *ApplicationCapabilities) V1_2Validation() bool { ret := _m.Called() var r0 bool @@ -164,7 +178,7 @@ func (_m *AppCapabilities) V1_2Validation() bool { } // V1_3Validation provides a mock function with given fields: -func (_m *AppCapabilities) V1_3Validation() bool { +func (_m *ApplicationCapabilities) V1_3Validation() bool { ret := _m.Called() var r0 bool @@ -178,7 +192,7 @@ func (_m *AppCapabilities) V1_3Validation() bool { } // V2_0Validation provides a mock function with given fields: -func (_m *AppCapabilities) V2_0Validation() bool { +func (_m *ApplicationCapabilities) V2_0Validation() bool { ret := _m.Called() var r0 bool @@ -190,3 +204,18 @@ func (_m *AppCapabilities) V2_0Validation() bool { return r0 } + +type mockConstructorTestingTNewApplicationCapabilities interface { + mock.TestingT + Cleanup(func()) +} + +// NewApplicationCapabilities creates a new instance of ApplicationCapabilities. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +func NewApplicationCapabilities(t mockConstructorTestingTNewApplicationCapabilities) *ApplicationCapabilities { + mock := &ApplicationCapabilities{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/gossip/state/state_test.go b/gossip/state/state_test.go index 0be20ddb790..65e31c80dab 100644 --- a/gossip/state/state_test.go +++ b/gossip/state/state_test.go @@ -416,7 +416,7 @@ func newPeerNodeWithGossipWithValidatorWithMetrics(logger gossiputil.Logger, id mspID := "Org1MSP" capabilityProvider := &capabilitymock.CapabilityProvider{} - appCapability := &capabilitymock.AppCapabilities{} + appCapability := &capabilitymock.ApplicationCapabilities{} capabilityProvider.On("Capabilities").Return(appCapability) appCapability.On("StorePvtDataOfInvalidTx").Return(true) coord := privdata.NewCoordinator(mspID, privdata.Support{