diff --git a/common/ledger/testutil/fakes/signing_identity.go b/common/ledger/testutil/fakes/signing_identity.go new file mode 100644 index 00000000000..0b33f1325a1 --- /dev/null +++ b/common/ledger/testutil/fakes/signing_identity.go @@ -0,0 +1,795 @@ +// Code generated by counterfeiter. DO NOT EDIT. +package fakes + +import ( + "sync" + "time" + + mspa "github.com/hyperledger/fabric-protos-go/msp" + "github.com/hyperledger/fabric/msp" +) + +type SigningIdentity struct { + AnonymousStub func() bool + anonymousMutex sync.RWMutex + anonymousArgsForCall []struct { + } + anonymousReturns struct { + result1 bool + } + anonymousReturnsOnCall map[int]struct { + result1 bool + } + ExpiresAtStub func() time.Time + expiresAtMutex sync.RWMutex + expiresAtArgsForCall []struct { + } + expiresAtReturns struct { + result1 time.Time + } + expiresAtReturnsOnCall map[int]struct { + result1 time.Time + } + GetIdentifierStub func() *msp.IdentityIdentifier + getIdentifierMutex sync.RWMutex + getIdentifierArgsForCall []struct { + } + getIdentifierReturns struct { + result1 *msp.IdentityIdentifier + } + getIdentifierReturnsOnCall map[int]struct { + result1 *msp.IdentityIdentifier + } + GetMSPIdentifierStub func() string + getMSPIdentifierMutex sync.RWMutex + getMSPIdentifierArgsForCall []struct { + } + getMSPIdentifierReturns struct { + result1 string + } + getMSPIdentifierReturnsOnCall map[int]struct { + result1 string + } + GetOrganizationalUnitsStub func() []*msp.OUIdentifier + getOrganizationalUnitsMutex sync.RWMutex + getOrganizationalUnitsArgsForCall []struct { + } + getOrganizationalUnitsReturns struct { + result1 []*msp.OUIdentifier + } + getOrganizationalUnitsReturnsOnCall map[int]struct { + result1 []*msp.OUIdentifier + } + GetPublicVersionStub func() msp.Identity + getPublicVersionMutex sync.RWMutex + getPublicVersionArgsForCall []struct { + } + getPublicVersionReturns struct { + result1 msp.Identity + } + getPublicVersionReturnsOnCall map[int]struct { + result1 msp.Identity + } + SatisfiesPrincipalStub func(*mspa.MSPPrincipal) error + satisfiesPrincipalMutex sync.RWMutex + satisfiesPrincipalArgsForCall []struct { + arg1 *mspa.MSPPrincipal + } + satisfiesPrincipalReturns struct { + result1 error + } + satisfiesPrincipalReturnsOnCall map[int]struct { + result1 error + } + SerializeStub func() ([]byte, error) + serializeMutex sync.RWMutex + serializeArgsForCall []struct { + } + serializeReturns struct { + result1 []byte + result2 error + } + serializeReturnsOnCall map[int]struct { + result1 []byte + result2 error + } + SignStub func([]byte) ([]byte, error) + signMutex sync.RWMutex + signArgsForCall []struct { + arg1 []byte + } + signReturns struct { + result1 []byte + result2 error + } + signReturnsOnCall map[int]struct { + result1 []byte + result2 error + } + ValidateStub func() error + validateMutex sync.RWMutex + validateArgsForCall []struct { + } + validateReturns struct { + result1 error + } + validateReturnsOnCall map[int]struct { + result1 error + } + VerifyStub func([]byte, []byte) error + verifyMutex sync.RWMutex + verifyArgsForCall []struct { + arg1 []byte + arg2 []byte + } + verifyReturns struct { + result1 error + } + verifyReturnsOnCall map[int]struct { + result1 error + } + invocations map[string][][]interface{} + invocationsMutex sync.RWMutex +} + +func (fake *SigningIdentity) Anonymous() bool { + fake.anonymousMutex.Lock() + ret, specificReturn := fake.anonymousReturnsOnCall[len(fake.anonymousArgsForCall)] + fake.anonymousArgsForCall = append(fake.anonymousArgsForCall, struct { + }{}) + fake.recordInvocation("Anonymous", []interface{}{}) + fake.anonymousMutex.Unlock() + if fake.AnonymousStub != nil { + return fake.AnonymousStub() + } + if specificReturn { + return ret.result1 + } + fakeReturns := fake.anonymousReturns + return fakeReturns.result1 +} + +func (fake *SigningIdentity) AnonymousCallCount() int { + fake.anonymousMutex.RLock() + defer fake.anonymousMutex.RUnlock() + return len(fake.anonymousArgsForCall) +} + +func (fake *SigningIdentity) AnonymousCalls(stub func() bool) { + fake.anonymousMutex.Lock() + defer fake.anonymousMutex.Unlock() + fake.AnonymousStub = stub +} + +func (fake *SigningIdentity) AnonymousReturns(result1 bool) { + fake.anonymousMutex.Lock() + defer fake.anonymousMutex.Unlock() + fake.AnonymousStub = nil + fake.anonymousReturns = struct { + result1 bool + }{result1} +} + +func (fake *SigningIdentity) AnonymousReturnsOnCall(i int, result1 bool) { + fake.anonymousMutex.Lock() + defer fake.anonymousMutex.Unlock() + fake.AnonymousStub = nil + if fake.anonymousReturnsOnCall == nil { + fake.anonymousReturnsOnCall = make(map[int]struct { + result1 bool + }) + } + fake.anonymousReturnsOnCall[i] = struct { + result1 bool + }{result1} +} + +func (fake *SigningIdentity) ExpiresAt() time.Time { + fake.expiresAtMutex.Lock() + ret, specificReturn := fake.expiresAtReturnsOnCall[len(fake.expiresAtArgsForCall)] + fake.expiresAtArgsForCall = append(fake.expiresAtArgsForCall, struct { + }{}) + fake.recordInvocation("ExpiresAt", []interface{}{}) + fake.expiresAtMutex.Unlock() + if fake.ExpiresAtStub != nil { + return fake.ExpiresAtStub() + } + if specificReturn { + return ret.result1 + } + fakeReturns := fake.expiresAtReturns + return fakeReturns.result1 +} + +func (fake *SigningIdentity) ExpiresAtCallCount() int { + fake.expiresAtMutex.RLock() + defer fake.expiresAtMutex.RUnlock() + return len(fake.expiresAtArgsForCall) +} + +func (fake *SigningIdentity) ExpiresAtCalls(stub func() time.Time) { + fake.expiresAtMutex.Lock() + defer fake.expiresAtMutex.Unlock() + fake.ExpiresAtStub = stub +} + +func (fake *SigningIdentity) ExpiresAtReturns(result1 time.Time) { + fake.expiresAtMutex.Lock() + defer fake.expiresAtMutex.Unlock() + fake.ExpiresAtStub = nil + fake.expiresAtReturns = struct { + result1 time.Time + }{result1} +} + +func (fake *SigningIdentity) ExpiresAtReturnsOnCall(i int, result1 time.Time) { + fake.expiresAtMutex.Lock() + defer fake.expiresAtMutex.Unlock() + fake.ExpiresAtStub = nil + if fake.expiresAtReturnsOnCall == nil { + fake.expiresAtReturnsOnCall = make(map[int]struct { + result1 time.Time + }) + } + fake.expiresAtReturnsOnCall[i] = struct { + result1 time.Time + }{result1} +} + +func (fake *SigningIdentity) GetIdentifier() *msp.IdentityIdentifier { + fake.getIdentifierMutex.Lock() + ret, specificReturn := fake.getIdentifierReturnsOnCall[len(fake.getIdentifierArgsForCall)] + fake.getIdentifierArgsForCall = append(fake.getIdentifierArgsForCall, struct { + }{}) + fake.recordInvocation("GetIdentifier", []interface{}{}) + fake.getIdentifierMutex.Unlock() + if fake.GetIdentifierStub != nil { + return fake.GetIdentifierStub() + } + if specificReturn { + return ret.result1 + } + fakeReturns := fake.getIdentifierReturns + return fakeReturns.result1 +} + +func (fake *SigningIdentity) GetIdentifierCallCount() int { + fake.getIdentifierMutex.RLock() + defer fake.getIdentifierMutex.RUnlock() + return len(fake.getIdentifierArgsForCall) +} + +func (fake *SigningIdentity) GetIdentifierCalls(stub func() *msp.IdentityIdentifier) { + fake.getIdentifierMutex.Lock() + defer fake.getIdentifierMutex.Unlock() + fake.GetIdentifierStub = stub +} + +func (fake *SigningIdentity) GetIdentifierReturns(result1 *msp.IdentityIdentifier) { + fake.getIdentifierMutex.Lock() + defer fake.getIdentifierMutex.Unlock() + fake.GetIdentifierStub = nil + fake.getIdentifierReturns = struct { + result1 *msp.IdentityIdentifier + }{result1} +} + +func (fake *SigningIdentity) GetIdentifierReturnsOnCall(i int, result1 *msp.IdentityIdentifier) { + fake.getIdentifierMutex.Lock() + defer fake.getIdentifierMutex.Unlock() + fake.GetIdentifierStub = nil + if fake.getIdentifierReturnsOnCall == nil { + fake.getIdentifierReturnsOnCall = make(map[int]struct { + result1 *msp.IdentityIdentifier + }) + } + fake.getIdentifierReturnsOnCall[i] = struct { + result1 *msp.IdentityIdentifier + }{result1} +} + +func (fake *SigningIdentity) GetMSPIdentifier() string { + fake.getMSPIdentifierMutex.Lock() + ret, specificReturn := fake.getMSPIdentifierReturnsOnCall[len(fake.getMSPIdentifierArgsForCall)] + fake.getMSPIdentifierArgsForCall = append(fake.getMSPIdentifierArgsForCall, struct { + }{}) + fake.recordInvocation("GetMSPIdentifier", []interface{}{}) + fake.getMSPIdentifierMutex.Unlock() + if fake.GetMSPIdentifierStub != nil { + return fake.GetMSPIdentifierStub() + } + if specificReturn { + return ret.result1 + } + fakeReturns := fake.getMSPIdentifierReturns + return fakeReturns.result1 +} + +func (fake *SigningIdentity) GetMSPIdentifierCallCount() int { + fake.getMSPIdentifierMutex.RLock() + defer fake.getMSPIdentifierMutex.RUnlock() + return len(fake.getMSPIdentifierArgsForCall) +} + +func (fake *SigningIdentity) GetMSPIdentifierCalls(stub func() string) { + fake.getMSPIdentifierMutex.Lock() + defer fake.getMSPIdentifierMutex.Unlock() + fake.GetMSPIdentifierStub = stub +} + +func (fake *SigningIdentity) GetMSPIdentifierReturns(result1 string) { + fake.getMSPIdentifierMutex.Lock() + defer fake.getMSPIdentifierMutex.Unlock() + fake.GetMSPIdentifierStub = nil + fake.getMSPIdentifierReturns = struct { + result1 string + }{result1} +} + +func (fake *SigningIdentity) GetMSPIdentifierReturnsOnCall(i int, result1 string) { + fake.getMSPIdentifierMutex.Lock() + defer fake.getMSPIdentifierMutex.Unlock() + fake.GetMSPIdentifierStub = nil + if fake.getMSPIdentifierReturnsOnCall == nil { + fake.getMSPIdentifierReturnsOnCall = make(map[int]struct { + result1 string + }) + } + fake.getMSPIdentifierReturnsOnCall[i] = struct { + result1 string + }{result1} +} + +func (fake *SigningIdentity) GetOrganizationalUnits() []*msp.OUIdentifier { + fake.getOrganizationalUnitsMutex.Lock() + ret, specificReturn := fake.getOrganizationalUnitsReturnsOnCall[len(fake.getOrganizationalUnitsArgsForCall)] + fake.getOrganizationalUnitsArgsForCall = append(fake.getOrganizationalUnitsArgsForCall, struct { + }{}) + fake.recordInvocation("GetOrganizationalUnits", []interface{}{}) + fake.getOrganizationalUnitsMutex.Unlock() + if fake.GetOrganizationalUnitsStub != nil { + return fake.GetOrganizationalUnitsStub() + } + if specificReturn { + return ret.result1 + } + fakeReturns := fake.getOrganizationalUnitsReturns + return fakeReturns.result1 +} + +func (fake *SigningIdentity) GetOrganizationalUnitsCallCount() int { + fake.getOrganizationalUnitsMutex.RLock() + defer fake.getOrganizationalUnitsMutex.RUnlock() + return len(fake.getOrganizationalUnitsArgsForCall) +} + +func (fake *SigningIdentity) GetOrganizationalUnitsCalls(stub func() []*msp.OUIdentifier) { + fake.getOrganizationalUnitsMutex.Lock() + defer fake.getOrganizationalUnitsMutex.Unlock() + fake.GetOrganizationalUnitsStub = stub +} + +func (fake *SigningIdentity) GetOrganizationalUnitsReturns(result1 []*msp.OUIdentifier) { + fake.getOrganizationalUnitsMutex.Lock() + defer fake.getOrganizationalUnitsMutex.Unlock() + fake.GetOrganizationalUnitsStub = nil + fake.getOrganizationalUnitsReturns = struct { + result1 []*msp.OUIdentifier + }{result1} +} + +func (fake *SigningIdentity) GetOrganizationalUnitsReturnsOnCall(i int, result1 []*msp.OUIdentifier) { + fake.getOrganizationalUnitsMutex.Lock() + defer fake.getOrganizationalUnitsMutex.Unlock() + fake.GetOrganizationalUnitsStub = nil + if fake.getOrganizationalUnitsReturnsOnCall == nil { + fake.getOrganizationalUnitsReturnsOnCall = make(map[int]struct { + result1 []*msp.OUIdentifier + }) + } + fake.getOrganizationalUnitsReturnsOnCall[i] = struct { + result1 []*msp.OUIdentifier + }{result1} +} + +func (fake *SigningIdentity) GetPublicVersion() msp.Identity { + fake.getPublicVersionMutex.Lock() + ret, specificReturn := fake.getPublicVersionReturnsOnCall[len(fake.getPublicVersionArgsForCall)] + fake.getPublicVersionArgsForCall = append(fake.getPublicVersionArgsForCall, struct { + }{}) + fake.recordInvocation("GetPublicVersion", []interface{}{}) + fake.getPublicVersionMutex.Unlock() + if fake.GetPublicVersionStub != nil { + return fake.GetPublicVersionStub() + } + if specificReturn { + return ret.result1 + } + fakeReturns := fake.getPublicVersionReturns + return fakeReturns.result1 +} + +func (fake *SigningIdentity) GetPublicVersionCallCount() int { + fake.getPublicVersionMutex.RLock() + defer fake.getPublicVersionMutex.RUnlock() + return len(fake.getPublicVersionArgsForCall) +} + +func (fake *SigningIdentity) GetPublicVersionCalls(stub func() msp.Identity) { + fake.getPublicVersionMutex.Lock() + defer fake.getPublicVersionMutex.Unlock() + fake.GetPublicVersionStub = stub +} + +func (fake *SigningIdentity) GetPublicVersionReturns(result1 msp.Identity) { + fake.getPublicVersionMutex.Lock() + defer fake.getPublicVersionMutex.Unlock() + fake.GetPublicVersionStub = nil + fake.getPublicVersionReturns = struct { + result1 msp.Identity + }{result1} +} + +func (fake *SigningIdentity) GetPublicVersionReturnsOnCall(i int, result1 msp.Identity) { + fake.getPublicVersionMutex.Lock() + defer fake.getPublicVersionMutex.Unlock() + fake.GetPublicVersionStub = nil + if fake.getPublicVersionReturnsOnCall == nil { + fake.getPublicVersionReturnsOnCall = make(map[int]struct { + result1 msp.Identity + }) + } + fake.getPublicVersionReturnsOnCall[i] = struct { + result1 msp.Identity + }{result1} +} + +func (fake *SigningIdentity) SatisfiesPrincipal(arg1 *mspa.MSPPrincipal) error { + fake.satisfiesPrincipalMutex.Lock() + ret, specificReturn := fake.satisfiesPrincipalReturnsOnCall[len(fake.satisfiesPrincipalArgsForCall)] + fake.satisfiesPrincipalArgsForCall = append(fake.satisfiesPrincipalArgsForCall, struct { + arg1 *mspa.MSPPrincipal + }{arg1}) + fake.recordInvocation("SatisfiesPrincipal", []interface{}{arg1}) + fake.satisfiesPrincipalMutex.Unlock() + if fake.SatisfiesPrincipalStub != nil { + return fake.SatisfiesPrincipalStub(arg1) + } + if specificReturn { + return ret.result1 + } + fakeReturns := fake.satisfiesPrincipalReturns + return fakeReturns.result1 +} + +func (fake *SigningIdentity) SatisfiesPrincipalCallCount() int { + fake.satisfiesPrincipalMutex.RLock() + defer fake.satisfiesPrincipalMutex.RUnlock() + return len(fake.satisfiesPrincipalArgsForCall) +} + +func (fake *SigningIdentity) SatisfiesPrincipalCalls(stub func(*mspa.MSPPrincipal) error) { + fake.satisfiesPrincipalMutex.Lock() + defer fake.satisfiesPrincipalMutex.Unlock() + fake.SatisfiesPrincipalStub = stub +} + +func (fake *SigningIdentity) SatisfiesPrincipalArgsForCall(i int) *mspa.MSPPrincipal { + fake.satisfiesPrincipalMutex.RLock() + defer fake.satisfiesPrincipalMutex.RUnlock() + argsForCall := fake.satisfiesPrincipalArgsForCall[i] + return argsForCall.arg1 +} + +func (fake *SigningIdentity) SatisfiesPrincipalReturns(result1 error) { + fake.satisfiesPrincipalMutex.Lock() + defer fake.satisfiesPrincipalMutex.Unlock() + fake.SatisfiesPrincipalStub = nil + fake.satisfiesPrincipalReturns = struct { + result1 error + }{result1} +} + +func (fake *SigningIdentity) SatisfiesPrincipalReturnsOnCall(i int, result1 error) { + fake.satisfiesPrincipalMutex.Lock() + defer fake.satisfiesPrincipalMutex.Unlock() + fake.SatisfiesPrincipalStub = nil + if fake.satisfiesPrincipalReturnsOnCall == nil { + fake.satisfiesPrincipalReturnsOnCall = make(map[int]struct { + result1 error + }) + } + fake.satisfiesPrincipalReturnsOnCall[i] = struct { + result1 error + }{result1} +} + +func (fake *SigningIdentity) Serialize() ([]byte, error) { + fake.serializeMutex.Lock() + ret, specificReturn := fake.serializeReturnsOnCall[len(fake.serializeArgsForCall)] + fake.serializeArgsForCall = append(fake.serializeArgsForCall, struct { + }{}) + fake.recordInvocation("Serialize", []interface{}{}) + fake.serializeMutex.Unlock() + if fake.SerializeStub != nil { + return fake.SerializeStub() + } + if specificReturn { + return ret.result1, ret.result2 + } + fakeReturns := fake.serializeReturns + return fakeReturns.result1, fakeReturns.result2 +} + +func (fake *SigningIdentity) SerializeCallCount() int { + fake.serializeMutex.RLock() + defer fake.serializeMutex.RUnlock() + return len(fake.serializeArgsForCall) +} + +func (fake *SigningIdentity) SerializeCalls(stub func() ([]byte, error)) { + fake.serializeMutex.Lock() + defer fake.serializeMutex.Unlock() + fake.SerializeStub = stub +} + +func (fake *SigningIdentity) SerializeReturns(result1 []byte, result2 error) { + fake.serializeMutex.Lock() + defer fake.serializeMutex.Unlock() + fake.SerializeStub = nil + fake.serializeReturns = struct { + result1 []byte + result2 error + }{result1, result2} +} + +func (fake *SigningIdentity) SerializeReturnsOnCall(i int, result1 []byte, result2 error) { + fake.serializeMutex.Lock() + defer fake.serializeMutex.Unlock() + fake.SerializeStub = nil + if fake.serializeReturnsOnCall == nil { + fake.serializeReturnsOnCall = make(map[int]struct { + result1 []byte + result2 error + }) + } + fake.serializeReturnsOnCall[i] = struct { + result1 []byte + result2 error + }{result1, result2} +} + +func (fake *SigningIdentity) Sign(arg1 []byte) ([]byte, error) { + var arg1Copy []byte + if arg1 != nil { + arg1Copy = make([]byte, len(arg1)) + copy(arg1Copy, arg1) + } + fake.signMutex.Lock() + ret, specificReturn := fake.signReturnsOnCall[len(fake.signArgsForCall)] + fake.signArgsForCall = append(fake.signArgsForCall, struct { + arg1 []byte + }{arg1Copy}) + fake.recordInvocation("Sign", []interface{}{arg1Copy}) + fake.signMutex.Unlock() + if fake.SignStub != nil { + return fake.SignStub(arg1) + } + if specificReturn { + return ret.result1, ret.result2 + } + fakeReturns := fake.signReturns + return fakeReturns.result1, fakeReturns.result2 +} + +func (fake *SigningIdentity) SignCallCount() int { + fake.signMutex.RLock() + defer fake.signMutex.RUnlock() + return len(fake.signArgsForCall) +} + +func (fake *SigningIdentity) SignCalls(stub func([]byte) ([]byte, error)) { + fake.signMutex.Lock() + defer fake.signMutex.Unlock() + fake.SignStub = stub +} + +func (fake *SigningIdentity) SignArgsForCall(i int) []byte { + fake.signMutex.RLock() + defer fake.signMutex.RUnlock() + argsForCall := fake.signArgsForCall[i] + return argsForCall.arg1 +} + +func (fake *SigningIdentity) SignReturns(result1 []byte, result2 error) { + fake.signMutex.Lock() + defer fake.signMutex.Unlock() + fake.SignStub = nil + fake.signReturns = struct { + result1 []byte + result2 error + }{result1, result2} +} + +func (fake *SigningIdentity) SignReturnsOnCall(i int, result1 []byte, result2 error) { + fake.signMutex.Lock() + defer fake.signMutex.Unlock() + fake.SignStub = nil + if fake.signReturnsOnCall == nil { + fake.signReturnsOnCall = make(map[int]struct { + result1 []byte + result2 error + }) + } + fake.signReturnsOnCall[i] = struct { + result1 []byte + result2 error + }{result1, result2} +} + +func (fake *SigningIdentity) Validate() error { + fake.validateMutex.Lock() + ret, specificReturn := fake.validateReturnsOnCall[len(fake.validateArgsForCall)] + fake.validateArgsForCall = append(fake.validateArgsForCall, struct { + }{}) + fake.recordInvocation("Validate", []interface{}{}) + fake.validateMutex.Unlock() + if fake.ValidateStub != nil { + return fake.ValidateStub() + } + if specificReturn { + return ret.result1 + } + fakeReturns := fake.validateReturns + return fakeReturns.result1 +} + +func (fake *SigningIdentity) ValidateCallCount() int { + fake.validateMutex.RLock() + defer fake.validateMutex.RUnlock() + return len(fake.validateArgsForCall) +} + +func (fake *SigningIdentity) ValidateCalls(stub func() error) { + fake.validateMutex.Lock() + defer fake.validateMutex.Unlock() + fake.ValidateStub = stub +} + +func (fake *SigningIdentity) ValidateReturns(result1 error) { + fake.validateMutex.Lock() + defer fake.validateMutex.Unlock() + fake.ValidateStub = nil + fake.validateReturns = struct { + result1 error + }{result1} +} + +func (fake *SigningIdentity) ValidateReturnsOnCall(i int, result1 error) { + fake.validateMutex.Lock() + defer fake.validateMutex.Unlock() + fake.ValidateStub = nil + if fake.validateReturnsOnCall == nil { + fake.validateReturnsOnCall = make(map[int]struct { + result1 error + }) + } + fake.validateReturnsOnCall[i] = struct { + result1 error + }{result1} +} + +func (fake *SigningIdentity) Verify(arg1 []byte, arg2 []byte) error { + var arg1Copy []byte + if arg1 != nil { + arg1Copy = make([]byte, len(arg1)) + copy(arg1Copy, arg1) + } + var arg2Copy []byte + if arg2 != nil { + arg2Copy = make([]byte, len(arg2)) + copy(arg2Copy, arg2) + } + fake.verifyMutex.Lock() + ret, specificReturn := fake.verifyReturnsOnCall[len(fake.verifyArgsForCall)] + fake.verifyArgsForCall = append(fake.verifyArgsForCall, struct { + arg1 []byte + arg2 []byte + }{arg1Copy, arg2Copy}) + fake.recordInvocation("Verify", []interface{}{arg1Copy, arg2Copy}) + fake.verifyMutex.Unlock() + if fake.VerifyStub != nil { + return fake.VerifyStub(arg1, arg2) + } + if specificReturn { + return ret.result1 + } + fakeReturns := fake.verifyReturns + return fakeReturns.result1 +} + +func (fake *SigningIdentity) VerifyCallCount() int { + fake.verifyMutex.RLock() + defer fake.verifyMutex.RUnlock() + return len(fake.verifyArgsForCall) +} + +func (fake *SigningIdentity) VerifyCalls(stub func([]byte, []byte) error) { + fake.verifyMutex.Lock() + defer fake.verifyMutex.Unlock() + fake.VerifyStub = stub +} + +func (fake *SigningIdentity) VerifyArgsForCall(i int) ([]byte, []byte) { + fake.verifyMutex.RLock() + defer fake.verifyMutex.RUnlock() + argsForCall := fake.verifyArgsForCall[i] + return argsForCall.arg1, argsForCall.arg2 +} + +func (fake *SigningIdentity) VerifyReturns(result1 error) { + fake.verifyMutex.Lock() + defer fake.verifyMutex.Unlock() + fake.VerifyStub = nil + fake.verifyReturns = struct { + result1 error + }{result1} +} + +func (fake *SigningIdentity) VerifyReturnsOnCall(i int, result1 error) { + fake.verifyMutex.Lock() + defer fake.verifyMutex.Unlock() + fake.VerifyStub = nil + if fake.verifyReturnsOnCall == nil { + fake.verifyReturnsOnCall = make(map[int]struct { + result1 error + }) + } + fake.verifyReturnsOnCall[i] = struct { + result1 error + }{result1} +} + +func (fake *SigningIdentity) Invocations() map[string][][]interface{} { + fake.invocationsMutex.RLock() + defer fake.invocationsMutex.RUnlock() + fake.anonymousMutex.RLock() + defer fake.anonymousMutex.RUnlock() + fake.expiresAtMutex.RLock() + defer fake.expiresAtMutex.RUnlock() + fake.getIdentifierMutex.RLock() + defer fake.getIdentifierMutex.RUnlock() + fake.getMSPIdentifierMutex.RLock() + defer fake.getMSPIdentifierMutex.RUnlock() + fake.getOrganizationalUnitsMutex.RLock() + defer fake.getOrganizationalUnitsMutex.RUnlock() + fake.getPublicVersionMutex.RLock() + defer fake.getPublicVersionMutex.RUnlock() + fake.satisfiesPrincipalMutex.RLock() + defer fake.satisfiesPrincipalMutex.RUnlock() + fake.serializeMutex.RLock() + defer fake.serializeMutex.RUnlock() + fake.signMutex.RLock() + defer fake.signMutex.RUnlock() + fake.validateMutex.RLock() + defer fake.validateMutex.RUnlock() + fake.verifyMutex.RLock() + defer fake.verifyMutex.RUnlock() + copiedInvocations := map[string][][]interface{}{} + for key, value := range fake.invocations { + copiedInvocations[key] = value + } + return copiedInvocations +} + +func (fake *SigningIdentity) recordInvocation(key string, args []interface{}) { + fake.invocationsMutex.Lock() + defer fake.invocationsMutex.Unlock() + if fake.invocations == nil { + fake.invocations = map[string][][]interface{}{} + } + if fake.invocations[key] == nil { + fake.invocations[key] = [][]interface{}{} + } + fake.invocations[key] = append(fake.invocations[key], args) +} diff --git a/common/ledger/testutil/test_helper.go b/common/ledger/testutil/test_helper.go index 79ac74c21a4..8ff83496fb9 100644 --- a/common/ledger/testutil/test_helper.go +++ b/common/ledger/testutil/test_helper.go @@ -16,7 +16,8 @@ import ( "github.com/hyperledger/fabric/bccsp/sw" "github.com/hyperledger/fabric/common/configtx/test" "github.com/hyperledger/fabric/common/crypto" - mmsp "github.com/hyperledger/fabric/common/mocks/msp" + + "github.com/hyperledger/fabric/common/ledger/testutil/fakes" lutils "github.com/hyperledger/fabric/core/ledger/util" "github.com/hyperledger/fabric/msp" mspmgmt "github.com/hyperledger/fabric/msp/mgmt" @@ -64,6 +65,12 @@ type BlockDetails struct { Txs []*TxDetails } +//go:generate counterfeiter -o fakes/signing_identity.go --fake-name SigningIdentity . signingIdentity + +type signingIdentity interface { + msp.SigningIdentity +} + // NewBlockGenerator instantiates new BlockGenerator for testing func NewBlockGenerator(t *testing.T, ledgerID string, signTxs bool) (*BlockGenerator, *common.Block) { gb, err := test.MakeGenesisBlock(ledgerID) @@ -360,8 +367,8 @@ func ConstructUnsignedTxEnv( visibility []byte, headerType common.HeaderType, ) (*common.Envelope, string, error) { - mspLcl := mmsp.NewNoopMsp() - sigId, _ := mspLcl.GetDefaultSigningIdentity() + + sigId := &fakes.SigningIdentity{} return ConstructSignedTxEnv( chainID, diff --git a/common/mocks/msp/noopmsp.go b/common/mocks/msp/noopmsp.go deleted file mode 100644 index fcc56398955..00000000000 --- a/common/mocks/msp/noopmsp.go +++ /dev/null @@ -1,155 +0,0 @@ -/* -Copyright IBM Corp. 2016 All Rights Reserved. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package msp - -import ( - "time" - - "github.com/hyperledger/fabric-protos-go/msp" - m "github.com/hyperledger/fabric/msp" -) - -type noopmsp struct { -} - -// NewNoopMsp returns a no-op implementation of the MSP interface -func NewNoopMsp() m.MSP { - return &noopmsp{} -} - -func (msp *noopmsp) Setup(*msp.MSPConfig) error { - return nil -} - -func (msp *noopmsp) GetVersion() m.MSPVersion { - return m.MSPv1_0 -} - -func (msp *noopmsp) GetType() m.ProviderType { - return 0 -} - -func (msp *noopmsp) GetIdentifier() (string, error) { - return "NOOP", nil -} - -func (msp *noopmsp) GetSigningIdentity(identifier *m.IdentityIdentifier) (m.SigningIdentity, error) { - id, _ := newNoopSigningIdentity() - return id, nil -} - -func (msp *noopmsp) GetDefaultSigningIdentity() (m.SigningIdentity, error) { - id, _ := newNoopSigningIdentity() - return id, nil -} - -// GetRootCerts returns the root certificates for this MSP -func (msp *noopmsp) GetRootCerts() []m.Identity { - return nil -} - -// GetIntermediateCerts returns the intermediate root certificates for this MSP -func (msp *noopmsp) GetIntermediateCerts() []m.Identity { - return nil -} - -// GetTLSRootCerts returns the root certificates for this MSP -func (msp *noopmsp) GetTLSRootCerts() [][]byte { - return nil -} - -// GetTLSIntermediateCerts returns the intermediate root certificates for this MSP -func (msp *noopmsp) GetTLSIntermediateCerts() [][]byte { - return nil -} - -func (msp *noopmsp) DeserializeIdentity(serializedID []byte) (m.Identity, error) { - id, _ := newNoopIdentity() - return id, nil -} - -func (msp *noopmsp) Validate(id m.Identity) error { - return nil -} - -func (msp *noopmsp) SatisfiesPrincipal(id m.Identity, principal *msp.MSPPrincipal) error { - return nil -} - -// IsWellFormed checks if the given identity can be deserialized into its provider-specific form -func (msp *noopmsp) IsWellFormed(_ *msp.SerializedIdentity) error { - return nil -} - -type noopidentity struct { -} - -func newNoopIdentity() (m.Identity, error) { - return &noopidentity{}, nil -} - -func (id *noopidentity) Anonymous() bool { - panic("implement me") -} - -func (id *noopidentity) SatisfiesPrincipal(*msp.MSPPrincipal) error { - return nil -} - -func (id *noopidentity) ExpiresAt() time.Time { - return time.Time{} -} - -func (id *noopidentity) GetIdentifier() *m.IdentityIdentifier { - return &m.IdentityIdentifier{Mspid: "NOOP", Id: "Bob"} -} - -func (id *noopidentity) GetMSPIdentifier() string { - return "MSPID" -} - -func (id *noopidentity) Validate() error { - return nil -} - -func (id *noopidentity) GetOrganizationalUnits() []*m.OUIdentifier { - return nil -} - -func (id *noopidentity) Verify(msg []byte, sig []byte) error { - return nil -} - -func (id *noopidentity) Serialize() ([]byte, error) { - return []byte("cert"), nil -} - -type noopsigningidentity struct { - noopidentity -} - -func newNoopSigningIdentity() (m.SigningIdentity, error) { - return &noopsigningidentity{}, nil -} - -func (id *noopsigningidentity) Sign(msg []byte) ([]byte, error) { - return []byte("signature"), nil -} - -func (id *noopsigningidentity) GetPublicVersion() m.Identity { - return id -} diff --git a/common/mocks/msp/noopmsp_test.go b/common/mocks/msp/noopmsp_test.go deleted file mode 100644 index be573c88f3e..00000000000 --- a/common/mocks/msp/noopmsp_test.go +++ /dev/null @@ -1,60 +0,0 @@ -/* -Copyright IBM Corp. 2017 All Rights Reserved. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package msp - -import "testing" - -func TestNoopMSP(t *testing.T) { - noopmsp := NewNoopMsp() - - id, err := noopmsp.GetDefaultSigningIdentity() - if err != nil { - t.Fatalf("GetSigningIdentity should have succeeded") - return - } - - serializedID, err := id.Serialize() - if err != nil { - t.Fatalf("Serialize should have succeeded") - return - } - - idBack, err := noopmsp.DeserializeIdentity(serializedID) - if err != nil { - t.Fatalf("DeserializeIdentity should have succeeded") - return - } - - msg := []byte("foo") - sig, err := id.Sign(msg) - if err != nil { - t.Fatalf("Sign should have succeeded") - return - } - - err = id.Verify(msg, sig) - if err != nil { - t.Fatalf("The signature should be valid") - return - } - - err = idBack.Verify(msg, sig) - if err != nil { - t.Fatalf("The signature should be valid") - return - } -} diff --git a/common/mocks/policies/policies.go b/common/mocks/policies/policies.go deleted file mode 100644 index 17939e50e00..00000000000 --- a/common/mocks/policies/policies.go +++ /dev/null @@ -1,62 +0,0 @@ -/* -Copyright IBM Corp. All Rights Reserved. - -SPDX-License-Identifier: Apache-2.0 -*/ - -package policies - -import ( - "github.com/hyperledger/fabric/common/policies" - "github.com/hyperledger/fabric/msp" - "github.com/hyperledger/fabric/protoutil" -) - -// Policy is a mock implementation of the policies.Policy interface -type Policy struct { - // Err is the error returned by Evaluate - Err error -} - -// EvaluateSignedData returns the Err set in Policy -func (p *Policy) EvaluateSignedData(signatureSet []*protoutil.SignedData) error { - return p.Err -} - -// EvaluateIdentities returns nil -func (p *Policy) EvaluateIdentities(ids []msp.Identity) error { - return p.Err -} - -// Manager is a mock implementation of the policies.Manager interface -type Manager struct { - // Policy is returned as the output to GetPolicy if a Policy - // for id is not in PolicyMap - Policy *Policy - - // PolicyMap is returned is used to look up Policies in - PolicyMap map[string]policies.Policy - - // SubManagers is used for the return value of Manager - SubManagersMap map[string]*Manager -} - -// Manager returns the Manager from SubManagers for the last component of the path -func (m *Manager) Manager(path []string) (policies.Manager, bool) { - if len(path) == 0 { - return m, true - } - manager, ok := m.SubManagersMap[path[len(path)-1]] - return manager, ok -} - -// GetPolicy returns the value of Manager.Policy and whether it was nil or not -func (m *Manager) GetPolicy(id string) (policies.Policy, bool) { - if m.PolicyMap != nil { - policy, ok := m.PolicyMap[id] - if ok { - return policy, true - } - } - return m.Policy, m.Policy != nil -} diff --git a/common/mocks/policies/policies_test.go b/common/mocks/policies/policies_test.go deleted file mode 100644 index c01af1414e1..00000000000 --- a/common/mocks/policies/policies_test.go +++ /dev/null @@ -1,31 +0,0 @@ -/* -Copyright IBM Corp. 2016 All Rights Reserved. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package policies - -import ( - "testing" - - "github.com/hyperledger/fabric/common/policies" -) - -func TestPolicyManagerInterface(t *testing.T) { - _ = policies.Manager(&Manager{}) -} - -func TestPolicyInterface(t *testing.T) { - _ = policies.Policy(&Policy{}) -} diff --git a/core/chaincode/chaincode_suite_test.go b/core/chaincode/chaincode_suite_test.go index 650bc753add..e5f87d8dc22 100644 --- a/core/chaincode/chaincode_suite_test.go +++ b/core/chaincode/chaincode_suite_test.go @@ -11,6 +11,7 @@ import ( "github.com/hyperledger/fabric/common/channelconfig" commonledger "github.com/hyperledger/fabric/common/ledger" + "github.com/hyperledger/fabric/common/policies" "github.com/hyperledger/fabric/core/chaincode" "github.com/hyperledger/fabric/core/common/privdata" "github.com/hyperledger/fabric/core/container/ccintf" @@ -135,3 +136,13 @@ type applicationCapabilities interface { type applicationConfig interface { channelconfig.Application } + +//go:generate counterfeiter -o mock/policy_manager.go -fake-name PolicyManager . policyManager +type policyManager interface { + policies.Manager +} + +//go:generate counterfeiter -o mock/policy.go -fake-name Policy . policy +type policy interface { + policies.Policy +} diff --git a/core/chaincode/chaincode_support_test.go b/core/chaincode/chaincode_support_test.go index c1018b4c3b9..7d9f3a50bcc 100644 --- a/core/chaincode/chaincode_support_test.go +++ b/core/chaincode/chaincode_support_test.go @@ -270,7 +270,7 @@ func initMockPeer(channelIDs ...string) (*peer.Peer, *ChaincodeSupport, func(), globalBlockNum = make(map[string]uint64, len(channelIDs)) for _, id := range channelIDs { - if err := peer.CreateMockChannel(peerInstance, id); err != nil { + if err := peer.CreateMockChannel(peerInstance, id, &mock.PolicyManager{}); err != nil { cleanup() return nil, nil, func() {}, err } diff --git a/core/chaincode/exectransaction_test.go b/core/chaincode/exectransaction_test.go index 537bab182a7..a1e79da028d 100644 --- a/core/chaincode/exectransaction_test.go +++ b/core/chaincode/exectransaction_test.go @@ -36,7 +36,7 @@ import ( "github.com/hyperledger/fabric/common/crypto/tlsgen" "github.com/hyperledger/fabric/common/flogging" "github.com/hyperledger/fabric/common/metrics/disabled" - mockpolicies "github.com/hyperledger/fabric/common/mocks/policies" + "github.com/hyperledger/fabric/common/policies" "github.com/hyperledger/fabric/common/util" "github.com/hyperledger/fabric/core/aclmgmt" @@ -57,7 +57,7 @@ import ( cut "github.com/hyperledger/fabric/core/ledger/util" "github.com/hyperledger/fabric/core/peer" "github.com/hyperledger/fabric/core/policy" - "github.com/hyperledger/fabric/core/policy/mocks" + policymocks "github.com/hyperledger/fabric/core/policy/mocks" "github.com/hyperledger/fabric/core/scc" "github.com/hyperledger/fabric/core/scc/lscc" "github.com/hyperledger/fabric/internal/peer/packaging" @@ -211,17 +211,6 @@ func initPeer(channelIDs ...string) (*cm.Lifecycle, net.Listener, *ChaincodeSupp scc.DeploySysCC(lsccImpl, chaincodeSupport) - for _, id := range channelIDs { - if err = peer.CreateMockChannel(peerInstance, id); err != nil { - closeListenerAndSleep(lis) - return nil, nil, nil, nil, err - } - // any channel other than the default testchannelid does not have a MSP set up -> create one - if id != "testchannelid" { - mspmgmt.XXXSetMSPManager(id, mspmgmt.GetManagerForChain("testchannelid")) - } - } - go grpcServer.Serve(lis) cleanup := func() { @@ -622,9 +611,9 @@ const ( // Test the execution of a chaincode that invokes another chaincode. func TestChaincodeInvokeChaincode(t *testing.T) { - channel := "testchannelid" - channel2 := channel + "2" - ml, lis, chaincodeSupport, cleanup, err := initPeer(channel, channel2) + channel1 := "testchannelid" + channel2 := channel1 + "2" + ml, lis, chaincodeSupport, cleanup, err := initPeer(channel1, channel2) if err != nil { t.Fail() t.Logf("Error creating peer: %s", err) @@ -632,6 +621,23 @@ func TestChaincodeInvokeChaincode(t *testing.T) { defer cleanup() defer closeListenerAndSleep(lis) + mockPolicy := &mock.Policy{} + mockPolicy.EvaluateSignedDataReturns(nil) + + polMgrChannel1 := &mock.PolicyManager{} + polMgrChannel1.GetPolicyReturns(mockPolicy, true) + err = peer.CreateMockChannel(chaincodeSupport.Peer, channel1, polMgrChannel1) + if err != nil { + t.Fatalf("Failed to create mock channel: %s", err) + } + + polMgrChannel2 := &mock.PolicyManager{} + polMgrChannel2.GetPolicyReturns(mockPolicy, true) + err = peer.CreateMockChannel(chaincodeSupport.Peer, channel2, polMgrChannel2) + if err != nil { + t.Fatalf("Failed to create mock channel: %s", err) + } + peerInstance := chaincodeSupport.Peer var nextBlockNumber1 uint64 = 1 @@ -661,7 +667,7 @@ func TestChaincodeInvokeChaincode(t *testing.T) { pb.ChaincodeSpec_GOLANG, chaincodeExample02GolangPath, util.ToChaincodeArgs("init", "a", strconv.Itoa(initialA), "b", strconv.Itoa(initialB)), - channel, + channel1, nextBlockNumber1, chaincodeSupport, ) @@ -682,7 +688,7 @@ func TestChaincodeInvokeChaincode(t *testing.T) { chaincode2Type, chaincode2Path, util.ToChaincodeArgs("init"), - channel, + channel1, nextBlockNumber1, chaincodeSupport, ) @@ -703,27 +709,21 @@ func TestChaincodeInvokeChaincode(t *testing.T) { Args: util.ToChaincodeArgs(ccContext1.Name, "invoke", "a", "b", "10", ""), }, } - _, _, _, err = invoke(channel, chaincode2InvokeSpec, nextBlockNumber1, []byte("Alice"), chaincodeSupport) + _, _, _, err = invoke(channel1, chaincode2InvokeSpec, nextBlockNumber1, []byte("Alice"), chaincodeSupport) require.NoErrorf(t, err, "error invoking %s: %s", chaincode2Name, err) nextBlockNumber1++ // Check the state in the ledger - err = checkFinalState(peerInstance, channel, ccContext1, initialA-10, initialB+10) + err = checkFinalState(peerInstance, channel1, ccContext1, initialA-10, initialB+10) require.NoErrorf(t, err, "incorrect final state after transaction for %s: %s", chaincode1Name, err) // Change the policies of the two channels in such a way: // 1. Alice has reader access to both the channels. // 2. Bob has access only to chainID2. // Therefore the chaincode invocation should fail. - pm := peerInstance.GetPolicyManager(channel) - pm.(*mockpolicies.Manager).PolicyMap = map[string]policies.Policy{ - policies.ChannelApplicationWriters: &CreatorPolicy{Creators: [][]byte{[]byte("Alice")}}, - } - pm = peerInstance.GetPolicyManager(channel2) - pm.(*mockpolicies.Manager).PolicyMap = map[string]policies.Policy{ - policies.ChannelApplicationWriters: &CreatorPolicy{Creators: [][]byte{[]byte("Alice"), []byte("Bob")}}, - } + polMgrChannel1.GetPolicyReturns(&CreatorPolicy{Creators: [][]byte{[]byte("Alice")}}, true) + polMgrChannel2.GetPolicyReturns(&CreatorPolicy{Creators: [][]byte{[]byte("Alice"), []byte("Bob")}}, true) // deploy chaincode2 on channel2 _, ccContext3, err := deployChaincode( @@ -748,18 +748,18 @@ func TestChaincodeInvokeChaincode(t *testing.T) { Version: chaincode2Version, }, Input: &pb.ChaincodeInput{ - Args: util.ToChaincodeArgs(ccContext1.Name, "invoke", "a", "b", "10", channel), + Args: util.ToChaincodeArgs(ccContext1.Name, "invoke", "a", "b", "10", channel1), }, } // as Bob, invoke chaincode2 on channel2 so that it invokes chaincode1 on channel _, _, _, err = invoke(channel2, chaincode2InvokeSpec, nextBlockNumber2, []byte("Bob"), chaincodeSupport) - require.Errorf(t, err, "as Bob, invoking <%s/%s> via <%s/%s> should fail, but it succeeded.", ccContext1.Name, channel, chaincode2Name, channel2) + require.Errorf(t, err, "as Bob, invoking <%s/%s> via <%s/%s> should fail, but it succeeded.", ccContext1.Name, channel1, chaincode2Name, channel2) assert.True(t, strings.Contains(err.Error(), "[Creator not recognized [Bob]]")) // as Alice, invoke chaincode2 on channel2 so that it invokes chaincode1 on channel _, _, _, err = invoke(channel2, chaincode2InvokeSpec, nextBlockNumber2, []byte("Alice"), chaincodeSupport) - require.NoError(t, err, "as Alice, invoking <%s/%s> via <%s/%s> should should of succeeded, but it failed: %s", ccContext1.Name, channel, chaincode2Name, channel2, err) + require.NoError(t, err, "as Alice, invoking <%s/%s> via <%s/%s> should should of succeeded, but it failed: %s", ccContext1.Name, channel1, chaincode2Name, channel2, err) nextBlockNumber2++ } @@ -779,6 +779,14 @@ func TestChaincodeInvokeChaincodeErrorCase(t *testing.T) { } defer cleanup() + polMgr := &mock.PolicyManager{} + mockPolicy := &mock.Policy{} + mockPolicy.EvaluateIdentitiesReturns(nil) + mockPolicy.EvaluateSignedDataReturns(nil) + polMgr.GetPolicyReturns(mockPolicy, true) + + peer.CreateMockChannel(chaincodeSupport.Peer, channelID, polMgr) + ml.ChaincodeEndorsementInfoStub = func(_, name string, _ ledger.SimpleQueryExecutor) (*lifecycle.ChaincodeEndorsementInfo, error) { switch name { case "lscc": @@ -874,6 +882,8 @@ func TestChaincodeInit(t *testing.T) { defer cleanup() + peer.CreateMockChannel(chaincodeSupport.Peer, channelID, nil) + url := "github.com/hyperledger/fabric/core/chaincode/testdata/src/chaincodes/init_private_data" cID := &pb.ChaincodeID{Name: "init_pvtdata", Path: url, Version: "0"} @@ -928,6 +938,8 @@ func TestQueries(t *testing.T) { defer cleanup() + peer.CreateMockChannel(chaincodeSupport.Peer, channelID, nil) + url := "github.com/hyperledger/fabric/core/chaincode/testdata/src/chaincodes/map" cID := &pb.ChaincodeID{Name: "tmap", Path: url, Version: "0"} @@ -1271,10 +1283,10 @@ func (c *CreatorPolicy) EvaluateIdentities(identities []msp.Identity) error { func newPolicyChecker(peerInstance *peer.Peer) policy.PolicyChecker { return policy.NewPolicyChecker( policies.PolicyManagerGetterFunc(peerInstance.GetPolicyManager), - &mocks.MockIdentityDeserializer{ + &policymocks.MockIdentityDeserializer{ Identity: []byte("Admin"), Msg: []byte("msg1"), }, - &mocks.MockMSPPrincipalGetter{Principal: []byte("Admin")}, + &policymocks.MockMSPPrincipalGetter{Principal: []byte("Admin")}, ) } diff --git a/core/chaincode/executetransaction_pvtdata_test.go b/core/chaincode/executetransaction_pvtdata_test.go index 0a4d5a9f4d7..1356936abcf 100644 --- a/core/chaincode/executetransaction_pvtdata_test.go +++ b/core/chaincode/executetransaction_pvtdata_test.go @@ -15,6 +15,7 @@ import ( "github.com/hyperledger/fabric-protos-go/common" pb "github.com/hyperledger/fabric-protos-go/peer" "github.com/hyperledger/fabric/common/util" + "github.com/hyperledger/fabric/core/peer" "github.com/spf13/viper" "github.com/stretchr/testify/assert" ) @@ -35,6 +36,8 @@ func TestQueriesPrivateData(t *testing.T) { defer cleanup() + peer.CreateMockChannel(chaincodeSupport.Peer, channelID, nil) + url := "github.com/hyperledger/fabric/core/chaincode/testdata/src/chaincodes/map" cID := &pb.ChaincodeID{Name: "tmap", Path: url, Version: "0"} diff --git a/core/chaincode/mock/collection_store.go b/core/chaincode/mock/collection_store.go index 1f6fe93445a..4118abaf80b 100644 --- a/core/chaincode/mock/collection_store.go +++ b/core/chaincode/mock/collection_store.go @@ -593,5 +593,3 @@ func (fake *CollectionStore) recordInvocation(key string, args []interface{}) { } fake.invocations[key] = append(fake.invocations[key], args) } - -var _ privdata.CollectionStore = new(CollectionStore) diff --git a/core/chaincode/mock/policy.go b/core/chaincode/mock/policy.go new file mode 100644 index 00000000000..08749bda11a --- /dev/null +++ b/core/chaincode/mock/policy.go @@ -0,0 +1,192 @@ +// Code generated by counterfeiter. DO NOT EDIT. +package mock + +import ( + "sync" + + "github.com/hyperledger/fabric/msp" + "github.com/hyperledger/fabric/protoutil" +) + +type Policy struct { + EvaluateIdentitiesStub func([]msp.Identity) error + evaluateIdentitiesMutex sync.RWMutex + evaluateIdentitiesArgsForCall []struct { + arg1 []msp.Identity + } + evaluateIdentitiesReturns struct { + result1 error + } + evaluateIdentitiesReturnsOnCall map[int]struct { + result1 error + } + EvaluateSignedDataStub func([]*protoutil.SignedData) error + evaluateSignedDataMutex sync.RWMutex + evaluateSignedDataArgsForCall []struct { + arg1 []*protoutil.SignedData + } + evaluateSignedDataReturns struct { + result1 error + } + evaluateSignedDataReturnsOnCall map[int]struct { + result1 error + } + invocations map[string][][]interface{} + invocationsMutex sync.RWMutex +} + +func (fake *Policy) EvaluateIdentities(arg1 []msp.Identity) error { + var arg1Copy []msp.Identity + if arg1 != nil { + arg1Copy = make([]msp.Identity, len(arg1)) + copy(arg1Copy, arg1) + } + fake.evaluateIdentitiesMutex.Lock() + ret, specificReturn := fake.evaluateIdentitiesReturnsOnCall[len(fake.evaluateIdentitiesArgsForCall)] + fake.evaluateIdentitiesArgsForCall = append(fake.evaluateIdentitiesArgsForCall, struct { + arg1 []msp.Identity + }{arg1Copy}) + fake.recordInvocation("EvaluateIdentities", []interface{}{arg1Copy}) + fake.evaluateIdentitiesMutex.Unlock() + if fake.EvaluateIdentitiesStub != nil { + return fake.EvaluateIdentitiesStub(arg1) + } + if specificReturn { + return ret.result1 + } + fakeReturns := fake.evaluateIdentitiesReturns + return fakeReturns.result1 +} + +func (fake *Policy) EvaluateIdentitiesCallCount() int { + fake.evaluateIdentitiesMutex.RLock() + defer fake.evaluateIdentitiesMutex.RUnlock() + return len(fake.evaluateIdentitiesArgsForCall) +} + +func (fake *Policy) EvaluateIdentitiesCalls(stub func([]msp.Identity) error) { + fake.evaluateIdentitiesMutex.Lock() + defer fake.evaluateIdentitiesMutex.Unlock() + fake.EvaluateIdentitiesStub = stub +} + +func (fake *Policy) EvaluateIdentitiesArgsForCall(i int) []msp.Identity { + fake.evaluateIdentitiesMutex.RLock() + defer fake.evaluateIdentitiesMutex.RUnlock() + argsForCall := fake.evaluateIdentitiesArgsForCall[i] + return argsForCall.arg1 +} + +func (fake *Policy) EvaluateIdentitiesReturns(result1 error) { + fake.evaluateIdentitiesMutex.Lock() + defer fake.evaluateIdentitiesMutex.Unlock() + fake.EvaluateIdentitiesStub = nil + fake.evaluateIdentitiesReturns = struct { + result1 error + }{result1} +} + +func (fake *Policy) EvaluateIdentitiesReturnsOnCall(i int, result1 error) { + fake.evaluateIdentitiesMutex.Lock() + defer fake.evaluateIdentitiesMutex.Unlock() + fake.EvaluateIdentitiesStub = nil + if fake.evaluateIdentitiesReturnsOnCall == nil { + fake.evaluateIdentitiesReturnsOnCall = make(map[int]struct { + result1 error + }) + } + fake.evaluateIdentitiesReturnsOnCall[i] = struct { + result1 error + }{result1} +} + +func (fake *Policy) EvaluateSignedData(arg1 []*protoutil.SignedData) error { + var arg1Copy []*protoutil.SignedData + if arg1 != nil { + arg1Copy = make([]*protoutil.SignedData, len(arg1)) + copy(arg1Copy, arg1) + } + fake.evaluateSignedDataMutex.Lock() + ret, specificReturn := fake.evaluateSignedDataReturnsOnCall[len(fake.evaluateSignedDataArgsForCall)] + fake.evaluateSignedDataArgsForCall = append(fake.evaluateSignedDataArgsForCall, struct { + arg1 []*protoutil.SignedData + }{arg1Copy}) + fake.recordInvocation("EvaluateSignedData", []interface{}{arg1Copy}) + fake.evaluateSignedDataMutex.Unlock() + if fake.EvaluateSignedDataStub != nil { + return fake.EvaluateSignedDataStub(arg1) + } + if specificReturn { + return ret.result1 + } + fakeReturns := fake.evaluateSignedDataReturns + return fakeReturns.result1 +} + +func (fake *Policy) EvaluateSignedDataCallCount() int { + fake.evaluateSignedDataMutex.RLock() + defer fake.evaluateSignedDataMutex.RUnlock() + return len(fake.evaluateSignedDataArgsForCall) +} + +func (fake *Policy) EvaluateSignedDataCalls(stub func([]*protoutil.SignedData) error) { + fake.evaluateSignedDataMutex.Lock() + defer fake.evaluateSignedDataMutex.Unlock() + fake.EvaluateSignedDataStub = stub +} + +func (fake *Policy) EvaluateSignedDataArgsForCall(i int) []*protoutil.SignedData { + fake.evaluateSignedDataMutex.RLock() + defer fake.evaluateSignedDataMutex.RUnlock() + argsForCall := fake.evaluateSignedDataArgsForCall[i] + return argsForCall.arg1 +} + +func (fake *Policy) EvaluateSignedDataReturns(result1 error) { + fake.evaluateSignedDataMutex.Lock() + defer fake.evaluateSignedDataMutex.Unlock() + fake.EvaluateSignedDataStub = nil + fake.evaluateSignedDataReturns = struct { + result1 error + }{result1} +} + +func (fake *Policy) EvaluateSignedDataReturnsOnCall(i int, result1 error) { + fake.evaluateSignedDataMutex.Lock() + defer fake.evaluateSignedDataMutex.Unlock() + fake.EvaluateSignedDataStub = nil + if fake.evaluateSignedDataReturnsOnCall == nil { + fake.evaluateSignedDataReturnsOnCall = make(map[int]struct { + result1 error + }) + } + fake.evaluateSignedDataReturnsOnCall[i] = struct { + result1 error + }{result1} +} + +func (fake *Policy) Invocations() map[string][][]interface{} { + fake.invocationsMutex.RLock() + defer fake.invocationsMutex.RUnlock() + fake.evaluateIdentitiesMutex.RLock() + defer fake.evaluateIdentitiesMutex.RUnlock() + fake.evaluateSignedDataMutex.RLock() + defer fake.evaluateSignedDataMutex.RUnlock() + copiedInvocations := map[string][][]interface{}{} + for key, value := range fake.invocations { + copiedInvocations[key] = value + } + return copiedInvocations +} + +func (fake *Policy) recordInvocation(key string, args []interface{}) { + fake.invocationsMutex.Lock() + defer fake.invocationsMutex.Unlock() + if fake.invocations == nil { + fake.invocations = map[string][][]interface{}{} + } + if fake.invocations[key] == nil { + fake.invocations[key] = [][]interface{}{} + } + fake.invocations[key] = append(fake.invocations[key], args) +} diff --git a/core/chaincode/mock/policy_manager.go b/core/chaincode/mock/policy_manager.go new file mode 100644 index 00000000000..6245db27d2e --- /dev/null +++ b/core/chaincode/mock/policy_manager.go @@ -0,0 +1,196 @@ +// Code generated by counterfeiter. DO NOT EDIT. +package mock + +import ( + "sync" + + "github.com/hyperledger/fabric/common/policies" +) + +type PolicyManager struct { + GetPolicyStub func(string) (policies.Policy, bool) + getPolicyMutex sync.RWMutex + getPolicyArgsForCall []struct { + arg1 string + } + getPolicyReturns struct { + result1 policies.Policy + result2 bool + } + getPolicyReturnsOnCall map[int]struct { + result1 policies.Policy + result2 bool + } + ManagerStub func([]string) (policies.Manager, bool) + managerMutex sync.RWMutex + managerArgsForCall []struct { + arg1 []string + } + managerReturns struct { + result1 policies.Manager + result2 bool + } + managerReturnsOnCall map[int]struct { + result1 policies.Manager + result2 bool + } + invocations map[string][][]interface{} + invocationsMutex sync.RWMutex +} + +func (fake *PolicyManager) GetPolicy(arg1 string) (policies.Policy, bool) { + fake.getPolicyMutex.Lock() + ret, specificReturn := fake.getPolicyReturnsOnCall[len(fake.getPolicyArgsForCall)] + fake.getPolicyArgsForCall = append(fake.getPolicyArgsForCall, struct { + arg1 string + }{arg1}) + fake.recordInvocation("GetPolicy", []interface{}{arg1}) + fake.getPolicyMutex.Unlock() + if fake.GetPolicyStub != nil { + return fake.GetPolicyStub(arg1) + } + if specificReturn { + return ret.result1, ret.result2 + } + fakeReturns := fake.getPolicyReturns + return fakeReturns.result1, fakeReturns.result2 +} + +func (fake *PolicyManager) GetPolicyCallCount() int { + fake.getPolicyMutex.RLock() + defer fake.getPolicyMutex.RUnlock() + return len(fake.getPolicyArgsForCall) +} + +func (fake *PolicyManager) GetPolicyCalls(stub func(string) (policies.Policy, bool)) { + fake.getPolicyMutex.Lock() + defer fake.getPolicyMutex.Unlock() + fake.GetPolicyStub = stub +} + +func (fake *PolicyManager) GetPolicyArgsForCall(i int) string { + fake.getPolicyMutex.RLock() + defer fake.getPolicyMutex.RUnlock() + argsForCall := fake.getPolicyArgsForCall[i] + return argsForCall.arg1 +} + +func (fake *PolicyManager) GetPolicyReturns(result1 policies.Policy, result2 bool) { + fake.getPolicyMutex.Lock() + defer fake.getPolicyMutex.Unlock() + fake.GetPolicyStub = nil + fake.getPolicyReturns = struct { + result1 policies.Policy + result2 bool + }{result1, result2} +} + +func (fake *PolicyManager) GetPolicyReturnsOnCall(i int, result1 policies.Policy, result2 bool) { + fake.getPolicyMutex.Lock() + defer fake.getPolicyMutex.Unlock() + fake.GetPolicyStub = nil + if fake.getPolicyReturnsOnCall == nil { + fake.getPolicyReturnsOnCall = make(map[int]struct { + result1 policies.Policy + result2 bool + }) + } + fake.getPolicyReturnsOnCall[i] = struct { + result1 policies.Policy + result2 bool + }{result1, result2} +} + +func (fake *PolicyManager) Manager(arg1 []string) (policies.Manager, bool) { + var arg1Copy []string + if arg1 != nil { + arg1Copy = make([]string, len(arg1)) + copy(arg1Copy, arg1) + } + fake.managerMutex.Lock() + ret, specificReturn := fake.managerReturnsOnCall[len(fake.managerArgsForCall)] + fake.managerArgsForCall = append(fake.managerArgsForCall, struct { + arg1 []string + }{arg1Copy}) + fake.recordInvocation("Manager", []interface{}{arg1Copy}) + fake.managerMutex.Unlock() + if fake.ManagerStub != nil { + return fake.ManagerStub(arg1) + } + if specificReturn { + return ret.result1, ret.result2 + } + fakeReturns := fake.managerReturns + return fakeReturns.result1, fakeReturns.result2 +} + +func (fake *PolicyManager) ManagerCallCount() int { + fake.managerMutex.RLock() + defer fake.managerMutex.RUnlock() + return len(fake.managerArgsForCall) +} + +func (fake *PolicyManager) ManagerCalls(stub func([]string) (policies.Manager, bool)) { + fake.managerMutex.Lock() + defer fake.managerMutex.Unlock() + fake.ManagerStub = stub +} + +func (fake *PolicyManager) ManagerArgsForCall(i int) []string { + fake.managerMutex.RLock() + defer fake.managerMutex.RUnlock() + argsForCall := fake.managerArgsForCall[i] + return argsForCall.arg1 +} + +func (fake *PolicyManager) ManagerReturns(result1 policies.Manager, result2 bool) { + fake.managerMutex.Lock() + defer fake.managerMutex.Unlock() + fake.ManagerStub = nil + fake.managerReturns = struct { + result1 policies.Manager + result2 bool + }{result1, result2} +} + +func (fake *PolicyManager) ManagerReturnsOnCall(i int, result1 policies.Manager, result2 bool) { + fake.managerMutex.Lock() + defer fake.managerMutex.Unlock() + fake.ManagerStub = nil + if fake.managerReturnsOnCall == nil { + fake.managerReturnsOnCall = make(map[int]struct { + result1 policies.Manager + result2 bool + }) + } + fake.managerReturnsOnCall[i] = struct { + result1 policies.Manager + result2 bool + }{result1, result2} +} + +func (fake *PolicyManager) Invocations() map[string][][]interface{} { + fake.invocationsMutex.RLock() + defer fake.invocationsMutex.RUnlock() + fake.getPolicyMutex.RLock() + defer fake.getPolicyMutex.RUnlock() + fake.managerMutex.RLock() + defer fake.managerMutex.RUnlock() + copiedInvocations := map[string][][]interface{}{} + for key, value := range fake.invocations { + copiedInvocations[key] = value + } + return copiedInvocations +} + +func (fake *PolicyManager) recordInvocation(key string, args []interface{}) { + fake.invocationsMutex.Lock() + defer fake.invocationsMutex.Unlock() + if fake.invocations == nil { + fake.invocations = map[string][][]interface{}{} + } + if fake.invocations[key] == nil { + fake.invocations[key] = [][]interface{}{} + } + fake.invocations[key] = append(fake.invocations[key], args) +} diff --git a/core/ledger/kvledger/tests/fakes/signer.go b/core/ledger/kvledger/tests/fakes/signer.go new file mode 100644 index 00000000000..b7854e8d6ff --- /dev/null +++ b/core/ledger/kvledger/tests/fakes/signer.go @@ -0,0 +1,185 @@ +// Code generated by counterfeiter. DO NOT EDIT. +package fakes + +import ( + "sync" +) + +type Signer struct { + SerializeStub func() ([]byte, error) + serializeMutex sync.RWMutex + serializeArgsForCall []struct { + } + serializeReturns struct { + result1 []byte + result2 error + } + serializeReturnsOnCall map[int]struct { + result1 []byte + result2 error + } + SignStub func([]byte) ([]byte, error) + signMutex sync.RWMutex + signArgsForCall []struct { + arg1 []byte + } + signReturns struct { + result1 []byte + result2 error + } + signReturnsOnCall map[int]struct { + result1 []byte + result2 error + } + invocations map[string][][]interface{} + invocationsMutex sync.RWMutex +} + +func (fake *Signer) Serialize() ([]byte, error) { + fake.serializeMutex.Lock() + ret, specificReturn := fake.serializeReturnsOnCall[len(fake.serializeArgsForCall)] + fake.serializeArgsForCall = append(fake.serializeArgsForCall, struct { + }{}) + fake.recordInvocation("Serialize", []interface{}{}) + fake.serializeMutex.Unlock() + if fake.SerializeStub != nil { + return fake.SerializeStub() + } + if specificReturn { + return ret.result1, ret.result2 + } + fakeReturns := fake.serializeReturns + return fakeReturns.result1, fakeReturns.result2 +} + +func (fake *Signer) SerializeCallCount() int { + fake.serializeMutex.RLock() + defer fake.serializeMutex.RUnlock() + return len(fake.serializeArgsForCall) +} + +func (fake *Signer) SerializeCalls(stub func() ([]byte, error)) { + fake.serializeMutex.Lock() + defer fake.serializeMutex.Unlock() + fake.SerializeStub = stub +} + +func (fake *Signer) SerializeReturns(result1 []byte, result2 error) { + fake.serializeMutex.Lock() + defer fake.serializeMutex.Unlock() + fake.SerializeStub = nil + fake.serializeReturns = struct { + result1 []byte + result2 error + }{result1, result2} +} + +func (fake *Signer) SerializeReturnsOnCall(i int, result1 []byte, result2 error) { + fake.serializeMutex.Lock() + defer fake.serializeMutex.Unlock() + fake.SerializeStub = nil + if fake.serializeReturnsOnCall == nil { + fake.serializeReturnsOnCall = make(map[int]struct { + result1 []byte + result2 error + }) + } + fake.serializeReturnsOnCall[i] = struct { + result1 []byte + result2 error + }{result1, result2} +} + +func (fake *Signer) Sign(arg1 []byte) ([]byte, error) { + var arg1Copy []byte + if arg1 != nil { + arg1Copy = make([]byte, len(arg1)) + copy(arg1Copy, arg1) + } + fake.signMutex.Lock() + ret, specificReturn := fake.signReturnsOnCall[len(fake.signArgsForCall)] + fake.signArgsForCall = append(fake.signArgsForCall, struct { + arg1 []byte + }{arg1Copy}) + fake.recordInvocation("Sign", []interface{}{arg1Copy}) + fake.signMutex.Unlock() + if fake.SignStub != nil { + return fake.SignStub(arg1) + } + if specificReturn { + return ret.result1, ret.result2 + } + fakeReturns := fake.signReturns + return fakeReturns.result1, fakeReturns.result2 +} + +func (fake *Signer) SignCallCount() int { + fake.signMutex.RLock() + defer fake.signMutex.RUnlock() + return len(fake.signArgsForCall) +} + +func (fake *Signer) SignCalls(stub func([]byte) ([]byte, error)) { + fake.signMutex.Lock() + defer fake.signMutex.Unlock() + fake.SignStub = stub +} + +func (fake *Signer) SignArgsForCall(i int) []byte { + fake.signMutex.RLock() + defer fake.signMutex.RUnlock() + argsForCall := fake.signArgsForCall[i] + return argsForCall.arg1 +} + +func (fake *Signer) SignReturns(result1 []byte, result2 error) { + fake.signMutex.Lock() + defer fake.signMutex.Unlock() + fake.SignStub = nil + fake.signReturns = struct { + result1 []byte + result2 error + }{result1, result2} +} + +func (fake *Signer) SignReturnsOnCall(i int, result1 []byte, result2 error) { + fake.signMutex.Lock() + defer fake.signMutex.Unlock() + fake.SignStub = nil + if fake.signReturnsOnCall == nil { + fake.signReturnsOnCall = make(map[int]struct { + result1 []byte + result2 error + }) + } + fake.signReturnsOnCall[i] = struct { + result1 []byte + result2 error + }{result1, result2} +} + +func (fake *Signer) Invocations() map[string][][]interface{} { + fake.invocationsMutex.RLock() + defer fake.invocationsMutex.RUnlock() + fake.serializeMutex.RLock() + defer fake.serializeMutex.RUnlock() + fake.signMutex.RLock() + defer fake.signMutex.RUnlock() + copiedInvocations := map[string][][]interface{}{} + for key, value := range fake.invocations { + copiedInvocations[key] = value + } + return copiedInvocations +} + +func (fake *Signer) recordInvocation(key string, args []interface{}) { + fake.invocationsMutex.Lock() + defer fake.invocationsMutex.Unlock() + if fake.invocations == nil { + fake.invocations = map[string][][]interface{}{} + } + if fake.invocations[key] == nil { + fake.invocations[key] = [][]interface{}{} + } + fake.invocations[key] = append(fake.invocations[key], args) +} diff --git a/core/ledger/kvledger/tests/util.go b/core/ledger/kvledger/tests/util.go index f7aa6cebc0e..f3640779172 100644 --- a/core/ledger/kvledger/tests/util.go +++ b/core/ledger/kvledger/tests/util.go @@ -15,7 +15,7 @@ import ( configtxtest "github.com/hyperledger/fabric/common/configtx/test" "github.com/hyperledger/fabric/common/crypto" "github.com/hyperledger/fabric/common/flogging" - mmsp "github.com/hyperledger/fabric/common/mocks/msp" + "github.com/hyperledger/fabric/core/ledger/kvledger/tests/fakes" lutils "github.com/hyperledger/fabric/core/ledger/util" "github.com/hyperledger/fabric/protoutil" ) @@ -38,6 +38,13 @@ type txAndPvtdata struct { Pvtws *rwset.TxPvtReadWriteSet } +//go:generate counterfeiter -o fakes/signer.go --fake-name Signer . signer + +type signer interface { + Sign(msg []byte) ([]byte, error) + Serialize() ([]byte, error) +} + func convertToCollConfigProtoBytes(collConfs []*collConf) ([]byte, error) { var protoConfArray []*common.CollectionConfig for _, c := range collConfs { @@ -122,8 +129,10 @@ func constructUnsignedTxEnv( visibility []byte, headerType common.HeaderType, ) (*common.Envelope, string, error) { - mspLcl := mmsp.NewNoopMsp() - sigID, _ := mspLcl.GetDefaultSigningIdentity() + + sigID := &fakes.Signer{} + sigID.SerializeReturns([]byte("signer"), nil) + sigID.SignReturns([]byte("signature"), nil) ss, err := sigID.Serialize() if err != nil { diff --git a/core/mocks/txvalidator/support.go b/core/mocks/txvalidator/support.go index a7f5e2f133c..7b1d1b7e2a2 100644 --- a/core/mocks/txvalidator/support.go +++ b/core/mocks/txvalidator/support.go @@ -21,8 +21,6 @@ import ( "github.com/hyperledger/fabric-protos-go/common" "github.com/hyperledger/fabric/common/channelconfig" - mockpolicies "github.com/hyperledger/fabric/common/mocks/policies" - "github.com/hyperledger/fabric/common/policies" "github.com/hyperledger/fabric/core/ledger" "github.com/hyperledger/fabric/msp" ) @@ -63,10 +61,6 @@ func (ms *Support) Apply(configtx *common.ConfigEnvelope) error { return ms.ApplyVal } -func (ms *Support) PolicyManager() policies.Manager { - return &mockpolicies.Manager{} -} - func (ms *Support) GetMSPIDs() []string { return []string{"SampleOrg"} } diff --git a/core/peer/mock_helpers.go b/core/peer/mock_helpers.go index cef62947683..dcb3134e200 100644 --- a/core/peer/mock_helpers.go +++ b/core/peer/mock_helpers.go @@ -11,11 +11,11 @@ import ( configtxtest "github.com/hyperledger/fabric/common/configtx/test" mockchannelconfig "github.com/hyperledger/fabric/common/mocks/config" mockconfigtx "github.com/hyperledger/fabric/common/mocks/configtx" - mockpolicies "github.com/hyperledger/fabric/common/mocks/policies" + "github.com/hyperledger/fabric/common/policies" "github.com/hyperledger/fabric/core/ledger" ) -func CreateMockChannel(p *Peer, cid string) error { +func CreateMockChannel(p *Peer, cid string, policyMgr policies.Manager) error { var ledger ledger.PeerLedger var err error @@ -41,9 +41,7 @@ func CreateMockChannel(p *Peer, cid string) error { p.channels[cid] = &Channel{ ledger: ledger, resources: &mockchannelconfig.Resources{ - PolicyManagerVal: &mockpolicies.Manager{ - Policy: &mockpolicies.Policy{}, - }, + PolicyManagerVal: policyMgr, ConfigtxValidatorVal: &mockconfigtx.Validator{}, ApplicationConfigVal: &mockchannelconfig.MockApplication{CapabilitiesRv: &mockchannelconfig.MockApplicationCapabilities{}}, }, diff --git a/core/scc/qscc/query_test.go b/core/scc/qscc/query_test.go index 4a5da31314f..133c19ed4de 100644 --- a/core/scc/qscc/query_test.go +++ b/core/scc/qscc/query_test.go @@ -58,7 +58,7 @@ func setupTestLedger(chainid string, path string) (*shimtest.MockStub, *peer.Pee LedgerMgr: ledgerMgr, CryptoProvider: cryptoProvider, } - peer.CreateMockChannel(peerInstance, chainid) + peer.CreateMockChannel(peerInstance, chainid, nil) lq := &LedgerQuerier{ aclProvider: mockAclProvider, diff --git a/internal/peer/gossip/mcs_test.go b/internal/peer/gossip/mcs_test.go index c26a81807c6..e59a388aa31 100644 --- a/internal/peer/gossip/mcs_test.go +++ b/internal/peer/gossip/mcs_test.go @@ -31,6 +31,12 @@ import ( "github.com/stretchr/testify/mock" ) +//go:generate counterfeiter -o mocks/policy_manager.go -fake-name PolicyManager . policyManager + +type policyManager interface { + policies.Manager +} + //go:generate counterfeiter -o mocks/signer_serializer.go --fake-name SignerSerializer . signerSerializer type signerSerializer interface { diff --git a/internal/peer/gossip/mocks/mocks.go b/internal/peer/gossip/mocks/mocks.go index 9fd70a2cec5..6b4641c7b42 100644 --- a/internal/peer/gossip/mocks/mocks.go +++ b/internal/peer/gossip/mocks/mocks.go @@ -13,7 +13,6 @@ import ( "time" mspproto "github.com/hyperledger/fabric-protos-go/msp" - mockpolicies "github.com/hyperledger/fabric/common/mocks/policies" "github.com/hyperledger/fabric/common/policies" "github.com/hyperledger/fabric/msp" "github.com/hyperledger/fabric/protoutil" @@ -23,7 +22,9 @@ import ( type ChannelPolicyManagerGetter struct{} func (c *ChannelPolicyManagerGetter) Manager(channelID string) policies.Manager { - return &mockpolicies.Manager{Policy: &mockpolicies.Policy{Err: nil}} + policyMgr := &PolicyManager{} + policyMgr.GetPolicyReturns(nil, true) + return policyMgr } type ChannelPolicyManagerGetterWithManager struct { diff --git a/internal/peer/gossip/mocks/policy_manager.go b/internal/peer/gossip/mocks/policy_manager.go new file mode 100644 index 00000000000..b6aeca42592 --- /dev/null +++ b/internal/peer/gossip/mocks/policy_manager.go @@ -0,0 +1,196 @@ +// Code generated by counterfeiter. DO NOT EDIT. +package mocks + +import ( + "sync" + + "github.com/hyperledger/fabric/common/policies" +) + +type PolicyManager struct { + GetPolicyStub func(string) (policies.Policy, bool) + getPolicyMutex sync.RWMutex + getPolicyArgsForCall []struct { + arg1 string + } + getPolicyReturns struct { + result1 policies.Policy + result2 bool + } + getPolicyReturnsOnCall map[int]struct { + result1 policies.Policy + result2 bool + } + ManagerStub func([]string) (policies.Manager, bool) + managerMutex sync.RWMutex + managerArgsForCall []struct { + arg1 []string + } + managerReturns struct { + result1 policies.Manager + result2 bool + } + managerReturnsOnCall map[int]struct { + result1 policies.Manager + result2 bool + } + invocations map[string][][]interface{} + invocationsMutex sync.RWMutex +} + +func (fake *PolicyManager) GetPolicy(arg1 string) (policies.Policy, bool) { + fake.getPolicyMutex.Lock() + ret, specificReturn := fake.getPolicyReturnsOnCall[len(fake.getPolicyArgsForCall)] + fake.getPolicyArgsForCall = append(fake.getPolicyArgsForCall, struct { + arg1 string + }{arg1}) + fake.recordInvocation("GetPolicy", []interface{}{arg1}) + fake.getPolicyMutex.Unlock() + if fake.GetPolicyStub != nil { + return fake.GetPolicyStub(arg1) + } + if specificReturn { + return ret.result1, ret.result2 + } + fakeReturns := fake.getPolicyReturns + return fakeReturns.result1, fakeReturns.result2 +} + +func (fake *PolicyManager) GetPolicyCallCount() int { + fake.getPolicyMutex.RLock() + defer fake.getPolicyMutex.RUnlock() + return len(fake.getPolicyArgsForCall) +} + +func (fake *PolicyManager) GetPolicyCalls(stub func(string) (policies.Policy, bool)) { + fake.getPolicyMutex.Lock() + defer fake.getPolicyMutex.Unlock() + fake.GetPolicyStub = stub +} + +func (fake *PolicyManager) GetPolicyArgsForCall(i int) string { + fake.getPolicyMutex.RLock() + defer fake.getPolicyMutex.RUnlock() + argsForCall := fake.getPolicyArgsForCall[i] + return argsForCall.arg1 +} + +func (fake *PolicyManager) GetPolicyReturns(result1 policies.Policy, result2 bool) { + fake.getPolicyMutex.Lock() + defer fake.getPolicyMutex.Unlock() + fake.GetPolicyStub = nil + fake.getPolicyReturns = struct { + result1 policies.Policy + result2 bool + }{result1, result2} +} + +func (fake *PolicyManager) GetPolicyReturnsOnCall(i int, result1 policies.Policy, result2 bool) { + fake.getPolicyMutex.Lock() + defer fake.getPolicyMutex.Unlock() + fake.GetPolicyStub = nil + if fake.getPolicyReturnsOnCall == nil { + fake.getPolicyReturnsOnCall = make(map[int]struct { + result1 policies.Policy + result2 bool + }) + } + fake.getPolicyReturnsOnCall[i] = struct { + result1 policies.Policy + result2 bool + }{result1, result2} +} + +func (fake *PolicyManager) Manager(arg1 []string) (policies.Manager, bool) { + var arg1Copy []string + if arg1 != nil { + arg1Copy = make([]string, len(arg1)) + copy(arg1Copy, arg1) + } + fake.managerMutex.Lock() + ret, specificReturn := fake.managerReturnsOnCall[len(fake.managerArgsForCall)] + fake.managerArgsForCall = append(fake.managerArgsForCall, struct { + arg1 []string + }{arg1Copy}) + fake.recordInvocation("Manager", []interface{}{arg1Copy}) + fake.managerMutex.Unlock() + if fake.ManagerStub != nil { + return fake.ManagerStub(arg1) + } + if specificReturn { + return ret.result1, ret.result2 + } + fakeReturns := fake.managerReturns + return fakeReturns.result1, fakeReturns.result2 +} + +func (fake *PolicyManager) ManagerCallCount() int { + fake.managerMutex.RLock() + defer fake.managerMutex.RUnlock() + return len(fake.managerArgsForCall) +} + +func (fake *PolicyManager) ManagerCalls(stub func([]string) (policies.Manager, bool)) { + fake.managerMutex.Lock() + defer fake.managerMutex.Unlock() + fake.ManagerStub = stub +} + +func (fake *PolicyManager) ManagerArgsForCall(i int) []string { + fake.managerMutex.RLock() + defer fake.managerMutex.RUnlock() + argsForCall := fake.managerArgsForCall[i] + return argsForCall.arg1 +} + +func (fake *PolicyManager) ManagerReturns(result1 policies.Manager, result2 bool) { + fake.managerMutex.Lock() + defer fake.managerMutex.Unlock() + fake.ManagerStub = nil + fake.managerReturns = struct { + result1 policies.Manager + result2 bool + }{result1, result2} +} + +func (fake *PolicyManager) ManagerReturnsOnCall(i int, result1 policies.Manager, result2 bool) { + fake.managerMutex.Lock() + defer fake.managerMutex.Unlock() + fake.ManagerStub = nil + if fake.managerReturnsOnCall == nil { + fake.managerReturnsOnCall = make(map[int]struct { + result1 policies.Manager + result2 bool + }) + } + fake.managerReturnsOnCall[i] = struct { + result1 policies.Manager + result2 bool + }{result1, result2} +} + +func (fake *PolicyManager) Invocations() map[string][][]interface{} { + fake.invocationsMutex.RLock() + defer fake.invocationsMutex.RUnlock() + fake.getPolicyMutex.RLock() + defer fake.getPolicyMutex.RUnlock() + fake.managerMutex.RLock() + defer fake.managerMutex.RUnlock() + copiedInvocations := map[string][][]interface{}{} + for key, value := range fake.invocations { + copiedInvocations[key] = value + } + return copiedInvocations +} + +func (fake *PolicyManager) recordInvocation(key string, args []interface{}) { + fake.invocationsMutex.Lock() + defer fake.invocationsMutex.Unlock() + if fake.invocations == nil { + fake.invocations = map[string][][]interface{}{} + } + if fake.invocations[key] == nil { + fake.invocations[key] = [][]interface{}{} + } + fake.invocations[key] = append(fake.invocations[key], args) +}