Skip to content

Commit 1374d9e

Browse files
xiejunanjiangyaoguo
authored andcommitted
event name can not be nil string
event name can not be nil string Change-Id: I99d9a2bb5a39e33182e7623bac60fb052ef7741d Signed-off-by: xiejunan <[email protected]> Signed-off-by: jiangyaoguo <[email protected]>
1 parent 384e294 commit 1374d9e

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

core/chaincode/shim/chaincode.go

+3
Original file line numberDiff line numberDiff line change
@@ -904,6 +904,9 @@ func insertRowInternal(stub ChaincodeStubInterface, tableName string, row Row, u
904904

905905
// SetEvent saves the event to be sent when a transaction is made part of a block
906906
func (stub *ChaincodeStub) SetEvent(name string, payload []byte) error {
907+
if name == "" {
908+
return errors.New("Event name can not be nil string.")
909+
}
907910
stub.chaincodeEvent = &pb.ChaincodeEvent{EventName: name, Payload: payload}
908911
return nil
909912
}

core/chaincode/shim/shim_test.go

+8
Original file line numberDiff line numberDiff line change
@@ -134,3 +134,11 @@ func TestChaincodeLogging(t *testing.T) {
134134
t.Errorf("'bar' should be enabled for LogCritical")
135135
}
136136
}
137+
138+
func TestNilEventName(t *testing.T) {
139+
stub := ChaincodeStub{}
140+
if err := stub.SetEvent("", []byte("event payload")); err == nil {
141+
t.Error("Event name can not be nil string.")
142+
}
143+
144+
}

0 commit comments

Comments
 (0)