Skip to content

Commit

Permalink
register everything, add simulation etc
Browse files Browse the repository at this point in the history
  • Loading branch information
quasisamurai committed Sep 16, 2024
1 parent e0360d0 commit afd556c
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 25 deletions.
8 changes: 6 additions & 2 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ var (
),
ibchooks.AppModuleBasic{},
packetforward.AppModuleBasic{},
ibcratelimitmodule.AppModuleBasic{},
auction.AppModuleBasic{},
globalfee.AppModule{},
feemarket.AppModuleBasic{},
Expand Down Expand Up @@ -379,6 +380,8 @@ type App struct {

PFMModule packetforward.AppModule

//IBCRLModule ibcratelimitmodule.AppModule

Check failure on line 383 in app/app.go

View workflow job for this annotation

GitHub Actions / lint

commentFormatting: put a space between `//` and comment text (gocritic)

TransferStack *ibchooks.IBCMiddleware
Ics20WasmHooks *ibchooks.WasmHooks
RateLimitingICS4Wrapper *ibcratelimit.ICS4Wrapper
Expand Down Expand Up @@ -631,6 +634,7 @@ func New(
)

app.WireICS20PreWasmKeeper(appCodec)
//app:= feerefunder.NewAppModule(appCodec, *app.FeeKeeper, app.AccountKeeper, app.BankKeeper)
app.PFMModule = packetforward.NewAppModule(app.PFMKeeper, app.GetSubspace(pfmtypes.ModuleName))

app.ICAControllerKeeper = icacontrollerkeeper.NewKeeper(
Expand Down Expand Up @@ -875,7 +879,7 @@ func New(
)
interchainTxsModule := interchaintxs.NewAppModule(appCodec, app.InterchainTxsKeeper, app.AccountKeeper, app.BankKeeper)
contractManagerModule := contractmanager.NewAppModule(appCodec, app.ContractManagerKeeper)
ibcRateLimitmodule := ibcratelimitmodule.NewAppModule(*app.RateLimitingICS4Wrapper)
ibcRateLimitmodule := ibcratelimitmodule.NewAppModule(appCodec, *app.RateLimitingICS4Wrapper.IbcratelimitKeeper, *app.RateLimitingICS4Wrapper)
ibcHooksModule := ibchooks.NewAppModule(app.AccountKeeper)

transferModule := transferSudo.NewAppModule(app.TransferKeeper)
Expand Down Expand Up @@ -1093,6 +1097,7 @@ func New(
ibc.NewAppModule(app.IBCKeeper),
params.NewAppModule(app.ParamsKeeper),
transferModule,
ibcRateLimitmodule,
consumerModule,
icaModule,
app.PFMModule,
Expand Down Expand Up @@ -1691,7 +1696,6 @@ func (app *App) WireICS20PreWasmKeeper(
// wasm keeper we set later.
nil,
&app.BankKeeper,
app.GetSubspace(ibcratelimittypes.ModuleName),
&ibcratelimitKeeper,
)
app.RateLimitingICS4Wrapper = &rateLimitingICS4Wrapper
Expand Down
11 changes: 5 additions & 6 deletions x/ibc-rate-limit/ibc_middleware_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -614,13 +614,12 @@ func (suite *MiddlewareTestSuite) InstantiateRLContract(quotas string) sdk.AccAd
}

func (suite *MiddlewareTestSuite) RegisterRateLimitingContract(addr []byte) {
addrStr, err := sdk.Bech32ifyAddressBytes("neutron", addr)
msg := types.MsgUpdateParams{Params: types.Params{ContractAddress: addrStr}}
require.NoError(suite.ChainA.TB, err)
addrStr, _ := sdk.Bech32ifyAddressBytes("neutron", addr)
app := suite.GetNeutronZoneApp(suite.ChainA)
paramSpace, ok := app.HooksICS4Wrapper.GetSubspace(types.ModuleName)
require.True(suite.ChainA.TB, ok)
paramSpace.SetParamSet(suite.ChainA.GetContext(), &params)
_ = app.RateLimitingICS4Wrapper.IbcratelimitKeeper.SetParams(suite.ChainA.GetContext(), types.Params{ContractAddress: addrStr})
a := app.RateLimitingICS4Wrapper.GetContractAddress(suite.ChainA.GetContext())
fmt.Println(a)
require.True(suite.ChainA.TB, true)
}

// AssertEventEmitted asserts that ctx's event manager has emitted the given number of events
Expand Down
25 changes: 20 additions & 5 deletions x/ibc-rate-limit/ibcratelimitmodule/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"

"github.com/grpc-ecosystem/grpc-gateway/runtime"
"github.com/neutron-org/neutron/v4/x/ibc-rate-limit/keeper"
"github.com/spf13/cobra"

codectypes "github.com/cosmos/cosmos-sdk/codec/types"
Expand Down Expand Up @@ -35,11 +36,18 @@ var (
_ module.HasServices = AppModule{}
)

type AppModuleBasic struct{}
type AppModuleBasic struct {
cdc codec.BinaryCodec
}

func NewAppModuleBasic(cdc codec.BinaryCodec) AppModuleBasic {
return AppModuleBasic{cdc: cdc}
}

func (AppModuleBasic) Name() string { return types.ModuleName }

func (AppModuleBasic) RegisterLegacyAminoCodec(_ *codec.LegacyAmino) {
func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
types.RegisterCodec(cdc)
}

func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage {
Expand Down Expand Up @@ -70,7 +78,8 @@ func (b AppModuleBasic) GetQueryCmd() *cobra.Command {
}

// RegisterInterfaces registers interfaces and implementations of the ibc-rate-limit module.
func (AppModuleBasic) RegisterInterfaces(_ codectypes.InterfaceRegistry) {
func (AppModuleBasic) RegisterInterfaces(reg codectypes.InterfaceRegistry) {
types.RegisterInterfaces(reg)
}

// ----------------------------------------------------------------------------
Expand All @@ -82,11 +91,16 @@ type AppModule struct {
AppModuleBasic

ics4wrapper ibcratelimit.ICS4Wrapper
keeper keeper.Keeper
}

func NewAppModule(ics4wrapper ibcratelimit.ICS4Wrapper) AppModule {
func NewAppModule(
cdc codec.Codec,
keeper keeper.Keeper,
ics4wrapper ibcratelimit.ICS4Wrapper) AppModule {
return AppModule{
AppModuleBasic: AppModuleBasic{},
AppModuleBasic: NewAppModuleBasic(cdc),
keeper: keeper,
ics4wrapper: ics4wrapper,
}
}
Expand All @@ -109,6 +123,7 @@ func (AppModule) QuerierRoute() string { return types.RouterKey }
// module-specific GRPC queries.
func (am AppModule) RegisterServices(cfg module.Configurator) {
queryproto.RegisterQueryServer(cfg.QueryServer(), grpc.Querier{Q: ibcratelimitclient.Querier{K: am.ics4wrapper}})
types.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(am.keeper))
}

// RegisterInvariants registers the txfees module's invariants.
Expand Down
48 changes: 48 additions & 0 deletions x/ibc-rate-limit/ibcratelimitmodule/module_simulation.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package ibcratelimitmodule

import (
"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/testutil/sims"
"github.com/cosmos/cosmos-sdk/types/module"
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
"github.com/cosmos/cosmos-sdk/x/simulation"
"github.com/neutron-org/neutron/v4/testutil/common/sample"
ibcratelimitsimulation "github.com/neutron-org/neutron/v4/x/ibc-rate-limit/simulation"
"github.com/neutron-org/neutron/v4/x/ibc-rate-limit/types"
)

// avoid unused import issue
var (
_ = sample.AccAddress
_ = ibcratelimitsimulation.FindAccount
_ = sims.StakePerAccount
_ = simulation.MsgEntryKind
_ = baseapp.Paramspace
)

// GenerateGenesisState creates a randomized GenState of the module
func (AppModule) GenerateGenesisState(simState *module.SimulationState) {
accs := make([]string, len(simState.Accounts))
for i, acc := range simState.Accounts {
accs[i] = acc.Address.String()
}
interchainqueriesGenesis := types.GenesisState{
Params: types.DefaultParams(),
}
simState.GenState[types.ModuleName] = simState.Cdc.MustMarshalJSON(&interchainqueriesGenesis)
}

// ProposalContents doesn't return any content functions for governance proposals
func (AppModule) ProposalContents(_ module.SimulationState) []simtypes.WeightedProposalMsg {
return nil
}

// RegisterStoreDecoder registers a decoder
func (am AppModule) RegisterStoreDecoder(_ simtypes.StoreDecoderRegistry) {}

// WeightedOperations returns the all the gov module operations with their respective weights.
func (am AppModule) WeightedOperations(_ module.SimulationState) []simtypes.WeightedOperation {
operations := make([]simtypes.WeightedOperation, 0)

return operations
}
16 changes: 5 additions & 11 deletions x/ibc-rate-limit/ics4_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper"
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types"
transfertypes "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types"
clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types"
Expand All @@ -31,8 +30,7 @@ type ICS4Wrapper struct {
accountKeeper *authkeeper.AccountKeeper
bankKeeper *bankkeeper.BaseKeeper
ContractKeeper *wasmkeeper.PermissionedKeeper
paramSpace paramtypes.Subspace
ibcratelimitKeeper *keeper.Keeper
IbcratelimitKeeper *keeper.Keeper
}

func (i *ICS4Wrapper) GetAppVersion(ctx sdk.Context, portID, channelID string) (string, bool) {
Expand All @@ -42,18 +40,14 @@ func (i *ICS4Wrapper) GetAppVersion(ctx sdk.Context, portID, channelID string) (
func NewICS4Middleware(
channel porttypes.ICS4Wrapper,
accountKeeper *authkeeper.AccountKeeper, contractKeeper *wasmkeeper.PermissionedKeeper,
bankKeeper *bankkeeper.BaseKeeper, paramSpace paramtypes.Subspace, ibcratelimitkeeper *keeper.Keeper,
bankKeeper *bankkeeper.BaseKeeper, ibcratelimitkeeper *keeper.Keeper,
) ICS4Wrapper {
if !paramSpace.HasKeyTable() {
paramSpace = paramSpace.WithKeyTable(types.ParamKeyTable())
}
return ICS4Wrapper{
channel: channel,
accountKeeper: accountKeeper,
ContractKeeper: contractKeeper,
bankKeeper: bankKeeper,
paramSpace: paramSpace,
ibcratelimitKeeper: ibcratelimitkeeper,
IbcratelimitKeeper: ibcratelimitkeeper,
}
}

Expand Down Expand Up @@ -105,10 +99,10 @@ func (i *ICS4Wrapper) GetContractAddress(ctx sdk.Context) (contract string) {
}

func (i *ICS4Wrapper) GetParams(ctx sdk.Context) (params types.Params) {
params = i.ibcratelimitKeeper.GetParams(ctx)
params = i.IbcratelimitKeeper.GetParams(ctx)
return params
}

func (i *ICS4Wrapper) SetParams(ctx sdk.Context, params types.Params) {
i.ibcratelimitKeeper.SetParams(ctx, params)
i.IbcratelimitKeeper.SetParams(ctx, params)

Check failure on line 107 in x/ibc-rate-limit/ics4_wrapper.go

View workflow job for this annotation

GitHub Actions / lint

Error return value of `i.IbcratelimitKeeper.SetParams` is not checked (errcheck)
}
15 changes: 15 additions & 0 deletions x/ibc-rate-limit/simulation/simap.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package simulation

import (
sdk "github.com/cosmos/cosmos-sdk/types"
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
)

// FindAccount find a specific address from an account list
func FindAccount(accs []simtypes.Account, address string) (simtypes.Account, bool) {
creator, err := sdk.AccAddressFromBech32(address)
if err != nil {
panic(err)
}
return simtypes.FindAccount(accs, creator)
}
2 changes: 1 addition & 1 deletion x/ibc-rate-limit/types/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ func RegisterInterfaces(registry cdctypes.InterfaceRegistry) {

var (
Amino = codec.NewLegacyAmino()
ModuleCdc = codec.NewProtoCodec(cdctypes.NewInterfaceRegistry())
ModuleCdc *codec.ProtoCodec
)

0 comments on commit afd556c

Please sign in to comment.