Skip to content

Commit

Permalink
test(testnode): configure custom min gas price (#3680)
Browse files Browse the repository at this point in the history
Context:
celestiaorg/celestia-node#3453 (comment)

Fix testnode so that it is possible to query the local min gas price
again. I plan on backporting this to v2.x to fix celestia-node
integration tests which query local min gas price.

(cherry picked from commit 5b27eba)

# Conflicts:
#	app/test/testnode_test.go
  • Loading branch information
rootulp authored and mergify[bot] committed Jul 16, 2024
1 parent be6b40b commit 2d2c099
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 16 deletions.
44 changes: 44 additions & 0 deletions app/test/testnode_test.go
Original file line number Diff line number Diff line change
@@ -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)
})
}
32 changes: 18 additions & 14 deletions pkg/user/tx_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -83,51 +86,52 @@ 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) {
addr := suite.txClient.Account("b").Address()
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)
})
}
Expand Down
42 changes: 40 additions & 2 deletions test/util/testnode/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -126,7 +132,7 @@ func DefaultConfig() *Config {
WithTendermintConfig(DefaultTendermintConfig()).
WithAppConfig(DefaultAppConfig()).
WithAppOptions(DefaultAppOptions()).
WithAppCreator(cmd.NewAppServer).
WithAppCreator(DefaultAppCreator()).
WithSuppressLogs(true).
WithConsensusParams(DefaultConsensusParams()).
WithSuppressLogs(true)
Expand Down Expand Up @@ -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),
)
}
}

0 comments on commit 2d2c099

Please sign in to comment.