Skip to content

Commit

Permalink
[FAB-9084] MockStub extensions
Browse files Browse the repository at this point in the history
This change set includes support for GetPrivateData and
PutPrivateData.

Change-Id: I15704f09722be7e4a139461dcfea8db7f574bbbf
Signed-off-by: Alessandro Sorniotti <[email protected]>
  • Loading branch information
ale-linux committed Mar 23, 2018
1 parent 2e0c661 commit 0b78ca0
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions core/chaincode/shim/mockstub.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ type MockStub struct {

// stores a channel ID of the proposal
ChannelID string

PvtState map[string]map[string][]byte
}

func (stub *MockStub) GetTxID() string {
Expand Down Expand Up @@ -146,11 +148,25 @@ func (stub *MockStub) MockInvokeWithSignedProposal(uuid string, args [][]byte, s
}

func (stub *MockStub) GetPrivateData(collection string, key string) ([]byte, error) {
return nil, errors.New("Not Implemented")
m, in := stub.PvtState[collection]

if !in {
return nil, nil
}

return m[key], nil
}

func (stub *MockStub) PutPrivateData(collection string, key string, value []byte) error {
return errors.New("Not Implemented")
m, in := stub.PvtState[collection]
if !in {
stub.PvtState[collection] = make(map[string][]byte)
m, in = stub.PvtState[collection]
}

m[key] = value

return nil
}

func (stub *MockStub) DelPrivateData(collection string, key string) error {
Expand Down Expand Up @@ -358,6 +374,7 @@ func NewMockStub(name string, cc Chaincode) *MockStub {
s.Name = name
s.cc = cc
s.State = make(map[string][]byte)
s.PvtState = make(map[string]map[string][]byte)
s.Invokables = make(map[string]*MockStub)
s.Keys = list.New()

Expand Down

0 comments on commit 0b78ca0

Please sign in to comment.