Skip to content

Commit c44a833

Browse files
committed
Fix a set of wrong string format issue
It will fix FAB-1482. Change-Id: I88777803f37e06f01d8c8578dd61699206873d26 Signed-off-by: grapebaba <[email protected]>
1 parent 5adaef7 commit c44a833

File tree

7 files changed

+54
-51
lines changed

7 files changed

+54
-51
lines changed

common/cauthdsl/cauthdsl_test.go

+10-10
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,13 @@ func TestSimpleSignature(t *testing.T) {
4545
}
4646

4747
if !spe.Authenticate(nil, [][]byte{signers[0]}, [][]byte{validSignature}) {
48-
t.Errorf("Expected authentication to succeed with valid signatures")
48+
t.Error("Expected authentication to succeed with valid signatures")
4949
}
5050
if spe.Authenticate(nil, [][]byte{signers[0]}, [][]byte{invalidSignature}) {
51-
t.Errorf("Expected authentication to fail given the invalid signature")
51+
t.Error("Expected authentication to fail given the invalid signature")
5252
}
5353
if spe.Authenticate(nil, [][]byte{signers[1]}, [][]byte{validSignature}) {
54-
t.Errorf("Expected authentication to fail because signers[1] is not authorized in the policy, despite his valid signature")
54+
t.Error("Expected authentication to fail because signers[1] is not authorized in the policy, despite his valid signature")
5555
}
5656
}
5757

@@ -65,13 +65,13 @@ func TestMultipleSignature(t *testing.T) {
6565
}
6666

6767
if !spe.Authenticate(nil, signers, [][]byte{validSignature, validSignature}) {
68-
t.Errorf("Expected authentication to succeed with valid signatures")
68+
t.Error("Expected authentication to succeed with valid signatures")
6969
}
7070
if spe.Authenticate(nil, signers, [][]byte{validSignature, invalidSignature}) {
71-
t.Errorf("Expected authentication to fail given one of two invalid signatures")
71+
t.Error("Expected authentication to fail given one of two invalid signatures")
7272
}
7373
if spe.Authenticate(nil, [][]byte{signers[0], signers[0]}, [][]byte{validSignature, validSignature}) {
74-
t.Errorf("Expected authentication to fail because although there were two valid signatures, one was duplicated")
74+
t.Error("Expected authentication to fail because although there were two valid signatures, one was duplicated")
7575
}
7676
}
7777

@@ -85,13 +85,13 @@ func TestComplexNestedSignature(t *testing.T) {
8585
}
8686

8787
if !spe.Authenticate(nil, signers, [][]byte{validSignature, validSignature}) {
88-
t.Errorf("Expected authentication to succeed with valid signatures")
88+
t.Error("Expected authentication to succeed with valid signatures")
8989
}
9090
if spe.Authenticate(nil, signers, [][]byte{invalidSignature, validSignature}) {
91-
t.Errorf("Expected authentication failure as only the signature of signer[1] was valid")
91+
t.Error("Expected authentication failure as only the signature of signer[1] was valid")
9292
}
9393
if !spe.Authenticate(nil, [][]byte{signers[0], signers[0]}, [][]byte{validSignature, validSignature}) {
94-
t.Errorf("Expected authentication to succeed because the rule allows duplicated signatures for signer[0]")
94+
t.Error("Expected authentication to succeed because the rule allows duplicated signatures for signer[0]")
9595
}
9696
}
9797

@@ -104,6 +104,6 @@ func TestNegatively(t *testing.T) {
104104
_ = proto.Unmarshal(b, policy)
105105
_, err := NewSignaturePolicyEvaluator(policy, mch)
106106
if err == nil {
107-
t.Fatalf("Should have errored compiling because the Type field was nil")
107+
t.Fatal("Should have errored compiling because the Type field was nil")
108108
}
109109
}

common/configtx/bytes_handler.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
cb "github.com/hyperledger/fabric/protos/common"
2121
)
2222

23-
// BytesHandler is a trivial ConfigHandler which simpy tracks the bytes stores in a config
23+
// BytesHandler is a trivial ConfigHandler which simply tracks the bytes stores in a config
2424
type BytesHandler struct {
2525
config map[string][]byte
2626
proposed map[string][]byte

common/configtx/filter_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func TestForwardNonConfig(t *testing.T) {
5151
Payload: []byte("Opaque"),
5252
})
5353
if result != filter.Forward {
54-
t.Fatalf("Should have forwarded opaque message")
54+
t.Fatal("Should have forwarded opaque message")
5555
}
5656
}
5757

