Skip to content

Commit

Permalink
Merge pull request #498 from mmsqe/fix_supply
Browse files Browse the repository at this point in the history
fix: missing supply for add-genesis-account
  • Loading branch information
cbrit authored Mar 22, 2023
2 parents d4cdead + 50a797c commit 9b457ae
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
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...)
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)
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

0 comments on commit 9b457ae

Please sign in to comment.