github.com/kchristidis/fabric@v1.0.4-0.20171028114726-837acd08cde1/core/mocks/ccprovider/ccprovider.go (about) 1 /* 2 Copyright IBM Corp. 2017 All Rights Reserved. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package ccprovider 18 19 import ( 20 "context" 21 22 "github.com/hyperledger/fabric/core/chaincode/shim" 23 "github.com/hyperledger/fabric/core/common/ccprovider" 24 "github.com/hyperledger/fabric/core/ledger" 25 "github.com/hyperledger/fabric/protos/peer" 26 ) 27 28 type ExecuteChaincodeResultProvider interface { 29 ExecuteChaincodeResult() (*peer.Response, *peer.ChaincodeEvent, error) 30 } 31 32 // MockCcProviderFactory is a factory that returns 33 // mock implementations of the ccprovider.ChaincodeProvider interface 34 type MockCcProviderFactory struct { 35 ExecuteResultProvider ExecuteChaincodeResultProvider 36 } 37 38 // NewChaincodeProvider returns a mock implementation of the ccprovider.ChaincodeProvider interface 39 func (c *MockCcProviderFactory) NewChaincodeProvider() ccprovider.ChaincodeProvider { 40 return &mockCcProviderImpl{c.ExecuteResultProvider} 41 } 42 43 // mockCcProviderImpl is a mock implementation of the chaincode provider 44 type mockCcProviderImpl struct { 45 executeResultProvider ExecuteChaincodeResultProvider 46 } 47 48 type mockCcProviderContextImpl struct { 49 } 50 51 // GetContext does nothing 52 func (c *mockCcProviderImpl) GetContext(ledger ledger.PeerLedger) (context.Context, error) { 53 return nil, nil 54 } 55 56 // GetCCContext does nothing 57 func (c *mockCcProviderImpl) GetCCContext(cid, name, version, txid string, syscc bool, signedProp *peer.SignedProposal, prop *peer.Proposal) interface{} { 58 return &mockCcProviderContextImpl{} 59 } 60 61 // GetCCValidationInfoFromLSCC does nothing 62 func (c *mockCcProviderImpl) GetCCValidationInfoFromLSCC(ctxt context.Context, txid string, signedProp *peer.SignedProposal, prop *peer.Proposal, chainID string, chaincodeID string) (string, []byte, error) { 63 return "vscc", nil, nil 64 } 65 66 // ExecuteChaincode does nothing 67 func (c *mockCcProviderImpl) ExecuteChaincode(ctxt context.Context, cccid interface{}, args [][]byte) (*peer.Response, *peer.ChaincodeEvent, error) { 68 if c.executeResultProvider != nil { 69 return c.executeResultProvider.ExecuteChaincodeResult() 70 } 71 return &peer.Response{Status: shim.OK}, nil, nil 72 } 73 74 // Execute executes the chaincode given context and spec (invocation or deploy) 75 func (c *mockCcProviderImpl) Execute(ctxt context.Context, cccid interface{}, spec interface{}) (*peer.Response, *peer.ChaincodeEvent, error) { 76 return nil, nil, nil 77 } 78 79 // ExecuteWithErrorFilder executes the chaincode given context and spec and returns payload 80 func (c *mockCcProviderImpl) ExecuteWithErrorFilter(ctxt context.Context, cccid interface{}, spec interface{}) ([]byte, *peer.ChaincodeEvent, error) { 81 return nil, nil, nil 82 } 83 84 // Stop stops the chaincode given context and deployment spec 85 func (c *mockCcProviderImpl) Stop(ctxt context.Context, cccid interface{}, spec *peer.ChaincodeDeploymentSpec) error { 86 return nil 87 } 88 89 // ReleaseContext does nothing 90 func (c *mockCcProviderImpl) ReleaseContext() { 91 }