mocking

package
v0.0.0-...-82cad83 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2023 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MockChaincodeStub

type MockChaincodeStub 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 MockChaincodeStub chaincodes that can be called from this MockChaincodeStub
	Invokables map[string]*MockChaincodeStub

	// 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
}

MockChaincodeStub implements the ChaincodeStubInterface for unit testing chaincode.

func NewMockChaincodeStub

func NewMockChaincodeStub(name string, cc shim.Chaincode, transient map[string][]byte) *MockChaincodeStub

NewMockChaincodeStub Constructor to initialise the internal State map

func (*MockChaincodeStub) CreateCompositeKey

func (m *MockChaincodeStub) CreateCompositeKey(objectType string, attributes []string) (string, error)

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

func (*MockChaincodeStub) DelPrivateData

func (m *MockChaincodeStub) DelPrivateData(collection string, key string) error

DelPrivateData ...

func (*MockChaincodeStub) DelState

func (m *MockChaincodeStub) DelState(key string) error

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

func (*MockChaincodeStub) GetArgs

func (m *MockChaincodeStub) GetArgs() [][]byte

GetArgs ...

func (*MockChaincodeStub) GetArgsSlice

func (m *MockChaincodeStub) GetArgsSlice() ([]byte, error)

GetArgsSlice Not implemented ...

func (*MockChaincodeStub) GetBinding

func (m *MockChaincodeStub) GetBinding() ([]byte, error)

GetBinding Not implemented ...

func (*MockChaincodeStub) GetChannelID

func (m *MockChaincodeStub) GetChannelID() string

GetChannelID ...

func (*MockChaincodeStub) GetCreator

func (m *MockChaincodeStub) GetCreator() ([]byte, error)

GetCreator ...

func (*MockChaincodeStub) GetDecorations

func (m *MockChaincodeStub) GetDecorations() map[string][]byte

GetDecorations ...

func (*MockChaincodeStub) GetFunctionAndParameters

func (m *MockChaincodeStub) GetFunctionAndParameters() (function string, params []string)

GetFunctionAndParameters ...

func (*MockChaincodeStub) GetHistoryForKey

func (m *MockChaincodeStub) 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 (*MockChaincodeStub) GetPrivateData

func (m *MockChaincodeStub) GetPrivateData(collection string, key string) ([]byte, error)

GetPrivateData ...

func (*MockChaincodeStub) GetPrivateDataByPartialCompositeKey

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

GetPrivateDataByPartialCompositeKey ...

func (*MockChaincodeStub) GetPrivateDataByRange

func (m *MockChaincodeStub) GetPrivateDataByRange(collection, startKey, endKey string) (shim.StateQueryIteratorInterface, error)

GetPrivateDataByRange ...

func (*MockChaincodeStub) GetPrivateDataHash

func (m *MockChaincodeStub) GetPrivateDataHash(collection, key string) ([]byte, error)

GetPrivateDataHash ...

func (*MockChaincodeStub) GetPrivateDataQueryResult

func (m *MockChaincodeStub) GetPrivateDataQueryResult(collection, query string) (shim.StateQueryIteratorInterface, error)

GetPrivateDataQueryResult ...

func (*MockChaincodeStub) GetPrivateDataValidationParameter

func (m *MockChaincodeStub) GetPrivateDataValidationParameter(collection, key string) ([]byte, error)

GetPrivateDataValidationParameter ...

func (*MockChaincodeStub) GetQueryResult

func (m *MockChaincodeStub) 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 (*MockChaincodeStub) GetQueryResultWithPagination

func (m *MockChaincodeStub) GetQueryResultWithPagination(query string, pageSize int32,
	bookmark string) (shim.StateQueryIteratorInterface, *pb.QueryResponseMetadata, error)

GetQueryResultWithPagination ...

func (*MockChaincodeStub) GetSignedProposal

func (m *MockChaincodeStub) GetSignedProposal() (*pb.SignedProposal, error)

GetSignedProposal ...

func (*MockChaincodeStub) GetState

func (m *MockChaincodeStub) GetState(key string) (value []byte, err error)

GetState retrieves the value for a given key from the ledger

func (*MockChaincodeStub) GetStateByPartialCompositeKey

func (m *MockChaincodeStub) 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 (*MockChaincodeStub) GetStateByPartialCompositeKeyWithPagination

func (m *MockChaincodeStub) GetStateByPartialCompositeKeyWithPagination(objectType string, keys []string,
	pageSize int32, bookmark string) (shim.StateQueryIteratorInterface, *pb.QueryResponseMetadata, error)

GetStateByPartialCompositeKeyWithPagination ...

func (*MockChaincodeStub) GetStateByRange

func (m *MockChaincodeStub) GetStateByRange(startKey, endKey string) (shim.StateQueryIteratorInterface, error)

GetStateByRange ...

func (*MockChaincodeStub) GetStateByRangeWithPagination

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

GetStateByRangeWithPagination ...

func (*MockChaincodeStub) GetStateValidationParameter

func (m *MockChaincodeStub) GetStateValidationParameter(key string) ([]byte, error)

GetStateValidationParameter ...

func (*MockChaincodeStub) GetStringArgs

func (m *MockChaincodeStub) GetStringArgs() []string

GetStringArgs ...

func (*MockChaincodeStub) GetTransient

func (m *MockChaincodeStub) GetTransient() (map[string][]byte, error)

GetTransient ...

func (*MockChaincodeStub) GetTxID

func (m *MockChaincodeStub) GetTxID() string

GetTxID ...

func (*MockChaincodeStub) GetTxTimestamp

func (m *MockChaincodeStub) GetTxTimestamp() (*timestamp.Timestamp, error)

GetTxTimestamp ...

func (*MockChaincodeStub) InvokeChaincode

func (m *MockChaincodeStub) 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 MockChaincodeStub stub2, call shim.NewMockChaincodeStub("othercc", Chaincode) and register it with stub1 by calling stub1.MockPeerChaincode("othercc", stub2, channel)

func (*MockChaincodeStub) MockInvoke

func (m *MockChaincodeStub) MockInvoke(uuid string, args [][]byte) pb.Response

MockInvoke Invoke this chaincode, also starts and ends a transaction.

func (*MockChaincodeStub) MockTransactionEnd

func (m *MockChaincodeStub) MockTransactionEnd(uuid string)

MockTransactionEnd End a mocked transaction, clearing the UUID.

func (*MockChaincodeStub) MockTransactionStart

func (m *MockChaincodeStub) 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. MockChaincodeStub doesn't support concurrent transactions at present.

func (*MockChaincodeStub) PutPrivateData

func (m *MockChaincodeStub) PutPrivateData(collection string, key string, value []byte) error

PutPrivateData ...

func (*MockChaincodeStub) PutState

func (m *MockChaincodeStub) PutState(key string, value []byte) error

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

func (*MockChaincodeStub) SetEvent

func (m *MockChaincodeStub) SetEvent(name string, payload []byte) error

SetEvent ...

func (*MockChaincodeStub) SetPrivateDataValidationParameter

func (m *MockChaincodeStub) SetPrivateDataValidationParameter(collection, key string, ep []byte) error

SetPrivateDataValidationParameter ...

func (*MockChaincodeStub) SetStateValidationParameter

func (m *MockChaincodeStub) SetStateValidationParameter(key string, ep []byte) error

SetStateValidationParameter ...

func (*MockChaincodeStub) SplitCompositeKey

func (m *MockChaincodeStub) SplitCompositeKey(compositeKey string) (string, []string, error)

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

type MockClientIdentity

type MockClientIdentity struct {
	// contains filtered or unexported fields
}

MockClientIdentity Implements the ClientIdentity interface for unit testing chaincode.

func NewMockClientIdentity

func NewMockClientIdentity(stub shim.ChaincodeStubInterface, mspID string, cert *x509.Certificate, attrs *attrmgr.Attributes) *MockClientIdentity

func (*MockClientIdentity) AssertAttributeValue

func (m *MockClientIdentity) AssertAttributeValue(string, string) error

func (*MockClientIdentity) GetAttributeValue

func (m *MockClientIdentity) GetAttributeValue(string) (string, bool, error)

func (*MockClientIdentity) GetID

func (m *MockClientIdentity) GetID() (string, error)

func (*MockClientIdentity) GetMSPID

func (m *MockClientIdentity) GetMSPID() (string, error)

func (*MockClientIdentity) GetX509Certificate

func (m *MockClientIdentity) GetX509Certificate() (*x509.Certificate, error)

type MockStateRangeQueryIterator

type MockStateRangeQueryIterator struct {
	Closed   bool
	Stub     *MockChaincodeStub
	StartKey string
	EndKey   string
	Current  *list.Element
}

MockStateRangeQueryIterator ...

func NewMockStateRangeQueryIterator

func NewMockStateRangeQueryIterator(m *MockChaincodeStub, 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 MockTransactionContext

type MockTransactionContext struct {
	// contains filtered or unexported fields
}

MockTransactionContext implements the TransactionContextInterface for unit testing chaincode.

func (*MockTransactionContext) GetClientIdentity

func (t *MockTransactionContext) GetClientIdentity() cid.ClientIdentity

func (*MockTransactionContext) GetStub

Jump to

Keyboard shortcuts

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