diff --git a/vms/platformvm/block/builder/helpers_test.go b/vms/platformvm/block/builder/helpers_test.go index 0ed61f930d01..1d7436485e17 100644 --- a/vms/platformvm/block/builder/helpers_test.go +++ b/vms/platformvm/block/builder/helpers_test.go @@ -15,7 +15,6 @@ import ( "github.com/ava-labs/avalanchego/chains/atomic" "github.com/ava-labs/avalanchego/codec" "github.com/ava-labs/avalanchego/codec/linearcodec" - "github.com/ava-labs/avalanchego/database" "github.com/ava-labs/avalanchego/database/memdb" "github.com/ava-labs/avalanchego/database/prefixdb" "github.com/ava-labs/avalanchego/database/versiondb" @@ -43,6 +42,7 @@ import ( "github.com/ava-labs/avalanchego/vms/platformvm/network" "github.com/ava-labs/avalanchego/vms/platformvm/reward" "github.com/ava-labs/avalanchego/vms/platformvm/state" + "github.com/ava-labs/avalanchego/vms/platformvm/state/statetest" "github.com/ava-labs/avalanchego/vms/platformvm/status" "github.com/ava-labs/avalanchego/vms/platformvm/txs" "github.com/ava-labs/avalanchego/vms/platformvm/txs/fee" @@ -139,7 +139,13 @@ func newEnvironment(t *testing.T, f upgradetest.Fork) *environment { //nolint:un res.fx = defaultFx(t, res.clk, res.ctx.Log, res.isBootstrapped.Get()) rewardsCalc := reward.NewCalculator(res.config.RewardConfig) - res.state = defaultState(t, res.config, res.ctx, res.baseDB, rewardsCalc) + res.state = statetest.New(t, statetest.Config{ + DB: res.baseDB, + Genesis: buildGenesisTest(t, res.ctx), + Validators: res.config.Validators, + Context: res.ctx, + Rewards: rewardsCalc, + }) res.uptimes = uptime.NewManager(res.state, res.clk) res.utxosVerifier = utxo.NewVerifier(res.ctx, res.clk, res.fx) @@ -263,35 +269,6 @@ func addSubnet(t *testing.T, env *environment) { require.NoError(env.state.Commit()) } -func defaultState( - t *testing.T, - cfg *config.Config, - ctx *snow.Context, - db database.Database, - rewards reward.Calculator, -) state.State { - require := require.New(t) - - execCfg, _ := config.GetExecutionConfig([]byte(`{}`)) - genesisBytes := buildGenesisTest(t, ctx) - state, err := state.New( - db, - genesisBytes, - prometheus.NewRegistry(), - cfg, - execCfg, - ctx, - metrics.Noop, - rewards, - ) - require.NoError(err) - - // persist and reload to init a bunch of in-memory stuff - state.SetHeight(0) - require.NoError(state.Commit()) - return state -} - func defaultConfig(f upgradetest.Fork) *config.Config { upgrades := upgradetest.GetConfigWithUpgradeTime(f, time.Time{}) // This package neglects fork ordering diff --git a/vms/platformvm/block/executor/helpers_test.go b/vms/platformvm/block/executor/helpers_test.go index 22305de07ac7..08b1d334d4df 100644 --- a/vms/platformvm/block/executor/helpers_test.go +++ b/vms/platformvm/block/executor/helpers_test.go @@ -17,7 +17,6 @@ import ( "github.com/ava-labs/avalanchego/chains/atomic" "github.com/ava-labs/avalanchego/codec" "github.com/ava-labs/avalanchego/codec/linearcodec" - "github.com/ava-labs/avalanchego/database" "github.com/ava-labs/avalanchego/database/memdb" "github.com/ava-labs/avalanchego/database/prefixdb" "github.com/ava-labs/avalanchego/database/versiondb" @@ -43,6 +42,7 @@ import ( "github.com/ava-labs/avalanchego/vms/platformvm/metrics" "github.com/ava-labs/avalanchego/vms/platformvm/reward" "github.com/ava-labs/avalanchego/vms/platformvm/state" + "github.com/ava-labs/avalanchego/vms/platformvm/state/statetest" "github.com/ava-labs/avalanchego/vms/platformvm/status" "github.com/ava-labs/avalanchego/vms/platformvm/txs" "github.com/ava-labs/avalanchego/vms/platformvm/txs/executor" @@ -77,8 +77,7 @@ var ( avaxAssetID = ids.ID{'y', 'e', 'e', 't'} defaultTxFee = uint64(100) - genesisBlkID ids.ID - testSubnet1 *txs.Tx + testSubnet1 *txs.Tx // Node IDs of genesis validators. Initialized in init function genesisNodeIDs []ids.NodeID @@ -148,7 +147,14 @@ func newEnvironment(t *testing.T, ctrl *gomock.Controller, f upgradetest.Fork) * rewardsCalc := reward.NewCalculator(res.config.RewardConfig) if ctrl == nil { - res.state = defaultState(res.config, res.ctx, res.baseDB, rewardsCalc) + res.state = statetest.New(t, statetest.Config{ + DB: res.baseDB, + Genesis: buildGenesisTest(res.ctx), + Validators: res.config.Validators, + Context: res.ctx, + Rewards: rewardsCalc, + }) + res.uptimes = uptime.NewManager(res.state, res.clk) res.utxosVerifier = utxo.NewVerifier(res.ctx, res.clk, res.fx) res.factory = txstest.NewWalletFactory( @@ -157,7 +163,6 @@ func newEnvironment(t *testing.T, ctrl *gomock.Controller, f upgradetest.Fork) * res.state, ) } else { - genesisBlkID = ids.GenerateTestID() res.mockedState = state.NewMockState(ctrl) res.uptimes = uptime.NewManager(res.mockedState, res.clk) res.utxosVerifier = utxo.NewVerifier(res.ctx, res.clk, res.fx) @@ -168,7 +173,7 @@ func newEnvironment(t *testing.T, ctrl *gomock.Controller, f upgradetest.Fork) * ) // setup expectations strictly needed for environment creation - res.mockedState.EXPECT().GetLastAccepted().Return(genesisBlkID).Times(1) + res.mockedState.EXPECT().GetLastAccepted().Return(ids.GenerateTestID()).Times(1) } res.backend = &executor.Backend{ @@ -292,37 +297,6 @@ func addSubnet(env *environment) { } } -func defaultState( - cfg *config.Config, - ctx *snow.Context, - db database.Database, - rewards reward.Calculator, -) state.State { - genesisBytes := buildGenesisTest(ctx) - execCfg, _ := config.GetExecutionConfig([]byte(`{}`)) - state, err := state.New( - db, - genesisBytes, - prometheus.NewRegistry(), - cfg, - execCfg, - ctx, - metrics.Noop, - rewards, - ) - if err != nil { - panic(err) - } - - // persist and reload to init a bunch of in-memory stuff - state.SetHeight(0) - if err := state.Commit(); err != nil { - panic(err) - } - genesisBlkID = state.GetLastAccepted() - return state -} - func defaultConfig(f upgradetest.Fork) *config.Config { upgrades := upgradetest.GetConfigWithUpgradeTime(f, time.Time{}) // This package neglects fork ordering diff --git a/vms/platformvm/block/executor/proposal_block_test.go b/vms/platformvm/block/executor/proposal_block_test.go index 0dbcb74c11d5..a7f38e28850c 100644 --- a/vms/platformvm/block/executor/proposal_block_test.go +++ b/vms/platformvm/block/executor/proposal_block_test.go @@ -148,7 +148,7 @@ func TestBanffProposalBlockTimeVerification(t *testing.T) { parentHeight := uint64(2022) banffParentBlk, err := block.NewApricotStandardBlock( - genesisBlkID, // does not matter + ids.GenerateTestID(), // does not matter parentHeight, nil, // txs do not matter in this test ) diff --git a/vms/platformvm/state/state.go b/vms/platformvm/state/state.go index 6923f2414e25..9002293f6511 100644 --- a/vms/platformvm/state/state.go +++ b/vms/platformvm/state/state.go @@ -26,6 +26,7 @@ import ( "github.com/ava-labs/avalanchego/snow/choices" "github.com/ava-labs/avalanchego/snow/uptime" "github.com/ava-labs/avalanchego/snow/validators" + "github.com/ava-labs/avalanchego/upgrade" "github.com/ava-labs/avalanchego/utils/constants" "github.com/ava-labs/avalanchego/utils/crypto/bls" "github.com/ava-labs/avalanchego/utils/hashing" @@ -285,7 +286,7 @@ type state struct { validators validators.Manager ctx *snow.Context - cfg *config.Config + upgrades upgrade.Config metrics metrics.Metrics rewards reward.Calculator @@ -452,7 +453,8 @@ func New( db database.Database, genesisBytes []byte, metricsReg prometheus.Registerer, - cfg *config.Config, + validators validators.Manager, + upgrades upgrade.Config, execCfg *config.ExecutionConfig, ctx *snow.Context, metrics metrics.Metrics, @@ -585,9 +587,9 @@ func New( s := &state{ validatorState: newValidatorState(), - validators: cfg.Validators, + validators: validators, ctx: ctx, - cfg: cfg, + upgrades: upgrades, metrics: metrics, rewards: rewards, baseDB: baseDB, @@ -1670,7 +1672,7 @@ func (s *state) initValidatorSets() error { func (s *state) write(updateValidators bool, height uint64) error { codecVersion := CodecVersion1 - if !s.cfg.UpgradeConfig.IsDurangoActivated(s.GetTimestamp()) { + if !s.upgrades.IsDurangoActivated(s.GetTimestamp()) { codecVersion = CodecVersion0 } diff --git a/vms/platformvm/state/state_test.go b/vms/platformvm/state/state_test.go index 21357874e434..2bd5798bc721 100644 --- a/vms/platformvm/state/state_test.go +++ b/vms/platformvm/state/state_test.go @@ -23,6 +23,7 @@ import ( "github.com/ava-labs/avalanchego/snow" "github.com/ava-labs/avalanchego/snow/choices" "github.com/ava-labs/avalanchego/snow/validators" + "github.com/ava-labs/avalanchego/upgrade/upgradetest" "github.com/ava-labs/avalanchego/utils/constants" "github.com/ava-labs/avalanchego/utils/crypto/bls" "github.com/ava-labs/avalanchego/utils/logging" @@ -50,9 +51,8 @@ func newTestState(t testing.TB, db database.Database) *state { db, genesistest.NewBytes(t), prometheus.NewRegistry(), - &config.Config{ - Validators: validators.NewManager(), - }, + validators.NewManager(), + upgradetest.GetConfig(upgradetest.Latest), &config.DefaultExecutionConfig, &snow.Context{ Log: logging.NoLog{}, @@ -152,7 +152,7 @@ func TestPersistStakers(t *testing.T) { r.Equal(staker, retrievedStaker) }, checkValidatorsSet: func(r *require.Assertions, s *state, staker *Staker) { - valsMap := s.cfg.Validators.GetMap(staker.SubnetID) + valsMap := s.validators.GetMap(staker.SubnetID) r.Contains(valsMap, staker.NodeID) r.Equal( &validators.GetValidatorOutput{ @@ -258,7 +258,7 @@ func TestPersistStakers(t *testing.T) { val, err := s.GetCurrentValidator(staker.SubnetID, staker.NodeID) r.NoError(err) - valsMap := s.cfg.Validators.GetMap(staker.SubnetID) + valsMap := s.validators.GetMap(staker.SubnetID) r.Contains(valsMap, staker.NodeID) valOut := valsMap[staker.NodeID] r.Equal(valOut.NodeID, staker.NodeID) @@ -313,7 +313,7 @@ func TestPersistStakers(t *testing.T) { }, checkValidatorsSet: func(r *require.Assertions, s *state, staker *Staker) { // pending validators are not showed in validators set - valsMap := s.cfg.Validators.GetMap(staker.SubnetID) + valsMap := s.validators.GetMap(staker.SubnetID) r.NotContains(valsMap, staker.NodeID) }, checkValidatorUptimes: func(r *require.Assertions, s *state, staker *Staker) { @@ -388,7 +388,7 @@ func TestPersistStakers(t *testing.T) { r.Equal(staker, retrievedDelegator) }, checkValidatorsSet: func(r *require.Assertions, s *state, staker *Staker) { - valsMap := s.cfg.Validators.GetMap(staker.SubnetID) + valsMap := s.validators.GetMap(staker.SubnetID) r.NotContains(valsMap, staker.NodeID) }, checkValidatorUptimes: func(*require.Assertions, *state, *Staker) {}, @@ -435,7 +435,7 @@ func TestPersistStakers(t *testing.T) { }, checkValidatorsSet: func(r *require.Assertions, s *state, staker *Staker) { // deleted validators are not showed in the validators set anymore - valsMap := s.cfg.Validators.GetMap(staker.SubnetID) + valsMap := s.validators.GetMap(staker.SubnetID) r.NotContains(valsMap, staker.NodeID) }, checkValidatorUptimes: func(r *require.Assertions, s *state, staker *Staker) { @@ -532,7 +532,7 @@ func TestPersistStakers(t *testing.T) { val, err := s.GetCurrentValidator(staker.SubnetID, staker.NodeID) r.NoError(err) - valsMap := s.cfg.Validators.GetMap(staker.SubnetID) + valsMap := s.validators.GetMap(staker.SubnetID) r.Contains(valsMap, staker.NodeID) valOut := valsMap[staker.NodeID] r.Equal(valOut.NodeID, staker.NodeID) @@ -589,7 +589,7 @@ func TestPersistStakers(t *testing.T) { r.ErrorIs(err, database.ErrNotFound) }, checkValidatorsSet: func(r *require.Assertions, s *state, staker *Staker) { - valsMap := s.cfg.Validators.GetMap(staker.SubnetID) + valsMap := s.validators.GetMap(staker.SubnetID) r.NotContains(valsMap, staker.NodeID) }, checkValidatorUptimes: func(r *require.Assertions, s *state, staker *Staker) { @@ -660,7 +660,7 @@ func TestPersistStakers(t *testing.T) { delIt.Release() }, checkValidatorsSet: func(r *require.Assertions, s *state, staker *Staker) { - valsMap := s.cfg.Validators.GetMap(staker.SubnetID) + valsMap := s.validators.GetMap(staker.SubnetID) r.NotContains(valsMap, staker.NodeID) }, checkValidatorUptimes: func(*require.Assertions, *state, *Staker) {}, diff --git a/vms/platformvm/state/statetest/state.go b/vms/platformvm/state/statetest/state.go new file mode 100644 index 000000000000..fbc71381ec51 --- /dev/null +++ b/vms/platformvm/state/statetest/state.go @@ -0,0 +1,90 @@ +// Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. +// See the file LICENSE for licensing terms. + +package statetest + +import ( + "testing" + "time" + + "github.com/prometheus/client_golang/prometheus" + "github.com/stretchr/testify/require" + + "github.com/ava-labs/avalanchego/database" + "github.com/ava-labs/avalanchego/database/memdb" + "github.com/ava-labs/avalanchego/ids" + "github.com/ava-labs/avalanchego/snow" + "github.com/ava-labs/avalanchego/snow/validators" + "github.com/ava-labs/avalanchego/upgrade" + "github.com/ava-labs/avalanchego/upgrade/upgradetest" + "github.com/ava-labs/avalanchego/utils/constants" + "github.com/ava-labs/avalanchego/utils/logging" + "github.com/ava-labs/avalanchego/utils/units" + "github.com/ava-labs/avalanchego/vms/platformvm/config" + "github.com/ava-labs/avalanchego/vms/platformvm/genesis/genesistest" + "github.com/ava-labs/avalanchego/vms/platformvm/metrics" + "github.com/ava-labs/avalanchego/vms/platformvm/reward" + "github.com/ava-labs/avalanchego/vms/platformvm/state" +) + +type Config struct { + DB database.Database + Genesis []byte + Registerer prometheus.Registerer + Validators validators.Manager + Upgrades upgrade.Config + ExecutionConfig config.ExecutionConfig + Context *snow.Context + Metrics metrics.Metrics + Rewards reward.Calculator +} + +func New(t testing.TB, c Config) state.State { + if c.DB == nil { + c.DB = memdb.New() + } + if len(c.Genesis) == 0 { + c.Genesis = genesistest.NewBytes(t) + } + if c.Registerer == nil { + c.Registerer = prometheus.NewRegistry() + } + if c.Upgrades == (upgrade.Config{}) { + c.Upgrades = upgradetest.GetConfig(upgradetest.Latest) + } + if c.ExecutionConfig == (config.ExecutionConfig{}) { + c.ExecutionConfig = config.DefaultExecutionConfig + } + if c.Context == nil { + c.Context = &snow.Context{ + NetworkID: constants.UnitTestID, + NodeID: ids.GenerateTestNodeID(), + Log: logging.NoLog{}, + } + } + if c.Metrics == nil { + c.Metrics = metrics.Noop + } + if c.Rewards == nil { + c.Rewards = reward.NewCalculator(reward.Config{ + MaxConsumptionRate: .12 * reward.PercentDenominator, + MinConsumptionRate: .1 * reward.PercentDenominator, + MintingPeriod: 365 * 24 * time.Hour, + SupplyCap: 720 * units.MegaAvax, + }) + } + + s, err := state.New( + c.DB, + c.Genesis, + c.Registerer, + c.Validators, + c.Upgrades, + &c.ExecutionConfig, + c.Context, + c.Metrics, + c.Rewards, + ) + require.NoError(t, err) + return s +} diff --git a/vms/platformvm/txs/executor/helpers_test.go b/vms/platformvm/txs/executor/helpers_test.go index 2342f2270d43..4005c32fddaa 100644 --- a/vms/platformvm/txs/executor/helpers_test.go +++ b/vms/platformvm/txs/executor/helpers_test.go @@ -10,14 +10,12 @@ import ( "testing" "time" - "github.com/prometheus/client_golang/prometheus" "github.com/stretchr/testify/require" "github.com/ava-labs/avalanchego/chains" "github.com/ava-labs/avalanchego/chains/atomic" "github.com/ava-labs/avalanchego/codec" "github.com/ava-labs/avalanchego/codec/linearcodec" - "github.com/ava-labs/avalanchego/database" "github.com/ava-labs/avalanchego/database/memdb" "github.com/ava-labs/avalanchego/database/versiondb" "github.com/ava-labs/avalanchego/ids" @@ -38,9 +36,9 @@ import ( "github.com/ava-labs/avalanchego/vms/platformvm/api" "github.com/ava-labs/avalanchego/vms/platformvm/config" "github.com/ava-labs/avalanchego/vms/platformvm/fx" - "github.com/ava-labs/avalanchego/vms/platformvm/metrics" "github.com/ava-labs/avalanchego/vms/platformvm/reward" "github.com/ava-labs/avalanchego/vms/platformvm/state" + "github.com/ava-labs/avalanchego/vms/platformvm/state/statetest" "github.com/ava-labs/avalanchego/vms/platformvm/status" "github.com/ava-labs/avalanchego/vms/platformvm/txs" "github.com/ava-labs/avalanchego/vms/platformvm/txs/fee" @@ -133,7 +131,15 @@ func newEnvironment(t *testing.T, f upgradetest.Fork) *environment { fx := defaultFx(clk, ctx.Log, isBootstrapped.Get()) rewards := reward.NewCalculator(config.RewardConfig) - baseState := defaultState(config, ctx, baseDB, rewards) + baseState := statetest.New(t, statetest.Config{ + DB: baseDB, + Genesis: buildGenesisTest(ctx), + Validators: config.Validators, + Upgrades: config.UpgradeConfig, + Context: ctx, + Rewards: rewards, + }) + lastAcceptedID = baseState.GetLastAccepted() uptimes := uptime.NewManager(baseState, clk) utxosVerifier := utxo.NewVerifier(ctx, clk, fx) @@ -235,37 +241,6 @@ func addSubnet(t *testing.T, env *environment) { require.NoError(env.state.Commit()) } -func defaultState( - cfg *config.Config, - ctx *snow.Context, - db database.Database, - rewards reward.Calculator, -) state.State { - genesisBytes := buildGenesisTest(ctx) - execCfg, _ := config.GetExecutionConfig(nil) - state, err := state.New( - db, - genesisBytes, - prometheus.NewRegistry(), - cfg, - execCfg, - ctx, - metrics.Noop, - rewards, - ) - if err != nil { - panic(err) - } - - // persist and reload to init a bunch of in-memory stuff - state.SetHeight(0) - if err := state.Commit(); err != nil { - panic(err) - } - lastAcceptedID = state.GetLastAccepted() - return state -} - func defaultConfig(f upgradetest.Fork) *config.Config { upgrades := upgradetest.GetConfigWithUpgradeTime( f, diff --git a/vms/platformvm/validators/manager_benchmark_test.go b/vms/platformvm/validators/manager_benchmark_test.go index 8215a54475a4..905bb8fc2a1d 100644 --- a/vms/platformvm/validators/manager_benchmark_test.go +++ b/vms/platformvm/validators/manager_benchmark_test.go @@ -14,7 +14,6 @@ import ( "github.com/ava-labs/avalanchego/database/leveldb" "github.com/ava-labs/avalanchego/ids" - "github.com/ava-labs/avalanchego/snow" "github.com/ava-labs/avalanchego/snow/validators" "github.com/ava-labs/avalanchego/utils/constants" "github.com/ava-labs/avalanchego/utils/crypto/bls" @@ -30,6 +29,7 @@ import ( "github.com/ava-labs/avalanchego/vms/platformvm/metrics" "github.com/ava-labs/avalanchego/vms/platformvm/reward" "github.com/ava-labs/avalanchego/vms/platformvm/state" + "github.com/ava-labs/avalanchego/vms/platformvm/state/statetest" "github.com/ava-labs/avalanchego/vms/platformvm/txs" ) @@ -99,35 +99,11 @@ func BenchmarkGetValidatorSet(b *testing.B) { require.NoError(err) vdrs := validators.NewManager() - - execConfig, err := config.GetExecutionConfig(nil) - require.NoError(err) - - metrics, err := metrics.New(prometheus.NewRegistry()) - require.NoError(err) - - s, err := state.New( - db, - genesisBytes, - prometheus.NewRegistry(), - &config.Config{ - Validators: vdrs, - }, - execConfig, - &snow.Context{ - NetworkID: constants.UnitTestID, - NodeID: ids.GenerateTestNodeID(), - Log: logging.NoLog{}, - }, - metrics, - reward.NewCalculator(reward.Config{ - MaxConsumptionRate: .12 * reward.PercentDenominator, - MinConsumptionRate: .10 * reward.PercentDenominator, - MintingPeriod: 365 * 24 * time.Hour, - SupplyCap: 720 * units.MegaAvax, - }), - ) - require.NoError(err) + s := statetest.New(b, statetest.Config{ + DB: db, + Genesis: genesisBytes, + Validators: vdrs, + }) m := NewManager( logging.NoLog{}, @@ -135,7 +111,7 @@ func BenchmarkGetValidatorSet(b *testing.B) { Validators: vdrs, }, s, - metrics, + metrics.Noop, new(mockable.Clock), ) diff --git a/vms/platformvm/vm.go b/vms/platformvm/vm.go index d6b97a441270..ba86190e953b 100644 --- a/vms/platformvm/vm.go +++ b/vms/platformvm/vm.go @@ -139,7 +139,8 @@ func (vm *VM) Initialize( vm.db, genesisBytes, registerer, - &vm.Config, + vm.Config.Validators, + vm.Config.UpgradeConfig, execConfig, vm.ctx, vm.metrics, diff --git a/vms/platformvm/vm_regression_test.go b/vms/platformvm/vm_regression_test.go index 3146a8372518..851117920bcf 100644 --- a/vms/platformvm/vm_regression_test.go +++ b/vms/platformvm/vm_regression_test.go @@ -10,7 +10,6 @@ import ( "testing" "time" - "github.com/prometheus/client_golang/prometheus" "github.com/stretchr/testify/require" "golang.org/x/sync/errgroup" @@ -36,10 +35,9 @@ import ( "github.com/ava-labs/avalanchego/vms/components/avax" "github.com/ava-labs/avalanchego/vms/platformvm/block" "github.com/ava-labs/avalanchego/vms/platformvm/config" - "github.com/ava-labs/avalanchego/vms/platformvm/metrics" "github.com/ava-labs/avalanchego/vms/platformvm/reward" "github.com/ava-labs/avalanchego/vms/platformvm/signer" - "github.com/ava-labs/avalanchego/vms/platformvm/state" + "github.com/ava-labs/avalanchego/vms/platformvm/state/statetest" "github.com/ava-labs/avalanchego/vms/platformvm/txs" "github.com/ava-labs/avalanchego/vms/platformvm/txs/executor" "github.com/ava-labs/avalanchego/vms/platformvm/txs/txstest" @@ -764,18 +762,13 @@ func TestRejectedStateRegressionInvalidValidatorTimestamp(t *testing.T) { // Force a reload of the state from the database. vm.Config.Validators = validators.NewManager() - execCfg, _ := config.GetExecutionConfig(nil) - newState, err := state.New( - vm.db, - nil, - prometheus.NewRegistry(), - &vm.Config, - execCfg, - vm.ctx, - metrics.Noop, - reward.NewCalculator(vm.Config.RewardConfig), - ) - require.NoError(err) + newState := statetest.New(t, statetest.Config{ + DB: vm.db, + Validators: vm.Config.Validators, + Upgrades: vm.Config.UpgradeConfig, + Context: vm.ctx, + Rewards: reward.NewCalculator(vm.Config.RewardConfig), + }) // Verify that new validator is now in the current validator set. { @@ -1067,18 +1060,13 @@ func TestRejectedStateRegressionInvalidValidatorReward(t *testing.T) { // Force a reload of the state from the database. vm.Config.Validators = validators.NewManager() - execCfg, _ := config.GetExecutionConfig(nil) - newState, err := state.New( - vm.db, - nil, - prometheus.NewRegistry(), - &vm.Config, - execCfg, - vm.ctx, - metrics.Noop, - reward.NewCalculator(vm.Config.RewardConfig), - ) - require.NoError(err) + newState := statetest.New(t, statetest.Config{ + DB: vm.db, + Validators: vm.Config.Validators, + Upgrades: vm.Config.UpgradeConfig, + Context: vm.ctx, + Rewards: reward.NewCalculator(vm.Config.RewardConfig), + }) // Verify that validators are in the current validator set with the correct // reward calculated.