Skip to content

Commit e4ce81e

Browse files
committed
check module accounts on genesis
1 parent 7f1cb00 commit e4ce81e

17 files changed

Lines changed: 117 additions & 12 deletions

File tree

app/app.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,7 @@ func New(
675675
appCodec,
676676
keys[incentivetypes.StoreKey],
677677
keys[incentivetypes.MemStoreKey],
678+
app.AccountKeeper,
678679
app.BankKeeper,
679680
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
680681
)
@@ -683,6 +684,7 @@ func New(
683684
appCodec,
684685
keys[btcbridgetypes.StoreKey],
685686
keys[btcbridgetypes.MemStoreKey],
687+
app.AccountKeeper,
686688
app.BankKeeper,
687689
app.StakingKeeper,
688690
app.OracleKeeper,
@@ -709,6 +711,7 @@ func New(
709711
appCodec,
710712
keys[liquidationtypes.StoreKey],
711713
keys[liquidationtypes.MemStoreKey],
714+
app.AccountKeeper,
712715
app.BankKeeper,
713716
app.OracleKeeper,
714717
app.TSSKeeper,

testutil/keeper/btc_bridge.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ func BtcBridgeKeeper(t testing.TB) (*keeper.Keeper, sdk.Context) {
4545
cdc,
4646
storeKey,
4747
memStoreKey,
48+
app.AccountKeeper,
4849
app.BankKeeper,
4950
app.StakingKeeper,
5051
app.OracleKeeper,

testutil/keeper/incentive.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ func IncentiveKeeper(t testing.TB) (keeper.Keeper, sdk.Context) {
4545
cdc,
4646
storeKey,
4747
memStoreKey,
48+
app.AccountKeeper,
4849
app.BankKeeper,
4950
authority,
5051
)

testutil/keeper/liquidation.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ func LiquidationKeeper(t testing.TB) (keeper.Keeper, sdk.Context) {
4545
cdc,
4646
storeKey,
4747
memStoreKey,
48+
app.AccountKeeper,
4849
app.BankKeeper,
4950
app.OracleKeeper,
5051
app.TSSKeeper,

x/btcbridge/keeper/keeper.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ type (
2626
storeKey storetypes.StoreKey
2727
memKey storetypes.StoreKey
2828

29+
authKeeper types.AccountKeeper
2930
bankKeeper types.BankKeeper
3031
stakingKeeper types.StakingKeeper
3132
oracleKeeper types.OracleKeeper
@@ -44,6 +45,7 @@ func NewKeeper(
4445
cdc codec.BinaryCodec,
4546
storeKey,
4647
memKey storetypes.StoreKey,
48+
authKeeper types.AccountKeeper,
4749
bankKeeper types.BankKeeper,
4850
stakingKeeper types.StakingKeeper,
4951
oracleKeeper types.OracleKeeper,
@@ -55,10 +57,16 @@ func NewKeeper(
5557
ibctransferKeeper types.IBCTransferKeeper,
5658
authority string,
5759
) *Keeper {
60+
// ensure the module account is set
61+
if addr := authKeeper.GetModuleAddress(types.ModuleName); addr == nil {
62+
panic(fmt.Sprintf("%s module account has not been set", types.ModuleName))
63+
}
64+
5865
return &Keeper{
5966
cdc: cdc,
6067
storeKey: storeKey,
6168
memKey: memKey,
69+
authKeeper: authKeeper,
6270
bankKeeper: bankKeeper,
6371
stakingKeeper: stakingKeeper,
6472
oracleKeeper: oracleKeeper,
@@ -92,6 +100,10 @@ func (k Keeper) GetParams(ctx sdk.Context) types.Params {
92100
return params
93101
}
94102

103+
func (k Keeper) GetModuleAccount(ctx sdk.Context) sdk.ModuleAccountI {
104+
return k.authKeeper.GetModuleAccount(ctx, types.ModuleName)
105+
}
106+
95107
func (k Keeper) BankKeeper() types.BankKeeper {
96108
return k.bankKeeper
97109
}

x/btcbridge/module/genesis.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package btcbridge
22

33
import (
4+
"fmt"
45
"sort"
56

67
sdk "github.com/cosmos/cosmos-sdk/types"
@@ -35,6 +36,12 @@ func InitGenesis(ctx sdk.Context, k keeper.Keeper, genState types.GenesisState)
3536

3637
// set the rate limit
3738
k.SetRateLimit(ctx, k.NewRateLimit(ctx))
39+
40+
// check if the module account exists
41+
moduleAcc := k.GetModuleAccount(ctx)
42+
if moduleAcc == nil {
43+
panic(fmt.Sprintf("%s module account has not been set", types.ModuleName))
44+
}
3845
}
3946

4047
// ExportGenesis returns the module's exported genesis

x/btcbridge/types/expected_keepers.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"context"
55

66
sdk "github.com/cosmos/cosmos-sdk/types"
7-
"github.com/cosmos/cosmos-sdk/x/auth/types"
87
banktype "github.com/cosmos/cosmos-sdk/x/bank/types"
98
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
109
ibctransfertypes "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types"
@@ -15,10 +14,12 @@ import (
1514
oracletypes "github.com/sideprotocol/side/x/oracle/types"
1615
)
1716

18-
// AccountKeeper defines the expected account keeper used for simulations (noalias)
17+
// AccountKeeper defines the expected account keeper interface
1918
type AccountKeeper interface {
20-
GetAccount(ctx sdk.Context, addr sdk.AccAddress) types.AccountI
21-
// Methods imported from account should be defined here
19+
GetAccount(ctx context.Context, addr sdk.AccAddress) sdk.AccountI
20+
21+
GetModuleAddress(name string) sdk.AccAddress
22+
GetModuleAccount(ctx context.Context, moduleName string) sdk.ModuleAccountI
2223
}
2324

2425
// BankKeeper defines the expected interface needed to retrieve account balances.

x/farming/module/genesis.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,6 @@ func InitGenesis(ctx sdk.Context, k keeper.Keeper, genState types.GenesisState)
2929
if moduleAcc == nil {
3030
panic(fmt.Sprintf("%s module account has not been set", types.ModuleName))
3131
}
32-
33-
// set the module account if there is zero balance
34-
balances := k.BankKeeper().GetAllBalances(ctx, moduleAcc.GetAddress())
35-
if balances.IsZero() {
36-
k.AuthKeeper().SetModuleAccount(ctx, moduleAcc)
37-
}
3832
}
3933

4034
// ExportGenesis returns the module's exported genesis

x/farming/types/expected_keepers.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ type AccountKeeper interface {
1313

1414
GetModuleAddress(name string) sdk.AccAddress
1515
GetModuleAccount(ctx context.Context, moduleName string) sdk.ModuleAccountI
16-
17-
SetModuleAccount(ctx context.Context, macc sdk.ModuleAccountI)
1816
}
1917

2018
// BankKeeper defines the expected bank keeper interface

x/incentive/keeper/keeper.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package keeper
22

33
import (
4+
"fmt"
5+
46
"cosmossdk.io/log"
57
storetypes "cosmossdk.io/store/types"
68
"github.com/cosmos/cosmos-sdk/codec"
@@ -14,6 +16,7 @@ type Keeper struct {
1416
storeKey storetypes.StoreKey
1517
memKey storetypes.StoreKey
1618

19+
authKeeper types.AccountKeeper
1720
bankKeeper types.BankKeeper
1821

1922
authority string
@@ -23,13 +26,20 @@ func NewKeeper(
2326
cdc codec.BinaryCodec,
2427
storeKey,
2528
memKey storetypes.StoreKey,
29+
authKeeper types.AccountKeeper,
2630
bankKeeper types.BankKeeper,
2731
authority string,
2832
) Keeper {
33+
// ensure the module account is set
34+
if addr := authKeeper.GetModuleAddress(types.ModuleName); addr == nil {
35+
panic(fmt.Sprintf("%s module account has not been set", types.ModuleName))
36+
}
37+
2938
return Keeper{
3039
cdc: cdc,
3140
storeKey: storeKey,
3241
memKey: memKey,
42+
authKeeper: authKeeper,
3343
bankKeeper: bankKeeper,
3444
authority: authority,
3545
}
@@ -57,3 +67,7 @@ func (k Keeper) GetParams(ctx sdk.Context) types.Params {
5767

5868
return params
5969
}
70+
71+
func (k Keeper) GetModuleAccount(ctx sdk.Context) sdk.ModuleAccountI {
72+
return k.authKeeper.GetModuleAccount(ctx, types.ModuleName)
73+
}

0 commit comments

Comments
 (0)