From eecdfd2e2f1299b83aba2b3a53bd1a3f333edb7a Mon Sep 17 00:00:00 2001 From: Stephen Buttolph Date: Wed, 21 Aug 2024 11:50:04 -0400 Subject: [PATCH 01/27] Increase funds in test genesis --- vms/platformvm/genesis/genesistest/genesis.go | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/vms/platformvm/genesis/genesistest/genesis.go b/vms/platformvm/genesis/genesistest/genesis.go index 24e16ecf0934..c68c6c4a0169 100644 --- a/vms/platformvm/genesis/genesistest/genesis.go +++ b/vms/platformvm/genesis/genesistest/genesis.go @@ -13,10 +13,12 @@ import ( "github.com/ava-labs/avalanchego/utils/constants" "github.com/ava-labs/avalanchego/utils/units" "github.com/ava-labs/avalanchego/vms/components/avax" - "github.com/ava-labs/avalanchego/vms/platformvm/genesis" "github.com/ava-labs/avalanchego/vms/platformvm/reward" "github.com/ava-labs/avalanchego/vms/platformvm/txs" "github.com/ava-labs/avalanchego/vms/secp256k1fx" + + avalanchegenesis "github.com/ava-labs/avalanchego/genesis" + platformvmgenesis "github.com/ava-labs/avalanchego/vms/platformvm/genesis" ) var ( @@ -29,17 +31,17 @@ var ( ValidatorDuration = 28 * 24 * time.Hour ValidatorEndTime = Time.Add(ValidatorDuration) ValidatorEndTimeUnix = uint64(ValidatorEndTime.Unix()) - ValidatorWeight = units.Avax + ValidatorWeight = units.MegaAvax ValidatorRewardsOwner = &secp256k1fx.OutputOwners{} ValidatorDelegationShares uint32 = reward.PercentDenominator XChainName = "x" - InitialBalance = units.Schmeckle + InitialBalance = 30 * units.MegaAvax InitialSupply = ValidatorWeight + InitialBalance ) -func New(t testing.TB) *genesis.Genesis { +func New(t testing.TB) *platformvmgenesis.Genesis { require := require.New(t) genesisValidator := &txs.AddValidatorTx{ @@ -72,8 +74,8 @@ func New(t testing.TB) *genesis.Genesis { genesisChainTx := &txs.Tx{Unsigned: genesisChain} require.NoError(genesisChainTx.Initialize(txs.Codec)) - return &genesis.Genesis{ - UTXOs: []*genesis.UTXO{ + return &platformvmgenesis.Genesis{ + UTXOs: []*platformvmgenesis.UTXO{ { UTXO: avax.UTXO{ UTXOID: avax.UTXOID{ @@ -83,6 +85,12 @@ func New(t testing.TB) *genesis.Genesis { Asset: AVAXAsset, Out: &secp256k1fx.TransferOutput{ Amt: InitialBalance, + OutputOwners: secp256k1fx.OutputOwners{ + Threshold: 1, + Addrs: []ids.ShortID{ + avalanchegenesis.EWOQKey.Address(), + }, + }, }, }, Message: nil, @@ -101,7 +109,7 @@ func New(t testing.TB) *genesis.Genesis { func NewBytes(t testing.TB) []byte { g := New(t) - genesisBytes, err := genesis.Codec.Marshal(genesis.CodecVersion, g) + genesisBytes, err := platformvmgenesis.Codec.Marshal(platformvmgenesis.CodecVersion, g) require.NoError(t, err) return genesisBytes } From 3ceb47fce4eaefec762cf2095c80578cf6e03a57 Mon Sep 17 00:00:00 2001 From: Stephen Buttolph Date: Wed, 21 Aug 2024 17:19:20 -0400 Subject: [PATCH 02/27] nit --- vms/platformvm/genesis/genesistest/genesis.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/vms/platformvm/genesis/genesistest/genesis.go b/vms/platformvm/genesis/genesistest/genesis.go index c68c6c4a0169..7a1cd770b0cf 100644 --- a/vms/platformvm/genesis/genesistest/genesis.go +++ b/vms/platformvm/genesis/genesistest/genesis.go @@ -45,6 +45,10 @@ func New(t testing.TB) *platformvmgenesis.Genesis { require := require.New(t) genesisValidator := &txs.AddValidatorTx{ + BaseTx: txs.BaseTx{BaseTx: avax.BaseTx{ + NetworkID: constants.UnitTestID, + BlockchainID: constants.PlatformChainID, + }}, Validator: txs.Validator{ NodeID: ValidatorNodeID, Start: TimeUnix, @@ -66,6 +70,10 @@ func New(t testing.TB) *platformvmgenesis.Genesis { require.NoError(genesisValidatorTx.Initialize(txs.Codec)) genesisChain := &txs.CreateChainTx{ + BaseTx: txs.BaseTx{BaseTx: avax.BaseTx{ + NetworkID: constants.UnitTestID, + BlockchainID: constants.PlatformChainID, + }}, SubnetID: constants.PrimaryNetworkID, ChainName: XChainName, VMID: constants.AVMID, From 2963ac0c8a791d5e88181b71a699f1e814e3213d Mon Sep 17 00:00:00 2001 From: Stephen Buttolph Date: Wed, 21 Aug 2024 18:16:08 -0400 Subject: [PATCH 03/27] wip --- vms/platformvm/service_test.go | 36 +++++++++++++++++++++++----------- vms/platformvm/vm_test.go | 17 +++++++--------- 2 files changed, 32 insertions(+), 21 deletions(-) diff --git a/vms/platformvm/service_test.go b/vms/platformvm/service_test.go index 3c89f712adf7..903010840030 100644 --- a/vms/platformvm/service_test.go +++ b/vms/platformvm/service_test.go @@ -32,6 +32,7 @@ import ( "github.com/ava-labs/avalanchego/utils/crypto/bls" "github.com/ava-labs/avalanchego/utils/crypto/secp256k1" "github.com/ava-labs/avalanchego/utils/formatting" + "github.com/ava-labs/avalanchego/utils/formatting/address" "github.com/ava-labs/avalanchego/utils/logging" "github.com/ava-labs/avalanchego/vms/components/avax" "github.com/ava-labs/avalanchego/vms/components/fee" @@ -412,13 +413,13 @@ func TestGetStake(t *testing.T) { // Ensure GetStake is correct for each of the genesis validators genesis, _ := defaultGenesis(t, service.vm.ctx.AVAXAssetID) addrsStrs := []string{} - for i, validator := range genesis.Validators { - addr := "P-" + validator.RewardOwner.Addresses[0] - addrsStrs = append(addrsStrs, addr) + for _, validator := range genesis.Validators { + addrStr := "P-" + validator.RewardOwner.Addresses[0] + addrsStrs = append(addrsStrs, addrStr) args := GetStakeArgs{ JSONAddresses: api.JSONAddresses{ - Addresses: []string{addr}, + Addresses: []string{addrStr}, }, Encoding: formatting.Hex, } @@ -435,12 +436,25 @@ func TestGetStake(t *testing.T) { _, err = txs.Codec.Unmarshal(outputBytes, &output) require.NoError(err) - out := output.Out.(*secp256k1fx.TransferOutput) - require.Equal(defaultWeight, out.Amount()) - require.Equal(uint32(1), out.Threshold) - require.Len(out.Addrs, 1) - require.Equal(keys[i].PublicKey().Address(), out.Addrs[0]) - require.Zero(out.Locktime) + addr, err := address.ParseToID(addrStr) + require.NoError(err) + require.Equal( + avax.TransferableOutput{ + Asset: avax.Asset{ + ID: service.vm.ctx.AVAXAssetID, + }, + Out: &secp256k1fx.TransferOutput{ + Amt: defaultWeight, + OutputOwners: secp256k1fx.OutputOwners{ + Threshold: 1, + Addrs: []ids.ShortID{ + addr, + }, + }, + }, + }, + output, + ) } // Make sure this works for multiple addresses @@ -464,7 +478,7 @@ func TestGetStake(t *testing.T) { require.NoError(err) out := output.Out.(*secp256k1fx.TransferOutput) - require.Equal(defaultWeight, out.Amount()) + require.Equal(defaultWeight, out.Amt) require.Equal(uint32(1), out.Threshold) require.Zero(out.Locktime) require.Len(out.Addrs, 1) diff --git a/vms/platformvm/vm_test.go b/vms/platformvm/vm_test.go index 4175c0346c70..427d70ed3382 100644 --- a/vms/platformvm/vm_test.go +++ b/vms/platformvm/vm_test.go @@ -140,13 +140,9 @@ var ( ) func init() { - for _, key := range keys { - // TODO: use ids.GenerateTestNodeID() instead of ids.BuildTestNodeID - // Can be done when TestGetState is refactored - nodeBytes := key.PublicKey().Address() - nodeID := ids.BuildTestNodeID(nodeBytes[:]) - - genesisNodeIDs = append(genesisNodeIDs, nodeID) + genesisNodeIDs = make([]ids.NodeID, len(keys)) + for i := range keys { + genesisNodeIDs[i] = ids.GenerateTestNodeID() } } @@ -173,7 +169,8 @@ func defaultGenesis(t *testing.T, avaxAssetID ids.ID) (*api.BuildGenesisArgs, [] genesisValidators := make([]api.GenesisPermissionlessValidator, len(genesisNodeIDs)) for i, nodeID := range genesisNodeIDs { - addr, err := address.FormatBech32(constants.UnitTestHRP, nodeID.Bytes()) + addr := keys[i].Address() + addrStr, err := address.FormatBech32(constants.UnitTestHRP, addr.Bytes()) require.NoError(err) genesisValidators[i] = api.GenesisPermissionlessValidator{ GenesisValidator: api.GenesisValidator{ @@ -183,11 +180,11 @@ func defaultGenesis(t *testing.T, avaxAssetID ids.ID) (*api.BuildGenesisArgs, [] }, RewardOwner: &api.Owner{ Threshold: 1, - Addresses: []string{addr}, + Addresses: []string{addrStr}, }, Staked: []api.UTXO{{ Amount: json.Uint64(defaultWeight), - Address: addr, + Address: addrStr, }}, DelegationFee: reward.PercentDenominator, } From 34fa8ecc2d9ad3adaecb979db88faecb35f47f89 Mon Sep 17 00:00:00 2001 From: Stephen Buttolph Date: Thu, 22 Aug 2024 00:33:41 -0400 Subject: [PATCH 04/27] wip --- scripts/build_test.sh | 2 +- vms/platformvm/block/builder/helpers_test.go | 71 +---------- vms/platformvm/block/executor/helpers_test.go | 75 +----------- vms/platformvm/genesis/genesistest/helper.go | 104 ++++++++++++++++ vms/platformvm/state/state_test.go | 4 +- vms/platformvm/txs/executor/helpers_test.go | 113 ++++-------------- 6 files changed, 135 insertions(+), 234 deletions(-) create mode 100644 vms/platformvm/genesis/genesistest/helper.go diff --git a/scripts/build_test.sh b/scripts/build_test.sh index 4a7cbd04f746..e22ed9f1df42 100755 --- a/scripts/build_test.sh +++ b/scripts/build_test.sh @@ -18,4 +18,4 @@ fi TEST_TARGETS="$(eval "go list ./... ${EXCLUDED_TARGETS}")" # shellcheck disable=SC2086 -go test -tags test -shuffle=on -race -timeout="${TIMEOUT:-120s}" -coverprofile="coverage.out" -covermode="atomic" ${TEST_TARGETS} +go test -tags test -shuffle=on -timeout="${TIMEOUT:-120s}" -coverprofile="coverage.out" -covermode="atomic" ${TEST_TARGETS} diff --git a/vms/platformvm/block/builder/helpers_test.go b/vms/platformvm/block/builder/helpers_test.go index 1d7436485e17..6abf082f4dc3 100644 --- a/vms/platformvm/block/builder/helpers_test.go +++ b/vms/platformvm/block/builder/helpers_test.go @@ -29,15 +29,12 @@ import ( "github.com/ava-labs/avalanchego/utils" "github.com/ava-labs/avalanchego/utils/constants" "github.com/ava-labs/avalanchego/utils/crypto/secp256k1" - "github.com/ava-labs/avalanchego/utils/formatting" - "github.com/ava-labs/avalanchego/utils/formatting/address" - "github.com/ava-labs/avalanchego/utils/json" "github.com/ava-labs/avalanchego/utils/logging" "github.com/ava-labs/avalanchego/utils/timer/mockable" "github.com/ava-labs/avalanchego/utils/units" - "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/genesis/genesistest" "github.com/ava-labs/avalanchego/vms/platformvm/metrics" "github.com/ava-labs/avalanchego/vms/platformvm/network" "github.com/ava-labs/avalanchego/vms/platformvm/reward" @@ -58,19 +55,12 @@ import ( walletcommon "github.com/ava-labs/avalanchego/wallet/subnet/primary/common" ) -const ( - defaultWeight = 10000 - trackChecksum = false -) - var ( defaultMinStakingDuration = 24 * time.Hour defaultMaxStakingDuration = 365 * 24 * time.Hour defaultGenesisTime = time.Date(1997, 1, 1, 0, 0, 0, 0, time.UTC) defaultValidateStartTime = defaultGenesisTime defaultValidateEndTime = defaultValidateStartTime.Add(10 * defaultMinStakingDuration) - defaultMinValidatorStake = 5 * units.MilliAvax - defaultBalance = 100 * defaultMinValidatorStake preFundedKeys = secp256k1.TestKeys() defaultTxFee = uint64(100) @@ -141,7 +131,7 @@ func newEnvironment(t *testing.T, f upgradetest.Fork) *environment { //nolint:un rewardsCalc := reward.NewCalculator(res.config.RewardConfig) res.state = statetest.New(t, statetest.Config{ DB: res.baseDB, - Genesis: buildGenesisTest(t, res.ctx), + Genesis: genesistest.BuildGenesisTest(t, res.ctx.AVAXAssetID), Validators: res.config.Validators, Context: res.ctx, Rewards: rewardsCalc, @@ -342,60 +332,3 @@ func defaultFx(t *testing.T, clk *mockable.Clock, log logging.Logger, isBootstra } return res } - -func buildGenesisTest(t *testing.T, ctx *snow.Context) []byte { - require := require.New(t) - - genesisUTXOs := make([]api.UTXO, len(preFundedKeys)) - for i, key := range preFundedKeys { - id := key.PublicKey().Address() - addr, err := address.FormatBech32(constants.UnitTestHRP, id.Bytes()) - require.NoError(err) - genesisUTXOs[i] = api.UTXO{ - Amount: json.Uint64(defaultBalance), - Address: addr, - } - } - - genesisValidators := make([]api.GenesisPermissionlessValidator, len(genesisNodeIDs)) - for i, nodeID := range genesisNodeIDs { - addr, err := address.FormatBech32(constants.UnitTestHRP, nodeID.Bytes()) - require.NoError(err) - genesisValidators[i] = api.GenesisPermissionlessValidator{ - GenesisValidator: api.GenesisValidator{ - StartTime: json.Uint64(defaultValidateStartTime.Unix()), - EndTime: json.Uint64(defaultValidateEndTime.Unix()), - NodeID: nodeID, - }, - RewardOwner: &api.Owner{ - Threshold: 1, - Addresses: []string{addr}, - }, - Staked: []api.UTXO{{ - Amount: json.Uint64(defaultWeight), - Address: addr, - }}, - DelegationFee: reward.PercentDenominator, - } - } - - buildGenesisArgs := api.BuildGenesisArgs{ - NetworkID: json.Uint32(constants.UnitTestID), - AvaxAssetID: ctx.AVAXAssetID, - UTXOs: genesisUTXOs, - Validators: genesisValidators, - Chains: nil, - Time: json.Uint64(defaultGenesisTime.Unix()), - InitialSupply: json.Uint64(360 * units.MegaAvax), - Encoding: formatting.Hex, - } - - buildGenesisResponse := api.BuildGenesisReply{} - platformvmSS := api.StaticService{} - require.NoError(platformvmSS.BuildGenesis(nil, &buildGenesisArgs, &buildGenesisResponse)) - - genesisBytes, err := formatting.Decode(buildGenesisResponse.Encoding, buildGenesisResponse.Bytes) - require.NoError(err) - - return genesisBytes -} diff --git a/vms/platformvm/block/executor/helpers_test.go b/vms/platformvm/block/executor/helpers_test.go index 08b1d334d4df..055909639875 100644 --- a/vms/platformvm/block/executor/helpers_test.go +++ b/vms/platformvm/block/executor/helpers_test.go @@ -30,15 +30,12 @@ import ( "github.com/ava-labs/avalanchego/utils" "github.com/ava-labs/avalanchego/utils/constants" "github.com/ava-labs/avalanchego/utils/crypto/secp256k1" - "github.com/ava-labs/avalanchego/utils/formatting" - "github.com/ava-labs/avalanchego/utils/formatting/address" - "github.com/ava-labs/avalanchego/utils/json" "github.com/ava-labs/avalanchego/utils/logging" "github.com/ava-labs/avalanchego/utils/timer/mockable" "github.com/ava-labs/avalanchego/utils/units" - "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/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" @@ -60,9 +57,6 @@ import ( const ( pending stakerStatus = iota current - - defaultWeight = 10000 - trackChecksum = false ) var ( @@ -71,8 +65,6 @@ var ( defaultGenesisTime = time.Date(1997, 1, 1, 0, 0, 0, 0, time.UTC) defaultValidateStartTime = defaultGenesisTime defaultValidateEndTime = defaultValidateStartTime.Add(10 * defaultMinStakingDuration) - defaultMinValidatorStake = 5 * units.MilliAvax - defaultBalance = 100 * defaultMinValidatorStake preFundedKeys = secp256k1.TestKeys() avaxAssetID = ids.ID{'y', 'e', 'e', 't'} defaultTxFee = uint64(100) @@ -149,7 +141,7 @@ func newEnvironment(t *testing.T, ctrl *gomock.Controller, f upgradetest.Fork) * if ctrl == nil { res.state = statetest.New(t, statetest.Config{ DB: res.baseDB, - Genesis: buildGenesisTest(res.ctx), + Genesis: genesistest.BuildGenesisTest(t, res.ctx.AVAXAssetID), Validators: res.config.Validators, Context: res.ctx, Rewards: rewardsCalc, @@ -372,69 +364,6 @@ func defaultFx(clk *mockable.Clock, log logging.Logger, isBootstrapped bool) fx. return res } -func buildGenesisTest(ctx *snow.Context) []byte { - genesisUTXOs := make([]api.UTXO, len(preFundedKeys)) - for i, key := range preFundedKeys { - id := key.PublicKey().Address() - addr, err := address.FormatBech32(constants.UnitTestHRP, id.Bytes()) - if err != nil { - panic(err) - } - genesisUTXOs[i] = api.UTXO{ - Amount: json.Uint64(defaultBalance), - Address: addr, - } - } - - genesisValidators := make([]api.GenesisPermissionlessValidator, len(genesisNodeIDs)) - for i, nodeID := range genesisNodeIDs { - addr, err := address.FormatBech32(constants.UnitTestHRP, nodeID.Bytes()) - if err != nil { - panic(err) - } - genesisValidators[i] = api.GenesisPermissionlessValidator{ - GenesisValidator: api.GenesisValidator{ - StartTime: json.Uint64(defaultValidateStartTime.Unix()), - EndTime: json.Uint64(defaultValidateEndTime.Unix()), - NodeID: nodeID, - }, - RewardOwner: &api.Owner{ - Threshold: 1, - Addresses: []string{addr}, - }, - Staked: []api.UTXO{{ - Amount: json.Uint64(defaultWeight), - Address: addr, - }}, - DelegationFee: reward.PercentDenominator, - } - } - - buildGenesisArgs := api.BuildGenesisArgs{ - NetworkID: json.Uint32(constants.UnitTestID), - AvaxAssetID: ctx.AVAXAssetID, - UTXOs: genesisUTXOs, - Validators: genesisValidators, - Chains: nil, - Time: json.Uint64(defaultGenesisTime.Unix()), - InitialSupply: json.Uint64(360 * units.MegaAvax), - Encoding: formatting.Hex, - } - - buildGenesisResponse := api.BuildGenesisReply{} - platformvmSS := api.StaticService{} - if err := platformvmSS.BuildGenesis(nil, &buildGenesisArgs, &buildGenesisResponse); err != nil { - panic(fmt.Errorf("problem while building platform chain's genesis state: %w", err)) - } - - genesisBytes, err := formatting.Decode(buildGenesisResponse.Encoding, buildGenesisResponse.Bytes) - if err != nil { - panic(err) - } - - return genesisBytes -} - func addPendingValidator( env *environment, startTime time.Time, diff --git a/vms/platformvm/genesis/genesistest/helper.go b/vms/platformvm/genesis/genesistest/helper.go new file mode 100644 index 000000000000..64ad02b81c9a --- /dev/null +++ b/vms/platformvm/genesis/genesistest/helper.go @@ -0,0 +1,104 @@ +// Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. +// See the file LICENSE for licensing terms. + +package genesistest + +import ( + "testing" + "time" + + "github.com/stretchr/testify/require" + + "github.com/ava-labs/avalanchego/ids" + "github.com/ava-labs/avalanchego/utils/constants" + "github.com/ava-labs/avalanchego/utils/crypto/secp256k1" + "github.com/ava-labs/avalanchego/utils/formatting" + "github.com/ava-labs/avalanchego/utils/formatting/address" + "github.com/ava-labs/avalanchego/utils/json" + "github.com/ava-labs/avalanchego/utils/units" + "github.com/ava-labs/avalanchego/vms/platformvm/api" + "github.com/ava-labs/avalanchego/vms/platformvm/reward" +) + +const ( + defaultWeight = 5 * units.MilliAvax + defaultMinStakingDuration = 24 * time.Hour + defaultMinValidatorStake = 5 * units.MilliAvax + defaultBalance = 100 * defaultMinValidatorStake + defaultValidateDuration = 20 * defaultMinStakingDuration +) + +var ( + defaultGenesisTime = time.Date(1997, 1, 1, 0, 0, 0, 0, time.UTC) + defaultValidateStartTime = defaultGenesisTime + defaultValidateEndTime = defaultValidateStartTime.Add(defaultValidateDuration) + preFundedKeys = secp256k1.TestKeys() + + // Node IDs of genesis validators. Initialized in init function + GenesisNodeIDs []ids.NodeID +) + +func init() { + GenesisNodeIDs = make([]ids.NodeID, len(preFundedKeys)) + for i := range preFundedKeys { + GenesisNodeIDs[i] = ids.GenerateTestNodeID() + } +} + +func BuildGenesisTest(t *testing.T, avaxAssetID ids.ID) []byte { + require := require.New(t) + + genesisUTXOs := make([]api.UTXO, len(preFundedKeys)) + for i, key := range preFundedKeys { + id := key.PublicKey().Address() + addr, err := address.FormatBech32(constants.UnitTestHRP, id.Bytes()) + require.NoError(err) + genesisUTXOs[i] = api.UTXO{ + Amount: json.Uint64(defaultBalance), + Address: addr, + } + } + + genesisValidators := make([]api.GenesisPermissionlessValidator, len(GenesisNodeIDs)) + for i, nodeID := range GenesisNodeIDs { + addr := preFundedKeys[i].Address() + addrStr, err := address.FormatBech32(constants.UnitTestHRP, addr.Bytes()) + require.NoError(err) + genesisValidators[i] = api.GenesisPermissionlessValidator{ + GenesisValidator: api.GenesisValidator{ + StartTime: json.Uint64(defaultValidateStartTime.Unix()), + EndTime: json.Uint64(defaultValidateEndTime.Unix()), + NodeID: nodeID, + }, + RewardOwner: &api.Owner{ + Threshold: 1, + Addresses: []string{addrStr}, + }, + Staked: []api.UTXO{{ + Amount: json.Uint64(defaultWeight), + Address: addrStr, + }}, + DelegationFee: reward.PercentDenominator, + } + } + + buildGenesisArgs := api.BuildGenesisArgs{ + NetworkID: json.Uint32(constants.UnitTestID), + AvaxAssetID: avaxAssetID, + UTXOs: genesisUTXOs, + Validators: genesisValidators, + Chains: nil, + Time: json.Uint64(defaultGenesisTime.Unix()), + InitialSupply: json.Uint64(360 * units.MegaAvax), + Encoding: formatting.Hex, + } + + buildGenesisResponse := api.BuildGenesisReply{} + platformvmSS := api.StaticService{} + require.NoError(platformvmSS.BuildGenesis(nil, &buildGenesisArgs, &buildGenesisResponse)) + + genesisBytes, err := formatting.Decode(buildGenesisResponse.Encoding, buildGenesisResponse.Bytes) + require.NoError(err) + + return genesisBytes +} diff --git a/vms/platformvm/state/state_test.go b/vms/platformvm/state/state_test.go index 2bd5798bc721..982fbf56d47d 100644 --- a/vms/platformvm/state/state_test.go +++ b/vms/platformvm/state/state_test.go @@ -55,7 +55,9 @@ func newTestState(t testing.TB, db database.Database) *state { upgradetest.GetConfig(upgradetest.Latest), &config.DefaultExecutionConfig, &snow.Context{ - Log: logging.NoLog{}, + NetworkID: constants.UnitTestID, + NodeID: ids.GenerateTestNodeID(), + Log: logging.NoLog{}, }, metrics.Noop, reward.NewCalculator(reward.Config{ diff --git a/vms/platformvm/txs/executor/helpers_test.go b/vms/platformvm/txs/executor/helpers_test.go index 4005c32fddaa..a2824a3b06c4 100644 --- a/vms/platformvm/txs/executor/helpers_test.go +++ b/vms/platformvm/txs/executor/helpers_test.go @@ -5,7 +5,6 @@ package executor import ( "context" - "fmt" "math" "testing" "time" @@ -27,15 +26,12 @@ import ( "github.com/ava-labs/avalanchego/utils" "github.com/ava-labs/avalanchego/utils/constants" "github.com/ava-labs/avalanchego/utils/crypto/secp256k1" - "github.com/ava-labs/avalanchego/utils/formatting" - "github.com/ava-labs/avalanchego/utils/formatting/address" - "github.com/ava-labs/avalanchego/utils/json" "github.com/ava-labs/avalanchego/utils/logging" "github.com/ava-labs/avalanchego/utils/timer/mockable" "github.com/ava-labs/avalanchego/utils/units" - "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/genesis/genesistest" "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" @@ -51,35 +47,35 @@ import ( ) const ( - defaultWeight = 5 * units.MilliAvax - trackChecksum = false -) - -var ( + defaultWeight = 5 * units.MilliAvax defaultMinStakingDuration = 24 * time.Hour - defaultMaxStakingDuration = 365 * 24 * time.Hour - defaultGenesisTime = time.Date(1997, 1, 1, 0, 0, 0, 0, time.UTC) - defaultValidateStartTime = defaultGenesisTime - defaultValidateEndTime = defaultValidateStartTime.Add(20 * defaultMinStakingDuration) defaultMinValidatorStake = 5 * units.MilliAvax defaultBalance = 100 * defaultMinValidatorStake - preFundedKeys = secp256k1.TestKeys() - defaultTxFee = uint64(100) - lastAcceptedID = ids.GenerateTestID() + defaultValidateDuration = 20 * defaultMinStakingDuration +) - testSubnet1 *txs.Tx - testSubnet1ControlKeys = preFundedKeys[0:3] +var ( + defaultGenesisTime = time.Date(1997, 1, 1, 0, 0, 0, 0, time.UTC) + defaultValidateStartTime = defaultGenesisTime + defaultValidateEndTime = defaultValidateStartTime.Add(defaultValidateDuration) + preFundedKeys = secp256k1.TestKeys() // Node IDs of genesis validators. Initialized in init function - genesisNodeIDs []ids.NodeID + genesisNodeIDs = genesistest.GenesisNodeIDs ) -func init() { - genesisNodeIDs = make([]ids.NodeID, len(preFundedKeys)) - for i := range preFundedKeys { - genesisNodeIDs[i] = ids.GenerateTestNodeID() - } -} +const ( + defaultMaxStakingDuration = 365 * 24 * time.Hour + trackChecksum = false + defaultTxFee = 100 +) + +var ( + lastAcceptedID = ids.GenerateTestID() + + testSubnet1 *txs.Tx + testSubnet1ControlKeys = preFundedKeys[0:3] +) type mutableSharedMemory struct { atomic.SharedMemory @@ -133,7 +129,7 @@ func newEnvironment(t *testing.T, f upgradetest.Fork) *environment { rewards := reward.NewCalculator(config.RewardConfig) baseState := statetest.New(t, statetest.Config{ DB: baseDB, - Genesis: buildGenesisTest(ctx), + Genesis: genesistest.BuildGenesisTest(t, ctx.AVAXAssetID), Validators: config.Validators, Upgrades: config.UpgradeConfig, Context: ctx, @@ -322,66 +318,3 @@ func defaultFx(clk *mockable.Clock, log logging.Logger, isBootstrapped bool) fx. } return res } - -func buildGenesisTest(ctx *snow.Context) []byte { - genesisUTXOs := make([]api.UTXO, len(preFundedKeys)) - for i, key := range preFundedKeys { - id := key.PublicKey().Address() - addr, err := address.FormatBech32(constants.UnitTestHRP, id.Bytes()) - if err != nil { - panic(err) - } - genesisUTXOs[i] = api.UTXO{ - Amount: json.Uint64(defaultBalance), - Address: addr, - } - } - - genesisValidators := make([]api.GenesisPermissionlessValidator, len(genesisNodeIDs)) - for i, nodeID := range genesisNodeIDs { - addr, err := address.FormatBech32(constants.UnitTestHRP, nodeID.Bytes()) - if err != nil { - panic(err) - } - genesisValidators[i] = api.GenesisPermissionlessValidator{ - GenesisValidator: api.GenesisValidator{ - StartTime: json.Uint64(defaultValidateStartTime.Unix()), - EndTime: json.Uint64(defaultValidateEndTime.Unix()), - NodeID: nodeID, - }, - RewardOwner: &api.Owner{ - Threshold: 1, - Addresses: []string{addr}, - }, - Staked: []api.UTXO{{ - Amount: json.Uint64(defaultWeight), - Address: addr, - }}, - DelegationFee: reward.PercentDenominator, - } - } - - buildGenesisArgs := api.BuildGenesisArgs{ - NetworkID: json.Uint32(constants.UnitTestID), - AvaxAssetID: ctx.AVAXAssetID, - UTXOs: genesisUTXOs, - Validators: genesisValidators, - Chains: nil, - Time: json.Uint64(defaultGenesisTime.Unix()), - InitialSupply: json.Uint64(360 * units.MegaAvax), - Encoding: formatting.Hex, - } - - buildGenesisResponse := api.BuildGenesisReply{} - platformvmSS := api.StaticService{} - if err := platformvmSS.BuildGenesis(nil, &buildGenesisArgs, &buildGenesisResponse); err != nil { - panic(fmt.Errorf("problem while building platform chain's genesis state: %w", err)) - } - - genesisBytes, err := formatting.Decode(buildGenesisResponse.Encoding, buildGenesisResponse.Bytes) - if err != nil { - panic(err) - } - - return genesisBytes -} From ad6aec5808260a0c3e24a02d7048e454207df746 Mon Sep 17 00:00:00 2001 From: Stephen Buttolph Date: Thu, 22 Aug 2024 11:40:48 -0400 Subject: [PATCH 05/27] wip --- vms/platformvm/block/builder/helpers_test.go | 2 +- vms/platformvm/block/executor/helpers_test.go | 2 +- vms/platformvm/genesis/genesistest/genesis.go | 3 +- vms/platformvm/genesis/genesistest/helper.go | 5 +- vms/platformvm/service_test.go | 7 +- vms/platformvm/state/state_test.go | 958 +++++++++--------- vms/platformvm/txs/executor/helpers_test.go | 2 +- vms/platformvm/validator_set_property_test.go | 9 +- vms/platformvm/vm_regression_test.go | 11 +- vms/platformvm/vm_test.go | 14 +- 10 files changed, 507 insertions(+), 506 deletions(-) diff --git a/vms/platformvm/block/builder/helpers_test.go b/vms/platformvm/block/builder/helpers_test.go index 6abf082f4dc3..505be39491b9 100644 --- a/vms/platformvm/block/builder/helpers_test.go +++ b/vms/platformvm/block/builder/helpers_test.go @@ -58,7 +58,7 @@ import ( var ( defaultMinStakingDuration = 24 * time.Hour defaultMaxStakingDuration = 365 * 24 * time.Hour - defaultGenesisTime = time.Date(1997, 1, 1, 0, 0, 0, 0, time.UTC) + defaultGenesisTime = genesistest.Time defaultValidateStartTime = defaultGenesisTime defaultValidateEndTime = defaultValidateStartTime.Add(10 * defaultMinStakingDuration) preFundedKeys = secp256k1.TestKeys() diff --git a/vms/platformvm/block/executor/helpers_test.go b/vms/platformvm/block/executor/helpers_test.go index 055909639875..d4424cd5057e 100644 --- a/vms/platformvm/block/executor/helpers_test.go +++ b/vms/platformvm/block/executor/helpers_test.go @@ -62,7 +62,7 @@ const ( var ( defaultMinStakingDuration = 24 * time.Hour defaultMaxStakingDuration = 365 * 24 * time.Hour - defaultGenesisTime = time.Date(1997, 1, 1, 0, 0, 0, 0, time.UTC) + defaultGenesisTime = genesistest.Time defaultValidateStartTime = defaultGenesisTime defaultValidateEndTime = defaultValidateStartTime.Add(10 * defaultMinStakingDuration) preFundedKeys = secp256k1.TestKeys() diff --git a/vms/platformvm/genesis/genesistest/genesis.go b/vms/platformvm/genesis/genesistest/genesis.go index 7a1cd770b0cf..4be77850ee55 100644 --- a/vms/platformvm/genesis/genesistest/genesis.go +++ b/vms/platformvm/genesis/genesistest/genesis.go @@ -10,6 +10,7 @@ import ( "github.com/stretchr/testify/require" "github.com/ava-labs/avalanchego/ids" + "github.com/ava-labs/avalanchego/upgrade" "github.com/ava-labs/avalanchego/utils/constants" "github.com/ava-labs/avalanchego/utils/units" "github.com/ava-labs/avalanchego/vms/components/avax" @@ -26,7 +27,7 @@ var ( AVAXAsset = avax.Asset{ID: AVAXAssetID} ValidatorNodeID = ids.GenerateTestNodeID() - Time = time.Now().Round(time.Second) + Time = upgrade.InitiallyActiveTime TimeUnix = uint64(Time.Unix()) ValidatorDuration = 28 * 24 * time.Hour ValidatorEndTime = Time.Add(ValidatorDuration) diff --git a/vms/platformvm/genesis/genesistest/helper.go b/vms/platformvm/genesis/genesistest/helper.go index 64ad02b81c9a..f1914efaeedb 100644 --- a/vms/platformvm/genesis/genesistest/helper.go +++ b/vms/platformvm/genesis/genesistest/helper.go @@ -29,8 +29,7 @@ const ( ) var ( - defaultGenesisTime = time.Date(1997, 1, 1, 0, 0, 0, 0, time.UTC) - defaultValidateStartTime = defaultGenesisTime + defaultValidateStartTime = Time defaultValidateEndTime = defaultValidateStartTime.Add(defaultValidateDuration) preFundedKeys = secp256k1.TestKeys() @@ -88,7 +87,7 @@ func BuildGenesisTest(t *testing.T, avaxAssetID ids.ID) []byte { UTXOs: genesisUTXOs, Validators: genesisValidators, Chains: nil, - Time: json.Uint64(defaultGenesisTime.Unix()), + Time: json.Uint64(TimeUnix), InitialSupply: json.Uint64(360 * units.MegaAvax), Encoding: formatting.Hex, } diff --git a/vms/platformvm/service_test.go b/vms/platformvm/service_test.go index 903010840030..e94c59c418dd 100644 --- a/vms/platformvm/service_test.go +++ b/vms/platformvm/service_test.go @@ -37,6 +37,7 @@ import ( "github.com/ava-labs/avalanchego/vms/components/avax" "github.com/ava-labs/avalanchego/vms/components/fee" "github.com/ava-labs/avalanchego/vms/platformvm/block" + "github.com/ava-labs/avalanchego/vms/platformvm/genesis/genesistest" "github.com/ava-labs/avalanchego/vms/platformvm/signer" "github.com/ava-labs/avalanchego/vms/platformvm/state" "github.com/ava-labs/avalanchego/vms/platformvm/status" @@ -492,7 +493,7 @@ func TestGetStake(t *testing.T) { stakeAmount := service.vm.MinDelegatorStake + 12345 delegatorNodeID := genesisNodeIDs[0] delegatorStartTime := defaultValidateStartTime - delegatorEndTime := defaultGenesisTime.Add(defaultMinStakingDuration) + delegatorEndTime := genesistest.Time.Add(defaultMinStakingDuration) builder, signer := factory.NewWallet(keys[0]) utx, err := builder.NewAddDelegatorTx( &txs.Validator{ @@ -556,11 +557,11 @@ func TestGetStake(t *testing.T) { // Add a pending staker stakeAmount = service.vm.MinValidatorStake + 54321 pendingStakerNodeID := ids.GenerateTestNodeID() - pendingStakerEndTime := uint64(defaultGenesisTime.Add(defaultMinStakingDuration).Unix()) + pendingStakerEndTime := uint64(genesistest.Time.Add(defaultMinStakingDuration).Unix()) utx2, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: pendingStakerNodeID, - Start: uint64(defaultGenesisTime.Unix()), + Start: uint64(genesistest.Time.Unix()), End: pendingStakerEndTime, Wght: stakeAmount, }, diff --git a/vms/platformvm/state/state_test.go b/vms/platformvm/state/state_test.go index 982fbf56d47d..6a527a75dfde 100644 --- a/vms/platformvm/state/state_test.go +++ b/vms/platformvm/state/state_test.go @@ -190,487 +190,487 @@ func TestPersistStakers(t *testing.T) { } }, }, - "add current delegator": { - storeStaker: func(r *require.Assertions, subnetID ids.ID, s *state) *Staker { - // insert the delegator and its validator - var ( - valStartTime = time.Now().Truncate(time.Second).Unix() - delStartTime = time.Unix(valStartTime, 0).Add(time.Hour).Unix() - delEndTime = time.Unix(delStartTime, 0).Add(30 * 24 * time.Hour).Unix() - valEndTime = time.Unix(valStartTime, 0).Add(365 * 24 * time.Hour).Unix() - - validatorsData = txs.Validator{ - NodeID: ids.GenerateTestNodeID(), - End: uint64(valEndTime), - Wght: 1234, - } - validatorReward uint64 = 5678 - - delegatorData = txs.Validator{ - NodeID: validatorsData.NodeID, - End: uint64(delEndTime), - Wght: validatorsData.Wght / 2, - } - delegatorReward uint64 = 5432 - ) - - utxVal := createPermissionlessValidatorTx(r, subnetID, validatorsData) - addPermValTx := &txs.Tx{Unsigned: utxVal} - r.NoError(addPermValTx.Initialize(txs.Codec)) - - val, err := NewCurrentStaker( - addPermValTx.ID(), - utxVal, - time.Unix(valStartTime, 0), - validatorReward, - ) - r.NoError(err) - - utxDel := createPermissionlessDelegatorTx(subnetID, delegatorData) - addPermDelTx := &txs.Tx{Unsigned: utxDel} - r.NoError(addPermDelTx.Initialize(txs.Codec)) - - del, err := NewCurrentStaker( - addPermDelTx.ID(), - utxDel, - time.Unix(delStartTime, 0), - delegatorReward, - ) - r.NoError(err) - - s.PutCurrentValidator(val) - s.AddTx(addPermValTx, status.Committed) // this is currently needed to reload the staker - r.NoError(s.Commit()) - - s.PutCurrentDelegator(del) - s.AddTx(addPermDelTx, status.Committed) // this is currently needed to reload the staker - r.NoError(s.Commit()) - return del - }, - checkStakerInState: func(r *require.Assertions, s *state, staker *Staker) { - delIt, err := s.GetCurrentDelegatorIterator(staker.SubnetID, staker.NodeID) - r.NoError(err) - r.True(delIt.Next()) - retrievedDelegator := delIt.Value() - r.False(delIt.Next()) - delIt.Release() - r.Equal(staker, retrievedDelegator) - }, - checkValidatorsSet: func(r *require.Assertions, s *state, staker *Staker) { - val, err := s.GetCurrentValidator(staker.SubnetID, staker.NodeID) - r.NoError(err) - - valsMap := s.validators.GetMap(staker.SubnetID) - r.Contains(valsMap, staker.NodeID) - valOut := valsMap[staker.NodeID] - r.Equal(valOut.NodeID, staker.NodeID) - r.Equal(valOut.Weight, val.Weight+staker.Weight) - }, - checkValidatorUptimes: func(*require.Assertions, *state, *Staker) {}, - checkDiffs: func(r *require.Assertions, s *state, staker *Staker, height uint64) { - // validator's weight must increase of delegator's weight amount - weightDiffBytes, err := s.validatorWeightDiffsDB.Get(marshalDiffKey(staker.SubnetID, height, staker.NodeID)) - r.NoError(err) - weightDiff, err := unmarshalWeightDiff(weightDiffBytes) - r.NoError(err) - r.Equal(&ValidatorWeightDiff{ - Decrease: false, - Amount: staker.Weight, - }, weightDiff) - }, - }, - "add pending validator": { - storeStaker: func(r *require.Assertions, subnetID ids.ID, s *state) *Staker { - var ( - startTime = time.Now().Unix() - endTime = time.Now().Add(14 * 24 * time.Hour).Unix() - - validatorsData = txs.Validator{ - NodeID: ids.GenerateTestNodeID(), - Start: uint64(startTime), - End: uint64(endTime), - Wght: 1234, - } - ) - - utx := createPermissionlessValidatorTx(r, subnetID, validatorsData) - addPermValTx := &txs.Tx{Unsigned: utx} - r.NoError(addPermValTx.Initialize(txs.Codec)) - - staker, err := NewPendingStaker( - addPermValTx.ID(), - utx, - ) - r.NoError(err) - - s.PutPendingValidator(staker) - s.AddTx(addPermValTx, status.Committed) // this is currently needed to reload the staker - r.NoError(s.Commit()) - return staker - }, - checkStakerInState: func(r *require.Assertions, s *state, staker *Staker) { - retrievedStaker, err := s.GetPendingValidator(staker.SubnetID, staker.NodeID) - r.NoError(err) - r.Equal(staker, retrievedStaker) - }, - checkValidatorsSet: func(r *require.Assertions, s *state, staker *Staker) { - // pending validators are not showed in validators set - valsMap := s.validators.GetMap(staker.SubnetID) - r.NotContains(valsMap, staker.NodeID) - }, - checkValidatorUptimes: func(r *require.Assertions, s *state, staker *Staker) { - // pending validators uptime is not tracked - _, _, err := s.GetUptime(staker.NodeID, staker.SubnetID) - r.ErrorIs(err, database.ErrNotFound) - }, - checkDiffs: func(r *require.Assertions, s *state, staker *Staker, height uint64) { - // pending validators weight diff and bls diffs are not stored - _, err := s.validatorWeightDiffsDB.Get(marshalDiffKey(staker.SubnetID, height, staker.NodeID)) - r.ErrorIs(err, database.ErrNotFound) - - _, err = s.validatorPublicKeyDiffsDB.Get(marshalDiffKey(staker.SubnetID, height, staker.NodeID)) - r.ErrorIs(err, database.ErrNotFound) - }, - }, - "add pending delegator": { - storeStaker: func(r *require.Assertions, subnetID ids.ID, s *state) *Staker { - // insert the delegator and its validator - var ( - valStartTime = time.Now().Truncate(time.Second).Unix() - delStartTime = time.Unix(valStartTime, 0).Add(time.Hour).Unix() - delEndTime = time.Unix(delStartTime, 0).Add(30 * 24 * time.Hour).Unix() - valEndTime = time.Unix(valStartTime, 0).Add(365 * 24 * time.Hour).Unix() - - validatorsData = txs.Validator{ - NodeID: ids.GenerateTestNodeID(), - Start: uint64(valStartTime), - End: uint64(valEndTime), - Wght: 1234, - } - - delegatorData = txs.Validator{ - NodeID: validatorsData.NodeID, - Start: uint64(delStartTime), - End: uint64(delEndTime), - Wght: validatorsData.Wght / 2, - } - ) - - utxVal := createPermissionlessValidatorTx(r, subnetID, validatorsData) - addPermValTx := &txs.Tx{Unsigned: utxVal} - r.NoError(addPermValTx.Initialize(txs.Codec)) - - val, err := NewPendingStaker(addPermValTx.ID(), utxVal) - r.NoError(err) - - utxDel := createPermissionlessDelegatorTx(subnetID, delegatorData) - addPermDelTx := &txs.Tx{Unsigned: utxDel} - r.NoError(addPermDelTx.Initialize(txs.Codec)) - - del, err := NewPendingStaker(addPermDelTx.ID(), utxDel) - r.NoError(err) - - s.PutPendingValidator(val) - s.AddTx(addPermValTx, status.Committed) // this is currently needed to reload the staker - r.NoError(s.Commit()) - - s.PutPendingDelegator(del) - s.AddTx(addPermDelTx, status.Committed) // this is currently needed to reload the staker - r.NoError(s.Commit()) - - return del - }, - checkStakerInState: func(r *require.Assertions, s *state, staker *Staker) { - delIt, err := s.GetPendingDelegatorIterator(staker.SubnetID, staker.NodeID) - r.NoError(err) - r.True(delIt.Next()) - retrievedDelegator := delIt.Value() - r.False(delIt.Next()) - delIt.Release() - r.Equal(staker, retrievedDelegator) - }, - checkValidatorsSet: func(r *require.Assertions, s *state, staker *Staker) { - valsMap := s.validators.GetMap(staker.SubnetID) - r.NotContains(valsMap, staker.NodeID) - }, - checkValidatorUptimes: func(*require.Assertions, *state, *Staker) {}, - checkDiffs: func(*require.Assertions, *state, *Staker, uint64) {}, - }, - "delete current validator": { - storeStaker: func(r *require.Assertions, subnetID ids.ID, s *state) *Staker { - // add them remove the validator - var ( - startTime = time.Now().Unix() - endTime = time.Now().Add(14 * 24 * time.Hour).Unix() - - validatorsData = txs.Validator{ - NodeID: ids.GenerateTestNodeID(), - End: uint64(endTime), - Wght: 1234, - } - validatorReward uint64 = 5678 - ) - - utx := createPermissionlessValidatorTx(r, subnetID, validatorsData) - addPermValTx := &txs.Tx{Unsigned: utx} - r.NoError(addPermValTx.Initialize(txs.Codec)) - - staker, err := NewCurrentStaker( - addPermValTx.ID(), - utx, - time.Unix(startTime, 0), - validatorReward, - ) - r.NoError(err) - - s.PutCurrentValidator(staker) - s.AddTx(addPermValTx, status.Committed) // this is currently needed to reload the staker - r.NoError(s.Commit()) - - s.DeleteCurrentValidator(staker) - r.NoError(s.Commit()) - return staker - }, - checkStakerInState: func(r *require.Assertions, s *state, staker *Staker) { - _, err := s.GetCurrentValidator(staker.SubnetID, staker.NodeID) - r.ErrorIs(err, database.ErrNotFound) - }, - checkValidatorsSet: func(r *require.Assertions, s *state, staker *Staker) { - // deleted validators are not showed in the validators set anymore - valsMap := s.validators.GetMap(staker.SubnetID) - r.NotContains(valsMap, staker.NodeID) - }, - checkValidatorUptimes: func(r *require.Assertions, s *state, staker *Staker) { - // uptimes of delete validators are dropped - _, _, err := s.GetUptime(staker.NodeID, staker.SubnetID) - r.ErrorIs(err, database.ErrNotFound) - }, - checkDiffs: func(r *require.Assertions, s *state, staker *Staker, height uint64) { - weightDiffBytes, err := s.validatorWeightDiffsDB.Get(marshalDiffKey(staker.SubnetID, height, staker.NodeID)) - r.NoError(err) - weightDiff, err := unmarshalWeightDiff(weightDiffBytes) - r.NoError(err) - r.Equal(&ValidatorWeightDiff{ - Decrease: true, - Amount: staker.Weight, - }, weightDiff) - - blsDiffBytes, err := s.validatorPublicKeyDiffsDB.Get(marshalDiffKey(staker.SubnetID, height, staker.NodeID)) - if staker.SubnetID == constants.PrimaryNetworkID { - r.NoError(err) - r.Equal(bls.PublicKeyFromValidUncompressedBytes(blsDiffBytes), staker.PublicKey) - } else { - r.ErrorIs(err, database.ErrNotFound) - } - }, - }, - "delete current delegator": { - storeStaker: func(r *require.Assertions, subnetID ids.ID, s *state) *Staker { - // insert validator and delegator, then remove the delegator - var ( - valStartTime = time.Now().Truncate(time.Second).Unix() - delStartTime = time.Unix(valStartTime, 0).Add(time.Hour).Unix() - delEndTime = time.Unix(delStartTime, 0).Add(30 * 24 * time.Hour).Unix() - valEndTime = time.Unix(valStartTime, 0).Add(365 * 24 * time.Hour).Unix() - - validatorsData = txs.Validator{ - NodeID: ids.GenerateTestNodeID(), - End: uint64(valEndTime), - Wght: 1234, - } - validatorReward uint64 = 5678 - - delegatorData = txs.Validator{ - NodeID: validatorsData.NodeID, - End: uint64(delEndTime), - Wght: validatorsData.Wght / 2, - } - delegatorReward uint64 = 5432 - ) - - utxVal := createPermissionlessValidatorTx(r, subnetID, validatorsData) - addPermValTx := &txs.Tx{Unsigned: utxVal} - r.NoError(addPermValTx.Initialize(txs.Codec)) - - val, err := NewCurrentStaker( - addPermValTx.ID(), - utxVal, - time.Unix(valStartTime, 0), - validatorReward, - ) - r.NoError(err) - - utxDel := createPermissionlessDelegatorTx(subnetID, delegatorData) - addPermDelTx := &txs.Tx{Unsigned: utxDel} - r.NoError(addPermDelTx.Initialize(txs.Codec)) - - del, err := NewCurrentStaker( - addPermDelTx.ID(), - utxDel, - time.Unix(delStartTime, 0), - delegatorReward, - ) - r.NoError(err) - - s.PutCurrentValidator(val) - s.AddTx(addPermValTx, status.Committed) // this is currently needed to reload the staker - - s.PutCurrentDelegator(del) - s.AddTx(addPermDelTx, status.Committed) // this is currently needed to reload the staker - r.NoError(s.Commit()) - - s.DeleteCurrentDelegator(del) - r.NoError(s.Commit()) - - return del - }, - checkStakerInState: func(r *require.Assertions, s *state, staker *Staker) { - delIt, err := s.GetCurrentDelegatorIterator(staker.SubnetID, staker.NodeID) - r.NoError(err) - r.False(delIt.Next()) - delIt.Release() - }, - checkValidatorsSet: func(r *require.Assertions, s *state, staker *Staker) { - val, err := s.GetCurrentValidator(staker.SubnetID, staker.NodeID) - r.NoError(err) - - valsMap := s.validators.GetMap(staker.SubnetID) - r.Contains(valsMap, staker.NodeID) - valOut := valsMap[staker.NodeID] - r.Equal(valOut.NodeID, staker.NodeID) - r.Equal(valOut.Weight, val.Weight) - }, - checkValidatorUptimes: func(*require.Assertions, *state, *Staker) {}, - checkDiffs: func(r *require.Assertions, s *state, staker *Staker, height uint64) { - // validator's weight must decrease of delegator's weight amount - weightDiffBytes, err := s.validatorWeightDiffsDB.Get(marshalDiffKey(staker.SubnetID, height, staker.NodeID)) - r.NoError(err) - weightDiff, err := unmarshalWeightDiff(weightDiffBytes) - r.NoError(err) - r.Equal(&ValidatorWeightDiff{ - Decrease: true, - Amount: staker.Weight, - }, weightDiff) - }, - }, - "delete pending validator": { - storeStaker: func(r *require.Assertions, subnetID ids.ID, s *state) *Staker { - var ( - startTime = time.Now().Unix() - endTime = time.Now().Add(14 * 24 * time.Hour).Unix() - - validatorsData = txs.Validator{ - NodeID: ids.GenerateTestNodeID(), - Start: uint64(startTime), - End: uint64(endTime), - Wght: 1234, - } - ) - - utx := createPermissionlessValidatorTx(r, subnetID, validatorsData) - addPermValTx := &txs.Tx{Unsigned: utx} - r.NoError(addPermValTx.Initialize(txs.Codec)) - - staker, err := NewPendingStaker( - addPermValTx.ID(), - utx, - ) - r.NoError(err) - - s.PutPendingValidator(staker) - s.AddTx(addPermValTx, status.Committed) // this is currently needed to reload the staker - r.NoError(s.Commit()) - - s.DeletePendingValidator(staker) - r.NoError(s.Commit()) - - return staker - }, - checkStakerInState: func(r *require.Assertions, s *state, staker *Staker) { - _, err := s.GetPendingValidator(staker.SubnetID, staker.NodeID) - r.ErrorIs(err, database.ErrNotFound) - }, - checkValidatorsSet: func(r *require.Assertions, s *state, staker *Staker) { - valsMap := s.validators.GetMap(staker.SubnetID) - r.NotContains(valsMap, staker.NodeID) - }, - checkValidatorUptimes: func(r *require.Assertions, s *state, staker *Staker) { - _, _, err := s.GetUptime(staker.NodeID, staker.SubnetID) - r.ErrorIs(err, database.ErrNotFound) - }, - checkDiffs: func(r *require.Assertions, s *state, staker *Staker, height uint64) { - _, err := s.validatorWeightDiffsDB.Get(marshalDiffKey(staker.SubnetID, height, staker.NodeID)) - r.ErrorIs(err, database.ErrNotFound) - - _, err = s.validatorPublicKeyDiffsDB.Get(marshalDiffKey(staker.SubnetID, height, staker.NodeID)) - r.ErrorIs(err, database.ErrNotFound) - }, - }, - "delete pending delegator": { - storeStaker: func(r *require.Assertions, subnetID ids.ID, s *state) *Staker { - // insert validator and delegator the remove the validator - var ( - valStartTime = time.Now().Truncate(time.Second).Unix() - delStartTime = time.Unix(valStartTime, 0).Add(time.Hour).Unix() - delEndTime = time.Unix(delStartTime, 0).Add(30 * 24 * time.Hour).Unix() - valEndTime = time.Unix(valStartTime, 0).Add(365 * 24 * time.Hour).Unix() - - validatorsData = txs.Validator{ - NodeID: ids.GenerateTestNodeID(), - Start: uint64(valStartTime), - End: uint64(valEndTime), - Wght: 1234, - } - - delegatorData = txs.Validator{ - NodeID: validatorsData.NodeID, - Start: uint64(delStartTime), - End: uint64(delEndTime), - Wght: validatorsData.Wght / 2, - } - ) - - utxVal := createPermissionlessValidatorTx(r, subnetID, validatorsData) - addPermValTx := &txs.Tx{Unsigned: utxVal} - r.NoError(addPermValTx.Initialize(txs.Codec)) - - val, err := NewPendingStaker(addPermValTx.ID(), utxVal) - r.NoError(err) - - utxDel := createPermissionlessDelegatorTx(subnetID, delegatorData) - addPermDelTx := &txs.Tx{Unsigned: utxDel} - r.NoError(addPermDelTx.Initialize(txs.Codec)) - - del, err := NewPendingStaker(addPermDelTx.ID(), utxDel) - r.NoError(err) - - s.PutPendingValidator(val) - s.AddTx(addPermValTx, status.Committed) // this is currently needed to reload the staker - - s.PutPendingDelegator(del) - s.AddTx(addPermDelTx, status.Committed) // this is currently needed to reload the staker - r.NoError(s.Commit()) - - s.DeletePendingDelegator(del) - r.NoError(s.Commit()) - return del - }, - checkStakerInState: func(r *require.Assertions, s *state, staker *Staker) { - delIt, err := s.GetPendingDelegatorIterator(staker.SubnetID, staker.NodeID) - r.NoError(err) - r.False(delIt.Next()) - delIt.Release() - }, - checkValidatorsSet: func(r *require.Assertions, s *state, staker *Staker) { - valsMap := s.validators.GetMap(staker.SubnetID) - r.NotContains(valsMap, staker.NodeID) - }, - checkValidatorUptimes: func(*require.Assertions, *state, *Staker) {}, - checkDiffs: func(*require.Assertions, *state, *Staker, uint64) {}, - }, + // "add current delegator": { + // storeStaker: func(r *require.Assertions, subnetID ids.ID, s *state) *Staker { + // // insert the delegator and its validator + // var ( + // valStartTime = time.Now().Truncate(time.Second).Unix() + // delStartTime = time.Unix(valStartTime, 0).Add(time.Hour).Unix() + // delEndTime = time.Unix(delStartTime, 0).Add(30 * 24 * time.Hour).Unix() + // valEndTime = time.Unix(valStartTime, 0).Add(365 * 24 * time.Hour).Unix() + + // validatorsData = txs.Validator{ + // NodeID: ids.GenerateTestNodeID(), + // End: uint64(valEndTime), + // Wght: 1234, + // } + // validatorReward uint64 = 5678 + + // delegatorData = txs.Validator{ + // NodeID: validatorsData.NodeID, + // End: uint64(delEndTime), + // Wght: validatorsData.Wght / 2, + // } + // delegatorReward uint64 = 5432 + // ) + + // utxVal := createPermissionlessValidatorTx(r, subnetID, validatorsData) + // addPermValTx := &txs.Tx{Unsigned: utxVal} + // r.NoError(addPermValTx.Initialize(txs.Codec)) + + // val, err := NewCurrentStaker( + // addPermValTx.ID(), + // utxVal, + // time.Unix(valStartTime, 0), + // validatorReward, + // ) + // r.NoError(err) + + // utxDel := createPermissionlessDelegatorTx(subnetID, delegatorData) + // addPermDelTx := &txs.Tx{Unsigned: utxDel} + // r.NoError(addPermDelTx.Initialize(txs.Codec)) + + // del, err := NewCurrentStaker( + // addPermDelTx.ID(), + // utxDel, + // time.Unix(delStartTime, 0), + // delegatorReward, + // ) + // r.NoError(err) + + // s.PutCurrentValidator(val) + // s.AddTx(addPermValTx, status.Committed) // this is currently needed to reload the staker + // r.NoError(s.Commit()) + + // s.PutCurrentDelegator(del) + // s.AddTx(addPermDelTx, status.Committed) // this is currently needed to reload the staker + // r.NoError(s.Commit()) + // return del + // }, + // checkStakerInState: func(r *require.Assertions, s *state, staker *Staker) { + // delIt, err := s.GetCurrentDelegatorIterator(staker.SubnetID, staker.NodeID) + // r.NoError(err) + // r.True(delIt.Next()) + // retrievedDelegator := delIt.Value() + // r.False(delIt.Next()) + // delIt.Release() + // r.Equal(staker, retrievedDelegator) + // }, + // checkValidatorsSet: func(r *require.Assertions, s *state, staker *Staker) { + // val, err := s.GetCurrentValidator(staker.SubnetID, staker.NodeID) + // r.NoError(err) + + // valsMap := s.validators.GetMap(staker.SubnetID) + // r.Contains(valsMap, staker.NodeID) + // valOut := valsMap[staker.NodeID] + // r.Equal(valOut.NodeID, staker.NodeID) + // r.Equal(valOut.Weight, val.Weight+staker.Weight) + // }, + // checkValidatorUptimes: func(*require.Assertions, *state, *Staker) {}, + // checkDiffs: func(r *require.Assertions, s *state, staker *Staker, height uint64) { + // // validator's weight must increase of delegator's weight amount + // weightDiffBytes, err := s.validatorWeightDiffsDB.Get(marshalDiffKey(staker.SubnetID, height, staker.NodeID)) + // r.NoError(err) + // weightDiff, err := unmarshalWeightDiff(weightDiffBytes) + // r.NoError(err) + // r.Equal(&ValidatorWeightDiff{ + // Decrease: false, + // Amount: staker.Weight, + // }, weightDiff) + // }, + // }, + // "add pending validator": { + // storeStaker: func(r *require.Assertions, subnetID ids.ID, s *state) *Staker { + // var ( + // startTime = time.Now().Unix() + // endTime = time.Now().Add(14 * 24 * time.Hour).Unix() + + // validatorsData = txs.Validator{ + // NodeID: ids.GenerateTestNodeID(), + // Start: uint64(startTime), + // End: uint64(endTime), + // Wght: 1234, + // } + // ) + + // utx := createPermissionlessValidatorTx(r, subnetID, validatorsData) + // addPermValTx := &txs.Tx{Unsigned: utx} + // r.NoError(addPermValTx.Initialize(txs.Codec)) + + // staker, err := NewPendingStaker( + // addPermValTx.ID(), + // utx, + // ) + // r.NoError(err) + + // s.PutPendingValidator(staker) + // s.AddTx(addPermValTx, status.Committed) // this is currently needed to reload the staker + // r.NoError(s.Commit()) + // return staker + // }, + // checkStakerInState: func(r *require.Assertions, s *state, staker *Staker) { + // retrievedStaker, err := s.GetPendingValidator(staker.SubnetID, staker.NodeID) + // r.NoError(err) + // r.Equal(staker, retrievedStaker) + // }, + // checkValidatorsSet: func(r *require.Assertions, s *state, staker *Staker) { + // // pending validators are not showed in validators set + // valsMap := s.validators.GetMap(staker.SubnetID) + // r.NotContains(valsMap, staker.NodeID) + // }, + // checkValidatorUptimes: func(r *require.Assertions, s *state, staker *Staker) { + // // pending validators uptime is not tracked + // _, _, err := s.GetUptime(staker.NodeID, staker.SubnetID) + // r.ErrorIs(err, database.ErrNotFound) + // }, + // checkDiffs: func(r *require.Assertions, s *state, staker *Staker, height uint64) { + // // pending validators weight diff and bls diffs are not stored + // _, err := s.validatorWeightDiffsDB.Get(marshalDiffKey(staker.SubnetID, height, staker.NodeID)) + // r.ErrorIs(err, database.ErrNotFound) + + // _, err = s.validatorPublicKeyDiffsDB.Get(marshalDiffKey(staker.SubnetID, height, staker.NodeID)) + // r.ErrorIs(err, database.ErrNotFound) + // }, + // }, + // "add pending delegator": { + // storeStaker: func(r *require.Assertions, subnetID ids.ID, s *state) *Staker { + // // insert the delegator and its validator + // var ( + // valStartTime = time.Now().Truncate(time.Second).Unix() + // delStartTime = time.Unix(valStartTime, 0).Add(time.Hour).Unix() + // delEndTime = time.Unix(delStartTime, 0).Add(30 * 24 * time.Hour).Unix() + // valEndTime = time.Unix(valStartTime, 0).Add(365 * 24 * time.Hour).Unix() + + // validatorsData = txs.Validator{ + // NodeID: ids.GenerateTestNodeID(), + // Start: uint64(valStartTime), + // End: uint64(valEndTime), + // Wght: 1234, + // } + + // delegatorData = txs.Validator{ + // NodeID: validatorsData.NodeID, + // Start: uint64(delStartTime), + // End: uint64(delEndTime), + // Wght: validatorsData.Wght / 2, + // } + // ) + + // utxVal := createPermissionlessValidatorTx(r, subnetID, validatorsData) + // addPermValTx := &txs.Tx{Unsigned: utxVal} + // r.NoError(addPermValTx.Initialize(txs.Codec)) + + // val, err := NewPendingStaker(addPermValTx.ID(), utxVal) + // r.NoError(err) + + // utxDel := createPermissionlessDelegatorTx(subnetID, delegatorData) + // addPermDelTx := &txs.Tx{Unsigned: utxDel} + // r.NoError(addPermDelTx.Initialize(txs.Codec)) + + // del, err := NewPendingStaker(addPermDelTx.ID(), utxDel) + // r.NoError(err) + + // s.PutPendingValidator(val) + // s.AddTx(addPermValTx, status.Committed) // this is currently needed to reload the staker + // r.NoError(s.Commit()) + + // s.PutPendingDelegator(del) + // s.AddTx(addPermDelTx, status.Committed) // this is currently needed to reload the staker + // r.NoError(s.Commit()) + + // return del + // }, + // checkStakerInState: func(r *require.Assertions, s *state, staker *Staker) { + // delIt, err := s.GetPendingDelegatorIterator(staker.SubnetID, staker.NodeID) + // r.NoError(err) + // r.True(delIt.Next()) + // retrievedDelegator := delIt.Value() + // r.False(delIt.Next()) + // delIt.Release() + // r.Equal(staker, retrievedDelegator) + // }, + // checkValidatorsSet: func(r *require.Assertions, s *state, staker *Staker) { + // valsMap := s.validators.GetMap(staker.SubnetID) + // r.NotContains(valsMap, staker.NodeID) + // }, + // checkValidatorUptimes: func(*require.Assertions, *state, *Staker) {}, + // checkDiffs: func(*require.Assertions, *state, *Staker, uint64) {}, + // }, + // "delete current validator": { + // storeStaker: func(r *require.Assertions, subnetID ids.ID, s *state) *Staker { + // // add them remove the validator + // var ( + // startTime = time.Now().Unix() + // endTime = time.Now().Add(14 * 24 * time.Hour).Unix() + + // validatorsData = txs.Validator{ + // NodeID: ids.GenerateTestNodeID(), + // End: uint64(endTime), + // Wght: 1234, + // } + // validatorReward uint64 = 5678 + // ) + + // utx := createPermissionlessValidatorTx(r, subnetID, validatorsData) + // addPermValTx := &txs.Tx{Unsigned: utx} + // r.NoError(addPermValTx.Initialize(txs.Codec)) + + // staker, err := NewCurrentStaker( + // addPermValTx.ID(), + // utx, + // time.Unix(startTime, 0), + // validatorReward, + // ) + // r.NoError(err) + + // s.PutCurrentValidator(staker) + // s.AddTx(addPermValTx, status.Committed) // this is currently needed to reload the staker + // r.NoError(s.Commit()) + + // s.DeleteCurrentValidator(staker) + // r.NoError(s.Commit()) + // return staker + // }, + // checkStakerInState: func(r *require.Assertions, s *state, staker *Staker) { + // _, err := s.GetCurrentValidator(staker.SubnetID, staker.NodeID) + // r.ErrorIs(err, database.ErrNotFound) + // }, + // checkValidatorsSet: func(r *require.Assertions, s *state, staker *Staker) { + // // deleted validators are not showed in the validators set anymore + // valsMap := s.validators.GetMap(staker.SubnetID) + // r.NotContains(valsMap, staker.NodeID) + // }, + // checkValidatorUptimes: func(r *require.Assertions, s *state, staker *Staker) { + // // uptimes of delete validators are dropped + // _, _, err := s.GetUptime(staker.NodeID, staker.SubnetID) + // r.ErrorIs(err, database.ErrNotFound) + // }, + // checkDiffs: func(r *require.Assertions, s *state, staker *Staker, height uint64) { + // weightDiffBytes, err := s.validatorWeightDiffsDB.Get(marshalDiffKey(staker.SubnetID, height, staker.NodeID)) + // r.NoError(err) + // weightDiff, err := unmarshalWeightDiff(weightDiffBytes) + // r.NoError(err) + // r.Equal(&ValidatorWeightDiff{ + // Decrease: true, + // Amount: staker.Weight, + // }, weightDiff) + + // blsDiffBytes, err := s.validatorPublicKeyDiffsDB.Get(marshalDiffKey(staker.SubnetID, height, staker.NodeID)) + // if staker.SubnetID == constants.PrimaryNetworkID { + // r.NoError(err) + // r.Equal(bls.PublicKeyFromValidUncompressedBytes(blsDiffBytes), staker.PublicKey) + // } else { + // r.ErrorIs(err, database.ErrNotFound) + // } + // }, + // }, + // "delete current delegator": { + // storeStaker: func(r *require.Assertions, subnetID ids.ID, s *state) *Staker { + // // insert validator and delegator, then remove the delegator + // var ( + // valStartTime = time.Now().Truncate(time.Second).Unix() + // delStartTime = time.Unix(valStartTime, 0).Add(time.Hour).Unix() + // delEndTime = time.Unix(delStartTime, 0).Add(30 * 24 * time.Hour).Unix() + // valEndTime = time.Unix(valStartTime, 0).Add(365 * 24 * time.Hour).Unix() + + // validatorsData = txs.Validator{ + // NodeID: ids.GenerateTestNodeID(), + // End: uint64(valEndTime), + // Wght: 1234, + // } + // validatorReward uint64 = 5678 + + // delegatorData = txs.Validator{ + // NodeID: validatorsData.NodeID, + // End: uint64(delEndTime), + // Wght: validatorsData.Wght / 2, + // } + // delegatorReward uint64 = 5432 + // ) + + // utxVal := createPermissionlessValidatorTx(r, subnetID, validatorsData) + // addPermValTx := &txs.Tx{Unsigned: utxVal} + // r.NoError(addPermValTx.Initialize(txs.Codec)) + + // val, err := NewCurrentStaker( + // addPermValTx.ID(), + // utxVal, + // time.Unix(valStartTime, 0), + // validatorReward, + // ) + // r.NoError(err) + + // utxDel := createPermissionlessDelegatorTx(subnetID, delegatorData) + // addPermDelTx := &txs.Tx{Unsigned: utxDel} + // r.NoError(addPermDelTx.Initialize(txs.Codec)) + + // del, err := NewCurrentStaker( + // addPermDelTx.ID(), + // utxDel, + // time.Unix(delStartTime, 0), + // delegatorReward, + // ) + // r.NoError(err) + + // s.PutCurrentValidator(val) + // s.AddTx(addPermValTx, status.Committed) // this is currently needed to reload the staker + + // s.PutCurrentDelegator(del) + // s.AddTx(addPermDelTx, status.Committed) // this is currently needed to reload the staker + // r.NoError(s.Commit()) + + // s.DeleteCurrentDelegator(del) + // r.NoError(s.Commit()) + + // return del + // }, + // checkStakerInState: func(r *require.Assertions, s *state, staker *Staker) { + // delIt, err := s.GetCurrentDelegatorIterator(staker.SubnetID, staker.NodeID) + // r.NoError(err) + // r.False(delIt.Next()) + // delIt.Release() + // }, + // checkValidatorsSet: func(r *require.Assertions, s *state, staker *Staker) { + // val, err := s.GetCurrentValidator(staker.SubnetID, staker.NodeID) + // r.NoError(err) + + // valsMap := s.validators.GetMap(staker.SubnetID) + // r.Contains(valsMap, staker.NodeID) + // valOut := valsMap[staker.NodeID] + // r.Equal(valOut.NodeID, staker.NodeID) + // r.Equal(valOut.Weight, val.Weight) + // }, + // checkValidatorUptimes: func(*require.Assertions, *state, *Staker) {}, + // checkDiffs: func(r *require.Assertions, s *state, staker *Staker, height uint64) { + // // validator's weight must decrease of delegator's weight amount + // weightDiffBytes, err := s.validatorWeightDiffsDB.Get(marshalDiffKey(staker.SubnetID, height, staker.NodeID)) + // r.NoError(err) + // weightDiff, err := unmarshalWeightDiff(weightDiffBytes) + // r.NoError(err) + // r.Equal(&ValidatorWeightDiff{ + // Decrease: true, + // Amount: staker.Weight, + // }, weightDiff) + // }, + // }, + // "delete pending validator": { + // storeStaker: func(r *require.Assertions, subnetID ids.ID, s *state) *Staker { + // var ( + // startTime = time.Now().Unix() + // endTime = time.Now().Add(14 * 24 * time.Hour).Unix() + + // validatorsData = txs.Validator{ + // NodeID: ids.GenerateTestNodeID(), + // Start: uint64(startTime), + // End: uint64(endTime), + // Wght: 1234, + // } + // ) + + // utx := createPermissionlessValidatorTx(r, subnetID, validatorsData) + // addPermValTx := &txs.Tx{Unsigned: utx} + // r.NoError(addPermValTx.Initialize(txs.Codec)) + + // staker, err := NewPendingStaker( + // addPermValTx.ID(), + // utx, + // ) + // r.NoError(err) + + // s.PutPendingValidator(staker) + // s.AddTx(addPermValTx, status.Committed) // this is currently needed to reload the staker + // r.NoError(s.Commit()) + + // s.DeletePendingValidator(staker) + // r.NoError(s.Commit()) + + // return staker + // }, + // checkStakerInState: func(r *require.Assertions, s *state, staker *Staker) { + // _, err := s.GetPendingValidator(staker.SubnetID, staker.NodeID) + // r.ErrorIs(err, database.ErrNotFound) + // }, + // checkValidatorsSet: func(r *require.Assertions, s *state, staker *Staker) { + // valsMap := s.validators.GetMap(staker.SubnetID) + // r.NotContains(valsMap, staker.NodeID) + // }, + // checkValidatorUptimes: func(r *require.Assertions, s *state, staker *Staker) { + // _, _, err := s.GetUptime(staker.NodeID, staker.SubnetID) + // r.ErrorIs(err, database.ErrNotFound) + // }, + // checkDiffs: func(r *require.Assertions, s *state, staker *Staker, height uint64) { + // _, err := s.validatorWeightDiffsDB.Get(marshalDiffKey(staker.SubnetID, height, staker.NodeID)) + // r.ErrorIs(err, database.ErrNotFound) + + // _, err = s.validatorPublicKeyDiffsDB.Get(marshalDiffKey(staker.SubnetID, height, staker.NodeID)) + // r.ErrorIs(err, database.ErrNotFound) + // }, + // }, + // "delete pending delegator": { + // storeStaker: func(r *require.Assertions, subnetID ids.ID, s *state) *Staker { + // // insert validator and delegator the remove the validator + // var ( + // valStartTime = time.Now().Truncate(time.Second).Unix() + // delStartTime = time.Unix(valStartTime, 0).Add(time.Hour).Unix() + // delEndTime = time.Unix(delStartTime, 0).Add(30 * 24 * time.Hour).Unix() + // valEndTime = time.Unix(valStartTime, 0).Add(365 * 24 * time.Hour).Unix() + + // validatorsData = txs.Validator{ + // NodeID: ids.GenerateTestNodeID(), + // Start: uint64(valStartTime), + // End: uint64(valEndTime), + // Wght: 1234, + // } + + // delegatorData = txs.Validator{ + // NodeID: validatorsData.NodeID, + // Start: uint64(delStartTime), + // End: uint64(delEndTime), + // Wght: validatorsData.Wght / 2, + // } + // ) + + // utxVal := createPermissionlessValidatorTx(r, subnetID, validatorsData) + // addPermValTx := &txs.Tx{Unsigned: utxVal} + // r.NoError(addPermValTx.Initialize(txs.Codec)) + + // val, err := NewPendingStaker(addPermValTx.ID(), utxVal) + // r.NoError(err) + + // utxDel := createPermissionlessDelegatorTx(subnetID, delegatorData) + // addPermDelTx := &txs.Tx{Unsigned: utxDel} + // r.NoError(addPermDelTx.Initialize(txs.Codec)) + + // del, err := NewPendingStaker(addPermDelTx.ID(), utxDel) + // r.NoError(err) + + // s.PutPendingValidator(val) + // s.AddTx(addPermValTx, status.Committed) // this is currently needed to reload the staker + + // s.PutPendingDelegator(del) + // s.AddTx(addPermDelTx, status.Committed) // this is currently needed to reload the staker + // r.NoError(s.Commit()) + + // s.DeletePendingDelegator(del) + // r.NoError(s.Commit()) + // return del + // }, + // checkStakerInState: func(r *require.Assertions, s *state, staker *Staker) { + // delIt, err := s.GetPendingDelegatorIterator(staker.SubnetID, staker.NodeID) + // r.NoError(err) + // r.False(delIt.Next()) + // delIt.Release() + // }, + // checkValidatorsSet: func(r *require.Assertions, s *state, staker *Staker) { + // valsMap := s.validators.GetMap(staker.SubnetID) + // r.NotContains(valsMap, staker.NodeID) + // }, + // checkValidatorUptimes: func(*require.Assertions, *state, *Staker) {}, + // checkDiffs: func(*require.Assertions, *state, *Staker, uint64) {}, + // }, } - subnetIDs := []ids.ID{constants.PrimaryNetworkID, ids.GenerateTestID()} + subnetIDs := []ids.ID{constants.PrimaryNetworkID /*, ids.GenerateTestID()*/} for _, subnetID := range subnetIDs { for name, test := range tests { t.Run(fmt.Sprintf("%s - subnetID %s", name, subnetID), func(t *testing.T) { diff --git a/vms/platformvm/txs/executor/helpers_test.go b/vms/platformvm/txs/executor/helpers_test.go index a2824a3b06c4..adc0181c885e 100644 --- a/vms/platformvm/txs/executor/helpers_test.go +++ b/vms/platformvm/txs/executor/helpers_test.go @@ -55,7 +55,7 @@ const ( ) var ( - defaultGenesisTime = time.Date(1997, 1, 1, 0, 0, 0, 0, time.UTC) + defaultGenesisTime = genesistest.Time defaultValidateStartTime = defaultGenesisTime defaultValidateEndTime = defaultValidateStartTime.Add(defaultValidateDuration) preFundedKeys = secp256k1.TestKeys() diff --git a/vms/platformvm/validator_set_property_test.go b/vms/platformvm/validator_set_property_test.go index 3935b75416a9..d5c901683ded 100644 --- a/vms/platformvm/validator_set_property_test.go +++ b/vms/platformvm/validator_set_property_test.go @@ -40,6 +40,7 @@ import ( "github.com/ava-labs/avalanchego/vms/platformvm/api" "github.com/ava-labs/avalanchego/vms/platformvm/block" "github.com/ava-labs/avalanchego/vms/platformvm/config" + "github.com/ava-labs/avalanchego/vms/platformvm/genesis/genesistest" "github.com/ava-labs/avalanchego/vms/platformvm/reward" "github.com/ava-labs/avalanchego/vms/platformvm/signer" "github.com/ava-labs/avalanchego/vms/platformvm/state" @@ -89,7 +90,7 @@ func TestGetValidatorsSetProperty(t *testing.T) { }() nodeID := ids.GenerateTestNodeID() - currentTime := defaultGenesisTime + currentTime := genesistest.Time vm.clock.Set(currentTime) vm.state.SetTimestamp(currentTime) @@ -662,9 +663,9 @@ func buildVM(t *testing.T) (*VM, ids.ID, error) { MinStakeDuration: defaultMinStakingDuration, MaxStakeDuration: defaultMaxStakingDuration, RewardConfig: defaultRewardConfig, - UpgradeConfig: upgradetest.GetConfigWithUpgradeTime(upgradetest.Durango, defaultGenesisTime), + UpgradeConfig: upgradetest.GetConfigWithUpgradeTime(upgradetest.Durango, genesistest.Time), }} - vm.clock.Set(defaultGenesisTime.Add(time.Second)) + vm.clock.Set(genesistest.Time.Add(time.Second)) baseDB := memdb.New() chainDB := prefixdb.New([]byte{0}, baseDB) @@ -805,7 +806,7 @@ func buildCustomGenesis(avaxAssetID ids.ID) ([]byte, error) { UTXOs: genesisUTXOs, Validators: []api.GenesisPermissionlessValidator{genesisValidator}, Chains: nil, - Time: json.Uint64(defaultGenesisTime.Unix()), + Time: json.Uint64(genesistest.Time.Unix()), InitialSupply: json.Uint64(360 * units.MegaAvax), } diff --git a/vms/platformvm/vm_regression_test.go b/vms/platformvm/vm_regression_test.go index 851117920bcf..8f81da1cb2d9 100644 --- a/vms/platformvm/vm_regression_test.go +++ b/vms/platformvm/vm_regression_test.go @@ -35,6 +35,7 @@ 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/genesis/genesistest" "github.com/ava-labs/avalanchego/vms/platformvm/reward" "github.com/ava-labs/avalanchego/vms/platformvm/signer" "github.com/ava-labs/avalanchego/vms/platformvm/state/statetest" @@ -247,7 +248,7 @@ func TestAddDelegatorTxHeapCorruption(t *testing.T) { }, { name: "post-upgrade calculate max stake correctly", - ap3Time: defaultGenesisTime, + ap3Time: genesistest.Time, }, } @@ -1637,7 +1638,7 @@ func TestSubnetValidatorBLSKeyDiffAfterExpiry(t *testing.T) { subnetID := testSubnet1.TxID // setup time - currentTime := defaultGenesisTime + currentTime := genesistest.Time vm.clock.Set(currentTime) vm.state.SetTimestamp(currentTime) @@ -1900,7 +1901,7 @@ func TestPrimaryNetworkValidatorPopulatedToEmptyBLSKeyDiff(t *testing.T) { defer vm.ctx.Lock.Unlock() // setup time - currentTime := defaultGenesisTime + currentTime := genesistest.Time vm.clock.Set(currentTime) vm.state.SetTimestamp(currentTime) @@ -2058,7 +2059,7 @@ func TestSubnetValidatorPopulatedToEmptyBLSKeyDiff(t *testing.T) { subnetID := testSubnet1.TxID // setup time - currentTime := defaultGenesisTime + currentTime := genesistest.Time vm.clock.Set(currentTime) vm.state.SetTimestamp(currentTime) @@ -2277,7 +2278,7 @@ func TestSubnetValidatorSetAfterPrimaryNetworkValidatorRemoval(t *testing.T) { subnetID := testSubnet1.TxID // setup time - currentTime := defaultGenesisTime + currentTime := genesistest.Time vm.clock.Set(currentTime) vm.state.SetTimestamp(currentTime) diff --git a/vms/platformvm/vm_test.go b/vms/platformvm/vm_test.go index 427d70ed3382..f107647bcc7c 100644 --- a/vms/platformvm/vm_test.go +++ b/vms/platformvm/vm_test.go @@ -54,6 +54,7 @@ import ( "github.com/ava-labs/avalanchego/vms/platformvm/api" "github.com/ava-labs/avalanchego/vms/platformvm/block" "github.com/ava-labs/avalanchego/vms/platformvm/config" + "github.com/ava-labs/avalanchego/vms/platformvm/genesis/genesistest" "github.com/ava-labs/avalanchego/vms/platformvm/reward" "github.com/ava-labs/avalanchego/vms/platformvm/signer" "github.com/ava-labs/avalanchego/vms/platformvm/status" @@ -91,16 +92,13 @@ var ( defaultTxFee = uint64(100) - // chain timestamp at genesis - defaultGenesisTime = time.Date(1997, 1, 1, 0, 0, 0, 0, time.UTC) - // time that genesis validators start validating - defaultValidateStartTime = defaultGenesisTime + defaultValidateStartTime = genesistest.Time // time that genesis validators stop validating defaultValidateEndTime = defaultValidateStartTime.Add(10 * defaultMinStakingDuration) - latestForkTime = defaultGenesisTime.Add(time.Second) + latestForkTime = genesistest.Time.Add(time.Second) // each key controls an address that has [defaultBalance] AVAX at genesis keys = secp256k1.TestKeys() @@ -197,7 +195,7 @@ func defaultGenesis(t *testing.T, avaxAssetID ids.ID) (*api.BuildGenesisArgs, [] UTXOs: genesisUTXOs, Validators: genesisValidators, Chains: nil, - Time: json.Uint64(defaultGenesisTime.Unix()), + Time: json.Uint64(genesistest.Time.Unix()), InitialSupply: json.Uint64(360 * units.MegaAvax), } @@ -216,7 +214,7 @@ func defaultVM(t *testing.T, f upgradetest.Fork) (*VM, *txstest.WalletFactory, d // always reset latestForkTime (a package level variable) // to ensure test independence - latestForkTime = defaultGenesisTime.Add(time.Second) + latestForkTime = genesistest.Time.Add(time.Second) vm := &VM{Config: config.Config{ Chains: chains.TestManager, UptimeLockedCalculator: uptime.NewLockedCalculator(), @@ -451,7 +449,7 @@ func TestInvalidAddValidatorCommit(t *testing.T) { defer vm.ctx.Lock.Unlock() nodeID := ids.GenerateTestNodeID() - startTime := defaultGenesisTime.Add(-txexecutor.SyncBound).Add(-1 * time.Second) + startTime := genesistest.Time.Add(-txexecutor.SyncBound).Add(-1 * time.Second) endTime := startTime.Add(defaultMinStakingDuration) // create invalid tx From b4a08515f4cd0d4283bb4237d3968e1dd69f9558 Mon Sep 17 00:00:00 2001 From: Stephen Buttolph Date: Thu, 22 Aug 2024 11:46:29 -0400 Subject: [PATCH 06/27] wip --- vms/platformvm/block/builder/helpers_test.go | 5 ++-- vms/platformvm/block/executor/helpers_test.go | 5 ++-- .../block/executor/proposal_block_test.go | 23 ++++++++++--------- .../block/executor/standard_block_test.go | 13 ++++++----- .../block/executor/verifier_test.go | 9 ++++---- .../txs/executor/advance_time_test.go | 3 ++- .../txs/executor/create_chain_test.go | 5 ++-- .../txs/executor/create_subnet_test.go | 5 ++-- vms/platformvm/txs/executor/helpers_test.go | 5 ++-- .../txs/executor/proposal_tx_executor_test.go | 17 +++++++------- .../txs/executor/standard_tx_executor_test.go | 23 ++++++++++--------- 11 files changed, 59 insertions(+), 54 deletions(-) diff --git a/vms/platformvm/block/builder/helpers_test.go b/vms/platformvm/block/builder/helpers_test.go index 505be39491b9..70337a1d315e 100644 --- a/vms/platformvm/block/builder/helpers_test.go +++ b/vms/platformvm/block/builder/helpers_test.go @@ -58,8 +58,7 @@ import ( var ( defaultMinStakingDuration = 24 * time.Hour defaultMaxStakingDuration = 365 * 24 * time.Hour - defaultGenesisTime = genesistest.Time - defaultValidateStartTime = defaultGenesisTime + defaultValidateStartTime = genesistest.Time defaultValidateEndTime = defaultValidateStartTime.Add(10 * defaultMinStakingDuration) preFundedKeys = secp256k1.TestKeys() defaultTxFee = uint64(100) @@ -295,7 +294,7 @@ func defaultConfig(f upgradetest.Fork) *config.Config { func defaultClock() *mockable.Clock { // set time after Banff fork (and before default nextStakerTime) clk := &mockable.Clock{} - clk.Set(defaultGenesisTime) + clk.Set(genesistest.Time) return clk } diff --git a/vms/platformvm/block/executor/helpers_test.go b/vms/platformvm/block/executor/helpers_test.go index d4424cd5057e..c1d859e6f9c8 100644 --- a/vms/platformvm/block/executor/helpers_test.go +++ b/vms/platformvm/block/executor/helpers_test.go @@ -62,8 +62,7 @@ const ( var ( defaultMinStakingDuration = 24 * time.Hour defaultMaxStakingDuration = 365 * 24 * time.Hour - defaultGenesisTime = genesistest.Time - defaultValidateStartTime = defaultGenesisTime + defaultValidateStartTime = genesistest.Time defaultValidateEndTime = defaultValidateStartTime.Add(10 * defaultMinStakingDuration) preFundedKeys = secp256k1.TestKeys() avaxAssetID = ids.ID{'y', 'e', 'e', 't'} @@ -324,7 +323,7 @@ func defaultConfig(f upgradetest.Fork) *config.Config { func defaultClock() *mockable.Clock { clk := &mockable.Clock{} - clk.Set(defaultGenesisTime) + clk.Set(genesistest.Time) return clk } diff --git a/vms/platformvm/block/executor/proposal_block_test.go b/vms/platformvm/block/executor/proposal_block_test.go index a7f38e28850c..d50a858b1658 100644 --- a/vms/platformvm/block/executor/proposal_block_test.go +++ b/vms/platformvm/block/executor/proposal_block_test.go @@ -23,6 +23,7 @@ import ( "github.com/ava-labs/avalanchego/vms/components/avax" "github.com/ava-labs/avalanchego/vms/components/fee" "github.com/ava-labs/avalanchego/vms/platformvm/block" + "github.com/ava-labs/avalanchego/vms/platformvm/genesis/genesistest" "github.com/ava-labs/avalanchego/vms/platformvm/reward" "github.com/ava-labs/avalanchego/vms/platformvm/signer" "github.com/ava-labs/avalanchego/vms/platformvm/state" @@ -144,7 +145,7 @@ func TestBanffProposalBlockTimeVerification(t *testing.T) { env := newEnvironment(t, ctrl, upgradetest.Banff) // create parentBlock. It's a standard one for simplicity - parentTime := defaultGenesisTime + parentTime := genesistest.Time parentHeight := uint64(2022) banffParentBlk, err := block.NewApricotStandardBlock( @@ -374,15 +375,15 @@ func TestBanffProposalBlockUpdateStakers(t *testing.T) { staker0 := staker{ nodeID: ids.BuildTestNodeID([]byte{0xf0}), rewardAddress: ids.ShortID{0xf0}, - startTime: defaultGenesisTime, + startTime: genesistest.Time, endTime: time.Time{}, // actual endTime depends on specific test } staker1 := staker{ nodeID: ids.BuildTestNodeID([]byte{0xf1}), rewardAddress: ids.ShortID{0xf1}, - startTime: defaultGenesisTime.Add(1 * time.Minute), - endTime: defaultGenesisTime.Add(10 * defaultMinStakingDuration).Add(1 * time.Minute), + startTime: genesistest.Time.Add(1 * time.Minute), + endTime: genesistest.Time.Add(10 * defaultMinStakingDuration).Add(1 * time.Minute), } staker2 := staker{ nodeID: ids.BuildTestNodeID([]byte{0xf2}), @@ -876,8 +877,8 @@ func TestBanffProposalBlockTrackedSubnet(t *testing.T) { // Add a subnet validator to the staker set subnetValidatorNodeID := genesisNodeIDs[0] - subnetVdr1StartTime := defaultGenesisTime.Add(1 * time.Minute) - subnetVdr1EndTime := defaultGenesisTime.Add(10 * defaultMinStakingDuration).Add(1 * time.Minute) + subnetVdr1StartTime := genesistest.Time.Add(1 * time.Minute) + subnetVdr1EndTime := genesistest.Time.Add(10 * defaultMinStakingDuration).Add(1 * time.Minute) builder, signer := env.factory.NewWallet(preFundedKeys[0], preFundedKeys[1]) utx, err := builder.NewAddSubnetValidatorTx( @@ -910,7 +911,7 @@ func TestBanffProposalBlockTrackedSubnet(t *testing.T) { // add Staker0 (with the right end time) to state // so to allow proposalBlk issuance - staker0StartTime := defaultGenesisTime + staker0StartTime := genesistest.Time staker0EndTime := subnetVdr1StartTime uVdrTx, err := builder.NewAddValidatorTx( @@ -985,7 +986,7 @@ func TestBanffProposalBlockDelegatorStakerWeight(t *testing.T) { // Case: Timestamp is after next validator start time // Add a pending validator - pendingValidatorStartTime := defaultGenesisTime.Add(1 * time.Second) + pendingValidatorStartTime := genesistest.Time.Add(1 * time.Second) pendingValidatorEndTime := pendingValidatorStartTime.Add(defaultMaxStakingDuration) nodeID := ids.GenerateTestNodeID() rewardAddress := ids.GenerateTestShortID() @@ -1001,7 +1002,7 @@ func TestBanffProposalBlockDelegatorStakerWeight(t *testing.T) { // add Staker0 (with the right end time) to state // just to allow proposalBlk issuance (with a reward Tx) - staker0StartTime := defaultGenesisTime + staker0StartTime := genesistest.Time staker0EndTime := pendingValidatorStartTime builder, signer := env.factory.NewWallet(preFundedKeys[0], preFundedKeys[1]) utx, err := builder.NewAddValidatorTx( @@ -1180,7 +1181,7 @@ func TestBanffProposalBlockDelegatorStakers(t *testing.T) { // Case: Timestamp is after next validator start time // Add a pending validator - pendingValidatorStartTime := defaultGenesisTime.Add(1 * time.Second) + pendingValidatorStartTime := genesistest.Time.Add(1 * time.Second) pendingValidatorEndTime := pendingValidatorStartTime.Add(defaultMinStakingDuration) nodeIDKey, _ := secp256k1.NewPrivateKey() rewardAddress := nodeIDKey.PublicKey().Address() @@ -1198,7 +1199,7 @@ func TestBanffProposalBlockDelegatorStakers(t *testing.T) { // add Staker0 (with the right end time) to state // so to allow proposalBlk issuance - staker0StartTime := defaultGenesisTime + staker0StartTime := genesistest.Time staker0EndTime := pendingValidatorStartTime builder, txSigner := env.factory.NewWallet(preFundedKeys[0], preFundedKeys[1]) utx, err := builder.NewAddValidatorTx( diff --git a/vms/platformvm/block/executor/standard_block_test.go b/vms/platformvm/block/executor/standard_block_test.go index 3dc1f999e789..8b076da56d8c 100644 --- a/vms/platformvm/block/executor/standard_block_test.go +++ b/vms/platformvm/block/executor/standard_block_test.go @@ -20,6 +20,7 @@ import ( "github.com/ava-labs/avalanchego/vms/components/avax" "github.com/ava-labs/avalanchego/vms/components/fee" "github.com/ava-labs/avalanchego/vms/platformvm/block" + "github.com/ava-labs/avalanchego/vms/platformvm/genesis/genesistest" "github.com/ava-labs/avalanchego/vms/platformvm/state" "github.com/ava-labs/avalanchego/vms/platformvm/status" "github.com/ava-labs/avalanchego/vms/platformvm/txs" @@ -295,7 +296,7 @@ func TestBanffStandardBlockUpdatePrimaryNetworkStakers(t *testing.T) { // Case: Timestamp is after next validator start time // Add a pending validator - pendingValidatorStartTime := defaultGenesisTime.Add(1 * time.Second) + pendingValidatorStartTime := genesistest.Time.Add(1 * time.Second) pendingValidatorEndTime := pendingValidatorStartTime.Add(defaultMinStakingDuration) nodeID := ids.GenerateTestNodeID() rewardAddress := ids.GenerateTestShortID() @@ -362,8 +363,8 @@ func TestBanffStandardBlockUpdateStakers(t *testing.T) { staker1 := staker{ nodeID: ids.BuildTestNodeID([]byte{0xf1}), rewardAddress: ids.ShortID{0xf1}, - startTime: defaultGenesisTime.Add(1 * time.Minute), - endTime: defaultGenesisTime.Add(10 * defaultMinStakingDuration).Add(1 * time.Minute), + startTime: genesistest.Time.Add(1 * time.Minute), + endTime: genesistest.Time.Add(10 * defaultMinStakingDuration).Add(1 * time.Minute), } staker2 := staker{ nodeID: ids.BuildTestNodeID([]byte{0xf2}), @@ -708,8 +709,8 @@ func TestBanffStandardBlockTrackedSubnet(t *testing.T) { // Add a subnet validator to the staker set subnetValidatorNodeID := genesisNodeIDs[0] - subnetVdr1StartTime := defaultGenesisTime.Add(1 * time.Minute) - subnetVdr1EndTime := defaultGenesisTime.Add(10 * defaultMinStakingDuration).Add(1 * time.Minute) + subnetVdr1StartTime := genesistest.Time.Add(1 * time.Minute) + subnetVdr1EndTime := genesistest.Time.Add(10 * defaultMinStakingDuration).Add(1 * time.Minute) builder, signer := env.factory.NewWallet(preFundedKeys[0], preFundedKeys[1]) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ @@ -767,7 +768,7 @@ func TestBanffStandardBlockDelegatorStakerWeight(t *testing.T) { // Case: Timestamp is after next validator start time // Add a pending validator - pendingValidatorStartTime := defaultGenesisTime.Add(1 * time.Second) + pendingValidatorStartTime := genesistest.Time.Add(1 * time.Second) pendingValidatorEndTime := pendingValidatorStartTime.Add(defaultMaxStakingDuration) nodeID := ids.GenerateTestNodeID() rewardAddress := ids.GenerateTestShortID() diff --git a/vms/platformvm/block/executor/verifier_test.go b/vms/platformvm/block/executor/verifier_test.go index 535e7d70f37e..f399222faca2 100644 --- a/vms/platformvm/block/executor/verifier_test.go +++ b/vms/platformvm/block/executor/verifier_test.go @@ -23,6 +23,7 @@ import ( "github.com/ava-labs/avalanchego/vms/components/verify" "github.com/ava-labs/avalanchego/vms/platformvm/block" "github.com/ava-labs/avalanchego/vms/platformvm/config" + "github.com/ava-labs/avalanchego/vms/platformvm/genesis/genesistest" "github.com/ava-labs/avalanchego/vms/platformvm/state" "github.com/ava-labs/avalanchego/vms/platformvm/status" "github.com/ava-labs/avalanchego/vms/platformvm/txs" @@ -468,7 +469,7 @@ func TestVerifyUnverifiedParent(t *testing.T) { func TestBanffAbortBlockTimestampChecks(t *testing.T) { ctrl := gomock.NewController(t) - now := defaultGenesisTime.Add(time.Hour) + now := genesistest.Time.Add(time.Hour) tests := []struct { description string @@ -531,7 +532,7 @@ func TestBanffAbortBlockTimestampChecks(t *testing.T) { require.NoError(err) // setup parent state - parentTime := defaultGenesisTime + parentTime := genesistest.Time s.EXPECT().GetLastAccepted().Return(parentID).Times(3) s.EXPECT().GetTimestamp().Return(parentTime).Times(3) s.EXPECT().GetFeeState().Return(fee.State{}).Times(3) @@ -565,7 +566,7 @@ func TestBanffAbortBlockTimestampChecks(t *testing.T) { func TestBanffCommitBlockTimestampChecks(t *testing.T) { ctrl := gomock.NewController(t) - now := defaultGenesisTime.Add(time.Hour) + now := genesistest.Time.Add(time.Hour) tests := []struct { description string @@ -628,7 +629,7 @@ func TestBanffCommitBlockTimestampChecks(t *testing.T) { require.NoError(err) // setup parent state - parentTime := defaultGenesisTime + parentTime := genesistest.Time s.EXPECT().GetLastAccepted().Return(parentID).Times(3) s.EXPECT().GetTimestamp().Return(parentTime).Times(3) s.EXPECT().GetFeeState().Return(fee.State{}).Times(3) diff --git a/vms/platformvm/txs/executor/advance_time_test.go b/vms/platformvm/txs/executor/advance_time_test.go index e9e54ad8a3e6..e21018666898 100644 --- a/vms/platformvm/txs/executor/advance_time_test.go +++ b/vms/platformvm/txs/executor/advance_time_test.go @@ -17,6 +17,7 @@ import ( "github.com/ava-labs/avalanchego/upgrade/upgradetest" "github.com/ava-labs/avalanchego/utils/constants" "github.com/ava-labs/avalanchego/utils/crypto/secp256k1" + "github.com/ava-labs/avalanchego/vms/platformvm/genesis/genesistest" "github.com/ava-labs/avalanchego/vms/platformvm/reward" "github.com/ava-labs/avalanchego/vms/platformvm/state" "github.com/ava-labs/avalanchego/vms/platformvm/status" @@ -882,7 +883,7 @@ func TestAdvanceTimeTxAfterBanff(t *testing.T) { env := newEnvironment(t, upgradetest.Durango) env.ctx.Lock.Lock() defer env.ctx.Lock.Unlock() - env.clk.Set(defaultGenesisTime) // VM's clock reads the genesis time + env.clk.Set(genesistest.Time) // VM's clock reads the genesis time upgradeTime := env.clk.Time().Add(SyncBound) env.config.UpgradeConfig.BanffTime = upgradeTime env.config.UpgradeConfig.CortinaTime = upgradeTime diff --git a/vms/platformvm/txs/executor/create_chain_test.go b/vms/platformvm/txs/executor/create_chain_test.go index a1ad4c81e186..c4718d156bc3 100644 --- a/vms/platformvm/txs/executor/create_chain_test.go +++ b/vms/platformvm/txs/executor/create_chain_test.go @@ -18,6 +18,7 @@ import ( "github.com/ava-labs/avalanchego/utils/hashing" "github.com/ava-labs/avalanchego/utils/set" "github.com/ava-labs/avalanchego/utils/units" + "github.com/ava-labs/avalanchego/vms/platformvm/genesis/genesistest" "github.com/ava-labs/avalanchego/vms/platformvm/state" "github.com/ava-labs/avalanchego/vms/platformvm/txs" "github.com/ava-labs/avalanchego/vms/platformvm/txs/txstest" @@ -180,7 +181,7 @@ func TestCreateChainTxValid(t *testing.T) { } func TestCreateChainTxAP3FeeChange(t *testing.T) { - ap3Time := defaultGenesisTime.Add(time.Hour) + ap3Time := genesistest.Time.Add(time.Hour) tests := []struct { name string time time.Time @@ -189,7 +190,7 @@ func TestCreateChainTxAP3FeeChange(t *testing.T) { }{ { name: "pre-fork - correctly priced", - time: defaultGenesisTime, + time: genesistest.Time, fee: 0, expectedError: nil, }, diff --git a/vms/platformvm/txs/executor/create_subnet_test.go b/vms/platformvm/txs/executor/create_subnet_test.go index a991bda7de0e..abe1fac1eee4 100644 --- a/vms/platformvm/txs/executor/create_subnet_test.go +++ b/vms/platformvm/txs/executor/create_subnet_test.go @@ -14,6 +14,7 @@ import ( "github.com/ava-labs/avalanchego/upgrade/upgradetest" "github.com/ava-labs/avalanchego/utils/set" "github.com/ava-labs/avalanchego/utils/units" + "github.com/ava-labs/avalanchego/vms/platformvm/genesis/genesistest" "github.com/ava-labs/avalanchego/vms/platformvm/state" "github.com/ava-labs/avalanchego/vms/platformvm/txs/txstest" "github.com/ava-labs/avalanchego/vms/platformvm/utxo" @@ -23,7 +24,7 @@ import ( ) func TestCreateSubnetTxAP3FeeChange(t *testing.T) { - ap3Time := defaultGenesisTime.Add(time.Hour) + ap3Time := genesistest.Time.Add(time.Hour) tests := []struct { name string time time.Time @@ -32,7 +33,7 @@ func TestCreateSubnetTxAP3FeeChange(t *testing.T) { }{ { name: "pre-fork - correctly priced", - time: defaultGenesisTime, + time: genesistest.Time, fee: 0, expectedErr: nil, }, diff --git a/vms/platformvm/txs/executor/helpers_test.go b/vms/platformvm/txs/executor/helpers_test.go index adc0181c885e..6e4955061cff 100644 --- a/vms/platformvm/txs/executor/helpers_test.go +++ b/vms/platformvm/txs/executor/helpers_test.go @@ -55,8 +55,7 @@ const ( ) var ( - defaultGenesisTime = genesistest.Time - defaultValidateStartTime = defaultGenesisTime + defaultValidateStartTime = genesistest.Time defaultValidateEndTime = defaultValidateStartTime.Add(defaultValidateDuration) preFundedKeys = secp256k1.TestKeys() @@ -273,7 +272,7 @@ func defaultConfig(f upgradetest.Fork) *config.Config { } func defaultClock(f upgradetest.Fork) *mockable.Clock { - now := defaultGenesisTime + now := genesistest.Time if f >= upgradetest.Banff { // 1 second after active fork now = defaultValidateEndTime.Add(-2 * time.Second) diff --git a/vms/platformvm/txs/executor/proposal_tx_executor_test.go b/vms/platformvm/txs/executor/proposal_tx_executor_test.go index 0efbae5e65ba..3f938a54ed8f 100644 --- a/vms/platformvm/txs/executor/proposal_tx_executor_test.go +++ b/vms/platformvm/txs/executor/proposal_tx_executor_test.go @@ -16,6 +16,7 @@ import ( "github.com/ava-labs/avalanchego/upgrade/upgradetest" "github.com/ava-labs/avalanchego/utils/crypto/secp256k1" "github.com/ava-labs/avalanchego/utils/hashing" + "github.com/ava-labs/avalanchego/vms/platformvm/genesis/genesistest" "github.com/ava-labs/avalanchego/vms/platformvm/reward" "github.com/ava-labs/avalanchego/vms/platformvm/state" "github.com/ava-labs/avalanchego/vms/platformvm/status" @@ -134,7 +135,7 @@ func TestProposalTxExecuteAddDelegator(t *testing.T) { nodeID: nodeID, feeKeys: []*secp256k1.PrivateKey{preFundedKeys[0]}, setup: nil, - AP3Time: defaultGenesisTime, + AP3Time: genesistest.Time, expectedErr: ErrPeriodMismatch, }, { @@ -145,7 +146,7 @@ func TestProposalTxExecuteAddDelegator(t *testing.T) { nodeID: newValidatorID, feeKeys: []*secp256k1.PrivateKey{preFundedKeys[0]}, setup: nil, - AP3Time: defaultGenesisTime, + AP3Time: genesistest.Time, expectedErr: database.ErrNotFound, }, { @@ -156,7 +157,7 @@ func TestProposalTxExecuteAddDelegator(t *testing.T) { nodeID: newValidatorID, feeKeys: []*secp256k1.PrivateKey{preFundedKeys[0]}, setup: addMinStakeValidator, - AP3Time: defaultGenesisTime, + AP3Time: genesistest.Time, expectedErr: ErrPeriodMismatch, }, { @@ -167,7 +168,7 @@ func TestProposalTxExecuteAddDelegator(t *testing.T) { nodeID: newValidatorID, feeKeys: []*secp256k1.PrivateKey{preFundedKeys[0]}, setup: addMinStakeValidator, - AP3Time: defaultGenesisTime, + AP3Time: genesistest.Time, expectedErr: ErrPeriodMismatch, }, { @@ -178,7 +179,7 @@ func TestProposalTxExecuteAddDelegator(t *testing.T) { nodeID: newValidatorID, feeKeys: []*secp256k1.PrivateKey{preFundedKeys[0]}, setup: addMinStakeValidator, - AP3Time: defaultGenesisTime, + AP3Time: genesistest.Time, expectedErr: nil, }, { @@ -189,7 +190,7 @@ func TestProposalTxExecuteAddDelegator(t *testing.T) { nodeID: nodeID, feeKeys: []*secp256k1.PrivateKey{preFundedKeys[0]}, setup: nil, - AP3Time: defaultGenesisTime, + AP3Time: genesistest.Time, expectedErr: ErrTimestampNotBeforeStartTime, }, { @@ -212,7 +213,7 @@ func TestProposalTxExecuteAddDelegator(t *testing.T) { env.state.SetHeight(dummyHeight) require.NoError(t, env.state.Commit()) }, - AP3Time: defaultGenesisTime, + AP3Time: genesistest.Time, expectedErr: ErrFlowCheckFailed, }, { @@ -234,7 +235,7 @@ func TestProposalTxExecuteAddDelegator(t *testing.T) { nodeID: newValidatorID, feeKeys: []*secp256k1.PrivateKey{preFundedKeys[0]}, setup: addMaxStakeValidator, - AP3Time: defaultGenesisTime, + AP3Time: genesistest.Time, expectedErr: ErrOverDelegated, }, } diff --git a/vms/platformvm/txs/executor/standard_tx_executor_test.go b/vms/platformvm/txs/executor/standard_tx_executor_test.go index d2a0010f87c5..838339d2c0eb 100644 --- a/vms/platformvm/txs/executor/standard_tx_executor_test.go +++ b/vms/platformvm/txs/executor/standard_tx_executor_test.go @@ -28,6 +28,7 @@ import ( "github.com/ava-labs/avalanchego/vms/components/verify" "github.com/ava-labs/avalanchego/vms/platformvm/config" "github.com/ava-labs/avalanchego/vms/platformvm/fx" + "github.com/ava-labs/avalanchego/vms/platformvm/genesis/genesistest" "github.com/ava-labs/avalanchego/vms/platformvm/reward" "github.com/ava-labs/avalanchego/vms/platformvm/signer" "github.com/ava-labs/avalanchego/vms/platformvm/state" @@ -218,7 +219,7 @@ func TestStandardTxExecutorAddDelegator(t *testing.T) { nodeID: nodeID, feeKeys: []*secp256k1.PrivateKey{preFundedKeys[0]}, setup: nil, - AP3Time: defaultGenesisTime, + AP3Time: genesistest.Time, expectedExecutionErr: ErrPeriodMismatch, }, { @@ -229,7 +230,7 @@ func TestStandardTxExecutorAddDelegator(t *testing.T) { nodeID: newValidatorID, feeKeys: []*secp256k1.PrivateKey{preFundedKeys[0]}, setup: nil, - AP3Time: defaultGenesisTime, + AP3Time: genesistest.Time, expectedExecutionErr: database.ErrNotFound, }, { @@ -240,7 +241,7 @@ func TestStandardTxExecutorAddDelegator(t *testing.T) { nodeID: newValidatorID, feeKeys: []*secp256k1.PrivateKey{preFundedKeys[0]}, setup: addMinStakeValidator, - AP3Time: defaultGenesisTime, + AP3Time: genesistest.Time, expectedExecutionErr: ErrPeriodMismatch, }, { @@ -251,7 +252,7 @@ func TestStandardTxExecutorAddDelegator(t *testing.T) { nodeID: newValidatorID, feeKeys: []*secp256k1.PrivateKey{preFundedKeys[0]}, setup: addMinStakeValidator, - AP3Time: defaultGenesisTime, + AP3Time: genesistest.Time, expectedExecutionErr: ErrPeriodMismatch, }, { @@ -262,7 +263,7 @@ func TestStandardTxExecutorAddDelegator(t *testing.T) { nodeID: newValidatorID, feeKeys: []*secp256k1.PrivateKey{preFundedKeys[0]}, setup: addMinStakeValidator, - AP3Time: defaultGenesisTime, + AP3Time: genesistest.Time, expectedExecutionErr: nil, }, { @@ -273,7 +274,7 @@ func TestStandardTxExecutorAddDelegator(t *testing.T) { nodeID: nodeID, // node ID feeKeys: []*secp256k1.PrivateKey{preFundedKeys[0]}, // tx fee payer setup: nil, - AP3Time: defaultGenesisTime, + AP3Time: genesistest.Time, expectedExecutionErr: ErrTimestampNotBeforeStartTime, }, { @@ -296,7 +297,7 @@ func TestStandardTxExecutorAddDelegator(t *testing.T) { env.state.SetHeight(dummyHeight) require.NoError(t, env.state.Commit()) }, - AP3Time: defaultGenesisTime, + AP3Time: genesistest.Time, expectedExecutionErr: ErrFlowCheckFailed, }, { @@ -318,7 +319,7 @@ func TestStandardTxExecutorAddDelegator(t *testing.T) { nodeID: newValidatorID, feeKeys: []*secp256k1.PrivateKey{preFundedKeys[0]}, setup: addMaxStakeValidator, - AP3Time: defaultGenesisTime, + AP3Time: genesistest.Time, expectedExecutionErr: ErrOverDelegated, }, } @@ -448,7 +449,7 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { // Add a validator to pending validator set of primary network // Starts validating primary network 10 seconds after genesis pendingDSValidatorID := ids.GenerateTestNodeID() - dsStartTime := defaultGenesisTime.Add(10 * time.Second) + dsStartTime := genesistest.Time.Add(10 * time.Second) dsEndTime := dsStartTime.Add(5 * defaultMinStakingDuration) builder, signer := env.factory.NewWallet(preFundedKeys[0]) @@ -618,7 +619,7 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { // Case: Proposed validator start validating at/before current timestamp // First, advance the timestamp - newTimestamp := defaultGenesisTime.Add(2 * time.Second) + newTimestamp := genesistest.Time.Add(2 * time.Second) env.state.SetTimestamp(newTimestamp) { @@ -653,7 +654,7 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { } // reset the timestamp - env.state.SetTimestamp(defaultGenesisTime) + env.state.SetTimestamp(genesistest.Time) // Case: Proposed validator already validating the subnet // First, add validator as validator of subnet From 411b482aa14520139cdc290f3e16a542192566b9 Mon Sep 17 00:00:00 2001 From: Stephen Buttolph Date: Thu, 22 Aug 2024 12:16:30 -0400 Subject: [PATCH 07/27] wip --- vms/platformvm/block/builder/helpers_test.go | 4 +- vms/platformvm/block/executor/helpers_test.go | 4 +- .../block/executor/proposal_block_test.go | 8 +-- .../block/executor/standard_block_test.go | 5 +- vms/platformvm/genesis/genesistest/helper.go | 9 +-- vms/platformvm/service_test.go | 14 ++-- .../txs/executor/advance_time_test.go | 25 ++++--- vms/platformvm/txs/executor/export_test.go | 3 +- vms/platformvm/txs/executor/helpers_test.go | 11 ++-- .../txs/executor/proposal_tx_executor_test.go | 66 +++++++++---------- .../txs/executor/reward_validator_test.go | 19 +++--- .../txs/executor/standard_tx_executor_test.go | 66 +++++++++---------- vms/platformvm/vm_test.go | 50 +++++++------- 13 files changed, 132 insertions(+), 152 deletions(-) diff --git a/vms/platformvm/block/builder/helpers_test.go b/vms/platformvm/block/builder/helpers_test.go index 70337a1d315e..24c3dd7cf514 100644 --- a/vms/platformvm/block/builder/helpers_test.go +++ b/vms/platformvm/block/builder/helpers_test.go @@ -58,8 +58,6 @@ import ( var ( defaultMinStakingDuration = 24 * time.Hour defaultMaxStakingDuration = 365 * 24 * time.Hour - defaultValidateStartTime = genesistest.Time - defaultValidateEndTime = defaultValidateStartTime.Add(10 * defaultMinStakingDuration) preFundedKeys = secp256k1.TestKeys() defaultTxFee = uint64(100) @@ -264,7 +262,7 @@ func defaultConfig(f upgradetest.Fork) *config.Config { upgradetest.SetTimesTo( &upgrades, min(f, upgradetest.ApricotPhase5), - defaultValidateEndTime, + genesistest.ValidatorEndTime, ) return &config.Config{ diff --git a/vms/platformvm/block/executor/helpers_test.go b/vms/platformvm/block/executor/helpers_test.go index c1d859e6f9c8..81c9481b950d 100644 --- a/vms/platformvm/block/executor/helpers_test.go +++ b/vms/platformvm/block/executor/helpers_test.go @@ -62,8 +62,6 @@ const ( var ( defaultMinStakingDuration = 24 * time.Hour defaultMaxStakingDuration = 365 * 24 * time.Hour - defaultValidateStartTime = genesistest.Time - defaultValidateEndTime = defaultValidateStartTime.Add(10 * defaultMinStakingDuration) preFundedKeys = secp256k1.TestKeys() avaxAssetID = ids.ID{'y', 'e', 'e', 't'} defaultTxFee = uint64(100) @@ -294,7 +292,7 @@ func defaultConfig(f upgradetest.Fork) *config.Config { upgradetest.SetTimesTo( &upgrades, min(f, upgradetest.ApricotPhase5), - defaultValidateEndTime, + genesistest.ValidatorEndTime, ) return &config.Config{ diff --git a/vms/platformvm/block/executor/proposal_block_test.go b/vms/platformvm/block/executor/proposal_block_test.go index d50a858b1658..cab87bd3b6a8 100644 --- a/vms/platformvm/block/executor/proposal_block_test.go +++ b/vms/platformvm/block/executor/proposal_block_test.go @@ -718,14 +718,13 @@ func TestBanffProposalBlockRemoveSubnetValidator(t *testing.T) { // Add a subnet validator to the staker set subnetValidatorNodeID := genesisNodeIDs[0] - subnetVdr1StartTime := defaultValidateStartTime - subnetVdr1EndTime := defaultValidateStartTime.Add(defaultMinStakingDuration) + subnetVdr1EndTime := genesistest.Time.Add(defaultMinStakingDuration) builder, signer := env.factory.NewWallet(preFundedKeys[0], preFundedKeys[1]) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: subnetValidatorNodeID, - Start: uint64(subnetVdr1StartTime.Unix()), + Start: genesistest.TimeUnix, End: uint64(subnetVdr1EndTime.Unix()), Wght: 1, }, @@ -785,12 +784,11 @@ func TestBanffProposalBlockRemoveSubnetValidator(t *testing.T) { // add Staker0 (with the right end time) to state // so to allow proposalBlk issuance - staker0StartTime := defaultValidateStartTime staker0EndTime := subnetVdr1EndTime uVdrTx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: ids.GenerateTestNodeID(), - Start: uint64(staker0StartTime.Unix()), + Start: genesistest.TimeUnix, End: uint64(staker0EndTime.Unix()), Wght: 10, }, diff --git a/vms/platformvm/block/executor/standard_block_test.go b/vms/platformvm/block/executor/standard_block_test.go index 8b076da56d8c..1cd59106e5aa 100644 --- a/vms/platformvm/block/executor/standard_block_test.go +++ b/vms/platformvm/block/executor/standard_block_test.go @@ -603,14 +603,13 @@ func TestBanffStandardBlockRemoveSubnetValidator(t *testing.T) { // Add a subnet validator to the staker set subnetValidatorNodeID := genesisNodeIDs[0] - subnetVdr1StartTime := defaultValidateStartTime - subnetVdr1EndTime := defaultValidateStartTime.Add(defaultMinStakingDuration) + subnetVdr1EndTime := genesistest.Time.Add(defaultMinStakingDuration) builder, signer := env.factory.NewWallet(preFundedKeys[0], preFundedKeys[1]) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: subnetValidatorNodeID, - Start: uint64(subnetVdr1StartTime.Unix()), + Start: genesistest.TimeUnix, End: uint64(subnetVdr1EndTime.Unix()), Wght: 1, }, diff --git a/vms/platformvm/genesis/genesistest/helper.go b/vms/platformvm/genesis/genesistest/helper.go index f1914efaeedb..b08ecfdd8f12 100644 --- a/vms/platformvm/genesis/genesistest/helper.go +++ b/vms/platformvm/genesis/genesistest/helper.go @@ -25,13 +25,10 @@ const ( defaultMinStakingDuration = 24 * time.Hour defaultMinValidatorStake = 5 * units.MilliAvax defaultBalance = 100 * defaultMinValidatorStake - defaultValidateDuration = 20 * defaultMinStakingDuration ) var ( - defaultValidateStartTime = Time - defaultValidateEndTime = defaultValidateStartTime.Add(defaultValidateDuration) - preFundedKeys = secp256k1.TestKeys() + preFundedKeys = secp256k1.TestKeys() // Node IDs of genesis validators. Initialized in init function GenesisNodeIDs []ids.NodeID @@ -65,8 +62,8 @@ func BuildGenesisTest(t *testing.T, avaxAssetID ids.ID) []byte { require.NoError(err) genesisValidators[i] = api.GenesisPermissionlessValidator{ GenesisValidator: api.GenesisValidator{ - StartTime: json.Uint64(defaultValidateStartTime.Unix()), - EndTime: json.Uint64(defaultValidateEndTime.Unix()), + StartTime: json.Uint64(TimeUnix), + EndTime: json.Uint64(ValidatorEndTimeUnix), NodeID: nodeID, }, RewardOwner: &api.Owner{ diff --git a/vms/platformvm/service_test.go b/vms/platformvm/service_test.go index e94c59c418dd..5e2e5514f5c2 100644 --- a/vms/platformvm/service_test.go +++ b/vms/platformvm/service_test.go @@ -492,13 +492,12 @@ func TestGetStake(t *testing.T) { // Add a delegator stakeAmount := service.vm.MinDelegatorStake + 12345 delegatorNodeID := genesisNodeIDs[0] - delegatorStartTime := defaultValidateStartTime delegatorEndTime := genesistest.Time.Add(defaultMinStakingDuration) builder, signer := factory.NewWallet(keys[0]) utx, err := builder.NewAddDelegatorTx( &txs.Validator{ NodeID: delegatorNodeID, - Start: uint64(delegatorStartTime.Unix()), + Start: genesistest.TimeUnix, End: uint64(delegatorEndTime.Unix()), Wght: stakeAmount, }, @@ -519,7 +518,7 @@ func TestGetStake(t *testing.T) { staker, err := state.NewCurrentStaker( tx.ID(), addDelTx, - delegatorStartTime, + genesistest.Time, 0, ) require.NoError(err) @@ -640,8 +639,7 @@ func TestGetCurrentValidators(t *testing.T) { // Add a delegator stakeAmount := service.vm.MinDelegatorStake + 12345 validatorNodeID := genesisNodeIDs[1] - delegatorStartTime := defaultValidateStartTime - delegatorEndTime := delegatorStartTime.Add(defaultMinStakingDuration) + delegatorEndTime := genesistest.Time.Add(defaultMinStakingDuration) service.vm.ctx.Lock.Lock() @@ -649,7 +647,7 @@ func TestGetCurrentValidators(t *testing.T) { utx, err := builder.NewAddDelegatorTx( &txs.Validator{ NodeID: validatorNodeID, - Start: uint64(delegatorStartTime.Unix()), + Start: genesistest.TimeUnix, End: uint64(delegatorEndTime.Unix()), Wght: stakeAmount, }, @@ -670,7 +668,7 @@ func TestGetCurrentValidators(t *testing.T) { staker, err := state.NewCurrentStaker( delTx.ID(), addDelTx, - delegatorStartTime, + genesistest.Time, 0, ) require.NoError(err) @@ -712,7 +710,7 @@ func TestGetCurrentValidators(t *testing.T) { require.Len(*innerVdr.Delegators, 1) delegator := (*innerVdr.Delegators)[0] require.Equal(delegator.NodeID, innerVdr.NodeID) - require.Equal(int64(delegator.StartTime), delegatorStartTime.Unix()) + require.Equal(uint64(delegator.StartTime), genesistest.TimeUnix) require.Equal(int64(delegator.EndTime), delegatorEndTime.Unix()) require.Equal(uint64(delegator.Weight), stakeAmount) } diff --git a/vms/platformvm/txs/executor/advance_time_test.go b/vms/platformvm/txs/executor/advance_time_test.go index e21018666898..630a0ecfd876 100644 --- a/vms/platformvm/txs/executor/advance_time_test.go +++ b/vms/platformvm/txs/executor/advance_time_test.go @@ -47,7 +47,7 @@ func TestAdvanceTimeTxUpdatePrimaryNetworkStakers(t *testing.T) { // Case: Timestamp is after next validator start time // Add a pending validator - pendingValidatorStartTime := defaultValidateStartTime.Add(1 * time.Second) + pendingValidatorStartTime := genesistest.Time.Add(1 * time.Second) pendingValidatorEndTime := pendingValidatorStartTime.Add(defaultMinStakingDuration) nodeID := ids.GenerateTestNodeID() addPendingValidatorTx, err := addPendingValidator( @@ -137,7 +137,7 @@ func TestAdvanceTimeTxTimestampTooLate(t *testing.T) { // Case: Timestamp is after next validator start time // Add a pending validator - pendingValidatorStartTime := defaultValidateStartTime.Add(1 * time.Second) + pendingValidatorStartTime := genesistest.Time.Add(1 * time.Second) pendingValidatorEndTime := pendingValidatorStartTime.Add(defaultMinStakingDuration) nodeID := ids.GenerateTestNodeID() _, err := addPendingValidator(env, pendingValidatorStartTime, pendingValidatorEndTime, nodeID, []*secp256k1.PrivateKey{preFundedKeys[0]}) @@ -171,11 +171,11 @@ func TestAdvanceTimeTxTimestampTooLate(t *testing.T) { defer env.ctx.Lock.Unlock() // fast forward clock to 10 seconds before genesis validators stop validating - env.clk.Set(defaultValidateEndTime.Add(-10 * time.Second)) + env.clk.Set(genesistest.ValidatorEndTime.Add(-10 * time.Second)) { // Proposes advancing timestamp to 1 second after genesis validators stop validating - tx, err := newAdvanceTimeTx(t, defaultValidateEndTime.Add(1*time.Second)) + tx, err := newAdvanceTimeTx(t, genesistest.ValidatorEndTime.Add(1*time.Second)) require.NoError(err) onCommitState, err := state.NewDiff(lastAcceptedID, env) @@ -229,8 +229,8 @@ func TestAdvanceTimeTxUpdateStakers(t *testing.T) { // Staker5: |--------------------| staker1 := staker{ nodeID: ids.GenerateTestNodeID(), - startTime: defaultValidateStartTime.Add(1 * time.Minute), - endTime: defaultValidateStartTime.Add(10 * defaultMinStakingDuration).Add(1 * time.Minute), + startTime: genesistest.Time.Add(1 * time.Minute), + endTime: genesistest.Time.Add(10 * defaultMinStakingDuration).Add(1 * time.Minute), } staker2 := staker{ nodeID: ids.GenerateTestNodeID(), @@ -488,15 +488,14 @@ func TestAdvanceTimeTxRemoveSubnetValidator(t *testing.T) { dummyHeight := uint64(1) // Add a subnet validator to the staker set subnetValidatorNodeID := genesisNodeIDs[0] - subnetVdr1StartTime := defaultValidateStartTime - subnetVdr1EndTime := defaultValidateStartTime.Add(defaultMinStakingDuration) + subnetVdr1EndTime := genesistest.Time.Add(defaultMinStakingDuration) builder, signer := env.factory.NewWallet(preFundedKeys[0], preFundedKeys[1]) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: subnetValidatorNodeID, - Start: uint64(subnetVdr1StartTime.Unix()), + Start: genesistest.TimeUnix, End: uint64(subnetVdr1EndTime.Unix()), Wght: 1, }, @@ -605,8 +604,8 @@ func TestTrackedSubnet(t *testing.T) { // Add a subnet validator to the staker set subnetValidatorNodeID := genesisNodeIDs[0] - subnetVdr1StartTime := defaultValidateStartTime.Add(1 * time.Minute) - subnetVdr1EndTime := defaultValidateStartTime.Add(10 * defaultMinStakingDuration).Add(1 * time.Minute) + subnetVdr1StartTime := genesistest.Time.Add(1 * time.Minute) + subnetVdr1EndTime := genesistest.Time.Add(10 * defaultMinStakingDuration).Add(1 * time.Minute) builder, signer := env.factory.NewWallet(preFundedKeys[0], preFundedKeys[1]) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ @@ -674,7 +673,7 @@ func TestAdvanceTimeTxDelegatorStakerWeight(t *testing.T) { // Case: Timestamp is after next validator start time // Add a pending validator - pendingValidatorStartTime := defaultValidateStartTime.Add(1 * time.Second) + pendingValidatorStartTime := genesistest.Time.Add(1 * time.Second) pendingValidatorEndTime := pendingValidatorStartTime.Add(defaultMaxStakingDuration) nodeID := ids.GenerateTestNodeID() _, err := addPendingValidator( @@ -784,7 +783,7 @@ func TestAdvanceTimeTxDelegatorStakers(t *testing.T) { // Case: Timestamp is after next validator start time // Add a pending validator - pendingValidatorStartTime := defaultValidateStartTime.Add(1 * time.Second) + pendingValidatorStartTime := genesistest.Time.Add(1 * time.Second) pendingValidatorEndTime := pendingValidatorStartTime.Add(defaultMinStakingDuration) nodeID := ids.GenerateTestNodeID() _, err := addPendingValidator(env, pendingValidatorStartTime, pendingValidatorEndTime, nodeID, []*secp256k1.PrivateKey{preFundedKeys[0]}) diff --git a/vms/platformvm/txs/executor/export_test.go b/vms/platformvm/txs/executor/export_test.go index d392f0bc9618..c285bcf609c7 100644 --- a/vms/platformvm/txs/executor/export_test.go +++ b/vms/platformvm/txs/executor/export_test.go @@ -14,6 +14,7 @@ import ( "github.com/ava-labs/avalanchego/upgrade/upgradetest" "github.com/ava-labs/avalanchego/utils/crypto/secp256k1" "github.com/ava-labs/avalanchego/vms/components/avax" + "github.com/ava-labs/avalanchego/vms/platformvm/genesis/genesistest" "github.com/ava-labs/avalanchego/vms/platformvm/state" "github.com/ava-labs/avalanchego/vms/secp256k1fx" @@ -39,7 +40,7 @@ func TestNewExportTx(t *testing.T) { description: "P->X export", destinationChainID: env.ctx.XChainID, sourceKeys: []*secp256k1.PrivateKey{sourceKey}, - timestamp: defaultValidateStartTime, + timestamp: genesistest.Time, }, { description: "P->C export", diff --git a/vms/platformvm/txs/executor/helpers_test.go b/vms/platformvm/txs/executor/helpers_test.go index 6e4955061cff..30f1f11e8973 100644 --- a/vms/platformvm/txs/executor/helpers_test.go +++ b/vms/platformvm/txs/executor/helpers_test.go @@ -51,13 +51,10 @@ const ( defaultMinStakingDuration = 24 * time.Hour defaultMinValidatorStake = 5 * units.MilliAvax defaultBalance = 100 * defaultMinValidatorStake - defaultValidateDuration = 20 * defaultMinStakingDuration ) var ( - defaultValidateStartTime = genesistest.Time - defaultValidateEndTime = defaultValidateStartTime.Add(defaultValidateDuration) - preFundedKeys = secp256k1.TestKeys() + preFundedKeys = secp256k1.TestKeys() // Node IDs of genesis validators. Initialized in init function genesisNodeIDs = genesistest.GenesisNodeIDs @@ -239,12 +236,12 @@ func addSubnet(t *testing.T, env *environment) { func defaultConfig(f upgradetest.Fork) *config.Config { upgrades := upgradetest.GetConfigWithUpgradeTime( f, - defaultValidateStartTime.Add(-2*time.Second), + genesistest.Time.Add(-2*time.Second), ) upgradetest.SetTimesTo( &upgrades, min(f, upgradetest.ApricotPhase5), - defaultValidateEndTime, + genesistest.ValidatorEndTime, ) return &config.Config{ @@ -275,7 +272,7 @@ func defaultClock(f upgradetest.Fork) *mockable.Clock { now := genesistest.Time if f >= upgradetest.Banff { // 1 second after active fork - now = defaultValidateEndTime.Add(-2 * time.Second) + now = genesistest.ValidatorEndTime.Add(-2 * time.Second) } clk := &mockable.Clock{} clk.Set(now) diff --git a/vms/platformvm/txs/executor/proposal_tx_executor_test.go b/vms/platformvm/txs/executor/proposal_tx_executor_test.go index 3f938a54ed8f..893228c9e59b 100644 --- a/vms/platformvm/txs/executor/proposal_tx_executor_test.go +++ b/vms/platformvm/txs/executor/proposal_tx_executor_test.go @@ -32,8 +32,8 @@ func TestProposalTxExecuteAddDelegator(t *testing.T) { nodeID := genesisNodeIDs[0] newValidatorID := ids.GenerateTestNodeID() - newValidatorStartTime := uint64(defaultValidateStartTime.Add(5 * time.Second).Unix()) - newValidatorEndTime := uint64(defaultValidateEndTime.Add(-5 * time.Second).Unix()) + newValidatorStartTime := uint64(genesistest.Time.Add(5 * time.Second).Unix()) + newValidatorEndTime := uint64(genesistest.ValidatorEndTime.Add(-5 * time.Second).Unix()) // [addMinStakeValidator] adds a new validator to the primary network's // pending validator set with the minimum staking amount @@ -130,8 +130,8 @@ func TestProposalTxExecuteAddDelegator(t *testing.T) { { description: "validator stops validating earlier than delegator", stakeAmount: env.config.MinDelegatorStake, - startTime: uint64(defaultValidateStartTime.Unix()) + 1, - endTime: uint64(defaultValidateEndTime.Unix()) + 1, + startTime: genesistest.TimeUnix + 1, + endTime: genesistest.ValidatorEndTimeUnix + 1, nodeID: nodeID, feeKeys: []*secp256k1.PrivateKey{preFundedKeys[0]}, setup: nil, @@ -141,8 +141,8 @@ func TestProposalTxExecuteAddDelegator(t *testing.T) { { description: "validator not in the current or pending validator sets", stakeAmount: env.config.MinDelegatorStake, - startTime: uint64(defaultValidateStartTime.Add(5 * time.Second).Unix()), - endTime: uint64(defaultValidateEndTime.Add(-5 * time.Second).Unix()), + startTime: uint64(genesistest.Time.Add(5 * time.Second).Unix()), + endTime: uint64(genesistest.ValidatorEndTime.Add(-5 * time.Second).Unix()), nodeID: newValidatorID, feeKeys: []*secp256k1.PrivateKey{preFundedKeys[0]}, setup: nil, @@ -186,7 +186,7 @@ func TestProposalTxExecuteAddDelegator(t *testing.T) { description: "starts delegating at current timestamp", stakeAmount: env.config.MinDelegatorStake, startTime: uint64(currentTimestamp.Unix()), - endTime: uint64(defaultValidateEndTime.Unix()), + endTime: genesistest.ValidatorEndTimeUnix, nodeID: nodeID, feeKeys: []*secp256k1.PrivateKey{preFundedKeys[0]}, setup: nil, @@ -196,8 +196,8 @@ func TestProposalTxExecuteAddDelegator(t *testing.T) { { description: "tx fee paying key has no funds", stakeAmount: env.config.MinDelegatorStake, - startTime: uint64(defaultValidateStartTime.Unix()) + 1, - endTime: uint64(defaultValidateEndTime.Unix()), + startTime: genesistest.TimeUnix + 1, + endTime: genesistest.ValidatorEndTimeUnix, nodeID: nodeID, feeKeys: []*secp256k1.PrivateKey{preFundedKeys[1]}, setup: func(env *environment) { // Remove all UTXOs owned by keys[1] @@ -224,7 +224,7 @@ func TestProposalTxExecuteAddDelegator(t *testing.T) { nodeID: newValidatorID, feeKeys: []*secp256k1.PrivateKey{preFundedKeys[0]}, setup: addMaxStakeValidator, - AP3Time: defaultValidateEndTime, + AP3Time: genesistest.ValidatorEndTime, expectedErr: nil, }, { @@ -303,8 +303,8 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: nodeID, - Start: uint64(defaultValidateStartTime.Unix()) + 1, - End: uint64(defaultValidateEndTime.Unix()) + 1, + Start: genesistest.TimeUnix + 1, + End: genesistest.ValidatorEndTimeUnix + 1, Wght: defaultWeight, }, Subnet: testSubnet1.ID(), @@ -342,8 +342,8 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: nodeID, - Start: uint64(defaultValidateStartTime.Unix()) + 1, - End: uint64(defaultValidateEndTime.Unix()), + Start: genesistest.TimeUnix + 1, + End: genesistest.ValidatorEndTimeUnix, Wght: defaultWeight, }, Subnet: testSubnet1.ID(), @@ -373,7 +373,7 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { // Add a validator to pending validator set of primary network // Starts validating primary network 10 seconds after genesis pendingDSValidatorID := ids.GenerateTestNodeID() - dsStartTime := defaultValidateStartTime.Add(10 * time.Second) + dsStartTime := genesistest.Time.Add(10 * time.Second) dsEndTime := dsStartTime.Add(5 * defaultMinStakingDuration) builder, signer := env.factory.NewWallet(preFundedKeys[0]) @@ -559,7 +559,7 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { // Case: Proposed validator start validating at/before current timestamp // First, advance the timestamp - newTimestamp := defaultValidateStartTime.Add(2 * time.Second) + newTimestamp := genesistest.Time.Add(2 * time.Second) env.state.SetTimestamp(newTimestamp) { @@ -598,7 +598,7 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { } // reset the timestamp - env.state.SetTimestamp(defaultValidateStartTime) + env.state.SetTimestamp(genesistest.Time) // Case: Proposed validator already validating the subnet // First, add validator as validator of subnet @@ -607,8 +607,8 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: nodeID, - Start: uint64(defaultValidateStartTime.Unix()), - End: uint64(defaultValidateEndTime.Unix()), + Start: genesistest.TimeUnix, + End: genesistest.ValidatorEndTimeUnix, Wght: defaultWeight, }, Subnet: testSubnet1.ID(), @@ -639,8 +639,8 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: nodeID, - Start: uint64(defaultValidateStartTime.Unix()) + 1, - End: uint64(defaultValidateEndTime.Unix()), + Start: genesistest.TimeUnix + 1, + End: genesistest.ValidatorEndTimeUnix, Wght: defaultWeight, }, Subnet: testSubnet1.ID(), @@ -679,8 +679,8 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: nodeID, - Start: uint64(defaultValidateStartTime.Unix()) + 1, - End: uint64(defaultValidateStartTime.Add(defaultMinStakingDuration).Unix()) + 1, + Start: genesistest.TimeUnix + 1, + End: uint64(genesistest.Time.Add(defaultMinStakingDuration).Unix()) + 1, Wght: defaultWeight, }, Subnet: testSubnet1.ID(), @@ -722,8 +722,8 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: nodeID, - Start: uint64(defaultValidateStartTime.Unix()) + 1, - End: uint64(defaultValidateStartTime.Add(defaultMinStakingDuration).Unix()) + 1, + Start: genesistest.TimeUnix + 1, + End: uint64(genesistest.Time.Add(defaultMinStakingDuration).Unix()) + 1, Wght: defaultWeight, }, Subnet: testSubnet1.ID(), @@ -764,8 +764,8 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: nodeID, - Start: uint64(defaultValidateStartTime.Unix()) + 1, - End: uint64(defaultValidateStartTime.Add(defaultMinStakingDuration).Unix()) + 1, + Start: genesistest.TimeUnix + 1, + End: uint64(genesistest.Time.Add(defaultMinStakingDuration).Unix()) + 1, Wght: defaultWeight, }, Subnet: testSubnet1.ID(), @@ -824,7 +824,7 @@ func TestProposalTxExecuteAddValidator(t *testing.T) { &txs.Validator{ NodeID: nodeID, Start: uint64(chainTime.Unix()), - End: uint64(defaultValidateEndTime.Unix()), + End: genesistest.ValidatorEndTimeUnix, Wght: env.config.MinValidatorStake, }, &secp256k1fx.OutputOwners{ @@ -863,8 +863,8 @@ func TestProposalTxExecuteAddValidator(t *testing.T) { utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID, - Start: uint64(defaultValidateStartTime.Unix()) + 1, - End: uint64(defaultValidateEndTime.Unix()), + Start: genesistest.TimeUnix + 1, + End: genesistest.ValidatorEndTimeUnix, Wght: env.config.MinValidatorStake, }, &secp256k1fx.OutputOwners{ @@ -897,7 +897,7 @@ func TestProposalTxExecuteAddValidator(t *testing.T) { { // Case: Validator in pending validator set of primary network - startTime := defaultValidateStartTime.Add(1 * time.Second) + startTime := genesistest.Time.Add(1 * time.Second) builder, signer := env.factory.NewWallet(preFundedKeys[0]) utx, err := builder.NewAddValidatorTx( &txs.Validator{ @@ -955,8 +955,8 @@ func TestProposalTxExecuteAddValidator(t *testing.T) { utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: ids.GenerateTestNodeID(), - Start: uint64(defaultValidateStartTime.Unix()) + 1, - End: uint64(defaultValidateEndTime.Unix()), + Start: genesistest.TimeUnix + 1, + End: genesistest.ValidatorEndTimeUnix, Wght: env.config.MinValidatorStake, }, &secp256k1fx.OutputOwners{ diff --git a/vms/platformvm/txs/executor/reward_validator_test.go b/vms/platformvm/txs/executor/reward_validator_test.go index 04dc3c27af9a..f96c07b32cb3 100644 --- a/vms/platformvm/txs/executor/reward_validator_test.go +++ b/vms/platformvm/txs/executor/reward_validator_test.go @@ -18,6 +18,7 @@ import ( "github.com/ava-labs/avalanchego/utils/math" "github.com/ava-labs/avalanchego/utils/set" "github.com/ava-labs/avalanchego/vms/components/avax" + "github.com/ava-labs/avalanchego/vms/platformvm/genesis/genesistest" "github.com/ava-labs/avalanchego/vms/platformvm/reward" "github.com/ava-labs/avalanchego/vms/platformvm/state" "github.com/ava-labs/avalanchego/vms/platformvm/status" @@ -137,7 +138,7 @@ func TestRewardValidatorTxExecuteOnCommit(t *testing.T) { onCommitBalance, err := avax.GetBalance(env.state, stakeOwners) require.NoError(err) - require.Equal(oldBalance+stakerToRemove.Weight+27697, onCommitBalance) + require.Equal(oldBalance+stakerToRemove.Weight+38944, onCommitBalance) } func TestRewardValidatorTxExecuteOnAbort(t *testing.T) { @@ -246,8 +247,8 @@ func TestRewardDelegatorTxExecuteOnCommitPreDelegateeDeferral(t *testing.T) { vdrRewardAddress := ids.GenerateTestShortID() delRewardAddress := ids.GenerateTestShortID() - vdrStartTime := uint64(defaultValidateStartTime.Unix()) + 1 - vdrEndTime := uint64(defaultValidateStartTime.Add(2 * defaultMinStakingDuration).Unix()) + vdrStartTime := genesistest.TimeUnix + 1 + vdrEndTime := uint64(genesistest.Time.Add(2 * defaultMinStakingDuration).Unix()) vdrNodeID := ids.GenerateTestNodeID() builder, signer := env.factory.NewWallet(preFundedKeys[0]) @@ -380,8 +381,8 @@ func TestRewardDelegatorTxExecuteOnCommitPostDelegateeDeferral(t *testing.T) { vdrRewardAddress := ids.GenerateTestShortID() delRewardAddress := ids.GenerateTestShortID() - vdrStartTime := uint64(defaultValidateStartTime.Unix()) + 1 - vdrEndTime := uint64(defaultValidateStartTime.Add(2 * defaultMinStakingDuration).Unix()) + vdrStartTime := genesistest.TimeUnix + 1 + vdrEndTime := uint64(genesistest.Time.Add(2 * defaultMinStakingDuration).Unix()) vdrNodeID := ids.GenerateTestNodeID() builder, signer := env.factory.NewWallet(preFundedKeys[0]) @@ -610,8 +611,8 @@ func TestRewardDelegatorTxAndValidatorTxExecuteOnCommitPostDelegateeDeferral(t * vdrRewardAddress := ids.GenerateTestShortID() delRewardAddress := ids.GenerateTestShortID() - vdrStartTime := uint64(defaultValidateStartTime.Unix()) + 1 - vdrEndTime := uint64(defaultValidateStartTime.Add(2 * defaultMinStakingDuration).Unix()) + vdrStartTime := genesistest.TimeUnix + 1 + vdrEndTime := uint64(genesistest.Time.Add(2 * defaultMinStakingDuration).Unix()) vdrNodeID := ids.GenerateTestNodeID() builder, signer := env.factory.NewWallet(preFundedKeys[0]) @@ -786,8 +787,8 @@ func TestRewardDelegatorTxExecuteOnAbort(t *testing.T) { vdrRewardAddress := ids.GenerateTestShortID() delRewardAddress := ids.GenerateTestShortID() - vdrStartTime := uint64(defaultValidateStartTime.Unix()) + 1 - vdrEndTime := uint64(defaultValidateStartTime.Add(2 * defaultMinStakingDuration).Unix()) + vdrStartTime := genesistest.TimeUnix + 1 + vdrEndTime := uint64(genesistest.Time.Add(2 * defaultMinStakingDuration).Unix()) vdrNodeID := ids.GenerateTestNodeID() builder, signer := env.factory.NewWallet(preFundedKeys[0]) diff --git a/vms/platformvm/txs/executor/standard_tx_executor_test.go b/vms/platformvm/txs/executor/standard_tx_executor_test.go index 838339d2c0eb..c92f3ac81d2c 100644 --- a/vms/platformvm/txs/executor/standard_tx_executor_test.go +++ b/vms/platformvm/txs/executor/standard_tx_executor_test.go @@ -54,7 +54,7 @@ func TestStandardTxExecutorAddValidatorTxEmptyID(t *testing.T) { defer env.ctx.Lock.Unlock() chainTime := env.state.GetTimestamp() - startTime := defaultValidateStartTime.Add(1 * time.Second) + startTime := genesistest.Time.Add(1 * time.Second) tests := []struct { banffTime time.Time @@ -82,7 +82,7 @@ func TestStandardTxExecutorAddValidatorTxEmptyID(t *testing.T) { &txs.Validator{ NodeID: ids.EmptyNodeID, Start: uint64(startTime.Unix()), - End: uint64(defaultValidateEndTime.Unix()), + End: genesistest.ValidatorEndTimeUnix, Wght: env.config.MinValidatorStake, }, &secp256k1fx.OutputOwners{ @@ -116,8 +116,8 @@ func TestStandardTxExecutorAddDelegator(t *testing.T) { nodeID := genesisNodeIDs[0] newValidatorID := ids.GenerateTestNodeID() - newValidatorStartTime := defaultValidateStartTime.Add(5 * time.Second) - newValidatorEndTime := defaultValidateEndTime.Add(-5 * time.Second) + newValidatorStartTime := genesistest.Time.Add(5 * time.Second) + newValidatorEndTime := genesistest.ValidatorEndTime.Add(-5 * time.Second) // [addMinStakeValidator] adds a new validator to the primary network's // pending validator set with the minimum staking amount @@ -214,8 +214,8 @@ func TestStandardTxExecutorAddDelegator(t *testing.T) { { description: "validator stops validating earlier than delegator", stakeAmount: env.config.MinDelegatorStake, - startTime: defaultValidateStartTime.Add(time.Second), - endTime: defaultValidateEndTime.Add(time.Second), + startTime: genesistest.Time.Add(time.Second), + endTime: genesistest.ValidatorEndTime.Add(time.Second), nodeID: nodeID, feeKeys: []*secp256k1.PrivateKey{preFundedKeys[0]}, setup: nil, @@ -225,8 +225,8 @@ func TestStandardTxExecutorAddDelegator(t *testing.T) { { description: "validator not in the current or pending validator sets", stakeAmount: env.config.MinDelegatorStake, - startTime: defaultValidateStartTime.Add(5 * time.Second), - endTime: defaultValidateEndTime.Add(-5 * time.Second), + startTime: genesistest.Time.Add(5 * time.Second), + endTime: genesistest.ValidatorEndTime.Add(-5 * time.Second), nodeID: newValidatorID, feeKeys: []*secp256k1.PrivateKey{preFundedKeys[0]}, setup: nil, @@ -270,7 +270,7 @@ func TestStandardTxExecutorAddDelegator(t *testing.T) { description: "starts delegating at current timestamp", stakeAmount: env.config.MinDelegatorStake, // weight startTime: currentTimestamp, // start time - endTime: defaultValidateEndTime, // end time + endTime: genesistest.ValidatorEndTime, // end time nodeID: nodeID, // node ID feeKeys: []*secp256k1.PrivateKey{preFundedKeys[0]}, // tx fee payer setup: nil, @@ -280,8 +280,8 @@ func TestStandardTxExecutorAddDelegator(t *testing.T) { { description: "tx fee paying key has no funds", stakeAmount: env.config.MinDelegatorStake, // weight - startTime: defaultValidateStartTime.Add(time.Second), // start time - endTime: defaultValidateEndTime, // end time + startTime: genesistest.Time.Add(time.Second), // start time + endTime: genesistest.ValidatorEndTime, // end time nodeID: nodeID, // node ID feeKeys: []*secp256k1.PrivateKey{preFundedKeys[1]}, // tx fee payer setup: func(env *environment) { // Remove all UTXOs owned by keys[1] @@ -308,7 +308,7 @@ func TestStandardTxExecutorAddDelegator(t *testing.T) { nodeID: newValidatorID, feeKeys: []*secp256k1.PrivateKey{preFundedKeys[0]}, setup: addMaxStakeValidator, - AP3Time: defaultValidateEndTime, + AP3Time: genesistest.ValidatorEndTime, expectedExecutionErr: nil, }, { @@ -381,14 +381,14 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { // Case: Proposed validator currently validating primary network // but stops validating subnet after stops validating primary network // (note that keys[0] is a genesis validator) - startTime := defaultValidateStartTime.Add(time.Second) + startTime := genesistest.Time.Add(time.Second) builder, signer := env.factory.NewWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: nodeID, Start: uint64(startTime.Unix()), - End: uint64(defaultValidateEndTime.Unix()) + 1, + End: genesistest.ValidatorEndTimeUnix + 1, Wght: defaultWeight, }, Subnet: testSubnet1.ID(), @@ -422,8 +422,8 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: nodeID, - Start: uint64(defaultValidateStartTime.Unix() + 1), - End: uint64(defaultValidateEndTime.Unix()), + Start: genesistest.TimeUnix + 1, + End: genesistest.ValidatorEndTimeUnix, Wght: defaultWeight, }, Subnet: testSubnet1.ID(), @@ -663,8 +663,8 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: nodeID, - Start: uint64(defaultValidateStartTime.Unix()), - End: uint64(defaultValidateEndTime.Unix()), + Start: genesistest.TimeUnix, + End: genesistest.ValidatorEndTimeUnix, Wght: defaultWeight, }, Subnet: testSubnet1.ID(), @@ -678,7 +678,7 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { staker, err = state.NewCurrentStaker( subnetTx.ID(), addSubnetValTx, - defaultValidateStartTime, + genesistest.Time, 0, ) require.NoError(err) @@ -690,14 +690,14 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { { // Node with ID nodeIDKey.PublicKey().Address() now validating subnet with ID testSubnet1.ID - startTime := defaultValidateStartTime.Add(time.Second) + startTime := genesistest.Time.Add(time.Second) builder, signer := env.factory.NewWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: nodeID, Start: uint64(startTime.Unix()), - End: uint64(defaultValidateEndTime.Unix()), + End: genesistest.ValidatorEndTimeUnix, Wght: defaultWeight, }, Subnet: testSubnet1.ID(), @@ -727,7 +727,7 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { { // Case: Duplicate signatures - startTime := defaultValidateStartTime.Add(time.Second) + startTime := genesistest.Time.Add(time.Second) builder, signer := env.factory.NewWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1], testSubnet1ControlKeys[2]) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ @@ -767,7 +767,7 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { { // Case: Too few signatures - startTime := defaultValidateStartTime.Add(time.Second) + startTime := genesistest.Time.Add(time.Second) builder, signer := env.factory.NewWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[2]) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ @@ -807,7 +807,7 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { { // Case: Control Signature from invalid key (keys[3] is not a control key) - startTime := defaultValidateStartTime.Add(time.Second) + startTime := genesistest.Time.Add(time.Second) builder, signer := env.factory.NewWallet(testSubnet1ControlKeys[0], preFundedKeys[1]) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ @@ -846,7 +846,7 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { { // Case: Proposed validator in pending validator set for subnet // First, add validator to pending validator set of subnet - startTime := defaultValidateStartTime.Add(time.Second) + startTime := genesistest.Time.Add(time.Second) builder, signer := env.factory.NewWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ @@ -867,7 +867,7 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { staker, err = state.NewCurrentStaker( subnetTx.ID(), addSubnetValTx, - defaultValidateStartTime, + genesistest.Time, 0, ) require.NoError(err) @@ -905,8 +905,8 @@ func TestEtnaStandardTxExecutorAddSubnetValidator(t *testing.T) { &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: nodeID, - Start: uint64(defaultValidateStartTime.Unix() + 1), - End: uint64(defaultValidateEndTime.Unix()), + Start: genesistest.TimeUnix + 1, + End: genesistest.ValidatorEndTimeUnix, Wght: defaultWeight, }, Subnet: testSubnet1.ID(), @@ -944,8 +944,8 @@ func TestBanffStandardTxExecutorAddValidator(t *testing.T) { utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID, - Start: uint64(defaultValidateStartTime.Unix()) - 1, - End: uint64(defaultValidateEndTime.Unix()), + Start: genesistest.TimeUnix - 1, + End: genesistest.ValidatorEndTimeUnix, Wght: env.config.MinValidatorStake, }, &secp256k1fx.OutputOwners{ @@ -974,7 +974,7 @@ func TestBanffStandardTxExecutorAddValidator(t *testing.T) { { // Case: Validator in current validator set of primary network - startTime := defaultValidateStartTime.Add(1 * time.Second) + startTime := genesistest.Time.Add(1 * time.Second) builder, signer := env.factory.NewWallet(preFundedKeys[0]) utx, err := builder.NewAddValidatorTx( &txs.Validator{ @@ -1021,7 +1021,7 @@ func TestBanffStandardTxExecutorAddValidator(t *testing.T) { { // Case: Validator in pending validator set of primary network - startTime := defaultValidateStartTime.Add(1 * time.Second) + startTime := genesistest.Time.Add(1 * time.Second) builder, signer := env.factory.NewWallet(preFundedKeys[0]) utx, err := builder.NewAddValidatorTx( &txs.Validator{ @@ -1065,7 +1065,7 @@ func TestBanffStandardTxExecutorAddValidator(t *testing.T) { { // Case: Validator doesn't have enough tokens to cover stake amount - startTime := defaultValidateStartTime.Add(1 * time.Second) + startTime := genesistest.Time.Add(1 * time.Second) builder, signer := env.factory.NewWallet(preFundedKeys[0]) utx, err := builder.NewAddValidatorTx( &txs.Validator{ diff --git a/vms/platformvm/vm_test.go b/vms/platformvm/vm_test.go index f107647bcc7c..34920d167736 100644 --- a/vms/platformvm/vm_test.go +++ b/vms/platformvm/vm_test.go @@ -92,12 +92,6 @@ var ( defaultTxFee = uint64(100) - // time that genesis validators start validating - defaultValidateStartTime = genesistest.Time - - // time that genesis validators stop validating - defaultValidateEndTime = defaultValidateStartTime.Add(10 * defaultMinStakingDuration) - latestForkTime = genesistest.Time.Add(time.Second) // each key controls an address that has [defaultBalance] AVAX at genesis @@ -172,8 +166,8 @@ func defaultGenesis(t *testing.T, avaxAssetID ids.ID) (*api.BuildGenesisArgs, [] require.NoError(err) genesisValidators[i] = api.GenesisPermissionlessValidator{ GenesisValidator: api.GenesisValidator{ - StartTime: json.Uint64(defaultValidateStartTime.Unix()), - EndTime: json.Uint64(defaultValidateEndTime.Unix()), + StartTime: json.Uint64(genesistest.TimeUnix), + EndTime: json.Uint64(genesistest.ValidatorEndTimeUnix), NodeID: nodeID, }, RewardOwner: &api.Owner{ @@ -614,7 +608,7 @@ func TestAddSubnetValidatorAccept(t *testing.T) { // create valid tx // note that [startTime, endTime] is a subset of time that keys[0] - // validates primary network ([defaultValidateStartTime, defaultValidateEndTime]) + // validates primary network ([genesistest.Time, genesistest.ValidatorEndTime]) builder, txSigner := factory.NewWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ @@ -666,7 +660,7 @@ func TestAddSubnetValidatorReject(t *testing.T) { // create valid tx // note that [startTime, endTime] is a subset of time that keys[0] - // validates primary network ([defaultValidateStartTime, defaultValidateEndTime]) + // validates primary network ([genesistest.Time, genesistest.ValidatorEndTime]) builder, txSigner := factory.NewWallet(testSubnet1ControlKeys[1], testSubnet1ControlKeys[2]) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ @@ -710,7 +704,7 @@ func TestRewardValidatorAccept(t *testing.T) { defer vm.ctx.Lock.Unlock() // Fast forward clock to time for genesis validators to leave - vm.clock.Set(defaultValidateEndTime) + vm.clock.Set(genesistest.ValidatorEndTime) // Advance time and create proposal to reward a genesis validator blk, err := vm.Builder.BuildBlock(context.Background()) @@ -748,7 +742,7 @@ func TestRewardValidatorAccept(t *testing.T) { // Verify that chain's timestamp has advanced timestamp := vm.state.GetTimestamp() - require.Equal(defaultValidateEndTime.Unix(), timestamp.Unix()) + require.Equal(genesistest.ValidatorEndTimeUnix, uint64(timestamp.Unix())) // Verify that rewarded validator has been removed. // Note that test genesis has multiple validators @@ -778,7 +772,7 @@ func TestRewardValidatorReject(t *testing.T) { defer vm.ctx.Lock.Unlock() // Fast forward clock to time for genesis validators to leave - vm.clock.Set(defaultValidateEndTime) + vm.clock.Set(genesistest.ValidatorEndTime) // Advance time and create proposal to reward a genesis validator blk, err := vm.Builder.BuildBlock(context.Background()) @@ -818,7 +812,7 @@ func TestRewardValidatorReject(t *testing.T) { // Verify that chain's timestamp has advanced timestamp := vm.state.GetTimestamp() - require.Equal(defaultValidateEndTime.Unix(), timestamp.Unix()) + require.Equal(genesistest.ValidatorEndTimeUnix, uint64(timestamp.Unix())) // Verify that rewarded validator has been removed. // Note that test genesis has multiple validators @@ -1754,23 +1748,23 @@ func TestMaxStakeAmount(t *testing.T) { }{ { description: "[validator.StartTime] == [startTime] < [endTime] == [validator.EndTime]", - startTime: defaultValidateStartTime, - endTime: defaultValidateEndTime, + startTime: genesistest.Time, + endTime: genesistest.ValidatorEndTime, }, { description: "[validator.StartTime] < [startTime] < [endTime] == [validator.EndTime]", - startTime: defaultValidateStartTime.Add(time.Minute), - endTime: defaultValidateEndTime, + startTime: genesistest.Time.Add(time.Minute), + endTime: genesistest.ValidatorEndTime, }, { description: "[validator.StartTime] == [startTime] < [endTime] < [validator.EndTime]", - startTime: defaultValidateStartTime, - endTime: defaultValidateEndTime.Add(-time.Minute), + startTime: genesistest.Time, + endTime: genesistest.ValidatorEndTime.Add(-time.Minute), }, { description: "[validator.StartTime] < [startTime] < [endTime] < [validator.EndTime]", - startTime: defaultValidateStartTime.Add(time.Minute), - endTime: defaultValidateEndTime.Add(-time.Minute), + startTime: genesistest.Time.Add(time.Minute), + endTime: genesistest.ValidatorEndTime.Add(-time.Minute), }, } @@ -1789,7 +1783,7 @@ func TestMaxStakeAmount(t *testing.T) { func TestUptimeDisallowedWithRestart(t *testing.T) { require := require.New(t) - latestForkTime = defaultValidateStartTime.Add(defaultMinStakingDuration) + latestForkTime = genesistest.Time.Add(defaultMinStakingDuration) db := memdb.New() firstDB := prefixdb.New([]byte{}, db) @@ -1829,8 +1823,8 @@ func TestUptimeDisallowedWithRestart(t *testing.T) { require.NoError(firstVM.SetState(context.Background(), snow.NormalOp)) // Fast forward clock so that validators meet 20% uptime required for reward - durationForReward := defaultValidateEndTime.Sub(defaultValidateStartTime) * firstUptimePercentage / 100 - vmStopTime := defaultValidateStartTime.Add(durationForReward) + durationForReward := genesistest.ValidatorEndTime.Sub(genesistest.Time) * firstUptimePercentage / 100 + vmStopTime := genesistest.Time.Add(durationForReward) firstVM.clock.Set(vmStopTime) // Shutdown VM to stop all genesis validator uptime. @@ -1880,7 +1874,7 @@ func TestUptimeDisallowedWithRestart(t *testing.T) { require.NoError(secondVM.SetState(context.Background(), snow.NormalOp)) // after restart and change of uptime required for reward, push validators to their end of life - secondVM.clock.Set(defaultValidateEndTime) + secondVM.clock.Set(genesistest.ValidatorEndTime) // evaluate a genesis validator for reward blk, err := secondVM.Builder.BuildBlock(context.Background()) @@ -1933,7 +1927,7 @@ func TestUptimeDisallowedWithRestart(t *testing.T) { func TestUptimeDisallowedAfterNeverConnecting(t *testing.T) { require := require.New(t) - latestForkTime = defaultValidateStartTime.Add(defaultMinStakingDuration) + latestForkTime = genesistest.Time.Add(defaultMinStakingDuration) db := memdb.New() @@ -1982,7 +1976,7 @@ func TestUptimeDisallowedAfterNeverConnecting(t *testing.T) { require.NoError(vm.SetState(context.Background(), snow.NormalOp)) // Fast forward clock to time for genesis validators to leave - vm.clock.Set(defaultValidateEndTime) + vm.clock.Set(genesistest.ValidatorEndTime) // evaluate a genesis validator for reward blk, err := vm.Builder.BuildBlock(context.Background()) From f57d6318254ae0a3f81478b3839f954232e55795 Mon Sep 17 00:00:00 2001 From: Stephen Buttolph Date: Thu, 22 Aug 2024 12:47:00 -0400 Subject: [PATCH 08/27] wip --- vms/platformvm/block/builder/helpers_test.go | 2 +- vms/platformvm/block/executor/helpers_test.go | 4 +- .../block/executor/proposal_block_test.go | 19 - .../block/executor/standard_block_test.go | 3 +- vms/platformvm/genesis/genesistest/genesis.go | 6 +- vms/platformvm/genesis/genesistest/helper.go | 15 +- vms/platformvm/state/state_test.go | 958 +++++++++--------- .../txs/executor/advance_time_test.go | 6 +- vms/platformvm/txs/executor/helpers_test.go | 9 +- .../txs/executor/proposal_tx_executor_test.go | 6 +- .../txs/executor/standard_tx_executor_test.go | 6 +- 11 files changed, 505 insertions(+), 529 deletions(-) diff --git a/vms/platformvm/block/builder/helpers_test.go b/vms/platformvm/block/builder/helpers_test.go index 24c3dd7cf514..9f7ad4f6e637 100644 --- a/vms/platformvm/block/builder/helpers_test.go +++ b/vms/platformvm/block/builder/helpers_test.go @@ -128,7 +128,7 @@ func newEnvironment(t *testing.T, f upgradetest.Fork) *environment { //nolint:un rewardsCalc := reward.NewCalculator(res.config.RewardConfig) res.state = statetest.New(t, statetest.Config{ DB: res.baseDB, - Genesis: genesistest.BuildGenesisTest(t, res.ctx.AVAXAssetID), + Genesis: genesistest.BuildGenesisTest(t), Validators: res.config.Validators, Context: res.ctx, Rewards: rewardsCalc, diff --git a/vms/platformvm/block/executor/helpers_test.go b/vms/platformvm/block/executor/helpers_test.go index 81c9481b950d..069d233e3e2b 100644 --- a/vms/platformvm/block/executor/helpers_test.go +++ b/vms/platformvm/block/executor/helpers_test.go @@ -63,7 +63,6 @@ var ( defaultMinStakingDuration = 24 * time.Hour defaultMaxStakingDuration = 365 * 24 * time.Hour preFundedKeys = secp256k1.TestKeys() - avaxAssetID = ids.ID{'y', 'e', 'e', 't'} defaultTxFee = uint64(100) testSubnet1 *txs.Tx @@ -128,7 +127,6 @@ func newEnvironment(t *testing.T, ctrl *gomock.Controller, f upgradetest.Fork) * m := atomic.NewMemory(atomicDB) res.ctx = snowtest.Context(t, snowtest.PChainID) - res.ctx.AVAXAssetID = avaxAssetID res.ctx.SharedMemory = m.NewSharedMemory(res.ctx.ChainID) res.fx = defaultFx(res.clk, res.ctx.Log, res.isBootstrapped.Get()) @@ -138,7 +136,7 @@ func newEnvironment(t *testing.T, ctrl *gomock.Controller, f upgradetest.Fork) * if ctrl == nil { res.state = statetest.New(t, statetest.Config{ DB: res.baseDB, - Genesis: genesistest.BuildGenesisTest(t, res.ctx.AVAXAssetID), + Genesis: genesistest.BuildGenesisTest(t), Validators: res.config.Validators, Context: res.ctx, Rewards: rewardsCalc, diff --git a/vms/platformvm/block/executor/proposal_block_test.go b/vms/platformvm/block/executor/proposal_block_test.go index cab87bd3b6a8..fb55fde2af74 100644 --- a/vms/platformvm/block/executor/proposal_block_test.go +++ b/vms/platformvm/block/executor/proposal_block_test.go @@ -509,25 +509,6 @@ func TestBanffProposalBlockUpdateStakers(t *testing.T) { staker5.nodeID: pending, }, }, - { - description: "advance time to staker5 start", - stakers: []staker{staker1, staker2, staker3, staker4, staker5}, - advanceTimeTo: []time.Time{staker1.startTime, staker2.startTime, staker3.startTime, staker5.startTime}, - expectedStakers: map[ids.NodeID]stakerStatus{ - staker1.nodeID: current, - - // Staker2's end time matches staker5's start time, so typically - // the block builder would produce a ProposalBlock to remove - // staker2 when advancing the time. However, this test injects - // staker0 into the staker set artificially to advance the time. - // This means that staker2 is not removed by the ProposalBlock - // when advancing the time. - staker2.nodeID: current, - staker3.nodeID: current, - staker4.nodeID: current, - staker5.nodeID: current, - }, - }, } for _, test := range tests { diff --git a/vms/platformvm/block/executor/standard_block_test.go b/vms/platformvm/block/executor/standard_block_test.go index 1cd59106e5aa..11490077c7a2 100644 --- a/vms/platformvm/block/executor/standard_block_test.go +++ b/vms/platformvm/block/executor/standard_block_test.go @@ -14,6 +14,7 @@ import ( "github.com/ava-labs/avalanchego/database" "github.com/ava-labs/avalanchego/ids" + "github.com/ava-labs/avalanchego/snow/snowtest" "github.com/ava-labs/avalanchego/upgrade/upgradetest" "github.com/ava-labs/avalanchego/utils/constants" "github.com/ava-labs/avalanchego/utils/crypto/secp256k1" @@ -143,7 +144,7 @@ func TestBanffStandardBlockTimeVerification(t *testing.T) { TxID: txID, }, Asset: avax.Asset{ - ID: avaxAssetID, + ID: snowtest.AVAXAssetID, }, Out: &secp256k1fx.TransferOutput{ Amt: env.config.StaticFeeConfig.CreateSubnetTxFee, diff --git a/vms/platformvm/genesis/genesistest/genesis.go b/vms/platformvm/genesis/genesistest/genesis.go index 4be77850ee55..d3228a410aa4 100644 --- a/vms/platformvm/genesis/genesistest/genesis.go +++ b/vms/platformvm/genesis/genesistest/genesis.go @@ -10,6 +10,7 @@ import ( "github.com/stretchr/testify/require" "github.com/ava-labs/avalanchego/ids" + "github.com/ava-labs/avalanchego/snow/snowtest" "github.com/ava-labs/avalanchego/upgrade" "github.com/ava-labs/avalanchego/utils/constants" "github.com/ava-labs/avalanchego/utils/units" @@ -23,8 +24,7 @@ import ( ) var ( - AVAXAssetID = ids.GenerateTestID() - AVAXAsset = avax.Asset{ID: AVAXAssetID} + AVAXAsset = avax.Asset{ID: snowtest.AVAXAssetID} ValidatorNodeID = ids.GenerateTestNodeID() Time = upgrade.InitiallyActiveTime @@ -88,7 +88,7 @@ func New(t testing.TB) *platformvmgenesis.Genesis { { UTXO: avax.UTXO{ UTXOID: avax.UTXOID{ - TxID: AVAXAssetID, + TxID: snowtest.AVAXAssetID, OutputIndex: 0, }, Asset: AVAXAsset, diff --git a/vms/platformvm/genesis/genesistest/helper.go b/vms/platformvm/genesis/genesistest/helper.go index b08ecfdd8f12..dea8e747d813 100644 --- a/vms/platformvm/genesis/genesistest/helper.go +++ b/vms/platformvm/genesis/genesistest/helper.go @@ -10,6 +10,7 @@ import ( "github.com/stretchr/testify/require" "github.com/ava-labs/avalanchego/ids" + "github.com/ava-labs/avalanchego/snow/snowtest" "github.com/ava-labs/avalanchego/utils/constants" "github.com/ava-labs/avalanchego/utils/crypto/secp256k1" "github.com/ava-labs/avalanchego/utils/formatting" @@ -31,17 +32,17 @@ var ( preFundedKeys = secp256k1.TestKeys() // Node IDs of genesis validators. Initialized in init function - GenesisNodeIDs []ids.NodeID + NodeIDs []ids.NodeID ) func init() { - GenesisNodeIDs = make([]ids.NodeID, len(preFundedKeys)) + NodeIDs = make([]ids.NodeID, len(preFundedKeys)) for i := range preFundedKeys { - GenesisNodeIDs[i] = ids.GenerateTestNodeID() + NodeIDs[i] = ids.GenerateTestNodeID() } } -func BuildGenesisTest(t *testing.T, avaxAssetID ids.ID) []byte { +func BuildGenesisTest(t *testing.T) []byte { require := require.New(t) genesisUTXOs := make([]api.UTXO, len(preFundedKeys)) @@ -55,8 +56,8 @@ func BuildGenesisTest(t *testing.T, avaxAssetID ids.ID) []byte { } } - genesisValidators := make([]api.GenesisPermissionlessValidator, len(GenesisNodeIDs)) - for i, nodeID := range GenesisNodeIDs { + genesisValidators := make([]api.GenesisPermissionlessValidator, len(NodeIDs)) + for i, nodeID := range NodeIDs { addr := preFundedKeys[i].Address() addrStr, err := address.FormatBech32(constants.UnitTestHRP, addr.Bytes()) require.NoError(err) @@ -80,7 +81,7 @@ func BuildGenesisTest(t *testing.T, avaxAssetID ids.ID) []byte { buildGenesisArgs := api.BuildGenesisArgs{ NetworkID: json.Uint32(constants.UnitTestID), - AvaxAssetID: avaxAssetID, + AvaxAssetID: snowtest.AVAXAssetID, UTXOs: genesisUTXOs, Validators: genesisValidators, Chains: nil, diff --git a/vms/platformvm/state/state_test.go b/vms/platformvm/state/state_test.go index 6a527a75dfde..982fbf56d47d 100644 --- a/vms/platformvm/state/state_test.go +++ b/vms/platformvm/state/state_test.go @@ -190,487 +190,487 @@ func TestPersistStakers(t *testing.T) { } }, }, - // "add current delegator": { - // storeStaker: func(r *require.Assertions, subnetID ids.ID, s *state) *Staker { - // // insert the delegator and its validator - // var ( - // valStartTime = time.Now().Truncate(time.Second).Unix() - // delStartTime = time.Unix(valStartTime, 0).Add(time.Hour).Unix() - // delEndTime = time.Unix(delStartTime, 0).Add(30 * 24 * time.Hour).Unix() - // valEndTime = time.Unix(valStartTime, 0).Add(365 * 24 * time.Hour).Unix() - - // validatorsData = txs.Validator{ - // NodeID: ids.GenerateTestNodeID(), - // End: uint64(valEndTime), - // Wght: 1234, - // } - // validatorReward uint64 = 5678 - - // delegatorData = txs.Validator{ - // NodeID: validatorsData.NodeID, - // End: uint64(delEndTime), - // Wght: validatorsData.Wght / 2, - // } - // delegatorReward uint64 = 5432 - // ) - - // utxVal := createPermissionlessValidatorTx(r, subnetID, validatorsData) - // addPermValTx := &txs.Tx{Unsigned: utxVal} - // r.NoError(addPermValTx.Initialize(txs.Codec)) - - // val, err := NewCurrentStaker( - // addPermValTx.ID(), - // utxVal, - // time.Unix(valStartTime, 0), - // validatorReward, - // ) - // r.NoError(err) - - // utxDel := createPermissionlessDelegatorTx(subnetID, delegatorData) - // addPermDelTx := &txs.Tx{Unsigned: utxDel} - // r.NoError(addPermDelTx.Initialize(txs.Codec)) - - // del, err := NewCurrentStaker( - // addPermDelTx.ID(), - // utxDel, - // time.Unix(delStartTime, 0), - // delegatorReward, - // ) - // r.NoError(err) - - // s.PutCurrentValidator(val) - // s.AddTx(addPermValTx, status.Committed) // this is currently needed to reload the staker - // r.NoError(s.Commit()) - - // s.PutCurrentDelegator(del) - // s.AddTx(addPermDelTx, status.Committed) // this is currently needed to reload the staker - // r.NoError(s.Commit()) - // return del - // }, - // checkStakerInState: func(r *require.Assertions, s *state, staker *Staker) { - // delIt, err := s.GetCurrentDelegatorIterator(staker.SubnetID, staker.NodeID) - // r.NoError(err) - // r.True(delIt.Next()) - // retrievedDelegator := delIt.Value() - // r.False(delIt.Next()) - // delIt.Release() - // r.Equal(staker, retrievedDelegator) - // }, - // checkValidatorsSet: func(r *require.Assertions, s *state, staker *Staker) { - // val, err := s.GetCurrentValidator(staker.SubnetID, staker.NodeID) - // r.NoError(err) - - // valsMap := s.validators.GetMap(staker.SubnetID) - // r.Contains(valsMap, staker.NodeID) - // valOut := valsMap[staker.NodeID] - // r.Equal(valOut.NodeID, staker.NodeID) - // r.Equal(valOut.Weight, val.Weight+staker.Weight) - // }, - // checkValidatorUptimes: func(*require.Assertions, *state, *Staker) {}, - // checkDiffs: func(r *require.Assertions, s *state, staker *Staker, height uint64) { - // // validator's weight must increase of delegator's weight amount - // weightDiffBytes, err := s.validatorWeightDiffsDB.Get(marshalDiffKey(staker.SubnetID, height, staker.NodeID)) - // r.NoError(err) - // weightDiff, err := unmarshalWeightDiff(weightDiffBytes) - // r.NoError(err) - // r.Equal(&ValidatorWeightDiff{ - // Decrease: false, - // Amount: staker.Weight, - // }, weightDiff) - // }, - // }, - // "add pending validator": { - // storeStaker: func(r *require.Assertions, subnetID ids.ID, s *state) *Staker { - // var ( - // startTime = time.Now().Unix() - // endTime = time.Now().Add(14 * 24 * time.Hour).Unix() - - // validatorsData = txs.Validator{ - // NodeID: ids.GenerateTestNodeID(), - // Start: uint64(startTime), - // End: uint64(endTime), - // Wght: 1234, - // } - // ) - - // utx := createPermissionlessValidatorTx(r, subnetID, validatorsData) - // addPermValTx := &txs.Tx{Unsigned: utx} - // r.NoError(addPermValTx.Initialize(txs.Codec)) - - // staker, err := NewPendingStaker( - // addPermValTx.ID(), - // utx, - // ) - // r.NoError(err) - - // s.PutPendingValidator(staker) - // s.AddTx(addPermValTx, status.Committed) // this is currently needed to reload the staker - // r.NoError(s.Commit()) - // return staker - // }, - // checkStakerInState: func(r *require.Assertions, s *state, staker *Staker) { - // retrievedStaker, err := s.GetPendingValidator(staker.SubnetID, staker.NodeID) - // r.NoError(err) - // r.Equal(staker, retrievedStaker) - // }, - // checkValidatorsSet: func(r *require.Assertions, s *state, staker *Staker) { - // // pending validators are not showed in validators set - // valsMap := s.validators.GetMap(staker.SubnetID) - // r.NotContains(valsMap, staker.NodeID) - // }, - // checkValidatorUptimes: func(r *require.Assertions, s *state, staker *Staker) { - // // pending validators uptime is not tracked - // _, _, err := s.GetUptime(staker.NodeID, staker.SubnetID) - // r.ErrorIs(err, database.ErrNotFound) - // }, - // checkDiffs: func(r *require.Assertions, s *state, staker *Staker, height uint64) { - // // pending validators weight diff and bls diffs are not stored - // _, err := s.validatorWeightDiffsDB.Get(marshalDiffKey(staker.SubnetID, height, staker.NodeID)) - // r.ErrorIs(err, database.ErrNotFound) - - // _, err = s.validatorPublicKeyDiffsDB.Get(marshalDiffKey(staker.SubnetID, height, staker.NodeID)) - // r.ErrorIs(err, database.ErrNotFound) - // }, - // }, - // "add pending delegator": { - // storeStaker: func(r *require.Assertions, subnetID ids.ID, s *state) *Staker { - // // insert the delegator and its validator - // var ( - // valStartTime = time.Now().Truncate(time.Second).Unix() - // delStartTime = time.Unix(valStartTime, 0).Add(time.Hour).Unix() - // delEndTime = time.Unix(delStartTime, 0).Add(30 * 24 * time.Hour).Unix() - // valEndTime = time.Unix(valStartTime, 0).Add(365 * 24 * time.Hour).Unix() - - // validatorsData = txs.Validator{ - // NodeID: ids.GenerateTestNodeID(), - // Start: uint64(valStartTime), - // End: uint64(valEndTime), - // Wght: 1234, - // } - - // delegatorData = txs.Validator{ - // NodeID: validatorsData.NodeID, - // Start: uint64(delStartTime), - // End: uint64(delEndTime), - // Wght: validatorsData.Wght / 2, - // } - // ) - - // utxVal := createPermissionlessValidatorTx(r, subnetID, validatorsData) - // addPermValTx := &txs.Tx{Unsigned: utxVal} - // r.NoError(addPermValTx.Initialize(txs.Codec)) - - // val, err := NewPendingStaker(addPermValTx.ID(), utxVal) - // r.NoError(err) - - // utxDel := createPermissionlessDelegatorTx(subnetID, delegatorData) - // addPermDelTx := &txs.Tx{Unsigned: utxDel} - // r.NoError(addPermDelTx.Initialize(txs.Codec)) - - // del, err := NewPendingStaker(addPermDelTx.ID(), utxDel) - // r.NoError(err) - - // s.PutPendingValidator(val) - // s.AddTx(addPermValTx, status.Committed) // this is currently needed to reload the staker - // r.NoError(s.Commit()) - - // s.PutPendingDelegator(del) - // s.AddTx(addPermDelTx, status.Committed) // this is currently needed to reload the staker - // r.NoError(s.Commit()) - - // return del - // }, - // checkStakerInState: func(r *require.Assertions, s *state, staker *Staker) { - // delIt, err := s.GetPendingDelegatorIterator(staker.SubnetID, staker.NodeID) - // r.NoError(err) - // r.True(delIt.Next()) - // retrievedDelegator := delIt.Value() - // r.False(delIt.Next()) - // delIt.Release() - // r.Equal(staker, retrievedDelegator) - // }, - // checkValidatorsSet: func(r *require.Assertions, s *state, staker *Staker) { - // valsMap := s.validators.GetMap(staker.SubnetID) - // r.NotContains(valsMap, staker.NodeID) - // }, - // checkValidatorUptimes: func(*require.Assertions, *state, *Staker) {}, - // checkDiffs: func(*require.Assertions, *state, *Staker, uint64) {}, - // }, - // "delete current validator": { - // storeStaker: func(r *require.Assertions, subnetID ids.ID, s *state) *Staker { - // // add them remove the validator - // var ( - // startTime = time.Now().Unix() - // endTime = time.Now().Add(14 * 24 * time.Hour).Unix() - - // validatorsData = txs.Validator{ - // NodeID: ids.GenerateTestNodeID(), - // End: uint64(endTime), - // Wght: 1234, - // } - // validatorReward uint64 = 5678 - // ) - - // utx := createPermissionlessValidatorTx(r, subnetID, validatorsData) - // addPermValTx := &txs.Tx{Unsigned: utx} - // r.NoError(addPermValTx.Initialize(txs.Codec)) - - // staker, err := NewCurrentStaker( - // addPermValTx.ID(), - // utx, - // time.Unix(startTime, 0), - // validatorReward, - // ) - // r.NoError(err) - - // s.PutCurrentValidator(staker) - // s.AddTx(addPermValTx, status.Committed) // this is currently needed to reload the staker - // r.NoError(s.Commit()) - - // s.DeleteCurrentValidator(staker) - // r.NoError(s.Commit()) - // return staker - // }, - // checkStakerInState: func(r *require.Assertions, s *state, staker *Staker) { - // _, err := s.GetCurrentValidator(staker.SubnetID, staker.NodeID) - // r.ErrorIs(err, database.ErrNotFound) - // }, - // checkValidatorsSet: func(r *require.Assertions, s *state, staker *Staker) { - // // deleted validators are not showed in the validators set anymore - // valsMap := s.validators.GetMap(staker.SubnetID) - // r.NotContains(valsMap, staker.NodeID) - // }, - // checkValidatorUptimes: func(r *require.Assertions, s *state, staker *Staker) { - // // uptimes of delete validators are dropped - // _, _, err := s.GetUptime(staker.NodeID, staker.SubnetID) - // r.ErrorIs(err, database.ErrNotFound) - // }, - // checkDiffs: func(r *require.Assertions, s *state, staker *Staker, height uint64) { - // weightDiffBytes, err := s.validatorWeightDiffsDB.Get(marshalDiffKey(staker.SubnetID, height, staker.NodeID)) - // r.NoError(err) - // weightDiff, err := unmarshalWeightDiff(weightDiffBytes) - // r.NoError(err) - // r.Equal(&ValidatorWeightDiff{ - // Decrease: true, - // Amount: staker.Weight, - // }, weightDiff) - - // blsDiffBytes, err := s.validatorPublicKeyDiffsDB.Get(marshalDiffKey(staker.SubnetID, height, staker.NodeID)) - // if staker.SubnetID == constants.PrimaryNetworkID { - // r.NoError(err) - // r.Equal(bls.PublicKeyFromValidUncompressedBytes(blsDiffBytes), staker.PublicKey) - // } else { - // r.ErrorIs(err, database.ErrNotFound) - // } - // }, - // }, - // "delete current delegator": { - // storeStaker: func(r *require.Assertions, subnetID ids.ID, s *state) *Staker { - // // insert validator and delegator, then remove the delegator - // var ( - // valStartTime = time.Now().Truncate(time.Second).Unix() - // delStartTime = time.Unix(valStartTime, 0).Add(time.Hour).Unix() - // delEndTime = time.Unix(delStartTime, 0).Add(30 * 24 * time.Hour).Unix() - // valEndTime = time.Unix(valStartTime, 0).Add(365 * 24 * time.Hour).Unix() - - // validatorsData = txs.Validator{ - // NodeID: ids.GenerateTestNodeID(), - // End: uint64(valEndTime), - // Wght: 1234, - // } - // validatorReward uint64 = 5678 - - // delegatorData = txs.Validator{ - // NodeID: validatorsData.NodeID, - // End: uint64(delEndTime), - // Wght: validatorsData.Wght / 2, - // } - // delegatorReward uint64 = 5432 - // ) - - // utxVal := createPermissionlessValidatorTx(r, subnetID, validatorsData) - // addPermValTx := &txs.Tx{Unsigned: utxVal} - // r.NoError(addPermValTx.Initialize(txs.Codec)) - - // val, err := NewCurrentStaker( - // addPermValTx.ID(), - // utxVal, - // time.Unix(valStartTime, 0), - // validatorReward, - // ) - // r.NoError(err) - - // utxDel := createPermissionlessDelegatorTx(subnetID, delegatorData) - // addPermDelTx := &txs.Tx{Unsigned: utxDel} - // r.NoError(addPermDelTx.Initialize(txs.Codec)) - - // del, err := NewCurrentStaker( - // addPermDelTx.ID(), - // utxDel, - // time.Unix(delStartTime, 0), - // delegatorReward, - // ) - // r.NoError(err) - - // s.PutCurrentValidator(val) - // s.AddTx(addPermValTx, status.Committed) // this is currently needed to reload the staker - - // s.PutCurrentDelegator(del) - // s.AddTx(addPermDelTx, status.Committed) // this is currently needed to reload the staker - // r.NoError(s.Commit()) - - // s.DeleteCurrentDelegator(del) - // r.NoError(s.Commit()) - - // return del - // }, - // checkStakerInState: func(r *require.Assertions, s *state, staker *Staker) { - // delIt, err := s.GetCurrentDelegatorIterator(staker.SubnetID, staker.NodeID) - // r.NoError(err) - // r.False(delIt.Next()) - // delIt.Release() - // }, - // checkValidatorsSet: func(r *require.Assertions, s *state, staker *Staker) { - // val, err := s.GetCurrentValidator(staker.SubnetID, staker.NodeID) - // r.NoError(err) - - // valsMap := s.validators.GetMap(staker.SubnetID) - // r.Contains(valsMap, staker.NodeID) - // valOut := valsMap[staker.NodeID] - // r.Equal(valOut.NodeID, staker.NodeID) - // r.Equal(valOut.Weight, val.Weight) - // }, - // checkValidatorUptimes: func(*require.Assertions, *state, *Staker) {}, - // checkDiffs: func(r *require.Assertions, s *state, staker *Staker, height uint64) { - // // validator's weight must decrease of delegator's weight amount - // weightDiffBytes, err := s.validatorWeightDiffsDB.Get(marshalDiffKey(staker.SubnetID, height, staker.NodeID)) - // r.NoError(err) - // weightDiff, err := unmarshalWeightDiff(weightDiffBytes) - // r.NoError(err) - // r.Equal(&ValidatorWeightDiff{ - // Decrease: true, - // Amount: staker.Weight, - // }, weightDiff) - // }, - // }, - // "delete pending validator": { - // storeStaker: func(r *require.Assertions, subnetID ids.ID, s *state) *Staker { - // var ( - // startTime = time.Now().Unix() - // endTime = time.Now().Add(14 * 24 * time.Hour).Unix() - - // validatorsData = txs.Validator{ - // NodeID: ids.GenerateTestNodeID(), - // Start: uint64(startTime), - // End: uint64(endTime), - // Wght: 1234, - // } - // ) - - // utx := createPermissionlessValidatorTx(r, subnetID, validatorsData) - // addPermValTx := &txs.Tx{Unsigned: utx} - // r.NoError(addPermValTx.Initialize(txs.Codec)) - - // staker, err := NewPendingStaker( - // addPermValTx.ID(), - // utx, - // ) - // r.NoError(err) - - // s.PutPendingValidator(staker) - // s.AddTx(addPermValTx, status.Committed) // this is currently needed to reload the staker - // r.NoError(s.Commit()) - - // s.DeletePendingValidator(staker) - // r.NoError(s.Commit()) - - // return staker - // }, - // checkStakerInState: func(r *require.Assertions, s *state, staker *Staker) { - // _, err := s.GetPendingValidator(staker.SubnetID, staker.NodeID) - // r.ErrorIs(err, database.ErrNotFound) - // }, - // checkValidatorsSet: func(r *require.Assertions, s *state, staker *Staker) { - // valsMap := s.validators.GetMap(staker.SubnetID) - // r.NotContains(valsMap, staker.NodeID) - // }, - // checkValidatorUptimes: func(r *require.Assertions, s *state, staker *Staker) { - // _, _, err := s.GetUptime(staker.NodeID, staker.SubnetID) - // r.ErrorIs(err, database.ErrNotFound) - // }, - // checkDiffs: func(r *require.Assertions, s *state, staker *Staker, height uint64) { - // _, err := s.validatorWeightDiffsDB.Get(marshalDiffKey(staker.SubnetID, height, staker.NodeID)) - // r.ErrorIs(err, database.ErrNotFound) - - // _, err = s.validatorPublicKeyDiffsDB.Get(marshalDiffKey(staker.SubnetID, height, staker.NodeID)) - // r.ErrorIs(err, database.ErrNotFound) - // }, - // }, - // "delete pending delegator": { - // storeStaker: func(r *require.Assertions, subnetID ids.ID, s *state) *Staker { - // // insert validator and delegator the remove the validator - // var ( - // valStartTime = time.Now().Truncate(time.Second).Unix() - // delStartTime = time.Unix(valStartTime, 0).Add(time.Hour).Unix() - // delEndTime = time.Unix(delStartTime, 0).Add(30 * 24 * time.Hour).Unix() - // valEndTime = time.Unix(valStartTime, 0).Add(365 * 24 * time.Hour).Unix() - - // validatorsData = txs.Validator{ - // NodeID: ids.GenerateTestNodeID(), - // Start: uint64(valStartTime), - // End: uint64(valEndTime), - // Wght: 1234, - // } - - // delegatorData = txs.Validator{ - // NodeID: validatorsData.NodeID, - // Start: uint64(delStartTime), - // End: uint64(delEndTime), - // Wght: validatorsData.Wght / 2, - // } - // ) - - // utxVal := createPermissionlessValidatorTx(r, subnetID, validatorsData) - // addPermValTx := &txs.Tx{Unsigned: utxVal} - // r.NoError(addPermValTx.Initialize(txs.Codec)) - - // val, err := NewPendingStaker(addPermValTx.ID(), utxVal) - // r.NoError(err) - - // utxDel := createPermissionlessDelegatorTx(subnetID, delegatorData) - // addPermDelTx := &txs.Tx{Unsigned: utxDel} - // r.NoError(addPermDelTx.Initialize(txs.Codec)) - - // del, err := NewPendingStaker(addPermDelTx.ID(), utxDel) - // r.NoError(err) - - // s.PutPendingValidator(val) - // s.AddTx(addPermValTx, status.Committed) // this is currently needed to reload the staker - - // s.PutPendingDelegator(del) - // s.AddTx(addPermDelTx, status.Committed) // this is currently needed to reload the staker - // r.NoError(s.Commit()) - - // s.DeletePendingDelegator(del) - // r.NoError(s.Commit()) - // return del - // }, - // checkStakerInState: func(r *require.Assertions, s *state, staker *Staker) { - // delIt, err := s.GetPendingDelegatorIterator(staker.SubnetID, staker.NodeID) - // r.NoError(err) - // r.False(delIt.Next()) - // delIt.Release() - // }, - // checkValidatorsSet: func(r *require.Assertions, s *state, staker *Staker) { - // valsMap := s.validators.GetMap(staker.SubnetID) - // r.NotContains(valsMap, staker.NodeID) - // }, - // checkValidatorUptimes: func(*require.Assertions, *state, *Staker) {}, - // checkDiffs: func(*require.Assertions, *state, *Staker, uint64) {}, - // }, + "add current delegator": { + storeStaker: func(r *require.Assertions, subnetID ids.ID, s *state) *Staker { + // insert the delegator and its validator + var ( + valStartTime = time.Now().Truncate(time.Second).Unix() + delStartTime = time.Unix(valStartTime, 0).Add(time.Hour).Unix() + delEndTime = time.Unix(delStartTime, 0).Add(30 * 24 * time.Hour).Unix() + valEndTime = time.Unix(valStartTime, 0).Add(365 * 24 * time.Hour).Unix() + + validatorsData = txs.Validator{ + NodeID: ids.GenerateTestNodeID(), + End: uint64(valEndTime), + Wght: 1234, + } + validatorReward uint64 = 5678 + + delegatorData = txs.Validator{ + NodeID: validatorsData.NodeID, + End: uint64(delEndTime), + Wght: validatorsData.Wght / 2, + } + delegatorReward uint64 = 5432 + ) + + utxVal := createPermissionlessValidatorTx(r, subnetID, validatorsData) + addPermValTx := &txs.Tx{Unsigned: utxVal} + r.NoError(addPermValTx.Initialize(txs.Codec)) + + val, err := NewCurrentStaker( + addPermValTx.ID(), + utxVal, + time.Unix(valStartTime, 0), + validatorReward, + ) + r.NoError(err) + + utxDel := createPermissionlessDelegatorTx(subnetID, delegatorData) + addPermDelTx := &txs.Tx{Unsigned: utxDel} + r.NoError(addPermDelTx.Initialize(txs.Codec)) + + del, err := NewCurrentStaker( + addPermDelTx.ID(), + utxDel, + time.Unix(delStartTime, 0), + delegatorReward, + ) + r.NoError(err) + + s.PutCurrentValidator(val) + s.AddTx(addPermValTx, status.Committed) // this is currently needed to reload the staker + r.NoError(s.Commit()) + + s.PutCurrentDelegator(del) + s.AddTx(addPermDelTx, status.Committed) // this is currently needed to reload the staker + r.NoError(s.Commit()) + return del + }, + checkStakerInState: func(r *require.Assertions, s *state, staker *Staker) { + delIt, err := s.GetCurrentDelegatorIterator(staker.SubnetID, staker.NodeID) + r.NoError(err) + r.True(delIt.Next()) + retrievedDelegator := delIt.Value() + r.False(delIt.Next()) + delIt.Release() + r.Equal(staker, retrievedDelegator) + }, + checkValidatorsSet: func(r *require.Assertions, s *state, staker *Staker) { + val, err := s.GetCurrentValidator(staker.SubnetID, staker.NodeID) + r.NoError(err) + + valsMap := s.validators.GetMap(staker.SubnetID) + r.Contains(valsMap, staker.NodeID) + valOut := valsMap[staker.NodeID] + r.Equal(valOut.NodeID, staker.NodeID) + r.Equal(valOut.Weight, val.Weight+staker.Weight) + }, + checkValidatorUptimes: func(*require.Assertions, *state, *Staker) {}, + checkDiffs: func(r *require.Assertions, s *state, staker *Staker, height uint64) { + // validator's weight must increase of delegator's weight amount + weightDiffBytes, err := s.validatorWeightDiffsDB.Get(marshalDiffKey(staker.SubnetID, height, staker.NodeID)) + r.NoError(err) + weightDiff, err := unmarshalWeightDiff(weightDiffBytes) + r.NoError(err) + r.Equal(&ValidatorWeightDiff{ + Decrease: false, + Amount: staker.Weight, + }, weightDiff) + }, + }, + "add pending validator": { + storeStaker: func(r *require.Assertions, subnetID ids.ID, s *state) *Staker { + var ( + startTime = time.Now().Unix() + endTime = time.Now().Add(14 * 24 * time.Hour).Unix() + + validatorsData = txs.Validator{ + NodeID: ids.GenerateTestNodeID(), + Start: uint64(startTime), + End: uint64(endTime), + Wght: 1234, + } + ) + + utx := createPermissionlessValidatorTx(r, subnetID, validatorsData) + addPermValTx := &txs.Tx{Unsigned: utx} + r.NoError(addPermValTx.Initialize(txs.Codec)) + + staker, err := NewPendingStaker( + addPermValTx.ID(), + utx, + ) + r.NoError(err) + + s.PutPendingValidator(staker) + s.AddTx(addPermValTx, status.Committed) // this is currently needed to reload the staker + r.NoError(s.Commit()) + return staker + }, + checkStakerInState: func(r *require.Assertions, s *state, staker *Staker) { + retrievedStaker, err := s.GetPendingValidator(staker.SubnetID, staker.NodeID) + r.NoError(err) + r.Equal(staker, retrievedStaker) + }, + checkValidatorsSet: func(r *require.Assertions, s *state, staker *Staker) { + // pending validators are not showed in validators set + valsMap := s.validators.GetMap(staker.SubnetID) + r.NotContains(valsMap, staker.NodeID) + }, + checkValidatorUptimes: func(r *require.Assertions, s *state, staker *Staker) { + // pending validators uptime is not tracked + _, _, err := s.GetUptime(staker.NodeID, staker.SubnetID) + r.ErrorIs(err, database.ErrNotFound) + }, + checkDiffs: func(r *require.Assertions, s *state, staker *Staker, height uint64) { + // pending validators weight diff and bls diffs are not stored + _, err := s.validatorWeightDiffsDB.Get(marshalDiffKey(staker.SubnetID, height, staker.NodeID)) + r.ErrorIs(err, database.ErrNotFound) + + _, err = s.validatorPublicKeyDiffsDB.Get(marshalDiffKey(staker.SubnetID, height, staker.NodeID)) + r.ErrorIs(err, database.ErrNotFound) + }, + }, + "add pending delegator": { + storeStaker: func(r *require.Assertions, subnetID ids.ID, s *state) *Staker { + // insert the delegator and its validator + var ( + valStartTime = time.Now().Truncate(time.Second).Unix() + delStartTime = time.Unix(valStartTime, 0).Add(time.Hour).Unix() + delEndTime = time.Unix(delStartTime, 0).Add(30 * 24 * time.Hour).Unix() + valEndTime = time.Unix(valStartTime, 0).Add(365 * 24 * time.Hour).Unix() + + validatorsData = txs.Validator{ + NodeID: ids.GenerateTestNodeID(), + Start: uint64(valStartTime), + End: uint64(valEndTime), + Wght: 1234, + } + + delegatorData = txs.Validator{ + NodeID: validatorsData.NodeID, + Start: uint64(delStartTime), + End: uint64(delEndTime), + Wght: validatorsData.Wght / 2, + } + ) + + utxVal := createPermissionlessValidatorTx(r, subnetID, validatorsData) + addPermValTx := &txs.Tx{Unsigned: utxVal} + r.NoError(addPermValTx.Initialize(txs.Codec)) + + val, err := NewPendingStaker(addPermValTx.ID(), utxVal) + r.NoError(err) + + utxDel := createPermissionlessDelegatorTx(subnetID, delegatorData) + addPermDelTx := &txs.Tx{Unsigned: utxDel} + r.NoError(addPermDelTx.Initialize(txs.Codec)) + + del, err := NewPendingStaker(addPermDelTx.ID(), utxDel) + r.NoError(err) + + s.PutPendingValidator(val) + s.AddTx(addPermValTx, status.Committed) // this is currently needed to reload the staker + r.NoError(s.Commit()) + + s.PutPendingDelegator(del) + s.AddTx(addPermDelTx, status.Committed) // this is currently needed to reload the staker + r.NoError(s.Commit()) + + return del + }, + checkStakerInState: func(r *require.Assertions, s *state, staker *Staker) { + delIt, err := s.GetPendingDelegatorIterator(staker.SubnetID, staker.NodeID) + r.NoError(err) + r.True(delIt.Next()) + retrievedDelegator := delIt.Value() + r.False(delIt.Next()) + delIt.Release() + r.Equal(staker, retrievedDelegator) + }, + checkValidatorsSet: func(r *require.Assertions, s *state, staker *Staker) { + valsMap := s.validators.GetMap(staker.SubnetID) + r.NotContains(valsMap, staker.NodeID) + }, + checkValidatorUptimes: func(*require.Assertions, *state, *Staker) {}, + checkDiffs: func(*require.Assertions, *state, *Staker, uint64) {}, + }, + "delete current validator": { + storeStaker: func(r *require.Assertions, subnetID ids.ID, s *state) *Staker { + // add them remove the validator + var ( + startTime = time.Now().Unix() + endTime = time.Now().Add(14 * 24 * time.Hour).Unix() + + validatorsData = txs.Validator{ + NodeID: ids.GenerateTestNodeID(), + End: uint64(endTime), + Wght: 1234, + } + validatorReward uint64 = 5678 + ) + + utx := createPermissionlessValidatorTx(r, subnetID, validatorsData) + addPermValTx := &txs.Tx{Unsigned: utx} + r.NoError(addPermValTx.Initialize(txs.Codec)) + + staker, err := NewCurrentStaker( + addPermValTx.ID(), + utx, + time.Unix(startTime, 0), + validatorReward, + ) + r.NoError(err) + + s.PutCurrentValidator(staker) + s.AddTx(addPermValTx, status.Committed) // this is currently needed to reload the staker + r.NoError(s.Commit()) + + s.DeleteCurrentValidator(staker) + r.NoError(s.Commit()) + return staker + }, + checkStakerInState: func(r *require.Assertions, s *state, staker *Staker) { + _, err := s.GetCurrentValidator(staker.SubnetID, staker.NodeID) + r.ErrorIs(err, database.ErrNotFound) + }, + checkValidatorsSet: func(r *require.Assertions, s *state, staker *Staker) { + // deleted validators are not showed in the validators set anymore + valsMap := s.validators.GetMap(staker.SubnetID) + r.NotContains(valsMap, staker.NodeID) + }, + checkValidatorUptimes: func(r *require.Assertions, s *state, staker *Staker) { + // uptimes of delete validators are dropped + _, _, err := s.GetUptime(staker.NodeID, staker.SubnetID) + r.ErrorIs(err, database.ErrNotFound) + }, + checkDiffs: func(r *require.Assertions, s *state, staker *Staker, height uint64) { + weightDiffBytes, err := s.validatorWeightDiffsDB.Get(marshalDiffKey(staker.SubnetID, height, staker.NodeID)) + r.NoError(err) + weightDiff, err := unmarshalWeightDiff(weightDiffBytes) + r.NoError(err) + r.Equal(&ValidatorWeightDiff{ + Decrease: true, + Amount: staker.Weight, + }, weightDiff) + + blsDiffBytes, err := s.validatorPublicKeyDiffsDB.Get(marshalDiffKey(staker.SubnetID, height, staker.NodeID)) + if staker.SubnetID == constants.PrimaryNetworkID { + r.NoError(err) + r.Equal(bls.PublicKeyFromValidUncompressedBytes(blsDiffBytes), staker.PublicKey) + } else { + r.ErrorIs(err, database.ErrNotFound) + } + }, + }, + "delete current delegator": { + storeStaker: func(r *require.Assertions, subnetID ids.ID, s *state) *Staker { + // insert validator and delegator, then remove the delegator + var ( + valStartTime = time.Now().Truncate(time.Second).Unix() + delStartTime = time.Unix(valStartTime, 0).Add(time.Hour).Unix() + delEndTime = time.Unix(delStartTime, 0).Add(30 * 24 * time.Hour).Unix() + valEndTime = time.Unix(valStartTime, 0).Add(365 * 24 * time.Hour).Unix() + + validatorsData = txs.Validator{ + NodeID: ids.GenerateTestNodeID(), + End: uint64(valEndTime), + Wght: 1234, + } + validatorReward uint64 = 5678 + + delegatorData = txs.Validator{ + NodeID: validatorsData.NodeID, + End: uint64(delEndTime), + Wght: validatorsData.Wght / 2, + } + delegatorReward uint64 = 5432 + ) + + utxVal := createPermissionlessValidatorTx(r, subnetID, validatorsData) + addPermValTx := &txs.Tx{Unsigned: utxVal} + r.NoError(addPermValTx.Initialize(txs.Codec)) + + val, err := NewCurrentStaker( + addPermValTx.ID(), + utxVal, + time.Unix(valStartTime, 0), + validatorReward, + ) + r.NoError(err) + + utxDel := createPermissionlessDelegatorTx(subnetID, delegatorData) + addPermDelTx := &txs.Tx{Unsigned: utxDel} + r.NoError(addPermDelTx.Initialize(txs.Codec)) + + del, err := NewCurrentStaker( + addPermDelTx.ID(), + utxDel, + time.Unix(delStartTime, 0), + delegatorReward, + ) + r.NoError(err) + + s.PutCurrentValidator(val) + s.AddTx(addPermValTx, status.Committed) // this is currently needed to reload the staker + + s.PutCurrentDelegator(del) + s.AddTx(addPermDelTx, status.Committed) // this is currently needed to reload the staker + r.NoError(s.Commit()) + + s.DeleteCurrentDelegator(del) + r.NoError(s.Commit()) + + return del + }, + checkStakerInState: func(r *require.Assertions, s *state, staker *Staker) { + delIt, err := s.GetCurrentDelegatorIterator(staker.SubnetID, staker.NodeID) + r.NoError(err) + r.False(delIt.Next()) + delIt.Release() + }, + checkValidatorsSet: func(r *require.Assertions, s *state, staker *Staker) { + val, err := s.GetCurrentValidator(staker.SubnetID, staker.NodeID) + r.NoError(err) + + valsMap := s.validators.GetMap(staker.SubnetID) + r.Contains(valsMap, staker.NodeID) + valOut := valsMap[staker.NodeID] + r.Equal(valOut.NodeID, staker.NodeID) + r.Equal(valOut.Weight, val.Weight) + }, + checkValidatorUptimes: func(*require.Assertions, *state, *Staker) {}, + checkDiffs: func(r *require.Assertions, s *state, staker *Staker, height uint64) { + // validator's weight must decrease of delegator's weight amount + weightDiffBytes, err := s.validatorWeightDiffsDB.Get(marshalDiffKey(staker.SubnetID, height, staker.NodeID)) + r.NoError(err) + weightDiff, err := unmarshalWeightDiff(weightDiffBytes) + r.NoError(err) + r.Equal(&ValidatorWeightDiff{ + Decrease: true, + Amount: staker.Weight, + }, weightDiff) + }, + }, + "delete pending validator": { + storeStaker: func(r *require.Assertions, subnetID ids.ID, s *state) *Staker { + var ( + startTime = time.Now().Unix() + endTime = time.Now().Add(14 * 24 * time.Hour).Unix() + + validatorsData = txs.Validator{ + NodeID: ids.GenerateTestNodeID(), + Start: uint64(startTime), + End: uint64(endTime), + Wght: 1234, + } + ) + + utx := createPermissionlessValidatorTx(r, subnetID, validatorsData) + addPermValTx := &txs.Tx{Unsigned: utx} + r.NoError(addPermValTx.Initialize(txs.Codec)) + + staker, err := NewPendingStaker( + addPermValTx.ID(), + utx, + ) + r.NoError(err) + + s.PutPendingValidator(staker) + s.AddTx(addPermValTx, status.Committed) // this is currently needed to reload the staker + r.NoError(s.Commit()) + + s.DeletePendingValidator(staker) + r.NoError(s.Commit()) + + return staker + }, + checkStakerInState: func(r *require.Assertions, s *state, staker *Staker) { + _, err := s.GetPendingValidator(staker.SubnetID, staker.NodeID) + r.ErrorIs(err, database.ErrNotFound) + }, + checkValidatorsSet: func(r *require.Assertions, s *state, staker *Staker) { + valsMap := s.validators.GetMap(staker.SubnetID) + r.NotContains(valsMap, staker.NodeID) + }, + checkValidatorUptimes: func(r *require.Assertions, s *state, staker *Staker) { + _, _, err := s.GetUptime(staker.NodeID, staker.SubnetID) + r.ErrorIs(err, database.ErrNotFound) + }, + checkDiffs: func(r *require.Assertions, s *state, staker *Staker, height uint64) { + _, err := s.validatorWeightDiffsDB.Get(marshalDiffKey(staker.SubnetID, height, staker.NodeID)) + r.ErrorIs(err, database.ErrNotFound) + + _, err = s.validatorPublicKeyDiffsDB.Get(marshalDiffKey(staker.SubnetID, height, staker.NodeID)) + r.ErrorIs(err, database.ErrNotFound) + }, + }, + "delete pending delegator": { + storeStaker: func(r *require.Assertions, subnetID ids.ID, s *state) *Staker { + // insert validator and delegator the remove the validator + var ( + valStartTime = time.Now().Truncate(time.Second).Unix() + delStartTime = time.Unix(valStartTime, 0).Add(time.Hour).Unix() + delEndTime = time.Unix(delStartTime, 0).Add(30 * 24 * time.Hour).Unix() + valEndTime = time.Unix(valStartTime, 0).Add(365 * 24 * time.Hour).Unix() + + validatorsData = txs.Validator{ + NodeID: ids.GenerateTestNodeID(), + Start: uint64(valStartTime), + End: uint64(valEndTime), + Wght: 1234, + } + + delegatorData = txs.Validator{ + NodeID: validatorsData.NodeID, + Start: uint64(delStartTime), + End: uint64(delEndTime), + Wght: validatorsData.Wght / 2, + } + ) + + utxVal := createPermissionlessValidatorTx(r, subnetID, validatorsData) + addPermValTx := &txs.Tx{Unsigned: utxVal} + r.NoError(addPermValTx.Initialize(txs.Codec)) + + val, err := NewPendingStaker(addPermValTx.ID(), utxVal) + r.NoError(err) + + utxDel := createPermissionlessDelegatorTx(subnetID, delegatorData) + addPermDelTx := &txs.Tx{Unsigned: utxDel} + r.NoError(addPermDelTx.Initialize(txs.Codec)) + + del, err := NewPendingStaker(addPermDelTx.ID(), utxDel) + r.NoError(err) + + s.PutPendingValidator(val) + s.AddTx(addPermValTx, status.Committed) // this is currently needed to reload the staker + + s.PutPendingDelegator(del) + s.AddTx(addPermDelTx, status.Committed) // this is currently needed to reload the staker + r.NoError(s.Commit()) + + s.DeletePendingDelegator(del) + r.NoError(s.Commit()) + return del + }, + checkStakerInState: func(r *require.Assertions, s *state, staker *Staker) { + delIt, err := s.GetPendingDelegatorIterator(staker.SubnetID, staker.NodeID) + r.NoError(err) + r.False(delIt.Next()) + delIt.Release() + }, + checkValidatorsSet: func(r *require.Assertions, s *state, staker *Staker) { + valsMap := s.validators.GetMap(staker.SubnetID) + r.NotContains(valsMap, staker.NodeID) + }, + checkValidatorUptimes: func(*require.Assertions, *state, *Staker) {}, + checkDiffs: func(*require.Assertions, *state, *Staker, uint64) {}, + }, } - subnetIDs := []ids.ID{constants.PrimaryNetworkID /*, ids.GenerateTestID()*/} + subnetIDs := []ids.ID{constants.PrimaryNetworkID, ids.GenerateTestID()} for _, subnetID := range subnetIDs { for name, test := range tests { t.Run(fmt.Sprintf("%s - subnetID %s", name, subnetID), func(t *testing.T) { diff --git a/vms/platformvm/txs/executor/advance_time_test.go b/vms/platformvm/txs/executor/advance_time_test.go index 630a0ecfd876..d71dfff3bd36 100644 --- a/vms/platformvm/txs/executor/advance_time_test.go +++ b/vms/platformvm/txs/executor/advance_time_test.go @@ -487,7 +487,7 @@ func TestAdvanceTimeTxRemoveSubnetValidator(t *testing.T) { dummyHeight := uint64(1) // Add a subnet validator to the staker set - subnetValidatorNodeID := genesisNodeIDs[0] + subnetValidatorNodeID := genesistest.NodeIDs[0] subnetVdr1EndTime := genesistest.Time.Add(defaultMinStakingDuration) builder, signer := env.factory.NewWallet(preFundedKeys[0], preFundedKeys[1]) @@ -523,7 +523,7 @@ func TestAdvanceTimeTxRemoveSubnetValidator(t *testing.T) { // The above validator is now part of the staking set // Queue a staker that joins the staker set after the above validator leaves - subnetVdr2NodeID := genesisNodeIDs[1] + subnetVdr2NodeID := genesistest.NodeIDs[1] utx, err = builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -602,7 +602,7 @@ func TestTrackedSubnet(t *testing.T) { } // Add a subnet validator to the staker set - subnetValidatorNodeID := genesisNodeIDs[0] + subnetValidatorNodeID := genesistest.NodeIDs[0] subnetVdr1StartTime := genesistest.Time.Add(1 * time.Minute) subnetVdr1EndTime := genesistest.Time.Add(10 * defaultMinStakingDuration).Add(1 * time.Minute) diff --git a/vms/platformvm/txs/executor/helpers_test.go b/vms/platformvm/txs/executor/helpers_test.go index 30f1f11e8973..91b6146d2c15 100644 --- a/vms/platformvm/txs/executor/helpers_test.go +++ b/vms/platformvm/txs/executor/helpers_test.go @@ -53,12 +53,7 @@ const ( defaultBalance = 100 * defaultMinValidatorStake ) -var ( - preFundedKeys = secp256k1.TestKeys() - - // Node IDs of genesis validators. Initialized in init function - genesisNodeIDs = genesistest.GenesisNodeIDs -) +var preFundedKeys = secp256k1.TestKeys() const ( defaultMaxStakingDuration = 365 * 24 * time.Hour @@ -125,7 +120,7 @@ func newEnvironment(t *testing.T, f upgradetest.Fork) *environment { rewards := reward.NewCalculator(config.RewardConfig) baseState := statetest.New(t, statetest.Config{ DB: baseDB, - Genesis: genesistest.BuildGenesisTest(t, ctx.AVAXAssetID), + Genesis: genesistest.BuildGenesisTest(t), Validators: config.Validators, Upgrades: config.UpgradeConfig, Context: ctx, diff --git a/vms/platformvm/txs/executor/proposal_tx_executor_test.go b/vms/platformvm/txs/executor/proposal_tx_executor_test.go index 893228c9e59b..efad81c42e8d 100644 --- a/vms/platformvm/txs/executor/proposal_tx_executor_test.go +++ b/vms/platformvm/txs/executor/proposal_tx_executor_test.go @@ -29,7 +29,7 @@ import ( func TestProposalTxExecuteAddDelegator(t *testing.T) { dummyHeight := uint64(1) rewardAddress := preFundedKeys[0].PublicKey().Address() - nodeID := genesisNodeIDs[0] + nodeID := genesistest.NodeIDs[0] newValidatorID := ids.GenerateTestNodeID() newValidatorStartTime := uint64(genesistest.Time.Add(5 * time.Second).Unix()) @@ -293,7 +293,7 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { env.ctx.Lock.Lock() defer env.ctx.Lock.Unlock() - nodeID := genesisNodeIDs[0] + nodeID := genesistest.NodeIDs[0] { // Case: Proposed validator currently validating primary network // but stops validating subnet after stops validating primary network @@ -856,7 +856,7 @@ func TestProposalTxExecuteAddValidator(t *testing.T) { } { - nodeID := genesisNodeIDs[0] + nodeID := genesistest.NodeIDs[0] // Case: Validator already validating primary network builder, signer := env.factory.NewWallet(preFundedKeys[0]) diff --git a/vms/platformvm/txs/executor/standard_tx_executor_test.go b/vms/platformvm/txs/executor/standard_tx_executor_test.go index c92f3ac81d2c..328caecf1c80 100644 --- a/vms/platformvm/txs/executor/standard_tx_executor_test.go +++ b/vms/platformvm/txs/executor/standard_tx_executor_test.go @@ -113,7 +113,7 @@ func TestStandardTxExecutorAddValidatorTxEmptyID(t *testing.T) { func TestStandardTxExecutorAddDelegator(t *testing.T) { dummyHeight := uint64(1) rewardAddress := preFundedKeys[0].PublicKey().Address() - nodeID := genesisNodeIDs[0] + nodeID := genesistest.NodeIDs[0] newValidatorID := ids.GenerateTestNodeID() newValidatorStartTime := genesistest.Time.Add(5 * time.Second) @@ -375,7 +375,7 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { env.ctx.Lock.Lock() defer env.ctx.Lock.Unlock() - nodeID := genesisNodeIDs[0] + nodeID := genesistest.NodeIDs[0] { // Case: Proposed validator currently validating primary network @@ -898,7 +898,7 @@ func TestEtnaStandardTxExecutorAddSubnetValidator(t *testing.T) { env.ctx.Lock.Lock() defer env.ctx.Lock.Unlock() - nodeID := genesisNodeIDs[0] + nodeID := genesistest.NodeIDs[0] builder, signer := env.factory.NewWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) utx, err := builder.NewAddSubnetValidatorTx( From 3ff26f87b9fab3261a983dafc62ca9e0fd6e4a5e Mon Sep 17 00:00:00 2001 From: Stephen Buttolph Date: Thu, 22 Aug 2024 13:48:57 -0400 Subject: [PATCH 09/27] wip --- vms/platformvm/service_test.go | 4 ++-- vms/platformvm/validator_set_property_test.go | 2 +- vms/platformvm/vm_regression_test.go | 22 ++++++++--------- vms/platformvm/vm_test.go | 24 +++++++------------ 4 files changed, 22 insertions(+), 30 deletions(-) diff --git a/vms/platformvm/service_test.go b/vms/platformvm/service_test.go index 5e2e5514f5c2..1b39730db7ff 100644 --- a/vms/platformvm/service_test.go +++ b/vms/platformvm/service_test.go @@ -491,7 +491,7 @@ func TestGetStake(t *testing.T) { // Add a delegator stakeAmount := service.vm.MinDelegatorStake + 12345 - delegatorNodeID := genesisNodeIDs[0] + delegatorNodeID := genesistest.NodeIDs[0] delegatorEndTime := genesistest.Time.Add(defaultMinStakingDuration) builder, signer := factory.NewWallet(keys[0]) utx, err := builder.NewAddDelegatorTx( @@ -638,7 +638,7 @@ func TestGetCurrentValidators(t *testing.T) { // Add a delegator stakeAmount := service.vm.MinDelegatorStake + 12345 - validatorNodeID := genesisNodeIDs[1] + validatorNodeID := genesistest.NodeIDs[1] delegatorEndTime := genesistest.Time.Add(defaultMinStakingDuration) service.vm.ctx.Lock.Lock() diff --git a/vms/platformvm/validator_set_property_test.go b/vms/platformvm/validator_set_property_test.go index d5c901683ded..3f2ca72bf886 100644 --- a/vms/platformvm/validator_set_property_test.go +++ b/vms/platformvm/validator_set_property_test.go @@ -774,7 +774,7 @@ func buildCustomGenesis(avaxAssetID ids.ID) ([]byte, error) { // won't find next staker to promote/evict from stakers set. Contrary to // what happens with production code we push such validator at the end of // times, so to avoid interference with our tests - nodeID := genesisNodeIDs[len(genesisNodeIDs)-1] + nodeID := genesistest.NodeIDs[len(genesistest.NodeIDs)-1] addr, err := address.FormatBech32(constants.UnitTestHRP, nodeID.Bytes()) if err != nil { return nil, err diff --git a/vms/platformvm/vm_regression_test.go b/vms/platformvm/vm_regression_test.go index 8f81da1cb2d9..573a0b5fe247 100644 --- a/vms/platformvm/vm_regression_test.go +++ b/vms/platformvm/vm_regression_test.go @@ -1103,11 +1103,11 @@ func TestValidatorSetAtCacheOverwriteRegression(t *testing.T) { require.Equal(uint64(1), currentHeight) expectedValidators1 := map[ids.NodeID]uint64{ - genesisNodeIDs[0]: defaultWeight, - genesisNodeIDs[1]: defaultWeight, - genesisNodeIDs[2]: defaultWeight, - genesisNodeIDs[3]: defaultWeight, - genesisNodeIDs[4]: defaultWeight, + genesistest.NodeIDs[0]: defaultWeight, + genesistest.NodeIDs[1]: defaultWeight, + genesistest.NodeIDs[2]: defaultWeight, + genesistest.NodeIDs[3]: defaultWeight, + genesistest.NodeIDs[4]: defaultWeight, } validators, err := vm.GetValidatorSet(context.Background(), 1, constants.PrimaryNetworkID) require.NoError(err) @@ -1207,12 +1207,12 @@ func TestValidatorSetAtCacheOverwriteRegression(t *testing.T) { } expectedValidators2 := map[ids.NodeID]uint64{ - genesisNodeIDs[0]: defaultWeight, - genesisNodeIDs[1]: defaultWeight, - genesisNodeIDs[2]: defaultWeight, - genesisNodeIDs[3]: defaultWeight, - genesisNodeIDs[4]: defaultWeight, - extraNodeID: vm.MaxValidatorStake, + genesistest.NodeIDs[0]: defaultWeight, + genesistest.NodeIDs[1]: defaultWeight, + genesistest.NodeIDs[2]: defaultWeight, + genesistest.NodeIDs[3]: defaultWeight, + genesistest.NodeIDs[4]: defaultWeight, + extraNodeID: vm.MaxValidatorStake, } validators, err = vm.GetValidatorSet(context.Background(), 3, constants.PrimaryNetworkID) require.NoError(err) diff --git a/vms/platformvm/vm_test.go b/vms/platformvm/vm_test.go index 34920d167736..6c14120f6e92 100644 --- a/vms/platformvm/vm_test.go +++ b/vms/platformvm/vm_test.go @@ -98,7 +98,6 @@ var ( keys = secp256k1.TestKeys() // Node IDs of genesis validators. Initialized in init function - genesisNodeIDs []ids.NodeID defaultMinDelegatorStake = 1 * units.MilliAvax defaultMinValidatorStake = 5 * defaultMinDelegatorStake defaultMaxValidatorStake = 100 * defaultMinValidatorStake @@ -131,13 +130,6 @@ var ( testSubnet1ControlKeys = keys[0:3] ) -func init() { - genesisNodeIDs = make([]ids.NodeID, len(keys)) - for i := range keys { - genesisNodeIDs[i] = ids.GenerateTestNodeID() - } -} - type mutableSharedMemory struct { atomic.SharedMemory } @@ -159,8 +151,8 @@ func defaultGenesis(t *testing.T, avaxAssetID ids.ID) (*api.BuildGenesisArgs, [] } } - genesisValidators := make([]api.GenesisPermissionlessValidator, len(genesisNodeIDs)) - for i, nodeID := range genesisNodeIDs { + genesisValidators := make([]api.GenesisPermissionlessValidator, len(genesistest.NodeIDs)) + for i, nodeID := range genesistest.NodeIDs { addr := keys[i].Address() addrStr, err := address.FormatBech32(constants.UnitTestHRP, addr.Bytes()) require.NoError(err) @@ -360,7 +352,7 @@ func TestGenesis(t *testing.T) { // Ensure current validator set of primary network is correct require.Len(genesisState.Validators, vm.Validators.Count(constants.PrimaryNetworkID)) - for _, nodeID := range genesisNodeIDs { + for _, nodeID := range genesistest.NodeIDs { _, ok := vm.Validators.GetValidator(constants.PrimaryNetworkID, nodeID) require.True(ok) } @@ -550,7 +542,7 @@ func TestAddValidatorInvalidNotReissued(t *testing.T) { defer vm.ctx.Lock.Unlock() // Use nodeID that is already in the genesis - repeatNodeID := genesisNodeIDs[0] + repeatNodeID := genesistest.NodeIDs[0] startTime := latestForkTime.Add(txexecutor.SyncBound).Add(1 * time.Second) endTime := startTime.Add(defaultMinStakingDuration) @@ -603,7 +595,7 @@ func TestAddSubnetValidatorAccept(t *testing.T) { var ( startTime = vm.clock.Time().Add(txexecutor.SyncBound).Add(1 * time.Second) endTime = startTime.Add(defaultMinStakingDuration) - nodeID = genesisNodeIDs[0] + nodeID = genesistest.NodeIDs[0] ) // create valid tx @@ -655,7 +647,7 @@ func TestAddSubnetValidatorReject(t *testing.T) { var ( startTime = vm.clock.Time().Add(txexecutor.SyncBound).Add(1 * time.Second) endTime = startTime.Add(defaultMinStakingDuration) - nodeID = genesisNodeIDs[0] + nodeID = genesistest.NodeIDs[0] ) // create valid tx @@ -942,7 +934,7 @@ func TestCreateSubnet(t *testing.T) { require.Contains(subnetIDs, subnetID) // Now that we've created a new subnet, add a validator to that subnet - nodeID := genesisNodeIDs[0] + nodeID := genesistest.NodeIDs[0] startTime := vm.clock.Time().Add(txexecutor.SyncBound).Add(1 * time.Second) endTime := startTime.Add(defaultMinStakingDuration) // [startTime, endTime] is subset of time keys[0] validates default subnet so tx is valid @@ -1739,7 +1731,7 @@ func TestMaxStakeAmount(t *testing.T) { vm.ctx.Lock.Lock() defer vm.ctx.Lock.Unlock() - nodeID := genesisNodeIDs[0] + nodeID := genesistest.NodeIDs[0] tests := []struct { description string From e779192e41827a9eb18b4c8c48d01014552b42ad Mon Sep 17 00:00:00 2001 From: Stephen Buttolph Date: Thu, 22 Aug 2024 13:54:45 -0400 Subject: [PATCH 10/27] wip --- vms/platformvm/block/builder/helpers_test.go | 10 ---------- vms/platformvm/block/executor/helpers_test.go | 10 ---------- vms/platformvm/block/executor/proposal_block_test.go | 6 +++--- vms/platformvm/block/executor/standard_block_test.go | 6 +++--- 4 files changed, 6 insertions(+), 26 deletions(-) diff --git a/vms/platformvm/block/builder/helpers_test.go b/vms/platformvm/block/builder/helpers_test.go index 9f7ad4f6e637..c44813de6119 100644 --- a/vms/platformvm/block/builder/helpers_test.go +++ b/vms/platformvm/block/builder/helpers_test.go @@ -63,18 +63,8 @@ var ( testSubnet1 *txs.Tx testSubnet1ControlKeys = preFundedKeys[0:3] - - // Node IDs of genesis validators. Initialized in init function - genesisNodeIDs []ids.NodeID ) -func init() { - genesisNodeIDs = make([]ids.NodeID, len(preFundedKeys)) - for i := range preFundedKeys { - genesisNodeIDs[i] = ids.GenerateTestNodeID() - } -} - type mutableSharedMemory struct { atomic.SharedMemory } diff --git a/vms/platformvm/block/executor/helpers_test.go b/vms/platformvm/block/executor/helpers_test.go index 069d233e3e2b..5a63ee749b40 100644 --- a/vms/platformvm/block/executor/helpers_test.go +++ b/vms/platformvm/block/executor/helpers_test.go @@ -66,18 +66,8 @@ var ( defaultTxFee = uint64(100) testSubnet1 *txs.Tx - - // Node IDs of genesis validators. Initialized in init function - genesisNodeIDs []ids.NodeID ) -func init() { - genesisNodeIDs = make([]ids.NodeID, len(preFundedKeys)) - for i := range preFundedKeys { - genesisNodeIDs[i] = ids.GenerateTestNodeID() - } -} - type stakerStatus uint type staker struct { diff --git a/vms/platformvm/block/executor/proposal_block_test.go b/vms/platformvm/block/executor/proposal_block_test.go index fb55fde2af74..e75dee67b108 100644 --- a/vms/platformvm/block/executor/proposal_block_test.go +++ b/vms/platformvm/block/executor/proposal_block_test.go @@ -698,7 +698,7 @@ func TestBanffProposalBlockRemoveSubnetValidator(t *testing.T) { env.config.TrackedSubnets.Add(subnetID) // Add a subnet validator to the staker set - subnetValidatorNodeID := genesisNodeIDs[0] + subnetValidatorNodeID := genesistest.NodeIDs[0] subnetVdr1EndTime := genesistest.Time.Add(defaultMinStakingDuration) builder, signer := env.factory.NewWallet(preFundedKeys[0], preFundedKeys[1]) utx, err := builder.NewAddSubnetValidatorTx( @@ -732,7 +732,7 @@ func TestBanffProposalBlockRemoveSubnetValidator(t *testing.T) { // The above validator is now part of the staking set // Queue a staker that joins the staker set after the above validator leaves - subnetVdr2NodeID := genesisNodeIDs[1] + subnetVdr2NodeID := genesistest.NodeIDs[1] utx, err = builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -855,7 +855,7 @@ func TestBanffProposalBlockTrackedSubnet(t *testing.T) { } // Add a subnet validator to the staker set - subnetValidatorNodeID := genesisNodeIDs[0] + subnetValidatorNodeID := genesistest.NodeIDs[0] subnetVdr1StartTime := genesistest.Time.Add(1 * time.Minute) subnetVdr1EndTime := genesistest.Time.Add(10 * defaultMinStakingDuration).Add(1 * time.Minute) diff --git a/vms/platformvm/block/executor/standard_block_test.go b/vms/platformvm/block/executor/standard_block_test.go index 11490077c7a2..40b97f86bb3f 100644 --- a/vms/platformvm/block/executor/standard_block_test.go +++ b/vms/platformvm/block/executor/standard_block_test.go @@ -603,7 +603,7 @@ func TestBanffStandardBlockRemoveSubnetValidator(t *testing.T) { env.config.TrackedSubnets.Add(subnetID) // Add a subnet validator to the staker set - subnetValidatorNodeID := genesisNodeIDs[0] + subnetValidatorNodeID := genesistest.NodeIDs[0] subnetVdr1EndTime := genesistest.Time.Add(defaultMinStakingDuration) builder, signer := env.factory.NewWallet(preFundedKeys[0], preFundedKeys[1]) utx, err := builder.NewAddSubnetValidatorTx( @@ -637,7 +637,7 @@ func TestBanffStandardBlockRemoveSubnetValidator(t *testing.T) { // The above validator is now part of the staking set // Queue a staker that joins the staker set after the above validator leaves - subnetVdr2NodeID := genesisNodeIDs[1] + subnetVdr2NodeID := genesistest.NodeIDs[1] utx, err = builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -708,7 +708,7 @@ func TestBanffStandardBlockTrackedSubnet(t *testing.T) { } // Add a subnet validator to the staker set - subnetValidatorNodeID := genesisNodeIDs[0] + subnetValidatorNodeID := genesistest.NodeIDs[0] subnetVdr1StartTime := genesistest.Time.Add(1 * time.Minute) subnetVdr1EndTime := genesistest.Time.Add(10 * defaultMinStakingDuration).Add(1 * time.Minute) builder, signer := env.factory.NewWallet(preFundedKeys[0], preFundedKeys[1]) From e390ca2d1d908148918e62e02957d0bd8d029922 Mon Sep 17 00:00:00 2001 From: Stephen Buttolph Date: Thu, 22 Aug 2024 14:10:47 -0400 Subject: [PATCH 11/27] Use key var --- vms/platformvm/block/builder/builder_test.go | 25 +++--- vms/platformvm/block/builder/helpers_test.go | 14 ++- .../block/builder/standard_block_test.go | 3 +- vms/platformvm/block/executor/helpers_test.go | 11 ++- .../block/executor/proposal_block_test.go | 40 ++++----- .../block/executor/standard_block_test.go | 16 ++-- vms/platformvm/genesis/genesistest/helper.go | 15 ++-- .../txs/executor/advance_time_test.go | 24 ++--- .../txs/executor/create_chain_test.go | 8 +- .../txs/executor/create_subnet_test.go | 6 +- vms/platformvm/txs/executor/export_test.go | 2 +- vms/platformvm/txs/executor/helpers_test.go | 15 ++-- .../txs/executor/proposal_tx_executor_test.go | 42 ++++----- .../txs/executor/reward_validator_test.go | 8 +- .../txs/executor/standard_tx_executor_test.go | 88 +++++++++---------- 15 files changed, 157 insertions(+), 160 deletions(-) diff --git a/vms/platformvm/block/builder/builder_test.go b/vms/platformvm/block/builder/builder_test.go index 33574b384582..095e766b1e3a 100644 --- a/vms/platformvm/block/builder/builder_test.go +++ b/vms/platformvm/block/builder/builder_test.go @@ -20,6 +20,7 @@ import ( "github.com/ava-labs/avalanchego/utils/timer/mockable" "github.com/ava-labs/avalanchego/utils/units" "github.com/ava-labs/avalanchego/vms/platformvm/block" + "github.com/ava-labs/avalanchego/vms/platformvm/genesis/genesistest" "github.com/ava-labs/avalanchego/vms/platformvm/reward" "github.com/ava-labs/avalanchego/vms/platformvm/signer" "github.com/ava-labs/avalanchego/vms/platformvm/state" @@ -112,7 +113,7 @@ func TestBuildBlockShouldReward(t *testing.T) { require.NoError(err) // Create a valid [AddPermissionlessValidatorTx] - builder, txSigner := env.factory.NewWallet(preFundedKeys[0]) + builder, txSigner := env.factory.NewWallet(genesistest.FundedKeys[0]) utx, err := builder.NewAddPermissionlessValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -127,16 +128,16 @@ func TestBuildBlockShouldReward(t *testing.T) { env.ctx.AVAXAssetID, &secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{preFundedKeys[0].PublicKey().Address()}, + Addrs: []ids.ShortID{genesistest.FundedKeys[0].PublicKey().Address()}, }, &secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{preFundedKeys[0].PublicKey().Address()}, + Addrs: []ids.ShortID{genesistest.FundedKeys[0].PublicKey().Address()}, }, reward.PercentDenominator, common.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{preFundedKeys[0].PublicKey().Address()}, + Addrs: []ids.ShortID{genesistest.FundedKeys[0].PublicKey().Address()}, }), ) require.NoError(err) @@ -321,7 +322,7 @@ func TestBuildBlockInvalidStakingDurations(t *testing.T) { sk, err := bls.NewSecretKey() require.NoError(err) - builder1, signer1 := env.factory.NewWallet(preFundedKeys[0]) + builder1, signer1 := env.factory.NewWallet(genesistest.FundedKeys[0]) utx1, err := builder1.NewAddPermissionlessValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -336,16 +337,16 @@ func TestBuildBlockInvalidStakingDurations(t *testing.T) { env.ctx.AVAXAssetID, &secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{preFundedKeys[0].PublicKey().Address()}, + Addrs: []ids.ShortID{genesistest.FundedKeys[0].PublicKey().Address()}, }, &secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{preFundedKeys[0].PublicKey().Address()}, + Addrs: []ids.ShortID{genesistest.FundedKeys[0].PublicKey().Address()}, }, reward.PercentDenominator, common.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{preFundedKeys[0].PublicKey().Address()}, + Addrs: []ids.ShortID{genesistest.FundedKeys[0].PublicKey().Address()}, }), ) require.NoError(err) @@ -362,7 +363,7 @@ func TestBuildBlockInvalidStakingDurations(t *testing.T) { sk, err = bls.NewSecretKey() require.NoError(err) - builder2, signer2 := env.factory.NewWallet(preFundedKeys[2]) + builder2, signer2 := env.factory.NewWallet(genesistest.FundedKeys[2]) utx2, err := builder2.NewAddPermissionlessValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -377,16 +378,16 @@ func TestBuildBlockInvalidStakingDurations(t *testing.T) { env.ctx.AVAXAssetID, &secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{preFundedKeys[2].PublicKey().Address()}, + Addrs: []ids.ShortID{genesistest.FundedKeys[2].PublicKey().Address()}, }, &secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{preFundedKeys[2].PublicKey().Address()}, + Addrs: []ids.ShortID{genesistest.FundedKeys[2].PublicKey().Address()}, }, reward.PercentDenominator, common.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{preFundedKeys[2].PublicKey().Address()}, + Addrs: []ids.ShortID{genesistest.FundedKeys[2].PublicKey().Address()}, }), ) require.NoError(err) diff --git a/vms/platformvm/block/builder/helpers_test.go b/vms/platformvm/block/builder/helpers_test.go index c44813de6119..d492c5cea2d0 100644 --- a/vms/platformvm/block/builder/helpers_test.go +++ b/vms/platformvm/block/builder/helpers_test.go @@ -28,7 +28,6 @@ import ( "github.com/ava-labs/avalanchego/upgrade/upgradetest" "github.com/ava-labs/avalanchego/utils" "github.com/ava-labs/avalanchego/utils/constants" - "github.com/ava-labs/avalanchego/utils/crypto/secp256k1" "github.com/ava-labs/avalanchego/utils/logging" "github.com/ava-labs/avalanchego/utils/timer/mockable" "github.com/ava-labs/avalanchego/utils/units" @@ -58,11 +57,10 @@ import ( var ( defaultMinStakingDuration = 24 * time.Hour defaultMaxStakingDuration = 365 * 24 * time.Hour - preFundedKeys = secp256k1.TestKeys() defaultTxFee = uint64(100) testSubnet1 *txs.Tx - testSubnet1ControlKeys = preFundedKeys[0:3] + testSubnet1ControlKeys = genesistest.FundedKeys[0:3] ) type mutableSharedMemory struct { @@ -209,19 +207,19 @@ func newEnvironment(t *testing.T, f upgradetest.Fork) *environment { //nolint:un func addSubnet(t *testing.T, env *environment) { require := require.New(t) - builder, signer := env.factory.NewWallet(preFundedKeys[0]) + builder, signer := env.factory.NewWallet(genesistest.FundedKeys[0]) utx, err := builder.NewCreateSubnetTx( &secp256k1fx.OutputOwners{ Threshold: 2, Addrs: []ids.ShortID{ - preFundedKeys[0].PublicKey().Address(), - preFundedKeys[1].PublicKey().Address(), - preFundedKeys[2].PublicKey().Address(), + genesistest.FundedKeys[0].PublicKey().Address(), + genesistest.FundedKeys[1].PublicKey().Address(), + genesistest.FundedKeys[2].PublicKey().Address(), }, }, walletcommon.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{preFundedKeys[0].PublicKey().Address()}, + Addrs: []ids.ShortID{genesistest.FundedKeys[0].PublicKey().Address()}, }), ) require.NoError(err) diff --git a/vms/platformvm/block/builder/standard_block_test.go b/vms/platformvm/block/builder/standard_block_test.go index 6909c0efd794..31fad123d4d5 100644 --- a/vms/platformvm/block/builder/standard_block_test.go +++ b/vms/platformvm/block/builder/standard_block_test.go @@ -14,6 +14,7 @@ import ( "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/upgrade/upgradetest" "github.com/ava-labs/avalanchego/vms/components/avax" + "github.com/ava-labs/avalanchego/vms/platformvm/genesis/genesistest" "github.com/ava-labs/avalanchego/vms/platformvm/status" "github.com/ava-labs/avalanchego/vms/platformvm/txs" "github.com/ava-labs/avalanchego/vms/secp256k1fx" @@ -33,7 +34,7 @@ func TestAtomicTxImports(t *testing.T) { OutputIndex: 1, } amount := uint64(70000) - recipientKey := preFundedKeys[1] + recipientKey := genesistest.FundedKeys[1] m := atomic.NewMemory(prefixdb.New([]byte{5}, env.baseDB)) diff --git a/vms/platformvm/block/executor/helpers_test.go b/vms/platformvm/block/executor/helpers_test.go index 5a63ee749b40..4021f65163b5 100644 --- a/vms/platformvm/block/executor/helpers_test.go +++ b/vms/platformvm/block/executor/helpers_test.go @@ -62,7 +62,6 @@ const ( var ( defaultMinStakingDuration = 24 * time.Hour defaultMaxStakingDuration = 365 * 24 * time.Hour - preFundedKeys = secp256k1.TestKeys() defaultTxFee = uint64(100) testSubnet1 *txs.Tx @@ -225,19 +224,19 @@ func newEnvironment(t *testing.T, ctrl *gomock.Controller, f upgradetest.Fork) * } func addSubnet(env *environment) { - builder, signer := env.factory.NewWallet(preFundedKeys[0]) + builder, signer := env.factory.NewWallet(genesistest.FundedKeys[0]) utx, err := builder.NewCreateSubnetTx( &secp256k1fx.OutputOwners{ Threshold: 2, Addrs: []ids.ShortID{ - preFundedKeys[0].PublicKey().Address(), - preFundedKeys[1].PublicKey().Address(), - preFundedKeys[2].PublicKey().Address(), + genesistest.FundedKeys[0].PublicKey().Address(), + genesistest.FundedKeys[1].PublicKey().Address(), + genesistest.FundedKeys[2].PublicKey().Address(), }, }, walletcommon.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{preFundedKeys[0].PublicKey().Address()}, + Addrs: []ids.ShortID{genesistest.FundedKeys[0].PublicKey().Address()}, }), ) if err != nil { diff --git a/vms/platformvm/block/executor/proposal_block_test.go b/vms/platformvm/block/executor/proposal_block_test.go index e75dee67b108..62b0c6719b7c 100644 --- a/vms/platformvm/block/executor/proposal_block_test.go +++ b/vms/platformvm/block/executor/proposal_block_test.go @@ -520,7 +520,7 @@ func TestBanffProposalBlockUpdateStakers(t *testing.T) { env.config.TrackedSubnets.Add(subnetID) for _, staker := range test.stakers { - builder, signer := env.factory.NewWallet(preFundedKeys[0]) + builder, signer := env.factory.NewWallet(genesistest.FundedKeys[0]) utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: staker.nodeID, @@ -554,7 +554,7 @@ func TestBanffProposalBlockUpdateStakers(t *testing.T) { } for _, subStaker := range test.subnetStakers { - builder, signer := env.factory.NewWallet(preFundedKeys[0], preFundedKeys[1]) + builder, signer := env.factory.NewWallet(genesistest.FundedKeys[0], genesistest.FundedKeys[1]) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -591,7 +591,7 @@ func TestBanffProposalBlockUpdateStakers(t *testing.T) { // add Staker0 (with the right end time) to state // so to allow proposalBlk issuance staker0.endTime = newTime - builder, signer := env.factory.NewWallet(preFundedKeys[0], preFundedKeys[1]) + builder, signer := env.factory.NewWallet(genesistest.FundedKeys[0], genesistest.FundedKeys[1]) utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: staker0.nodeID, @@ -700,7 +700,7 @@ func TestBanffProposalBlockRemoveSubnetValidator(t *testing.T) { // Add a subnet validator to the staker set subnetValidatorNodeID := genesistest.NodeIDs[0] subnetVdr1EndTime := genesistest.Time.Add(defaultMinStakingDuration) - builder, signer := env.factory.NewWallet(preFundedKeys[0], preFundedKeys[1]) + builder, signer := env.factory.NewWallet(genesistest.FundedKeys[0], genesistest.FundedKeys[1]) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -859,7 +859,7 @@ func TestBanffProposalBlockTrackedSubnet(t *testing.T) { subnetVdr1StartTime := genesistest.Time.Add(1 * time.Minute) subnetVdr1EndTime := genesistest.Time.Add(10 * defaultMinStakingDuration).Add(1 * time.Minute) - builder, signer := env.factory.NewWallet(preFundedKeys[0], preFundedKeys[1]) + builder, signer := env.factory.NewWallet(genesistest.FundedKeys[0], genesistest.FundedKeys[1]) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -975,7 +975,7 @@ func TestBanffProposalBlockDelegatorStakerWeight(t *testing.T) { pendingValidatorEndTime, nodeID, rewardAddress, - []*secp256k1.PrivateKey{preFundedKeys[0]}, + []*secp256k1.PrivateKey{genesistest.FundedKeys[0]}, ) require.NoError(err) @@ -983,7 +983,7 @@ func TestBanffProposalBlockDelegatorStakerWeight(t *testing.T) { // just to allow proposalBlk issuance (with a reward Tx) staker0StartTime := genesistest.Time staker0EndTime := pendingValidatorStartTime - builder, signer := env.factory.NewWallet(preFundedKeys[0], preFundedKeys[1]) + builder, signer := env.factory.NewWallet(genesistest.FundedKeys[0], genesistest.FundedKeys[1]) utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: ids.GenerateTestNodeID(), @@ -1054,7 +1054,7 @@ func TestBanffProposalBlockDelegatorStakerWeight(t *testing.T) { pendingDelegatorStartTime := pendingValidatorStartTime.Add(1 * time.Second) pendingDelegatorEndTime := pendingDelegatorStartTime.Add(1 * time.Second) - builder, signer = env.factory.NewWallet(preFundedKeys[0], preFundedKeys[1], preFundedKeys[4]) + builder, signer = env.factory.NewWallet(genesistest.FundedKeys[0], genesistest.FundedKeys[1], genesistest.FundedKeys[4]) uDelTx, err := builder.NewAddDelegatorTx( &txs.Validator{ NodeID: nodeID, @@ -1064,7 +1064,7 @@ func TestBanffProposalBlockDelegatorStakerWeight(t *testing.T) { }, &secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{preFundedKeys[0].PublicKey().Address()}, + Addrs: []ids.ShortID{genesistest.FundedKeys[0].PublicKey().Address()}, }, ) require.NoError(err) @@ -1085,7 +1085,7 @@ func TestBanffProposalBlockDelegatorStakerWeight(t *testing.T) { // add Staker0 (with the right end time) to state // so to allow proposalBlk issuance staker0EndTime = pendingDelegatorStartTime - builder, signer = env.factory.NewWallet(preFundedKeys[0], preFundedKeys[1]) + builder, signer = env.factory.NewWallet(genesistest.FundedKeys[0], genesistest.FundedKeys[1]) utx, err = builder.NewAddValidatorTx( &txs.Validator{ NodeID: ids.GenerateTestNodeID(), @@ -1172,7 +1172,7 @@ func TestBanffProposalBlockDelegatorStakers(t *testing.T) { pendingValidatorEndTime, nodeID, rewardAddress, - []*secp256k1.PrivateKey{preFundedKeys[0]}, + []*secp256k1.PrivateKey{genesistest.FundedKeys[0]}, ) require.NoError(err) @@ -1180,7 +1180,7 @@ func TestBanffProposalBlockDelegatorStakers(t *testing.T) { // so to allow proposalBlk issuance staker0StartTime := genesistest.Time staker0EndTime := pendingValidatorStartTime - builder, txSigner := env.factory.NewWallet(preFundedKeys[0], preFundedKeys[1]) + builder, txSigner := env.factory.NewWallet(genesistest.FundedKeys[0], genesistest.FundedKeys[1]) utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: ids.GenerateTestNodeID(), @@ -1250,7 +1250,7 @@ func TestBanffProposalBlockDelegatorStakers(t *testing.T) { // Add delegator pendingDelegatorStartTime := pendingValidatorStartTime.Add(1 * time.Second) pendingDelegatorEndTime := pendingDelegatorStartTime.Add(defaultMinStakingDuration) - builder, txSigner = env.factory.NewWallet(preFundedKeys[0], preFundedKeys[1], preFundedKeys[4]) + builder, txSigner = env.factory.NewWallet(genesistest.FundedKeys[0], genesistest.FundedKeys[1], genesistest.FundedKeys[4]) uDelTx, err := builder.NewAddDelegatorTx( &txs.Validator{ NodeID: nodeID, @@ -1260,7 +1260,7 @@ func TestBanffProposalBlockDelegatorStakers(t *testing.T) { }, &secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{preFundedKeys[0].PublicKey().Address()}, + Addrs: []ids.ShortID{genesistest.FundedKeys[0].PublicKey().Address()}, }, ) require.NoError(err) @@ -1281,7 +1281,7 @@ func TestBanffProposalBlockDelegatorStakers(t *testing.T) { // add Staker0 (with the right end time) to state // so to allow proposalBlk issuance staker0EndTime = pendingDelegatorStartTime - builder, txSigner = env.factory.NewWallet(preFundedKeys[0], preFundedKeys[1]) + builder, txSigner = env.factory.NewWallet(genesistest.FundedKeys[0], genesistest.FundedKeys[1]) utx, err = builder.NewAddValidatorTx( &txs.Validator{ NodeID: ids.GenerateTestNodeID(), @@ -1365,7 +1365,7 @@ func TestAddValidatorProposalBlock(t *testing.T) { sk, err := bls.NewSecretKey() require.NoError(err) - builder, txSigner := env.factory.NewWallet(preFundedKeys[0], preFundedKeys[1], preFundedKeys[4]) + builder, txSigner := env.factory.NewWallet(genesistest.FundedKeys[0], genesistest.FundedKeys[1], genesistest.FundedKeys[4]) utx, err := builder.NewAddPermissionlessValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -1380,11 +1380,11 @@ func TestAddValidatorProposalBlock(t *testing.T) { env.ctx.AVAXAssetID, &secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{preFundedKeys[0].PublicKey().Address()}, + Addrs: []ids.ShortID{genesistest.FundedKeys[0].PublicKey().Address()}, }, &secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{preFundedKeys[0].PublicKey().Address()}, + Addrs: []ids.ShortID{genesistest.FundedKeys[0].PublicKey().Address()}, }, 10000, ) @@ -1464,11 +1464,11 @@ func TestAddValidatorProposalBlock(t *testing.T) { env.ctx.AVAXAssetID, &secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{preFundedKeys[0].PublicKey().Address()}, + Addrs: []ids.ShortID{genesistest.FundedKeys[0].PublicKey().Address()}, }, &secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{preFundedKeys[0].PublicKey().Address()}, + Addrs: []ids.ShortID{genesistest.FundedKeys[0].PublicKey().Address()}, }, 10000, ) diff --git a/vms/platformvm/block/executor/standard_block_test.go b/vms/platformvm/block/executor/standard_block_test.go index 40b97f86bb3f..8c9ef031a94d 100644 --- a/vms/platformvm/block/executor/standard_block_test.go +++ b/vms/platformvm/block/executor/standard_block_test.go @@ -307,7 +307,7 @@ func TestBanffStandardBlockUpdatePrimaryNetworkStakers(t *testing.T) { pendingValidatorEndTime, nodeID, rewardAddress, - []*secp256k1.PrivateKey{preFundedKeys[0]}, + []*secp256k1.PrivateKey{genesistest.FundedKeys[0]}, ) require.NoError(err) @@ -506,13 +506,13 @@ func TestBanffStandardBlockUpdateStakers(t *testing.T) { staker.endTime, staker.nodeID, staker.rewardAddress, - []*secp256k1.PrivateKey{preFundedKeys[0]}, + []*secp256k1.PrivateKey{genesistest.FundedKeys[0]}, ) require.NoError(err) } for _, staker := range test.subnetStakers { - builder, signer := env.factory.NewWallet(preFundedKeys[0], preFundedKeys[1]) + builder, signer := env.factory.NewWallet(genesistest.FundedKeys[0], genesistest.FundedKeys[1]) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -605,7 +605,7 @@ func TestBanffStandardBlockRemoveSubnetValidator(t *testing.T) { // Add a subnet validator to the staker set subnetValidatorNodeID := genesistest.NodeIDs[0] subnetVdr1EndTime := genesistest.Time.Add(defaultMinStakingDuration) - builder, signer := env.factory.NewWallet(preFundedKeys[0], preFundedKeys[1]) + builder, signer := env.factory.NewWallet(genesistest.FundedKeys[0], genesistest.FundedKeys[1]) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -711,7 +711,7 @@ func TestBanffStandardBlockTrackedSubnet(t *testing.T) { subnetValidatorNodeID := genesistest.NodeIDs[0] subnetVdr1StartTime := genesistest.Time.Add(1 * time.Minute) subnetVdr1EndTime := genesistest.Time.Add(10 * defaultMinStakingDuration).Add(1 * time.Minute) - builder, signer := env.factory.NewWallet(preFundedKeys[0], preFundedKeys[1]) + builder, signer := env.factory.NewWallet(genesistest.FundedKeys[0], genesistest.FundedKeys[1]) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -778,7 +778,7 @@ func TestBanffStandardBlockDelegatorStakerWeight(t *testing.T) { pendingValidatorEndTime, nodeID, rewardAddress, - []*secp256k1.PrivateKey{preFundedKeys[0]}, + []*secp256k1.PrivateKey{genesistest.FundedKeys[0]}, ) require.NoError(err) @@ -806,7 +806,7 @@ func TestBanffStandardBlockDelegatorStakerWeight(t *testing.T) { pendingDelegatorStartTime := pendingValidatorStartTime.Add(1 * time.Second) pendingDelegatorEndTime := pendingDelegatorStartTime.Add(1 * time.Second) - builder, signer := env.factory.NewWallet(preFundedKeys[0], preFundedKeys[1], preFundedKeys[4]) + builder, signer := env.factory.NewWallet(genesistest.FundedKeys[0], genesistest.FundedKeys[1], genesistest.FundedKeys[4]) utx, err := builder.NewAddDelegatorTx( &txs.Validator{ NodeID: nodeID, @@ -816,7 +816,7 @@ func TestBanffStandardBlockDelegatorStakerWeight(t *testing.T) { }, &secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{preFundedKeys[0].PublicKey().Address()}, + Addrs: []ids.ShortID{genesistest.FundedKeys[0].PublicKey().Address()}, }, ) require.NoError(err) diff --git a/vms/platformvm/genesis/genesistest/helper.go b/vms/platformvm/genesis/genesistest/helper.go index dea8e747d813..572a4d5dfca1 100644 --- a/vms/platformvm/genesis/genesistest/helper.go +++ b/vms/platformvm/genesis/genesistest/helper.go @@ -29,15 +29,16 @@ const ( ) var ( - preFundedKeys = secp256k1.TestKeys() + // Keys that are funded in the genesis + FundedKeys = secp256k1.TestKeys() - // Node IDs of genesis validators. Initialized in init function + // Node IDs of genesis validators NodeIDs []ids.NodeID ) func init() { - NodeIDs = make([]ids.NodeID, len(preFundedKeys)) - for i := range preFundedKeys { + NodeIDs = make([]ids.NodeID, len(FundedKeys)) + for i := range FundedKeys { NodeIDs[i] = ids.GenerateTestNodeID() } } @@ -45,8 +46,8 @@ func init() { func BuildGenesisTest(t *testing.T) []byte { require := require.New(t) - genesisUTXOs := make([]api.UTXO, len(preFundedKeys)) - for i, key := range preFundedKeys { + genesisUTXOs := make([]api.UTXO, len(FundedKeys)) + for i, key := range FundedKeys { id := key.PublicKey().Address() addr, err := address.FormatBech32(constants.UnitTestHRP, id.Bytes()) require.NoError(err) @@ -58,7 +59,7 @@ func BuildGenesisTest(t *testing.T) []byte { genesisValidators := make([]api.GenesisPermissionlessValidator, len(NodeIDs)) for i, nodeID := range NodeIDs { - addr := preFundedKeys[i].Address() + addr := FundedKeys[i].Address() addrStr, err := address.FormatBech32(constants.UnitTestHRP, addr.Bytes()) require.NoError(err) genesisValidators[i] = api.GenesisPermissionlessValidator{ diff --git a/vms/platformvm/txs/executor/advance_time_test.go b/vms/platformvm/txs/executor/advance_time_test.go index d71dfff3bd36..8a618ac8e65c 100644 --- a/vms/platformvm/txs/executor/advance_time_test.go +++ b/vms/platformvm/txs/executor/advance_time_test.go @@ -55,7 +55,7 @@ func TestAdvanceTimeTxUpdatePrimaryNetworkStakers(t *testing.T) { pendingValidatorStartTime, pendingValidatorEndTime, nodeID, - []*secp256k1.PrivateKey{preFundedKeys[0]}, + []*secp256k1.PrivateKey{genesistest.FundedKeys[0]}, ) require.NoError(err) @@ -140,7 +140,7 @@ func TestAdvanceTimeTxTimestampTooLate(t *testing.T) { pendingValidatorStartTime := genesistest.Time.Add(1 * time.Second) pendingValidatorEndTime := pendingValidatorStartTime.Add(defaultMinStakingDuration) nodeID := ids.GenerateTestNodeID() - _, err := addPendingValidator(env, pendingValidatorStartTime, pendingValidatorEndTime, nodeID, []*secp256k1.PrivateKey{preFundedKeys[0]}) + _, err := addPendingValidator(env, pendingValidatorStartTime, pendingValidatorEndTime, nodeID, []*secp256k1.PrivateKey{genesistest.FundedKeys[0]}) require.NoError(err) { @@ -383,13 +383,13 @@ func TestAdvanceTimeTxUpdateStakers(t *testing.T) { staker.startTime, staker.endTime, staker.nodeID, - []*secp256k1.PrivateKey{preFundedKeys[0]}, + []*secp256k1.PrivateKey{genesistest.FundedKeys[0]}, ) require.NoError(err) } for _, staker := range test.subnetStakers { - builder, signer := env.factory.NewWallet(preFundedKeys[0], preFundedKeys[1]) + builder, signer := env.factory.NewWallet(genesistest.FundedKeys[0], genesistest.FundedKeys[1]) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -490,7 +490,7 @@ func TestAdvanceTimeTxRemoveSubnetValidator(t *testing.T) { subnetValidatorNodeID := genesistest.NodeIDs[0] subnetVdr1EndTime := genesistest.Time.Add(defaultMinStakingDuration) - builder, signer := env.factory.NewWallet(preFundedKeys[0], preFundedKeys[1]) + builder, signer := env.factory.NewWallet(genesistest.FundedKeys[0], genesistest.FundedKeys[1]) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -606,7 +606,7 @@ func TestTrackedSubnet(t *testing.T) { subnetVdr1StartTime := genesistest.Time.Add(1 * time.Minute) subnetVdr1EndTime := genesistest.Time.Add(10 * defaultMinStakingDuration).Add(1 * time.Minute) - builder, signer := env.factory.NewWallet(preFundedKeys[0], preFundedKeys[1]) + builder, signer := env.factory.NewWallet(genesistest.FundedKeys[0], genesistest.FundedKeys[1]) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -681,7 +681,7 @@ func TestAdvanceTimeTxDelegatorStakerWeight(t *testing.T) { pendingValidatorStartTime, pendingValidatorEndTime, nodeID, - []*secp256k1.PrivateKey{preFundedKeys[0]}, + []*secp256k1.PrivateKey{genesistest.FundedKeys[0]}, ) require.NoError(err) @@ -717,7 +717,7 @@ func TestAdvanceTimeTxDelegatorStakerWeight(t *testing.T) { pendingDelegatorStartTime := pendingValidatorStartTime.Add(1 * time.Second) pendingDelegatorEndTime := pendingDelegatorStartTime.Add(1 * time.Second) - builder, signer := env.factory.NewWallet(preFundedKeys[0], preFundedKeys[1], preFundedKeys[4]) + builder, signer := env.factory.NewWallet(genesistest.FundedKeys[0], genesistest.FundedKeys[1], genesistest.FundedKeys[4]) utx, err := builder.NewAddDelegatorTx( &txs.Validator{ NodeID: nodeID, @@ -727,7 +727,7 @@ func TestAdvanceTimeTxDelegatorStakerWeight(t *testing.T) { }, &secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{preFundedKeys[0].PublicKey().Address()}, + Addrs: []ids.ShortID{genesistest.FundedKeys[0].PublicKey().Address()}, }, ) require.NoError(err) @@ -786,7 +786,7 @@ func TestAdvanceTimeTxDelegatorStakers(t *testing.T) { pendingValidatorStartTime := genesistest.Time.Add(1 * time.Second) pendingValidatorEndTime := pendingValidatorStartTime.Add(defaultMinStakingDuration) nodeID := ids.GenerateTestNodeID() - _, err := addPendingValidator(env, pendingValidatorStartTime, pendingValidatorEndTime, nodeID, []*secp256k1.PrivateKey{preFundedKeys[0]}) + _, err := addPendingValidator(env, pendingValidatorStartTime, pendingValidatorEndTime, nodeID, []*secp256k1.PrivateKey{genesistest.FundedKeys[0]}) require.NoError(err) tx, err := newAdvanceTimeTx(t, pendingValidatorStartTime) @@ -820,7 +820,7 @@ func TestAdvanceTimeTxDelegatorStakers(t *testing.T) { // Add delegator pendingDelegatorStartTime := pendingValidatorStartTime.Add(1 * time.Second) pendingDelegatorEndTime := pendingDelegatorStartTime.Add(defaultMinStakingDuration) - builder, signer := env.factory.NewWallet(preFundedKeys[0], preFundedKeys[1], preFundedKeys[4]) + builder, signer := env.factory.NewWallet(genesistest.FundedKeys[0], genesistest.FundedKeys[1], genesistest.FundedKeys[4]) utx, err := builder.NewAddDelegatorTx( &txs.Validator{ NodeID: nodeID, @@ -830,7 +830,7 @@ func TestAdvanceTimeTxDelegatorStakers(t *testing.T) { }, &secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{preFundedKeys[0].PublicKey().Address()}, + Addrs: []ids.ShortID{genesistest.FundedKeys[0].PublicKey().Address()}, }, ) require.NoError(err) diff --git a/vms/platformvm/txs/executor/create_chain_test.go b/vms/platformvm/txs/executor/create_chain_test.go index c4718d156bc3..b31237bed5d5 100644 --- a/vms/platformvm/txs/executor/create_chain_test.go +++ b/vms/platformvm/txs/executor/create_chain_test.go @@ -35,7 +35,7 @@ func TestCreateChainTxInsufficientControlSigs(t *testing.T) { env.ctx.Lock.Lock() defer env.ctx.Lock.Unlock() - builder, signer := env.factory.NewWallet(preFundedKeys[0], preFundedKeys[1]) + builder, signer := env.factory.NewWallet(genesistest.FundedKeys[0], genesistest.FundedKeys[1]) utx, err := builder.NewCreateChainTx( testSubnet1.ID(), nil, @@ -214,8 +214,8 @@ func TestCreateChainTxAP3FeeChange(t *testing.T) { env := newEnvironment(t, upgradetest.Banff) env.config.UpgradeConfig.ApricotPhase3Time = ap3Time - addrs := set.NewSet[ids.ShortID](len(preFundedKeys)) - for _, key := range preFundedKeys { + addrs := set.NewSet[ids.ShortID](len(genesistest.FundedKeys)) + for _, key := range genesistest.FundedKeys { addrs.Add(key.Address()) } @@ -225,7 +225,7 @@ func TestCreateChainTxAP3FeeChange(t *testing.T) { cfg.StaticFeeConfig.CreateBlockchainTxFee = test.fee factory := txstest.NewWalletFactory(env.ctx, &cfg, env.state) - builder, signer := factory.NewWallet(preFundedKeys...) + builder, signer := factory.NewWallet(genesistest.FundedKeys...) utx, err := builder.NewCreateChainTx( testSubnet1.ID(), nil, diff --git a/vms/platformvm/txs/executor/create_subnet_test.go b/vms/platformvm/txs/executor/create_subnet_test.go index abe1fac1eee4..b294527bef78 100644 --- a/vms/platformvm/txs/executor/create_subnet_test.go +++ b/vms/platformvm/txs/executor/create_subnet_test.go @@ -61,15 +61,15 @@ func TestCreateSubnetTxAP3FeeChange(t *testing.T) { env.state.SetTimestamp(test.time) // to duly set fee - addrs := set.NewSet[ids.ShortID](len(preFundedKeys)) - for _, key := range preFundedKeys { + addrs := set.NewSet[ids.ShortID](len(genesistest.FundedKeys)) + for _, key := range genesistest.FundedKeys { addrs.Add(key.Address()) } cfg := *env.config cfg.StaticFeeConfig.CreateSubnetTxFee = test.fee factory := txstest.NewWalletFactory(env.ctx, &cfg, env.state) - builder, signer := factory.NewWallet(preFundedKeys...) + builder, signer := factory.NewWallet(genesistest.FundedKeys...) utx, err := builder.NewCreateSubnetTx( &secp256k1fx.OutputOwners{}, ) diff --git a/vms/platformvm/txs/executor/export_test.go b/vms/platformvm/txs/executor/export_test.go index c285bcf609c7..f19741c104f5 100644 --- a/vms/platformvm/txs/executor/export_test.go +++ b/vms/platformvm/txs/executor/export_test.go @@ -33,7 +33,7 @@ func TestNewExportTx(t *testing.T) { timestamp time.Time } - sourceKey := preFundedKeys[0] + sourceKey := genesistest.FundedKeys[0] tests := []test{ { diff --git a/vms/platformvm/txs/executor/helpers_test.go b/vms/platformvm/txs/executor/helpers_test.go index 91b6146d2c15..e2000cde8be7 100644 --- a/vms/platformvm/txs/executor/helpers_test.go +++ b/vms/platformvm/txs/executor/helpers_test.go @@ -25,7 +25,6 @@ import ( "github.com/ava-labs/avalanchego/upgrade/upgradetest" "github.com/ava-labs/avalanchego/utils" "github.com/ava-labs/avalanchego/utils/constants" - "github.com/ava-labs/avalanchego/utils/crypto/secp256k1" "github.com/ava-labs/avalanchego/utils/logging" "github.com/ava-labs/avalanchego/utils/timer/mockable" "github.com/ava-labs/avalanchego/utils/units" @@ -53,8 +52,6 @@ const ( defaultBalance = 100 * defaultMinValidatorStake ) -var preFundedKeys = secp256k1.TestKeys() - const ( defaultMaxStakingDuration = 365 * 24 * time.Hour trackChecksum = false @@ -65,7 +62,7 @@ var ( lastAcceptedID = ids.GenerateTestID() testSubnet1 *txs.Tx - testSubnet1ControlKeys = preFundedKeys[0:3] + testSubnet1ControlKeys = genesistest.FundedKeys[0:3] ) type mutableSharedMemory struct { @@ -192,19 +189,19 @@ func newEnvironment(t *testing.T, f upgradetest.Fork) *environment { func addSubnet(t *testing.T, env *environment) { require := require.New(t) - builder, signer := env.factory.NewWallet(preFundedKeys[0]) + builder, signer := env.factory.NewWallet(genesistest.FundedKeys[0]) utx, err := builder.NewCreateSubnetTx( &secp256k1fx.OutputOwners{ Threshold: 2, Addrs: []ids.ShortID{ - preFundedKeys[0].PublicKey().Address(), - preFundedKeys[1].PublicKey().Address(), - preFundedKeys[2].PublicKey().Address(), + genesistest.FundedKeys[0].PublicKey().Address(), + genesistest.FundedKeys[1].PublicKey().Address(), + genesistest.FundedKeys[2].PublicKey().Address(), }, }, common.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{preFundedKeys[0].PublicKey().Address()}, + Addrs: []ids.ShortID{genesistest.FundedKeys[0].PublicKey().Address()}, }), ) require.NoError(err) diff --git a/vms/platformvm/txs/executor/proposal_tx_executor_test.go b/vms/platformvm/txs/executor/proposal_tx_executor_test.go index efad81c42e8d..84807e9edb9e 100644 --- a/vms/platformvm/txs/executor/proposal_tx_executor_test.go +++ b/vms/platformvm/txs/executor/proposal_tx_executor_test.go @@ -28,7 +28,7 @@ import ( func TestProposalTxExecuteAddDelegator(t *testing.T) { dummyHeight := uint64(1) - rewardAddress := preFundedKeys[0].PublicKey().Address() + rewardAddress := genesistest.FundedKeys[0].PublicKey().Address() nodeID := genesistest.NodeIDs[0] newValidatorID := ids.GenerateTestNodeID() @@ -40,7 +40,7 @@ func TestProposalTxExecuteAddDelegator(t *testing.T) { addMinStakeValidator := func(env *environment) { require := require.New(t) - builder, signer := env.factory.NewWallet(preFundedKeys[0]) + builder, signer := env.factory.NewWallet(genesistest.FundedKeys[0]) utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: newValidatorID, @@ -78,7 +78,7 @@ func TestProposalTxExecuteAddDelegator(t *testing.T) { addMaxStakeValidator := func(env *environment) { require := require.New(t) - builder, signer := env.factory.NewWallet(preFundedKeys[0]) + builder, signer := env.factory.NewWallet(genesistest.FundedKeys[0]) utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: newValidatorID, @@ -133,7 +133,7 @@ func TestProposalTxExecuteAddDelegator(t *testing.T) { startTime: genesistest.TimeUnix + 1, endTime: genesistest.ValidatorEndTimeUnix + 1, nodeID: nodeID, - feeKeys: []*secp256k1.PrivateKey{preFundedKeys[0]}, + feeKeys: []*secp256k1.PrivateKey{genesistest.FundedKeys[0]}, setup: nil, AP3Time: genesistest.Time, expectedErr: ErrPeriodMismatch, @@ -144,7 +144,7 @@ func TestProposalTxExecuteAddDelegator(t *testing.T) { startTime: uint64(genesistest.Time.Add(5 * time.Second).Unix()), endTime: uint64(genesistest.ValidatorEndTime.Add(-5 * time.Second).Unix()), nodeID: newValidatorID, - feeKeys: []*secp256k1.PrivateKey{preFundedKeys[0]}, + feeKeys: []*secp256k1.PrivateKey{genesistest.FundedKeys[0]}, setup: nil, AP3Time: genesistest.Time, expectedErr: database.ErrNotFound, @@ -155,7 +155,7 @@ func TestProposalTxExecuteAddDelegator(t *testing.T) { startTime: newValidatorStartTime - 1, // start validating subnet before primary network endTime: newValidatorEndTime, nodeID: newValidatorID, - feeKeys: []*secp256k1.PrivateKey{preFundedKeys[0]}, + feeKeys: []*secp256k1.PrivateKey{genesistest.FundedKeys[0]}, setup: addMinStakeValidator, AP3Time: genesistest.Time, expectedErr: ErrPeriodMismatch, @@ -166,7 +166,7 @@ func TestProposalTxExecuteAddDelegator(t *testing.T) { startTime: newValidatorStartTime, endTime: newValidatorEndTime + 1, // stop validating subnet after stopping validating primary network nodeID: newValidatorID, - feeKeys: []*secp256k1.PrivateKey{preFundedKeys[0]}, + feeKeys: []*secp256k1.PrivateKey{genesistest.FundedKeys[0]}, setup: addMinStakeValidator, AP3Time: genesistest.Time, expectedErr: ErrPeriodMismatch, @@ -177,7 +177,7 @@ func TestProposalTxExecuteAddDelegator(t *testing.T) { startTime: newValidatorStartTime, // same start time as for primary network endTime: newValidatorEndTime, // same end time as for primary network nodeID: newValidatorID, - feeKeys: []*secp256k1.PrivateKey{preFundedKeys[0]}, + feeKeys: []*secp256k1.PrivateKey{genesistest.FundedKeys[0]}, setup: addMinStakeValidator, AP3Time: genesistest.Time, expectedErr: nil, @@ -188,7 +188,7 @@ func TestProposalTxExecuteAddDelegator(t *testing.T) { startTime: uint64(currentTimestamp.Unix()), endTime: genesistest.ValidatorEndTimeUnix, nodeID: nodeID, - feeKeys: []*secp256k1.PrivateKey{preFundedKeys[0]}, + feeKeys: []*secp256k1.PrivateKey{genesistest.FundedKeys[0]}, setup: nil, AP3Time: genesistest.Time, expectedErr: ErrTimestampNotBeforeStartTime, @@ -199,10 +199,10 @@ func TestProposalTxExecuteAddDelegator(t *testing.T) { startTime: genesistest.TimeUnix + 1, endTime: genesistest.ValidatorEndTimeUnix, nodeID: nodeID, - feeKeys: []*secp256k1.PrivateKey{preFundedKeys[1]}, + feeKeys: []*secp256k1.PrivateKey{genesistest.FundedKeys[1]}, setup: func(env *environment) { // Remove all UTXOs owned by keys[1] utxoIDs, err := env.state.UTXOIDs( - preFundedKeys[1].PublicKey().Address().Bytes(), + genesistest.FundedKeys[1].PublicKey().Address().Bytes(), ids.Empty, math.MaxInt32) require.NoError(t, err) @@ -222,7 +222,7 @@ func TestProposalTxExecuteAddDelegator(t *testing.T) { startTime: newValidatorStartTime, // same start time as for primary network endTime: newValidatorEndTime, // same end time as for primary network nodeID: newValidatorID, - feeKeys: []*secp256k1.PrivateKey{preFundedKeys[0]}, + feeKeys: []*secp256k1.PrivateKey{genesistest.FundedKeys[0]}, setup: addMaxStakeValidator, AP3Time: genesistest.ValidatorEndTime, expectedErr: nil, @@ -233,7 +233,7 @@ func TestProposalTxExecuteAddDelegator(t *testing.T) { startTime: newValidatorStartTime, // same start time as for primary network endTime: newValidatorEndTime, // same end time as for primary network nodeID: newValidatorID, - feeKeys: []*secp256k1.PrivateKey{preFundedKeys[0]}, + feeKeys: []*secp256k1.PrivateKey{genesistest.FundedKeys[0]}, setup: addMaxStakeValidator, AP3Time: genesistest.Time, expectedErr: ErrOverDelegated, @@ -376,7 +376,7 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { dsStartTime := genesistest.Time.Add(10 * time.Second) dsEndTime := dsStartTime.Add(5 * defaultMinStakingDuration) - builder, signer := env.factory.NewWallet(preFundedKeys[0]) + builder, signer := env.factory.NewWallet(genesistest.FundedKeys[0]) utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: pendingDSValidatorID, @@ -717,7 +717,7 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { { // Case: Control Signature from invalid key (keys[3] is not a control key) - builder, signer := env.factory.NewWallet(testSubnet1ControlKeys[0], preFundedKeys[1]) + builder, signer := env.factory.NewWallet(testSubnet1ControlKeys[0], genesistest.FundedKeys[1]) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -734,7 +734,7 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { require.NoError(err) // Replace a valid signature with one from keys[3] - sig, err := preFundedKeys[3].SignHash(hashing.ComputeHash256(tx.Unsigned.Bytes())) + sig, err := genesistest.FundedKeys[3].SignHash(hashing.ComputeHash256(tx.Unsigned.Bytes())) require.NoError(err) copy(tx.Creds[0].(*secp256k1fx.Credential).Sigs[0][:], sig) @@ -819,7 +819,7 @@ func TestProposalTxExecuteAddValidator(t *testing.T) { { // Case: Validator's start time too early - builder, signer := env.factory.NewWallet(preFundedKeys[0]) + builder, signer := env.factory.NewWallet(genesistest.FundedKeys[0]) utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID, @@ -859,7 +859,7 @@ func TestProposalTxExecuteAddValidator(t *testing.T) { nodeID := genesistest.NodeIDs[0] // Case: Validator already validating primary network - builder, signer := env.factory.NewWallet(preFundedKeys[0]) + builder, signer := env.factory.NewWallet(genesistest.FundedKeys[0]) utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID, @@ -898,7 +898,7 @@ func TestProposalTxExecuteAddValidator(t *testing.T) { { // Case: Validator in pending validator set of primary network startTime := genesistest.Time.Add(1 * time.Second) - builder, signer := env.factory.NewWallet(preFundedKeys[0]) + builder, signer := env.factory.NewWallet(genesistest.FundedKeys[0]) utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID, @@ -951,7 +951,7 @@ func TestProposalTxExecuteAddValidator(t *testing.T) { { // Case: Validator doesn't have enough tokens to cover stake amount - builder, signer := env.factory.NewWallet(preFundedKeys[0]) + builder, signer := env.factory.NewWallet(genesistest.FundedKeys[0]) utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: ids.GenerateTestNodeID(), @@ -970,7 +970,7 @@ func TestProposalTxExecuteAddValidator(t *testing.T) { require.NoError(err) // Remove all UTXOs owned by preFundedKeys[0] - utxoIDs, err := env.state.UTXOIDs(preFundedKeys[0].PublicKey().Address().Bytes(), ids.Empty, math.MaxInt32) + utxoIDs, err := env.state.UTXOIDs(genesistest.FundedKeys[0].PublicKey().Address().Bytes(), ids.Empty, math.MaxInt32) require.NoError(err) for _, utxoID := range utxoIDs { diff --git a/vms/platformvm/txs/executor/reward_validator_test.go b/vms/platformvm/txs/executor/reward_validator_test.go index f96c07b32cb3..28f3a92c89ea 100644 --- a/vms/platformvm/txs/executor/reward_validator_test.go +++ b/vms/platformvm/txs/executor/reward_validator_test.go @@ -251,7 +251,7 @@ func TestRewardDelegatorTxExecuteOnCommitPreDelegateeDeferral(t *testing.T) { vdrEndTime := uint64(genesistest.Time.Add(2 * defaultMinStakingDuration).Unix()) vdrNodeID := ids.GenerateTestNodeID() - builder, signer := env.factory.NewWallet(preFundedKeys[0]) + builder, signer := env.factory.NewWallet(genesistest.FundedKeys[0]) uVdrTx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: vdrNodeID, @@ -385,7 +385,7 @@ func TestRewardDelegatorTxExecuteOnCommitPostDelegateeDeferral(t *testing.T) { vdrEndTime := uint64(genesistest.Time.Add(2 * defaultMinStakingDuration).Unix()) vdrNodeID := ids.GenerateTestNodeID() - builder, signer := env.factory.NewWallet(preFundedKeys[0]) + builder, signer := env.factory.NewWallet(genesistest.FundedKeys[0]) uVdrTx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: vdrNodeID, @@ -615,7 +615,7 @@ func TestRewardDelegatorTxAndValidatorTxExecuteOnCommitPostDelegateeDeferral(t * vdrEndTime := uint64(genesistest.Time.Add(2 * defaultMinStakingDuration).Unix()) vdrNodeID := ids.GenerateTestNodeID() - builder, signer := env.factory.NewWallet(preFundedKeys[0]) + builder, signer := env.factory.NewWallet(genesistest.FundedKeys[0]) uVdrTx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: vdrNodeID, @@ -791,7 +791,7 @@ func TestRewardDelegatorTxExecuteOnAbort(t *testing.T) { vdrEndTime := uint64(genesistest.Time.Add(2 * defaultMinStakingDuration).Unix()) vdrNodeID := ids.GenerateTestNodeID() - builder, signer := env.factory.NewWallet(preFundedKeys[0]) + builder, signer := env.factory.NewWallet(genesistest.FundedKeys[0]) uVdrTx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: vdrNodeID, diff --git a/vms/platformvm/txs/executor/standard_tx_executor_test.go b/vms/platformvm/txs/executor/standard_tx_executor_test.go index 328caecf1c80..75565f5146ea 100644 --- a/vms/platformvm/txs/executor/standard_tx_executor_test.go +++ b/vms/platformvm/txs/executor/standard_tx_executor_test.go @@ -77,7 +77,7 @@ func TestStandardTxExecutorAddValidatorTxEmptyID(t *testing.T) { // Case: Empty validator node ID after banff env.config.UpgradeConfig.BanffTime = test.banffTime - builder, signer := env.factory.NewWallet(preFundedKeys[0]) + builder, signer := env.factory.NewWallet(genesistest.FundedKeys[0]) utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: ids.EmptyNodeID, @@ -112,7 +112,7 @@ func TestStandardTxExecutorAddValidatorTxEmptyID(t *testing.T) { func TestStandardTxExecutorAddDelegator(t *testing.T) { dummyHeight := uint64(1) - rewardAddress := preFundedKeys[0].PublicKey().Address() + rewardAddress := genesistest.FundedKeys[0].PublicKey().Address() nodeID := genesistest.NodeIDs[0] newValidatorID := ids.GenerateTestNodeID() @@ -124,7 +124,7 @@ func TestStandardTxExecutorAddDelegator(t *testing.T) { addMinStakeValidator := func(env *environment) { require := require.New(t) - builder, signer := env.factory.NewWallet(preFundedKeys[0]) + builder, signer := env.factory.NewWallet(genesistest.FundedKeys[0]) utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: newValidatorID, @@ -162,7 +162,7 @@ func TestStandardTxExecutorAddDelegator(t *testing.T) { addMaxStakeValidator := func(env *environment) { require := require.New(t) - builder, signer := env.factory.NewWallet(preFundedKeys[0]) + builder, signer := env.factory.NewWallet(genesistest.FundedKeys[0]) utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: newValidatorID, @@ -217,7 +217,7 @@ func TestStandardTxExecutorAddDelegator(t *testing.T) { startTime: genesistest.Time.Add(time.Second), endTime: genesistest.ValidatorEndTime.Add(time.Second), nodeID: nodeID, - feeKeys: []*secp256k1.PrivateKey{preFundedKeys[0]}, + feeKeys: []*secp256k1.PrivateKey{genesistest.FundedKeys[0]}, setup: nil, AP3Time: genesistest.Time, expectedExecutionErr: ErrPeriodMismatch, @@ -228,7 +228,7 @@ func TestStandardTxExecutorAddDelegator(t *testing.T) { startTime: genesistest.Time.Add(5 * time.Second), endTime: genesistest.ValidatorEndTime.Add(-5 * time.Second), nodeID: newValidatorID, - feeKeys: []*secp256k1.PrivateKey{preFundedKeys[0]}, + feeKeys: []*secp256k1.PrivateKey{genesistest.FundedKeys[0]}, setup: nil, AP3Time: genesistest.Time, expectedExecutionErr: database.ErrNotFound, @@ -239,7 +239,7 @@ func TestStandardTxExecutorAddDelegator(t *testing.T) { startTime: newValidatorStartTime.Add(-1 * time.Second), // start validating subnet before primary network endTime: newValidatorEndTime, nodeID: newValidatorID, - feeKeys: []*secp256k1.PrivateKey{preFundedKeys[0]}, + feeKeys: []*secp256k1.PrivateKey{genesistest.FundedKeys[0]}, setup: addMinStakeValidator, AP3Time: genesistest.Time, expectedExecutionErr: ErrPeriodMismatch, @@ -250,7 +250,7 @@ func TestStandardTxExecutorAddDelegator(t *testing.T) { startTime: newValidatorStartTime, endTime: newValidatorEndTime.Add(time.Second), // stop validating subnet after stopping validating primary network nodeID: newValidatorID, - feeKeys: []*secp256k1.PrivateKey{preFundedKeys[0]}, + feeKeys: []*secp256k1.PrivateKey{genesistest.FundedKeys[0]}, setup: addMinStakeValidator, AP3Time: genesistest.Time, expectedExecutionErr: ErrPeriodMismatch, @@ -261,32 +261,32 @@ func TestStandardTxExecutorAddDelegator(t *testing.T) { startTime: newValidatorStartTime, // same start time as for primary network endTime: newValidatorEndTime, // same end time as for primary network nodeID: newValidatorID, - feeKeys: []*secp256k1.PrivateKey{preFundedKeys[0]}, + feeKeys: []*secp256k1.PrivateKey{genesistest.FundedKeys[0]}, setup: addMinStakeValidator, AP3Time: genesistest.Time, expectedExecutionErr: nil, }, { description: "starts delegating at current timestamp", - stakeAmount: env.config.MinDelegatorStake, // weight - startTime: currentTimestamp, // start time - endTime: genesistest.ValidatorEndTime, // end time - nodeID: nodeID, // node ID - feeKeys: []*secp256k1.PrivateKey{preFundedKeys[0]}, // tx fee payer + stakeAmount: env.config.MinDelegatorStake, // weight + startTime: currentTimestamp, // start time + endTime: genesistest.ValidatorEndTime, // end time + nodeID: nodeID, // node ID + feeKeys: []*secp256k1.PrivateKey{genesistest.FundedKeys[0]}, // tx fee payer setup: nil, AP3Time: genesistest.Time, expectedExecutionErr: ErrTimestampNotBeforeStartTime, }, { description: "tx fee paying key has no funds", - stakeAmount: env.config.MinDelegatorStake, // weight - startTime: genesistest.Time.Add(time.Second), // start time - endTime: genesistest.ValidatorEndTime, // end time - nodeID: nodeID, // node ID - feeKeys: []*secp256k1.PrivateKey{preFundedKeys[1]}, // tx fee payer + stakeAmount: env.config.MinDelegatorStake, // weight + startTime: genesistest.Time.Add(time.Second), // start time + endTime: genesistest.ValidatorEndTime, // end time + nodeID: nodeID, // node ID + feeKeys: []*secp256k1.PrivateKey{genesistest.FundedKeys[1]}, // tx fee payer setup: func(env *environment) { // Remove all UTXOs owned by keys[1] utxoIDs, err := env.state.UTXOIDs( - preFundedKeys[1].PublicKey().Address().Bytes(), + genesistest.FundedKeys[1].PublicKey().Address().Bytes(), ids.Empty, math.MaxInt32) require.NoError(t, err) @@ -306,7 +306,7 @@ func TestStandardTxExecutorAddDelegator(t *testing.T) { startTime: newValidatorStartTime, // same start time as for primary network endTime: newValidatorEndTime, // same end time as for primary network nodeID: newValidatorID, - feeKeys: []*secp256k1.PrivateKey{preFundedKeys[0]}, + feeKeys: []*secp256k1.PrivateKey{genesistest.FundedKeys[0]}, setup: addMaxStakeValidator, AP3Time: genesistest.ValidatorEndTime, expectedExecutionErr: nil, @@ -317,7 +317,7 @@ func TestStandardTxExecutorAddDelegator(t *testing.T) { startTime: newValidatorStartTime, // same start time as for primary network endTime: newValidatorEndTime, // same end time as for primary network nodeID: newValidatorID, - feeKeys: []*secp256k1.PrivateKey{preFundedKeys[0]}, + feeKeys: []*secp256k1.PrivateKey{genesistest.FundedKeys[0]}, setup: addMaxStakeValidator, AP3Time: genesistest.Time, expectedExecutionErr: ErrOverDelegated, @@ -452,7 +452,7 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { dsStartTime := genesistest.Time.Add(10 * time.Second) dsEndTime := dsStartTime.Add(5 * defaultMinStakingDuration) - builder, signer := env.factory.NewWallet(preFundedKeys[0]) + builder, signer := env.factory.NewWallet(genesistest.FundedKeys[0]) utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: pendingDSValidatorID, @@ -808,7 +808,7 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { { // Case: Control Signature from invalid key (keys[3] is not a control key) startTime := genesistest.Time.Add(time.Second) - builder, signer := env.factory.NewWallet(testSubnet1ControlKeys[0], preFundedKeys[1]) + builder, signer := env.factory.NewWallet(testSubnet1ControlKeys[0], genesistest.FundedKeys[1]) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -825,7 +825,7 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { require.NoError(err) // Replace a valid signature with one from keys[3] - sig, err := preFundedKeys[3].SignHash(hashing.ComputeHash256(tx.Unsigned.Bytes())) + sig, err := genesistest.FundedKeys[3].SignHash(hashing.ComputeHash256(tx.Unsigned.Bytes())) require.NoError(err) copy(tx.Creds[0].(*secp256k1fx.Credential).Sigs[0][:], sig) @@ -940,7 +940,7 @@ func TestBanffStandardTxExecutorAddValidator(t *testing.T) { { // Case: Validator's start time too early - builder, signer := env.factory.NewWallet(preFundedKeys[0]) + builder, signer := env.factory.NewWallet(genesistest.FundedKeys[0]) utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID, @@ -975,7 +975,7 @@ func TestBanffStandardTxExecutorAddValidator(t *testing.T) { { // Case: Validator in current validator set of primary network startTime := genesistest.Time.Add(1 * time.Second) - builder, signer := env.factory.NewWallet(preFundedKeys[0]) + builder, signer := env.factory.NewWallet(genesistest.FundedKeys[0]) utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID, @@ -1022,7 +1022,7 @@ func TestBanffStandardTxExecutorAddValidator(t *testing.T) { { // Case: Validator in pending validator set of primary network startTime := genesistest.Time.Add(1 * time.Second) - builder, signer := env.factory.NewWallet(preFundedKeys[0]) + builder, signer := env.factory.NewWallet(genesistest.FundedKeys[0]) utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID, @@ -1066,7 +1066,7 @@ func TestBanffStandardTxExecutorAddValidator(t *testing.T) { { // Case: Validator doesn't have enough tokens to cover stake amount startTime := genesistest.Time.Add(1 * time.Second) - builder, signer := env.factory.NewWallet(preFundedKeys[0]) + builder, signer := env.factory.NewWallet(genesistest.FundedKeys[0]) utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID, @@ -1085,7 +1085,7 @@ func TestBanffStandardTxExecutorAddValidator(t *testing.T) { require.NoError(err) // Remove all UTXOs owned by preFundedKeys[0] - utxoIDs, err := env.state.UTXOIDs(preFundedKeys[0].PublicKey().Address().Bytes(), ids.Empty, math.MaxInt32) + utxoIDs, err := env.state.UTXOIDs(genesistest.FundedKeys[0].PublicKey().Address().Bytes(), ids.Empty, math.MaxInt32) require.NoError(err) onAcceptState, err := state.NewDiff(lastAcceptedID, env) @@ -1125,7 +1125,7 @@ func TestDurangoDisabledTransactions(t *testing.T) { endTime = chainTime.Add(defaultMaxStakingDuration) ) - builder, signer := env.factory.NewWallet(preFundedKeys...) + builder, signer := env.factory.NewWallet(genesistest.FundedKeys...) utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID, @@ -1163,7 +1163,7 @@ func TestDurangoDisabledTransactions(t *testing.T) { } it.Release() - builder, signer := env.factory.NewWallet(preFundedKeys...) + builder, signer := env.factory.NewWallet(genesistest.FundedKeys...) utx, err := builder.NewAddDelegatorTx( &txs.Validator{ NodeID: primaryValidator.NodeID, @@ -1235,7 +1235,7 @@ func TestDurangoMemoField(t *testing.T) { } it.Release() - builder, signer := env.factory.NewWallet(preFundedKeys...) + builder, signer := env.factory.NewWallet(genesistest.FundedKeys...) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -1260,7 +1260,7 @@ func TestDurangoMemoField(t *testing.T) { { name: "CreateChainTx", setupTest: func(env *environment, memoField []byte) (*txs.Tx, state.Diff) { - builder, signer := env.factory.NewWallet(preFundedKeys...) + builder, signer := env.factory.NewWallet(genesistest.FundedKeys...) utx, err := builder.NewCreateChainTx( testSubnet1.TxID, []byte{}, @@ -1282,7 +1282,7 @@ func TestDurangoMemoField(t *testing.T) { { name: "CreateSubnetTx", setupTest: func(env *environment, memoField []byte) (*txs.Tx, state.Diff) { - builder, signer := env.factory.NewWallet(preFundedKeys...) + builder, signer := env.factory.NewWallet(genesistest.FundedKeys...) utx, err := builder.NewCreateSubnetTx( &secp256k1fx.OutputOwners{ Threshold: 1, @@ -1308,7 +1308,7 @@ func TestDurangoMemoField(t *testing.T) { var ( sourceChain = env.ctx.XChainID - sourceKey = preFundedKeys[1] + sourceKey = genesistest.FundedKeys[1] sourceAmount = 10 * units.Avax ) @@ -1324,7 +1324,7 @@ func TestDurangoMemoField(t *testing.T) { ) env.msm.SharedMemory = sharedMemory - builder, signer := env.factory.NewWallet(preFundedKeys...) + builder, signer := env.factory.NewWallet(genesistest.FundedKeys...) utx, err := builder.NewImportTx( sourceChain, &secp256k1fx.OutputOwners{ @@ -1347,7 +1347,7 @@ func TestDurangoMemoField(t *testing.T) { { name: "ExportTx", setupTest: func(env *environment, memoField []byte) (*txs.Tx, state.Diff) { - builder, signer := env.factory.NewWallet(preFundedKeys...) + builder, signer := env.factory.NewWallet(genesistest.FundedKeys...) utx, err := builder.NewExportTx( env.ctx.XChainID, []*avax.TransferableOutput{{ @@ -1417,7 +1417,7 @@ func TestDurangoMemoField(t *testing.T) { Tx: subnetValTx, })) - builder, signer = env.factory.NewWallet(preFundedKeys...) + builder, signer = env.factory.NewWallet(genesistest.FundedKeys...) utx2, err := builder.NewRemoveSubnetValidatorTx( primaryValidator.NodeID, testSubnet1.ID(), @@ -1433,7 +1433,7 @@ func TestDurangoMemoField(t *testing.T) { { name: "TransformSubnetTx", setupTest: func(env *environment, memoField []byte) (*txs.Tx, state.Diff) { - builder, signer := env.factory.NewWallet(preFundedKeys...) + builder, signer := env.factory.NewWallet(genesistest.FundedKeys...) utx, err := builder.NewTransformSubnetTx( testSubnet1.TxID, // subnetID ids.GenerateTestID(), // assetID @@ -1472,7 +1472,7 @@ func TestDurangoMemoField(t *testing.T) { sk, err := bls.NewSecretKey() require.NoError(t, err) - builder, txSigner := env.factory.NewWallet(preFundedKeys...) + builder, txSigner := env.factory.NewWallet(genesistest.FundedKeys...) utx, err := builder.NewAddPermissionlessValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -1522,7 +1522,7 @@ func TestDurangoMemoField(t *testing.T) { } it.Release() - builder, signer := env.factory.NewWallet(preFundedKeys...) + builder, signer := env.factory.NewWallet(genesistest.FundedKeys...) utx, err := builder.NewAddPermissionlessDelegatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -1553,7 +1553,7 @@ func TestDurangoMemoField(t *testing.T) { { name: "TransferSubnetOwnershipTx", setupTest: func(env *environment, memoField []byte) (*txs.Tx, state.Diff) { - builder, signer := env.factory.NewWallet(preFundedKeys...) + builder, signer := env.factory.NewWallet(genesistest.FundedKeys...) utx, err := builder.NewTransferSubnetOwnershipTx( testSubnet1.TxID, &secp256k1fx.OutputOwners{ @@ -1575,7 +1575,7 @@ func TestDurangoMemoField(t *testing.T) { { name: "BaseTx", setupTest: func(env *environment, memoField []byte) (*txs.Tx, state.Diff) { - builder, signer := env.factory.NewWallet(preFundedKeys...) + builder, signer := env.factory.NewWallet(genesistest.FundedKeys...) utx, err := builder.NewBaseTx( []*avax.TransferableOutput{ { From b1f0d6790d4f555623e1e860700b39582ebe8ecc Mon Sep 17 00:00:00 2001 From: Stephen Buttolph Date: Thu, 22 Aug 2024 14:43:02 -0400 Subject: [PATCH 12/27] nit --- vms/platformvm/genesis/genesistest/genesis.go | 29 ++++++++++--------- vms/platformvm/genesis/genesistest/helper.go | 7 ++--- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/vms/platformvm/genesis/genesistest/genesis.go b/vms/platformvm/genesis/genesistest/genesis.go index d3228a410aa4..8d0ab699fb5f 100644 --- a/vms/platformvm/genesis/genesistest/genesis.go +++ b/vms/platformvm/genesis/genesistest/genesis.go @@ -23,25 +23,28 @@ import ( platformvmgenesis "github.com/ava-labs/avalanchego/vms/platformvm/genesis" ) -var ( - AVAXAsset = avax.Asset{ID: snowtest.AVAXAssetID} - - ValidatorNodeID = ids.GenerateTestNodeID() - Time = upgrade.InitiallyActiveTime - TimeUnix = uint64(Time.Unix()) - ValidatorDuration = 28 * 24 * time.Hour - ValidatorEndTime = Time.Add(ValidatorDuration) - ValidatorEndTimeUnix = uint64(ValidatorEndTime.Unix()) - ValidatorWeight = units.MegaAvax - ValidatorRewardsOwner = &secp256k1fx.OutputOwners{} - ValidatorDelegationShares uint32 = reward.PercentDenominator +const ( + ValidatorDuration = 28 * 24 * time.Hour + ValidatorWeight = units.MegaAvax + ValidatorDelegationShares = reward.PercentDenominator XChainName = "x" - InitialBalance = 30 * units.MegaAvax + InitialBalance = 10 * units.MegaAvax InitialSupply = ValidatorWeight + InitialBalance ) +var ( + AVAXAsset = avax.Asset{ID: snowtest.AVAXAssetID} + + ValidatorNodeID = ids.GenerateTestNodeID() + Time = upgrade.InitiallyActiveTime + TimeUnix = uint64(Time.Unix()) + ValidatorEndTime = Time.Add(ValidatorDuration) + ValidatorEndTimeUnix = uint64(ValidatorEndTime.Unix()) + ValidatorRewardsOwner = &secp256k1fx.OutputOwners{} +) + func New(t testing.TB) *platformvmgenesis.Genesis { require := require.New(t) diff --git a/vms/platformvm/genesis/genesistest/helper.go b/vms/platformvm/genesis/genesistest/helper.go index 572a4d5dfca1..dc408084df7b 100644 --- a/vms/platformvm/genesis/genesistest/helper.go +++ b/vms/platformvm/genesis/genesistest/helper.go @@ -5,7 +5,6 @@ package genesistest import ( "testing" - "time" "github.com/stretchr/testify/require" @@ -22,10 +21,8 @@ import ( ) const ( - defaultWeight = 5 * units.MilliAvax - defaultMinStakingDuration = 24 * time.Hour - defaultMinValidatorStake = 5 * units.MilliAvax - defaultBalance = 100 * defaultMinValidatorStake + defaultWeight = 5 * units.MilliAvax + defaultBalance = 500 * units.MilliAvax ) var ( From 259dd320a2e198631e8b210b8340902b3a767b6a Mon Sep 17 00:00:00 2001 From: Stephen Buttolph Date: Thu, 22 Aug 2024 15:04:54 -0400 Subject: [PATCH 13/27] wip --- vms/platformvm/block/builder/helpers_test.go | 2 +- vms/platformvm/block/executor/helpers_test.go | 2 +- vms/platformvm/genesis/genesistest/helper.go | 11 ++++++++--- vms/platformvm/service_test.go | 6 +++--- vms/platformvm/txs/executor/helpers_test.go | 2 +- vms/platformvm/vm_regression_test.go | 2 +- vms/platformvm/vm_test.go | 18 +++++++++--------- 7 files changed, 24 insertions(+), 19 deletions(-) diff --git a/vms/platformvm/block/builder/helpers_test.go b/vms/platformvm/block/builder/helpers_test.go index d492c5cea2d0..4abd918579fc 100644 --- a/vms/platformvm/block/builder/helpers_test.go +++ b/vms/platformvm/block/builder/helpers_test.go @@ -116,7 +116,7 @@ func newEnvironment(t *testing.T, f upgradetest.Fork) *environment { //nolint:un rewardsCalc := reward.NewCalculator(res.config.RewardConfig) res.state = statetest.New(t, statetest.Config{ DB: res.baseDB, - Genesis: genesistest.BuildGenesisTest(t), + Genesis: genesistest.BuildBytes(t), Validators: res.config.Validators, Context: res.ctx, Rewards: rewardsCalc, diff --git a/vms/platformvm/block/executor/helpers_test.go b/vms/platformvm/block/executor/helpers_test.go index 4021f65163b5..d4f488ac49d4 100644 --- a/vms/platformvm/block/executor/helpers_test.go +++ b/vms/platformvm/block/executor/helpers_test.go @@ -125,7 +125,7 @@ func newEnvironment(t *testing.T, ctrl *gomock.Controller, f upgradetest.Fork) * if ctrl == nil { res.state = statetest.New(t, statetest.Config{ DB: res.baseDB, - Genesis: genesistest.BuildGenesisTest(t), + Genesis: genesistest.BuildBytes(t), Validators: res.config.Validators, Context: res.ctx, Rewards: rewardsCalc, diff --git a/vms/platformvm/genesis/genesistest/helper.go b/vms/platformvm/genesis/genesistest/helper.go index dc408084df7b..5f76b3c21f2d 100644 --- a/vms/platformvm/genesis/genesistest/helper.go +++ b/vms/platformvm/genesis/genesistest/helper.go @@ -40,7 +40,7 @@ func init() { } } -func BuildGenesisTest(t *testing.T) []byte { +func Build(t *testing.T) *api.BuildGenesisArgs { require := require.New(t) genesisUTXOs := make([]api.UTXO, len(FundedKeys)) @@ -77,7 +77,7 @@ func BuildGenesisTest(t *testing.T) []byte { } } - buildGenesisArgs := api.BuildGenesisArgs{ + return &api.BuildGenesisArgs{ NetworkID: json.Uint32(constants.UnitTestID), AvaxAssetID: snowtest.AVAXAssetID, UTXOs: genesisUTXOs, @@ -87,10 +87,15 @@ func BuildGenesisTest(t *testing.T) []byte { InitialSupply: json.Uint64(360 * units.MegaAvax), Encoding: formatting.Hex, } +} + +func BuildBytes(t *testing.T) []byte { + require := require.New(t) + buildGenesisArgs := Build(t) buildGenesisResponse := api.BuildGenesisReply{} platformvmSS := api.StaticService{} - require.NoError(platformvmSS.BuildGenesis(nil, &buildGenesisArgs, &buildGenesisResponse)) + require.NoError(platformvmSS.BuildGenesis(nil, buildGenesisArgs, &buildGenesisResponse)) genesisBytes, err := formatting.Decode(buildGenesisResponse.Encoding, buildGenesisResponse.Bytes) require.NoError(err) diff --git a/vms/platformvm/service_test.go b/vms/platformvm/service_test.go index 1b39730db7ff..e7a9d3409103 100644 --- a/vms/platformvm/service_test.go +++ b/vms/platformvm/service_test.go @@ -384,7 +384,7 @@ func TestGetBalance(t *testing.T) { require.NoError(err) // Ensure GetStake is correct for each of the genesis validators - genesis, _ := defaultGenesis(t, service.vm.ctx.AVAXAssetID) + genesis, _ := defaultGenesis(t) for idx, utxo := range genesis.UTXOs { request := GetBalanceRequest{ Addresses: []string{ @@ -412,7 +412,7 @@ func TestGetStake(t *testing.T) { service, _, factory := defaultService(t) // Ensure GetStake is correct for each of the genesis validators - genesis, _ := defaultGenesis(t, service.vm.ctx.AVAXAssetID) + genesis, _ := defaultGenesis(t) addrsStrs := []string{} for _, validator := range genesis.Validators { addrStr := "P-" + validator.RewardOwner.Addresses[0] @@ -612,7 +612,7 @@ func TestGetCurrentValidators(t *testing.T) { require := require.New(t) service, _, factory := defaultService(t) - genesis, _ := defaultGenesis(t, service.vm.ctx.AVAXAssetID) + genesis, _ := defaultGenesis(t) // Call getValidators args := GetCurrentValidatorsArgs{SubnetID: constants.PrimaryNetworkID} diff --git a/vms/platformvm/txs/executor/helpers_test.go b/vms/platformvm/txs/executor/helpers_test.go index e2000cde8be7..dea18d377282 100644 --- a/vms/platformvm/txs/executor/helpers_test.go +++ b/vms/platformvm/txs/executor/helpers_test.go @@ -117,7 +117,7 @@ func newEnvironment(t *testing.T, f upgradetest.Fork) *environment { rewards := reward.NewCalculator(config.RewardConfig) baseState := statetest.New(t, statetest.Config{ DB: baseDB, - Genesis: genesistest.BuildGenesisTest(t), + Genesis: genesistest.BuildBytes(t), Validators: config.Validators, Upgrades: config.UpgradeConfig, Context: ctx, diff --git a/vms/platformvm/vm_regression_test.go b/vms/platformvm/vm_regression_test.go index 573a0b5fe247..a884d826a06d 100644 --- a/vms/platformvm/vm_regression_test.go +++ b/vms/platformvm/vm_regression_test.go @@ -464,7 +464,7 @@ func TestUnverifiedParentPanicRegression(t *testing.T) { ctx.Lock.Unlock() }() - _, genesisBytes := defaultGenesis(t, ctx.AVAXAssetID) + _, genesisBytes := defaultGenesis(t) msgChan := make(chan common.Message, 1) require.NoError(vm.Initialize( diff --git a/vms/platformvm/vm_test.go b/vms/platformvm/vm_test.go index 6c14120f6e92..2a74b8e7e24e 100644 --- a/vms/platformvm/vm_test.go +++ b/vms/platformvm/vm_test.go @@ -137,7 +137,7 @@ type mutableSharedMemory struct { // Returns: // 1) The genesis state // 2) The byte representation of the default genesis for tests -func defaultGenesis(t *testing.T, avaxAssetID ids.ID) (*api.BuildGenesisArgs, []byte) { +func defaultGenesis(t *testing.T) (*api.BuildGenesisArgs, []byte) { require := require.New(t) genesisUTXOs := make([]api.UTXO, len(keys)) @@ -177,7 +177,7 @@ func defaultGenesis(t *testing.T, avaxAssetID ids.ID) (*api.BuildGenesisArgs, [] buildGenesisArgs := api.BuildGenesisArgs{ Encoding: formatting.Hex, NetworkID: json.Uint32(constants.UnitTestID), - AvaxAssetID: avaxAssetID, + AvaxAssetID: snowtest.AVAXAssetID, UTXOs: genesisUTXOs, Validators: genesisValidators, Chains: nil, @@ -233,7 +233,7 @@ func defaultVM(t *testing.T, f upgradetest.Fork) (*VM, *txstest.WalletFactory, d ctx.Lock.Lock() defer ctx.Lock.Unlock() - _, genesisBytes := defaultGenesis(t, ctx.AVAXAssetID) + _, genesisBytes := defaultGenesis(t) appSender := &enginetest.Sender{} appSender.CantSendAppGossip = true appSender.SendAppGossipF = func(context.Context, common.SendConfig, []byte) error { @@ -324,7 +324,7 @@ func TestGenesis(t *testing.T) { require.NoError(err) require.NotNil(genesisBlock) - genesisState, _ := defaultGenesis(t, vm.ctx.AVAXAssetID) + genesisState, _ := defaultGenesis(t) // Ensure all the genesis UTXOs are there for _, utxo := range genesisState.UTXOs { _, addrBytes, err := address.ParseBech32(utxo.Address) @@ -1156,7 +1156,7 @@ func TestRestartFullyAccepted(t *testing.T) { firstCtx := snowtest.Context(t, snowtest.PChainID) - _, genesisBytes := defaultGenesis(t, firstCtx.AVAXAssetID) + _, genesisBytes := defaultGenesis(t) baseDB := memdb.New() atomicDB := prefixdb.New([]byte{1}, baseDB) @@ -1289,7 +1289,7 @@ func TestBootstrapPartiallyAccepted(t *testing.T) { vm.clock.Set(initialClkTime) ctx := snowtest.Context(t, snowtest.PChainID) - _, genesisBytes := defaultGenesis(t, ctx.AVAXAssetID) + _, genesisBytes := defaultGenesis(t) atomicDB := prefixdb.New([]byte{1}, baseDB) m := atomic.NewMemory(atomicDB) @@ -1640,7 +1640,7 @@ func TestUnverifiedParent(t *testing.T) { ctx.Lock.Unlock() }() - _, genesisBytes := defaultGenesis(t, ctx.AVAXAssetID) + _, genesisBytes := defaultGenesis(t) msgChan := make(chan common.Message, 1) require.NoError(vm.Initialize( @@ -1792,7 +1792,7 @@ func TestUptimeDisallowedWithRestart(t *testing.T) { firstCtx := snowtest.Context(t, snowtest.PChainID) firstCtx.Lock.Lock() - _, genesisBytes := defaultGenesis(t, firstCtx.AVAXAssetID) + _, genesisBytes := defaultGenesis(t) firstMsgChan := make(chan common.Message, 1) require.NoError(firstVM.Initialize( @@ -1935,7 +1935,7 @@ func TestUptimeDisallowedAfterNeverConnecting(t *testing.T) { ctx := snowtest.Context(t, snowtest.PChainID) ctx.Lock.Lock() - _, genesisBytes := defaultGenesis(t, ctx.AVAXAssetID) + _, genesisBytes := defaultGenesis(t) atomicDB := prefixdb.New([]byte{1}, db) m := atomic.NewMemory(atomicDB) From 62729ae820760449a40e963a003f838e865fd823 Mon Sep 17 00:00:00 2001 From: Stephen Buttolph Date: Thu, 22 Aug 2024 15:33:45 -0400 Subject: [PATCH 14/27] wip --- vms/platformvm/service_test.go | 26 +++--- vms/platformvm/validator_set_property_test.go | 18 ++-- vms/platformvm/vm_regression_test.go | 78 ++++++++-------- vms/platformvm/vm_test.go | 89 +++++++++---------- 4 files changed, 104 insertions(+), 107 deletions(-) diff --git a/vms/platformvm/service_test.go b/vms/platformvm/service_test.go index e7a9d3409103..0df492ed6833 100644 --- a/vms/platformvm/service_test.go +++ b/vms/platformvm/service_test.go @@ -107,7 +107,7 @@ func TestExportKey(t *testing.T) { pk, err := secp256k1.ToPrivateKey(testPrivateKey) require.NoError(err) - require.NoError(user.PutKeys(pk, keys[0])) + require.NoError(user.PutKeys(pk, genesistest.FundedKeys[0])) service.vm.ctx.Lock.Unlock() @@ -234,7 +234,7 @@ func TestGetTx(t *testing.T) { "chain name", common.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{keys[0].PublicKey().Address()}, + Addrs: []ids.ShortID{genesistest.FundedKeys[0].PublicKey().Address()}, }), ) require.NoError(t, err) @@ -252,7 +252,7 @@ func TestGetTx(t *testing.T) { Addrs: []ids.ShortID{ids.GenerateTestShortID()}, } - builder, txSigner := factory.NewWallet(keys[0]) + builder, txSigner := factory.NewWallet(genesistest.FundedKeys[0]) utx, err := builder.NewAddPermissionlessValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -270,7 +270,7 @@ func TestGetTx(t *testing.T) { 0, common.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{keys[0].PublicKey().Address()}, + Addrs: []ids.ShortID{genesistest.FundedKeys[0].PublicKey().Address()}, }), ) require.NoError(t, err) @@ -280,7 +280,7 @@ func TestGetTx(t *testing.T) { { "atomic block", func(service *Service, factory *txstest.WalletFactory) (*txs.Tx, error) { - builder, signer := factory.NewWallet(keys[0]) + builder, signer := factory.NewWallet(genesistest.FundedKeys[0]) utx, err := builder.NewExportTx( service.vm.ctx.XChainID, []*avax.TransferableOutput{{ @@ -296,7 +296,7 @@ func TestGetTx(t *testing.T) { }}, common.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{keys[0].PublicKey().Address()}, + Addrs: []ids.ShortID{genesistest.FundedKeys[0].PublicKey().Address()}, }), ) require.NoError(t, err) @@ -493,7 +493,7 @@ func TestGetStake(t *testing.T) { stakeAmount := service.vm.MinDelegatorStake + 12345 delegatorNodeID := genesistest.NodeIDs[0] delegatorEndTime := genesistest.Time.Add(defaultMinStakingDuration) - builder, signer := factory.NewWallet(keys[0]) + builder, signer := factory.NewWallet(genesistest.FundedKeys[0]) utx, err := builder.NewAddDelegatorTx( &txs.Validator{ NodeID: delegatorNodeID, @@ -507,7 +507,7 @@ func TestGetStake(t *testing.T) { }, common.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{keys[0].PublicKey().Address()}, + Addrs: []ids.ShortID{genesistest.FundedKeys[0].PublicKey().Address()}, }), ) require.NoError(err) @@ -530,7 +530,7 @@ func TestGetStake(t *testing.T) { service.vm.ctx.Lock.Unlock() // Make sure the delegator addr has the right stake (old stake + stakeAmount) - addr, _ := service.addrManager.FormatLocalAddress(keys[0].PublicKey().Address()) + addr, _ := service.addrManager.FormatLocalAddress(genesistest.FundedKeys[0].PublicKey().Address()) args.Addresses = []string{addr} require.NoError(service.GetStake(nil, &args, &response)) require.Equal(oldStake+stakeAmount, uint64(response.Staked)) @@ -571,7 +571,7 @@ func TestGetStake(t *testing.T) { 0, common.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{keys[0].PublicKey().Address()}, + Addrs: []ids.ShortID{genesistest.FundedKeys[0].PublicKey().Address()}, }), ) require.NoError(err) @@ -643,7 +643,7 @@ func TestGetCurrentValidators(t *testing.T) { service.vm.ctx.Lock.Lock() - builder, signer := factory.NewWallet(keys[0]) + builder, signer := factory.NewWallet(genesistest.FundedKeys[0]) utx, err := builder.NewAddDelegatorTx( &txs.Validator{ NodeID: validatorNodeID, @@ -657,7 +657,7 @@ func TestGetCurrentValidators(t *testing.T) { }, common.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{keys[0].PublicKey().Address()}, + Addrs: []ids.ShortID{genesistest.FundedKeys[0].PublicKey().Address()}, }), ) require.NoError(err) @@ -794,7 +794,7 @@ func TestGetBlock(t *testing.T) { "chain name", common.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{keys[0].PublicKey().Address()}, + Addrs: []ids.ShortID{genesistest.FundedKeys[0].PublicKey().Address()}, }), ) require.NoError(err) diff --git a/vms/platformvm/validator_set_property_test.go b/vms/platformvm/validator_set_property_test.go index 3f2ca72bf886..199f4e550eea 100644 --- a/vms/platformvm/validator_set_property_test.go +++ b/vms/platformvm/validator_set_property_test.go @@ -261,7 +261,7 @@ func takeValidatorsSnapshotAtCurrentHeight(vm *VM, validatorsSetByHeightAndSubne func addSubnetValidator(vm *VM, data *validatorInputData, subnetID ids.ID) (*state.Staker, error) { factory := txstest.NewWalletFactory(vm.ctx, &vm.Config, vm.state) - builder, signer := factory.NewWallet(keys[0], keys[1]) + builder, signer := factory.NewWallet(genesistest.FundedKeys[0], genesistest.FundedKeys[1]) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -274,7 +274,7 @@ func addSubnetValidator(vm *VM, data *validatorInputData, subnetID ids.ID) (*sta }, walletcommon.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{keys[0].PublicKey().Address()}, + Addrs: []ids.ShortID{genesistest.FundedKeys[0].PublicKey().Address()}, }), ) if err != nil { @@ -288,7 +288,7 @@ func addSubnetValidator(vm *VM, data *validatorInputData, subnetID ids.ID) (*sta } func addPrimaryValidatorWithBLSKey(vm *VM, data *validatorInputData) (*state.Staker, error) { - addr := keys[0].PublicKey().Address() + addr := genesistest.FundedKeys[0].PublicKey().Address() sk, err := bls.NewSecretKey() if err != nil { @@ -296,7 +296,7 @@ func addPrimaryValidatorWithBLSKey(vm *VM, data *validatorInputData) (*state.Sta } factory := txstest.NewWalletFactory(vm.ctx, &vm.Config, vm.state) - builder, txSigner := factory.NewWallet(keys[0], keys[1]) + builder, txSigner := factory.NewWallet(genesistest.FundedKeys[0], genesistest.FundedKeys[1]) utx, err := builder.NewAddPermissionlessValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -714,15 +714,15 @@ func buildVM(t *testing.T) (*VM, ids.ID, error) { // Note: following Banff activation, block acceptance will move // chain time ahead factory := txstest.NewWalletFactory(vm.ctx, &vm.Config, vm.state) - builder, signer := factory.NewWallet(keys[len(keys)-1]) + builder, signer := factory.NewWallet(genesistest.FundedKeys[len(genesistest.FundedKeys)-1]) utx, err := builder.NewCreateSubnetTx( &secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{keys[0].PublicKey().Address()}, + Addrs: []ids.ShortID{genesistest.FundedKeys[0].PublicKey().Address()}, }, walletcommon.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{keys[0].PublicKey().Address()}, + Addrs: []ids.ShortID{genesistest.FundedKeys[0].PublicKey().Address()}, }), ) if err != nil { @@ -757,8 +757,8 @@ func buildVM(t *testing.T) (*VM, ids.ID, error) { } func buildCustomGenesis(avaxAssetID ids.ID) ([]byte, error) { - genesisUTXOs := make([]api.UTXO, len(keys)) - for i, key := range keys { + genesisUTXOs := make([]api.UTXO, len(genesistest.FundedKeys)) + for i, key := range genesistest.FundedKeys { id := key.PublicKey().Address() addr, err := address.FormatBech32(constants.UnitTestHRP, id.Bytes()) if err != nil { diff --git a/vms/platformvm/vm_regression_test.go b/vms/platformvm/vm_regression_test.go index a884d826a06d..697a432b2f46 100644 --- a/vms/platformvm/vm_regression_test.go +++ b/vms/platformvm/vm_regression_test.go @@ -59,10 +59,10 @@ func TestAddDelegatorTxOverDelegatedRegression(t *testing.T) { validatorEndTime := validatorStartTime.Add(360 * 24 * time.Hour) nodeID := ids.GenerateTestNodeID() - changeAddr := keys[0].PublicKey().Address() + changeAddr := genesistest.FundedKeys[0].PublicKey().Address() // create valid tx - builder, txSigner := factory.NewWallet(keys[0]) + builder, txSigner := factory.NewWallet(genesistest.FundedKeys[0]) utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID, @@ -107,7 +107,7 @@ func TestAddDelegatorTxOverDelegatedRegression(t *testing.T) { firstDelegatorEndTime := firstDelegatorStartTime.Add(vm.MinStakeDuration) // create valid tx - builder, txSigner = factory.NewWallet(keys[0], keys[1]) + builder, txSigner = factory.NewWallet(genesistest.FundedKeys[0], genesistest.FundedKeys[1]) uDelTx1, err := builder.NewAddDelegatorTx( &txs.Validator{ NodeID: nodeID, @@ -153,7 +153,7 @@ func TestAddDelegatorTxOverDelegatedRegression(t *testing.T) { vm.clock.Set(secondDelegatorStartTime.Add(-10 * executor.SyncBound)) // create valid tx - builder, txSigner = factory.NewWallet(keys[0], keys[1], keys[3]) + builder, txSigner = factory.NewWallet(genesistest.FundedKeys[0], genesistest.FundedKeys[1], genesistest.FundedKeys[3]) uDelTx2, err := builder.NewAddDelegatorTx( &txs.Validator{ NodeID: nodeID, @@ -189,7 +189,7 @@ func TestAddDelegatorTxOverDelegatedRegression(t *testing.T) { thirdDelegatorEndTime := thirdDelegatorStartTime.Add(vm.MinStakeDuration) // create valid tx - builder, txSigner = factory.NewWallet(keys[0], keys[1], keys[4]) + builder, txSigner = factory.NewWallet(genesistest.FundedKeys[0], genesistest.FundedKeys[1], genesistest.FundedKeys[4]) uDelTx3, err := builder.NewAddDelegatorTx( &txs.Validator{ NodeID: nodeID, @@ -267,10 +267,10 @@ func TestAddDelegatorTxHeapCorruption(t *testing.T) { id := key.PublicKey().Address() nodeID := ids.GenerateTestNodeID() - changeAddr := keys[0].PublicKey().Address() + changeAddr := genesistest.FundedKeys[0].PublicKey().Address() // create valid tx - builder, txSigner := factory.NewWallet(keys[0], keys[1]) + builder, txSigner := factory.NewWallet(genesistest.FundedKeys[0], genesistest.FundedKeys[1]) utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID, @@ -314,7 +314,7 @@ func TestAddDelegatorTxHeapCorruption(t *testing.T) { }, &secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{keys[0].PublicKey().Address()}, + Addrs: []ids.ShortID{genesistest.FundedKeys[0].PublicKey().Address()}, }, walletcommon.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, @@ -347,7 +347,7 @@ func TestAddDelegatorTxHeapCorruption(t *testing.T) { }, &secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{keys[0].PublicKey().Address()}, + Addrs: []ids.ShortID{genesistest.FundedKeys[0].PublicKey().Address()}, }, walletcommon.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, @@ -380,7 +380,7 @@ func TestAddDelegatorTxHeapCorruption(t *testing.T) { }, &secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{keys[0].PublicKey().Address()}, + Addrs: []ids.ShortID{genesistest.FundedKeys[0].PublicKey().Address()}, }, walletcommon.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, @@ -413,7 +413,7 @@ func TestAddDelegatorTxHeapCorruption(t *testing.T) { }, &secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{keys[0].PublicKey().Address()}, + Addrs: []ids.ShortID{genesistest.FundedKeys[0].PublicKey().Address()}, }, walletcommon.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, @@ -486,8 +486,8 @@ func TestUnverifiedParentPanicRegression(t *testing.T) { vm.clock.Set(latestForkTime.Add(time.Second)) vm.state.SetTimestamp(latestForkTime.Add(time.Second)) - key0 := keys[0] - key1 := keys[1] + key0 := genesistest.FundedKeys[0] + key1 := genesistest.FundedKeys[1] addr0 := key0.PublicKey().Address() addr1 := key1.PublicKey().Address() @@ -602,7 +602,7 @@ func TestRejectedStateRegressionInvalidValidatorTimestamp(t *testing.T) { newValidatorEndTime := newValidatorStartTime.Add(defaultMinStakingDuration) // Create the tx to add a new validator - builder, txSigner := factory.NewWallet(keys[0]) + builder, txSigner := factory.NewWallet(genesistest.FundedKeys[0]) utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID, @@ -799,7 +799,7 @@ func TestRejectedStateRegressionInvalidValidatorReward(t *testing.T) { nodeID0 := ids.GenerateTestNodeID() // Create the tx to add the first new validator - builder, txSigner := factory.NewWallet(keys[0]) + builder, txSigner := factory.NewWallet(genesistest.FundedKeys[0]) utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID0, @@ -968,7 +968,7 @@ func TestRejectedStateRegressionInvalidValidatorReward(t *testing.T) { nodeID1 := ids.GenerateTestNodeID() // Create the tx to add the second new validator - builder, txSigner = factory.NewWallet(keys[1]) + builder, txSigner = factory.NewWallet(genesistest.FundedKeys[1]) utx1, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID1, @@ -1121,7 +1121,7 @@ func TestValidatorSetAtCacheOverwriteRegression(t *testing.T) { extraNodeID := ids.GenerateTestNodeID() // Create the tx to add the first new validator - builder, txSigner := factory.NewWallet(keys[0]) + builder, txSigner := factory.NewWallet(genesistest.FundedKeys[0]) utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: extraNodeID, @@ -1245,10 +1245,10 @@ func TestAddDelegatorTxAddBeforeRemove(t *testing.T) { id := key.Address() nodeID := ids.GenerateTestNodeID() - changeAddr := keys[0].PublicKey().Address() + changeAddr := genesistest.FundedKeys[0].PublicKey().Address() // create valid tx - builder, txSigner := factory.NewWallet(keys[0], keys[1]) + builder, txSigner := factory.NewWallet(genesistest.FundedKeys[0], genesistest.FundedKeys[1]) utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID, @@ -1292,7 +1292,7 @@ func TestAddDelegatorTxAddBeforeRemove(t *testing.T) { }, &secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{keys[0].PublicKey().Address()}, + Addrs: []ids.ShortID{genesistest.FundedKeys[0].PublicKey().Address()}, }, walletcommon.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, @@ -1325,7 +1325,7 @@ func TestAddDelegatorTxAddBeforeRemove(t *testing.T) { }, &secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{keys[0].PublicKey().Address()}, + Addrs: []ids.ShortID{genesistest.FundedKeys[0].PublicKey().Address()}, }, walletcommon.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, @@ -1359,9 +1359,9 @@ func TestRemovePermissionedValidatorDuringPendingToCurrentTransitionNotTracked(t id := key.Address() nodeID := ids.GenerateTestNodeID() - changeAddr := keys[0].PublicKey().Address() + changeAddr := genesistest.FundedKeys[0].PublicKey().Address() - builder, txSigner := factory.NewWallet(keys[0], keys[1]) + builder, txSigner := factory.NewWallet(genesistest.FundedKeys[0], genesistest.FundedKeys[1]) utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID, @@ -1508,9 +1508,9 @@ func TestRemovePermissionedValidatorDuringPendingToCurrentTransitionTracked(t *t id := key.PublicKey().Address() nodeID := ids.GenerateTestNodeID() - changeAddr := keys[0].PublicKey().Address() + changeAddr := genesistest.FundedKeys[0].PublicKey().Address() - builder, txSigner := factory.NewWallet(keys[0], keys[1]) + builder, txSigner := factory.NewWallet(genesistest.FundedKeys[0], genesistest.FundedKeys[1]) utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID, @@ -1655,13 +1655,13 @@ func TestSubnetValidatorBLSKeyDiffAfterExpiry(t *testing.T) { // insert primary network validator var ( nodeID = ids.GenerateTestNodeID() - addr = keys[0].PublicKey().Address() + addr = genesistest.FundedKeys[0].PublicKey().Address() ) sk1, err := bls.NewSecretKey() require.NoError(err) // build primary network validator with BLS key - builder, txSigner := factory.NewWallet(keys...) + builder, txSigner := factory.NewWallet(genesistest.FundedKeys...) uPrimaryTx, err := builder.NewAddPermissionlessValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -1710,7 +1710,7 @@ func TestSubnetValidatorBLSKeyDiffAfterExpiry(t *testing.T) { require.NoError(err) // insert the subnet validator - builder, txSigner = factory.NewWallet(keys[0], keys[1]) + builder, txSigner = factory.NewWallet(genesistest.FundedKeys[0], genesistest.FundedKeys[1]) uAddSubnetValTx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -1791,7 +1791,7 @@ func TestSubnetValidatorBLSKeyDiffAfterExpiry(t *testing.T) { require.NoError(err) require.NotEqual(sk1, sk2) - builder, txSigner = factory.NewWallet(keys...) + builder, txSigner = factory.NewWallet(genesistest.FundedKeys...) uPrimaryRestartTx, err := builder.NewAddPermissionlessValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -1915,9 +1915,9 @@ func TestPrimaryNetworkValidatorPopulatedToEmptyBLSKeyDiff(t *testing.T) { // Add a primary network validator with no BLS key nodeID := ids.GenerateTestNodeID() - addr := keys[0].PublicKey().Address() + addr := genesistest.FundedKeys[0].PublicKey().Address() - builder, txSigner := factory.NewWallet(keys[0]) + builder, txSigner := factory.NewWallet(genesistest.FundedKeys[0]) uAddValTx1, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID, @@ -1987,7 +1987,7 @@ func TestPrimaryNetworkValidatorPopulatedToEmptyBLSKeyDiff(t *testing.T) { sk2, err := bls.NewSecretKey() require.NoError(err) - builder, txSigner = factory.NewWallet(keys...) + builder, txSigner = factory.NewWallet(genesistest.FundedKeys...) uPrimaryRestartTx, err := builder.NewAddPermissionlessValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -2075,9 +2075,9 @@ func TestSubnetValidatorPopulatedToEmptyBLSKeyDiff(t *testing.T) { // Add a primary network validator with no BLS key nodeID := ids.GenerateTestNodeID() - addr := keys[0].PublicKey().Address() + addr := genesistest.FundedKeys[0].PublicKey().Address() - builder, txSigner := factory.NewWallet(keys[0]) + builder, txSigner := factory.NewWallet(genesistest.FundedKeys[0]) uPrimaryTx1, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID, @@ -2117,7 +2117,7 @@ func TestSubnetValidatorPopulatedToEmptyBLSKeyDiff(t *testing.T) { require.NoError(err) // insert the subnet validator - builder, txSigner = factory.NewWallet(keys[0], keys[1]) + builder, txSigner = factory.NewWallet(genesistest.FundedKeys[0], genesistest.FundedKeys[1]) uAddSubnetValTx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -2197,7 +2197,7 @@ func TestSubnetValidatorPopulatedToEmptyBLSKeyDiff(t *testing.T) { sk2, err := bls.NewSecretKey() require.NoError(err) - builder, txSigner = factory.NewWallet(keys...) + builder, txSigner = factory.NewWallet(genesistest.FundedKeys...) uPrimaryRestartTx, err := builder.NewAddPermissionlessValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -2292,9 +2292,9 @@ func TestSubnetValidatorSetAfterPrimaryNetworkValidatorRemoval(t *testing.T) { // Add a primary network validator with no BLS key nodeID := ids.GenerateTestNodeID() - addr := keys[0].PublicKey().Address() + addr := genesistest.FundedKeys[0].PublicKey().Address() - builder, txSigner := factory.NewWallet(keys[0]) + builder, txSigner := factory.NewWallet(genesistest.FundedKeys[0]) uPrimaryTx1, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID, @@ -2331,7 +2331,7 @@ func TestSubnetValidatorSetAfterPrimaryNetworkValidatorRemoval(t *testing.T) { require.NoError(err) // insert the subnet validator - builder, txSigner = factory.NewWallet(keys[0], keys[1]) + builder, txSigner = factory.NewWallet(genesistest.FundedKeys[0], genesistest.FundedKeys[1]) uAddSubnetValTx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ diff --git a/vms/platformvm/vm_test.go b/vms/platformvm/vm_test.go index 2a74b8e7e24e..58d000a0c52a 100644 --- a/vms/platformvm/vm_test.go +++ b/vms/platformvm/vm_test.go @@ -94,9 +94,6 @@ var ( latestForkTime = genesistest.Time.Add(time.Second) - // each key controls an address that has [defaultBalance] AVAX at genesis - keys = secp256k1.TestKeys() - // Node IDs of genesis validators. Initialized in init function defaultMinDelegatorStake = 1 * units.MilliAvax defaultMinValidatorStake = 5 * defaultMinDelegatorStake @@ -127,7 +124,7 @@ var ( // Its controlKeys are keys[0], keys[1], keys[2] // Its threshold is 2 testSubnet1 *txs.Tx - testSubnet1ControlKeys = keys[0:3] + testSubnet1ControlKeys = genesistest.FundedKeys[0:3] ) type mutableSharedMemory struct { @@ -140,8 +137,8 @@ type mutableSharedMemory struct { func defaultGenesis(t *testing.T) (*api.BuildGenesisArgs, []byte) { require := require.New(t) - genesisUTXOs := make([]api.UTXO, len(keys)) - for i, key := range keys { + genesisUTXOs := make([]api.UTXO, len(genesistest.FundedKeys)) + for i, key := range genesistest.FundedKeys { id := key.PublicKey().Address() addr, err := address.FormatBech32(constants.UnitTestHRP, id.Bytes()) require.NoError(err) @@ -153,7 +150,7 @@ func defaultGenesis(t *testing.T) (*api.BuildGenesisArgs, []byte) { genesisValidators := make([]api.GenesisPermissionlessValidator, len(genesistest.NodeIDs)) for i, nodeID := range genesistest.NodeIDs { - addr := keys[i].Address() + addr := genesistest.FundedKeys[i].Address() addrStr, err := address.FormatBech32(constants.UnitTestHRP, addr.Bytes()) require.NoError(err) genesisValidators[i] = api.GenesisPermissionlessValidator{ @@ -270,19 +267,19 @@ func defaultVM(t *testing.T, f upgradetest.Fork) (*VM, *txstest.WalletFactory, d // Create a subnet and store it in testSubnet1 // Note: following Banff activation, block acceptance will move // chain time ahead - builder, signer := factory.NewWallet(keys[0]) + builder, signer := factory.NewWallet(genesistest.FundedKeys[0]) utx, err := builder.NewCreateSubnetTx( &secp256k1fx.OutputOwners{ Threshold: 2, Addrs: []ids.ShortID{ - keys[0].PublicKey().Address(), - keys[1].PublicKey().Address(), - keys[2].PublicKey().Address(), + genesistest.FundedKeys[0].PublicKey().Address(), + genesistest.FundedKeys[1].PublicKey().Address(), + genesistest.FundedKeys[2].PublicKey().Address(), }, }, walletcommon.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{keys[0].PublicKey().Address()}, + Addrs: []ids.ShortID{genesistest.FundedKeys[0].PublicKey().Address()}, }), ) require.NoError(err) @@ -340,7 +337,7 @@ func TestGenesis(t *testing.T) { out := utxos[0].Out.(*secp256k1fx.TransferOutput) if out.Amount() != uint64(utxo.Amount) { - id := keys[0].PublicKey().Address() + id := genesistest.FundedKeys[0].PublicKey().Address() addr, err := address.FormatBech32(constants.UnitTestHRP, id.Bytes()) require.NoError(err) @@ -380,7 +377,7 @@ func TestAddValidatorCommit(t *testing.T) { require.NoError(err) // create valid tx - builder, txSigner := factory.NewWallet(keys[0]) + builder, txSigner := factory.NewWallet(genesistest.FundedKeys[0]) utx, err := builder.NewAddPermissionlessValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -439,7 +436,7 @@ func TestInvalidAddValidatorCommit(t *testing.T) { endTime := startTime.Add(defaultMinStakingDuration) // create invalid tx - builder, txSigner := factory.NewWallet(keys[0]) + builder, txSigner := factory.NewWallet(genesistest.FundedKeys[0]) utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID, @@ -498,7 +495,7 @@ func TestAddValidatorReject(t *testing.T) { ) // create valid tx - builder, txSigner := factory.NewWallet(keys[0]) + builder, txSigner := factory.NewWallet(genesistest.FundedKeys[0]) utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID, @@ -551,7 +548,7 @@ func TestAddValidatorInvalidNotReissued(t *testing.T) { require.NoError(err) // create valid tx - builder, txSigner := factory.NewWallet(keys[0]) + builder, txSigner := factory.NewWallet(genesistest.FundedKeys[0]) utx, err := builder.NewAddPermissionlessValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -894,18 +891,18 @@ func TestCreateSubnet(t *testing.T) { vm.ctx.Lock.Lock() defer vm.ctx.Lock.Unlock() - builder, txSigner := factory.NewWallet(keys[0]) + builder, txSigner := factory.NewWallet(genesistest.FundedKeys[0]) uCreateSubnetTx, err := builder.NewCreateSubnetTx( &secp256k1fx.OutputOwners{ Threshold: 1, Addrs: []ids.ShortID{ - keys[0].PublicKey().Address(), - keys[1].PublicKey().Address(), + genesistest.FundedKeys[0].PublicKey().Address(), + genesistest.FundedKeys[1].PublicKey().Address(), }, }, walletcommon.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{keys[0].PublicKey().Address()}, + Addrs: []ids.ShortID{genesistest.FundedKeys[0].PublicKey().Address()}, }), ) require.NoError(err) @@ -1001,14 +998,14 @@ func TestAtomicImport(t *testing.T) { OutputIndex: 1, } amount := uint64(50000) - recipientKey := keys[1] + recipientKey := genesistest.FundedKeys[1] m := atomic.NewMemory(prefixdb.New([]byte{5}, baseDB)) mutableSharedMemory.SharedMemory = m.NewSharedMemory(vm.ctx.ChainID) peerSharedMemory := m.NewSharedMemory(vm.ctx.XChainID) - builder, _ := factory.NewWallet(keys[0]) + builder, _ := factory.NewWallet(genesistest.FundedKeys[0]) _, err := builder.NewImportTx( vm.ctx.XChainID, &secp256k1fx.OutputOwners{ @@ -2037,7 +2034,7 @@ func TestRemovePermissionedValidatorDuringAddPending(t *testing.T) { sk, err := bls.NewSecretKey() require.NoError(err) - builder, txSigner := factory.NewWallet(keys[0]) + builder, txSigner := factory.NewWallet(genesistest.FundedKeys[0]) uAddValTx, err := builder.NewAddPermissionlessValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -2061,7 +2058,7 @@ func TestRemovePermissionedValidatorDuringAddPending(t *testing.T) { reward.PercentDenominator, walletcommon.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{keys[0].PublicKey().Address()}, + Addrs: []ids.ShortID{genesistest.FundedKeys[0].PublicKey().Address()}, }), ) require.NoError(err) @@ -2086,7 +2083,7 @@ func TestRemovePermissionedValidatorDuringAddPending(t *testing.T) { }, walletcommon.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{keys[0].PublicKey().Address()}, + Addrs: []ids.ShortID{genesistest.FundedKeys[0].PublicKey().Address()}, }), ) require.NoError(err) @@ -2104,7 +2101,7 @@ func TestRemovePermissionedValidatorDuringAddPending(t *testing.T) { require.NoError(createSubnetBlock.Accept(context.Background())) require.NoError(vm.SetPreference(context.Background(), vm.manager.LastAccepted())) - builder, txSigner = factory.NewWallet(key, keys[1]) + builder, txSigner = factory.NewWallet(key, genesistest.FundedKeys[1]) uAddSubnetValTx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -2117,20 +2114,20 @@ func TestRemovePermissionedValidatorDuringAddPending(t *testing.T) { }, walletcommon.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{keys[1].PublicKey().Address()}, + Addrs: []ids.ShortID{genesistest.FundedKeys[1].PublicKey().Address()}, }), ) require.NoError(err) addSubnetValidatorTx, err := walletsigner.SignUnsigned(context.Background(), txSigner, uAddSubnetValTx) require.NoError(err) - builder, txSigner = factory.NewWallet(key, keys[2]) + builder, txSigner = factory.NewWallet(key, genesistest.FundedKeys[2]) uRemoveSubnetValTx, err := builder.NewRemoveSubnetValidatorTx( nodeID, createSubnetTx.ID(), walletcommon.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{keys[2].PublicKey().Address()}, + Addrs: []ids.ShortID{genesistest.FundedKeys[2].PublicKey().Address()}, }), ) require.NoError(err) @@ -2165,15 +2162,15 @@ func TestTransferSubnetOwnershipTx(t *testing.T) { vm.ctx.Lock.Lock() defer vm.ctx.Lock.Unlock() - builder, txSigner := factory.NewWallet(keys[0]) + builder, txSigner := factory.NewWallet(genesistest.FundedKeys[0]) uCreateSubnetTx, err := builder.NewCreateSubnetTx( &secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{keys[0].PublicKey().Address()}, + Addrs: []ids.ShortID{genesistest.FundedKeys[0].PublicKey().Address()}, }, walletcommon.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{keys[0].PublicKey().Address()}, + Addrs: []ids.ShortID{genesistest.FundedKeys[0].PublicKey().Address()}, }), ) require.NoError(err) @@ -2202,7 +2199,7 @@ func TestTransferSubnetOwnershipTx(t *testing.T) { Locktime: 0, Threshold: 1, Addrs: []ids.ShortID{ - keys[0].PublicKey().Address(), + genesistest.FundedKeys[0].PublicKey().Address(), }, } ctx, err := walletbuilder.NewSnowContext(vm.ctx.NetworkID, vm.ctx.AVAXAssetID) @@ -2214,7 +2211,7 @@ func TestTransferSubnetOwnershipTx(t *testing.T) { subnetID, &secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{keys[1].PublicKey().Address()}, + Addrs: []ids.ShortID{genesistest.FundedKeys[1].PublicKey().Address()}, }, ) require.NoError(err) @@ -2241,7 +2238,7 @@ func TestTransferSubnetOwnershipTx(t *testing.T) { Locktime: 0, Threshold: 1, Addrs: []ids.ShortID{ - keys[1].PublicKey().Address(), + genesistest.FundedKeys[1].PublicKey().Address(), }, } expectedOwner.InitCtx(ctx) @@ -2257,7 +2254,7 @@ func TestBaseTx(t *testing.T) { sendAmt := uint64(100000) changeAddr := ids.ShortEmpty - builder, txSigner := factory.NewWallet(keys[0]) + builder, txSigner := factory.NewWallet(genesistest.FundedKeys[0]) utx, err := builder.NewBaseTx( []*avax.TransferableOutput{ { @@ -2267,7 +2264,7 @@ func TestBaseTx(t *testing.T) { OutputOwners: secp256k1fx.OutputOwners{ Threshold: 1, Addrs: []ids.ShortID{ - keys[1].Address(), + genesistest.FundedKeys[1].Address(), }, }, }, @@ -2289,7 +2286,7 @@ func TestBaseTx(t *testing.T) { require.NoError(err) require.IsType(&secp256k1fx.TransferOutput{}, utxo.Out) castOut := utxo.Out.(*secp256k1fx.TransferOutput) - if castOut.AddressesSet().Equals(set.Of(keys[0].Address())) { + if castOut.AddressesSet().Equals(set.Of(genesistest.FundedKeys[0].Address())) { key0InputAmt += castOut.Amt } totalInputAmt += castOut.Amt @@ -2303,10 +2300,10 @@ func TestBaseTx(t *testing.T) { for _, output := range baseTx.Unsigned.Outputs() { require.IsType(&secp256k1fx.TransferOutput{}, output.Out) castOut := output.Out.(*secp256k1fx.TransferOutput) - if castOut.AddressesSet().Equals(set.Of(keys[0].Address())) { + if castOut.AddressesSet().Equals(set.Of(genesistest.FundedKeys[0].Address())) { key0OutputAmt += castOut.Amt } - if castOut.AddressesSet().Equals(set.Of(keys[1].Address())) { + if castOut.AddressesSet().Equals(set.Of(genesistest.FundedKeys[1].Address())) { key1OutputAmt += castOut.Amt } if castOut.AddressesSet().Equals(set.Of(changeAddr)) { @@ -2344,7 +2341,7 @@ func TestPruneMempool(t *testing.T) { sendAmt := uint64(100000) changeAddr := ids.ShortEmpty - builder, txSigner := factory.NewWallet(keys[0]) + builder, txSigner := factory.NewWallet(genesistest.FundedKeys[0]) utx, err := builder.NewBaseTx( []*avax.TransferableOutput{ { @@ -2354,7 +2351,7 @@ func TestPruneMempool(t *testing.T) { OutputOwners: secp256k1fx.OutputOwners{ Threshold: 1, Addrs: []ids.ShortID{ - keys[1].Address(), + genesistest.FundedKeys[1].Address(), }, }, }, @@ -2387,7 +2384,7 @@ func TestPruneMempool(t *testing.T) { sk, err := bls.NewSecretKey() require.NoError(err) - builder, txSigner = factory.NewWallet(keys[1]) + builder, txSigner = factory.NewWallet(genesistest.FundedKeys[1]) uAddValTx, err := builder.NewAddPermissionlessValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -2402,11 +2399,11 @@ func TestPruneMempool(t *testing.T) { vm.ctx.AVAXAssetID, &secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{keys[2].Address()}, + Addrs: []ids.ShortID{genesistest.FundedKeys[2].Address()}, }, &secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{keys[2].Address()}, + Addrs: []ids.ShortID{genesistest.FundedKeys[2].Address()}, }, 20000, ) From c74673a8bcfee033ed57ba9c812948e82f68fa0d Mon Sep 17 00:00:00 2001 From: Stephen Buttolph Date: Thu, 22 Aug 2024 15:42:00 -0400 Subject: [PATCH 15/27] wip --- vms/platformvm/genesis/genesistest/helper.go | 2 +- vms/platformvm/vm_test.go | 18 ++++++++++-------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/vms/platformvm/genesis/genesistest/helper.go b/vms/platformvm/genesis/genesistest/helper.go index 5f76b3c21f2d..f06dbb39089b 100644 --- a/vms/platformvm/genesis/genesistest/helper.go +++ b/vms/platformvm/genesis/genesistest/helper.go @@ -22,7 +22,7 @@ import ( const ( defaultWeight = 5 * units.MilliAvax - defaultBalance = 500 * units.MilliAvax + defaultBalance = 1 * units.Avax ) var ( diff --git a/vms/platformvm/vm_test.go b/vms/platformvm/vm_test.go index 58d000a0c52a..8b6d47389cf3 100644 --- a/vms/platformvm/vm_test.go +++ b/vms/platformvm/vm_test.go @@ -77,7 +77,15 @@ import ( walletcommon "github.com/ava-labs/avalanchego/wallet/subnet/primary/common" ) -const defaultWeight uint64 = 10000 +const ( + defaultWeight = 5 * units.MilliAvax + + // Node IDs of genesis validators. Initialized in init function + defaultMinDelegatorStake = 1 * units.MilliAvax + defaultMinValidatorStake = 5 * defaultMinDelegatorStake + defaultMaxValidatorStake = 100 * defaultMinValidatorStake + defaultBalance = 2 * defaultMaxValidatorStake // amount all genesis validators have in defaultVM +) var ( defaultMinStakingDuration = 24 * time.Hour @@ -94,12 +102,6 @@ var ( latestForkTime = genesistest.Time.Add(time.Second) - // Node IDs of genesis validators. Initialized in init function - defaultMinDelegatorStake = 1 * units.MilliAvax - defaultMinValidatorStake = 5 * defaultMinDelegatorStake - defaultMaxValidatorStake = 100 * defaultMinValidatorStake - defaultBalance = 2 * defaultMaxValidatorStake // amount all genesis validators have in defaultVM - defaultStaticFeeConfig = txfee.StaticConfig{ TxFee: defaultTxFee, CreateSubnetTxFee: 100 * defaultTxFee, @@ -178,7 +180,7 @@ func defaultGenesis(t *testing.T) (*api.BuildGenesisArgs, []byte) { UTXOs: genesisUTXOs, Validators: genesisValidators, Chains: nil, - Time: json.Uint64(genesistest.Time.Unix()), + Time: json.Uint64(genesistest.TimeUnix), InitialSupply: json.Uint64(360 * units.MegaAvax), } From 7715994bf023f7adcc62949a637dfe10c5d974d6 Mon Sep 17 00:00:00 2001 From: Stephen Buttolph Date: Thu, 22 Aug 2024 15:48:10 -0400 Subject: [PATCH 16/27] another one --- vms/platformvm/service_test.go | 6 +- vms/platformvm/vm_regression_test.go | 4 +- vms/platformvm/vm_test.go | 85 +++------------------------- 3 files changed, 11 insertions(+), 84 deletions(-) diff --git a/vms/platformvm/service_test.go b/vms/platformvm/service_test.go index 0df492ed6833..0e4ae5d7f10b 100644 --- a/vms/platformvm/service_test.go +++ b/vms/platformvm/service_test.go @@ -384,7 +384,7 @@ func TestGetBalance(t *testing.T) { require.NoError(err) // Ensure GetStake is correct for each of the genesis validators - genesis, _ := defaultGenesis(t) + genesis := genesistest.Build(t) for idx, utxo := range genesis.UTXOs { request := GetBalanceRequest{ Addresses: []string{ @@ -412,7 +412,7 @@ func TestGetStake(t *testing.T) { service, _, factory := defaultService(t) // Ensure GetStake is correct for each of the genesis validators - genesis, _ := defaultGenesis(t) + genesis := genesistest.Build(t) addrsStrs := []string{} for _, validator := range genesis.Validators { addrStr := "P-" + validator.RewardOwner.Addresses[0] @@ -612,7 +612,7 @@ func TestGetCurrentValidators(t *testing.T) { require := require.New(t) service, _, factory := defaultService(t) - genesis, _ := defaultGenesis(t) + genesis := genesistest.Build(t) // Call getValidators args := GetCurrentValidatorsArgs{SubnetID: constants.PrimaryNetworkID} diff --git a/vms/platformvm/vm_regression_test.go b/vms/platformvm/vm_regression_test.go index 697a432b2f46..774b490e3a1a 100644 --- a/vms/platformvm/vm_regression_test.go +++ b/vms/platformvm/vm_regression_test.go @@ -464,14 +464,12 @@ func TestUnverifiedParentPanicRegression(t *testing.T) { ctx.Lock.Unlock() }() - _, genesisBytes := defaultGenesis(t) - msgChan := make(chan common.Message, 1) require.NoError(vm.Initialize( context.Background(), ctx, baseDB, - genesisBytes, + genesistest.BuildBytes(t), nil, nil, msgChan, diff --git a/vms/platformvm/vm_test.go b/vms/platformvm/vm_test.go index 8b6d47389cf3..a043547dc78d 100644 --- a/vms/platformvm/vm_test.go +++ b/vms/platformvm/vm_test.go @@ -40,9 +40,7 @@ import ( "github.com/ava-labs/avalanchego/utils/constants" "github.com/ava-labs/avalanchego/utils/crypto/bls" "github.com/ava-labs/avalanchego/utils/crypto/secp256k1" - "github.com/ava-labs/avalanchego/utils/formatting" "github.com/ava-labs/avalanchego/utils/formatting/address" - "github.com/ava-labs/avalanchego/utils/json" "github.com/ava-labs/avalanchego/utils/logging" "github.com/ava-labs/avalanchego/utils/math/meter" "github.com/ava-labs/avalanchego/utils/resource" @@ -51,7 +49,6 @@ import ( "github.com/ava-labs/avalanchego/utils/units" "github.com/ava-labs/avalanchego/version" "github.com/ava-labs/avalanchego/vms/components/avax" - "github.com/ava-labs/avalanchego/vms/platformvm/api" "github.com/ava-labs/avalanchego/vms/platformvm/block" "github.com/ava-labs/avalanchego/vms/platformvm/config" "github.com/ava-labs/avalanchego/vms/platformvm/genesis/genesistest" @@ -133,67 +130,6 @@ type mutableSharedMemory struct { atomic.SharedMemory } -// Returns: -// 1) The genesis state -// 2) The byte representation of the default genesis for tests -func defaultGenesis(t *testing.T) (*api.BuildGenesisArgs, []byte) { - require := require.New(t) - - genesisUTXOs := make([]api.UTXO, len(genesistest.FundedKeys)) - for i, key := range genesistest.FundedKeys { - id := key.PublicKey().Address() - addr, err := address.FormatBech32(constants.UnitTestHRP, id.Bytes()) - require.NoError(err) - genesisUTXOs[i] = api.UTXO{ - Amount: json.Uint64(defaultBalance), - Address: addr, - } - } - - genesisValidators := make([]api.GenesisPermissionlessValidator, len(genesistest.NodeIDs)) - for i, nodeID := range genesistest.NodeIDs { - addr := genesistest.FundedKeys[i].Address() - addrStr, err := address.FormatBech32(constants.UnitTestHRP, addr.Bytes()) - require.NoError(err) - genesisValidators[i] = api.GenesisPermissionlessValidator{ - GenesisValidator: api.GenesisValidator{ - StartTime: json.Uint64(genesistest.TimeUnix), - EndTime: json.Uint64(genesistest.ValidatorEndTimeUnix), - NodeID: nodeID, - }, - RewardOwner: &api.Owner{ - Threshold: 1, - Addresses: []string{addrStr}, - }, - Staked: []api.UTXO{{ - Amount: json.Uint64(defaultWeight), - Address: addrStr, - }}, - DelegationFee: reward.PercentDenominator, - } - } - - buildGenesisArgs := api.BuildGenesisArgs{ - Encoding: formatting.Hex, - NetworkID: json.Uint32(constants.UnitTestID), - AvaxAssetID: snowtest.AVAXAssetID, - UTXOs: genesisUTXOs, - Validators: genesisValidators, - Chains: nil, - Time: json.Uint64(genesistest.TimeUnix), - InitialSupply: json.Uint64(360 * units.MegaAvax), - } - - buildGenesisResponse := api.BuildGenesisReply{} - platformvmSS := api.StaticService{} - require.NoError(platformvmSS.BuildGenesis(nil, &buildGenesisArgs, &buildGenesisResponse)) - - genesisBytes, err := formatting.Decode(buildGenesisResponse.Encoding, buildGenesisResponse.Bytes) - require.NoError(err) - - return &buildGenesisArgs, genesisBytes -} - func defaultVM(t *testing.T, f upgradetest.Fork) (*VM, *txstest.WalletFactory, database.Database, *mutableSharedMemory) { require := require.New(t) @@ -232,7 +168,6 @@ func defaultVM(t *testing.T, f upgradetest.Fork) (*VM, *txstest.WalletFactory, d ctx.Lock.Lock() defer ctx.Lock.Unlock() - _, genesisBytes := defaultGenesis(t) appSender := &enginetest.Sender{} appSender.CantSendAppGossip = true appSender.SendAppGossipF = func(context.Context, common.SendConfig, []byte) error { @@ -247,7 +182,7 @@ func defaultVM(t *testing.T, f upgradetest.Fork) (*VM, *txstest.WalletFactory, d context.Background(), ctx, chainDB, - genesisBytes, + genesistest.BuildBytes(t), nil, dynamicConfigBytes, msgChan, @@ -323,7 +258,7 @@ func TestGenesis(t *testing.T) { require.NoError(err) require.NotNil(genesisBlock) - genesisState, _ := defaultGenesis(t) + genesisState := genesistest.Build(t) // Ensure all the genesis UTXOs are there for _, utxo := range genesisState.UTXOs { _, addrBytes, err := address.ParseBech32(utxo.Address) @@ -1155,7 +1090,7 @@ func TestRestartFullyAccepted(t *testing.T) { firstCtx := snowtest.Context(t, snowtest.PChainID) - _, genesisBytes := defaultGenesis(t) + genesisBytes := genesistest.BuildBytes(t) baseDB := memdb.New() atomicDB := prefixdb.New([]byte{1}, baseDB) @@ -1288,8 +1223,6 @@ func TestBootstrapPartiallyAccepted(t *testing.T) { vm.clock.Set(initialClkTime) ctx := snowtest.Context(t, snowtest.PChainID) - _, genesisBytes := defaultGenesis(t) - atomicDB := prefixdb.New([]byte{1}, baseDB) m := atomic.NewMemory(atomicDB) ctx.SharedMemory = m.NewSharedMemory(ctx.ChainID) @@ -1302,7 +1235,7 @@ func TestBootstrapPartiallyAccepted(t *testing.T) { context.Background(), ctx, vmDB, - genesisBytes, + genesistest.BuildBytes(t), nil, nil, msgChan, @@ -1639,14 +1572,12 @@ func TestUnverifiedParent(t *testing.T) { ctx.Lock.Unlock() }() - _, genesisBytes := defaultGenesis(t) - msgChan := make(chan common.Message, 1) require.NoError(vm.Initialize( context.Background(), ctx, memdb.New(), - genesisBytes, + genesistest.BuildBytes(t), nil, nil, msgChan, @@ -1791,7 +1722,7 @@ func TestUptimeDisallowedWithRestart(t *testing.T) { firstCtx := snowtest.Context(t, snowtest.PChainID) firstCtx.Lock.Lock() - _, genesisBytes := defaultGenesis(t) + genesisBytes := genesistest.BuildBytes(t) firstMsgChan := make(chan common.Message, 1) require.NoError(firstVM.Initialize( @@ -1934,8 +1865,6 @@ func TestUptimeDisallowedAfterNeverConnecting(t *testing.T) { ctx := snowtest.Context(t, snowtest.PChainID) ctx.Lock.Lock() - _, genesisBytes := defaultGenesis(t) - atomicDB := prefixdb.New([]byte{1}, db) m := atomic.NewMemory(atomicDB) ctx.SharedMemory = m.NewSharedMemory(ctx.ChainID) @@ -1946,7 +1875,7 @@ func TestUptimeDisallowedAfterNeverConnecting(t *testing.T) { context.Background(), ctx, db, - genesisBytes, + genesistest.BuildBytes(t), nil, nil, msgChan, From e8679c803c4f952e31de5f3ba203a980195fa4b5 Mon Sep 17 00:00:00 2001 From: Stephen Buttolph Date: Thu, 22 Aug 2024 16:08:59 -0400 Subject: [PATCH 17/27] wip --- vms/platformvm/genesis/genesistest/helper.go | 8 ++--- vms/platformvm/service_test.go | 14 ++++----- vms/platformvm/txs/executor/export_test.go | 2 +- vms/platformvm/txs/executor/helpers_test.go | 2 -- .../txs/executor/proposal_tx_executor_test.go | 24 +++++++-------- .../txs/executor/standard_tx_executor_test.go | 30 +++++++++---------- vms/platformvm/validator_set_property_test.go | 4 +-- vms/platformvm/vm_regression_test.go | 20 ++++++------- vms/platformvm/vm_test.go | 11 +++---- 9 files changed, 55 insertions(+), 60 deletions(-) diff --git a/vms/platformvm/genesis/genesistest/helper.go b/vms/platformvm/genesis/genesistest/helper.go index f06dbb39089b..3a38834d6a7c 100644 --- a/vms/platformvm/genesis/genesistest/helper.go +++ b/vms/platformvm/genesis/genesistest/helper.go @@ -21,8 +21,8 @@ import ( ) const ( - defaultWeight = 5 * units.MilliAvax - defaultBalance = 1 * units.Avax + ValidatorWeight2 = 5 * units.MilliAvax + InitialBalance2 = 1 * units.Avax ) var ( @@ -49,7 +49,7 @@ func Build(t *testing.T) *api.BuildGenesisArgs { addr, err := address.FormatBech32(constants.UnitTestHRP, id.Bytes()) require.NoError(err) genesisUTXOs[i] = api.UTXO{ - Amount: json.Uint64(defaultBalance), + Amount: json.Uint64(InitialBalance2), Address: addr, } } @@ -70,7 +70,7 @@ func Build(t *testing.T) *api.BuildGenesisArgs { Addresses: []string{addrStr}, }, Staked: []api.UTXO{{ - Amount: json.Uint64(defaultWeight), + Amount: json.Uint64(ValidatorWeight2), Address: addrStr, }}, DelegationFee: reward.PercentDenominator, diff --git a/vms/platformvm/service_test.go b/vms/platformvm/service_test.go index 0e4ae5d7f10b..75f3ba712159 100644 --- a/vms/platformvm/service_test.go +++ b/vms/platformvm/service_test.go @@ -394,11 +394,11 @@ func TestGetBalance(t *testing.T) { reply := GetBalanceResponse{} require.NoError(service.GetBalance(nil, &request, &reply)) - balance := defaultBalance + balance := genesistest.InitialBalance2 if idx == 0 { // we use the first key to fund a subnet creation in [defaultGenesis]. // As such we need to account for the subnet creation fee - balance = defaultBalance - createSubnetFee + balance = genesistest.InitialBalance2 - createSubnetFee } require.Equal(avajson.Uint64(balance), reply.Balance) require.Equal(avajson.Uint64(balance), reply.Unlocked) @@ -426,7 +426,7 @@ func TestGetStake(t *testing.T) { } response := GetStakeReply{} require.NoError(service.GetStake(nil, &args, &response)) - require.Equal(defaultWeight, uint64(response.Staked)) + require.Equal(genesistest.ValidatorWeight2, uint64(response.Staked)) require.Len(response.Outputs, 1) // Unmarshal into an output @@ -445,7 +445,7 @@ func TestGetStake(t *testing.T) { ID: service.vm.ctx.AVAXAssetID, }, Out: &secp256k1fx.TransferOutput{ - Amt: defaultWeight, + Amt: genesistest.ValidatorWeight2, OutputOwners: secp256k1fx.OutputOwners{ Threshold: 1, Addrs: []ids.ShortID{ @@ -467,7 +467,7 @@ func TestGetStake(t *testing.T) { } response := GetStakeReply{} require.NoError(service.GetStake(nil, &args, &response)) - require.Equal(len(genesis.Validators)*int(defaultWeight), int(response.Staked)) + require.Equal(len(genesis.Validators)*int(genesistest.ValidatorWeight2), int(response.Staked)) require.Len(response.Outputs, len(genesis.Validators)) for _, outputStr := range response.Outputs { @@ -479,13 +479,13 @@ func TestGetStake(t *testing.T) { require.NoError(err) out := output.Out.(*secp256k1fx.TransferOutput) - require.Equal(defaultWeight, out.Amt) + require.Equal(genesistest.ValidatorWeight2, out.Amt) require.Equal(uint32(1), out.Threshold) require.Zero(out.Locktime) require.Len(out.Addrs, 1) } - oldStake := defaultWeight + oldStake := genesistest.ValidatorWeight2 service.vm.ctx.Lock.Lock() diff --git a/vms/platformvm/txs/executor/export_test.go b/vms/platformvm/txs/executor/export_test.go index f19741c104f5..4dba9f92dd29 100644 --- a/vms/platformvm/txs/executor/export_test.go +++ b/vms/platformvm/txs/executor/export_test.go @@ -61,7 +61,7 @@ func TestNewExportTx(t *testing.T) { []*avax.TransferableOutput{{ Asset: avax.Asset{ID: env.ctx.AVAXAssetID}, Out: &secp256k1fx.TransferOutput{ - Amt: defaultBalance - defaultTxFee, + Amt: genesistest.InitialBalance2 - defaultTxFee, OutputOwners: secp256k1fx.OutputOwners{ Locktime: 0, Threshold: 1, diff --git a/vms/platformvm/txs/executor/helpers_test.go b/vms/platformvm/txs/executor/helpers_test.go index dea18d377282..e115e2315a6a 100644 --- a/vms/platformvm/txs/executor/helpers_test.go +++ b/vms/platformvm/txs/executor/helpers_test.go @@ -46,10 +46,8 @@ import ( ) const ( - defaultWeight = 5 * units.MilliAvax defaultMinStakingDuration = 24 * time.Hour defaultMinValidatorStake = 5 * units.MilliAvax - defaultBalance = 100 * defaultMinValidatorStake ) const ( diff --git a/vms/platformvm/txs/executor/proposal_tx_executor_test.go b/vms/platformvm/txs/executor/proposal_tx_executor_test.go index 84807e9edb9e..aa10af91f3ac 100644 --- a/vms/platformvm/txs/executor/proposal_tx_executor_test.go +++ b/vms/platformvm/txs/executor/proposal_tx_executor_test.go @@ -305,7 +305,7 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { NodeID: nodeID, Start: genesistest.TimeUnix + 1, End: genesistest.ValidatorEndTimeUnix + 1, - Wght: defaultWeight, + Wght: genesistest.ValidatorWeight2, }, Subnet: testSubnet1.ID(), }, @@ -344,7 +344,7 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { NodeID: nodeID, Start: genesistest.TimeUnix + 1, End: genesistest.ValidatorEndTimeUnix, - Wght: defaultWeight, + Wght: genesistest.ValidatorWeight2, }, Subnet: testSubnet1.ID(), }, @@ -403,7 +403,7 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { NodeID: pendingDSValidatorID, Start: uint64(dsStartTime.Unix()), // start validating subnet before primary network End: uint64(dsEndTime.Unix()), - Wght: defaultWeight, + Wght: genesistest.ValidatorWeight2, }, Subnet: testSubnet1.ID(), }, @@ -457,7 +457,7 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { NodeID: pendingDSValidatorID, Start: uint64(dsStartTime.Unix()) - 1, // start validating subnet before primary network End: uint64(dsEndTime.Unix()), - Wght: defaultWeight, + Wght: genesistest.ValidatorWeight2, }, Subnet: testSubnet1.ID(), }, @@ -494,7 +494,7 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { NodeID: pendingDSValidatorID, Start: uint64(dsStartTime.Unix()), End: uint64(dsEndTime.Unix()) + 1, // stop validating subnet after stopping validating primary network - Wght: defaultWeight, + Wght: genesistest.ValidatorWeight2, }, Subnet: testSubnet1.ID(), }, @@ -531,7 +531,7 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { NodeID: pendingDSValidatorID, Start: uint64(dsStartTime.Unix()), // same start time as for primary network End: uint64(dsEndTime.Unix()), // same end time as for primary network - Wght: defaultWeight, + Wght: genesistest.ValidatorWeight2, }, Subnet: testSubnet1.ID(), }, @@ -570,7 +570,7 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { NodeID: nodeID, Start: uint64(newTimestamp.Unix()), End: uint64(newTimestamp.Add(defaultMinStakingDuration).Unix()), - Wght: defaultWeight, + Wght: genesistest.ValidatorWeight2, }, Subnet: testSubnet1.ID(), }, @@ -609,7 +609,7 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { NodeID: nodeID, Start: genesistest.TimeUnix, End: genesistest.ValidatorEndTimeUnix, - Wght: defaultWeight, + Wght: genesistest.ValidatorWeight2, }, Subnet: testSubnet1.ID(), }, @@ -641,7 +641,7 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { NodeID: nodeID, Start: genesistest.TimeUnix + 1, End: genesistest.ValidatorEndTimeUnix, - Wght: defaultWeight, + Wght: genesistest.ValidatorWeight2, }, Subnet: testSubnet1.ID(), }, @@ -681,7 +681,7 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { NodeID: nodeID, Start: genesistest.TimeUnix + 1, End: uint64(genesistest.Time.Add(defaultMinStakingDuration).Unix()) + 1, - Wght: defaultWeight, + Wght: genesistest.ValidatorWeight2, }, Subnet: testSubnet1.ID(), }, @@ -724,7 +724,7 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { NodeID: nodeID, Start: genesistest.TimeUnix + 1, End: uint64(genesistest.Time.Add(defaultMinStakingDuration).Unix()) + 1, - Wght: defaultWeight, + Wght: genesistest.ValidatorWeight2, }, Subnet: testSubnet1.ID(), }, @@ -766,7 +766,7 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { NodeID: nodeID, Start: genesistest.TimeUnix + 1, End: uint64(genesistest.Time.Add(defaultMinStakingDuration).Unix()) + 1, - Wght: defaultWeight, + Wght: genesistest.ValidatorWeight2, }, Subnet: testSubnet1.ID(), }, diff --git a/vms/platformvm/txs/executor/standard_tx_executor_test.go b/vms/platformvm/txs/executor/standard_tx_executor_test.go index 75565f5146ea..88b3476fbbb3 100644 --- a/vms/platformvm/txs/executor/standard_tx_executor_test.go +++ b/vms/platformvm/txs/executor/standard_tx_executor_test.go @@ -389,7 +389,7 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { NodeID: nodeID, Start: uint64(startTime.Unix()), End: genesistest.ValidatorEndTimeUnix + 1, - Wght: defaultWeight, + Wght: genesistest.ValidatorWeight2, }, Subnet: testSubnet1.ID(), }, @@ -424,7 +424,7 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { NodeID: nodeID, Start: genesistest.TimeUnix + 1, End: genesistest.ValidatorEndTimeUnix, - Wght: defaultWeight, + Wght: genesistest.ValidatorWeight2, }, Subnet: testSubnet1.ID(), }, @@ -479,7 +479,7 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { NodeID: pendingDSValidatorID, Start: uint64(dsStartTime.Unix()), // start validating subnet before primary network End: uint64(dsEndTime.Unix()), - Wght: defaultWeight, + Wght: genesistest.ValidatorWeight2, }, Subnet: testSubnet1.ID(), }, @@ -529,7 +529,7 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { NodeID: pendingDSValidatorID, Start: uint64(dsStartTime.Unix()) - 1, // start validating subnet before primary network End: uint64(dsEndTime.Unix()), - Wght: defaultWeight, + Wght: genesistest.ValidatorWeight2, }, Subnet: testSubnet1.ID(), }, @@ -562,7 +562,7 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { NodeID: pendingDSValidatorID, Start: uint64(dsStartTime.Unix()), End: uint64(dsEndTime.Unix()) + 1, // stop validating subnet after stopping validating primary network - Wght: defaultWeight, + Wght: genesistest.ValidatorWeight2, }, Subnet: testSubnet1.ID(), }, @@ -595,7 +595,7 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { NodeID: pendingDSValidatorID, Start: uint64(dsStartTime.Unix()), // same start time as for primary network End: uint64(dsEndTime.Unix()), // same end time as for primary network - Wght: defaultWeight, + Wght: genesistest.ValidatorWeight2, }, Subnet: testSubnet1.ID(), }, @@ -630,7 +630,7 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { NodeID: nodeID, Start: uint64(newTimestamp.Unix()), End: uint64(newTimestamp.Add(defaultMinStakingDuration).Unix()), - Wght: defaultWeight, + Wght: genesistest.ValidatorWeight2, }, Subnet: testSubnet1.ID(), }, @@ -665,7 +665,7 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { NodeID: nodeID, Start: genesistest.TimeUnix, End: genesistest.ValidatorEndTimeUnix, - Wght: defaultWeight, + Wght: genesistest.ValidatorWeight2, }, Subnet: testSubnet1.ID(), }, @@ -698,7 +698,7 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { NodeID: nodeID, Start: uint64(startTime.Unix()), End: genesistest.ValidatorEndTimeUnix, - Wght: defaultWeight, + Wght: genesistest.ValidatorWeight2, }, Subnet: testSubnet1.ID(), }, @@ -735,7 +735,7 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { NodeID: nodeID, Start: uint64(startTime.Unix()), End: uint64(startTime.Add(defaultMinStakingDuration).Unix()) + 1, - Wght: defaultWeight, + Wght: genesistest.ValidatorWeight2, }, Subnet: testSubnet1.ID(), }, @@ -775,7 +775,7 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { NodeID: nodeID, Start: uint64(startTime.Unix()), End: uint64(startTime.Add(defaultMinStakingDuration).Unix()), - Wght: defaultWeight, + Wght: genesistest.ValidatorWeight2, }, Subnet: testSubnet1.ID(), }, @@ -815,7 +815,7 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { NodeID: nodeID, Start: uint64(startTime.Unix()), End: uint64(startTime.Add(defaultMinStakingDuration).Unix()), - Wght: defaultWeight, + Wght: genesistest.ValidatorWeight2, }, Subnet: testSubnet1.ID(), }, @@ -854,7 +854,7 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { NodeID: nodeID, Start: uint64(startTime.Unix()) + 1, End: uint64(startTime.Add(defaultMinStakingDuration).Unix()) + 1, - Wght: defaultWeight, + Wght: genesistest.ValidatorWeight2, }, Subnet: testSubnet1.ID(), }, @@ -907,7 +907,7 @@ func TestEtnaStandardTxExecutorAddSubnetValidator(t *testing.T) { NodeID: nodeID, Start: genesistest.TimeUnix + 1, End: genesistest.ValidatorEndTimeUnix, - Wght: defaultWeight, + Wght: genesistest.ValidatorWeight2, }, Subnet: testSubnet1.ID(), }, @@ -1397,7 +1397,7 @@ func TestDurangoMemoField(t *testing.T) { NodeID: primaryValidator.NodeID, Start: 0, End: uint64(endTime.Unix()), - Wght: defaultWeight, + Wght: genesistest.ValidatorWeight2, }, Subnet: testSubnet1.ID(), }, diff --git a/vms/platformvm/validator_set_property_test.go b/vms/platformvm/validator_set_property_test.go index 199f4e550eea..24690809b15a 100644 --- a/vms/platformvm/validator_set_property_test.go +++ b/vms/platformvm/validator_set_property_test.go @@ -765,7 +765,7 @@ func buildCustomGenesis(avaxAssetID ids.ID) ([]byte, error) { return nil, err } genesisUTXOs[i] = api.UTXO{ - Amount: json.Uint64(defaultBalance), + Amount: json.Uint64(genesistest.InitialBalance2), Address: addr, } } @@ -793,7 +793,7 @@ func buildCustomGenesis(avaxAssetID ids.ID) ([]byte, error) { Addresses: []string{addr}, }, Staked: []api.UTXO{{ - Amount: json.Uint64(defaultWeight), + Amount: json.Uint64(genesistest.ValidatorWeight2), Address: addr, }}, DelegationFee: reward.PercentDenominator, diff --git a/vms/platformvm/vm_regression_test.go b/vms/platformvm/vm_regression_test.go index 774b490e3a1a..58b454bc9e6f 100644 --- a/vms/platformvm/vm_regression_test.go +++ b/vms/platformvm/vm_regression_test.go @@ -1101,11 +1101,11 @@ func TestValidatorSetAtCacheOverwriteRegression(t *testing.T) { require.Equal(uint64(1), currentHeight) expectedValidators1 := map[ids.NodeID]uint64{ - genesistest.NodeIDs[0]: defaultWeight, - genesistest.NodeIDs[1]: defaultWeight, - genesistest.NodeIDs[2]: defaultWeight, - genesistest.NodeIDs[3]: defaultWeight, - genesistest.NodeIDs[4]: defaultWeight, + genesistest.NodeIDs[0]: genesistest.ValidatorWeight2, + genesistest.NodeIDs[1]: genesistest.ValidatorWeight2, + genesistest.NodeIDs[2]: genesistest.ValidatorWeight2, + genesistest.NodeIDs[3]: genesistest.ValidatorWeight2, + genesistest.NodeIDs[4]: genesistest.ValidatorWeight2, } validators, err := vm.GetValidatorSet(context.Background(), 1, constants.PrimaryNetworkID) require.NoError(err) @@ -1205,11 +1205,11 @@ func TestValidatorSetAtCacheOverwriteRegression(t *testing.T) { } expectedValidators2 := map[ids.NodeID]uint64{ - genesistest.NodeIDs[0]: defaultWeight, - genesistest.NodeIDs[1]: defaultWeight, - genesistest.NodeIDs[2]: defaultWeight, - genesistest.NodeIDs[3]: defaultWeight, - genesistest.NodeIDs[4]: defaultWeight, + genesistest.NodeIDs[0]: genesistest.ValidatorWeight2, + genesistest.NodeIDs[1]: genesistest.ValidatorWeight2, + genesistest.NodeIDs[2]: genesistest.ValidatorWeight2, + genesistest.NodeIDs[3]: genesistest.ValidatorWeight2, + genesistest.NodeIDs[4]: genesistest.ValidatorWeight2, extraNodeID: vm.MaxValidatorStake, } validators, err = vm.GetValidatorSet(context.Background(), 3, constants.PrimaryNetworkID) diff --git a/vms/platformvm/vm_test.go b/vms/platformvm/vm_test.go index a043547dc78d..49ca10c68c88 100644 --- a/vms/platformvm/vm_test.go +++ b/vms/platformvm/vm_test.go @@ -75,13 +75,10 @@ import ( ) const ( - defaultWeight = 5 * units.MilliAvax - // Node IDs of genesis validators. Initialized in init function defaultMinDelegatorStake = 1 * units.MilliAvax defaultMinValidatorStake = 5 * defaultMinDelegatorStake defaultMaxValidatorStake = 100 * defaultMinValidatorStake - defaultBalance = 2 * defaultMaxValidatorStake // amount all genesis validators have in defaultVM ) var ( @@ -542,7 +539,7 @@ func TestAddSubnetValidatorAccept(t *testing.T) { NodeID: nodeID, Start: uint64(startTime.Unix()), End: uint64(endTime.Unix()), - Wght: defaultWeight, + Wght: genesistest.ValidatorWeight2, }, Subnet: testSubnet1.ID(), }, @@ -594,7 +591,7 @@ func TestAddSubnetValidatorReject(t *testing.T) { NodeID: nodeID, Start: uint64(startTime.Unix()), End: uint64(endTime.Unix()), - Wght: defaultWeight, + Wght: genesistest.ValidatorWeight2, }, Subnet: testSubnet1.ID(), }, @@ -878,7 +875,7 @@ func TestCreateSubnet(t *testing.T) { NodeID: nodeID, Start: uint64(startTime.Unix()), End: uint64(endTime.Unix()), - Wght: defaultWeight, + Wght: genesistest.ValidatorWeight2, }, Subnet: subnetID, }, @@ -1698,7 +1695,7 @@ func TestMaxStakeAmount(t *testing.T) { amount, err := txexecutor.GetMaxWeight(vm.state, staker, test.startTime, test.endTime) require.NoError(err) - require.Equal(defaultWeight, amount) + require.Equal(genesistest.ValidatorWeight2, amount) }) } } From 991af2e8ab90645906360e03aadf47c04294830e Mon Sep 17 00:00:00 2001 From: Stephen Buttolph Date: Thu, 22 Aug 2024 16:14:27 -0400 Subject: [PATCH 18/27] nit --- vms/platformvm/genesis/genesistest/helper.go | 34 +++++++++----------- 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/vms/platformvm/genesis/genesistest/helper.go b/vms/platformvm/genesis/genesistest/helper.go index 3a38834d6a7c..99333df3eb7e 100644 --- a/vms/platformvm/genesis/genesistest/helper.go +++ b/vms/platformvm/genesis/genesistest/helper.go @@ -23,6 +23,7 @@ import ( const ( ValidatorWeight2 = 5 * units.MilliAvax InitialBalance2 = 1 * units.Avax + InitialSupply2 = 360 * units.MegaAvax ) var ( @@ -43,23 +44,21 @@ func init() { func Build(t *testing.T) *api.BuildGenesisArgs { require := require.New(t) - genesisUTXOs := make([]api.UTXO, len(FundedKeys)) + var ( + utxos = make([]api.UTXO, len(FundedKeys)) + validators = make([]api.GenesisPermissionlessValidator, len(FundedKeys)) + ) for i, key := range FundedKeys { - id := key.PublicKey().Address() - addr, err := address.FormatBech32(constants.UnitTestHRP, id.Bytes()) + addr, err := address.FormatBech32(constants.UnitTestHRP, key.Address().Bytes()) require.NoError(err) - genesisUTXOs[i] = api.UTXO{ + + utxos[i] = api.UTXO{ Amount: json.Uint64(InitialBalance2), Address: addr, } - } - genesisValidators := make([]api.GenesisPermissionlessValidator, len(NodeIDs)) - for i, nodeID := range NodeIDs { - addr := FundedKeys[i].Address() - addrStr, err := address.FormatBech32(constants.UnitTestHRP, addr.Bytes()) - require.NoError(err) - genesisValidators[i] = api.GenesisPermissionlessValidator{ + nodeID := NodeIDs[i] + validators[i] = api.GenesisPermissionlessValidator{ GenesisValidator: api.GenesisValidator{ StartTime: json.Uint64(TimeUnix), EndTime: json.Uint64(ValidatorEndTimeUnix), @@ -67,24 +66,23 @@ func Build(t *testing.T) *api.BuildGenesisArgs { }, RewardOwner: &api.Owner{ Threshold: 1, - Addresses: []string{addrStr}, + Addresses: []string{addr}, }, Staked: []api.UTXO{{ Amount: json.Uint64(ValidatorWeight2), - Address: addrStr, + Address: addr, }}, DelegationFee: reward.PercentDenominator, } } return &api.BuildGenesisArgs{ - NetworkID: json.Uint32(constants.UnitTestID), AvaxAssetID: snowtest.AVAXAssetID, - UTXOs: genesisUTXOs, - Validators: genesisValidators, - Chains: nil, + NetworkID: json.Uint32(constants.UnitTestID), + UTXOs: utxos, + Validators: validators, Time: json.Uint64(TimeUnix), - InitialSupply: json.Uint64(360 * units.MegaAvax), + InitialSupply: json.Uint64(InitialSupply2), Encoding: formatting.Hex, } } From a70158878706d3334de009cf9b90340978cacd56 Mon Sep 17 00:00:00 2001 From: Stephen Buttolph Date: Thu, 22 Aug 2024 16:20:47 -0400 Subject: [PATCH 19/27] nit --- vms/platformvm/block/builder/helpers_test.go | 7 +++++-- vms/platformvm/block/executor/helpers_test.go | 7 +++---- vms/platformvm/reward/calculator_test.go | 4 ++-- vms/platformvm/txs/executor/helpers_test.go | 10 ++++------ vms/platformvm/vm_test.go | 9 ++++----- 5 files changed, 18 insertions(+), 19 deletions(-) diff --git a/vms/platformvm/block/builder/helpers_test.go b/vms/platformvm/block/builder/helpers_test.go index 4abd918579fc..baac7afe8a62 100644 --- a/vms/platformvm/block/builder/helpers_test.go +++ b/vms/platformvm/block/builder/helpers_test.go @@ -54,11 +54,14 @@ import ( walletcommon "github.com/ava-labs/avalanchego/wallet/subnet/primary/common" ) -var ( +const ( defaultMinStakingDuration = 24 * time.Hour defaultMaxStakingDuration = 365 * 24 * time.Hour - defaultTxFee = uint64(100) + defaultTxFee = 100 * units.NanoAvax +) + +var ( testSubnet1 *txs.Tx testSubnet1ControlKeys = genesistest.FundedKeys[0:3] ) diff --git a/vms/platformvm/block/executor/helpers_test.go b/vms/platformvm/block/executor/helpers_test.go index d4f488ac49d4..d2ebd91cf169 100644 --- a/vms/platformvm/block/executor/helpers_test.go +++ b/vms/platformvm/block/executor/helpers_test.go @@ -57,16 +57,15 @@ import ( const ( pending stakerStatus = iota current -) -var ( defaultMinStakingDuration = 24 * time.Hour defaultMaxStakingDuration = 365 * 24 * time.Hour - defaultTxFee = uint64(100) - testSubnet1 *txs.Tx + defaultTxFee = 100 * units.NanoAvax ) +var testSubnet1 *txs.Tx + type stakerStatus uint type staker struct { diff --git a/vms/platformvm/reward/calculator_test.go b/vms/platformvm/reward/calculator_test.go index d2fd17ff9e2b..c2c94d0c9f78 100644 --- a/vms/platformvm/reward/calculator_test.go +++ b/vms/platformvm/reward/calculator_test.go @@ -15,10 +15,10 @@ import ( ) const ( + defaultMinValidatorStake = 5 * units.MilliAvax + defaultMinStakingDuration = 24 * time.Hour defaultMaxStakingDuration = 365 * 24 * time.Hour - - defaultMinValidatorStake = 5 * units.MilliAvax ) var defaultConfig = Config{ diff --git a/vms/platformvm/txs/executor/helpers_test.go b/vms/platformvm/txs/executor/helpers_test.go index e115e2315a6a..679e3160f667 100644 --- a/vms/platformvm/txs/executor/helpers_test.go +++ b/vms/platformvm/txs/executor/helpers_test.go @@ -46,14 +46,12 @@ import ( ) const ( - defaultMinStakingDuration = 24 * time.Hour - defaultMinValidatorStake = 5 * units.MilliAvax -) + defaultMinValidatorStake = 5 * units.MilliAvax -const ( + defaultMinStakingDuration = 24 * time.Hour defaultMaxStakingDuration = 365 * 24 * time.Hour - trackChecksum = false - defaultTxFee = 100 + + defaultTxFee = 100 * units.NanoAvax ) var ( diff --git a/vms/platformvm/vm_test.go b/vms/platformvm/vm_test.go index 49ca10c68c88..1a9021c738d2 100644 --- a/vms/platformvm/vm_test.go +++ b/vms/platformvm/vm_test.go @@ -75,16 +75,17 @@ import ( ) const ( - // Node IDs of genesis validators. Initialized in init function defaultMinDelegatorStake = 1 * units.MilliAvax defaultMinValidatorStake = 5 * defaultMinDelegatorStake defaultMaxValidatorStake = 100 * defaultMinValidatorStake -) -var ( defaultMinStakingDuration = 24 * time.Hour defaultMaxStakingDuration = 365 * 24 * time.Hour + defaultTxFee = 100 * units.NanoAvax +) + +var ( defaultRewardConfig = reward.Config{ MaxConsumptionRate: .12 * reward.PercentDenominator, MinConsumptionRate: .10 * reward.PercentDenominator, @@ -92,8 +93,6 @@ var ( SupplyCap: 720 * units.MegaAvax, } - defaultTxFee = uint64(100) - latestForkTime = genesistest.Time.Add(time.Second) defaultStaticFeeConfig = txfee.StaticConfig{ From d381beca7b6fdc84b30324aa44523e6a59cb9bf0 Mon Sep 17 00:00:00 2001 From: Stephen Buttolph Date: Thu, 22 Aug 2024 16:23:09 -0400 Subject: [PATCH 20/27] nit --- vms/platformvm/block/builder/builder_test.go | 18 ++++---- vms/platformvm/block/builder/helpers_test.go | 8 ++-- .../block/builder/standard_block_test.go | 6 +-- vms/platformvm/block/executor/helpers_test.go | 8 ++-- .../block/executor/proposal_block_test.go | 14 +++--- .../block/executor/standard_block_test.go | 2 +- vms/platformvm/block/parse_test.go | 4 +- vms/platformvm/service_test.go | 20 ++++----- vms/platformvm/txs/add_delegator_test.go | 12 ++--- .../txs/add_subnet_validator_test.go | 4 +- vms/platformvm/txs/add_validator_test.go | 12 ++--- vms/platformvm/txs/create_chain_test.go | 2 +- .../txs/executor/advance_time_test.go | 4 +- vms/platformvm/txs/executor/helpers_test.go | 8 ++-- vms/platformvm/txs/executor/import_test.go | 4 +- .../txs/executor/proposal_tx_executor_test.go | 10 ++--- .../txs/executor/standard_tx_executor_test.go | 12 ++--- vms/platformvm/validator_set_property_test.go | 10 ++--- vms/platformvm/vm_regression_test.go | 38 ++++++++-------- vms/platformvm/vm_test.go | 44 +++++++++---------- 20 files changed, 120 insertions(+), 120 deletions(-) diff --git a/vms/platformvm/block/builder/builder_test.go b/vms/platformvm/block/builder/builder_test.go index 095e766b1e3a..d9c3fe75b367 100644 --- a/vms/platformvm/block/builder/builder_test.go +++ b/vms/platformvm/block/builder/builder_test.go @@ -128,16 +128,16 @@ func TestBuildBlockShouldReward(t *testing.T) { env.ctx.AVAXAssetID, &secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{genesistest.FundedKeys[0].PublicKey().Address()}, + Addrs: []ids.ShortID{genesistest.FundedKeys[0].Address()}, }, &secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{genesistest.FundedKeys[0].PublicKey().Address()}, + Addrs: []ids.ShortID{genesistest.FundedKeys[0].Address()}, }, reward.PercentDenominator, common.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{genesistest.FundedKeys[0].PublicKey().Address()}, + Addrs: []ids.ShortID{genesistest.FundedKeys[0].Address()}, }), ) require.NoError(err) @@ -337,16 +337,16 @@ func TestBuildBlockInvalidStakingDurations(t *testing.T) { env.ctx.AVAXAssetID, &secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{genesistest.FundedKeys[0].PublicKey().Address()}, + Addrs: []ids.ShortID{genesistest.FundedKeys[0].Address()}, }, &secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{genesistest.FundedKeys[0].PublicKey().Address()}, + Addrs: []ids.ShortID{genesistest.FundedKeys[0].Address()}, }, reward.PercentDenominator, common.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{genesistest.FundedKeys[0].PublicKey().Address()}, + Addrs: []ids.ShortID{genesistest.FundedKeys[0].Address()}, }), ) require.NoError(err) @@ -378,16 +378,16 @@ func TestBuildBlockInvalidStakingDurations(t *testing.T) { env.ctx.AVAXAssetID, &secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{genesistest.FundedKeys[2].PublicKey().Address()}, + Addrs: []ids.ShortID{genesistest.FundedKeys[2].Address()}, }, &secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{genesistest.FundedKeys[2].PublicKey().Address()}, + Addrs: []ids.ShortID{genesistest.FundedKeys[2].Address()}, }, reward.PercentDenominator, common.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{genesistest.FundedKeys[2].PublicKey().Address()}, + Addrs: []ids.ShortID{genesistest.FundedKeys[2].Address()}, }), ) require.NoError(err) diff --git a/vms/platformvm/block/builder/helpers_test.go b/vms/platformvm/block/builder/helpers_test.go index baac7afe8a62..03680d87f421 100644 --- a/vms/platformvm/block/builder/helpers_test.go +++ b/vms/platformvm/block/builder/helpers_test.go @@ -215,14 +215,14 @@ func addSubnet(t *testing.T, env *environment) { &secp256k1fx.OutputOwners{ Threshold: 2, Addrs: []ids.ShortID{ - genesistest.FundedKeys[0].PublicKey().Address(), - genesistest.FundedKeys[1].PublicKey().Address(), - genesistest.FundedKeys[2].PublicKey().Address(), + genesistest.FundedKeys[0].Address(), + genesistest.FundedKeys[1].Address(), + genesistest.FundedKeys[2].Address(), }, }, walletcommon.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{genesistest.FundedKeys[0].PublicKey().Address()}, + Addrs: []ids.ShortID{genesistest.FundedKeys[0].Address()}, }), ) require.NoError(err) diff --git a/vms/platformvm/block/builder/standard_block_test.go b/vms/platformvm/block/builder/standard_block_test.go index 31fad123d4d5..5eb44e36e9ac 100644 --- a/vms/platformvm/block/builder/standard_block_test.go +++ b/vms/platformvm/block/builder/standard_block_test.go @@ -47,7 +47,7 @@ func TestAtomicTxImports(t *testing.T) { Amt: amount, OutputOwners: secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{recipientKey.PublicKey().Address()}, + Addrs: []ids.ShortID{recipientKey.Address()}, }, }, } @@ -60,7 +60,7 @@ func TestAtomicTxImports(t *testing.T) { Key: inputID[:], Value: utxoBytes, Traits: [][]byte{ - recipientKey.PublicKey().Address().Bytes(), + recipientKey.Address().Bytes(), }, }}}, })) @@ -70,7 +70,7 @@ func TestAtomicTxImports(t *testing.T) { env.ctx.XChainID, &secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{recipientKey.PublicKey().Address()}, + Addrs: []ids.ShortID{recipientKey.Address()}, }, ) require.NoError(err) diff --git a/vms/platformvm/block/executor/helpers_test.go b/vms/platformvm/block/executor/helpers_test.go index d2ebd91cf169..da2ad4ee903a 100644 --- a/vms/platformvm/block/executor/helpers_test.go +++ b/vms/platformvm/block/executor/helpers_test.go @@ -228,14 +228,14 @@ func addSubnet(env *environment) { &secp256k1fx.OutputOwners{ Threshold: 2, Addrs: []ids.ShortID{ - genesistest.FundedKeys[0].PublicKey().Address(), - genesistest.FundedKeys[1].PublicKey().Address(), - genesistest.FundedKeys[2].PublicKey().Address(), + genesistest.FundedKeys[0].Address(), + genesistest.FundedKeys[1].Address(), + genesistest.FundedKeys[2].Address(), }, }, walletcommon.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{genesistest.FundedKeys[0].PublicKey().Address()}, + Addrs: []ids.ShortID{genesistest.FundedKeys[0].Address()}, }), ) if err != nil { diff --git a/vms/platformvm/block/executor/proposal_block_test.go b/vms/platformvm/block/executor/proposal_block_test.go index 62b0c6719b7c..2bc6de1b24f9 100644 --- a/vms/platformvm/block/executor/proposal_block_test.go +++ b/vms/platformvm/block/executor/proposal_block_test.go @@ -1064,7 +1064,7 @@ func TestBanffProposalBlockDelegatorStakerWeight(t *testing.T) { }, &secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{genesistest.FundedKeys[0].PublicKey().Address()}, + Addrs: []ids.ShortID{genesistest.FundedKeys[0].Address()}, }, ) require.NoError(err) @@ -1163,7 +1163,7 @@ func TestBanffProposalBlockDelegatorStakers(t *testing.T) { pendingValidatorStartTime := genesistest.Time.Add(1 * time.Second) pendingValidatorEndTime := pendingValidatorStartTime.Add(defaultMinStakingDuration) nodeIDKey, _ := secp256k1.NewPrivateKey() - rewardAddress := nodeIDKey.PublicKey().Address() + rewardAddress := nodeIDKey.Address() nodeID := ids.BuildTestNodeID(rewardAddress[:]) _, err := addPendingValidator( @@ -1260,7 +1260,7 @@ func TestBanffProposalBlockDelegatorStakers(t *testing.T) { }, &secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{genesistest.FundedKeys[0].PublicKey().Address()}, + Addrs: []ids.ShortID{genesistest.FundedKeys[0].Address()}, }, ) require.NoError(err) @@ -1380,11 +1380,11 @@ func TestAddValidatorProposalBlock(t *testing.T) { env.ctx.AVAXAssetID, &secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{genesistest.FundedKeys[0].PublicKey().Address()}, + Addrs: []ids.ShortID{genesistest.FundedKeys[0].Address()}, }, &secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{genesistest.FundedKeys[0].PublicKey().Address()}, + Addrs: []ids.ShortID{genesistest.FundedKeys[0].Address()}, }, 10000, ) @@ -1464,11 +1464,11 @@ func TestAddValidatorProposalBlock(t *testing.T) { env.ctx.AVAXAssetID, &secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{genesistest.FundedKeys[0].PublicKey().Address()}, + Addrs: []ids.ShortID{genesistest.FundedKeys[0].Address()}, }, &secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{genesistest.FundedKeys[0].PublicKey().Address()}, + Addrs: []ids.ShortID{genesistest.FundedKeys[0].Address()}, }, 10000, ) diff --git a/vms/platformvm/block/executor/standard_block_test.go b/vms/platformvm/block/executor/standard_block_test.go index 8c9ef031a94d..eb05016725d1 100644 --- a/vms/platformvm/block/executor/standard_block_test.go +++ b/vms/platformvm/block/executor/standard_block_test.go @@ -816,7 +816,7 @@ func TestBanffStandardBlockDelegatorStakerWeight(t *testing.T) { }, &secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{genesistest.FundedKeys[0].PublicKey().Address()}, + Addrs: []ids.ShortID{genesistest.FundedKeys[0].Address()}, }, ) require.NoError(err) diff --git a/vms/platformvm/block/parse_test.go b/vms/platformvm/block/parse_test.go index 8bebb50753c4..b63d4bbc513f 100644 --- a/vms/platformvm/block/parse_test.go +++ b/vms/platformvm/block/parse_test.go @@ -296,7 +296,7 @@ func testAtomicTx() (*txs.Tx, error) { Amt: uint64(1234), OutputOwners: secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{preFundedKeys[0].PublicKey().Address()}, + Addrs: []ids.ShortID{preFundedKeys[0].Address()}, }, }, }}, @@ -345,7 +345,7 @@ func testDecisionTxs() ([]*txs.Tx, error) { Amt: uint64(1234), OutputOwners: secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{preFundedKeys[0].PublicKey().Address()}, + Addrs: []ids.ShortID{preFundedKeys[0].Address()}, }, }, }}, diff --git a/vms/platformvm/service_test.go b/vms/platformvm/service_test.go index 75f3ba712159..a66071b974f6 100644 --- a/vms/platformvm/service_test.go +++ b/vms/platformvm/service_test.go @@ -147,7 +147,7 @@ func TestGetTxStatus(t *testing.T) { Amt: 1234567, OutputOwners: secp256k1fx.OutputOwners{ Locktime: 0, - Addrs: []ids.ShortID{recipientKey.PublicKey().Address()}, + Addrs: []ids.ShortID{recipientKey.Address()}, Threshold: 1, }, }, @@ -163,7 +163,7 @@ func TestGetTxStatus(t *testing.T) { Key: inputID[:], Value: utxoBytes, Traits: [][]byte{ - recipientKey.PublicKey().Address().Bytes(), + recipientKey.Address().Bytes(), }, }, }, @@ -234,7 +234,7 @@ func TestGetTx(t *testing.T) { "chain name", common.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{genesistest.FundedKeys[0].PublicKey().Address()}, + Addrs: []ids.ShortID{genesistest.FundedKeys[0].Address()}, }), ) require.NoError(t, err) @@ -270,7 +270,7 @@ func TestGetTx(t *testing.T) { 0, common.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{genesistest.FundedKeys[0].PublicKey().Address()}, + Addrs: []ids.ShortID{genesistest.FundedKeys[0].Address()}, }), ) require.NoError(t, err) @@ -296,7 +296,7 @@ func TestGetTx(t *testing.T) { }}, common.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{genesistest.FundedKeys[0].PublicKey().Address()}, + Addrs: []ids.ShortID{genesistest.FundedKeys[0].Address()}, }), ) require.NoError(t, err) @@ -507,7 +507,7 @@ func TestGetStake(t *testing.T) { }, common.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{genesistest.FundedKeys[0].PublicKey().Address()}, + Addrs: []ids.ShortID{genesistest.FundedKeys[0].Address()}, }), ) require.NoError(err) @@ -530,7 +530,7 @@ func TestGetStake(t *testing.T) { service.vm.ctx.Lock.Unlock() // Make sure the delegator addr has the right stake (old stake + stakeAmount) - addr, _ := service.addrManager.FormatLocalAddress(genesistest.FundedKeys[0].PublicKey().Address()) + addr, _ := service.addrManager.FormatLocalAddress(genesistest.FundedKeys[0].Address()) args.Addresses = []string{addr} require.NoError(service.GetStake(nil, &args, &response)) require.Equal(oldStake+stakeAmount, uint64(response.Staked)) @@ -571,7 +571,7 @@ func TestGetStake(t *testing.T) { 0, common.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{genesistest.FundedKeys[0].PublicKey().Address()}, + Addrs: []ids.ShortID{genesistest.FundedKeys[0].Address()}, }), ) require.NoError(err) @@ -657,7 +657,7 @@ func TestGetCurrentValidators(t *testing.T) { }, common.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{genesistest.FundedKeys[0].PublicKey().Address()}, + Addrs: []ids.ShortID{genesistest.FundedKeys[0].Address()}, }), ) require.NoError(err) @@ -794,7 +794,7 @@ func TestGetBlock(t *testing.T) { "chain name", common.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{genesistest.FundedKeys[0].PublicKey().Address()}, + Addrs: []ids.ShortID{genesistest.FundedKeys[0].Address()}, }), ) require.NoError(err) diff --git a/vms/platformvm/txs/add_delegator_test.go b/vms/platformvm/txs/add_delegator_test.go index ac3290fb2431..3d2ba834f9c6 100644 --- a/vms/platformvm/txs/add_delegator_test.go +++ b/vms/platformvm/txs/add_delegator_test.go @@ -58,7 +58,7 @@ func TestAddDelegatorTxSyntacticVerify(t *testing.T) { Amt: uint64(1234), OutputOwners: secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{preFundedKeys[0].PublicKey().Address()}, + Addrs: []ids.ShortID{preFundedKeys[0].Address()}, }, }, }} @@ -70,7 +70,7 @@ func TestAddDelegatorTxSyntacticVerify(t *testing.T) { Amt: validatorWeight, OutputOwners: secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{preFundedKeys[0].PublicKey().Address()}, + Addrs: []ids.ShortID{preFundedKeys[0].Address()}, }, }, }, @@ -93,7 +93,7 @@ func TestAddDelegatorTxSyntacticVerify(t *testing.T) { DelegationRewardsOwner: &secp256k1fx.OutputOwners{ Locktime: 0, Threshold: 1, - Addrs: []ids.ShortID{preFundedKeys[0].PublicKey().Address()}, + Addrs: []ids.ShortID{preFundedKeys[0].Address()}, }, } @@ -157,7 +157,7 @@ func TestAddDelegatorTxSyntacticVerifyNotAVAX(t *testing.T) { Amt: uint64(1234), OutputOwners: secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{preFundedKeys[0].PublicKey().Address()}, + Addrs: []ids.ShortID{preFundedKeys[0].Address()}, }, }, }} @@ -169,7 +169,7 @@ func TestAddDelegatorTxSyntacticVerifyNotAVAX(t *testing.T) { Amt: validatorWeight, OutputOwners: secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{preFundedKeys[0].PublicKey().Address()}, + Addrs: []ids.ShortID{preFundedKeys[0].Address()}, }, }, }, @@ -192,7 +192,7 @@ func TestAddDelegatorTxSyntacticVerifyNotAVAX(t *testing.T) { DelegationRewardsOwner: &secp256k1fx.OutputOwners{ Locktime: 0, Threshold: 1, - Addrs: []ids.ShortID{preFundedKeys[0].PublicKey().Address()}, + Addrs: []ids.ShortID{preFundedKeys[0].Address()}, }, } diff --git a/vms/platformvm/txs/add_subnet_validator_test.go b/vms/platformvm/txs/add_subnet_validator_test.go index 8dc8d76782ac..b3c3630ef2f0 100644 --- a/vms/platformvm/txs/add_subnet_validator_test.go +++ b/vms/platformvm/txs/add_subnet_validator_test.go @@ -58,7 +58,7 @@ func TestAddSubnetValidatorTxSyntacticVerify(t *testing.T) { Amt: uint64(1234), OutputOwners: secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{preFundedKeys[0].PublicKey().Address()}, + Addrs: []ids.ShortID{preFundedKeys[0].Address()}, }, }, }} @@ -169,7 +169,7 @@ func TestAddSubnetValidatorMarshal(t *testing.T) { Amt: uint64(1234), OutputOwners: secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{preFundedKeys[0].PublicKey().Address()}, + Addrs: []ids.ShortID{preFundedKeys[0].Address()}, }, }, }} diff --git a/vms/platformvm/txs/add_validator_test.go b/vms/platformvm/txs/add_validator_test.go index daf32f66746d..27ea18dc5a7e 100644 --- a/vms/platformvm/txs/add_validator_test.go +++ b/vms/platformvm/txs/add_validator_test.go @@ -40,7 +40,7 @@ func TestAddValidatorTxSyntacticVerify(t *testing.T) { require.ErrorIs(err, ErrNilTx) validatorWeight := uint64(2022) - rewardAddress := preFundedKeys[0].PublicKey().Address() + rewardAddress := preFundedKeys[0].Address() inputs := []*avax.TransferableInput{{ UTXOID: avax.UTXOID{ TxID: ids.ID{'t', 'x', 'I', 'D'}, @@ -58,7 +58,7 @@ func TestAddValidatorTxSyntacticVerify(t *testing.T) { Amt: uint64(1234), OutputOwners: secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{preFundedKeys[0].PublicKey().Address()}, + Addrs: []ids.ShortID{preFundedKeys[0].Address()}, }, }, }} @@ -70,7 +70,7 @@ func TestAddValidatorTxSyntacticVerify(t *testing.T) { Amt: validatorWeight, OutputOwners: secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{preFundedKeys[0].PublicKey().Address()}, + Addrs: []ids.ShortID{preFundedKeys[0].Address()}, }, }, }, @@ -156,7 +156,7 @@ func TestAddValidatorTxSyntacticVerifyNotAVAX(t *testing.T) { assetID := ids.GenerateTestID() validatorWeight := uint64(2022) - rewardAddress := preFundedKeys[0].PublicKey().Address() + rewardAddress := preFundedKeys[0].Address() inputs := []*avax.TransferableInput{{ UTXOID: avax.UTXOID{ TxID: ids.ID{'t', 'x', 'I', 'D'}, @@ -174,7 +174,7 @@ func TestAddValidatorTxSyntacticVerifyNotAVAX(t *testing.T) { Amt: uint64(1234), OutputOwners: secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{preFundedKeys[0].PublicKey().Address()}, + Addrs: []ids.ShortID{preFundedKeys[0].Address()}, }, }, }} @@ -186,7 +186,7 @@ func TestAddValidatorTxSyntacticVerifyNotAVAX(t *testing.T) { Amt: validatorWeight, OutputOwners: secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{preFundedKeys[0].PublicKey().Address()}, + Addrs: []ids.ShortID{preFundedKeys[0].Address()}, }, }, }, diff --git a/vms/platformvm/txs/create_chain_test.go b/vms/platformvm/txs/create_chain_test.go index ecf52567d357..a3565d4ae29d 100644 --- a/vms/platformvm/txs/create_chain_test.go +++ b/vms/platformvm/txs/create_chain_test.go @@ -143,7 +143,7 @@ func TestUnsignedCreateChainTxVerify(t *testing.T) { Amt: uint64(1234), OutputOwners: secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{preFundedKeys[0].PublicKey().Address()}, + Addrs: []ids.ShortID{preFundedKeys[0].Address()}, }, }, }} diff --git a/vms/platformvm/txs/executor/advance_time_test.go b/vms/platformvm/txs/executor/advance_time_test.go index 8a618ac8e65c..517a2c90f16c 100644 --- a/vms/platformvm/txs/executor/advance_time_test.go +++ b/vms/platformvm/txs/executor/advance_time_test.go @@ -727,7 +727,7 @@ func TestAdvanceTimeTxDelegatorStakerWeight(t *testing.T) { }, &secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{genesistest.FundedKeys[0].PublicKey().Address()}, + Addrs: []ids.ShortID{genesistest.FundedKeys[0].Address()}, }, ) require.NoError(err) @@ -830,7 +830,7 @@ func TestAdvanceTimeTxDelegatorStakers(t *testing.T) { }, &secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{genesistest.FundedKeys[0].PublicKey().Address()}, + Addrs: []ids.ShortID{genesistest.FundedKeys[0].Address()}, }, ) require.NoError(err) diff --git a/vms/platformvm/txs/executor/helpers_test.go b/vms/platformvm/txs/executor/helpers_test.go index 679e3160f667..529e6ea5e60b 100644 --- a/vms/platformvm/txs/executor/helpers_test.go +++ b/vms/platformvm/txs/executor/helpers_test.go @@ -190,14 +190,14 @@ func addSubnet(t *testing.T, env *environment) { &secp256k1fx.OutputOwners{ Threshold: 2, Addrs: []ids.ShortID{ - genesistest.FundedKeys[0].PublicKey().Address(), - genesistest.FundedKeys[1].PublicKey().Address(), - genesistest.FundedKeys[2].PublicKey().Address(), + genesistest.FundedKeys[0].Address(), + genesistest.FundedKeys[1].Address(), + genesistest.FundedKeys[2].Address(), }, }, common.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{genesistest.FundedKeys[0].PublicKey().Address()}, + Addrs: []ids.ShortID{genesistest.FundedKeys[0].Address()}, }), ) require.NoError(err) diff --git a/vms/platformvm/txs/executor/import_test.go b/vms/platformvm/txs/executor/import_test.go index ed9ff97375af..6cc5c8a0cb38 100644 --- a/vms/platformvm/txs/executor/import_test.go +++ b/vms/platformvm/txs/executor/import_test.go @@ -200,7 +200,7 @@ func fundedSharedMemory( Amt: amt, OutputOwners: secp256k1fx.OutputOwners{ Locktime: 0, - Addrs: []ids.ShortID{sourceKey.PublicKey().Address()}, + Addrs: []ids.ShortID{sourceKey.Address()}, Threshold: 1, }, }, @@ -216,7 +216,7 @@ func fundedSharedMemory( Key: inputID[:], Value: utxoBytes, Traits: [][]byte{ - sourceKey.PublicKey().Address().Bytes(), + sourceKey.Address().Bytes(), }, }, }, diff --git a/vms/platformvm/txs/executor/proposal_tx_executor_test.go b/vms/platformvm/txs/executor/proposal_tx_executor_test.go index aa10af91f3ac..183ac6e3603e 100644 --- a/vms/platformvm/txs/executor/proposal_tx_executor_test.go +++ b/vms/platformvm/txs/executor/proposal_tx_executor_test.go @@ -28,7 +28,7 @@ import ( func TestProposalTxExecuteAddDelegator(t *testing.T) { dummyHeight := uint64(1) - rewardAddress := genesistest.FundedKeys[0].PublicKey().Address() + rewardAddress := genesistest.FundedKeys[0].Address() nodeID := genesistest.NodeIDs[0] newValidatorID := ids.GenerateTestNodeID() @@ -202,7 +202,7 @@ func TestProposalTxExecuteAddDelegator(t *testing.T) { feeKeys: []*secp256k1.PrivateKey{genesistest.FundedKeys[1]}, setup: func(env *environment) { // Remove all UTXOs owned by keys[1] utxoIDs, err := env.state.UTXOIDs( - genesistest.FundedKeys[1].PublicKey().Address().Bytes(), + genesistest.FundedKeys[1].Address().Bytes(), ids.Empty, math.MaxInt32) require.NoError(t, err) @@ -445,7 +445,7 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { env.state.SetHeight(dummyHeight) require.NoError(env.state.Commit()) - // Node with ID key.PublicKey().Address() now a pending validator for primary network + // Node with ID key.Address() now a pending validator for primary network { // Case: Proposed validator is pending validator of primary network @@ -633,7 +633,7 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { require.NoError(env.state.Commit()) { - // Node with ID nodeIDKey.PublicKey().Address() now validating subnet with ID testSubnet1.ID + // Node with ID nodeIDKey.Address() now validating subnet with ID testSubnet1.ID builder, signer := env.factory.NewWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ @@ -970,7 +970,7 @@ func TestProposalTxExecuteAddValidator(t *testing.T) { require.NoError(err) // Remove all UTXOs owned by preFundedKeys[0] - utxoIDs, err := env.state.UTXOIDs(genesistest.FundedKeys[0].PublicKey().Address().Bytes(), ids.Empty, math.MaxInt32) + utxoIDs, err := env.state.UTXOIDs(genesistest.FundedKeys[0].Address().Bytes(), ids.Empty, math.MaxInt32) require.NoError(err) for _, utxoID := range utxoIDs { diff --git a/vms/platformvm/txs/executor/standard_tx_executor_test.go b/vms/platformvm/txs/executor/standard_tx_executor_test.go index 88b3476fbbb3..c903655efc5d 100644 --- a/vms/platformvm/txs/executor/standard_tx_executor_test.go +++ b/vms/platformvm/txs/executor/standard_tx_executor_test.go @@ -112,7 +112,7 @@ func TestStandardTxExecutorAddValidatorTxEmptyID(t *testing.T) { func TestStandardTxExecutorAddDelegator(t *testing.T) { dummyHeight := uint64(1) - rewardAddress := genesistest.FundedKeys[0].PublicKey().Address() + rewardAddress := genesistest.FundedKeys[0].Address() nodeID := genesistest.NodeIDs[0] newValidatorID := ids.GenerateTestNodeID() @@ -286,7 +286,7 @@ func TestStandardTxExecutorAddDelegator(t *testing.T) { feeKeys: []*secp256k1.PrivateKey{genesistest.FundedKeys[1]}, // tx fee payer setup: func(env *environment) { // Remove all UTXOs owned by keys[1] utxoIDs, err := env.state.UTXOIDs( - genesistest.FundedKeys[1].PublicKey().Address().Bytes(), + genesistest.FundedKeys[1].Address().Bytes(), ids.Empty, math.MaxInt32) require.NoError(t, err) @@ -517,7 +517,7 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { env.state.SetHeight(dummyHeight) require.NoError(env.state.Commit()) - // Node with ID key.PublicKey().Address() now a pending validator for primary network + // Node with ID key.Address() now a pending validator for primary network { // Case: Proposed validator is pending validator of primary network @@ -689,7 +689,7 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { require.NoError(env.state.Commit()) { - // Node with ID nodeIDKey.PublicKey().Address() now validating subnet with ID testSubnet1.ID + // Node with ID nodeIDKey.Address() now validating subnet with ID testSubnet1.ID startTime := genesistest.Time.Add(time.Second) builder, signer := env.factory.NewWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) utx, err := builder.NewAddSubnetValidatorTx( @@ -1085,7 +1085,7 @@ func TestBanffStandardTxExecutorAddValidator(t *testing.T) { require.NoError(err) // Remove all UTXOs owned by preFundedKeys[0] - utxoIDs, err := env.state.UTXOIDs(genesistest.FundedKeys[0].PublicKey().Address().Bytes(), ids.Empty, math.MaxInt32) + utxoIDs, err := env.state.UTXOIDs(genesistest.FundedKeys[0].Address().Bytes(), ids.Empty, math.MaxInt32) require.NoError(err) onAcceptState, err := state.NewDiff(lastAcceptedID, env) @@ -1330,7 +1330,7 @@ func TestDurangoMemoField(t *testing.T) { &secp256k1fx.OutputOwners{ Locktime: 0, Threshold: 1, - Addrs: []ids.ShortID{sourceKey.PublicKey().Address()}, + Addrs: []ids.ShortID{sourceKey.Address()}, }, common.WithMemo(memoField), ) diff --git a/vms/platformvm/validator_set_property_test.go b/vms/platformvm/validator_set_property_test.go index 24690809b15a..b3b35acecb2e 100644 --- a/vms/platformvm/validator_set_property_test.go +++ b/vms/platformvm/validator_set_property_test.go @@ -274,7 +274,7 @@ func addSubnetValidator(vm *VM, data *validatorInputData, subnetID ids.ID) (*sta }, walletcommon.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{genesistest.FundedKeys[0].PublicKey().Address()}, + Addrs: []ids.ShortID{genesistest.FundedKeys[0].Address()}, }), ) if err != nil { @@ -288,7 +288,7 @@ func addSubnetValidator(vm *VM, data *validatorInputData, subnetID ids.ID) (*sta } func addPrimaryValidatorWithBLSKey(vm *VM, data *validatorInputData) (*state.Staker, error) { - addr := genesistest.FundedKeys[0].PublicKey().Address() + addr := genesistest.FundedKeys[0].Address() sk, err := bls.NewSecretKey() if err != nil { @@ -718,11 +718,11 @@ func buildVM(t *testing.T) (*VM, ids.ID, error) { utx, err := builder.NewCreateSubnetTx( &secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{genesistest.FundedKeys[0].PublicKey().Address()}, + Addrs: []ids.ShortID{genesistest.FundedKeys[0].Address()}, }, walletcommon.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{genesistest.FundedKeys[0].PublicKey().Address()}, + Addrs: []ids.ShortID{genesistest.FundedKeys[0].Address()}, }), ) if err != nil { @@ -759,7 +759,7 @@ func buildVM(t *testing.T) (*VM, ids.ID, error) { func buildCustomGenesis(avaxAssetID ids.ID) ([]byte, error) { genesisUTXOs := make([]api.UTXO, len(genesistest.FundedKeys)) for i, key := range genesistest.FundedKeys { - id := key.PublicKey().Address() + id := key.Address() addr, err := address.FormatBech32(constants.UnitTestHRP, id.Bytes()) if err != nil { return nil, err diff --git a/vms/platformvm/vm_regression_test.go b/vms/platformvm/vm_regression_test.go index 58b454bc9e6f..01aac542da17 100644 --- a/vms/platformvm/vm_regression_test.go +++ b/vms/platformvm/vm_regression_test.go @@ -59,7 +59,7 @@ func TestAddDelegatorTxOverDelegatedRegression(t *testing.T) { validatorEndTime := validatorStartTime.Add(360 * 24 * time.Hour) nodeID := ids.GenerateTestNodeID() - changeAddr := genesistest.FundedKeys[0].PublicKey().Address() + changeAddr := genesistest.FundedKeys[0].Address() // create valid tx builder, txSigner := factory.NewWallet(genesistest.FundedKeys[0]) @@ -265,9 +265,9 @@ func TestAddDelegatorTxHeapCorruption(t *testing.T) { key, err := secp256k1.NewPrivateKey() require.NoError(err) - id := key.PublicKey().Address() + id := key.Address() nodeID := ids.GenerateTestNodeID() - changeAddr := genesistest.FundedKeys[0].PublicKey().Address() + changeAddr := genesistest.FundedKeys[0].Address() // create valid tx builder, txSigner := factory.NewWallet(genesistest.FundedKeys[0], genesistest.FundedKeys[1]) @@ -314,7 +314,7 @@ func TestAddDelegatorTxHeapCorruption(t *testing.T) { }, &secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{genesistest.FundedKeys[0].PublicKey().Address()}, + Addrs: []ids.ShortID{genesistest.FundedKeys[0].Address()}, }, walletcommon.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, @@ -347,7 +347,7 @@ func TestAddDelegatorTxHeapCorruption(t *testing.T) { }, &secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{genesistest.FundedKeys[0].PublicKey().Address()}, + Addrs: []ids.ShortID{genesistest.FundedKeys[0].Address()}, }, walletcommon.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, @@ -380,7 +380,7 @@ func TestAddDelegatorTxHeapCorruption(t *testing.T) { }, &secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{genesistest.FundedKeys[0].PublicKey().Address()}, + Addrs: []ids.ShortID{genesistest.FundedKeys[0].Address()}, }, walletcommon.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, @@ -413,7 +413,7 @@ func TestAddDelegatorTxHeapCorruption(t *testing.T) { }, &secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{genesistest.FundedKeys[0].PublicKey().Address()}, + Addrs: []ids.ShortID{genesistest.FundedKeys[0].Address()}, }, walletcommon.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, @@ -486,8 +486,8 @@ func TestUnverifiedParentPanicRegression(t *testing.T) { key0 := genesistest.FundedKeys[0] key1 := genesistest.FundedKeys[1] - addr0 := key0.PublicKey().Address() - addr1 := key1.PublicKey().Address() + addr0 := key0.Address() + addr1 := key1.Address() factory := txstest.NewWalletFactory( vm.ctx, @@ -1243,7 +1243,7 @@ func TestAddDelegatorTxAddBeforeRemove(t *testing.T) { id := key.Address() nodeID := ids.GenerateTestNodeID() - changeAddr := genesistest.FundedKeys[0].PublicKey().Address() + changeAddr := genesistest.FundedKeys[0].Address() // create valid tx builder, txSigner := factory.NewWallet(genesistest.FundedKeys[0], genesistest.FundedKeys[1]) @@ -1290,7 +1290,7 @@ func TestAddDelegatorTxAddBeforeRemove(t *testing.T) { }, &secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{genesistest.FundedKeys[0].PublicKey().Address()}, + Addrs: []ids.ShortID{genesistest.FundedKeys[0].Address()}, }, walletcommon.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, @@ -1323,7 +1323,7 @@ func TestAddDelegatorTxAddBeforeRemove(t *testing.T) { }, &secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{genesistest.FundedKeys[0].PublicKey().Address()}, + Addrs: []ids.ShortID{genesistest.FundedKeys[0].Address()}, }, walletcommon.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, @@ -1357,7 +1357,7 @@ func TestRemovePermissionedValidatorDuringPendingToCurrentTransitionNotTracked(t id := key.Address() nodeID := ids.GenerateTestNodeID() - changeAddr := genesistest.FundedKeys[0].PublicKey().Address() + changeAddr := genesistest.FundedKeys[0].Address() builder, txSigner := factory.NewWallet(genesistest.FundedKeys[0], genesistest.FundedKeys[1]) utx, err := builder.NewAddValidatorTx( @@ -1504,9 +1504,9 @@ func TestRemovePermissionedValidatorDuringPendingToCurrentTransitionTracked(t *t key, err := secp256k1.NewPrivateKey() require.NoError(err) - id := key.PublicKey().Address() + id := key.Address() nodeID := ids.GenerateTestNodeID() - changeAddr := genesistest.FundedKeys[0].PublicKey().Address() + changeAddr := genesistest.FundedKeys[0].Address() builder, txSigner := factory.NewWallet(genesistest.FundedKeys[0], genesistest.FundedKeys[1]) utx, err := builder.NewAddValidatorTx( @@ -1653,7 +1653,7 @@ func TestSubnetValidatorBLSKeyDiffAfterExpiry(t *testing.T) { // insert primary network validator var ( nodeID = ids.GenerateTestNodeID() - addr = genesistest.FundedKeys[0].PublicKey().Address() + addr = genesistest.FundedKeys[0].Address() ) sk1, err := bls.NewSecretKey() require.NoError(err) @@ -1913,7 +1913,7 @@ func TestPrimaryNetworkValidatorPopulatedToEmptyBLSKeyDiff(t *testing.T) { // Add a primary network validator with no BLS key nodeID := ids.GenerateTestNodeID() - addr := genesistest.FundedKeys[0].PublicKey().Address() + addr := genesistest.FundedKeys[0].Address() builder, txSigner := factory.NewWallet(genesistest.FundedKeys[0]) uAddValTx1, err := builder.NewAddValidatorTx( @@ -2073,7 +2073,7 @@ func TestSubnetValidatorPopulatedToEmptyBLSKeyDiff(t *testing.T) { // Add a primary network validator with no BLS key nodeID := ids.GenerateTestNodeID() - addr := genesistest.FundedKeys[0].PublicKey().Address() + addr := genesistest.FundedKeys[0].Address() builder, txSigner := factory.NewWallet(genesistest.FundedKeys[0]) uPrimaryTx1, err := builder.NewAddValidatorTx( @@ -2290,7 +2290,7 @@ func TestSubnetValidatorSetAfterPrimaryNetworkValidatorRemoval(t *testing.T) { // Add a primary network validator with no BLS key nodeID := ids.GenerateTestNodeID() - addr := genesistest.FundedKeys[0].PublicKey().Address() + addr := genesistest.FundedKeys[0].Address() builder, txSigner := factory.NewWallet(genesistest.FundedKeys[0]) uPrimaryTx1, err := builder.NewAddValidatorTx( diff --git a/vms/platformvm/vm_test.go b/vms/platformvm/vm_test.go index 1a9021c738d2..7d7ad1ee5584 100644 --- a/vms/platformvm/vm_test.go +++ b/vms/platformvm/vm_test.go @@ -205,14 +205,14 @@ func defaultVM(t *testing.T, f upgradetest.Fork) (*VM, *txstest.WalletFactory, d &secp256k1fx.OutputOwners{ Threshold: 2, Addrs: []ids.ShortID{ - genesistest.FundedKeys[0].PublicKey().Address(), - genesistest.FundedKeys[1].PublicKey().Address(), - genesistest.FundedKeys[2].PublicKey().Address(), + genesistest.FundedKeys[0].Address(), + genesistest.FundedKeys[1].Address(), + genesistest.FundedKeys[2].Address(), }, }, walletcommon.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{genesistest.FundedKeys[0].PublicKey().Address()}, + Addrs: []ids.ShortID{genesistest.FundedKeys[0].Address()}, }), ) require.NoError(err) @@ -270,7 +270,7 @@ func TestGenesis(t *testing.T) { out := utxos[0].Out.(*secp256k1fx.TransferOutput) if out.Amount() != uint64(utxo.Amount) { - id := genesistest.FundedKeys[0].PublicKey().Address() + id := genesistest.FundedKeys[0].Address() addr, err := address.FormatBech32(constants.UnitTestHRP, id.Bytes()) require.NoError(err) @@ -829,13 +829,13 @@ func TestCreateSubnet(t *testing.T) { &secp256k1fx.OutputOwners{ Threshold: 1, Addrs: []ids.ShortID{ - genesistest.FundedKeys[0].PublicKey().Address(), - genesistest.FundedKeys[1].PublicKey().Address(), + genesistest.FundedKeys[0].Address(), + genesistest.FundedKeys[1].Address(), }, }, walletcommon.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{genesistest.FundedKeys[0].PublicKey().Address()}, + Addrs: []ids.ShortID{genesistest.FundedKeys[0].Address()}, }), ) require.NoError(err) @@ -943,7 +943,7 @@ func TestAtomicImport(t *testing.T) { vm.ctx.XChainID, &secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{recipientKey.PublicKey().Address()}, + Addrs: []ids.ShortID{recipientKey.Address()}, }, ) require.ErrorIs(err, walletbuilder.ErrInsufficientFunds) @@ -957,7 +957,7 @@ func TestAtomicImport(t *testing.T) { Amt: amount, OutputOwners: secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{recipientKey.PublicKey().Address()}, + Addrs: []ids.ShortID{recipientKey.Address()}, }, }, } @@ -972,7 +972,7 @@ func TestAtomicImport(t *testing.T) { Key: inputID[:], Value: utxoBytes, Traits: [][]byte{ - recipientKey.PublicKey().Address().Bytes(), + recipientKey.Address().Bytes(), }, }, }, @@ -984,7 +984,7 @@ func TestAtomicImport(t *testing.T) { vm.ctx.XChainID, &secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{recipientKey.PublicKey().Address()}, + Addrs: []ids.ShortID{recipientKey.Address()}, }, ) require.NoError(err) @@ -1956,7 +1956,7 @@ func TestRemovePermissionedValidatorDuringAddPending(t *testing.T) { key, err := secp256k1.NewPrivateKey() require.NoError(err) - id := key.PublicKey().Address() + id := key.Address() nodeID := ids.GenerateTestNodeID() sk, err := bls.NewSecretKey() require.NoError(err) @@ -1985,7 +1985,7 @@ func TestRemovePermissionedValidatorDuringAddPending(t *testing.T) { reward.PercentDenominator, walletcommon.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{genesistest.FundedKeys[0].PublicKey().Address()}, + Addrs: []ids.ShortID{genesistest.FundedKeys[0].Address()}, }), ) require.NoError(err) @@ -2010,7 +2010,7 @@ func TestRemovePermissionedValidatorDuringAddPending(t *testing.T) { }, walletcommon.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{genesistest.FundedKeys[0].PublicKey().Address()}, + Addrs: []ids.ShortID{genesistest.FundedKeys[0].Address()}, }), ) require.NoError(err) @@ -2041,7 +2041,7 @@ func TestRemovePermissionedValidatorDuringAddPending(t *testing.T) { }, walletcommon.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{genesistest.FundedKeys[1].PublicKey().Address()}, + Addrs: []ids.ShortID{genesistest.FundedKeys[1].Address()}, }), ) require.NoError(err) @@ -2054,7 +2054,7 @@ func TestRemovePermissionedValidatorDuringAddPending(t *testing.T) { createSubnetTx.ID(), walletcommon.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{genesistest.FundedKeys[2].PublicKey().Address()}, + Addrs: []ids.ShortID{genesistest.FundedKeys[2].Address()}, }), ) require.NoError(err) @@ -2093,11 +2093,11 @@ func TestTransferSubnetOwnershipTx(t *testing.T) { uCreateSubnetTx, err := builder.NewCreateSubnetTx( &secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{genesistest.FundedKeys[0].PublicKey().Address()}, + Addrs: []ids.ShortID{genesistest.FundedKeys[0].Address()}, }, walletcommon.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{genesistest.FundedKeys[0].PublicKey().Address()}, + Addrs: []ids.ShortID{genesistest.FundedKeys[0].Address()}, }), ) require.NoError(err) @@ -2126,7 +2126,7 @@ func TestTransferSubnetOwnershipTx(t *testing.T) { Locktime: 0, Threshold: 1, Addrs: []ids.ShortID{ - genesistest.FundedKeys[0].PublicKey().Address(), + genesistest.FundedKeys[0].Address(), }, } ctx, err := walletbuilder.NewSnowContext(vm.ctx.NetworkID, vm.ctx.AVAXAssetID) @@ -2138,7 +2138,7 @@ func TestTransferSubnetOwnershipTx(t *testing.T) { subnetID, &secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{genesistest.FundedKeys[1].PublicKey().Address()}, + Addrs: []ids.ShortID{genesistest.FundedKeys[1].Address()}, }, ) require.NoError(err) @@ -2165,7 +2165,7 @@ func TestTransferSubnetOwnershipTx(t *testing.T) { Locktime: 0, Threshold: 1, Addrs: []ids.ShortID{ - genesistest.FundedKeys[1].PublicKey().Address(), + genesistest.FundedKeys[1].Address(), }, } expectedOwner.InitCtx(ctx) From 86e01fe88223449a2a0979a49f728ba47296a1d4 Mon Sep 17 00:00:00 2001 From: Stephen Buttolph Date: Thu, 22 Aug 2024 16:31:11 -0400 Subject: [PATCH 21/27] reduce diff --- vms/platformvm/reward/calculator_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vms/platformvm/reward/calculator_test.go b/vms/platformvm/reward/calculator_test.go index c2c94d0c9f78..d2fd17ff9e2b 100644 --- a/vms/platformvm/reward/calculator_test.go +++ b/vms/platformvm/reward/calculator_test.go @@ -15,10 +15,10 @@ import ( ) const ( - defaultMinValidatorStake = 5 * units.MilliAvax - defaultMinStakingDuration = 24 * time.Hour defaultMaxStakingDuration = 365 * 24 * time.Hour + + defaultMinValidatorStake = 5 * units.MilliAvax ) var defaultConfig = Config{ From 09a7c9f16672a868306915a8e18ce77751d588b8 Mon Sep 17 00:00:00 2001 From: Stephen Buttolph Date: Thu, 22 Aug 2024 16:41:59 -0400 Subject: [PATCH 22/27] nit --- vms/platformvm/validator_set_property_test.go | 37 +++++++------------ 1 file changed, 13 insertions(+), 24 deletions(-) diff --git a/vms/platformvm/validator_set_property_test.go b/vms/platformvm/validator_set_property_test.go index b3b35acecb2e..501f4a75f40a 100644 --- a/vms/platformvm/validator_set_property_test.go +++ b/vms/platformvm/validator_set_property_test.go @@ -15,6 +15,7 @@ import ( "github.com/leanovate/gopter" "github.com/leanovate/gopter/gen" "github.com/leanovate/gopter/prop" + "github.com/stretchr/testify/require" "golang.org/x/exp/maps" "github.com/ava-labs/avalanchego/chains" @@ -685,16 +686,11 @@ func buildVM(t *testing.T) (*VM, ids.ID, error) { return nil } - genesisBytes, err := buildCustomGenesis(ctx.AVAXAssetID) - if err != nil { - return nil, ids.Empty, err - } - - err = vm.Initialize( + err := vm.Initialize( context.Background(), ctx, chainDB, - genesisBytes, + buildCustomGenesis(t), nil, nil, msgChan, @@ -756,14 +752,13 @@ func buildVM(t *testing.T) (*VM, ids.ID, error) { return vm, testSubnet1.ID(), nil } -func buildCustomGenesis(avaxAssetID ids.ID) ([]byte, error) { +func buildCustomGenesis(t testing.TB) []byte { + require := require.New(t) + genesisUTXOs := make([]api.UTXO, len(genesistest.FundedKeys)) for i, key := range genesistest.FundedKeys { - id := key.Address() - addr, err := address.FormatBech32(constants.UnitTestHRP, id.Bytes()) - if err != nil { - return nil, err - } + addr, err := address.FormatBech32(constants.UnitTestHRP, key.Address().Bytes()) + require.NoError(err) genesisUTXOs[i] = api.UTXO{ Amount: json.Uint64(genesistest.InitialBalance2), Address: addr, @@ -776,9 +771,7 @@ func buildCustomGenesis(avaxAssetID ids.ID) ([]byte, error) { // times, so to avoid interference with our tests nodeID := genesistest.NodeIDs[len(genesistest.NodeIDs)-1] addr, err := address.FormatBech32(constants.UnitTestHRP, nodeID.Bytes()) - if err != nil { - return nil, err - } + require.NoError(err) starTime := mockable.MaxTime.Add(-1 * defaultMinStakingDuration) endTime := mockable.MaxTime @@ -802,7 +795,7 @@ func buildCustomGenesis(avaxAssetID ids.ID) ([]byte, error) { buildGenesisArgs := api.BuildGenesisArgs{ Encoding: formatting.Hex, NetworkID: json.Uint32(constants.UnitTestID), - AvaxAssetID: avaxAssetID, + AvaxAssetID: snowtest.AVAXAssetID, UTXOs: genesisUTXOs, Validators: []api.GenesisPermissionlessValidator{genesisValidator}, Chains: nil, @@ -812,14 +805,10 @@ func buildCustomGenesis(avaxAssetID ids.ID) ([]byte, error) { buildGenesisResponse := api.BuildGenesisReply{} platformvmSS := api.StaticService{} - if err := platformvmSS.BuildGenesis(nil, &buildGenesisArgs, &buildGenesisResponse); err != nil { - return nil, err - } + require.NoError(platformvmSS.BuildGenesis(nil, &buildGenesisArgs, &buildGenesisResponse)) genesisBytes, err := formatting.Decode(buildGenesisResponse.Encoding, buildGenesisResponse.Bytes) - if err != nil { - return nil, err - } + require.NoError(err) - return genesisBytes, nil + return genesisBytes } From 42a4afc6c1f034428f438de9744a9c92b4b66452 Mon Sep 17 00:00:00 2001 From: Stephen Buttolph Date: Thu, 22 Aug 2024 18:56:22 -0400 Subject: [PATCH 23/27] done? --- vms/platformvm/block/builder/builder_test.go | 24 +- vms/platformvm/block/builder/helpers_test.go | 18 +- .../block/builder/standard_block_test.go | 2 +- vms/platformvm/block/executor/helpers_test.go | 16 +- .../block/executor/proposal_block_test.go | 74 +++---- .../block/executor/standard_block_test.go | 38 ++-- .../block/executor/verifier_test.go | 8 +- vms/platformvm/genesis/genesistest/genesis.go | 192 ++++++++++------ vms/platformvm/genesis/genesistest/helper.go | 102 --------- vms/platformvm/service_test.go | 107 +++++---- vms/platformvm/state/stakers_test.go | 2 +- vms/platformvm/state/state_test.go | 16 +- vms/platformvm/state/statetest/state.go | 9 +- .../txs/executor/advance_time_test.go | 56 ++--- .../txs/executor/create_chain_test.go | 12 +- .../txs/executor/create_subnet_test.go | 10 +- vms/platformvm/txs/executor/export_test.go | 6 +- vms/platformvm/txs/executor/helpers_test.go | 22 +- .../txs/executor/proposal_tx_executor_test.go | 154 ++++++------- .../txs/executor/reward_validator_test.go | 24 +- .../txs/executor/standard_tx_executor_test.go | 206 +++++++++--------- vms/platformvm/validator_set_property_test.go | 94 ++------ .../validators/manager_benchmark_test.go | 55 +---- vms/platformvm/vm_regression_test.go | 112 +++++----- vms/platformvm/vm_test.go | 181 ++++++++------- 25 files changed, 699 insertions(+), 841 deletions(-) delete mode 100644 vms/platformvm/genesis/genesistest/helper.go diff --git a/vms/platformvm/block/builder/builder_test.go b/vms/platformvm/block/builder/builder_test.go index d9c3fe75b367..b0b8d53d6e11 100644 --- a/vms/platformvm/block/builder/builder_test.go +++ b/vms/platformvm/block/builder/builder_test.go @@ -113,7 +113,7 @@ func TestBuildBlockShouldReward(t *testing.T) { require.NoError(err) // Create a valid [AddPermissionlessValidatorTx] - builder, txSigner := env.factory.NewWallet(genesistest.FundedKeys[0]) + builder, txSigner := env.factory.NewWallet(genesistest.DefaultFundedKeys[0]) utx, err := builder.NewAddPermissionlessValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -128,16 +128,16 @@ func TestBuildBlockShouldReward(t *testing.T) { env.ctx.AVAXAssetID, &secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{genesistest.FundedKeys[0].Address()}, + Addrs: []ids.ShortID{genesistest.DefaultFundedKeys[0].Address()}, }, &secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{genesistest.FundedKeys[0].Address()}, + Addrs: []ids.ShortID{genesistest.DefaultFundedKeys[0].Address()}, }, reward.PercentDenominator, common.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{genesistest.FundedKeys[0].Address()}, + Addrs: []ids.ShortID{genesistest.DefaultFundedKeys[0].Address()}, }), ) require.NoError(err) @@ -322,7 +322,7 @@ func TestBuildBlockInvalidStakingDurations(t *testing.T) { sk, err := bls.NewSecretKey() require.NoError(err) - builder1, signer1 := env.factory.NewWallet(genesistest.FundedKeys[0]) + builder1, signer1 := env.factory.NewWallet(genesistest.DefaultFundedKeys[0]) utx1, err := builder1.NewAddPermissionlessValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -337,16 +337,16 @@ func TestBuildBlockInvalidStakingDurations(t *testing.T) { env.ctx.AVAXAssetID, &secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{genesistest.FundedKeys[0].Address()}, + Addrs: []ids.ShortID{genesistest.DefaultFundedKeys[0].Address()}, }, &secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{genesistest.FundedKeys[0].Address()}, + Addrs: []ids.ShortID{genesistest.DefaultFundedKeys[0].Address()}, }, reward.PercentDenominator, common.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{genesistest.FundedKeys[0].Address()}, + Addrs: []ids.ShortID{genesistest.DefaultFundedKeys[0].Address()}, }), ) require.NoError(err) @@ -363,7 +363,7 @@ func TestBuildBlockInvalidStakingDurations(t *testing.T) { sk, err = bls.NewSecretKey() require.NoError(err) - builder2, signer2 := env.factory.NewWallet(genesistest.FundedKeys[2]) + builder2, signer2 := env.factory.NewWallet(genesistest.DefaultFundedKeys[2]) utx2, err := builder2.NewAddPermissionlessValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -378,16 +378,16 @@ func TestBuildBlockInvalidStakingDurations(t *testing.T) { env.ctx.AVAXAssetID, &secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{genesistest.FundedKeys[2].Address()}, + Addrs: []ids.ShortID{genesistest.DefaultFundedKeys[2].Address()}, }, &secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{genesistest.FundedKeys[2].Address()}, + Addrs: []ids.ShortID{genesistest.DefaultFundedKeys[2].Address()}, }, reward.PercentDenominator, common.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{genesistest.FundedKeys[2].Address()}, + Addrs: []ids.ShortID{genesistest.DefaultFundedKeys[2].Address()}, }), ) require.NoError(err) diff --git a/vms/platformvm/block/builder/helpers_test.go b/vms/platformvm/block/builder/helpers_test.go index 03680d87f421..56b38828de9c 100644 --- a/vms/platformvm/block/builder/helpers_test.go +++ b/vms/platformvm/block/builder/helpers_test.go @@ -63,7 +63,7 @@ const ( var ( testSubnet1 *txs.Tx - testSubnet1ControlKeys = genesistest.FundedKeys[0:3] + testSubnet1ControlKeys = genesistest.DefaultFundedKeys[0:3] ) type mutableSharedMemory struct { @@ -119,7 +119,7 @@ func newEnvironment(t *testing.T, f upgradetest.Fork) *environment { //nolint:un rewardsCalc := reward.NewCalculator(res.config.RewardConfig) res.state = statetest.New(t, statetest.Config{ DB: res.baseDB, - Genesis: genesistest.BuildBytes(t), + Genesis: genesistest.NewBytes(t, genesistest.Config{}), Validators: res.config.Validators, Context: res.ctx, Rewards: rewardsCalc, @@ -210,19 +210,19 @@ func newEnvironment(t *testing.T, f upgradetest.Fork) *environment { //nolint:un func addSubnet(t *testing.T, env *environment) { require := require.New(t) - builder, signer := env.factory.NewWallet(genesistest.FundedKeys[0]) + builder, signer := env.factory.NewWallet(genesistest.DefaultFundedKeys[0]) utx, err := builder.NewCreateSubnetTx( &secp256k1fx.OutputOwners{ Threshold: 2, Addrs: []ids.ShortID{ - genesistest.FundedKeys[0].Address(), - genesistest.FundedKeys[1].Address(), - genesistest.FundedKeys[2].Address(), + genesistest.DefaultFundedKeys[0].Address(), + genesistest.DefaultFundedKeys[1].Address(), + genesistest.DefaultFundedKeys[2].Address(), }, }, walletcommon.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{genesistest.FundedKeys[0].Address()}, + Addrs: []ids.ShortID{genesistest.DefaultFundedKeys[0].Address()}, }), ) require.NoError(err) @@ -253,7 +253,7 @@ func defaultConfig(f upgradetest.Fork) *config.Config { upgradetest.SetTimesTo( &upgrades, min(f, upgradetest.ApricotPhase5), - genesistest.ValidatorEndTime, + genesistest.DefaultValidatorEndTime, ) return &config.Config{ @@ -283,7 +283,7 @@ func defaultConfig(f upgradetest.Fork) *config.Config { func defaultClock() *mockable.Clock { // set time after Banff fork (and before default nextStakerTime) clk := &mockable.Clock{} - clk.Set(genesistest.Time) + clk.Set(genesistest.DefaultTime) return clk } diff --git a/vms/platformvm/block/builder/standard_block_test.go b/vms/platformvm/block/builder/standard_block_test.go index 5eb44e36e9ac..e97cbee313fd 100644 --- a/vms/platformvm/block/builder/standard_block_test.go +++ b/vms/platformvm/block/builder/standard_block_test.go @@ -34,7 +34,7 @@ func TestAtomicTxImports(t *testing.T) { OutputIndex: 1, } amount := uint64(70000) - recipientKey := genesistest.FundedKeys[1] + recipientKey := genesistest.DefaultFundedKeys[1] m := atomic.NewMemory(prefixdb.New([]byte{5}, env.baseDB)) diff --git a/vms/platformvm/block/executor/helpers_test.go b/vms/platformvm/block/executor/helpers_test.go index da2ad4ee903a..661f1d801fbb 100644 --- a/vms/platformvm/block/executor/helpers_test.go +++ b/vms/platformvm/block/executor/helpers_test.go @@ -124,7 +124,7 @@ func newEnvironment(t *testing.T, ctrl *gomock.Controller, f upgradetest.Fork) * if ctrl == nil { res.state = statetest.New(t, statetest.Config{ DB: res.baseDB, - Genesis: genesistest.BuildBytes(t), + Genesis: genesistest.NewBytes(t, genesistest.Config{}), Validators: res.config.Validators, Context: res.ctx, Rewards: rewardsCalc, @@ -223,19 +223,19 @@ func newEnvironment(t *testing.T, ctrl *gomock.Controller, f upgradetest.Fork) * } func addSubnet(env *environment) { - builder, signer := env.factory.NewWallet(genesistest.FundedKeys[0]) + builder, signer := env.factory.NewWallet(genesistest.DefaultFundedKeys[0]) utx, err := builder.NewCreateSubnetTx( &secp256k1fx.OutputOwners{ Threshold: 2, Addrs: []ids.ShortID{ - genesistest.FundedKeys[0].Address(), - genesistest.FundedKeys[1].Address(), - genesistest.FundedKeys[2].Address(), + genesistest.DefaultFundedKeys[0].Address(), + genesistest.DefaultFundedKeys[1].Address(), + genesistest.DefaultFundedKeys[2].Address(), }, }, walletcommon.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{genesistest.FundedKeys[0].Address()}, + Addrs: []ids.ShortID{genesistest.DefaultFundedKeys[0].Address()}, }), ) if err != nil { @@ -278,7 +278,7 @@ func defaultConfig(f upgradetest.Fork) *config.Config { upgradetest.SetTimesTo( &upgrades, min(f, upgradetest.ApricotPhase5), - genesistest.ValidatorEndTime, + genesistest.DefaultValidatorEndTime, ) return &config.Config{ @@ -307,7 +307,7 @@ func defaultConfig(f upgradetest.Fork) *config.Config { func defaultClock() *mockable.Clock { clk := &mockable.Clock{} - clk.Set(genesistest.Time) + clk.Set(genesistest.DefaultTime) return clk } diff --git a/vms/platformvm/block/executor/proposal_block_test.go b/vms/platformvm/block/executor/proposal_block_test.go index 2bc6de1b24f9..22bcda3a7274 100644 --- a/vms/platformvm/block/executor/proposal_block_test.go +++ b/vms/platformvm/block/executor/proposal_block_test.go @@ -145,7 +145,7 @@ func TestBanffProposalBlockTimeVerification(t *testing.T) { env := newEnvironment(t, ctrl, upgradetest.Banff) // create parentBlock. It's a standard one for simplicity - parentTime := genesistest.Time + parentTime := genesistest.DefaultTime parentHeight := uint64(2022) banffParentBlk, err := block.NewApricotStandardBlock( @@ -375,15 +375,15 @@ func TestBanffProposalBlockUpdateStakers(t *testing.T) { staker0 := staker{ nodeID: ids.BuildTestNodeID([]byte{0xf0}), rewardAddress: ids.ShortID{0xf0}, - startTime: genesistest.Time, + startTime: genesistest.DefaultTime, endTime: time.Time{}, // actual endTime depends on specific test } staker1 := staker{ nodeID: ids.BuildTestNodeID([]byte{0xf1}), rewardAddress: ids.ShortID{0xf1}, - startTime: genesistest.Time.Add(1 * time.Minute), - endTime: genesistest.Time.Add(10 * defaultMinStakingDuration).Add(1 * time.Minute), + startTime: genesistest.DefaultTime.Add(1 * time.Minute), + endTime: genesistest.DefaultTime.Add(10 * defaultMinStakingDuration).Add(1 * time.Minute), } staker2 := staker{ nodeID: ids.BuildTestNodeID([]byte{0xf2}), @@ -520,7 +520,7 @@ func TestBanffProposalBlockUpdateStakers(t *testing.T) { env.config.TrackedSubnets.Add(subnetID) for _, staker := range test.stakers { - builder, signer := env.factory.NewWallet(genesistest.FundedKeys[0]) + builder, signer := env.factory.NewWallet(genesistest.DefaultFundedKeys[0]) utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: staker.nodeID, @@ -554,7 +554,7 @@ func TestBanffProposalBlockUpdateStakers(t *testing.T) { } for _, subStaker := range test.subnetStakers { - builder, signer := env.factory.NewWallet(genesistest.FundedKeys[0], genesistest.FundedKeys[1]) + builder, signer := env.factory.NewWallet(genesistest.DefaultFundedKeys[0], genesistest.DefaultFundedKeys[1]) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -591,7 +591,7 @@ func TestBanffProposalBlockUpdateStakers(t *testing.T) { // add Staker0 (with the right end time) to state // so to allow proposalBlk issuance staker0.endTime = newTime - builder, signer := env.factory.NewWallet(genesistest.FundedKeys[0], genesistest.FundedKeys[1]) + builder, signer := env.factory.NewWallet(genesistest.DefaultFundedKeys[0], genesistest.DefaultFundedKeys[1]) utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: staker0.nodeID, @@ -698,14 +698,14 @@ func TestBanffProposalBlockRemoveSubnetValidator(t *testing.T) { env.config.TrackedSubnets.Add(subnetID) // Add a subnet validator to the staker set - subnetValidatorNodeID := genesistest.NodeIDs[0] - subnetVdr1EndTime := genesistest.Time.Add(defaultMinStakingDuration) - builder, signer := env.factory.NewWallet(genesistest.FundedKeys[0], genesistest.FundedKeys[1]) + subnetValidatorNodeID := genesistest.DefaultNodeIDs[0] + subnetVdr1EndTime := genesistest.DefaultTime.Add(defaultMinStakingDuration) + builder, signer := env.factory.NewWallet(genesistest.DefaultFundedKeys[0], genesistest.DefaultFundedKeys[1]) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: subnetValidatorNodeID, - Start: genesistest.TimeUnix, + Start: genesistest.DefaultTimeUnix, End: uint64(subnetVdr1EndTime.Unix()), Wght: 1, }, @@ -732,7 +732,7 @@ func TestBanffProposalBlockRemoveSubnetValidator(t *testing.T) { // The above validator is now part of the staking set // Queue a staker that joins the staker set after the above validator leaves - subnetVdr2NodeID := genesistest.NodeIDs[1] + subnetVdr2NodeID := genesistest.DefaultNodeIDs[1] utx, err = builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -769,7 +769,7 @@ func TestBanffProposalBlockRemoveSubnetValidator(t *testing.T) { uVdrTx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: ids.GenerateTestNodeID(), - Start: genesistest.TimeUnix, + Start: genesistest.DefaultTimeUnix, End: uint64(staker0EndTime.Unix()), Wght: 10, }, @@ -855,11 +855,11 @@ func TestBanffProposalBlockTrackedSubnet(t *testing.T) { } // Add a subnet validator to the staker set - subnetValidatorNodeID := genesistest.NodeIDs[0] - subnetVdr1StartTime := genesistest.Time.Add(1 * time.Minute) - subnetVdr1EndTime := genesistest.Time.Add(10 * defaultMinStakingDuration).Add(1 * time.Minute) + subnetValidatorNodeID := genesistest.DefaultNodeIDs[0] + subnetVdr1StartTime := genesistest.DefaultTime.Add(1 * time.Minute) + subnetVdr1EndTime := genesistest.DefaultTime.Add(10 * defaultMinStakingDuration).Add(1 * time.Minute) - builder, signer := env.factory.NewWallet(genesistest.FundedKeys[0], genesistest.FundedKeys[1]) + builder, signer := env.factory.NewWallet(genesistest.DefaultFundedKeys[0], genesistest.DefaultFundedKeys[1]) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -890,7 +890,7 @@ func TestBanffProposalBlockTrackedSubnet(t *testing.T) { // add Staker0 (with the right end time) to state // so to allow proposalBlk issuance - staker0StartTime := genesistest.Time + staker0StartTime := genesistest.DefaultTime staker0EndTime := subnetVdr1StartTime uVdrTx, err := builder.NewAddValidatorTx( @@ -965,7 +965,7 @@ func TestBanffProposalBlockDelegatorStakerWeight(t *testing.T) { // Case: Timestamp is after next validator start time // Add a pending validator - pendingValidatorStartTime := genesistest.Time.Add(1 * time.Second) + pendingValidatorStartTime := genesistest.DefaultTime.Add(1 * time.Second) pendingValidatorEndTime := pendingValidatorStartTime.Add(defaultMaxStakingDuration) nodeID := ids.GenerateTestNodeID() rewardAddress := ids.GenerateTestShortID() @@ -975,15 +975,15 @@ func TestBanffProposalBlockDelegatorStakerWeight(t *testing.T) { pendingValidatorEndTime, nodeID, rewardAddress, - []*secp256k1.PrivateKey{genesistest.FundedKeys[0]}, + []*secp256k1.PrivateKey{genesistest.DefaultFundedKeys[0]}, ) require.NoError(err) // add Staker0 (with the right end time) to state // just to allow proposalBlk issuance (with a reward Tx) - staker0StartTime := genesistest.Time + staker0StartTime := genesistest.DefaultTime staker0EndTime := pendingValidatorStartTime - builder, signer := env.factory.NewWallet(genesistest.FundedKeys[0], genesistest.FundedKeys[1]) + builder, signer := env.factory.NewWallet(genesistest.DefaultFundedKeys[0], genesistest.DefaultFundedKeys[1]) utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: ids.GenerateTestNodeID(), @@ -1054,7 +1054,7 @@ func TestBanffProposalBlockDelegatorStakerWeight(t *testing.T) { pendingDelegatorStartTime := pendingValidatorStartTime.Add(1 * time.Second) pendingDelegatorEndTime := pendingDelegatorStartTime.Add(1 * time.Second) - builder, signer = env.factory.NewWallet(genesistest.FundedKeys[0], genesistest.FundedKeys[1], genesistest.FundedKeys[4]) + builder, signer = env.factory.NewWallet(genesistest.DefaultFundedKeys[0], genesistest.DefaultFundedKeys[1], genesistest.DefaultFundedKeys[4]) uDelTx, err := builder.NewAddDelegatorTx( &txs.Validator{ NodeID: nodeID, @@ -1064,7 +1064,7 @@ func TestBanffProposalBlockDelegatorStakerWeight(t *testing.T) { }, &secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{genesistest.FundedKeys[0].Address()}, + Addrs: []ids.ShortID{genesistest.DefaultFundedKeys[0].Address()}, }, ) require.NoError(err) @@ -1085,7 +1085,7 @@ func TestBanffProposalBlockDelegatorStakerWeight(t *testing.T) { // add Staker0 (with the right end time) to state // so to allow proposalBlk issuance staker0EndTime = pendingDelegatorStartTime - builder, signer = env.factory.NewWallet(genesistest.FundedKeys[0], genesistest.FundedKeys[1]) + builder, signer = env.factory.NewWallet(genesistest.DefaultFundedKeys[0], genesistest.DefaultFundedKeys[1]) utx, err = builder.NewAddValidatorTx( &txs.Validator{ NodeID: ids.GenerateTestNodeID(), @@ -1160,7 +1160,7 @@ func TestBanffProposalBlockDelegatorStakers(t *testing.T) { // Case: Timestamp is after next validator start time // Add a pending validator - pendingValidatorStartTime := genesistest.Time.Add(1 * time.Second) + pendingValidatorStartTime := genesistest.DefaultTime.Add(1 * time.Second) pendingValidatorEndTime := pendingValidatorStartTime.Add(defaultMinStakingDuration) nodeIDKey, _ := secp256k1.NewPrivateKey() rewardAddress := nodeIDKey.Address() @@ -1172,15 +1172,15 @@ func TestBanffProposalBlockDelegatorStakers(t *testing.T) { pendingValidatorEndTime, nodeID, rewardAddress, - []*secp256k1.PrivateKey{genesistest.FundedKeys[0]}, + []*secp256k1.PrivateKey{genesistest.DefaultFundedKeys[0]}, ) require.NoError(err) // add Staker0 (with the right end time) to state // so to allow proposalBlk issuance - staker0StartTime := genesistest.Time + staker0StartTime := genesistest.DefaultTime staker0EndTime := pendingValidatorStartTime - builder, txSigner := env.factory.NewWallet(genesistest.FundedKeys[0], genesistest.FundedKeys[1]) + builder, txSigner := env.factory.NewWallet(genesistest.DefaultFundedKeys[0], genesistest.DefaultFundedKeys[1]) utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: ids.GenerateTestNodeID(), @@ -1250,7 +1250,7 @@ func TestBanffProposalBlockDelegatorStakers(t *testing.T) { // Add delegator pendingDelegatorStartTime := pendingValidatorStartTime.Add(1 * time.Second) pendingDelegatorEndTime := pendingDelegatorStartTime.Add(defaultMinStakingDuration) - builder, txSigner = env.factory.NewWallet(genesistest.FundedKeys[0], genesistest.FundedKeys[1], genesistest.FundedKeys[4]) + builder, txSigner = env.factory.NewWallet(genesistest.DefaultFundedKeys[0], genesistest.DefaultFundedKeys[1], genesistest.DefaultFundedKeys[4]) uDelTx, err := builder.NewAddDelegatorTx( &txs.Validator{ NodeID: nodeID, @@ -1260,7 +1260,7 @@ func TestBanffProposalBlockDelegatorStakers(t *testing.T) { }, &secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{genesistest.FundedKeys[0].Address()}, + Addrs: []ids.ShortID{genesistest.DefaultFundedKeys[0].Address()}, }, ) require.NoError(err) @@ -1281,7 +1281,7 @@ func TestBanffProposalBlockDelegatorStakers(t *testing.T) { // add Staker0 (with the right end time) to state // so to allow proposalBlk issuance staker0EndTime = pendingDelegatorStartTime - builder, txSigner = env.factory.NewWallet(genesistest.FundedKeys[0], genesistest.FundedKeys[1]) + builder, txSigner = env.factory.NewWallet(genesistest.DefaultFundedKeys[0], genesistest.DefaultFundedKeys[1]) utx, err = builder.NewAddValidatorTx( &txs.Validator{ NodeID: ids.GenerateTestNodeID(), @@ -1365,7 +1365,7 @@ func TestAddValidatorProposalBlock(t *testing.T) { sk, err := bls.NewSecretKey() require.NoError(err) - builder, txSigner := env.factory.NewWallet(genesistest.FundedKeys[0], genesistest.FundedKeys[1], genesistest.FundedKeys[4]) + builder, txSigner := env.factory.NewWallet(genesistest.DefaultFundedKeys[0], genesistest.DefaultFundedKeys[1], genesistest.DefaultFundedKeys[4]) utx, err := builder.NewAddPermissionlessValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -1380,11 +1380,11 @@ func TestAddValidatorProposalBlock(t *testing.T) { env.ctx.AVAXAssetID, &secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{genesistest.FundedKeys[0].Address()}, + Addrs: []ids.ShortID{genesistest.DefaultFundedKeys[0].Address()}, }, &secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{genesistest.FundedKeys[0].Address()}, + Addrs: []ids.ShortID{genesistest.DefaultFundedKeys[0].Address()}, }, 10000, ) @@ -1464,11 +1464,11 @@ func TestAddValidatorProposalBlock(t *testing.T) { env.ctx.AVAXAssetID, &secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{genesistest.FundedKeys[0].Address()}, + Addrs: []ids.ShortID{genesistest.DefaultFundedKeys[0].Address()}, }, &secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{genesistest.FundedKeys[0].Address()}, + Addrs: []ids.ShortID{genesistest.DefaultFundedKeys[0].Address()}, }, 10000, ) diff --git a/vms/platformvm/block/executor/standard_block_test.go b/vms/platformvm/block/executor/standard_block_test.go index eb05016725d1..4da0c48831a5 100644 --- a/vms/platformvm/block/executor/standard_block_test.go +++ b/vms/platformvm/block/executor/standard_block_test.go @@ -297,7 +297,7 @@ func TestBanffStandardBlockUpdatePrimaryNetworkStakers(t *testing.T) { // Case: Timestamp is after next validator start time // Add a pending validator - pendingValidatorStartTime := genesistest.Time.Add(1 * time.Second) + pendingValidatorStartTime := genesistest.DefaultTime.Add(1 * time.Second) pendingValidatorEndTime := pendingValidatorStartTime.Add(defaultMinStakingDuration) nodeID := ids.GenerateTestNodeID() rewardAddress := ids.GenerateTestShortID() @@ -307,7 +307,7 @@ func TestBanffStandardBlockUpdatePrimaryNetworkStakers(t *testing.T) { pendingValidatorEndTime, nodeID, rewardAddress, - []*secp256k1.PrivateKey{genesistest.FundedKeys[0]}, + []*secp256k1.PrivateKey{genesistest.DefaultFundedKeys[0]}, ) require.NoError(err) @@ -364,8 +364,8 @@ func TestBanffStandardBlockUpdateStakers(t *testing.T) { staker1 := staker{ nodeID: ids.BuildTestNodeID([]byte{0xf1}), rewardAddress: ids.ShortID{0xf1}, - startTime: genesistest.Time.Add(1 * time.Minute), - endTime: genesistest.Time.Add(10 * defaultMinStakingDuration).Add(1 * time.Minute), + startTime: genesistest.DefaultTime.Add(1 * time.Minute), + endTime: genesistest.DefaultTime.Add(10 * defaultMinStakingDuration).Add(1 * time.Minute), } staker2 := staker{ nodeID: ids.BuildTestNodeID([]byte{0xf2}), @@ -506,13 +506,13 @@ func TestBanffStandardBlockUpdateStakers(t *testing.T) { staker.endTime, staker.nodeID, staker.rewardAddress, - []*secp256k1.PrivateKey{genesistest.FundedKeys[0]}, + []*secp256k1.PrivateKey{genesistest.DefaultFundedKeys[0]}, ) require.NoError(err) } for _, staker := range test.subnetStakers { - builder, signer := env.factory.NewWallet(genesistest.FundedKeys[0], genesistest.FundedKeys[1]) + builder, signer := env.factory.NewWallet(genesistest.DefaultFundedKeys[0], genesistest.DefaultFundedKeys[1]) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -603,14 +603,14 @@ func TestBanffStandardBlockRemoveSubnetValidator(t *testing.T) { env.config.TrackedSubnets.Add(subnetID) // Add a subnet validator to the staker set - subnetValidatorNodeID := genesistest.NodeIDs[0] - subnetVdr1EndTime := genesistest.Time.Add(defaultMinStakingDuration) - builder, signer := env.factory.NewWallet(genesistest.FundedKeys[0], genesistest.FundedKeys[1]) + subnetValidatorNodeID := genesistest.DefaultNodeIDs[0] + subnetVdr1EndTime := genesistest.DefaultTime.Add(defaultMinStakingDuration) + builder, signer := env.factory.NewWallet(genesistest.DefaultFundedKeys[0], genesistest.DefaultFundedKeys[1]) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: subnetValidatorNodeID, - Start: genesistest.TimeUnix, + Start: genesistest.DefaultTimeUnix, End: uint64(subnetVdr1EndTime.Unix()), Wght: 1, }, @@ -637,7 +637,7 @@ func TestBanffStandardBlockRemoveSubnetValidator(t *testing.T) { // The above validator is now part of the staking set // Queue a staker that joins the staker set after the above validator leaves - subnetVdr2NodeID := genesistest.NodeIDs[1] + subnetVdr2NodeID := genesistest.DefaultNodeIDs[1] utx, err = builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -708,10 +708,10 @@ func TestBanffStandardBlockTrackedSubnet(t *testing.T) { } // Add a subnet validator to the staker set - subnetValidatorNodeID := genesistest.NodeIDs[0] - subnetVdr1StartTime := genesistest.Time.Add(1 * time.Minute) - subnetVdr1EndTime := genesistest.Time.Add(10 * defaultMinStakingDuration).Add(1 * time.Minute) - builder, signer := env.factory.NewWallet(genesistest.FundedKeys[0], genesistest.FundedKeys[1]) + subnetValidatorNodeID := genesistest.DefaultNodeIDs[0] + subnetVdr1StartTime := genesistest.DefaultTime.Add(1 * time.Minute) + subnetVdr1EndTime := genesistest.DefaultTime.Add(10 * defaultMinStakingDuration).Add(1 * time.Minute) + builder, signer := env.factory.NewWallet(genesistest.DefaultFundedKeys[0], genesistest.DefaultFundedKeys[1]) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -768,7 +768,7 @@ func TestBanffStandardBlockDelegatorStakerWeight(t *testing.T) { // Case: Timestamp is after next validator start time // Add a pending validator - pendingValidatorStartTime := genesistest.Time.Add(1 * time.Second) + pendingValidatorStartTime := genesistest.DefaultTime.Add(1 * time.Second) pendingValidatorEndTime := pendingValidatorStartTime.Add(defaultMaxStakingDuration) nodeID := ids.GenerateTestNodeID() rewardAddress := ids.GenerateTestShortID() @@ -778,7 +778,7 @@ func TestBanffStandardBlockDelegatorStakerWeight(t *testing.T) { pendingValidatorEndTime, nodeID, rewardAddress, - []*secp256k1.PrivateKey{genesistest.FundedKeys[0]}, + []*secp256k1.PrivateKey{genesistest.DefaultFundedKeys[0]}, ) require.NoError(err) @@ -806,7 +806,7 @@ func TestBanffStandardBlockDelegatorStakerWeight(t *testing.T) { pendingDelegatorStartTime := pendingValidatorStartTime.Add(1 * time.Second) pendingDelegatorEndTime := pendingDelegatorStartTime.Add(1 * time.Second) - builder, signer := env.factory.NewWallet(genesistest.FundedKeys[0], genesistest.FundedKeys[1], genesistest.FundedKeys[4]) + builder, signer := env.factory.NewWallet(genesistest.DefaultFundedKeys[0], genesistest.DefaultFundedKeys[1], genesistest.DefaultFundedKeys[4]) utx, err := builder.NewAddDelegatorTx( &txs.Validator{ NodeID: nodeID, @@ -816,7 +816,7 @@ func TestBanffStandardBlockDelegatorStakerWeight(t *testing.T) { }, &secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{genesistest.FundedKeys[0].Address()}, + Addrs: []ids.ShortID{genesistest.DefaultFundedKeys[0].Address()}, }, ) require.NoError(err) diff --git a/vms/platformvm/block/executor/verifier_test.go b/vms/platformvm/block/executor/verifier_test.go index f399222faca2..00772bb549ac 100644 --- a/vms/platformvm/block/executor/verifier_test.go +++ b/vms/platformvm/block/executor/verifier_test.go @@ -469,7 +469,7 @@ func TestVerifyUnverifiedParent(t *testing.T) { func TestBanffAbortBlockTimestampChecks(t *testing.T) { ctrl := gomock.NewController(t) - now := genesistest.Time.Add(time.Hour) + now := genesistest.DefaultTime.Add(time.Hour) tests := []struct { description string @@ -532,7 +532,7 @@ func TestBanffAbortBlockTimestampChecks(t *testing.T) { require.NoError(err) // setup parent state - parentTime := genesistest.Time + parentTime := genesistest.DefaultTime s.EXPECT().GetLastAccepted().Return(parentID).Times(3) s.EXPECT().GetTimestamp().Return(parentTime).Times(3) s.EXPECT().GetFeeState().Return(fee.State{}).Times(3) @@ -566,7 +566,7 @@ func TestBanffAbortBlockTimestampChecks(t *testing.T) { func TestBanffCommitBlockTimestampChecks(t *testing.T) { ctrl := gomock.NewController(t) - now := genesistest.Time.Add(time.Hour) + now := genesistest.DefaultTime.Add(time.Hour) tests := []struct { description string @@ -629,7 +629,7 @@ func TestBanffCommitBlockTimestampChecks(t *testing.T) { require.NoError(err) // setup parent state - parentTime := genesistest.Time + parentTime := genesistest.DefaultTime s.EXPECT().GetLastAccepted().Return(parentID).Times(3) s.EXPECT().GetTimestamp().Return(parentTime).Times(3) s.EXPECT().GetFeeState().Return(fee.State{}).Times(3) diff --git a/vms/platformvm/genesis/genesistest/genesis.go b/vms/platformvm/genesis/genesistest/genesis.go index 8d0ab699fb5f..efc2815c6cee 100644 --- a/vms/platformvm/genesis/genesistest/genesis.go +++ b/vms/platformvm/genesis/genesistest/genesis.go @@ -13,67 +13,144 @@ import ( "github.com/ava-labs/avalanchego/snow/snowtest" "github.com/ava-labs/avalanchego/upgrade" "github.com/ava-labs/avalanchego/utils/constants" + "github.com/ava-labs/avalanchego/utils/crypto/secp256k1" "github.com/ava-labs/avalanchego/utils/units" "github.com/ava-labs/avalanchego/vms/components/avax" "github.com/ava-labs/avalanchego/vms/platformvm/reward" "github.com/ava-labs/avalanchego/vms/platformvm/txs" "github.com/ava-labs/avalanchego/vms/secp256k1fx" - avalanchegenesis "github.com/ava-labs/avalanchego/genesis" platformvmgenesis "github.com/ava-labs/avalanchego/vms/platformvm/genesis" ) const ( - ValidatorDuration = 28 * 24 * time.Hour - ValidatorWeight = units.MegaAvax + DefaultValidatorDuration = 28 * 24 * time.Hour + DefaultValidatorWeight = 5 * units.MilliAvax + DefaultInitialBalance = 1 * units.Avax + ValidatorDelegationShares = reward.PercentDenominator + XChainName = "x" + InitialSupply = 360 * units.MegaAvax +) - XChainName = "x" +var ( + AVAXAsset = avax.Asset{ID: snowtest.AVAXAssetID} - InitialBalance = 10 * units.MegaAvax - InitialSupply = ValidatorWeight + InitialBalance + DefaultTime = upgrade.InitiallyActiveTime + DefaultTimeUnix = uint64(DefaultTime.Unix()) + DefaultValidatorEndTime = DefaultTime.Add(DefaultValidatorDuration) + DefaultValidatorEndTimeUnix = uint64(DefaultValidatorEndTime.Unix()) ) var ( - AVAXAsset = avax.Asset{ID: snowtest.AVAXAssetID} + // Keys that are funded in the genesis + DefaultFundedKeys = secp256k1.TestKeys() - ValidatorNodeID = ids.GenerateTestNodeID() - Time = upgrade.InitiallyActiveTime - TimeUnix = uint64(Time.Unix()) - ValidatorEndTime = Time.Add(ValidatorDuration) - ValidatorEndTimeUnix = uint64(ValidatorEndTime.Unix()) - ValidatorRewardsOwner = &secp256k1fx.OutputOwners{} + // Node IDs of genesis validators + DefaultNodeIDs []ids.NodeID ) -func New(t testing.TB) *platformvmgenesis.Genesis { +func init() { + DefaultNodeIDs = make([]ids.NodeID, len(DefaultFundedKeys)) + for i := range DefaultFundedKeys { + DefaultNodeIDs[i] = ids.GenerateTestNodeID() + } +} + +type Config struct { + NodeIDs []ids.NodeID + ValidatorWeight uint64 + Time time.Time + ValidatorEndTime time.Time + + FundedKeys []*secp256k1.PrivateKey + InitialBalance uint64 +} + +func New(t testing.TB, c Config) *platformvmgenesis.Genesis { + if len(c.NodeIDs) == 0 { + c.NodeIDs = DefaultNodeIDs + } + if c.ValidatorWeight == 0 { + c.ValidatorWeight = DefaultValidatorWeight + } + if c.Time.IsZero() { + c.Time = DefaultTime + } + if c.ValidatorEndTime.IsZero() { + c.ValidatorEndTime = DefaultValidatorEndTime + } + if len(c.FundedKeys) == 0 { + c.FundedKeys = DefaultFundedKeys + } + if c.InitialBalance == 0 { + c.InitialBalance = DefaultInitialBalance + } + require := require.New(t) - genesisValidator := &txs.AddValidatorTx{ - BaseTx: txs.BaseTx{BaseTx: avax.BaseTx{ - NetworkID: constants.UnitTestID, - BlockchainID: constants.PlatformChainID, - }}, - Validator: txs.Validator{ - NodeID: ValidatorNodeID, - Start: TimeUnix, - End: ValidatorEndTimeUnix, - Wght: ValidatorWeight, - }, - StakeOuts: []*avax.TransferableOutput{ - { - Asset: AVAXAsset, - Out: &secp256k1fx.TransferOutput{ - Amt: ValidatorWeight, + genesis := &platformvmgenesis.Genesis{ + UTXOs: make([]*platformvmgenesis.UTXO, len(c.FundedKeys)), + Validators: make([]*txs.Tx, len(c.NodeIDs)), + Timestamp: uint64(c.Time.Unix()), + InitialSupply: InitialSupply, + } + for i, key := range c.FundedKeys { + genesis.UTXOs[i] = &platformvmgenesis.UTXO{UTXO: avax.UTXO{ + UTXOID: avax.UTXOID{ + TxID: snowtest.AVAXAssetID, + OutputIndex: uint32(i), + }, + Asset: AVAXAsset, + Out: &secp256k1fx.TransferOutput{ + Amt: c.InitialBalance, + OutputOwners: secp256k1fx.OutputOwners{ + Threshold: 1, + Addrs: []ids.ShortID{ + key.Address(), + }, + }, + }, + }} + } + for i, nodeID := range c.NodeIDs { + key := c.FundedKeys[i%len(c.FundedKeys)] + owner := secp256k1fx.OutputOwners{ + Threshold: 1, + Addrs: []ids.ShortID{ + key.Address(), + }, + } + validator := &txs.AddValidatorTx{ + BaseTx: txs.BaseTx{BaseTx: avax.BaseTx{ + NetworkID: constants.UnitTestID, + BlockchainID: constants.PlatformChainID, + }}, + Validator: txs.Validator{ + NodeID: nodeID, + Start: uint64(c.Time.Unix()), + End: uint64(c.ValidatorEndTime.Unix()), + Wght: c.ValidatorWeight, + }, + StakeOuts: []*avax.TransferableOutput{ + { + Asset: AVAXAsset, + Out: &secp256k1fx.TransferOutput{ + Amt: c.ValidatorWeight, + OutputOwners: owner, + }, }, }, - }, - RewardsOwner: ValidatorRewardsOwner, - DelegationShares: ValidatorDelegationShares, + RewardsOwner: &owner, + DelegationShares: ValidatorDelegationShares, + } + validatorTx := &txs.Tx{Unsigned: validator} + require.NoError(validatorTx.Initialize(txs.GenesisCodec)) + + genesis.Validators[i] = validatorTx } - genesisValidatorTx := &txs.Tx{Unsigned: genesisValidator} - require.NoError(genesisValidatorTx.Initialize(txs.Codec)) - genesisChain := &txs.CreateChainTx{ + chain := &txs.CreateChainTx{ BaseTx: txs.BaseTx{BaseTx: avax.BaseTx{ NetworkID: constants.UnitTestID, BlockchainID: constants.PlatformChainID, @@ -83,44 +160,15 @@ func New(t testing.TB) *platformvmgenesis.Genesis { VMID: constants.AVMID, SubnetAuth: &secp256k1fx.Input{}, } - genesisChainTx := &txs.Tx{Unsigned: genesisChain} - require.NoError(genesisChainTx.Initialize(txs.Codec)) - - return &platformvmgenesis.Genesis{ - UTXOs: []*platformvmgenesis.UTXO{ - { - UTXO: avax.UTXO{ - UTXOID: avax.UTXOID{ - TxID: snowtest.AVAXAssetID, - OutputIndex: 0, - }, - Asset: AVAXAsset, - Out: &secp256k1fx.TransferOutput{ - Amt: InitialBalance, - OutputOwners: secp256k1fx.OutputOwners{ - Threshold: 1, - Addrs: []ids.ShortID{ - avalanchegenesis.EWOQKey.Address(), - }, - }, - }, - }, - Message: nil, - }, - }, - Validators: []*txs.Tx{ - genesisValidatorTx, - }, - Chains: []*txs.Tx{ - genesisChainTx, - }, - Timestamp: TimeUnix, - InitialSupply: InitialSupply, - } + chainTx := &txs.Tx{Unsigned: chain} + require.NoError(chainTx.Initialize(txs.GenesisCodec)) + + genesis.Chains = []*txs.Tx{chainTx} + return genesis } -func NewBytes(t testing.TB) []byte { - g := New(t) +func NewBytes(t testing.TB, c Config) []byte { + g := New(t, c) genesisBytes, err := platformvmgenesis.Codec.Marshal(platformvmgenesis.CodecVersion, g) require.NoError(t, err) return genesisBytes diff --git a/vms/platformvm/genesis/genesistest/helper.go b/vms/platformvm/genesis/genesistest/helper.go deleted file mode 100644 index 99333df3eb7e..000000000000 --- a/vms/platformvm/genesis/genesistest/helper.go +++ /dev/null @@ -1,102 +0,0 @@ -// Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. -// See the file LICENSE for licensing terms. - -package genesistest - -import ( - "testing" - - "github.com/stretchr/testify/require" - - "github.com/ava-labs/avalanchego/ids" - "github.com/ava-labs/avalanchego/snow/snowtest" - "github.com/ava-labs/avalanchego/utils/constants" - "github.com/ava-labs/avalanchego/utils/crypto/secp256k1" - "github.com/ava-labs/avalanchego/utils/formatting" - "github.com/ava-labs/avalanchego/utils/formatting/address" - "github.com/ava-labs/avalanchego/utils/json" - "github.com/ava-labs/avalanchego/utils/units" - "github.com/ava-labs/avalanchego/vms/platformvm/api" - "github.com/ava-labs/avalanchego/vms/platformvm/reward" -) - -const ( - ValidatorWeight2 = 5 * units.MilliAvax - InitialBalance2 = 1 * units.Avax - InitialSupply2 = 360 * units.MegaAvax -) - -var ( - // Keys that are funded in the genesis - FundedKeys = secp256k1.TestKeys() - - // Node IDs of genesis validators - NodeIDs []ids.NodeID -) - -func init() { - NodeIDs = make([]ids.NodeID, len(FundedKeys)) - for i := range FundedKeys { - NodeIDs[i] = ids.GenerateTestNodeID() - } -} - -func Build(t *testing.T) *api.BuildGenesisArgs { - require := require.New(t) - - var ( - utxos = make([]api.UTXO, len(FundedKeys)) - validators = make([]api.GenesisPermissionlessValidator, len(FundedKeys)) - ) - for i, key := range FundedKeys { - addr, err := address.FormatBech32(constants.UnitTestHRP, key.Address().Bytes()) - require.NoError(err) - - utxos[i] = api.UTXO{ - Amount: json.Uint64(InitialBalance2), - Address: addr, - } - - nodeID := NodeIDs[i] - validators[i] = api.GenesisPermissionlessValidator{ - GenesisValidator: api.GenesisValidator{ - StartTime: json.Uint64(TimeUnix), - EndTime: json.Uint64(ValidatorEndTimeUnix), - NodeID: nodeID, - }, - RewardOwner: &api.Owner{ - Threshold: 1, - Addresses: []string{addr}, - }, - Staked: []api.UTXO{{ - Amount: json.Uint64(ValidatorWeight2), - Address: addr, - }}, - DelegationFee: reward.PercentDenominator, - } - } - - return &api.BuildGenesisArgs{ - AvaxAssetID: snowtest.AVAXAssetID, - NetworkID: json.Uint32(constants.UnitTestID), - UTXOs: utxos, - Validators: validators, - Time: json.Uint64(TimeUnix), - InitialSupply: json.Uint64(InitialSupply2), - Encoding: formatting.Hex, - } -} - -func BuildBytes(t *testing.T) []byte { - require := require.New(t) - - buildGenesisArgs := Build(t) - buildGenesisResponse := api.BuildGenesisReply{} - platformvmSS := api.StaticService{} - require.NoError(platformvmSS.BuildGenesis(nil, buildGenesisArgs, &buildGenesisResponse)) - - genesisBytes, err := formatting.Decode(buildGenesisResponse.Encoding, buildGenesisResponse.Bytes) - require.NoError(err) - - return genesisBytes -} diff --git a/vms/platformvm/service_test.go b/vms/platformvm/service_test.go index a66071b974f6..9500ab839e7e 100644 --- a/vms/platformvm/service_test.go +++ b/vms/platformvm/service_test.go @@ -107,7 +107,7 @@ func TestExportKey(t *testing.T) { pk, err := secp256k1.ToPrivateKey(testPrivateKey) require.NoError(err) - require.NoError(user.PutKeys(pk, genesistest.FundedKeys[0])) + require.NoError(user.PutKeys(pk, genesistest.DefaultFundedKeys[0])) service.vm.ctx.Lock.Unlock() @@ -234,7 +234,7 @@ func TestGetTx(t *testing.T) { "chain name", common.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{genesistest.FundedKeys[0].Address()}, + Addrs: []ids.ShortID{genesistest.DefaultFundedKeys[0].Address()}, }), ) require.NoError(t, err) @@ -252,7 +252,7 @@ func TestGetTx(t *testing.T) { Addrs: []ids.ShortID{ids.GenerateTestShortID()}, } - builder, txSigner := factory.NewWallet(genesistest.FundedKeys[0]) + builder, txSigner := factory.NewWallet(genesistest.DefaultFundedKeys[0]) utx, err := builder.NewAddPermissionlessValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -270,7 +270,7 @@ func TestGetTx(t *testing.T) { 0, common.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{genesistest.FundedKeys[0].Address()}, + Addrs: []ids.ShortID{genesistest.DefaultFundedKeys[0].Address()}, }), ) require.NoError(t, err) @@ -280,7 +280,7 @@ func TestGetTx(t *testing.T) { { "atomic block", func(service *Service, factory *txstest.WalletFactory) (*txs.Tx, error) { - builder, signer := factory.NewWallet(genesistest.FundedKeys[0]) + builder, signer := factory.NewWallet(genesistest.DefaultFundedKeys[0]) utx, err := builder.NewExportTx( service.vm.ctx.XChainID, []*avax.TransferableOutput{{ @@ -296,7 +296,7 @@ func TestGetTx(t *testing.T) { }}, common.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{genesistest.FundedKeys[0].Address()}, + Addrs: []ids.ShortID{genesistest.DefaultFundedKeys[0].Address()}, }), ) require.NoError(t, err) @@ -384,21 +384,28 @@ func TestGetBalance(t *testing.T) { require.NoError(err) // Ensure GetStake is correct for each of the genesis validators - genesis := genesistest.Build(t) + genesis := genesistest.New(t, genesistest.Config{}) for idx, utxo := range genesis.UTXOs { + out := utxo.Out.(*secp256k1fx.TransferOutput) + require.Len(out.Addrs, 1) + + addr := out.Addrs[0] + addrStr, err := address.Format("P", constants.UnitTestHRP, addr.Bytes()) + require.NoError(err) + request := GetBalanceRequest{ Addresses: []string{ - "P-" + utxo.Address, + addrStr, }, } reply := GetBalanceResponse{} require.NoError(service.GetBalance(nil, &request, &reply)) - balance := genesistest.InitialBalance2 + balance := genesistest.DefaultInitialBalance if idx == 0 { // we use the first key to fund a subnet creation in [defaultGenesis]. // As such we need to account for the subnet creation fee - balance = genesistest.InitialBalance2 - createSubnetFee + balance = genesistest.DefaultInitialBalance - createSubnetFee } require.Equal(avajson.Uint64(balance), reply.Balance) require.Equal(avajson.Uint64(balance), reply.Unlocked) @@ -412,10 +419,18 @@ func TestGetStake(t *testing.T) { service, _, factory := defaultService(t) // Ensure GetStake is correct for each of the genesis validators - genesis := genesistest.Build(t) + genesis := genesistest.New(t, genesistest.Config{}) addrsStrs := []string{} - for _, validator := range genesis.Validators { - addrStr := "P-" + validator.RewardOwner.Addresses[0] + for _, validatorTx := range genesis.Validators { + validator := validatorTx.Unsigned.(*txs.AddValidatorTx) + require.Len(validator.StakeOuts, 1) + stakeOut := validator.StakeOuts[0].Out.(*secp256k1fx.TransferOutput) + require.Len(stakeOut.Addrs, 1) + addr := stakeOut.Addrs[0] + + addrStr, err := address.Format("P", constants.UnitTestHRP, addr.Bytes()) + require.NoError(err) + addrsStrs = append(addrsStrs, addrStr) args := GetStakeArgs{ @@ -426,7 +441,7 @@ func TestGetStake(t *testing.T) { } response := GetStakeReply{} require.NoError(service.GetStake(nil, &args, &response)) - require.Equal(genesistest.ValidatorWeight2, uint64(response.Staked)) + require.Equal(genesistest.DefaultValidatorWeight, uint64(response.Staked)) require.Len(response.Outputs, 1) // Unmarshal into an output @@ -437,15 +452,13 @@ func TestGetStake(t *testing.T) { _, err = txs.Codec.Unmarshal(outputBytes, &output) require.NoError(err) - addr, err := address.ParseToID(addrStr) - require.NoError(err) require.Equal( avax.TransferableOutput{ Asset: avax.Asset{ ID: service.vm.ctx.AVAXAssetID, }, Out: &secp256k1fx.TransferOutput{ - Amt: genesistest.ValidatorWeight2, + Amt: genesistest.DefaultValidatorWeight, OutputOwners: secp256k1fx.OutputOwners{ Threshold: 1, Addrs: []ids.ShortID{ @@ -467,7 +480,7 @@ func TestGetStake(t *testing.T) { } response := GetStakeReply{} require.NoError(service.GetStake(nil, &args, &response)) - require.Equal(len(genesis.Validators)*int(genesistest.ValidatorWeight2), int(response.Staked)) + require.Equal(len(genesis.Validators)*int(genesistest.DefaultValidatorWeight), int(response.Staked)) require.Len(response.Outputs, len(genesis.Validators)) for _, outputStr := range response.Outputs { @@ -479,25 +492,25 @@ func TestGetStake(t *testing.T) { require.NoError(err) out := output.Out.(*secp256k1fx.TransferOutput) - require.Equal(genesistest.ValidatorWeight2, out.Amt) + require.Equal(genesistest.DefaultValidatorWeight, out.Amt) require.Equal(uint32(1), out.Threshold) require.Zero(out.Locktime) require.Len(out.Addrs, 1) } - oldStake := genesistest.ValidatorWeight2 + oldStake := genesistest.DefaultValidatorWeight service.vm.ctx.Lock.Lock() // Add a delegator stakeAmount := service.vm.MinDelegatorStake + 12345 - delegatorNodeID := genesistest.NodeIDs[0] - delegatorEndTime := genesistest.Time.Add(defaultMinStakingDuration) - builder, signer := factory.NewWallet(genesistest.FundedKeys[0]) + delegatorNodeID := genesistest.DefaultNodeIDs[0] + delegatorEndTime := genesistest.DefaultTime.Add(defaultMinStakingDuration) + builder, signer := factory.NewWallet(genesistest.DefaultFundedKeys[0]) utx, err := builder.NewAddDelegatorTx( &txs.Validator{ NodeID: delegatorNodeID, - Start: genesistest.TimeUnix, + Start: genesistest.DefaultTimeUnix, End: uint64(delegatorEndTime.Unix()), Wght: stakeAmount, }, @@ -507,7 +520,7 @@ func TestGetStake(t *testing.T) { }, common.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{genesistest.FundedKeys[0].Address()}, + Addrs: []ids.ShortID{genesistest.DefaultFundedKeys[0].Address()}, }), ) require.NoError(err) @@ -518,7 +531,7 @@ func TestGetStake(t *testing.T) { staker, err := state.NewCurrentStaker( tx.ID(), addDelTx, - genesistest.Time, + genesistest.DefaultTime, 0, ) require.NoError(err) @@ -530,7 +543,7 @@ func TestGetStake(t *testing.T) { service.vm.ctx.Lock.Unlock() // Make sure the delegator addr has the right stake (old stake + stakeAmount) - addr, _ := service.addrManager.FormatLocalAddress(genesistest.FundedKeys[0].Address()) + addr, _ := service.addrManager.FormatLocalAddress(genesistest.DefaultFundedKeys[0].Address()) args.Addresses = []string{addr} require.NoError(service.GetStake(nil, &args, &response)) require.Equal(oldStake+stakeAmount, uint64(response.Staked)) @@ -556,11 +569,11 @@ func TestGetStake(t *testing.T) { // Add a pending staker stakeAmount = service.vm.MinValidatorStake + 54321 pendingStakerNodeID := ids.GenerateTestNodeID() - pendingStakerEndTime := uint64(genesistest.Time.Add(defaultMinStakingDuration).Unix()) + pendingStakerEndTime := uint64(genesistest.DefaultTime.Add(defaultMinStakingDuration).Unix()) utx2, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: pendingStakerNodeID, - Start: uint64(genesistest.Time.Unix()), + Start: uint64(genesistest.DefaultTime.Unix()), End: pendingStakerEndTime, Wght: stakeAmount, }, @@ -571,7 +584,7 @@ func TestGetStake(t *testing.T) { 0, common.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{genesistest.FundedKeys[0].Address()}, + Addrs: []ids.ShortID{genesistest.DefaultFundedKeys[0].Address()}, }), ) require.NoError(err) @@ -612,7 +625,7 @@ func TestGetCurrentValidators(t *testing.T) { require := require.New(t) service, _, factory := defaultService(t) - genesis := genesistest.Build(t) + genesis := genesistest.New(t, genesistest.Config{}) // Call getValidators args := GetCurrentValidatorsArgs{SubnetID: constants.PrimaryNetworkID} @@ -621,33 +634,37 @@ func TestGetCurrentValidators(t *testing.T) { require.NoError(service.GetCurrentValidators(nil, &args, &response)) require.Len(response.Validators, len(genesis.Validators)) - for _, vdr := range genesis.Validators { + for _, validatorTx := range genesis.Validators { + validator := validatorTx.Unsigned.(*txs.AddValidatorTx) + nodeID := validator.NodeID() + found := false - for i := 0; i < len(response.Validators) && !found; i++ { + for i := 0; i < len(response.Validators); i++ { gotVdr := response.Validators[i].(pchainapi.PermissionlessValidator) - if gotVdr.NodeID != vdr.NodeID { + if gotVdr.NodeID != nodeID { continue } - require.Equal(vdr.EndTime, gotVdr.EndTime) - require.Equal(vdr.StartTime, gotVdr.StartTime) + require.Equal(validator.EndTime().Unix(), int64(gotVdr.EndTime)) + require.Equal(validator.StartTime().Unix(), int64(gotVdr.StartTime)) found = true + break } - require.True(found, "expected validators to contain %s but didn't", vdr.NodeID) + require.True(found, "expected validators to contain %s but didn't", nodeID) } // Add a delegator stakeAmount := service.vm.MinDelegatorStake + 12345 - validatorNodeID := genesistest.NodeIDs[1] - delegatorEndTime := genesistest.Time.Add(defaultMinStakingDuration) + validatorNodeID := genesistest.DefaultNodeIDs[1] + delegatorEndTime := genesistest.DefaultTime.Add(defaultMinStakingDuration) service.vm.ctx.Lock.Lock() - builder, signer := factory.NewWallet(genesistest.FundedKeys[0]) + builder, signer := factory.NewWallet(genesistest.DefaultFundedKeys[0]) utx, err := builder.NewAddDelegatorTx( &txs.Validator{ NodeID: validatorNodeID, - Start: genesistest.TimeUnix, + Start: genesistest.DefaultTimeUnix, End: uint64(delegatorEndTime.Unix()), Wght: stakeAmount, }, @@ -657,7 +674,7 @@ func TestGetCurrentValidators(t *testing.T) { }, common.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{genesistest.FundedKeys[0].Address()}, + Addrs: []ids.ShortID{genesistest.DefaultFundedKeys[0].Address()}, }), ) require.NoError(err) @@ -668,7 +685,7 @@ func TestGetCurrentValidators(t *testing.T) { staker, err := state.NewCurrentStaker( delTx.ID(), addDelTx, - genesistest.Time, + genesistest.DefaultTime, 0, ) require.NoError(err) @@ -710,7 +727,7 @@ func TestGetCurrentValidators(t *testing.T) { require.Len(*innerVdr.Delegators, 1) delegator := (*innerVdr.Delegators)[0] require.Equal(delegator.NodeID, innerVdr.NodeID) - require.Equal(uint64(delegator.StartTime), genesistest.TimeUnix) + require.Equal(uint64(delegator.StartTime), genesistest.DefaultTimeUnix) require.Equal(int64(delegator.EndTime), delegatorEndTime.Unix()) require.Equal(uint64(delegator.Weight), stakeAmount) } @@ -794,7 +811,7 @@ func TestGetBlock(t *testing.T) { "chain name", common.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{genesistest.FundedKeys[0].Address()}, + Addrs: []ids.ShortID{genesistest.DefaultFundedKeys[0].Address()}, }), ) require.NoError(err) diff --git a/vms/platformvm/state/stakers_test.go b/vms/platformvm/state/stakers_test.go index d01593c0548e..8753fe6fd915 100644 --- a/vms/platformvm/state/stakers_test.go +++ b/vms/platformvm/state/stakers_test.go @@ -220,7 +220,7 @@ func TestDiffStakersDelegator(t *testing.T) { func newTestStaker() *Staker { startTime := time.Now().Round(time.Second) - endTime := startTime.Add(genesistest.ValidatorDuration) + endTime := startTime.Add(genesistest.DefaultValidatorDuration) return &Staker{ TxID: ids.GenerateTestID(), NodeID: ids.GenerateTestNodeID(), diff --git a/vms/platformvm/state/state_test.go b/vms/platformvm/state/state_test.go index 982fbf56d47d..5107eafacfad 100644 --- a/vms/platformvm/state/state_test.go +++ b/vms/platformvm/state/state_test.go @@ -46,10 +46,14 @@ import ( safemath "github.com/ava-labs/avalanchego/utils/math" ) +var defaultValidatorNodeID = ids.GenerateTestNodeID() + func newTestState(t testing.TB, db database.Database) *state { s, err := New( db, - genesistest.NewBytes(t), + genesistest.NewBytes(t, genesistest.Config{ + NodeIDs: []ids.NodeID{defaultValidatorNodeID}, + }), prometheus.NewRegistry(), validators.NewManager(), upgradetest.GetConfig(upgradetest.Latest), @@ -76,12 +80,12 @@ func TestStateSyncGenesis(t *testing.T) { require := require.New(t) state := newTestState(t, memdb.New()) - staker, err := state.GetCurrentValidator(constants.PrimaryNetworkID, genesistest.ValidatorNodeID) + staker, err := state.GetCurrentValidator(constants.PrimaryNetworkID, defaultValidatorNodeID) require.NoError(err) require.NotNil(staker) - require.Equal(genesistest.ValidatorNodeID, staker.NodeID) + require.Equal(defaultValidatorNodeID, staker.NodeID) - delegatorIterator, err := state.GetCurrentDelegatorIterator(constants.PrimaryNetworkID, genesistest.ValidatorNodeID) + delegatorIterator, err := state.GetCurrentDelegatorIterator(constants.PrimaryNetworkID, defaultValidatorNodeID) require.NoError(err) assertIteratorsEqual(t, EmptyIterator, delegatorIterator) @@ -89,10 +93,10 @@ func TestStateSyncGenesis(t *testing.T) { require.NoError(err) assertIteratorsEqual(t, NewSliceIterator(staker), stakerIterator) - _, err = state.GetPendingValidator(constants.PrimaryNetworkID, genesistest.ValidatorNodeID) + _, err = state.GetPendingValidator(constants.PrimaryNetworkID, defaultValidatorNodeID) require.ErrorIs(err, database.ErrNotFound) - delegatorIterator, err = state.GetPendingDelegatorIterator(constants.PrimaryNetworkID, genesistest.ValidatorNodeID) + delegatorIterator, err = state.GetPendingDelegatorIterator(constants.PrimaryNetworkID, defaultValidatorNodeID) require.NoError(err) assertIteratorsEqual(t, EmptyIterator, delegatorIterator) } diff --git a/vms/platformvm/state/statetest/state.go b/vms/platformvm/state/statetest/state.go index fbc71381ec51..66998ea3cf10 100644 --- a/vms/platformvm/state/statetest/state.go +++ b/vms/platformvm/state/statetest/state.go @@ -27,6 +27,8 @@ import ( "github.com/ava-labs/avalanchego/vms/platformvm/state" ) +var DefaultNodeID = ids.GenerateTestNodeID() + type Config struct { DB database.Database Genesis []byte @@ -44,11 +46,14 @@ func New(t testing.TB, c Config) state.State { c.DB = memdb.New() } if len(c.Genesis) == 0 { - c.Genesis = genesistest.NewBytes(t) + c.Genesis = genesistest.NewBytes(t, genesistest.Config{}) } if c.Registerer == nil { c.Registerer = prometheus.NewRegistry() } + if c.Validators == nil { + c.Validators = validators.NewManager() + } if c.Upgrades == (upgrade.Config{}) { c.Upgrades = upgradetest.GetConfig(upgradetest.Latest) } @@ -58,7 +63,7 @@ func New(t testing.TB, c Config) state.State { if c.Context == nil { c.Context = &snow.Context{ NetworkID: constants.UnitTestID, - NodeID: ids.GenerateTestNodeID(), + NodeID: DefaultNodeID, Log: logging.NoLog{}, } } diff --git a/vms/platformvm/txs/executor/advance_time_test.go b/vms/platformvm/txs/executor/advance_time_test.go index 517a2c90f16c..5f25a074a3e9 100644 --- a/vms/platformvm/txs/executor/advance_time_test.go +++ b/vms/platformvm/txs/executor/advance_time_test.go @@ -47,7 +47,7 @@ func TestAdvanceTimeTxUpdatePrimaryNetworkStakers(t *testing.T) { // Case: Timestamp is after next validator start time // Add a pending validator - pendingValidatorStartTime := genesistest.Time.Add(1 * time.Second) + pendingValidatorStartTime := genesistest.DefaultTime.Add(1 * time.Second) pendingValidatorEndTime := pendingValidatorStartTime.Add(defaultMinStakingDuration) nodeID := ids.GenerateTestNodeID() addPendingValidatorTx, err := addPendingValidator( @@ -55,7 +55,7 @@ func TestAdvanceTimeTxUpdatePrimaryNetworkStakers(t *testing.T) { pendingValidatorStartTime, pendingValidatorEndTime, nodeID, - []*secp256k1.PrivateKey{genesistest.FundedKeys[0]}, + []*secp256k1.PrivateKey{genesistest.DefaultFundedKeys[0]}, ) require.NoError(err) @@ -137,10 +137,10 @@ func TestAdvanceTimeTxTimestampTooLate(t *testing.T) { // Case: Timestamp is after next validator start time // Add a pending validator - pendingValidatorStartTime := genesistest.Time.Add(1 * time.Second) + pendingValidatorStartTime := genesistest.DefaultTime.Add(1 * time.Second) pendingValidatorEndTime := pendingValidatorStartTime.Add(defaultMinStakingDuration) nodeID := ids.GenerateTestNodeID() - _, err := addPendingValidator(env, pendingValidatorStartTime, pendingValidatorEndTime, nodeID, []*secp256k1.PrivateKey{genesistest.FundedKeys[0]}) + _, err := addPendingValidator(env, pendingValidatorStartTime, pendingValidatorEndTime, nodeID, []*secp256k1.PrivateKey{genesistest.DefaultFundedKeys[0]}) require.NoError(err) { @@ -171,11 +171,11 @@ func TestAdvanceTimeTxTimestampTooLate(t *testing.T) { defer env.ctx.Lock.Unlock() // fast forward clock to 10 seconds before genesis validators stop validating - env.clk.Set(genesistest.ValidatorEndTime.Add(-10 * time.Second)) + env.clk.Set(genesistest.DefaultValidatorEndTime.Add(-10 * time.Second)) { // Proposes advancing timestamp to 1 second after genesis validators stop validating - tx, err := newAdvanceTimeTx(t, genesistest.ValidatorEndTime.Add(1*time.Second)) + tx, err := newAdvanceTimeTx(t, genesistest.DefaultValidatorEndTime.Add(1*time.Second)) require.NoError(err) onCommitState, err := state.NewDiff(lastAcceptedID, env) @@ -229,8 +229,8 @@ func TestAdvanceTimeTxUpdateStakers(t *testing.T) { // Staker5: |--------------------| staker1 := staker{ nodeID: ids.GenerateTestNodeID(), - startTime: genesistest.Time.Add(1 * time.Minute), - endTime: genesistest.Time.Add(10 * defaultMinStakingDuration).Add(1 * time.Minute), + startTime: genesistest.DefaultTime.Add(1 * time.Minute), + endTime: genesistest.DefaultTime.Add(10 * defaultMinStakingDuration).Add(1 * time.Minute), } staker2 := staker{ nodeID: ids.GenerateTestNodeID(), @@ -383,13 +383,13 @@ func TestAdvanceTimeTxUpdateStakers(t *testing.T) { staker.startTime, staker.endTime, staker.nodeID, - []*secp256k1.PrivateKey{genesistest.FundedKeys[0]}, + []*secp256k1.PrivateKey{genesistest.DefaultFundedKeys[0]}, ) require.NoError(err) } for _, staker := range test.subnetStakers { - builder, signer := env.factory.NewWallet(genesistest.FundedKeys[0], genesistest.FundedKeys[1]) + builder, signer := env.factory.NewWallet(genesistest.DefaultFundedKeys[0], genesistest.DefaultFundedKeys[1]) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -487,15 +487,15 @@ func TestAdvanceTimeTxRemoveSubnetValidator(t *testing.T) { dummyHeight := uint64(1) // Add a subnet validator to the staker set - subnetValidatorNodeID := genesistest.NodeIDs[0] - subnetVdr1EndTime := genesistest.Time.Add(defaultMinStakingDuration) + subnetValidatorNodeID := genesistest.DefaultNodeIDs[0] + subnetVdr1EndTime := genesistest.DefaultTime.Add(defaultMinStakingDuration) - builder, signer := env.factory.NewWallet(genesistest.FundedKeys[0], genesistest.FundedKeys[1]) + builder, signer := env.factory.NewWallet(genesistest.DefaultFundedKeys[0], genesistest.DefaultFundedKeys[1]) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: subnetValidatorNodeID, - Start: genesistest.TimeUnix, + Start: genesistest.DefaultTimeUnix, End: uint64(subnetVdr1EndTime.Unix()), Wght: 1, }, @@ -523,7 +523,7 @@ func TestAdvanceTimeTxRemoveSubnetValidator(t *testing.T) { // The above validator is now part of the staking set // Queue a staker that joins the staker set after the above validator leaves - subnetVdr2NodeID := genesistest.NodeIDs[1] + subnetVdr2NodeID := genesistest.DefaultNodeIDs[1] utx, err = builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -602,11 +602,11 @@ func TestTrackedSubnet(t *testing.T) { } // Add a subnet validator to the staker set - subnetValidatorNodeID := genesistest.NodeIDs[0] + subnetValidatorNodeID := genesistest.DefaultNodeIDs[0] - subnetVdr1StartTime := genesistest.Time.Add(1 * time.Minute) - subnetVdr1EndTime := genesistest.Time.Add(10 * defaultMinStakingDuration).Add(1 * time.Minute) - builder, signer := env.factory.NewWallet(genesistest.FundedKeys[0], genesistest.FundedKeys[1]) + subnetVdr1StartTime := genesistest.DefaultTime.Add(1 * time.Minute) + subnetVdr1EndTime := genesistest.DefaultTime.Add(10 * defaultMinStakingDuration).Add(1 * time.Minute) + builder, signer := env.factory.NewWallet(genesistest.DefaultFundedKeys[0], genesistest.DefaultFundedKeys[1]) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -673,7 +673,7 @@ func TestAdvanceTimeTxDelegatorStakerWeight(t *testing.T) { // Case: Timestamp is after next validator start time // Add a pending validator - pendingValidatorStartTime := genesistest.Time.Add(1 * time.Second) + pendingValidatorStartTime := genesistest.DefaultTime.Add(1 * time.Second) pendingValidatorEndTime := pendingValidatorStartTime.Add(defaultMaxStakingDuration) nodeID := ids.GenerateTestNodeID() _, err := addPendingValidator( @@ -681,7 +681,7 @@ func TestAdvanceTimeTxDelegatorStakerWeight(t *testing.T) { pendingValidatorStartTime, pendingValidatorEndTime, nodeID, - []*secp256k1.PrivateKey{genesistest.FundedKeys[0]}, + []*secp256k1.PrivateKey{genesistest.DefaultFundedKeys[0]}, ) require.NoError(err) @@ -717,7 +717,7 @@ func TestAdvanceTimeTxDelegatorStakerWeight(t *testing.T) { pendingDelegatorStartTime := pendingValidatorStartTime.Add(1 * time.Second) pendingDelegatorEndTime := pendingDelegatorStartTime.Add(1 * time.Second) - builder, signer := env.factory.NewWallet(genesistest.FundedKeys[0], genesistest.FundedKeys[1], genesistest.FundedKeys[4]) + builder, signer := env.factory.NewWallet(genesistest.DefaultFundedKeys[0], genesistest.DefaultFundedKeys[1], genesistest.DefaultFundedKeys[4]) utx, err := builder.NewAddDelegatorTx( &txs.Validator{ NodeID: nodeID, @@ -727,7 +727,7 @@ func TestAdvanceTimeTxDelegatorStakerWeight(t *testing.T) { }, &secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{genesistest.FundedKeys[0].Address()}, + Addrs: []ids.ShortID{genesistest.DefaultFundedKeys[0].Address()}, }, ) require.NoError(err) @@ -783,10 +783,10 @@ func TestAdvanceTimeTxDelegatorStakers(t *testing.T) { // Case: Timestamp is after next validator start time // Add a pending validator - pendingValidatorStartTime := genesistest.Time.Add(1 * time.Second) + pendingValidatorStartTime := genesistest.DefaultTime.Add(1 * time.Second) pendingValidatorEndTime := pendingValidatorStartTime.Add(defaultMinStakingDuration) nodeID := ids.GenerateTestNodeID() - _, err := addPendingValidator(env, pendingValidatorStartTime, pendingValidatorEndTime, nodeID, []*secp256k1.PrivateKey{genesistest.FundedKeys[0]}) + _, err := addPendingValidator(env, pendingValidatorStartTime, pendingValidatorEndTime, nodeID, []*secp256k1.PrivateKey{genesistest.DefaultFundedKeys[0]}) require.NoError(err) tx, err := newAdvanceTimeTx(t, pendingValidatorStartTime) @@ -820,7 +820,7 @@ func TestAdvanceTimeTxDelegatorStakers(t *testing.T) { // Add delegator pendingDelegatorStartTime := pendingValidatorStartTime.Add(1 * time.Second) pendingDelegatorEndTime := pendingDelegatorStartTime.Add(defaultMinStakingDuration) - builder, signer := env.factory.NewWallet(genesistest.FundedKeys[0], genesistest.FundedKeys[1], genesistest.FundedKeys[4]) + builder, signer := env.factory.NewWallet(genesistest.DefaultFundedKeys[0], genesistest.DefaultFundedKeys[1], genesistest.DefaultFundedKeys[4]) utx, err := builder.NewAddDelegatorTx( &txs.Validator{ NodeID: nodeID, @@ -830,7 +830,7 @@ func TestAdvanceTimeTxDelegatorStakers(t *testing.T) { }, &secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{genesistest.FundedKeys[0].Address()}, + Addrs: []ids.ShortID{genesistest.DefaultFundedKeys[0].Address()}, }, ) require.NoError(err) @@ -882,7 +882,7 @@ func TestAdvanceTimeTxAfterBanff(t *testing.T) { env := newEnvironment(t, upgradetest.Durango) env.ctx.Lock.Lock() defer env.ctx.Lock.Unlock() - env.clk.Set(genesistest.Time) // VM's clock reads the genesis time + env.clk.Set(genesistest.DefaultTime) // VM's clock reads the genesis time upgradeTime := env.clk.Time().Add(SyncBound) env.config.UpgradeConfig.BanffTime = upgradeTime env.config.UpgradeConfig.CortinaTime = upgradeTime diff --git a/vms/platformvm/txs/executor/create_chain_test.go b/vms/platformvm/txs/executor/create_chain_test.go index b31237bed5d5..80bf9d669665 100644 --- a/vms/platformvm/txs/executor/create_chain_test.go +++ b/vms/platformvm/txs/executor/create_chain_test.go @@ -35,7 +35,7 @@ func TestCreateChainTxInsufficientControlSigs(t *testing.T) { env.ctx.Lock.Lock() defer env.ctx.Lock.Unlock() - builder, signer := env.factory.NewWallet(genesistest.FundedKeys[0], genesistest.FundedKeys[1]) + builder, signer := env.factory.NewWallet(genesistest.DefaultFundedKeys[0], genesistest.DefaultFundedKeys[1]) utx, err := builder.NewCreateChainTx( testSubnet1.ID(), nil, @@ -181,7 +181,7 @@ func TestCreateChainTxValid(t *testing.T) { } func TestCreateChainTxAP3FeeChange(t *testing.T) { - ap3Time := genesistest.Time.Add(time.Hour) + ap3Time := genesistest.DefaultTime.Add(time.Hour) tests := []struct { name string time time.Time @@ -190,7 +190,7 @@ func TestCreateChainTxAP3FeeChange(t *testing.T) { }{ { name: "pre-fork - correctly priced", - time: genesistest.Time, + time: genesistest.DefaultTime, fee: 0, expectedError: nil, }, @@ -214,8 +214,8 @@ func TestCreateChainTxAP3FeeChange(t *testing.T) { env := newEnvironment(t, upgradetest.Banff) env.config.UpgradeConfig.ApricotPhase3Time = ap3Time - addrs := set.NewSet[ids.ShortID](len(genesistest.FundedKeys)) - for _, key := range genesistest.FundedKeys { + addrs := set.NewSet[ids.ShortID](len(genesistest.DefaultFundedKeys)) + for _, key := range genesistest.DefaultFundedKeys { addrs.Add(key.Address()) } @@ -225,7 +225,7 @@ func TestCreateChainTxAP3FeeChange(t *testing.T) { cfg.StaticFeeConfig.CreateBlockchainTxFee = test.fee factory := txstest.NewWalletFactory(env.ctx, &cfg, env.state) - builder, signer := factory.NewWallet(genesistest.FundedKeys...) + builder, signer := factory.NewWallet(genesistest.DefaultFundedKeys...) utx, err := builder.NewCreateChainTx( testSubnet1.ID(), nil, diff --git a/vms/platformvm/txs/executor/create_subnet_test.go b/vms/platformvm/txs/executor/create_subnet_test.go index b294527bef78..6a2bc9e586f6 100644 --- a/vms/platformvm/txs/executor/create_subnet_test.go +++ b/vms/platformvm/txs/executor/create_subnet_test.go @@ -24,7 +24,7 @@ import ( ) func TestCreateSubnetTxAP3FeeChange(t *testing.T) { - ap3Time := genesistest.Time.Add(time.Hour) + ap3Time := genesistest.DefaultTime.Add(time.Hour) tests := []struct { name string time time.Time @@ -33,7 +33,7 @@ func TestCreateSubnetTxAP3FeeChange(t *testing.T) { }{ { name: "pre-fork - correctly priced", - time: genesistest.Time, + time: genesistest.DefaultTime, fee: 0, expectedErr: nil, }, @@ -61,15 +61,15 @@ func TestCreateSubnetTxAP3FeeChange(t *testing.T) { env.state.SetTimestamp(test.time) // to duly set fee - addrs := set.NewSet[ids.ShortID](len(genesistest.FundedKeys)) - for _, key := range genesistest.FundedKeys { + addrs := set.NewSet[ids.ShortID](len(genesistest.DefaultFundedKeys)) + for _, key := range genesistest.DefaultFundedKeys { addrs.Add(key.Address()) } cfg := *env.config cfg.StaticFeeConfig.CreateSubnetTxFee = test.fee factory := txstest.NewWalletFactory(env.ctx, &cfg, env.state) - builder, signer := factory.NewWallet(genesistest.FundedKeys...) + builder, signer := factory.NewWallet(genesistest.DefaultFundedKeys...) utx, err := builder.NewCreateSubnetTx( &secp256k1fx.OutputOwners{}, ) diff --git a/vms/platformvm/txs/executor/export_test.go b/vms/platformvm/txs/executor/export_test.go index 4dba9f92dd29..3fd2124aed40 100644 --- a/vms/platformvm/txs/executor/export_test.go +++ b/vms/platformvm/txs/executor/export_test.go @@ -33,14 +33,14 @@ func TestNewExportTx(t *testing.T) { timestamp time.Time } - sourceKey := genesistest.FundedKeys[0] + sourceKey := genesistest.DefaultFundedKeys[0] tests := []test{ { description: "P->X export", destinationChainID: env.ctx.XChainID, sourceKeys: []*secp256k1.PrivateKey{sourceKey}, - timestamp: genesistest.Time, + timestamp: genesistest.DefaultTime, }, { description: "P->C export", @@ -61,7 +61,7 @@ func TestNewExportTx(t *testing.T) { []*avax.TransferableOutput{{ Asset: avax.Asset{ID: env.ctx.AVAXAssetID}, Out: &secp256k1fx.TransferOutput{ - Amt: genesistest.InitialBalance2 - defaultTxFee, + Amt: genesistest.DefaultInitialBalance - defaultTxFee, OutputOwners: secp256k1fx.OutputOwners{ Locktime: 0, Threshold: 1, diff --git a/vms/platformvm/txs/executor/helpers_test.go b/vms/platformvm/txs/executor/helpers_test.go index 529e6ea5e60b..6085a6c180a1 100644 --- a/vms/platformvm/txs/executor/helpers_test.go +++ b/vms/platformvm/txs/executor/helpers_test.go @@ -58,7 +58,7 @@ var ( lastAcceptedID = ids.GenerateTestID() testSubnet1 *txs.Tx - testSubnet1ControlKeys = genesistest.FundedKeys[0:3] + testSubnet1ControlKeys = genesistest.DefaultFundedKeys[0:3] ) type mutableSharedMemory struct { @@ -113,7 +113,7 @@ func newEnvironment(t *testing.T, f upgradetest.Fork) *environment { rewards := reward.NewCalculator(config.RewardConfig) baseState := statetest.New(t, statetest.Config{ DB: baseDB, - Genesis: genesistest.BuildBytes(t), + Genesis: genesistest.NewBytes(t, genesistest.Config{}), Validators: config.Validators, Upgrades: config.UpgradeConfig, Context: ctx, @@ -185,19 +185,19 @@ func newEnvironment(t *testing.T, f upgradetest.Fork) *environment { func addSubnet(t *testing.T, env *environment) { require := require.New(t) - builder, signer := env.factory.NewWallet(genesistest.FundedKeys[0]) + builder, signer := env.factory.NewWallet(genesistest.DefaultFundedKeys[0]) utx, err := builder.NewCreateSubnetTx( &secp256k1fx.OutputOwners{ Threshold: 2, Addrs: []ids.ShortID{ - genesistest.FundedKeys[0].Address(), - genesistest.FundedKeys[1].Address(), - genesistest.FundedKeys[2].Address(), + genesistest.DefaultFundedKeys[0].Address(), + genesistest.DefaultFundedKeys[1].Address(), + genesistest.DefaultFundedKeys[2].Address(), }, }, common.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{genesistest.FundedKeys[0].Address()}, + Addrs: []ids.ShortID{genesistest.DefaultFundedKeys[0].Address()}, }), ) require.NoError(err) @@ -224,12 +224,12 @@ func addSubnet(t *testing.T, env *environment) { func defaultConfig(f upgradetest.Fork) *config.Config { upgrades := upgradetest.GetConfigWithUpgradeTime( f, - genesistest.Time.Add(-2*time.Second), + genesistest.DefaultTime.Add(-2*time.Second), ) upgradetest.SetTimesTo( &upgrades, min(f, upgradetest.ApricotPhase5), - genesistest.ValidatorEndTime, + genesistest.DefaultValidatorEndTime, ) return &config.Config{ @@ -257,10 +257,10 @@ func defaultConfig(f upgradetest.Fork) *config.Config { } func defaultClock(f upgradetest.Fork) *mockable.Clock { - now := genesistest.Time + now := genesistest.DefaultTime if f >= upgradetest.Banff { // 1 second after active fork - now = genesistest.ValidatorEndTime.Add(-2 * time.Second) + now = genesistest.DefaultValidatorEndTime.Add(-2 * time.Second) } clk := &mockable.Clock{} clk.Set(now) diff --git a/vms/platformvm/txs/executor/proposal_tx_executor_test.go b/vms/platformvm/txs/executor/proposal_tx_executor_test.go index 183ac6e3603e..aeea06426b78 100644 --- a/vms/platformvm/txs/executor/proposal_tx_executor_test.go +++ b/vms/platformvm/txs/executor/proposal_tx_executor_test.go @@ -28,19 +28,19 @@ import ( func TestProposalTxExecuteAddDelegator(t *testing.T) { dummyHeight := uint64(1) - rewardAddress := genesistest.FundedKeys[0].Address() - nodeID := genesistest.NodeIDs[0] + rewardAddress := genesistest.DefaultFundedKeys[0].Address() + nodeID := genesistest.DefaultNodeIDs[0] newValidatorID := ids.GenerateTestNodeID() - newValidatorStartTime := uint64(genesistest.Time.Add(5 * time.Second).Unix()) - newValidatorEndTime := uint64(genesistest.ValidatorEndTime.Add(-5 * time.Second).Unix()) + newValidatorStartTime := uint64(genesistest.DefaultTime.Add(5 * time.Second).Unix()) + newValidatorEndTime := uint64(genesistest.DefaultValidatorEndTime.Add(-5 * time.Second).Unix()) // [addMinStakeValidator] adds a new validator to the primary network's // pending validator set with the minimum staking amount addMinStakeValidator := func(env *environment) { require := require.New(t) - builder, signer := env.factory.NewWallet(genesistest.FundedKeys[0]) + builder, signer := env.factory.NewWallet(genesistest.DefaultFundedKeys[0]) utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: newValidatorID, @@ -78,7 +78,7 @@ func TestProposalTxExecuteAddDelegator(t *testing.T) { addMaxStakeValidator := func(env *environment) { require := require.New(t) - builder, signer := env.factory.NewWallet(genesistest.FundedKeys[0]) + builder, signer := env.factory.NewWallet(genesistest.DefaultFundedKeys[0]) utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: newValidatorID, @@ -130,23 +130,23 @@ func TestProposalTxExecuteAddDelegator(t *testing.T) { { description: "validator stops validating earlier than delegator", stakeAmount: env.config.MinDelegatorStake, - startTime: genesistest.TimeUnix + 1, - endTime: genesistest.ValidatorEndTimeUnix + 1, + startTime: genesistest.DefaultTimeUnix + 1, + endTime: genesistest.DefaultValidatorEndTimeUnix + 1, nodeID: nodeID, - feeKeys: []*secp256k1.PrivateKey{genesistest.FundedKeys[0]}, + feeKeys: []*secp256k1.PrivateKey{genesistest.DefaultFundedKeys[0]}, setup: nil, - AP3Time: genesistest.Time, + AP3Time: genesistest.DefaultTime, expectedErr: ErrPeriodMismatch, }, { description: "validator not in the current or pending validator sets", stakeAmount: env.config.MinDelegatorStake, - startTime: uint64(genesistest.Time.Add(5 * time.Second).Unix()), - endTime: uint64(genesistest.ValidatorEndTime.Add(-5 * time.Second).Unix()), + startTime: uint64(genesistest.DefaultTime.Add(5 * time.Second).Unix()), + endTime: uint64(genesistest.DefaultValidatorEndTime.Add(-5 * time.Second).Unix()), nodeID: newValidatorID, - feeKeys: []*secp256k1.PrivateKey{genesistest.FundedKeys[0]}, + feeKeys: []*secp256k1.PrivateKey{genesistest.DefaultFundedKeys[0]}, setup: nil, - AP3Time: genesistest.Time, + AP3Time: genesistest.DefaultTime, expectedErr: database.ErrNotFound, }, { @@ -155,9 +155,9 @@ func TestProposalTxExecuteAddDelegator(t *testing.T) { startTime: newValidatorStartTime - 1, // start validating subnet before primary network endTime: newValidatorEndTime, nodeID: newValidatorID, - feeKeys: []*secp256k1.PrivateKey{genesistest.FundedKeys[0]}, + feeKeys: []*secp256k1.PrivateKey{genesistest.DefaultFundedKeys[0]}, setup: addMinStakeValidator, - AP3Time: genesistest.Time, + AP3Time: genesistest.DefaultTime, expectedErr: ErrPeriodMismatch, }, { @@ -166,9 +166,9 @@ func TestProposalTxExecuteAddDelegator(t *testing.T) { startTime: newValidatorStartTime, endTime: newValidatorEndTime + 1, // stop validating subnet after stopping validating primary network nodeID: newValidatorID, - feeKeys: []*secp256k1.PrivateKey{genesistest.FundedKeys[0]}, + feeKeys: []*secp256k1.PrivateKey{genesistest.DefaultFundedKeys[0]}, setup: addMinStakeValidator, - AP3Time: genesistest.Time, + AP3Time: genesistest.DefaultTime, expectedErr: ErrPeriodMismatch, }, { @@ -177,32 +177,32 @@ func TestProposalTxExecuteAddDelegator(t *testing.T) { startTime: newValidatorStartTime, // same start time as for primary network endTime: newValidatorEndTime, // same end time as for primary network nodeID: newValidatorID, - feeKeys: []*secp256k1.PrivateKey{genesistest.FundedKeys[0]}, + feeKeys: []*secp256k1.PrivateKey{genesistest.DefaultFundedKeys[0]}, setup: addMinStakeValidator, - AP3Time: genesistest.Time, + AP3Time: genesistest.DefaultTime, expectedErr: nil, }, { description: "starts delegating at current timestamp", stakeAmount: env.config.MinDelegatorStake, startTime: uint64(currentTimestamp.Unix()), - endTime: genesistest.ValidatorEndTimeUnix, + endTime: genesistest.DefaultValidatorEndTimeUnix, nodeID: nodeID, - feeKeys: []*secp256k1.PrivateKey{genesistest.FundedKeys[0]}, + feeKeys: []*secp256k1.PrivateKey{genesistest.DefaultFundedKeys[0]}, setup: nil, - AP3Time: genesistest.Time, + AP3Time: genesistest.DefaultTime, expectedErr: ErrTimestampNotBeforeStartTime, }, { description: "tx fee paying key has no funds", stakeAmount: env.config.MinDelegatorStake, - startTime: genesistest.TimeUnix + 1, - endTime: genesistest.ValidatorEndTimeUnix, + startTime: genesistest.DefaultTimeUnix + 1, + endTime: genesistest.DefaultValidatorEndTimeUnix, nodeID: nodeID, - feeKeys: []*secp256k1.PrivateKey{genesistest.FundedKeys[1]}, + feeKeys: []*secp256k1.PrivateKey{genesistest.DefaultFundedKeys[1]}, setup: func(env *environment) { // Remove all UTXOs owned by keys[1] utxoIDs, err := env.state.UTXOIDs( - genesistest.FundedKeys[1].Address().Bytes(), + genesistest.DefaultFundedKeys[1].Address().Bytes(), ids.Empty, math.MaxInt32) require.NoError(t, err) @@ -213,7 +213,7 @@ func TestProposalTxExecuteAddDelegator(t *testing.T) { env.state.SetHeight(dummyHeight) require.NoError(t, env.state.Commit()) }, - AP3Time: genesistest.Time, + AP3Time: genesistest.DefaultTime, expectedErr: ErrFlowCheckFailed, }, { @@ -222,9 +222,9 @@ func TestProposalTxExecuteAddDelegator(t *testing.T) { startTime: newValidatorStartTime, // same start time as for primary network endTime: newValidatorEndTime, // same end time as for primary network nodeID: newValidatorID, - feeKeys: []*secp256k1.PrivateKey{genesistest.FundedKeys[0]}, + feeKeys: []*secp256k1.PrivateKey{genesistest.DefaultFundedKeys[0]}, setup: addMaxStakeValidator, - AP3Time: genesistest.ValidatorEndTime, + AP3Time: genesistest.DefaultValidatorEndTime, expectedErr: nil, }, { @@ -233,9 +233,9 @@ func TestProposalTxExecuteAddDelegator(t *testing.T) { startTime: newValidatorStartTime, // same start time as for primary network endTime: newValidatorEndTime, // same end time as for primary network nodeID: newValidatorID, - feeKeys: []*secp256k1.PrivateKey{genesistest.FundedKeys[0]}, + feeKeys: []*secp256k1.PrivateKey{genesistest.DefaultFundedKeys[0]}, setup: addMaxStakeValidator, - AP3Time: genesistest.Time, + AP3Time: genesistest.DefaultTime, expectedErr: ErrOverDelegated, }, } @@ -293,7 +293,7 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { env.ctx.Lock.Lock() defer env.ctx.Lock.Unlock() - nodeID := genesistest.NodeIDs[0] + nodeID := genesistest.DefaultNodeIDs[0] { // Case: Proposed validator currently validating primary network // but stops validating subnet after stops validating primary network @@ -303,9 +303,9 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: nodeID, - Start: genesistest.TimeUnix + 1, - End: genesistest.ValidatorEndTimeUnix + 1, - Wght: genesistest.ValidatorWeight2, + Start: genesistest.DefaultTimeUnix + 1, + End: genesistest.DefaultValidatorEndTimeUnix + 1, + Wght: genesistest.DefaultValidatorWeight, }, Subnet: testSubnet1.ID(), }, @@ -342,9 +342,9 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: nodeID, - Start: genesistest.TimeUnix + 1, - End: genesistest.ValidatorEndTimeUnix, - Wght: genesistest.ValidatorWeight2, + Start: genesistest.DefaultTimeUnix + 1, + End: genesistest.DefaultValidatorEndTimeUnix, + Wght: genesistest.DefaultValidatorWeight, }, Subnet: testSubnet1.ID(), }, @@ -373,10 +373,10 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { // Add a validator to pending validator set of primary network // Starts validating primary network 10 seconds after genesis pendingDSValidatorID := ids.GenerateTestNodeID() - dsStartTime := genesistest.Time.Add(10 * time.Second) + dsStartTime := genesistest.DefaultTime.Add(10 * time.Second) dsEndTime := dsStartTime.Add(5 * defaultMinStakingDuration) - builder, signer := env.factory.NewWallet(genesistest.FundedKeys[0]) + builder, signer := env.factory.NewWallet(genesistest.DefaultFundedKeys[0]) utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: pendingDSValidatorID, @@ -403,7 +403,7 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { NodeID: pendingDSValidatorID, Start: uint64(dsStartTime.Unix()), // start validating subnet before primary network End: uint64(dsEndTime.Unix()), - Wght: genesistest.ValidatorWeight2, + Wght: genesistest.DefaultValidatorWeight, }, Subnet: testSubnet1.ID(), }, @@ -457,7 +457,7 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { NodeID: pendingDSValidatorID, Start: uint64(dsStartTime.Unix()) - 1, // start validating subnet before primary network End: uint64(dsEndTime.Unix()), - Wght: genesistest.ValidatorWeight2, + Wght: genesistest.DefaultValidatorWeight, }, Subnet: testSubnet1.ID(), }, @@ -494,7 +494,7 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { NodeID: pendingDSValidatorID, Start: uint64(dsStartTime.Unix()), End: uint64(dsEndTime.Unix()) + 1, // stop validating subnet after stopping validating primary network - Wght: genesistest.ValidatorWeight2, + Wght: genesistest.DefaultValidatorWeight, }, Subnet: testSubnet1.ID(), }, @@ -531,7 +531,7 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { NodeID: pendingDSValidatorID, Start: uint64(dsStartTime.Unix()), // same start time as for primary network End: uint64(dsEndTime.Unix()), // same end time as for primary network - Wght: genesistest.ValidatorWeight2, + Wght: genesistest.DefaultValidatorWeight, }, Subnet: testSubnet1.ID(), }, @@ -559,7 +559,7 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { // Case: Proposed validator start validating at/before current timestamp // First, advance the timestamp - newTimestamp := genesistest.Time.Add(2 * time.Second) + newTimestamp := genesistest.DefaultTime.Add(2 * time.Second) env.state.SetTimestamp(newTimestamp) { @@ -570,7 +570,7 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { NodeID: nodeID, Start: uint64(newTimestamp.Unix()), End: uint64(newTimestamp.Add(defaultMinStakingDuration).Unix()), - Wght: genesistest.ValidatorWeight2, + Wght: genesistest.DefaultValidatorWeight, }, Subnet: testSubnet1.ID(), }, @@ -598,7 +598,7 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { } // reset the timestamp - env.state.SetTimestamp(genesistest.Time) + env.state.SetTimestamp(genesistest.DefaultTime) // Case: Proposed validator already validating the subnet // First, add validator as validator of subnet @@ -607,9 +607,9 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: nodeID, - Start: genesistest.TimeUnix, - End: genesistest.ValidatorEndTimeUnix, - Wght: genesistest.ValidatorWeight2, + Start: genesistest.DefaultTimeUnix, + End: genesistest.DefaultValidatorEndTimeUnix, + Wght: genesistest.DefaultValidatorWeight, }, Subnet: testSubnet1.ID(), }, @@ -639,9 +639,9 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: nodeID, - Start: genesistest.TimeUnix + 1, - End: genesistest.ValidatorEndTimeUnix, - Wght: genesistest.ValidatorWeight2, + Start: genesistest.DefaultTimeUnix + 1, + End: genesistest.DefaultValidatorEndTimeUnix, + Wght: genesistest.DefaultValidatorWeight, }, Subnet: testSubnet1.ID(), }, @@ -679,9 +679,9 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: nodeID, - Start: genesistest.TimeUnix + 1, - End: uint64(genesistest.Time.Add(defaultMinStakingDuration).Unix()) + 1, - Wght: genesistest.ValidatorWeight2, + Start: genesistest.DefaultTimeUnix + 1, + End: uint64(genesistest.DefaultTime.Add(defaultMinStakingDuration).Unix()) + 1, + Wght: genesistest.DefaultValidatorWeight, }, Subnet: testSubnet1.ID(), }, @@ -717,14 +717,14 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { { // Case: Control Signature from invalid key (keys[3] is not a control key) - builder, signer := env.factory.NewWallet(testSubnet1ControlKeys[0], genesistest.FundedKeys[1]) + builder, signer := env.factory.NewWallet(testSubnet1ControlKeys[0], genesistest.DefaultFundedKeys[1]) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: nodeID, - Start: genesistest.TimeUnix + 1, - End: uint64(genesistest.Time.Add(defaultMinStakingDuration).Unix()) + 1, - Wght: genesistest.ValidatorWeight2, + Start: genesistest.DefaultTimeUnix + 1, + End: uint64(genesistest.DefaultTime.Add(defaultMinStakingDuration).Unix()) + 1, + Wght: genesistest.DefaultValidatorWeight, }, Subnet: testSubnet1.ID(), }, @@ -734,7 +734,7 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { require.NoError(err) // Replace a valid signature with one from keys[3] - sig, err := genesistest.FundedKeys[3].SignHash(hashing.ComputeHash256(tx.Unsigned.Bytes())) + sig, err := genesistest.DefaultFundedKeys[3].SignHash(hashing.ComputeHash256(tx.Unsigned.Bytes())) require.NoError(err) copy(tx.Creds[0].(*secp256k1fx.Credential).Sigs[0][:], sig) @@ -764,9 +764,9 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: nodeID, - Start: genesistest.TimeUnix + 1, - End: uint64(genesistest.Time.Add(defaultMinStakingDuration).Unix()) + 1, - Wght: genesistest.ValidatorWeight2, + Start: genesistest.DefaultTimeUnix + 1, + End: uint64(genesistest.DefaultTime.Add(defaultMinStakingDuration).Unix()) + 1, + Wght: genesistest.DefaultValidatorWeight, }, Subnet: testSubnet1.ID(), }, @@ -819,12 +819,12 @@ func TestProposalTxExecuteAddValidator(t *testing.T) { { // Case: Validator's start time too early - builder, signer := env.factory.NewWallet(genesistest.FundedKeys[0]) + builder, signer := env.factory.NewWallet(genesistest.DefaultFundedKeys[0]) utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID, Start: uint64(chainTime.Unix()), - End: genesistest.ValidatorEndTimeUnix, + End: genesistest.DefaultValidatorEndTimeUnix, Wght: env.config.MinValidatorStake, }, &secp256k1fx.OutputOwners{ @@ -856,15 +856,15 @@ func TestProposalTxExecuteAddValidator(t *testing.T) { } { - nodeID := genesistest.NodeIDs[0] + nodeID := genesistest.DefaultNodeIDs[0] // Case: Validator already validating primary network - builder, signer := env.factory.NewWallet(genesistest.FundedKeys[0]) + builder, signer := env.factory.NewWallet(genesistest.DefaultFundedKeys[0]) utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID, - Start: genesistest.TimeUnix + 1, - End: genesistest.ValidatorEndTimeUnix, + Start: genesistest.DefaultTimeUnix + 1, + End: genesistest.DefaultValidatorEndTimeUnix, Wght: env.config.MinValidatorStake, }, &secp256k1fx.OutputOwners{ @@ -897,8 +897,8 @@ func TestProposalTxExecuteAddValidator(t *testing.T) { { // Case: Validator in pending validator set of primary network - startTime := genesistest.Time.Add(1 * time.Second) - builder, signer := env.factory.NewWallet(genesistest.FundedKeys[0]) + startTime := genesistest.DefaultTime.Add(1 * time.Second) + builder, signer := env.factory.NewWallet(genesistest.DefaultFundedKeys[0]) utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID, @@ -951,12 +951,12 @@ func TestProposalTxExecuteAddValidator(t *testing.T) { { // Case: Validator doesn't have enough tokens to cover stake amount - builder, signer := env.factory.NewWallet(genesistest.FundedKeys[0]) + builder, signer := env.factory.NewWallet(genesistest.DefaultFundedKeys[0]) utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: ids.GenerateTestNodeID(), - Start: genesistest.TimeUnix + 1, - End: genesistest.ValidatorEndTimeUnix, + Start: genesistest.DefaultTimeUnix + 1, + End: genesistest.DefaultValidatorEndTimeUnix, Wght: env.config.MinValidatorStake, }, &secp256k1fx.OutputOwners{ @@ -970,7 +970,7 @@ func TestProposalTxExecuteAddValidator(t *testing.T) { require.NoError(err) // Remove all UTXOs owned by preFundedKeys[0] - utxoIDs, err := env.state.UTXOIDs(genesistest.FundedKeys[0].Address().Bytes(), ids.Empty, math.MaxInt32) + utxoIDs, err := env.state.UTXOIDs(genesistest.DefaultFundedKeys[0].Address().Bytes(), ids.Empty, math.MaxInt32) require.NoError(err) for _, utxoID := range utxoIDs { diff --git a/vms/platformvm/txs/executor/reward_validator_test.go b/vms/platformvm/txs/executor/reward_validator_test.go index 28f3a92c89ea..52029d318889 100644 --- a/vms/platformvm/txs/executor/reward_validator_test.go +++ b/vms/platformvm/txs/executor/reward_validator_test.go @@ -247,11 +247,11 @@ func TestRewardDelegatorTxExecuteOnCommitPreDelegateeDeferral(t *testing.T) { vdrRewardAddress := ids.GenerateTestShortID() delRewardAddress := ids.GenerateTestShortID() - vdrStartTime := genesistest.TimeUnix + 1 - vdrEndTime := uint64(genesistest.Time.Add(2 * defaultMinStakingDuration).Unix()) + vdrStartTime := genesistest.DefaultTimeUnix + 1 + vdrEndTime := uint64(genesistest.DefaultTime.Add(2 * defaultMinStakingDuration).Unix()) vdrNodeID := ids.GenerateTestNodeID() - builder, signer := env.factory.NewWallet(genesistest.FundedKeys[0]) + builder, signer := env.factory.NewWallet(genesistest.DefaultFundedKeys[0]) uVdrTx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: vdrNodeID, @@ -381,11 +381,11 @@ func TestRewardDelegatorTxExecuteOnCommitPostDelegateeDeferral(t *testing.T) { vdrRewardAddress := ids.GenerateTestShortID() delRewardAddress := ids.GenerateTestShortID() - vdrStartTime := genesistest.TimeUnix + 1 - vdrEndTime := uint64(genesistest.Time.Add(2 * defaultMinStakingDuration).Unix()) + vdrStartTime := genesistest.DefaultTimeUnix + 1 + vdrEndTime := uint64(genesistest.DefaultTime.Add(2 * defaultMinStakingDuration).Unix()) vdrNodeID := ids.GenerateTestNodeID() - builder, signer := env.factory.NewWallet(genesistest.FundedKeys[0]) + builder, signer := env.factory.NewWallet(genesistest.DefaultFundedKeys[0]) uVdrTx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: vdrNodeID, @@ -611,11 +611,11 @@ func TestRewardDelegatorTxAndValidatorTxExecuteOnCommitPostDelegateeDeferral(t * vdrRewardAddress := ids.GenerateTestShortID() delRewardAddress := ids.GenerateTestShortID() - vdrStartTime := genesistest.TimeUnix + 1 - vdrEndTime := uint64(genesistest.Time.Add(2 * defaultMinStakingDuration).Unix()) + vdrStartTime := genesistest.DefaultTimeUnix + 1 + vdrEndTime := uint64(genesistest.DefaultTime.Add(2 * defaultMinStakingDuration).Unix()) vdrNodeID := ids.GenerateTestNodeID() - builder, signer := env.factory.NewWallet(genesistest.FundedKeys[0]) + builder, signer := env.factory.NewWallet(genesistest.DefaultFundedKeys[0]) uVdrTx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: vdrNodeID, @@ -787,11 +787,11 @@ func TestRewardDelegatorTxExecuteOnAbort(t *testing.T) { vdrRewardAddress := ids.GenerateTestShortID() delRewardAddress := ids.GenerateTestShortID() - vdrStartTime := genesistest.TimeUnix + 1 - vdrEndTime := uint64(genesistest.Time.Add(2 * defaultMinStakingDuration).Unix()) + vdrStartTime := genesistest.DefaultTimeUnix + 1 + vdrEndTime := uint64(genesistest.DefaultTime.Add(2 * defaultMinStakingDuration).Unix()) vdrNodeID := ids.GenerateTestNodeID() - builder, signer := env.factory.NewWallet(genesistest.FundedKeys[0]) + builder, signer := env.factory.NewWallet(genesistest.DefaultFundedKeys[0]) uVdrTx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: vdrNodeID, diff --git a/vms/platformvm/txs/executor/standard_tx_executor_test.go b/vms/platformvm/txs/executor/standard_tx_executor_test.go index c903655efc5d..d12285cc9b1b 100644 --- a/vms/platformvm/txs/executor/standard_tx_executor_test.go +++ b/vms/platformvm/txs/executor/standard_tx_executor_test.go @@ -54,7 +54,7 @@ func TestStandardTxExecutorAddValidatorTxEmptyID(t *testing.T) { defer env.ctx.Lock.Unlock() chainTime := env.state.GetTimestamp() - startTime := genesistest.Time.Add(1 * time.Second) + startTime := genesistest.DefaultTime.Add(1 * time.Second) tests := []struct { banffTime time.Time @@ -77,12 +77,12 @@ func TestStandardTxExecutorAddValidatorTxEmptyID(t *testing.T) { // Case: Empty validator node ID after banff env.config.UpgradeConfig.BanffTime = test.banffTime - builder, signer := env.factory.NewWallet(genesistest.FundedKeys[0]) + builder, signer := env.factory.NewWallet(genesistest.DefaultFundedKeys[0]) utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: ids.EmptyNodeID, Start: uint64(startTime.Unix()), - End: genesistest.ValidatorEndTimeUnix, + End: genesistest.DefaultValidatorEndTimeUnix, Wght: env.config.MinValidatorStake, }, &secp256k1fx.OutputOwners{ @@ -112,19 +112,19 @@ func TestStandardTxExecutorAddValidatorTxEmptyID(t *testing.T) { func TestStandardTxExecutorAddDelegator(t *testing.T) { dummyHeight := uint64(1) - rewardAddress := genesistest.FundedKeys[0].Address() - nodeID := genesistest.NodeIDs[0] + rewardAddress := genesistest.DefaultFundedKeys[0].Address() + nodeID := genesistest.DefaultNodeIDs[0] newValidatorID := ids.GenerateTestNodeID() - newValidatorStartTime := genesistest.Time.Add(5 * time.Second) - newValidatorEndTime := genesistest.ValidatorEndTime.Add(-5 * time.Second) + newValidatorStartTime := genesistest.DefaultTime.Add(5 * time.Second) + newValidatorEndTime := genesistest.DefaultValidatorEndTime.Add(-5 * time.Second) // [addMinStakeValidator] adds a new validator to the primary network's // pending validator set with the minimum staking amount addMinStakeValidator := func(env *environment) { require := require.New(t) - builder, signer := env.factory.NewWallet(genesistest.FundedKeys[0]) + builder, signer := env.factory.NewWallet(genesistest.DefaultFundedKeys[0]) utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: newValidatorID, @@ -162,7 +162,7 @@ func TestStandardTxExecutorAddDelegator(t *testing.T) { addMaxStakeValidator := func(env *environment) { require := require.New(t) - builder, signer := env.factory.NewWallet(genesistest.FundedKeys[0]) + builder, signer := env.factory.NewWallet(genesistest.DefaultFundedKeys[0]) utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: newValidatorID, @@ -214,23 +214,23 @@ func TestStandardTxExecutorAddDelegator(t *testing.T) { { description: "validator stops validating earlier than delegator", stakeAmount: env.config.MinDelegatorStake, - startTime: genesistest.Time.Add(time.Second), - endTime: genesistest.ValidatorEndTime.Add(time.Second), + startTime: genesistest.DefaultTime.Add(time.Second), + endTime: genesistest.DefaultValidatorEndTime.Add(time.Second), nodeID: nodeID, - feeKeys: []*secp256k1.PrivateKey{genesistest.FundedKeys[0]}, + feeKeys: []*secp256k1.PrivateKey{genesistest.DefaultFundedKeys[0]}, setup: nil, - AP3Time: genesistest.Time, + AP3Time: genesistest.DefaultTime, expectedExecutionErr: ErrPeriodMismatch, }, { description: "validator not in the current or pending validator sets", stakeAmount: env.config.MinDelegatorStake, - startTime: genesistest.Time.Add(5 * time.Second), - endTime: genesistest.ValidatorEndTime.Add(-5 * time.Second), + startTime: genesistest.DefaultTime.Add(5 * time.Second), + endTime: genesistest.DefaultValidatorEndTime.Add(-5 * time.Second), nodeID: newValidatorID, - feeKeys: []*secp256k1.PrivateKey{genesistest.FundedKeys[0]}, + feeKeys: []*secp256k1.PrivateKey{genesistest.DefaultFundedKeys[0]}, setup: nil, - AP3Time: genesistest.Time, + AP3Time: genesistest.DefaultTime, expectedExecutionErr: database.ErrNotFound, }, { @@ -239,9 +239,9 @@ func TestStandardTxExecutorAddDelegator(t *testing.T) { startTime: newValidatorStartTime.Add(-1 * time.Second), // start validating subnet before primary network endTime: newValidatorEndTime, nodeID: newValidatorID, - feeKeys: []*secp256k1.PrivateKey{genesistest.FundedKeys[0]}, + feeKeys: []*secp256k1.PrivateKey{genesistest.DefaultFundedKeys[0]}, setup: addMinStakeValidator, - AP3Time: genesistest.Time, + AP3Time: genesistest.DefaultTime, expectedExecutionErr: ErrPeriodMismatch, }, { @@ -250,9 +250,9 @@ func TestStandardTxExecutorAddDelegator(t *testing.T) { startTime: newValidatorStartTime, endTime: newValidatorEndTime.Add(time.Second), // stop validating subnet after stopping validating primary network nodeID: newValidatorID, - feeKeys: []*secp256k1.PrivateKey{genesistest.FundedKeys[0]}, + feeKeys: []*secp256k1.PrivateKey{genesistest.DefaultFundedKeys[0]}, setup: addMinStakeValidator, - AP3Time: genesistest.Time, + AP3Time: genesistest.DefaultTime, expectedExecutionErr: ErrPeriodMismatch, }, { @@ -261,32 +261,32 @@ func TestStandardTxExecutorAddDelegator(t *testing.T) { startTime: newValidatorStartTime, // same start time as for primary network endTime: newValidatorEndTime, // same end time as for primary network nodeID: newValidatorID, - feeKeys: []*secp256k1.PrivateKey{genesistest.FundedKeys[0]}, + feeKeys: []*secp256k1.PrivateKey{genesistest.DefaultFundedKeys[0]}, setup: addMinStakeValidator, - AP3Time: genesistest.Time, + AP3Time: genesistest.DefaultTime, expectedExecutionErr: nil, }, { description: "starts delegating at current timestamp", - stakeAmount: env.config.MinDelegatorStake, // weight - startTime: currentTimestamp, // start time - endTime: genesistest.ValidatorEndTime, // end time - nodeID: nodeID, // node ID - feeKeys: []*secp256k1.PrivateKey{genesistest.FundedKeys[0]}, // tx fee payer + stakeAmount: env.config.MinDelegatorStake, // weight + startTime: currentTimestamp, // start time + endTime: genesistest.DefaultValidatorEndTime, // end time + nodeID: nodeID, // node ID + feeKeys: []*secp256k1.PrivateKey{genesistest.DefaultFundedKeys[0]}, // tx fee payer setup: nil, - AP3Time: genesistest.Time, + AP3Time: genesistest.DefaultTime, expectedExecutionErr: ErrTimestampNotBeforeStartTime, }, { description: "tx fee paying key has no funds", - stakeAmount: env.config.MinDelegatorStake, // weight - startTime: genesistest.Time.Add(time.Second), // start time - endTime: genesistest.ValidatorEndTime, // end time - nodeID: nodeID, // node ID - feeKeys: []*secp256k1.PrivateKey{genesistest.FundedKeys[1]}, // tx fee payer + stakeAmount: env.config.MinDelegatorStake, // weight + startTime: genesistest.DefaultTime.Add(time.Second), // start time + endTime: genesistest.DefaultValidatorEndTime, // end time + nodeID: nodeID, // node ID + feeKeys: []*secp256k1.PrivateKey{genesistest.DefaultFundedKeys[1]}, // tx fee payer setup: func(env *environment) { // Remove all UTXOs owned by keys[1] utxoIDs, err := env.state.UTXOIDs( - genesistest.FundedKeys[1].Address().Bytes(), + genesistest.DefaultFundedKeys[1].Address().Bytes(), ids.Empty, math.MaxInt32) require.NoError(t, err) @@ -297,7 +297,7 @@ func TestStandardTxExecutorAddDelegator(t *testing.T) { env.state.SetHeight(dummyHeight) require.NoError(t, env.state.Commit()) }, - AP3Time: genesistest.Time, + AP3Time: genesistest.DefaultTime, expectedExecutionErr: ErrFlowCheckFailed, }, { @@ -306,9 +306,9 @@ func TestStandardTxExecutorAddDelegator(t *testing.T) { startTime: newValidatorStartTime, // same start time as for primary network endTime: newValidatorEndTime, // same end time as for primary network nodeID: newValidatorID, - feeKeys: []*secp256k1.PrivateKey{genesistest.FundedKeys[0]}, + feeKeys: []*secp256k1.PrivateKey{genesistest.DefaultFundedKeys[0]}, setup: addMaxStakeValidator, - AP3Time: genesistest.ValidatorEndTime, + AP3Time: genesistest.DefaultValidatorEndTime, expectedExecutionErr: nil, }, { @@ -317,9 +317,9 @@ func TestStandardTxExecutorAddDelegator(t *testing.T) { startTime: newValidatorStartTime, // same start time as for primary network endTime: newValidatorEndTime, // same end time as for primary network nodeID: newValidatorID, - feeKeys: []*secp256k1.PrivateKey{genesistest.FundedKeys[0]}, + feeKeys: []*secp256k1.PrivateKey{genesistest.DefaultFundedKeys[0]}, setup: addMaxStakeValidator, - AP3Time: genesistest.Time, + AP3Time: genesistest.DefaultTime, expectedExecutionErr: ErrOverDelegated, }, } @@ -375,21 +375,21 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { env.ctx.Lock.Lock() defer env.ctx.Lock.Unlock() - nodeID := genesistest.NodeIDs[0] + nodeID := genesistest.DefaultNodeIDs[0] { // Case: Proposed validator currently validating primary network // but stops validating subnet after stops validating primary network // (note that keys[0] is a genesis validator) - startTime := genesistest.Time.Add(time.Second) + startTime := genesistest.DefaultTime.Add(time.Second) builder, signer := env.factory.NewWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: nodeID, Start: uint64(startTime.Unix()), - End: genesistest.ValidatorEndTimeUnix + 1, - Wght: genesistest.ValidatorWeight2, + End: genesistest.DefaultValidatorEndTimeUnix + 1, + Wght: genesistest.DefaultValidatorWeight, }, Subnet: testSubnet1.ID(), }, @@ -422,9 +422,9 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: nodeID, - Start: genesistest.TimeUnix + 1, - End: genesistest.ValidatorEndTimeUnix, - Wght: genesistest.ValidatorWeight2, + Start: genesistest.DefaultTimeUnix + 1, + End: genesistest.DefaultValidatorEndTimeUnix, + Wght: genesistest.DefaultValidatorWeight, }, Subnet: testSubnet1.ID(), }, @@ -449,10 +449,10 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { // Add a validator to pending validator set of primary network // Starts validating primary network 10 seconds after genesis pendingDSValidatorID := ids.GenerateTestNodeID() - dsStartTime := genesistest.Time.Add(10 * time.Second) + dsStartTime := genesistest.DefaultTime.Add(10 * time.Second) dsEndTime := dsStartTime.Add(5 * defaultMinStakingDuration) - builder, signer := env.factory.NewWallet(genesistest.FundedKeys[0]) + builder, signer := env.factory.NewWallet(genesistest.DefaultFundedKeys[0]) utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: pendingDSValidatorID, @@ -479,7 +479,7 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { NodeID: pendingDSValidatorID, Start: uint64(dsStartTime.Unix()), // start validating subnet before primary network End: uint64(dsEndTime.Unix()), - Wght: genesistest.ValidatorWeight2, + Wght: genesistest.DefaultValidatorWeight, }, Subnet: testSubnet1.ID(), }, @@ -529,7 +529,7 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { NodeID: pendingDSValidatorID, Start: uint64(dsStartTime.Unix()) - 1, // start validating subnet before primary network End: uint64(dsEndTime.Unix()), - Wght: genesistest.ValidatorWeight2, + Wght: genesistest.DefaultValidatorWeight, }, Subnet: testSubnet1.ID(), }, @@ -562,7 +562,7 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { NodeID: pendingDSValidatorID, Start: uint64(dsStartTime.Unix()), End: uint64(dsEndTime.Unix()) + 1, // stop validating subnet after stopping validating primary network - Wght: genesistest.ValidatorWeight2, + Wght: genesistest.DefaultValidatorWeight, }, Subnet: testSubnet1.ID(), }, @@ -595,7 +595,7 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { NodeID: pendingDSValidatorID, Start: uint64(dsStartTime.Unix()), // same start time as for primary network End: uint64(dsEndTime.Unix()), // same end time as for primary network - Wght: genesistest.ValidatorWeight2, + Wght: genesistest.DefaultValidatorWeight, }, Subnet: testSubnet1.ID(), }, @@ -619,7 +619,7 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { // Case: Proposed validator start validating at/before current timestamp // First, advance the timestamp - newTimestamp := genesistest.Time.Add(2 * time.Second) + newTimestamp := genesistest.DefaultTime.Add(2 * time.Second) env.state.SetTimestamp(newTimestamp) { @@ -630,7 +630,7 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { NodeID: nodeID, Start: uint64(newTimestamp.Unix()), End: uint64(newTimestamp.Add(defaultMinStakingDuration).Unix()), - Wght: genesistest.ValidatorWeight2, + Wght: genesistest.DefaultValidatorWeight, }, Subnet: testSubnet1.ID(), }, @@ -654,7 +654,7 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { } // reset the timestamp - env.state.SetTimestamp(genesistest.Time) + env.state.SetTimestamp(genesistest.DefaultTime) // Case: Proposed validator already validating the subnet // First, add validator as validator of subnet @@ -663,9 +663,9 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: nodeID, - Start: genesistest.TimeUnix, - End: genesistest.ValidatorEndTimeUnix, - Wght: genesistest.ValidatorWeight2, + Start: genesistest.DefaultTimeUnix, + End: genesistest.DefaultValidatorEndTimeUnix, + Wght: genesistest.DefaultValidatorWeight, }, Subnet: testSubnet1.ID(), }, @@ -678,7 +678,7 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { staker, err = state.NewCurrentStaker( subnetTx.ID(), addSubnetValTx, - genesistest.Time, + genesistest.DefaultTime, 0, ) require.NoError(err) @@ -690,15 +690,15 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { { // Node with ID nodeIDKey.Address() now validating subnet with ID testSubnet1.ID - startTime := genesistest.Time.Add(time.Second) + startTime := genesistest.DefaultTime.Add(time.Second) builder, signer := env.factory.NewWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: nodeID, Start: uint64(startTime.Unix()), - End: genesistest.ValidatorEndTimeUnix, - Wght: genesistest.ValidatorWeight2, + End: genesistest.DefaultValidatorEndTimeUnix, + Wght: genesistest.DefaultValidatorWeight, }, Subnet: testSubnet1.ID(), }, @@ -727,7 +727,7 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { { // Case: Duplicate signatures - startTime := genesistest.Time.Add(time.Second) + startTime := genesistest.DefaultTime.Add(time.Second) builder, signer := env.factory.NewWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1], testSubnet1ControlKeys[2]) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ @@ -735,7 +735,7 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { NodeID: nodeID, Start: uint64(startTime.Unix()), End: uint64(startTime.Add(defaultMinStakingDuration).Unix()) + 1, - Wght: genesistest.ValidatorWeight2, + Wght: genesistest.DefaultValidatorWeight, }, Subnet: testSubnet1.ID(), }, @@ -767,7 +767,7 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { { // Case: Too few signatures - startTime := genesistest.Time.Add(time.Second) + startTime := genesistest.DefaultTime.Add(time.Second) builder, signer := env.factory.NewWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[2]) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ @@ -775,7 +775,7 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { NodeID: nodeID, Start: uint64(startTime.Unix()), End: uint64(startTime.Add(defaultMinStakingDuration).Unix()), - Wght: genesistest.ValidatorWeight2, + Wght: genesistest.DefaultValidatorWeight, }, Subnet: testSubnet1.ID(), }, @@ -807,15 +807,15 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { { // Case: Control Signature from invalid key (keys[3] is not a control key) - startTime := genesistest.Time.Add(time.Second) - builder, signer := env.factory.NewWallet(testSubnet1ControlKeys[0], genesistest.FundedKeys[1]) + startTime := genesistest.DefaultTime.Add(time.Second) + builder, signer := env.factory.NewWallet(testSubnet1ControlKeys[0], genesistest.DefaultFundedKeys[1]) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: nodeID, Start: uint64(startTime.Unix()), End: uint64(startTime.Add(defaultMinStakingDuration).Unix()), - Wght: genesistest.ValidatorWeight2, + Wght: genesistest.DefaultValidatorWeight, }, Subnet: testSubnet1.ID(), }, @@ -825,7 +825,7 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { require.NoError(err) // Replace a valid signature with one from keys[3] - sig, err := genesistest.FundedKeys[3].SignHash(hashing.ComputeHash256(tx.Unsigned.Bytes())) + sig, err := genesistest.DefaultFundedKeys[3].SignHash(hashing.ComputeHash256(tx.Unsigned.Bytes())) require.NoError(err) copy(tx.Creds[0].(*secp256k1fx.Credential).Sigs[0][:], sig) @@ -846,7 +846,7 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { { // Case: Proposed validator in pending validator set for subnet // First, add validator to pending validator set of subnet - startTime := genesistest.Time.Add(time.Second) + startTime := genesistest.DefaultTime.Add(time.Second) builder, signer := env.factory.NewWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ @@ -854,7 +854,7 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { NodeID: nodeID, Start: uint64(startTime.Unix()) + 1, End: uint64(startTime.Add(defaultMinStakingDuration).Unix()) + 1, - Wght: genesistest.ValidatorWeight2, + Wght: genesistest.DefaultValidatorWeight, }, Subnet: testSubnet1.ID(), }, @@ -867,7 +867,7 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { staker, err = state.NewCurrentStaker( subnetTx.ID(), addSubnetValTx, - genesistest.Time, + genesistest.DefaultTime, 0, ) require.NoError(err) @@ -898,16 +898,16 @@ func TestEtnaStandardTxExecutorAddSubnetValidator(t *testing.T) { env.ctx.Lock.Lock() defer env.ctx.Lock.Unlock() - nodeID := genesistest.NodeIDs[0] + nodeID := genesistest.DefaultNodeIDs[0] builder, signer := env.factory.NewWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: nodeID, - Start: genesistest.TimeUnix + 1, - End: genesistest.ValidatorEndTimeUnix, - Wght: genesistest.ValidatorWeight2, + Start: genesistest.DefaultTimeUnix + 1, + End: genesistest.DefaultValidatorEndTimeUnix, + Wght: genesistest.DefaultValidatorWeight, }, Subnet: testSubnet1.ID(), }, @@ -940,12 +940,12 @@ func TestBanffStandardTxExecutorAddValidator(t *testing.T) { { // Case: Validator's start time too early - builder, signer := env.factory.NewWallet(genesistest.FundedKeys[0]) + builder, signer := env.factory.NewWallet(genesistest.DefaultFundedKeys[0]) utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID, - Start: genesistest.TimeUnix - 1, - End: genesistest.ValidatorEndTimeUnix, + Start: genesistest.DefaultTimeUnix - 1, + End: genesistest.DefaultValidatorEndTimeUnix, Wght: env.config.MinValidatorStake, }, &secp256k1fx.OutputOwners{ @@ -974,8 +974,8 @@ func TestBanffStandardTxExecutorAddValidator(t *testing.T) { { // Case: Validator in current validator set of primary network - startTime := genesistest.Time.Add(1 * time.Second) - builder, signer := env.factory.NewWallet(genesistest.FundedKeys[0]) + startTime := genesistest.DefaultTime.Add(1 * time.Second) + builder, signer := env.factory.NewWallet(genesistest.DefaultFundedKeys[0]) utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID, @@ -1021,8 +1021,8 @@ func TestBanffStandardTxExecutorAddValidator(t *testing.T) { { // Case: Validator in pending validator set of primary network - startTime := genesistest.Time.Add(1 * time.Second) - builder, signer := env.factory.NewWallet(genesistest.FundedKeys[0]) + startTime := genesistest.DefaultTime.Add(1 * time.Second) + builder, signer := env.factory.NewWallet(genesistest.DefaultFundedKeys[0]) utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID, @@ -1065,8 +1065,8 @@ func TestBanffStandardTxExecutorAddValidator(t *testing.T) { { // Case: Validator doesn't have enough tokens to cover stake amount - startTime := genesistest.Time.Add(1 * time.Second) - builder, signer := env.factory.NewWallet(genesistest.FundedKeys[0]) + startTime := genesistest.DefaultTime.Add(1 * time.Second) + builder, signer := env.factory.NewWallet(genesistest.DefaultFundedKeys[0]) utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID, @@ -1085,7 +1085,7 @@ func TestBanffStandardTxExecutorAddValidator(t *testing.T) { require.NoError(err) // Remove all UTXOs owned by preFundedKeys[0] - utxoIDs, err := env.state.UTXOIDs(genesistest.FundedKeys[0].Address().Bytes(), ids.Empty, math.MaxInt32) + utxoIDs, err := env.state.UTXOIDs(genesistest.DefaultFundedKeys[0].Address().Bytes(), ids.Empty, math.MaxInt32) require.NoError(err) onAcceptState, err := state.NewDiff(lastAcceptedID, env) @@ -1125,7 +1125,7 @@ func TestDurangoDisabledTransactions(t *testing.T) { endTime = chainTime.Add(defaultMaxStakingDuration) ) - builder, signer := env.factory.NewWallet(genesistest.FundedKeys...) + builder, signer := env.factory.NewWallet(genesistest.DefaultFundedKeys...) utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID, @@ -1163,7 +1163,7 @@ func TestDurangoDisabledTransactions(t *testing.T) { } it.Release() - builder, signer := env.factory.NewWallet(genesistest.FundedKeys...) + builder, signer := env.factory.NewWallet(genesistest.DefaultFundedKeys...) utx, err := builder.NewAddDelegatorTx( &txs.Validator{ NodeID: primaryValidator.NodeID, @@ -1235,7 +1235,7 @@ func TestDurangoMemoField(t *testing.T) { } it.Release() - builder, signer := env.factory.NewWallet(genesistest.FundedKeys...) + builder, signer := env.factory.NewWallet(genesistest.DefaultFundedKeys...) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -1260,7 +1260,7 @@ func TestDurangoMemoField(t *testing.T) { { name: "CreateChainTx", setupTest: func(env *environment, memoField []byte) (*txs.Tx, state.Diff) { - builder, signer := env.factory.NewWallet(genesistest.FundedKeys...) + builder, signer := env.factory.NewWallet(genesistest.DefaultFundedKeys...) utx, err := builder.NewCreateChainTx( testSubnet1.TxID, []byte{}, @@ -1282,7 +1282,7 @@ func TestDurangoMemoField(t *testing.T) { { name: "CreateSubnetTx", setupTest: func(env *environment, memoField []byte) (*txs.Tx, state.Diff) { - builder, signer := env.factory.NewWallet(genesistest.FundedKeys...) + builder, signer := env.factory.NewWallet(genesistest.DefaultFundedKeys...) utx, err := builder.NewCreateSubnetTx( &secp256k1fx.OutputOwners{ Threshold: 1, @@ -1308,7 +1308,7 @@ func TestDurangoMemoField(t *testing.T) { var ( sourceChain = env.ctx.XChainID - sourceKey = genesistest.FundedKeys[1] + sourceKey = genesistest.DefaultFundedKeys[1] sourceAmount = 10 * units.Avax ) @@ -1324,7 +1324,7 @@ func TestDurangoMemoField(t *testing.T) { ) env.msm.SharedMemory = sharedMemory - builder, signer := env.factory.NewWallet(genesistest.FundedKeys...) + builder, signer := env.factory.NewWallet(genesistest.DefaultFundedKeys...) utx, err := builder.NewImportTx( sourceChain, &secp256k1fx.OutputOwners{ @@ -1347,7 +1347,7 @@ func TestDurangoMemoField(t *testing.T) { { name: "ExportTx", setupTest: func(env *environment, memoField []byte) (*txs.Tx, state.Diff) { - builder, signer := env.factory.NewWallet(genesistest.FundedKeys...) + builder, signer := env.factory.NewWallet(genesistest.DefaultFundedKeys...) utx, err := builder.NewExportTx( env.ctx.XChainID, []*avax.TransferableOutput{{ @@ -1397,7 +1397,7 @@ func TestDurangoMemoField(t *testing.T) { NodeID: primaryValidator.NodeID, Start: 0, End: uint64(endTime.Unix()), - Wght: genesistest.ValidatorWeight2, + Wght: genesistest.DefaultValidatorWeight, }, Subnet: testSubnet1.ID(), }, @@ -1417,7 +1417,7 @@ func TestDurangoMemoField(t *testing.T) { Tx: subnetValTx, })) - builder, signer = env.factory.NewWallet(genesistest.FundedKeys...) + builder, signer = env.factory.NewWallet(genesistest.DefaultFundedKeys...) utx2, err := builder.NewRemoveSubnetValidatorTx( primaryValidator.NodeID, testSubnet1.ID(), @@ -1433,7 +1433,7 @@ func TestDurangoMemoField(t *testing.T) { { name: "TransformSubnetTx", setupTest: func(env *environment, memoField []byte) (*txs.Tx, state.Diff) { - builder, signer := env.factory.NewWallet(genesistest.FundedKeys...) + builder, signer := env.factory.NewWallet(genesistest.DefaultFundedKeys...) utx, err := builder.NewTransformSubnetTx( testSubnet1.TxID, // subnetID ids.GenerateTestID(), // assetID @@ -1472,7 +1472,7 @@ func TestDurangoMemoField(t *testing.T) { sk, err := bls.NewSecretKey() require.NoError(t, err) - builder, txSigner := env.factory.NewWallet(genesistest.FundedKeys...) + builder, txSigner := env.factory.NewWallet(genesistest.DefaultFundedKeys...) utx, err := builder.NewAddPermissionlessValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -1522,7 +1522,7 @@ func TestDurangoMemoField(t *testing.T) { } it.Release() - builder, signer := env.factory.NewWallet(genesistest.FundedKeys...) + builder, signer := env.factory.NewWallet(genesistest.DefaultFundedKeys...) utx, err := builder.NewAddPermissionlessDelegatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -1553,7 +1553,7 @@ func TestDurangoMemoField(t *testing.T) { { name: "TransferSubnetOwnershipTx", setupTest: func(env *environment, memoField []byte) (*txs.Tx, state.Diff) { - builder, signer := env.factory.NewWallet(genesistest.FundedKeys...) + builder, signer := env.factory.NewWallet(genesistest.DefaultFundedKeys...) utx, err := builder.NewTransferSubnetOwnershipTx( testSubnet1.TxID, &secp256k1fx.OutputOwners{ @@ -1575,7 +1575,7 @@ func TestDurangoMemoField(t *testing.T) { { name: "BaseTx", setupTest: func(env *environment, memoField []byte) (*txs.Tx, state.Diff) { - builder, signer := env.factory.NewWallet(genesistest.FundedKeys...) + builder, signer := env.factory.NewWallet(genesistest.DefaultFundedKeys...) utx, err := builder.NewBaseTx( []*avax.TransferableOutput{ { diff --git a/vms/platformvm/validator_set_property_test.go b/vms/platformvm/validator_set_property_test.go index 501f4a75f40a..b739de466bb1 100644 --- a/vms/platformvm/validator_set_property_test.go +++ b/vms/platformvm/validator_set_property_test.go @@ -15,7 +15,6 @@ import ( "github.com/leanovate/gopter" "github.com/leanovate/gopter/gen" "github.com/leanovate/gopter/prop" - "github.com/stretchr/testify/require" "golang.org/x/exp/maps" "github.com/ava-labs/avalanchego/chains" @@ -33,12 +32,7 @@ import ( "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/formatting" - "github.com/ava-labs/avalanchego/utils/formatting/address" - "github.com/ava-labs/avalanchego/utils/json" "github.com/ava-labs/avalanchego/utils/timer/mockable" - "github.com/ava-labs/avalanchego/utils/units" - "github.com/ava-labs/avalanchego/vms/platformvm/api" "github.com/ava-labs/avalanchego/vms/platformvm/block" "github.com/ava-labs/avalanchego/vms/platformvm/config" "github.com/ava-labs/avalanchego/vms/platformvm/genesis/genesistest" @@ -91,7 +85,7 @@ func TestGetValidatorsSetProperty(t *testing.T) { }() nodeID := ids.GenerateTestNodeID() - currentTime := genesistest.Time + currentTime := genesistest.DefaultTime vm.clock.Set(currentTime) vm.state.SetTimestamp(currentTime) @@ -262,7 +256,7 @@ func takeValidatorsSnapshotAtCurrentHeight(vm *VM, validatorsSetByHeightAndSubne func addSubnetValidator(vm *VM, data *validatorInputData, subnetID ids.ID) (*state.Staker, error) { factory := txstest.NewWalletFactory(vm.ctx, &vm.Config, vm.state) - builder, signer := factory.NewWallet(genesistest.FundedKeys[0], genesistest.FundedKeys[1]) + builder, signer := factory.NewWallet(genesistest.DefaultFundedKeys[0], genesistest.DefaultFundedKeys[1]) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -275,7 +269,7 @@ func addSubnetValidator(vm *VM, data *validatorInputData, subnetID ids.ID) (*sta }, walletcommon.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{genesistest.FundedKeys[0].Address()}, + Addrs: []ids.ShortID{genesistest.DefaultFundedKeys[0].Address()}, }), ) if err != nil { @@ -289,7 +283,7 @@ func addSubnetValidator(vm *VM, data *validatorInputData, subnetID ids.ID) (*sta } func addPrimaryValidatorWithBLSKey(vm *VM, data *validatorInputData) (*state.Staker, error) { - addr := genesistest.FundedKeys[0].Address() + addr := genesistest.DefaultFundedKeys[0].Address() sk, err := bls.NewSecretKey() if err != nil { @@ -297,7 +291,7 @@ func addPrimaryValidatorWithBLSKey(vm *VM, data *validatorInputData) (*state.Sta } factory := txstest.NewWalletFactory(vm.ctx, &vm.Config, vm.state) - builder, txSigner := factory.NewWallet(genesistest.FundedKeys[0], genesistest.FundedKeys[1]) + builder, txSigner := factory.NewWallet(genesistest.DefaultFundedKeys[0], genesistest.DefaultFundedKeys[1]) utx, err := builder.NewAddPermissionlessValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -664,9 +658,9 @@ func buildVM(t *testing.T) (*VM, ids.ID, error) { MinStakeDuration: defaultMinStakingDuration, MaxStakeDuration: defaultMaxStakingDuration, RewardConfig: defaultRewardConfig, - UpgradeConfig: upgradetest.GetConfigWithUpgradeTime(upgradetest.Durango, genesistest.Time), + UpgradeConfig: upgradetest.GetConfigWithUpgradeTime(upgradetest.Durango, genesistest.DefaultTime), }} - vm.clock.Set(genesistest.Time.Add(time.Second)) + vm.clock.Set(genesistest.DefaultTime.Add(time.Second)) baseDB := memdb.New() chainDB := prefixdb.New([]byte{0}, baseDB) @@ -690,7 +684,12 @@ func buildVM(t *testing.T) (*VM, ids.ID, error) { context.Background(), ctx, chainDB, - buildCustomGenesis(t), + genesistest.NewBytes(t, genesistest.Config{ + NodeIDs: []ids.NodeID{ + genesistest.DefaultNodeIDs[len(genesistest.DefaultNodeIDs)-1], + }, + ValidatorEndTime: mockable.MaxTime, + }), nil, nil, msgChan, @@ -710,15 +709,15 @@ func buildVM(t *testing.T) (*VM, ids.ID, error) { // Note: following Banff activation, block acceptance will move // chain time ahead factory := txstest.NewWalletFactory(vm.ctx, &vm.Config, vm.state) - builder, signer := factory.NewWallet(genesistest.FundedKeys[len(genesistest.FundedKeys)-1]) + builder, signer := factory.NewWallet(genesistest.DefaultFundedKeys[len(genesistest.DefaultFundedKeys)-1]) utx, err := builder.NewCreateSubnetTx( &secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{genesistest.FundedKeys[0].Address()}, + Addrs: []ids.ShortID{genesistest.DefaultFundedKeys[0].Address()}, }, walletcommon.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{genesistest.FundedKeys[0].Address()}, + Addrs: []ids.ShortID{genesistest.DefaultFundedKeys[0].Address()}, }), ) if err != nil { @@ -751,64 +750,3 @@ func buildVM(t *testing.T) (*VM, ids.ID, error) { return vm, testSubnet1.ID(), nil } - -func buildCustomGenesis(t testing.TB) []byte { - require := require.New(t) - - genesisUTXOs := make([]api.UTXO, len(genesistest.FundedKeys)) - for i, key := range genesistest.FundedKeys { - addr, err := address.FormatBech32(constants.UnitTestHRP, key.Address().Bytes()) - require.NoError(err) - genesisUTXOs[i] = api.UTXO{ - Amount: json.Uint64(genesistest.InitialBalance2), - Address: addr, - } - } - - // we need at least a validator, otherwise BuildBlock would fail, since it - // won't find next staker to promote/evict from stakers set. Contrary to - // what happens with production code we push such validator at the end of - // times, so to avoid interference with our tests - nodeID := genesistest.NodeIDs[len(genesistest.NodeIDs)-1] - addr, err := address.FormatBech32(constants.UnitTestHRP, nodeID.Bytes()) - require.NoError(err) - - starTime := mockable.MaxTime.Add(-1 * defaultMinStakingDuration) - endTime := mockable.MaxTime - genesisValidator := api.GenesisPermissionlessValidator{ - GenesisValidator: api.GenesisValidator{ - StartTime: json.Uint64(starTime.Unix()), - EndTime: json.Uint64(endTime.Unix()), - NodeID: nodeID, - }, - RewardOwner: &api.Owner{ - Threshold: 1, - Addresses: []string{addr}, - }, - Staked: []api.UTXO{{ - Amount: json.Uint64(genesistest.ValidatorWeight2), - Address: addr, - }}, - DelegationFee: reward.PercentDenominator, - } - - buildGenesisArgs := api.BuildGenesisArgs{ - Encoding: formatting.Hex, - NetworkID: json.Uint32(constants.UnitTestID), - AvaxAssetID: snowtest.AVAXAssetID, - UTXOs: genesisUTXOs, - Validators: []api.GenesisPermissionlessValidator{genesisValidator}, - Chains: nil, - Time: json.Uint64(genesistest.Time.Unix()), - InitialSupply: json.Uint64(360 * units.MegaAvax), - } - - buildGenesisResponse := api.BuildGenesisReply{} - platformvmSS := api.StaticService{} - require.NoError(platformvmSS.BuildGenesis(nil, &buildGenesisArgs, &buildGenesisResponse)) - - genesisBytes, err := formatting.Decode(buildGenesisResponse.Encoding, buildGenesisResponse.Bytes) - require.NoError(err) - - return genesisBytes -} diff --git a/vms/platformvm/validators/manager_benchmark_test.go b/vms/platformvm/validators/manager_benchmark_test.go index 905bb8fc2a1d..be2e5f9ba83b 100644 --- a/vms/platformvm/validators/manager_benchmark_test.go +++ b/vms/platformvm/validators/manager_benchmark_test.go @@ -17,17 +17,13 @@ import ( "github.com/ava-labs/avalanchego/snow/validators" "github.com/ava-labs/avalanchego/utils/constants" "github.com/ava-labs/avalanchego/utils/crypto/bls" - "github.com/ava-labs/avalanchego/utils/formatting" - "github.com/ava-labs/avalanchego/utils/formatting/address" - "github.com/ava-labs/avalanchego/utils/json" "github.com/ava-labs/avalanchego/utils/logging" "github.com/ava-labs/avalanchego/utils/timer/mockable" "github.com/ava-labs/avalanchego/utils/units" - "github.com/ava-labs/avalanchego/vms/platformvm/api" "github.com/ava-labs/avalanchego/vms/platformvm/block" "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" "github.com/ava-labs/avalanchego/vms/platformvm/state/statetest" "github.com/ava-labs/avalanchego/vms/platformvm/txs" @@ -56,52 +52,9 @@ func BenchmarkGetValidatorSet(b *testing.B) { require.NoError(db.Close()) }() - avaxAssetID := ids.GenerateTestID() - genesisTime := time.Now().Truncate(time.Second) - genesisEndTime := genesisTime.Add(28 * 24 * time.Hour) - - addr, err := address.FormatBech32(constants.UnitTestHRP, ids.GenerateTestShortID().Bytes()) - require.NoError(err) - - genesisValidators := []api.GenesisPermissionlessValidator{{ - GenesisValidator: api.GenesisValidator{ - StartTime: json.Uint64(genesisTime.Unix()), - EndTime: json.Uint64(genesisEndTime.Unix()), - NodeID: ids.GenerateTestNodeID(), - }, - RewardOwner: &api.Owner{ - Threshold: 1, - Addresses: []string{addr}, - }, - Staked: []api.UTXO{{ - Amount: json.Uint64(2 * units.KiloAvax), - Address: addr, - }}, - DelegationFee: reward.PercentDenominator, - }} - - buildGenesisArgs := api.BuildGenesisArgs{ - NetworkID: json.Uint32(constants.UnitTestID), - AvaxAssetID: avaxAssetID, - UTXOs: nil, - Validators: genesisValidators, - Chains: nil, - Time: json.Uint64(genesisTime.Unix()), - InitialSupply: json.Uint64(360 * units.MegaAvax), - Encoding: formatting.Hex, - } - - buildGenesisResponse := api.BuildGenesisReply{} - platformvmSS := api.StaticService{} - require.NoError(platformvmSS.BuildGenesis(nil, &buildGenesisArgs, &buildGenesisResponse)) - - genesisBytes, err := formatting.Decode(buildGenesisResponse.Encoding, buildGenesisResponse.Bytes) - require.NoError(err) - vdrs := validators.NewManager() s := statetest.New(b, statetest.Config{ DB: db, - Genesis: genesisBytes, Validators: vdrs, }) @@ -121,18 +74,18 @@ func BenchmarkGetValidatorSet(b *testing.B) { ) for i := 0; i < 50; i++ { currentHeight++ - nodeID, err := addPrimaryValidator(s, genesisTime, genesisEndTime, currentHeight) + nodeID, err := addPrimaryValidator(s, genesistest.DefaultTime, genesistest.DefaultValidatorEndTime, currentHeight) require.NoError(err) nodeIDs = append(nodeIDs, nodeID) } subnetID := ids.GenerateTestID() for _, nodeID := range nodeIDs { currentHeight++ - require.NoError(addSubnetValidator(s, subnetID, genesisTime, genesisEndTime, nodeID, currentHeight)) + require.NoError(addSubnetValidator(s, subnetID, genesistest.DefaultTime, genesistest.DefaultValidatorEndTime, nodeID, currentHeight)) } for i := 0; i < 9900; i++ { currentHeight++ - require.NoError(addSubnetDelegator(s, subnetID, genesisTime, genesisEndTime, nodeIDs, currentHeight)) + require.NoError(addSubnetDelegator(s, subnetID, genesistest.DefaultTime, genesistest.DefaultValidatorEndTime, nodeIDs, currentHeight)) } ctx := context.Background() diff --git a/vms/platformvm/vm_regression_test.go b/vms/platformvm/vm_regression_test.go index 01aac542da17..5d39be736fc1 100644 --- a/vms/platformvm/vm_regression_test.go +++ b/vms/platformvm/vm_regression_test.go @@ -59,10 +59,10 @@ func TestAddDelegatorTxOverDelegatedRegression(t *testing.T) { validatorEndTime := validatorStartTime.Add(360 * 24 * time.Hour) nodeID := ids.GenerateTestNodeID() - changeAddr := genesistest.FundedKeys[0].Address() + changeAddr := genesistest.DefaultFundedKeys[0].Address() // create valid tx - builder, txSigner := factory.NewWallet(genesistest.FundedKeys[0]) + builder, txSigner := factory.NewWallet(genesistest.DefaultFundedKeys[0]) utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID, @@ -107,7 +107,7 @@ func TestAddDelegatorTxOverDelegatedRegression(t *testing.T) { firstDelegatorEndTime := firstDelegatorStartTime.Add(vm.MinStakeDuration) // create valid tx - builder, txSigner = factory.NewWallet(genesistest.FundedKeys[0], genesistest.FundedKeys[1]) + builder, txSigner = factory.NewWallet(genesistest.DefaultFundedKeys[0], genesistest.DefaultFundedKeys[1]) uDelTx1, err := builder.NewAddDelegatorTx( &txs.Validator{ NodeID: nodeID, @@ -153,7 +153,7 @@ func TestAddDelegatorTxOverDelegatedRegression(t *testing.T) { vm.clock.Set(secondDelegatorStartTime.Add(-10 * executor.SyncBound)) // create valid tx - builder, txSigner = factory.NewWallet(genesistest.FundedKeys[0], genesistest.FundedKeys[1], genesistest.FundedKeys[3]) + builder, txSigner = factory.NewWallet(genesistest.DefaultFundedKeys[0], genesistest.DefaultFundedKeys[1], genesistest.DefaultFundedKeys[3]) uDelTx2, err := builder.NewAddDelegatorTx( &txs.Validator{ NodeID: nodeID, @@ -189,7 +189,7 @@ func TestAddDelegatorTxOverDelegatedRegression(t *testing.T) { thirdDelegatorEndTime := thirdDelegatorStartTime.Add(vm.MinStakeDuration) // create valid tx - builder, txSigner = factory.NewWallet(genesistest.FundedKeys[0], genesistest.FundedKeys[1], genesistest.FundedKeys[4]) + builder, txSigner = factory.NewWallet(genesistest.DefaultFundedKeys[0], genesistest.DefaultFundedKeys[1], genesistest.DefaultFundedKeys[4]) uDelTx3, err := builder.NewAddDelegatorTx( &txs.Validator{ NodeID: nodeID, @@ -248,7 +248,7 @@ func TestAddDelegatorTxHeapCorruption(t *testing.T) { }, { name: "post-upgrade calculate max stake correctly", - ap3Time: genesistest.Time, + ap3Time: genesistest.DefaultTime, }, } @@ -267,10 +267,10 @@ func TestAddDelegatorTxHeapCorruption(t *testing.T) { id := key.Address() nodeID := ids.GenerateTestNodeID() - changeAddr := genesistest.FundedKeys[0].Address() + changeAddr := genesistest.DefaultFundedKeys[0].Address() // create valid tx - builder, txSigner := factory.NewWallet(genesistest.FundedKeys[0], genesistest.FundedKeys[1]) + builder, txSigner := factory.NewWallet(genesistest.DefaultFundedKeys[0], genesistest.DefaultFundedKeys[1]) utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID, @@ -314,7 +314,7 @@ func TestAddDelegatorTxHeapCorruption(t *testing.T) { }, &secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{genesistest.FundedKeys[0].Address()}, + Addrs: []ids.ShortID{genesistest.DefaultFundedKeys[0].Address()}, }, walletcommon.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, @@ -347,7 +347,7 @@ func TestAddDelegatorTxHeapCorruption(t *testing.T) { }, &secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{genesistest.FundedKeys[0].Address()}, + Addrs: []ids.ShortID{genesistest.DefaultFundedKeys[0].Address()}, }, walletcommon.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, @@ -380,7 +380,7 @@ func TestAddDelegatorTxHeapCorruption(t *testing.T) { }, &secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{genesistest.FundedKeys[0].Address()}, + Addrs: []ids.ShortID{genesistest.DefaultFundedKeys[0].Address()}, }, walletcommon.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, @@ -413,7 +413,7 @@ func TestAddDelegatorTxHeapCorruption(t *testing.T) { }, &secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{genesistest.FundedKeys[0].Address()}, + Addrs: []ids.ShortID{genesistest.DefaultFundedKeys[0].Address()}, }, walletcommon.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, @@ -469,7 +469,7 @@ func TestUnverifiedParentPanicRegression(t *testing.T) { context.Background(), ctx, baseDB, - genesistest.BuildBytes(t), + genesistest.NewBytes(t, genesistest.Config{}), nil, nil, msgChan, @@ -484,8 +484,8 @@ func TestUnverifiedParentPanicRegression(t *testing.T) { vm.clock.Set(latestForkTime.Add(time.Second)) vm.state.SetTimestamp(latestForkTime.Add(time.Second)) - key0 := genesistest.FundedKeys[0] - key1 := genesistest.FundedKeys[1] + key0 := genesistest.DefaultFundedKeys[0] + key1 := genesistest.DefaultFundedKeys[1] addr0 := key0.Address() addr1 := key1.Address() @@ -600,7 +600,7 @@ func TestRejectedStateRegressionInvalidValidatorTimestamp(t *testing.T) { newValidatorEndTime := newValidatorStartTime.Add(defaultMinStakingDuration) // Create the tx to add a new validator - builder, txSigner := factory.NewWallet(genesistest.FundedKeys[0]) + builder, txSigner := factory.NewWallet(genesistest.DefaultFundedKeys[0]) utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID, @@ -797,7 +797,7 @@ func TestRejectedStateRegressionInvalidValidatorReward(t *testing.T) { nodeID0 := ids.GenerateTestNodeID() // Create the tx to add the first new validator - builder, txSigner := factory.NewWallet(genesistest.FundedKeys[0]) + builder, txSigner := factory.NewWallet(genesistest.DefaultFundedKeys[0]) utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID0, @@ -966,7 +966,7 @@ func TestRejectedStateRegressionInvalidValidatorReward(t *testing.T) { nodeID1 := ids.GenerateTestNodeID() // Create the tx to add the second new validator - builder, txSigner = factory.NewWallet(genesistest.FundedKeys[1]) + builder, txSigner = factory.NewWallet(genesistest.DefaultFundedKeys[1]) utx1, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID1, @@ -1101,11 +1101,11 @@ func TestValidatorSetAtCacheOverwriteRegression(t *testing.T) { require.Equal(uint64(1), currentHeight) expectedValidators1 := map[ids.NodeID]uint64{ - genesistest.NodeIDs[0]: genesistest.ValidatorWeight2, - genesistest.NodeIDs[1]: genesistest.ValidatorWeight2, - genesistest.NodeIDs[2]: genesistest.ValidatorWeight2, - genesistest.NodeIDs[3]: genesistest.ValidatorWeight2, - genesistest.NodeIDs[4]: genesistest.ValidatorWeight2, + genesistest.DefaultNodeIDs[0]: genesistest.DefaultValidatorWeight, + genesistest.DefaultNodeIDs[1]: genesistest.DefaultValidatorWeight, + genesistest.DefaultNodeIDs[2]: genesistest.DefaultValidatorWeight, + genesistest.DefaultNodeIDs[3]: genesistest.DefaultValidatorWeight, + genesistest.DefaultNodeIDs[4]: genesistest.DefaultValidatorWeight, } validators, err := vm.GetValidatorSet(context.Background(), 1, constants.PrimaryNetworkID) require.NoError(err) @@ -1119,7 +1119,7 @@ func TestValidatorSetAtCacheOverwriteRegression(t *testing.T) { extraNodeID := ids.GenerateTestNodeID() // Create the tx to add the first new validator - builder, txSigner := factory.NewWallet(genesistest.FundedKeys[0]) + builder, txSigner := factory.NewWallet(genesistest.DefaultFundedKeys[0]) utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: extraNodeID, @@ -1205,12 +1205,12 @@ func TestValidatorSetAtCacheOverwriteRegression(t *testing.T) { } expectedValidators2 := map[ids.NodeID]uint64{ - genesistest.NodeIDs[0]: genesistest.ValidatorWeight2, - genesistest.NodeIDs[1]: genesistest.ValidatorWeight2, - genesistest.NodeIDs[2]: genesistest.ValidatorWeight2, - genesistest.NodeIDs[3]: genesistest.ValidatorWeight2, - genesistest.NodeIDs[4]: genesistest.ValidatorWeight2, - extraNodeID: vm.MaxValidatorStake, + genesistest.DefaultNodeIDs[0]: genesistest.DefaultValidatorWeight, + genesistest.DefaultNodeIDs[1]: genesistest.DefaultValidatorWeight, + genesistest.DefaultNodeIDs[2]: genesistest.DefaultValidatorWeight, + genesistest.DefaultNodeIDs[3]: genesistest.DefaultValidatorWeight, + genesistest.DefaultNodeIDs[4]: genesistest.DefaultValidatorWeight, + extraNodeID: vm.MaxValidatorStake, } validators, err = vm.GetValidatorSet(context.Background(), 3, constants.PrimaryNetworkID) require.NoError(err) @@ -1243,10 +1243,10 @@ func TestAddDelegatorTxAddBeforeRemove(t *testing.T) { id := key.Address() nodeID := ids.GenerateTestNodeID() - changeAddr := genesistest.FundedKeys[0].Address() + changeAddr := genesistest.DefaultFundedKeys[0].Address() // create valid tx - builder, txSigner := factory.NewWallet(genesistest.FundedKeys[0], genesistest.FundedKeys[1]) + builder, txSigner := factory.NewWallet(genesistest.DefaultFundedKeys[0], genesistest.DefaultFundedKeys[1]) utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID, @@ -1290,7 +1290,7 @@ func TestAddDelegatorTxAddBeforeRemove(t *testing.T) { }, &secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{genesistest.FundedKeys[0].Address()}, + Addrs: []ids.ShortID{genesistest.DefaultFundedKeys[0].Address()}, }, walletcommon.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, @@ -1323,7 +1323,7 @@ func TestAddDelegatorTxAddBeforeRemove(t *testing.T) { }, &secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{genesistest.FundedKeys[0].Address()}, + Addrs: []ids.ShortID{genesistest.DefaultFundedKeys[0].Address()}, }, walletcommon.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, @@ -1357,9 +1357,9 @@ func TestRemovePermissionedValidatorDuringPendingToCurrentTransitionNotTracked(t id := key.Address() nodeID := ids.GenerateTestNodeID() - changeAddr := genesistest.FundedKeys[0].Address() + changeAddr := genesistest.DefaultFundedKeys[0].Address() - builder, txSigner := factory.NewWallet(genesistest.FundedKeys[0], genesistest.FundedKeys[1]) + builder, txSigner := factory.NewWallet(genesistest.DefaultFundedKeys[0], genesistest.DefaultFundedKeys[1]) utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID, @@ -1506,9 +1506,9 @@ func TestRemovePermissionedValidatorDuringPendingToCurrentTransitionTracked(t *t id := key.Address() nodeID := ids.GenerateTestNodeID() - changeAddr := genesistest.FundedKeys[0].Address() + changeAddr := genesistest.DefaultFundedKeys[0].Address() - builder, txSigner := factory.NewWallet(genesistest.FundedKeys[0], genesistest.FundedKeys[1]) + builder, txSigner := factory.NewWallet(genesistest.DefaultFundedKeys[0], genesistest.DefaultFundedKeys[1]) utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID, @@ -1636,7 +1636,7 @@ func TestSubnetValidatorBLSKeyDiffAfterExpiry(t *testing.T) { subnetID := testSubnet1.TxID // setup time - currentTime := genesistest.Time + currentTime := genesistest.DefaultTime vm.clock.Set(currentTime) vm.state.SetTimestamp(currentTime) @@ -1653,13 +1653,13 @@ func TestSubnetValidatorBLSKeyDiffAfterExpiry(t *testing.T) { // insert primary network validator var ( nodeID = ids.GenerateTestNodeID() - addr = genesistest.FundedKeys[0].Address() + addr = genesistest.DefaultFundedKeys[0].Address() ) sk1, err := bls.NewSecretKey() require.NoError(err) // build primary network validator with BLS key - builder, txSigner := factory.NewWallet(genesistest.FundedKeys...) + builder, txSigner := factory.NewWallet(genesistest.DefaultFundedKeys...) uPrimaryTx, err := builder.NewAddPermissionlessValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -1708,7 +1708,7 @@ func TestSubnetValidatorBLSKeyDiffAfterExpiry(t *testing.T) { require.NoError(err) // insert the subnet validator - builder, txSigner = factory.NewWallet(genesistest.FundedKeys[0], genesistest.FundedKeys[1]) + builder, txSigner = factory.NewWallet(genesistest.DefaultFundedKeys[0], genesistest.DefaultFundedKeys[1]) uAddSubnetValTx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -1789,7 +1789,7 @@ func TestSubnetValidatorBLSKeyDiffAfterExpiry(t *testing.T) { require.NoError(err) require.NotEqual(sk1, sk2) - builder, txSigner = factory.NewWallet(genesistest.FundedKeys...) + builder, txSigner = factory.NewWallet(genesistest.DefaultFundedKeys...) uPrimaryRestartTx, err := builder.NewAddPermissionlessValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -1899,7 +1899,7 @@ func TestPrimaryNetworkValidatorPopulatedToEmptyBLSKeyDiff(t *testing.T) { defer vm.ctx.Lock.Unlock() // setup time - currentTime := genesistest.Time + currentTime := genesistest.DefaultTime vm.clock.Set(currentTime) vm.state.SetTimestamp(currentTime) @@ -1913,9 +1913,9 @@ func TestPrimaryNetworkValidatorPopulatedToEmptyBLSKeyDiff(t *testing.T) { // Add a primary network validator with no BLS key nodeID := ids.GenerateTestNodeID() - addr := genesistest.FundedKeys[0].Address() + addr := genesistest.DefaultFundedKeys[0].Address() - builder, txSigner := factory.NewWallet(genesistest.FundedKeys[0]) + builder, txSigner := factory.NewWallet(genesistest.DefaultFundedKeys[0]) uAddValTx1, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID, @@ -1985,7 +1985,7 @@ func TestPrimaryNetworkValidatorPopulatedToEmptyBLSKeyDiff(t *testing.T) { sk2, err := bls.NewSecretKey() require.NoError(err) - builder, txSigner = factory.NewWallet(genesistest.FundedKeys...) + builder, txSigner = factory.NewWallet(genesistest.DefaultFundedKeys...) uPrimaryRestartTx, err := builder.NewAddPermissionlessValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -2057,7 +2057,7 @@ func TestSubnetValidatorPopulatedToEmptyBLSKeyDiff(t *testing.T) { subnetID := testSubnet1.TxID // setup time - currentTime := genesistest.Time + currentTime := genesistest.DefaultTime vm.clock.Set(currentTime) vm.state.SetTimestamp(currentTime) @@ -2073,9 +2073,9 @@ func TestSubnetValidatorPopulatedToEmptyBLSKeyDiff(t *testing.T) { // Add a primary network validator with no BLS key nodeID := ids.GenerateTestNodeID() - addr := genesistest.FundedKeys[0].Address() + addr := genesistest.DefaultFundedKeys[0].Address() - builder, txSigner := factory.NewWallet(genesistest.FundedKeys[0]) + builder, txSigner := factory.NewWallet(genesistest.DefaultFundedKeys[0]) uPrimaryTx1, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID, @@ -2115,7 +2115,7 @@ func TestSubnetValidatorPopulatedToEmptyBLSKeyDiff(t *testing.T) { require.NoError(err) // insert the subnet validator - builder, txSigner = factory.NewWallet(genesistest.FundedKeys[0], genesistest.FundedKeys[1]) + builder, txSigner = factory.NewWallet(genesistest.DefaultFundedKeys[0], genesistest.DefaultFundedKeys[1]) uAddSubnetValTx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -2195,7 +2195,7 @@ func TestSubnetValidatorPopulatedToEmptyBLSKeyDiff(t *testing.T) { sk2, err := bls.NewSecretKey() require.NoError(err) - builder, txSigner = factory.NewWallet(genesistest.FundedKeys...) + builder, txSigner = factory.NewWallet(genesistest.DefaultFundedKeys...) uPrimaryRestartTx, err := builder.NewAddPermissionlessValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -2276,7 +2276,7 @@ func TestSubnetValidatorSetAfterPrimaryNetworkValidatorRemoval(t *testing.T) { subnetID := testSubnet1.TxID // setup time - currentTime := genesistest.Time + currentTime := genesistest.DefaultTime vm.clock.Set(currentTime) vm.state.SetTimestamp(currentTime) @@ -2290,9 +2290,9 @@ func TestSubnetValidatorSetAfterPrimaryNetworkValidatorRemoval(t *testing.T) { // Add a primary network validator with no BLS key nodeID := ids.GenerateTestNodeID() - addr := genesistest.FundedKeys[0].Address() + addr := genesistest.DefaultFundedKeys[0].Address() - builder, txSigner := factory.NewWallet(genesistest.FundedKeys[0]) + builder, txSigner := factory.NewWallet(genesistest.DefaultFundedKeys[0]) uPrimaryTx1, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID, @@ -2329,7 +2329,7 @@ func TestSubnetValidatorSetAfterPrimaryNetworkValidatorRemoval(t *testing.T) { require.NoError(err) // insert the subnet validator - builder, txSigner = factory.NewWallet(genesistest.FundedKeys[0], genesistest.FundedKeys[1]) + builder, txSigner = factory.NewWallet(genesistest.DefaultFundedKeys[0], genesistest.DefaultFundedKeys[1]) uAddSubnetValTx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ diff --git a/vms/platformvm/vm_test.go b/vms/platformvm/vm_test.go index 7d7ad1ee5584..14cde1200222 100644 --- a/vms/platformvm/vm_test.go +++ b/vms/platformvm/vm_test.go @@ -40,7 +40,6 @@ import ( "github.com/ava-labs/avalanchego/utils/constants" "github.com/ava-labs/avalanchego/utils/crypto/bls" "github.com/ava-labs/avalanchego/utils/crypto/secp256k1" - "github.com/ava-labs/avalanchego/utils/formatting/address" "github.com/ava-labs/avalanchego/utils/logging" "github.com/ava-labs/avalanchego/utils/math/meter" "github.com/ava-labs/avalanchego/utils/resource" @@ -93,7 +92,7 @@ var ( SupplyCap: 720 * units.MegaAvax, } - latestForkTime = genesistest.Time.Add(time.Second) + latestForkTime = genesistest.DefaultTime.Add(time.Second) defaultStaticFeeConfig = txfee.StaticConfig{ TxFee: defaultTxFee, @@ -119,7 +118,7 @@ var ( // Its controlKeys are keys[0], keys[1], keys[2] // Its threshold is 2 testSubnet1 *txs.Tx - testSubnet1ControlKeys = genesistest.FundedKeys[0:3] + testSubnet1ControlKeys = genesistest.DefaultFundedKeys[0:3] ) type mutableSharedMemory struct { @@ -131,7 +130,7 @@ func defaultVM(t *testing.T, f upgradetest.Fork) (*VM, *txstest.WalletFactory, d // always reset latestForkTime (a package level variable) // to ensure test independence - latestForkTime = genesistest.Time.Add(time.Second) + latestForkTime = genesistest.DefaultTime.Add(time.Second) vm := &VM{Config: config.Config{ Chains: chains.TestManager, UptimeLockedCalculator: uptime.NewLockedCalculator(), @@ -178,7 +177,7 @@ func defaultVM(t *testing.T, f upgradetest.Fork) (*VM, *txstest.WalletFactory, d context.Background(), ctx, chainDB, - genesistest.BuildBytes(t), + genesistest.NewBytes(t, genesistest.Config{}), nil, dynamicConfigBytes, msgChan, @@ -200,19 +199,19 @@ func defaultVM(t *testing.T, f upgradetest.Fork) (*VM, *txstest.WalletFactory, d // Create a subnet and store it in testSubnet1 // Note: following Banff activation, block acceptance will move // chain time ahead - builder, signer := factory.NewWallet(genesistest.FundedKeys[0]) + builder, signer := factory.NewWallet(genesistest.DefaultFundedKeys[0]) utx, err := builder.NewCreateSubnetTx( &secp256k1fx.OutputOwners{ Threshold: 2, Addrs: []ids.ShortID{ - genesistest.FundedKeys[0].Address(), - genesistest.FundedKeys[1].Address(), - genesistest.FundedKeys[2].Address(), + genesistest.DefaultFundedKeys[0].Address(), + genesistest.DefaultFundedKeys[1].Address(), + genesistest.DefaultFundedKeys[2].Address(), }, }, walletcommon.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{genesistest.FundedKeys[0].Address()}, + Addrs: []ids.ShortID{genesistest.DefaultFundedKeys[0].Address()}, }), ) require.NoError(err) @@ -254,35 +253,31 @@ func TestGenesis(t *testing.T) { require.NoError(err) require.NotNil(genesisBlock) - genesisState := genesistest.Build(t) + genesisState := genesistest.New(t, genesistest.Config{}) // Ensure all the genesis UTXOs are there for _, utxo := range genesisState.UTXOs { - _, addrBytes, err := address.ParseBech32(utxo.Address) - require.NoError(err) - - addr, err := ids.ToShortID(addrBytes) - require.NoError(err) - - addrs := set.Of(addr) - utxos, err := avax.GetAllUTXOs(vm.state, addrs) + genesisOut := utxo.Out.(*secp256k1fx.TransferOutput) + utxos, err := avax.GetAllUTXOs( + vm.state, + genesisOut.OutputOwners.AddressesSet(), + ) require.NoError(err) require.Len(utxos, 1) out := utxos[0].Out.(*secp256k1fx.TransferOutput) - if out.Amount() != uint64(utxo.Amount) { - id := genesistest.FundedKeys[0].Address() - addr, err := address.FormatBech32(constants.UnitTestHRP, id.Bytes()) - require.NoError(err) - - require.Equal(utxo.Address, addr) - require.Equal(uint64(utxo.Amount)-vm.StaticFeeConfig.CreateSubnetTxFee, out.Amount()) + if out.Amt != genesisOut.Amt { + require.Equal( + []ids.ShortID{genesistest.DefaultFundedKeys[0].Address()}, + out.OutputOwners.Addrs, + ) + require.Equal(genesisOut.Amt-vm.StaticFeeConfig.CreateSubnetTxFee, out.Amt) } } // Ensure current validator set of primary network is correct require.Len(genesisState.Validators, vm.Validators.Count(constants.PrimaryNetworkID)) - for _, nodeID := range genesistest.NodeIDs { + for _, nodeID := range genesistest.DefaultNodeIDs { _, ok := vm.Validators.GetValidator(constants.PrimaryNetworkID, nodeID) require.True(ok) } @@ -310,7 +305,7 @@ func TestAddValidatorCommit(t *testing.T) { require.NoError(err) // create valid tx - builder, txSigner := factory.NewWallet(genesistest.FundedKeys[0]) + builder, txSigner := factory.NewWallet(genesistest.DefaultFundedKeys[0]) utx, err := builder.NewAddPermissionlessValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -365,11 +360,11 @@ func TestInvalidAddValidatorCommit(t *testing.T) { defer vm.ctx.Lock.Unlock() nodeID := ids.GenerateTestNodeID() - startTime := genesistest.Time.Add(-txexecutor.SyncBound).Add(-1 * time.Second) + startTime := genesistest.DefaultTime.Add(-txexecutor.SyncBound).Add(-1 * time.Second) endTime := startTime.Add(defaultMinStakingDuration) // create invalid tx - builder, txSigner := factory.NewWallet(genesistest.FundedKeys[0]) + builder, txSigner := factory.NewWallet(genesistest.DefaultFundedKeys[0]) utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID, @@ -428,7 +423,7 @@ func TestAddValidatorReject(t *testing.T) { ) // create valid tx - builder, txSigner := factory.NewWallet(genesistest.FundedKeys[0]) + builder, txSigner := factory.NewWallet(genesistest.DefaultFundedKeys[0]) utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID, @@ -472,7 +467,7 @@ func TestAddValidatorInvalidNotReissued(t *testing.T) { defer vm.ctx.Lock.Unlock() // Use nodeID that is already in the genesis - repeatNodeID := genesistest.NodeIDs[0] + repeatNodeID := genesistest.DefaultNodeIDs[0] startTime := latestForkTime.Add(txexecutor.SyncBound).Add(1 * time.Second) endTime := startTime.Add(defaultMinStakingDuration) @@ -481,7 +476,7 @@ func TestAddValidatorInvalidNotReissued(t *testing.T) { require.NoError(err) // create valid tx - builder, txSigner := factory.NewWallet(genesistest.FundedKeys[0]) + builder, txSigner := factory.NewWallet(genesistest.DefaultFundedKeys[0]) utx, err := builder.NewAddPermissionlessValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -525,7 +520,7 @@ func TestAddSubnetValidatorAccept(t *testing.T) { var ( startTime = vm.clock.Time().Add(txexecutor.SyncBound).Add(1 * time.Second) endTime = startTime.Add(defaultMinStakingDuration) - nodeID = genesistest.NodeIDs[0] + nodeID = genesistest.DefaultNodeIDs[0] ) // create valid tx @@ -538,7 +533,7 @@ func TestAddSubnetValidatorAccept(t *testing.T) { NodeID: nodeID, Start: uint64(startTime.Unix()), End: uint64(endTime.Unix()), - Wght: genesistest.ValidatorWeight2, + Wght: genesistest.DefaultValidatorWeight, }, Subnet: testSubnet1.ID(), }, @@ -577,7 +572,7 @@ func TestAddSubnetValidatorReject(t *testing.T) { var ( startTime = vm.clock.Time().Add(txexecutor.SyncBound).Add(1 * time.Second) endTime = startTime.Add(defaultMinStakingDuration) - nodeID = genesistest.NodeIDs[0] + nodeID = genesistest.DefaultNodeIDs[0] ) // create valid tx @@ -590,7 +585,7 @@ func TestAddSubnetValidatorReject(t *testing.T) { NodeID: nodeID, Start: uint64(startTime.Unix()), End: uint64(endTime.Unix()), - Wght: genesistest.ValidatorWeight2, + Wght: genesistest.DefaultValidatorWeight, }, Subnet: testSubnet1.ID(), }, @@ -626,7 +621,7 @@ func TestRewardValidatorAccept(t *testing.T) { defer vm.ctx.Lock.Unlock() // Fast forward clock to time for genesis validators to leave - vm.clock.Set(genesistest.ValidatorEndTime) + vm.clock.Set(genesistest.DefaultValidatorEndTime) // Advance time and create proposal to reward a genesis validator blk, err := vm.Builder.BuildBlock(context.Background()) @@ -664,7 +659,7 @@ func TestRewardValidatorAccept(t *testing.T) { // Verify that chain's timestamp has advanced timestamp := vm.state.GetTimestamp() - require.Equal(genesistest.ValidatorEndTimeUnix, uint64(timestamp.Unix())) + require.Equal(genesistest.DefaultValidatorEndTimeUnix, uint64(timestamp.Unix())) // Verify that rewarded validator has been removed. // Note that test genesis has multiple validators @@ -694,7 +689,7 @@ func TestRewardValidatorReject(t *testing.T) { defer vm.ctx.Lock.Unlock() // Fast forward clock to time for genesis validators to leave - vm.clock.Set(genesistest.ValidatorEndTime) + vm.clock.Set(genesistest.DefaultValidatorEndTime) // Advance time and create proposal to reward a genesis validator blk, err := vm.Builder.BuildBlock(context.Background()) @@ -734,7 +729,7 @@ func TestRewardValidatorReject(t *testing.T) { // Verify that chain's timestamp has advanced timestamp := vm.state.GetTimestamp() - require.Equal(genesistest.ValidatorEndTimeUnix, uint64(timestamp.Unix())) + require.Equal(genesistest.DefaultValidatorEndTimeUnix, uint64(timestamp.Unix())) // Verify that rewarded validator has been removed. // Note that test genesis has multiple validators @@ -824,18 +819,18 @@ func TestCreateSubnet(t *testing.T) { vm.ctx.Lock.Lock() defer vm.ctx.Lock.Unlock() - builder, txSigner := factory.NewWallet(genesistest.FundedKeys[0]) + builder, txSigner := factory.NewWallet(genesistest.DefaultFundedKeys[0]) uCreateSubnetTx, err := builder.NewCreateSubnetTx( &secp256k1fx.OutputOwners{ Threshold: 1, Addrs: []ids.ShortID{ - genesistest.FundedKeys[0].Address(), - genesistest.FundedKeys[1].Address(), + genesistest.DefaultFundedKeys[0].Address(), + genesistest.DefaultFundedKeys[1].Address(), }, }, walletcommon.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{genesistest.FundedKeys[0].Address()}, + Addrs: []ids.ShortID{genesistest.DefaultFundedKeys[0].Address()}, }), ) require.NoError(err) @@ -864,7 +859,7 @@ func TestCreateSubnet(t *testing.T) { require.Contains(subnetIDs, subnetID) // Now that we've created a new subnet, add a validator to that subnet - nodeID := genesistest.NodeIDs[0] + nodeID := genesistest.DefaultNodeIDs[0] startTime := vm.clock.Time().Add(txexecutor.SyncBound).Add(1 * time.Second) endTime := startTime.Add(defaultMinStakingDuration) // [startTime, endTime] is subset of time keys[0] validates default subnet so tx is valid @@ -874,7 +869,7 @@ func TestCreateSubnet(t *testing.T) { NodeID: nodeID, Start: uint64(startTime.Unix()), End: uint64(endTime.Unix()), - Wght: genesistest.ValidatorWeight2, + Wght: genesistest.DefaultValidatorWeight, }, Subnet: subnetID, }, @@ -931,14 +926,14 @@ func TestAtomicImport(t *testing.T) { OutputIndex: 1, } amount := uint64(50000) - recipientKey := genesistest.FundedKeys[1] + recipientKey := genesistest.DefaultFundedKeys[1] m := atomic.NewMemory(prefixdb.New([]byte{5}, baseDB)) mutableSharedMemory.SharedMemory = m.NewSharedMemory(vm.ctx.ChainID) peerSharedMemory := m.NewSharedMemory(vm.ctx.XChainID) - builder, _ := factory.NewWallet(genesistest.FundedKeys[0]) + builder, _ := factory.NewWallet(genesistest.DefaultFundedKeys[0]) _, err := builder.NewImportTx( vm.ctx.XChainID, &secp256k1fx.OutputOwners{ @@ -1086,7 +1081,7 @@ func TestRestartFullyAccepted(t *testing.T) { firstCtx := snowtest.Context(t, snowtest.PChainID) - genesisBytes := genesistest.BuildBytes(t) + genesisBytes := genesistest.NewBytes(t, genesistest.Config{}) baseDB := memdb.New() atomicDB := prefixdb.New([]byte{1}, baseDB) @@ -1231,7 +1226,7 @@ func TestBootstrapPartiallyAccepted(t *testing.T) { context.Background(), ctx, vmDB, - genesistest.BuildBytes(t), + genesistest.NewBytes(t, genesistest.Config{}), nil, nil, msgChan, @@ -1573,7 +1568,7 @@ func TestUnverifiedParent(t *testing.T) { context.Background(), ctx, memdb.New(), - genesistest.BuildBytes(t), + genesistest.NewBytes(t, genesistest.Config{}), nil, nil, msgChan, @@ -1657,7 +1652,7 @@ func TestMaxStakeAmount(t *testing.T) { vm.ctx.Lock.Lock() defer vm.ctx.Lock.Unlock() - nodeID := genesistest.NodeIDs[0] + nodeID := genesistest.DefaultNodeIDs[0] tests := []struct { description string @@ -1666,23 +1661,23 @@ func TestMaxStakeAmount(t *testing.T) { }{ { description: "[validator.StartTime] == [startTime] < [endTime] == [validator.EndTime]", - startTime: genesistest.Time, - endTime: genesistest.ValidatorEndTime, + startTime: genesistest.DefaultTime, + endTime: genesistest.DefaultValidatorEndTime, }, { description: "[validator.StartTime] < [startTime] < [endTime] == [validator.EndTime]", - startTime: genesistest.Time.Add(time.Minute), - endTime: genesistest.ValidatorEndTime, + startTime: genesistest.DefaultTime.Add(time.Minute), + endTime: genesistest.DefaultValidatorEndTime, }, { description: "[validator.StartTime] == [startTime] < [endTime] < [validator.EndTime]", - startTime: genesistest.Time, - endTime: genesistest.ValidatorEndTime.Add(-time.Minute), + startTime: genesistest.DefaultTime, + endTime: genesistest.DefaultValidatorEndTime.Add(-time.Minute), }, { description: "[validator.StartTime] < [startTime] < [endTime] < [validator.EndTime]", - startTime: genesistest.Time.Add(time.Minute), - endTime: genesistest.ValidatorEndTime.Add(-time.Minute), + startTime: genesistest.DefaultTime.Add(time.Minute), + endTime: genesistest.DefaultValidatorEndTime.Add(-time.Minute), }, } @@ -1694,14 +1689,14 @@ func TestMaxStakeAmount(t *testing.T) { amount, err := txexecutor.GetMaxWeight(vm.state, staker, test.startTime, test.endTime) require.NoError(err) - require.Equal(genesistest.ValidatorWeight2, amount) + require.Equal(genesistest.DefaultValidatorWeight, amount) }) } } func TestUptimeDisallowedWithRestart(t *testing.T) { require := require.New(t) - latestForkTime = genesistest.Time.Add(defaultMinStakingDuration) + latestForkTime = genesistest.DefaultTime.Add(defaultMinStakingDuration) db := memdb.New() firstDB := prefixdb.New([]byte{}, db) @@ -1718,7 +1713,7 @@ func TestUptimeDisallowedWithRestart(t *testing.T) { firstCtx := snowtest.Context(t, snowtest.PChainID) firstCtx.Lock.Lock() - genesisBytes := genesistest.BuildBytes(t) + genesisBytes := genesistest.NewBytes(t, genesistest.Config{}) firstMsgChan := make(chan common.Message, 1) require.NoError(firstVM.Initialize( @@ -1741,8 +1736,8 @@ func TestUptimeDisallowedWithRestart(t *testing.T) { require.NoError(firstVM.SetState(context.Background(), snow.NormalOp)) // Fast forward clock so that validators meet 20% uptime required for reward - durationForReward := genesistest.ValidatorEndTime.Sub(genesistest.Time) * firstUptimePercentage / 100 - vmStopTime := genesistest.Time.Add(durationForReward) + durationForReward := genesistest.DefaultValidatorEndTime.Sub(genesistest.DefaultTime) * firstUptimePercentage / 100 + vmStopTime := genesistest.DefaultTime.Add(durationForReward) firstVM.clock.Set(vmStopTime) // Shutdown VM to stop all genesis validator uptime. @@ -1792,7 +1787,7 @@ func TestUptimeDisallowedWithRestart(t *testing.T) { require.NoError(secondVM.SetState(context.Background(), snow.NormalOp)) // after restart and change of uptime required for reward, push validators to their end of life - secondVM.clock.Set(genesistest.ValidatorEndTime) + secondVM.clock.Set(genesistest.DefaultValidatorEndTime) // evaluate a genesis validator for reward blk, err := secondVM.Builder.BuildBlock(context.Background()) @@ -1845,7 +1840,7 @@ func TestUptimeDisallowedWithRestart(t *testing.T) { func TestUptimeDisallowedAfterNeverConnecting(t *testing.T) { require := require.New(t) - latestForkTime = genesistest.Time.Add(defaultMinStakingDuration) + latestForkTime = genesistest.DefaultTime.Add(defaultMinStakingDuration) db := memdb.New() @@ -1871,7 +1866,7 @@ func TestUptimeDisallowedAfterNeverConnecting(t *testing.T) { context.Background(), ctx, db, - genesistest.BuildBytes(t), + genesistest.NewBytes(t, genesistest.Config{}), nil, nil, msgChan, @@ -1892,7 +1887,7 @@ func TestUptimeDisallowedAfterNeverConnecting(t *testing.T) { require.NoError(vm.SetState(context.Background(), snow.NormalOp)) // Fast forward clock to time for genesis validators to leave - vm.clock.Set(genesistest.ValidatorEndTime) + vm.clock.Set(genesistest.DefaultValidatorEndTime) // evaluate a genesis validator for reward blk, err := vm.Builder.BuildBlock(context.Background()) @@ -1961,7 +1956,7 @@ func TestRemovePermissionedValidatorDuringAddPending(t *testing.T) { sk, err := bls.NewSecretKey() require.NoError(err) - builder, txSigner := factory.NewWallet(genesistest.FundedKeys[0]) + builder, txSigner := factory.NewWallet(genesistest.DefaultFundedKeys[0]) uAddValTx, err := builder.NewAddPermissionlessValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -1985,7 +1980,7 @@ func TestRemovePermissionedValidatorDuringAddPending(t *testing.T) { reward.PercentDenominator, walletcommon.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{genesistest.FundedKeys[0].Address()}, + Addrs: []ids.ShortID{genesistest.DefaultFundedKeys[0].Address()}, }), ) require.NoError(err) @@ -2010,7 +2005,7 @@ func TestRemovePermissionedValidatorDuringAddPending(t *testing.T) { }, walletcommon.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{genesistest.FundedKeys[0].Address()}, + Addrs: []ids.ShortID{genesistest.DefaultFundedKeys[0].Address()}, }), ) require.NoError(err) @@ -2028,7 +2023,7 @@ func TestRemovePermissionedValidatorDuringAddPending(t *testing.T) { require.NoError(createSubnetBlock.Accept(context.Background())) require.NoError(vm.SetPreference(context.Background(), vm.manager.LastAccepted())) - builder, txSigner = factory.NewWallet(key, genesistest.FundedKeys[1]) + builder, txSigner = factory.NewWallet(key, genesistest.DefaultFundedKeys[1]) uAddSubnetValTx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -2041,20 +2036,20 @@ func TestRemovePermissionedValidatorDuringAddPending(t *testing.T) { }, walletcommon.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{genesistest.FundedKeys[1].Address()}, + Addrs: []ids.ShortID{genesistest.DefaultFundedKeys[1].Address()}, }), ) require.NoError(err) addSubnetValidatorTx, err := walletsigner.SignUnsigned(context.Background(), txSigner, uAddSubnetValTx) require.NoError(err) - builder, txSigner = factory.NewWallet(key, genesistest.FundedKeys[2]) + builder, txSigner = factory.NewWallet(key, genesistest.DefaultFundedKeys[2]) uRemoveSubnetValTx, err := builder.NewRemoveSubnetValidatorTx( nodeID, createSubnetTx.ID(), walletcommon.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{genesistest.FundedKeys[2].Address()}, + Addrs: []ids.ShortID{genesistest.DefaultFundedKeys[2].Address()}, }), ) require.NoError(err) @@ -2089,15 +2084,15 @@ func TestTransferSubnetOwnershipTx(t *testing.T) { vm.ctx.Lock.Lock() defer vm.ctx.Lock.Unlock() - builder, txSigner := factory.NewWallet(genesistest.FundedKeys[0]) + builder, txSigner := factory.NewWallet(genesistest.DefaultFundedKeys[0]) uCreateSubnetTx, err := builder.NewCreateSubnetTx( &secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{genesistest.FundedKeys[0].Address()}, + Addrs: []ids.ShortID{genesistest.DefaultFundedKeys[0].Address()}, }, walletcommon.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{genesistest.FundedKeys[0].Address()}, + Addrs: []ids.ShortID{genesistest.DefaultFundedKeys[0].Address()}, }), ) require.NoError(err) @@ -2126,7 +2121,7 @@ func TestTransferSubnetOwnershipTx(t *testing.T) { Locktime: 0, Threshold: 1, Addrs: []ids.ShortID{ - genesistest.FundedKeys[0].Address(), + genesistest.DefaultFundedKeys[0].Address(), }, } ctx, err := walletbuilder.NewSnowContext(vm.ctx.NetworkID, vm.ctx.AVAXAssetID) @@ -2138,7 +2133,7 @@ func TestTransferSubnetOwnershipTx(t *testing.T) { subnetID, &secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{genesistest.FundedKeys[1].Address()}, + Addrs: []ids.ShortID{genesistest.DefaultFundedKeys[1].Address()}, }, ) require.NoError(err) @@ -2165,7 +2160,7 @@ func TestTransferSubnetOwnershipTx(t *testing.T) { Locktime: 0, Threshold: 1, Addrs: []ids.ShortID{ - genesistest.FundedKeys[1].Address(), + genesistest.DefaultFundedKeys[1].Address(), }, } expectedOwner.InitCtx(ctx) @@ -2181,7 +2176,7 @@ func TestBaseTx(t *testing.T) { sendAmt := uint64(100000) changeAddr := ids.ShortEmpty - builder, txSigner := factory.NewWallet(genesistest.FundedKeys[0]) + builder, txSigner := factory.NewWallet(genesistest.DefaultFundedKeys[0]) utx, err := builder.NewBaseTx( []*avax.TransferableOutput{ { @@ -2191,7 +2186,7 @@ func TestBaseTx(t *testing.T) { OutputOwners: secp256k1fx.OutputOwners{ Threshold: 1, Addrs: []ids.ShortID{ - genesistest.FundedKeys[1].Address(), + genesistest.DefaultFundedKeys[1].Address(), }, }, }, @@ -2213,7 +2208,7 @@ func TestBaseTx(t *testing.T) { require.NoError(err) require.IsType(&secp256k1fx.TransferOutput{}, utxo.Out) castOut := utxo.Out.(*secp256k1fx.TransferOutput) - if castOut.AddressesSet().Equals(set.Of(genesistest.FundedKeys[0].Address())) { + if castOut.AddressesSet().Equals(set.Of(genesistest.DefaultFundedKeys[0].Address())) { key0InputAmt += castOut.Amt } totalInputAmt += castOut.Amt @@ -2227,10 +2222,10 @@ func TestBaseTx(t *testing.T) { for _, output := range baseTx.Unsigned.Outputs() { require.IsType(&secp256k1fx.TransferOutput{}, output.Out) castOut := output.Out.(*secp256k1fx.TransferOutput) - if castOut.AddressesSet().Equals(set.Of(genesistest.FundedKeys[0].Address())) { + if castOut.AddressesSet().Equals(set.Of(genesistest.DefaultFundedKeys[0].Address())) { key0OutputAmt += castOut.Amt } - if castOut.AddressesSet().Equals(set.Of(genesistest.FundedKeys[1].Address())) { + if castOut.AddressesSet().Equals(set.Of(genesistest.DefaultFundedKeys[1].Address())) { key1OutputAmt += castOut.Amt } if castOut.AddressesSet().Equals(set.Of(changeAddr)) { @@ -2268,7 +2263,7 @@ func TestPruneMempool(t *testing.T) { sendAmt := uint64(100000) changeAddr := ids.ShortEmpty - builder, txSigner := factory.NewWallet(genesistest.FundedKeys[0]) + builder, txSigner := factory.NewWallet(genesistest.DefaultFundedKeys[0]) utx, err := builder.NewBaseTx( []*avax.TransferableOutput{ { @@ -2278,7 +2273,7 @@ func TestPruneMempool(t *testing.T) { OutputOwners: secp256k1fx.OutputOwners{ Threshold: 1, Addrs: []ids.ShortID{ - genesistest.FundedKeys[1].Address(), + genesistest.DefaultFundedKeys[1].Address(), }, }, }, @@ -2311,7 +2306,7 @@ func TestPruneMempool(t *testing.T) { sk, err := bls.NewSecretKey() require.NoError(err) - builder, txSigner = factory.NewWallet(genesistest.FundedKeys[1]) + builder, txSigner = factory.NewWallet(genesistest.DefaultFundedKeys[1]) uAddValTx, err := builder.NewAddPermissionlessValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -2326,11 +2321,11 @@ func TestPruneMempool(t *testing.T) { vm.ctx.AVAXAssetID, &secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{genesistest.FundedKeys[2].Address()}, + Addrs: []ids.ShortID{genesistest.DefaultFundedKeys[2].Address()}, }, &secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{genesistest.FundedKeys[2].Address()}, + Addrs: []ids.ShortID{genesistest.DefaultFundedKeys[2].Address()}, }, 20000, ) From 49d85ca4fb28711c0161579794e274811114d95a Mon Sep 17 00:00:00 2001 From: Stephen Buttolph Date: Thu, 22 Aug 2024 18:57:08 -0400 Subject: [PATCH 24/27] reduce diff --- scripts/build_test.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/build_test.sh b/scripts/build_test.sh index e22ed9f1df42..4a7cbd04f746 100755 --- a/scripts/build_test.sh +++ b/scripts/build_test.sh @@ -18,4 +18,4 @@ fi TEST_TARGETS="$(eval "go list ./... ${EXCLUDED_TARGETS}")" # shellcheck disable=SC2086 -go test -tags test -shuffle=on -timeout="${TIMEOUT:-120s}" -coverprofile="coverage.out" -covermode="atomic" ${TEST_TARGETS} +go test -tags test -shuffle=on -race -timeout="${TIMEOUT:-120s}" -coverprofile="coverage.out" -covermode="atomic" ${TEST_TARGETS} From c247d51333e16a400d087cf22e5ed992b746dfe2 Mon Sep 17 00:00:00 2001 From: Stephen Buttolph Date: Thu, 22 Aug 2024 19:03:40 -0400 Subject: [PATCH 25/27] nit --- .../block/executor/proposal_block_test.go | 16 ++++++++-------- .../block/executor/standard_block_test.go | 6 +++--- vms/platformvm/txs/executor/advance_time_test.go | 6 +++--- vms/platformvm/txs/executor/create_chain_test.go | 2 +- vms/platformvm/validator_set_property_test.go | 4 ++-- vms/platformvm/vm_regression_test.go | 16 ++++++++-------- 6 files changed, 25 insertions(+), 25 deletions(-) diff --git a/vms/platformvm/block/executor/proposal_block_test.go b/vms/platformvm/block/executor/proposal_block_test.go index 22bcda3a7274..69576ce999a4 100644 --- a/vms/platformvm/block/executor/proposal_block_test.go +++ b/vms/platformvm/block/executor/proposal_block_test.go @@ -554,7 +554,7 @@ func TestBanffProposalBlockUpdateStakers(t *testing.T) { } for _, subStaker := range test.subnetStakers { - builder, signer := env.factory.NewWallet(genesistest.DefaultFundedKeys[0], genesistest.DefaultFundedKeys[1]) + builder, signer := env.factory.NewWallet(genesistest.DefaultFundedKeys[:2]...) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -591,7 +591,7 @@ func TestBanffProposalBlockUpdateStakers(t *testing.T) { // add Staker0 (with the right end time) to state // so to allow proposalBlk issuance staker0.endTime = newTime - builder, signer := env.factory.NewWallet(genesistest.DefaultFundedKeys[0], genesistest.DefaultFundedKeys[1]) + builder, signer := env.factory.NewWallet(genesistest.DefaultFundedKeys[:2]...) utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: staker0.nodeID, @@ -700,7 +700,7 @@ func TestBanffProposalBlockRemoveSubnetValidator(t *testing.T) { // Add a subnet validator to the staker set subnetValidatorNodeID := genesistest.DefaultNodeIDs[0] subnetVdr1EndTime := genesistest.DefaultTime.Add(defaultMinStakingDuration) - builder, signer := env.factory.NewWallet(genesistest.DefaultFundedKeys[0], genesistest.DefaultFundedKeys[1]) + builder, signer := env.factory.NewWallet(genesistest.DefaultFundedKeys[:2]...) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -859,7 +859,7 @@ func TestBanffProposalBlockTrackedSubnet(t *testing.T) { subnetVdr1StartTime := genesistest.DefaultTime.Add(1 * time.Minute) subnetVdr1EndTime := genesistest.DefaultTime.Add(10 * defaultMinStakingDuration).Add(1 * time.Minute) - builder, signer := env.factory.NewWallet(genesistest.DefaultFundedKeys[0], genesistest.DefaultFundedKeys[1]) + builder, signer := env.factory.NewWallet(genesistest.DefaultFundedKeys[:2]...) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -983,7 +983,7 @@ func TestBanffProposalBlockDelegatorStakerWeight(t *testing.T) { // just to allow proposalBlk issuance (with a reward Tx) staker0StartTime := genesistest.DefaultTime staker0EndTime := pendingValidatorStartTime - builder, signer := env.factory.NewWallet(genesistest.DefaultFundedKeys[0], genesistest.DefaultFundedKeys[1]) + builder, signer := env.factory.NewWallet(genesistest.DefaultFundedKeys[:2]...) utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: ids.GenerateTestNodeID(), @@ -1085,7 +1085,7 @@ func TestBanffProposalBlockDelegatorStakerWeight(t *testing.T) { // add Staker0 (with the right end time) to state // so to allow proposalBlk issuance staker0EndTime = pendingDelegatorStartTime - builder, signer = env.factory.NewWallet(genesistest.DefaultFundedKeys[0], genesistest.DefaultFundedKeys[1]) + builder, signer = env.factory.NewWallet(genesistest.DefaultFundedKeys[:2]...) utx, err = builder.NewAddValidatorTx( &txs.Validator{ NodeID: ids.GenerateTestNodeID(), @@ -1180,7 +1180,7 @@ func TestBanffProposalBlockDelegatorStakers(t *testing.T) { // so to allow proposalBlk issuance staker0StartTime := genesistest.DefaultTime staker0EndTime := pendingValidatorStartTime - builder, txSigner := env.factory.NewWallet(genesistest.DefaultFundedKeys[0], genesistest.DefaultFundedKeys[1]) + builder, txSigner := env.factory.NewWallet(genesistest.DefaultFundedKeys[:2]...) utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: ids.GenerateTestNodeID(), @@ -1281,7 +1281,7 @@ func TestBanffProposalBlockDelegatorStakers(t *testing.T) { // add Staker0 (with the right end time) to state // so to allow proposalBlk issuance staker0EndTime = pendingDelegatorStartTime - builder, txSigner = env.factory.NewWallet(genesistest.DefaultFundedKeys[0], genesistest.DefaultFundedKeys[1]) + builder, txSigner = env.factory.NewWallet(genesistest.DefaultFundedKeys[:2]...) utx, err = builder.NewAddValidatorTx( &txs.Validator{ NodeID: ids.GenerateTestNodeID(), diff --git a/vms/platformvm/block/executor/standard_block_test.go b/vms/platformvm/block/executor/standard_block_test.go index 4da0c48831a5..08a6f56daab1 100644 --- a/vms/platformvm/block/executor/standard_block_test.go +++ b/vms/platformvm/block/executor/standard_block_test.go @@ -512,7 +512,7 @@ func TestBanffStandardBlockUpdateStakers(t *testing.T) { } for _, staker := range test.subnetStakers { - builder, signer := env.factory.NewWallet(genesistest.DefaultFundedKeys[0], genesistest.DefaultFundedKeys[1]) + builder, signer := env.factory.NewWallet(genesistest.DefaultFundedKeys[:2]...) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -605,7 +605,7 @@ func TestBanffStandardBlockRemoveSubnetValidator(t *testing.T) { // Add a subnet validator to the staker set subnetValidatorNodeID := genesistest.DefaultNodeIDs[0] subnetVdr1EndTime := genesistest.DefaultTime.Add(defaultMinStakingDuration) - builder, signer := env.factory.NewWallet(genesistest.DefaultFundedKeys[0], genesistest.DefaultFundedKeys[1]) + builder, signer := env.factory.NewWallet(genesistest.DefaultFundedKeys[:2]...) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -711,7 +711,7 @@ func TestBanffStandardBlockTrackedSubnet(t *testing.T) { subnetValidatorNodeID := genesistest.DefaultNodeIDs[0] subnetVdr1StartTime := genesistest.DefaultTime.Add(1 * time.Minute) subnetVdr1EndTime := genesistest.DefaultTime.Add(10 * defaultMinStakingDuration).Add(1 * time.Minute) - builder, signer := env.factory.NewWallet(genesistest.DefaultFundedKeys[0], genesistest.DefaultFundedKeys[1]) + builder, signer := env.factory.NewWallet(genesistest.DefaultFundedKeys[:2]...) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ diff --git a/vms/platformvm/txs/executor/advance_time_test.go b/vms/platformvm/txs/executor/advance_time_test.go index 5f25a074a3e9..f98f30e6ce6d 100644 --- a/vms/platformvm/txs/executor/advance_time_test.go +++ b/vms/platformvm/txs/executor/advance_time_test.go @@ -389,7 +389,7 @@ func TestAdvanceTimeTxUpdateStakers(t *testing.T) { } for _, staker := range test.subnetStakers { - builder, signer := env.factory.NewWallet(genesistest.DefaultFundedKeys[0], genesistest.DefaultFundedKeys[1]) + builder, signer := env.factory.NewWallet(genesistest.DefaultFundedKeys[:2]...) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -490,7 +490,7 @@ func TestAdvanceTimeTxRemoveSubnetValidator(t *testing.T) { subnetValidatorNodeID := genesistest.DefaultNodeIDs[0] subnetVdr1EndTime := genesistest.DefaultTime.Add(defaultMinStakingDuration) - builder, signer := env.factory.NewWallet(genesistest.DefaultFundedKeys[0], genesistest.DefaultFundedKeys[1]) + builder, signer := env.factory.NewWallet(genesistest.DefaultFundedKeys[:2]...) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -606,7 +606,7 @@ func TestTrackedSubnet(t *testing.T) { subnetVdr1StartTime := genesistest.DefaultTime.Add(1 * time.Minute) subnetVdr1EndTime := genesistest.DefaultTime.Add(10 * defaultMinStakingDuration).Add(1 * time.Minute) - builder, signer := env.factory.NewWallet(genesistest.DefaultFundedKeys[0], genesistest.DefaultFundedKeys[1]) + builder, signer := env.factory.NewWallet(genesistest.DefaultFundedKeys[:2]...) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ diff --git a/vms/platformvm/txs/executor/create_chain_test.go b/vms/platformvm/txs/executor/create_chain_test.go index 80bf9d669665..ffbfe73d4b8d 100644 --- a/vms/platformvm/txs/executor/create_chain_test.go +++ b/vms/platformvm/txs/executor/create_chain_test.go @@ -35,7 +35,7 @@ func TestCreateChainTxInsufficientControlSigs(t *testing.T) { env.ctx.Lock.Lock() defer env.ctx.Lock.Unlock() - builder, signer := env.factory.NewWallet(genesistest.DefaultFundedKeys[0], genesistest.DefaultFundedKeys[1]) + builder, signer := env.factory.NewWallet(genesistest.DefaultFundedKeys[:2]...) utx, err := builder.NewCreateChainTx( testSubnet1.ID(), nil, diff --git a/vms/platformvm/validator_set_property_test.go b/vms/platformvm/validator_set_property_test.go index b739de466bb1..b0595a760359 100644 --- a/vms/platformvm/validator_set_property_test.go +++ b/vms/platformvm/validator_set_property_test.go @@ -256,7 +256,7 @@ func takeValidatorsSnapshotAtCurrentHeight(vm *VM, validatorsSetByHeightAndSubne func addSubnetValidator(vm *VM, data *validatorInputData, subnetID ids.ID) (*state.Staker, error) { factory := txstest.NewWalletFactory(vm.ctx, &vm.Config, vm.state) - builder, signer := factory.NewWallet(genesistest.DefaultFundedKeys[0], genesistest.DefaultFundedKeys[1]) + builder, signer := factory.NewWallet(genesistest.DefaultFundedKeys[:2]...) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -291,7 +291,7 @@ func addPrimaryValidatorWithBLSKey(vm *VM, data *validatorInputData) (*state.Sta } factory := txstest.NewWalletFactory(vm.ctx, &vm.Config, vm.state) - builder, txSigner := factory.NewWallet(genesistest.DefaultFundedKeys[0], genesistest.DefaultFundedKeys[1]) + builder, txSigner := factory.NewWallet(genesistest.DefaultFundedKeys[:2]...) utx, err := builder.NewAddPermissionlessValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ diff --git a/vms/platformvm/vm_regression_test.go b/vms/platformvm/vm_regression_test.go index 5d39be736fc1..86cddabd3e38 100644 --- a/vms/platformvm/vm_regression_test.go +++ b/vms/platformvm/vm_regression_test.go @@ -107,7 +107,7 @@ func TestAddDelegatorTxOverDelegatedRegression(t *testing.T) { firstDelegatorEndTime := firstDelegatorStartTime.Add(vm.MinStakeDuration) // create valid tx - builder, txSigner = factory.NewWallet(genesistest.DefaultFundedKeys[0], genesistest.DefaultFundedKeys[1]) + builder, txSigner = factory.NewWallet(genesistest.DefaultFundedKeys[:2]...) uDelTx1, err := builder.NewAddDelegatorTx( &txs.Validator{ NodeID: nodeID, @@ -270,7 +270,7 @@ func TestAddDelegatorTxHeapCorruption(t *testing.T) { changeAddr := genesistest.DefaultFundedKeys[0].Address() // create valid tx - builder, txSigner := factory.NewWallet(genesistest.DefaultFundedKeys[0], genesistest.DefaultFundedKeys[1]) + builder, txSigner := factory.NewWallet(genesistest.DefaultFundedKeys[:2]...) utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID, @@ -1246,7 +1246,7 @@ func TestAddDelegatorTxAddBeforeRemove(t *testing.T) { changeAddr := genesistest.DefaultFundedKeys[0].Address() // create valid tx - builder, txSigner := factory.NewWallet(genesistest.DefaultFundedKeys[0], genesistest.DefaultFundedKeys[1]) + builder, txSigner := factory.NewWallet(genesistest.DefaultFundedKeys[:2]...) utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID, @@ -1359,7 +1359,7 @@ func TestRemovePermissionedValidatorDuringPendingToCurrentTransitionNotTracked(t nodeID := ids.GenerateTestNodeID() changeAddr := genesistest.DefaultFundedKeys[0].Address() - builder, txSigner := factory.NewWallet(genesistest.DefaultFundedKeys[0], genesistest.DefaultFundedKeys[1]) + builder, txSigner := factory.NewWallet(genesistest.DefaultFundedKeys[:2]...) utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID, @@ -1508,7 +1508,7 @@ func TestRemovePermissionedValidatorDuringPendingToCurrentTransitionTracked(t *t nodeID := ids.GenerateTestNodeID() changeAddr := genesistest.DefaultFundedKeys[0].Address() - builder, txSigner := factory.NewWallet(genesistest.DefaultFundedKeys[0], genesistest.DefaultFundedKeys[1]) + builder, txSigner := factory.NewWallet(genesistest.DefaultFundedKeys[:2]...) utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID, @@ -1708,7 +1708,7 @@ func TestSubnetValidatorBLSKeyDiffAfterExpiry(t *testing.T) { require.NoError(err) // insert the subnet validator - builder, txSigner = factory.NewWallet(genesistest.DefaultFundedKeys[0], genesistest.DefaultFundedKeys[1]) + builder, txSigner = factory.NewWallet(genesistest.DefaultFundedKeys[:2]...) uAddSubnetValTx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -2115,7 +2115,7 @@ func TestSubnetValidatorPopulatedToEmptyBLSKeyDiff(t *testing.T) { require.NoError(err) // insert the subnet validator - builder, txSigner = factory.NewWallet(genesistest.DefaultFundedKeys[0], genesistest.DefaultFundedKeys[1]) + builder, txSigner = factory.NewWallet(genesistest.DefaultFundedKeys[:2]...) uAddSubnetValTx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -2329,7 +2329,7 @@ func TestSubnetValidatorSetAfterPrimaryNetworkValidatorRemoval(t *testing.T) { require.NoError(err) // insert the subnet validator - builder, txSigner = factory.NewWallet(genesistest.DefaultFundedKeys[0], genesistest.DefaultFundedKeys[1]) + builder, txSigner = factory.NewWallet(genesistest.DefaultFundedKeys[:2]...) uAddSubnetValTx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ From b1626a3f7f06caeabaf06f60fb1b30569f1e3f62 Mon Sep 17 00:00:00 2001 From: Stephen Buttolph Date: Thu, 22 Aug 2024 21:37:14 -0400 Subject: [PATCH 26/27] rename --- vms/platformvm/block/builder/helpers_test.go | 2 +- vms/platformvm/block/executor/helpers_test.go | 2 +- .../block/executor/proposal_block_test.go | 28 ++++----- .../block/executor/standard_block_test.go | 16 ++--- .../block/executor/verifier_test.go | 8 +-- vms/platformvm/genesis/genesistest/genesis.go | 24 +++---- vms/platformvm/service_test.go | 18 +++--- .../txs/executor/advance_time_test.go | 22 +++---- .../txs/executor/create_chain_test.go | 4 +- .../txs/executor/create_subnet_test.go | 4 +- vms/platformvm/txs/executor/export_test.go | 2 +- vms/platformvm/txs/executor/helpers_test.go | 4 +- .../txs/executor/proposal_tx_executor_test.go | 56 ++++++++--------- .../txs/executor/reward_validator_test.go | 16 ++--- .../txs/executor/standard_tx_executor_test.go | 62 +++++++++---------- vms/platformvm/validator_set_property_test.go | 6 +- .../validators/manager_benchmark_test.go | 6 +- vms/platformvm/vm_regression_test.go | 10 +-- vms/platformvm/vm_test.go | 22 +++---- 19 files changed, 156 insertions(+), 156 deletions(-) diff --git a/vms/platformvm/block/builder/helpers_test.go b/vms/platformvm/block/builder/helpers_test.go index 56b38828de9c..79b4453f6aa0 100644 --- a/vms/platformvm/block/builder/helpers_test.go +++ b/vms/platformvm/block/builder/helpers_test.go @@ -283,7 +283,7 @@ func defaultConfig(f upgradetest.Fork) *config.Config { func defaultClock() *mockable.Clock { // set time after Banff fork (and before default nextStakerTime) clk := &mockable.Clock{} - clk.Set(genesistest.DefaultTime) + clk.Set(genesistest.DefaultValidatorStartTime) return clk } diff --git a/vms/platformvm/block/executor/helpers_test.go b/vms/platformvm/block/executor/helpers_test.go index 661f1d801fbb..947fd15a8691 100644 --- a/vms/platformvm/block/executor/helpers_test.go +++ b/vms/platformvm/block/executor/helpers_test.go @@ -307,7 +307,7 @@ func defaultConfig(f upgradetest.Fork) *config.Config { func defaultClock() *mockable.Clock { clk := &mockable.Clock{} - clk.Set(genesistest.DefaultTime) + clk.Set(genesistest.DefaultValidatorStartTime) return clk } diff --git a/vms/platformvm/block/executor/proposal_block_test.go b/vms/platformvm/block/executor/proposal_block_test.go index de6c40a00cdb..1060c1c59be0 100644 --- a/vms/platformvm/block/executor/proposal_block_test.go +++ b/vms/platformvm/block/executor/proposal_block_test.go @@ -146,7 +146,7 @@ func TestBanffProposalBlockTimeVerification(t *testing.T) { env := newEnvironment(t, ctrl, upgradetest.Banff) // create parentBlock. It's a standard one for simplicity - parentTime := genesistest.DefaultTime + parentTime := genesistest.DefaultValidatorStartTime parentHeight := uint64(2022) banffParentBlk, err := block.NewApricotStandardBlock( @@ -376,15 +376,15 @@ func TestBanffProposalBlockUpdateStakers(t *testing.T) { staker0 := staker{ nodeID: ids.BuildTestNodeID([]byte{0xf0}), rewardAddress: ids.ShortID{0xf0}, - startTime: genesistest.DefaultTime, + startTime: genesistest.DefaultValidatorStartTime, endTime: time.Time{}, // actual endTime depends on specific test } staker1 := staker{ nodeID: ids.BuildTestNodeID([]byte{0xf1}), rewardAddress: ids.ShortID{0xf1}, - startTime: genesistest.DefaultTime.Add(1 * time.Minute), - endTime: genesistest.DefaultTime.Add(10 * defaultMinStakingDuration).Add(1 * time.Minute), + startTime: genesistest.DefaultValidatorStartTime.Add(1 * time.Minute), + endTime: genesistest.DefaultValidatorStartTime.Add(10 * defaultMinStakingDuration).Add(1 * time.Minute), } staker2 := staker{ nodeID: ids.BuildTestNodeID([]byte{0xf2}), @@ -700,13 +700,13 @@ func TestBanffProposalBlockRemoveSubnetValidator(t *testing.T) { // Add a subnet validator to the staker set subnetValidatorNodeID := genesistest.DefaultNodeIDs[0] - subnetVdr1EndTime := genesistest.DefaultTime.Add(defaultMinStakingDuration) + subnetVdr1EndTime := genesistest.DefaultValidatorStartTime.Add(defaultMinStakingDuration) builder, signer := env.factory.NewWallet(genesistest.DefaultFundedKeys[:2]...) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: subnetValidatorNodeID, - Start: genesistest.DefaultTimeUnix, + Start: genesistest.DefaultValidatorStartTimeUnix, End: uint64(subnetVdr1EndTime.Unix()), Wght: 1, }, @@ -770,7 +770,7 @@ func TestBanffProposalBlockRemoveSubnetValidator(t *testing.T) { uVdrTx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: ids.GenerateTestNodeID(), - Start: genesistest.DefaultTimeUnix, + Start: genesistest.DefaultValidatorStartTimeUnix, End: uint64(staker0EndTime.Unix()), Wght: 10, }, @@ -857,8 +857,8 @@ func TestBanffProposalBlockTrackedSubnet(t *testing.T) { // Add a subnet validator to the staker set subnetValidatorNodeID := genesistest.DefaultNodeIDs[0] - subnetVdr1StartTime := genesistest.DefaultTime.Add(1 * time.Minute) - subnetVdr1EndTime := genesistest.DefaultTime.Add(10 * defaultMinStakingDuration).Add(1 * time.Minute) + subnetVdr1StartTime := genesistest.DefaultValidatorStartTime.Add(1 * time.Minute) + subnetVdr1EndTime := genesistest.DefaultValidatorStartTime.Add(10 * defaultMinStakingDuration).Add(1 * time.Minute) builder, signer := env.factory.NewWallet(genesistest.DefaultFundedKeys[:2]...) utx, err := builder.NewAddSubnetValidatorTx( @@ -891,7 +891,7 @@ func TestBanffProposalBlockTrackedSubnet(t *testing.T) { // add Staker0 (with the right end time) to state // so to allow proposalBlk issuance - staker0StartTime := genesistest.DefaultTime + staker0StartTime := genesistest.DefaultValidatorStartTime staker0EndTime := subnetVdr1StartTime uVdrTx, err := builder.NewAddValidatorTx( @@ -966,7 +966,7 @@ func TestBanffProposalBlockDelegatorStakerWeight(t *testing.T) { // Case: Timestamp is after next validator start time // Add a pending validator - pendingValidatorStartTime := genesistest.DefaultTime.Add(1 * time.Second) + pendingValidatorStartTime := genesistest.DefaultValidatorStartTime.Add(1 * time.Second) pendingValidatorEndTime := pendingValidatorStartTime.Add(defaultMaxStakingDuration) nodeID := ids.GenerateTestNodeID() rewardAddress := ids.GenerateTestShortID() @@ -982,7 +982,7 @@ func TestBanffProposalBlockDelegatorStakerWeight(t *testing.T) { // add Staker0 (with the right end time) to state // just to allow proposalBlk issuance (with a reward Tx) - staker0StartTime := genesistest.DefaultTime + staker0StartTime := genesistest.DefaultValidatorStartTime staker0EndTime := pendingValidatorStartTime builder, signer := env.factory.NewWallet(genesistest.DefaultFundedKeys[:2]...) utx, err := builder.NewAddValidatorTx( @@ -1161,7 +1161,7 @@ func TestBanffProposalBlockDelegatorStakers(t *testing.T) { // Case: Timestamp is after next validator start time // Add a pending validator - pendingValidatorStartTime := genesistest.DefaultTime.Add(1 * time.Second) + pendingValidatorStartTime := genesistest.DefaultValidatorStartTime.Add(1 * time.Second) pendingValidatorEndTime := pendingValidatorStartTime.Add(defaultMinStakingDuration) nodeIDKey, _ := secp256k1.NewPrivateKey() rewardAddress := nodeIDKey.Address() @@ -1179,7 +1179,7 @@ func TestBanffProposalBlockDelegatorStakers(t *testing.T) { // add Staker0 (with the right end time) to state // so to allow proposalBlk issuance - staker0StartTime := genesistest.DefaultTime + staker0StartTime := genesistest.DefaultValidatorStartTime staker0EndTime := pendingValidatorStartTime builder, txSigner := env.factory.NewWallet(genesistest.DefaultFundedKeys[:2]...) utx, err := builder.NewAddValidatorTx( diff --git a/vms/platformvm/block/executor/standard_block_test.go b/vms/platformvm/block/executor/standard_block_test.go index 9d5e1db3ffe1..3b9b55408ef1 100644 --- a/vms/platformvm/block/executor/standard_block_test.go +++ b/vms/platformvm/block/executor/standard_block_test.go @@ -298,7 +298,7 @@ func TestBanffStandardBlockUpdatePrimaryNetworkStakers(t *testing.T) { // Case: Timestamp is after next validator start time // Add a pending validator - pendingValidatorStartTime := genesistest.DefaultTime.Add(1 * time.Second) + pendingValidatorStartTime := genesistest.DefaultValidatorStartTime.Add(1 * time.Second) pendingValidatorEndTime := pendingValidatorStartTime.Add(defaultMinStakingDuration) nodeID := ids.GenerateTestNodeID() rewardAddress := ids.GenerateTestShortID() @@ -365,8 +365,8 @@ func TestBanffStandardBlockUpdateStakers(t *testing.T) { staker1 := staker{ nodeID: ids.BuildTestNodeID([]byte{0xf1}), rewardAddress: ids.ShortID{0xf1}, - startTime: genesistest.DefaultTime.Add(1 * time.Minute), - endTime: genesistest.DefaultTime.Add(10 * defaultMinStakingDuration).Add(1 * time.Minute), + startTime: genesistest.DefaultValidatorStartTime.Add(1 * time.Minute), + endTime: genesistest.DefaultValidatorStartTime.Add(10 * defaultMinStakingDuration).Add(1 * time.Minute), } staker2 := staker{ nodeID: ids.BuildTestNodeID([]byte{0xf2}), @@ -605,13 +605,13 @@ func TestBanffStandardBlockRemoveSubnetValidator(t *testing.T) { // Add a subnet validator to the staker set subnetValidatorNodeID := genesistest.DefaultNodeIDs[0] - subnetVdr1EndTime := genesistest.DefaultTime.Add(defaultMinStakingDuration) + subnetVdr1EndTime := genesistest.DefaultValidatorStartTime.Add(defaultMinStakingDuration) builder, signer := env.factory.NewWallet(genesistest.DefaultFundedKeys[:2]...) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: subnetValidatorNodeID, - Start: genesistest.DefaultTimeUnix, + Start: genesistest.DefaultValidatorStartTimeUnix, End: uint64(subnetVdr1EndTime.Unix()), Wght: 1, }, @@ -710,8 +710,8 @@ func TestBanffStandardBlockTrackedSubnet(t *testing.T) { // Add a subnet validator to the staker set subnetValidatorNodeID := genesistest.DefaultNodeIDs[0] - subnetVdr1StartTime := genesistest.DefaultTime.Add(1 * time.Minute) - subnetVdr1EndTime := genesistest.DefaultTime.Add(10 * defaultMinStakingDuration).Add(1 * time.Minute) + subnetVdr1StartTime := genesistest.DefaultValidatorStartTime.Add(1 * time.Minute) + subnetVdr1EndTime := genesistest.DefaultValidatorStartTime.Add(10 * defaultMinStakingDuration).Add(1 * time.Minute) builder, signer := env.factory.NewWallet(genesistest.DefaultFundedKeys[:2]...) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ @@ -769,7 +769,7 @@ func TestBanffStandardBlockDelegatorStakerWeight(t *testing.T) { // Case: Timestamp is after next validator start time // Add a pending validator - pendingValidatorStartTime := genesistest.DefaultTime.Add(1 * time.Second) + pendingValidatorStartTime := genesistest.DefaultValidatorStartTime.Add(1 * time.Second) pendingValidatorEndTime := pendingValidatorStartTime.Add(defaultMaxStakingDuration) nodeID := ids.GenerateTestNodeID() rewardAddress := ids.GenerateTestShortID() diff --git a/vms/platformvm/block/executor/verifier_test.go b/vms/platformvm/block/executor/verifier_test.go index bab6be40299d..d2b131a3f2a3 100644 --- a/vms/platformvm/block/executor/verifier_test.go +++ b/vms/platformvm/block/executor/verifier_test.go @@ -470,7 +470,7 @@ func TestVerifyUnverifiedParent(t *testing.T) { func TestBanffAbortBlockTimestampChecks(t *testing.T) { ctrl := gomock.NewController(t) - now := genesistest.DefaultTime.Add(time.Hour) + now := genesistest.DefaultValidatorStartTime.Add(time.Hour) tests := []struct { description string @@ -533,7 +533,7 @@ func TestBanffAbortBlockTimestampChecks(t *testing.T) { require.NoError(err) // setup parent state - parentTime := genesistest.DefaultTime + parentTime := genesistest.DefaultValidatorStartTime s.EXPECT().GetLastAccepted().Return(parentID).Times(3) s.EXPECT().GetTimestamp().Return(parentTime).Times(3) s.EXPECT().GetFeeState().Return(gas.State{}).Times(3) @@ -567,7 +567,7 @@ func TestBanffAbortBlockTimestampChecks(t *testing.T) { func TestBanffCommitBlockTimestampChecks(t *testing.T) { ctrl := gomock.NewController(t) - now := genesistest.DefaultTime.Add(time.Hour) + now := genesistest.DefaultValidatorStartTime.Add(time.Hour) tests := []struct { description string @@ -630,7 +630,7 @@ func TestBanffCommitBlockTimestampChecks(t *testing.T) { require.NoError(err) // setup parent state - parentTime := genesistest.DefaultTime + parentTime := genesistest.DefaultValidatorStartTime s.EXPECT().GetLastAccepted().Return(parentID).Times(3) s.EXPECT().GetTimestamp().Return(parentTime).Times(3) s.EXPECT().GetFeeState().Return(gas.State{}).Times(3) diff --git a/vms/platformvm/genesis/genesistest/genesis.go b/vms/platformvm/genesis/genesistest/genesis.go index efc2815c6cee..9a9f9a2a48c4 100644 --- a/vms/platformvm/genesis/genesistest/genesis.go +++ b/vms/platformvm/genesis/genesistest/genesis.go @@ -36,10 +36,10 @@ const ( var ( AVAXAsset = avax.Asset{ID: snowtest.AVAXAssetID} - DefaultTime = upgrade.InitiallyActiveTime - DefaultTimeUnix = uint64(DefaultTime.Unix()) - DefaultValidatorEndTime = DefaultTime.Add(DefaultValidatorDuration) - DefaultValidatorEndTimeUnix = uint64(DefaultValidatorEndTime.Unix()) + DefaultValidatorStartTime = upgrade.InitiallyActiveTime + DefaultValidatorStartTimeUnix = uint64(DefaultValidatorStartTime.Unix()) + DefaultValidatorEndTime = DefaultValidatorStartTime.Add(DefaultValidatorDuration) + DefaultValidatorEndTimeUnix = uint64(DefaultValidatorEndTime.Unix()) ) var ( @@ -58,10 +58,10 @@ func init() { } type Config struct { - NodeIDs []ids.NodeID - ValidatorWeight uint64 - Time time.Time - ValidatorEndTime time.Time + NodeIDs []ids.NodeID + ValidatorWeight uint64 + ValidatorStartTime time.Time + ValidatorEndTime time.Time FundedKeys []*secp256k1.PrivateKey InitialBalance uint64 @@ -74,8 +74,8 @@ func New(t testing.TB, c Config) *platformvmgenesis.Genesis { if c.ValidatorWeight == 0 { c.ValidatorWeight = DefaultValidatorWeight } - if c.Time.IsZero() { - c.Time = DefaultTime + if c.ValidatorStartTime.IsZero() { + c.ValidatorStartTime = DefaultValidatorStartTime } if c.ValidatorEndTime.IsZero() { c.ValidatorEndTime = DefaultValidatorEndTime @@ -92,7 +92,7 @@ func New(t testing.TB, c Config) *platformvmgenesis.Genesis { genesis := &platformvmgenesis.Genesis{ UTXOs: make([]*platformvmgenesis.UTXO, len(c.FundedKeys)), Validators: make([]*txs.Tx, len(c.NodeIDs)), - Timestamp: uint64(c.Time.Unix()), + Timestamp: uint64(c.ValidatorStartTime.Unix()), InitialSupply: InitialSupply, } for i, key := range c.FundedKeys { @@ -128,7 +128,7 @@ func New(t testing.TB, c Config) *platformvmgenesis.Genesis { }}, Validator: txs.Validator{ NodeID: nodeID, - Start: uint64(c.Time.Unix()), + Start: uint64(c.ValidatorStartTime.Unix()), End: uint64(c.ValidatorEndTime.Unix()), Wght: c.ValidatorWeight, }, diff --git a/vms/platformvm/service_test.go b/vms/platformvm/service_test.go index 9274fe70e799..47e8a48ef578 100644 --- a/vms/platformvm/service_test.go +++ b/vms/platformvm/service_test.go @@ -506,12 +506,12 @@ func TestGetStake(t *testing.T) { // Add a delegator stakeAmount := service.vm.MinDelegatorStake + 12345 delegatorNodeID := genesistest.DefaultNodeIDs[0] - delegatorEndTime := genesistest.DefaultTime.Add(defaultMinStakingDuration) + delegatorEndTime := genesistest.DefaultValidatorStartTime.Add(defaultMinStakingDuration) builder, signer := factory.NewWallet(genesistest.DefaultFundedKeys[0]) utx, err := builder.NewAddDelegatorTx( &txs.Validator{ NodeID: delegatorNodeID, - Start: genesistest.DefaultTimeUnix, + Start: genesistest.DefaultValidatorStartTimeUnix, End: uint64(delegatorEndTime.Unix()), Wght: stakeAmount, }, @@ -532,7 +532,7 @@ func TestGetStake(t *testing.T) { staker, err := state.NewCurrentStaker( tx.ID(), addDelTx, - genesistest.DefaultTime, + genesistest.DefaultValidatorStartTime, 0, ) require.NoError(err) @@ -570,11 +570,11 @@ func TestGetStake(t *testing.T) { // Add a pending staker stakeAmount = service.vm.MinValidatorStake + 54321 pendingStakerNodeID := ids.GenerateTestNodeID() - pendingStakerEndTime := uint64(genesistest.DefaultTime.Add(defaultMinStakingDuration).Unix()) + pendingStakerEndTime := uint64(genesistest.DefaultValidatorStartTime.Add(defaultMinStakingDuration).Unix()) utx2, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: pendingStakerNodeID, - Start: uint64(genesistest.DefaultTime.Unix()), + Start: uint64(genesistest.DefaultValidatorStartTime.Unix()), End: pendingStakerEndTime, Wght: stakeAmount, }, @@ -657,7 +657,7 @@ func TestGetCurrentValidators(t *testing.T) { // Add a delegator stakeAmount := service.vm.MinDelegatorStake + 12345 validatorNodeID := genesistest.DefaultNodeIDs[1] - delegatorEndTime := genesistest.DefaultTime.Add(defaultMinStakingDuration) + delegatorEndTime := genesistest.DefaultValidatorStartTime.Add(defaultMinStakingDuration) service.vm.ctx.Lock.Lock() @@ -665,7 +665,7 @@ func TestGetCurrentValidators(t *testing.T) { utx, err := builder.NewAddDelegatorTx( &txs.Validator{ NodeID: validatorNodeID, - Start: genesistest.DefaultTimeUnix, + Start: genesistest.DefaultValidatorStartTimeUnix, End: uint64(delegatorEndTime.Unix()), Wght: stakeAmount, }, @@ -686,7 +686,7 @@ func TestGetCurrentValidators(t *testing.T) { staker, err := state.NewCurrentStaker( delTx.ID(), addDelTx, - genesistest.DefaultTime, + genesistest.DefaultValidatorStartTime, 0, ) require.NoError(err) @@ -728,7 +728,7 @@ func TestGetCurrentValidators(t *testing.T) { require.Len(*innerVdr.Delegators, 1) delegator := (*innerVdr.Delegators)[0] require.Equal(delegator.NodeID, innerVdr.NodeID) - require.Equal(uint64(delegator.StartTime), genesistest.DefaultTimeUnix) + require.Equal(uint64(delegator.StartTime), genesistest.DefaultValidatorStartTimeUnix) require.Equal(int64(delegator.EndTime), delegatorEndTime.Unix()) require.Equal(uint64(delegator.Weight), stakeAmount) } diff --git a/vms/platformvm/txs/executor/advance_time_test.go b/vms/platformvm/txs/executor/advance_time_test.go index f98f30e6ce6d..c10c76ec7bac 100644 --- a/vms/platformvm/txs/executor/advance_time_test.go +++ b/vms/platformvm/txs/executor/advance_time_test.go @@ -47,7 +47,7 @@ func TestAdvanceTimeTxUpdatePrimaryNetworkStakers(t *testing.T) { // Case: Timestamp is after next validator start time // Add a pending validator - pendingValidatorStartTime := genesistest.DefaultTime.Add(1 * time.Second) + pendingValidatorStartTime := genesistest.DefaultValidatorStartTime.Add(1 * time.Second) pendingValidatorEndTime := pendingValidatorStartTime.Add(defaultMinStakingDuration) nodeID := ids.GenerateTestNodeID() addPendingValidatorTx, err := addPendingValidator( @@ -137,7 +137,7 @@ func TestAdvanceTimeTxTimestampTooLate(t *testing.T) { // Case: Timestamp is after next validator start time // Add a pending validator - pendingValidatorStartTime := genesistest.DefaultTime.Add(1 * time.Second) + pendingValidatorStartTime := genesistest.DefaultValidatorStartTime.Add(1 * time.Second) pendingValidatorEndTime := pendingValidatorStartTime.Add(defaultMinStakingDuration) nodeID := ids.GenerateTestNodeID() _, err := addPendingValidator(env, pendingValidatorStartTime, pendingValidatorEndTime, nodeID, []*secp256k1.PrivateKey{genesistest.DefaultFundedKeys[0]}) @@ -229,8 +229,8 @@ func TestAdvanceTimeTxUpdateStakers(t *testing.T) { // Staker5: |--------------------| staker1 := staker{ nodeID: ids.GenerateTestNodeID(), - startTime: genesistest.DefaultTime.Add(1 * time.Minute), - endTime: genesistest.DefaultTime.Add(10 * defaultMinStakingDuration).Add(1 * time.Minute), + startTime: genesistest.DefaultValidatorStartTime.Add(1 * time.Minute), + endTime: genesistest.DefaultValidatorStartTime.Add(10 * defaultMinStakingDuration).Add(1 * time.Minute), } staker2 := staker{ nodeID: ids.GenerateTestNodeID(), @@ -488,14 +488,14 @@ func TestAdvanceTimeTxRemoveSubnetValidator(t *testing.T) { dummyHeight := uint64(1) // Add a subnet validator to the staker set subnetValidatorNodeID := genesistest.DefaultNodeIDs[0] - subnetVdr1EndTime := genesistest.DefaultTime.Add(defaultMinStakingDuration) + subnetVdr1EndTime := genesistest.DefaultValidatorStartTime.Add(defaultMinStakingDuration) builder, signer := env.factory.NewWallet(genesistest.DefaultFundedKeys[:2]...) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: subnetValidatorNodeID, - Start: genesistest.DefaultTimeUnix, + Start: genesistest.DefaultValidatorStartTimeUnix, End: uint64(subnetVdr1EndTime.Unix()), Wght: 1, }, @@ -604,8 +604,8 @@ func TestTrackedSubnet(t *testing.T) { // Add a subnet validator to the staker set subnetValidatorNodeID := genesistest.DefaultNodeIDs[0] - subnetVdr1StartTime := genesistest.DefaultTime.Add(1 * time.Minute) - subnetVdr1EndTime := genesistest.DefaultTime.Add(10 * defaultMinStakingDuration).Add(1 * time.Minute) + subnetVdr1StartTime := genesistest.DefaultValidatorStartTime.Add(1 * time.Minute) + subnetVdr1EndTime := genesistest.DefaultValidatorStartTime.Add(10 * defaultMinStakingDuration).Add(1 * time.Minute) builder, signer := env.factory.NewWallet(genesistest.DefaultFundedKeys[:2]...) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ @@ -673,7 +673,7 @@ func TestAdvanceTimeTxDelegatorStakerWeight(t *testing.T) { // Case: Timestamp is after next validator start time // Add a pending validator - pendingValidatorStartTime := genesistest.DefaultTime.Add(1 * time.Second) + pendingValidatorStartTime := genesistest.DefaultValidatorStartTime.Add(1 * time.Second) pendingValidatorEndTime := pendingValidatorStartTime.Add(defaultMaxStakingDuration) nodeID := ids.GenerateTestNodeID() _, err := addPendingValidator( @@ -783,7 +783,7 @@ func TestAdvanceTimeTxDelegatorStakers(t *testing.T) { // Case: Timestamp is after next validator start time // Add a pending validator - pendingValidatorStartTime := genesistest.DefaultTime.Add(1 * time.Second) + pendingValidatorStartTime := genesistest.DefaultValidatorStartTime.Add(1 * time.Second) pendingValidatorEndTime := pendingValidatorStartTime.Add(defaultMinStakingDuration) nodeID := ids.GenerateTestNodeID() _, err := addPendingValidator(env, pendingValidatorStartTime, pendingValidatorEndTime, nodeID, []*secp256k1.PrivateKey{genesistest.DefaultFundedKeys[0]}) @@ -882,7 +882,7 @@ func TestAdvanceTimeTxAfterBanff(t *testing.T) { env := newEnvironment(t, upgradetest.Durango) env.ctx.Lock.Lock() defer env.ctx.Lock.Unlock() - env.clk.Set(genesistest.DefaultTime) // VM's clock reads the genesis time + env.clk.Set(genesistest.DefaultValidatorStartTime) // VM's clock reads the genesis time upgradeTime := env.clk.Time().Add(SyncBound) env.config.UpgradeConfig.BanffTime = upgradeTime env.config.UpgradeConfig.CortinaTime = upgradeTime diff --git a/vms/platformvm/txs/executor/create_chain_test.go b/vms/platformvm/txs/executor/create_chain_test.go index ffbfe73d4b8d..d454cda30a78 100644 --- a/vms/platformvm/txs/executor/create_chain_test.go +++ b/vms/platformvm/txs/executor/create_chain_test.go @@ -181,7 +181,7 @@ func TestCreateChainTxValid(t *testing.T) { } func TestCreateChainTxAP3FeeChange(t *testing.T) { - ap3Time := genesistest.DefaultTime.Add(time.Hour) + ap3Time := genesistest.DefaultValidatorStartTime.Add(time.Hour) tests := []struct { name string time time.Time @@ -190,7 +190,7 @@ func TestCreateChainTxAP3FeeChange(t *testing.T) { }{ { name: "pre-fork - correctly priced", - time: genesistest.DefaultTime, + time: genesistest.DefaultValidatorStartTime, fee: 0, expectedError: nil, }, diff --git a/vms/platformvm/txs/executor/create_subnet_test.go b/vms/platformvm/txs/executor/create_subnet_test.go index 6a2bc9e586f6..ad51fdc0b2b0 100644 --- a/vms/platformvm/txs/executor/create_subnet_test.go +++ b/vms/platformvm/txs/executor/create_subnet_test.go @@ -24,7 +24,7 @@ import ( ) func TestCreateSubnetTxAP3FeeChange(t *testing.T) { - ap3Time := genesistest.DefaultTime.Add(time.Hour) + ap3Time := genesistest.DefaultValidatorStartTime.Add(time.Hour) tests := []struct { name string time time.Time @@ -33,7 +33,7 @@ func TestCreateSubnetTxAP3FeeChange(t *testing.T) { }{ { name: "pre-fork - correctly priced", - time: genesistest.DefaultTime, + time: genesistest.DefaultValidatorStartTime, fee: 0, expectedErr: nil, }, diff --git a/vms/platformvm/txs/executor/export_test.go b/vms/platformvm/txs/executor/export_test.go index 3fd2124aed40..a6f292c92c33 100644 --- a/vms/platformvm/txs/executor/export_test.go +++ b/vms/platformvm/txs/executor/export_test.go @@ -40,7 +40,7 @@ func TestNewExportTx(t *testing.T) { description: "P->X export", destinationChainID: env.ctx.XChainID, sourceKeys: []*secp256k1.PrivateKey{sourceKey}, - timestamp: genesistest.DefaultTime, + timestamp: genesistest.DefaultValidatorStartTime, }, { description: "P->C export", diff --git a/vms/platformvm/txs/executor/helpers_test.go b/vms/platformvm/txs/executor/helpers_test.go index 6085a6c180a1..e740178fbe48 100644 --- a/vms/platformvm/txs/executor/helpers_test.go +++ b/vms/platformvm/txs/executor/helpers_test.go @@ -224,7 +224,7 @@ func addSubnet(t *testing.T, env *environment) { func defaultConfig(f upgradetest.Fork) *config.Config { upgrades := upgradetest.GetConfigWithUpgradeTime( f, - genesistest.DefaultTime.Add(-2*time.Second), + genesistest.DefaultValidatorStartTime.Add(-2*time.Second), ) upgradetest.SetTimesTo( &upgrades, @@ -257,7 +257,7 @@ func defaultConfig(f upgradetest.Fork) *config.Config { } func defaultClock(f upgradetest.Fork) *mockable.Clock { - now := genesistest.DefaultTime + now := genesistest.DefaultValidatorStartTime if f >= upgradetest.Banff { // 1 second after active fork now = genesistest.DefaultValidatorEndTime.Add(-2 * time.Second) diff --git a/vms/platformvm/txs/executor/proposal_tx_executor_test.go b/vms/platformvm/txs/executor/proposal_tx_executor_test.go index aeea06426b78..e7d79ca58eba 100644 --- a/vms/platformvm/txs/executor/proposal_tx_executor_test.go +++ b/vms/platformvm/txs/executor/proposal_tx_executor_test.go @@ -32,7 +32,7 @@ func TestProposalTxExecuteAddDelegator(t *testing.T) { nodeID := genesistest.DefaultNodeIDs[0] newValidatorID := ids.GenerateTestNodeID() - newValidatorStartTime := uint64(genesistest.DefaultTime.Add(5 * time.Second).Unix()) + newValidatorStartTime := uint64(genesistest.DefaultValidatorStartTime.Add(5 * time.Second).Unix()) newValidatorEndTime := uint64(genesistest.DefaultValidatorEndTime.Add(-5 * time.Second).Unix()) // [addMinStakeValidator] adds a new validator to the primary network's @@ -130,23 +130,23 @@ func TestProposalTxExecuteAddDelegator(t *testing.T) { { description: "validator stops validating earlier than delegator", stakeAmount: env.config.MinDelegatorStake, - startTime: genesistest.DefaultTimeUnix + 1, + startTime: genesistest.DefaultValidatorStartTimeUnix + 1, endTime: genesistest.DefaultValidatorEndTimeUnix + 1, nodeID: nodeID, feeKeys: []*secp256k1.PrivateKey{genesistest.DefaultFundedKeys[0]}, setup: nil, - AP3Time: genesistest.DefaultTime, + AP3Time: genesistest.DefaultValidatorStartTime, expectedErr: ErrPeriodMismatch, }, { description: "validator not in the current or pending validator sets", stakeAmount: env.config.MinDelegatorStake, - startTime: uint64(genesistest.DefaultTime.Add(5 * time.Second).Unix()), + startTime: uint64(genesistest.DefaultValidatorStartTime.Add(5 * time.Second).Unix()), endTime: uint64(genesistest.DefaultValidatorEndTime.Add(-5 * time.Second).Unix()), nodeID: newValidatorID, feeKeys: []*secp256k1.PrivateKey{genesistest.DefaultFundedKeys[0]}, setup: nil, - AP3Time: genesistest.DefaultTime, + AP3Time: genesistest.DefaultValidatorStartTime, expectedErr: database.ErrNotFound, }, { @@ -157,7 +157,7 @@ func TestProposalTxExecuteAddDelegator(t *testing.T) { nodeID: newValidatorID, feeKeys: []*secp256k1.PrivateKey{genesistest.DefaultFundedKeys[0]}, setup: addMinStakeValidator, - AP3Time: genesistest.DefaultTime, + AP3Time: genesistest.DefaultValidatorStartTime, expectedErr: ErrPeriodMismatch, }, { @@ -168,7 +168,7 @@ func TestProposalTxExecuteAddDelegator(t *testing.T) { nodeID: newValidatorID, feeKeys: []*secp256k1.PrivateKey{genesistest.DefaultFundedKeys[0]}, setup: addMinStakeValidator, - AP3Time: genesistest.DefaultTime, + AP3Time: genesistest.DefaultValidatorStartTime, expectedErr: ErrPeriodMismatch, }, { @@ -179,7 +179,7 @@ func TestProposalTxExecuteAddDelegator(t *testing.T) { nodeID: newValidatorID, feeKeys: []*secp256k1.PrivateKey{genesistest.DefaultFundedKeys[0]}, setup: addMinStakeValidator, - AP3Time: genesistest.DefaultTime, + AP3Time: genesistest.DefaultValidatorStartTime, expectedErr: nil, }, { @@ -190,13 +190,13 @@ func TestProposalTxExecuteAddDelegator(t *testing.T) { nodeID: nodeID, feeKeys: []*secp256k1.PrivateKey{genesistest.DefaultFundedKeys[0]}, setup: nil, - AP3Time: genesistest.DefaultTime, + AP3Time: genesistest.DefaultValidatorStartTime, expectedErr: ErrTimestampNotBeforeStartTime, }, { description: "tx fee paying key has no funds", stakeAmount: env.config.MinDelegatorStake, - startTime: genesistest.DefaultTimeUnix + 1, + startTime: genesistest.DefaultValidatorStartTimeUnix + 1, endTime: genesistest.DefaultValidatorEndTimeUnix, nodeID: nodeID, feeKeys: []*secp256k1.PrivateKey{genesistest.DefaultFundedKeys[1]}, @@ -213,7 +213,7 @@ func TestProposalTxExecuteAddDelegator(t *testing.T) { env.state.SetHeight(dummyHeight) require.NoError(t, env.state.Commit()) }, - AP3Time: genesistest.DefaultTime, + AP3Time: genesistest.DefaultValidatorStartTime, expectedErr: ErrFlowCheckFailed, }, { @@ -235,7 +235,7 @@ func TestProposalTxExecuteAddDelegator(t *testing.T) { nodeID: newValidatorID, feeKeys: []*secp256k1.PrivateKey{genesistest.DefaultFundedKeys[0]}, setup: addMaxStakeValidator, - AP3Time: genesistest.DefaultTime, + AP3Time: genesistest.DefaultValidatorStartTime, expectedErr: ErrOverDelegated, }, } @@ -303,7 +303,7 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: nodeID, - Start: genesistest.DefaultTimeUnix + 1, + Start: genesistest.DefaultValidatorStartTimeUnix + 1, End: genesistest.DefaultValidatorEndTimeUnix + 1, Wght: genesistest.DefaultValidatorWeight, }, @@ -342,7 +342,7 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: nodeID, - Start: genesistest.DefaultTimeUnix + 1, + Start: genesistest.DefaultValidatorStartTimeUnix + 1, End: genesistest.DefaultValidatorEndTimeUnix, Wght: genesistest.DefaultValidatorWeight, }, @@ -373,7 +373,7 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { // Add a validator to pending validator set of primary network // Starts validating primary network 10 seconds after genesis pendingDSValidatorID := ids.GenerateTestNodeID() - dsStartTime := genesistest.DefaultTime.Add(10 * time.Second) + dsStartTime := genesistest.DefaultValidatorStartTime.Add(10 * time.Second) dsEndTime := dsStartTime.Add(5 * defaultMinStakingDuration) builder, signer := env.factory.NewWallet(genesistest.DefaultFundedKeys[0]) @@ -559,7 +559,7 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { // Case: Proposed validator start validating at/before current timestamp // First, advance the timestamp - newTimestamp := genesistest.DefaultTime.Add(2 * time.Second) + newTimestamp := genesistest.DefaultValidatorStartTime.Add(2 * time.Second) env.state.SetTimestamp(newTimestamp) { @@ -598,7 +598,7 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { } // reset the timestamp - env.state.SetTimestamp(genesistest.DefaultTime) + env.state.SetTimestamp(genesistest.DefaultValidatorStartTime) // Case: Proposed validator already validating the subnet // First, add validator as validator of subnet @@ -607,7 +607,7 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: nodeID, - Start: genesistest.DefaultTimeUnix, + Start: genesistest.DefaultValidatorStartTimeUnix, End: genesistest.DefaultValidatorEndTimeUnix, Wght: genesistest.DefaultValidatorWeight, }, @@ -639,7 +639,7 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: nodeID, - Start: genesistest.DefaultTimeUnix + 1, + Start: genesistest.DefaultValidatorStartTimeUnix + 1, End: genesistest.DefaultValidatorEndTimeUnix, Wght: genesistest.DefaultValidatorWeight, }, @@ -679,8 +679,8 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: nodeID, - Start: genesistest.DefaultTimeUnix + 1, - End: uint64(genesistest.DefaultTime.Add(defaultMinStakingDuration).Unix()) + 1, + Start: genesistest.DefaultValidatorStartTimeUnix + 1, + End: uint64(genesistest.DefaultValidatorStartTime.Add(defaultMinStakingDuration).Unix()) + 1, Wght: genesistest.DefaultValidatorWeight, }, Subnet: testSubnet1.ID(), @@ -722,8 +722,8 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: nodeID, - Start: genesistest.DefaultTimeUnix + 1, - End: uint64(genesistest.DefaultTime.Add(defaultMinStakingDuration).Unix()) + 1, + Start: genesistest.DefaultValidatorStartTimeUnix + 1, + End: uint64(genesistest.DefaultValidatorStartTime.Add(defaultMinStakingDuration).Unix()) + 1, Wght: genesistest.DefaultValidatorWeight, }, Subnet: testSubnet1.ID(), @@ -764,8 +764,8 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: nodeID, - Start: genesistest.DefaultTimeUnix + 1, - End: uint64(genesistest.DefaultTime.Add(defaultMinStakingDuration).Unix()) + 1, + Start: genesistest.DefaultValidatorStartTimeUnix + 1, + End: uint64(genesistest.DefaultValidatorStartTime.Add(defaultMinStakingDuration).Unix()) + 1, Wght: genesistest.DefaultValidatorWeight, }, Subnet: testSubnet1.ID(), @@ -863,7 +863,7 @@ func TestProposalTxExecuteAddValidator(t *testing.T) { utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID, - Start: genesistest.DefaultTimeUnix + 1, + Start: genesistest.DefaultValidatorStartTimeUnix + 1, End: genesistest.DefaultValidatorEndTimeUnix, Wght: env.config.MinValidatorStake, }, @@ -897,7 +897,7 @@ func TestProposalTxExecuteAddValidator(t *testing.T) { { // Case: Validator in pending validator set of primary network - startTime := genesistest.DefaultTime.Add(1 * time.Second) + startTime := genesistest.DefaultValidatorStartTime.Add(1 * time.Second) builder, signer := env.factory.NewWallet(genesistest.DefaultFundedKeys[0]) utx, err := builder.NewAddValidatorTx( &txs.Validator{ @@ -955,7 +955,7 @@ func TestProposalTxExecuteAddValidator(t *testing.T) { utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: ids.GenerateTestNodeID(), - Start: genesistest.DefaultTimeUnix + 1, + Start: genesistest.DefaultValidatorStartTimeUnix + 1, End: genesistest.DefaultValidatorEndTimeUnix, Wght: env.config.MinValidatorStake, }, diff --git a/vms/platformvm/txs/executor/reward_validator_test.go b/vms/platformvm/txs/executor/reward_validator_test.go index 52029d318889..27dd9d304937 100644 --- a/vms/platformvm/txs/executor/reward_validator_test.go +++ b/vms/platformvm/txs/executor/reward_validator_test.go @@ -247,8 +247,8 @@ func TestRewardDelegatorTxExecuteOnCommitPreDelegateeDeferral(t *testing.T) { vdrRewardAddress := ids.GenerateTestShortID() delRewardAddress := ids.GenerateTestShortID() - vdrStartTime := genesistest.DefaultTimeUnix + 1 - vdrEndTime := uint64(genesistest.DefaultTime.Add(2 * defaultMinStakingDuration).Unix()) + vdrStartTime := genesistest.DefaultValidatorStartTimeUnix + 1 + vdrEndTime := uint64(genesistest.DefaultValidatorStartTime.Add(2 * defaultMinStakingDuration).Unix()) vdrNodeID := ids.GenerateTestNodeID() builder, signer := env.factory.NewWallet(genesistest.DefaultFundedKeys[0]) @@ -381,8 +381,8 @@ func TestRewardDelegatorTxExecuteOnCommitPostDelegateeDeferral(t *testing.T) { vdrRewardAddress := ids.GenerateTestShortID() delRewardAddress := ids.GenerateTestShortID() - vdrStartTime := genesistest.DefaultTimeUnix + 1 - vdrEndTime := uint64(genesistest.DefaultTime.Add(2 * defaultMinStakingDuration).Unix()) + vdrStartTime := genesistest.DefaultValidatorStartTimeUnix + 1 + vdrEndTime := uint64(genesistest.DefaultValidatorStartTime.Add(2 * defaultMinStakingDuration).Unix()) vdrNodeID := ids.GenerateTestNodeID() builder, signer := env.factory.NewWallet(genesistest.DefaultFundedKeys[0]) @@ -611,8 +611,8 @@ func TestRewardDelegatorTxAndValidatorTxExecuteOnCommitPostDelegateeDeferral(t * vdrRewardAddress := ids.GenerateTestShortID() delRewardAddress := ids.GenerateTestShortID() - vdrStartTime := genesistest.DefaultTimeUnix + 1 - vdrEndTime := uint64(genesistest.DefaultTime.Add(2 * defaultMinStakingDuration).Unix()) + vdrStartTime := genesistest.DefaultValidatorStartTimeUnix + 1 + vdrEndTime := uint64(genesistest.DefaultValidatorStartTime.Add(2 * defaultMinStakingDuration).Unix()) vdrNodeID := ids.GenerateTestNodeID() builder, signer := env.factory.NewWallet(genesistest.DefaultFundedKeys[0]) @@ -787,8 +787,8 @@ func TestRewardDelegatorTxExecuteOnAbort(t *testing.T) { vdrRewardAddress := ids.GenerateTestShortID() delRewardAddress := ids.GenerateTestShortID() - vdrStartTime := genesistest.DefaultTimeUnix + 1 - vdrEndTime := uint64(genesistest.DefaultTime.Add(2 * defaultMinStakingDuration).Unix()) + vdrStartTime := genesistest.DefaultValidatorStartTimeUnix + 1 + vdrEndTime := uint64(genesistest.DefaultValidatorStartTime.Add(2 * defaultMinStakingDuration).Unix()) vdrNodeID := ids.GenerateTestNodeID() builder, signer := env.factory.NewWallet(genesistest.DefaultFundedKeys[0]) diff --git a/vms/platformvm/txs/executor/standard_tx_executor_test.go b/vms/platformvm/txs/executor/standard_tx_executor_test.go index 139a84ab9490..d0652e6bd419 100644 --- a/vms/platformvm/txs/executor/standard_tx_executor_test.go +++ b/vms/platformvm/txs/executor/standard_tx_executor_test.go @@ -54,7 +54,7 @@ func TestStandardTxExecutorAddValidatorTxEmptyID(t *testing.T) { defer env.ctx.Lock.Unlock() chainTime := env.state.GetTimestamp() - startTime := genesistest.DefaultTime.Add(1 * time.Second) + startTime := genesistest.DefaultValidatorStartTime.Add(1 * time.Second) tests := []struct { banffTime time.Time @@ -116,7 +116,7 @@ func TestStandardTxExecutorAddDelegator(t *testing.T) { nodeID := genesistest.DefaultNodeIDs[0] newValidatorID := ids.GenerateTestNodeID() - newValidatorStartTime := genesistest.DefaultTime.Add(5 * time.Second) + newValidatorStartTime := genesistest.DefaultValidatorStartTime.Add(5 * time.Second) newValidatorEndTime := genesistest.DefaultValidatorEndTime.Add(-5 * time.Second) // [addMinStakeValidator] adds a new validator to the primary network's @@ -214,23 +214,23 @@ func TestStandardTxExecutorAddDelegator(t *testing.T) { { description: "validator stops validating earlier than delegator", stakeAmount: env.config.MinDelegatorStake, - startTime: genesistest.DefaultTime.Add(time.Second), + startTime: genesistest.DefaultValidatorStartTime.Add(time.Second), endTime: genesistest.DefaultValidatorEndTime.Add(time.Second), nodeID: nodeID, feeKeys: []*secp256k1.PrivateKey{genesistest.DefaultFundedKeys[0]}, setup: nil, - AP3Time: genesistest.DefaultTime, + AP3Time: genesistest.DefaultValidatorStartTime, expectedExecutionErr: ErrPeriodMismatch, }, { description: "validator not in the current or pending validator sets", stakeAmount: env.config.MinDelegatorStake, - startTime: genesistest.DefaultTime.Add(5 * time.Second), + startTime: genesistest.DefaultValidatorStartTime.Add(5 * time.Second), endTime: genesistest.DefaultValidatorEndTime.Add(-5 * time.Second), nodeID: newValidatorID, feeKeys: []*secp256k1.PrivateKey{genesistest.DefaultFundedKeys[0]}, setup: nil, - AP3Time: genesistest.DefaultTime, + AP3Time: genesistest.DefaultValidatorStartTime, expectedExecutionErr: database.ErrNotFound, }, { @@ -241,7 +241,7 @@ func TestStandardTxExecutorAddDelegator(t *testing.T) { nodeID: newValidatorID, feeKeys: []*secp256k1.PrivateKey{genesistest.DefaultFundedKeys[0]}, setup: addMinStakeValidator, - AP3Time: genesistest.DefaultTime, + AP3Time: genesistest.DefaultValidatorStartTime, expectedExecutionErr: ErrPeriodMismatch, }, { @@ -252,7 +252,7 @@ func TestStandardTxExecutorAddDelegator(t *testing.T) { nodeID: newValidatorID, feeKeys: []*secp256k1.PrivateKey{genesistest.DefaultFundedKeys[0]}, setup: addMinStakeValidator, - AP3Time: genesistest.DefaultTime, + AP3Time: genesistest.DefaultValidatorStartTime, expectedExecutionErr: ErrPeriodMismatch, }, { @@ -263,7 +263,7 @@ func TestStandardTxExecutorAddDelegator(t *testing.T) { nodeID: newValidatorID, feeKeys: []*secp256k1.PrivateKey{genesistest.DefaultFundedKeys[0]}, setup: addMinStakeValidator, - AP3Time: genesistest.DefaultTime, + AP3Time: genesistest.DefaultValidatorStartTime, expectedExecutionErr: nil, }, { @@ -274,13 +274,13 @@ func TestStandardTxExecutorAddDelegator(t *testing.T) { nodeID: nodeID, // node ID feeKeys: []*secp256k1.PrivateKey{genesistest.DefaultFundedKeys[0]}, // tx fee payer setup: nil, - AP3Time: genesistest.DefaultTime, + AP3Time: genesistest.DefaultValidatorStartTime, expectedExecutionErr: ErrTimestampNotBeforeStartTime, }, { description: "tx fee paying key has no funds", stakeAmount: env.config.MinDelegatorStake, // weight - startTime: genesistest.DefaultTime.Add(time.Second), // start time + startTime: genesistest.DefaultValidatorStartTime.Add(time.Second), // start time endTime: genesistest.DefaultValidatorEndTime, // end time nodeID: nodeID, // node ID feeKeys: []*secp256k1.PrivateKey{genesistest.DefaultFundedKeys[1]}, // tx fee payer @@ -297,7 +297,7 @@ func TestStandardTxExecutorAddDelegator(t *testing.T) { env.state.SetHeight(dummyHeight) require.NoError(t, env.state.Commit()) }, - AP3Time: genesistest.DefaultTime, + AP3Time: genesistest.DefaultValidatorStartTime, expectedExecutionErr: ErrFlowCheckFailed, }, { @@ -319,7 +319,7 @@ func TestStandardTxExecutorAddDelegator(t *testing.T) { nodeID: newValidatorID, feeKeys: []*secp256k1.PrivateKey{genesistest.DefaultFundedKeys[0]}, setup: addMaxStakeValidator, - AP3Time: genesistest.DefaultTime, + AP3Time: genesistest.DefaultValidatorStartTime, expectedExecutionErr: ErrOverDelegated, }, } @@ -381,7 +381,7 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { // Case: Proposed validator currently validating primary network // but stops validating subnet after stops validating primary network // (note that keys[0] is a genesis validator) - startTime := genesistest.DefaultTime.Add(time.Second) + startTime := genesistest.DefaultValidatorStartTime.Add(time.Second) builder, signer := env.factory.NewWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ @@ -422,7 +422,7 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: nodeID, - Start: genesistest.DefaultTimeUnix + 1, + Start: genesistest.DefaultValidatorStartTimeUnix + 1, End: genesistest.DefaultValidatorEndTimeUnix, Wght: genesistest.DefaultValidatorWeight, }, @@ -449,7 +449,7 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { // Add a validator to pending validator set of primary network // Starts validating primary network 10 seconds after genesis pendingDSValidatorID := ids.GenerateTestNodeID() - dsStartTime := genesistest.DefaultTime.Add(10 * time.Second) + dsStartTime := genesistest.DefaultValidatorStartTime.Add(10 * time.Second) dsEndTime := dsStartTime.Add(5 * defaultMinStakingDuration) builder, signer := env.factory.NewWallet(genesistest.DefaultFundedKeys[0]) @@ -619,7 +619,7 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { // Case: Proposed validator start validating at/before current timestamp // First, advance the timestamp - newTimestamp := genesistest.DefaultTime.Add(2 * time.Second) + newTimestamp := genesistest.DefaultValidatorStartTime.Add(2 * time.Second) env.state.SetTimestamp(newTimestamp) { @@ -654,7 +654,7 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { } // reset the timestamp - env.state.SetTimestamp(genesistest.DefaultTime) + env.state.SetTimestamp(genesistest.DefaultValidatorStartTime) // Case: Proposed validator already validating the subnet // First, add validator as validator of subnet @@ -663,7 +663,7 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: nodeID, - Start: genesistest.DefaultTimeUnix, + Start: genesistest.DefaultValidatorStartTimeUnix, End: genesistest.DefaultValidatorEndTimeUnix, Wght: genesistest.DefaultValidatorWeight, }, @@ -678,7 +678,7 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { staker, err = state.NewCurrentStaker( subnetTx.ID(), addSubnetValTx, - genesistest.DefaultTime, + genesistest.DefaultValidatorStartTime, 0, ) require.NoError(err) @@ -690,7 +690,7 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { { // Node with ID nodeIDKey.Address() now validating subnet with ID testSubnet1.ID - startTime := genesistest.DefaultTime.Add(time.Second) + startTime := genesistest.DefaultValidatorStartTime.Add(time.Second) builder, signer := env.factory.NewWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ @@ -727,7 +727,7 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { { // Case: Duplicate signatures - startTime := genesistest.DefaultTime.Add(time.Second) + startTime := genesistest.DefaultValidatorStartTime.Add(time.Second) builder, signer := env.factory.NewWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1], testSubnet1ControlKeys[2]) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ @@ -767,7 +767,7 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { { // Case: Too few signatures - startTime := genesistest.DefaultTime.Add(time.Second) + startTime := genesistest.DefaultValidatorStartTime.Add(time.Second) builder, signer := env.factory.NewWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[2]) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ @@ -807,7 +807,7 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { { // Case: Control Signature from invalid key (keys[3] is not a control key) - startTime := genesistest.DefaultTime.Add(time.Second) + startTime := genesistest.DefaultValidatorStartTime.Add(time.Second) builder, signer := env.factory.NewWallet(testSubnet1ControlKeys[0], genesistest.DefaultFundedKeys[1]) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ @@ -846,7 +846,7 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { { // Case: Proposed validator in pending validator set for subnet // First, add validator to pending validator set of subnet - startTime := genesistest.DefaultTime.Add(time.Second) + startTime := genesistest.DefaultValidatorStartTime.Add(time.Second) builder, signer := env.factory.NewWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ @@ -867,7 +867,7 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { staker, err = state.NewCurrentStaker( subnetTx.ID(), addSubnetValTx, - genesistest.DefaultTime, + genesistest.DefaultValidatorStartTime, 0, ) require.NoError(err) @@ -905,7 +905,7 @@ func TestEtnaStandardTxExecutorAddSubnetValidator(t *testing.T) { &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: nodeID, - Start: genesistest.DefaultTimeUnix + 1, + Start: genesistest.DefaultValidatorStartTimeUnix + 1, End: genesistest.DefaultValidatorEndTimeUnix, Wght: genesistest.DefaultValidatorWeight, }, @@ -944,7 +944,7 @@ func TestBanffStandardTxExecutorAddValidator(t *testing.T) { utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID, - Start: genesistest.DefaultTimeUnix - 1, + Start: genesistest.DefaultValidatorStartTimeUnix - 1, End: genesistest.DefaultValidatorEndTimeUnix, Wght: env.config.MinValidatorStake, }, @@ -974,7 +974,7 @@ func TestBanffStandardTxExecutorAddValidator(t *testing.T) { { // Case: Validator in current validator set of primary network - startTime := genesistest.DefaultTime.Add(1 * time.Second) + startTime := genesistest.DefaultValidatorStartTime.Add(1 * time.Second) builder, signer := env.factory.NewWallet(genesistest.DefaultFundedKeys[0]) utx, err := builder.NewAddValidatorTx( &txs.Validator{ @@ -1021,7 +1021,7 @@ func TestBanffStandardTxExecutorAddValidator(t *testing.T) { { // Case: Validator in pending validator set of primary network - startTime := genesistest.DefaultTime.Add(1 * time.Second) + startTime := genesistest.DefaultValidatorStartTime.Add(1 * time.Second) builder, signer := env.factory.NewWallet(genesistest.DefaultFundedKeys[0]) utx, err := builder.NewAddValidatorTx( &txs.Validator{ @@ -1065,7 +1065,7 @@ func TestBanffStandardTxExecutorAddValidator(t *testing.T) { { // Case: Validator doesn't have enough tokens to cover stake amount - startTime := genesistest.DefaultTime.Add(1 * time.Second) + startTime := genesistest.DefaultValidatorStartTime.Add(1 * time.Second) builder, signer := env.factory.NewWallet(genesistest.DefaultFundedKeys[0]) utx, err := builder.NewAddValidatorTx( &txs.Validator{ diff --git a/vms/platformvm/validator_set_property_test.go b/vms/platformvm/validator_set_property_test.go index b0595a760359..44ba02e0e1a7 100644 --- a/vms/platformvm/validator_set_property_test.go +++ b/vms/platformvm/validator_set_property_test.go @@ -85,7 +85,7 @@ func TestGetValidatorsSetProperty(t *testing.T) { }() nodeID := ids.GenerateTestNodeID() - currentTime := genesistest.DefaultTime + currentTime := genesistest.DefaultValidatorStartTime vm.clock.Set(currentTime) vm.state.SetTimestamp(currentTime) @@ -658,9 +658,9 @@ func buildVM(t *testing.T) (*VM, ids.ID, error) { MinStakeDuration: defaultMinStakingDuration, MaxStakeDuration: defaultMaxStakingDuration, RewardConfig: defaultRewardConfig, - UpgradeConfig: upgradetest.GetConfigWithUpgradeTime(upgradetest.Durango, genesistest.DefaultTime), + UpgradeConfig: upgradetest.GetConfigWithUpgradeTime(upgradetest.Durango, genesistest.DefaultValidatorStartTime), }} - vm.clock.Set(genesistest.DefaultTime.Add(time.Second)) + vm.clock.Set(genesistest.DefaultValidatorStartTime.Add(time.Second)) baseDB := memdb.New() chainDB := prefixdb.New([]byte{0}, baseDB) diff --git a/vms/platformvm/validators/manager_benchmark_test.go b/vms/platformvm/validators/manager_benchmark_test.go index be2e5f9ba83b..98227e09913d 100644 --- a/vms/platformvm/validators/manager_benchmark_test.go +++ b/vms/platformvm/validators/manager_benchmark_test.go @@ -74,18 +74,18 @@ func BenchmarkGetValidatorSet(b *testing.B) { ) for i := 0; i < 50; i++ { currentHeight++ - nodeID, err := addPrimaryValidator(s, genesistest.DefaultTime, genesistest.DefaultValidatorEndTime, currentHeight) + nodeID, err := addPrimaryValidator(s, genesistest.DefaultValidatorStartTime, genesistest.DefaultValidatorEndTime, currentHeight) require.NoError(err) nodeIDs = append(nodeIDs, nodeID) } subnetID := ids.GenerateTestID() for _, nodeID := range nodeIDs { currentHeight++ - require.NoError(addSubnetValidator(s, subnetID, genesistest.DefaultTime, genesistest.DefaultValidatorEndTime, nodeID, currentHeight)) + require.NoError(addSubnetValidator(s, subnetID, genesistest.DefaultValidatorStartTime, genesistest.DefaultValidatorEndTime, nodeID, currentHeight)) } for i := 0; i < 9900; i++ { currentHeight++ - require.NoError(addSubnetDelegator(s, subnetID, genesistest.DefaultTime, genesistest.DefaultValidatorEndTime, nodeIDs, currentHeight)) + require.NoError(addSubnetDelegator(s, subnetID, genesistest.DefaultValidatorStartTime, genesistest.DefaultValidatorEndTime, nodeIDs, currentHeight)) } ctx := context.Background() diff --git a/vms/platformvm/vm_regression_test.go b/vms/platformvm/vm_regression_test.go index 86cddabd3e38..9b4d8b19a5a6 100644 --- a/vms/platformvm/vm_regression_test.go +++ b/vms/platformvm/vm_regression_test.go @@ -248,7 +248,7 @@ func TestAddDelegatorTxHeapCorruption(t *testing.T) { }, { name: "post-upgrade calculate max stake correctly", - ap3Time: genesistest.DefaultTime, + ap3Time: genesistest.DefaultValidatorStartTime, }, } @@ -1636,7 +1636,7 @@ func TestSubnetValidatorBLSKeyDiffAfterExpiry(t *testing.T) { subnetID := testSubnet1.TxID // setup time - currentTime := genesistest.DefaultTime + currentTime := genesistest.DefaultValidatorStartTime vm.clock.Set(currentTime) vm.state.SetTimestamp(currentTime) @@ -1899,7 +1899,7 @@ func TestPrimaryNetworkValidatorPopulatedToEmptyBLSKeyDiff(t *testing.T) { defer vm.ctx.Lock.Unlock() // setup time - currentTime := genesistest.DefaultTime + currentTime := genesistest.DefaultValidatorStartTime vm.clock.Set(currentTime) vm.state.SetTimestamp(currentTime) @@ -2057,7 +2057,7 @@ func TestSubnetValidatorPopulatedToEmptyBLSKeyDiff(t *testing.T) { subnetID := testSubnet1.TxID // setup time - currentTime := genesistest.DefaultTime + currentTime := genesistest.DefaultValidatorStartTime vm.clock.Set(currentTime) vm.state.SetTimestamp(currentTime) @@ -2276,7 +2276,7 @@ func TestSubnetValidatorSetAfterPrimaryNetworkValidatorRemoval(t *testing.T) { subnetID := testSubnet1.TxID // setup time - currentTime := genesistest.DefaultTime + currentTime := genesistest.DefaultValidatorStartTime vm.clock.Set(currentTime) vm.state.SetTimestamp(currentTime) diff --git a/vms/platformvm/vm_test.go b/vms/platformvm/vm_test.go index 8094fec5b79a..c97c112ac772 100644 --- a/vms/platformvm/vm_test.go +++ b/vms/platformvm/vm_test.go @@ -92,7 +92,7 @@ var ( SupplyCap: 720 * units.MegaAvax, } - latestForkTime = genesistest.DefaultTime.Add(time.Second) + latestForkTime = genesistest.DefaultValidatorStartTime.Add(time.Second) defaultStaticFeeConfig = fee.StaticConfig{ TxFee: defaultTxFee, @@ -130,7 +130,7 @@ func defaultVM(t *testing.T, f upgradetest.Fork) (*VM, *txstest.WalletFactory, d // always reset latestForkTime (a package level variable) // to ensure test independence - latestForkTime = genesistest.DefaultTime.Add(time.Second) + latestForkTime = genesistest.DefaultValidatorStartTime.Add(time.Second) vm := &VM{Config: config.Config{ Chains: chains.TestManager, UptimeLockedCalculator: uptime.NewLockedCalculator(), @@ -360,7 +360,7 @@ func TestInvalidAddValidatorCommit(t *testing.T) { defer vm.ctx.Lock.Unlock() nodeID := ids.GenerateTestNodeID() - startTime := genesistest.DefaultTime.Add(-txexecutor.SyncBound).Add(-1 * time.Second) + startTime := genesistest.DefaultValidatorStartTime.Add(-txexecutor.SyncBound).Add(-1 * time.Second) endTime := startTime.Add(defaultMinStakingDuration) // create invalid tx @@ -1661,22 +1661,22 @@ func TestMaxStakeAmount(t *testing.T) { }{ { description: "[validator.StartTime] == [startTime] < [endTime] == [validator.EndTime]", - startTime: genesistest.DefaultTime, + startTime: genesistest.DefaultValidatorStartTime, endTime: genesistest.DefaultValidatorEndTime, }, { description: "[validator.StartTime] < [startTime] < [endTime] == [validator.EndTime]", - startTime: genesistest.DefaultTime.Add(time.Minute), + startTime: genesistest.DefaultValidatorStartTime.Add(time.Minute), endTime: genesistest.DefaultValidatorEndTime, }, { description: "[validator.StartTime] == [startTime] < [endTime] < [validator.EndTime]", - startTime: genesistest.DefaultTime, + startTime: genesistest.DefaultValidatorStartTime, endTime: genesistest.DefaultValidatorEndTime.Add(-time.Minute), }, { description: "[validator.StartTime] < [startTime] < [endTime] < [validator.EndTime]", - startTime: genesistest.DefaultTime.Add(time.Minute), + startTime: genesistest.DefaultValidatorStartTime.Add(time.Minute), endTime: genesistest.DefaultValidatorEndTime.Add(-time.Minute), }, } @@ -1696,7 +1696,7 @@ func TestMaxStakeAmount(t *testing.T) { func TestUptimeDisallowedWithRestart(t *testing.T) { require := require.New(t) - latestForkTime = genesistest.DefaultTime.Add(defaultMinStakingDuration) + latestForkTime = genesistest.DefaultValidatorStartTime.Add(defaultMinStakingDuration) db := memdb.New() firstDB := prefixdb.New([]byte{}, db) @@ -1736,8 +1736,8 @@ func TestUptimeDisallowedWithRestart(t *testing.T) { require.NoError(firstVM.SetState(context.Background(), snow.NormalOp)) // Fast forward clock so that validators meet 20% uptime required for reward - durationForReward := genesistest.DefaultValidatorEndTime.Sub(genesistest.DefaultTime) * firstUptimePercentage / 100 - vmStopTime := genesistest.DefaultTime.Add(durationForReward) + durationForReward := genesistest.DefaultValidatorEndTime.Sub(genesistest.DefaultValidatorStartTime) * firstUptimePercentage / 100 + vmStopTime := genesistest.DefaultValidatorStartTime.Add(durationForReward) firstVM.clock.Set(vmStopTime) // Shutdown VM to stop all genesis validator uptime. @@ -1840,7 +1840,7 @@ func TestUptimeDisallowedWithRestart(t *testing.T) { func TestUptimeDisallowedAfterNeverConnecting(t *testing.T) { require := require.New(t) - latestForkTime = genesistest.DefaultTime.Add(defaultMinStakingDuration) + latestForkTime = genesistest.DefaultValidatorStartTime.Add(defaultMinStakingDuration) db := memdb.New() From 8cb0d99c16eb9de8050e95a7252a0656280bdc78 Mon Sep 17 00:00:00 2001 From: Stephen Buttolph Date: Thu, 22 Aug 2024 21:38:03 -0400 Subject: [PATCH 27/27] update comments --- vms/platformvm/vm_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vms/platformvm/vm_test.go b/vms/platformvm/vm_test.go index c97c112ac772..e6cfada5e7f7 100644 --- a/vms/platformvm/vm_test.go +++ b/vms/platformvm/vm_test.go @@ -525,7 +525,7 @@ func TestAddSubnetValidatorAccept(t *testing.T) { // create valid tx // note that [startTime, endTime] is a subset of time that keys[0] - // validates primary network ([genesistest.Time, genesistest.ValidatorEndTime]) + // validates primary network ([genesistest.DefaultValidatorStartTime, genesistest.DefaultValidatorEndTime]) builder, txSigner := factory.NewWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ @@ -577,7 +577,7 @@ func TestAddSubnetValidatorReject(t *testing.T) { // create valid tx // note that [startTime, endTime] is a subset of time that keys[0] - // validates primary network ([genesistest.Time, genesistest.ValidatorEndTime]) + // validates primary network ([genesistest.DefaultValidatorStartTime, genesistest.DefaultValidatorEndTime]) builder, txSigner := factory.NewWallet(testSubnet1ControlKeys[1], testSubnet1ControlKeys[2]) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{