Skip to content

Commit 336738b

Browse files
mergify[bot]mmsqealjo242
authored andcommitted
fix(x/epochs): fix register of epoch hooks in InvokeSetHooks (backport cosmos#24770) (cosmos#24779)
Co-authored-by: mmsqe <[email protected]> Co-authored-by: aljo242 <[email protected]>
1 parent 1a7f097 commit 336738b

File tree

4 files changed

+68
-6
lines changed

4 files changed

+68
-6
lines changed

.github/workflows/dependabot-update-all.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,7 @@ jobs:
1414
if: ${{ github.actor == 'dependabot[bot]' }}
1515
steps:
1616
- name: Generate Token
17-
<<<<<<< HEAD
1817
uses: actions/create-github-app-token@3ff1caaa28b64c9cc276ce0a02e2ff584f3900c5 # v1
19-
=======
20-
uses: actions/create-github-app-token@df432ceedc7162793a195dd1713ff69aefc7379e # v1
21-
>>>>>>> acb39aa52 (build(deps): Bump actions/create-github-app-token from 2.0.3 to 2.0.6 (#24673))
2218
id: app-token
2319
with:
2420
app-id: "${{ secrets.APP_ID }}"

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ Ref: https://keepachangelog.com/en/1.0.0/
3636

3737
# Changelog
3838

39+
## [Unreleased]
40+
41+
### Bug Fixes
42+
43+
* (x/epochs) [#24770](https://github.com/cosmos/cosmos-sdk/pull/24770) Fix register of epoch hooks in `InvokeSetHooks`.
44+
3945
## [v0.53.0](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.53.0) - 2025-04-29
4046

4147
### Features

x/epochs/depinject.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ func ProvideModule(in ModuleInputs) ModuleOutputs {
4949
return ModuleOutputs{EpochKeeper: k, Module: m}
5050
}
5151

52-
func InvokeSetHooks(keeper keeper.Keeper, hooks map[string]types.EpochHooksWrapper) error {
53-
if hooks == nil {
52+
func InvokeSetHooks(keeper *keeper.Keeper, hooks map[string]types.EpochHooksWrapper) error {
53+
if keeper == nil || hooks == nil {
5454
return nil
5555
}
5656

x/epochs/depinject_test.go

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package epochs_test
2+
3+
import (
4+
"context"
5+
"testing"
6+
7+
"github.com/stretchr/testify/require"
8+
9+
storetypes "cosmossdk.io/store/types"
10+
11+
"github.com/cosmos/cosmos-sdk/runtime"
12+
"github.com/cosmos/cosmos-sdk/types/module/testutil"
13+
"github.com/cosmos/cosmos-sdk/x/epochs"
14+
"github.com/cosmos/cosmos-sdk/x/epochs/keeper"
15+
"github.com/cosmos/cosmos-sdk/x/epochs/types"
16+
)
17+
18+
type testEpochHooks struct{}
19+
20+
func (h testEpochHooks) AfterEpochEnd(ctx context.Context, epochIdentifier string, epochNumber int64) error {
21+
return nil
22+
}
23+
24+
func (h testEpochHooks) BeforeEpochStart(ctx context.Context, epochIdentifier string, epochNumber int64) error {
25+
return nil
26+
}
27+
28+
func TestInvokeSetHooks(t *testing.T) {
29+
// Create a mock keeper
30+
key := storetypes.NewKVStoreKey(types.StoreKey)
31+
storeService := runtime.NewKVStoreService(key)
32+
encCfg := testutil.MakeTestEncodingConfig()
33+
mockKeeper := keeper.NewKeeper(storeService, encCfg.Codec)
34+
35+
// Create mock hooks
36+
hook1 := types.EpochHooksWrapper{
37+
EpochHooks: testEpochHooks{},
38+
}
39+
hook2 := types.EpochHooksWrapper{
40+
EpochHooks: testEpochHooks{},
41+
}
42+
hooks := map[string]types.EpochHooksWrapper{
43+
"moduleA": hook1,
44+
"moduleB": hook2,
45+
}
46+
47+
// Call InvokeSetHooks
48+
err := epochs.InvokeSetHooks(&mockKeeper, hooks)
49+
require.NoError(t, err)
50+
51+
// Verify that hooks were set correctly
52+
require.NotNil(t, mockKeeper.Hooks())
53+
require.IsType(t, types.MultiEpochHooks{}, mockKeeper.Hooks())
54+
55+
// Verify the order of hooks (lexical order by module name)
56+
multiHooks := mockKeeper.Hooks().(types.MultiEpochHooks)
57+
require.Equal(t, 2, len(multiHooks))
58+
require.Equal(t, hook1, multiHooks[0])
59+
require.Equal(t, hook2, multiHooks[1])
60+
}

0 commit comments

Comments
 (0)