@@ -66,11 +66,11 @@ func TestAcceptGoodConfig(t *testing.T) {
6666
}
6767
result, committer := cf.Apply(configEnvelope)
6868
if result != filter.Accept {
69-
t.Fatalf("Should have indicated a good config message causes a reconfiguration")
69+
t.Fatal("Should have indicated a good config message causes a reconfiguration")
7070
}
7171

7272
if !committer.Isolated() {
73-
t.Fatalf("Configuration transactions should be isolated to their own block")
73+
t.Fatal("Configuration transactions should be isolated to their own block")
7474
}
7575

7676
committer.Commit()
@@ -88,6 +88,6 @@ func TestRejectBadConfig(t *testing.T) {
8888
Payload: configBytes,
8989
})
9090
if result != filter.Reject {
91-
t.Fatalf("Should have rejected bad config message")
91+
t.Fatal("Should have rejected bad config message")
9292
}
9393
}

common/configtx/manager.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
cb "github.com/hyperledger/fabric/protos/common"
2525

2626
"github.com/golang/protobuf/proto"
27+
"errors"
2728
)
2829

2930
// Handler provides a hook which allows other pieces of code to participate in config proposals
@@ -74,7 +75,7 @@ type configurationManager struct {
7475
// or an error if there is a problem with the configuration envelope
7576
func computeChainIDAndSequence(configtx *cb.ConfigurationEnvelope) (string, uint64, error) {
7677
if len(configtx.Items) == 0 {
77-
return "", 0, fmt.Errorf("Empty envelope unsupported")
78+
return "", 0, errors.New("Empty envelope unsupported")
7879
}
7980

8081
m := uint64(0) //configtx.Items[0].LastModified
@@ -115,7 +116,7 @@ func computeChainIDAndSequence(configtx *cb.ConfigurationEnvelope) (string, uint
115116
func NewConfigurationManager(configtx *cb.ConfigurationEnvelope, pm policies.Manager, handlers map[cb.ConfigurationItem_ConfigurationType]Handler) (Manager, error) {
116117
for ctype := range cb.ConfigurationItem_ConfigurationType_name {
117118
if _, ok := handlers[cb.ConfigurationItem_ConfigurationType(ctype)]; !ok {
118-
return nil, fmt.Errorf("Must supply a handler for all known types")
119+
return nil, errors.New("Must supply a handler for all known types")
119120
}
120121
}
121122

common/configtx/manager_test.go

+27-26
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
cb "github.com/hyperledger/fabric/protos/common"
2525

2626
"github.com/golang/protobuf/proto"
27+
"errors"
2728
)
2829

2930
var defaultChain = "DefaultChainID"
@@ -43,7 +44,7 @@ type mockPolicy struct {
4344

4445
func (mp *mockPolicy) Evaluate(headers [][]byte, payload []byte, identities [][]byte, signatures [][]byte) error {
4546
if mp == nil {
46-
return fmt.Errorf("Invoked nil policy")
47+
return errors.New("Invoked nil policy")
4748
}
4849
return mp.policyResult
4950
}
@@ -85,7 +86,7 @@ func TestOmittedHandler(t *testing.T) {
8586
}, &mockPolicyManager{&mockPolicy{}}, map[cb.ConfigurationItem_ConfigurationType]Handler{})
8687

8788
if err == nil {
88-
t.Fatalf("Should have failed to construct manager because handlers were missing")
89+
t.Fatal("Should have failed to construct manager because handlers were missing")
8990
}
9091
}
9192

@@ -105,12 +106,12 @@ func TestWrongChainID(t *testing.T) {
105106

106107
err = cm.Validate(newConfig)
107108
if err == nil {
108-
t.Errorf("Should have errored when validating a new configuration set the wrong chain ID")
109+
t.Error("Should have errored when validating a new configuration set the wrong chain ID")
109110
}
110111

111112
err = cm.Apply(newConfig)
112113
if err == nil {
113-
t.Errorf("Should have errored when applying a new configuration with the wrong chain ID")
114+
t.Error("Should have errored when applying a new configuration with the wrong chain ID")
114115
}
115116
}
116117

@@ -130,12 +131,12 @@ func TestOldConfigReplay(t *testing.T) {
130131

131132
err = cm.Validate(newConfig)
132133
if err == nil {
133-
t.Errorf("Should have errored when validating a configuration that is not a newer sequence number")
134+
t.Error("Should have errored when validating a configuration that is not a newer sequence number")
134135
}
135136

136137
err = cm.Apply(newConfig)
137138
if err == nil {
138-
t.Errorf("Should have errored when applying a configuration that is not a newer sequence number")
139+
t.Error("Should have errored when applying a configuration that is not a newer sequence number")
139140
}
140141
}
141142

@@ -148,7 +149,7 @@ func TestInvalidInitialConfigByStructure(t *testing.T) {
148149
}, &mockPolicyManager{&mockPolicy{}}, defaultHandlers())
149150

150151
if err == nil {
151-
t.Fatalf("Should have failed to construct configuration by policy")
152+
t.Fatal("Should have failed to construct configuration by policy")
152153
}
153154
}
154155

@@ -197,12 +198,12 @@ func TestConfigChangeRegressedSequence(t *testing.T) {
197198

198199
err = cm.Validate(newConfig)
199200
if err == nil {
200-
t.Errorf("Should have errored validating config because foo's sequence number regressed")
201+
t.Error("Should have errored validating config because foo's sequence number regressed")
201202
}
202203

203204
err = cm.Apply(newConfig)
204205
if err == nil {
205-
t.Errorf("Should have errored applying config because foo's sequence number regressed")
206+
t.Error("Should have errored applying config because foo's sequence number regressed")
206207
}
207208
}
208209

@@ -226,12 +227,12 @@ func TestConfigChangeOldSequence(t *testing.T) {
226227

227228
err = cm.Validate(newConfig)
228229
if err == nil {
229-
t.Errorf("Should have errored validating config because bar was new but its sequence number was old")
230+
t.Error("Should have errored validating config because bar was new but its sequence number was old")
230231
}
231232

232233
err = cm.Apply(newConfig)
233234
if err == nil {
234-
t.Errorf("Should have errored applying config because bar was new but its sequence number was old")
235+
t.Error("Should have errored applying config because bar was new but its sequence number was old")
235236
}
236237
}
237238

@@ -257,12 +258,12 @@ func TestConfigImplicitDelete(t *testing.T) {
257258

258259
err = cm.Validate(newConfig)
259260
if err == nil {
260-
t.Errorf("Should have errored validating config because foo was implicitly deleted")
261+
t.Error("Should have errored validating config because foo was implicitly deleted")
261262
}
262263

263264
err = cm.Apply(newConfig)
264265
if err == nil {
265-
t.Errorf("Should have errored applying config because foo was implicitly deleted")
266+
t.Error("Should have errored applying config because foo was implicitly deleted")
266267
}
267268
}
268269

@@ -280,12 +281,12 @@ func TestEmptyConfigUpdate(t *testing.T) {
280281

281282
err = cm.Validate(newConfig)
282283
if err == nil {
283-
t.Errorf("Should not errored validating config because new config is empty")
284+
t.Error("Should not errored validating config because new config is empty")
284285
}
285286

286287
err = cm.Apply(newConfig)
287288
if err == nil {
288-
t.Errorf("Should not errored applying config because new config is empty")
289+
t.Error("Should not errored applying config because new config is empty")
289290
}
290291
}
291292

@@ -313,12 +314,12 @@ func TestSilentConfigModification(t *testing.T) {
313314

314315
err = cm.Validate(newConfig)
315316
if err == nil {
316-
t.Errorf("Should not errored validating config because foo was silently modified (despite modification allowed by policy)")
317+
t.Error("Should not errored validating config because foo was silently modified (despite modification allowed by policy)")
317318
}
318319

319320
err = cm.Apply(newConfig)
320321
if err == nil {
321-
t.Errorf("Should not errored applying config because foo was silently modified (despite modification allowed by policy)")
322+
t.Error("Should not errored applying config because foo was silently modified (despite modification allowed by policy)")
322323
}
323324
}
324325

@@ -331,7 +332,7 @@ func TestInvalidInitialConfigByPolicy(t *testing.T) {
331332
// mockPolicyManager will return non-validating defualt policy
332333

333334
if err == nil {
334-
t.Fatalf("Should have failed to construct configuration by policy")
335+
t.Fatal("Should have failed to construct configuration by policy")
335336
}
336337
}
337338

