-
Notifications
You must be signed in to change notification settings - Fork 338
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: move upgrade unit tests together (#3302)
## Overview Moves all upgrade unit tests in one place
- Loading branch information
1 parent
9db2f8b
commit 34915fc
Showing
4 changed files
with
126 additions
and
262 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,144 @@ | ||
package app_test | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"strings" | ||
"testing" | ||
"time" | ||
|
||
app "github.com/celestiaorg/celestia-app/v2/app" | ||
"github.com/celestiaorg/celestia-app/v2/app/encoding" | ||
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/celestiaorg/celestia-app/v2/x/minfee" | ||
"github.com/cosmos/cosmos-sdk/crypto/keyring" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/cosmos/cosmos-sdk/x/params/types/proposal" | ||
icahosttypes "github.com/cosmos/ibc-go/v6/modules/apps/27-interchain-accounts/host/types" | ||
"github.com/stretchr/testify/require" | ||
abci "github.com/tendermint/tendermint/abci/types" | ||
tmproto "github.com/tendermint/tendermint/proto/tendermint/types" | ||
tmversion "github.com/tendermint/tendermint/proto/tendermint/version" | ||
dbm "github.com/tendermint/tm-db" | ||
|
||
packetforwardtypes "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v6/packetforward/types" | ||
|
||
"github.com/tendermint/tendermint/libs/log" | ||
) | ||
|
||
func TestUpgradeAppVersion(t *testing.T) { | ||
testApp, _ := util.SetupTestAppWithUpgradeHeight(t, 3) | ||
// TestAppUpgrades verifies that the all module's params are overridden during an | ||
// upgrade from v1 -> v2 and the app version changes correctly. | ||
func TestAppUpgrades(t *testing.T) { | ||
GlobalMinGasPriceDec, err := sdk.NewDecFromStr(fmt.Sprintf("%f", v2.GlobalMinGasPrice)) | ||
require.NoError(t, err) | ||
|
||
tests := []struct { | ||
module string | ||
subspace string | ||
key string | ||
expectedValue string | ||
}{ | ||
{ | ||
module: "MinFee", | ||
subspace: minfee.ModuleName, | ||
key: string(minfee.KeyGlobalMinGasPrice), | ||
expectedValue: GlobalMinGasPriceDec.String(), | ||
}, | ||
{ | ||
module: "ICA", | ||
subspace: icahosttypes.SubModuleName, | ||
key: string(icahosttypes.KeyHostEnabled), | ||
expectedValue: "true", | ||
}, | ||
{ | ||
module: "PFM", | ||
subspace: packetforwardtypes.ModuleName, | ||
key: string(packetforwardtypes.KeyFeePercentage), | ||
expectedValue: "0.000000000000000000", | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.module, func(t *testing.T) { | ||
testApp, _ := SetupTestAppWithUpgradeHeight(t, 3) | ||
|
||
supportedVersions := []uint64{v1.Version, v2.Version} | ||
require.Equal(t, supportedVersions, testApp.SupportedVersions()) | ||
|
||
ctx := testApp.NewContext(true, tmproto.Header{ | ||
Version: tmversion.Consensus{ | ||
App: 1, | ||
}, | ||
}) | ||
testApp.BeginBlock(abci.RequestBeginBlock{Header: tmproto.Header{ | ||
Height: 2, | ||
Version: tmversion.Consensus{App: 1}, | ||
}}) | ||
// app version should not have changed yet | ||
require.EqualValues(t, 1, testApp.AppVersion()) | ||
|
||
// Query the module params | ||
gotBefore, err := testApp.ParamsKeeper.Params(ctx, &proposal.QueryParamsRequest{ | ||
Subspace: tt.subspace, | ||
Key: tt.key, | ||
}) | ||
require.NoError(t, err) | ||
require.Equal(t, "", gotBefore.Param.Value) | ||
|
||
// Upgrade from v1 -> v2 | ||
testApp.EndBlock(abci.RequestEndBlock{Height: 2}) | ||
testApp.Commit() | ||
require.EqualValues(t, 2, testApp.AppVersion()) | ||
|
||
newCtx := testApp.NewContext(true, tmproto.Header{Version: tmversion.Consensus{App: 2}}) | ||
got, err := testApp.ParamsKeeper.Params(newCtx, &proposal.QueryParamsRequest{ | ||
Subspace: tt.subspace, | ||
Key: tt.key, | ||
}) | ||
require.NoError(t, err) | ||
require.Equal(t, tt.expectedValue, strings.Trim(got.Param.Value, "\"")) | ||
}) | ||
} | ||
} | ||
|
||
func SetupTestAppWithUpgradeHeight(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, 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, | ||
} | ||
|
||
supportedVersions := []uint64{v1.Version, v2.Version} | ||
_ = testApp.InitChain( | ||
abci.RequestInitChain{ | ||
Time: time.Now(), | ||
Validators: []abci.ValidatorUpdate{}, | ||
ConsensusParams: abciParams, | ||
AppStateBytes: stateBytes, | ||
ChainId: chainID, | ||
}, | ||
) | ||
|
||
require.Equal(t, supportedVersions, testApp.SupportedVersions()) | ||
// 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.BeginBlock(abci.RequestBeginBlock{Header: tmproto.Header{ | ||
Height: 2, | ||
Version: tmversion.Consensus{App: 1}, | ||
}}) | ||
// app version should not have changed yet | ||
require.EqualValues(t, 1, testApp.AppVersion()) | ||
respEndBlock := testApp.EndBlock(abci.RequestEndBlock{Height: 2}) | ||
// now the app version changes | ||
require.NotNil(t, respEndBlock.ConsensusParamUpdates.Version) | ||
require.EqualValues(t, 2, respEndBlock.ConsensusParamUpdates.Version.AppVersion) | ||
require.EqualValues(t, 2, testApp.AppVersion()) | ||
_ = testApp.Commit() | ||
return testApp, kr | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.