Skip to content

Commit

Permalink
[FAB-4208] proper UT for chaincode framework
Browse files Browse the repository at this point in the history
Replaces the heavyweight chaincode framework tests that
need a full fledged peer and container env for testing with
a lightweight UT tests using a mock environment. The CC side
and some of the ledger interfaces are mocked.

Also disables other tests in the framework so the community
can get a feel for the coverage and speedup

. renamed cc_test.go to chaincode_support_test.go
. add some minor tests
. added some error refactoring in handler.go

Change-Id: I462f05f7a78b7b2cfbb20138a20c5c0ee45a9be4
Signed-off-by: Srinivasan Muralidharan <muralisr@us.ibm.com>
  • Loading branch information
Srinivasan Muralidharan committed May 30, 2017
1 parent 3079333 commit 6860586
Show file tree
Hide file tree
Showing 7 changed files with 801 additions and 116 deletions.
18 changes: 16 additions & 2 deletions common/mocks/peer/mockccstream.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ type MockResponseSet struct {
//and response to send (optional)
type MockResponse struct {
RecvMsg *pb.ChaincodeMessage
RespMsg *pb.ChaincodeMessage
RespMsg interface{}
}

// MockCCComm implements the mock communication between chaincode and peer
Expand All @@ -60,6 +60,10 @@ type MockCCComm struct {
respSet *MockResponseSet
}

func (s *MockCCComm) SetName(newname string) {
s.name = newname
}

//Send sends a message
func (s *MockCCComm) Send(msg *pb.ChaincodeMessage) error {
s.sendStream <- msg
Expand Down Expand Up @@ -143,7 +147,17 @@ func (s *MockCCComm) respond(msg *pb.ChaincodeMessage) error {
}

if mockResp.RespMsg != nil {
err = s.Send(mockResp.RespMsg)
var ccMsg *pb.ChaincodeMessage
if ccMsg, _ = mockResp.RespMsg.(*pb.ChaincodeMessage); ccMsg == nil {
if ccMsgFunc, ok := mockResp.RespMsg.(func(*pb.ChaincodeMessage) *pb.ChaincodeMessage); ok && ccMsgFunc != nil {
ccMsg = ccMsgFunc(msg)
}
}

if ccMsg == nil {
panic("----no pb.ChaincodeMessage---")
}
err = s.Send(ccMsg)
}

s.respIndex = s.respIndex + 1
Expand Down
Loading

0 comments on commit 6860586

Please sign in to comment.