Skip to content

Commit a7fb6c2

Browse files
author
Jason Yellick
committed
FAB-13612 Clarify error attempting to define seq 0
Although a user should never attempt to define a chaincode with sequence 0, if they do, the error returned is currently quite opaque. This CR adds an explicit check for this condition and returns a more useful error message. Change-Id: I868c813853d57de5306ac724f7e5a92bc2a4bc95 Signed-off-by: Jason Yellick <jyellick@us.ibm.com>
1 parent e27b85e commit a7fb6c2

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

core/chaincode/lifecycle/lifecycle.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,10 @@ func (l *Lifecycle) DefineChaincodeForOrg(cd *ChaincodeDefinition, publicState R
166166

167167
requestedSequence := cd.Sequence
168168

169+
if currentSequence == requestedSequence && requestedSequence == 0 {
170+
return errors.Errorf("requested sequence is 0, but first definable sequence number is 1")
171+
}
172+
169173
if requestedSequence < currentSequence {
170174
return errors.Errorf("currently defined sequence %d is larger than requested sequence %d", currentSequence, requestedSequence)
171175
}

core/chaincode/lifecycle/lifecycle_test.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,17 @@ var _ = Describe("Lifecycle", func() {
201201
Expect(proto.Equal(committedDefinition.Collections, &cb.CollectionConfigPackage{})).To(BeTrue())
202202
})
203203

204+
Context("when the current sequence is undefined and the requested sequence is 0", func() {
205+
BeforeEach(func() {
206+
fakePublicKVStore = map[string][]byte{}
207+
})
208+
209+
It("returns an error", func() {
210+
err := l.DefineChaincodeForOrg(&lifecycle.ChaincodeDefinition{}, fakePublicState, fakeOrgState)
211+
Expect(err).To(MatchError("requested sequence is 0, but first definable sequence number is 1"))
212+
})
213+
})
214+
204215
Context("when the sequence number already has a definition", func() {
205216
BeforeEach(func() {
206217
fakePublicKVStore = map[string][]byte{}
@@ -362,7 +373,7 @@ var _ = Describe("Lifecycle", func() {
362373
})
363374
})
364375

365-
Describe("Define", func() {
376+
Describe("DefineChaincode", func() {
366377
var (
367378
fakePublicState *mock.ReadWritableState
368379
fakeOrgStates []*mock.ReadWritableState

0 commit comments

Comments
 (0)