From 8255ecfb78a16dbd4ea7a7e61c67cc956cfabf24 Mon Sep 17 00:00:00 2001 From: technicallyty <48813565+tytech3@users.noreply.github.com> Date: Thu, 10 Jun 2021 13:05:43 -0700 Subject: [PATCH 1/5] make testnet update the supply --- simapp/simd/cmd/testnet.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/simapp/simd/cmd/testnet.go b/simapp/simd/cmd/testnet.go index d789c3471f43..ac9a86739306 100644 --- a/simapp/simd/cmd/testnet.go +++ b/simapp/simd/cmd/testnet.go @@ -289,7 +289,11 @@ func initGenFiles( var bankGenState banktypes.GenesisState clientCtx.JSONCodec.MustUnmarshalJSON(appGenState[banktypes.ModuleName], &bankGenState) - bankGenState.Balances = genBalances + bankGenState.Balances = banktypes.SanitizeGenesisBalances(genBalances) + for _, bal := range bankGenState.Balances { + bankGenState.Supply.Add(bal.Coins...) + } + appGenState[banktypes.ModuleName] = clientCtx.JSONCodec.MustMarshalJSON(&bankGenState) appGenStateJSON, err := json.MarshalIndent(appGenState, "", " ") From 1efde1c857164d62f5ce96bafec89c7fabb0336b Mon Sep 17 00:00:00 2001 From: technicallyty <48813565+tytech3@users.noreply.github.com> Date: Fri, 11 Jun 2021 17:31:20 -0700 Subject: [PATCH 2/5] add testnet cli test --- simapp/simd/cmd/testnet_test.go | 43 +++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 simapp/simd/cmd/testnet_test.go diff --git a/simapp/simd/cmd/testnet_test.go b/simapp/simd/cmd/testnet_test.go new file mode 100644 index 000000000000..63d97424e6f2 --- /dev/null +++ b/simapp/simd/cmd/testnet_test.go @@ -0,0 +1,43 @@ +package cmd + +import ( + "context" + "fmt" + "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/cosmos/cosmos-sdk/types/module" + "github.com/cosmos/cosmos-sdk/x/genutil" + "github.com/stretchr/testify/require" + "testing" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/simapp" + banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" +) + +var testMbm = module.NewBasicManager(genutil.AppModuleBasic{}) + +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(testMbm, home, encodingConfig.Marshaler) + //require.NoError(t, err) + + //serverCtx := server.NewContext(viper.New(), cfg, logger) + clientCtx := client.Context{}. + WithJSONCodec(encodingConfig.Marshaler). + WithHomeDir(home). + WithTxConfig(encodingConfig.TxConfig) + + ctx := context.Background() + ctx = context.WithValue(ctx, client.ClientContextKey, &clientCtx) + //ctx = context.WithValue(ctx, server.ServerContextKey, serverCtx) + + cmd := testnetCmd(testMbm, banktypes.GenesisBalancesIterator{}) + cmd.SetArgs([]string{fmt.Sprintf("--%s=test", flags.FlagKeyringBackend)}) + err := cmd.ExecuteContext(ctx) + require.NoError(t, err) +} From 1e0ad9b2ee48455df1cd812e0919b38b1de83421 Mon Sep 17 00:00:00 2001 From: technicallyty <48813565+tytech3@users.noreply.github.com> Date: Fri, 11 Jun 2021 19:17:12 -0700 Subject: [PATCH 3/5] add test --- simapp/simd/cmd/testnet.go | 18 +++++++++----- simapp/simd/cmd/testnet_test.go | 44 ++++++++++++++++++++++----------- 2 files changed, 41 insertions(+), 21 deletions(-) diff --git a/simapp/simd/cmd/testnet.go b/simapp/simd/cmd/testnet.go index d789c3471f43..c38c4a6bd736 100644 --- a/simapp/simd/cmd/testnet.go +++ b/simapp/simd/cmd/testnet.go @@ -271,11 +271,14 @@ func initGenFiles( genFiles []string, numValidators int, ) error { - appGenState := mbm.DefaultGenesis(clientCtx.JSONCodec) + appGenState := mbm.DefaultGenesis(clientCtx.Codec) // set the accounts in the genesis state var authGenState authtypes.GenesisState - clientCtx.JSONCodec.MustUnmarshalJSON(appGenState[authtypes.ModuleName], &authGenState) + if len(appGenState[authtypes.ModuleName]) == 0 { + panic("nothing to unmarshal") + } + clientCtx.Codec.MustUnmarshalJSON(appGenState[authtypes.ModuleName], &authGenState) accounts, err := authtypes.PackAccounts(genAccounts) if err != nil { @@ -283,14 +286,17 @@ func initGenFiles( } authGenState.Accounts = accounts - appGenState[authtypes.ModuleName] = clientCtx.JSONCodec.MustMarshalJSON(&authGenState) + appGenState[authtypes.ModuleName] = clientCtx.Codec.MustMarshalJSON(&authGenState) // set the balances in the genesis state var bankGenState banktypes.GenesisState - clientCtx.JSONCodec.MustUnmarshalJSON(appGenState[banktypes.ModuleName], &bankGenState) + clientCtx.Codec.MustUnmarshalJSON(appGenState[banktypes.ModuleName], &bankGenState) - bankGenState.Balances = genBalances - appGenState[banktypes.ModuleName] = clientCtx.JSONCodec.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) appGenStateJSON, err := json.MarshalIndent(appGenState, "", " ") if err != nil { diff --git a/simapp/simd/cmd/testnet_test.go b/simapp/simd/cmd/testnet_test.go index 63d97424e6f2..e9bca72d4d2d 100644 --- a/simapp/simd/cmd/testnet_test.go +++ b/simapp/simd/cmd/testnet_test.go @@ -3,41 +3,55 @@ package cmd import ( "context" "fmt" - "github.com/cosmos/cosmos-sdk/client/flags" - "github.com/cosmos/cosmos-sdk/types/module" - "github.com/cosmos/cosmos-sdk/x/genutil" - "github.com/stretchr/testify/require" "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" + "github.com/cosmos/cosmos-sdk/types/module" + "github.com/cosmos/cosmos-sdk/x/auth" + authz "github.com/cosmos/cosmos-sdk/x/authz/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" + genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" + "github.com/spf13/viper" + "github.com/stretchr/testify/require" + "github.com/tendermint/tendermint/libs/log" ) -var testMbm = module.NewBasicManager(genutil.AppModuleBasic{}) +var testMbm = module.NewBasicManager(genutil.AppModuleBasic{}, auth.AppModuleBasic{}, authz.AppModuleBasic{}) func Test_TestnetCmd(t *testing.T) { home := t.TempDir() + fmt.Println(home) encodingConfig := simapp.MakeTestEncodingConfig() - //logger := log.NewNopLogger() - //cfg, err := genutiltest.CreateDefaultTendermintConfig(home) - //require.NoError(t, err) + logger := log.NewNopLogger() + cfg, err := genutiltest.CreateDefaultTendermintConfig(home) + require.NoError(t, err) - //err = genutiltest.ExecInitCmd(testMbm, home, encodingConfig.Marshaler) - //require.NoError(t, err) + err = genutiltest.ExecInitCmd(testMbm, home, encodingConfig.Marshaler) + require.NoError(t, err) - //serverCtx := server.NewContext(viper.New(), cfg, logger) + serverCtx := server.NewContext(viper.New(), cfg, logger) clientCtx := client.Context{}. WithJSONCodec(encodingConfig.Marshaler). WithHomeDir(home). WithTxConfig(encodingConfig.TxConfig) ctx := context.Background() + ctx = context.WithValue(ctx, server.ServerContextKey, serverCtx) ctx = context.WithValue(ctx, client.ClientContextKey, &clientCtx) - //ctx = context.WithValue(ctx, server.ServerContextKey, serverCtx) + 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) - cmd := testnetCmd(testMbm, banktypes.GenesisBalancesIterator{}) - cmd.SetArgs([]string{fmt.Sprintf("--%s=test", flags.FlagKeyringBackend)}) - err := cmd.ExecuteContext(ctx) + genFile := cfg.GenesisFile() + appState, _, err := genutiltypes.GenesisStateFromGenFile(genFile) require.NoError(t, err) + + bankGenState := banktypes.GetGenesisStateFromAppState(encodingConfig.Marshaler, appState) + require.NotEmpty(t, bankGenState.Supply.String()) } From 9173507fbf0446103dffbe630836f696527b0bd3 Mon Sep 17 00:00:00 2001 From: technicallyty <48813565+tytech3@users.noreply.github.com> Date: Fri, 11 Jun 2021 19:18:40 -0700 Subject: [PATCH 4/5] cleanup scraps --- simapp/simd/cmd/testnet.go | 5 +---- simapp/simd/cmd/testnet_test.go | 2 +- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/simapp/simd/cmd/testnet.go b/simapp/simd/cmd/testnet.go index c38c4a6bd736..071d9364d0e2 100644 --- a/simapp/simd/cmd/testnet.go +++ b/simapp/simd/cmd/testnet.go @@ -275,9 +275,6 @@ func initGenFiles( // set the accounts in the genesis state var authGenState authtypes.GenesisState - if len(appGenState[authtypes.ModuleName]) == 0 { - panic("nothing to unmarshal") - } clientCtx.Codec.MustUnmarshalJSON(appGenState[authtypes.ModuleName], &authGenState) accounts, err := authtypes.PackAccounts(genAccounts) @@ -343,7 +340,7 @@ func collectGenFiles( return err } - nodeAppState, err := genutil.GenAppStateFromConfig(clientCtx.JSONCodec, clientCtx.TxConfig, nodeConfig, initCfg, *genDoc, genBalIterator) + nodeAppState, err := genutil.GenAppStateFromConfig(clientCtx.Codec, clientCtx.TxConfig, nodeConfig, initCfg, *genDoc, genBalIterator) if err != nil { return err } diff --git a/simapp/simd/cmd/testnet_test.go b/simapp/simd/cmd/testnet_test.go index e9bca72d4d2d..ce043e1bfea4 100644 --- a/simapp/simd/cmd/testnet_test.go +++ b/simapp/simd/cmd/testnet_test.go @@ -36,7 +36,7 @@ func Test_TestnetCmd(t *testing.T) { serverCtx := server.NewContext(viper.New(), cfg, logger) clientCtx := client.Context{}. - WithJSONCodec(encodingConfig.Marshaler). + WithCodec(encodingConfig.Marshaler). WithHomeDir(home). WithTxConfig(encodingConfig.TxConfig) From df22968e77783968686444f7015655fe7dc9ea1e Mon Sep 17 00:00:00 2001 From: technicallyty <48813565+tytech3@users.noreply.github.com> Date: Fri, 11 Jun 2021 19:20:50 -0700 Subject: [PATCH 5/5] remove unused var --- simapp/simd/cmd/testnet_test.go | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/simapp/simd/cmd/testnet_test.go b/simapp/simd/cmd/testnet_test.go index ce043e1bfea4..da58fd454d82 100644 --- a/simapp/simd/cmd/testnet_test.go +++ b/simapp/simd/cmd/testnet_test.go @@ -9,11 +9,7 @@ import ( "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/server" "github.com/cosmos/cosmos-sdk/simapp" - "github.com/cosmos/cosmos-sdk/types/module" - "github.com/cosmos/cosmos-sdk/x/auth" - authz "github.com/cosmos/cosmos-sdk/x/authz/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" genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" "github.com/spf13/viper" @@ -21,17 +17,14 @@ import ( "github.com/tendermint/tendermint/libs/log" ) -var testMbm = module.NewBasicManager(genutil.AppModuleBasic{}, auth.AppModuleBasic{}, authz.AppModuleBasic{}) - func Test_TestnetCmd(t *testing.T) { home := t.TempDir() - fmt.Println(home) encodingConfig := simapp.MakeTestEncodingConfig() logger := log.NewNopLogger() cfg, err := genutiltest.CreateDefaultTendermintConfig(home) require.NoError(t, err) - err = genutiltest.ExecInitCmd(testMbm, home, encodingConfig.Marshaler) + err = genutiltest.ExecInitCmd(simapp.ModuleBasics, home, encodingConfig.Marshaler) require.NoError(t, err) serverCtx := server.NewContext(viper.New(), cfg, logger)