diff --git a/app/test/testnode_test.go b/app/test/testnode_test.go new file mode 100644 index 0000000000..f9f8466b7d --- /dev/null +++ b/app/test/testnode_test.go @@ -0,0 +1,44 @@ +package app_test + +import ( + "testing" + + v2 "github.com/celestiaorg/celestia-app/v2/pkg/appconsts/v2" + "github.com/celestiaorg/celestia-app/v2/test/util/testnode" + "github.com/celestiaorg/celestia-app/v2/x/minfee" + nodeservice "github.com/cosmos/cosmos-sdk/client/grpc/node" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +func Test_testnode(t *testing.T) { + t.Run("testnode can start a network with default chain ID", func(t *testing.T) { + testnode.NewNetwork(t, testnode.DefaultConfig()) + }) + t.Run("testnode can start a network with a custom chain ID", func(t *testing.T) { + chainID := "custom-chain-id" + config := testnode.DefaultConfig().WithChainID(chainID) + testnode.NewNetwork(t, config) + }) + t.Run("testnode can query network min gas price", func(t *testing.T) { + config := testnode.DefaultConfig() + cctx, _, _ := testnode.NewNetwork(t, config) + + queryClient := minfee.NewQueryClient(cctx.GRPCClient) + resp, err := queryClient.NetworkMinGasPrice(cctx.GoContext(), &minfee.QueryNetworkMinGasPrice{}) + require.NoError(t, err) + got, err := resp.NetworkMinGasPrice.Float64() + require.NoError(t, err) + assert.Equal(t, v2.NetworkMinGasPrice, got) + }) + t.Run("testnode can query local min gas price", func(t *testing.T) { + config := testnode.DefaultConfig() + cctx, _, _ := testnode.NewNetwork(t, config) + + serviceClient := nodeservice.NewServiceClient(cctx.GRPCClient) + resp, err := serviceClient.Config(cctx.GoContext(), &nodeservice.ConfigRequest{}) + require.NoError(t, err) + want := "0.002000000000000000utia" + assert.Equal(t, want, resp.MinimumGasPrice) + }) +} diff --git a/pkg/user/tx_client_test.go b/pkg/user/tx_client_test.go index 3dc717e7a4..ebdb6e1c66 100644 --- a/pkg/user/tx_client_test.go +++ b/pkg/user/tx_client_test.go @@ -37,7 +37,10 @@ type TxClientTestSuite struct { func (suite *TxClientTestSuite) SetupSuite() { suite.encCfg = encoding.MakeConfig(app.ModuleEncodingRegisters...) - suite.ctx, _, _ = testnode.NewNetwork(suite.T(), testnode.DefaultConfig().WithFundedAccounts("a", "b", "c")) + config := testnode.DefaultConfig(). + WithFundedAccounts("a", "b", "c"). + WithAppCreator(testnode.CustomAppCreator("0utia")) + suite.ctx, _, _ = testnode.NewNetwork(suite.T(), config) _, err := suite.ctx.WaitForHeight(1) suite.Require().NoError(err) suite.txClient, err = user.SetupTxClient(suite.ctx.GoContext(), suite.ctx.Keyring, suite.ctx.GRPCClient, suite.encCfg, user.WithGasMultiplier(1.2)) @@ -83,36 +86,37 @@ func (suite *TxClientTestSuite) TestSubmitPayForBlob() { func (suite *TxClientTestSuite) TestSubmitTx() { t := suite.T() - fee := user.SetFee(1e6) - gas := user.SetGasLimit(1e6) + gasLimit := uint64(1e6) + gasLimitOption := user.SetGasLimit(gasLimit) + feeOption := user.SetFee(1e6) addr := suite.txClient.DefaultAddress() msg := bank.NewMsgSend(addr, testnode.RandomAddress().(sdk.AccAddress), sdk.NewCoins(sdk.NewInt64Coin(app.BondDenom, 10))) t.Run("submit tx without provided fee and gas limit", func(t *testing.T) { resp, err := suite.txClient.SubmitTx(suite.ctx.GoContext(), []sdk.Msg{msg}) require.NoError(t, err) - require.EqualValues(t, 0, resp.Code) + require.Equal(t, abci.CodeTypeOK, resp.Code) require.Greater(t, resp.GasWanted, int64(0)) }) t.Run("submit tx with provided gas limit", func(t *testing.T) { - resp, err := suite.txClient.SubmitTx(suite.ctx.GoContext(), []sdk.Msg{msg}, gas) + resp, err := suite.txClient.SubmitTx(suite.ctx.GoContext(), []sdk.Msg{msg}, gasLimitOption) require.NoError(t, err) - require.EqualValues(t, 0, resp.Code) - require.EqualValues(t, resp.GasWanted, 1e6) + require.Equal(t, abci.CodeTypeOK, resp.Code) + require.EqualValues(t, gasLimit, resp.GasWanted) }) t.Run("submit tx with provided fee", func(t *testing.T) { - resp, err := suite.txClient.SubmitTx(suite.ctx.GoContext(), []sdk.Msg{msg}, fee) + resp, err := suite.txClient.SubmitTx(suite.ctx.GoContext(), []sdk.Msg{msg}, feeOption) require.NoError(t, err) - require.EqualValues(t, 0, resp.Code) + require.Equal(t, abci.CodeTypeOK, resp.Code) }) t.Run("submit tx with provided fee and gas limit", func(t *testing.T) { - resp, err := suite.txClient.SubmitTx(suite.ctx.GoContext(), []sdk.Msg{msg}, fee, gas) + resp, err := suite.txClient.SubmitTx(suite.ctx.GoContext(), []sdk.Msg{msg}, feeOption, gasLimitOption) require.NoError(t, err) - require.EqualValues(t, 0, resp.Code) - require.EqualValues(t, resp.GasWanted, 1e6) + require.Equal(t, abci.CodeTypeOK, resp.Code) + require.EqualValues(t, gasLimit, resp.GasWanted) }) t.Run("submit tx with a different account", func(t *testing.T) { @@ -120,14 +124,14 @@ func (suite *TxClientTestSuite) TestSubmitTx() { msg := bank.NewMsgSend(addr, testnode.RandomAddress().(sdk.AccAddress), sdk.NewCoins(sdk.NewInt64Coin(app.BondDenom, 10))) resp, err := suite.txClient.SubmitTx(suite.ctx.GoContext(), []sdk.Msg{msg}) require.NoError(t, err) - require.EqualValues(t, 0, resp.Code) + require.Equal(t, abci.CodeTypeOK, resp.Code) }) t.Run("submit tx with an updated default gas price", func(t *testing.T) { suite.txClient.SetDefaultGasPrice(appconsts.DefaultMinGasPrice / 2) resp, err := suite.txClient.SubmitTx(suite.ctx.GoContext(), []sdk.Msg{msg}) require.NoError(t, err) - require.EqualValues(t, 0, resp.Code) + require.Equal(t, abci.CodeTypeOK, resp.Code) suite.txClient.SetDefaultGasPrice(appconsts.DefaultMinGasPrice) }) } diff --git a/test/util/genesis/genesis.go b/test/util/genesis/genesis.go index ab2e8a93eb..228997f88b 100644 --- a/test/util/genesis/genesis.go +++ b/test/util/genesis/genesis.go @@ -167,14 +167,6 @@ func (g *Genesis) AddValidator(val Validator) error { return err } - // Add the validator's genesis transaction - gentx, err := val.GenTx(g.ecfg, g.kr, g.ChainID) - if err != nil { - return err - } - - // install the validator - g.genTxs = append(g.genTxs, gentx) g.validators = append(g.validators, val) return nil } @@ -192,7 +184,12 @@ func (g *Genesis) NewValidator(val Validator) error { // Export returns the genesis document of the network. func (g *Genesis) Export() (*coretypes.GenesisDoc, error) { gentxs := make([]json.RawMessage, 0, len(g.genTxs)) - for _, genTx := range g.genTxs { + for _, val := range g.validators { + genTx, err := val.GenTx(g.ecfg, g.kr, g.ChainID) + if err != nil { + return nil, err + } + bz, err := g.ecfg.TxConfig.TxJSONEncoder()(genTx) if err != nil { return nil, err diff --git a/test/util/testnode/config.go b/test/util/testnode/config.go index 18990d7c16..0e9a048441 100644 --- a/test/util/testnode/config.go +++ b/test/util/testnode/config.go @@ -2,16 +2,22 @@ package testnode import ( "fmt" + "io" "time" - "github.com/celestiaorg/celestia-app/v2/cmd/celestia-appd/cmd" + "github.com/celestiaorg/celestia-app/v2/app" + "github.com/celestiaorg/celestia-app/v2/app/encoding" "github.com/celestiaorg/celestia-app/v2/pkg/appconsts" "github.com/celestiaorg/celestia-app/v2/test/util/genesis" + "github.com/cosmos/cosmos-sdk/baseapp" srvconfig "github.com/cosmos/cosmos-sdk/server/config" srvtypes "github.com/cosmos/cosmos-sdk/server/types" + "github.com/cosmos/cosmos-sdk/simapp" tmconfig "github.com/tendermint/tendermint/config" + "github.com/tendermint/tendermint/libs/log" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" "github.com/tendermint/tendermint/types" + tmdb "github.com/tendermint/tm-db" ) const ( @@ -126,7 +132,7 @@ func DefaultConfig() *Config { WithTendermintConfig(DefaultTendermintConfig()). WithAppConfig(DefaultAppConfig()). WithAppOptions(DefaultAppOptions()). - WithAppCreator(cmd.NewAppServer). + WithAppCreator(DefaultAppCreator()). WithSuppressLogs(true). WithConsensusParams(DefaultConsensusParams()). WithSuppressLogs(true) @@ -166,3 +172,35 @@ func DefaultTendermintConfig() *tmconfig.Config { return tmCfg } + +func DefaultAppCreator() srvtypes.AppCreator { + return func(_ log.Logger, _ tmdb.DB, _ io.Writer, _ srvtypes.AppOptions) srvtypes.Application { + encodingConfig := encoding.MakeConfig(app.ModuleEncodingRegisters...) + return app.New( + log.NewNopLogger(), + tmdb.NewMemDB(), + nil, // trace store + 0, // invCheckPerid + encodingConfig, + 0, // v2 upgrade height + simapp.EmptyAppOptions{}, + baseapp.SetMinGasPrices(fmt.Sprintf("%v%v", appconsts.DefaultMinGasPrice, app.BondDenom)), + ) + } +} + +func CustomAppCreator(minGasPrice string) srvtypes.AppCreator { + return func(_ log.Logger, _ tmdb.DB, _ io.Writer, _ srvtypes.AppOptions) srvtypes.Application { + encodingConfig := encoding.MakeConfig(app.ModuleEncodingRegisters...) + return app.New( + log.NewNopLogger(), + tmdb.NewMemDB(), + nil, // trace store + 0, // invCheckPerid + encodingConfig, + 0, // v2 upgrade height + simapp.EmptyAppOptions{}, + baseapp.SetMinGasPrices(minGasPrice), + ) + } +}