@@ -55,7 +55,23 @@ func TestPeersForEndorsement(t *testing.T) {
55
55
newPeer (12 ),
56
56
}
57
57
58
- identities := alivePeers .toIdentitySet ()
58
+ pkiID2MSPID := map [string ]string {
59
+ "p0" : "Org1MSP" ,
60
+ "p1" : "Org1MSP" ,
61
+ "p2" : "Org1MSP" ,
62
+ "p3" : "Org1MSP" ,
63
+ "p4" : "Org1MSP" ,
64
+ "p5" : "Org2MSP" ,
65
+ "p6" : "Org2MSP" ,
66
+ "p7" : "Org2MSP" ,
67
+ "p8" : "Org2MSP" ,
68
+ "p9" : "Org2MSP" ,
69
+ "p10" : "Org2MSP" ,
70
+ "p11" : "Org2MSP" ,
71
+ "p12" : "Org2MSP" ,
72
+ }
73
+
74
+ identities := identitySet (pkiID2MSPID )
59
75
60
76
chanPeers := peerSet {
61
77
newPeer (0 ).withChaincode (cc , "1.0" ),
@@ -71,7 +87,7 @@ func TestPeersForEndorsement(t *testing.T) {
71
87
// Scenario I: Policy isn't found
72
88
pf .On ("PolicyByChaincode" , ccWithMissingPolicy ).Return (nil ).Once ()
73
89
analyzer := NewEndorsementAnalyzer (g , pf , & principalEvaluatorMock {}, mf )
74
- desc , err := analyzer .PeersForEndorsement (ccWithMissingPolicy , channel )
90
+ desc , err := analyzer .PeersForEndorsement (channel , & discovery2. ChaincodeInterest { ChaincodeNames : [] string { ccWithMissingPolicy }} )
75
91
assert .Nil (t , desc )
76
92
assert .Equal (t , "policy not found" , err .Error ())
77
93
@@ -88,9 +104,9 @@ func TestPeersForEndorsement(t *testing.T) {
88
104
Principal : []byte ("p11" ),
89
105
}).buildPolicy ()
90
106
91
- analyzer = NewEndorsementAnalyzer (g , pf , policy .ToPrincipalEvaluator (), mf )
107
+ analyzer = NewEndorsementAnalyzer (g , pf , policy .ToPrincipalEvaluator (pkiID2MSPID ), mf )
92
108
pf .On ("PolicyByChaincode" , cc ).Return (policy ).Once ()
93
- desc , err = analyzer .PeersForEndorsement (cc , channel )
109
+ desc , err = analyzer .PeersForEndorsement (channel , & discovery2. ChaincodeInterest { ChaincodeNames : [] string { cc }} )
94
110
assert .Nil (t , desc )
95
111
assert .Equal (t , err .Error (), "cannot satisfy any principal combination" )
96
112
@@ -108,9 +124,9 @@ func TestPeersForEndorsement(t *testing.T) {
108
124
Principal : []byte ("p12" ),
109
125
}).buildPolicy ()
110
126
111
- analyzer = NewEndorsementAnalyzer (g , pf , policy .ToPrincipalEvaluator (), mf )
127
+ analyzer = NewEndorsementAnalyzer (g , pf , policy .ToPrincipalEvaluator (pkiID2MSPID ), mf )
112
128
pf .On ("PolicyByChaincode" , cc ).Return (policy ).Once ()
113
- desc , err = analyzer .PeersForEndorsement (cc , channel )
129
+ desc , err = analyzer .PeersForEndorsement (channel , & discovery2. ChaincodeInterest { ChaincodeNames : [] string { cc }} )
114
130
assert .NoError (t , err )
115
131
assert .NotNil (t , desc )
116
132
assert .Len (t , desc .Layouts , 1 )
@@ -132,9 +148,9 @@ func TestPeersForEndorsement(t *testing.T) {
132
148
Principal : []byte ("p12" ),
133
149
}).buildPolicy ()
134
150
135
- analyzer = NewEndorsementAnalyzer (g , pf , policy .ToPrincipalEvaluator (), mf )
151
+ analyzer = NewEndorsementAnalyzer (g , pf , policy .ToPrincipalEvaluator (pkiID2MSPID ), mf )
136
152
pf .On ("PolicyByChaincode" , cc ).Return (policy ).Once ()
137
- desc , err = analyzer .PeersForEndorsement (cc , channel )
153
+ desc , err = analyzer .PeersForEndorsement (channel , & discovery2. ChaincodeInterest { ChaincodeNames : [] string { cc }} )
138
154
assert .NoError (t , err )
139
155
assert .NotNil (t , desc )
140
156
assert .Len (t , desc .Layouts , 2 )
@@ -153,7 +169,7 @@ func TestPeersForEndorsement(t *testing.T) {
153
169
}).Once ()
154
170
g .On ("PeersOfChannel" ).Return (chanPeers .toMembers ()).Once ()
155
171
pf .On ("PolicyByChaincode" , cc ).Return (policy ).Once ()
156
- desc , err = analyzer .PeersForEndorsement (cc , channel )
172
+ desc , err = analyzer .PeersForEndorsement (channel , & discovery2. ChaincodeInterest { ChaincodeNames : [] string { cc }} )
157
173
assert .Nil (t , desc )
158
174
assert .Equal (t , err .Error (), "cannot satisfy any principal combination" )
159
175
@@ -166,7 +182,7 @@ func TestPeersForEndorsement(t *testing.T) {
166
182
mf .On ("Metadata" ).Return (& chaincode.Metadata {
167
183
Name : cc , Version : "1.0" ,
168
184
}).Once ()
169
- desc , err = analyzer .PeersForEndorsement (cc , channel )
185
+ desc , err = analyzer .PeersForEndorsement (channel , & discovery2. ChaincodeInterest { ChaincodeNames : [] string { cc }} )
170
186
assert .Nil (t , desc )
171
187
assert .Equal (t , err .Error (), "cannot satisfy any principal combination" )
172
188
@@ -175,7 +191,7 @@ func TestPeersForEndorsement(t *testing.T) {
175
191
g .On ("PeersOfChannel" ).Return (chanPeers .toMembers ()).Once ()
176
192
pf .On ("PolicyByChaincode" , cc ).Return (policy ).Once ()
177
193
mf .On ("Metadata" ).Return (nil ).Once ()
178
- desc , err = analyzer .PeersForEndorsement (cc , channel )
194
+ desc , err = analyzer .PeersForEndorsement (channel , & discovery2. ChaincodeInterest { ChaincodeNames : [] string { cc }} )
179
195
assert .Nil (t , desc )
180
196
assert .Equal (t , err .Error (), "No metadata was found for chaincode chaincode in channel test" )
181
197
}
@@ -190,12 +206,13 @@ func (p peerSet) toMembers() discovery.Members {
190
206
return members
191
207
}
192
208
193
- func ( p peerSet ) toIdentitySet ( ) api.PeerIdentitySet {
209
+ func identitySet ( pkiID2MSPID map [ string ] string ) api.PeerIdentitySet {
194
210
var res api.PeerIdentitySet
195
- for _ , peer := range p {
211
+ for pkiID , mspID := range pkiID2MSPID {
196
212
res = append (res , api.PeerIdentityInfo {
197
- Identity : peer .identity ,
198
- PKIId : peer .pkiID ,
213
+ Identity : api .PeerIdentityType (pkiID ),
214
+ PKIId : common .PKIidType (pkiID ),
215
+ Organization : api .OrgIdentityType (mspID ),
199
216
})
200
217
}
201
218
return res
@@ -291,12 +308,17 @@ func (ip inquireablePolicy) SatisfiedBy() []policies.PrincipalSet {
291
308
return ip
292
309
}
293
310
294
- func (ip inquireablePolicy ) ToPrincipalEvaluator () * principalEvaluatorMock {
295
- return & principalEvaluatorMock {ip : ip }
311
+ func (ip inquireablePolicy ) ToPrincipalEvaluator (pkiID2MSPID map [ string ] string ) * principalEvaluatorMock {
312
+ return & principalEvaluatorMock {ip : ip , pkiID2MSPID : pkiID2MSPID }
296
313
}
297
314
298
315
type principalEvaluatorMock struct {
299
- ip []policies.PrincipalSet
316
+ pkiID2MSPID map [string ]string
317
+ ip []policies.PrincipalSet
318
+ }
319
+
320
+ func (pe * principalEvaluatorMock ) MSPOfPrincipal (principal * msp.MSPPrincipal ) string {
321
+ return pe .pkiID2MSPID [string (principal .Principal )]
300
322
}
301
323
302
324
func (pe * principalEvaluatorMock ) SatisfiesPrincipal (channel string , identity []byte , principal * msp.MSPPrincipal ) error {
0 commit comments