Skip to content

Commit

Permalink
[FAB-4375] Update MockEndorserServer
Browse files Browse the repository at this point in the history
Update MockEndorserServer to return nsReadWriteSet in ProposalResponsePayload
to allowed the unit test to check the ReadWriteSet in Proposal Response

Change-Id: Iad98c81b9ba65b3fb3170e7c80ea4e6764526d7b
Signed-off-by: Firas Qutishat <[email protected]>
  • Loading branch information
fqutishat committed Jun 5, 2017
1 parent 9c0f71b commit b288855
Show file tree
Hide file tree
Showing 9 changed files with 1,215 additions and 1 deletion.
36 changes: 35 additions & 1 deletion fabric-client/mocks/mockendorserserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,17 @@ limitations under the License.
package mocks

import (
"github.com/golang/protobuf/proto"
"golang.org/x/net/context"

"github.com/hyperledger/fabric/core/ledger/kvledger/txmgmt/rwset"
pb "github.com/hyperledger/fabric/protos/peer"
)

// MockEndorserServer mock endoreser server to process endorsement proposals
type MockEndorserServer struct {
ProposalError error
AddkvWrite bool
}

// ProcessProposal mock implementation that returns success if error is not set
Expand All @@ -37,10 +40,41 @@ func (m *MockEndorserServer) ProcessProposal(context context.Context,
if m.ProposalError == nil {
return &pb.ProposalResponse{Response: &pb.Response{
Status: 200,
}}, nil
}, Endorsement: &pb.Endorsement{Endorser: []byte("endorser"), Signature: []byte("signature")},
Payload: m.createProposalResponsePayload()}, nil
}
return &pb.ProposalResponse{Response: &pb.Response{
Status: 500,
Message: m.ProposalError.Error(),
}}, m.ProposalError
}

func (m *MockEndorserServer) createProposalResponsePayload() []byte {

prp := &pb.ProposalResponsePayload{}
ccAction := &pb.ChaincodeAction{}
var nsReadWriteSet []*rwset.NsReadWriteSet
var kvWrite []*rwset.KVWrite
if m.AddkvWrite {
kvWrite = append(kvWrite, &rwset.KVWrite{Key: "write", Value: []byte("value")})
} else {
kvWrite = nil
}
nsReadWriteSet = append(nsReadWriteSet, &rwset.NsReadWriteSet{Writes: kvWrite})
txRWSet := &rwset.TxReadWriteSet{NsRWs: nsReadWriteSet}
txRWSetBytes, err := txRWSet.Marshal()
if err != nil {
return nil
}
ccAction.Results = txRWSetBytes
ccActionBytes, err := proto.Marshal(ccAction)
if err != nil {
return nil
}
prp.Extension = ccActionBytes
prpBytes, err := proto.Marshal(prp)
if err != nil {
return nil
}
return prpBytes
}
99 changes: 99 additions & 0 deletions vendor/github.com/hyperledger/fabric/common/ledger/util/ioutil.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

62 changes: 62 additions & 0 deletions vendor/github.com/hyperledger/fabric/common/ledger/util/util.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit b288855

Please sign in to comment.