* fix: testnet cli command update genesis supply (#9497)
<!--
The default pull request template is for types feat, fix, or refactor.
For other templates, add one of the following parameters to the url:
- template=docs.md
- template=other.md
-->
## Description
closes: #9372
<!-- Add a description of the changes that this PR introduces and the files that
are the most critical to review. -->
### This PR makes the `testnet` command update the bank genesis supply.
When using the `testnet` cli command, it creates nodes and balances, but does **not** update the supply. When using this in conjunction with `add-genesis-account` which **does** update the supply, it creates an invalid genesis file. This PR updates the testnet command to properly set the supply.
---
### Author Checklist
*All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.*
I have...
- [x] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [x] added `!` to the type prefix if API or client breaking change
- [x] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#pr-targeting))
- [x] provided a link to the relevant issue or specification
- [x] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/master/docs/building-modules)
- [ ] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#testing)
- [ ] added a changelog entry to `CHANGELOG.md`
- [ ] included comments for [documenting Go code](https://blog.golang.org/godoc)
- [ ] updated the relevant documentation or specification
- [x] reviewed "Files changed" and left comments if necessary
- [ ] confirmed all CI checks have passed
### Reviewers Checklist
*All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.*
I have...
- [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] confirmed `!` in the type prefix if API or client breaking change
- [ ] confirmed all author checklist items have been addressed
- [ ] reviewed state machine logic
- [ ] reviewed API design and naming
- [ ] reviewed documentation is accurate
- [ ] reviewed tests and test coverage
- [ ] manually tested (if applicable)
(cherry picked from commit 179c819a9d
)
# Conflicts:
# simapp/simd/cmd/testnet.go
* fix errors
* changelog entry
Co-authored-by: Tyler <48813565+technicallyty@users.noreply.github.com>
Co-authored-by: technicallyty <48813565+tytech3@users.noreply.github.com>
This commit is contained in:
parent
35e9e7a617
commit
4a2527c711
|
@ -40,6 +40,8 @@ Ref: https://keepachangelog.com/en/1.0.0/
|
|||
|
||||
* [\#9401](https://github.com/cosmos/cosmos-sdk/pull/9401) Fixes incorrect export of IBC identifier sequences. Previously, the next identifier sequence for clients/connections/channels was not set during genesis export. This resulted in the next identifiers being generated on the new chain to reuse old identifiers (the sequences began again from 0).
|
||||
|
||||
* [\#9513](https://github.com/cosmos/cosmos-sdk/pull/9513) Fixes testnet CLI command. Testnet now updates the supply in genesis. Previously, when using add-genesis-account and testnet together, inconsistent genesis files would be produced, as only add-genesis-account was updating the supply.
|
||||
|
||||
### Features
|
||||
|
||||
|
||||
|
|
|
@ -289,7 +289,10 @@ func initGenFiles(
|
|||
var bankGenState banktypes.GenesisState
|
||||
clientCtx.JSONMarshaler.MustUnmarshalJSON(appGenState[banktypes.ModuleName], &bankGenState)
|
||||
|
||||
bankGenState.Balances = genBalances
|
||||
bankGenState.Balances = banktypes.SanitizeGenesisBalances(genBalances)
|
||||
for _, bal := range bankGenState.Balances {
|
||||
bankGenState.Supply = bankGenState.Supply.Add(bal.Coins...)
|
||||
}
|
||||
appGenState[banktypes.ModuleName] = clientCtx.JSONMarshaler.MustMarshalJSON(&bankGenState)
|
||||
|
||||
appGenStateJSON, err := json.MarshalIndent(appGenState, "", " ")
|
||||
|
|
|
@ -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{}.
|
||||
WithJSONMarshaler(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())
|
||||
}
|
Loading…
Reference in New Issue