Fix MarkEventsToIndex (#7161)
* fix MarkEventsToIndex * lint++ * fix TestDeliverTx
This commit is contained in:
parent
56f4ccfd26
commit
7b52911b2a
|
@ -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{})
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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": {
|
||||
|
|
Loading…
Reference in New Issue