From bb35f38b473a0b9ea4025bf7a7fe9b85056d0a39 Mon Sep 17 00:00:00 2001 From: Arnaud Mimart <33665250+amimart@users.noreply.github.com> Date: Wed, 10 Jan 2024 23:28:02 +0100 Subject: [PATCH] fix(test): allow default genesis creation in testutil --- app/genesis.go | 13 ++++++++++--- testutil/network/network.go | 2 +- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/app/genesis.go b/app/genesis.go index 5bf0c1da..34edce09 100644 --- a/app/genesis.go +++ b/app/genesis.go @@ -2,6 +2,12 @@ package app import ( "encoding/json" + "testing" + + "cosmossdk.io/log" + + dbm "github.com/cosmos/cosmos-db" + simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" "github.com/cosmos/cosmos-sdk/codec" ) @@ -15,7 +21,8 @@ import ( // object provided to it during init. type GenesisState map[string]json.RawMessage -// NewDefaultGenesisState generates the default state for the application. -func NewDefaultGenesisState(cdc codec.JSONCodec) GenesisState { - return ModuleBasics.DefaultGenesis(cdc) +// NewDefaultGenesisState generates the default state for the application, for testing purpose. +func NewDefaultGenesisState(t testing.TB, cdc codec.JSONCodec) GenesisState { + tempApp := New(log.NewNopLogger(), dbm.NewMemDB(), nil, true, simtestutil.NewAppOptionsWithFlagHome(t.TempDir())) + return tempApp.BasicModuleManager.DefaultGenesis(cdc) } diff --git a/testutil/network/network.go b/testutil/network/network.go index a6103630..9f2d5c3d 100644 --- a/testutil/network/network.go +++ b/testutil/network/network.go @@ -73,7 +73,7 @@ func DefaultConfig(t *testing.T) network.Config { baseapp.SetChainID(chainID), ) }, - GenesisState: app.NewDefaultGenesisState(encoding.Codec), + GenesisState: app.NewDefaultGenesisState(t, encoding.Codec), TimeoutCommit: 2 * time.Second, ChainID: chainID, NumValidators: 1,