Documentation ¶
Overview ¶
Package shimtest provides a mock of the ChaincodeStubInterface for unit testing chaincode.
Deprecated: ShimTest will be removed in a future release. Future development should make use of the ChaincodeStub Interface for generating mocks
Index ¶
- type MockStateRangeQueryIterator
- type MockStub
- func (stub *MockStub) CreateCompositeKey(objectType string, attributes []string) (string, error)
- func (stub *MockStub) DelPrivateData(collection string, key string) error
- func (stub *MockStub) DelState(key string) error
- func (stub *MockStub) GetArgs() [][]byte
- func (stub *MockStub) GetArgsSlice() ([]byte, error)
- func (stub *MockStub) GetBinding() ([]byte, error)
- func (stub *MockStub) GetChannelID() string
- func (stub *MockStub) GetCreator() ([]byte, error)
- func (stub *MockStub) GetDecorations() map[string][]byte
- func (stub *MockStub) GetFunctionAndParameters() (function string, params []string)
- func (stub *MockStub) GetHistoryForKey(key string) (shim.HistoryQueryIteratorInterface, error)
- func (stub *MockStub) GetPrivateData(collection string, key string) ([]byte, error)
- func (stub *MockStub) GetPrivateDataByPartialCompositeKey(collection, objectType string, attributes []string) (shim.StateQueryIteratorInterface, error)
- func (stub *MockStub) GetPrivateDataByRange(collection, startKey, endKey string) (shim.StateQueryIteratorInterface, error)
- func (stub *MockStub) GetPrivateDataHash(collection, key string) ([]byte, error)
- func (stub *MockStub) GetPrivateDataQueryResult(collection, query string) (shim.StateQueryIteratorInterface, error)
- func (stub *MockStub) GetPrivateDataValidationParameter(collection, key string) ([]byte, error)
- func (stub *MockStub) GetQueryResult(query string) (shim.StateQueryIteratorInterface, error)
- func (stub *MockStub) GetQueryResultWithPagination(query string, pageSize int32, bookmark string) (shim.StateQueryIteratorInterface, *pb.QueryResponseMetadata, error)
- func (stub *MockStub) GetSignedProposal() (*pb.SignedProposal, error)
- func (stub *MockStub) GetState(key string) ([]byte, error)
- func (stub *MockStub) GetStateByPartialCompositeKey(objectType string, attributes []string) (shim.StateQueryIteratorInterface, error)
- func (stub *MockStub) GetStateByPartialCompositeKeyWithPagination(objectType string, keys []string, pageSize int32, bookmark string) (shim.StateQueryIteratorInterface, *pb.QueryResponseMetadata, error)
- func (stub *MockStub) GetStateByRange(startKey, endKey string) (shim.StateQueryIteratorInterface, error)
- func (stub *MockStub) GetStateByRangeWithPagination(startKey, endKey string, pageSize int32, bookmark string) (shim.StateQueryIteratorInterface, *pb.QueryResponseMetadata, error)
- func (stub *MockStub) GetStateValidationParameter(key string) ([]byte, error)
- func (stub *MockStub) GetStringArgs() []string
- func (stub *MockStub) GetTransient() (map[string][]byte, error)
- func (stub *MockStub) GetTxID() string
- func (stub *MockStub) GetTxTimestamp() (*timestamp.Timestamp, error)
- func (stub *MockStub) InvokeChaincode(chaincodeName string, args [][]byte, channel string) pb.Response
- func (stub *MockStub) MockInit(uuid string, args [][]byte) pb.Response
- func (stub *MockStub) MockInvoke(uuid string, args [][]byte) pb.Response
- func (stub *MockStub) MockInvokeWithSignedProposal(uuid string, args [][]byte, sp *pb.SignedProposal) pb.Response
- func (stub *MockStub) MockPeerChaincode(invokableChaincodeName string, otherStub *MockStub, channel string)
- func (stub *MockStub) MockTransactionEnd(uuid string)
- func (stub *MockStub) MockTransactionStart(txid string)
- func (stub *MockStub) PutPrivateData(collection string, key string, value []byte) error
- func (stub *MockStub) PutState(key string, value []byte) error
- func (stub *MockStub) SetEvent(name string, payload []byte) error
- func (stub *MockStub) SetPrivateDataValidationParameter(collection, key string, ep []byte) error
- func (stub *MockStub) SetStateValidationParameter(key string, ep []byte) error
- func (stub *MockStub) SplitCompositeKey(compositeKey string) (string, []string, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type MockStateRangeQueryIterator ¶
type MockStateRangeQueryIterator struct { Closed bool Stub *MockStub StartKey string EndKey string Current *list.Element }
MockStateRangeQueryIterator ...
func NewMockStateRangeQueryIterator ¶
func NewMockStateRangeQueryIterator(stub *MockStub, startKey string, endKey string) *MockStateRangeQueryIterator
NewMockStateRangeQueryIterator ...
func (*MockStateRangeQueryIterator) Close ¶
func (iter *MockStateRangeQueryIterator) Close() error
Close closes the range query iterator. This should be called when done reading from the iterator to free up resources.
func (*MockStateRangeQueryIterator) HasNext ¶
func (iter *MockStateRangeQueryIterator) HasNext() bool
HasNext returns true if the range query iterator contains additional keys and values.
func (*MockStateRangeQueryIterator) Next ¶
func (iter *MockStateRangeQueryIterator) Next() (*queryresult.KV, error)
Next returns the next key and value in the range query iterator.
type MockStub ¶
type MockStub struct { // A nice name that can be used for logging Name string // State keeps name value pairs State map[string][]byte // Keys stores the list of mapped values in lexical order Keys *list.List // registered list of other MockStub chaincodes that can be called from this MockStub Invokables map[string]*MockStub // stores a transaction uuid while being Invoked / Deployed // TODO if a chaincode uses recursion this may need to be a stack of TxIDs or possibly a reference counting map TxID string TxTimestamp *timestamp.Timestamp // stores a channel ID of the proposal ChannelID string PvtState map[string]map[string][]byte // stores per-key endorsement policy, first map index is the collection, second map index is the key EndorsementPolicies map[string]map[string][]byte // channel to store ChaincodeEvents ChaincodeEventsChannel chan *pb.ChaincodeEvent Creator []byte Decorations map[string][]byte // contains filtered or unexported fields }
MockStub is an implementation of ChaincodeStubInterface for unit testing chaincode. Use this instead of ChaincodeStub in your chaincode's unit test calls to Init or Invoke.
func NewMockStub ¶
NewMockStub Constructor to initialise the internal State map
func (*MockStub) CreateCompositeKey ¶
CreateCompositeKey combines the list of attributes to form a composite key.
func (*MockStub) DelPrivateData ¶
DelPrivateData ...
func (*MockStub) GetArgsSlice ¶
GetArgsSlice Not implemented ...
func (*MockStub) GetBinding ¶
GetBinding Not implemented ...
func (*MockStub) GetDecorations ¶
GetDecorations ...
func (*MockStub) GetFunctionAndParameters ¶
GetFunctionAndParameters ...
func (*MockStub) GetHistoryForKey ¶
func (stub *MockStub) GetHistoryForKey(key string) (shim.HistoryQueryIteratorInterface, error)
GetHistoryForKey function can be invoked by a chaincode to return a history of key values across time. GetHistoryForKey is intended to be used for read-only queries.
func (*MockStub) GetPrivateData ¶
GetPrivateData ...
func (*MockStub) GetPrivateDataByPartialCompositeKey ¶
func (stub *MockStub) GetPrivateDataByPartialCompositeKey(collection, objectType string, attributes []string) (shim.StateQueryIteratorInterface, error)
GetPrivateDataByPartialCompositeKey ...
func (*MockStub) GetPrivateDataByRange ¶
func (stub *MockStub) GetPrivateDataByRange(collection, startKey, endKey string) (shim.StateQueryIteratorInterface, error)
GetPrivateDataByRange ...
func (*MockStub) GetPrivateDataHash ¶
GetPrivateDataHash ...
func (*MockStub) GetPrivateDataQueryResult ¶
func (stub *MockStub) GetPrivateDataQueryResult(collection, query string) (shim.StateQueryIteratorInterface, error)
GetPrivateDataQueryResult ...
func (*MockStub) GetPrivateDataValidationParameter ¶
GetPrivateDataValidationParameter ...
func (*MockStub) GetQueryResult ¶
func (stub *MockStub) GetQueryResult(query string) (shim.StateQueryIteratorInterface, error)
GetQueryResult function can be invoked by a chaincode to perform a rich query against state database. Only supported by state database implementations that support rich query. The query string is in the syntax of the underlying state database. An iterator is returned which can be used to iterate (next) over the query result set
func (*MockStub) GetQueryResultWithPagination ¶
func (stub *MockStub) GetQueryResultWithPagination(query string, pageSize int32, bookmark string) (shim.StateQueryIteratorInterface, *pb.QueryResponseMetadata, error)
GetQueryResultWithPagination ...
func (*MockStub) GetSignedProposal ¶
func (stub *MockStub) GetSignedProposal() (*pb.SignedProposal, error)
GetSignedProposal Not implemented ...
func (*MockStub) GetStateByPartialCompositeKey ¶
func (stub *MockStub) GetStateByPartialCompositeKey(objectType string, attributes []string) (shim.StateQueryIteratorInterface, error)
GetStateByPartialCompositeKey function can be invoked by a chaincode to query the state based on a given partial composite key. This function returns an iterator which can be used to iterate over all composite keys whose prefix matches the given partial composite key. This function should be used only for a partial composite key. For a full composite key, an iter with empty response would be returned.
func (*MockStub) GetStateByPartialCompositeKeyWithPagination ¶
func (stub *MockStub) GetStateByPartialCompositeKeyWithPagination(objectType string, keys []string, pageSize int32, bookmark string) (shim.StateQueryIteratorInterface, *pb.QueryResponseMetadata, error)
GetStateByPartialCompositeKeyWithPagination ...
func (*MockStub) GetStateByRange ¶
func (stub *MockStub) GetStateByRange(startKey, endKey string) (shim.StateQueryIteratorInterface, error)
GetStateByRange ...
func (*MockStub) GetStateByRangeWithPagination ¶
func (stub *MockStub) GetStateByRangeWithPagination(startKey, endKey string, pageSize int32, bookmark string) (shim.StateQueryIteratorInterface, *pb.QueryResponseMetadata, error)
GetStateByRangeWithPagination ...
func (*MockStub) GetStateValidationParameter ¶
GetStateValidationParameter ...
func (*MockStub) GetTransient ¶
GetTransient Not implemented ...
func (*MockStub) GetTxTimestamp ¶
GetTxTimestamp ...
func (*MockStub) InvokeChaincode ¶
func (stub *MockStub) InvokeChaincode(chaincodeName string, args [][]byte, channel string) pb.Response
InvokeChaincode locally calls the specified chaincode `Invoke`. E.g. stub1.InvokeChaincode("othercc", funcArgs, channel) Before calling this make sure to create another MockStub stub2, call shim.NewMockStub("othercc", Chaincode) and register it with stub1 by calling stub1.MockPeerChaincode("othercc", stub2, channel)
func (*MockStub) MockInvoke ¶
MockInvoke Invoke this chaincode, also starts and ends a transaction.
func (*MockStub) MockInvokeWithSignedProposal ¶
func (stub *MockStub) MockInvokeWithSignedProposal(uuid string, args [][]byte, sp *pb.SignedProposal) pb.Response
MockInvokeWithSignedProposal Invoke this chaincode, also starts and ends a transaction.
func (*MockStub) MockPeerChaincode ¶
func (stub *MockStub) MockPeerChaincode(invokableChaincodeName string, otherStub *MockStub, channel string)
MockPeerChaincode Register another MockStub chaincode with this MockStub. invokableChaincodeName is the name of a chaincode. otherStub is a MockStub of the chaincode, already initialized. channel is the name of a channel on which another MockStub is called.
func (*MockStub) MockTransactionEnd ¶
MockTransactionEnd End a mocked transaction, clearing the UUID.
func (*MockStub) MockTransactionStart ¶
MockTransactionStart Used to indicate to a chaincode that it is part of a transaction. This is important when chaincodes invoke each other. MockStub doesn't support concurrent transactions at present.
func (*MockStub) PutPrivateData ¶
PutPrivateData ...
func (*MockStub) SetPrivateDataValidationParameter ¶
SetPrivateDataValidationParameter ...
func (*MockStub) SetStateValidationParameter ¶
SetStateValidationParameter ...