Skip to content

Commit e644262

Browse files
committed
[FAB-3451] Move noopmsp in mocks
This change set moves the implementation of the noop version of MSP in common/mocks/msp/ as decided for all mocks. Change-Id: I411d50f1b869d84192dc3837ecd335036638e71e Signed-off-by: Alessandro Sorniotti <[email protected]>
1 parent ecc29dd commit e644262

File tree

8 files changed

+90
-75
lines changed

8 files changed

+90
-75
lines changed

common/configtx/tool/configtxgen/main.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ import (
3030
genesisconfig "github.com/hyperledger/fabric/common/configtx/tool/localconfig"
3131
"github.com/hyperledger/fabric/common/configtx/tool/provisional"
3232
"github.com/hyperledger/fabric/common/flogging"
33-
"github.com/hyperledger/fabric/msp"
3433
cb "github.com/hyperledger/fabric/protos/common"
3534
pb "github.com/hyperledger/fabric/protos/peer"
3635
"github.com/hyperledger/fabric/protos/utils"
3736

3837
"github.com/golang/protobuf/proto"
38+
mmsp "github.com/hyperledger/fabric/common/mocks/msp"
3939
logging "github.com/op/go-logging"
4040
)
4141

@@ -56,7 +56,7 @@ func doOutputBlock(config *genesisconfig.Profile, channelID string, outputBlock
5656
func doOutputChannelCreateTx(conf *genesisconfig.Profile, channelID string, outputChannelCreateTx string) error {
5757
logger.Info("Generating new channel configtx")
5858
// TODO, use actual MSP eventually
59-
signer, err := msp.NewNoopMsp().GetDefaultSigningIdentity()
59+
signer, err := mmsp.NewNoopMsp().GetDefaultSigningIdentity()
6060
if err != nil {
6161
return fmt.Errorf("Error getting signing identity: %s", err)
6262
}

msp/noopmsp.go common/mocks/msp/noopmsp.go

+20-28
Original file line numberDiff line numberDiff line change
@@ -17,87 +17,83 @@ limitations under the License.
1717
package msp
1818

1919
import (
20+
m "github.com/hyperledger/fabric/msp"
2021
"github.com/hyperledger/fabric/protos/msp"
2122
)
2223

2324
type noopmsp struct {
2425
}
2526

26-
func NewNoopMsp() MSP {
27-
mspLogger.Infof("Creating no-op MSP instance")
27+
// NewNoopMsp returns a no-op implementation of the MSP inteface
28+
func NewNoopMsp() m.MSP {
2829
return &noopmsp{}
2930
}
3031

3132
func (msp *noopmsp) Setup(*msp.MSPConfig) error {
3233
return nil
3334
}
3435

35-
func (msp *noopmsp) GetType() ProviderType {
36+
func (msp *noopmsp) GetType() m.ProviderType {
3637
return 0
3738
}
3839

3940
func (msp *noopmsp) GetIdentifier() (string, error) {
4041
return "NOOP", nil
4142
}
4243

43-
func (msp *noopmsp) GetSigningIdentity(identifier *IdentityIdentifier) (SigningIdentity, error) {
44-
mspLogger.Infof("Obtaining signing identity for %s", identifier)
44+
func (msp *noopmsp) GetSigningIdentity(identifier *m.IdentityIdentifier) (m.SigningIdentity, error) {
4545
id, _ := newNoopSigningIdentity()
4646
return id, nil
4747
}
4848

49-
func (msp *noopmsp) GetDefaultSigningIdentity() (SigningIdentity, error) {
50-
mspLogger.Infof("Obtaining default signing identity")
49+
func (msp *noopmsp) GetDefaultSigningIdentity() (m.SigningIdentity, error) {
5150
id, _ := newNoopSigningIdentity()
5251
return id, nil
5352
}
5453

5554
// GetRootCerts returns the root certificates for this MSP
56-
func (msp *noopmsp) GetRootCerts() []Identity {
55+
func (msp *noopmsp) GetRootCerts() []m.Identity {
5756
return nil
5857
}
5958

6059
// GetIntermediateCerts returns the intermediate root certificates for this MSP
61-
func (msp *noopmsp) GetIntermediateCerts() []Identity {
60+
func (msp *noopmsp) GetIntermediateCerts() []m.Identity {
6261
return nil
6362
}
6463

65-
func (msp *noopmsp) DeserializeIdentity(serializedID []byte) (Identity, error) {
66-
mspLogger.Infof("Obtaining identity for %s", string(serializedID))
64+
func (msp *noopmsp) DeserializeIdentity(serializedID []byte) (m.Identity, error) {
6765
id, _ := newNoopIdentity()
6866
return id, nil
6967
}
7068

71-
func (msp *noopmsp) Validate(id Identity) error {
69+
func (msp *noopmsp) Validate(id m.Identity) error {
7270
return nil
7371
}
7472

75-
func (msp *noopmsp) SatisfiesPrincipal(id Identity, principal *msp.MSPPrincipal) error {
73+
func (msp *noopmsp) SatisfiesPrincipal(id m.Identity, principal *msp.MSPPrincipal) error {
7674
return nil
7775
}
7876

7977
type noopidentity struct {
8078
}
8179

82-
func newNoopIdentity() (Identity, error) {
83-
mspLogger.Infof("Creating no-op identity instance")
80+
func newNoopIdentity() (m.Identity, error) {
8481
return &noopidentity{}, nil
8582
}
8683

8784
func (id *noopidentity) SatisfiesPrincipal(*msp.MSPPrincipal) error {
8885
return nil
8986
}
9087

91-
func (id *noopidentity) GetIdentifier() *IdentityIdentifier {
92-
return &IdentityIdentifier{Mspid: "NOOP", Id: "Bob"}
88+
func (id *noopidentity) GetIdentifier() *m.IdentityIdentifier {
89+
return &m.IdentityIdentifier{Mspid: "NOOP", Id: "Bob"}
9390
}
9491

9592
func (id *noopidentity) GetMSPIdentifier() string {
9693
return "MSPID"
9794
}
9895

9996
func (id *noopidentity) Validate() error {
100-
mspLogger.Infof("Identity is valid")
10197
return nil
10298
}
10399

@@ -106,46 +102,42 @@ func (id *noopidentity) GetOrganizationalUnits() []msp.FabricOUIdentifier {
106102
}
107103

108104
func (id *noopidentity) Verify(msg []byte, sig []byte) error {
109-
mspLogger.Infof("Signature is valid")
110105
return nil
111106
}
112107

113-
func (id *noopidentity) VerifyOpts(msg []byte, sig []byte, opts SignatureOpts) error {
108+
func (id *noopidentity) VerifyOpts(msg []byte, sig []byte, opts m.SignatureOpts) error {
114109
return nil
115110
}
116111

117-
func (id *noopidentity) VerifyAttributes(proof []byte, spec *AttributeProofSpec) error {
112+
func (id *noopidentity) VerifyAttributes(proof []byte, spec *m.AttributeProofSpec) error {
118113
return nil
119114
}
120115

121116
func (id *noopidentity) Serialize() ([]byte, error) {
122-
mspLogger.Infof("Serialinzing identity")
123117
return []byte("cert"), nil
124118
}
125119

126120
type noopsigningidentity struct {
127121
noopidentity
128122
}
129123

130-
func newNoopSigningIdentity() (SigningIdentity, error) {
131-
mspLogger.Infof("Creating no-op signing identity instance")
124+
func newNoopSigningIdentity() (m.SigningIdentity, error) {
132125
return &noopsigningidentity{}, nil
133126
}
134127

135128
func (id *noopsigningidentity) Sign(msg []byte) ([]byte, error) {
136-
mspLogger.Infof("signing message")
137129
return []byte("signature"), nil
138130
}
139131

140-
func (id *noopsigningidentity) SignOpts(msg []byte, opts SignatureOpts) ([]byte, error) {
132+
func (id *noopsigningidentity) SignOpts(msg []byte, opts m.SignatureOpts) ([]byte, error) {
141133
return nil, nil
142134
}
143135

144-
func (id *noopsigningidentity) GetAttributeProof(spec *AttributeProofSpec) (proof []byte, err error) {
136+
func (id *noopsigningidentity) GetAttributeProof(spec *m.AttributeProofSpec) (proof []byte, err error) {
145137
return nil, nil
146138
}
147139

148-
func (id *noopsigningidentity) GetPublicVersion() Identity {
140+
func (id *noopsigningidentity) GetPublicVersion() m.Identity {
149141
return id
150142
}
151143

common/mocks/msp/noopmsp_test.go

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
Copyright IBM Corp. 2017 All Rights Reserved.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package msp
18+
19+
import "testing"
20+
21+
func TestNoopMSP(t *testing.T) {
22+
noopmsp := NewNoopMsp()
23+
24+
id, err := noopmsp.GetDefaultSigningIdentity()
25+
if err != nil {
26+
t.Fatalf("GetSigningIdentity should have succeeded")
27+
return
28+
}
29+
30+
serializedID, err := id.Serialize()
31+
if err != nil {
32+
t.Fatalf("Serialize should have succeeded")
33+
return
34+
}
35+
36+
idBack, err := noopmsp.DeserializeIdentity(serializedID)
37+
if err != nil {
38+
t.Fatalf("DeserializeIdentity should have succeeded")
39+
return
40+
}
41+
42+
msg := []byte("foo")
43+
sig, err := id.Sign(msg)
44+
if err != nil {
45+
t.Fatalf("Sign should have succeeded")
46+
return
47+
}
48+
49+
err = id.Verify(msg, sig)
50+
if err != nil {
51+
t.Fatalf("The signature should be valid")
52+
return
53+
}
54+
55+
err = idBack.Verify(msg, sig)
56+
if err != nil {
57+
t.Fatalf("The signature should be valid")
58+
return
59+
}
60+
}

core/common/validation/fullflow_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"testing"
2424
"time"
2525

26+
mmsp "github.com/hyperledger/fabric/common/mocks/msp"
2627
"github.com/hyperledger/fabric/common/util"
2728
"github.com/hyperledger/fabric/msp"
2829
mspmgmt "github.com/hyperledger/fabric/msp/mgmt"
@@ -275,7 +276,7 @@ func TestBadProp(t *testing.T) {
275276
}
276277

277278
// get a bad signing identity
278-
badSigner, err := msp.NewNoopMsp().GetDefaultSigningIdentity()
279+
badSigner, err := mmsp.NewNoopMsp().GetDefaultSigningIdentity()
279280
if err != nil {
280281
t.Fatal("Couldn't get noop signer")
281282
return

events/producer/producer_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"testing"
2424
"time"
2525

26+
mmsp "github.com/hyperledger/fabric/common/mocks/msp"
2627
"github.com/hyperledger/fabric/common/util"
2728
"github.com/hyperledger/fabric/msp"
2829
"github.com/hyperledger/fabric/msp/mgmt"
@@ -96,7 +97,7 @@ func TestSignedEvent(t *testing.T) {
9697
}
9798

9899
// get a bad signing identity
99-
badSigner, err := msp.NewNoopMsp().GetDefaultSigningIdentity()
100+
badSigner, err := mmsp.NewNoopMsp().GetDefaultSigningIdentity()
100101
if err != nil {
101102
t.Fatal("couldn't get noop signer")
102103
return

msp/msp_test.go

-41
Original file line numberDiff line numberDiff line change
@@ -32,47 +32,6 @@ import (
3232
"github.com/stretchr/testify/assert"
3333
)
3434

35-
func TestNoopMSP(t *testing.T) {
36-
noopmsp := NewNoopMsp()
37-
38-
id, err := noopmsp.GetDefaultSigningIdentity()
39-
if err != nil {
40-
t.Fatalf("GetSigningIdentity should have succeeded")
41-
return
42-
}
43-
44-
serializedID, err := id.Serialize()
45-
if err != nil {
46-
t.Fatalf("Serialize should have succeeded")
47-
return
48-
}
49-
50-
idBack, err := noopmsp.DeserializeIdentity(serializedID)
51-
if err != nil {
52-
t.Fatalf("DeserializeIdentity should have succeeded")
53-
return
54-
}
55-
56-
msg := []byte("foo")
57-
sig, err := id.Sign(msg)
58-
if err != nil {
59-
t.Fatalf("Sign should have succeeded")
60-
return
61-
}
62-
63-
err = id.Verify(msg, sig)
64-
if err != nil {
65-
t.Fatalf("The signature should be valid")
66-
return
67-
}
68-
69-
err = idBack.Verify(msg, sig)
70-
if err != nil {
71-
t.Fatalf("The signature should be valid")
72-
return
73-
}
74-
}
75-
7635
func TestMSPSetupBad(t *testing.T) {
7736
_, err := GetLocalMspConfig("barf", nil, "DEFAULT")
7837
if err == nil {

orderer/multichain/manager_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import (
3434

3535
"errors"
3636

37+
mmsp "github.com/hyperledger/fabric/common/mocks/msp"
3738
logging "github.com/op/go-logging"
3839
"github.com/stretchr/testify/assert"
3940
)
@@ -46,7 +47,7 @@ func init() {
4647
conf = genesisconfig.Load(genesisconfig.SampleInsecureProfile)
4748
logging.SetLevel(logging.DEBUG, "")
4849
genesisBlock = provisional.New(conf).GenesisBlock()
49-
mockSigningIdentity, _ = msp.NewNoopMsp().GetDefaultSigningIdentity()
50+
mockSigningIdentity, _ = mmsp.NewNoopMsp().GetDefaultSigningIdentity()
5051
}
5152

5253
func mockCrypto() *mockCryptoHelper {

protos/testutils/txtestutils.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"fmt"
2121
"os"
2222

23+
mmsp "github.com/hyperledger/fabric/common/mocks/msp"
2324
"github.com/hyperledger/fabric/msp"
2425
mspmgmt "github.com/hyperledger/fabric/msp/mgmt"
2526
"github.com/hyperledger/fabric/msp/mgmt/testtools"
@@ -85,7 +86,7 @@ var sigId msp.SigningIdentity
8586
// ConstructUnsingedTxEnv creates a Transaction envelope from given inputs
8687
func ConstructUnsingedTxEnv(chainID string, ccid *pb.ChaincodeID, response *pb.Response, simulationResults []byte, events []byte, visibility []byte) (*common.Envelope, string, error) {
8788
if mspLcl == nil {
88-
mspLcl = msp.NewNoopMsp()
89+
mspLcl = mmsp.NewNoopMsp()
8990
sigId, _ = mspLcl.GetDefaultSigningIdentity()
9091
}
9192

0 commit comments

Comments
 (0)