diff --git a/simapp/simd/cmd/testnet.go b/simapp/simd/cmd/testnet.go index 0717b398427c..93ec60b675ff 100644 --- a/simapp/simd/cmd/testnet.go +++ b/simapp/simd/cmd/testnet.go @@ -289,8 +289,16 @@ func initGenFiles( var bankGenState banktypes.GenesisState clientCtx.JSONMarshaler.MustUnmarshalJSON(appGenState[banktypes.ModuleName], &bankGenState) +<<<<<<< HEAD bankGenState.Balances = genBalances appGenState[banktypes.ModuleName] = clientCtx.JSONMarshaler.MustMarshalJSON(&bankGenState) +======= + bankGenState.Balances = banktypes.SanitizeGenesisBalances(genBalances) + for _, bal := range bankGenState.Balances { + bankGenState.Supply = bankGenState.Supply.Add(bal.Coins...) + } + appGenState[banktypes.ModuleName] = clientCtx.Codec.MustMarshalJSON(&bankGenState) +>>>>>>> 179c819a9 (fix: testnet cli command update genesis supply (#9497)) appGenStateJSON, err := json.MarshalIndent(appGenState, "", " ") if err != nil { diff --git a/simapp/simd/cmd/testnet_test.go b/simapp/simd/cmd/testnet_test.go new file mode 100644 index 000000000000..da58fd454d82 --- /dev/null +++ b/simapp/simd/cmd/testnet_test.go @@ -0,0 +1,50 @@ +package cmd + +import ( + "context" + "fmt" + "testing" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/cosmos/cosmos-sdk/server" + "github.com/cosmos/cosmos-sdk/simapp" + banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" + genutiltest "github.com/cosmos/cosmos-sdk/x/genutil/client/testutil" + genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" + "github.com/spf13/viper" + "github.com/stretchr/testify/require" + "github.com/tendermint/tendermint/libs/log" +) + +func Test_TestnetCmd(t *testing.T) { + home := t.TempDir() + encodingConfig := simapp.MakeTestEncodingConfig() + logger := log.NewNopLogger() + cfg, err := genutiltest.CreateDefaultTendermintConfig(home) + require.NoError(t, err) + + err = genutiltest.ExecInitCmd(simapp.ModuleBasics, home, encodingConfig.Marshaler) + require.NoError(t, err) + + serverCtx := server.NewContext(viper.New(), cfg, logger) + clientCtx := client.Context{}. + WithCodec(encodingConfig.Marshaler). + WithHomeDir(home). + WithTxConfig(encodingConfig.TxConfig) + + ctx := context.Background() + ctx = context.WithValue(ctx, server.ServerContextKey, serverCtx) + ctx = context.WithValue(ctx, client.ClientContextKey, &clientCtx) + cmd := testnetCmd(simapp.ModuleBasics, banktypes.GenesisBalancesIterator{}) + cmd.SetArgs([]string{fmt.Sprintf("--%s=test", flags.FlagKeyringBackend), fmt.Sprintf("--output-dir=%s", home)}) + err = cmd.ExecuteContext(ctx) + require.NoError(t, err) + + genFile := cfg.GenesisFile() + appState, _, err := genutiltypes.GenesisStateFromGenFile(genFile) + require.NoError(t, err) + + bankGenState := banktypes.GetGenesisStateFromAppState(encodingConfig.Marshaler, appState) + require.NotEmpty(t, bankGenState.Supply.String()) +}