MockCCComm implements the mock communication between chaincode and peer We'd need two MockCCComm for communication. The receiver and sender will be switched between the two.
type MockCCComm struct {
// contains filtered or unexported fields
}
func (s *MockCCComm) CloseSend() error
CloseSend closes send
func (s *MockCCComm) GetRecvStream() chan *pb.ChaincodeMessage
GetRecvStream returns the recvStream
func (s *MockCCComm) GetSendStream() chan *pb.ChaincodeMessage
GetSendStream returns the sendStream
func (s *MockCCComm) Quit()
Quit closes the channels...
func (s *MockCCComm) Recv() (*pb.ChaincodeMessage, error)
Recv receives a message
func (s *MockCCComm) Run(done <-chan struct{}) error
Run receives and sends indefinitely
func (s *MockCCComm) Send(msg *pb.ChaincodeMessage) error
Send sends a message
func (s *MockCCComm) SetBailOnError(b bool)
SetBailOnError will cause Run to return on any error
func (s *MockCCComm) SetKeepAlive(ka *pb.ChaincodeMessage)
SetKeepAlive sets keepalive. This mut be done on the server only
func (s *MockCCComm) SetName(newname string)
func (s *MockCCComm) SetPong(val bool)
SetPong pongs received keepalive. This mut be done on the chaincode only
func (s *MockCCComm) SetResponses(respSet *MockResponseSet)
SetResponses sets responses for an Init or Invoke
MockPeerCCSupport provides CC support for peer interfaces.
type MockPeerCCSupport struct {
// contains filtered or unexported fields
}
func NewMockPeerSupport() *MockPeerCCSupport
NewMockPeerSupport getsa mock peer support
func (mp *MockPeerCCSupport) AddCC(name string, recv chan *pb.ChaincodeMessage, send chan *pb.ChaincodeMessage) (*MockCCComm, error)
AddCC adds a cc to the MockPeerCCSupport
func (mp *MockPeerCCSupport) GetCC(name string) (*MockCCComm, error)
GetCC gets a cc from the MockPeerCCSupport
func (mp *MockPeerCCSupport) GetCCMirror(name string) *MockCCComm
GetCCMirror creates a MockCCStream with streans switched
func (mp *MockPeerCCSupport) RemoveAll() error
RemoveAll removes all ccs
func (mp *MockPeerCCSupport) RemoveCC(name string) error
RemoveCC removes a cc
MockResponse contains the expected received message (optional) and response to send (optional)
type MockResponse struct { RecvMsg *pb.ChaincodeMessage RespMsg interface{} }
MockResponseSet is used for processing CC to Peer comm such as GET/PUT/DEL state. The MockResponse contains the response to be returned for each input received.from the CC. Every stub call will generate a response
type MockResponseSet struct { //DoneFunc is invoked when all I/O is done for this //response set DoneFunc func(int, error) //ErrorFunc is invoked at any step when the input does not //match the received message ErrorFunc func(int, error) //Responses contained the expected received message (optional) //and response to send (optional) Responses []*MockResponse }