Skip to content

Commit

Permalink
event name can not be nil string
Browse files Browse the repository at this point in the history
event name can not be nil string

Change-Id: I99d9a2bb5a39e33182e7623bac60fb052ef7741d
Signed-off-by: xiejunan <xiejunan@huawei.com>
Signed-off-by: jiangyaoguo <jiangyaoguo@gmail.com>
  • Loading branch information
xiejunan authored and jiangyaoguo committed Dec 22, 2016
1 parent 384e294 commit 1374d9e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
3 changes: 3 additions & 0 deletions core/chaincode/shim/chaincode.go
Original file line number Diff line number Diff line change
Expand Up @@ -904,6 +904,9 @@ func insertRowInternal(stub ChaincodeStubInterface, tableName string, row Row, u

// SetEvent saves the event to be sent when a transaction is made part of a block
func (stub *ChaincodeStub) SetEvent(name string, payload []byte) error {
if name == "" {
return errors.New("Event name can not be nil string.")
}
stub.chaincodeEvent = &pb.ChaincodeEvent{EventName: name, Payload: payload}
return nil
}
Expand Down
8 changes: 8 additions & 0 deletions core/chaincode/shim/shim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,11 @@ func TestChaincodeLogging(t *testing.T) {
t.Errorf("'bar' should be enabled for LogCritical")
}
}

func TestNilEventName(t *testing.T) {
stub := ChaincodeStub{}
if err := stub.SetEvent("", []byte("event payload")); err == nil {
t.Error("Event name can not be nil string.")
}

}

0 comments on commit 1374d9e

Please sign in to comment.