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{}, fromBytesConverter serialize.FromBytesConverter) 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 ChaincodeEvent
- type ChannelMockStubs
- type ChannelsMockStubs
- type CreatorTransformer
- type EventSubscription
- type Identities
- type IdentitySample
- type InvokeMutator
- 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(from ...int64) (events chan *peer.ChaincodeEvent, closer func() error)
- func (stub *MockStub) EventsList() []*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) WithChannel(channelID string) *MockStub
- func (stub *MockStub) WithTransient(transient map[string][]byte) *MockStub
- type MockedPeer
- func (m *MockedPeer) Blocks(ctx context.Context, channelName string, identity msp.SigningIdentity, ...) (blockChan <-chan *common.Block, closer func() error, err error)
- func (mp *MockedPeer) Chaincode(channel string, chaincode string) (*MockStub, error)
- func (mp *MockedPeer) CurrentIdentity() msp.SigningIdentity
- func (mp *MockedPeer) Events(ctx context.Context, channel string, chaincode string, ...) (events ..., closer func() error, err error)
- func (mp *MockedPeer) Invoke(ctx context.Context, channel string, chaincode string, args [][]byte, ...) (res *peer.Response, chaincodeTx string, err error)
- func (mp *MockedPeer) Query(ctx context.Context, channel string, chaincode string, args [][]byte, ...) (*peer.Response, error)
- func (mp *MockedPeer) WithChannel(channel string, mockStubs ...*MockStub) *MockedPeer
- type MockedPeerDecorator
- func (mpd *MockedPeerDecorator) CurrentIdentity() msp.SigningIdentity
- func (mpd *MockedPeerDecorator) Events(ctx context.Context, channel string, chaincode string, ...) (events ..., closer func() error, err error)
- func (mpd *MockedPeerDecorator) FailChaincode(chaincodes ...string)
- func (mpd *MockedPeerDecorator) FailInvoke(chaincodes ...string)
- func (mpd *MockedPeerDecorator) FailQuery(chaincodes ...string)
- func (mpd *MockedPeerDecorator) Invoke(ctx context.Context, channel string, chaincode string, args [][]byte, ...) (res *peer.Response, chaincodeTx string, err error)
- func (mpd *MockedPeerDecorator) Query(ctx context.Context, channel string, chaincode string, args [][]byte, ...) (*peer.Response, error)
- type PrivateMockStateRangeQueryIterator
- type QueryMutator
- 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 ( ErrPeerInvoke = errors.New(`invoke failed`) ErrPeerQuery = errors.New(`query failed`) ChaincodeSimulationErrorReponse = &peer.Response{ Status: shim.ERROR, Message: `chaincode simulation produced error response`} )
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 ¶
func CreatorFromSigningIdentity(creator msp.SigningIdentity) (mspID string, certPEM []byte, err error)
func IdentityFromFile ¶
IdentityFromFile returns Identity struct containing mspId and certificate
func MustConvertFromBytes ¶
func MustConvertFromBytes(bb []byte, target interface{}, fromBytesConverter serialize.FromBytesConverter) interface{}
func MustIdentityFromPem ¶
func MustIdentityFromPem(mspID string, certPEM []byte) *identity.CertIdentity
func MustJSONMarshal ¶
func MustJSONMarshal(val interface{}) []byte
func MustProtoMarshal ¶
MustProtoMarshal marshals proto.Message, panics if error
func MustProtoTimestamp ¶
MustProtoTimestamp creates proto.Timestamp, panics if error
func MustProtoUnmarshal ¶
MustProtoUnmarshal unmarshals proto.Message, panics if error
func TransformCreator ¶
TransformCreator transforms arbitrary tx creator (pmsp.SerializedIdentity etc) to mspID string, certPEM []byte,
Types ¶
type ChaincodeEvent ¶
type ChaincodeEvent struct {
// contains filtered or unexported fields
}
func (*ChaincodeEvent) Block ¶
func (eb *ChaincodeEvent) Block() uint64
func (*ChaincodeEvent) Event ¶
func (eb *ChaincodeEvent) Event() *peer.ChaincodeEvent
func (*ChaincodeEvent) TxTimestamp ¶
func (eb *ChaincodeEvent) TxTimestamp() *timestamp.Timestamp
type ChannelMockStubs ¶
type ChannelsMockStubs ¶
type ChannelsMockStubs map[string]ChannelMockStubs
type CreatorTransformer ¶
type EventSubscription ¶
type EventSubscription struct {
// contains filtered or unexported fields
}
func (*EventSubscription) Close ¶
func (es *EventSubscription) Close() error
func (*EventSubscription) Errors ¶
func (es *EventSubscription) Errors() chan error
func (*EventSubscription) Events ¶
func (es *EventSubscription) Events() chan *peer.ChaincodeEvent
type Identities ¶
func IdentitiesFromFiles ¶
func IdentitiesFromFiles(mspID string, files map[string]string, readFile ReadFile) (Identities, error)
IdentitiesFromFiles returns map of CertIdentity, loaded from PEM files
func IdentitiesFromPem ¶
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 ¶
func MustIdentitiesFromFiles(mspID string, files map[string]string, readFile ReadFile) Identities
MustIdentitiesFromFiles
type IdentitySample ¶
type IdentitySample interface {
SigningIdentity() msp.SigningIdentity
}
type InvokeMutator ¶
type MockStateRangeQueryPagedIterator ¶
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 ¶
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 ¶
func (iter *MockStateRangeQueryPagedIterator) Close() error
func (*MockStateRangeQueryPagedIterator) HasNext ¶
func (iter *MockStateRangeQueryPagedIterator) HasNext() bool
func (*MockStateRangeQueryPagedIterator) Len ¶
func (iter *MockStateRangeQueryPagedIterator) Len() int32
func (*MockStateRangeQueryPagedIterator) Next ¶
func (iter *MockStateRangeQueryPagedIterator) Next() (*queryresult.KV, error)
func (*MockStateRangeQueryPagedIterator) NextBookmark ¶
func (iter *MockStateRangeQueryPagedIterator) NextBookmark() string
type MockStub ¶
type MockStub struct { shimtest.MockStub StateBuffer []*StateItem // buffer for state changes during transaction Serializer serialize.Serializer TxResult peer.Response // last tx result ClearCreatorAfterInvoke bool Invokables map[string]*MockStub // invokable this version of MockStub LastTxID string 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 ¶
AddTransient adds key-value pairs to transient map
func (*MockStub) ClearEvents ¶
func (stub *MockStub) ClearEvents()
ClearEvents clears chaincode events channel
func (*MockStub) DelPrivateData ¶
DelPrivateData mocked
func (*MockStub) DumpStateBuffer ¶
func (stub *MockStub) DumpStateBuffer()
func (*MockStub) EventSubscription ¶
func (stub *MockStub) EventSubscription(from ...int64) (events chan *peer.ChaincodeEvent, closer func() error)
EventSubscription for new or all events
func (*MockStub) EventsList ¶
func (stub *MockStub) EventsList() []*peer.ChaincodeEvent
func (*MockStub) GetFunctionAndParameters ¶
GetFunctionAndParameters mocked
func (*MockStub) GetPrivateDataByPartialCompositeKey ¶
func (stub *MockStub) GetPrivateDataByPartialCompositeKey(collection, objectType string, attributes []string) (shim.StateQueryIteratorInterface, error)
GetPrivateDataByPartialCompositeKey mocked
func (*MockStub) GetStateByPartialCompositeKeyWithPagination ¶
func (stub *MockStub) GetStateByPartialCompositeKeyWithPagination(objectType string, keys []string, pageSize int32, bookmark string) (shim.StateQueryIteratorInterface, *pb.QueryResponseMetadata, error)
GetStateByPartialCompositeKeyWithPagination mocked
func (*MockStub) GetStateByRangeWithPagination ¶
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) InvokeBytes ¶
InvokeBytes 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 ¶
func (*MockStub) MockTransactionStart ¶
func (*MockStub) MockedPeerChaincodes ¶
MockedPeerChaincodes returns names of mocked chaincodes, available for invoke from current stub
func (*MockStub) PutPrivateData ¶
PutPrivateData mocked
func (*MockStub) PutState ¶
PutState wrapped functions puts state items in queue and dumps to state after invocation
func (*MockStub) QueryBytes ¶
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
func (*MockStub) WithChannel ¶
WithChannel sets channel id
type MockedPeer ¶
type MockedPeer struct { // channel name -> chaincode name ChannelCC ChannelsMockStubs // contains filtered or unexported fields }
func (*MockedPeer) Chaincode ¶
func (mp *MockedPeer) Chaincode(channel string, chaincode string) (*MockStub, error)
func (*MockedPeer) CurrentIdentity ¶
func (mp *MockedPeer) CurrentIdentity() msp.SigningIdentity
func (*MockedPeer) Events ¶
func (mp *MockedPeer) Events( ctx context.Context, channel string, chaincode string, identity msp.SigningIdentity, blockRange ...int64, ) (events chan interface { Event() *peer.ChaincodeEvent Block() uint64 TxTimestamp() *timestamp.Timestamp }, closer func() error, err error)
func (*MockedPeer) WithChannel ¶
func (mp *MockedPeer) WithChannel(channel string, mockStubs ...*MockStub) *MockedPeer
type MockedPeerDecorator ¶
type MockedPeerDecorator struct { SDK sdk.SDK InvokeMutator InvokeMutator QueryMutator QueryMutator }
func NewPeerDecorator ¶
func NewPeerDecorator(sdk sdk.SDK) *MockedPeerDecorator
func (*MockedPeerDecorator) CurrentIdentity ¶
func (mpd *MockedPeerDecorator) CurrentIdentity() msp.SigningIdentity
func (*MockedPeerDecorator) Events ¶
func (mpd *MockedPeerDecorator) Events( ctx context.Context, channel string, chaincode string, identity msp.SigningIdentity, blockRange ...int64, ) (events chan interface { Event() *peer.ChaincodeEvent Block() uint64 TxTimestamp() *timestamp.Timestamp }, closer func() error, err error)
func (*MockedPeerDecorator) FailChaincode ¶
func (mpd *MockedPeerDecorator) FailChaincode(chaincodes ...string)
func (*MockedPeerDecorator) FailInvoke ¶
func (mpd *MockedPeerDecorator) FailInvoke(chaincodes ...string)
func (*MockedPeerDecorator) FailQuery ¶
func (mpd *MockedPeerDecorator) FailQuery(chaincodes ...string)
type PrivateMockStateRangeQueryIterator ¶
type PrivateMockStateRangeQueryIterator struct { Closed bool Stub *MockStub StartKey string EndKey string Current *list.Element Collection string }
func NewPrivateMockStateRangeQueryIterator ¶
func NewPrivateMockStateRangeQueryIterator(stub *MockStub, collection string, startKey string, endKey string) *PrivateMockStateRangeQueryIterator
func (*PrivateMockStateRangeQueryIterator) Close ¶
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 ¶
func (iter *PrivateMockStateRangeQueryIterator) HasNext() bool
HasNext returns true if the range query iterator contains additional keys and values.
func (*PrivateMockStateRangeQueryIterator) Next ¶
func (iter *PrivateMockStateRangeQueryIterator) Next() (*queryresult.KV, error)
Next returns the next key and value in the range query iterator.
type QueryMutator ¶
type TxHandler ¶
type TxHandler struct { MockStub *MockStub Logger *zap.Logger Context router.Context // contains filtered or unexported fields }
func (*TxHandler) SetTxResult ¶
SetTxResult can be used for set txResult error during Tx
func (*TxHandler) TxEvent ¶
func (p *TxHandler) TxEvent() *peer.ChaincodeEvent
TxEvent returns last tx event
func (*TxHandler) TxFunc ¶
func (p *TxHandler) TxFunc(tx func()) func()
TxFunc returns tx closure, can be used directly as ginkgo func
func (*TxHandler) TxTimestamp ¶
TxTimestamp returns last tx timestamp