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: missing supply for add-genesis-account #498

Merged
merged 4 commits into from
Mar 22, 2023
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion module/cmd/gravity/cmd/genaccounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ contain valid denominations. Accounts may optionally be supplied with vesting pa
bankGenState := banktypes.GetGenesisStateFromAppState(depCdc, appState)
bankGenState.Balances = append(bankGenState.Balances, balances)
bankGenState.Balances = banktypes.SanitizeGenesisBalances(bankGenState.Balances)

bankGenState.Supply = bankGenState.Supply.Add(balances.Coins...)
cbrit marked this conversation as resolved.
Show resolved Hide resolved
bankGenStateBz, err := cdc.MarshalJSON(bankGenState)
if err != nil {
return fmt.Errorf("failed to marshal bank genesis state: %w", err)
Expand Down
29 changes: 25 additions & 4 deletions module/cmd/gravity/cmd/genaccounts_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package cmd_test
package cmd

import (
"context"
"encoding/json"
"fmt"
"os"
"testing"

"github.com/spf13/viper"
Expand All @@ -13,11 +15,13 @@ import (
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/server"
"github.com/cosmos/cosmos-sdk/simapp"
simcmd "github.com/cosmos/cosmos-sdk/simapp/simd/cmd"
"github.com/cosmos/cosmos-sdk/testutil/testdata"
"github.com/cosmos/cosmos-sdk/types/module"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
"github.com/cosmos/cosmos-sdk/x/genutil"
genutiltest "github.com/cosmos/cosmos-sdk/x/genutil/client/testutil"
tmjson "github.com/tendermint/tendermint/libs/json"
tmtypes "github.com/tendermint/tendermint/types"
)

var testMbm = module.NewBasicManager(genutil.AppModuleBasic{})
Expand Down Expand Up @@ -45,7 +49,7 @@ func TestAddGenesisAccountCmd(t *testing.T) {
{
name: "multiple denoms",
addr: addr1.String(),
denom: "1000atom, 2000stake",
denom: "1000atom,2000stake",
expectErr: false,
},
}
Expand All @@ -69,7 +73,7 @@ func TestAddGenesisAccountCmd(t *testing.T) {
ctx = context.WithValue(ctx, client.ClientContextKey, &clientCtx)
ctx = context.WithValue(ctx, server.ServerContextKey, serverCtx)

cmd := simcmd.AddGenesisAccountCmd(home)
cmd := AddGenesisAccountCmd(home)
cbrit marked this conversation as resolved.
Show resolved Hide resolved
cmd.SetArgs([]string{
tc.addr,
tc.denom,
Expand All @@ -80,6 +84,23 @@ func TestAddGenesisAccountCmd(t *testing.T) {
require.Error(t, cmd.ExecuteContext(ctx))
} else {
require.NoError(t, cmd.ExecuteContext(ctx))

genFile := serverCtx.Config.GenesisFile()
bytes, err := os.ReadFile(genFile)
require.NoError(t, err)

var genDoc tmtypes.GenesisDoc
tmjson.Unmarshal(bytes, &genDoc)

var appState map[string]json.RawMessage
err = json.Unmarshal(genDoc.AppState, &appState)
require.NoError(t, err)

var bankGenState banktypes.GenesisState
bankGenStateBz := appState[banktypes.ModuleName]
clientCtx.Codec.MustUnmarshalJSON(bankGenStateBz, &bankGenState)

require.Equal(t, bankGenState.Supply.String(), tc.denom)
}
})
}
Expand Down