Skip to content

Commit 0b78ca0

Browse files
committed
[FAB-9084] MockStub extensions
This change set includes support for GetPrivateData and PutPrivateData. Change-Id: I15704f09722be7e4a139461dcfea8db7f574bbbf Signed-off-by: Alessandro Sorniotti <ale.linux@sopit.net>
1 parent 2e0c661 commit 0b78ca0

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

core/chaincode/shim/mockstub.go

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ type MockStub struct {
5757

5858
// stores a channel ID of the proposal
5959
ChannelID string
60+
61+
PvtState map[string]map[string][]byte
6062
}
6163

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

148150
func (stub *MockStub) GetPrivateData(collection string, key string) ([]byte, error) {
149-
return nil, errors.New("Not Implemented")
151+
m, in := stub.PvtState[collection]
152+
153+
if !in {
154+
return nil, nil
155+
}
156+
157+
return m[key], nil
150158
}
151159

152160
func (stub *MockStub) PutPrivateData(collection string, key string, value []byte) error {
153-
return errors.New("Not Implemented")
161+
m, in := stub.PvtState[collection]
162+
if !in {
163+
stub.PvtState[collection] = make(map[string][]byte)
164+
m, in = stub.PvtState[collection]
165+
}
166+
167+
m[key] = value
168+
169+
return nil
154170
}
155171

156172
func (stub *MockStub) DelPrivateData(collection string, key string) error {
@@ -358,6 +374,7 @@ func NewMockStub(name string, cc Chaincode) *MockStub {
358374
s.Name = name
359375
s.cc = cc
360376
s.State = make(map[string][]byte)
377+
s.PvtState = make(map[string]map[string][]byte)
361378
s.Invokables = make(map[string]*MockStub)
362379
s.Keys = list.New()
363380

0 commit comments

Comments
 (0)