Skip to content

Commit

Permalink
Separate provider app and consumer app
Browse files Browse the repository at this point in the history
  • Loading branch information
trinitys7 committed Aug 30, 2024
1 parent aa0f830 commit bcf1dae
Show file tree
Hide file tree
Showing 45 changed files with 2,921 additions and 161 deletions.
1,076 changes: 1,076 additions & 0 deletions demo/app/consumer/app.go

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions demo/app/app_test.go → demo/app/consumer/app_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package app
package consumer

import (
"os"
"testing"

"github.com/CosmWasm/wasmd/x/wasm"
wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
dbm "github.com/cometbft/cometbft-db"
"github.com/cometbft/cometbft/libs/log"
"github.com/stretchr/testify/require"
Expand All @@ -13,19 +13,19 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
)

var emptyWasmOpts []wasm.Option
var emptyWasmOpts []wasmkeeper.Option

func TestMeshdExport(t *testing.T) {
db := dbm.NewMemDB()
gapp := NewMeshAppWithCustomOptions(t, false, SetupOptions{
gapp := NewMeshConsumerAppWithCustomOptions(t, false, SetupOptions{
Logger: log.NewTMLogger(log.NewSyncWriter(os.Stdout)),
DB: db,
AppOpts: simtestutil.NewAppOptionsWithFlagHome(t.TempDir()),
})
gapp.Commit()

// Making a new app object with the db, so that initchain hasn't been called
newGapp := NewMeshApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, true, simtestutil.NewAppOptionsWithFlagHome(t.TempDir()), emptyWasmOpts)
newGapp := NewMeshConsumerApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, true, simtestutil.NewAppOptionsWithFlagHome(t.TempDir()), emptyWasmOpts)
_, err := newGapp.ExportAppStateAndValidators(false, []string{}, nil)
require.NoError(t, err, "ExportAppStateAndValidators should not have an error")
}
Expand Down
2 changes: 1 addition & 1 deletion demo/app/encoding.go → demo/app/consumer/encoding.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package app
package consumer

