diff --git a/vms/platformvm/block/builder/helpers_test.go b/vms/platformvm/block/builder/helpers_test.go index 412804425921..d2acee3dc0d4 100644 --- a/vms/platformvm/block/builder/helpers_test.go +++ b/vms/platformvm/block/builder/helpers_test.go @@ -4,8 +4,6 @@ package builder import ( - "context" - "errors" "testing" "time" @@ -24,6 +22,7 @@ import ( "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/snow" "github.com/ava-labs/avalanchego/snow/engine/common" + "github.com/ava-labs/avalanchego/snow/snowtest" "github.com/ava-labs/avalanchego/snow/uptime" "github.com/ava-labs/avalanchego/snow/validators" "github.com/ava-labs/avalanchego/utils" @@ -69,18 +68,13 @@ var ( defaultMinValidatorStake = 5 * units.MilliAvax defaultBalance = 100 * defaultMinValidatorStake preFundedKeys = secp256k1.TestKeys() - avaxAssetID = ids.ID{'y', 'e', 'e', 't'} defaultTxFee = uint64(100) - xChainID = ids.Empty.Prefix(0) - cChainID = ids.Empty.Prefix(1) testSubnet1 *txs.Tx testSubnet1ControlKeys = preFundedKeys[0:3] // Node IDs of genesis validators. Initialized in init function genesisNodeIDs []ids.NodeID - - errMissing = errors.New("missing") ) func init() { @@ -127,7 +121,14 @@ func newEnvironment(t *testing.T) *environment { res.isBootstrapped.Set(true) res.baseDB = versiondb.New(memdb.New()) - res.ctx, res.msm = defaultCtx(res.baseDB) + atomicDB := prefixdb.New([]byte{1}, res.baseDB) + m := atomic.NewMemory(atomicDB) + + res.ctx = snowtest.Context(t, snowtest.PChainID) + res.msm = &mutableSharedMemory{ + SharedMemory: m.NewSharedMemory(res.ctx.ChainID), + } + res.ctx.SharedMemory = res.msm res.ctx.Lock.Lock() defer res.ctx.Lock.Unlock() @@ -264,38 +265,6 @@ func defaultState( return state } -func defaultCtx(db database.Database) (*snow.Context, *mutableSharedMemory) { - ctx := snow.DefaultContextTest() - ctx.NetworkID = 10 - ctx.XChainID = xChainID - ctx.CChainID = cChainID - ctx.AVAXAssetID = avaxAssetID - - atomicDB := prefixdb.New([]byte{1}, db) - m := atomic.NewMemory(atomicDB) - - msm := &mutableSharedMemory{ - SharedMemory: m.NewSharedMemory(ctx.ChainID), - } - ctx.SharedMemory = msm - - ctx.ValidatorState = &validators.TestState{ - GetSubnetIDF: func(_ context.Context, chainID ids.ID) (ids.ID, error) { - subnetID, ok := map[ids.ID]ids.ID{ - constants.PlatformChainID: constants.PrimaryNetworkID, - xChainID: constants.PrimaryNetworkID, - cChainID: constants.PrimaryNetworkID, - }[chainID] - if !ok { - return ids.Empty, errMissing - } - return subnetID, nil - }, - } - - return ctx, msm -} - func defaultConfig() *config.Config { return &config.Config{ Chains: chains.TestManager, diff --git a/vms/platformvm/block/builder/standard_block_test.go b/vms/platformvm/block/builder/standard_block_test.go index 74177e1f88b0..cdfe27d662ad 100644 --- a/vms/platformvm/block/builder/standard_block_test.go +++ b/vms/platformvm/block/builder/standard_block_test.go @@ -42,7 +42,7 @@ func TestAtomicTxImports(t *testing.T) { peerSharedMemory := m.NewSharedMemory(env.ctx.XChainID) utxo := &avax.UTXO{ UTXOID: utxoID, - Asset: avax.Asset{ID: avaxAssetID}, + Asset: avax.Asset{ID: env.ctx.AVAXAssetID}, Out: &secp256k1fx.TransferOutput{ Amt: amount, OutputOwners: secp256k1fx.OutputOwners{ diff --git a/vms/platformvm/block/executor/helpers_test.go b/vms/platformvm/block/executor/helpers_test.go index 5221f4a97d15..1d7d58217b15 100644 --- a/vms/platformvm/block/executor/helpers_test.go +++ b/vms/platformvm/block/executor/helpers_test.go @@ -4,8 +4,6 @@ package executor import ( - "context" - "errors" "fmt" "testing" "time" @@ -25,6 +23,7 @@ import ( "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/snow" "github.com/ava-labs/avalanchego/snow/engine/common" + "github.com/ava-labs/avalanchego/snow/snowtest" "github.com/ava-labs/avalanchego/snow/uptime" "github.com/ava-labs/avalanchego/snow/validators" "github.com/ava-labs/avalanchego/utils" @@ -73,16 +72,12 @@ var ( preFundedKeys = secp256k1.TestKeys() avaxAssetID = ids.ID{'y', 'e', 'e', 't'} defaultTxFee = uint64(100) - xChainID = ids.Empty.Prefix(0) - cChainID = ids.Empty.Prefix(1) genesisBlkID ids.ID testSubnet1 *txs.Tx // Node IDs of genesis validators. Initialized in init function genesisNodeIDs []ids.NodeID - - errMissing = errors.New("missing") ) func init() { @@ -138,7 +133,13 @@ func newEnvironment(t *testing.T, ctrl *gomock.Controller) *environment { res.isBootstrapped.Set(true) res.baseDB = versiondb.New(memdb.New()) - res.ctx = defaultCtx(res.baseDB) + atomicDB := prefixdb.New([]byte{1}, res.baseDB) + 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()) rewardsCalc := reward.NewCalculator(res.config.RewardConfig) @@ -293,35 +294,6 @@ func defaultState( return state } -func defaultCtx(db database.Database) *snow.Context { - ctx := snow.DefaultContextTest() - ctx.NetworkID = 10 - ctx.XChainID = xChainID - ctx.CChainID = cChainID - ctx.AVAXAssetID = avaxAssetID - - atomicDB := prefixdb.New([]byte{1}, db) - m := atomic.NewMemory(atomicDB) - - ctx.SharedMemory = m.NewSharedMemory(ctx.ChainID) - - ctx.ValidatorState = &validators.TestState{ - GetSubnetIDF: func(_ context.Context, chainID ids.ID) (ids.ID, error) { - subnetID, ok := map[ids.ID]ids.ID{ - constants.PlatformChainID: constants.PrimaryNetworkID, - xChainID: constants.PrimaryNetworkID, - cChainID: constants.PrimaryNetworkID, - }[chainID] - if !ok { - return ids.Empty, errMissing - } - return subnetID, nil - }, - } - - return ctx -} - func defaultConfig() *config.Config { return &config.Config{ Chains: chains.TestManager, diff --git a/vms/platformvm/service_test.go b/vms/platformvm/service_test.go index d6d96e66df41..28a3e80258ed 100644 --- a/vms/platformvm/service_test.go +++ b/vms/platformvm/service_test.go @@ -181,7 +181,7 @@ func TestGetTxStatus(t *testing.T) { m := atomic.NewMemory(prefixdb.New([]byte{}, service.vm.db)) sm := m.NewSharedMemory(service.vm.ctx.ChainID) - peerSharedMemory := m.NewSharedMemory(xChainID) + peerSharedMemory := m.NewSharedMemory(service.vm.ctx.XChainID) // #nosec G404 utxo := &avax.UTXO{ @@ -189,7 +189,7 @@ func TestGetTxStatus(t *testing.T) { TxID: ids.GenerateTestID(), OutputIndex: rand.Uint32(), }, - Asset: avax.Asset{ID: avaxAssetID}, + Asset: avax.Asset{ID: service.vm.ctx.AVAXAssetID}, Out: &secp256k1fx.TransferOutput{ Amt: 1234567, OutputOwners: secp256k1fx.OutputOwners{ @@ -220,7 +220,12 @@ func TestGetTxStatus(t *testing.T) { oldSharedMemory := mutableSharedMemory.SharedMemory mutableSharedMemory.SharedMemory = sm - tx, err := service.vm.txBuilder.NewImportTx(xChainID, ids.ShortEmpty, []*secp256k1.PrivateKey{recipientKey}, ids.ShortEmpty) + tx, err := service.vm.txBuilder.NewImportTx( + service.vm.ctx.XChainID, + ids.ShortEmpty, + []*secp256k1.PrivateKey{recipientKey}, + ids.ShortEmpty, + ) require.NoError(err) mutableSharedMemory.SharedMemory = oldSharedMemory @@ -399,7 +404,7 @@ func TestGetBalance(t *testing.T) { }() // Ensure GetStake is correct for each of the genesis validators - genesis, _ := defaultGenesis(t) + genesis, _ := defaultGenesis(t, service.vm.ctx.AVAXAssetID) for idx, utxo := range genesis.UTXOs { request := GetBalanceRequest{ Addresses: []string{ @@ -433,7 +438,7 @@ func TestGetStake(t *testing.T) { }() // Ensure GetStake is correct for each of the genesis validators - genesis, _ := defaultGenesis(t) + genesis, _ := defaultGenesis(t, service.vm.ctx.AVAXAssetID) addrsStrs := []string{} for i, validator := range genesis.Validators { addr := fmt.Sprintf("P-%s", validator.RewardOwner.Addresses[0]) @@ -608,7 +613,7 @@ func TestGetCurrentValidators(t *testing.T) { service.vm.ctx.Lock.Unlock() }() - genesis, _ := defaultGenesis(t) + genesis, _ := defaultGenesis(t, service.vm.ctx.AVAXAssetID) // Call getValidators args := GetCurrentValidatorsArgs{SubnetID: constants.PrimaryNetworkID} diff --git a/vms/platformvm/txs/add_delegator_test.go b/vms/platformvm/txs/add_delegator_test.go index cf053d45baba..1989690bb173 100644 --- a/vms/platformvm/txs/add_delegator_test.go +++ b/vms/platformvm/txs/add_delegator_test.go @@ -10,7 +10,7 @@ import ( "github.com/stretchr/testify/require" "github.com/ava-labs/avalanchego/ids" - "github.com/ava-labs/avalanchego/snow" + "github.com/ava-labs/avalanchego/snow/snowtest" "github.com/ava-labs/avalanchego/utils/crypto/secp256k1" "github.com/ava-labs/avalanchego/utils/timer/mockable" "github.com/ava-labs/avalanchego/vms/components/avax" @@ -23,8 +23,7 @@ var preFundedKeys = secp256k1.TestKeys() func TestAddDelegatorTxSyntacticVerify(t *testing.T) { require := require.New(t) clk := mockable.Clock{} - ctx := snow.DefaultContextTest() - ctx.AVAXAssetID = ids.GenerateTestID() + ctx := snowtest.Context(t, snowtest.PChainID) signers := [][]*secp256k1.PrivateKey{preFundedKeys} var ( @@ -130,8 +129,7 @@ func TestAddDelegatorTxSyntacticVerify(t *testing.T) { func TestAddDelegatorTxSyntacticVerifyNotAVAX(t *testing.T) { require := require.New(t) clk := mockable.Clock{} - ctx := snow.DefaultContextTest() - ctx.AVAXAssetID = ids.GenerateTestID() + ctx := snowtest.Context(t, snowtest.PChainID) signers := [][]*secp256k1.PrivateKey{preFundedKeys} var ( diff --git a/vms/platformvm/txs/add_validator_test.go b/vms/platformvm/txs/add_validator_test.go index 1076b2da69b2..4046d7c0d984 100644 --- a/vms/platformvm/txs/add_validator_test.go +++ b/vms/platformvm/txs/add_validator_test.go @@ -10,7 +10,7 @@ import ( "github.com/stretchr/testify/require" "github.com/ava-labs/avalanchego/ids" - "github.com/ava-labs/avalanchego/snow" + "github.com/ava-labs/avalanchego/snow/snowtest" "github.com/ava-labs/avalanchego/utils/crypto/secp256k1" "github.com/ava-labs/avalanchego/utils/timer/mockable" "github.com/ava-labs/avalanchego/vms/components/avax" @@ -22,8 +22,7 @@ import ( func TestAddValidatorTxSyntacticVerify(t *testing.T) { require := require.New(t) clk := mockable.Clock{} - ctx := snow.DefaultContextTest() - ctx.AVAXAssetID = ids.GenerateTestID() + ctx := snowtest.Context(t, snowtest.PChainID) signers := [][]*secp256k1.PrivateKey{preFundedKeys} var ( @@ -146,8 +145,7 @@ func TestAddValidatorTxSyntacticVerify(t *testing.T) { func TestAddValidatorTxSyntacticVerifyNotAVAX(t *testing.T) { require := require.New(t) clk := mockable.Clock{} - ctx := snow.DefaultContextTest() - ctx.AVAXAssetID = ids.GenerateTestID() + ctx := snowtest.Context(t, snowtest.PChainID) signers := [][]*secp256k1.PrivateKey{preFundedKeys} var ( diff --git a/vms/platformvm/txs/executor/export_test.go b/vms/platformvm/txs/executor/export_test.go index ebc64e1ecd1f..1369a5f8bbf3 100644 --- a/vms/platformvm/txs/executor/export_test.go +++ b/vms/platformvm/txs/executor/export_test.go @@ -33,13 +33,13 @@ func TestNewExportTx(t *testing.T) { tests := []test{ { description: "P->X export", - destinationChainID: xChainID, + destinationChainID: env.ctx.XChainID, sourceKeys: []*secp256k1.PrivateKey{sourceKey}, timestamp: defaultValidateStartTime, }, { description: "P->C export", - destinationChainID: cChainID, + destinationChainID: env.ctx.CChainID, sourceKeys: []*secp256k1.PrivateKey{sourceKey}, timestamp: env.config.ApricotPhase5Time, }, diff --git a/vms/platformvm/txs/executor/helpers_test.go b/vms/platformvm/txs/executor/helpers_test.go index 1aced0dcbad5..b72c136b5e54 100644 --- a/vms/platformvm/txs/executor/helpers_test.go +++ b/vms/platformvm/txs/executor/helpers_test.go @@ -4,8 +4,6 @@ package executor import ( - "context" - "errors" "fmt" "math" "testing" @@ -21,10 +19,10 @@ import ( "github.com/ava-labs/avalanchego/codec/linearcodec" "github.com/ava-labs/avalanchego/database" "github.com/ava-labs/avalanchego/database/memdb" - "github.com/ava-labs/avalanchego/database/prefixdb" "github.com/ava-labs/avalanchego/database/versiondb" "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/snow" + "github.com/ava-labs/avalanchego/snow/snowtest" "github.com/ava-labs/avalanchego/snow/uptime" "github.com/ava-labs/avalanchego/snow/validators" "github.com/ava-labs/avalanchego/utils" @@ -64,10 +62,7 @@ var ( defaultMinValidatorStake = 5 * units.MilliAvax defaultBalance = 100 * defaultMinValidatorStake preFundedKeys = secp256k1.TestKeys() - avaxAssetID = ids.ID{'y', 'e', 'e', 't'} defaultTxFee = uint64(100) - xChainID = ids.Empty.Prefix(0) - cChainID = ids.Empty.Prefix(1) lastAcceptedID = ids.GenerateTestID() testSubnet1 *txs.Tx @@ -75,8 +70,6 @@ var ( // Node IDs of genesis validators. Initialized in init function genesisNodeIDs []ids.NodeID - - errMissing = errors.New("missing") ) func init() { @@ -127,7 +120,12 @@ func newEnvironment(t *testing.T, postBanff, postCortina, postDurango bool) *env clk := defaultClock(postBanff || postCortina || postDurango) baseDB := versiondb.New(memdb.New()) - ctx, msm := defaultCtx(baseDB) + ctx := snowtest.Context(t, snowtest.PChainID) + m := atomic.NewMemory(baseDB) + msm := &mutableSharedMemory{ + SharedMemory: m.NewSharedMemory(ctx.ChainID), + } + ctx.SharedMemory = msm fx := defaultFx(clk, ctx.Log, isBootstrapped.Get()) @@ -249,38 +247,6 @@ func defaultState( return state } -func defaultCtx(db database.Database) (*snow.Context, *mutableSharedMemory) { - ctx := snow.DefaultContextTest() - ctx.NetworkID = 10 - ctx.XChainID = xChainID - ctx.CChainID = cChainID - ctx.AVAXAssetID = avaxAssetID - - atomicDB := prefixdb.New([]byte{1}, db) - m := atomic.NewMemory(atomicDB) - - msm := &mutableSharedMemory{ - SharedMemory: m.NewSharedMemory(ctx.ChainID), - } - ctx.SharedMemory = msm - - ctx.ValidatorState = &validators.TestState{ - GetSubnetIDF: func(_ context.Context, chainID ids.ID) (ids.ID, error) { - subnetID, ok := map[ids.ID]ids.ID{ - constants.PlatformChainID: constants.PrimaryNetworkID, - xChainID: constants.PrimaryNetworkID, - cChainID: constants.PrimaryNetworkID, - }[chainID] - if !ok { - return ids.Empty, errMissing - } - return subnetID, nil - }, - } - - return ctx, msm -} - func defaultConfig(postBanff, postCortina, postDurango bool) *config.Config { banffTime := mockable.MaxTime if postBanff { diff --git a/vms/platformvm/txs/executor/import_test.go b/vms/platformvm/txs/executor/import_test.go index e35eda20dbba..4ce779a9165e 100644 --- a/vms/platformvm/txs/executor/import_test.go +++ b/vms/platformvm/txs/executor/import_test.go @@ -118,9 +118,9 @@ func TestNewImportTx(t *testing.T) { }, { description: "attempting to import from C-chain", - sourceChainID: cChainID, + sourceChainID: env.ctx.CChainID, sharedMemory: fundedSharedMemory( - cChainID, + env.ctx.CChainID, map[ids.ID]uint64{ env.ctx.AVAXAssetID: env.config.TxFee, }, diff --git a/vms/platformvm/validator_set_property_test.go b/vms/platformvm/validator_set_property_test.go index 5eff65b68729..3dfb6e456bb2 100644 --- a/vms/platformvm/validator_set_property_test.go +++ b/vms/platformvm/validator_set_property_test.go @@ -26,6 +26,7 @@ import ( "github.com/ava-labs/avalanchego/snow" "github.com/ava-labs/avalanchego/snow/consensus/snowman" "github.com/ava-labs/avalanchego/snow/engine/common" + "github.com/ava-labs/avalanchego/snow/snowtest" "github.com/ava-labs/avalanchego/snow/uptime" "github.com/ava-labs/avalanchego/snow/validators" "github.com/ava-labs/avalanchego/utils/constants" @@ -733,7 +734,7 @@ func buildVM(t *testing.T) (*VM, ids.ID, error) { atomicDB := prefixdb.New([]byte{1}, baseDB) msgChan := make(chan common.Message, 1) - ctx := defaultContext(t) + ctx := snowtest.Context(t, snowtest.PChainID) m := atomic.NewMemory(atomicDB) ctx.SharedMemory = m.NewSharedMemory(ctx.ChainID) @@ -746,7 +747,7 @@ func buildVM(t *testing.T) (*VM, ids.ID, error) { return nil } - genesisBytes, err := buildCustomGenesis() + genesisBytes, err := buildCustomGenesis(ctx.AVAXAssetID) if err != nil { return nil, ids.Empty, err } @@ -804,7 +805,7 @@ func buildVM(t *testing.T) (*VM, ids.ID, error) { return vm, testSubnet1.ID(), nil } -func buildCustomGenesis() ([]byte, error) { +func buildCustomGenesis(avaxAssetID ids.ID) ([]byte, error) { genesisUTXOs := make([]api.UTXO, len(keys)) for i, key := range keys { id := key.PublicKey().Address() diff --git a/vms/platformvm/vm_regression_test.go b/vms/platformvm/vm_regression_test.go index cfc0b20329ca..03725da3a662 100644 --- a/vms/platformvm/vm_regression_test.go +++ b/vms/platformvm/vm_regression_test.go @@ -23,6 +23,7 @@ import ( "github.com/ava-labs/avalanchego/snow/choices" "github.com/ava-labs/avalanchego/snow/consensus/snowman" "github.com/ava-labs/avalanchego/snow/engine/common" + "github.com/ava-labs/avalanchego/snow/snowtest" "github.com/ava-labs/avalanchego/snow/uptime" "github.com/ava-labs/avalanchego/snow/validators" "github.com/ava-labs/avalanchego/utils/constants" @@ -340,7 +341,6 @@ func TestAddDelegatorTxHeapCorruption(t *testing.T) { // panic. func TestUnverifiedParentPanicRegression(t *testing.T) { require := require.New(t) - _, genesisBytes := defaultGenesis(t) baseDB := memdb.New() atomicDB := prefixdb.New([]byte{1}, baseDB) @@ -357,13 +357,15 @@ func TestUnverifiedParentPanicRegression(t *testing.T) { DurangoTime: mockable.MaxTime, }} - ctx := defaultContext(t) + ctx := snowtest.Context(t, snowtest.PChainID) ctx.Lock.Lock() defer func() { require.NoError(vm.Shutdown(context.Background())) ctx.Lock.Unlock() }() + _, genesisBytes := defaultGenesis(t, ctx.AVAXAssetID) + msgChan := make(chan common.Message, 1) require.NoError(vm.Initialize( context.Background(), diff --git a/vms/platformvm/vm_test.go b/vms/platformvm/vm_test.go index 3c3a017ec396..7d24a352ab78 100644 --- a/vms/platformvm/vm_test.go +++ b/vms/platformvm/vm_test.go @@ -6,7 +6,6 @@ package platformvm import ( "bytes" "context" - "errors" "fmt" "testing" "time" @@ -96,9 +95,6 @@ var ( SupplyCap: 720 * units.MegaAvax, } - // AVAX asset ID in tests - avaxAssetID = ids.ID{'y', 'e', 'e', 't'} - defaultTxFee = uint64(100) // chain timestamp at genesis @@ -127,11 +123,6 @@ var ( // Its threshold is 2 testSubnet1 *txs.Tx testSubnet1ControlKeys = keys[0:3] - - xChainID = ids.Empty.Prefix(0) - cChainID = ids.Empty.Prefix(1) - - errMissing = errors.New("missing") ) func init() { @@ -149,45 +140,10 @@ type mutableSharedMemory struct { atomic.SharedMemory } -func defaultContext(t *testing.T) *snow.Context { - require := require.New(t) - - ctx := snow.DefaultContextTest() - ctx.NetworkID = constants.UnitTestID - ctx.XChainID = xChainID - ctx.CChainID = cChainID - ctx.AVAXAssetID = avaxAssetID - aliaser := ids.NewAliaser() - - require.NoError(aliaser.Alias(constants.PlatformChainID, "P")) - require.NoError(aliaser.Alias(constants.PlatformChainID, constants.PlatformChainID.String())) - require.NoError(aliaser.Alias(xChainID, "X")) - require.NoError(aliaser.Alias(xChainID, xChainID.String())) - require.NoError(aliaser.Alias(cChainID, "C")) - require.NoError(aliaser.Alias(cChainID, cChainID.String())) - - ctx.BCLookup = aliaser - - ctx.ValidatorState = &validators.TestState{ - GetSubnetIDF: func(_ context.Context, chainID ids.ID) (ids.ID, error) { - subnetID, ok := map[ids.ID]ids.ID{ - constants.PlatformChainID: constants.PrimaryNetworkID, - xChainID: constants.PrimaryNetworkID, - cChainID: constants.PrimaryNetworkID, - }[chainID] - if !ok { - return ids.Empty, errMissing - } - return subnetID, nil - }, - } - return ctx -} - // Returns: // 1) The genesis state // 2) The byte representation of the default genesis for tests -func defaultGenesis(t *testing.T) (*api.BuildGenesisArgs, []byte) { +func defaultGenesis(t *testing.T, avaxAssetID ids.ID) (*api.BuildGenesisArgs, []byte) { require := require.New(t) genesisUTXOs := make([]api.UTXO, len(keys)) @@ -304,7 +260,7 @@ func defaultVM(t *testing.T, fork activeFork) (*VM, database.Database, *mutableS vm.clock.Set(latestForkTime) msgChan := make(chan common.Message, 1) - ctx := defaultContext(t) + ctx := snowtest.Context(t, snowtest.PChainID) m := atomic.NewMemory(atomicDB) msm := &mutableSharedMemory{ @@ -314,7 +270,7 @@ func defaultVM(t *testing.T, fork activeFork) (*VM, database.Database, *mutableS ctx.Lock.Lock() defer ctx.Lock.Unlock() - _, genesisBytes := defaultGenesis(t) + _, genesisBytes := defaultGenesis(t, ctx.AVAXAssetID) appSender := &common.SenderTest{} appSender.CantSendAppGossip = true appSender.SendAppGossipF = func(context.Context, []byte) error { @@ -378,7 +334,7 @@ func TestGenesis(t *testing.T) { require.NoError(err) require.Equal(choices.Accepted, genesisBlock.Status()) - genesisState, _ := defaultGenesis(t) + genesisState, _ := defaultGenesis(t, vm.ctx.AVAXAssetID) // Ensure all the genesis UTXOs are there for _, utxo := range genesisState.UTXOs { _, addrBytes, err := address.ParseBech32(utxo.Address) @@ -1030,7 +986,7 @@ func TestAtomicImport(t *testing.T) { utxo := &avax.UTXO{ UTXOID: utxoID, - Asset: avax.Asset{ID: avaxAssetID}, + Asset: avax.Asset{ID: vm.ctx.AVAXAssetID}, Out: &secp256k1fx.TransferOutput{ Amt: amount, OutputOwners: secp256k1fx.OutputOwners{ @@ -1146,7 +1102,6 @@ func TestOptimisticAtomicImport(t *testing.T) { // test restarting the node func TestRestartFullyAccepted(t *testing.T) { require := require.New(t) - _, genesisBytes := defaultGenesis(t) db := memdb.New() firstDB := prefixdb.New([]byte{}, db) @@ -1162,7 +1117,9 @@ func TestRestartFullyAccepted(t *testing.T) { DurangoTime: latestForkTime, }} - firstCtx := defaultContext(t) + firstCtx := snowtest.Context(t, snowtest.PChainID) + + _, genesisBytes := defaultGenesis(t, firstCtx.AVAXAssetID) baseDB := memdb.New() atomicDB := prefixdb.New([]byte{1}, baseDB) @@ -1247,7 +1204,7 @@ func TestRestartFullyAccepted(t *testing.T) { DurangoTime: latestForkTime, }} - secondCtx := defaultContext(t) + secondCtx := snowtest.Context(t, snowtest.PChainID) secondCtx.SharedMemory = firstCtx.SharedMemory secondVM.clock.Set(initialClkTime) secondCtx.Lock.Lock() @@ -1279,8 +1236,6 @@ func TestRestartFullyAccepted(t *testing.T) { func TestBootstrapPartiallyAccepted(t *testing.T) { require := require.New(t) - _, genesisBytes := defaultGenesis(t) - baseDB := memdb.New() vmDB := prefixdb.New([]byte("vm"), baseDB) bootstrappingDB := prefixdb.New([]byte("bootstrapping"), baseDB) @@ -1301,7 +1256,9 @@ func TestBootstrapPartiallyAccepted(t *testing.T) { initialClkTime := latestForkTime.Add(time.Second) vm.clock.Set(initialClkTime) - ctx := defaultContext(t) + ctx := snowtest.Context(t, snowtest.PChainID) + + _, genesisBytes := defaultGenesis(t, ctx.AVAXAssetID) atomicDB := prefixdb.New([]byte{1}, baseDB) m := atomic.NewMemory(atomicDB) @@ -1626,7 +1583,6 @@ func TestBootstrapPartiallyAccepted(t *testing.T) { func TestUnverifiedParent(t *testing.T) { require := require.New(t) - _, genesisBytes := defaultGenesis(t) vm := &VM{Config: config.Config{ Chains: chains.TestManager, @@ -1642,13 +1598,15 @@ func TestUnverifiedParent(t *testing.T) { initialClkTime := latestForkTime.Add(time.Second) vm.clock.Set(initialClkTime) - ctx := defaultContext(t) + ctx := snowtest.Context(t, snowtest.PChainID) ctx.Lock.Lock() defer func() { require.NoError(vm.Shutdown(context.Background())) ctx.Lock.Unlock() }() + _, genesisBytes := defaultGenesis(t, ctx.AVAXAssetID) + msgChan := make(chan common.Message, 1) require.NoError(vm.Initialize( context.Background(), @@ -1786,7 +1744,6 @@ func TestMaxStakeAmount(t *testing.T) { func TestUptimeDisallowedWithRestart(t *testing.T) { require := require.New(t) latestForkTime = defaultValidateStartTime.Add(defaultMinStakingDuration) - _, genesisBytes := defaultGenesis(t) db := memdb.New() firstDB := prefixdb.New([]byte{}, db) @@ -1802,9 +1759,11 @@ func TestUptimeDisallowedWithRestart(t *testing.T) { DurangoTime: latestForkTime, }} - firstCtx := defaultContext(t) + firstCtx := snowtest.Context(t, snowtest.PChainID) firstCtx.Lock.Lock() + _, genesisBytes := defaultGenesis(t, firstCtx.AVAXAssetID) + firstMsgChan := make(chan common.Message, 1) require.NoError(firstVM.Initialize( context.Background(), @@ -1848,7 +1807,7 @@ func TestUptimeDisallowedWithRestart(t *testing.T) { DurangoTime: latestForkTime, }} - secondCtx := defaultContext(t) + secondCtx := snowtest.Context(t, snowtest.PChainID) secondCtx.Lock.Lock() defer func() { require.NoError(secondVM.Shutdown(context.Background())) @@ -1933,7 +1892,7 @@ func TestUptimeDisallowedWithRestart(t *testing.T) { func TestUptimeDisallowedAfterNeverConnecting(t *testing.T) { require := require.New(t) latestForkTime = defaultValidateStartTime.Add(defaultMinStakingDuration) - _, genesisBytes := defaultGenesis(t) + db := memdb.New() vm := &VM{Config: config.Config{ @@ -1947,9 +1906,11 @@ func TestUptimeDisallowedAfterNeverConnecting(t *testing.T) { DurangoTime: latestForkTime, }} - ctx := defaultContext(t) + ctx := snowtest.Context(t, snowtest.PChainID) ctx.Lock.Lock() + _, genesisBytes := defaultGenesis(t, ctx.AVAXAssetID) + atomicDB := prefixdb.New([]byte{1}, db) m := atomic.NewMemory(atomicDB) ctx.SharedMemory = m.NewSharedMemory(ctx.ChainID)