From d7d17138bf68a4962cca915decbebc2247b1cca9 Mon Sep 17 00:00:00 2001 From: chatton Date: Thu, 21 Nov 2024 12:26:34 +0000 Subject: [PATCH] chore: fixed build errors in wasm app.go --- .../08-wasm/testing/simapp/app.go | 149 ++++++++++++++---- 1 file changed, 115 insertions(+), 34 deletions(-) diff --git a/modules/light-clients/08-wasm/testing/simapp/app.go b/modules/light-clients/08-wasm/testing/simapp/app.go index c99656e2c55..a17fdbb96d9 100644 --- a/modules/light-clients/08-wasm/testing/simapp/app.go +++ b/modules/light-clients/08-wasm/testing/simapp/app.go @@ -1,8 +1,20 @@ package simapp import ( + coreaddress "cosmossdk.io/core/address" + "cosmossdk.io/x/accounts/accountstd" + baseaccount "cosmossdk.io/x/accounts/defaults/base" + "cosmossdk.io/x/accounts/defaults/lockup" + "cosmossdk.io/x/accounts/defaults/multisig" + epochstypes "cosmossdk.io/x/epochs/types" + nftkeeper "cosmossdk.io/x/nft/keeper" + txdecode "cosmossdk.io/x/tx/decode" "encoding/json" "fmt" + cmtcrypto "github.com/cometbft/cometbft/crypto" + cmted25519 "github.com/cometbft/cometbft/crypto/ed25519" + sigtypes "github.com/cosmos/cosmos-sdk/types/tx/signing" + txmodule "github.com/cosmos/cosmos-sdk/x/auth/tx/config" "io" "math/rand" "os" @@ -181,8 +193,8 @@ type SimApp struct { // keepers AuthKeeper authkeeper.AccountKeeper - AccountKeeper accounts.Keeper - BankKeeper bankkeeper.Keeper + AccountsKeeper accounts.Keeper + BankKeeper bankkeeper.BaseKeeper StakingKeeper *stakingkeeper.Keeper SlashingKeeper slashingkeeper.Keeper MintKeeper mintkeeper.Keeper @@ -219,6 +231,12 @@ type SimApp struct { configurator module.Configurator } +func (app *SimApp) ValidatorKeyProvider() runtime.KeyGenF { + return func() (cmtcrypto.PrivKey, error) { + return cmted25519.GenPrivKey(), nil + } +} + func init() { userHomeDir, err := os.UserHomeDir() if err != nil { @@ -238,22 +256,37 @@ func NewSimApp( mockVM wasmtypes.WasmEngine, baseAppOptions ...func(*baseapp.BaseApp), ) *SimApp { - interfaceRegistry, _ := types.NewInterfaceRegistryWithOptions(types.InterfaceRegistryOptions{ + interfaceRegistry, err := types.NewInterfaceRegistryWithOptions(types.InterfaceRegistryOptions{ ProtoFiles: proto.HybridResolver, SigningOptions: signing.Options{ - AddressCodec: address.Bech32Codec{ - Bech32Prefix: sdk.GetConfig().GetBech32AccountAddrPrefix(), - }, - ValidatorAddressCodec: address.Bech32Codec{ - Bech32Prefix: sdk.GetConfig().GetBech32ValidatorAddrPrefix(), - }, + AddressCodec: address.NewBech32Codec(sdk.GetConfig().GetBech32AccountAddrPrefix()), + ValidatorAddressCodec: address.NewBech32Codec(sdk.GetConfig().GetBech32ValidatorAddrPrefix()), }, }) + if err != nil { + panic(err) + } appCodec := codec.NewProtoCodec(interfaceRegistry) legacyAmino := codec.NewLegacyAmino() signingCtx := interfaceRegistry.SigningContext() + txDecoder, err := txdecode.NewDecoder(txdecode.Options{ + SigningContext: signingCtx, + ProtoCodec: appCodec, + }) + if err != nil { + panic(err) + } txConfig := authtx.NewTxConfig(appCodec, signingCtx.AddressCodec(), signingCtx.ValidatorAddressCodec(), authtx.DefaultSignModes) + govModuleAddr, err := signingCtx.AddressCodec().BytesToString(authtypes.NewModuleAddress(govtypes.ModuleName)) + if err != nil { + panic(err) + } + + if err := signingCtx.Validate(); err != nil { + panic(err) + } + std.RegisterLegacyAminoCodec(legacyAmino) std.RegisterInterfaces(interfaceRegistry) @@ -289,18 +322,16 @@ func NewSimApp( bApp.SetInterfaceRegistry(interfaceRegistry) bApp.SetTxEncoder(txConfig.TxEncoder()) - govModuleAddr, err := signingCtx.AddressCodec().BytesToString(authtypes.NewModuleAddress(govtypes.ModuleName)) - if err != nil { - panic(err) - } - keys := storetypes.NewKVStoreKeys( authtypes.StoreKey, banktypes.StoreKey, stakingtypes.StoreKey, minttypes.StoreKey, distrtypes.StoreKey, slashingtypes.StoreKey, - govtypes.StoreKey, group.StoreKey, paramstypes.StoreKey, ibcexported.StoreKey, upgradetypes.StoreKey, feegrant.StoreKey, - evidencetypes.StoreKey, ibctransfertypes.StoreKey, icacontrollertypes.StoreKey, icahosttypes.StoreKey, - authzkeeper.StoreKey, ibcfeetypes.StoreKey, consensusparamtypes.StoreKey, circuittypes.StoreKey, wasmtypes.StoreKey, - pooltypes.StoreKey, accounts.StoreKey, + govtypes.StoreKey, consensusparamtypes.StoreKey, upgradetypes.StoreKey, feegrant.StoreKey, + evidencetypes.StoreKey, circuittypes.StoreKey, + authzkeeper.StoreKey, nftkeeper.StoreKey, group.StoreKey, pooltypes.StoreKey, + accounts.StoreKey, epochstypes.StoreKey, + paramstypes.StoreKey, + ibcexported.StoreKey, ibctransfertypes.StoreKey, icacontrollertypes.StoreKey, + icahosttypes.StoreKey, ibcfeetypes.StoreKey, wasmtypes.StoreKey, ) // register streaming services @@ -322,29 +353,47 @@ func NewSimApp( memKeys: memKeys, } + cometService := runtime.NewContextAwareCometInfoService() + app.ParamsKeeper = initParamsKeeper(appCodec, legacyAmino, keys[paramstypes.StoreKey], tkeys[paramstypes.TStoreKey]) // set the BaseApp's parameter store app.ConsensusParamsKeeper = consensusparamkeeper.NewKeeper(appCodec, runtime.NewEnvironment(runtime.NewKVStoreService(keys[consensusparamtypes.StoreKey]), logger.With(log.ModuleKey, "x/consensus")), govModuleAddr) bApp.SetParamStore(app.ConsensusParamsKeeper.ParamsStore) - // SDK module keepers + // set the version modifier + bApp.SetVersionModifier(consensus.ProvideAppVersionModifier(app.ConsensusParamsKeeper)) + + // add keepers - // add keepers // add keepers + // add keepers accountsKeeper, err := accounts.NewKeeper( appCodec, runtime.NewEnvironment(runtime.NewKVStoreService(keys[accounts.StoreKey]), logger.With(log.ModuleKey, "x/accounts"), runtime.EnvWithMsgRouterService(app.MsgServiceRouter()), runtime.EnvWithQueryRouterService(app.GRPCQueryRouter())), signingCtx.AddressCodec(), appCodec.InterfaceRegistry(), + txDecoder, + // Lockup account + accountstd.AddAccount(lockup.CONTINUOUS_LOCKING_ACCOUNT, lockup.NewContinuousLockingAccount), + accountstd.AddAccount(lockup.PERIODIC_LOCKING_ACCOUNT, lockup.NewPeriodicLockingAccount), + accountstd.AddAccount(lockup.DELAYED_LOCKING_ACCOUNT, lockup.NewDelayedLockingAccount), + accountstd.AddAccount(lockup.PERMANENT_LOCKING_ACCOUNT, lockup.NewPermanentLockingAccount), + accountstd.AddAccount("multisig", multisig.NewAccount), + // PRODUCTION: add + baseaccount.NewAccount("base", txConfig.SignModeHandler(), baseaccount.WithSecp256K1PubKey()), ) if err != nil { panic(err) } - app.AccountKeeper = accountsKeeper + + app.AccountsKeeper = accountsKeeper app.AuthKeeper = authkeeper.NewAccountKeeper(runtime.NewEnvironment(runtime.NewKVStoreService(keys[authtypes.StoreKey]), logger.With(log.ModuleKey, "x/auth")), appCodec, authtypes.ProtoBaseAccount, accountsKeeper, maccPerms, signingCtx.AddressCodec(), sdk.Bech32MainPrefix, govModuleAddr) - blockedAddrs := BlockedAddresses() + blockedAddrs, err := BlockedAddresses(signingCtx.AddressCodec()) + if err != nil { + panic(err) + } app.BankKeeper = bankkeeper.NewBaseKeeper( runtime.NewEnvironment(runtime.NewKVStoreService(keys[banktypes.StoreKey]), logger.With(log.ModuleKey, "x/bank")), @@ -354,7 +403,25 @@ func NewSimApp( govModuleAddr, ) - cometService := runtime.NewContextAwareCometInfoService() + // optional: enable sign mode textual by overwriting the default tx config (after setting the bank keeper) + enabledSignModes := append(authtx.DefaultSignModes, sigtypes.SignMode_SIGN_MODE_TEXTUAL) + txConfigOpts := authtx.ConfigOptions{ + EnabledSignModes: enabledSignModes, + TextualCoinMetadataQueryFn: txmodule.NewBankKeeperCoinMetadataQueryFn(app.BankKeeper), + SigningOptions: &signing.Options{ + AddressCodec: signingCtx.AddressCodec(), + ValidatorAddressCodec: signingCtx.ValidatorAddressCodec(), + }, + } + txConfig, err = authtx.NewTxConfigWithOptions( + appCodec, + txConfigOpts, + ) + if err != nil { + panic(err) + } + app.txConfig = txConfig + app.StakingKeeper = stakingkeeper.NewKeeper( appCodec, runtime.NewEnvironment( @@ -624,19 +691,19 @@ func NewSimApp( // must be passed by reference here. app.ModuleManager = module.NewManager( genutil.NewAppModule(appCodec, app.AuthKeeper, app.StakingKeeper, app, txConfig, genutiltypes.DefaultMessageValidator), - auth.NewAppModule(appCodec, app.AuthKeeper, app.AccountKeeper, authsims.RandomGenesisAccounts, nil), + auth.NewAppModule(appCodec, app.AuthKeeper, app.AccountsKeeper, authsims.RandomGenesisAccounts, nil), vesting.NewAppModule(app.AuthKeeper, app.BankKeeper), bank.NewAppModule(appCodec, app.BankKeeper, app.AuthKeeper), - feegrantmodule.NewAppModule(appCodec, app.AuthKeeper, app.BankKeeper, app.FeeGrantKeeper, app.interfaceRegistry), + feegrantmodule.NewAppModule(appCodec, app.FeeGrantKeeper, app.interfaceRegistry), gov.NewAppModule(appCodec, &app.GovKeeper, app.AuthKeeper, app.BankKeeper, app.PoolKeeper), mint.NewAppModule(appCodec, app.MintKeeper, app.AuthKeeper, nil), slashing.NewAppModule(appCodec, app.SlashingKeeper, app.AuthKeeper, app.BankKeeper, app.StakingKeeper, app.interfaceRegistry, cometService), - distr.NewAppModule(appCodec, app.DistrKeeper, app.AuthKeeper, app.BankKeeper, app.StakingKeeper), - staking.NewAppModule(appCodec, app.StakingKeeper, app.AuthKeeper, app.BankKeeper), + distr.NewAppModule(appCodec, app.DistrKeeper, app.StakingKeeper), + staking.NewAppModule(appCodec, app.StakingKeeper), upgrade.NewAppModule(app.UpgradeKeeper), evidence.NewAppModule(appCodec, app.EvidenceKeeper, cometService), params.NewAppModule(app.ParamsKeeper), - authzmodule.NewAppModule(appCodec, app.AuthzKeeper, app.AuthKeeper, app.BankKeeper, app.interfaceRegistry), + authzmodule.NewAppModule(appCodec, app.AuthzKeeper, app.interfaceRegistry), groupmodule.NewAppModule(appCodec, app.GroupKeeper, app.AuthKeeper, app.BankKeeper, app.interfaceRegistry), consensus.NewAppModule(appCodec, app.ConsensusParamsKeeper), circuit.NewAppModule(appCodec, app.CircuitKeeper), @@ -738,7 +805,7 @@ func NewSimApp( // NOTE: this is not required apps that don't use the simulator for fuzz testing // transactions overrideModules := map[string]module.AppModuleSimulation{ - authtypes.ModuleName: auth.NewAppModule(app.appCodec, app.AuthKeeper, app.AccountKeeper, authsims.RandomGenesisAccounts, nil), + authtypes.ModuleName: auth.NewAppModule(app.appCodec, app.AuthKeeper, app.AccountsKeeper, authsims.RandomGenesisAccounts, nil), } app.simulationManager = module.NewSimulationManagerFromAppModules(app.ModuleManager.Modules, overrideModules) @@ -1017,17 +1084,31 @@ func GetMaccPerms() map[string][]string { } // BlockedAddresses returns all the app's blocked account addresses. -func BlockedAddresses() map[string]bool { +func BlockedAddresses(ac coreaddress.Codec) (map[string]bool, error) { modAccAddrs := make(map[string]bool) for acc := range GetMaccPerms() { - modAccAddrs[authtypes.NewModuleAddress(acc).String()] = true + addr, err := ac.BytesToString(authtypes.NewModuleAddress(acc)) + if err != nil { + return nil, err + } + modAccAddrs[addr] = true } // allow the following addresses to receive funds - delete(modAccAddrs, authtypes.NewModuleAddress(govtypes.ModuleName).String()) - delete(modAccAddrs, authtypes.NewModuleAddress(ibcmock.ModuleName).String()) + govAddr, err := ac.BytesToString(authtypes.NewModuleAddress(govtypes.ModuleName)) + if err != nil { + return nil, err + } + + ibcMockAddr, err := ac.BytesToString(authtypes.NewModuleAddress(ibcmock.ModuleName)) + if err != nil { + return nil, err + } + + delete(modAccAddrs, govAddr) + delete(modAccAddrs, ibcMockAddr) - return modAccAddrs + return modAccAddrs, nil } // initParamsKeeper init params keeper and its subspaces