mock

package
v0.0.0-...-03d50b6 Latest Latest
Warning

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

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

Documentation

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
}

func NewMockStateRangeQueryIterator

func NewMockStateRangeQueryIterator(stub *MockStub, startKey string, endKey string) *MockStateRangeQueryIterator

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.

func (*MockStateRangeQueryIterator) Print

func (iter *MockStateRangeQueryIterator) Print()

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

	Decorations map[string][]byte

	Creator []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

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

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

func (*MockStub) GetArgsSlice

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

Not implemented

func (*MockStub) GetBinding

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

Not implemented

func (*MockStub) GetChannelID

func (stub *MockStub) GetChannelID() string

func (*MockStub) GetCreator

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

Not implemented

func (*MockStub) GetDecorations

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

func (*MockStub) GetFunctionAndParameters

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

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)

func (*MockStub) GetPrivateDataByPartialCompositeKey

func (stub *MockStub) GetPrivateDataByPartialCompositeKey(collection, objectType string, attributes []string) (shim.StateQueryIteratorInterface, error)

func (*MockStub) GetPrivateDataByRange

func (stub *MockStub) GetPrivateDataByRange(collection, startKey, endKey string) (shim.StateQueryIteratorInterface, error)

func (*MockStub) GetPrivateDataHash

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

func (*MockStub) GetPrivateDataQueryResult

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

func (*MockStub) GetPrivateDataValidationParameter

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

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)

func (*MockStub) GetSignedProposal

func (stub *MockStub) GetSignedProposal() (*pb.SignedProposal, error)

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)

func (*MockStub) GetStateByRange

func (stub *MockStub) GetStateByRange(startKey, endKey string) (shim.StateQueryIteratorInterface, error)

func (*MockStub) GetStateByRangeWithPagination

func (stub *MockStub) GetStateByRangeWithPagination(startKey, endKey string, pageSize int32,
	bookmark string) (shim.StateQueryIteratorInterface, *pb.QueryResponseMetadata, error)

func (*MockStub) GetStateValidationParameter

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

func (*MockStub) GetStringArgs

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

func (*MockStub) GetTransient

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

Not implemented

func (*MockStub) GetTxID

func (stub *MockStub) GetTxID() string

func (*MockStub) GetTxTimestamp

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

func (*MockStub) InvokeChaincode

func (stub *MockStub) InvokeChaincode(chaincodeName string, args [][]byte, channel string) pb.Response

InvokeChaincode calls a peered chaincode. E.g. stub1.InvokeChaincode("stub2Hash", funcArgs, channel) Before calling this make sure to create another MockStub stub2, call stub2.MockInit(uuid, func, args) and register it with stub1 by calling stub1.MockPeerChaincode("stub2Hash", stub2)

func (*MockStub) MockInit

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

Initialise this chaincode, also starts and ends a transaction.

func (*MockStub) MockInvoke

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

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

Invoke this chaincode, also starts and ends a transaction.

func (*MockStub) MockPeerChaincode

func (stub *MockStub) MockPeerChaincode(invokableChaincodeName string, otherStub *MockStub)

Register a peer chaincode with this MockStub invokableChaincodeName is the name or hash of the peer otherStub is a MockStub of the peer, already intialised

func (*MockStub) MockTransactionEnd

func (stub *MockStub) MockTransactionEnd(uuid string)

End a mocked transaction, clearing the UUID.

func (*MockStub) MockTransactionStart

func (stub *MockStub) MockTransactionStart(txid string)

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

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

func (*MockStub) SetPrivateDataValidationParameter

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

func (*MockStub) SetStateValidationParameter

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

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