Documentation ¶
Index ¶
- Constants
- Variables
- func CreatorFromSigningIdentity(creator msp.SigningIdentity) (mspID string, certPEM []byte, err error)
- func IdentityFromFile(mspID string, file string, readFile ReadFile) (*identity.CertIdentity, error)
- func MustConvertFromBytes(bb []byte, target interface{}) interface{}
- func MustIdentityFromPem(mspID string, certPEM []byte) *identity.CertIdentity
- func MustJSONMarshal(val interface{}) []byte
- func MustProtoMarshal(pb proto.Message) []byte
- func MustProtoTimestamp(t time.Time) *timestamp.Timestamp
- func MustProtoUnmarshal(bb []byte, pm proto.Message) proto.Message
- func MustTime(s string) *timestamp.Timestamp
- func PanicIfError(err error)
- func TransformCreator(txCreator ...interface{}) (mspID string, certPEM []byte, err error)
- type ChannelMockStubs
- type ChannelsMockStubs
- type CreatorTransformer
- type EventSubscription
- type Identities
- type IdentitySample
- type MockStateRangeQueryPagedIterator
- func (iter *MockStateRangeQueryPagedIterator) Close() error
- func (iter *MockStateRangeQueryPagedIterator) HasNext() bool
- func (iter *MockStateRangeQueryPagedIterator) Len() int32
- func (iter *MockStateRangeQueryPagedIterator) Next() (*queryresult.KV, error)
- func (iter *MockStateRangeQueryPagedIterator) NextBookmark() string
- type MockStub
- func (stub *MockStub) AddTransient(transient map[string][]byte) *MockStub
- func (stub *MockStub) ClearEvents()
- func (stub *MockStub) DelPrivateData(collection string, key string) error
- func (stub *MockStub) DelState(key string) error
- func (stub *MockStub) DumpStateBuffer()
- func (stub *MockStub) EventSubscription() chan *peer.ChaincodeEvent
- func (stub *MockStub) From(txCreator ...interface{}) *MockStub
- func (stub *MockStub) GetArgs() [][]byte
- func (stub *MockStub) GetCreator() ([]byte, error)
- func (stub *MockStub) GetFunctionAndParameters() (function string, params []string)
- func (stub *MockStub) GetPrivateDataByPartialCompositeKey(collection, 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) GetStateByRangeWithPagination(startKey, endKey string, pageSize int32, bookmark string) (shim.StateQueryIteratorInterface, *pb.QueryResponseMetadata, error)
- func (stub *MockStub) GetStringArgs() []string
- func (stub *MockStub) GetTransient() (map[string][]byte, error)
- func (stub *MockStub) Init(iargs ...interface{}) peer.Response
- func (stub *MockStub) InitBytes(args ...[]byte) peer.Response
- func (stub *MockStub) Invoke(funcName string, iargs ...interface{}) peer.Response
- func (stub *MockStub) InvokeBytes(args ...[]byte) peer.Response
- func (stub *MockStub) InvokeChaincode(chaincodeName string, args [][]byte, channel string) peer.Response
- func (stub *MockStub) MockCreator(mspID string, certPEM []byte)
- func (stub *MockStub) MockInit(uuid string, args [][]byte) peer.Response
- func (stub *MockStub) MockInvoke(uuid string, args [][]byte) peer.Response
- func (stub *MockStub) MockPeerChaincode(invokableChaincodeName string, otherStub *MockStub)
- func (stub *MockStub) MockQuery(uuid string, args [][]byte) peer.Response
- func (stub *MockStub) MockTransactionEnd(uuid string)
- func (stub *MockStub) MockTransactionStart(uuid string)
- func (stub *MockStub) MockedPeerChaincodes() []string
- func (stub *MockStub) PutPrivateData(collection string, key string, value []byte) error
- func (stub *MockStub) PutState(key string, value []byte) error
- func (stub *MockStub) Query(funcName string, iargs ...interface{}) peer.Response
- func (stub *MockStub) QueryBytes(args ...[]byte) peer.Response
- func (stub *MockStub) RegisterCreatorTransformer(creatorTransformer CreatorTransformer) *MockStub
- func (stub *MockStub) SetArgs(args [][]byte)
- func (stub *MockStub) SetEvent(name string, payload []byte) error
- func (stub *MockStub) WithTransient(transient map[string][]byte) *MockStub
- type MockedPeer
- func (mi *MockedPeer) Chaincode(channel string, chaincode string) (*MockStub, error)
- func (mi *MockedPeer) Invoke(ctx context.Context, from msp.SigningIdentity, channel string, ...) (*peer.Response, string, error)
- func (mi *MockedPeer) Query(ctx context.Context, from msp.SigningIdentity, channel string, ...) (*peer.Response, error)
- func (mi *MockedPeer) Subscribe(ctx context.Context, from msp.SigningIdentity, channel, chaincode string) (chan *peer.ChaincodeEvent, error)
- func (mi *MockedPeer) WithChannel(channel string, mockStubs ...*MockStub) *MockedPeer
- type PrivateMockStateRangeQueryIterator
- type ReadFile
- type StateItem
- type TxHandler
- func (p *TxHandler) Expect(res interface{}, err error) *expect.TxRes
- func (p *TxHandler) From(creator ...interface{}) *TxHandler
- func (p *TxHandler) Init(txHdl func(ctx router.Context) (interface{}, error)) *TxResult
- func (p *TxHandler) Invoke(invoke func(ctx router.Context) (interface{}, error)) *TxResult
- func (p *TxHandler) SetTxResult(err error)
- func (p *TxHandler) Tx(tx func())
- func (p *TxHandler) TxEvent() *peer.ChaincodeEvent
- func (p *TxHandler) TxFunc(tx func()) func()
- func (p *TxHandler) TxTimestamp() *timestamp.Timestamp
- type TxResult
Constants ¶
const EventChannelBufferSize = 100
Variables ¶
var ( // ErrChaincodeNotExists occurs when attempting to invoke a nonexostent external chaincode ErrChaincodeNotExists = errors.New(`chaincode not exists`) // ErrUnknownFromArgsType occurs when attempting to set unknown args in From func ErrUnknownFromArgsType = errors.New(`unknown args type to cckit.MockStub.From func`) // ErrKeyAlreadyExistsInTransientMap occurs when attempting to set existing key in transient map ErrKeyAlreadyExistsInTransientMap = errors.New(`key already exists in transient map`) )
Functions ¶
func CreatorFromSigningIdentity ¶ added in v0.6.10
func CreatorFromSigningIdentity(creator msp.SigningIdentity) (mspID string, certPEM []byte, err error)
func IdentityFromFile ¶ added in v0.5.2
IdentityFromFile returns Identity struct containing mspId and certificate
func MustConvertFromBytes ¶ added in v0.4.4
func MustConvertFromBytes(bb []byte, target interface{}) interface{}
func MustIdentityFromPem ¶ added in v0.4.5
func MustIdentityFromPem(mspID string, certPEM []byte) *identity.CertIdentity
func MustJSONMarshal ¶ added in v0.4.5
func MustJSONMarshal(val interface{}) []byte
func MustProtoMarshal ¶ added in v0.4.1
MustProtoMarshal marshals proto.Message, panics if error
func MustProtoTimestamp ¶ added in v0.4.1
MustProtoTimestamp, creates proto.Timestamp, panics if error
func MustProtoUnmarshal ¶ added in v0.4.3
MustProtoUnmarshal unmarshals proto.Message, panics if error
func TransformCreator ¶
TransformCreator transforms arbitrary tx creator (pmsp.SerializedIdentity etc) to mspID string, certPEM []byte,
Types ¶
type ChannelMockStubs ¶ added in v0.4.4
type ChannelsMockStubs ¶ added in v0.4.4
type ChannelsMockStubs map[string]ChannelMockStubs
type CreatorTransformer ¶
type EventSubscription ¶ added in v0.4.4
type EventSubscription struct {
// contains filtered or unexported fields
}
func (*EventSubscription) Close ¶ added in v0.4.4
func (es *EventSubscription) Close() error
func (*EventSubscription) Errors ¶ added in v0.4.4
func (es *EventSubscription) Errors() chan error
func (*EventSubscription) Events ¶ added in v0.4.4
func (es *EventSubscription) Events() chan *peer.ChaincodeEvent
type Identities ¶ added in v0.4.4
func IdentitiesFromFiles ¶ added in v0.4.4
func IdentitiesFromFiles(mspID string, files map[string]string, readFile ReadFile) (Identities, error)
IdentitiesFromFiles returns map of CertIdentity, loaded from PEM files
func IdentitiesFromPem ¶ added in v0.4.4
func IdentitiesFromPem(mspID string, certPEMs map[string][]byte) (ids Identities, err error)
IdentitiesFromPem returns CertIdentity (MSP ID and X.509 cert) converted PEM content
func MustIdentitiesFromFiles ¶ added in v0.4.5
func MustIdentitiesFromFiles(mspID string, files map[string]string, readFile ReadFile) Identities
MustIdentitiesFromFiles
type IdentitySample ¶ added in v0.6.10
type IdentitySample interface {
SigningIdentity() msp.SigningIdentity
}
type MockStateRangeQueryPagedIterator ¶ added in v0.7.7
type MockStateRangeQueryPagedIterator struct { Closed bool Stub *MockStub Keys *list.List Current *list.Element // contains filtered or unexported fields }
MockStateRangeQueryPagedIterator represents paged version of shimtest.MockStateRangeQueryIterator
func NewMockStatesRangeQueryPagedIterator ¶ added in v0.7.7
func NewMockStatesRangeQueryPagedIterator(stub *MockStub, startKey string, endKey string, pageSize int32, bookmark string) *MockStateRangeQueryPagedIterator
NewMockStatesRangeQueryPagedIterator creates iterator starting from bookmark and limited by pageSize
func (*MockStateRangeQueryPagedIterator) Close ¶ added in v0.7.7
func (iter *MockStateRangeQueryPagedIterator) Close() error
func (*MockStateRangeQueryPagedIterator) HasNext ¶ added in v0.7.7
func (iter *MockStateRangeQueryPagedIterator) HasNext() bool
func (*MockStateRangeQueryPagedIterator) Len ¶ added in v0.7.7
func (iter *MockStateRangeQueryPagedIterator) Len() int32
func (*MockStateRangeQueryPagedIterator) Next ¶ added in v0.7.7
func (iter *MockStateRangeQueryPagedIterator) Next() (*queryresult.KV, error)
func (*MockStateRangeQueryPagedIterator) NextBookmark ¶ added in v0.7.7
func (iter *MockStateRangeQueryPagedIterator) NextBookmark() string
type MockStub ¶
type MockStub struct { shimtest.MockStub StateBuffer []*StateItem // buffer for state changes during transaction TxResult peer.Response // last tx result ClearCreatorAfterInvoke bool Invokables map[string]*MockStub // invokable this version of MockStub ChaincodeEvent *peer.ChaincodeEvent // event in last tx PrivateKeys map[string]*list.List // contains filtered or unexported fields }
MockStub replacement of shim.MockStub with creator mocking facilities
func NewMockStub ¶
NewMockStub creates chaincode imitation
func (*MockStub) AddTransient ¶ added in v0.4.5
AddTransient adds key-value pairs to transient map
func (*MockStub) ClearEvents ¶
func (stub *MockStub) ClearEvents()
ClearEvents clears chaincode events channel
func (*MockStub) DelPrivateData ¶ added in v0.5.0
DelPrivateData mocked
func (*MockStub) DumpStateBuffer ¶ added in v0.7.2
func (stub *MockStub) DumpStateBuffer()
func (*MockStub) EventSubscription ¶
func (stub *MockStub) EventSubscription() chan *peer.ChaincodeEvent
func (*MockStub) GetFunctionAndParameters ¶
GetFunctionAndParameters mocked
func (*MockStub) GetPrivateDataByPartialCompositeKey ¶ added in v0.5.0
func (stub *MockStub) GetPrivateDataByPartialCompositeKey(collection, objectType string, attributes []string) (shim.StateQueryIteratorInterface, error)
GetPrivateDataByPartialCompositeKey mocked
func (*MockStub) GetStateByPartialCompositeKeyWithPagination ¶ added in v0.7.7
func (stub *MockStub) GetStateByPartialCompositeKeyWithPagination(objectType string, keys []string, pageSize int32, bookmark string) (shim.StateQueryIteratorInterface, *pb.QueryResponseMetadata, error)
GetStateByPartialCompositeKeyWithPagination mocked
func (*MockStub) GetStateByRangeWithPagination ¶ added in v0.7.7
func (stub *MockStub) GetStateByRangeWithPagination(startKey, endKey string, pageSize int32, bookmark string) (shim.StateQueryIteratorInterface, *pb.QueryResponseMetadata, error)
GetStateByRangeWithPagination mocked
func (*MockStub) GetStringArgs ¶
GetStringArgs get mocked args as strings
func (*MockStub) GetTransient ¶ added in v0.3.0
func (*MockStub) InvokeBytes ¶ added in v0.3.0
InvokeByte mock invoke with autogenerated tx uuid
func (*MockStub) InvokeChaincode ¶
func (stub *MockStub) InvokeChaincode(chaincodeName string, args [][]byte, channel string) peer.Response
InvokeChaincode using another MockStub
func (*MockStub) MockCreator ¶
MockCreator of tx
func (*MockStub) MockInvoke ¶
MockInvoke
func (*MockStub) MockPeerChaincode ¶
MockPeerChaincode link to another MockStub
func (*MockStub) MockTransactionEnd ¶ added in v0.7.3
func (*MockStub) MockTransactionStart ¶ added in v0.7.3
func (*MockStub) MockedPeerChaincodes ¶ added in v0.4.5
MockedPeerChaincodes returns names of mocked chaincodes, available for invoke from current stub
func (*MockStub) PutPrivateData ¶ added in v0.5.0
PutPrivateData mocked
func (*MockStub) PutState ¶ added in v0.7.2
PutState wrapped functions puts state items in queue and dumps to state after invocation
func (*MockStub) QueryBytes ¶ added in v0.4.1
QueryBytes mock query with autogenerated tx uuid
func (*MockStub) RegisterCreatorTransformer ¶
func (stub *MockStub) RegisterCreatorTransformer(creatorTransformer CreatorTransformer) *MockStub
RegisterCreatorTransformer that transforms creator data to MSP_ID and X.509 certificate
type MockedPeer ¶ added in v0.4.5
type MockedPeer struct { // channel name -> chaincode name ChannelCC ChannelsMockStubs // contains filtered or unexported fields }
func NewPeer ¶ added in v0.4.5
func NewPeer() *MockedPeer
NewInvoker implements Invoker interface from hlf-sdk-go
func (*MockedPeer) Chaincode ¶ added in v0.4.5
func (mi *MockedPeer) Chaincode(channel string, chaincode string) (*MockStub, error)
func (*MockedPeer) Subscribe ¶ added in v0.4.5
func (mi *MockedPeer) Subscribe( ctx context.Context, from msp.SigningIdentity, channel, chaincode string) (chan *peer.ChaincodeEvent, error)
func (*MockedPeer) WithChannel ¶ added in v0.4.5
func (mi *MockedPeer) WithChannel(channel string, mockStubs ...*MockStub) *MockedPeer
type PrivateMockStateRangeQueryIterator ¶ added in v0.5.0
type PrivateMockStateRangeQueryIterator struct { Closed bool Stub *MockStub StartKey string EndKey string Current *list.Element Collection string }
func NewPrivateMockStateRangeQueryIterator ¶ added in v0.5.0
func NewPrivateMockStateRangeQueryIterator(stub *MockStub, collection string, startKey string, endKey string) *PrivateMockStateRangeQueryIterator
func (*PrivateMockStateRangeQueryIterator) Close ¶ added in v0.5.0
func (iter *PrivateMockStateRangeQueryIterator) Close() error
Close closes the range query iterator. This should be called when done reading from the iterator to free up resources.
func (*PrivateMockStateRangeQueryIterator) HasNext ¶ added in v0.5.0
func (iter *PrivateMockStateRangeQueryIterator) HasNext() bool
HasNext returns true if the range query iterator contains additional keys and values.
func (*PrivateMockStateRangeQueryIterator) Next ¶ added in v0.5.0
func (iter *PrivateMockStateRangeQueryIterator) Next() (*queryresult.KV, error)
Next returns the next key and value in the range query iterator.
type TxHandler ¶ added in v0.6.7
type TxHandler struct { MockStub *MockStub Logger *zap.Logger Context router.Context // contains filtered or unexported fields }
func (*TxHandler) Invoke ¶ added in v0.6.7
Invoke emulates chaincode invocation and returns transaction result
func (*TxHandler) SetTxResult ¶ added in v0.7.4
SetTxResult can be used for set txResult error during Tx
func (*TxHandler) Tx ¶ added in v0.6.7
func (p *TxHandler) Tx(tx func())
Tx emulates chaincode invocation
func (*TxHandler) TxEvent ¶ added in v0.6.7
func (p *TxHandler) TxEvent() *peer.ChaincodeEvent
TxEvent returns last tx event
func (*TxHandler) TxFunc ¶ added in v0.6.10
func (p *TxHandler) TxFunc(tx func()) func()
TxFunc returns tx closure, can be used directly as ginkgo func
func (*TxHandler) TxTimestamp ¶ added in v0.6.7
TxTimestamp returns last tx timestamp