From a693a154c309d2bc0524168c768a899ef40d6f64 Mon Sep 17 00:00:00 2001 From: Austin Larson <78000745+alarso16@users.noreply.github.com> Date: Mon, 10 Nov 2025 11:21:23 -0500 Subject: [PATCH 1/6] ci: Missing test import lint (#1394) --- plugin/evm/tx_gossip_test.go | 5 ++-- utils/utilstest/context.go | 42 ----------------------------- utils/utilstest/snow.go | 52 ++++++++++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+), 44 deletions(-) create mode 100644 utils/utilstest/snow.go diff --git a/plugin/evm/tx_gossip_test.go b/plugin/evm/tx_gossip_test.go index cf9209362d..69b23754a3 100644 --- a/plugin/evm/tx_gossip_test.go +++ b/plugin/evm/tx_gossip_test.go @@ -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" @@ -36,8 +37,8 @@ import ( func TestEthTxGossip(t *testing.T) { require := require.New(t) - ctx := context.Background() - snowCtx := utilstest.NewTestSnowContext(t) + ctx := t.Context() + snowCtx := snowtest.Context(t, snowtest.CChainID) validatorState := utilstest.NewTestValidatorState() snowCtx.ValidatorState = validatorState diff --git a/utils/utilstest/context.go b/utils/utilstest/context.go index 16fa6ddf0b..bfcdcfa32c 100644 --- a/utils/utilstest/context.go +++ b/utils/utilstest/context.go @@ -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. // diff --git a/utils/utilstest/snow.go b/utils/utilstest/snow.go new file mode 100644 index 0000000000..f2015779d2 --- /dev/null +++ b/utils/utilstest/snow.go @@ -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 + }, + } +} From f7ad0df24e1bc258c8ecd17edeb5b6afc7dfa0bb Mon Sep 17 00:00:00 2001 From: Jonathan Oppenheimer Date: Fri, 21 Nov 2025 12:54:25 -0500 Subject: [PATCH 2/6] Cey suggestion --- plugin/evm/tx_gossip_test.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/plugin/evm/tx_gossip_test.go b/plugin/evm/tx_gossip_test.go index 69b23754a3..5856aecbf5 100644 --- a/plugin/evm/tx_gossip_test.go +++ b/plugin/evm/tx_gossip_test.go @@ -38,8 +38,12 @@ import ( func TestEthTxGossip(t *testing.T) { require := require.New(t) ctx := t.Context() - snowCtx := snowtest.Context(t, snowtest.CChainID) + validatorState := utilstest.NewTestValidatorState() + subnetID, err := validatorState.GetSubnetID(t.Context(), snowtest.CChainID) + require.NoError(err) + + snowCtx := snowtest.Context(t, subnetID) snowCtx.ValidatorState = validatorState responseSender := &enginetest.SenderStub{ From 875228038c1a93265af5966b2ffecf9552bb1977 Mon Sep 17 00:00:00 2001 From: Jonathan Oppenheimer Date: Fri, 21 Nov 2025 22:07:21 -0500 Subject: [PATCH 3/6] fix: use proper subnet chain ID --- plugin/evm/tx_gossip_test.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/plugin/evm/tx_gossip_test.go b/plugin/evm/tx_gossip_test.go index 93c7c0bc4c..b73f5915f6 100644 --- a/plugin/evm/tx_gossip_test.go +++ b/plugin/evm/tx_gossip_test.go @@ -35,15 +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() validatorState := utilstest.NewTestValidatorState() - subnetID, err := validatorState.GetSubnetID(t.Context(), snowtest.CChainID) - require.NoError(err) - snowCtx := snowtest.Context(t, subnetID) + snowCtx := snowtest.Context(t, SubnetEVMTestChainID) snowCtx.ValidatorState = validatorState responseSender := &enginetest.SenderStub{ From 0a2836ce49f058ffa390e3ba95da67b000108957 Mon Sep 17 00:00:00 2001 From: Jonathan Oppenheimer Date: Mon, 24 Nov 2025 10:40:05 -0500 Subject: [PATCH 4/6] Update plugin/evm/tx_gossip_test.go Co-authored-by: Austin Larson <78000745+alarso16@users.noreply.github.com> Signed-off-by: Jonathan Oppenheimer <147infiniti@gmail.com> --- plugin/evm/tx_gossip_test.go | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/plugin/evm/tx_gossip_test.go b/plugin/evm/tx_gossip_test.go index b73f5915f6..ff08882f65 100644 --- a/plugin/evm/tx_gossip_test.go +++ b/plugin/evm/tx_gossip_test.go @@ -41,11 +41,8 @@ var SubnetEVMTestChainID = ids.GenerateTestID() func TestEthTxGossip(t *testing.T) { require := require.New(t) ctx := t.Context() - - validatorState := utilstest.NewTestValidatorState() - snowCtx := snowtest.Context(t, SubnetEVMTestChainID) - snowCtx.ValidatorState = validatorState +snowCtx.ValidatorState = utilstest.NewTestValidatorState() responseSender := &enginetest.SenderStub{ SentAppResponse: make(chan []byte, 1), From 3bb75e70be3b91dba0f9813d34c0f7d9816a79ea Mon Sep 17 00:00:00 2001 From: Jonathan Oppenheimer Date: Mon, 24 Nov 2025 10:41:24 -0500 Subject: [PATCH 5/6] fix: austin suggestion tabbing --- plugin/evm/tx_gossip_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/evm/tx_gossip_test.go b/plugin/evm/tx_gossip_test.go index ff08882f65..8e6f8ca0fa 100644 --- a/plugin/evm/tx_gossip_test.go +++ b/plugin/evm/tx_gossip_test.go @@ -42,7 +42,7 @@ func TestEthTxGossip(t *testing.T) { require := require.New(t) ctx := t.Context() snowCtx := snowtest.Context(t, SubnetEVMTestChainID) -snowCtx.ValidatorState = utilstest.NewTestValidatorState() + snowCtx.ValidatorState = utilstest.NewTestValidatorState() responseSender := &enginetest.SenderStub{ SentAppResponse: make(chan []byte, 1), From ae1d79cfae8fcae605d6b6a603702806209f50ce Mon Sep 17 00:00:00 2001 From: Jonathan Oppenheimer Date: Mon, 24 Nov 2025 10:49:31 -0500 Subject: [PATCH 6/6] fix: revert Austin suggestion --- plugin/evm/tx_gossip_test.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/plugin/evm/tx_gossip_test.go b/plugin/evm/tx_gossip_test.go index 8e6f8ca0fa..d983586878 100644 --- a/plugin/evm/tx_gossip_test.go +++ b/plugin/evm/tx_gossip_test.go @@ -42,7 +42,8 @@ func TestEthTxGossip(t *testing.T) { require := require.New(t) ctx := t.Context() snowCtx := snowtest.Context(t, SubnetEVMTestChainID) - snowCtx.ValidatorState = utilstest.NewTestValidatorState() + validatorState := utilstest.NewTestValidatorState() + snowCtx.ValidatorState = validatorState responseSender := &enginetest.SenderStub{ SentAppResponse: make(chan []byte, 1), @@ -73,7 +74,7 @@ func TestEthTxGossip(t *testing.T) { validatorSet := p2p.NewValidators( logging.NoLog{}, snowCtx.SubnetID, - validatorState, + snowCtx.ValidatorState, 0, ) network, err := p2p.NewNetwork(