Skip to content

Commit

Permalink
test: proposal test of param change:
Browse files Browse the repository at this point in the history
  • Loading branch information
scorpioborn committed May 30, 2024
1 parent 980ae0e commit ab4c060
Show file tree
Hide file tree
Showing 22 changed files with 77 additions and 38 deletions.
16 changes: 8 additions & 8 deletions app/keepers/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ func NewAppKeeper(
BankKeeper: appKeepers.BankKeeper,
},
authtypes.FeeCollectorName,
govModAddress,
)

appKeepers.DistrKeeper = distrkeeper.NewKeeper(
Expand Down Expand Up @@ -475,7 +476,6 @@ func NewAppKeeper(
appKeepers.ContractKeeper = wasmkeeper.NewDefaultPermissionKeeper(&appKeepers.WasmKeeper)
appKeepers.Ics20WasmHooks.ContractKeeper = &appKeepers.WasmKeeper

authority := authtypes.NewModuleAddress(govtypes.ModuleName).String()
// // SGE keepers \\\\

appKeepers.OrderbookKeeper = orderbookmodulekeeper.NewKeeper(
Expand All @@ -487,23 +487,23 @@ func NewAppKeeper(
AccountKeeper: appKeepers.AccountKeeper,
FeeGrantKeeper: appKeepers.FeeGrantKeeper,
},
authority,
govModAddress,
)

appKeepers.OVMKeeper = ovmmodulekeeper.NewKeeper(
appCodec,
appKeepers.keys[ovmmoduletypes.StoreKey],
appKeepers.keys[ovmmoduletypes.MemStoreKey],
appKeepers.GetSubspace(ovmmoduletypes.ModuleName),
authority,
govModAddress,
)

appKeepers.MarketKeeper = marketmodulekeeper.NewKeeper(
appCodec,
appKeepers.keys[marketmoduletypes.StoreKey],
appKeepers.keys[marketmoduletypes.MemStoreKey],
appKeepers.GetSubspace(marketmoduletypes.ModuleName),
authority,
govModAddress,
)
appKeepers.MarketKeeper.SetOVMKeeper(appKeepers.OVMKeeper)
appKeepers.MarketKeeper.SetOrderbookKeeper(appKeepers.OrderbookKeeper)
Expand All @@ -513,7 +513,7 @@ func NewAppKeeper(
appKeepers.keys[betmoduletypes.StoreKey],
appKeepers.keys[betmoduletypes.MemStoreKey],
appKeepers.GetSubspace(betmoduletypes.ModuleName),
authority,
govModAddress,
)
appKeepers.BetKeeper.SetMarketKeeper(appKeepers.MarketKeeper)
appKeepers.BetKeeper.SetOrderbookKeeper(appKeepers.OrderbookKeeper)
Expand All @@ -532,7 +532,7 @@ func NewAppKeeper(
housemodulekeeper.SdkExpectedKeepers{
AuthzKeeper: appKeepers.AuthzKeeper,
},
authority,
govModAddress,
)
appKeepers.OrderbookKeeper.SetHouseKeeper(appKeepers.HouseKeeper)

Expand All @@ -546,7 +546,7 @@ func NewAppKeeper(
appKeepers.BetKeeper,
appKeepers.OrderbookKeeper,
appKeepers.HouseKeeper,
authority,
govModAddress,
)

appKeepers.RewardKeeper = rewardmodulekeeper.NewKeeper(
Expand All @@ -562,7 +562,7 @@ func NewAppKeeper(
BankKeeper: appKeepers.BankKeeper,
AccountKeeper: appKeepers.AccountKeeper,
},
authority,
govModAddress,
)

// ** Hooks ** \\
Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ require (
google.golang.org/genproto/googleapis/api v0.0.0-20240227224415-6ceb2ff114de
google.golang.org/grpc v1.63.2
gopkg.in/yaml.v2 v2.4.0
gotest.tools/v3 v3.5.1
mvdan.cc/gofumpt v0.5.0
)

Expand Down
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2273,6 +2273,7 @@ gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gotest.tools v2.2.0+incompatible h1:VsBPFP1AI068pPrMxtb/S8Zkgf9xEmTLJjfM+P5UIEo=
gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw=
gotest.tools/v3 v3.5.1 h1:EENdUnS3pdur5nybKYIh2Vfgc8IUNBjxDPSjtiJcOzU=
gotest.tools/v3 v3.5.1/go.mod h1:isy3WKz7GK6uNw/sbHzfKBLvlvXwUyV06n6brMxxopU=
Expand Down
2 changes: 1 addition & 1 deletion x/bet/simulation/proposals.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
const (
DefaultWeightMsgUpdateParams int = 100

OpWeightMsgUpdateParams = "op_weight_msg_update_params" //nolint:gosec
OpWeightMsgUpdateParams = "op_weight_msg_update_params" //#nosec
)

// ProposalMsgs defines the module weighted proposals' contents
Expand Down
1 change: 1 addition & 0 deletions x/bet/simulation/proposals_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
func TestProposalMsgs(t *testing.T) {
// initialize parameters
s := rand.NewSource(1)
//#nosec
r := rand.New(s)

ctx := sdk.NewContext(nil, tmproto.Header{}, true, nil)
Expand Down
2 changes: 1 addition & 1 deletion x/house/simulation/proposals.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
const (
DefaultWeightMsgUpdateParams int = 100

OpWeightMsgUpdateParams = "op_weight_msg_update_params" //nolint:gosec
OpWeightMsgUpdateParams = "op_weight_msg_update_params" //#nosec
)

// ProposalMsgs defines the module weighted proposals' contents
Expand Down
1 change: 1 addition & 0 deletions x/house/simulation/proposals_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
func TestProposalMsgs(t *testing.T) {
// initialize parameters
s := rand.NewSource(1)
//#nosec
r := rand.New(s)

ctx := sdk.NewContext(nil, tmproto.Header{}, true, nil)
Expand Down
4 changes: 2 additions & 2 deletions x/market/simulation/proposals.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
const (
DefaultWeightMsgUpdateParams int = 100

OpWeightMsgUpdateParams = "op_weight_msg_update_params" //nolint:gosec
OpWeightMsgUpdateParams = "op_weight_msg_update_params" //#nosec
)

// ProposalMsgs defines the module weighted proposals' contents
Expand All @@ -30,7 +30,7 @@ func ProposalMsgs() []simtypes.WeightedProposalMsg {
}

// SimulateMsgUpdateParams returns a random MsgUpdateParams
func SimulateMsgUpdateParams(r *rand.Rand, _ sdk.Context, _ []simtypes.Account) sdk.Msg {
func SimulateMsgUpdateParams(_ *rand.Rand, _ sdk.Context, _ []simtypes.Account) sdk.Msg {
// use the default gov module account address as authority
var authority sdk.AccAddress = address.Module("gov")

Expand Down
1 change: 1 addition & 0 deletions x/market/simulation/proposals_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
func TestProposalMsgs(t *testing.T) {
// initialize parameters
s := rand.NewSource(1)
//#nosec
r := rand.New(s)

ctx := sdk.NewContext(nil, tmproto.Header{}, true, nil)
Expand Down
5 changes: 5 additions & 0 deletions x/mint/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ type Keeper struct {
stakingKeeper types.StakingKeeper
bankKeeper types.BankKeeper
feeCollectorName string
// the address capable of executing a MsgUpdateParams message. Typically, this
// should be the x/gov module account.
authority string
}

// ExpectedKeepers contains expected keepers parameter needed by NewKeeper
Expand All @@ -37,6 +40,7 @@ func NewKeeper(
ak types.AccountKeeper,
expectedKeepers ExpectedKeepers,
feeCollectorName string,
authority string,
) *Keeper {
// ensure mint module account is set
if addr := ak.GetModuleAddress(types.ModuleName); addr == nil {
Expand All @@ -55,6 +59,7 @@ func NewKeeper(
stakingKeeper: expectedKeepers.StakingKeeper,
bankKeeper: expectedKeepers.BankKeeper,
feeCollectorName: feeCollectorName,
authority: authority,
}
}

Expand Down
17 changes: 17 additions & 0 deletions x/mint/keeper/msg_server.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package keeper

import (
"github.com/sge-network/sge/x/mint/types"
)

type msgServer struct {
Keeper
}

// NewMsgServerImpl returns an implementation of the MsgServer interface
// for the provided Keeper.
func NewMsgServerImpl(keeper Keeper) types.MsgServer {
return &msgServer{Keeper: keeper}
}

var _ types.MsgServer = msgServer{}
28 changes: 28 additions & 0 deletions x/mint/keeper/msg_server_params.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package keeper

import (
"context"

"cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"

"github.com/sge-network/sge/x/mint/types"
)

// UpdateParams updates the params.
func (k msgServer) UpdateParams(goCtx context.Context, req *types.MsgUpdateParams) (*types.MsgUpdateParamsResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)

if k.authority != req.Authority {
return nil, errors.Wrapf(govtypes.ErrInvalidSigner, "invalid authority; expected %s, got %s", k.authority, req.Authority)
}

if err := req.Params.Validate(); err != nil {
return nil, err
}

k.SetParams(ctx, req.Params)

return &types.MsgUpdateParamsResponse{}, nil
}
1 change: 1 addition & 0 deletions x/mint/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ func (AppModule) QuerierRoute() string { return types.QuerierRoute }
// RegisterServices registers a GRPC query service to respond to the
// module-specific GRPC queries.
func (am AppModule) RegisterServices(cfg module.Configurator) {
types.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(am.keeper))
types.RegisterQueryServer(cfg.QueryServer(), am.keeper)
}

Expand Down
19 changes: 0 additions & 19 deletions x/orderbook/keeper/msg_server_test.go

This file was deleted.

2 changes: 1 addition & 1 deletion x/orderbook/simulation/proposals.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
const (
DefaultWeightMsgUpdateParams int = 100

OpWeightMsgUpdateParams = "op_weight_msg_update_params" //nolint:gosec
OpWeightMsgUpdateParams = "op_weight_msg_update_params" //#nosec
)

// ProposalMsgs defines the module weighted proposals' contents
Expand Down
1 change: 1 addition & 0 deletions x/orderbook/simulation/proposals_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
func TestProposalMsgs(t *testing.T) {
// initialize parameters
s := rand.NewSource(1)
//#nosec
r := rand.New(s)

ctx := sdk.NewContext(nil, tmproto.Header{}, true, nil)
Expand Down
4 changes: 2 additions & 2 deletions x/ovm/simulation/proposals.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
const (
DefaultWeightMsgUpdateParams int = 100

OpWeightMsgUpdateParams = "op_weight_msg_update_params" //nolint:gosec
OpWeightMsgUpdateParams = "op_weight_msg_update_params" //#nosec
)

// ProposalMsgs defines the module weighted proposals' contents
Expand All @@ -30,7 +30,7 @@ func ProposalMsgs() []simtypes.WeightedProposalMsg {
}

// SimulateMsgUpdateParams returns a random MsgUpdateParams
func SimulateMsgUpdateParams(r *rand.Rand, _ sdk.Context, _ []simtypes.Account) sdk.Msg {
func SimulateMsgUpdateParams(_ *rand.Rand, _ sdk.Context, _ []simtypes.Account) sdk.Msg {
// use the default gov module account address as authority
var authority sdk.AccAddress = address.Module("gov")

Expand Down
1 change: 1 addition & 0 deletions x/ovm/simulation/proposals_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
func TestProposalMsgs(t *testing.T) {
// initialize parameters
s := rand.NewSource(1)
//#nosec
r := rand.New(s)

ctx := sdk.NewContext(nil, tmproto.Header{}, true, nil)
Expand Down
4 changes: 2 additions & 2 deletions x/reward/simulation/proposals.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
const (
DefaultWeightMsgUpdateParams int = 100

OpWeightMsgUpdateParams = "op_weight_msg_update_params" //nolint:gosec
OpWeightMsgUpdateParams = "op_weight_msg_update_params" //#nosec
)

// ProposalMsgs defines the module weighted proposals' contents
Expand All @@ -30,7 +30,7 @@ func ProposalMsgs() []simtypes.WeightedProposalMsg {
}

// SimulateMsgUpdateParams returns a random MsgUpdateParams
func SimulateMsgUpdateParams(r *rand.Rand, _ sdk.Context, _ []simtypes.Account) sdk.Msg {
func SimulateMsgUpdateParams(_ *rand.Rand, _ sdk.Context, _ []simtypes.Account) sdk.Msg {
// use the default gov module account address as authority
var authority sdk.AccAddress = address.Module("gov")

Expand Down
1 change: 1 addition & 0 deletions x/reward/simulation/proposals_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
func TestProposalMsgs(t *testing.T) {
// initialize parameters
s := rand.NewSource(1)
//#nosec
r := rand.New(s)

ctx := sdk.NewContext(nil, tmproto.Header{}, true, nil)
Expand Down
2 changes: 1 addition & 1 deletion x/subaccount/simulation/proposals.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
const (
DefaultWeightMsgUpdateParams int = 100

OpWeightMsgUpdateParams = "op_weight_msg_update_params" //nolint:gosec
OpWeightMsgUpdateParams = "op_weight_msg_update_params" //#nosec
)

// ProposalMsgs defines the module weighted proposals' contents
Expand Down
1 change: 1 addition & 0 deletions x/subaccount/simulation/proposals_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
func TestProposalMsgs(t *testing.T) {
// initialize parameters
s := rand.NewSource(1)
//#nosec
r := rand.New(s)

ctx := sdk.NewContext(nil, tmproto.Header{}, true, nil)
Expand Down

0 comments on commit ab4c060

Please sign in to comment.