Skip to content

Commit

Permalink
fix(rollapp): trigger EventTypeStatusChange instead of EventTypeState…
Browse files Browse the repository at this point in the history
…Update on state update finalization (#913)
  • Loading branch information
srene authored Jun 5, 2024
1 parent 983dd90 commit 3e7dfc9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion x/rollapp/keeper/block_height_to_finalization_queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (k Keeper) finalizePending(ctx sdk.Context, pendingFinalizationQueue []type

// emit event
ctx.EventManager().EmitEvent(
sdk.NewEvent(types.EventTypeStateUpdate,
sdk.NewEvent(types.EventTypeStatusChange,
stateInfo.GetEvents()...,
),
)
Expand Down
14 changes: 11 additions & 3 deletions x/rollapp/keeper/block_height_to_finalization_queue_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package keeper_test

import (
"slices"
"strconv"
"testing"

Expand Down Expand Up @@ -101,18 +102,21 @@ func (suite *RollappTestSuite) TestFinalize() {
suite.Require().Nil(err)

// Finalize pending queues and check
suite.App.EndBlocker(suite.Ctx, abci.RequestEndBlock{Height: suite.Ctx.BlockHeight()})
response := suite.App.EndBlocker(suite.Ctx, abci.RequestEndBlock{Height: suite.Ctx.BlockHeight()})
suite.Require().Len(keeper.GetAllBlockHeightToFinalizationQueue(*ctx), 2)
suite.False(findEvent(response, types.EventTypeStatusChange))

// Finalize pending queues and check
suite.Ctx = suite.Ctx.WithBlockHeight(int64(initialheight + keeper.DisputePeriodInBlocks(*ctx)))
suite.App.EndBlocker(suite.Ctx, abci.RequestEndBlock{Height: suite.Ctx.BlockHeight()})
response = suite.App.EndBlocker(suite.Ctx, abci.RequestEndBlock{Height: suite.Ctx.BlockHeight()})
suite.Require().Len(keeper.GetAllBlockHeightToFinalizationQueue(*ctx), 1)
suite.True(findEvent(response, types.EventTypeStatusChange))

// Finalize pending queues and check
suite.Ctx = suite.Ctx.WithBlockHeight(int64(initialheight + keeper.DisputePeriodInBlocks(*ctx) + 1))
suite.App.EndBlocker(suite.Ctx, abci.RequestEndBlock{Height: suite.Ctx.BlockHeight()})
response = suite.App.EndBlocker(suite.Ctx, abci.RequestEndBlock{Height: suite.Ctx.BlockHeight()})
suite.Require().Len(keeper.GetAllBlockHeightToFinalizationQueue(*ctx), 0)
suite.True(findEvent(response, types.EventTypeStatusChange))
}

/* ---------------------------------- utils --------------------------------- */
Expand All @@ -124,3 +128,7 @@ func createNBlockHeightToFinalizationQueue(keeper *keeper.Keeper, ctx sdk.Contex
}
return items
}

func findEvent(response abci.ResponseEndBlock, eventType string) bool {
return slices.ContainsFunc(response.Events, func(e abci.Event) bool { return e.Type == eventType })
}

0 comments on commit 3e7dfc9

Please sign in to comment.