Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix simapp tests #16185

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 45 additions & 11 deletions simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@ import (
reflectionv1 "cosmossdk.io/api/cosmos/reflection/v1"
"cosmossdk.io/client/v2/autocli"
"cosmossdk.io/core/appmodule"

authcodec "github.com/cosmos/cosmos-sdk/x/auth/codec"
"github.com/cosmos/cosmos-sdk/x/auth/tx"

abci "github.com/cometbft/cometbft/abci/types"
dbm "github.com/cosmos/cosmos-db"
"github.com/cosmos/gogoproto/proto"
"github.com/spf13/cast"

simappparams "cosmossdk.io/simapp/params"
storetypes "cosmossdk.io/store/types"
"cosmossdk.io/x/evidence"
evidencekeeper "cosmossdk.io/x/evidence/keeper"
Expand All @@ -40,6 +41,7 @@ import (
"cosmossdk.io/x/circuit"
circuitkeeper "cosmossdk.io/x/circuit/keeper"
circuittypes "cosmossdk.io/x/circuit/types"

"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
Expand Down Expand Up @@ -132,6 +134,36 @@ var (
_ servertypes.Application = (*SimApp)(nil)
)

// stdAccAddressCodec is a temporary address codec that we will use until we
// can populate it with the correct bech32 prefixes without depending on the global.
type stdAccAddressCodec struct{}

func (g stdAccAddressCodec) StringToBytes(text string) ([]byte, error) {
if text == "" {
return nil, nil
}
return sdk.AccAddressFromBech32(text)
}

func (g stdAccAddressCodec) BytesToString(bz []byte) (string, error) {
if bz == nil {
return "", nil
}
return sdk.AccAddress(bz).String(), nil
}

// stdValAddressCodec is a temporary address codec that we will use until we
// can populate it with the correct bech32 prefixes without depending on the global.
type stdValAddressCodec struct{}

func (g stdValAddressCodec) StringToBytes(text string) ([]byte, error) {
return sdk.ValAddressFromBech32(text)
}

func (g stdValAddressCodec) BytesToString(bz []byte) (string, error) {
return sdk.ValAddress(bz).String(), nil
}

// SimApp extends an ABCI application, but with most of its parameters exported.
// They are exported for convenience in creating helper functions, as object
// capabilities aren't needed for testing.
Expand Down Expand Up @@ -194,12 +226,14 @@ func NewSimApp(
appOpts servertypes.AppOptions,
baseAppOptions ...func(*baseapp.BaseApp),
) *SimApp {
encodingConfig := simappparams.MakeTestEncodingConfig()

appCodec := encodingConfig.Codec
legacyAmino := encodingConfig.Amino
interfaceRegistry := encodingConfig.InterfaceRegistry
txConfig := encodingConfig.TxConfig
interfaceRegistry, _ := types.NewInterfaceRegistryWithOptions(types.InterfaceRegistryOptions{
ProtoFiles: proto.HybridResolver,
AddressCodec: stdAccAddressCodec{},
ValidatorAddressCodec: stdValAddressCodec{},
})
appCodec := codec.NewProtoCodec(interfaceRegistry)
legacyAmino := codec.NewLegacyAmino()
txConfig := tx.NewTxConfig(appCodec, tx.DefaultSignModes)

std.RegisterLegacyAminoCodec(legacyAmino)
std.RegisterInterfaces(interfaceRegistry)
Expand Down Expand Up @@ -367,7 +401,7 @@ func NewSimApp(
app.ModuleManager = module.NewManager(
genutil.NewAppModule(
app.AccountKeeper, app.StakingKeeper, app,
encodingConfig.TxConfig,
txConfig,
),
auth.NewAppModule(appCodec, app.AccountKeeper, authsims.RandomGenesisAccounts, app.GetSubspace(authtypes.ModuleName)),
vesting.NewAppModule(app.AccountKeeper, app.BankKeeper),
Expand Down Expand Up @@ -403,8 +437,8 @@ func NewSimApp(
},
),
})
app.BasicModuleManager.RegisterLegacyAminoCodec(encodingConfig.Amino)
app.BasicModuleManager.RegisterInterfaces(encodingConfig.InterfaceRegistry)
app.BasicModuleManager.RegisterLegacyAminoCodec(legacyAmino)
app.BasicModuleManager.RegisterInterfaces(interfaceRegistry)

// During begin block slashing happens after distr.BeginBlocker so that
// there is nothing left over in the validator fee pool, so as to keep the
Expand Down Expand Up @@ -486,7 +520,7 @@ func NewSimApp(
app.SetInitChainer(app.InitChainer)
app.SetBeginBlocker(app.BeginBlocker)
app.SetEndBlocker(app.EndBlocker)
app.setAnteHandler(encodingConfig.TxConfig)
app.setAnteHandler(txConfig)

// In v0.46, the SDK introduces _postHandlers_. PostHandlers are like
// antehandlers, but are run _after_ the `runMsgs` execution. They are also
Expand Down