diff --git a/tests/e2e/initialization/config.go b/tests/e2e/initialization/config.go index 062c4d20871..0611ab872fa 100644 --- a/tests/e2e/initialization/config.go +++ b/tests/e2e/initialization/config.go @@ -8,10 +8,9 @@ import ( "github.com/cosmos/cosmos-sdk/server" sdk "github.com/cosmos/cosmos-sdk/types" - authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + authhelpers "github.com/cosmos/cosmos-sdk/x/auth/helpers" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" crisistypes "github.com/cosmos/cosmos-sdk/x/crisis/types" - "github.com/cosmos/cosmos-sdk/x/genutil" genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" staketypes "github.com/cosmos/cosmos-sdk/x/staking/types" @@ -124,72 +123,11 @@ func addAccount(path, moniker, amountStr string, accAddr sdk.AccAddress, forkHei config.SetRoot(path) config.Moniker = moniker - coins, err := sdk.ParseCoinsNormalized(amountStr) - if err != nil { - return fmt.Errorf("failed to parse coins: %w", err) - } - coins = coins.Add(sdk.NewCoin(E2EFeeToken, sdk.NewInt(GenesisFeeBalance))) - - balances := banktypes.Balance{Address: accAddr.String(), Coins: coins.Sort()} - genAccount := authtypes.NewBaseAccount(accAddr, nil, 0, 0) - - // TODO: Make the SDK make it far cleaner to add an account to GenesisState + feeToken := sdk.NewCoin(E2EFeeToken, sdk.NewInt(GenesisFeeBalance)) + amountStr = amountStr + "," + feeToken.String() genFile := config.GenesisFile() - appState, genDoc, err := genutiltypes.GenesisStateFromGenFile(genFile) - if err != nil { - return fmt.Errorf("failed to unmarshal genesis state: %w", err) - } - - genDoc.InitialHeight = int64(forkHeight) - - authGenState := authtypes.GetGenesisStateFromAppState(util.Cdc, appState) - - accs, err := authtypes.UnpackAccounts(authGenState.Accounts) - if err != nil { - return fmt.Errorf("failed to get accounts from any: %w", err) - } - - if accs.Contains(accAddr) { - return fmt.Errorf("failed to add account to genesis state; account already exists: %s", accAddr) - } - - // Add the new account to the set of genesis accounts and sanitize the - // accounts afterwards. - accs = append(accs, genAccount) - accs = authtypes.SanitizeGenesisAccounts(accs) - - genAccs, err := authtypes.PackAccounts(accs) - if err != nil { - return fmt.Errorf("failed to convert accounts into any's: %w", err) - } - - authGenState.Accounts = genAccs - - authGenStateBz, err := util.Cdc.MarshalJSON(&authGenState) - if err != nil { - return fmt.Errorf("failed to marshal auth genesis state: %w", err) - } - - appState[authtypes.ModuleName] = authGenStateBz - - bankGenState := banktypes.GetGenesisStateFromAppState(util.Cdc, appState) - bankGenState.Balances = append(bankGenState.Balances, balances) - bankGenState.Balances = banktypes.SanitizeGenesisBalances(bankGenState.Balances) - - bankGenStateBz, err := util.Cdc.MarshalJSON(bankGenState) - if err != nil { - return fmt.Errorf("failed to marshal bank genesis state: %w", err) - } - - appState[banktypes.ModuleName] = bankGenStateBz - - appStateJSON, err := json.Marshal(appState) - if err != nil { - return fmt.Errorf("failed to marshal application genesis state: %w", err) - } - genDoc.AppState = appStateJSON - return genutil.ExportGenesisFile(genDoc, genFile) + return authhelpers.AddGenesisAccount(util.Cdc, accAddr, false, genFile, amountStr, "", 0, 0) } func updateModuleGenesis[V proto.Message](appGenState map[string]json.RawMessage, moduleName string, protoVal V, updateGenesis func(V)) error {