Skip to content

Commit

Permalink
test: optimize minfee test too
Browse files Browse the repository at this point in the history
  • Loading branch information
ninabarbakadze committed Apr 11, 2024
1 parent 5eb8e65 commit b1ce2ca
Showing 1 changed file with 2 additions and 54 deletions.
56 changes: 2 additions & 54 deletions x/minfee/upgrade_test.go
Original file line number Diff line number Diff line change
@@ -1,35 +1,27 @@
package minfee_test

import (
"encoding/json"
"fmt"
"strings"
"testing"
"time"

"github.com/celestiaorg/celestia-app/v2/app"
"github.com/celestiaorg/celestia-app/v2/app/encoding"
"github.com/celestiaorg/celestia-app/v2/x/minfee"

v1 "github.com/celestiaorg/celestia-app/v2/pkg/appconsts/v1"
v2 "github.com/celestiaorg/celestia-app/v2/pkg/appconsts/v2"
"github.com/celestiaorg/celestia-app/v2/test/util"

"github.com/cosmos/cosmos-sdk/crypto/keyring"

sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/cosmos/cosmos-sdk/x/params/types/proposal"
"github.com/stretchr/testify/require"
abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/libs/log"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
version "github.com/tendermint/tendermint/proto/tendermint/version"
dbm "github.com/tendermint/tm-db"
)

func TestUpgradeAppVersion(t *testing.T) {
testApp, _ := setupTestApp(t, 3)
testApp, _ := util.SetupTestApp(t, 3)

supportedVersions := []uint64{v1.Version, v2.Version}

Expand Down Expand Up @@ -81,48 +73,4 @@ func TestUpgradeAppVersion(t *testing.T) {
want, err := sdk.NewDecFromStr(fmt.Sprintf("%f", v2.GlobalMinGasPrice))
require.NoError(t, err)
require.Equal(t, want.String(), strings.Trim(got.Param.Value, "\""))
}

func setupTestApp(t *testing.T, upgradeHeight int64) (*app.App, keyring.Keyring) {
t.Helper()

db := dbm.NewMemDB()
chainID := "test_chain"
encCfg := encoding.MakeConfig(app.ModuleEncodingRegisters...)
testApp := app.New(log.NewNopLogger(), db, nil, true, 0, encCfg, upgradeHeight, util.EmptyAppOptions{})

genesisState, _, kr := util.GenesisStateWithSingleValidator(testApp, "account")

stateBytes, err := json.MarshalIndent(genesisState, "", " ")
require.NoError(t, err)
infoResp := testApp.Info(abci.RequestInfo{})
require.EqualValues(t, 0, infoResp.AppVersion)

cp := app.DefaultInitialConsensusParams()
abciParams := &abci.ConsensusParams{
Block: &abci.BlockParams{
MaxBytes: cp.Block.MaxBytes,
MaxGas: cp.Block.MaxGas,
},
Evidence: &cp.Evidence,
Validator: &cp.Validator,
Version: &cp.Version,
}

_ = testApp.InitChain(
abci.RequestInitChain{
Time: time.Now(),
Validators: []abci.ValidatorUpdate{},
ConsensusParams: abciParams,
AppStateBytes: stateBytes,
ChainId: chainID,
},
)

// assert that the chain starts with version provided in genesis
infoResp = testApp.Info(abci.RequestInfo{})
require.EqualValues(t, app.DefaultInitialConsensusParams().Version.AppVersion, infoResp.AppVersion)

_ = testApp.Commit()
return testApp, kr
}
}

0 comments on commit b1ce2ca

Please sign in to comment.