Skip to content

Commit db94aec

Browse files
committed
[FAB-14324] remove peer.GetMSPIDs function
- replace calls with peer instance function - wire function into lscc as typed MSPIDsGetter func - remove MockMSPIDGetter var in the lscc package - wire mock implementations of MSPIDsGetter to lscc constructor in test Change-Id: I9bbe93cbdb74c568f9b3a2154a88a7f7bea940cb Signed-off-by: Matthew Sykes <sykesmat@us.ibm.com>
1 parent 6de7433 commit db94aec

File tree

10 files changed

+83
-88
lines changed

10 files changed

+83
-88
lines changed

core/chaincode/chaincode_support_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ func initMockPeer(chainIDs ...string) (*ChaincodeSupport, func(), error) {
180180
globalConfig.StartupTimeout = 10 * time.Second
181181
globalConfig.ExecuteTimeout = 1 * time.Second
182182
pr := platforms.NewRegistry(&golang.Platform{})
183-
lsccImpl := lscc.New(sccp, mockAclProvider, pr)
183+
lsccImpl := lscc.New(sccp, mockAclProvider, pr, peer.Default.GetMSPIDs)
184184
ml := &mock.Lifecycle{}
185185
ml.ChaincodeContainerInfoStub = func(_, name string, _ ledger.SimpleQueryExecutor) (*ccprovider.ChaincodeContainerInfo, error) {
186186
switch name {

core/chaincode/exectransaction_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ func initPeer(chainIDs ...string) (*cm.Lifecycle, net.Listener, *ChaincodeSuppor
109109
ca, _ := tlsgen.NewCA()
110110
pr := platforms.NewRegistry(&golang.Platform{})
111111
mockAclProvider := &mock.ACLProvider{}
112-
lsccImpl := lscc.New(sccp, mockAclProvider, pr)
112+
lsccImpl := lscc.New(sccp, mockAclProvider, pr, peer.Default.GetMSPIDs)
113113
ml := &cm.Lifecycle{}
114114
ml.ChaincodeContainerInfoStub = func(_, name string, _ ledger.SimpleQueryExecutor) (*ccprovider.ChaincodeContainerInfo, error) {
115115
switch name {

core/handlers/validation/builtin/v12/validation_logic_test.go

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ func TestRWSetTooBig(t *testing.T) {
471471
v := newValidationInstance(state)
472472

473473
mockAclProvider := &aclmocks.MockACLProvider{}
474-
lccc := lscc.New(mp, mockAclProvider, platforms.NewRegistry(&golang.Platform{}))
474+
lccc := lscc.New(mp, mockAclProvider, platforms.NewRegistry(&golang.Platform{}), mockMSPIDGetter)
475475
stublccc := shim.NewMockStub("lscc", lccc)
476476
state["lscc"] = stublccc.State
477477

@@ -531,7 +531,7 @@ func TestValidateDeployFail(t *testing.T) {
531531

532532
v := newValidationInstance(state)
533533
mockAclProvider := &aclmocks.MockACLProvider{}
534-
lccc := lscc.New(mp, mockAclProvider, platforms.NewRegistry(&golang.Platform{}))
534+
lccc := lscc.New(mp, mockAclProvider, platforms.NewRegistry(&golang.Platform{}), mockMSPIDGetter)
535535
stublccc := shim.NewMockStub("lscc", lccc)
536536
state["lscc"] = stublccc.State
537537

@@ -798,7 +798,7 @@ func TestAlreadyDeployed(t *testing.T) {
798798

799799
v := newValidationInstance(state)
800800
mockAclProvider := &aclmocks.MockACLProvider{}
801-
lccc := lscc.New(mp, mockAclProvider, platforms.NewRegistry(&golang.Platform{}))
801+
lccc := lscc.New(mp, mockAclProvider, platforms.NewRegistry(&golang.Platform{}), mockMSPIDGetter)
802802
stublccc := shim.NewMockStub("lscc", lccc)
803803
state["lscc"] = stublccc.State
804804

@@ -893,7 +893,7 @@ func TestValidateDeployOK(t *testing.T) {
893893
v := newValidationInstance(state)
894894

895895
mockAclProvider := &aclmocks.MockACLProvider{}
896-
lccc := lscc.New(mp, mockAclProvider, platforms.NewRegistry(&golang.Platform{}))
896+
lccc := lscc.New(mp, mockAclProvider, platforms.NewRegistry(&golang.Platform{}), mockMSPIDGetter)
897897
stublccc := shim.NewMockStub("lscc", lccc)
898898
state["lscc"] = stublccc.State
899899

@@ -943,7 +943,7 @@ func TestValidateDeployWithCollection(t *testing.T) {
943943
})
944944

945945
mockAclProvider := &aclmocks.MockACLProvider{}
946-
lccc := lscc.New(mp, mockAclProvider, platforms.NewRegistry(&golang.Platform{}))
946+
lccc := lscc.New(mp, mockAclProvider, platforms.NewRegistry(&golang.Platform{}), mockMSPIDGetter)
947947
stublccc := shim.NewMockStub("lscc", lccc)
948948
state["lscc"] = stublccc.State
949949

@@ -1036,7 +1036,7 @@ func TestValidateDeployWithCollection(t *testing.T) {
10361036

10371037
v = newValidationInstance(state)
10381038

1039-
lccc = lscc.New(mp, mockAclProvider, platforms.NewRegistry(&golang.Platform{}))
1039+
lccc = lscc.New(mp, mockAclProvider, platforms.NewRegistry(&golang.Platform{}), mockMSPIDGetter)
10401040
stublccc = shim.NewMockStub("lscc", lccc)
10411041
state["lscc"] = stublccc.State
10421042

@@ -1061,7 +1061,7 @@ func TestValidateDeployWithPolicies(t *testing.T) {
10611061
v := newValidationInstance(state)
10621062

10631063
mockAclProvider := &aclmocks.MockACLProvider{}
1064-
lccc := lscc.New(mp, mockAclProvider, platforms.NewRegistry(&golang.Platform{}))
1064+
lccc := lscc.New(mp, mockAclProvider, platforms.NewRegistry(&golang.Platform{}), mockMSPIDGetter)
10651065
stublccc := shim.NewMockStub("lscc", lccc)
10661066
state["lscc"] = stublccc.State
10671067

@@ -1134,7 +1134,7 @@ func TestInvalidUpgrade(t *testing.T) {
11341134
v := newValidationInstance(state)
11351135

11361136
mockAclProvider := &aclmocks.MockACLProvider{}
1137-
lccc := lscc.New(mp, mockAclProvider, platforms.NewRegistry(&golang.Platform{}))
1137+
lccc := lscc.New(mp, mockAclProvider, platforms.NewRegistry(&golang.Platform{}), mockMSPIDGetter)
11381138
stublccc := shim.NewMockStub("lscc", lccc)
11391139
state["lscc"] = stublccc.State
11401140

@@ -1176,7 +1176,7 @@ func TestValidateUpgradeOK(t *testing.T) {
11761176
v := newValidationInstance(state)
11771177

11781178
mockAclProvider := &aclmocks.MockACLProvider{}
1179-
lccc := lscc.New(mp, mockAclProvider, platforms.NewRegistry(&golang.Platform{}))
1179+
lccc := lscc.New(mp, mockAclProvider, platforms.NewRegistry(&golang.Platform{}), mockMSPIDGetter)
11801180
stublccc := shim.NewMockStub("lscc", lccc)
11811181
state["lscc"] = stublccc.State
11821182

@@ -1239,7 +1239,7 @@ func TestInvalidateUpgradeBadVersion(t *testing.T) {
12391239
v := newValidationInstance(state)
12401240

12411241
mockAclProvider := &aclmocks.MockACLProvider{}
1242-
lccc := lscc.New(mp, mockAclProvider, platforms.NewRegistry(&golang.Platform{}))
1242+
lccc := lscc.New(mp, mockAclProvider, platforms.NewRegistry(&golang.Platform{}), mockMSPIDGetter)
12431243
stublccc := shim.NewMockStub("lscc", lccc)
12441244
state["lscc"] = stublccc.State
12451245

@@ -1308,7 +1308,7 @@ func validateUpgradeWithCollection(t *testing.T, ccver string, V1_2Validation bo
13081308
})
13091309

13101310
mockAclProvider := &aclmocks.MockACLProvider{}
1311-
lccc := lscc.New(mp, mockAclProvider, platforms.NewRegistry(&golang.Platform{}))
1311+
lccc := lscc.New(mp, mockAclProvider, platforms.NewRegistry(&golang.Platform{}), mockMSPIDGetter)
13121312
stublccc := shim.NewMockStub("lscc", lccc)
13131313
state["lscc"] = stublccc.State
13141314

@@ -1495,7 +1495,7 @@ func TestValidateUpgradeWithPoliciesOK(t *testing.T) {
14951495
v := newValidationInstance(state)
14961496

14971497
mockAclProvider := &aclmocks.MockACLProvider{}
1498-
lccc := lscc.New(mp, mockAclProvider, platforms.NewRegistry(&golang.Platform{}))
1498+
lccc := lscc.New(mp, mockAclProvider, platforms.NewRegistry(&golang.Platform{}), mockMSPIDGetter)
14991499
stublccc := shim.NewMockStub("lscc", lccc)
15001500
state["lscc"] = stublccc.State
15011501

@@ -1581,7 +1581,7 @@ func validateUpgradeWithNewFailAllIP(t *testing.T, ccver string, v11capability,
15811581
v := newCustomValidationInstance(qec, capabilities)
15821582

15831583
mockAclProvider := &aclmocks.MockACLProvider{}
1584-
lccc := lscc.New(mp, mockAclProvider, platforms.NewRegistry(&golang.Platform{}))
1584+
lccc := lscc.New(mp, mockAclProvider, platforms.NewRegistry(&golang.Platform{}), mockMSPIDGetter)
15851585
stublccc := shim.NewMockStub("lscc", lccc)
15861586
state["lscc"] = stublccc.State
15871587

@@ -1659,7 +1659,7 @@ func TestValidateUpgradeWithPoliciesFail(t *testing.T) {
16591659
v := newValidationInstance(state)
16601660

16611661
mockAclProvider := &aclmocks.MockACLProvider{}
1662-
lccc := lscc.New(mp, mockAclProvider, platforms.NewRegistry(&golang.Platform{}))
1662+
lccc := lscc.New(mp, mockAclProvider, platforms.NewRegistry(&golang.Platform{}), mockMSPIDGetter)
16631663
stublccc := shim.NewMockStub("lscc", lccc)
16641664
state["lscc"] = stublccc.State
16651665

@@ -1967,6 +1967,10 @@ func TestValidateRWSetAndCollectionForUpgrade(t *testing.T) {
19671967
assert.EqualError(t, err, "the BlockToLive in the following existing collections must not be modified: [mycollection2]")
19681968
}
19691969

1970+
var mockMSPIDGetter = func(cid string) []string {
1971+
return []string{"SampleOrg"}
1972+
}
1973+
19701974
func TestMain(m *testing.M) {
19711975
testDir, err := ioutil.TempDir("", "v1.2-validation")
19721976
if err != nil {
@@ -1978,10 +1982,6 @@ func TestMain(m *testing.M) {
19781982

19791983
policy.RegisterPolicyCheckerFactory(&mockPolicyCheckerFactory{})
19801984

1981-
lscc.MockMSPIDGetter = func(cid string) []string {
1982-
return []string{"SampleOrg"}
1983-
}
1984-
19851985
// setup the MSP manager so that we can sign/verify
19861986
msptesttools.LoadMSPSetupForTesting()
19871987

core/handlers/validation/builtin/v13/validation_logic_test.go

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ func TestRWSetTooBig(t *testing.T) {
445445
v := newValidationInstance(state)
446446

447447
mockAclProvider := &aclmocks.MockACLProvider{}
448-
lccc := lscc.New(mp, mockAclProvider, platforms.NewRegistry(&golang.Platform{}))
448+
lccc := lscc.New(mp, mockAclProvider, platforms.NewRegistry(&golang.Platform{}), mockMSPIDGetter)
449449
stublccc := shim.NewMockStub("lscc", lccc)
450450
state["lscc"] = stublccc.State
451451

@@ -505,7 +505,7 @@ func TestValidateDeployFail(t *testing.T) {
505505

506506
v := newValidationInstance(state)
507507
mockAclProvider := &aclmocks.MockACLProvider{}
508-
lccc := lscc.New(mp, mockAclProvider, platforms.NewRegistry(&golang.Platform{}))
508+
lccc := lscc.New(mp, mockAclProvider, platforms.NewRegistry(&golang.Platform{}), mockMSPIDGetter)
509509
stublccc := shim.NewMockStub("lscc", lccc)
510510
state["lscc"] = stublccc.State
511511

@@ -772,7 +772,7 @@ func TestAlreadyDeployed(t *testing.T) {
772772

773773
v := newValidationInstance(state)
774774
mockAclProvider := &aclmocks.MockACLProvider{}
775-
lccc := lscc.New(mp, mockAclProvider, platforms.NewRegistry(&golang.Platform{}))
775+
lccc := lscc.New(mp, mockAclProvider, platforms.NewRegistry(&golang.Platform{}), mockMSPIDGetter)
776776
stublccc := shim.NewMockStub("lscc", lccc)
777777
state["lscc"] = stublccc.State
778778

@@ -867,7 +867,7 @@ func TestValidateDeployOK(t *testing.T) {
867867
v := newValidationInstance(state)
868868

869869
mockAclProvider := &aclmocks.MockACLProvider{}
870-
lccc := lscc.New(mp, mockAclProvider, platforms.NewRegistry(&golang.Platform{}))
870+
lccc := lscc.New(mp, mockAclProvider, platforms.NewRegistry(&golang.Platform{}), mockMSPIDGetter)
871871
stublccc := shim.NewMockStub("lscc", lccc)
872872
state["lscc"] = stublccc.State
873873

@@ -917,7 +917,7 @@ func TestValidateDeployWithCollection(t *testing.T) {
917917
})
918918

919919
mockAclProvider := &aclmocks.MockACLProvider{}
920-
lccc := lscc.New(mp, mockAclProvider, platforms.NewRegistry(&golang.Platform{}))
920+
lccc := lscc.New(mp, mockAclProvider, platforms.NewRegistry(&golang.Platform{}), mockMSPIDGetter)
921921
stublccc := shim.NewMockStub("lscc", lccc)
922922
state["lscc"] = stublccc.State
923923

@@ -1010,7 +1010,7 @@ func TestValidateDeployWithCollection(t *testing.T) {
10101010

10111011
v = newValidationInstance(state)
10121012

1013-
lccc = lscc.New(mp, mockAclProvider, platforms.NewRegistry(&golang.Platform{}))
1013+
lccc = lscc.New(mp, mockAclProvider, platforms.NewRegistry(&golang.Platform{}), mockMSPIDGetter)
10141014
stublccc = shim.NewMockStub("lscc", lccc)
10151015
state["lscc"] = stublccc.State
10161016

@@ -1035,7 +1035,7 @@ func TestValidateDeployWithPolicies(t *testing.T) {
10351035
v := newValidationInstance(state)
10361036

10371037
mockAclProvider := &aclmocks.MockACLProvider{}
1038-
lccc := lscc.New(mp, mockAclProvider, platforms.NewRegistry(&golang.Platform{}))
1038+
lccc := lscc.New(mp, mockAclProvider, platforms.NewRegistry(&golang.Platform{}), mockMSPIDGetter)
10391039
stublccc := shim.NewMockStub("lscc", lccc)
10401040
state["lscc"] = stublccc.State
10411041

@@ -1108,7 +1108,7 @@ func TestInvalidUpgrade(t *testing.T) {
11081108
v := newValidationInstance(state)
11091109

11101110
mockAclProvider := &aclmocks.MockACLProvider{}
1111-
lccc := lscc.New(mp, mockAclProvider, platforms.NewRegistry(&golang.Platform{}))
1111+
lccc := lscc.New(mp, mockAclProvider, platforms.NewRegistry(&golang.Platform{}), mockMSPIDGetter)
11121112
stublccc := shim.NewMockStub("lscc", lccc)
11131113
state["lscc"] = stublccc.State
11141114

@@ -1150,7 +1150,7 @@ func TestValidateUpgradeOK(t *testing.T) {
11501150
v := newValidationInstance(state)
11511151

11521152
mockAclProvider := &aclmocks.MockACLProvider{}
1153-
lccc := lscc.New(mp, mockAclProvider, platforms.NewRegistry(&golang.Platform{}))
1153+
lccc := lscc.New(mp, mockAclProvider, platforms.NewRegistry(&golang.Platform{}), mockMSPIDGetter)
11541154
stublccc := shim.NewMockStub("lscc", lccc)
11551155
state["lscc"] = stublccc.State
11561156

@@ -1213,7 +1213,7 @@ func TestInvalidateUpgradeBadVersion(t *testing.T) {
12131213
v := newValidationInstance(state)
12141214

12151215
mockAclProvider := &aclmocks.MockACLProvider{}
1216-
lccc := lscc.New(mp, mockAclProvider, platforms.NewRegistry(&golang.Platform{}))
1216+
lccc := lscc.New(mp, mockAclProvider, platforms.NewRegistry(&golang.Platform{}), mockMSPIDGetter)
12171217
stublccc := shim.NewMockStub("lscc", lccc)
12181218
state["lscc"] = stublccc.State
12191219

@@ -1282,7 +1282,7 @@ func validateUpgradeWithCollection(t *testing.T, ccver string, V1_2Validation bo
12821282
})
12831283

12841284
mockAclProvider := &aclmocks.MockACLProvider{}
1285-
lccc := lscc.New(mp, mockAclProvider, platforms.NewRegistry(&golang.Platform{}))
1285+
lccc := lscc.New(mp, mockAclProvider, platforms.NewRegistry(&golang.Platform{}), mockMSPIDGetter)
12861286
stublccc := shim.NewMockStub("lscc", lccc)
12871287
state["lscc"] = stublccc.State
12881288

@@ -1469,7 +1469,7 @@ func TestValidateUpgradeWithPoliciesOK(t *testing.T) {
14691469
v := newValidationInstance(state)
14701470

14711471
mockAclProvider := &aclmocks.MockACLProvider{}
1472-
lccc := lscc.New(mp, mockAclProvider, platforms.NewRegistry(&golang.Platform{}))
1472+
lccc := lscc.New(mp, mockAclProvider, platforms.NewRegistry(&golang.Platform{}), mockMSPIDGetter)
14731473
stublccc := shim.NewMockStub("lscc", lccc)
14741474
state["lscc"] = stublccc.State
14751475

@@ -1555,7 +1555,7 @@ func validateUpgradeWithNewFailAllIP(t *testing.T, ccver string, v11capability,
15551555
v := newCustomValidationInstance(qec, capabilities)
15561556

15571557
mockAclProvider := &aclmocks.MockACLProvider{}
1558-
lccc := lscc.New(mp, mockAclProvider, platforms.NewRegistry(&golang.Platform{}))
1558+
lccc := lscc.New(mp, mockAclProvider, platforms.NewRegistry(&golang.Platform{}), mockMSPIDGetter)
15591559
stublccc := shim.NewMockStub("lscc", lccc)
15601560
state["lscc"] = stublccc.State
15611561

@@ -1633,7 +1633,7 @@ func TestValidateUpgradeWithPoliciesFail(t *testing.T) {
16331633
v := newValidationInstance(state)
16341634

16351635
mockAclProvider := &aclmocks.MockACLProvider{}
1636-
lccc := lscc.New(mp, mockAclProvider, platforms.NewRegistry(&golang.Platform{}))
1636+
lccc := lscc.New(mp, mockAclProvider, platforms.NewRegistry(&golang.Platform{}), mockMSPIDGetter)
16371637
stublccc := shim.NewMockStub("lscc", lccc)
16381638
state["lscc"] = stublccc.State
16391639

@@ -1941,6 +1941,10 @@ func TestValidateRWSetAndCollectionForUpgrade(t *testing.T) {
19411941
assert.EqualError(t, err, "the BlockToLive in the following existing collections must not be modified: [mycollection2]")
19421942
}
19431943

1944+
var mockMSPIDGetter = func(cid string) []string {
1945+
return []string{"SampleOrg"}
1946+
}
1947+
19441948
func TestMain(m *testing.M) {
19451949
testDir, err := ioutil.TempDir("", "v1.3-validation")
19461950
if err != nil {
@@ -1952,10 +1956,6 @@ func TestMain(m *testing.M) {
19521956

19531957
policy.RegisterPolicyCheckerFactory(&mockPolicyCheckerFactory{})
19541958

1955-
lscc.MockMSPIDGetter = func(cid string) []string {
1956-
return []string{"SampleOrg"}
1957-
}
1958-
19591959
// setup the MSP manager so that we can sign/verify
19601960
msptesttools.LoadMSPSetupForTesting()
19611961

core/handlers/validation/builtin/v20/validation_logic_test.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import (
2323
validation "github.com/hyperledger/fabric/core/handlers/validation/api/capabilities"
2424
"github.com/hyperledger/fabric/core/handlers/validation/builtin/v20/mocks"
2525
"github.com/hyperledger/fabric/core/policy"
26-
"github.com/hyperledger/fabric/core/scc/lscc"
2726
"github.com/hyperledger/fabric/msp"
2827
mspmgmt "github.com/hyperledger/fabric/msp/mgmt"
2928
msptesttools "github.com/hyperledger/fabric/msp/mgmt/testtools"
@@ -262,10 +261,6 @@ func TestMain(m *testing.M) {
262261

263262
policy.RegisterPolicyCheckerFactory(&mockPolicyCheckerFactory{})
264263

265-
lscc.MockMSPIDGetter = func(cid string) []string {
266-
return []string{"SampleOrg"}
267-
}
268-
269264
// setup the MSP manager so that we can sign/verify
270265
msptesttools.LoadMSPSetupForTesting()
271266

core/peer/peer.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -678,7 +678,6 @@ func (p *Peer) GetLedger(cid string) ledger.PeerLedger {
678678
}
679679

680680
// GetMSPIDs returns the ID of each application MSP defined on this channel
681-
func GetMSPIDs(cid string) []string { return Default.GetMSPIDs(cid) }
682681
func (p *Peer) GetMSPIDs(cid string) []string {
683682
p.mutex.RLock()
684683
defer p.mutex.RUnlock()

0 commit comments

Comments
 (0)