import (
"github.com/cosmos/cosmos-sdk/std"
Expand Down
6 changes: 3 additions & 3 deletions demo/app/export.go → demo/app/consumer/export.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package app
package consumer

import (
"encoding/json"
Expand All @@ -16,7 +16,7 @@ import (

// ExportAppStateAndValidators exports the state of the application for a genesis
// file.
func (app *MeshApp) ExportAppStateAndValidators(forZeroHeight bool, jailAllowedAddrs []string, modulesToExport []string) (servertypes.ExportedApp, error) {
func (app *MeshConsumerApp) ExportAppStateAndValidators(forZeroHeight bool, jailAllowedAddrs []string, modulesToExport []string) (servertypes.ExportedApp, error) {
// as if they could withdraw from the start of the next block
ctx := app.NewContext(true, tmproto.Header{Height: app.LastBlockHeight()})

Expand Down Expand Up @@ -47,7 +47,7 @@ func (app *MeshApp) ExportAppStateAndValidators(forZeroHeight bool, jailAllowedA
// NOTE zero height genesis is a temporary feature which will be deprecated
//
// in favour of export at a block height
func (app *MeshApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []string) {
func (app *MeshConsumerApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []string) {
applyAllowedAddrs := false

// check if there is a allowed address list
Expand Down
2 changes: 1 addition & 1 deletion demo/app/genesis.go → demo/app/consumer/genesis.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package app
package consumer

import (
"encoding/json"
Expand Down
18 changes: 9 additions & 9 deletions demo/app/sim_test.go → demo/app/consumer/sim_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package app
package consumer

import (
"encoding/json"
Expand Down Expand Up @@ -130,8 +130,8 @@ func TestAppImportExport(t *testing.T) {
require.NoError(t, os.RemoveAll(newDir))
}()

newApp := NewMeshApp(log.NewNopLogger(), newDB, nil, true, appOptions, emptyWasmOpts, fauxMerkleModeOpt, baseapp.SetChainID(SimAppChainID))
require.Equal(t, "MeshApp", newApp.Name())
newApp := NewMeshConsumerApp(log.NewNopLogger(), newDB, nil, true, appOptions, emptyWasmOpts, fauxMerkleModeOpt, baseapp.SetChainID(SimAppChainID))
require.Equal(t, "MeshConsumerApp", newApp.Name())

var genesisState GenesisState
err = json.Unmarshal(exported.AppState, &genesisState)
Expand Down Expand Up @@ -233,8 +233,8 @@ func TestAppSimulationAfterImport(t *testing.T) {
require.NoError(t, os.RemoveAll(newDir))
}()

newApp := NewMeshApp(log.NewNopLogger(), newDB, nil, true, appOptions, emptyWasmOpts, fauxMerkleModeOpt, baseapp.SetChainID(SimAppChainID))
require.Equal(t, "MeshApp", newApp.Name())
newApp := NewMeshConsumerApp(log.NewNopLogger(), newDB, nil, true, appOptions, emptyWasmOpts, fauxMerkleModeOpt, baseapp.SetChainID(SimAppChainID))
require.Equal(t, "MeshConsumerApp", newApp.Name())

newApp.InitChain(abci.RequestInitChain{
ChainId: SimAppChainID,
Expand All @@ -255,7 +255,7 @@ func TestAppSimulationAfterImport(t *testing.T) {
require.NoError(t, err)
}

func setupSimulationApp(t *testing.T, msg string) (simtypes.Config, dbm.DB, simtestutil.AppOptionsMap, *MeshApp) {
func setupSimulationApp(t *testing.T, msg string) (simtypes.Config, dbm.DB, simtestutil.AppOptionsMap, *MeshConsumerApp) {
config := simcli.NewConfigFromFlags()
config.ChainID = SimAppChainID

Expand All @@ -274,8 +274,8 @@ 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 := NewMeshApp(logger, db, nil, true, appOptions, emptyWasmOpts, fauxMerkleModeOpt, baseapp.SetChainID(SimAppChainID))
require.Equal(t, "MeshApp", app.Name())
app := NewMeshConsumerApp(logger, db, nil, true, appOptions, emptyWasmOpts, fauxMerkleModeOpt, baseapp.SetChainID(SimAppChainID))
require.Equal(t, "MeshConsumerApp", app.Name())
return config, db, appOptions, app
}

Expand Down Expand Up @@ -313,7 +313,7 @@ func TestAppStateDeterminism(t *testing.T) {
}

db := dbm.NewMemDB()
app := NewMeshApp(logger, db, nil, true, appOptions, emptyWasmOpts, interBlockCacheOpt(), baseapp.SetChainID(SimAppChainID))
app := NewMeshConsumerApp(logger, db, nil, true, appOptions, emptyWasmOpts, interBlockCacheOpt(), baseapp.SetChainID(SimAppChainID))

fmt.Printf(
"running non-determinism simulation; seed %d: %d/%d, attempt: %d/%d\n",
Expand Down
44 changes: 22 additions & 22 deletions demo/app/test_helpers.go → demo/app/consumer/test_helpers.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package app
package consumer

import (
"encoding/json"
Expand Down Expand Up @@ -45,15 +45,15 @@ import (
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
)

// SetupOptions defines arguments that are passed into `MeshApp` constructor.
// SetupOptions defines arguments that are passed into `MeshConsumerApp` constructor.
type SetupOptions struct {
Logger log.Logger
DB *dbm.MemDB
AppOpts servertypes.AppOptions
WasmOpts []wasmkeeper.Option
}

func setup(t testing.TB, chainID string, withGenesis bool, invCheckPeriod uint, opts ...wasmkeeper.Option) (*MeshApp, GenesisState) {
func setup(t testing.TB, chainID string, withGenesis bool, invCheckPeriod uint, opts ...wasmkeeper.Option) (*MeshConsumerApp, GenesisState) {
db := dbm.NewMemDB()
nodeHome := t.TempDir()
snapshotDir := filepath.Join(nodeHome, "data", "snapshots")
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 := NewMeshApp(log.NewNopLogger(), db, nil, true, appOptions, opts, bam.SetChainID(chainID), bam.SetSnapshot(snapshotStore, snapshottypes.SnapshotOptions{KeepRecent: 2}))
app := NewMeshConsumerApp(log.NewNopLogger(), db, nil, true, appOptions, opts, bam.SetChainID(chainID), bam.SetSnapshot(snapshotStore, snapshottypes.SnapshotOptions{KeepRecent: 2}))
if withGenesis {
return app, NewDefaultGenesisState(app.AppCodec())
}
return app, GenesisState{}
}

// NewMeshAppWithCustomOptions initializes a new MeshApp with custom options.
func NewMeshAppWithCustomOptions(t *testing.T, isCheckTx bool, options SetupOptions) *MeshApp {
// NewMeshConsumerAppWithCustomOptions initializes a new MeshConsumerApp with custom options.
func NewMeshConsumerAppWithCustomOptions(t *testing.T, isCheckTx bool, options SetupOptions) *MeshConsumerApp {
t.Helper()

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

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

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

privVal := mock.NewPV()
Expand All @@ -141,11 +141,11 @@ func Setup(t *testing.T, opts ...wasmkeeper.Option) *MeshApp {
return app
}

// SetupWithGenesisValSet initializes a new MeshApp with a validator set and genesis accounts
// SetupWithGenesisValSet initializes a new MeshConsumerApp 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 MeshApp from first genesis
// account. A Nop logger is set in MeshApp.
func SetupWithGenesisValSet(t *testing.T, valSet *tmtypes.ValidatorSet, genAccs []authtypes.GenesisAccount, chainID string, opts []wasmkeeper.Option, balances ...banktypes.Balance) *MeshApp {
// of one consensus engine unit in the default token of the MeshConsumerApp from first genesis
// account. A Nop logger is set in MeshConsumerApp.
func SetupWithGenesisValSet(t *testing.T, valSet *tmtypes.ValidatorSet, genAccs []authtypes.GenesisAccount, chainID string, opts []wasmkeeper.Option, balances ...banktypes.Balance) *MeshConsumerApp {
t.Helper()

app, genesisState := setup(t, chainID, true, 5, opts...)
Expand Down Expand Up @@ -195,14 +195,14 @@ func SetupWithGenesisValSet(t *testing.T, valSet *tmtypes.ValidatorSet, genAccs
}

// SetupWithEmptyStore set up a wasmd app instance with empty DB
func SetupWithEmptyStore(t testing.TB) *MeshApp {
func SetupWithEmptyStore(t testing.TB) *MeshConsumerApp {
app, _ := setup(t, "testing", false, 0)
return app
}

// GenesisStateWithSingleValidator initializes GenesisState with a single validator and genesis accounts
// that also act as delegators.
func GenesisStateWithSingleValidator(t *testing.T, app *MeshApp) GenesisState {
func GenesisStateWithSingleValidator(t *testing.T, app *MeshConsumerApp) GenesisState {
t.Helper()

privVal := mock.NewPV()
Expand Down Expand Up @@ -232,11 +232,11 @@ func GenesisStateWithSingleValidator(t *testing.T, app *MeshApp) GenesisState {

// AddTestAddrsIncremental constructs and returns accNum amount of accounts with an
// initial balance of accAmt in random order
func AddTestAddrsIncremental(app *MeshApp, ctx sdk.Context, accNum int, accAmt math.Int) []sdk.AccAddress {
func AddTestAddrsIncremental(app *MeshConsumerApp, ctx sdk.Context, accNum int, accAmt math.Int) []sdk.AccAddress {
return addTestAddrs(app, ctx, accNum, accAmt, simtestutil.CreateIncrementalAccounts)
}

func addTestAddrs(app *MeshApp, ctx sdk.Context, accNum int, accAmt math.Int, strategy simtestutil.GenerateAccountStrategy) []sdk.AccAddress {
func addTestAddrs(app *MeshConsumerApp, ctx sdk.Context, accNum int, accAmt math.Int, strategy simtestutil.GenerateAccountStrategy) []sdk.AccAddress {
testAddrs := strategy(accNum)

initCoins := sdk.NewCoins(sdk.NewCoin(app.StakingKeeper.BondDenom(ctx), accAmt))
Expand All @@ -248,7 +248,7 @@ func addTestAddrs(app *MeshApp, ctx sdk.Context, accNum int, accAmt math.Int, st
return testAddrs
}

func initAccountWithCoins(app *MeshApp, ctx sdk.Context, addr sdk.AccAddress, coins sdk.Coins) {
func initAccountWithCoins(app *MeshConsumerApp, ctx sdk.Context, addr sdk.AccAddress, coins sdk.Coins) {
err := app.BankKeeper.MintCoins(ctx, minttypes.ModuleName, coins)
if err != nil {
panic(err)
Expand All @@ -262,24 +262,24 @@ func initAccountWithCoins(app *MeshApp, ctx sdk.Context, addr sdk.AccAddress, co

// ModuleAccountAddrs provides a list of blocked module accounts from configuration in AppConfig
//
// Ported from MeshApp
// Ported from MeshConsumerApp
func ModuleAccountAddrs() map[string]bool {
return BlockedAddresses()
}

var emptyWasmOptions []wasmkeeper.Option

// NewTestNetworkFixture returns a new MeshApp AppConstructor for network simulation tests
// NewTestNetworkFixture returns a new MeshConsumerApp 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 := NewMeshApp(log.NewNopLogger(), dbm.NewMemDB(), nil, true, simtestutil.NewAppOptionsWithFlagHome(dir), emptyWasmOptions)
app := NewMeshConsumerApp(log.NewNopLogger(), dbm.NewMemDB(), nil, true, simtestutil.NewAppOptionsWithFlagHome(dir), emptyWasmOptions)
appCtr := func(val network.ValidatorI) servertypes.Application {
return NewMeshApp(val.GetCtx().Logger, dbm.NewMemDB(), nil, true, simtestutil.NewAppOptionsWithFlagHome(val.GetCtx().Config.RootDir), emptyWasmOptions, bam.SetPruning(pruningtypes.NewPruningOptionsFromString(val.GetAppConfig().Pruning)), bam.SetMinGasPrices(val.GetAppConfig().MinGasPrices), bam.SetChainID(val.GetCtx().Viper.GetString(flags.FlagChainID)))
return NewMeshConsumerApp(val.GetCtx().Logger, dbm.NewMemDB(), nil, true, simtestutil.NewAppOptionsWithFlagHome(val.GetCtx().Config.RootDir), emptyWasmOptions, bam.SetPruning(pruningtypes.NewPruningOptionsFromString(val.GetAppConfig().Pruning)), bam.SetMinGasPrices(val.GetAppConfig().MinGasPrices), bam.SetChainID(val.GetCtx().Viper.GetString(flags.FlagChainID)))
}

return network.TestFixture{
Expand Down
16 changes: 8 additions & 8 deletions demo/app/test_support.go → demo/app/consumer/test_support.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package app
package consumer

import (
wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
Expand All @@ -11,30 +11,30 @@ import (
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
)

func (app *MeshApp) GetIBCKeeper() *ibckeeper.Keeper {
func (app *MeshConsumerApp) GetIBCKeeper() *ibckeeper.Keeper {
return app.IBCKeeper
}

func (app *MeshApp) GetScopedIBCKeeper() capabilitykeeper.ScopedKeeper {
func (app *MeshConsumerApp) GetScopedIBCKeeper() capabilitykeeper.ScopedKeeper {
return app.ScopedIBCKeeper
}

func (app *MeshApp) GetBaseApp() *baseapp.BaseApp {
func (app *MeshConsumerApp) GetBaseApp() *baseapp.BaseApp {
return app.BaseApp
}

func (app *MeshApp) GetBankKeeper() bankkeeper.Keeper {
func (app *MeshConsumerApp) GetBankKeeper() bankkeeper.Keeper {
return app.BankKeeper
}

func (app *MeshApp) GetStakingKeeper() *stakingkeeper.Keeper {
func (app *MeshConsumerApp) GetStakingKeeper() *stakingkeeper.Keeper {
return app.StakingKeeper
}

func (app *MeshApp) GetAccountKeeper() authkeeper.AccountKeeper {
func (app *MeshConsumerApp) GetAccountKeeper() authkeeper.AccountKeeper {
return app.AccountKeeper
}

func (app *MeshApp) GetWasmKeeper() wasmkeeper.Keeper {
func (app *MeshConsumerApp) GetWasmKeeper() wasmkeeper.Keeper {
return app.WasmKeeper
}
4 changes: 2 additions & 2 deletions demo/app/upgrades.go → demo/app/consumer/upgrades.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package app
package consumer

import (
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
Expand Down Expand Up @@ -32,7 +32,7 @@ import (
// v0.46.x to v0.47.x.
const UpgradeName = "v046-to-v047"

func (app MeshApp) RegisterUpgradeHandlers() {
func (app MeshConsumerApp) RegisterUpgradeHandlers() {
// Set param key table for params module migration
for _, subspace := range app.ParamsKeeper.GetSubspaces() {
subspace := subspace
Expand Down
Loading

0 comments on commit bcf1dae

Please sign in to comment.