@@ -355,12 +356,12 @@ func TestConfigChangeViolatesPolicy(t *testing.T) {
355356

356357
err = cm.Validate(newConfig)
357358
if err == nil {
358-
t.Errorf("Should have errored validating config because policy rejected modification")
359+
t.Error("Should have errored validating config because policy rejected modification")
359360
}
360361

361362
err = cm.Apply(newConfig)
362363
if err == nil {
363-
t.Errorf("Should have errored applying config because policy rejected modification")
364+
t.Error("Should have errored applying config because policy rejected modification")
364365
}
365366
}
366367

@@ -370,7 +371,7 @@ func (fh failHandler) BeginConfig() {}
370371
func (fh failHandler) RollbackConfig() {}
371372
func (fh failHandler) CommitConfig() {}
372373
func (fh failHandler) ProposeConfig(item *cb.ConfigurationItem) error {
373-
return fmt.Errorf("Fail")
374+
return errors.New("Fail")
374375
}
375376

376377
// TestInvalidProposal checks that even if the policy allows the transaction and the sequence etc. is well formed,
@@ -393,12 +394,12 @@ func TestInvalidProposal(t *testing.T) {
393394

394395
err = cm.Validate(newConfig)
395396
if err == nil {
396-
t.Errorf("Should have errored validating config because the handler rejected it")
397+
t.Error("Should have errored validating config because the handler rejected it")
397398
}
398399

399400
err = cm.Apply(newConfig)
400401
if err == nil {
401-
t.Errorf("Should have errored applying config because the handler rejected it")
402+
t.Error("Should have errored applying config because the handler rejected it")
402403
}
403404
}
404405

@@ -413,7 +414,7 @@ func TestMissingHeader(t *testing.T) {
413414
}, &mockPolicyManager{&mockPolicy{}}, handlers)
414415

415416
if err == nil {
416-
t.Errorf("Should have errored creating the configuration manager because of the missing header")
417+
t.Error("Should have errored creating the configuration manager because of the missing header")
417418
}
418419
}
419420

@@ -425,7 +426,7 @@ func TestMissingChainID(t *testing.T) {
425426
}, &mockPolicyManager{&mockPolicy{}}, handlers)
426427

427428
if err == nil {
428-
t.Errorf("Should have errored creating the configuration manager because of the missing header")
429+
t.Error("Should have errored creating the configuration manager because of the missing header")
429430
}
430431
}
431432

@@ -440,6 +441,6 @@ func TestMismatchedChainID(t *testing.T) {
440441
}, &mockPolicyManager{&mockPolicy{}}, handlers)
441442

442443
if err == nil {
443-
t.Errorf("Should have errored creating the configuration manager because of the missing header")
444+
t.Error("Should have errored creating the configuration manager because of the missing header")
444445
}
445446
}

common/policies/policy.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
cb "github.com/hyperledger/fabric/protos/common"
2424

2525
"github.com/golang/protobuf/proto"
26+
"errors"
2627
)
2728

2829
// Policy is used to determine if a signature is valid
@@ -52,7 +53,7 @@ func newPolicy(policySource *cb.Policy, ch cauthdsl.CryptoHelper) (*policy, erro
5253
}
5354

5455
if envelopeWrapper.SignaturePolicy == nil {
55-
return nil, fmt.Errorf("Nil signature policy received")
56+
return nil, errors.New("Nil signature policy received")
5657
}
5758

5859
sigPolicy := envelopeWrapper.SignaturePolicy
@@ -73,12 +74,12 @@ func newPolicy(policySource *cb.Policy, ch cauthdsl.CryptoHelper) (*policy, erro
7374
// verifies the corresponding signature.
7475
func (p *policy) Evaluate(header [][]byte, payload []byte, identities [][]byte, signatures [][]byte) error {
7576
if p == nil {
76-
return fmt.Errorf("Evaluated default policy, results in reject")
77+
return errors.New("Evaluated default policy, results in reject")
7778
}
7879

7980
// XXX This is wrong, as the signatures are over the payload envelope, not the message, fix either here, or in cauthdsl once transaction is finalized
8081
if !p.evaluator.Authenticate(payload, identities, signatures) {
81-
return fmt.Errorf("Failed to authenticate policy")
82+
return errors.New("Failed to authenticate policy")
8283
}
8384
return nil
8485
}

0 commit comments

Comments
 (0)