shimtest

package
v0.0.0-...-b6cadcb Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 27, 2020 License: Apache-2.0 Imports: 10 Imported by: 0

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

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

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

func NewMockStub(name string, cc shim.Chaincode) *MockStub

NewMockStub Constructor to initialise the internal State map

func (*MockStub) CreateCompositeKey

func (stub *MockStub) CreateCompositeKey(objectType string, attributes []string) (string, error)

CreateCompositeKey combines the list of attributes to form a composite key.

func (*MockStub) DelPrivateData

func (stub *MockStub) DelPrivateData(collection string, key string) error

DelPrivateData ...

func (*MockStub) DelState

func (stub *MockStub) DelState(key string) error

DelState removes the specified `key` and its value from the ledger.

func (*MockStub) GetArgs

func (stub *MockStub) GetArgs() [][]byte

GetArgs ...

func (*MockStub) GetArgsSlice

func (stub *MockStub) GetArgsSlice() ([]byte, error)

GetArgsSlice Not implemented ...

func (*MockStub) GetBinding

func (stub *MockStub) GetBinding() ([]byte, error)

GetBinding Not implemented ...

func (*MockStub) GetChannelID

func (stub *MockStub) GetChannelID() string

GetChannelID ...

func (*MockStub) GetCreator

func (stub *MockStub) GetCreator() ([]byte, error)

GetCreator ...

func (*MockStub) GetDecorations

func (stub *MockStub) GetDecorations() map[string][]byte

GetDecorations ...

func (*MockStub) GetFunctionAndParameters

func (stub *MockStub) GetFunctionAndParameters() (function string, params []string)

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

func (stub *MockStub) GetPrivateData(collection string, key string) ([]byte, error)

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

func (stub *MockStub) GetPrivateDataHash(collection, key string) ([]byte, error)

GetPrivateDataHash ...

func (*MockStub) GetPrivateDataQueryResult

func (stub *MockStub) GetPrivateDataQueryResult(collection, query string) (shim.StateQueryIteratorInterface, error)

GetPrivateDataQueryResult ...

func (*MockStub) GetPrivateDataValidationParameter

func (stub *MockStub) GetPrivateDataValidationParameter(collection, key string) ([]byte, error)

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) GetState

func (stub *MockStub) GetState(key string) ([]byte, error)

GetState retrieves the value for a given key from the ledger

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

func (stub *MockStub) GetStateValidationParameter(key string) ([]byte, error)

GetStateValidationParameter ...

func (*MockStub) GetStringArgs

func (stub *MockStub) GetStringArgs() []string

GetStringArgs ...

func (*MockStub) GetTransient

func (stub *MockStub) GetTransient() (map[string][]byte, error)

GetTransient Not implemented ...

func (*MockStub) GetTxID

func (stub *MockStub) GetTxID() string

GetTxID ...

func (*MockStub) GetTxTimestamp

func (stub *MockStub) GetTxTimestamp() (*timestamp.Timestamp, error)

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) MockInit

func (stub *MockStub) MockInit(uuid string, args [][]byte) pb.Response

MockInit Initialise this chaincode, also starts and ends a transaction.

func (*MockStub) MockInvoke

func (stub *MockStub) MockInvoke(uuid string, args [][]byte) pb.Response

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

func (stub *MockStub) MockTransactionEnd(uuid string)

MockTransactionEnd End a mocked transaction, clearing the UUID.

func (*MockStub) MockTransactionStart

func (stub *MockStub) MockTransactionStart(txid string)

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

func (stub *MockStub) PutPrivateData(collection string, key string, value []byte) error

PutPrivateData ...

func (*MockStub) PutState

func (stub *MockStub) PutState(key string, value []byte) error

PutState writes the specified `value` and `key` into the ledger.

func (*MockStub) SetEvent

func (stub *MockStub) SetEvent(name string, payload []byte) error

SetEvent ...

func (*MockStub) SetPrivateDataValidationParameter

func (stub *MockStub) SetPrivateDataValidationParameter(collection, key string, ep []byte) error

SetPrivateDataValidationParameter ...

func (*MockStub) SetStateValidationParameter

func (stub *MockStub) SetStateValidationParameter(key string, ep []byte) error

SetStateValidationParameter ...

func (*MockStub) SplitCompositeKey

func (stub *MockStub) SplitCompositeKey(compositeKey string) (string, []string, error)

SplitCompositeKey splits the composite key into attributes on which the composite key was formed.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL