mock

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2021 License: MIT Imports: 23 Imported by: 0

Documentation

Overview

Package mock provides mock methods to simulate how a peer node interact with CouchDB and simulate a transaction proposal. This does not requires a working Fabric Peer like FabricSDK but require connection to a remote CouchDB instance.

The workflow is as follow

1) Create a core.yaml follow similar template in test/contract/core.yaml, remember to change the configuration of the couchDB as you need

2) Create a NewMockStubExtend object that point to the core.yaml and the smart contract object

3) Process Indexes (if need)

4) Perform MockInvokeTransaction

For more details, please find test example in the README file

Index

Constants

View Source
const (
	// The couchDB test will have this name: DefaultChannelName_chaincodeName
	DefaultChannelName = "testchannel" // Fabric channel
)

Variables

This section is empty.

Functions

func MockInitTransaction

func MockInitTransaction(t *testing.T, stub *MockStubExtend, args [][]byte) string

MockIInit creates a mock invoke transaction using MockStubExtend

func MockInvokeTransaction

func MockInvokeTransaction(t *testing.T, stub *MockStubExtend, args [][]byte) string

MockInvokeTransaction creates a mock invoke transaction using MockStubExtend

func MockQueryTransaction

func MockQueryTransaction(t *testing.T, stub *MockStubExtend, args [][]byte) string

MockQueryTransaction creates a mock query transaction using MockStubExtend

Types

type AkcQueryIterator

type AkcQueryIterator struct {
	*StateQueryIterator
	// contains filtered or unexported fields
}

AkcQueryIterator inherits StateQueryIterator to simulate how the peer handle query string response

func FromResultsIterator

func FromResultsIterator(rit statedb.ResultsIterator) (*AkcQueryIterator, error)

FromResultsIterator provides a way of converting ResultsIterator into StateQueryIterator

func (*AkcQueryIterator) Close

func (it *AkcQueryIterator) Close() error

func (*AkcQueryIterator) HasNext

func (it *AkcQueryIterator) HasNext() bool

func (*AkcQueryIterator) Length

func (it *AkcQueryIterator) Length() int

func (*AkcQueryIterator) Next

func (it *AkcQueryIterator) Next() (*queryresult.KV, error)

type CouchDBHandler

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

CouchDBHandler holds 1 parameter: dbEngine: a VersionedDB object that is used by the chaincode to query. This is to guarantee that the test uses the same logic in interaction with stateDB as the chaincode. This also includes how chaincode builds its query to interact with the stateDB.

func NewCouchDBHandler

func NewCouchDBHandler(isDrop bool, ccName string) (*CouchDBHandler, error)

NewCouchDBHandler returns a new CouchDBHandler and setup database for testing

func (*CouchDBHandler) ProcessIndexesForChaincodeDeploy

func (handler *CouchDBHandler) ProcessIndexesForChaincodeDeploy(path string) error

ProcessIndexesForChaincodeDeploy creates indexes for a database. We will need the name of the json index fil and the relative path to this file

func (*CouchDBHandler) QueryDocument

func (handler *CouchDBHandler) QueryDocument(query string) (statedb.ResultsIterator, error)

QueryDocument executes a query string and return results

func (*CouchDBHandler) QueryDocumentByRange

func (handler *CouchDBHandler) QueryDocumentByRange(startKey, endKey string) (statedb.ResultsIterator, error)

QueryDocumentByRange get a list of documents from couchDB by key range

func (*CouchDBHandler) QueryDocumentWithPagination

func (handler *CouchDBHandler) QueryDocumentWithPagination(query string, limit int32, bookmark string) (statedb.ResultsIterator, error)

QueryDocumentWithPagination executes a query string and return results

func (*CouchDBHandler) ReadDocument

func (handler *CouchDBHandler) ReadDocument(id string) ([]byte, error)

ReadDocument executes a query string and return results

func (*CouchDBHandler) SaveDocument

func (handler *CouchDBHandler) SaveDocument(key string, value []byte) error

SaveDocument stores a value in couchDB

type MockStubExtend

type MockStubExtend struct {
	CouchDB   bool            // if we use couchDB
	DbHandler *CouchDBHandler // if we use couchDB
	*shimtest.MockStub
	// contains filtered or unexported fields
}

MockStubExtend provides composition class for MockStub as some of the mockstub methods are not implemented

func NewMockStubExtend

func NewMockStubExtend(stub *shimtest.MockStub, cc shim.Chaincode, configPath string) *MockStubExtend

NewMockStubExtend creates a new MockStubExtend object. You must set config path to the directory contains core.yaml file.

func (*MockStubExtend) GetFunctionAndParameters

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

GetFunctionAndParameters Override this function from MockStub

func (*MockStubExtend) GetQueryResult

func (stub *MockStubExtend) GetQueryResult(query string) (shim.StateQueryIteratorInterface, error)

GetQueryResult overrides the same function in MockStub that did not implement anything.

func (*MockStubExtend) GetQueryResultWithPagination

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

GetQueryResultWithPagination overrides the same function in MockStub that did not implement anything.

func (*MockStubExtend) GetState

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

GetState retrieves the value for a given key from the ledger

func (*MockStubExtend) GetStateByPartialCompositeKey

func (stub *MockStubExtend) GetStateByPartialCompositeKey(objectType string, attributes []string) (shim.StateQueryIteratorInterface, error)

GetStateByPartialCompositeKey queries couchdb by range

func (*MockStubExtend) GetStateOriginal

func (stub *MockStubExtend) GetStateOriginal(key string) ([]byte, error)

GetStateOriginal is copied from mockstub as we still need to carry on normal GetState operation with the mock ledger map

func (*MockStubExtend) GetStringArgs

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

GetStringArgs override this function from MockStub

func (*MockStubExtend) MockInit

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

MockInit Override this function from MockStub

func (*MockStubExtend) MockInvoke

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

MockInvoke Override this function from MockStub

func (*MockStubExtend) PutState

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

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

func (*MockStubExtend) SetCouchDBConfiguration

func (stub *MockStubExtend) SetCouchDBConfiguration(handler *CouchDBHandler)

SetCouchDBConfiguration sets the couchdb configuration with appropriate database handler

type TarFileEntry added in v1.0.1

type TarFileEntry struct {
	Name, Body string
}

TarFileEntry is a structure for adding test index files to an tar

Jump to

Keyboard shortcuts

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