diff --git a/baseapp/baseapp_test.go b/baseapp/baseapp_test.go index 931e7ef50..05038ce2c 100644 --- a/baseapp/baseapp_test.go +++ b/baseapp/baseapp_test.go @@ -832,8 +832,8 @@ func TestDeliverTx(t *testing.T) { require.True(t, res.IsOK(), fmt.Sprintf("%v", res)) events := res.GetEvents() require.Len(t, events, 3, "should contain ante handler, message type and counter events respectively") - require.Equal(t, counterEvent("ante_handler", counter).ToABCIEvents()[0], events[0], "ante handler event") - require.Equal(t, counterEvent(sdk.EventTypeMessage, counter).ToABCIEvents()[0], events[2], "msg handler update counter event") + require.Equal(t, sdk.MarkEventsToIndex(counterEvent("ante_handler", counter).ToABCIEvents(), map[string]struct{}{})[0], events[0], "ante handler event") + require.Equal(t, sdk.MarkEventsToIndex(counterEvent(sdk.EventTypeMessage, counter).ToABCIEvents(), map[string]struct{}{})[0], events[2], "msg handler update counter event") } app.EndBlock(abci.RequestEndBlock{}) diff --git a/types/events.go b/types/events.go index 988cd05ea..d334d3d60 100644 --- a/types/events.go +++ b/types/events.go @@ -203,7 +203,9 @@ func StringifyEvents(events []abci.Event) StringEvents { // MarkEventsToIndex returns the set of ABCI events, where each event's attribute // has it's index value marked based on the provided set of events to index. func MarkEventsToIndex(events []abci.Event, indexSet map[string]struct{}) []abci.Event { + indexAll := len(indexSet) == 0 updatedEvents := make([]abci.Event, len(events)) + for i, e := range events { updatedEvent := abci.Event{ Type: e.Type, @@ -215,7 +217,7 @@ func MarkEventsToIndex(events []abci.Event, indexSet map[string]struct{}) []abci updatedAttr := abci.EventAttribute{ Key: attr.Key, Value: attr.Value, - Index: index, + Index: index || indexAll, } updatedEvent.Attributes[j] = updatedAttr diff --git a/types/events_test.go b/types/events_test.go index ad855f71a..ad8bf767a 100644 --- a/types/events_test.go +++ b/types/events_test.go @@ -95,8 +95,23 @@ func TestMarkEventsToIndex(t *testing.T) { expected []abci.Event }{ "empty index set": { - events: events, - expected: events, + events: events, + expected: []abci.Event{ + { + Type: "message", + Attributes: []abci.EventAttribute{ + {Key: []byte("sender"), Value: []byte("foo"), Index: true}, + {Key: []byte("recipient"), Value: []byte("bar"), Index: true}, + }, + }, + { + Type: "staking", + Attributes: []abci.EventAttribute{ + {Key: []byte("deposit"), Value: []byte("5"), Index: true}, + {Key: []byte("unbond"), Value: []byte("10"), Index: true}, + }, + }, + }, indexSet: map[string]struct{}{}, }, "index some events": {