Skip to content

Commit

Permalink
Remove snow.DefaultContextTest (#2518)
Browse files Browse the repository at this point in the history
  • Loading branch information
dhrubabasu authored Dec 22, 2023
1 parent f59e46f commit a809807
Show file tree
Hide file tree
Showing 35 changed files with 367 additions and 305 deletions.
4 changes: 3 additions & 1 deletion api/server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/stretchr/testify/require"

"github.com/ava-labs/avalanchego/snow"
"github.com/ava-labs/avalanchego/snow/snowtest"
)

func TestRejectMiddleware(t *testing.T) {
Expand Down Expand Up @@ -58,7 +59,8 @@ func TestRejectMiddleware(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
require := require.New(t)

ctx := &snow.ConsensusContext{}
snowCtx := snowtest.Context(t, snowtest.CChainID)
ctx := snowtest.ConsensusContext(snowCtx)
ctx.State.Set(snow.EngineState{
State: tt.state,
})
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ require (
github.com/DataDog/zstd v1.5.2
github.com/Microsoft/go-winio v0.5.2
github.com/NYTimes/gziphandler v1.1.1
github.com/ava-labs/coreth v0.12.9-rc.9.0.20231219231451-224728dbacb4
github.com/ava-labs/coreth v0.12.9-rc.9.0.20231222191417-2e3f762373e9
github.com/ava-labs/ledger-avalanche/go v0.0.0-20231102202641-ae2ebdaeac34
github.com/btcsuite/btcd/btcutil v1.1.3
github.com/cockroachdb/pebble v0.0.0-20230209160836-829675f94811
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ github.com/allegro/bigcache v1.2.1-0.20190218064605-e24eb225f156 h1:eMwmnE/GDgah
github.com/allegro/bigcache v1.2.1-0.20190218064605-e24eb225f156/go.mod h1:Cb/ax3seSYIx7SuZdm2G2xzfwmv3TPSk2ucNfQESPXM=
github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY=
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8=
github.com/ava-labs/coreth v0.12.9-rc.9.0.20231219231451-224728dbacb4 h1:LXL5nSxcblyBFR5/zdO4TAqSWqoB15bT3sGb1Nkh7o4=
github.com/ava-labs/coreth v0.12.9-rc.9.0.20231219231451-224728dbacb4/go.mod h1:84JZyt3colgzGI/jOYGB5Wzxr/wNP0zjebHiWZjFthk=
github.com/ava-labs/coreth v0.12.9-rc.9.0.20231222191417-2e3f762373e9 h1:DiJBkm2IJ/My4u5DP4gq2wIbdflFRuZJbDm8DbgNDdg=
github.com/ava-labs/coreth v0.12.9-rc.9.0.20231222191417-2e3f762373e9/go.mod h1:Xftjgk8T46k5/pWSQWcmdPanNl68kTcufd9S4kB58bM=
github.com/ava-labs/ledger-avalanche/go v0.0.0-20231102202641-ae2ebdaeac34 h1:mg9Uw6oZFJKytJxgxnl3uxZOs/SB8CVHg6Io4Tf99Zc=
github.com/ava-labs/ledger-avalanche/go v0.0.0-20231102202641-ae2ebdaeac34/go.mod h1:pJxaT9bUgeRNVmNRgtCHb7sFDIRKy7CzTQVi8gGNT6g=
github.com/aymerick/raymond v2.0.3-0.20180322193309-b565731e1464+incompatible/go.mod h1:osfaiScAUVup+UC9Nfq76eWqDhXlp+4UYaA8uhTBO6g=
Expand Down
9 changes: 6 additions & 3 deletions indexer/index_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ func TestIndex(t *testing.T) {
require.NoError(codec.RegisterCodec(codecVersion, linearcodec.NewDefault()))
baseDB := memdb.New()
db := versiondb.New(baseDB)
ctx := snowtest.ConsensusContext()
snowCtx := snowtest.Context(t, snowtest.CChainID)
ctx := snowtest.ConsensusContext(snowCtx)

indexIntf, err := newIndex(db, logging.NoLog{}, codec, mockable.Clock{})
require.NoError(err)
Expand Down Expand Up @@ -116,7 +117,8 @@ func TestIndexGetContainerByRangeMaxPageSize(t *testing.T) {
codec := codec.NewDefaultManager()
require.NoError(codec.RegisterCodec(codecVersion, linearcodec.NewDefault()))
db := memdb.New()
ctx := snowtest.ConsensusContext()
snowCtx := snowtest.Context(t, snowtest.CChainID)
ctx := snowtest.ConsensusContext(snowCtx)
indexIntf, err := newIndex(db, logging.NoLog{}, codec, mockable.Clock{})
require.NoError(err)
idx := indexIntf.(*index)
Expand Down Expand Up @@ -156,7 +158,8 @@ func TestDontIndexSameContainerTwice(t *testing.T) {
codec := codec.NewDefaultManager()
require.NoError(codec.RegisterCodec(codecVersion, linearcodec.NewDefault()))
db := memdb.New()
ctx := snowtest.ConsensusContext()
snowCtx := snowtest.Context(t, snowtest.CChainID)
ctx := snowtest.ConsensusContext(snowCtx)
idx, err := newIndex(db, logging.NoLog{}, codec, mockable.Clock{})
require.NoError(err)

Expand Down
21 changes: 11 additions & 10 deletions indexer/indexer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@ func TestIndexer(t *testing.T) {
idxr.clock.Set(now)

// Assert state is right
chain1Ctx := snowtest.ConsensusContext()
chain1Ctx.ChainID = ids.GenerateTestID()
snow1Ctx := snowtest.Context(t, snowtest.CChainID)
chain1Ctx := snowtest.ConsensusContext(snow1Ctx)
isIncomplete, err := idxr.isIncomplete(chain1Ctx.ChainID)
require.NoError(err)
require.False(isIncomplete)
Expand Down Expand Up @@ -259,8 +259,8 @@ func TestIndexer(t *testing.T) {
require.Contains(server.endpoints, "/block")

// Register a DAG chain
chain2Ctx := snowtest.ConsensusContext()
chain2Ctx.ChainID = ids.GenerateTestID()
snow2Ctx := snowtest.Context(t, snowtest.XChainID)
chain2Ctx := snowtest.ConsensusContext(snow2Ctx)
isIncomplete, err = idxr.isIncomplete(chain2Ctx.ChainID)
require.NoError(err)
require.False(isIncomplete)
Expand Down Expand Up @@ -419,8 +419,8 @@ func TestIncompleteIndex(t *testing.T) {
require.False(idxr.indexingEnabled)

// Register a chain
chain1Ctx := snowtest.ConsensusContext()
chain1Ctx.ChainID = ids.GenerateTestID()
snow1Ctx := snowtest.Context(t, snowtest.CChainID)
chain1Ctx := snowtest.ConsensusContext(snow1Ctx)
isIncomplete, err := idxr.isIncomplete(chain1Ctx.ChainID)
require.NoError(err)
require.False(isIncomplete)
Expand Down Expand Up @@ -501,10 +501,11 @@ func TestIgnoreNonDefaultChains(t *testing.T) {
require.IsType(&indexer{}, idxrIntf)
idxr := idxrIntf.(*indexer)

// Assert state is right
chain1Ctx := snowtest.ConsensusContext()
chain1Ctx.ChainID = ids.GenerateTestID()
chain1Ctx.SubnetID = ids.GenerateTestID()
// Create chain1Ctx for a random subnet + chain.
chain1Ctx := snowtest.ConsensusContext(&snow.Context{
ChainID: ids.GenerateTestID(),
SubnetID: ids.GenerateTestID(),
})

// RegisterChain should return without adding an index for this chain
chainVM := mocks.NewMockChainVM(ctrl)
Expand Down
6 changes: 2 additions & 4 deletions network/test_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"github.com/ava-labs/avalanchego/network/throttling"
"github.com/ava-labs/avalanchego/snow/networking/router"
"github.com/ava-labs/avalanchego/snow/networking/tracker"
"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/staking"
Expand Down Expand Up @@ -187,7 +186,6 @@ func NewTestNetwork(
networkConfig.TLSConfig = tlsConfig
networkConfig.TLSKey = tlsCert.PrivateKey.(crypto.Signer)

ctx := snowtest.ConsensusContext()
beacons := validators.NewManager()
networkConfig.Validators = currentValidators
networkConfig.Beacons = beacons
Expand All @@ -207,7 +205,7 @@ func NewTestNetwork(
return nil, err
}
networkConfig.CPUTargeter = tracker.NewTargeter(
ctx.Log,
logging.NoLog{},
&tracker.TargeterConfig{
VdrAlloc: float64(runtime.NumCPU()),
MaxNonVdrUsage: .8 * float64(runtime.NumCPU()),
Expand All @@ -217,7 +215,7 @@ func NewTestNetwork(
networkConfig.ResourceTracker.CPUTracker(),
)
networkConfig.DiskTargeter = tracker.NewTargeter(
ctx.Log,
logging.NoLog{},
&tracker.TargeterConfig{
VdrAlloc: 1000 * units.GiB,
MaxNonVdrUsage: 1000 * units.GiB,
Expand Down
Loading

0 comments on commit a809807

Please sign in to comment.