Skip to content
This repository was archived by the owner on Dec 16, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 4 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: 7 additions & 1 deletion 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,11 +35,16 @@ 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)

validatorState := utilstest.NewTestValidatorState()

snowCtx := snowtest.Context(t, SubnetEVMTestChainID)
snowCtx.ValidatorState = validatorState

responseSender := &enginetest.SenderStub{
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