From d4e0e27ee7d5dae842793d6b15472283880be306 Mon Sep 17 00:00:00 2001 From: Angelo De Caro Date: Thu, 4 May 2023 14:55:33 +0200 Subject: [PATCH 1/3] introduce query policy Signed-off-by: Angelo De Caro --- .../fabric/core/generic/chaincode/invoke.go | 56 ++++++++++++++++--- platform/fabric/driver/chaincode.go | 10 ++++ .../fabric/services/chaincode/chaincode.go | 12 ++++ platform/fabric/services/chaincode/query.go | 18 +++++- 4 files changed, 87 insertions(+), 9 deletions(-) diff --git a/platform/fabric/core/generic/chaincode/invoke.go b/platform/fabric/core/generic/chaincode/invoke.go index d3c4aa0be..bd92748ec 100644 --- a/platform/fabric/core/generic/chaincode/invoke.go +++ b/platform/fabric/core/generic/chaincode/invoke.go @@ -10,6 +10,7 @@ import ( "bytes" "context" "encoding/base64" + "fmt" "strconv" "strings" "sync" @@ -50,6 +51,7 @@ type Invoke struct { NumRetries int RetrySleep time.Duration Context context.Context + QueryPolicy driver.QueryPolicy } func NewInvoke(chaincode *Chaincode, function string, args ...interface{}) *Invoke { @@ -264,6 +266,11 @@ func (i *Invoke) WithRetrySleep(duration time.Duration) driver.ChaincodeInvocati return i } +func (i *Invoke) WithQueryPolicy(policy driver.QueryPolicy) driver.ChaincodeInvocation { + i.QueryPolicy = policy + return i +} + func (i *Invoke) prepare(query bool) (string, *pb.Proposal, []*pb.ProposalResponse, driver.SigningIdentity, error) { // TODO: improve by providing grpc connection pool var peerClients []peer2.Client @@ -335,7 +342,8 @@ func (i *Invoke) prepare(query bool) (string, *pb.Proposal, []*pb.ProposalRespon } } - // get a peer client for all discovered peers + // get a peer client for all discovered peers and collect the errors + var errs []error for _, peer := range discoveredPeers { peerClient, err := i.Channel.NewPeerClientForAddress(grpc.ConnectionConfig{ Address: peer.Endpoint, @@ -343,19 +351,28 @@ func (i *Invoke) prepare(query bool) (string, *pb.Proposal, []*pb.ProposalRespon TLSRootCertBytes: peer.TLSRootCerts, }) if err != nil { - return "", nil, nil, nil, errors.WithMessagef(err, "error getting endorser client for %s", peer.Endpoint) + errs = append(errs, errors.WithMessagef(err, "error getting endorser client for %s", peer.Endpoint)) + continue } peerClients = append(peerClients, peerClient) } + if err := i.checkQueryPolicy(errs, len(discoveredPeers)); err != nil { + return "", nil, nil, nil, errors.WithMessagef(err, "cannot match query policy with the given discovered peers") + } // get endorser clients + errs = nil for _, client := range peerClients { endorserClient, err := client.Endorser() if err != nil { - return "", nil, nil, nil, errors.WithMessagef(err, "error getting endorser client for %s", client.Address()) + errs = append(errs, errors.WithMessagef(err, "error getting endorser client for %s", client.Address())) + continue } endorserClients = append(endorserClients, endorserClient) } + if err := i.checkQueryPolicy(errs, len(peerClients)); err != nil { + return "", nil, nil, nil, errors.WithMessagef(err, "cannot match query policy with the given peer clients") + } if len(endorserClients) == 0 { return "", nil, nil, nil, errors.New("no endorser clients retrieved with the current filters") } @@ -373,15 +390,17 @@ func (i *Invoke) prepare(query bool) (string, *pb.Proposal, []*pb.ProposalRespon } // collect responses - responses, err := i.collectResponses(endorserClients, signedProp) + responses, errs := i.collectResponses(endorserClients, signedProp) if err != nil { return "", nil, nil, nil, errors.Wrapf(err, "failed collecting proposal responses") } - if len(responses) == 0 { // this should only happen if some new code has introduced a bug return "", nil, nil, nil, errors.New("no proposal responses received - this might indicate a bug") } + if err := i.checkQueryPolicy(errs, len(endorserClients)); err != nil { + return "", nil, nil, nil, errors.WithMessagef(err, "cannot match query policy with the given peer clients") + } return txID, prop, responses, signer, nil } @@ -447,7 +466,7 @@ func (i *Invoke) createChaincodeProposalWithTxIDAndTransient(typ common.HeaderTy } // collectResponses sends a signed proposal to a set of peers, and gathers all the responses. -func (i *Invoke) collectResponses(endorserClients []pb.EndorserClient, signedProposal *pb.SignedProposal) ([]*pb.ProposalResponse, error) { +func (i *Invoke) collectResponses(endorserClients []pb.EndorserClient, signedProposal *pb.SignedProposal) ([]*pb.ProposalResponse, []error) { responsesCh := make(chan *pb.ProposalResponse, len(endorserClients)) errorCh := make(chan error, len(endorserClients)) wg := sync.WaitGroup{} @@ -466,14 +485,15 @@ func (i *Invoke) collectResponses(endorserClients []pb.EndorserClient, signedPro wg.Wait() close(responsesCh) close(errorCh) + var errs []error for err := range errorCh { - return nil, err + errs = append(errs, err) } var responses []*pb.ProposalResponse for response := range responsesCh { responses = append(responses, response) } - return responses, nil + return responses, errs } // getChaincodeSpec get chaincode spec from the fsccli cmd parameters @@ -536,3 +556,23 @@ func (i *Invoke) broadcast(txID string, env *common.Envelope) error { } return i.Channel.IsFinal(context.Background(), txID) } + +func (i *Invoke) checkQueryPolicy(errs []error, n int) error { + switch i.QueryPolicy { + case driver.QueryAll: + if len(errs) != 0 { + return errors.Errorf("query all policy, no errors expected [%v]", errs) + } + case driver.QueryOne: + if len(errs) == n { + return errors.Errorf("query one policy, errors occurred [%v]", errs) + } + case driver.QueryMajority: + if len(errs) > n/2 { + return errors.Errorf("query majority policy, no majority reached [%v]", errs) + } + default: + panic(fmt.Sprintf("programming error, policy [%d] is not valid", i.QueryPolicy)) + } + return nil +} diff --git a/platform/fabric/driver/chaincode.go b/platform/fabric/driver/chaincode.go index b9e47515c..335eef9e9 100644 --- a/platform/fabric/driver/chaincode.go +++ b/platform/fabric/driver/chaincode.go @@ -19,6 +19,14 @@ type TxID struct { Creator []byte } +type QueryPolicy int + +const ( + QueryAll QueryPolicy = iota + QueryMajority + QueryOne +) + // ChaincodeInvocation models a client-side chaincode invocation type ChaincodeInvocation interface { Endorse() (Envelope, error) @@ -56,6 +64,8 @@ type ChaincodeInvocation interface { WithRetrySleep(duration time.Duration) ChaincodeInvocation WithContext(context context.Context) ChaincodeInvocation + + WithQueryPolicy(policy QueryPolicy) ChaincodeInvocation } // DiscoveredPeer contains the information of a discovered peer diff --git a/platform/fabric/services/chaincode/chaincode.go b/platform/fabric/services/chaincode/chaincode.go index 28f4e407d..c204c25ce 100644 --- a/platform/fabric/services/chaincode/chaincode.go +++ b/platform/fabric/services/chaincode/chaincode.go @@ -9,6 +9,8 @@ package chaincode import ( "time" + "github.com/hyperledger-labs/fabric-smart-client/platform/fabric/driver" + "github.com/hyperledger-labs/fabric-smart-client/platform/fabric" "github.com/hyperledger-labs/fabric-smart-client/platform/fabric/services/fpc" "github.com/hyperledger-labs/fabric-smart-client/platform/view/view" @@ -34,6 +36,7 @@ type Query interface { Call() ([]byte, error) WithNumRetries(retries uint) WithRetrySleep(sleep time.Duration) + WithQueryPolicy(policy driver.QueryPolicy) Query } type Chaincode interface { @@ -117,6 +120,11 @@ func (s *stdQuery) WithRetrySleep(duration time.Duration) { s.chq.WithRetrySleep(duration) } +func (s *stdQuery) WithQueryPolicy(policy driver.QueryPolicy) Query { + s.chq.WithQueryPolicy(policy) + return s +} + type stdChaincode struct { ch *fabric.Chaincode } @@ -204,6 +212,10 @@ func (s *fpcQuery) WithNumRetries(numRetries uint) { func (s *fpcQuery) WithRetrySleep(duration time.Duration) { } +func (s *fpcQuery) WithQueryPolicy(policy driver.QueryPolicy) Query { + return nil +} + type fpcChaincode struct { ch *fpc.Chaincode } diff --git a/platform/fabric/services/chaincode/query.go b/platform/fabric/services/chaincode/query.go index 5a9f48a91..a1e699956 100644 --- a/platform/fabric/services/chaincode/query.go +++ b/platform/fabric/services/chaincode/query.go @@ -9,14 +9,25 @@ package chaincode import ( "time" + "github.com/hyperledger-labs/fabric-smart-client/platform/fabric/driver" + "github.com/hyperledger-labs/fabric-smart-client/platform/fabric" "github.com/hyperledger-labs/fabric-smart-client/platform/fabric/services/fpc" "github.com/hyperledger-labs/fabric-smart-client/platform/view/view" "github.com/pkg/errors" ) +type QueryPolicy = driver.QueryPolicy + +const ( + QueryAll = driver.QueryAll + QueryMajority = driver.QueryMajority + QueryOne = driver.QueryOne +) + type queryChaincodeView struct { *InvokeCall + policy QueryPolicy } func NewQueryView(chaincode, function string, args ...interface{}) *queryChaincodeView { @@ -62,7 +73,7 @@ func (i *queryChaincodeView) Query(context view.Context) ([]byte, error) { logger.Debugf("chaincode [%s:%s:%s] is a standard chaincode", i.Network, i.Channel, i.ChaincodeName) } - invocation := chaincode.Query(i.Function, i.Args...).WithInvokerIdentity(i.InvokerIdentity) + invocation := chaincode.Query(i.Function, i.Args...).WithInvokerIdentity(i.InvokerIdentity).WithQueryPolicy(i.policy) for k, v := range i.TransientMap { invocation.WithTransientEntry(k, v) } @@ -134,3 +145,8 @@ func (i *queryChaincodeView) WithRetrySleep(duration time.Duration) *queryChainc i.RetrySleep = duration return i } + +func (i *queryChaincodeView) WithPolicy(policy QueryPolicy) *queryChaincodeView { + i.policy = policy + return i +} From 2c37888037c990f69df43c0e99cbb0f2d26dbfd3 Mon Sep 17 00:00:00 2001 From: Angelo De Caro Date: Fri, 5 May 2023 08:50:03 +0200 Subject: [PATCH 2/3] fixup! introduce query policy Signed-off-by: Angelo De Caro --- platform/fabric/chaincode.go | 18 + .../core/generic/chaincode/chaincode.go | 4 +- .../fabric/core/generic/chaincode/invoke.go | 41 +- .../core/generic/chaincode/invoke_test.go | 151 +++++ .../fabric/core/generic/chaincode/mocks/cd.go | 391 +++++++++++++ .../core/generic/chaincode/mocks/channel.go | 466 +++++++++++++++ .../fabric/core/generic/chaincode/mocks/ec.go | 123 ++++ .../core/generic/chaincode/mocks/mspid.go | 253 ++++++++ .../core/generic/chaincode/mocks/mspm.go | 122 ++++ .../core/generic/chaincode/mocks/network.go | 451 ++++++++++++++ .../fabric/core/generic/chaincode/mocks/pc.go | 552 ++++++++++++++++++ .../fabric/core/generic/chaincode/mocks/sc.go | 275 +++++++++ .../core/generic/chaincode/mocks/sersig.go | 191 ++++++ .../fabric/core/generic/chaincode/mocks/si.go | 191 ++++++ .../fabric/core/generic/chaincode/mocks/sp.go | 118 ++++ .../fabric/core/generic/chaincode/support.go | 23 + platform/fabric/driver/chaincode.go | 6 + .../fabric/services/chaincode/chaincode.go | 5 +- platform/fabric/services/chaincode/query.go | 16 +- 19 files changed, 3369 insertions(+), 28 deletions(-) create mode 100644 platform/fabric/core/generic/chaincode/invoke_test.go create mode 100644 platform/fabric/core/generic/chaincode/mocks/cd.go create mode 100644 platform/fabric/core/generic/chaincode/mocks/channel.go create mode 100644 platform/fabric/core/generic/chaincode/mocks/ec.go create mode 100644 platform/fabric/core/generic/chaincode/mocks/mspid.go create mode 100644 platform/fabric/core/generic/chaincode/mocks/mspm.go create mode 100644 platform/fabric/core/generic/chaincode/mocks/network.go create mode 100644 platform/fabric/core/generic/chaincode/mocks/pc.go create mode 100644 platform/fabric/core/generic/chaincode/mocks/sc.go create mode 100644 platform/fabric/core/generic/chaincode/mocks/sersig.go create mode 100644 platform/fabric/core/generic/chaincode/mocks/si.go create mode 100644 platform/fabric/core/generic/chaincode/mocks/sp.go diff --git a/platform/fabric/chaincode.go b/platform/fabric/chaincode.go index 685702c8f..46a2e9a1d 100644 --- a/platform/fabric/chaincode.go +++ b/platform/fabric/chaincode.go @@ -15,6 +15,18 @@ import ( "github.com/hyperledger-labs/fabric-smart-client/platform/view/view" ) +// QueryPolicy defines the policy to use to decide if a query is successful +type QueryPolicy int + +const ( + // QueryAll requires an answer from all selected peers + QueryAll QueryPolicy = iota + // QueryMajority requires an answer from the majority of the selected peers + QueryMajority + // QueryOne requires an answer from at least one of the selected peers + QueryOne +) + type Envelope struct { e driver.Envelope } @@ -249,6 +261,12 @@ func (i *ChaincodeQuery) WithRetrySleep(duration time.Duration) *ChaincodeQuery return i } +// WithQueryPolicy sets the query policy to use +func (i *ChaincodeQuery) WithQueryPolicy(policy QueryPolicy) *ChaincodeQuery { + i.ChaincodeInvocation.WithQueryPolicy(driver.QueryPolicy(policy)) + return i +} + type ChaincodeEndorse struct { ChaincodeInvocation driver.ChaincodeInvocation } diff --git a/platform/fabric/core/generic/chaincode/chaincode.go b/platform/fabric/core/generic/chaincode/chaincode.go index 42e70cd9e..c1e8a6dfc 100644 --- a/platform/fabric/core/generic/chaincode/chaincode.go +++ b/platform/fabric/core/generic/chaincode/chaincode.go @@ -41,7 +41,9 @@ func NewChaincode(name string, sp view.ServiceProvider, network Network, channel } func (c *Chaincode) NewInvocation(function string, args ...interface{}) driver.ChaincodeInvocation { - return NewInvoke(c, function, args...) + return NewInvoke(c, func(chaincode *Chaincode) driver.ChaincodeDiscover { + return NewDiscovery(chaincode) + }, function, args...) } func (c *Chaincode) NewDiscover() driver.ChaincodeDiscover { diff --git a/platform/fabric/core/generic/chaincode/invoke.go b/platform/fabric/core/generic/chaincode/invoke.go index bd92748ec..b35d84847 100644 --- a/platform/fabric/core/generic/chaincode/invoke.go +++ b/platform/fabric/core/generic/chaincode/invoke.go @@ -29,11 +29,14 @@ import ( "go.uber.org/zap/zapcore" ) +type NewChaincodeDiscoverFunc = func(chaincode *Chaincode) driver.ChaincodeDiscover + type Invoke struct { Chaincode *Chaincode ServiceProvider view2.ServiceProvider Network Network Channel Channel + NewChaincodeDiscover NewChaincodeDiscoverFunc TxID driver.TxID SignerIdentity view.Identity ChaincodePath string @@ -54,17 +57,18 @@ type Invoke struct { QueryPolicy driver.QueryPolicy } -func NewInvoke(chaincode *Chaincode, function string, args ...interface{}) *Invoke { +func NewInvoke(chaincode *Chaincode, newChaincodeDiscover NewChaincodeDiscoverFunc, function string, args ...interface{}) *Invoke { return &Invoke{ - Chaincode: chaincode, - ServiceProvider: chaincode.sp, - Network: chaincode.network, - Channel: chaincode.channel, - ChaincodeName: chaincode.name, - Function: function, - Args: args, - NumRetries: int(chaincode.NumRetries), - RetrySleep: chaincode.RetrySleep, + Chaincode: chaincode, + ServiceProvider: chaincode.sp, + Network: chaincode.network, + Channel: chaincode.channel, + ChaincodeName: chaincode.name, + Function: function, + Args: args, + NumRetries: int(chaincode.NumRetries), + RetrySleep: chaincode.RetrySleep, + NewChaincodeDiscover: newChaincodeDiscover, } } @@ -312,7 +316,7 @@ func (i *Invoke) prepare(query bool) (string, *pb.Proposal, []*pb.ProposalRespon // discover var err error - discovery := NewDiscovery( + discovery := i.NewChaincodeDiscover( i.Chaincode, ) discovery.WithFilterByMSPIDs( @@ -342,6 +346,7 @@ func (i *Invoke) prepare(query bool) (string, *pb.Proposal, []*pb.ProposalRespon } } + n := len(discoveredPeers) // get a peer client for all discovered peers and collect the errors var errs []error for _, peer := range discoveredPeers { @@ -356,7 +361,7 @@ func (i *Invoke) prepare(query bool) (string, *pb.Proposal, []*pb.ProposalRespon } peerClients = append(peerClients, peerClient) } - if err := i.checkQueryPolicy(errs, len(discoveredPeers)); err != nil { + if err := i.checkQueryPolicy(errs, len(peerClients), n); err != nil { return "", nil, nil, nil, errors.WithMessagef(err, "cannot match query policy with the given discovered peers") } @@ -370,7 +375,7 @@ func (i *Invoke) prepare(query bool) (string, *pb.Proposal, []*pb.ProposalRespon } endorserClients = append(endorserClients, endorserClient) } - if err := i.checkQueryPolicy(errs, len(peerClients)); err != nil { + if err := i.checkQueryPolicy(errs, len(endorserClients), n); err != nil { return "", nil, nil, nil, errors.WithMessagef(err, "cannot match query policy with the given peer clients") } if len(endorserClients) == 0 { @@ -398,7 +403,7 @@ func (i *Invoke) prepare(query bool) (string, *pb.Proposal, []*pb.ProposalRespon // this should only happen if some new code has introduced a bug return "", nil, nil, nil, errors.New("no proposal responses received - this might indicate a bug") } - if err := i.checkQueryPolicy(errs, len(endorserClients)); err != nil { + if err := i.checkQueryPolicy(errs, len(responses), n); err != nil { return "", nil, nil, nil, errors.WithMessagef(err, "cannot match query policy with the given peer clients") } @@ -470,8 +475,8 @@ func (i *Invoke) collectResponses(endorserClients []pb.EndorserClient, signedPro responsesCh := make(chan *pb.ProposalResponse, len(endorserClients)) errorCh := make(chan error, len(endorserClients)) wg := sync.WaitGroup{} + wg.Add(len(endorserClients)) for _, endorser := range endorserClients { - wg.Add(1) go func(endorser pb.EndorserClient) { defer wg.Done() proposalResp, err := endorser.ProcessProposal(context.Background(), signedProposal) @@ -557,18 +562,18 @@ func (i *Invoke) broadcast(txID string, env *common.Envelope) error { return i.Channel.IsFinal(context.Background(), txID) } -func (i *Invoke) checkQueryPolicy(errs []error, n int) error { +func (i *Invoke) checkQueryPolicy(errs []error, successes int, n int) error { switch i.QueryPolicy { case driver.QueryAll: if len(errs) != 0 { return errors.Errorf("query all policy, no errors expected [%v]", errs) } case driver.QueryOne: - if len(errs) == n { + if successes == 0 { return errors.Errorf("query one policy, errors occurred [%v]", errs) } case driver.QueryMajority: - if len(errs) > n/2 { + if successes <= n/2 { return errors.Errorf("query majority policy, no majority reached [%v]", errs) } default: diff --git a/platform/fabric/core/generic/chaincode/invoke_test.go b/platform/fabric/core/generic/chaincode/invoke_test.go new file mode 100644 index 000000000..960bf48a2 --- /dev/null +++ b/platform/fabric/core/generic/chaincode/invoke_test.go @@ -0,0 +1,151 @@ +/* +Copyright IBM Corp. All Rights Reserved. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package chaincode_test + +import ( + "testing" + "time" + + "github.com/hyperledger/fabric-protos-go/peer" + + "github.com/hyperledger-labs/fabric-smart-client/platform/fabric/core/generic/chaincode" + "github.com/hyperledger-labs/fabric-smart-client/platform/fabric/core/generic/chaincode/mocks" + "github.com/hyperledger-labs/fabric-smart-client/platform/fabric/core/generic/config" + config2 "github.com/hyperledger-labs/fabric-smart-client/platform/fabric/core/generic/config" + mock2 "github.com/hyperledger-labs/fabric-smart-client/platform/fabric/core/generic/msp/mock" + "github.com/hyperledger-labs/fabric-smart-client/platform/fabric/driver" + "github.com/pkg/errors" + "github.com/stretchr/testify/assert" +) + +func TestInvokeQueryFailMatchPolicyDiscoveredPeers(t *testing.T) { + network := &mocks.Network{} + cp := &mock2.ConfigProvider{} + cp.IsSetReturns(false) + networkConfig, err := config2.New(cp, "default", true) + assert.NoError(t, err) + network.ConfigReturns(networkConfig) + sc := &mocks.SignerService{} + si := &mocks.SigningIdentity{} + si.SerializeReturns([]byte("alice"), nil) + si.SignReturns([]byte("alice's signature"), nil) + sc.GetSigningIdentityReturns(si, nil) + network.SignerServiceReturns(sc) + channel := &mocks.Channel{} + mspManager := &mocks.MSPManager{} + mspIdentity := &mocks.MSPIdentity{} + mspIdentity.GetMSPIdentifierReturns("mspid") + mspManager.DeserializeIdentityReturns(mspIdentity, nil) + channel.MSPManagerReturns(mspManager) + chConfig := &config.Channel{ + Name: "blueberry", + Default: true, + Quiet: false, + NumRetries: 1, + RetrySleep: 1 * time.Second, + Chaincodes: nil, + } + channel.ConfigReturns(chConfig) + pc := &mocks.PeerClient{} + //ec := &mocks.EndorserClient{} + pc.EndorserReturns(nil, errors.Errorf("endorser not found")) + channel.NewPeerClientForAddressReturnsOnCall(0, pc, nil) + channel.NewPeerClientForAddressReturnsOnCall(1, pc, nil) + channel.NewPeerClientForAddressReturnsOnCall(2, pc, nil) + channel.NewPeerClientForAddressReturnsOnCall(3, nil, errors.Errorf("peer not found")) + channel.NewPeerClientForAddressReturnsOnCall(4, pc, nil) + channel.NewPeerClientForAddressReturnsOnCall(5, pc, nil) + channel.NewPeerClientForAddressReturnsOnCall(6, pc, nil) + channel.NewPeerClientForAddressReturnsOnCall(7, nil, errors.Errorf("peer not found")) + channel.NewPeerClientForAddressReturnsOnCall(8, pc, nil) + channel.NewPeerClientForAddressReturnsOnCall(9, pc, nil) + channel.NewPeerClientForAddressReturnsOnCall(10, pc, nil) + channel.NewPeerClientForAddressReturnsOnCall(11, nil, errors.Errorf("peer not found")) + discover := &mocks.Discover{} + discover.WithFilterByMSPIDsReturns(discover) + discover.WithImplicitCollectionsReturns(discover) + discoveredPeers := []driver.DiscoveredPeer{ + { + Identity: []byte("peer1"), + MSPID: "mspid", + Endpoint: "1.1.1.1", + TLSRootCerts: nil, + }, + { + Identity: []byte("peer2"), + MSPID: "mspid", + Endpoint: "2.1.1.1", + TLSRootCerts: nil, + }, + { + Identity: []byte("peer3"), + MSPID: "mspid", + Endpoint: "3.1.1.1", + TLSRootCerts: nil, + }, + { + Identity: []byte("peer4"), + MSPID: "mspid", + Endpoint: "4.1.1.1", + TLSRootCerts: nil, + }, + } + discover.CallReturns(discoveredPeers, nil) + ch := chaincode.NewChaincode("pineapple", nil, network, channel) + + invoke := chaincode.NewInvoke(ch, func(chaincode *chaincode.Chaincode) driver.ChaincodeDiscover { + return discover + }, "apple") + invoke.WithEndorsersFromMyOrg() + invoke.WithQueryPolicy(driver.QueryAll) + invoke.WithSignerIdentity([]byte("alice")) + + _, err = invoke.Query() + assert.Error(t, err) + assert.Contains(t, err.Error(), "cannot match query policy with the given discovered peers") + assert.Contains(t, err.Error(), "query all policy, no errors expected [") + + invoke = chaincode.NewInvoke(ch, func(chaincode *chaincode.Chaincode) driver.ChaincodeDiscover { + return discover + }, "apple") + invoke.WithEndorsersFromMyOrg() + invoke.WithQueryPolicy(driver.QueryMajority) + invoke.WithSignerIdentity([]byte("alice")) + _, err = invoke.Query() + assert.Error(t, err) + assert.Contains(t, err.Error(), "cannot match query policy with the given peer clients") + assert.Contains(t, err.Error(), "query majority policy, no majority reached") + + ec := &mocks.EndorserClient{} + pr := &peer.ProposalResponse{ + Version: 0, + Timestamp: nil, + Response: &peer.Response{ + Status: 0, + Message: "", + Payload: nil, + }, + Payload: nil, + Endorsement: &peer.Endorsement{ + Endorser: []byte("endorser"), + Signature: []byte("endorser's signature"), + }, + Interest: nil, + } + ec.ProcessProposalReturnsOnCall(0, pr, nil) + ec.ProcessProposalReturnsOnCall(1, nil, errors.New("cannot return proposal response")) + ec.ProcessProposalReturnsOnCall(2, nil, errors.New("cannot return proposal response")) + pc.EndorserReturns(ec, nil) + invoke = chaincode.NewInvoke(ch, func(chaincode *chaincode.Chaincode) driver.ChaincodeDiscover { + return discover + }, "apple") + invoke.WithEndorsersFromMyOrg() + invoke.WithQueryPolicy(driver.QueryOne) + invoke.WithSignerIdentity([]byte("alice")) + _, err = invoke.Query() + assert.NoError(t, err) +} diff --git a/platform/fabric/core/generic/chaincode/mocks/cd.go b/platform/fabric/core/generic/chaincode/mocks/cd.go new file mode 100644 index 000000000..8de4e09ce --- /dev/null +++ b/platform/fabric/core/generic/chaincode/mocks/cd.go @@ -0,0 +1,391 @@ +// Code generated by counterfeiter. DO NOT EDIT. +package mocks + +import ( + "sync" + + "github.com/hyperledger-labs/fabric-smart-client/platform/fabric/core/generic/chaincode" + "github.com/hyperledger-labs/fabric-smart-client/platform/fabric/driver" +) + +type Discover struct { + CallStub func() ([]driver.DiscoveredPeer, error) + callMutex sync.RWMutex + callArgsForCall []struct { + } + callReturns struct { + result1 []driver.DiscoveredPeer + result2 error + } + callReturnsOnCall map[int]struct { + result1 []driver.DiscoveredPeer + result2 error + } + ChaincodeVersionStub func() (string, error) + chaincodeVersionMutex sync.RWMutex + chaincodeVersionArgsForCall []struct { + } + chaincodeVersionReturns struct { + result1 string + result2 error + } + chaincodeVersionReturnsOnCall map[int]struct { + result1 string + result2 error + } + WithFilterByMSPIDsStub func(...string) driver.ChaincodeDiscover + withFilterByMSPIDsMutex sync.RWMutex + withFilterByMSPIDsArgsForCall []struct { + arg1 []string + } + withFilterByMSPIDsReturns struct { + result1 driver.ChaincodeDiscover + } + withFilterByMSPIDsReturnsOnCall map[int]struct { + result1 driver.ChaincodeDiscover + } + WithForQueryStub func() driver.ChaincodeDiscover + withForQueryMutex sync.RWMutex + withForQueryArgsForCall []struct { + } + withForQueryReturns struct { + result1 driver.ChaincodeDiscover + } + withForQueryReturnsOnCall map[int]struct { + result1 driver.ChaincodeDiscover + } + WithImplicitCollectionsStub func(...string) driver.ChaincodeDiscover + withImplicitCollectionsMutex sync.RWMutex + withImplicitCollectionsArgsForCall []struct { + arg1 []string + } + withImplicitCollectionsReturns struct { + result1 driver.ChaincodeDiscover + } + withImplicitCollectionsReturnsOnCall map[int]struct { + result1 driver.ChaincodeDiscover + } + invocations map[string][][]interface{} + invocationsMutex sync.RWMutex +} + +func (fake *Discover) Call() ([]driver.DiscoveredPeer, error) { + fake.callMutex.Lock() + ret, specificReturn := fake.callReturnsOnCall[len(fake.callArgsForCall)] + fake.callArgsForCall = append(fake.callArgsForCall, struct { + }{}) + stub := fake.CallStub + fakeReturns := fake.callReturns + fake.recordInvocation("Call", []interface{}{}) + fake.callMutex.Unlock() + if stub != nil { + return stub() + } + if specificReturn { + return ret.result1, ret.result2 + } + return fakeReturns.result1, fakeReturns.result2 +} + +func (fake *Discover) CallCallCount() int { + fake.callMutex.RLock() + defer fake.callMutex.RUnlock() + return len(fake.callArgsForCall) +} + +func (fake *Discover) CallCalls(stub func() ([]driver.DiscoveredPeer, error)) { + fake.callMutex.Lock() + defer fake.callMutex.Unlock() + fake.CallStub = stub +} + +func (fake *Discover) CallReturns(result1 []driver.DiscoveredPeer, result2 error) { + fake.callMutex.Lock() + defer fake.callMutex.Unlock() + fake.CallStub = nil + fake.callReturns = struct { + result1 []driver.DiscoveredPeer + result2 error + }{result1, result2} +} + +func (fake *Discover) CallReturnsOnCall(i int, result1 []driver.DiscoveredPeer, result2 error) { + fake.callMutex.Lock() + defer fake.callMutex.Unlock() + fake.CallStub = nil + if fake.callReturnsOnCall == nil { + fake.callReturnsOnCall = make(map[int]struct { + result1 []driver.DiscoveredPeer + result2 error + }) + } + fake.callReturnsOnCall[i] = struct { + result1 []driver.DiscoveredPeer + result2 error + }{result1, result2} +} + +func (fake *Discover) ChaincodeVersion() (string, error) { + fake.chaincodeVersionMutex.Lock() + ret, specificReturn := fake.chaincodeVersionReturnsOnCall[len(fake.chaincodeVersionArgsForCall)] + fake.chaincodeVersionArgsForCall = append(fake.chaincodeVersionArgsForCall, struct { + }{}) + stub := fake.ChaincodeVersionStub + fakeReturns := fake.chaincodeVersionReturns + fake.recordInvocation("ChaincodeVersion", []interface{}{}) + fake.chaincodeVersionMutex.Unlock() + if stub != nil { + return stub() + } + if specificReturn { + return ret.result1, ret.result2 + } + return fakeReturns.result1, fakeReturns.result2 +} + +func (fake *Discover) ChaincodeVersionCallCount() int { + fake.chaincodeVersionMutex.RLock() + defer fake.chaincodeVersionMutex.RUnlock() + return len(fake.chaincodeVersionArgsForCall) +} + +func (fake *Discover) ChaincodeVersionCalls(stub func() (string, error)) { + fake.chaincodeVersionMutex.Lock() + defer fake.chaincodeVersionMutex.Unlock() + fake.ChaincodeVersionStub = stub +} + +func (fake *Discover) ChaincodeVersionReturns(result1 string, result2 error) { + fake.chaincodeVersionMutex.Lock() + defer fake.chaincodeVersionMutex.Unlock() + fake.ChaincodeVersionStub = nil + fake.chaincodeVersionReturns = struct { + result1 string + result2 error + }{result1, result2} +} + +func (fake *Discover) ChaincodeVersionReturnsOnCall(i int, result1 string, result2 error) { + fake.chaincodeVersionMutex.Lock() + defer fake.chaincodeVersionMutex.Unlock() + fake.ChaincodeVersionStub = nil + if fake.chaincodeVersionReturnsOnCall == nil { + fake.chaincodeVersionReturnsOnCall = make(map[int]struct { + result1 string + result2 error + }) + } + fake.chaincodeVersionReturnsOnCall[i] = struct { + result1 string + result2 error + }{result1, result2} +} + +func (fake *Discover) WithFilterByMSPIDs(arg1 ...string) driver.ChaincodeDiscover { + fake.withFilterByMSPIDsMutex.Lock() + ret, specificReturn := fake.withFilterByMSPIDsReturnsOnCall[len(fake.withFilterByMSPIDsArgsForCall)] + fake.withFilterByMSPIDsArgsForCall = append(fake.withFilterByMSPIDsArgsForCall, struct { + arg1 []string + }{arg1}) + stub := fake.WithFilterByMSPIDsStub + fakeReturns := fake.withFilterByMSPIDsReturns + fake.recordInvocation("WithFilterByMSPIDs", []interface{}{arg1}) + fake.withFilterByMSPIDsMutex.Unlock() + if stub != nil { + return stub(arg1...) + } + if specificReturn { + return ret.result1 + } + return fakeReturns.result1 +} + +func (fake *Discover) WithFilterByMSPIDsCallCount() int { + fake.withFilterByMSPIDsMutex.RLock() + defer fake.withFilterByMSPIDsMutex.RUnlock() + return len(fake.withFilterByMSPIDsArgsForCall) +} + +func (fake *Discover) WithFilterByMSPIDsCalls(stub func(...string) driver.ChaincodeDiscover) { + fake.withFilterByMSPIDsMutex.Lock() + defer fake.withFilterByMSPIDsMutex.Unlock() + fake.WithFilterByMSPIDsStub = stub +} + +func (fake *Discover) WithFilterByMSPIDsArgsForCall(i int) []string { + fake.withFilterByMSPIDsMutex.RLock() + defer fake.withFilterByMSPIDsMutex.RUnlock() + argsForCall := fake.withFilterByMSPIDsArgsForCall[i] + return argsForCall.arg1 +} + +func (fake *Discover) WithFilterByMSPIDsReturns(result1 driver.ChaincodeDiscover) { + fake.withFilterByMSPIDsMutex.Lock() + defer fake.withFilterByMSPIDsMutex.Unlock() + fake.WithFilterByMSPIDsStub = nil + fake.withFilterByMSPIDsReturns = struct { + result1 driver.ChaincodeDiscover + }{result1} +} + +func (fake *Discover) WithFilterByMSPIDsReturnsOnCall(i int, result1 driver.ChaincodeDiscover) { + fake.withFilterByMSPIDsMutex.Lock() + defer fake.withFilterByMSPIDsMutex.Unlock() + fake.WithFilterByMSPIDsStub = nil + if fake.withFilterByMSPIDsReturnsOnCall == nil { + fake.withFilterByMSPIDsReturnsOnCall = make(map[int]struct { + result1 driver.ChaincodeDiscover + }) + } + fake.withFilterByMSPIDsReturnsOnCall[i] = struct { + result1 driver.ChaincodeDiscover + }{result1} +} + +func (fake *Discover) WithForQuery() driver.ChaincodeDiscover { + fake.withForQueryMutex.Lock() + ret, specificReturn := fake.withForQueryReturnsOnCall[len(fake.withForQueryArgsForCall)] + fake.withForQueryArgsForCall = append(fake.withForQueryArgsForCall, struct { + }{}) + stub := fake.WithForQueryStub + fakeReturns := fake.withForQueryReturns + fake.recordInvocation("WithForQuery", []interface{}{}) + fake.withForQueryMutex.Unlock() + if stub != nil { + return stub() + } + if specificReturn { + return ret.result1 + } + return fakeReturns.result1 +} + +func (fake *Discover) WithForQueryCallCount() int { + fake.withForQueryMutex.RLock() + defer fake.withForQueryMutex.RUnlock() + return len(fake.withForQueryArgsForCall) +} + +func (fake *Discover) WithForQueryCalls(stub func() driver.ChaincodeDiscover) { + fake.withForQueryMutex.Lock() + defer fake.withForQueryMutex.Unlock() + fake.WithForQueryStub = stub +} + +func (fake *Discover) WithForQueryReturns(result1 driver.ChaincodeDiscover) { + fake.withForQueryMutex.Lock() + defer fake.withForQueryMutex.Unlock() + fake.WithForQueryStub = nil + fake.withForQueryReturns = struct { + result1 driver.ChaincodeDiscover + }{result1} +} + +func (fake *Discover) WithForQueryReturnsOnCall(i int, result1 driver.ChaincodeDiscover) { + fake.withForQueryMutex.Lock() + defer fake.withForQueryMutex.Unlock() + fake.WithForQueryStub = nil + if fake.withForQueryReturnsOnCall == nil { + fake.withForQueryReturnsOnCall = make(map[int]struct { + result1 driver.ChaincodeDiscover + }) + } + fake.withForQueryReturnsOnCall[i] = struct { + result1 driver.ChaincodeDiscover + }{result1} +} + +func (fake *Discover) WithImplicitCollections(arg1 ...string) driver.ChaincodeDiscover { + fake.withImplicitCollectionsMutex.Lock() + ret, specificReturn := fake.withImplicitCollectionsReturnsOnCall[len(fake.withImplicitCollectionsArgsForCall)] + fake.withImplicitCollectionsArgsForCall = append(fake.withImplicitCollectionsArgsForCall, struct { + arg1 []string + }{arg1}) + stub := fake.WithImplicitCollectionsStub + fakeReturns := fake.withImplicitCollectionsReturns + fake.recordInvocation("WithImplicitCollections", []interface{}{arg1}) + fake.withImplicitCollectionsMutex.Unlock() + if stub != nil { + return stub(arg1...) + } + if specificReturn { + return ret.result1 + } + return fakeReturns.result1 +} + +func (fake *Discover) WithImplicitCollectionsCallCount() int { + fake.withImplicitCollectionsMutex.RLock() + defer fake.withImplicitCollectionsMutex.RUnlock() + return len(fake.withImplicitCollectionsArgsForCall) +} + +func (fake *Discover) WithImplicitCollectionsCalls(stub func(...string) driver.ChaincodeDiscover) { + fake.withImplicitCollectionsMutex.Lock() + defer fake.withImplicitCollectionsMutex.Unlock() + fake.WithImplicitCollectionsStub = stub +} + +func (fake *Discover) WithImplicitCollectionsArgsForCall(i int) []string { + fake.withImplicitCollectionsMutex.RLock() + defer fake.withImplicitCollectionsMutex.RUnlock() + argsForCall := fake.withImplicitCollectionsArgsForCall[i] + return argsForCall.arg1 +} + +func (fake *Discover) WithImplicitCollectionsReturns(result1 driver.ChaincodeDiscover) { + fake.withImplicitCollectionsMutex.Lock() + defer fake.withImplicitCollectionsMutex.Unlock() + fake.WithImplicitCollectionsStub = nil + fake.withImplicitCollectionsReturns = struct { + result1 driver.ChaincodeDiscover + }{result1} +} + +func (fake *Discover) WithImplicitCollectionsReturnsOnCall(i int, result1 driver.ChaincodeDiscover) { + fake.withImplicitCollectionsMutex.Lock() + defer fake.withImplicitCollectionsMutex.Unlock() + fake.WithImplicitCollectionsStub = nil + if fake.withImplicitCollectionsReturnsOnCall == nil { + fake.withImplicitCollectionsReturnsOnCall = make(map[int]struct { + result1 driver.ChaincodeDiscover + }) + } + fake.withImplicitCollectionsReturnsOnCall[i] = struct { + result1 driver.ChaincodeDiscover + }{result1} +} + +func (fake *Discover) Invocations() map[string][][]interface{} { + fake.invocationsMutex.RLock() + defer fake.invocationsMutex.RUnlock() + fake.callMutex.RLock() + defer fake.callMutex.RUnlock() + fake.chaincodeVersionMutex.RLock() + defer fake.chaincodeVersionMutex.RUnlock() + fake.withFilterByMSPIDsMutex.RLock() + defer fake.withFilterByMSPIDsMutex.RUnlock() + fake.withForQueryMutex.RLock() + defer fake.withForQueryMutex.RUnlock() + fake.withImplicitCollectionsMutex.RLock() + defer fake.withImplicitCollectionsMutex.RUnlock() + copiedInvocations := map[string][][]interface{}{} + for key, value := range fake.invocations { + copiedInvocations[key] = value + } + return copiedInvocations +} + +func (fake *Discover) 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) +} + +var _ chaincode.Discover = new(Discover) diff --git a/platform/fabric/core/generic/chaincode/mocks/channel.go b/platform/fabric/core/generic/chaincode/mocks/channel.go new file mode 100644 index 000000000..fe997b875 --- /dev/null +++ b/platform/fabric/core/generic/chaincode/mocks/channel.go @@ -0,0 +1,466 @@ +// Code generated by counterfeiter. DO NOT EDIT. +package mocks + +import ( + "context" + "sync" + + "github.com/hyperledger-labs/fabric-smart-client/platform/fabric/core/generic/chaincode" + "github.com/hyperledger-labs/fabric-smart-client/platform/fabric/core/generic/config" + "github.com/hyperledger-labs/fabric-smart-client/platform/fabric/core/generic/peer" + "github.com/hyperledger-labs/fabric-smart-client/platform/fabric/driver" + "github.com/hyperledger-labs/fabric-smart-client/platform/view/services/grpc" +) + +type Channel struct { + ChaincodeStub func(string) driver.Chaincode + chaincodeMutex sync.RWMutex + chaincodeArgsForCall []struct { + arg1 string + } + chaincodeReturns struct { + result1 driver.Chaincode + } + chaincodeReturnsOnCall map[int]struct { + result1 driver.Chaincode + } + ConfigStub func() *config.Channel + configMutex sync.RWMutex + configArgsForCall []struct { + } + configReturns struct { + result1 *config.Channel + } + configReturnsOnCall map[int]struct { + result1 *config.Channel + } + IsFinalStub func(context.Context, string) error + isFinalMutex sync.RWMutex + isFinalArgsForCall []struct { + arg1 context.Context + arg2 string + } + isFinalReturns struct { + result1 error + } + isFinalReturnsOnCall map[int]struct { + result1 error + } + MSPManagerStub func() driver.MSPManager + mSPManagerMutex sync.RWMutex + mSPManagerArgsForCall []struct { + } + mSPManagerReturns struct { + result1 driver.MSPManager + } + mSPManagerReturnsOnCall map[int]struct { + result1 driver.MSPManager + } + NameStub func() string + nameMutex sync.RWMutex + nameArgsForCall []struct { + } + nameReturns struct { + result1 string + } + nameReturnsOnCall map[int]struct { + result1 string + } + NewPeerClientForAddressStub func(grpc.ConnectionConfig) (peer.Client, error) + newPeerClientForAddressMutex sync.RWMutex + newPeerClientForAddressArgsForCall []struct { + arg1 grpc.ConnectionConfig + } + newPeerClientForAddressReturns struct { + result1 peer.Client + result2 error + } + newPeerClientForAddressReturnsOnCall map[int]struct { + result1 peer.Client + result2 error + } + invocations map[string][][]interface{} + invocationsMutex sync.RWMutex +} + +func (fake *Channel) Chaincode(arg1 string) driver.Chaincode { + fake.chaincodeMutex.Lock() + ret, specificReturn := fake.chaincodeReturnsOnCall[len(fake.chaincodeArgsForCall)] + fake.chaincodeArgsForCall = append(fake.chaincodeArgsForCall, struct { + arg1 string + }{arg1}) + stub := fake.ChaincodeStub + fakeReturns := fake.chaincodeReturns + fake.recordInvocation("Chaincode", []interface{}{arg1}) + fake.chaincodeMutex.Unlock() + if stub != nil { + return stub(arg1) + } + if specificReturn { + return ret.result1 + } + return fakeReturns.result1 +} + +func (fake *Channel) ChaincodeCallCount() int { + fake.chaincodeMutex.RLock() + defer fake.chaincodeMutex.RUnlock() + return len(fake.chaincodeArgsForCall) +} + +func (fake *Channel) ChaincodeCalls(stub func(string) driver.Chaincode) { + fake.chaincodeMutex.Lock() + defer fake.chaincodeMutex.Unlock() + fake.ChaincodeStub = stub +} + +func (fake *Channel) ChaincodeArgsForCall(i int) string { + fake.chaincodeMutex.RLock() + defer fake.chaincodeMutex.RUnlock() + argsForCall := fake.chaincodeArgsForCall[i] + return argsForCall.arg1 +} + +func (fake *Channel) ChaincodeReturns(result1 driver.Chaincode) { + fake.chaincodeMutex.Lock() + defer fake.chaincodeMutex.Unlock() + fake.ChaincodeStub = nil + fake.chaincodeReturns = struct { + result1 driver.Chaincode + }{result1} +} + +func (fake *Channel) ChaincodeReturnsOnCall(i int, result1 driver.Chaincode) { + fake.chaincodeMutex.Lock() + defer fake.chaincodeMutex.Unlock() + fake.ChaincodeStub = nil + if fake.chaincodeReturnsOnCall == nil { + fake.chaincodeReturnsOnCall = make(map[int]struct { + result1 driver.Chaincode + }) + } + fake.chaincodeReturnsOnCall[i] = struct { + result1 driver.Chaincode + }{result1} +} + +func (fake *Channel) Config() *config.Channel { + fake.configMutex.Lock() + ret, specificReturn := fake.configReturnsOnCall[len(fake.configArgsForCall)] + fake.configArgsForCall = append(fake.configArgsForCall, struct { + }{}) + stub := fake.ConfigStub + fakeReturns := fake.configReturns + fake.recordInvocation("Config", []interface{}{}) + fake.configMutex.Unlock() + if stub != nil { + return stub() + } + if specificReturn { + return ret.result1 + } + return fakeReturns.result1 +} + +func (fake *Channel) ConfigCallCount() int { + fake.configMutex.RLock() + defer fake.configMutex.RUnlock() + return len(fake.configArgsForCall) +} + +func (fake *Channel) ConfigCalls(stub func() *config.Channel) { + fake.configMutex.Lock() + defer fake.configMutex.Unlock() + fake.ConfigStub = stub +} + +func (fake *Channel) ConfigReturns(result1 *config.Channel) { + fake.configMutex.Lock() + defer fake.configMutex.Unlock() + fake.ConfigStub = nil + fake.configReturns = struct { + result1 *config.Channel + }{result1} +} + +func (fake *Channel) ConfigReturnsOnCall(i int, result1 *config.Channel) { + fake.configMutex.Lock() + defer fake.configMutex.Unlock() + fake.ConfigStub = nil + if fake.configReturnsOnCall == nil { + fake.configReturnsOnCall = make(map[int]struct { + result1 *config.Channel + }) + } + fake.configReturnsOnCall[i] = struct { + result1 *config.Channel + }{result1} +} + +func (fake *Channel) IsFinal(arg1 context.Context, arg2 string) error { + fake.isFinalMutex.Lock() + ret, specificReturn := fake.isFinalReturnsOnCall[len(fake.isFinalArgsForCall)] + fake.isFinalArgsForCall = append(fake.isFinalArgsForCall, struct { + arg1 context.Context + arg2 string + }{arg1, arg2}) + stub := fake.IsFinalStub + fakeReturns := fake.isFinalReturns + fake.recordInvocation("IsFinal", []interface{}{arg1, arg2}) + fake.isFinalMutex.Unlock() + if stub != nil { + return stub(arg1, arg2) + } + if specificReturn { + return ret.result1 + } + return fakeReturns.result1 +} + +func (fake *Channel) IsFinalCallCount() int { + fake.isFinalMutex.RLock() + defer fake.isFinalMutex.RUnlock() + return len(fake.isFinalArgsForCall) +} + +func (fake *Channel) IsFinalCalls(stub func(context.Context, string) error) { + fake.isFinalMutex.Lock() + defer fake.isFinalMutex.Unlock() + fake.IsFinalStub = stub +} + +func (fake *Channel) IsFinalArgsForCall(i int) (context.Context, string) { + fake.isFinalMutex.RLock() + defer fake.isFinalMutex.RUnlock() + argsForCall := fake.isFinalArgsForCall[i] + return argsForCall.arg1, argsForCall.arg2 +} + +func (fake *Channel) IsFinalReturns(result1 error) { + fake.isFinalMutex.Lock() + defer fake.isFinalMutex.Unlock() + fake.IsFinalStub = nil + fake.isFinalReturns = struct { + result1 error + }{result1} +} + +func (fake *Channel) IsFinalReturnsOnCall(i int, result1 error) { + fake.isFinalMutex.Lock() + defer fake.isFinalMutex.Unlock() + fake.IsFinalStub = nil + if fake.isFinalReturnsOnCall == nil { + fake.isFinalReturnsOnCall = make(map[int]struct { + result1 error + }) + } + fake.isFinalReturnsOnCall[i] = struct { + result1 error + }{result1} +} + +func (fake *Channel) MSPManager() driver.MSPManager { + fake.mSPManagerMutex.Lock() + ret, specificReturn := fake.mSPManagerReturnsOnCall[len(fake.mSPManagerArgsForCall)] + fake.mSPManagerArgsForCall = append(fake.mSPManagerArgsForCall, struct { + }{}) + stub := fake.MSPManagerStub + fakeReturns := fake.mSPManagerReturns + fake.recordInvocation("MSPManager", []interface{}{}) + fake.mSPManagerMutex.Unlock() + if stub != nil { + return stub() + } + if specificReturn { + return ret.result1 + } + return fakeReturns.result1 +} + +func (fake *Channel) MSPManagerCallCount() int { + fake.mSPManagerMutex.RLock() + defer fake.mSPManagerMutex.RUnlock() + return len(fake.mSPManagerArgsForCall) +} + +func (fake *Channel) MSPManagerCalls(stub func() driver.MSPManager) { + fake.mSPManagerMutex.Lock() + defer fake.mSPManagerMutex.Unlock() + fake.MSPManagerStub = stub +} + +func (fake *Channel) MSPManagerReturns(result1 driver.MSPManager) { + fake.mSPManagerMutex.Lock() + defer fake.mSPManagerMutex.Unlock() + fake.MSPManagerStub = nil + fake.mSPManagerReturns = struct { + result1 driver.MSPManager + }{result1} +} + +func (fake *Channel) MSPManagerReturnsOnCall(i int, result1 driver.MSPManager) { + fake.mSPManagerMutex.Lock() + defer fake.mSPManagerMutex.Unlock() + fake.MSPManagerStub = nil + if fake.mSPManagerReturnsOnCall == nil { + fake.mSPManagerReturnsOnCall = make(map[int]struct { + result1 driver.MSPManager + }) + } + fake.mSPManagerReturnsOnCall[i] = struct { + result1 driver.MSPManager + }{result1} +} + +func (fake *Channel) Name() string { + fake.nameMutex.Lock() + ret, specificReturn := fake.nameReturnsOnCall[len(fake.nameArgsForCall)] + fake.nameArgsForCall = append(fake.nameArgsForCall, struct { + }{}) + stub := fake.NameStub + fakeReturns := fake.nameReturns + fake.recordInvocation("Name", []interface{}{}) + fake.nameMutex.Unlock() + if stub != nil { + return stub() + } + if specificReturn { + return ret.result1 + } + return fakeReturns.result1 +} + +func (fake *Channel) NameCallCount() int { + fake.nameMutex.RLock() + defer fake.nameMutex.RUnlock() + return len(fake.nameArgsForCall) +} + +func (fake *Channel) NameCalls(stub func() string) { + fake.nameMutex.Lock() + defer fake.nameMutex.Unlock() + fake.NameStub = stub +} + +func (fake *Channel) NameReturns(result1 string) { + fake.nameMutex.Lock() + defer fake.nameMutex.Unlock() + fake.NameStub = nil + fake.nameReturns = struct { + result1 string + }{result1} +} + +func (fake *Channel) NameReturnsOnCall(i int, result1 string) { + fake.nameMutex.Lock() + defer fake.nameMutex.Unlock() + fake.NameStub = nil + if fake.nameReturnsOnCall == nil { + fake.nameReturnsOnCall = make(map[int]struct { + result1 string + }) + } + fake.nameReturnsOnCall[i] = struct { + result1 string + }{result1} +} + +func (fake *Channel) NewPeerClientForAddress(arg1 grpc.ConnectionConfig) (peer.Client, error) { + fake.newPeerClientForAddressMutex.Lock() + ret, specificReturn := fake.newPeerClientForAddressReturnsOnCall[len(fake.newPeerClientForAddressArgsForCall)] + fake.newPeerClientForAddressArgsForCall = append(fake.newPeerClientForAddressArgsForCall, struct { + arg1 grpc.ConnectionConfig + }{arg1}) + stub := fake.NewPeerClientForAddressStub + fakeReturns := fake.newPeerClientForAddressReturns + fake.recordInvocation("NewPeerClientForAddress", []interface{}{arg1}) + fake.newPeerClientForAddressMutex.Unlock() + if stub != nil { + return stub(arg1) + } + if specificReturn { + return ret.result1, ret.result2 + } + return fakeReturns.result1, fakeReturns.result2 +} + +func (fake *Channel) NewPeerClientForAddressCallCount() int { + fake.newPeerClientForAddressMutex.RLock() + defer fake.newPeerClientForAddressMutex.RUnlock() + return len(fake.newPeerClientForAddressArgsForCall) +} + +func (fake *Channel) NewPeerClientForAddressCalls(stub func(grpc.ConnectionConfig) (peer.Client, error)) { + fake.newPeerClientForAddressMutex.Lock() + defer fake.newPeerClientForAddressMutex.Unlock() + fake.NewPeerClientForAddressStub = stub +} + +func (fake *Channel) NewPeerClientForAddressArgsForCall(i int) grpc.ConnectionConfig { + fake.newPeerClientForAddressMutex.RLock() + defer fake.newPeerClientForAddressMutex.RUnlock() + argsForCall := fake.newPeerClientForAddressArgsForCall[i] + return argsForCall.arg1 +} + +func (fake *Channel) NewPeerClientForAddressReturns(result1 peer.Client, result2 error) { + fake.newPeerClientForAddressMutex.Lock() + defer fake.newPeerClientForAddressMutex.Unlock() + fake.NewPeerClientForAddressStub = nil + fake.newPeerClientForAddressReturns = struct { + result1 peer.Client + result2 error + }{result1, result2} +} + +func (fake *Channel) NewPeerClientForAddressReturnsOnCall(i int, result1 peer.Client, result2 error) { + fake.newPeerClientForAddressMutex.Lock() + defer fake.newPeerClientForAddressMutex.Unlock() + fake.NewPeerClientForAddressStub = nil + if fake.newPeerClientForAddressReturnsOnCall == nil { + fake.newPeerClientForAddressReturnsOnCall = make(map[int]struct { + result1 peer.Client + result2 error + }) + } + fake.newPeerClientForAddressReturnsOnCall[i] = struct { + result1 peer.Client + result2 error + }{result1, result2} +} + +func (fake *Channel) Invocations() map[string][][]interface{} { + fake.invocationsMutex.RLock() + defer fake.invocationsMutex.RUnlock() + fake.chaincodeMutex.RLock() + defer fake.chaincodeMutex.RUnlock() + fake.configMutex.RLock() + defer fake.configMutex.RUnlock() + fake.isFinalMutex.RLock() + defer fake.isFinalMutex.RUnlock() + fake.mSPManagerMutex.RLock() + defer fake.mSPManagerMutex.RUnlock() + fake.nameMutex.RLock() + defer fake.nameMutex.RUnlock() + fake.newPeerClientForAddressMutex.RLock() + defer fake.newPeerClientForAddressMutex.RUnlock() + copiedInvocations := map[string][][]interface{}{} + for key, value := range fake.invocations { + copiedInvocations[key] = value + } + return copiedInvocations +} + +func (fake *Channel) 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) +} + +var _ chaincode.Channel = new(Channel) diff --git a/platform/fabric/core/generic/chaincode/mocks/ec.go b/platform/fabric/core/generic/chaincode/mocks/ec.go new file mode 100644 index 000000000..b78ebf449 --- /dev/null +++ b/platform/fabric/core/generic/chaincode/mocks/ec.go @@ -0,0 +1,123 @@ +// Code generated by counterfeiter. DO NOT EDIT. +package mocks + +import ( + "context" + "sync" + + "github.com/hyperledger-labs/fabric-smart-client/platform/fabric/core/generic/chaincode" + "github.com/hyperledger/fabric-protos-go/peer" + "google.golang.org/grpc" +) + +type EndorserClient struct { + ProcessProposalStub func(context.Context, *peer.SignedProposal, ...grpc.CallOption) (*peer.ProposalResponse, error) + processProposalMutex sync.RWMutex + processProposalArgsForCall []struct { + arg1 context.Context + arg2 *peer.SignedProposal + arg3 []grpc.CallOption + } + processProposalReturns struct { + result1 *peer.ProposalResponse + result2 error + } + processProposalReturnsOnCall map[int]struct { + result1 *peer.ProposalResponse + result2 error + } + invocations map[string][][]interface{} + invocationsMutex sync.RWMutex +} + +func (fake *EndorserClient) ProcessProposal(arg1 context.Context, arg2 *peer.SignedProposal, arg3 ...grpc.CallOption) (*peer.ProposalResponse, error) { + fake.processProposalMutex.Lock() + ret, specificReturn := fake.processProposalReturnsOnCall[len(fake.processProposalArgsForCall)] + fake.processProposalArgsForCall = append(fake.processProposalArgsForCall, struct { + arg1 context.Context + arg2 *peer.SignedProposal + arg3 []grpc.CallOption + }{arg1, arg2, arg3}) + stub := fake.ProcessProposalStub + fakeReturns := fake.processProposalReturns + fake.recordInvocation("ProcessProposal", []interface{}{arg1, arg2, arg3}) + fake.processProposalMutex.Unlock() + if stub != nil { + return stub(arg1, arg2, arg3...) + } + if specificReturn { + return ret.result1, ret.result2 + } + return fakeReturns.result1, fakeReturns.result2 +} + +func (fake *EndorserClient) ProcessProposalCallCount() int { + fake.processProposalMutex.RLock() + defer fake.processProposalMutex.RUnlock() + return len(fake.processProposalArgsForCall) +} + +func (fake *EndorserClient) ProcessProposalCalls(stub func(context.Context, *peer.SignedProposal, ...grpc.CallOption) (*peer.ProposalResponse, error)) { + fake.processProposalMutex.Lock() + defer fake.processProposalMutex.Unlock() + fake.ProcessProposalStub = stub +} + +func (fake *EndorserClient) ProcessProposalArgsForCall(i int) (context.Context, *peer.SignedProposal, []grpc.CallOption) { + fake.processProposalMutex.RLock() + defer fake.processProposalMutex.RUnlock() + argsForCall := fake.processProposalArgsForCall[i] + return argsForCall.arg1, argsForCall.arg2, argsForCall.arg3 +} + +func (fake *EndorserClient) ProcessProposalReturns(result1 *peer.ProposalResponse, result2 error) { + fake.processProposalMutex.Lock() + defer fake.processProposalMutex.Unlock() + fake.ProcessProposalStub = nil + fake.processProposalReturns = struct { + result1 *peer.ProposalResponse + result2 error + }{result1, result2} +} + +func (fake *EndorserClient) ProcessProposalReturnsOnCall(i int, result1 *peer.ProposalResponse, result2 error) { + fake.processProposalMutex.Lock() + defer fake.processProposalMutex.Unlock() + fake.ProcessProposalStub = nil + if fake.processProposalReturnsOnCall == nil { + fake.processProposalReturnsOnCall = make(map[int]struct { + result1 *peer.ProposalResponse + result2 error + }) + } + fake.processProposalReturnsOnCall[i] = struct { + result1 *peer.ProposalResponse + result2 error + }{result1, result2} +} + +func (fake *EndorserClient) Invocations() map[string][][]interface{} { + fake.invocationsMutex.RLock() + defer fake.invocationsMutex.RUnlock() + fake.processProposalMutex.RLock() + defer fake.processProposalMutex.RUnlock() + copiedInvocations := map[string][][]interface{}{} + for key, value := range fake.invocations { + copiedInvocations[key] = value + } + return copiedInvocations +} + +func (fake *EndorserClient) 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) +} + +var _ chaincode.EndorserClient = new(EndorserClient) diff --git a/platform/fabric/core/generic/chaincode/mocks/mspid.go b/platform/fabric/core/generic/chaincode/mocks/mspid.go new file mode 100644 index 000000000..510124cd5 --- /dev/null +++ b/platform/fabric/core/generic/chaincode/mocks/mspid.go @@ -0,0 +1,253 @@ +// Code generated by counterfeiter. DO NOT EDIT. +package mocks + +import ( + "sync" + + "github.com/hyperledger-labs/fabric-smart-client/platform/fabric/core/generic/chaincode" +) + +type MSPIdentity struct { + GetMSPIdentifierStub func() string + getMSPIdentifierMutex sync.RWMutex + getMSPIdentifierArgsForCall []struct { + } + getMSPIdentifierReturns struct { + result1 string + } + getMSPIdentifierReturnsOnCall map[int]struct { + result1 string + } + 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 *MSPIdentity) GetMSPIdentifier() string { + fake.getMSPIdentifierMutex.Lock() + ret, specificReturn := fake.getMSPIdentifierReturnsOnCall[len(fake.getMSPIdentifierArgsForCall)] + fake.getMSPIdentifierArgsForCall = append(fake.getMSPIdentifierArgsForCall, struct { + }{}) + stub := fake.GetMSPIdentifierStub + fakeReturns := fake.getMSPIdentifierReturns + fake.recordInvocation("GetMSPIdentifier", []interface{}{}) + fake.getMSPIdentifierMutex.Unlock() + if stub != nil { + return stub() + } + if specificReturn { + return ret.result1 + } + return fakeReturns.result1 +} + +func (fake *MSPIdentity) GetMSPIdentifierCallCount() int { + fake.getMSPIdentifierMutex.RLock() + defer fake.getMSPIdentifierMutex.RUnlock() + return len(fake.getMSPIdentifierArgsForCall) +} + +func (fake *MSPIdentity) GetMSPIdentifierCalls(stub func() string) { + fake.getMSPIdentifierMutex.Lock() + defer fake.getMSPIdentifierMutex.Unlock() + fake.GetMSPIdentifierStub = stub +} + +func (fake *MSPIdentity) GetMSPIdentifierReturns(result1 string) { + fake.getMSPIdentifierMutex.Lock() + defer fake.getMSPIdentifierMutex.Unlock() + fake.GetMSPIdentifierStub = nil + fake.getMSPIdentifierReturns = struct { + result1 string + }{result1} +} + +func (fake *MSPIdentity) 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 *MSPIdentity) Validate() error { + fake.validateMutex.Lock() + ret, specificReturn := fake.validateReturnsOnCall[len(fake.validateArgsForCall)] + fake.validateArgsForCall = append(fake.validateArgsForCall, struct { + }{}) + stub := fake.ValidateStub + fakeReturns := fake.validateReturns + fake.recordInvocation("Validate", []interface{}{}) + fake.validateMutex.Unlock() + if stub != nil { + return stub() + } + if specificReturn { + return ret.result1 + } + return fakeReturns.result1 +} + +func (fake *MSPIdentity) ValidateCallCount() int { + fake.validateMutex.RLock() + defer fake.validateMutex.RUnlock() + return len(fake.validateArgsForCall) +} + +func (fake *MSPIdentity) ValidateCalls(stub func() error) { + fake.validateMutex.Lock() + defer fake.validateMutex.Unlock() + fake.ValidateStub = stub +} + +func (fake *MSPIdentity) ValidateReturns(result1 error) { + fake.validateMutex.Lock() + defer fake.validateMutex.Unlock() + fake.ValidateStub = nil + fake.validateReturns = struct { + result1 error + }{result1} +} + +func (fake *MSPIdentity) 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 *MSPIdentity) 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}) + stub := fake.VerifyStub + fakeReturns := fake.verifyReturns + fake.recordInvocation("Verify", []interface{}{arg1Copy, arg2Copy}) + fake.verifyMutex.Unlock() + if stub != nil { + return stub(arg1, arg2) + } + if specificReturn { + return ret.result1 + } + return fakeReturns.result1 +} + +func (fake *MSPIdentity) VerifyCallCount() int { + fake.verifyMutex.RLock() + defer fake.verifyMutex.RUnlock() + return len(fake.verifyArgsForCall) +} + +func (fake *MSPIdentity) VerifyCalls(stub func([]byte, []byte) error) { + fake.verifyMutex.Lock() + defer fake.verifyMutex.Unlock() + fake.VerifyStub = stub +} + +func (fake *MSPIdentity) VerifyArgsForCall(i int) ([]byte, []byte) { + fake.verifyMutex.RLock() + defer fake.verifyMutex.RUnlock() + argsForCall := fake.verifyArgsForCall[i] + return argsForCall.arg1, argsForCall.arg2 +} + +func (fake *MSPIdentity) VerifyReturns(result1 error) { + fake.verifyMutex.Lock() + defer fake.verifyMutex.Unlock() + fake.VerifyStub = nil + fake.verifyReturns = struct { + result1 error + }{result1} +} + +func (fake *MSPIdentity) 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 *MSPIdentity) Invocations() map[string][][]interface{} { + fake.invocationsMutex.RLock() + defer fake.invocationsMutex.RUnlock() + fake.getMSPIdentifierMutex.RLock() + defer fake.getMSPIdentifierMutex.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 *MSPIdentity) 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) +} + +var _ chaincode.MSPIdentity = new(MSPIdentity) diff --git a/platform/fabric/core/generic/chaincode/mocks/mspm.go b/platform/fabric/core/generic/chaincode/mocks/mspm.go new file mode 100644 index 000000000..c381c6db1 --- /dev/null +++ b/platform/fabric/core/generic/chaincode/mocks/mspm.go @@ -0,0 +1,122 @@ +// Code generated by counterfeiter. DO NOT EDIT. +package mocks + +import ( + "sync" + + "github.com/hyperledger-labs/fabric-smart-client/platform/fabric/core/generic/chaincode" + "github.com/hyperledger-labs/fabric-smart-client/platform/fabric/driver" +) + +type MSPManager struct { + DeserializeIdentityStub func([]byte) (driver.MSPIdentity, error) + deserializeIdentityMutex sync.RWMutex + deserializeIdentityArgsForCall []struct { + arg1 []byte + } + deserializeIdentityReturns struct { + result1 driver.MSPIdentity + result2 error + } + deserializeIdentityReturnsOnCall map[int]struct { + result1 driver.MSPIdentity + result2 error + } + invocations map[string][][]interface{} + invocationsMutex sync.RWMutex +} + +func (fake *MSPManager) DeserializeIdentity(arg1 []byte) (driver.MSPIdentity, error) { + var arg1Copy []byte + if arg1 != nil { + arg1Copy = make([]byte, len(arg1)) + copy(arg1Copy, arg1) + } + fake.deserializeIdentityMutex.Lock() + ret, specificReturn := fake.deserializeIdentityReturnsOnCall[len(fake.deserializeIdentityArgsForCall)] + fake.deserializeIdentityArgsForCall = append(fake.deserializeIdentityArgsForCall, struct { + arg1 []byte + }{arg1Copy}) + stub := fake.DeserializeIdentityStub + fakeReturns := fake.deserializeIdentityReturns + fake.recordInvocation("DeserializeIdentity", []interface{}{arg1Copy}) + fake.deserializeIdentityMutex.Unlock() + if stub != nil { + return stub(arg1) + } + if specificReturn { + return ret.result1, ret.result2 + } + return fakeReturns.result1, fakeReturns.result2 +} + +func (fake *MSPManager) DeserializeIdentityCallCount() int { + fake.deserializeIdentityMutex.RLock() + defer fake.deserializeIdentityMutex.RUnlock() + return len(fake.deserializeIdentityArgsForCall) +} + +func (fake *MSPManager) DeserializeIdentityCalls(stub func([]byte) (driver.MSPIdentity, error)) { + fake.deserializeIdentityMutex.Lock() + defer fake.deserializeIdentityMutex.Unlock() + fake.DeserializeIdentityStub = stub +} + +func (fake *MSPManager) DeserializeIdentityArgsForCall(i int) []byte { + fake.deserializeIdentityMutex.RLock() + defer fake.deserializeIdentityMutex.RUnlock() + argsForCall := fake.deserializeIdentityArgsForCall[i] + return argsForCall.arg1 +} + +func (fake *MSPManager) DeserializeIdentityReturns(result1 driver.MSPIdentity, result2 error) { + fake.deserializeIdentityMutex.Lock() + defer fake.deserializeIdentityMutex.Unlock() + fake.DeserializeIdentityStub = nil + fake.deserializeIdentityReturns = struct { + result1 driver.MSPIdentity + result2 error + }{result1, result2} +} + +func (fake *MSPManager) DeserializeIdentityReturnsOnCall(i int, result1 driver.MSPIdentity, result2 error) { + fake.deserializeIdentityMutex.Lock() + defer fake.deserializeIdentityMutex.Unlock() + fake.DeserializeIdentityStub = nil + if fake.deserializeIdentityReturnsOnCall == nil { + fake.deserializeIdentityReturnsOnCall = make(map[int]struct { + result1 driver.MSPIdentity + result2 error + }) + } + fake.deserializeIdentityReturnsOnCall[i] = struct { + result1 driver.MSPIdentity + result2 error + }{result1, result2} +} + +func (fake *MSPManager) Invocations() map[string][][]interface{} { + fake.invocationsMutex.RLock() + defer fake.invocationsMutex.RUnlock() + fake.deserializeIdentityMutex.RLock() + defer fake.deserializeIdentityMutex.RUnlock() + copiedInvocations := map[string][][]interface{}{} + for key, value := range fake.invocations { + copiedInvocations[key] = value + } + return copiedInvocations +} + +func (fake *MSPManager) 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) +} + +var _ chaincode.MSPManager = new(MSPManager) diff --git a/platform/fabric/core/generic/chaincode/mocks/network.go b/platform/fabric/core/generic/chaincode/mocks/network.go new file mode 100644 index 000000000..8801e4868 --- /dev/null +++ b/platform/fabric/core/generic/chaincode/mocks/network.go @@ -0,0 +1,451 @@ +// Code generated by counterfeiter. DO NOT EDIT. +package mocks + +import ( + "context" + "sync" + + "github.com/hyperledger-labs/fabric-smart-client/platform/fabric/core/generic/chaincode" + "github.com/hyperledger-labs/fabric-smart-client/platform/fabric/core/generic/config" + "github.com/hyperledger-labs/fabric-smart-client/platform/fabric/driver" + "github.com/hyperledger-labs/fabric-smart-client/platform/view/services/grpc" +) + +type Network struct { + BroadcastStub func(context.Context, interface{}) error + broadcastMutex sync.RWMutex + broadcastArgsForCall []struct { + arg1 context.Context + arg2 interface{} + } + broadcastReturns struct { + result1 error + } + broadcastReturnsOnCall map[int]struct { + result1 error + } + ConfigStub func() *config.Config + configMutex sync.RWMutex + configArgsForCall []struct { + } + configReturns struct { + result1 *config.Config + } + configReturnsOnCall map[int]struct { + result1 *config.Config + } + LocalMembershipStub func() driver.LocalMembership + localMembershipMutex sync.RWMutex + localMembershipArgsForCall []struct { + } + localMembershipReturns struct { + result1 driver.LocalMembership + } + localMembershipReturnsOnCall map[int]struct { + result1 driver.LocalMembership + } + NameStub func() string + nameMutex sync.RWMutex + nameArgsForCall []struct { + } + nameReturns struct { + result1 string + } + nameReturnsOnCall map[int]struct { + result1 string + } + PickPeerStub func(driver.PeerFunctionType) *grpc.ConnectionConfig + pickPeerMutex sync.RWMutex + pickPeerArgsForCall []struct { + arg1 driver.PeerFunctionType + } + pickPeerReturns struct { + result1 *grpc.ConnectionConfig + } + pickPeerReturnsOnCall map[int]struct { + result1 *grpc.ConnectionConfig + } + SignerServiceStub func() driver.SignerService + signerServiceMutex sync.RWMutex + signerServiceArgsForCall []struct { + } + signerServiceReturns struct { + result1 driver.SignerService + } + signerServiceReturnsOnCall map[int]struct { + result1 driver.SignerService + } + invocations map[string][][]interface{} + invocationsMutex sync.RWMutex +} + +func (fake *Network) Broadcast(arg1 context.Context, arg2 interface{}) error { + fake.broadcastMutex.Lock() + ret, specificReturn := fake.broadcastReturnsOnCall[len(fake.broadcastArgsForCall)] + fake.broadcastArgsForCall = append(fake.broadcastArgsForCall, struct { + arg1 context.Context + arg2 interface{} + }{arg1, arg2}) + stub := fake.BroadcastStub + fakeReturns := fake.broadcastReturns + fake.recordInvocation("Broadcast", []interface{}{arg1, arg2}) + fake.broadcastMutex.Unlock() + if stub != nil { + return stub(arg1, arg2) + } + if specificReturn { + return ret.result1 + } + return fakeReturns.result1 +} + +func (fake *Network) BroadcastCallCount() int { + fake.broadcastMutex.RLock() + defer fake.broadcastMutex.RUnlock() + return len(fake.broadcastArgsForCall) +} + +func (fake *Network) BroadcastCalls(stub func(context.Context, interface{}) error) { + fake.broadcastMutex.Lock() + defer fake.broadcastMutex.Unlock() + fake.BroadcastStub = stub +} + +func (fake *Network) BroadcastArgsForCall(i int) (context.Context, interface{}) { + fake.broadcastMutex.RLock() + defer fake.broadcastMutex.RUnlock() + argsForCall := fake.broadcastArgsForCall[i] + return argsForCall.arg1, argsForCall.arg2 +} + +func (fake *Network) BroadcastReturns(result1 error) { + fake.broadcastMutex.Lock() + defer fake.broadcastMutex.Unlock() + fake.BroadcastStub = nil + fake.broadcastReturns = struct { + result1 error + }{result1} +} + +func (fake *Network) BroadcastReturnsOnCall(i int, result1 error) { + fake.broadcastMutex.Lock() + defer fake.broadcastMutex.Unlock() + fake.BroadcastStub = nil + if fake.broadcastReturnsOnCall == nil { + fake.broadcastReturnsOnCall = make(map[int]struct { + result1 error + }) + } + fake.broadcastReturnsOnCall[i] = struct { + result1 error + }{result1} +} + +func (fake *Network) Config() *config.Config { + fake.configMutex.Lock() + ret, specificReturn := fake.configReturnsOnCall[len(fake.configArgsForCall)] + fake.configArgsForCall = append(fake.configArgsForCall, struct { + }{}) + stub := fake.ConfigStub + fakeReturns := fake.configReturns + fake.recordInvocation("Config", []interface{}{}) + fake.configMutex.Unlock() + if stub != nil { + return stub() + } + if specificReturn { + return ret.result1 + } + return fakeReturns.result1 +} + +func (fake *Network) ConfigCallCount() int { + fake.configMutex.RLock() + defer fake.configMutex.RUnlock() + return len(fake.configArgsForCall) +} + +func (fake *Network) ConfigCalls(stub func() *config.Config) { + fake.configMutex.Lock() + defer fake.configMutex.Unlock() + fake.ConfigStub = stub +} + +func (fake *Network) ConfigReturns(result1 *config.Config) { + fake.configMutex.Lock() + defer fake.configMutex.Unlock() + fake.ConfigStub = nil + fake.configReturns = struct { + result1 *config.Config + }{result1} +} + +func (fake *Network) ConfigReturnsOnCall(i int, result1 *config.Config) { + fake.configMutex.Lock() + defer fake.configMutex.Unlock() + fake.ConfigStub = nil + if fake.configReturnsOnCall == nil { + fake.configReturnsOnCall = make(map[int]struct { + result1 *config.Config + }) + } + fake.configReturnsOnCall[i] = struct { + result1 *config.Config + }{result1} +} + +func (fake *Network) LocalMembership() driver.LocalMembership { + fake.localMembershipMutex.Lock() + ret, specificReturn := fake.localMembershipReturnsOnCall[len(fake.localMembershipArgsForCall)] + fake.localMembershipArgsForCall = append(fake.localMembershipArgsForCall, struct { + }{}) + stub := fake.LocalMembershipStub + fakeReturns := fake.localMembershipReturns + fake.recordInvocation("LocalMembership", []interface{}{}) + fake.localMembershipMutex.Unlock() + if stub != nil { + return stub() + } + if specificReturn { + return ret.result1 + } + return fakeReturns.result1 +} + +func (fake *Network) LocalMembershipCallCount() int { + fake.localMembershipMutex.RLock() + defer fake.localMembershipMutex.RUnlock() + return len(fake.localMembershipArgsForCall) +} + +func (fake *Network) LocalMembershipCalls(stub func() driver.LocalMembership) { + fake.localMembershipMutex.Lock() + defer fake.localMembershipMutex.Unlock() + fake.LocalMembershipStub = stub +} + +func (fake *Network) LocalMembershipReturns(result1 driver.LocalMembership) { + fake.localMembershipMutex.Lock() + defer fake.localMembershipMutex.Unlock() + fake.LocalMembershipStub = nil + fake.localMembershipReturns = struct { + result1 driver.LocalMembership + }{result1} +} + +func (fake *Network) LocalMembershipReturnsOnCall(i int, result1 driver.LocalMembership) { + fake.localMembershipMutex.Lock() + defer fake.localMembershipMutex.Unlock() + fake.LocalMembershipStub = nil + if fake.localMembershipReturnsOnCall == nil { + fake.localMembershipReturnsOnCall = make(map[int]struct { + result1 driver.LocalMembership + }) + } + fake.localMembershipReturnsOnCall[i] = struct { + result1 driver.LocalMembership + }{result1} +} + +func (fake *Network) Name() string { + fake.nameMutex.Lock() + ret, specificReturn := fake.nameReturnsOnCall[len(fake.nameArgsForCall)] + fake.nameArgsForCall = append(fake.nameArgsForCall, struct { + }{}) + stub := fake.NameStub + fakeReturns := fake.nameReturns + fake.recordInvocation("Name", []interface{}{}) + fake.nameMutex.Unlock() + if stub != nil { + return stub() + } + if specificReturn { + return ret.result1 + } + return fakeReturns.result1 +} + +func (fake *Network) NameCallCount() int { + fake.nameMutex.RLock() + defer fake.nameMutex.RUnlock() + return len(fake.nameArgsForCall) +} + +func (fake *Network) NameCalls(stub func() string) { + fake.nameMutex.Lock() + defer fake.nameMutex.Unlock() + fake.NameStub = stub +} + +func (fake *Network) NameReturns(result1 string) { + fake.nameMutex.Lock() + defer fake.nameMutex.Unlock() + fake.NameStub = nil + fake.nameReturns = struct { + result1 string + }{result1} +} + +func (fake *Network) NameReturnsOnCall(i int, result1 string) { + fake.nameMutex.Lock() + defer fake.nameMutex.Unlock() + fake.NameStub = nil + if fake.nameReturnsOnCall == nil { + fake.nameReturnsOnCall = make(map[int]struct { + result1 string + }) + } + fake.nameReturnsOnCall[i] = struct { + result1 string + }{result1} +} + +func (fake *Network) PickPeer(arg1 driver.PeerFunctionType) *grpc.ConnectionConfig { + fake.pickPeerMutex.Lock() + ret, specificReturn := fake.pickPeerReturnsOnCall[len(fake.pickPeerArgsForCall)] + fake.pickPeerArgsForCall = append(fake.pickPeerArgsForCall, struct { + arg1 driver.PeerFunctionType + }{arg1}) + stub := fake.PickPeerStub + fakeReturns := fake.pickPeerReturns + fake.recordInvocation("PickPeer", []interface{}{arg1}) + fake.pickPeerMutex.Unlock() + if stub != nil { + return stub(arg1) + } + if specificReturn { + return ret.result1 + } + return fakeReturns.result1 +} + +func (fake *Network) PickPeerCallCount() int { + fake.pickPeerMutex.RLock() + defer fake.pickPeerMutex.RUnlock() + return len(fake.pickPeerArgsForCall) +} + +func (fake *Network) PickPeerCalls(stub func(driver.PeerFunctionType) *grpc.ConnectionConfig) { + fake.pickPeerMutex.Lock() + defer fake.pickPeerMutex.Unlock() + fake.PickPeerStub = stub +} + +func (fake *Network) PickPeerArgsForCall(i int) driver.PeerFunctionType { + fake.pickPeerMutex.RLock() + defer fake.pickPeerMutex.RUnlock() + argsForCall := fake.pickPeerArgsForCall[i] + return argsForCall.arg1 +} + +func (fake *Network) PickPeerReturns(result1 *grpc.ConnectionConfig) { + fake.pickPeerMutex.Lock() + defer fake.pickPeerMutex.Unlock() + fake.PickPeerStub = nil + fake.pickPeerReturns = struct { + result1 *grpc.ConnectionConfig + }{result1} +} + +func (fake *Network) PickPeerReturnsOnCall(i int, result1 *grpc.ConnectionConfig) { + fake.pickPeerMutex.Lock() + defer fake.pickPeerMutex.Unlock() + fake.PickPeerStub = nil + if fake.pickPeerReturnsOnCall == nil { + fake.pickPeerReturnsOnCall = make(map[int]struct { + result1 *grpc.ConnectionConfig + }) + } + fake.pickPeerReturnsOnCall[i] = struct { + result1 *grpc.ConnectionConfig + }{result1} +} + +func (fake *Network) SignerService() driver.SignerService { + fake.signerServiceMutex.Lock() + ret, specificReturn := fake.signerServiceReturnsOnCall[len(fake.signerServiceArgsForCall)] + fake.signerServiceArgsForCall = append(fake.signerServiceArgsForCall, struct { + }{}) + stub := fake.SignerServiceStub + fakeReturns := fake.signerServiceReturns + fake.recordInvocation("SignerService", []interface{}{}) + fake.signerServiceMutex.Unlock() + if stub != nil { + return stub() + } + if specificReturn { + return ret.result1 + } + return fakeReturns.result1 +} + +func (fake *Network) SignerServiceCallCount() int { + fake.signerServiceMutex.RLock() + defer fake.signerServiceMutex.RUnlock() + return len(fake.signerServiceArgsForCall) +} + +func (fake *Network) SignerServiceCalls(stub func() driver.SignerService) { + fake.signerServiceMutex.Lock() + defer fake.signerServiceMutex.Unlock() + fake.SignerServiceStub = stub +} + +func (fake *Network) SignerServiceReturns(result1 driver.SignerService) { + fake.signerServiceMutex.Lock() + defer fake.signerServiceMutex.Unlock() + fake.SignerServiceStub = nil + fake.signerServiceReturns = struct { + result1 driver.SignerService + }{result1} +} + +func (fake *Network) SignerServiceReturnsOnCall(i int, result1 driver.SignerService) { + fake.signerServiceMutex.Lock() + defer fake.signerServiceMutex.Unlock() + fake.SignerServiceStub = nil + if fake.signerServiceReturnsOnCall == nil { + fake.signerServiceReturnsOnCall = make(map[int]struct { + result1 driver.SignerService + }) + } + fake.signerServiceReturnsOnCall[i] = struct { + result1 driver.SignerService + }{result1} +} + +func (fake *Network) Invocations() map[string][][]interface{} { + fake.invocationsMutex.RLock() + defer fake.invocationsMutex.RUnlock() + fake.broadcastMutex.RLock() + defer fake.broadcastMutex.RUnlock() + fake.configMutex.RLock() + defer fake.configMutex.RUnlock() + fake.localMembershipMutex.RLock() + defer fake.localMembershipMutex.RUnlock() + fake.nameMutex.RLock() + defer fake.nameMutex.RUnlock() + fake.pickPeerMutex.RLock() + defer fake.pickPeerMutex.RUnlock() + fake.signerServiceMutex.RLock() + defer fake.signerServiceMutex.RUnlock() + copiedInvocations := map[string][][]interface{}{} + for key, value := range fake.invocations { + copiedInvocations[key] = value + } + return copiedInvocations +} + +func (fake *Network) 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) +} + +var _ chaincode.Network = new(Network) diff --git a/platform/fabric/core/generic/chaincode/mocks/pc.go b/platform/fabric/core/generic/chaincode/mocks/pc.go new file mode 100644 index 000000000..54c5ee181 --- /dev/null +++ b/platform/fabric/core/generic/chaincode/mocks/pc.go @@ -0,0 +1,552 @@ +// Code generated by counterfeiter. DO NOT EDIT. +package mocks + +import ( + "crypto/tls" + "sync" + + "github.com/hyperledger-labs/fabric-smart-client/platform/fabric/core/generic/chaincode" + peera "github.com/hyperledger-labs/fabric-smart-client/platform/fabric/core/generic/peer" + "github.com/hyperledger/fabric-protos-go/discovery" + "github.com/hyperledger/fabric-protos-go/peer" + "google.golang.org/grpc" +) + +type PeerClient struct { + AddressStub func() string + addressMutex sync.RWMutex + addressArgsForCall []struct { + } + addressReturns struct { + result1 string + } + addressReturnsOnCall map[int]struct { + result1 string + } + CertificateStub func() tls.Certificate + certificateMutex sync.RWMutex + certificateArgsForCall []struct { + } + certificateReturns struct { + result1 tls.Certificate + } + certificateReturnsOnCall map[int]struct { + result1 tls.Certificate + } + CloseStub func() + closeMutex sync.RWMutex + closeArgsForCall []struct { + } + ConnectionStub func() (*grpc.ClientConn, error) + connectionMutex sync.RWMutex + connectionArgsForCall []struct { + } + connectionReturns struct { + result1 *grpc.ClientConn + result2 error + } + connectionReturnsOnCall map[int]struct { + result1 *grpc.ClientConn + result2 error + } + DeliverClientStub func() (peer.DeliverClient, error) + deliverClientMutex sync.RWMutex + deliverClientArgsForCall []struct { + } + deliverClientReturns struct { + result1 peer.DeliverClient + result2 error + } + deliverClientReturnsOnCall map[int]struct { + result1 peer.DeliverClient + result2 error + } + DiscoveryStub func() (discovery.DiscoveryClient, error) + discoveryMutex sync.RWMutex + discoveryArgsForCall []struct { + } + discoveryReturns struct { + result1 discovery.DiscoveryClient + result2 error + } + discoveryReturnsOnCall map[int]struct { + result1 discovery.DiscoveryClient + result2 error + } + DiscoveryClientStub func() (peera.DiscoveryClient, error) + discoveryClientMutex sync.RWMutex + discoveryClientArgsForCall []struct { + } + discoveryClientReturns struct { + result1 peera.DiscoveryClient + result2 error + } + discoveryClientReturnsOnCall map[int]struct { + result1 peera.DiscoveryClient + result2 error + } + EndorserStub func() (peer.EndorserClient, error) + endorserMutex sync.RWMutex + endorserArgsForCall []struct { + } + endorserReturns struct { + result1 peer.EndorserClient + result2 error + } + endorserReturnsOnCall map[int]struct { + result1 peer.EndorserClient + result2 error + } + invocations map[string][][]interface{} + invocationsMutex sync.RWMutex +} + +func (fake *PeerClient) Address() string { + fake.addressMutex.Lock() + ret, specificReturn := fake.addressReturnsOnCall[len(fake.addressArgsForCall)] + fake.addressArgsForCall = append(fake.addressArgsForCall, struct { + }{}) + stub := fake.AddressStub + fakeReturns := fake.addressReturns + fake.recordInvocation("Address", []interface{}{}) + fake.addressMutex.Unlock() + if stub != nil { + return stub() + } + if specificReturn { + return ret.result1 + } + return fakeReturns.result1 +} + +func (fake *PeerClient) AddressCallCount() int { + fake.addressMutex.RLock() + defer fake.addressMutex.RUnlock() + return len(fake.addressArgsForCall) +} + +func (fake *PeerClient) AddressCalls(stub func() string) { + fake.addressMutex.Lock() + defer fake.addressMutex.Unlock() + fake.AddressStub = stub +} + +func (fake *PeerClient) AddressReturns(result1 string) { + fake.addressMutex.Lock() + defer fake.addressMutex.Unlock() + fake.AddressStub = nil + fake.addressReturns = struct { + result1 string + }{result1} +} + +func (fake *PeerClient) AddressReturnsOnCall(i int, result1 string) { + fake.addressMutex.Lock() + defer fake.addressMutex.Unlock() + fake.AddressStub = nil + if fake.addressReturnsOnCall == nil { + fake.addressReturnsOnCall = make(map[int]struct { + result1 string + }) + } + fake.addressReturnsOnCall[i] = struct { + result1 string + }{result1} +} + +func (fake *PeerClient) Certificate() tls.Certificate { + fake.certificateMutex.Lock() + ret, specificReturn := fake.certificateReturnsOnCall[len(fake.certificateArgsForCall)] + fake.certificateArgsForCall = append(fake.certificateArgsForCall, struct { + }{}) + stub := fake.CertificateStub + fakeReturns := fake.certificateReturns + fake.recordInvocation("Certificate", []interface{}{}) + fake.certificateMutex.Unlock() + if stub != nil { + return stub() + } + if specificReturn { + return ret.result1 + } + return fakeReturns.result1 +} + +func (fake *PeerClient) CertificateCallCount() int { + fake.certificateMutex.RLock() + defer fake.certificateMutex.RUnlock() + return len(fake.certificateArgsForCall) +} + +func (fake *PeerClient) CertificateCalls(stub func() tls.Certificate) { + fake.certificateMutex.Lock() + defer fake.certificateMutex.Unlock() + fake.CertificateStub = stub +} + +func (fake *PeerClient) CertificateReturns(result1 tls.Certificate) { + fake.certificateMutex.Lock() + defer fake.certificateMutex.Unlock() + fake.CertificateStub = nil + fake.certificateReturns = struct { + result1 tls.Certificate + }{result1} +} + +func (fake *PeerClient) CertificateReturnsOnCall(i int, result1 tls.Certificate) { + fake.certificateMutex.Lock() + defer fake.certificateMutex.Unlock() + fake.CertificateStub = nil + if fake.certificateReturnsOnCall == nil { + fake.certificateReturnsOnCall = make(map[int]struct { + result1 tls.Certificate + }) + } + fake.certificateReturnsOnCall[i] = struct { + result1 tls.Certificate + }{result1} +} + +func (fake *PeerClient) Close() { + fake.closeMutex.Lock() + fake.closeArgsForCall = append(fake.closeArgsForCall, struct { + }{}) + stub := fake.CloseStub + fake.recordInvocation("Close", []interface{}{}) + fake.closeMutex.Unlock() + if stub != nil { + fake.CloseStub() + } +} + +func (fake *PeerClient) CloseCallCount() int { + fake.closeMutex.RLock() + defer fake.closeMutex.RUnlock() + return len(fake.closeArgsForCall) +} + +func (fake *PeerClient) CloseCalls(stub func()) { + fake.closeMutex.Lock() + defer fake.closeMutex.Unlock() + fake.CloseStub = stub +} + +func (fake *PeerClient) Connection() (*grpc.ClientConn, error) { + fake.connectionMutex.Lock() + ret, specificReturn := fake.connectionReturnsOnCall[len(fake.connectionArgsForCall)] + fake.connectionArgsForCall = append(fake.connectionArgsForCall, struct { + }{}) + stub := fake.ConnectionStub + fakeReturns := fake.connectionReturns + fake.recordInvocation("Connection", []interface{}{}) + fake.connectionMutex.Unlock() + if stub != nil { + return stub() + } + if specificReturn { + return ret.result1, ret.result2 + } + return fakeReturns.result1, fakeReturns.result2 +} + +func (fake *PeerClient) ConnectionCallCount() int { + fake.connectionMutex.RLock() + defer fake.connectionMutex.RUnlock() + return len(fake.connectionArgsForCall) +} + +func (fake *PeerClient) ConnectionCalls(stub func() (*grpc.ClientConn, error)) { + fake.connectionMutex.Lock() + defer fake.connectionMutex.Unlock() + fake.ConnectionStub = stub +} + +func (fake *PeerClient) ConnectionReturns(result1 *grpc.ClientConn, result2 error) { + fake.connectionMutex.Lock() + defer fake.connectionMutex.Unlock() + fake.ConnectionStub = nil + fake.connectionReturns = struct { + result1 *grpc.ClientConn + result2 error + }{result1, result2} +} + +func (fake *PeerClient) ConnectionReturnsOnCall(i int, result1 *grpc.ClientConn, result2 error) { + fake.connectionMutex.Lock() + defer fake.connectionMutex.Unlock() + fake.ConnectionStub = nil + if fake.connectionReturnsOnCall == nil { + fake.connectionReturnsOnCall = make(map[int]struct { + result1 *grpc.ClientConn + result2 error + }) + } + fake.connectionReturnsOnCall[i] = struct { + result1 *grpc.ClientConn + result2 error + }{result1, result2} +} + +func (fake *PeerClient) DeliverClient() (peer.DeliverClient, error) { + fake.deliverClientMutex.Lock() + ret, specificReturn := fake.deliverClientReturnsOnCall[len(fake.deliverClientArgsForCall)] + fake.deliverClientArgsForCall = append(fake.deliverClientArgsForCall, struct { + }{}) + stub := fake.DeliverClientStub + fakeReturns := fake.deliverClientReturns + fake.recordInvocation("DeliverClient", []interface{}{}) + fake.deliverClientMutex.Unlock() + if stub != nil { + return stub() + } + if specificReturn { + return ret.result1, ret.result2 + } + return fakeReturns.result1, fakeReturns.result2 +} + +func (fake *PeerClient) DeliverClientCallCount() int { + fake.deliverClientMutex.RLock() + defer fake.deliverClientMutex.RUnlock() + return len(fake.deliverClientArgsForCall) +} + +func (fake *PeerClient) DeliverClientCalls(stub func() (peer.DeliverClient, error)) { + fake.deliverClientMutex.Lock() + defer fake.deliverClientMutex.Unlock() + fake.DeliverClientStub = stub +} + +func (fake *PeerClient) DeliverClientReturns(result1 peer.DeliverClient, result2 error) { + fake.deliverClientMutex.Lock() + defer fake.deliverClientMutex.Unlock() + fake.DeliverClientStub = nil + fake.deliverClientReturns = struct { + result1 peer.DeliverClient + result2 error + }{result1, result2} +} + +func (fake *PeerClient) DeliverClientReturnsOnCall(i int, result1 peer.DeliverClient, result2 error) { + fake.deliverClientMutex.Lock() + defer fake.deliverClientMutex.Unlock() + fake.DeliverClientStub = nil + if fake.deliverClientReturnsOnCall == nil { + fake.deliverClientReturnsOnCall = make(map[int]struct { + result1 peer.DeliverClient + result2 error + }) + } + fake.deliverClientReturnsOnCall[i] = struct { + result1 peer.DeliverClient + result2 error + }{result1, result2} +} + +func (fake *PeerClient) Discovery() (discovery.DiscoveryClient, error) { + fake.discoveryMutex.Lock() + ret, specificReturn := fake.discoveryReturnsOnCall[len(fake.discoveryArgsForCall)] + fake.discoveryArgsForCall = append(fake.discoveryArgsForCall, struct { + }{}) + stub := fake.DiscoveryStub + fakeReturns := fake.discoveryReturns + fake.recordInvocation("Discovery", []interface{}{}) + fake.discoveryMutex.Unlock() + if stub != nil { + return stub() + } + if specificReturn { + return ret.result1, ret.result2 + } + return fakeReturns.result1, fakeReturns.result2 +} + +func (fake *PeerClient) DiscoveryCallCount() int { + fake.discoveryMutex.RLock() + defer fake.discoveryMutex.RUnlock() + return len(fake.discoveryArgsForCall) +} + +func (fake *PeerClient) DiscoveryCalls(stub func() (discovery.DiscoveryClient, error)) { + fake.discoveryMutex.Lock() + defer fake.discoveryMutex.Unlock() + fake.DiscoveryStub = stub +} + +func (fake *PeerClient) DiscoveryReturns(result1 discovery.DiscoveryClient, result2 error) { + fake.discoveryMutex.Lock() + defer fake.discoveryMutex.Unlock() + fake.DiscoveryStub = nil + fake.discoveryReturns = struct { + result1 discovery.DiscoveryClient + result2 error + }{result1, result2} +} + +func (fake *PeerClient) DiscoveryReturnsOnCall(i int, result1 discovery.DiscoveryClient, result2 error) { + fake.discoveryMutex.Lock() + defer fake.discoveryMutex.Unlock() + fake.DiscoveryStub = nil + if fake.discoveryReturnsOnCall == nil { + fake.discoveryReturnsOnCall = make(map[int]struct { + result1 discovery.DiscoveryClient + result2 error + }) + } + fake.discoveryReturnsOnCall[i] = struct { + result1 discovery.DiscoveryClient + result2 error + }{result1, result2} +} + +func (fake *PeerClient) DiscoveryClient() (peera.DiscoveryClient, error) { + fake.discoveryClientMutex.Lock() + ret, specificReturn := fake.discoveryClientReturnsOnCall[len(fake.discoveryClientArgsForCall)] + fake.discoveryClientArgsForCall = append(fake.discoveryClientArgsForCall, struct { + }{}) + stub := fake.DiscoveryClientStub + fakeReturns := fake.discoveryClientReturns + fake.recordInvocation("DiscoveryClient", []interface{}{}) + fake.discoveryClientMutex.Unlock() + if stub != nil { + return stub() + } + if specificReturn { + return ret.result1, ret.result2 + } + return fakeReturns.result1, fakeReturns.result2 +} + +func (fake *PeerClient) DiscoveryClientCallCount() int { + fake.discoveryClientMutex.RLock() + defer fake.discoveryClientMutex.RUnlock() + return len(fake.discoveryClientArgsForCall) +} + +func (fake *PeerClient) DiscoveryClientCalls(stub func() (peera.DiscoveryClient, error)) { + fake.discoveryClientMutex.Lock() + defer fake.discoveryClientMutex.Unlock() + fake.DiscoveryClientStub = stub +} + +func (fake *PeerClient) DiscoveryClientReturns(result1 peera.DiscoveryClient, result2 error) { + fake.discoveryClientMutex.Lock() + defer fake.discoveryClientMutex.Unlock() + fake.DiscoveryClientStub = nil + fake.discoveryClientReturns = struct { + result1 peera.DiscoveryClient + result2 error + }{result1, result2} +} + +func (fake *PeerClient) DiscoveryClientReturnsOnCall(i int, result1 peera.DiscoveryClient, result2 error) { + fake.discoveryClientMutex.Lock() + defer fake.discoveryClientMutex.Unlock() + fake.DiscoveryClientStub = nil + if fake.discoveryClientReturnsOnCall == nil { + fake.discoveryClientReturnsOnCall = make(map[int]struct { + result1 peera.DiscoveryClient + result2 error + }) + } + fake.discoveryClientReturnsOnCall[i] = struct { + result1 peera.DiscoveryClient + result2 error + }{result1, result2} +} + +func (fake *PeerClient) Endorser() (peer.EndorserClient, error) { + fake.endorserMutex.Lock() + ret, specificReturn := fake.endorserReturnsOnCall[len(fake.endorserArgsForCall)] + fake.endorserArgsForCall = append(fake.endorserArgsForCall, struct { + }{}) + stub := fake.EndorserStub + fakeReturns := fake.endorserReturns + fake.recordInvocation("Endorser", []interface{}{}) + fake.endorserMutex.Unlock() + if stub != nil { + return stub() + } + if specificReturn { + return ret.result1, ret.result2 + } + return fakeReturns.result1, fakeReturns.result2 +} + +func (fake *PeerClient) EndorserCallCount() int { + fake.endorserMutex.RLock() + defer fake.endorserMutex.RUnlock() + return len(fake.endorserArgsForCall) +} + +func (fake *PeerClient) EndorserCalls(stub func() (peer.EndorserClient, error)) { + fake.endorserMutex.Lock() + defer fake.endorserMutex.Unlock() + fake.EndorserStub = stub +} + +func (fake *PeerClient) EndorserReturns(result1 peer.EndorserClient, result2 error) { + fake.endorserMutex.Lock() + defer fake.endorserMutex.Unlock() + fake.EndorserStub = nil + fake.endorserReturns = struct { + result1 peer.EndorserClient + result2 error + }{result1, result2} +} + +func (fake *PeerClient) EndorserReturnsOnCall(i int, result1 peer.EndorserClient, result2 error) { + fake.endorserMutex.Lock() + defer fake.endorserMutex.Unlock() + fake.EndorserStub = nil + if fake.endorserReturnsOnCall == nil { + fake.endorserReturnsOnCall = make(map[int]struct { + result1 peer.EndorserClient + result2 error + }) + } + fake.endorserReturnsOnCall[i] = struct { + result1 peer.EndorserClient + result2 error + }{result1, result2} +} + +func (fake *PeerClient) Invocations() map[string][][]interface{} { + fake.invocationsMutex.RLock() + defer fake.invocationsMutex.RUnlock() + fake.addressMutex.RLock() + defer fake.addressMutex.RUnlock() + fake.certificateMutex.RLock() + defer fake.certificateMutex.RUnlock() + fake.closeMutex.RLock() + defer fake.closeMutex.RUnlock() + fake.connectionMutex.RLock() + defer fake.connectionMutex.RUnlock() + fake.deliverClientMutex.RLock() + defer fake.deliverClientMutex.RUnlock() + fake.discoveryMutex.RLock() + defer fake.discoveryMutex.RUnlock() + fake.discoveryClientMutex.RLock() + defer fake.discoveryClientMutex.RUnlock() + fake.endorserMutex.RLock() + defer fake.endorserMutex.RUnlock() + copiedInvocations := map[string][][]interface{}{} + for key, value := range fake.invocations { + copiedInvocations[key] = value + } + return copiedInvocations +} + +func (fake *PeerClient) 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) +} + +var _ chaincode.PeerClient = new(PeerClient) diff --git a/platform/fabric/core/generic/chaincode/mocks/sc.go b/platform/fabric/core/generic/chaincode/mocks/sc.go new file mode 100644 index 000000000..983243753 --- /dev/null +++ b/platform/fabric/core/generic/chaincode/mocks/sc.go @@ -0,0 +1,275 @@ +// Code generated by counterfeiter. DO NOT EDIT. +package mocks + +import ( + "sync" + + "github.com/hyperledger-labs/fabric-smart-client/platform/fabric/core/generic/chaincode" + "github.com/hyperledger-labs/fabric-smart-client/platform/fabric/driver" + "github.com/hyperledger-labs/fabric-smart-client/platform/view/view" +) + +type SignerService struct { + GetSignerStub func(view.Identity) (driver.Signer, error) + getSignerMutex sync.RWMutex + getSignerArgsForCall []struct { + arg1 view.Identity + } + getSignerReturns struct { + result1 driver.Signer + result2 error + } + getSignerReturnsOnCall map[int]struct { + result1 driver.Signer + result2 error + } + GetSigningIdentityStub func(view.Identity) (driver.SigningIdentity, error) + getSigningIdentityMutex sync.RWMutex + getSigningIdentityArgsForCall []struct { + arg1 view.Identity + } + getSigningIdentityReturns struct { + result1 driver.SigningIdentity + result2 error + } + getSigningIdentityReturnsOnCall map[int]struct { + result1 driver.SigningIdentity + result2 error + } + RegisterSignerStub func(view.Identity, driver.Signer, driver.Verifier) error + registerSignerMutex sync.RWMutex + registerSignerArgsForCall []struct { + arg1 view.Identity + arg2 driver.Signer + arg3 driver.Verifier + } + registerSignerReturns struct { + result1 error + } + registerSignerReturnsOnCall map[int]struct { + result1 error + } + invocations map[string][][]interface{} + invocationsMutex sync.RWMutex +} + +func (fake *SignerService) GetSigner(arg1 view.Identity) (driver.Signer, error) { + fake.getSignerMutex.Lock() + ret, specificReturn := fake.getSignerReturnsOnCall[len(fake.getSignerArgsForCall)] + fake.getSignerArgsForCall = append(fake.getSignerArgsForCall, struct { + arg1 view.Identity + }{arg1}) + stub := fake.GetSignerStub + fakeReturns := fake.getSignerReturns + fake.recordInvocation("GetSigner", []interface{}{arg1}) + fake.getSignerMutex.Unlock() + if stub != nil { + return stub(arg1) + } + if specificReturn { + return ret.result1, ret.result2 + } + return fakeReturns.result1, fakeReturns.result2 +} + +func (fake *SignerService) GetSignerCallCount() int { + fake.getSignerMutex.RLock() + defer fake.getSignerMutex.RUnlock() + return len(fake.getSignerArgsForCall) +} + +func (fake *SignerService) GetSignerCalls(stub func(view.Identity) (driver.Signer, error)) { + fake.getSignerMutex.Lock() + defer fake.getSignerMutex.Unlock() + fake.GetSignerStub = stub +} + +func (fake *SignerService) GetSignerArgsForCall(i int) view.Identity { + fake.getSignerMutex.RLock() + defer fake.getSignerMutex.RUnlock() + argsForCall := fake.getSignerArgsForCall[i] + return argsForCall.arg1 +} + +func (fake *SignerService) GetSignerReturns(result1 driver.Signer, result2 error) { + fake.getSignerMutex.Lock() + defer fake.getSignerMutex.Unlock() + fake.GetSignerStub = nil + fake.getSignerReturns = struct { + result1 driver.Signer + result2 error + }{result1, result2} +} + +func (fake *SignerService) GetSignerReturnsOnCall(i int, result1 driver.Signer, result2 error) { + fake.getSignerMutex.Lock() + defer fake.getSignerMutex.Unlock() + fake.GetSignerStub = nil + if fake.getSignerReturnsOnCall == nil { + fake.getSignerReturnsOnCall = make(map[int]struct { + result1 driver.Signer + result2 error + }) + } + fake.getSignerReturnsOnCall[i] = struct { + result1 driver.Signer + result2 error + }{result1, result2} +} + +func (fake *SignerService) GetSigningIdentity(arg1 view.Identity) (driver.SigningIdentity, error) { + fake.getSigningIdentityMutex.Lock() + ret, specificReturn := fake.getSigningIdentityReturnsOnCall[len(fake.getSigningIdentityArgsForCall)] + fake.getSigningIdentityArgsForCall = append(fake.getSigningIdentityArgsForCall, struct { + arg1 view.Identity + }{arg1}) + stub := fake.GetSigningIdentityStub + fakeReturns := fake.getSigningIdentityReturns + fake.recordInvocation("GetSigningIdentity", []interface{}{arg1}) + fake.getSigningIdentityMutex.Unlock() + if stub != nil { + return stub(arg1) + } + if specificReturn { + return ret.result1, ret.result2 + } + return fakeReturns.result1, fakeReturns.result2 +} + +func (fake *SignerService) GetSigningIdentityCallCount() int { + fake.getSigningIdentityMutex.RLock() + defer fake.getSigningIdentityMutex.RUnlock() + return len(fake.getSigningIdentityArgsForCall) +} + +func (fake *SignerService) GetSigningIdentityCalls(stub func(view.Identity) (driver.SigningIdentity, error)) { + fake.getSigningIdentityMutex.Lock() + defer fake.getSigningIdentityMutex.Unlock() + fake.GetSigningIdentityStub = stub +} + +func (fake *SignerService) GetSigningIdentityArgsForCall(i int) view.Identity { + fake.getSigningIdentityMutex.RLock() + defer fake.getSigningIdentityMutex.RUnlock() + argsForCall := fake.getSigningIdentityArgsForCall[i] + return argsForCall.arg1 +} + +func (fake *SignerService) GetSigningIdentityReturns(result1 driver.SigningIdentity, result2 error) { + fake.getSigningIdentityMutex.Lock() + defer fake.getSigningIdentityMutex.Unlock() + fake.GetSigningIdentityStub = nil + fake.getSigningIdentityReturns = struct { + result1 driver.SigningIdentity + result2 error + }{result1, result2} +} + +func (fake *SignerService) GetSigningIdentityReturnsOnCall(i int, result1 driver.SigningIdentity, result2 error) { + fake.getSigningIdentityMutex.Lock() + defer fake.getSigningIdentityMutex.Unlock() + fake.GetSigningIdentityStub = nil + if fake.getSigningIdentityReturnsOnCall == nil { + fake.getSigningIdentityReturnsOnCall = make(map[int]struct { + result1 driver.SigningIdentity + result2 error + }) + } + fake.getSigningIdentityReturnsOnCall[i] = struct { + result1 driver.SigningIdentity + result2 error + }{result1, result2} +} + +func (fake *SignerService) RegisterSigner(arg1 view.Identity, arg2 driver.Signer, arg3 driver.Verifier) error { + fake.registerSignerMutex.Lock() + ret, specificReturn := fake.registerSignerReturnsOnCall[len(fake.registerSignerArgsForCall)] + fake.registerSignerArgsForCall = append(fake.registerSignerArgsForCall, struct { + arg1 view.Identity + arg2 driver.Signer + arg3 driver.Verifier + }{arg1, arg2, arg3}) + stub := fake.RegisterSignerStub + fakeReturns := fake.registerSignerReturns + fake.recordInvocation("RegisterSigner", []interface{}{arg1, arg2, arg3}) + fake.registerSignerMutex.Unlock() + if stub != nil { + return stub(arg1, arg2, arg3) + } + if specificReturn { + return ret.result1 + } + return fakeReturns.result1 +} + +func (fake *SignerService) RegisterSignerCallCount() int { + fake.registerSignerMutex.RLock() + defer fake.registerSignerMutex.RUnlock() + return len(fake.registerSignerArgsForCall) +} + +func (fake *SignerService) RegisterSignerCalls(stub func(view.Identity, driver.Signer, driver.Verifier) error) { + fake.registerSignerMutex.Lock() + defer fake.registerSignerMutex.Unlock() + fake.RegisterSignerStub = stub +} + +func (fake *SignerService) RegisterSignerArgsForCall(i int) (view.Identity, driver.Signer, driver.Verifier) { + fake.registerSignerMutex.RLock() + defer fake.registerSignerMutex.RUnlock() + argsForCall := fake.registerSignerArgsForCall[i] + return argsForCall.arg1, argsForCall.arg2, argsForCall.arg3 +} + +func (fake *SignerService) RegisterSignerReturns(result1 error) { + fake.registerSignerMutex.Lock() + defer fake.registerSignerMutex.Unlock() + fake.RegisterSignerStub = nil + fake.registerSignerReturns = struct { + result1 error + }{result1} +} + +func (fake *SignerService) RegisterSignerReturnsOnCall(i int, result1 error) { + fake.registerSignerMutex.Lock() + defer fake.registerSignerMutex.Unlock() + fake.RegisterSignerStub = nil + if fake.registerSignerReturnsOnCall == nil { + fake.registerSignerReturnsOnCall = make(map[int]struct { + result1 error + }) + } + fake.registerSignerReturnsOnCall[i] = struct { + result1 error + }{result1} +} + +func (fake *SignerService) Invocations() map[string][][]interface{} { + fake.invocationsMutex.RLock() + defer fake.invocationsMutex.RUnlock() + fake.getSignerMutex.RLock() + defer fake.getSignerMutex.RUnlock() + fake.getSigningIdentityMutex.RLock() + defer fake.getSigningIdentityMutex.RUnlock() + fake.registerSignerMutex.RLock() + defer fake.registerSignerMutex.RUnlock() + copiedInvocations := map[string][][]interface{}{} + for key, value := range fake.invocations { + copiedInvocations[key] = value + } + return copiedInvocations +} + +func (fake *SignerService) 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) +} + +var _ chaincode.SignerService = new(SignerService) diff --git a/platform/fabric/core/generic/chaincode/mocks/sersig.go b/platform/fabric/core/generic/chaincode/mocks/sersig.go new file mode 100644 index 000000000..392aa49bf --- /dev/null +++ b/platform/fabric/core/generic/chaincode/mocks/sersig.go @@ -0,0 +1,191 @@ +// Code generated by counterfeiter. DO NOT EDIT. +package mocks + +import ( + "sync" + + "github.com/hyperledger-labs/fabric-smart-client/platform/fabric/core/generic/chaincode" +) + +type SerializableSigner 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 *SerializableSigner) Serialize() ([]byte, error) { + fake.serializeMutex.Lock() + ret, specificReturn := fake.serializeReturnsOnCall[len(fake.serializeArgsForCall)] + fake.serializeArgsForCall = append(fake.serializeArgsForCall, struct { + }{}) + stub := fake.SerializeStub + fakeReturns := fake.serializeReturns + fake.recordInvocation("Serialize", []interface{}{}) + fake.serializeMutex.Unlock() + if stub != nil { + return stub() + } + if specificReturn { + return ret.result1, ret.result2 + } + return fakeReturns.result1, fakeReturns.result2 +} + +func (fake *SerializableSigner) SerializeCallCount() int { + fake.serializeMutex.RLock() + defer fake.serializeMutex.RUnlock() + return len(fake.serializeArgsForCall) +} + +func (fake *SerializableSigner) SerializeCalls(stub func() ([]byte, error)) { + fake.serializeMutex.Lock() + defer fake.serializeMutex.Unlock() + fake.SerializeStub = stub +} + +func (fake *SerializableSigner) 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 *SerializableSigner) 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 *SerializableSigner) 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}) + stub := fake.SignStub + fakeReturns := fake.signReturns + fake.recordInvocation("Sign", []interface{}{arg1Copy}) + fake.signMutex.Unlock() + if stub != nil { + return stub(arg1) + } + if specificReturn { + return ret.result1, ret.result2 + } + return fakeReturns.result1, fakeReturns.result2 +} + +func (fake *SerializableSigner) SignCallCount() int { + fake.signMutex.RLock() + defer fake.signMutex.RUnlock() + return len(fake.signArgsForCall) +} + +func (fake *SerializableSigner) SignCalls(stub func([]byte) ([]byte, error)) { + fake.signMutex.Lock() + defer fake.signMutex.Unlock() + fake.SignStub = stub +} + +func (fake *SerializableSigner) SignArgsForCall(i int) []byte { + fake.signMutex.RLock() + defer fake.signMutex.RUnlock() + argsForCall := fake.signArgsForCall[i] + return argsForCall.arg1 +} + +func (fake *SerializableSigner) 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 *SerializableSigner) 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 *SerializableSigner) 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 *SerializableSigner) 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) +} + +var _ chaincode.SerializableSigner = new(SerializableSigner) diff --git a/platform/fabric/core/generic/chaincode/mocks/si.go b/platform/fabric/core/generic/chaincode/mocks/si.go new file mode 100644 index 000000000..be77c3373 --- /dev/null +++ b/platform/fabric/core/generic/chaincode/mocks/si.go @@ -0,0 +1,191 @@ +// Code generated by counterfeiter. DO NOT EDIT. +package mocks + +import ( + "sync" + + "github.com/hyperledger-labs/fabric-smart-client/platform/fabric/core/generic/chaincode" +) + +type SigningIdentity 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 *SigningIdentity) Serialize() ([]byte, error) { + fake.serializeMutex.Lock() + ret, specificReturn := fake.serializeReturnsOnCall[len(fake.serializeArgsForCall)] + fake.serializeArgsForCall = append(fake.serializeArgsForCall, struct { + }{}) + stub := fake.SerializeStub + fakeReturns := fake.serializeReturns + fake.recordInvocation("Serialize", []interface{}{}) + fake.serializeMutex.Unlock() + if stub != nil { + return stub() + } + if specificReturn { + return ret.result1, ret.result2 + } + 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}) + stub := fake.SignStub + fakeReturns := fake.signReturns + fake.recordInvocation("Sign", []interface{}{arg1Copy}) + fake.signMutex.Unlock() + if stub != nil { + return stub(arg1) + } + if specificReturn { + return ret.result1, ret.result2 + } + 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) 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 *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) +} + +var _ chaincode.SigningIdentity = new(SigningIdentity) diff --git a/platform/fabric/core/generic/chaincode/mocks/sp.go b/platform/fabric/core/generic/chaincode/mocks/sp.go new file mode 100644 index 000000000..7a1443ad7 --- /dev/null +++ b/platform/fabric/core/generic/chaincode/mocks/sp.go @@ -0,0 +1,118 @@ +// Code generated by counterfeiter. DO NOT EDIT. +package mocks + +import ( + "sync" + + "github.com/hyperledger-labs/fabric-smart-client/platform/fabric/core/generic/chaincode" + "github.com/hyperledger-labs/fabric-smart-client/platform/view" + viewa "github.com/hyperledger-labs/fabric-smart-client/platform/view/view" +) + +type SignerProvider struct { + GetSigningIdentityStub func(viewa.Identity) (*view.SigningIdentity, error) + getSigningIdentityMutex sync.RWMutex + getSigningIdentityArgsForCall []struct { + arg1 viewa.Identity + } + getSigningIdentityReturns struct { + result1 *view.SigningIdentity + result2 error + } + getSigningIdentityReturnsOnCall map[int]struct { + result1 *view.SigningIdentity + result2 error + } + invocations map[string][][]interface{} + invocationsMutex sync.RWMutex +} + +func (fake *SignerProvider) GetSigningIdentity(arg1 viewa.Identity) (*view.SigningIdentity, error) { + fake.getSigningIdentityMutex.Lock() + ret, specificReturn := fake.getSigningIdentityReturnsOnCall[len(fake.getSigningIdentityArgsForCall)] + fake.getSigningIdentityArgsForCall = append(fake.getSigningIdentityArgsForCall, struct { + arg1 viewa.Identity + }{arg1}) + stub := fake.GetSigningIdentityStub + fakeReturns := fake.getSigningIdentityReturns + fake.recordInvocation("GetSigningIdentity", []interface{}{arg1}) + fake.getSigningIdentityMutex.Unlock() + if stub != nil { + return stub(arg1) + } + if specificReturn { + return ret.result1, ret.result2 + } + return fakeReturns.result1, fakeReturns.result2 +} + +func (fake *SignerProvider) GetSigningIdentityCallCount() int { + fake.getSigningIdentityMutex.RLock() + defer fake.getSigningIdentityMutex.RUnlock() + return len(fake.getSigningIdentityArgsForCall) +} + +func (fake *SignerProvider) GetSigningIdentityCalls(stub func(viewa.Identity) (*view.SigningIdentity, error)) { + fake.getSigningIdentityMutex.Lock() + defer fake.getSigningIdentityMutex.Unlock() + fake.GetSigningIdentityStub = stub +} + +func (fake *SignerProvider) GetSigningIdentityArgsForCall(i int) viewa.Identity { + fake.getSigningIdentityMutex.RLock() + defer fake.getSigningIdentityMutex.RUnlock() + argsForCall := fake.getSigningIdentityArgsForCall[i] + return argsForCall.arg1 +} + +func (fake *SignerProvider) GetSigningIdentityReturns(result1 *view.SigningIdentity, result2 error) { + fake.getSigningIdentityMutex.Lock() + defer fake.getSigningIdentityMutex.Unlock() + fake.GetSigningIdentityStub = nil + fake.getSigningIdentityReturns = struct { + result1 *view.SigningIdentity + result2 error + }{result1, result2} +} + +func (fake *SignerProvider) GetSigningIdentityReturnsOnCall(i int, result1 *view.SigningIdentity, result2 error) { + fake.getSigningIdentityMutex.Lock() + defer fake.getSigningIdentityMutex.Unlock() + fake.GetSigningIdentityStub = nil + if fake.getSigningIdentityReturnsOnCall == nil { + fake.getSigningIdentityReturnsOnCall = make(map[int]struct { + result1 *view.SigningIdentity + result2 error + }) + } + fake.getSigningIdentityReturnsOnCall[i] = struct { + result1 *view.SigningIdentity + result2 error + }{result1, result2} +} + +func (fake *SignerProvider) Invocations() map[string][][]interface{} { + fake.invocationsMutex.RLock() + defer fake.invocationsMutex.RUnlock() + fake.getSigningIdentityMutex.RLock() + defer fake.getSigningIdentityMutex.RUnlock() + copiedInvocations := map[string][][]interface{}{} + for key, value := range fake.invocations { + copiedInvocations[key] = value + } + return copiedInvocations +} + +func (fake *SignerProvider) 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) +} + +var _ chaincode.SignerProvider = new(SignerProvider) diff --git a/platform/fabric/core/generic/chaincode/support.go b/platform/fabric/core/generic/chaincode/support.go index 8d28e7096..cf45077b8 100644 --- a/platform/fabric/core/generic/chaincode/support.go +++ b/platform/fabric/core/generic/chaincode/support.go @@ -9,6 +9,8 @@ package chaincode import ( "context" + pb "github.com/hyperledger/fabric-protos-go/peer" + "github.com/hyperledger-labs/fabric-smart-client/platform/fabric/core/generic/config" "github.com/hyperledger-labs/fabric-smart-client/platform/fabric/core/generic/peer" "github.com/hyperledger-labs/fabric-smart-client/platform/fabric/driver" @@ -20,6 +22,27 @@ import ( var logger = flogging.MustGetLogger("fabric-sdk.chaincode") +//go:generate counterfeiter -o mocks/sp.go -fake-name SignerProvider . SignerProvider +//go:generate counterfeiter -o mocks/sersig.go -fake-name SerializableSigner . SerializableSigner +//go:generate counterfeiter -o mocks/network.go -fake-name Network . Network +//go:generate counterfeiter -o mocks/channel.go -fake-name Channel . Channel +//go:generate counterfeiter -o mocks/cd.go -fake-name Discover . Discover +//go:generate counterfeiter -o mocks/mspm.go -fake-name MSPManager . MSPManager +//go:generate counterfeiter -o mocks/mspid.go -fake-name MSPIdentity . MSPIdentity +//go:generate counterfeiter -o mocks/pc.go -fake-name PeerClient . PeerClient +//go:generate counterfeiter -o mocks/ec.go -fake-name EndorserClient . EndorserClient +//go:generate counterfeiter -o mocks/sc.go -fake-name SignerService . SignerService +//go:generate counterfeiter -o mocks/si.go -fake-name SigningIdentity . SigningIdentity + +type SigningIdentity = driver.SigningIdentity +type SignerService = driver.SignerService +type EndorserClient = pb.EndorserClient +type PeerClient = peer.Client +type MSPIdentity = driver.MSPIdentity +type MSPManager = driver.MSPManager + +type Discover = driver.ChaincodeDiscover + type SignerProvider interface { GetSigningIdentity(identity view.Identity) (*view2.SigningIdentity, error) } diff --git a/platform/fabric/driver/chaincode.go b/platform/fabric/driver/chaincode.go index 335eef9e9..2868e933d 100644 --- a/platform/fabric/driver/chaincode.go +++ b/platform/fabric/driver/chaincode.go @@ -19,11 +19,15 @@ type TxID struct { Creator []byte } +// QueryPolicy defines the policy to use to decide if a query is successful type QueryPolicy int const ( + // QueryAll requires an answer from all selected peers QueryAll QueryPolicy = iota + // QueryMajority requires an answer from the majority of the selected peers QueryMajority + // QueryOne requires an answer from at least one of the selected peers QueryOne ) @@ -86,6 +90,8 @@ type ChaincodeDiscover interface { Call() ([]DiscoveredPeer, error) WithFilterByMSPIDs(mspIDs ...string) ChaincodeDiscover WithImplicitCollections(mspIDs ...string) ChaincodeDiscover + WithForQuery() ChaincodeDiscover + ChaincodeVersion() (string, error) } // Chaincode exposes chaincode-related functions diff --git a/platform/fabric/services/chaincode/chaincode.go b/platform/fabric/services/chaincode/chaincode.go index c204c25ce..8be1a1761 100644 --- a/platform/fabric/services/chaincode/chaincode.go +++ b/platform/fabric/services/chaincode/chaincode.go @@ -9,9 +9,8 @@ package chaincode import ( "time" - "github.com/hyperledger-labs/fabric-smart-client/platform/fabric/driver" - "github.com/hyperledger-labs/fabric-smart-client/platform/fabric" + "github.com/hyperledger-labs/fabric-smart-client/platform/fabric/driver" "github.com/hyperledger-labs/fabric-smart-client/platform/fabric/services/fpc" "github.com/hyperledger-labs/fabric-smart-client/platform/view/view" ) @@ -121,7 +120,7 @@ func (s *stdQuery) WithRetrySleep(duration time.Duration) { } func (s *stdQuery) WithQueryPolicy(policy driver.QueryPolicy) Query { - s.chq.WithQueryPolicy(policy) + s.chq.WithQueryPolicy(fabric.QueryPolicy(policy)) return s } diff --git a/platform/fabric/services/chaincode/query.go b/platform/fabric/services/chaincode/query.go index a1e699956..fdbbad8fb 100644 --- a/platform/fabric/services/chaincode/query.go +++ b/platform/fabric/services/chaincode/query.go @@ -17,12 +17,16 @@ import ( "github.com/pkg/errors" ) -type QueryPolicy = driver.QueryPolicy +// QueryPolicy defines the policy to use to decide if a query is successful +type QueryPolicy int const ( - QueryAll = driver.QueryAll - QueryMajority = driver.QueryMajority - QueryOne = driver.QueryOne + // QueryAll requires an answer from all selected peers + QueryAll QueryPolicy = iota + // QueryMajority requires an answer from the majority of the selected peers + QueryMajority + // QueryOne requires an answer from at least one of the selected peers + QueryOne ) type queryChaincodeView struct { @@ -73,7 +77,7 @@ func (i *queryChaincodeView) Query(context view.Context) ([]byte, error) { logger.Debugf("chaincode [%s:%s:%s] is a standard chaincode", i.Network, i.Channel, i.ChaincodeName) } - invocation := chaincode.Query(i.Function, i.Args...).WithInvokerIdentity(i.InvokerIdentity).WithQueryPolicy(i.policy) + invocation := chaincode.Query(i.Function, i.Args...).WithInvokerIdentity(i.InvokerIdentity).WithQueryPolicy(driver.QueryPolicy(i.policy)) for k, v := range i.TransientMap { invocation.WithTransientEntry(k, v) } @@ -146,7 +150,7 @@ func (i *queryChaincodeView) WithRetrySleep(duration time.Duration) *queryChainc return i } -func (i *queryChaincodeView) WithPolicy(policy QueryPolicy) *queryChaincodeView { +func (i *queryChaincodeView) WithQueryPolicy(policy QueryPolicy) *queryChaincodeView { i.policy = policy return i } From 047b0ad6d0f7eeae7986ddebd6a9c699cf7e89aa Mon Sep 17 00:00:00 2001 From: Angelo De Caro Date: Sat, 6 May 2023 09:08:47 +0200 Subject: [PATCH 3/3] fixup! introduce query policy Signed-off-by: Angelo De Caro --- platform/fabric/core/generic/chaincode/invoke_test.go | 3 +-- platform/fabric/services/chaincode/chaincode.go | 2 +- platform/fabric/services/chaincode/query.go | 3 +-- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/platform/fabric/core/generic/chaincode/invoke_test.go b/platform/fabric/core/generic/chaincode/invoke_test.go index 960bf48a2..b972ae8bd 100644 --- a/platform/fabric/core/generic/chaincode/invoke_test.go +++ b/platform/fabric/core/generic/chaincode/invoke_test.go @@ -10,14 +10,13 @@ import ( "testing" "time" - "github.com/hyperledger/fabric-protos-go/peer" - "github.com/hyperledger-labs/fabric-smart-client/platform/fabric/core/generic/chaincode" "github.com/hyperledger-labs/fabric-smart-client/platform/fabric/core/generic/chaincode/mocks" "github.com/hyperledger-labs/fabric-smart-client/platform/fabric/core/generic/config" config2 "github.com/hyperledger-labs/fabric-smart-client/platform/fabric/core/generic/config" mock2 "github.com/hyperledger-labs/fabric-smart-client/platform/fabric/core/generic/msp/mock" "github.com/hyperledger-labs/fabric-smart-client/platform/fabric/driver" + "github.com/hyperledger/fabric-protos-go/peer" "github.com/pkg/errors" "github.com/stretchr/testify/assert" ) diff --git a/platform/fabric/services/chaincode/chaincode.go b/platform/fabric/services/chaincode/chaincode.go index 8be1a1761..08b9932e8 100644 --- a/platform/fabric/services/chaincode/chaincode.go +++ b/platform/fabric/services/chaincode/chaincode.go @@ -212,7 +212,7 @@ func (s *fpcQuery) WithRetrySleep(duration time.Duration) { } func (s *fpcQuery) WithQueryPolicy(policy driver.QueryPolicy) Query { - return nil + return s } type fpcChaincode struct { diff --git a/platform/fabric/services/chaincode/query.go b/platform/fabric/services/chaincode/query.go index fdbbad8fb..34dd10bbd 100644 --- a/platform/fabric/services/chaincode/query.go +++ b/platform/fabric/services/chaincode/query.go @@ -9,9 +9,8 @@ package chaincode import ( "time" - "github.com/hyperledger-labs/fabric-smart-client/platform/fabric/driver" - "github.com/hyperledger-labs/fabric-smart-client/platform/fabric" + "github.com/hyperledger-labs/fabric-smart-client/platform/fabric/driver" "github.com/hyperledger-labs/fabric-smart-client/platform/fabric/services/fpc" "github.com/hyperledger-labs/fabric-smart-client/platform/view/view" "github.com/pkg/errors"