{"modulePath":"github.com/s7techlab/cckit","version":"v0.10.5","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package testing\n\n## Constants\n\n```go\nconst EventChannelBufferSize = 100\n```\n\n## Variables\n\n```go\nvar (\n\tErrPeerInvoke                   = errors.New(`invoke failed`)\n\tErrPeerQuery                    = errors.New(`query failed`)\n\tChaincodeSimulationErrorReponse = \u0026peer.Response{\n\t\tStatus: shim.ERROR, Message: `chaincode simulation produced error response`}\n)\n```\n\n```go\nvar (\n\t// ErrChaincodeNotExists occurs when attempting to invoke a nonexostent external chaincode\n\tErrChaincodeNotExists = errors.New(`chaincode not exists`)\n\t// ErrUnknownFromArgsType occurs when attempting to set unknown args in From func\n\tErrUnknownFromArgsType = errors.New(`unknown args type to cckit.MockStub.From func`)\n\t// ErrKeyAlreadyExistsInTransientMap occurs when attempting to set existing key in transient map\n\tErrKeyAlreadyExistsInTransientMap = errors.New(`key already exists in transient map`)\n)\n```\n\n## Functions\n\n```go\nfunc CreatorFromSigningIdentity(creator msp.SigningIdentity) (mspID string, certPEM []byte, err error)\n```\n\n```go\nfunc IdentityFromFile(mspID string, file string, readFile ReadFile) (*identity.CertIdentity, error)\n```\nIdentityFromFile returns Identity struct containing mspId and certificate\n\n```go\nfunc MustConvertFromBytes(bb []byte, target interface{}) interface{}\n```\n\n```go\nfunc MustIdentityFromPem(mspID string, certPEM []byte) *identity.CertIdentity\n```\n\n```go\nfunc MustJSONMarshal(val interface{}) []byte\n```\n\n```go\nfunc MustProtoMarshal(pb proto.Message) []byte\n```\nMustProtoMarshal marshals proto.Message, panics if error\n\n```go\nfunc MustProtoTimestamp(t time.Time) *timestamp.Timestamp\n```\nMustProtoTimestamp, creates proto.Timestamp, panics if error\n\n```go\nfunc MustProtoUnmarshal(bb []byte, pm proto.Message) proto.Message\n```\nMustProtoUnmarshal unmarshals proto.Message, panics if error\n\n```go\nfunc MustTime(s string) *timestamp.Timestamp\n```\nMustTime returns Timestamp for date string or panic\n\n```go\nfunc PanicIfError(err error)\n```\nPanicIfError\n\n```go\nfunc TransformCreator(txCreator ...interface{}) (mspID string, certPEM []byte, err error)\n```\nTransformCreator transforms arbitrary tx creator (pmsp.SerializedIdentity etc)  to mspID string, certPEM \\[]byte,\n\n## Types\n\n```go\ntype ChaincodeEvent struct {\n\t// contains filtered or unexported fields\n}\n```\n\n```go\nfunc (eb *ChaincodeEvent) Block() uint64\n```\n\n```go\nfunc (eb *ChaincodeEvent) Event() *peer.ChaincodeEvent\n```\n\n```go\nfunc (eb *ChaincodeEvent) TxTimestamp() *timestamp.Timestamp\n```\n\n```go\ntype ChannelMockStubs map[string]*MockStub\n```\n\n```go\ntype ChannelsMockStubs map[string]ChannelMockStubs\n```\n\n```go\ntype CreatorTransformer func(...interface{}) (mspID string, certPEM []byte, err error)\n```\n\n```go\ntype EventSubscription struct {\n\t// contains filtered or unexported fields\n}\n```\n\n```go\nfunc (es *EventSubscription) Close() error\n```\n\n```go\nfunc (es *EventSubscription) Errors() chan error\n```\n\n```go\nfunc (es *EventSubscription) Events() chan *peer.ChaincodeEvent\n```\n\n```go\ntype Identities map[string]identity.Identity\n```\n\n```go\nfunc IdentitiesFromFiles(mspID string, files map[string]string, readFile ReadFile) (Identities, error)\n```\nIdentitiesFromFiles returns map of CertIdentity, loaded from PEM files\n\n```go\nfunc IdentitiesFromPem(mspID string, certPEMs map[string][]byte) (ids Identities, err error)\n```\nIdentitiesFromPem returns CertIdentity (MSP ID and X.509 cert) converted PEM content\n\n```go\nfunc MustIdentitiesFromFiles(mspID string, files map[string]string, readFile ReadFile) Identities\n```\nMustIdentitiesFromFiles\n\n```go\ntype IdentitySample interface {\n\tSigningIdentity() msp.SigningIdentity\n}\n```\n\n```go\ntype InvokeMutator func(\n\tsdk sdk.SDK,\n\tctx context.Context,\n\tchannel string,\n\tchaincode string,\n\targs [][]byte,\n\tidentity msp.SigningIdentity,\n\ttransArgs map[string][]byte,\n\ttxWaiterType string) (res *peer.Response, chaincodeTx string, err error)\n```\n\n```go\ntype MockStateRangeQueryPagedIterator struct {\n\tClosed  bool\n\tStub    *MockStub\n\tKeys    *list.List\n\tCurrent *list.Element\n\t// contains filtered or unexported fields\n}\n```\nMockStateRangeQueryPagedIterator represents paged version of shimtest.MockStateRangeQueryIterator\n\n```go\nfunc NewMockStatesRangeQueryPagedIterator(stub *MockStub, startKey string, endKey string, pageSize int32, bookmark string) *MockStateRangeQueryPagedIterator\n```\nNewMockStatesRangeQueryPagedIterator creates iterator starting from bookmark and limited by pageSize\n\n```go\nfunc (iter *MockStateRangeQueryPagedIterator) Close() error\n```\n\n```go\nfunc (iter *MockStateRangeQueryPagedIterator) HasNext() bool\n```\n\n```go\nfunc (iter *MockStateRangeQueryPagedIterator) Len() int32\n```\n\n```go\nfunc (iter *MockStateRangeQueryPagedIterator) Next() (*queryresult.KV, error)\n```\n\n```go\nfunc (iter *MockStateRangeQueryPagedIterator) NextBookmark() string\n```\n\n```go\ntype MockStub struct {\n\tshimtest.MockStub\n\n\tStateBuffer []*StateItem // buffer for state changes during transaction\n\n\tTxResult peer.Response // last tx result\n\n\tClearCreatorAfterInvoke bool\n\n\tInvokables map[string]*MockStub // invokable this version of MockStub\n\n\tLastTxID       string\n\tChaincodeEvent *peer.ChaincodeEvent // event in last tx\n\n\tPrivateKeys map[string]*list.List\n\t// contains filtered or unexported fields\n}\n```\nMockStub replacement of shim.MockStub with creator mocking facilities\n\n```go\nfunc NewMockStub(name string, cc shim.Chaincode) *MockStub\n```\nNewMockStub creates chaincode imitation\n\n```go\nfunc (stub *MockStub) AddTransient(transient map[string][]byte) *MockStub\n```\nAddTransient adds key-value pairs to transient map\n\n```go\nfunc (stub *MockStub) ClearEvents()\n```\nClearEvents clears chaincode events channel\n\n```go\nfunc (stub *MockStub) DelPrivateData(collection string, key string) error\n```\nDelPrivateData mocked\n\n```go\nfunc (stub *MockStub) DelState(key string) error\n```\n\n```go\nfunc (stub *MockStub) DumpStateBuffer()\n```\n\n```go\nfunc (stub *MockStub) EventSubscription(from ...int64) (events chan *peer.ChaincodeEvent, closer func() error)\n```\nEventSubscription for new or all events\n\n```go\nfunc (stub *MockStub) EventsList() []*peer.ChaincodeEvent\n```\n\n```go\nfunc (stub *MockStub) From(txCreator ...interface{}) *MockStub\n```\nFrom mock tx creator\n\n```go\nfunc (stub *MockStub) GetArgs() [][]byte\n```\nGetArgs mocked args\n\n```go\nfunc (stub *MockStub) GetCreator() ([]byte, error)\n```\nGetCreator mocked\n\n```go\nfunc (stub *MockStub) GetFunctionAndParameters() (function string, params []string)\n```\nGetFunctionAndParameters mocked\n\n```go\nfunc (stub *MockStub) GetPrivateDataByPartialCompositeKey(collection, objectType string, attributes []string) (shim.StateQueryIteratorInterface, error)\n```\nGetPrivateDataByPartialCompositeKey mocked\n\n```go\nfunc (stub *MockStub) GetStateByPartialCompositeKeyWithPagination(objectType string, keys []string,\n\tpageSize int32, bookmark string) (shim.StateQueryIteratorInterface, *pb.QueryResponseMetadata, error)\n```\nGetStateByPartialCompositeKeyWithPagination mocked\n\n```go\nfunc (stub *MockStub) GetStateByRangeWithPagination(startKey, endKey string, pageSize int32,\n\tbookmark string) (shim.StateQueryIteratorInterface, *pb.QueryResponseMetadata, error)\n```\nGetStateByRangeWithPagination mocked\n\n```go\nfunc (stub *MockStub) GetStringArgs() []string\n```\nGetStringArgs get mocked args as strings\n\n```go\nfunc (stub *MockStub) GetTransient() (map[string][]byte, error)\n```\n\n```go\nfunc (stub *MockStub) Init(iargs ...interface{}) peer.Response\n```\nInit func of chaincode - sugared version with autogenerated tx uuid\n\n```go\nfunc (stub *MockStub) InitBytes(args ...[]byte) peer.Response\n```\nInitBytes init func with ...\\[]byte args\n\n```go\nfunc (stub *MockStub) Invoke(funcName string, iargs ...interface{}) peer.Response\n```\nInvoke sugared invoke function with autogenerated tx uuid\n\n```go\nfunc (stub *MockStub) InvokeBytes(args ...[]byte) peer.Response\n```\nInvokeBytes mock invoke with autogenerated tx uuid\n\n```go\nfunc (stub *MockStub) InvokeChaincode(chaincodeName string, args [][]byte, channel string) peer.Response\n```\nInvokeChaincode using another MockStub\n\n```go\nfunc (stub *MockStub) MockCreator(mspID string, certPEM []byte)\n```\nMockCreator of tx\n\n```go\nfunc (stub *MockStub) MockInit(uuid string, args [][]byte) peer.Response\n```\nMockInit mocked init function\n\n```go\nfunc (stub *MockStub) MockInvoke(uuid string, args [][]byte) peer.Response\n```\nMockInvoke\n\n```go\nfunc (stub *MockStub) MockPeerChaincode(invokableChaincodeName string, otherStub *MockStub)\n```\nMockPeerChaincode link to another MockStub\n\n```go\nfunc (stub *MockStub) MockQuery(uuid string, args [][]byte) peer.Response\n```\nMockQuery\n\n```go\nfunc (stub *MockStub) MockTransactionEnd(uuid string)\n```\n\n```go\nfunc (stub *MockStub) MockTransactionStart(uuid string)\n```\n\n```go\nfunc (stub *MockStub) MockedPeerChaincodes() []string\n```\nMockedPeerChaincodes returns names of mocked chaincodes, available for invoke from current stub\n\n```go\nfunc (stub *MockStub) PutPrivateData(collection string, key string, value []byte) error\n```\nPutPrivateData mocked\n\n```go\nfunc (stub *MockStub) PutState(key string, value []byte) error\n```\nPutState wrapped functions puts state items in queue and dumps to state after invocation\n\n```go\nfunc (stub *MockStub) Query(funcName string, iargs ...interface{}) peer.Response\n```\n\n```go\nfunc (stub *MockStub) QueryBytes(args ...[]byte) peer.Response\n```\nQueryBytes mock query with autogenerated tx uuid\n\n```go\nfunc (stub *MockStub) RegisterCreatorTransformer(creatorTransformer CreatorTransformer) *MockStub\n```\nRegisterCreatorTransformer  that transforms creator data to MSP\\_ID and X.509 certificate\n\n```go\nfunc (stub *MockStub) SetArgs(args [][]byte)\n```\nSetArgs set mocked args\n\n```go\nfunc (stub *MockStub) SetEvent(name string, payload []byte) error\n```\nSetEvent sets chaincode event\n\n```go\nfunc (stub *MockStub) WithTransient(transient map[string][]byte) *MockStub\n```\nWithTransient sets transient map\n\n```go\ntype MockedPeer struct {\n\t// channel name -\u003e chaincode name\n\tChannelCC ChannelsMockStubs\n\t// contains filtered or unexported fields\n}\n```\n\n```go\nfunc NewPeer() *MockedPeer\n```\nNewPeer implements Peer interface\n\n```go\nfunc (m *MockedPeer) Blocks(\n\tctx context.Context,\n\tchannelName string,\n\tidentity msp.SigningIdentity,\n\tblockRange ...int64,\n) (blockChan \u003c-chan *common.Block, closer func() error, err error)\n```\n\n```go\nfunc (mp *MockedPeer) Chaincode(channel string, chaincode string) (*MockStub, error)\n```\n\n```go\nfunc (mp *MockedPeer) CurrentIdentity() msp.SigningIdentity\n```\n\n```go\nfunc (mp *MockedPeer) Events(\n\tctx context.Context,\n\tchannel string,\n\tchaincode string,\n\tidentity msp.SigningIdentity,\n\tblockRange ...int64,\n) (events chan interface {\n\tEvent() *peer.ChaincodeEvent\n\tBlock() uint64\n\tTxTimestamp() *timestamp.Timestamp\n}, closer func() error, err error)\n```\n\n```go\nfunc (mp *MockedPeer) Invoke(\n\tctx context.Context,\n\tchannel string,\n\tchaincode string,\n\targs [][]byte,\n\tidentity msp.SigningIdentity,\n\ttransArgs map[string][]byte,\n\ttxWaiterType string) (res *peer.Response, chaincodeTx string, err error)\n```\n\n```go\nfunc (mp *MockedPeer) Query(\n\tctx context.Context,\n\tchannel string,\n\tchaincode string,\n\targs [][]byte,\n\tidentity msp.SigningIdentity,\n\ttransArgs map[string][]byte) (*peer.Response, error)\n```\n\n```go\nfunc (mp *MockedPeer) WithChannel(channel string, mockStubs ...*MockStub) *MockedPeer\n```\n\n```go\ntype MockedPeerDecorator struct {\n\tSDK sdk.SDK\n\n\tInvokeMutator InvokeMutator\n\tQueryMutator  QueryMutator\n}\n```\n\n```go\nfunc NewPeerDecorator(sdk sdk.SDK) *MockedPeerDecorator\n```\n\n```go\nfunc (mpd *MockedPeerDecorator) CurrentIdentity() msp.SigningIdentity\n```\n\n```go\nfunc (mpd *MockedPeerDecorator) Events(\n\tctx context.Context,\n\tchannel string,\n\tchaincode string,\n\tidentity msp.SigningIdentity,\n\tblockRange ...int64,\n) (events chan interface {\n\tEvent() *peer.ChaincodeEvent\n\tBlock() uint64\n\tTxTimestamp() *timestamp.Timestamp\n}, closer func() error, err error)\n```\n\n```go\nfunc (mpd *MockedPeerDecorator) FailChaincode(chaincodes ...string)\n```\n\n```go\nfunc (mpd *MockedPeerDecorator) FailInvoke(chaincodes ...string)\n```\n\n```go\nfunc (mpd *MockedPeerDecorator) FailQuery(chaincodes ...string)\n```\n\n```go\nfunc (mpd *MockedPeerDecorator) Invoke(\n\tctx context.Context,\n\tchannel string,\n\tchaincode string,\n\targs [][]byte,\n\tidentity msp.SigningIdentity,\n\ttransArgs map[string][]byte,\n\ttxWaiterType string) (res *peer.Response, chaincodeTx string, err error)\n```\n\n```go\nfunc (mpd *MockedPeerDecorator) Query(\n\tctx context.Context,\n\tchannel string,\n\tchaincode string,\n\targs [][]byte,\n\tidentity msp.SigningIdentity,\n\ttransArgs map[string][]byte) (*peer.Response, error)\n```\n\n```go\ntype PrivateMockStateRangeQueryIterator struct {\n\tClosed     bool\n\tStub       *MockStub\n\tStartKey   string\n\tEndKey     string\n\tCurrent    *list.Element\n\tCollection string\n}\n```\n\n```go\nfunc NewPrivateMockStateRangeQueryIterator(stub *MockStub, collection string, startKey string, endKey string) *PrivateMockStateRangeQueryIterator\n```\n\n```go\nfunc (iter *PrivateMockStateRangeQueryIterator) Close() error\n```\nClose closes the range query iterator. This should be called when done reading from the iterator to free up resources.\n\n```go\nfunc (iter *PrivateMockStateRangeQueryIterator) HasNext() bool\n```\nHasNext returns true if the range query iterator contains additional keys and values.\n\n```go\nfunc (iter *PrivateMockStateRangeQueryIterator) Next() (*queryresult.KV, error)\n```\nNext returns the next key and value in the range query iterator.\n\n```go\ntype QueryMutator func(\n\tsdk sdk.SDK,\n\tctx context.Context,\n\tchannel string,\n\tchaincode string,\n\targs [][]byte,\n\tidentity msp.SigningIdentity,\n\ttransArgs map[string][]byte) (*peer.Response, error)\n```\n\n```go\ntype ReadFile func(string) ([]byte, error)\n```\n\n```go\ntype StateItem struct {\n\tKey    string\n\tValue  []byte\n\tDelete bool\n}\n```\n\n```go\ntype TxHandler struct {\n\tMockStub *MockStub\n\n\tLogger  *zap.Logger\n\tContext router.Context\n\t// contains filtered or unexported fields\n}\n```\n\n```go\nfunc NewTxHandler(name string) (*TxHandler, router.Context)\n```\n\n```go\nfunc (p *TxHandler) Expect(res interface{}, err error) *expect.TxRes\n```\nExpect returns assertion helper\n\n```go\nfunc (p *TxHandler) From(creator ...interface{}) *TxHandler\n```\n\n```go\nfunc (p *TxHandler) Init(txHdl func(ctx router.Context) (interface{}, error)) *TxResult\n```\n\n```go\nfunc (p *TxHandler) Invoke(invoke func(ctx router.Context) (interface{}, error)) *TxResult\n```\nInvoke emulates chaincode invocation and returns transaction result\n\n```go\nfunc (p *TxHandler) SetTxResult(err error)\n```\nSetTxResult can be used for set txResult error during Tx\n\n```go\nfunc (p *TxHandler) Tx(tx func())\n```\nTx emulates chaincode invocation\n\n```go\nfunc (p *TxHandler) TxEvent() *peer.ChaincodeEvent\n```\nTxEvent returns last tx event\n\n```go\nfunc (p *TxHandler) TxFunc(tx func()) func()\n```\nTxFunc returns tx closure, can be used directly as ginkgo func\n\n```go\nfunc (p *TxHandler) TxTimestamp() *timestamp.Timestamp\n```\nTxTimestamp returns last tx timestamp\n\n```go\ntype TxResult struct {\n\tResult interface{}\n\tErr    error\n\tEvent  *peer.ChaincodeEvent\n}\n```\n\n```go\nfunc (r *TxResult) Expect() *expect.TxRes\n```\n\n","path":"github.com/s7techlab/cckit/testing","name":"testing","synopsis":"","isRedistributable":true}
