Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions plugin/evm/tx_gossip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/ava-labs/avalanchego/proto/pb/sdk"
"github.com/ava-labs/avalanchego/snow"
"github.com/ava-labs/avalanchego/snow/engine/enginetest"
"github.com/ava-labs/avalanchego/snow/snowtest"
"github.com/ava-labs/avalanchego/snow/validators"
"github.com/ava-labs/avalanchego/upgrade/upgradetest"
"github.com/ava-labs/avalanchego/utils/logging"
Expand All @@ -34,10 +35,13 @@ import (
agoUtils "github.com/ava-labs/avalanchego/utils"
)

// SubnetEVMTestChainID is a subnet-evm specific chain ID for testing
var SubnetEVMTestChainID = ids.GenerateTestID()

func TestEthTxGossip(t *testing.T) {
require := require.New(t)
ctx := t.Context()
snowCtx := utilstest.NewTestSnowContext(t)
snowCtx := snowtest.Context(t, SubnetEVMTestChainID)
validatorState := utilstest.NewTestValidatorState()
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need to separately define this to set GetValidatorSetF on line 96.

snowCtx.ValidatorState = validatorState

Expand Down Expand Up @@ -70,7 +74,7 @@ func TestEthTxGossip(t *testing.T) {
validatorSet := p2p.NewValidators(
logging.NoLog{},
snowCtx.SubnetID,
validatorState,
snowCtx.ValidatorState,
0,
)
network, err := p2p.NewNetwork(
Expand Down
42 changes: 0 additions & 42 deletions utils/utilstest/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,55 +4,13 @@
package utilstest

import (
"context"
"errors"
"testing"

"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/validators"
"github.com/ava-labs/avalanchego/snow/validators/validatorstest"
"github.com/ava-labs/avalanchego/utils/constants"
)

// SubnetEVMTestChainID is a subnet-evm specific chain ID for testing
var SubnetEVMTestChainID = ids.GenerateTestID()

// @TODO: This should eventually be replaced by a more robust solution, or alternatively, the presence of nil
// validator states shouldn't be depended upon by tests
func NewTestValidatorState() *validatorstest.State {
return &validatorstest.State{
GetCurrentHeightF: func(context.Context) (uint64, error) {
return 0, nil
},
GetSubnetIDF: func(_ context.Context, chainID ids.ID) (ids.ID, error) {
subnetID, ok := map[ids.ID]ids.ID{
constants.PlatformChainID: constants.PrimaryNetworkID,
snowtest.XChainID: constants.PrimaryNetworkID,
snowtest.CChainID: constants.PrimaryNetworkID,
SubnetEVMTestChainID: constants.PrimaryNetworkID,
}[chainID]
if !ok {
return ids.Empty, errors.New("unknown chain")
}
return subnetID, nil
},
GetValidatorSetF: func(context.Context, uint64, ids.ID) (map[ids.NodeID]*validators.GetValidatorOutput, error) {
return map[ids.NodeID]*validators.GetValidatorOutput{}, nil
},
GetWarpValidatorSetsF: func(context.Context, uint64) (map[ids.ID]validators.WarpSet, error) {
return nil, nil
},
GetWarpValidatorSetF: func(context.Context, uint64, ids.ID) (validators.WarpSet, error) {
return validators.WarpSet{}, nil
},
GetCurrentValidatorSetF: func(context.Context, ids.ID) (map[ids.ID]*validators.GetCurrentValidatorOutput, uint64, error) {
return map[ids.ID]*validators.GetCurrentValidatorOutput{}, 0, nil
},
}
}

// NewTestSnowContext returns a snow.Context with validator state properly configured for testing.
// This wraps snowtest.Context and sets the validator state to avoid the missing GetValidatorSetF issue.
//
Expand Down
52 changes: 52 additions & 0 deletions utils/utilstest/snow.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.

package utilstest

import (
"context"
"errors"

"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/snow/snowtest"
"github.com/ava-labs/avalanchego/snow/validators"
"github.com/ava-labs/avalanchego/snow/validators/validatorstest"
"github.com/ava-labs/avalanchego/utils/constants"
)

// SubnetEVMTestChainID is a subnet-evm specific chain ID for testing
var SubnetEVMTestChainID = ids.GenerateTestID()

// @TODO: This should eventually be replaced by a more robust solution, or alternatively, the presence of nil
// validator states shouldn't be depended upon by tests
func NewTestValidatorState() *validatorstest.State {
return &validatorstest.State{
GetCurrentHeightF: func(context.Context) (uint64, error) {
return 0, nil
},
GetSubnetIDF: func(_ context.Context, chainID ids.ID) (ids.ID, error) {
subnetID, ok := map[ids.ID]ids.ID{
constants.PlatformChainID: constants.PrimaryNetworkID,
snowtest.XChainID: constants.PrimaryNetworkID,
snowtest.CChainID: constants.PrimaryNetworkID,
SubnetEVMTestChainID: constants.PrimaryNetworkID,
}[chainID]
if !ok {
return ids.Empty, errors.New("unknown chain")
}
return subnetID, nil
},
GetValidatorSetF: func(context.Context, uint64, ids.ID) (map[ids.NodeID]*validators.GetValidatorOutput, error) {
return map[ids.NodeID]*validators.GetValidatorOutput{}, nil
},
GetWarpValidatorSetsF: func(context.Context, uint64) (map[ids.ID]validators.WarpSet, error) {
return nil, nil
},
GetWarpValidatorSetF: func(context.Context, uint64, ids.ID) (validators.WarpSet, error) {
return validators.WarpSet{}, nil
},
GetCurrentValidatorSetF: func(context.Context, ids.ID) (map[ids.ID]*validators.GetCurrentValidatorOutput, uint64, error) {
return map[ids.ID]*validators.GetCurrentValidatorOutput{}, 0, nil
},
}
}
Loading