Skip to content

Commit

Permalink
Puneet/epochevents (#2515)
Browse files Browse the repository at this point in the history
* add events from cachectx to main ctx events

* add tests for events from hooks.

* add entry to CHANGELOG.md

(cherry picked from commit 1b5e970)

# Conflicts:
#	CHANGELOG.md
  • Loading branch information
puneet2019 authored and mergify[bot] committed Aug 26, 2022
1 parent e25af35 commit 646edbe
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,19 @@ This release contains minor CLI bug fixes.
* [1759](https://github.com/osmosis-labs/osmosis/pull/1759) Fix pagination filter in incentives query.
* [1698](https://github.com/osmosis-labs/osmosis/pull/1698) Register wasm snapshotter extension.
* [1931](https://github.com/osmosis-labs/osmosis/pull/1931) Add explicit check for input denoms to `CalcJoinPoolShares`
<<<<<<< HEAD
=======
* [2011](https://github.com/osmosis-labs/osmosis/pull/2011) Fix bug in TokenFactory initGenesis, relating to denom creation fee param.
* [2186](https://github.com/osmosis-labs/osmosis/pull/2186) Remove liquidity event that was emitted twice per message.

### 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:
* Minimum deposit on proposer at submission time: https://github.com/osmosis-labs/cosmos-sdk/pull/296
>>>>>>> 1b5e970c (Puneet/epochevents (#2515))
## [v9.0.0 - Nitrogen](https://github.com/osmosis-labs/osmosis/releases/tag/v9.0.0)

Expand Down
1 change: 1 addition & 0 deletions x/epochs/types/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,5 @@ func panicCatchingEpochHook(
cacheCtx, write := ctx.CacheContext()
hookFn(cacheCtx, epochIdentifier, epochNumber)
write()
ctx.EventManager().EmitEvents(cacheCtx.EventManager().Events())
}
27 changes: 26 additions & 1 deletion x/epochs/types/hooks_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package types_test

import (
"strconv"
"testing"

sdk "github.com/cosmos/cosmos-sdk/types"
Expand All @@ -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.
Expand All @@ -39,13 +56,16 @@ 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) {
if hook.shouldPanic {
panic("dummyEpochHook is panicking")
}
hook.successCounter += 1
ctx.EventManager().EmitEvent(dummyBeforeEpochStartEvent(epochIdentifier, epochNumber))

}

func (hook *dummyEpochHook) Clone() *dummyEpochHook {
Expand All @@ -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}
Expand All @@ -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)

}
})

Expand Down

0 comments on commit 646edbe

Please sign in to comment.