From 817457120ce037371f207ebee7f44512fec16c0e Mon Sep 17 00:00:00 2001 From: puneetmahajan Date: Fri, 26 Aug 2022 09:55:14 +0400 Subject: [PATCH 1/3] add events from cachectx to main ctx events --- x/epochs/types/hooks.go | 1 + 1 file changed, 1 insertion(+) diff --git a/x/epochs/types/hooks.go b/x/epochs/types/hooks.go index 852226edb14..aa4cc3e4d7a 100644 --- a/x/epochs/types/hooks.go +++ b/x/epochs/types/hooks.go @@ -50,4 +50,5 @@ func panicCatchingEpochHook( cacheCtx, write := ctx.CacheContext() hookFn(cacheCtx, epochIdentifier, epochNumber) write() + ctx.EventManager().EmitEvents(cacheCtx.EventManager().Events()) } From d49cb6af031b310400c6e739aa24518a265194ba Mon Sep 17 00:00:00 2001 From: puneetmahajan Date: Fri, 26 Aug 2022 09:55:34 +0400 Subject: [PATCH 2/3] add tests for events from hooks. --- x/epochs/types/hooks_test.go | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/x/epochs/types/hooks_test.go b/x/epochs/types/hooks_test.go index 49493a3c502..1d15007fd12 100644 --- a/x/epochs/types/hooks_test.go +++ b/x/epochs/types/hooks_test.go @@ -1,6 +1,7 @@ package types_test import ( + "strconv" "testing" sdk "github.com/cosmos/cosmos-sdk/types" @@ -26,6 +27,22 @@ func (suite *KeeperTestSuite) SetupTest() { suite.queryClient = types.NewQueryClient(suite.QueryHelper) } +func dummyAfterEpochEndEvent(epochIdentifier string, epochNumber int64) sdk.Event { + return sdk.NewEvent( + "afterEpochEnd", + sdk.NewAttribute("epochIdentifier", epochIdentifier), + sdk.NewAttribute("epochNumber", strconv.FormatInt(epochNumber, 10)), + ) +} + +func dummyBeforeEpochStartEvent(epochIdentifier string, epochNumber int64) sdk.Event { + return sdk.NewEvent( + "beforeEpochStart", + sdk.NewAttribute("epochIdentifier", epochIdentifier), + sdk.NewAttribute("epochNumber", strconv.FormatInt(epochNumber, 10)), + ) +} + // dummyEpochHook is a struct satisfying the epoch hook interface, // that maintains a counter for how many times its been succesfully called, // and a boolean for whether it should panic during its execution. @@ -39,6 +56,7 @@ func (hook *dummyEpochHook) AfterEpochEnd(ctx sdk.Context, epochIdentifier strin panic("dummyEpochHook is panicking") } hook.successCounter += 1 + ctx.EventManager().EmitEvent(dummyAfterEpochEndEvent(epochIdentifier, epochNumber)) } func (hook *dummyEpochHook) BeforeEpochStart(ctx sdk.Context, epochIdentifier string, epochNumber int64) { @@ -46,6 +64,8 @@ func (hook *dummyEpochHook) BeforeEpochStart(ctx sdk.Context, epochIdentifier st panic("dummyEpochHook is panicking") } hook.successCounter += 1 + ctx.EventManager().EmitEvent(dummyBeforeEpochStartEvent(epochIdentifier, epochNumber)) + } func (hook *dummyEpochHook) Clone() *dummyEpochHook { @@ -55,7 +75,7 @@ func (hook *dummyEpochHook) Clone() *dummyEpochHook { var _ types.EpochHooks = &dummyEpochHook{} -func (suite *KeeperTestSuite) TestHooksPanicRecovery() { +func (suite *KeeperTestSuite) TestHooksPanicRecoveryAndEvents() { panicHook := dummyEpochHook{shouldPanic: true} noPanicHook := dummyEpochHook{shouldPanic: false} simpleHooks := []dummyEpochHook{panicHook, noPanicHook} @@ -81,8 +101,13 @@ func (suite *KeeperTestSuite) TestHooksPanicRecovery() { suite.NotPanics(func() { if epochActionSelector == 0 { hooks.BeforeEpochStart(suite.Ctx, "id", 0) + suite.Require().Equal(suite.Ctx.EventManager().Events(), sdk.Events{dummyBeforeEpochStartEvent("id", 0)}, + "test case index %d, before epoch event check", tcIndex) } else if epochActionSelector == 1 { hooks.AfterEpochEnd(suite.Ctx, "id", 0) + suite.Require().Equal(suite.Ctx.EventManager().Events(), sdk.Events{dummyAfterEpochEndEvent("id", 0)}, + "test case index %d, after epoch event check", tcIndex) + } }) From 4cb8ec9d348c331928eceddcf6fd93150e2fedca Mon Sep 17 00:00:00 2001 From: puneetmahajan Date: Fri, 26 Aug 2022 10:36:14 +0400 Subject: [PATCH 3/3] add entry to CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 850645df65d..befd500bae9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -105,6 +105,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Improvements * [#2214](https://github.com/osmosis-labs/osmosis/pull/2214) Speedup epoch distribution, superfluid component +* [#2515](https://github.com/osmosis-labs/osmosis/pull/2515) Emit events from functions implementing epoch hooks' `panicCatchingEpochHook` cacheCtx ### SDK Upgrades * [#2245](https://github.com/osmosis-labs/osmosis/pull/2244) Upgrade SDK with the following major changes: