From 313102d14a7c561b9dc38616b55ce972b88ce7f7 Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Wed, 31 Jan 2024 11:05:14 +0100 Subject: [PATCH 01/10] merge --- go.work.sum | 3 +++ 1 file changed, 3 insertions(+) diff --git a/go.work.sum b/go.work.sum index 4cf0be8d93..93acb49091 100644 --- a/go.work.sum +++ b/go.work.sum @@ -620,6 +620,7 @@ github.com/cloudflare/cloudflare-go v0.79.0/go.mod h1:gkHQf9xEubaQPEuerBuoinR9P8 github.com/cncf/udpa/go v0.0.0-20220112060539-c52dc94e7fbe/go.mod h1:6pvJx4me5XPnfI9Z40ddWsdw2W/uZgQLFXToKeRcDiI= github.com/cncf/xds/go v0.0.0-20230607035331-e9ce68804cb4/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= github.com/cncf/xds/go v0.0.0-20231109132714-523115ebc101/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= +github.com/cncf/xds/go v0.0.0-20231109132714-523115ebc101/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= github.com/cockroachdb/datadriven v1.0.0/go.mod h1:5Ib8Meh+jk1RlHIXej6Pzevx/NLlNvQB9pmSBZErGA4= github.com/cockroachdb/datadriven v1.0.3-0.20230413201302-be42291fc80f/go.mod h1:a9RdTaap04u637JoCzcUoIcDmvwSUtcUFtT/C3kJlTU= github.com/cockroachdb/errors v1.6.1/go.mod h1:tm6FTP5G81vwJ5lC0SizQo374JNCOPrHyXGitRJoDqM= @@ -928,6 +929,8 @@ google.golang.org/genproto v0.0.0-20231106174013-bbf56f31fb17/go.mod h1:J7XzRzVy google.golang.org/genproto/googleapis/api v0.0.0-20230822172742-b8732ec3820d/go.mod h1:KjSP20unUpOx5kyQUFa7k4OJg0qeJ7DEZflGDu2p6Bk= google.golang.org/genproto/googleapis/api v0.0.0-20231016165738-49dd2c1f3d0b/go.mod h1:IBQ646DjkDkvUIsVq/cc03FUFQ9wbZu7yE396YcL870= google.golang.org/genproto/googleapis/api v0.0.0-20231106174013-bbf56f31fb17/go.mod h1:0xJLfVdJqpAPl8tDg1ujOCGzx6LFLttXT5NhllGOXY4= +google.golang.org/genproto/googleapis/api v0.0.0-20231106174013-bbf56f31fb17/go.mod h1:0xJLfVdJqpAPl8tDg1ujOCGzx6LFLttXT5NhllGOXY4= +google.golang.org/genproto/googleapis/bytestream v0.0.0-20230530153820-e85fd2cbaebc/go.mod h1:ylj+BE99M198VPbBh6A8d9n3w8fChvyLK3wwBOjXBFA= google.golang.org/genproto/googleapis/bytestream v0.0.0-20231030173426-d783a09b4405/go.mod h1:GRUCuLdzVqZte8+Dl/D4N25yLzcGqqWaYkeVOwulFqw= google.golang.org/genproto/googleapis/rpc v0.0.0-20230822172742-b8732ec3820d/go.mod h1:+Bk1OCOj40wS2hwAMA+aCW9ypzm63QTBBHp6lQ3p+9M= google.golang.org/genproto/googleapis/rpc v0.0.0-20231016165738-49dd2c1f3d0b/go.mod h1:swOH3j0KzcDDgGUWr+SNpyTen5YrXjS3eyPzFYKc6lc= From e8b6c2abd04f420b28f1dedb20ab53929bdd5e58 Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Thu, 1 Feb 2024 18:11:44 +0100 Subject: [PATCH 02/10] fix: PrepareProposal always passes v0 to GovSquareSizeUpperBound --- app/square_size.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/square_size.go b/app/square_size.go index 8703f1dea7..e97e2c5ebe 100644 --- a/app/square_size.go +++ b/app/square_size.go @@ -19,6 +19,6 @@ func (app *App) GovSquareSizeUpperBound(ctx sdk.Context) int { } gmax := int(app.BlobKeeper.GovMaxSquareSize(ctx)) - hardMax := appconsts.SquareSizeUpperBound(ctx.BlockHeader().Version.App) + hardMax := appconsts.SquareSizeUpperBound(app.AppVersion(ctx)) return min(gmax, hardMax) } From 1f497d975b656841dc01676c4a026ff545d80eff Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Thu, 11 Apr 2024 17:59:13 +0200 Subject: [PATCH 03/10] chore: move ica upgrade test to test --- {app/test => test/ica}/ica_upgrade_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename {app/test => test/ica}/ica_upgrade_test.go (99%) diff --git a/app/test/ica_upgrade_test.go b/test/ica/ica_upgrade_test.go similarity index 99% rename from app/test/ica_upgrade_test.go rename to test/ica/ica_upgrade_test.go index 5a1fc8e022..e30693fb1a 100644 --- a/app/test/ica_upgrade_test.go +++ b/test/ica/ica_upgrade_test.go @@ -1,4 +1,4 @@ -package app_test +package ica_test import ( "encoding/json" From 5eb8e65e301030b5bf3dec01832454a8d5f4a631 Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Thu, 11 Apr 2024 20:02:19 +0200 Subject: [PATCH 04/10] refactor: try reduce repetition in upgrade tests --- app/test/upgrade_test.go | 3 +- test/ica/ica_upgrade_test.go | 54 +----------------- .../packetforward_upgrade_test.go | 52 +---------------- test/util/test_app.go | 2 +- test/util/testapp_upgrade.go | 56 +++++++++++++++++++ 5 files changed, 62 insertions(+), 105 deletions(-) create mode 100644 test/util/testapp_upgrade.go diff --git a/app/test/upgrade_test.go b/app/test/upgrade_test.go index 4cea521252..e3e7b87241 100644 --- a/app/test/upgrade_test.go +++ b/app/test/upgrade_test.go @@ -5,6 +5,7 @@ import ( 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/stretchr/testify/require" abci "github.com/tendermint/tendermint/abci/types" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" @@ -12,7 +13,7 @@ import ( ) func TestUpgradeAppVersion(t *testing.T) { - testApp, _ := setupTestApp(t, 3) + testApp, _ := util.SetupTestApp(t, 3) supportedVersions := []uint64{v1.Version, v2.Version} diff --git a/test/ica/ica_upgrade_test.go b/test/ica/ica_upgrade_test.go index e30693fb1a..06f699365e 100644 --- a/test/ica/ica_upgrade_test.go +++ b/test/ica/ica_upgrade_test.go @@ -1,30 +1,21 @@ package ica_test import ( - "encoding/json" "testing" - "time" - "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/cosmos/cosmos-sdk/crypto/keyring" "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" - "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" ) // TestICA verifies that the ICA module's params are overridden during an // upgrade from v1 -> v2. func TestICA(t *testing.T) { - testApp, _ := setupTestApp(t, 3) + testApp, _ := util.SetupTestApp(t, 3) ctx := testApp.NewContext(true, tmproto.Header{ Version: version.Consensus{ App: 1, @@ -57,46 +48,3 @@ func TestICA(t *testing.T) { require.NoError(t, err) require.Equal(t, "true", 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() - supportedVersions := []uint64{v1.Version, v2.Version} - require.Equal(t, supportedVersions, testApp.SupportedVersions()) - return testApp, kr -} diff --git a/test/packetforward/packetforward_upgrade_test.go b/test/packetforward/packetforward_upgrade_test.go index a9972a515e..e17bc21717 100644 --- a/test/packetforward/packetforward_upgrade_test.go +++ b/test/packetforward/packetforward_upgrade_test.go @@ -1,31 +1,24 @@ package packetforward_test import ( - "encoding/json" "strings" "testing" - "time" - "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/cosmos/cosmos-sdk/crypto/keyring" "github.com/cosmos/cosmos-sdk/x/params/types/proposal" packetforwardtypes "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v6/router/types" "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" ) // TestPacketForwardMiddlewareAgainstAppUpgrades verifies that the PFM module's params are overridden during an // upgrade from v1 -> v2. func TestPacketForwardMiddlewareAgainstAppUpgrades(t *testing.T) { - testApp, _ := setupTestApp(t, 3) + testApp, _ := util.SetupTestApp(t, 3) supportedVersions := []uint64{v1.Version, v2.Version} require.Equal(t, supportedVersions, testApp.SupportedVersions()) @@ -73,45 +66,4 @@ func TestPacketForwardMiddlewareAgainstAppUpgrades(t *testing.T) { require.NoError(t, err) require.Equal(t, "0.000000000000000000", 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 -} +} \ No newline at end of file diff --git a/test/util/test_app.go b/test/util/test_app.go index 59b7f3cb26..631791ddeb 100644 --- a/test/util/test_app.go +++ b/test/util/test_app.go @@ -292,4 +292,4 @@ func genesisStateWithValSet( // NewDefaultGenesisState generates the default state for the application. func NewDefaultGenesisState(cdc codec.JSONCodec) app.GenesisState { return app.ModuleBasics.DefaultGenesis(cdc) -} +} \ No newline at end of file diff --git a/test/util/testapp_upgrade.go b/test/util/testapp_upgrade.go new file mode 100644 index 0000000000..c7f2d8919e --- /dev/null +++ b/test/util/testapp_upgrade.go @@ -0,0 +1,56 @@ +package util + +import ( + "encoding/json" + "testing" + "time" + + "github.com/celestiaorg/celestia-app/v2/app" + "github.com/celestiaorg/celestia-app/v2/app/encoding" + "github.com/cosmos/cosmos-sdk/crypto/keyring" + "github.com/stretchr/testify/require" + abci "github.com/tendermint/tendermint/abci/types" + "github.com/tendermint/tendermint/libs/log" + dbm "github.com/tendermint/tm-db" +) + +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, EmptyAppOptions{}) + genesisState, _, kr := 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 +} From b1ce2ca34cd50dabc9982476774778e84757b5a2 Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Thu, 11 Apr 2024 20:24:11 +0200 Subject: [PATCH 05/10] test: optimize minfee test too --- x/minfee/upgrade_test.go | 56 ++-------------------------------------- 1 file changed, 2 insertions(+), 54 deletions(-) diff --git a/x/minfee/upgrade_test.go b/x/minfee/upgrade_test.go index 7ce3566fdb..43f5e5b2a8 100644 --- a/x/minfee/upgrade_test.go +++ b/x/minfee/upgrade_test.go @@ -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} @@ -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 -} +} \ No newline at end of file From 980ca89260e6b87df25bd48675a59c098476e5ec Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Thu, 11 Apr 2024 20:24:36 +0200 Subject: [PATCH 06/10] style: lint --- test/packetforward/packetforward_upgrade_test.go | 2 +- test/util/test_app.go | 2 +- x/minfee/upgrade_test.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/test/packetforward/packetforward_upgrade_test.go b/test/packetforward/packetforward_upgrade_test.go index e17bc21717..07a968e21d 100644 --- a/test/packetforward/packetforward_upgrade_test.go +++ b/test/packetforward/packetforward_upgrade_test.go @@ -66,4 +66,4 @@ func TestPacketForwardMiddlewareAgainstAppUpgrades(t *testing.T) { require.NoError(t, err) require.Equal(t, "0.000000000000000000", strings.Trim(got.Param.Value, "\"")) -} \ No newline at end of file +} diff --git a/test/util/test_app.go b/test/util/test_app.go index 631791ddeb..59b7f3cb26 100644 --- a/test/util/test_app.go +++ b/test/util/test_app.go @@ -292,4 +292,4 @@ func genesisStateWithValSet( // NewDefaultGenesisState generates the default state for the application. func NewDefaultGenesisState(cdc codec.JSONCodec) app.GenesisState { return app.ModuleBasics.DefaultGenesis(cdc) -} \ No newline at end of file +} diff --git a/x/minfee/upgrade_test.go b/x/minfee/upgrade_test.go index 43f5e5b2a8..38f8526aaa 100644 --- a/x/minfee/upgrade_test.go +++ b/x/minfee/upgrade_test.go @@ -73,4 +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, "\"")) -} \ No newline at end of file +} From f1a8997ecbc990b8ed38779f0c0aa0f139a53c65 Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Mon, 15 Apr 2024 21:38:19 +0200 Subject: [PATCH 07/10] test: move all upgrade tests in one place --- app/test/upgrade_test.go | 147 ++++++++++++++++++++++++++++++++++- test/ica/ica_upgrade_test.go | 50 ------------ test/util/testapp_upgrade.go | 56 ------------- x/minfee/upgrade_test.go | 76 ------------------ 4 files changed, 146 insertions(+), 183 deletions(-) delete mode 100644 test/ica/ica_upgrade_test.go delete mode 100644 test/util/testapp_upgrade.go delete mode 100644 x/minfee/upgrade_test.go diff --git a/app/test/upgrade_test.go b/app/test/upgrade_test.go index e3e7b87241..8962cca16c 100644 --- a/app/test/upgrade_test.go +++ b/app/test/upgrade_test.go @@ -3,17 +3,31 @@ package app_test import ( "testing" + "fmt" + 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" + "encoding/json" + + "github.com/tendermint/tendermint/libs/log" + "strings" + "time" ) func TestUpgradeAppVersion(t *testing.T) { - testApp, _ := util.SetupTestApp(t, 3) + testApp, _ := SetupTestAppWithUpgradeHeight(t, 3) supportedVersions := []uint64{v1.Version, v2.Version} @@ -31,3 +45,134 @@ func TestUpgradeAppVersion(t *testing.T) { require.EqualValues(t, 2, respEndBlock.ConsensusParamUpdates.Version.AppVersion) require.EqualValues(t, 2, testApp.AppVersion()) } + +func TestMinFeeDuringVersionUpgrades(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()) + + // global min gas price should not have been set yet + gotBefore, err := testApp.ParamsKeeper.Params(ctx, &proposal.QueryParamsRequest{ + Subspace: minfee.ModuleName, + Key: string(minfee.KeyGlobalMinGasPrice), + }) + require.Equal(t, "", gotBefore.Param.Value) + require.NoError(t, err) + + // now the app version changes + respEndBlock := testApp.EndBlock(abci.RequestEndBlock{Height: 2}) + testApp.Commit() + + require.NotNil(t, respEndBlock.ConsensusParamUpdates.Version) + require.EqualValues(t, 2, respEndBlock.ConsensusParamUpdates.Version.AppVersion) + require.EqualValues(t, 2, testApp.AppVersion()) + + // create a new context after endBlock + newCtx := testApp.NewContext(true, tmproto.Header{ + Version: tmversion.Consensus{ + App: 2, + }, + }) + + // global min gas price should be set + got, err := testApp.ParamsKeeper.Params(newCtx, &proposal.QueryParamsRequest{ + Subspace: minfee.ModuleName, + Key: string(minfee.KeyGlobalMinGasPrice), + }) + require.NoError(t, err) + + want, err := sdk.NewDecFromStr(fmt.Sprintf("%f", v2.GlobalMinGasPrice)) + require.NoError(t, err) + require.Equal(t, want.String(), strings.Trim(got.Param.Value, "\"")) +} + +func TestICADuringVersionUpgrades(t *testing.T) { + testApp, _ := SetupTestAppWithUpgradeHeight(t, 3) + 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}, + }}) + require.EqualValues(t, 1, testApp.AppVersion()) + + // Query the ICA host module params + gotBefore, err := testApp.ParamsKeeper.Params(ctx, &proposal.QueryParamsRequest{ + Subspace: icahosttypes.SubModuleName, + Key: string(icahosttypes.KeyHostEnabled), + }) + 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: icahosttypes.SubModuleName, + Key: string(icahosttypes.KeyHostEnabled), + }) + require.NoError(t, err) + require.Equal(t, "true", 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, 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 +} diff --git a/test/ica/ica_upgrade_test.go b/test/ica/ica_upgrade_test.go deleted file mode 100644 index 06f699365e..0000000000 --- a/test/ica/ica_upgrade_test.go +++ /dev/null @@ -1,50 +0,0 @@ -package ica_test - -import ( - "testing" - - "github.com/celestiaorg/celestia-app/v2/test/util" - "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" - version "github.com/tendermint/tendermint/proto/tendermint/version" -) - -// TestICA verifies that the ICA module's params are overridden during an -// upgrade from v1 -> v2. -func TestICA(t *testing.T) { - testApp, _ := util.SetupTestApp(t, 3) - ctx := testApp.NewContext(true, tmproto.Header{ - Version: version.Consensus{ - App: 1, - }, - }) - testApp.BeginBlock(abci.RequestBeginBlock{Header: tmproto.Header{ - Height: 2, - Version: version.Consensus{App: 1}, - }}) - require.EqualValues(t, 1, testApp.AppVersion()) - - // Query the ICA host module params - gotBefore, err := testApp.ParamsKeeper.Params(ctx, &proposal.QueryParamsRequest{ - Subspace: icahosttypes.SubModuleName, - Key: string(icahosttypes.KeyHostEnabled), - }) - 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: version.Consensus{App: 2}}) - got, err := testApp.ParamsKeeper.Params(newCtx, &proposal.QueryParamsRequest{ - Subspace: icahosttypes.SubModuleName, - Key: string(icahosttypes.KeyHostEnabled), - }) - require.NoError(t, err) - require.Equal(t, "true", got.Param.Value) -} diff --git a/test/util/testapp_upgrade.go b/test/util/testapp_upgrade.go deleted file mode 100644 index c7f2d8919e..0000000000 --- a/test/util/testapp_upgrade.go +++ /dev/null @@ -1,56 +0,0 @@ -package util - -import ( - "encoding/json" - "testing" - "time" - - "github.com/celestiaorg/celestia-app/v2/app" - "github.com/celestiaorg/celestia-app/v2/app/encoding" - "github.com/cosmos/cosmos-sdk/crypto/keyring" - "github.com/stretchr/testify/require" - abci "github.com/tendermint/tendermint/abci/types" - "github.com/tendermint/tendermint/libs/log" - dbm "github.com/tendermint/tm-db" -) - -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, EmptyAppOptions{}) - genesisState, _, kr := 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 -} diff --git a/x/minfee/upgrade_test.go b/x/minfee/upgrade_test.go deleted file mode 100644 index 38f8526aaa..0000000000 --- a/x/minfee/upgrade_test.go +++ /dev/null @@ -1,76 +0,0 @@ -package minfee_test - -import ( - "fmt" - "strings" - "testing" - - "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" - - 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" - tmproto "github.com/tendermint/tendermint/proto/tendermint/types" - version "github.com/tendermint/tendermint/proto/tendermint/version" -) - -func TestUpgradeAppVersion(t *testing.T) { - testApp, _ := util.SetupTestApp(t, 3) - - supportedVersions := []uint64{v1.Version, v2.Version} - - require.Equal(t, supportedVersions, testApp.SupportedVersions()) - - ctx := testApp.NewContext(true, tmproto.Header{ - Version: version.Consensus{ - App: 1, - }, - }) - testApp.BeginBlock(abci.RequestBeginBlock{Header: tmproto.Header{ - Height: 2, - Version: version.Consensus{App: 1}, - }}) - - // app version should not have changed yet - require.EqualValues(t, 1, testApp.AppVersion()) - - // global min gas price should not have been set yet - gotBefore, err := testApp.ParamsKeeper.Params(ctx, &proposal.QueryParamsRequest{ - Subspace: minfee.ModuleName, - Key: string(minfee.KeyGlobalMinGasPrice), - }) - require.Equal(t, "", gotBefore.Param.Value) - require.NoError(t, err) - - // now the app version changes - respEndBlock := testApp.EndBlock(abci.RequestEndBlock{Height: 2}) - testApp.Commit() - - require.NotNil(t, respEndBlock.ConsensusParamUpdates.Version) - require.EqualValues(t, 2, respEndBlock.ConsensusParamUpdates.Version.AppVersion) - require.EqualValues(t, 2, testApp.AppVersion()) - - // create a new context after endBlock - newCtx := testApp.NewContext(true, tmproto.Header{ - Version: version.Consensus{ - App: 2, - }, - }) - - // global min gas price should be set - got, err := testApp.ParamsKeeper.Params(newCtx, &proposal.QueryParamsRequest{ - Subspace: minfee.ModuleName, - Key: string(minfee.KeyGlobalMinGasPrice), - }) - require.NoError(t, err) - - want, err := sdk.NewDecFromStr(fmt.Sprintf("%f", v2.GlobalMinGasPrice)) - require.NoError(t, err) - require.Equal(t, want.String(), strings.Trim(got.Param.Value, "\"")) -} From acc69af6c4ca339209db4f3dee329424348ab1ca Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Mon, 15 Apr 2024 21:47:06 +0200 Subject: [PATCH 08/10] test: add pfm upgrade test too --- app/test/upgrade_test.go | 59 ++++++++++++++-- .../packetforward_upgrade_test.go | 69 ------------------- 2 files changed, 55 insertions(+), 73 deletions(-) delete mode 100644 test/packetforward/packetforward_upgrade_test.go diff --git a/app/test/upgrade_test.go b/app/test/upgrade_test.go index 8962cca16c..fd0770d139 100644 --- a/app/test/upgrade_test.go +++ b/app/test/upgrade_test.go @@ -1,9 +1,12 @@ package app_test import ( + "encoding/json" + "fmt" + "strings" "testing" + "time" - "fmt" 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" @@ -19,11 +22,9 @@ import ( tmproto "github.com/tendermint/tendermint/proto/tendermint/types" tmversion "github.com/tendermint/tendermint/proto/tendermint/version" dbm "github.com/tendermint/tm-db" - "encoding/json" + packetforwardtypes "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v6/router/types" "github.com/tendermint/tendermint/libs/log" - "strings" - "time" ) func TestUpgradeAppVersion(t *testing.T) { @@ -46,6 +47,8 @@ func TestUpgradeAppVersion(t *testing.T) { require.EqualValues(t, 2, testApp.AppVersion()) } +// TestMinFeeDuringVersionUpgrades verifies that the minfee module's params are overridden during an +// upgrade from v1 -> v2. func TestMinFeeDuringVersionUpgrades(t *testing.T) { testApp, _ := SetupTestAppWithUpgradeHeight(t, 3) @@ -101,6 +104,8 @@ func TestMinFeeDuringVersionUpgrades(t *testing.T) { require.Equal(t, want.String(), strings.Trim(got.Param.Value, "\"")) } +// TestICADuringVersionUpgrades verifies that the ICA module's params are overridden during an +// upgrade from v1 -> v2. func TestICADuringVersionUpgrades(t *testing.T) { testApp, _ := SetupTestAppWithUpgradeHeight(t, 3) ctx := testApp.NewContext(true, tmproto.Header{ @@ -136,6 +141,52 @@ func TestICADuringVersionUpgrades(t *testing.T) { require.Equal(t, "true", got.Param.Value) } +// TestPacketForwardMiddlewareAgainstAppUpgrades verifies that the PFM module's params are overridden during an +// upgrade from v1 -> v2. +func TestPacketForwardMiddlewareAgainstAppUpgrades(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()) + // PacketForwardMiddleware should not have been set yet + gotBefore, err := testApp.ParamsKeeper.Params(ctx, &proposal.QueryParamsRequest{ + Subspace: packetforwardtypes.ModuleName, + Key: string(packetforwardtypes.KeyFeePercentage), + }) + require.Equal(t, "", gotBefore.Param.Value) + require.NoError(t, err) + // now the app version changes + respEndBlock := testApp.EndBlock(abci.RequestEndBlock{Height: 2}) + testApp.Commit() + require.NotNil(t, respEndBlock.ConsensusParamUpdates.Version) + require.EqualValues(t, 2, respEndBlock.ConsensusParamUpdates.Version.AppVersion) + require.EqualValues(t, 2, testApp.AppVersion()) + // create a new context after endBlock + newCtx := testApp.NewContext(true, tmproto.Header{ + Version: tmversion.Consensus{ + App: 2, + }, + }) + got, err := testApp.ParamsKeeper.Params(newCtx, &proposal.QueryParamsRequest{ + Subspace: packetforwardtypes.ModuleName, + Key: string(packetforwardtypes.KeyFeePercentage), + }) + require.NoError(t, err) + require.NoError(t, err) + require.Equal(t, "0.000000000000000000", strings.Trim(got.Param.Value, "\"")) +} + func SetupTestAppWithUpgradeHeight(t *testing.T, upgradeHeight int64) (*app.App, keyring.Keyring) { t.Helper() diff --git a/test/packetforward/packetforward_upgrade_test.go b/test/packetforward/packetforward_upgrade_test.go deleted file mode 100644 index 07a968e21d..0000000000 --- a/test/packetforward/packetforward_upgrade_test.go +++ /dev/null @@ -1,69 +0,0 @@ -package packetforward_test - -import ( - "strings" - "testing" - - 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/x/params/types/proposal" - packetforwardtypes "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v6/router/types" - "github.com/stretchr/testify/require" - abci "github.com/tendermint/tendermint/abci/types" - tmproto "github.com/tendermint/tendermint/proto/tendermint/types" - version "github.com/tendermint/tendermint/proto/tendermint/version" -) - -// TestPacketForwardMiddlewareAgainstAppUpgrades verifies that the PFM module's params are overridden during an -// upgrade from v1 -> v2. -func TestPacketForwardMiddlewareAgainstAppUpgrades(t *testing.T) { - testApp, _ := util.SetupTestApp(t, 3) - supportedVersions := []uint64{v1.Version, v2.Version} - require.Equal(t, supportedVersions, testApp.SupportedVersions()) - - ctx := testApp.NewContext(true, tmproto.Header{ - Version: version.Consensus{ - App: 1, - }, - }) - testApp.BeginBlock(abci.RequestBeginBlock{Header: tmproto.Header{ - Height: 2, - Version: version.Consensus{App: 1}, - }}) - - // app version should not have changed yet - require.EqualValues(t, 1, testApp.AppVersion()) - - // PacketForwardMiddleware should not have been set yet - gotBefore, err := testApp.ParamsKeeper.Params(ctx, &proposal.QueryParamsRequest{ - Subspace: packetforwardtypes.ModuleName, - Key: string(packetforwardtypes.KeyFeePercentage), - }) - require.Equal(t, "", gotBefore.Param.Value) - require.NoError(t, err) - - // now the app version changes - respEndBlock := testApp.EndBlock(abci.RequestEndBlock{Height: 2}) - testApp.Commit() - - require.NotNil(t, respEndBlock.ConsensusParamUpdates.Version) - require.EqualValues(t, 2, respEndBlock.ConsensusParamUpdates.Version.AppVersion) - require.EqualValues(t, 2, testApp.AppVersion()) - - // create a new context after endBlock - newCtx := testApp.NewContext(true, tmproto.Header{ - Version: version.Consensus{ - App: 2, - }, - }) - - got, err := testApp.ParamsKeeper.Params(newCtx, &proposal.QueryParamsRequest{ - Subspace: packetforwardtypes.ModuleName, - Key: string(packetforwardtypes.KeyFeePercentage), - }) - require.NoError(t, err) - - require.NoError(t, err) - require.Equal(t, "0.000000000000000000", strings.Trim(got.Param.Value, "\"")) -} From 17bf8a59eb46e869f7f023a2e6e78e81096bcd4f Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Mon, 15 Apr 2024 21:48:56 +0200 Subject: [PATCH 09/10] test: nits --- app/test/upgrade_test.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/test/upgrade_test.go b/app/test/upgrade_test.go index fd0770d139..ba7bf2d76f 100644 --- a/app/test/upgrade_test.go +++ b/app/test/upgrade_test.go @@ -27,6 +27,7 @@ import ( "github.com/tendermint/tendermint/libs/log" ) +// TestUpgradeAppVersion verifies that app version changes correctly during an upgrade from v1 -> v2. func TestUpgradeAppVersion(t *testing.T) { testApp, _ := SetupTestAppWithUpgradeHeight(t, 3) @@ -49,7 +50,7 @@ func TestUpgradeAppVersion(t *testing.T) { // TestMinFeeDuringVersionUpgrades verifies that the minfee module's params are overridden during an // upgrade from v1 -> v2. -func TestMinFeeDuringVersionUpgrades(t *testing.T) { +func TestMinFeeAgainstAppUpgrades(t *testing.T) { testApp, _ := SetupTestAppWithUpgradeHeight(t, 3) supportedVersions := []uint64{v1.Version, v2.Version} @@ -106,7 +107,7 @@ func TestMinFeeDuringVersionUpgrades(t *testing.T) { // TestICADuringVersionUpgrades verifies that the ICA module's params are overridden during an // upgrade from v1 -> v2. -func TestICADuringVersionUpgrades(t *testing.T) { +func TestICADuringAppUpgrades(t *testing.T) { testApp, _ := SetupTestAppWithUpgradeHeight(t, 3) ctx := testApp.NewContext(true, tmproto.Header{ Version: tmversion.Consensus{ @@ -143,7 +144,7 @@ func TestICADuringVersionUpgrades(t *testing.T) { // TestPacketForwardMiddlewareAgainstAppUpgrades verifies that the PFM module's params are overridden during an // upgrade from v1 -> v2. -func TestPacketForwardMiddlewareAgainstAppUpgrades(t *testing.T) { +func TestPFMAgainstAppUpgrades(t *testing.T) { testApp, _ := SetupTestAppWithUpgradeHeight(t, 3) supportedVersions := []uint64{v1.Version, v2.Version} require.Equal(t, supportedVersions, testApp.SupportedVersions()) From 3e3a60c92dbc05b1ea663cbfd7aba676585dbbff Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Wed, 17 Apr 2024 19:06:42 +0200 Subject: [PATCH 10/10] test: revert to the refactored test --- app/test/upgrade_test.go | 223 ++++++++++++--------------------------- 1 file changed, 68 insertions(+), 155 deletions(-) diff --git a/app/test/upgrade_test.go b/app/test/upgrade_test.go index ba7bf2d76f..5d2e99d843 100644 --- a/app/test/upgrade_test.go +++ b/app/test/upgrade_test.go @@ -23,169 +23,82 @@ import ( 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/router/types" + packetforwardtypes "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v6/packetforward/types" "github.com/tendermint/tendermint/libs/log" ) -// TestUpgradeAppVersion verifies that app version changes correctly during an upgrade from v1 -> v2. -func TestUpgradeAppVersion(t *testing.T) { - testApp, _ := SetupTestAppWithUpgradeHeight(t, 3) - - supportedVersions := []uint64{v1.Version, v2.Version} - - require.Equal(t, supportedVersions, testApp.SupportedVersions()) - - 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()) -} - -// TestMinFeeDuringVersionUpgrades verifies that the minfee module's params are overridden during an -// upgrade from v1 -> v2. -func TestMinFeeAgainstAppUpgrades(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()) - - // global min gas price should not have been set yet - gotBefore, err := testApp.ParamsKeeper.Params(ctx, &proposal.QueryParamsRequest{ - Subspace: minfee.ModuleName, - Key: string(minfee.KeyGlobalMinGasPrice), - }) - require.Equal(t, "", gotBefore.Param.Value) +// 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) - // now the app version changes - respEndBlock := testApp.EndBlock(abci.RequestEndBlock{Height: 2}) - testApp.Commit() - - require.NotNil(t, respEndBlock.ConsensusParamUpdates.Version) - require.EqualValues(t, 2, respEndBlock.ConsensusParamUpdates.Version.AppVersion) - require.EqualValues(t, 2, testApp.AppVersion()) - - // create a new context after endBlock - newCtx := testApp.NewContext(true, tmproto.Header{ - Version: tmversion.Consensus{ - App: 2, + tests := []struct { + module string + subspace string + key string + expectedValue string + }{ + { + module: "MinFee", + subspace: minfee.ModuleName, + key: string(minfee.KeyGlobalMinGasPrice), + expectedValue: GlobalMinGasPriceDec.String(), }, - }) - - // global min gas price should be set - got, err := testApp.ParamsKeeper.Params(newCtx, &proposal.QueryParamsRequest{ - Subspace: minfee.ModuleName, - Key: string(minfee.KeyGlobalMinGasPrice), - }) - require.NoError(t, err) - - want, err := sdk.NewDecFromStr(fmt.Sprintf("%f", v2.GlobalMinGasPrice)) - require.NoError(t, err) - require.Equal(t, want.String(), strings.Trim(got.Param.Value, "\"")) -} - -// TestICADuringVersionUpgrades verifies that the ICA module's params are overridden during an -// upgrade from v1 -> v2. -func TestICADuringAppUpgrades(t *testing.T) { - testApp, _ := SetupTestAppWithUpgradeHeight(t, 3) - 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}, - }}) - require.EqualValues(t, 1, testApp.AppVersion()) - - // Query the ICA host module params - gotBefore, err := testApp.ParamsKeeper.Params(ctx, &proposal.QueryParamsRequest{ - Subspace: icahosttypes.SubModuleName, - Key: string(icahosttypes.KeyHostEnabled), - }) - 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: icahosttypes.SubModuleName, - Key: string(icahosttypes.KeyHostEnabled), - }) - require.NoError(t, err) - require.Equal(t, "true", got.Param.Value) -} - -// TestPacketForwardMiddlewareAgainstAppUpgrades verifies that the PFM module's params are overridden during an -// upgrade from v1 -> v2. -func TestPFMAgainstAppUpgrades(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, + { + module: "ICA", + subspace: icahosttypes.SubModuleName, + key: string(icahosttypes.KeyHostEnabled), + expectedValue: "true", }, - }) - 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()) - // PacketForwardMiddleware should not have been set yet - gotBefore, err := testApp.ParamsKeeper.Params(ctx, &proposal.QueryParamsRequest{ - Subspace: packetforwardtypes.ModuleName, - Key: string(packetforwardtypes.KeyFeePercentage), - }) - require.Equal(t, "", gotBefore.Param.Value) - require.NoError(t, err) - // now the app version changes - respEndBlock := testApp.EndBlock(abci.RequestEndBlock{Height: 2}) - testApp.Commit() - require.NotNil(t, respEndBlock.ConsensusParamUpdates.Version) - require.EqualValues(t, 2, respEndBlock.ConsensusParamUpdates.Version.AppVersion) - require.EqualValues(t, 2, testApp.AppVersion()) - // create a new context after endBlock - newCtx := testApp.NewContext(true, tmproto.Header{ - Version: tmversion.Consensus{ - App: 2, + { + module: "PFM", + subspace: packetforwardtypes.ModuleName, + key: string(packetforwardtypes.KeyFeePercentage), + expectedValue: "0.000000000000000000", }, - }) - got, err := testApp.ParamsKeeper.Params(newCtx, &proposal.QueryParamsRequest{ - Subspace: packetforwardtypes.ModuleName, - Key: string(packetforwardtypes.KeyFeePercentage), - }) - require.NoError(t, err) - require.NoError(t, err) - require.Equal(t, "0.000000000000000000", strings.Trim(got.Param.Value, "\"")) + } + 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) {