Skip to content

Commit

Permalink
continue working on ibc hooks for v50
Browse files Browse the repository at this point in the history
  • Loading branch information
faddat committed Mar 6, 2024
1 parent 83a62da commit 57b349e
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 16 deletions.
27 changes: 26 additions & 1 deletion modules/ibc-hooks/simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ import (
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"

"github.com/cometbft/cometbft/libs/log"
"cosmossdk.io/log"

ica "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts"
icacontrollerkeeper "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/controller/keeper"
Expand Down Expand Up @@ -1024,3 +1024,28 @@ func (app *App) ModuleAccountAddrs() map[string]bool {
func (app *App) GetKey(storeKey string) *storetypes.KVStoreKey {
return app.keys[storeKey]
}

// BlockedAddresses returns all the app's blocked account addresses.
func BlockedAddresses() map[string]bool {
modAccAddrs := make(map[string]bool)
for acc := range GetMaccPerms() {
modAccAddrs[authtypes.NewModuleAddress(acc).String()] = true
}

// allow the following addresses to receive funds
delete(modAccAddrs, authtypes.NewModuleAddress(govtypes.ModuleName).String())

return modAccAddrs
}

// GetMaccPerms returns a copy of the module account permissions
//
// NOTE: This is solely to be used for testing purposes.
func GetMaccPerms() map[string][]string {
dupMaccPerms := make(map[string][]string)
for k, v := range maccPerms {
dupMaccPerms[k] = v
}

return dupMaccPerms
}
4 changes: 2 additions & 2 deletions modules/ibc-hooks/simapp/simulation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func setupSimulationApp(t *testing.T, msg string) (simtypes.Config, dbm.DB, simt
appOptions[flags.FlagHome] = dir // ensure a unique folder
appOptions[server.FlagInvCheckPeriod] = simcli.FlagPeriodValue

app := NewApp(logger, db, nil, true, appOptions, emptyWasmOpts, fauxMerkleModeOpt, baseapp.SetChainID(SimAppChainID))
require.Equal(t, "WasmApp", app.Name())
app := NewSimApp(logger, db, nil, true, appOptions, emptyWasmOpts, fauxMerkleModeOpt, baseapp.SetChainID(SimAppChainID))
require.Equal(t, "SimApp", app.Name())
return config, db, appOptions, app
}
24 changes: 12 additions & 12 deletions modules/ibc-hooks/simapp/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ import (
wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
)

// SetupOptions defines arguments that are passed into `WasmApp` constructor.
// SetupOptions defines arguments that are passed into `App` constructor.
type SetupOptions struct {
Logger log.Logger
DB *dbm.MemDB
Expand All @@ -67,15 +67,15 @@ func setup(t testing.TB, chainID string, withGenesis bool, invCheckPeriod uint,
appOptions := make(simtestutil.AppOptionsMap, 0)
appOptions[flags.FlagHome] = nodeHome // ensure unique folder
appOptions[server.FlagInvCheckPeriod] = invCheckPeriod
app := NewWasmApp(log.NewNopLogger(), db, nil, true, appOptions, opts, bam.SetChainID(chainID), bam.SetSnapshot(snapshotStore, snapshottypes.SnapshotOptions{KeepRecent: 2}))
app := NewApp(log.NewNopLogger(), db, nil, true, appOptions, opts, bam.SetChainID(chainID), bam.SetSnapshot(snapshotStore, snapshottypes.SnapshotOptions{KeepRecent: 2}))
if withGenesis {
return app, app.DefaultGenesis()
}
return app, GenesisState{}
}

// NewWasmAppWithCustomOptions initializes a new WasmApp with custom options.
func NewWasmAppWithCustomOptions(t *testing.T, isCheckTx bool, options SetupOptions) *App {
// NewAppWithCustomOptions initializes a new App with custom options.
func NewAppWithCustomOptions(t *testing.T, isCheckTx bool, options SetupOptions) *App {
t.Helper()

privVal := mock.NewPV()
Expand All @@ -93,7 +93,7 @@ func NewWasmAppWithCustomOptions(t *testing.T, isCheckTx bool, options SetupOpti
Coins: sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdkmath.NewInt(100000000000000))),
}

app := NewWasmApp(options.Logger, options.DB, nil, true, options.AppOpts, options.WasmOpts)
app := NewSimApp(options.Logger, options.DB, nil, true, options.AppOpts, options.WasmOpts)
genesisState := app.DefaultGenesis()
genesisState, err = GenesisStateWithValSet(app.AppCodec(), genesisState, valSet, []authtypes.GenesisAccount{acc}, balance)
require.NoError(t, err)
Expand All @@ -116,7 +116,7 @@ func NewWasmAppWithCustomOptions(t *testing.T, isCheckTx bool, options SetupOpti
return app
}

// Setup initializes a new WasmApp. A Nop logger is set in WasmApp.
// Setup initializes a new App. A Nop logger is set in App.
func Setup(t *testing.T, opts ...wasmkeeper.Option) *App {
t.Helper()

Expand All @@ -141,10 +141,10 @@ func Setup(t *testing.T, opts ...wasmkeeper.Option) *App {
return app
}

// SetupWithGenesisValSet initializes a new WasmApp with a validator set and genesis accounts
// SetupWithGenesisValSet initializes a new App with a validator set and genesis accounts
// that also act as delegators. For simplicity, each validator is bonded with a delegation
// of one consensus engine unit in the default token of the WasmApp from first genesis
// account. A Nop logger is set in WasmApp.
// of one consensus engine unit in the default token of the App from first genesis
// account. A Nop logger is set in App.
func SetupWithGenesisValSet(
t *testing.T,
valSet *cmttypes.ValidatorSet,
Expand Down Expand Up @@ -257,17 +257,17 @@ func initAccountWithCoins(app *App, ctx sdk.Context, addr sdk.AccAddress, coins

var emptyWasmOptions []wasmkeeper.Option

// NewTestNetworkFixture returns a new WasmApp AppConstructor for network simulation tests
// NewTestNetworkFixture returns a new App AppConstructor for network simulation tests
func NewTestNetworkFixture() network.TestFixture {
dir, err := os.MkdirTemp("", "simapp")
if err != nil {
panic(fmt.Sprintf("failed creating temporary directory: %v", err))
}
defer os.RemoveAll(dir)

app := NewWasmApp(log.NewNopLogger(), dbm.NewMemDB(), nil, true, simtestutil.NewAppOptionsWithFlagHome(dir), emptyWasmOptions)
app := NewSimApp(log.NewNopLogger(), dbm.NewMemDB(), nil, true, simtestutil.NewAppOptionsWithFlagHome(dir), emptyWasmOptions)
appCtr := func(val network.ValidatorI) servertypes.Application {
return NewWasmApp(
return NewSimApp(
val.GetCtx().Logger, dbm.NewMemDB(), nil, true,
simtestutil.NewAppOptionsWithFlagHome(val.GetCtx().Config.RootDir),
emptyWasmOptions,
Expand Down
2 changes: 1 addition & 1 deletion modules/ibc-hooks/tests/unit/module_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func TestIBCHooksTestSuite(t *testing.T) {

func (suite *HooksTestSuite) SetupEnv() {
// Setup the environment
app, ctx, acc := simapp.Setup(suite.T())
app := simapp.Setup(suite.T())

Check failure on line 49 in modules/ibc-hooks/tests/unit/module_test.go

View workflow job for this annotation

GitHub Actions / Linter

suite.T undefined (type *HooksTestSuite has no field or method T) (typecheck)

// create the echo contract
contractID, _, err := app.ContractKeeper.Create(ctx, acc.GetAddress(), counterWasm, nil)

Check failure on line 52 in modules/ibc-hooks/tests/unit/module_test.go

View workflow job for this annotation

GitHub Actions / Linter

undefined: ctx (typecheck)
Expand Down

0 comments on commit 57b349e

Please sign in to comment.