From 5edec3d2057dbca837b25c488b74e22b72385331 Mon Sep 17 00:00:00 2001 From: Rootul Patel Date: Fri, 6 Dec 2024 12:48:58 -0500 Subject: [PATCH] refactor: export test chain id --- app/benchmarks/benchmark_ibc_update_client_test.go | 4 +--- app/test/upgrade_test.go | 2 +- pkg/appconsts/chain_ids.go | 2 ++ pkg/appconsts/versioned_consts.go | 2 +- pkg/appconsts/versioned_consts_test.go | 4 ++-- test/e2e/benchmark/throughput.go | 2 +- x/signal/integration_test.go | 5 ++--- x/signal/keeper_test.go | 6 +++--- 8 files changed, 13 insertions(+), 14 deletions(-) diff --git a/app/benchmarks/benchmark_ibc_update_client_test.go b/app/benchmarks/benchmark_ibc_update_client_test.go index 873c560a95..d397076384 100644 --- a/app/benchmarks/benchmark_ibc_update_client_test.go +++ b/app/benchmarks/benchmark_ibc_update_client_test.go @@ -441,8 +441,6 @@ func generateUpdateClientTransaction(b *testing.B, app *app.App, signer user.Sig return msgs } -var chainID = "test" - func makeState(nVals, height int) (sm.State, dbm.DB, map[string]types0.PrivValidator) { vals := make([]types0.GenesisValidator, nVals) privVals := make(map[string]types0.PrivValidator, nVals) @@ -459,7 +457,7 @@ func makeState(nVals, height int) (sm.State, dbm.DB, map[string]types0.PrivValid privVals[valAddr.String()] = types0.NewMockPVWithParams(pk, false, false) } s, _ := sm.MakeGenesisState(&types0.GenesisDoc{ - ChainID: chainID, + ChainID: appconsts.TestChainID, Validators: vals, AppHash: nil, }) diff --git a/app/test/upgrade_test.go b/app/test/upgrade_test.go index 899d2268c9..b90e146c67 100644 --- a/app/test/upgrade_test.go +++ b/app/test/upgrade_test.go @@ -255,7 +255,7 @@ func SetupTestAppWithUpgradeHeight(t *testing.T, upgradeHeight int64) (*app.App, encCfg := encoding.MakeConfig(app.ModuleEncodingRegisters...) testApp := app.New(log.NewNopLogger(), db, nil, 0, encCfg, upgradeHeight, util.EmptyAppOptions{}) genesis := genesis.NewDefaultGenesis(). - WithChainID("test"). + WithChainID(appconsts.TestChainID). WithValidators(genesis.NewDefaultValidator(testnode.DefaultValidatorAccountName)). WithConsensusParams(app.DefaultInitialConsensusParams()) genDoc, err := genesis.Export() diff --git a/pkg/appconsts/chain_ids.go b/pkg/appconsts/chain_ids.go index 50c26932f9..f26b4816f7 100644 --- a/pkg/appconsts/chain_ids.go +++ b/pkg/appconsts/chain_ids.go @@ -2,4 +2,6 @@ package appconsts const ( ArabicaChainID = "arabica-11" + // TestChainID is the chain ID used for testing. + TestChainID = "test" ) diff --git a/pkg/appconsts/versioned_consts.go b/pkg/appconsts/versioned_consts.go index 57ff919bee..0ddbe16ff1 100644 --- a/pkg/appconsts/versioned_consts.go +++ b/pkg/appconsts/versioned_consts.go @@ -80,7 +80,7 @@ func GetTimeoutCommit(v uint64) time.Duration { // UpgradeHeightDelay returns the delay in blocks after a quorum has been reached that the chain should upgrade to the new version. func UpgradeHeightDelay(chainID string, v uint64) int64 { - if chainID == "test" { + if chainID == TestChainID { return 3 } switch v { diff --git a/pkg/appconsts/versioned_consts_test.go b/pkg/appconsts/versioned_consts_test.go index f85d05b163..6b62a58d98 100644 --- a/pkg/appconsts/versioned_consts_test.go +++ b/pkg/appconsts/versioned_consts_test.go @@ -120,13 +120,13 @@ func TestUpgradeHeightDelay(t *testing.T) { }, { name: "the upgrade delay for chainID 'test' should be 3 regardless of the version", - chainID: "test", + chainID: appconsts.TestChainID, version: 3, expectedUpgradeHeightDelay: 3, }, { name: "the upgrade delay for chainID 'test' should be 3 regardless of the version", - chainID: "test", + chainID: appconsts.TestChainID, version: 4, expectedUpgradeHeightDelay: 3, }, diff --git a/test/e2e/benchmark/throughput.go b/test/e2e/benchmark/throughput.go index 75bf1bdf6c..fb3fdca6ba 100644 --- a/test/e2e/benchmark/throughput.go +++ b/test/e2e/benchmark/throughput.go @@ -11,7 +11,7 @@ import ( ) var bigBlockManifest = Manifest{ - ChainID: "test", + ChainID: appconsts.TestChainID, Validators: 2, TxClients: 2, ValidatorResource: testnet.Resources{ diff --git a/x/signal/integration_test.go b/x/signal/integration_test.go index e1f79db39b..378ff748d3 100644 --- a/x/signal/integration_test.go +++ b/x/signal/integration_test.go @@ -23,12 +23,11 @@ func TestUpgradeIntegration(t *testing.T) { cp := app.DefaultConsensusParams() cp.Version.AppVersion = v2.Version app, _ := testutil.SetupTestAppWithGenesisValSet(cp) - chainID := "test" ctx := sdk.NewContext(app.CommitMultiStore(), tmtypes.Header{ Version: tmversion.Consensus{ App: v2.Version, }, - ChainID: chainID, + ChainID: appconsts.TestChainID, }, false, tmlog.NewNopLogger()) goCtx := sdk.WrapSDKContext(ctx) ctx = sdk.UnwrapSDKContext(goCtx) @@ -89,7 +88,7 @@ func TestUpgradeIntegration(t *testing.T) { require.False(t, shouldUpgrade) require.EqualValues(t, 0, version) - ctx = ctx.WithBlockHeight(ctx.BlockHeight() + appconsts.UpgradeHeightDelay(chainID, version)) + ctx = ctx.WithBlockHeight(ctx.BlockHeight() + appconsts.UpgradeHeightDelay(appconsts.TestChainID, version)) shouldUpgrade, version = app.SignalKeeper.ShouldUpgrade(ctx) require.True(t, shouldUpgrade) diff --git a/x/signal/keeper_test.go b/x/signal/keeper_test.go index 676c93f838..2cefad5b34 100644 --- a/x/signal/keeper_test.go +++ b/x/signal/keeper_test.go @@ -183,7 +183,7 @@ func TestTallyingLogic(t *testing.T) { require.False(t, shouldUpgrade) // should be false because upgrade height hasn't been reached. require.Equal(t, uint64(0), version) - ctx = ctx.WithBlockHeight(ctx.BlockHeight() + appconsts.UpgradeHeightDelay("test", version)) + ctx = ctx.WithBlockHeight(ctx.BlockHeight() + appconsts.UpgradeHeightDelay(appconsts.TestChainID, version)) shouldUpgrade, version = upgradeKeeper.ShouldUpgrade(ctx) require.True(t, shouldUpgrade) // should be true because upgrade height has been reached. @@ -426,7 +426,7 @@ func TestGetUpgrade(t *testing.T) { got, err := upgradeKeeper.GetUpgrade(ctx, &types.QueryGetUpgradeRequest{}) require.NoError(t, err) assert.Equal(t, v2.Version, got.Upgrade.AppVersion) - assert.Equal(t, appconsts.UpgradeHeightDelay("test", v2.Version), got.Upgrade.UpgradeHeight) + assert.Equal(t, appconsts.UpgradeHeightDelay(appconsts.TestChainID, v2.Version), got.Upgrade.UpgradeHeight) }) } @@ -477,7 +477,7 @@ func setup(t *testing.T) (signal.Keeper, sdk.Context, *mockStakingKeeper) { Block: 1, App: 1, }, - ChainID: "test", + ChainID: appconsts.TestChainID, }, false, log.NewNopLogger()) mockStakingKeeper := newMockStakingKeeper( map[string]int64{