From f29b3b71230e2a4025319ce3e50f9e4c3fee0d79 Mon Sep 17 00:00:00 2001 From: Stephen Buttolph Date: Fri, 26 Apr 2024 16:10:25 -0400 Subject: [PATCH 01/24] Cleanup test blocks --- snow/consensus/snowman/consensus_test.go | 817 +++++++----------- snow/consensus/snowman/network_test.go | 21 +- snow/consensus/snowman/snowmantest/block.go | 90 ++ .../snowman/{ => snowmantest}/mock_block.go | 6 +- .../snowman/bootstrap/bootstrapper_test.go | 13 +- snow/engine/snowman/getter/getter_test.go | 5 +- snow/engine/snowman/transitive_test.go | 122 ++- 7 files changed, 475 insertions(+), 599 deletions(-) create mode 100644 snow/consensus/snowman/snowmantest/block.go rename snow/consensus/snowman/{ => snowmantest}/mock_block.go (95%) diff --git a/snow/consensus/snowman/consensus_test.go b/snow/consensus/snowman/consensus_test.go index 01ae6199cea5..43d24a6d6e9a 100644 --- a/snow/consensus/snowman/consensus_test.go +++ b/snow/consensus/snowman/consensus_test.go @@ -11,7 +11,6 @@ import ( "runtime" "strings" "testing" - "time" "github.com/prometheus/client_golang/prometheus" "github.com/stretchr/testify/require" @@ -20,6 +19,7 @@ import ( "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/snow/choices" "github.com/ava-labs/avalanchego/snow/consensus/snowball" + "github.com/ava-labs/avalanchego/snow/consensus/snowman/snowmantest" "github.com/ava-labs/avalanchego/snow/snowtest" "github.com/ava-labs/avalanchego/utils/bag" ) @@ -27,14 +27,6 @@ import ( type testFunc func(*testing.T, Factory) var ( - GenesisID = ids.Empty.Prefix(0) - GenesisHeight = uint64(0) - GenesisTimestamp = time.Unix(1, 0) - Genesis = &TestBlock{TestDecidable: choices.TestDecidable{ - IDV: GenesisID, - StatusV: choices.Accepted, - }} - testFuncs = []testFunc{ InitializeTest, NumProcessingTest, @@ -65,7 +57,6 @@ var ( ErrorOnTransitiveRejectionTest, RandomizedConsistencyTest, ErrorOnAddDecidedBlockTest, - ErrorOnAddDuplicateBlockIDTest, RecordPollWithDefaultParameters, RecordPollRegressionCalculateInDegreeIndegreeCalculation, } @@ -105,9 +96,15 @@ func InitializeTest(t *testing.T, factory Factory) { MaxItemProcessingTime: 1, } - require.NoError(sm.Initialize(ctx, params, GenesisID, GenesisHeight, GenesisTimestamp)) + require.NoError(sm.Initialize( + ctx, + params, + snowmantest.GenesisID, + snowmantest.GenesisHeight, + snowmantest.GenesisTimestamp, + )) - require.Equal(GenesisID, sm.Preference()) + require.Equal(snowmantest.GenesisID, sm.Preference()) require.Zero(sm.NumProcessing()) } @@ -129,27 +126,24 @@ func NumProcessingTest(t *testing.T, factory Factory) { MaxOutstandingItems: 1, MaxItemProcessingTime: 1, } - require.NoError(sm.Initialize(ctx, params, GenesisID, GenesisHeight, GenesisTimestamp)) + require.NoError(sm.Initialize( + ctx, + params, + snowmantest.GenesisID, + snowmantest.GenesisHeight, + snowmantest.GenesisTimestamp, + )) - block := &TestBlock{ - TestDecidable: choices.TestDecidable{ - IDV: ids.Empty.Prefix(1), - StatusV: choices.Processing, - }, - ParentV: Genesis.IDV, - HeightV: Genesis.HeightV + 1, - } + block := snowmantest.BuildChildBlock(snowmantest.Genesis) require.Zero(sm.NumProcessing()) // Adding to the previous preference will update the preference require.NoError(sm.Add(context.Background(), block)) - require.Equal(1, sm.NumProcessing()) votes := bag.Of(block.ID()) require.NoError(sm.RecordPoll(context.Background(), votes)) - require.Zero(sm.NumProcessing()) } @@ -171,16 +165,15 @@ func AddToTailTest(t *testing.T, factory Factory) { MaxOutstandingItems: 1, MaxItemProcessingTime: 1, } - require.NoError(sm.Initialize(ctx, params, GenesisID, GenesisHeight, GenesisTimestamp)) + require.NoError(sm.Initialize( + ctx, + params, + snowmantest.GenesisID, + snowmantest.GenesisHeight, + snowmantest.GenesisTimestamp, + )) - block := &TestBlock{ - TestDecidable: choices.TestDecidable{ - IDV: ids.Empty.Prefix(1), - StatusV: choices.Processing, - }, - ParentV: Genesis.IDV, - HeightV: Genesis.HeightV + 1, - } + block := snowmantest.BuildChildBlock(snowmantest.Genesis) // Adding to the previous preference will update the preference require.NoError(sm.Add(context.Background(), block)) @@ -210,24 +203,16 @@ func AddToNonTailTest(t *testing.T, factory Factory) { MaxOutstandingItems: 1, MaxItemProcessingTime: 1, } - require.NoError(sm.Initialize(ctx, params, GenesisID, GenesisHeight, GenesisTimestamp)) + require.NoError(sm.Initialize( + ctx, + params, + snowmantest.GenesisID, + snowmantest.GenesisHeight, + snowmantest.GenesisTimestamp, + )) - firstBlock := &TestBlock{ - TestDecidable: choices.TestDecidable{ - IDV: ids.Empty.Prefix(1), - StatusV: choices.Processing, - }, - ParentV: Genesis.IDV, - HeightV: Genesis.HeightV + 1, - } - secondBlock := &TestBlock{ - TestDecidable: choices.TestDecidable{ - IDV: ids.Empty.Prefix(2), - StatusV: choices.Processing, - }, - ParentV: Genesis.IDV, - HeightV: Genesis.HeightV + 1, - } + firstBlock := snowmantest.BuildChildBlock(snowmantest.Genesis) + secondBlock := snowmantest.BuildChildBlock(snowmantest.Genesis) // Adding to the previous preference will update the preference require.NoError(sm.Add(context.Background(), firstBlock)) @@ -258,26 +243,27 @@ func AddToUnknownTest(t *testing.T, factory Factory) { MaxOutstandingItems: 1, MaxItemProcessingTime: 1, } - require.NoError(sm.Initialize(ctx, params, GenesisID, GenesisHeight, GenesisTimestamp)) + require.NoError(sm.Initialize( + ctx, + params, + snowmantest.GenesisID, + snowmantest.GenesisHeight, + snowmantest.GenesisTimestamp, + )) - parent := &TestBlock{TestDecidable: choices.TestDecidable{ - IDV: ids.Empty.Prefix(1), - StatusV: choices.Unknown, - }} - - block := &TestBlock{ + block := &snowmantest.Block{ TestDecidable: choices.TestDecidable{ - IDV: ids.Empty.Prefix(2), + IDV: ids.GenerateTestID(), StatusV: choices.Processing, }, - ParentV: parent.IDV, - HeightV: parent.HeightV + 1, + ParentV: ids.GenerateTestID(), + HeightV: snowmantest.GenesisHeight + 2, } // Adding a block with an unknown parent means the parent must have already // been rejected. Therefore the block should be immediately rejected require.NoError(sm.Add(context.Background(), block)) - require.Equal(GenesisID, sm.Preference()) + require.Equal(snowmantest.GenesisID, sm.Preference()) require.Equal(choices.Rejected, block.Status()) } @@ -298,16 +284,22 @@ func StatusOrProcessingPreviouslyAcceptedTest(t *testing.T, factory Factory) { MaxOutstandingItems: 1, MaxItemProcessingTime: 1, } - require.NoError(sm.Initialize(ctx, params, GenesisID, GenesisHeight, GenesisTimestamp)) + require.NoError(sm.Initialize( + ctx, + params, + snowmantest.GenesisID, + snowmantest.GenesisHeight, + snowmantest.GenesisTimestamp, + )) - require.Equal(choices.Accepted, Genesis.Status()) - require.False(sm.Processing(Genesis.ID())) - require.True(sm.Decided(Genesis)) - require.True(sm.IsPreferred(Genesis)) + require.Equal(choices.Accepted, snowmantest.Genesis.Status()) + require.False(sm.Processing(snowmantest.Genesis.ID())) + require.True(sm.Decided(snowmantest.Genesis)) + require.True(sm.IsPreferred(snowmantest.Genesis)) - pref, ok := sm.PreferenceAtHeight(Genesis.Height()) + pref, ok := sm.PreferenceAtHeight(snowmantest.Genesis.Height()) require.True(ok) - require.Equal(Genesis.ID(), pref) + require.Equal(snowmantest.Genesis.ID(), pref) } func StatusOrProcessingPreviouslyRejectedTest(t *testing.T, factory Factory) { @@ -327,16 +319,16 @@ func StatusOrProcessingPreviouslyRejectedTest(t *testing.T, factory Factory) { MaxOutstandingItems: 1, MaxItemProcessingTime: 1, } - require.NoError(sm.Initialize(ctx, params, GenesisID, GenesisHeight, GenesisTimestamp)) + require.NoError(sm.Initialize( + ctx, + params, + snowmantest.GenesisID, + snowmantest.GenesisHeight, + snowmantest.GenesisTimestamp, + )) - block := &TestBlock{ - TestDecidable: choices.TestDecidable{ - IDV: ids.Empty.Prefix(1), - StatusV: choices.Rejected, - }, - ParentV: Genesis.IDV, - HeightV: Genesis.HeightV + 1, - } + block := snowmantest.BuildChildBlock(snowmantest.Genesis) + require.NoError(block.Reject(context.Background())) require.Equal(choices.Rejected, block.Status()) require.False(sm.Processing(block.ID())) @@ -364,16 +356,15 @@ func StatusOrProcessingUnissuedTest(t *testing.T, factory Factory) { MaxOutstandingItems: 1, MaxItemProcessingTime: 1, } - require.NoError(sm.Initialize(ctx, params, GenesisID, GenesisHeight, GenesisTimestamp)) + require.NoError(sm.Initialize( + ctx, + params, + snowmantest.GenesisID, + snowmantest.GenesisHeight, + snowmantest.GenesisTimestamp, + )) - block := &TestBlock{ - TestDecidable: choices.TestDecidable{ - IDV: ids.Empty.Prefix(1), - StatusV: choices.Processing, - }, - ParentV: Genesis.IDV, - HeightV: Genesis.HeightV + 1, - } + block := snowmantest.BuildChildBlock(snowmantest.Genesis) require.Equal(choices.Processing, block.Status()) require.False(sm.Processing(block.ID())) @@ -401,16 +392,15 @@ func StatusOrProcessingIssuedTest(t *testing.T, factory Factory) { MaxOutstandingItems: 1, MaxItemProcessingTime: 1, } - require.NoError(sm.Initialize(ctx, params, GenesisID, GenesisHeight, GenesisTimestamp)) + require.NoError(sm.Initialize( + ctx, + params, + snowmantest.GenesisID, + snowmantest.GenesisHeight, + snowmantest.GenesisTimestamp, + )) - block := &TestBlock{ - TestDecidable: choices.TestDecidable{ - IDV: ids.Empty.Prefix(1), - StatusV: choices.Processing, - }, - ParentV: Genesis.IDV, - HeightV: Genesis.HeightV + 1, - } + block := snowmantest.BuildChildBlock(snowmantest.Genesis) require.NoError(sm.Add(context.Background(), block)) require.Equal(choices.Processing, block.Status()) @@ -440,16 +430,15 @@ func RecordPollAcceptSingleBlockTest(t *testing.T, factory Factory) { MaxOutstandingItems: 1, MaxItemProcessingTime: 1, } - require.NoError(sm.Initialize(ctx, params, GenesisID, GenesisHeight, GenesisTimestamp)) + require.NoError(sm.Initialize( + ctx, + params, + snowmantest.GenesisID, + snowmantest.GenesisHeight, + snowmantest.GenesisTimestamp, + )) - block := &TestBlock{ - TestDecidable: choices.TestDecidable{ - IDV: ids.Empty.Prefix(1), - StatusV: choices.Processing, - }, - ParentV: Genesis.IDV, - HeightV: Genesis.HeightV + 1, - } + block := snowmantest.BuildChildBlock(snowmantest.Genesis) require.NoError(sm.Add(context.Background(), block)) @@ -482,24 +471,16 @@ func RecordPollAcceptAndRejectTest(t *testing.T, factory Factory) { MaxOutstandingItems: 1, MaxItemProcessingTime: 1, } - require.NoError(sm.Initialize(ctx, params, GenesisID, GenesisHeight, GenesisTimestamp)) + require.NoError(sm.Initialize( + ctx, + params, + snowmantest.GenesisID, + snowmantest.GenesisHeight, + snowmantest.GenesisTimestamp, + )) - firstBlock := &TestBlock{ - TestDecidable: choices.TestDecidable{ - IDV: ids.Empty.Prefix(1), - StatusV: choices.Processing, - }, - ParentV: Genesis.IDV, - HeightV: Genesis.HeightV + 1, - } - secondBlock := &TestBlock{ - TestDecidable: choices.TestDecidable{ - IDV: ids.Empty.Prefix(2), - StatusV: choices.Processing, - }, - ParentV: Genesis.IDV, - HeightV: Genesis.HeightV + 1, - } + firstBlock := snowmantest.BuildChildBlock(snowmantest.Genesis) + secondBlock := snowmantest.BuildChildBlock(snowmantest.Genesis) require.NoError(sm.Add(context.Background(), firstBlock)) require.NoError(sm.Add(context.Background(), secondBlock)) @@ -538,24 +519,16 @@ func RecordPollSplitVoteNoChangeTest(t *testing.T, factory Factory) { MaxOutstandingItems: 1, MaxItemProcessingTime: 1, } - require.NoError(sm.Initialize(ctx, params, GenesisID, GenesisHeight, GenesisTimestamp)) + require.NoError(sm.Initialize( + ctx, + params, + snowmantest.GenesisID, + snowmantest.GenesisHeight, + snowmantest.GenesisTimestamp, + )) - firstBlock := &TestBlock{ - TestDecidable: choices.TestDecidable{ - IDV: ids.Empty.Prefix(1), - StatusV: choices.Processing, - }, - ParentV: Genesis.IDV, - HeightV: Genesis.HeightV + 1, - } - secondBlock := &TestBlock{ - TestDecidable: choices.TestDecidable{ - IDV: ids.Empty.Prefix(2), - StatusV: choices.Processing, - }, - ParentV: Genesis.IDV, - HeightV: Genesis.HeightV + 1, - } + firstBlock := snowmantest.BuildChildBlock(snowmantest.Genesis) + secondBlock := snowmantest.BuildChildBlock(snowmantest.Genesis) require.NoError(sm.Add(context.Background(), firstBlock)) require.NoError(sm.Add(context.Background(), secondBlock)) @@ -598,12 +571,18 @@ func RecordPollWhenFinalizedTest(t *testing.T, factory Factory) { MaxOutstandingItems: 1, MaxItemProcessingTime: 1, } - require.NoError(sm.Initialize(ctx, params, GenesisID, GenesisHeight, GenesisTimestamp)) + require.NoError(sm.Initialize( + ctx, + params, + snowmantest.GenesisID, + snowmantest.GenesisHeight, + snowmantest.GenesisTimestamp, + )) - votes := bag.Of(GenesisID) + votes := bag.Of(snowmantest.GenesisID) require.NoError(sm.RecordPoll(context.Background(), votes)) require.Zero(sm.NumProcessing()) - require.Equal(GenesisID, sm.Preference()) + require.Equal(snowmantest.GenesisID, sm.Preference()) } func RecordPollRejectTransitivelyTest(t *testing.T, factory Factory) { @@ -623,32 +602,17 @@ func RecordPollRejectTransitivelyTest(t *testing.T, factory Factory) { MaxOutstandingItems: 1, MaxItemProcessingTime: 1, } - require.NoError(sm.Initialize(ctx, params, GenesisID, GenesisHeight, GenesisTimestamp)) + require.NoError(sm.Initialize( + ctx, + params, + snowmantest.GenesisID, + snowmantest.GenesisHeight, + snowmantest.GenesisTimestamp, + )) - block0 := &TestBlock{ - TestDecidable: choices.TestDecidable{ - IDV: ids.Empty.Prefix(1), - StatusV: choices.Processing, - }, - ParentV: Genesis.IDV, - HeightV: Genesis.HeightV + 1, - } - block1 := &TestBlock{ - TestDecidable: choices.TestDecidable{ - IDV: ids.Empty.Prefix(2), - StatusV: choices.Processing, - }, - ParentV: Genesis.IDV, - HeightV: Genesis.HeightV + 1, - } - block2 := &TestBlock{ - TestDecidable: choices.TestDecidable{ - IDV: ids.Empty.Prefix(3), - StatusV: choices.Processing, - }, - ParentV: block1.IDV, - HeightV: block1.HeightV + 1, - } + block0 := snowmantest.BuildChildBlock(snowmantest.Genesis) + block1 := snowmantest.BuildChildBlock(snowmantest.Genesis) + block2 := snowmantest.BuildChildBlock(block1) require.NoError(sm.Add(context.Background(), block0)) require.NoError(sm.Add(context.Background(), block1)) @@ -693,40 +657,18 @@ func RecordPollTransitivelyResetConfidenceTest(t *testing.T, factory Factory) { MaxOutstandingItems: 1, MaxItemProcessingTime: 1, } - require.NoError(sm.Initialize(ctx, params, GenesisID, GenesisHeight, GenesisTimestamp)) + require.NoError(sm.Initialize( + ctx, + params, + snowmantest.GenesisID, + snowmantest.GenesisHeight, + snowmantest.GenesisTimestamp, + )) - block0 := &TestBlock{ - TestDecidable: choices.TestDecidable{ - IDV: ids.Empty.Prefix(1), - StatusV: choices.Processing, - }, - ParentV: Genesis.IDV, - HeightV: Genesis.HeightV + 1, - } - block1 := &TestBlock{ - TestDecidable: choices.TestDecidable{ - IDV: ids.Empty.Prefix(2), - StatusV: choices.Processing, - }, - ParentV: Genesis.IDV, - HeightV: Genesis.HeightV + 1, - } - block2 := &TestBlock{ - TestDecidable: choices.TestDecidable{ - IDV: ids.Empty.Prefix(3), - StatusV: choices.Processing, - }, - ParentV: block1.IDV, - HeightV: block1.HeightV + 1, - } - block3 := &TestBlock{ - TestDecidable: choices.TestDecidable{ - IDV: ids.Empty.Prefix(4), - StatusV: choices.Processing, - }, - ParentV: block1.IDV, - HeightV: block1.HeightV + 1, - } + block0 := snowmantest.BuildChildBlock(snowmantest.Genesis) + block1 := snowmantest.BuildChildBlock(snowmantest.Genesis) + block2 := snowmantest.BuildChildBlock(block1) + block3 := snowmantest.BuildChildBlock(block1) require.NoError(sm.Add(context.Background(), block0)) require.NoError(sm.Add(context.Background(), block1)) @@ -785,17 +727,16 @@ func RecordPollInvalidVoteTest(t *testing.T, factory Factory) { MaxOutstandingItems: 1, MaxItemProcessingTime: 1, } - require.NoError(sm.Initialize(ctx, params, GenesisID, GenesisHeight, GenesisTimestamp)) + require.NoError(sm.Initialize( + ctx, + params, + snowmantest.GenesisID, + snowmantest.GenesisHeight, + snowmantest.GenesisTimestamp, + )) - block := &TestBlock{ - TestDecidable: choices.TestDecidable{ - IDV: ids.Empty.Prefix(1), - StatusV: choices.Processing, - }, - ParentV: Genesis.IDV, - HeightV: Genesis.HeightV + 1, - } - unknownBlockID := ids.Empty.Prefix(2) + block := snowmantest.BuildChildBlock(snowmantest.Genesis) + unknownBlockID := ids.GenerateTestID() require.NoError(sm.Add(context.Background(), block)) @@ -826,48 +767,19 @@ func RecordPollTransitiveVotingTest(t *testing.T, factory Factory) { MaxOutstandingItems: 1, MaxItemProcessingTime: 1, } - require.NoError(sm.Initialize(ctx, params, GenesisID, GenesisHeight, GenesisTimestamp)) + require.NoError(sm.Initialize( + ctx, + params, + snowmantest.GenesisID, + snowmantest.GenesisHeight, + snowmantest.GenesisTimestamp, + )) - block0 := &TestBlock{ - TestDecidable: choices.TestDecidable{ - IDV: ids.Empty.Prefix(1), - StatusV: choices.Processing, - }, - ParentV: Genesis.IDV, - HeightV: Genesis.HeightV + 1, - } - block1 := &TestBlock{ - TestDecidable: choices.TestDecidable{ - IDV: ids.Empty.Prefix(2), - StatusV: choices.Processing, - }, - ParentV: block0.IDV, - HeightV: block0.HeightV + 1, - } - block2 := &TestBlock{ - TestDecidable: choices.TestDecidable{ - IDV: ids.Empty.Prefix(3), - StatusV: choices.Processing, - }, - ParentV: block1.IDV, - HeightV: block1.HeightV + 1, - } - block3 := &TestBlock{ - TestDecidable: choices.TestDecidable{ - IDV: ids.Empty.Prefix(4), - StatusV: choices.Processing, - }, - ParentV: block0.IDV, - HeightV: block0.HeightV + 1, - } - block4 := &TestBlock{ - TestDecidable: choices.TestDecidable{ - IDV: ids.Empty.Prefix(5), - StatusV: choices.Processing, - }, - ParentV: block3.IDV, - HeightV: block3.HeightV + 1, - } + block0 := snowmantest.BuildChildBlock(snowmantest.Genesis) + block1 := snowmantest.BuildChildBlock(block0) + block2 := snowmantest.BuildChildBlock(block1) + block3 := snowmantest.BuildChildBlock(block0) + block4 := snowmantest.BuildChildBlock(block3) require.NoError(sm.Add(context.Background(), block0)) require.NoError(sm.Add(context.Background(), block1)) @@ -936,40 +848,39 @@ func RecordPollDivergedVotingWithNoConflictingBitTest(t *testing.T, factory Fact MaxOutstandingItems: 1, MaxItemProcessingTime: 1, } - require.NoError(sm.Initialize(ctx, params, GenesisID, GenesisHeight, GenesisTimestamp)) + require.NoError(sm.Initialize( + ctx, + params, + snowmantest.GenesisID, + snowmantest.GenesisHeight, + snowmantest.GenesisTimestamp, + )) - block0 := &TestBlock{ + block0 := &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.ID{0x06}, // 0110 StatusV: choices.Processing, }, - ParentV: Genesis.IDV, - HeightV: Genesis.HeightV + 1, + ParentV: snowmantest.GenesisID, + HeightV: snowmantest.GenesisHeight + 1, } - block1 := &TestBlock{ + block1 := &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.ID{0x08}, // 0001 StatusV: choices.Processing, }, - ParentV: Genesis.IDV, - HeightV: Genesis.HeightV + 1, + ParentV: snowmantest.GenesisID, + HeightV: snowmantest.GenesisHeight + 1, } - block2 := &TestBlock{ + block2 := &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.ID{0x01}, // 1000 StatusV: choices.Processing, }, - ParentV: Genesis.IDV, - HeightV: Genesis.HeightV + 1, - } - block3 := &TestBlock{ - TestDecidable: choices.TestDecidable{ - IDV: ids.Empty.Prefix(1), - StatusV: choices.Processing, - }, - ParentV: block2.IDV, - HeightV: block2.HeightV + 1, + ParentV: snowmantest.GenesisID, + HeightV: snowmantest.GenesisHeight + 1, } + block3 := snowmantest.BuildChildBlock(block2) require.NoError(sm.Add(context.Background(), block0)) require.NoError(sm.Add(context.Background(), block1)) @@ -1040,40 +951,18 @@ func RecordPollChangePreferredChainTest(t *testing.T, factory Factory) { MaxOutstandingItems: 1, MaxItemProcessingTime: 1, } - require.NoError(sm.Initialize(ctx, params, GenesisID, GenesisHeight, GenesisTimestamp)) + require.NoError(sm.Initialize( + ctx, + params, + snowmantest.GenesisID, + snowmantest.GenesisHeight, + snowmantest.GenesisTimestamp, + )) - a1Block := &TestBlock{ - TestDecidable: choices.TestDecidable{ - IDV: ids.GenerateTestID(), - StatusV: choices.Processing, - }, - ParentV: Genesis.IDV, - HeightV: Genesis.HeightV + 1, - } - b1Block := &TestBlock{ - TestDecidable: choices.TestDecidable{ - IDV: ids.GenerateTestID(), - StatusV: choices.Processing, - }, - ParentV: Genesis.IDV, - HeightV: Genesis.HeightV + 1, - } - a2Block := &TestBlock{ - TestDecidable: choices.TestDecidable{ - IDV: ids.GenerateTestID(), - StatusV: choices.Processing, - }, - ParentV: a1Block.IDV, - HeightV: a1Block.HeightV + 1, - } - b2Block := &TestBlock{ - TestDecidable: choices.TestDecidable{ - IDV: ids.GenerateTestID(), - StatusV: choices.Processing, - }, - ParentV: b1Block.IDV, - HeightV: b1Block.HeightV + 1, - } + a1Block := snowmantest.BuildChildBlock(snowmantest.Genesis) + b1Block := snowmantest.BuildChildBlock(snowmantest.Genesis) + a2Block := snowmantest.BuildChildBlock(a1Block) + b2Block := snowmantest.BuildChildBlock(b1Block) require.NoError(sm.Add(context.Background(), a1Block)) require.NoError(sm.Add(context.Background(), a2Block)) @@ -1147,44 +1036,22 @@ func LastAcceptedTest(t *testing.T, factory Factory) { MaxOutstandingItems: 1, MaxItemProcessingTime: 1, } - require.NoError(sm.Initialize(ctx, params, GenesisID, GenesisHeight, GenesisTimestamp)) + require.NoError(sm.Initialize( + ctx, + params, + snowmantest.GenesisID, + snowmantest.GenesisHeight, + snowmantest.GenesisTimestamp, + )) - block0 := &TestBlock{ - TestDecidable: choices.TestDecidable{ - IDV: ids.GenerateTestID(), - StatusV: choices.Processing, - }, - ParentV: Genesis.IDV, - HeightV: Genesis.HeightV + 1, - } - block1 := &TestBlock{ - TestDecidable: choices.TestDecidable{ - IDV: ids.GenerateTestID(), - StatusV: choices.Processing, - }, - ParentV: block0.IDV, - HeightV: block0.HeightV + 1, - } - block2 := &TestBlock{ - TestDecidable: choices.TestDecidable{ - IDV: ids.GenerateTestID(), - StatusV: choices.Processing, - }, - ParentV: block1.IDV, - HeightV: block1.HeightV + 1, - } - block1Conflict := &TestBlock{ - TestDecidable: choices.TestDecidable{ - IDV: ids.GenerateTestID(), - StatusV: choices.Processing, - }, - ParentV: block0.IDV, - HeightV: block0.HeightV + 1, - } + block0 := snowmantest.BuildChildBlock(snowmantest.Genesis) + block1 := snowmantest.BuildChildBlock(block0) + block2 := snowmantest.BuildChildBlock(block1) + block1Conflict := snowmantest.BuildChildBlock(block0) lastAcceptedID, lastAcceptedHeight := sm.LastAccepted() - require.Equal(GenesisID, lastAcceptedID) - require.Equal(GenesisHeight, lastAcceptedHeight) + require.Equal(snowmantest.GenesisID, lastAcceptedID) + require.Equal(snowmantest.GenesisHeight, lastAcceptedHeight) require.NoError(sm.Add(context.Background(), block0)) require.NoError(sm.Add(context.Background(), block1)) @@ -1192,14 +1059,14 @@ func LastAcceptedTest(t *testing.T, factory Factory) { require.NoError(sm.Add(context.Background(), block2)) lastAcceptedID, lastAcceptedHeight = sm.LastAccepted() - require.Equal(GenesisID, lastAcceptedID) - require.Equal(GenesisHeight, lastAcceptedHeight) + require.Equal(snowmantest.GenesisID, lastAcceptedID) + require.Equal(snowmantest.GenesisHeight, lastAcceptedHeight) require.NoError(sm.RecordPoll(context.Background(), bag.Of(block0.IDV))) lastAcceptedID, lastAcceptedHeight = sm.LastAccepted() - require.Equal(GenesisID, lastAcceptedID) - require.Equal(GenesisHeight, lastAcceptedHeight) + require.Equal(snowmantest.GenesisID, lastAcceptedID) + require.Equal(snowmantest.GenesisHeight, lastAcceptedHeight) require.NoError(sm.RecordPoll(context.Background(), bag.Of(block1.IDV))) @@ -1244,14 +1111,19 @@ func MetricsProcessingErrorTest(t *testing.T, factory Factory) { MaxItemProcessingTime: 1, } - numProcessing := prometheus.NewGauge( - prometheus.GaugeOpts{ - Name: "blks_processing", - }) + numProcessing := prometheus.NewGauge(prometheus.GaugeOpts{ + Name: "blks_processing", + }) require.NoError(ctx.Registerer.Register(numProcessing)) - err := sm.Initialize(ctx, params, GenesisID, GenesisHeight, GenesisTimestamp) + err := sm.Initialize( + ctx, + params, + snowmantest.GenesisID, + snowmantest.GenesisHeight, + snowmantest.GenesisTimestamp, + ) require.Error(err) //nolint:forbidigo // error is not exported https://github.com/prometheus/client_golang/blob/main/prometheus/registry.go#L315 } @@ -1273,14 +1145,19 @@ func MetricsAcceptedErrorTest(t *testing.T, factory Factory) { MaxItemProcessingTime: 1, } - numAccepted := prometheus.NewGauge( - prometheus.GaugeOpts{ - Name: "blks_accepted_count", - }) + numAccepted := prometheus.NewGauge(prometheus.GaugeOpts{ + Name: "blks_accepted_count", + }) require.NoError(ctx.Registerer.Register(numAccepted)) - err := sm.Initialize(ctx, params, GenesisID, GenesisHeight, GenesisTimestamp) + err := sm.Initialize( + ctx, + params, + snowmantest.GenesisID, + snowmantest.GenesisHeight, + snowmantest.GenesisTimestamp, + ) require.Error(err) //nolint:forbidigo // error is not exported https://github.com/prometheus/client_golang/blob/main/prometheus/registry.go#L315 } @@ -1302,14 +1179,19 @@ func MetricsRejectedErrorTest(t *testing.T, factory Factory) { MaxItemProcessingTime: 1, } - numRejected := prometheus.NewGauge( - prometheus.GaugeOpts{ - Name: "blks_rejected_count", - }) + numRejected := prometheus.NewGauge(prometheus.GaugeOpts{ + Name: "blks_rejected_count", + }) require.NoError(ctx.Registerer.Register(numRejected)) - err := sm.Initialize(ctx, params, GenesisID, GenesisHeight, GenesisTimestamp) + err := sm.Initialize( + ctx, + params, + snowmantest.GenesisID, + snowmantest.GenesisHeight, + snowmantest.GenesisTimestamp, + ) require.Error(err) //nolint:forbidigo // error is not exported https://github.com/prometheus/client_golang/blob/main/prometheus/registry.go#L315 } @@ -1331,21 +1213,22 @@ func ErrorOnInitialRejectionTest(t *testing.T, factory Factory) { MaxItemProcessingTime: 1, } - require.NoError(sm.Initialize(ctx, params, GenesisID, GenesisHeight, GenesisTimestamp)) + require.NoError(sm.Initialize( + ctx, + params, + snowmantest.GenesisID, + snowmantest.GenesisHeight, + snowmantest.GenesisTimestamp, + )) - rejectedBlock := &TestBlock{TestDecidable: choices.TestDecidable{ - IDV: ids.Empty.Prefix(1), - StatusV: choices.Rejected, - }} - - block := &TestBlock{ + block := &snowmantest.Block{ TestDecidable: choices.TestDecidable{ - IDV: ids.Empty.Prefix(2), + IDV: ids.GenerateTestID(), RejectV: errTest, StatusV: choices.Processing, }, - ParentV: rejectedBlock.IDV, - HeightV: rejectedBlock.HeightV + 1, + ParentV: ids.GenerateTestID(), + HeightV: snowmantest.GenesisHeight + 1, } err := sm.Add(context.Background(), block) @@ -1370,17 +1253,16 @@ func ErrorOnAcceptTest(t *testing.T, factory Factory) { MaxItemProcessingTime: 1, } - require.NoError(sm.Initialize(ctx, params, GenesisID, GenesisHeight, GenesisTimestamp)) + require.NoError(sm.Initialize( + ctx, + params, + snowmantest.GenesisID, + snowmantest.GenesisHeight, + snowmantest.GenesisTimestamp, + )) - block := &TestBlock{ - TestDecidable: choices.TestDecidable{ - IDV: ids.Empty.Prefix(1), - AcceptV: errTest, - StatusV: choices.Processing, - }, - ParentV: Genesis.IDV, - HeightV: Genesis.HeightV + 1, - } + block := snowmantest.BuildChildBlock(snowmantest.Genesis) + block.AcceptV = errTest require.NoError(sm.Add(context.Background(), block)) @@ -1407,25 +1289,17 @@ func ErrorOnRejectSiblingTest(t *testing.T, factory Factory) { MaxItemProcessingTime: 1, } - require.NoError(sm.Initialize(ctx, params, GenesisID, GenesisHeight, GenesisTimestamp)) + require.NoError(sm.Initialize( + ctx, + params, + snowmantest.GenesisID, + snowmantest.GenesisHeight, + snowmantest.GenesisTimestamp, + )) - block0 := &TestBlock{ - TestDecidable: choices.TestDecidable{ - IDV: ids.Empty.Prefix(1), - StatusV: choices.Processing, - }, - ParentV: Genesis.IDV, - HeightV: Genesis.HeightV + 1, - } - block1 := &TestBlock{ - TestDecidable: choices.TestDecidable{ - IDV: ids.Empty.Prefix(2), - RejectV: errTest, - StatusV: choices.Processing, - }, - ParentV: Genesis.IDV, - HeightV: Genesis.HeightV + 1, - } + block0 := snowmantest.BuildChildBlock(snowmantest.Genesis) + block1 := snowmantest.BuildChildBlock(snowmantest.Genesis) + block1.RejectV = errTest require.NoError(sm.Add(context.Background(), block0)) require.NoError(sm.Add(context.Background(), block1)) @@ -1453,33 +1327,18 @@ func ErrorOnTransitiveRejectionTest(t *testing.T, factory Factory) { MaxItemProcessingTime: 1, } - require.NoError(sm.Initialize(ctx, params, GenesisID, GenesisHeight, GenesisTimestamp)) + require.NoError(sm.Initialize( + ctx, + params, + snowmantest.GenesisID, + snowmantest.GenesisHeight, + snowmantest.GenesisTimestamp, + )) - block0 := &TestBlock{ - TestDecidable: choices.TestDecidable{ - IDV: ids.Empty.Prefix(1), - StatusV: choices.Processing, - }, - ParentV: Genesis.IDV, - HeightV: Genesis.HeightV + 1, - } - block1 := &TestBlock{ - TestDecidable: choices.TestDecidable{ - IDV: ids.Empty.Prefix(2), - StatusV: choices.Processing, - }, - ParentV: Genesis.IDV, - HeightV: Genesis.HeightV + 1, - } - block2 := &TestBlock{ - TestDecidable: choices.TestDecidable{ - IDV: ids.Empty.Prefix(3), - RejectV: errTest, - StatusV: choices.Processing, - }, - ParentV: block1.IDV, - HeightV: block1.HeightV + 1, - } + block0 := snowmantest.BuildChildBlock(snowmantest.Genesis) + block1 := snowmantest.BuildChildBlock(snowmantest.Genesis) + block2 := snowmantest.BuildChildBlock(block1) + block2.RejectV = errTest require.NoError(sm.Add(context.Background(), block0)) require.NoError(sm.Add(context.Background(), block1)) @@ -1541,57 +1400,18 @@ func ErrorOnAddDecidedBlockTest(t *testing.T, factory Factory) { MaxOutstandingItems: 1, MaxItemProcessingTime: 1, } - require.NoError(sm.Initialize(ctx, params, GenesisID, GenesisHeight, GenesisTimestamp)) + require.NoError(sm.Initialize( + ctx, + params, + snowmantest.GenesisID, + snowmantest.GenesisHeight, + snowmantest.GenesisTimestamp, + )) - block0 := &TestBlock{ - TestDecidable: choices.TestDecidable{ - IDV: ids.ID{0x03}, // 0b0011 - StatusV: choices.Accepted, - }, - ParentV: Genesis.IDV, - HeightV: Genesis.HeightV + 1, - } - err := sm.Add(context.Background(), block0) - require.ErrorIs(err, errDuplicateAdd) -} - -func ErrorOnAddDuplicateBlockIDTest(t *testing.T, factory Factory) { - sm := factory.New() - require := require.New(t) - - snowCtx := snowtest.Context(t, snowtest.CChainID) - ctx := snowtest.ConsensusContext(snowCtx) - params := snowball.Parameters{ - K: 1, - AlphaPreference: 1, - AlphaConfidence: 1, - Beta: 1, - ConcurrentRepolls: 1, - OptimalProcessing: 1, - MaxOutstandingItems: 1, - MaxItemProcessingTime: 1, - } - require.NoError(sm.Initialize(ctx, params, GenesisID, GenesisHeight, GenesisTimestamp)) + block := snowmantest.BuildChildBlock(snowmantest.Genesis) + require.NoError(block.Accept(context.Background())) - block0 := &TestBlock{ - TestDecidable: choices.TestDecidable{ - IDV: ids.ID{0x03}, // 0b0011 - StatusV: choices.Processing, - }, - ParentV: Genesis.IDV, - HeightV: Genesis.HeightV + 1, - } - block1 := &TestBlock{ - TestDecidable: choices.TestDecidable{ - IDV: ids.ID{0x03}, // 0b0011, same as block0 - StatusV: choices.Processing, - }, - ParentV: block0.IDV, - HeightV: block0.HeightV + 1, - } - - require.NoError(sm.Add(context.Background(), block0)) - err := sm.Add(context.Background(), block1) + err := sm.Add(context.Background(), block) require.ErrorIs(err, errDuplicateAdd) } @@ -1626,25 +1446,18 @@ func RecordPollWithDefaultParameters(t *testing.T, factory Factory) { snowCtx := snowtest.Context(t, snowtest.CChainID) ctx := snowtest.ConsensusContext(snowCtx) params := snowball.DefaultParameters - require.NoError(sm.Initialize(ctx, params, GenesisID, GenesisHeight, GenesisTimestamp)) + require.NoError(sm.Initialize( + ctx, + params, + snowmantest.GenesisID, + snowmantest.GenesisHeight, + snowmantest.GenesisTimestamp, + )) // "blk1" and "blk2" are in conflict - blk1 := &TestBlock{ - TestDecidable: choices.TestDecidable{ - IDV: ids.ID{1}, - StatusV: choices.Processing, - }, - ParentV: Genesis.IDV, - HeightV: Genesis.HeightV + 1, - } - blk2 := &TestBlock{ - TestDecidable: choices.TestDecidable{ - IDV: ids.ID{2}, - StatusV: choices.Processing, - }, - ParentV: Genesis.IDV, - HeightV: Genesis.HeightV + 1, - } + blk1 := snowmantest.BuildChildBlock(snowmantest.Genesis) + blk2 := snowmantest.BuildChildBlock(snowmantest.Genesis) + require.NoError(sm.Add(context.Background(), blk1)) require.NoError(sm.Add(context.Background(), blk2)) @@ -1679,32 +1492,18 @@ func RecordPollRegressionCalculateInDegreeIndegreeCalculation(t *testing.T, fact MaxOutstandingItems: 1, MaxItemProcessingTime: 1, } - require.NoError(sm.Initialize(ctx, params, GenesisID, GenesisHeight, GenesisTimestamp)) + require.NoError(sm.Initialize( + ctx, + params, + snowmantest.GenesisID, + snowmantest.GenesisHeight, + snowmantest.GenesisTimestamp, + )) + + blk1 := snowmantest.BuildChildBlock(snowmantest.Genesis) + blk2 := snowmantest.BuildChildBlock(blk1) + blk3 := snowmantest.BuildChildBlock(blk2) - blk1 := &TestBlock{ - TestDecidable: choices.TestDecidable{ - IDV: ids.ID{1}, - StatusV: choices.Processing, - }, - ParentV: Genesis.IDV, - HeightV: Genesis.HeightV + 1, - } - blk2 := &TestBlock{ - TestDecidable: choices.TestDecidable{ - IDV: ids.ID{2}, - StatusV: choices.Processing, - }, - ParentV: blk1.IDV, - HeightV: blk1.HeightV + 1, - } - blk3 := &TestBlock{ - TestDecidable: choices.TestDecidable{ - IDV: ids.ID{3}, - StatusV: choices.Processing, - }, - ParentV: blk2.IDV, - HeightV: blk2.HeightV + 1, - } require.NoError(sm.Add(context.Background(), blk1)) require.NoError(sm.Add(context.Background(), blk2)) require.NoError(sm.Add(context.Background(), blk3)) diff --git a/snow/consensus/snowman/network_test.go b/snow/consensus/snowman/network_test.go index aead346fb5e4..eec42f017953 100644 --- a/snow/consensus/snowman/network_test.go +++ b/snow/consensus/snowman/network_test.go @@ -10,6 +10,7 @@ import ( "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/snow/choices" "github.com/ava-labs/avalanchego/snow/consensus/snowball" + "github.com/ava-labs/avalanchego/snow/consensus/snowman/snowmantest" "github.com/ava-labs/avalanchego/snow/snowtest" "github.com/ava-labs/avalanchego/utils" "github.com/ava-labs/avalanchego/utils/bag" @@ -18,7 +19,7 @@ import ( type Network struct { params snowball.Parameters - colors []*TestBlock + colors []*snowmantest.Block rngSource sampler.Source nodes, running []Consensus } @@ -26,13 +27,13 @@ type Network struct { func NewNetwork(params snowball.Parameters, numColors int, rngSource sampler.Source) *Network { n := &Network{ params: params, - colors: []*TestBlock{{ + colors: []*snowmantest.Block{{ TestDecidable: choices.TestDecidable{ IDV: ids.Empty.Prefix(rngSource.Uint64()), StatusV: choices.Processing, }, - ParentV: Genesis.IDV, - HeightV: 1, + ParentV: snowmantest.GenesisID, + HeightV: snowmantest.GenesisHeight + 1, }}, rngSource: rngSource, } @@ -42,7 +43,7 @@ func NewNetwork(params snowball.Parameters, numColors int, rngSource sampler.Sou s.Initialize(uint64(len(n.colors))) dependencyInd, _ := s.Next() dependency := n.colors[dependencyInd] - n.colors = append(n.colors, &TestBlock{ + n.colors = append(n.colors, &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.Empty.Prefix(rngSource.Uint64()), StatusV: choices.Processing, @@ -58,7 +59,7 @@ func (n *Network) shuffleColors() { s := sampler.NewDeterministicUniform(n.rngSource) s.Initialize(uint64(len(n.colors))) indices, _ := s.Sample(len(n.colors)) - colors := []*TestBlock(nil) + colors := []*snowmantest.Block(nil) for _, index := range indices { colors = append(colors, n.colors[int(index)]) } @@ -69,7 +70,7 @@ func (n *Network) shuffleColors() { func (n *Network) AddNode(t testing.TB, sm Consensus) error { snowCtx := snowtest.Context(t, snowtest.CChainID) ctx := snowtest.ConsensusContext(snowCtx) - if err := sm.Initialize(ctx, n.params, Genesis.ID(), Genesis.Height(), Genesis.Timestamp()); err != nil { + if err := sm.Initialize(ctx, n.params, snowmantest.GenesisID, snowmantest.GenesisHeight, snowmantest.GenesisTimestamp); err != nil { return err } @@ -80,7 +81,7 @@ func (n *Network) AddNode(t testing.TB, sm Consensus) error { if !found { myDep = blk.Parent() } - myVtx := &TestBlock{ + myBlock := &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: blk.ID(), StatusV: blk.Status(), @@ -90,10 +91,10 @@ func (n *Network) AddNode(t testing.TB, sm Consensus) error { VerifyV: blk.Verify(context.Background()), BytesV: blk.Bytes(), } - if err := sm.Add(context.Background(), myVtx); err != nil { + if err := sm.Add(context.Background(), myBlock); err != nil { return err } - deps[myVtx.ID()] = myDep + deps[myBlock.ID()] = myDep } n.nodes = append(n.nodes, sm) n.running = append(n.running, sm) diff --git a/snow/consensus/snowman/snowmantest/block.go b/snow/consensus/snowman/snowmantest/block.go new file mode 100644 index 000000000000..e81b6bddaca3 --- /dev/null +++ b/snow/consensus/snowman/snowmantest/block.go @@ -0,0 +1,90 @@ +// Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. +// See the file LICENSE for licensing terms. + +package snowmantest + +import ( + "cmp" + "context" + "time" + + "github.com/ava-labs/avalanchego/ids" + "github.com/ava-labs/avalanchego/snow/choices" + "github.com/ava-labs/avalanchego/utils" +) + +const GenesisHeight uint64 = 0 + +var ( + _ utils.Sortable[*Block] = (*Block)(nil) + + GenesisID = ids.GenerateTestID() + GenesisTimestamp = time.Unix(1, 0) + GenesisBytes = GenesisID[:] + Genesis = &Block{ + TestDecidable: choices.TestDecidable{ + IDV: GenesisID, + StatusV: choices.Accepted, + }, + HeightV: GenesisHeight, + TimestampV: GenesisTimestamp, + BytesV: GenesisBytes, + } +) + +func BuildChildBlock(parent *Block) *Block { + blkID := ids.GenerateTestID() + return &Block{ + TestDecidable: choices.TestDecidable{ + IDV: blkID, + StatusV: choices.Processing, + }, + ParentV: parent.ID(), + HeightV: parent.Height() + 1, + TimestampV: parent.Timestamp().Add(time.Second), + BytesV: blkID[:], + } +} + +func BuildChain(parent *Block, length int) []*Block { + chain := make([]*Block, length) + for i := range chain { + parent = BuildChildBlock(parent) + chain[i] = parent + } + return chain +} + +type Block struct { + choices.TestDecidable + + ParentV ids.ID + HeightV uint64 + TimestampV time.Time + VerifyV error + BytesV []byte +} + +func (b *Block) Parent() ids.ID { + return b.ParentV +} + +func (b *Block) Height() uint64 { + return b.HeightV +} + +func (b *Block) Timestamp() time.Time { + return b.TimestampV +} + +func (b *Block) Verify(context.Context) error { + return b.VerifyV +} + +func (b *Block) Bytes() []byte { + return b.BytesV +} + +func (b *Block) Compare(other *Block) int { + return cmp.Compare(b.HeightV, other.HeightV) +} diff --git a/snow/consensus/snowman/mock_block.go b/snow/consensus/snowman/snowmantest/mock_block.go similarity index 95% rename from snow/consensus/snowman/mock_block.go rename to snow/consensus/snowman/snowmantest/mock_block.go index 45393bfe7bdb..4c1a4ae7beec 100644 --- a/snow/consensus/snowman/mock_block.go +++ b/snow/consensus/snowman/snowmantest/mock_block.go @@ -3,11 +3,11 @@ // // Generated by this command: // -// mockgen -package=snowman -destination=snow/consensus/snowman/mock_block.go github.com/ava-labs/avalanchego/snow/consensus/snowman Block +// mockgen -package=snowmantest -destination=snow/consensus/snowman/snowmantest/mock_block.go github.com/ava-labs/avalanchego/snow/consensus/snowman Block // -// Package snowman is a generated GoMock package. -package snowman +// Package snowmantest is a generated GoMock package. +package snowmantest import ( context "context" diff --git a/snow/engine/snowman/bootstrap/bootstrapper_test.go b/snow/engine/snowman/bootstrap/bootstrapper_test.go index fd7fc0f12835..f03ec1d4a913 100644 --- a/snow/engine/snowman/bootstrap/bootstrapper_test.go +++ b/snow/engine/snowman/bootstrap/bootstrapper_test.go @@ -21,6 +21,7 @@ import ( "github.com/ava-labs/avalanchego/snow" "github.com/ava-labs/avalanchego/snow/choices" "github.com/ava-labs/avalanchego/snow/consensus/snowman" + "github.com/ava-labs/avalanchego/snow/consensus/snowman/snowmantest" "github.com/ava-labs/avalanchego/snow/engine/common" "github.com/ava-labs/avalanchego/snow/engine/common/tracker" "github.com/ava-labs/avalanchego/snow/engine/snowman/block" @@ -157,7 +158,7 @@ func TestBootstrapperStartsOnlyIfEnoughStakeIsConnected(t *testing.T) { blkID0 := ids.Empty.Prefix(0) blkBytes0 := []byte{0} - blk0 := &snowman.TestBlock{ + blk0 := &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: blkID0, StatusV: choices.Accepted, @@ -548,7 +549,7 @@ func TestBootstrapOldBlockAfterStateSync(t *testing.T) { blks := generateBlockchain(2) initializeVMWithBlockchain(vm, blks) - blks[0].(*snowman.TestBlock).StatusV = choices.Processing + blks[0].(*snowmantest.Block).StatusV = choices.Processing require.NoError(blks[1].Accept(context.Background())) bs, err := New( @@ -656,7 +657,7 @@ func TestBootstrapNoParseOnNew(t *testing.T) { snowGetHandler, err := getter.New(vm, sender, ctx.Log, time.Second, 2000, ctx.Registerer) require.NoError(err) - blk0 := &snowman.TestBlock{ + blk0 := &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.GenerateTestID(), StatusV: choices.Accepted, @@ -665,7 +666,7 @@ func TestBootstrapNoParseOnNew(t *testing.T) { BytesV: utils.RandomBytes(32), } - blk1 := &snowman.TestBlock{ + blk1 := &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.GenerateTestID(), StatusV: choices.Processing, @@ -776,7 +777,7 @@ func generateBlockchain(length uint64) []snowman.Block { } blocks := make([]snowman.Block, length) - blocks[0] = &snowman.TestBlock{ + blocks[0] = &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.GenerateTestID(), StatusV: choices.Accepted, @@ -786,7 +787,7 @@ func generateBlockchain(length uint64) []snowman.Block { BytesV: binary.AppendUvarint(nil, 0), } for height := uint64(1); height < length; height++ { - blocks[height] = &snowman.TestBlock{ + blocks[height] = &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.GenerateTestID(), StatusV: choices.Processing, diff --git a/snow/engine/snowman/getter/getter_test.go b/snow/engine/snowman/getter/getter_test.go index 7d6482a1d3c3..d7a95048e8a6 100644 --- a/snow/engine/snowman/getter/getter_test.go +++ b/snow/engine/snowman/getter/getter_test.go @@ -16,6 +16,7 @@ import ( "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/snow/choices" "github.com/ava-labs/avalanchego/snow/consensus/snowman" + "github.com/ava-labs/avalanchego/snow/consensus/snowman/snowmantest" "github.com/ava-labs/avalanchego/snow/engine/common" "github.com/ava-labs/avalanchego/snow/engine/snowman/block" "github.com/ava-labs/avalanchego/utils/logging" @@ -81,11 +82,11 @@ func TestFilterAccepted(t *testing.T) { blkID1 := ids.GenerateTestID() blkID2 := ids.GenerateTestID() - blk0 := &snowman.TestBlock{TestDecidable: choices.TestDecidable{ + blk0 := &snowmantest.Block{TestDecidable: choices.TestDecidable{ IDV: blkID0, StatusV: choices.Accepted, }} - blk1 := &snowman.TestBlock{TestDecidable: choices.TestDecidable{ + blk1 := &snowmantest.Block{TestDecidable: choices.TestDecidable{ IDV: blkID1, StatusV: choices.Accepted, }} diff --git a/snow/engine/snowman/transitive_test.go b/snow/engine/snowman/transitive_test.go index a98e0bfd20d9..fb158dbed287 100644 --- a/snow/engine/snowman/transitive_test.go +++ b/snow/engine/snowman/transitive_test.go @@ -20,6 +20,7 @@ import ( "github.com/ava-labs/avalanchego/snow/choices" "github.com/ava-labs/avalanchego/snow/consensus/snowball" "github.com/ava-labs/avalanchego/snow/consensus/snowman" + "github.com/ava-labs/avalanchego/snow/consensus/snowman/snowmantest" "github.com/ava-labs/avalanchego/snow/engine/common" "github.com/ava-labs/avalanchego/snow/engine/snowman/ancestor" "github.com/ava-labs/avalanchego/snow/engine/snowman/block" @@ -40,7 +41,7 @@ var ( GenesisID = ids.GenerateTestID() GenesisBytes = utils.RandomBytes(32) - Genesis = &snowman.TestBlock{ + Genesis = &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: GenesisID, StatusV: choices.Accepted, @@ -49,24 +50,7 @@ var ( } ) -func BuildChain(root *snowman.TestBlock, length int) []*snowman.TestBlock { - chain := make([]*snowman.TestBlock, length) - for i := range chain { - root = &snowman.TestBlock{ - TestDecidable: choices.TestDecidable{ - IDV: ids.GenerateTestID(), - StatusV: choices.Processing, - }, - ParentV: root.ID(), - HeightV: root.Height() + 1, - BytesV: utils.RandomBytes(32), - } - chain[i] = root - } - return chain -} - -func MakeGetBlockF(blks ...[]*snowman.TestBlock) func(context.Context, ids.ID) (snowman.Block, error) { +func MakeGetBlockF(blks ...[]*snowmantest.Block) func(context.Context, ids.ID) (snowman.Block, error) { return func(_ context.Context, blkID ids.ID) (snowman.Block, error) { for _, blkSet := range blks { for _, blk := range blkSet { @@ -79,7 +63,7 @@ func MakeGetBlockF(blks ...[]*snowman.TestBlock) func(context.Context, ids.ID) ( } } -func MakeParseBlockF(blks ...[]*snowman.TestBlock) func(context.Context, []byte) (snowman.Block, error) { +func MakeParseBlockF(blks ...[]*snowmantest.Block) func(context.Context, []byte) (snowman.Block, error) { return func(_ context.Context, blkBytes []byte) (snowman.Block, error) { for _, blkSet := range blks { for _, blk := range blkSet { @@ -92,7 +76,7 @@ func MakeParseBlockF(blks ...[]*snowman.TestBlock) func(context.Context, []byte) } } -func MakeLastAcceptedBlockF(defaultBlk *snowman.TestBlock, blks ...[]*snowman.TestBlock) func(context.Context) (ids.ID, error) { +func MakeLastAcceptedBlockF(defaultBlk *snowmantest.Block, blks ...[]*snowmantest.Block) func(context.Context) (ids.ID, error) { return func(_ context.Context) (ids.ID, error) { highestHeight := defaultBlk.Height() highestID := defaultBlk.ID() @@ -167,7 +151,7 @@ func TestEngineDropsAttemptToIssueBlockAfterFailedRequest(t *testing.T) { peerID, _, sender, vm, engine := setup(t, DefaultConfig(t)) - blks := BuildChain(Genesis, 2) + blks := snowmantest.BuildChain(Genesis, 2) parent := blks[0] child := blks[1] @@ -215,7 +199,7 @@ func TestEngineQuery(t *testing.T) { peerID, _, sender, vm, engine := setup(t, DefaultConfig(t)) - blks := BuildChain(Genesis, 2) + blks := snowmantest.BuildChain(Genesis, 2) parent := blks[0] child := blks[1] @@ -401,7 +385,7 @@ func TestEngineMultipleQuery(t *testing.T) { vm.GetBlockF = nil vm.LastAcceptedF = nil - blks := BuildChain(Genesis, 2) + blks := snowmantest.BuildChain(Genesis, 2) blk0 := blks[0] blk1 := blks[1] @@ -501,7 +485,7 @@ func TestEngineBlockedIssue(t *testing.T) { sender.Default(false) - blks := BuildChain(Genesis, 2) + blks := snowmantest.BuildChain(Genesis, 2) blk0 := blks[0] blk1 := blks[1] @@ -569,7 +553,7 @@ func TestEnginePushQuery(t *testing.T) { sender.Default(true) - blks := BuildChain(Genesis, 1) + blks := snowmantest.BuildChain(Genesis, 1) blk := blks[0] vm.ParseBlockF = func(_ context.Context, b []byte) (snowman.Block, error) { @@ -624,7 +608,7 @@ func TestEngineBuildBlock(t *testing.T) { sender.Default(true) - blks := BuildChain(Genesis, 1) + blks := snowmantest.BuildChain(Genesis, 1) blk := blks[0] vm.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { @@ -728,7 +712,7 @@ func TestVoteCanceling(t *testing.T) { vm.LastAcceptedF = nil - blks := BuildChain(Genesis, 1) + blks := snowmantest.BuildChain(Genesis, 1) blk := blks[0] queried := new(bool) @@ -795,7 +779,7 @@ func TestEngineNoQuery(t *testing.T) { require.NoError(te.Start(context.Background(), 0)) - blks := BuildChain(Genesis, 1) + blks := snowmantest.BuildChain(Genesis, 1) blk := blks[0] require.NoError(te.issue( @@ -876,7 +860,7 @@ func TestEngineAbandonChit(t *testing.T) { sender.Default(true) - blks := BuildChain(Genesis, 1) + blks := snowmantest.BuildChain(Genesis, 1) blk := blks[0] vm.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { @@ -930,7 +914,7 @@ func TestEngineAbandonChitWithUnexpectedPutBlock(t *testing.T) { sender.Default(true) - blks := BuildChain(Genesis, 1) + blks := snowmantest.BuildChain(Genesis, 1) blk := blks[0] vm.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { @@ -991,7 +975,7 @@ func TestEngineBlockingChitRequest(t *testing.T) { sender.Default(true) - blks := BuildChain(Genesis, 3) + blks := snowmantest.BuildChain(Genesis, 3) missingBlk := blks[0] parentBlk := blks[1] blockingBlk := blks[2] @@ -1050,10 +1034,10 @@ func TestEngineBlockingChitResponse(t *testing.T) { sender.Default(true) - issuedBlks := BuildChain(Genesis, 1) + issuedBlks := snowmantest.BuildChain(Genesis, 1) issuedBlk := issuedBlks[0] - blockingBlks := BuildChain(Genesis, 2) + blockingBlks := snowmantest.BuildChain(Genesis, 2) missingBlk := blockingBlks[0] blockingBlk := blockingBlks[1] @@ -1187,7 +1171,7 @@ func TestEngineRetryFetch(t *testing.T) { sender.Default(true) - blks := BuildChain(Genesis, 1) + blks := snowmantest.BuildChain(Genesis, 1) missingBlk := blks[0] vm.CantGetBlock = false @@ -1227,7 +1211,7 @@ func TestEngineUndeclaredDependencyDeadlock(t *testing.T) { sender.Default(true) - blks := BuildChain(Genesis, 2) + blks := snowmantest.BuildChain(Genesis, 2) validBlk := blks[0] invalidBlk := blks[1] @@ -1306,7 +1290,7 @@ func TestEngineInvalidBlockIgnoredFromUnexpectedPeer(t *testing.T) { sender.Default(true) - blks := BuildChain(Genesis, 2) + blks := snowmantest.BuildChain(Genesis, 2) missingBlk := blks[0] pendingBlk := blks[1] @@ -1380,7 +1364,7 @@ func TestEnginePushQueryRequestIDConflict(t *testing.T) { sender.Default(true) - blks := BuildChain(Genesis, 2) + blks := snowmantest.BuildChain(Genesis, 2) missingBlk := blks[0] pendingBlk := blks[1] @@ -1491,7 +1475,7 @@ func TestEngineAggressivePolling(t *testing.T) { vm.GetBlockF = nil vm.LastAcceptedF = nil - blks := BuildChain(Genesis, 1) + blks := snowmantest.BuildChain(Genesis, 1) pendingBlk := blks[0] parsed := new(bool) @@ -1579,7 +1563,7 @@ func TestEngineDoubleChit(t *testing.T) { vm.LastAcceptedF = nil - blks := BuildChain(Genesis, 1) + blks := snowmantest.BuildChain(Genesis, 1) blk := blks[0] queried := new(bool) @@ -1667,7 +1651,7 @@ func TestEngineBuildBlockLimit(t *testing.T) { vm.GetBlockF = nil vm.LastAcceptedF = nil - blks := BuildChain(Genesis, 2) + blks := snowmantest.BuildChain(Genesis, 2) blk0 := blks[0] var ( @@ -1728,10 +1712,10 @@ func TestEngineReceiveNewRejectedBlock(t *testing.T) { vdr, _, sender, vm, te := setup(t, DefaultConfig(t)) - acceptedBlks := BuildChain(Genesis, 1) + acceptedBlks := snowmantest.BuildChain(Genesis, 1) acceptedBlk := acceptedBlks[0] - rejectedBlks := BuildChain(Genesis, 2) + rejectedBlks := snowmantest.BuildChain(Genesis, 2) rejectedBlk := rejectedBlks[0] pendingBlk := rejectedBlks[1] @@ -1799,10 +1783,10 @@ func TestEngineRejectionAmplification(t *testing.T) { vdr, _, sender, vm, te := setup(t, DefaultConfig(t)) - acceptedBlks := BuildChain(Genesis, 1) + acceptedBlks := snowmantest.BuildChain(Genesis, 1) acceptedBlk := acceptedBlks[0] - rejectedBlks := BuildChain(Genesis, 2) + rejectedBlks := snowmantest.BuildChain(Genesis, 2) rejectedBlk := rejectedBlks[0] pendingBlk := rejectedBlks[1] @@ -1888,10 +1872,10 @@ func TestEngineTransitiveRejectionAmplificationDueToRejectedParent(t *testing.T) vdr, _, sender, vm, te := setup(t, DefaultConfig(t)) - acceptedBlks := BuildChain(Genesis, 1) + acceptedBlks := snowmantest.BuildChain(Genesis, 1) acceptedBlk := acceptedBlks[0] - rejectedBlks := BuildChain(Genesis, 2) + rejectedBlks := snowmantest.BuildChain(Genesis, 2) rejectedBlk := rejectedBlks[0] pendingBlk := rejectedBlks[1] pendingBlk.RejectV = errUnexpectedCall @@ -1954,10 +1938,10 @@ func TestEngineTransitiveRejectionAmplificationDueToInvalidParent(t *testing.T) vdr, _, sender, vm, te := setup(t, DefaultConfig(t)) - acceptedBlks := BuildChain(Genesis, 1) + acceptedBlks := snowmantest.BuildChain(Genesis, 1) acceptedBlk := acceptedBlks[0] - rejectedBlks := BuildChain(Genesis, 2) + rejectedBlks := snowmantest.BuildChain(Genesis, 2) rejectedBlk := rejectedBlks[0] rejectedBlk.VerifyV = errUnexpectedCall pendingBlk := rejectedBlks[1] @@ -2024,10 +2008,10 @@ func TestEngineNonPreferredAmplification(t *testing.T) { vdr, _, sender, vm, te := setup(t, DefaultConfig(t)) - preferredBlks := BuildChain(Genesis, 1) + preferredBlks := snowmantest.BuildChain(Genesis, 1) preferredBlk := preferredBlks[0] - nonPreferredBlks := BuildChain(Genesis, 1) + nonPreferredBlks := snowmantest.BuildChain(Genesis, 1) nonPreferredBlk := nonPreferredBlks[0] vm.ParseBlockF = func(_ context.Context, b []byte) (snowman.Block, error) { @@ -2082,7 +2066,7 @@ func TestEngineBubbleVotesThroughInvalidBlock(t *testing.T) { vdr, _, sender, vm, te := setup(t, DefaultConfig(t)) expectedVdrSet := set.Of(vdr) - blks := BuildChain(Genesis, 2) + blks := snowmantest.BuildChain(Genesis, 2) blk1 := blks[0] // blk2 cannot pass verification until [blk1] has been marked as accepted. @@ -2241,7 +2225,7 @@ func TestEngineBubbleVotesThroughInvalidChain(t *testing.T) { vdr, _, sender, vm, te := setup(t, DefaultConfig(t)) expectedVdrSet := set.Of(vdr) - blks := BuildChain(Genesis, 3) + blks := snowmantest.BuildChain(Genesis, 3) blk1 := blks[0] // blk2 cannot pass verification until [blk1] has been marked as accepted. @@ -2355,7 +2339,7 @@ func TestEngineBuildBlockWithCachedNonVerifiedParent(t *testing.T) { sender.Default(true) - blks := BuildChain(Genesis, 3) + blks := snowmantest.BuildChain(Genesis, 3) grandParentBlk := blks[0] parentBlkA := blks[1] @@ -2363,7 +2347,7 @@ func TestEngineBuildBlockWithCachedNonVerifiedParent(t *testing.T) { // Note that [parentBlkB] has the same [ID()] as [parentBlkA]; // it's a different instantiation of the same block. - parentBlkB := &snowman.TestBlock{ + parentBlkB := &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: parentBlkA.IDV, StatusV: parentBlkA.StatusV, @@ -2516,7 +2500,7 @@ func TestEngineApplyAcceptedFrontierInQueryFailed(t *testing.T) { vm.LastAcceptedF = nil - blks := BuildChain(Genesis, 1) + blks := snowmantest.BuildChain(Genesis, 1) blk := blks[0] queryRequestID := new(uint32) @@ -2611,7 +2595,7 @@ func TestEngineRepollsMisconfiguredSubnet(t *testing.T) { vm.LastAcceptedF = nil - blks := BuildChain(Genesis, 1) + blks := snowmantest.BuildChain(Genesis, 1) blk := blks[0] // Issue the block. This shouldn't call the sender, because creating the @@ -2731,8 +2715,8 @@ func TestEngineVoteStallRegression(t *testing.T) { sender.Default(true) config.Sender = sender - acceptedChain := BuildChain(Genesis, 3) - rejectedChain := BuildChain(Genesis, 2) + acceptedChain := snowmantest.BuildChain(Genesis, 3) + rejectedChain := snowmantest.BuildChain(Genesis, 2) vm := &block.TestVM{ TestVM: common.TestVM{ @@ -2755,12 +2739,12 @@ func TestEngineVoteStallRegression(t *testing.T) { }, }, ParseBlockF: MakeParseBlockF( - []*snowman.TestBlock{Genesis}, + []*snowmantest.Block{Genesis}, acceptedChain, rejectedChain, ), GetBlockF: MakeGetBlockF( - []*snowman.TestBlock{Genesis}, + []*snowmantest.Block{Genesis}, acceptedChain, ), SetPreferenceF: func(context.Context, ids.ID) error { @@ -2899,7 +2883,7 @@ func TestEngineVoteStallRegression(t *testing.T) { // accepted, block 4 will be dropped. // Then poll 1 should terminate because block 4 was dropped. vm.GetBlockF = MakeGetBlockF( - []*snowman.TestBlock{Genesis}, + []*snowmantest.Block{Genesis}, acceptedChain, rejectedChain, ) @@ -2939,8 +2923,8 @@ func TestGetProcessingAncestor(t *testing.T) { ctx = snowtest.ConsensusContext( snowtest.Context(t, snowtest.PChainID), ) - issuedChain = BuildChain(Genesis, 1) - unissuedOnIssuedChain = BuildChain(issuedChain[0], 1) + issuedChain = snowmantest.BuildChain(Genesis, 1) + unissuedOnIssuedChain = snowmantest.BuildChain(issuedChain[0], 1) ) metrics, err := newMetrics("", prometheus.NewRegistry()) @@ -2979,7 +2963,7 @@ func TestGetProcessingAncestor(t *testing.T) { T: t, }, GetBlockF: MakeGetBlockF( - []*snowman.TestBlock{Genesis}, + []*snowmantest.Block{Genesis}, ), }, Consensus: c, @@ -3003,7 +2987,7 @@ func TestGetProcessingAncestor(t *testing.T) { T: t, }, GetBlockF: MakeGetBlockF( - []*snowman.TestBlock{Genesis}, + []*snowmantest.Block{Genesis}, ), }, Consensus: c, @@ -3027,7 +3011,7 @@ func TestGetProcessingAncestor(t *testing.T) { T: t, }, GetBlockF: MakeGetBlockF( - []*snowman.TestBlock{Genesis}, + []*snowmantest.Block{Genesis}, ), }, Consensus: c, @@ -3051,7 +3035,7 @@ func TestGetProcessingAncestor(t *testing.T) { T: t, }, GetBlockF: MakeGetBlockF( - []*snowman.TestBlock{Genesis}, + []*snowmantest.Block{Genesis}, ), }, Consensus: c, @@ -3075,7 +3059,7 @@ func TestGetProcessingAncestor(t *testing.T) { T: t, }, GetBlockF: MakeGetBlockF( - []*snowman.TestBlock{Genesis}, + []*snowmantest.Block{Genesis}, ), }, Consensus: c, From 32aa3f54cf96083447f66f94c6aa3a6e9640f05a Mon Sep 17 00:00:00 2001 From: Stephen Buttolph Date: Fri, 26 Apr 2024 16:10:38 -0400 Subject: [PATCH 02/24] nit --- scripts/mocks.mockgen.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/mocks.mockgen.txt b/scripts/mocks.mockgen.txt index ba2be886b0b6..139252666ab0 100644 --- a/scripts/mocks.mockgen.txt +++ b/scripts/mocks.mockgen.txt @@ -5,7 +5,7 @@ github.com/ava-labs/avalanchego/database=Batch=database/mock_batch.go github.com/ava-labs/avalanchego/database=Iterator=database/mock_iterator.go github.com/ava-labs/avalanchego/message=OutboundMessage=message/mock_message.go github.com/ava-labs/avalanchego/message=OutboundMsgBuilder=message/mock_outbound_message_builder.go -github.com/ava-labs/avalanchego/snow/consensus/snowman=Block=snow/consensus/snowman/mock_block.go +github.com/ava-labs/avalanchego/snow/consensus/snowman=Block=snow/consensus/snowman/snowmantest/mock_block.go github.com/ava-labs/avalanchego/snow/engine/avalanche/vertex=LinearizableVM=snow/engine/avalanche/vertex/mock_vm.go github.com/ava-labs/avalanchego/snow/engine/snowman/block=BuildBlockWithContextChainVM=snow/engine/snowman/block/mock_build_block_with_context_vm.go github.com/ava-labs/avalanchego/snow/engine/snowman/block=ChainVM=snow/engine/snowman/block/mock_chain_vm.go From f610c59ef4248f9d70ae24ff4785cc54db0ae4f0 Mon Sep 17 00:00:00 2001 From: Stephen Buttolph Date: Fri, 26 Apr 2024 16:17:50 -0400 Subject: [PATCH 03/24] update mocks --- vms/proposervm/block_test.go | 7 ++++--- vms/proposervm/pre_fork_block_test.go | 5 +++-- vms/proposervm/vm_test.go | 15 ++++++++------- vms/rpcchainvm/batched_vm_test.go | 6 +++--- vms/rpcchainvm/with_context_vm_test.go | 5 +++-- 5 files changed, 21 insertions(+), 17 deletions(-) diff --git a/vms/proposervm/block_test.go b/vms/proposervm/block_test.go index 3743cf8fa626..990ac5df4ad8 100644 --- a/vms/proposervm/block_test.go +++ b/vms/proposervm/block_test.go @@ -19,6 +19,7 @@ import ( "github.com/ava-labs/avalanchego/snow" "github.com/ava-labs/avalanchego/snow/choices" "github.com/ava-labs/avalanchego/snow/consensus/snowman" + "github.com/ava-labs/avalanchego/snow/consensus/snowman/snowmantest" "github.com/ava-labs/avalanchego/snow/engine/snowman/block" "github.com/ava-labs/avalanchego/snow/validators" "github.com/ava-labs/avalanchego/staking" @@ -45,11 +46,11 @@ func TestPostForkCommonComponents_buildChild(t *testing.T) { blkID = ids.GenerateTestID() ) - innerBlk := snowman.NewMockBlock(ctrl) + innerBlk := snowmantest.NewMockBlock(ctrl) innerBlk.EXPECT().ID().Return(blkID).AnyTimes() innerBlk.EXPECT().Height().Return(parentHeight + 1).AnyTimes() - builtBlk := snowman.NewMockBlock(ctrl) + builtBlk := snowmantest.NewMockBlock(ctrl) builtBlk.EXPECT().Bytes().Return([]byte{1, 2, 3}).AnyTimes() builtBlk.EXPECT().ID().Return(ids.GenerateTestID()).AnyTimes() builtBlk.EXPECT().Height().Return(pChainHeight).AnyTimes() @@ -387,7 +388,7 @@ func TestPostDurangoBuildChildResetScheduler(t *testing.T) { parentHeight uint64 = 1234 ) - innerBlk := snowman.NewMockBlock(ctrl) + innerBlk := snowmantest.NewMockBlock(ctrl) innerBlk.EXPECT().Height().Return(parentHeight + 1).AnyTimes() vdrState := validators.NewMockState(ctrl) diff --git a/vms/proposervm/pre_fork_block_test.go b/vms/proposervm/pre_fork_block_test.go index 3261f5f9ee9a..4259349cf094 100644 --- a/vms/proposervm/pre_fork_block_test.go +++ b/vms/proposervm/pre_fork_block_test.go @@ -17,6 +17,7 @@ import ( "github.com/ava-labs/avalanchego/snow" "github.com/ava-labs/avalanchego/snow/choices" "github.com/ava-labs/avalanchego/snow/consensus/snowman" + "github.com/ava-labs/avalanchego/snow/consensus/snowman/snowmantest" "github.com/ava-labs/avalanchego/snow/engine/snowman/block" "github.com/ava-labs/avalanchego/snow/validators" "github.com/ava-labs/avalanchego/utils/logging" @@ -798,10 +799,10 @@ func TestPreForkBlock_BuildBlockWithContext(t *testing.T) { pChainHeight := uint64(1337) blkID := ids.GenerateTestID() - innerBlk := snowman.NewMockBlock(ctrl) + innerBlk := snowmantest.NewMockBlock(ctrl) innerBlk.EXPECT().ID().Return(blkID).AnyTimes() innerBlk.EXPECT().Timestamp().Return(mockable.MaxTime) - builtBlk := snowman.NewMockBlock(ctrl) + builtBlk := snowmantest.NewMockBlock(ctrl) builtBlk.EXPECT().Bytes().Return([]byte{1, 2, 3}).AnyTimes() builtBlk.EXPECT().ID().Return(ids.GenerateTestID()).AnyTimes() builtBlk.EXPECT().Height().Return(pChainHeight).AnyTimes() diff --git a/vms/proposervm/vm_test.go b/vms/proposervm/vm_test.go index ae47a33889a3..eb40426c17c2 100644 --- a/vms/proposervm/vm_test.go +++ b/vms/proposervm/vm_test.go @@ -22,6 +22,7 @@ import ( "github.com/ava-labs/avalanchego/snow" "github.com/ava-labs/avalanchego/snow/choices" "github.com/ava-labs/avalanchego/snow/consensus/snowman" + "github.com/ava-labs/avalanchego/snow/consensus/snowman/snowmantest" "github.com/ava-labs/avalanchego/snow/engine/common" "github.com/ava-labs/avalanchego/snow/engine/snowman/block" "github.com/ava-labs/avalanchego/snow/snowtest" @@ -2260,7 +2261,7 @@ func TestVMInnerBlkCache(t *testing.T) { innerVM.EXPECT().Shutdown(gomock.Any()).Return(nil) { - innerBlk := snowman.NewMockBlock(ctrl) + innerBlk := snowmantest.NewMockBlock(ctrl) innerBlkID := ids.GenerateTestID() innerVM.EXPECT().LastAccepted(gomock.Any()).Return(innerBlkID, nil) innerVM.EXPECT().GetBlock(gomock.Any(), innerBlkID).Return(innerBlk, nil) @@ -2304,7 +2305,7 @@ func TestVMInnerBlkCache(t *testing.T) { // Not in the VM's state so need to parse it. state.EXPECT().GetBlock(blkNearTip.ID()).Return(blkNearTip, choices.Accepted, nil).Times(2) // We will ask the inner VM to parse. - mockInnerBlkNearTip := snowman.NewMockBlock(ctrl) + mockInnerBlkNearTip := snowmantest.NewMockBlock(ctrl) mockInnerBlkNearTip.EXPECT().Height().Return(uint64(1)).Times(2) mockInnerBlkNearTip.EXPECT().Bytes().Return(blkNearTipInnerBytes).Times(1) @@ -2457,7 +2458,7 @@ func TestVMInnerBlkMarkedAcceptedRegression(t *testing.T) { } type blockWithVerifyContext struct { - *snowman.MockBlock + *snowmantest.MockBlock *block.MockWithVerifyContext } @@ -2500,7 +2501,7 @@ func TestVM_VerifyBlockWithContext(t *testing.T) { innerVM.EXPECT().Shutdown(gomock.Any()).Return(nil) { - innerBlk := snowman.NewMockBlock(ctrl) + innerBlk := snowmantest.NewMockBlock(ctrl) innerBlkID := ids.GenerateTestID() innerVM.EXPECT().LastAccepted(gomock.Any()).Return(innerBlkID, nil) innerVM.EXPECT().GetBlock(gomock.Any(), innerBlkID).Return(innerBlk, nil) @@ -2527,7 +2528,7 @@ func TestVM_VerifyBlockWithContext(t *testing.T) { { pChainHeight := uint64(0) innerBlk := blockWithVerifyContext{ - MockBlock: snowman.NewMockBlock(ctrl), + MockBlock: snowmantest.NewMockBlock(ctrl), MockWithVerifyContext: block.NewMockWithVerifyContext(ctrl), } innerBlk.MockWithVerifyContext.EXPECT().ShouldVerifyWithContext(gomock.Any()).Return(true, nil).Times(2) @@ -2575,7 +2576,7 @@ func TestVM_VerifyBlockWithContext(t *testing.T) { // Ensure we call Verify on a block that returns // false for ShouldVerifyWithContext innerBlk := blockWithVerifyContext{ - MockBlock: snowman.NewMockBlock(ctrl), + MockBlock: snowmantest.NewMockBlock(ctrl), MockWithVerifyContext: block.NewMockWithVerifyContext(ctrl), } innerBlk.MockWithVerifyContext.EXPECT().ShouldVerifyWithContext(gomock.Any()).Return(false, nil) @@ -2598,7 +2599,7 @@ func TestVM_VerifyBlockWithContext(t *testing.T) { { // Ensure we call Verify on a block that doesn't have a valid context innerBlk := blockWithVerifyContext{ - MockBlock: snowman.NewMockBlock(ctrl), + MockBlock: snowmantest.NewMockBlock(ctrl), MockWithVerifyContext: block.NewMockWithVerifyContext(ctrl), } innerBlk.MockBlock.EXPECT().Verify(gomock.Any()).Return(nil) diff --git a/vms/rpcchainvm/batched_vm_test.go b/vms/rpcchainvm/batched_vm_test.go index 8039c9fb7ba3..b24c0699e597 100644 --- a/vms/rpcchainvm/batched_vm_test.go +++ b/vms/rpcchainvm/batched_vm_test.go @@ -14,7 +14,7 @@ import ( "github.com/ava-labs/avalanchego/database/memdb" "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/snow/choices" - "github.com/ava-labs/avalanchego/snow/consensus/snowman" + "github.com/ava-labs/avalanchego/snow/consensus/snowman/snowmantest" "github.com/ava-labs/avalanchego/snow/engine/snowman/block" "github.com/ava-labs/avalanchego/snow/snowtest" "github.com/ava-labs/avalanchego/vms/components/chain" @@ -43,8 +43,8 @@ func batchedParseBlockCachingTestPlugin(t *testing.T, loadExpectations bool) blo vm := block.NewMockChainVM(ctrl) if loadExpectations { - blk1 := snowman.NewMockBlock(ctrl) - blk2 := snowman.NewMockBlock(ctrl) + blk1 := snowmantest.NewMockBlock(ctrl) + blk2 := snowmantest.NewMockBlock(ctrl) gomock.InOrder( // Initialize vm.EXPECT().Initialize( diff --git a/vms/rpcchainvm/with_context_vm_test.go b/vms/rpcchainvm/with_context_vm_test.go index f9216f5a5b2e..f87a6cba5f0b 100644 --- a/vms/rpcchainvm/with_context_vm_test.go +++ b/vms/rpcchainvm/with_context_vm_test.go @@ -14,6 +14,7 @@ import ( "github.com/ava-labs/avalanchego/database/memdb" "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/snow/consensus/snowman" + "github.com/ava-labs/avalanchego/snow/consensus/snowman/snowmantest" "github.com/ava-labs/avalanchego/snow/engine/snowman/block" "github.com/ava-labs/avalanchego/snow/snowtest" ) @@ -40,7 +41,7 @@ type ContextEnabledVMMock struct { } type ContextEnabledBlockMock struct { - *snowman.MockBlock + *snowmantest.MockBlock *block.MockWithVerifyContext } @@ -56,7 +57,7 @@ func contextEnabledTestPlugin(t *testing.T, loadExpectations bool) block.ChainVM if loadExpectations { ctxBlock := ContextEnabledBlockMock{ - MockBlock: snowman.NewMockBlock(ctrl), + MockBlock: snowmantest.NewMockBlock(ctrl), MockWithVerifyContext: block.NewMockWithVerifyContext(ctrl), } gomock.InOrder( From 3dce249cd8f003553aae68c3bf3db8539737b769 Mon Sep 17 00:00:00 2001 From: Stephen Buttolph Date: Fri, 26 Apr 2024 16:34:22 -0400 Subject: [PATCH 04/24] Update test references --- vms/components/chain/state_test.go | 13 ++-- vms/proposervm/batched_vm_test.go | 45 +++++------ vms/proposervm/block_test.go | 8 +- vms/proposervm/post_fork_block_test.go | 49 ++++++------ vms/proposervm/post_fork_option_test.go | 39 +++++----- vms/proposervm/pre_fork_block_test.go | 46 +++++------ vms/proposervm/state_syncable_vm_test.go | 15 ++-- vms/proposervm/tree/tree_test.go | 67 +++------------- vms/proposervm/vm_byzantine_test.go | 39 +++++----- vms/proposervm/vm_test.go | 98 ++++++++++++------------ vms/rpcchainvm/state_syncable_vm_test.go | 6 +- 11 files changed, 191 insertions(+), 234 deletions(-) diff --git a/vms/components/chain/state_test.go b/vms/components/chain/state_test.go index 8bdda5960f1a..c67e344295ee 100644 --- a/vms/components/chain/state_test.go +++ b/vms/components/chain/state_test.go @@ -16,6 +16,7 @@ import ( "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/snow/choices" "github.com/ava-labs/avalanchego/snow/consensus/snowman" + "github.com/ava-labs/avalanchego/snow/consensus/snowman/snowmantest" "github.com/ava-labs/avalanchego/utils/hashing" "github.com/ava-labs/avalanchego/utils/metric" ) @@ -31,12 +32,12 @@ var ( ) type TestBlock struct { - *snowman.TestBlock + *snowmantest.Block } // SetStatus sets the status of the Block. func (b *TestBlock) SetStatus(status choices.Status) { - b.TestBlock.TestDecidable.StatusV = status + b.Block.TestDecidable.StatusV = status } // NewTestBlock returns a new test block with height, bytes, and ID derived from [i] @@ -45,7 +46,7 @@ func NewTestBlock(i uint64, parentID ids.ID) *TestBlock { b := []byte{byte(i)} id := hashing.ComputeHash256Array(b) return &TestBlock{ - TestBlock: &snowman.TestBlock{ + Block: &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: id, StatusV: choices.Unknown, @@ -199,7 +200,7 @@ func TestState(t *testing.T) { blk3Bytes := []byte{byte(3)} blk3ID := hashing.ComputeHash256Array(blk3Bytes) blk3 := &TestBlock{ - TestBlock: &snowman.TestBlock{ + Block: &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: blk3ID, StatusV: choices.Processing, @@ -630,7 +631,7 @@ func TestSetLastAcceptedBlock(t *testing.T) { postSetBlk1Bytes := []byte{byte(200)} postSetBlk2Bytes := []byte{byte(201)} postSetBlk1 := &TestBlock{ - TestBlock: &snowman.TestBlock{ + Block: &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: hashing.ComputeHash256Array(postSetBlk1Bytes), StatusV: choices.Accepted, @@ -641,7 +642,7 @@ func TestSetLastAcceptedBlock(t *testing.T) { }, } postSetBlk2 := &TestBlock{ - TestBlock: &snowman.TestBlock{ + Block: &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: hashing.ComputeHash256Array(postSetBlk2Bytes), StatusV: choices.Processing, diff --git a/vms/proposervm/batched_vm_test.go b/vms/proposervm/batched_vm_test.go index a95e9d5e164d..f0714b732363 100644 --- a/vms/proposervm/batched_vm_test.go +++ b/vms/proposervm/batched_vm_test.go @@ -18,6 +18,7 @@ import ( "github.com/ava-labs/avalanchego/snow" "github.com/ava-labs/avalanchego/snow/choices" "github.com/ava-labs/avalanchego/snow/consensus/snowman" + "github.com/ava-labs/avalanchego/snow/consensus/snowman/snowmantest" "github.com/ava-labs/avalanchego/snow/engine/common" "github.com/ava-labs/avalanchego/snow/engine/snowman/block" "github.com/ava-labs/avalanchego/snow/snowtest" @@ -67,7 +68,7 @@ func TestGetAncestorsPreForkOnly(t *testing.T) { }() // Build some prefork blocks.... - coreBlk1 := &snowman.TestBlock{ + coreBlk1 := &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.GenerateTestID(), StatusV: choices.Processing, @@ -94,7 +95,7 @@ func TestGetAncestorsPreForkOnly(t *testing.T) { } } - coreBlk2 := &snowman.TestBlock{ + coreBlk2 := &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.GenerateTestID(), StatusV: choices.Processing, @@ -121,7 +122,7 @@ func TestGetAncestorsPreForkOnly(t *testing.T) { } } - coreBlk3 := &snowman.TestBlock{ + coreBlk3 := &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.GenerateTestID(), StatusV: choices.Processing, @@ -217,7 +218,7 @@ func TestGetAncestorsPostForkOnly(t *testing.T) { }() // Build some post-Fork blocks.... - coreBlk1 := &snowman.TestBlock{ + coreBlk1 := &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.GenerateTestID(), StatusV: choices.Processing, @@ -237,7 +238,7 @@ func TestGetAncestorsPostForkOnly(t *testing.T) { require.NoError(proRemoteVM.SetPreference(context.Background(), builtBlk1.ID())) require.NoError(waitForProposerWindow(proRemoteVM, builtBlk1, 0)) - coreBlk2 := &snowman.TestBlock{ + coreBlk2 := &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.GenerateTestID(), StatusV: choices.Processing, @@ -257,7 +258,7 @@ func TestGetAncestorsPostForkOnly(t *testing.T) { require.NoError(proRemoteVM.SetPreference(context.Background(), builtBlk2.ID())) require.NoError(waitForProposerWindow(proRemoteVM, builtBlk2, 0)) - coreBlk3 := &snowman.TestBlock{ + coreBlk3 := &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.GenerateTestID(), StatusV: choices.Processing, @@ -378,7 +379,7 @@ func TestGetAncestorsAtSnomanPlusPlusFork(t *testing.T) { // Build some prefork blocks.... proRemoteVM.Set(preForkTime) - coreBlk1 := &snowman.TestBlock{ + coreBlk1 := &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.GenerateTestID(), StatusV: choices.Processing, @@ -406,7 +407,7 @@ func TestGetAncestorsAtSnomanPlusPlusFork(t *testing.T) { } } - coreBlk2 := &snowman.TestBlock{ + coreBlk2 := &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.GenerateTestID(), StatusV: choices.Processing, @@ -436,7 +437,7 @@ func TestGetAncestorsAtSnomanPlusPlusFork(t *testing.T) { // .. and some post-fork proRemoteVM.Set(postForkTime) - coreBlk3 := &snowman.TestBlock{ + coreBlk3 := &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.GenerateTestID(), StatusV: choices.Processing, @@ -457,7 +458,7 @@ func TestGetAncestorsAtSnomanPlusPlusFork(t *testing.T) { require.NoError(proRemoteVM.SetPreference(context.Background(), builtBlk3.ID())) require.NoError(waitForProposerWindow(proRemoteVM, builtBlk3, builtBlk3.(*postForkBlock).PChainHeight())) - coreBlk4 := &snowman.TestBlock{ + coreBlk4 := &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.GenerateTestID(), StatusV: choices.Processing, @@ -579,7 +580,7 @@ func TestBatchedParseBlockPreForkOnly(t *testing.T) { }() // Build some prefork blocks.... - coreBlk1 := &snowman.TestBlock{ + coreBlk1 := &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.GenerateTestID(), StatusV: choices.Processing, @@ -605,7 +606,7 @@ func TestBatchedParseBlockPreForkOnly(t *testing.T) { } } - coreBlk2 := &snowman.TestBlock{ + coreBlk2 := &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.GenerateTestID(), StatusV: choices.Processing, @@ -631,7 +632,7 @@ func TestBatchedParseBlockPreForkOnly(t *testing.T) { } } - coreBlk3 := &snowman.TestBlock{ + coreBlk3 := &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.GenerateTestID(), StatusV: choices.Processing, @@ -701,7 +702,7 @@ func TestBatchedParseBlockPostForkOnly(t *testing.T) { }() // Build some post-Fork blocks.... - coreBlk1 := &snowman.TestBlock{ + coreBlk1 := &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.GenerateTestID(), StatusV: choices.Processing, @@ -721,7 +722,7 @@ func TestBatchedParseBlockPostForkOnly(t *testing.T) { require.NoError(proRemoteVM.SetPreference(context.Background(), builtBlk1.ID())) require.NoError(waitForProposerWindow(proRemoteVM, builtBlk1, 0)) - coreBlk2 := &snowman.TestBlock{ + coreBlk2 := &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.GenerateTestID(), StatusV: choices.Processing, @@ -741,7 +742,7 @@ func TestBatchedParseBlockPostForkOnly(t *testing.T) { require.NoError(proRemoteVM.SetPreference(context.Background(), builtBlk2.ID())) require.NoError(waitForProposerWindow(proRemoteVM, builtBlk2, builtBlk2.(*postForkBlock).PChainHeight())) - coreBlk3 := &snowman.TestBlock{ + coreBlk3 := &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.GenerateTestID(), StatusV: choices.Processing, @@ -819,7 +820,7 @@ func TestBatchedParseBlockAtSnomanPlusPlusFork(t *testing.T) { // Build some prefork blocks.... proRemoteVM.Set(preForkTime) - coreBlk1 := &snowman.TestBlock{ + coreBlk1 := &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.GenerateTestID(), StatusV: choices.Processing, @@ -847,7 +848,7 @@ func TestBatchedParseBlockAtSnomanPlusPlusFork(t *testing.T) { } } - coreBlk2 := &snowman.TestBlock{ + coreBlk2 := &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.GenerateTestID(), StatusV: choices.Processing, @@ -877,7 +878,7 @@ func TestBatchedParseBlockAtSnomanPlusPlusFork(t *testing.T) { // .. and some post-fork proRemoteVM.Set(postForkTime) - coreBlk3 := &snowman.TestBlock{ + coreBlk3 := &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.GenerateTestID(), StatusV: choices.Processing, @@ -898,7 +899,7 @@ func TestBatchedParseBlockAtSnomanPlusPlusFork(t *testing.T) { require.NoError(proRemoteVM.SetPreference(context.Background(), builtBlk3.ID())) require.NoError(waitForProposerWindow(proRemoteVM, builtBlk3, builtBlk3.(*postForkBlock).PChainHeight())) - coreBlk4 := &snowman.TestBlock{ + coreBlk4 := &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.GenerateTestID(), StatusV: choices.Processing, @@ -977,11 +978,11 @@ func initTestRemoteProposerVM( ) ( TestRemoteProposerVM, *VM, - *snowman.TestBlock, + *snowmantest.Block, ) { require := require.New(t) - coreGenBlk := &snowman.TestBlock{ + coreGenBlk := &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.GenerateTestID(), StatusV: choices.Accepted, diff --git a/vms/proposervm/block_test.go b/vms/proposervm/block_test.go index 990ac5df4ad8..9ddce10c7a3e 100644 --- a/vms/proposervm/block_test.go +++ b/vms/proposervm/block_test.go @@ -119,7 +119,7 @@ func TestPreDurangoValidatorNodeBlockBuiltDelaysTests(t *testing.T) { parentTime := time.Now().Truncate(time.Second) proVM.Set(parentTime) - coreParentBlk := &snowman.TestBlock{ + coreParentBlk := &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.GenerateTestID(), StatusV: choices.Processing, @@ -177,7 +177,7 @@ func TestPreDurangoValidatorNodeBlockBuiltDelaysTests(t *testing.T) { }, nil } - coreChildBlk := &snowman.TestBlock{ + coreChildBlk := &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.GenerateTestID(), StatusV: choices.Processing, @@ -256,7 +256,7 @@ func TestPreDurangoNonValidatorNodeBlockBuiltDelaysTests(t *testing.T) { parentTime := time.Now().Truncate(time.Second) proVM.Set(parentTime) - coreParentBlk := &snowman.TestBlock{ + coreParentBlk := &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.GenerateTestID(), StatusV: choices.Processing, @@ -316,7 +316,7 @@ func TestPreDurangoNonValidatorNodeBlockBuiltDelaysTests(t *testing.T) { }, nil } - coreChildBlk := &snowman.TestBlock{ + coreChildBlk := &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.GenerateTestID(), StatusV: choices.Processing, diff --git a/vms/proposervm/post_fork_block_test.go b/vms/proposervm/post_fork_block_test.go index a16d4a7d6219..a949f137269a 100644 --- a/vms/proposervm/post_fork_block_test.go +++ b/vms/proposervm/post_fork_block_test.go @@ -16,6 +16,7 @@ import ( "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/snow/choices" "github.com/ava-labs/avalanchego/snow/consensus/snowman" + "github.com/ava-labs/avalanchego/snow/consensus/snowman/snowmantest" "github.com/ava-labs/avalanchego/snow/validators" "github.com/ava-labs/avalanchego/utils/timer/mockable" "github.com/ava-labs/avalanchego/vms/proposervm/block" @@ -31,7 +32,7 @@ func TestOracle_PostForkBlock_ImplementsInterface(t *testing.T) { // setup proBlk := postForkBlock{ postForkCommonComponents: postForkCommonComponents{ - innerBlk: &snowman.TestBlock{}, + innerBlk: &snowmantest.Block{}, }, } @@ -50,20 +51,20 @@ func TestOracle_PostForkBlock_ImplementsInterface(t *testing.T) { }() innerOracleBlk := &TestOptionsBlock{ - TestBlock: snowman.TestBlock{ + Block: snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.Empty.Prefix(1111), }, BytesV: []byte{1}, }, opts: [2]snowman.Block{ - &snowman.TestBlock{ + &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.Empty.Prefix(2222), }, BytesV: []byte{2}, }, - &snowman.TestBlock{ + &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.Empty.Prefix(3333), }, @@ -115,7 +116,7 @@ func TestBlockVerify_PostForkBlock_PreDurango_ParentChecks(t *testing.T) { } // create parent block ... - parentCoreBlk := &snowman.TestBlock{ + parentCoreBlk := &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.Empty.Prefix(1111), StatusV: choices.Processing, @@ -155,7 +156,7 @@ func TestBlockVerify_PostForkBlock_PreDurango_ParentChecks(t *testing.T) { require.NoError(proVM.SetPreference(context.Background(), parentBlk.ID())) // .. create child block ... - childCoreBlk := &snowman.TestBlock{ + childCoreBlk := &snowmantest.Block{ ParentV: parentCoreBlk.ID(), BytesV: []byte{2}, HeightV: parentCoreBlk.Height() + 1, @@ -218,7 +219,7 @@ func TestBlockVerify_PostForkBlock_PostDurango_ParentChecks(t *testing.T) { return pChainHeight, nil } - parentCoreBlk := &snowman.TestBlock{ + parentCoreBlk := &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.Empty.Prefix(1111), StatusV: choices.Processing, @@ -257,7 +258,7 @@ func TestBlockVerify_PostForkBlock_PostDurango_ParentChecks(t *testing.T) { require.NoError(parentBlk.Verify(context.Background())) require.NoError(proVM.SetPreference(context.Background(), parentBlk.ID())) - childCoreBlk := &snowman.TestBlock{ + childCoreBlk := &snowmantest.Block{ ParentV: parentCoreBlk.ID(), BytesV: []byte{2}, HeightV: parentCoreBlk.Height() + 1, @@ -347,7 +348,7 @@ func TestBlockVerify_PostForkBlock_TimestampChecks(t *testing.T) { } // create parent block ... - parentCoreBlk := &snowman.TestBlock{ + parentCoreBlk := &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.Empty.Prefix(1111), StatusV: choices.Processing, @@ -391,7 +392,7 @@ func TestBlockVerify_PostForkBlock_TimestampChecks(t *testing.T) { parentPChainHeight = parentBlk.(*postForkBlock).PChainHeight() ) - childCoreBlk := &snowman.TestBlock{ + childCoreBlk := &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.Empty.Prefix(2222), StatusV: choices.Processing, @@ -552,7 +553,7 @@ func TestBlockVerify_PostForkBlock_PChainHeightChecks(t *testing.T) { } // create parent block ... - parentCoreBlk := &snowman.TestBlock{ + parentCoreBlk := &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.Empty.Prefix(1111), StatusV: choices.Processing, @@ -596,7 +597,7 @@ func TestBlockVerify_PostForkBlock_PChainHeightChecks(t *testing.T) { parentBlkPChainHeight := parentBlk.(*postForkBlock).PChainHeight() require.NoError(waitForProposerWindow(proVM, parentBlk, parentBlkPChainHeight)) - childCoreBlk := &snowman.TestBlock{ + childCoreBlk := &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.Empty.Prefix(2222), StatusV: choices.Processing, @@ -724,7 +725,7 @@ func TestBlockVerify_PostForkBlockBuiltOnOption_PChainHeightChecks(t *testing.T) // create post fork oracle block ... oracleCoreBlk := &TestOptionsBlock{ - TestBlock: snowman.TestBlock{ + Block: snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.Empty.Prefix(1111), StatusV: choices.Processing, @@ -735,7 +736,7 @@ func TestBlockVerify_PostForkBlockBuiltOnOption_PChainHeightChecks(t *testing.T) }, } oracleCoreBlk.opts = [2]snowman.Block{ - &snowman.TestBlock{ + &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.Empty.Prefix(2222), StatusV: choices.Processing, @@ -744,7 +745,7 @@ func TestBlockVerify_PostForkBlockBuiltOnOption_PChainHeightChecks(t *testing.T) ParentV: oracleCoreBlk.ID(), HeightV: oracleCoreBlk.Height() + 1, }, - &snowman.TestBlock{ + &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.Empty.Prefix(3333), StatusV: choices.Processing, @@ -810,7 +811,7 @@ func TestBlockVerify_PostForkBlockBuiltOnOption_PChainHeightChecks(t *testing.T) parentBlkPChainHeight := postForkOracleBlk.PChainHeight() // option takes proposal blocks' Pchain height - childCoreBlk := &snowman.TestBlock{ + childCoreBlk := &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.Empty.Prefix(2222), StatusV: choices.Processing, @@ -919,7 +920,7 @@ func TestBlockVerify_PostForkBlock_CoreBlockVerifyIsCalledOnce(t *testing.T) { return pChainHeight, nil } - coreBlk := &snowman.TestBlock{ + coreBlk := &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.Empty.Prefix(1111), StatusV: choices.Processing, @@ -986,7 +987,7 @@ func TestBlockAccept_PostForkBlock_SetsLastAcceptedBlock(t *testing.T) { return pChainHeight, nil } - coreBlk := &snowman.TestBlock{ + coreBlk := &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.Empty.Prefix(1111), StatusV: choices.Processing, @@ -1054,7 +1055,7 @@ func TestBlockAccept_PostForkBlock_TwoProBlocksWithSameCoreBlock_OneIsAccepted(t } // generate two blocks with the same core block and store them - coreBlk := &snowman.TestBlock{ + coreBlk := &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.Empty.Prefix(111), StatusV: choices.Processing, @@ -1099,7 +1100,7 @@ func TestBlockReject_PostForkBlock_InnerBlockIsNotRejected(t *testing.T) { require.NoError(proVM.Shutdown(context.Background())) }() - coreBlk := &snowman.TestBlock{ + coreBlk := &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.Empty.Prefix(111), StatusV: choices.Processing, @@ -1137,7 +1138,7 @@ func TestBlockVerify_PostForkBlock_ShouldBePostForkOption(t *testing.T) { // create post fork oracle block ... oracleCoreBlk := &TestOptionsBlock{ - TestBlock: snowman.TestBlock{ + Block: snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.Empty.Prefix(1111), StatusV: choices.Processing, @@ -1147,7 +1148,7 @@ func TestBlockVerify_PostForkBlock_ShouldBePostForkOption(t *testing.T) { HeightV: coreGenBlk.Height() + 1, }, } - coreOpt0 := &snowman.TestBlock{ + coreOpt0 := &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.Empty.Prefix(2222), StatusV: choices.Processing, @@ -1156,7 +1157,7 @@ func TestBlockVerify_PostForkBlock_ShouldBePostForkOption(t *testing.T) { ParentV: oracleCoreBlk.ID(), HeightV: oracleCoreBlk.Height() + 1, } - coreOpt1 := &snowman.TestBlock{ + coreOpt1 := &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.Empty.Prefix(3333), StatusV: choices.Processing, @@ -1253,7 +1254,7 @@ func TestBlockVerify_PostForkBlock_PChainTooLow(t *testing.T) { require.NoError(proVM.Shutdown(context.Background())) }() - coreBlk := &snowman.TestBlock{ + coreBlk := &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.GenerateTestID(), StatusV: choices.Processing, diff --git a/vms/proposervm/post_fork_option_test.go b/vms/proposervm/post_fork_option_test.go index dd16f8cdb518..d81218580fc7 100644 --- a/vms/proposervm/post_fork_option_test.go +++ b/vms/proposervm/post_fork_option_test.go @@ -16,6 +16,7 @@ import ( "github.com/ava-labs/avalanchego/snow" "github.com/ava-labs/avalanchego/snow/choices" "github.com/ava-labs/avalanchego/snow/consensus/snowman" + "github.com/ava-labs/avalanchego/snow/consensus/snowman/snowmantest" "github.com/ava-labs/avalanchego/snow/engine/common" "github.com/ava-labs/avalanchego/vms/proposervm/block" ) @@ -23,7 +24,7 @@ import ( var _ snowman.OracleBlock = (*TestOptionsBlock)(nil) type TestOptionsBlock struct { - snowman.TestBlock + snowmantest.Block opts [2]snowman.Block optsErr error } @@ -47,7 +48,7 @@ func TestBlockVerify_PostForkOption_ParentChecks(t *testing.T) { // create post fork oracle block ... oracleCoreBlk := &TestOptionsBlock{ - TestBlock: snowman.TestBlock{ + Block: snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.Empty.Prefix(1111), StatusV: choices.Processing, @@ -58,7 +59,7 @@ func TestBlockVerify_PostForkOption_ParentChecks(t *testing.T) { }, } oracleCoreBlk.opts = [2]snowman.Block{ - &snowman.TestBlock{ + &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.Empty.Prefix(2222), StatusV: choices.Processing, @@ -67,7 +68,7 @@ func TestBlockVerify_PostForkOption_ParentChecks(t *testing.T) { ParentV: oracleCoreBlk.ID(), HeightV: oracleCoreBlk.Height() + 1, }, - &snowman.TestBlock{ + &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.Empty.Prefix(3333), StatusV: choices.Processing, @@ -130,7 +131,7 @@ func TestBlockVerify_PostForkOption_ParentChecks(t *testing.T) { // show we can build on options require.NoError(proVM.SetPreference(context.Background(), opts[0].ID())) - childCoreBlk := &snowman.TestBlock{ + childCoreBlk := &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.Empty.Prefix(4444), StatusV: choices.Processing, @@ -166,7 +167,7 @@ func TestBlockVerify_PostForkOption_CoreBlockVerifyIsCalledOnce(t *testing.T) { // create post fork oracle block ... oracleCoreBlk := &TestOptionsBlock{ - TestBlock: snowman.TestBlock{ + Block: snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.Empty.Prefix(1111), StatusV: choices.Processing, @@ -176,7 +177,7 @@ func TestBlockVerify_PostForkOption_CoreBlockVerifyIsCalledOnce(t *testing.T) { HeightV: coreGenBlk.Height() + 1, }, } - coreOpt0 := &snowman.TestBlock{ + coreOpt0 := &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.Empty.Prefix(2222), StatusV: choices.Processing, @@ -185,7 +186,7 @@ func TestBlockVerify_PostForkOption_CoreBlockVerifyIsCalledOnce(t *testing.T) { ParentV: oracleCoreBlk.ID(), HeightV: oracleCoreBlk.Height() + 1, } - coreOpt1 := &snowman.TestBlock{ + coreOpt1 := &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.Empty.Prefix(3333), StatusV: choices.Processing, @@ -271,7 +272,7 @@ func TestBlockAccept_PostForkOption_SetsLastAcceptedBlock(t *testing.T) { // create post fork oracle block ... oracleCoreBlk := &TestOptionsBlock{ - TestBlock: snowman.TestBlock{ + Block: snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.Empty.Prefix(1111), StatusV: choices.Processing, @@ -282,7 +283,7 @@ func TestBlockAccept_PostForkOption_SetsLastAcceptedBlock(t *testing.T) { }, } oracleCoreBlk.opts = [2]snowman.Block{ - &snowman.TestBlock{ + &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.Empty.Prefix(2222), StatusV: choices.Processing, @@ -291,7 +292,7 @@ func TestBlockAccept_PostForkOption_SetsLastAcceptedBlock(t *testing.T) { ParentV: oracleCoreBlk.ID(), HeightV: oracleCoreBlk.Height() + 1, }, - &snowman.TestBlock{ + &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.Empty.Prefix(3333), StatusV: choices.Processing, @@ -384,7 +385,7 @@ func TestBlockReject_InnerBlockIsNotRejected(t *testing.T) { // create post fork oracle block ... oracleCoreBlk := &TestOptionsBlock{ - TestBlock: snowman.TestBlock{ + Block: snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.Empty.Prefix(1111), StatusV: choices.Processing, @@ -395,7 +396,7 @@ func TestBlockReject_InnerBlockIsNotRejected(t *testing.T) { }, } oracleCoreBlk.opts = [2]snowman.Block{ - &snowman.TestBlock{ + &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.Empty.Prefix(2222), StatusV: choices.Processing, @@ -404,7 +405,7 @@ func TestBlockReject_InnerBlockIsNotRejected(t *testing.T) { ParentV: oracleCoreBlk.ID(), HeightV: oracleCoreBlk.Height() + 1, }, - &snowman.TestBlock{ + &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.Empty.Prefix(3333), StatusV: choices.Processing, @@ -488,7 +489,7 @@ func TestBlockVerify_PostForkOption_ParentIsNotOracleWithError(t *testing.T) { }() coreBlk := &TestOptionsBlock{ - TestBlock: snowman.TestBlock{ + Block: snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.GenerateTestID(), StatusV: choices.Processing, @@ -500,7 +501,7 @@ func TestBlockVerify_PostForkOption_ParentIsNotOracleWithError(t *testing.T) { optsErr: snowman.ErrNotOracle, } - coreChildBlk := &snowman.TestBlock{ + coreChildBlk := &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.GenerateTestID(), StatusV: choices.Processing, @@ -574,7 +575,7 @@ func TestOptionTimestampValidity(t *testing.T) { coreOracleBlkID := ids.GenerateTestID() coreOracleBlk := &TestOptionsBlock{ - TestBlock: snowman.TestBlock{ + Block: snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: coreOracleBlkID, StatusV: choices.Processing, @@ -584,7 +585,7 @@ func TestOptionTimestampValidity(t *testing.T) { HeightV: coreGenBlk.Height() + 1, }, opts: [2]snowman.Block{ - &snowman.TestBlock{ + &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.GenerateTestID(), StatusV: choices.Processing, @@ -593,7 +594,7 @@ func TestOptionTimestampValidity(t *testing.T) { ParentV: coreOracleBlkID, HeightV: coreGenBlk.Height() + 2, }, - &snowman.TestBlock{ + &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.GenerateTestID(), StatusV: choices.Processing, diff --git a/vms/proposervm/pre_fork_block_test.go b/vms/proposervm/pre_fork_block_test.go index 4259349cf094..9dc8fa2e3c44 100644 --- a/vms/proposervm/pre_fork_block_test.go +++ b/vms/proposervm/pre_fork_block_test.go @@ -31,7 +31,7 @@ func TestOracle_PreForkBlkImplementsInterface(t *testing.T) { // setup proBlk := preForkBlock{ - Block: &snowman.TestBlock{}, + Block: &snowmantest.Block{}, } // test @@ -62,7 +62,7 @@ func TestOracle_PreForkBlkCanBuiltOnPreForkOption(t *testing.T) { // create pre fork oracle block ... oracleCoreBlk := &TestOptionsBlock{ - TestBlock: snowman.TestBlock{ + Block: snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.Empty.Prefix(1111), StatusV: choices.Processing, @@ -72,7 +72,7 @@ func TestOracle_PreForkBlkCanBuiltOnPreForkOption(t *testing.T) { }, } oracleCoreBlk.opts = [2]snowman.Block{ - &snowman.TestBlock{ + &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.Empty.Prefix(2222), StatusV: choices.Processing, @@ -80,7 +80,7 @@ func TestOracle_PreForkBlkCanBuiltOnPreForkOption(t *testing.T) { BytesV: []byte{2}, ParentV: oracleCoreBlk.ID(), }, - &snowman.TestBlock{ + &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.Empty.Prefix(3333), StatusV: choices.Processing, @@ -122,7 +122,7 @@ func TestOracle_PreForkBlkCanBuiltOnPreForkOption(t *testing.T) { require.NoError(proVM.SetPreference(context.Background(), opts[0].ID())) lastCoreBlk := &TestOptionsBlock{ - TestBlock: snowman.TestBlock{ + Block: snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.Empty.Prefix(4444), StatusV: choices.Processing, @@ -154,7 +154,7 @@ func TestOracle_PostForkBlkCanBuiltOnPreForkOption(t *testing.T) { // create pre fork oracle block pre activation time... oracleCoreBlk := &TestOptionsBlock{ - TestBlock: snowman.TestBlock{ + Block: snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.Empty.Prefix(1111), StatusV: choices.Processing, @@ -167,7 +167,7 @@ func TestOracle_PostForkBlkCanBuiltOnPreForkOption(t *testing.T) { // ... whose options are post activation time oracleCoreBlk.opts = [2]snowman.Block{ - &snowman.TestBlock{ + &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.Empty.Prefix(2222), StatusV: choices.Processing, @@ -176,7 +176,7 @@ func TestOracle_PostForkBlkCanBuiltOnPreForkOption(t *testing.T) { ParentV: oracleCoreBlk.ID(), TimestampV: activationTime.Add(time.Second), }, - &snowman.TestBlock{ + &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.Empty.Prefix(3333), StatusV: choices.Processing, @@ -219,7 +219,7 @@ func TestOracle_PostForkBlkCanBuiltOnPreForkOption(t *testing.T) { require.NoError(proVM.SetPreference(context.Background(), opts[0].ID())) lastCoreBlk := &TestOptionsBlock{ - TestBlock: snowman.TestBlock{ + Block: snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.Empty.Prefix(4444), StatusV: choices.Processing, @@ -252,7 +252,7 @@ func TestBlockVerify_PreFork_ParentChecks(t *testing.T) { require.True(coreGenBlk.Timestamp().Before(activationTime)) // create parent block ... - parentCoreBlk := &snowman.TestBlock{ + parentCoreBlk := &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.Empty.Prefix(1111), StatusV: choices.Processing, @@ -289,7 +289,7 @@ func TestBlockVerify_PreFork_ParentChecks(t *testing.T) { require.NoError(err) // .. create child block ... - childCoreBlk := &snowman.TestBlock{ + childCoreBlk := &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.GenerateTestID(), StatusV: choices.Processing, @@ -332,7 +332,7 @@ func TestBlockVerify_BlocksBuiltOnPreForkGenesis(t *testing.T) { preActivationTime := activationTime.Add(-1 * time.Second) proVM.Set(preActivationTime) - coreBlk := &snowman.TestBlock{ + coreBlk := &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.Empty.Prefix(1111), StatusV: choices.Processing, @@ -386,7 +386,7 @@ func TestBlockVerify_BlocksBuiltOnPreForkGenesis(t *testing.T) { } require.NoError(proVM.SetPreference(context.Background(), preForkChild.ID())) - secondCoreBlk := &snowman.TestBlock{ + secondCoreBlk := &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.Empty.Prefix(2222), }, @@ -417,7 +417,7 @@ func TestBlockVerify_BlocksBuiltOnPreForkGenesis(t *testing.T) { require.NoError(lastPreForkBlk.Verify(context.Background())) require.NoError(proVM.SetPreference(context.Background(), lastPreForkBlk.ID())) - thirdCoreBlk := &snowman.TestBlock{ + thirdCoreBlk := &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.Empty.Prefix(333), }, @@ -464,7 +464,7 @@ func TestBlockVerify_BlocksBuiltOnPostForkGenesis(t *testing.T) { }() // build parent block after fork activation time ... - coreBlock := &snowman.TestBlock{ + coreBlock := &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.Empty.Prefix(1111), StatusV: choices.Processing, @@ -507,7 +507,7 @@ func TestBlockAccept_PreFork_SetsLastAcceptedBlock(t *testing.T) { require.NoError(proVM.Shutdown(context.Background())) }() - coreBlk := &snowman.TestBlock{ + coreBlk := &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.Empty.Prefix(1111), StatusV: choices.Processing, @@ -569,7 +569,7 @@ func TestBlockReject_PreForkBlock_InnerBlockIsRejected(t *testing.T) { require.NoError(proVM.Shutdown(context.Background())) }() - coreBlk := &snowman.TestBlock{ + coreBlk := &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.Empty.Prefix(111), StatusV: choices.Processing, @@ -610,7 +610,7 @@ func TestBlockVerify_ForkBlockIsOracleBlock(t *testing.T) { coreBlkID := ids.GenerateTestID() coreBlk := &TestOptionsBlock{ - TestBlock: snowman.TestBlock{ + Block: snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: coreBlkID, StatusV: choices.Processing, @@ -620,7 +620,7 @@ func TestBlockVerify_ForkBlockIsOracleBlock(t *testing.T) { TimestampV: postActivationTime, }, opts: [2]snowman.Block{ - &snowman.TestBlock{ + &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.GenerateTestID(), StatusV: choices.Processing, @@ -629,7 +629,7 @@ func TestBlockVerify_ForkBlockIsOracleBlock(t *testing.T) { ParentV: coreBlkID, TimestampV: postActivationTime, }, - &snowman.TestBlock{ + &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.GenerateTestID(), StatusV: choices.Processing, @@ -704,7 +704,7 @@ func TestBlockVerify_ForkBlockIsOracleBlockButChildrenAreSigned(t *testing.T) { coreBlkID := ids.GenerateTestID() coreBlk := &TestOptionsBlock{ - TestBlock: snowman.TestBlock{ + Block: snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: coreBlkID, StatusV: choices.Processing, @@ -714,7 +714,7 @@ func TestBlockVerify_ForkBlockIsOracleBlockButChildrenAreSigned(t *testing.T) { TimestampV: postActivationTime, }, opts: [2]snowman.Block{ - &snowman.TestBlock{ + &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.GenerateTestID(), StatusV: choices.Processing, @@ -723,7 +723,7 @@ func TestBlockVerify_ForkBlockIsOracleBlockButChildrenAreSigned(t *testing.T) { ParentV: coreBlkID, TimestampV: postActivationTime, }, - &snowman.TestBlock{ + &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.GenerateTestID(), StatusV: choices.Processing, diff --git a/vms/proposervm/state_syncable_vm_test.go b/vms/proposervm/state_syncable_vm_test.go index d03f3c3d1c58..45093fb67a06 100644 --- a/vms/proposervm/state_syncable_vm_test.go +++ b/vms/proposervm/state_syncable_vm_test.go @@ -17,6 +17,7 @@ import ( "github.com/ava-labs/avalanchego/snow" "github.com/ava-labs/avalanchego/snow/choices" "github.com/ava-labs/avalanchego/snow/consensus/snowman" + "github.com/ava-labs/avalanchego/snow/consensus/snowman/snowmantest" "github.com/ava-labs/avalanchego/snow/engine/common" "github.com/ava-labs/avalanchego/snow/engine/snowman/block" "github.com/ava-labs/avalanchego/snow/snowtest" @@ -40,7 +41,7 @@ func helperBuildStateSyncTestObjects(t *testing.T) (*fullVM, *VM) { } // load innerVM expectations - innerGenesisBlk := &snowman.TestBlock{ + innerGenesisBlk := &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.ID{'i', 'n', 'n', 'e', 'r', 'G', 'e', 'n', 'e', 's', 'i', 's', 'I', 'D'}, }, @@ -166,7 +167,7 @@ func TestStateSyncGetOngoingSyncStateSummary(t *testing.T) { require.NoError(vm.SetForkHeight(innerSummary.Height() - 1)) // store post fork block associated with summary - innerBlk := &snowman.TestBlock{ + innerBlk := &snowmantest.Block{ BytesV: []byte{1}, ParentV: ids.GenerateTestID(), HeightV: innerSummary.Height(), @@ -250,7 +251,7 @@ func TestStateSyncGetLastStateSummary(t *testing.T) { require.NoError(vm.SetForkHeight(innerSummary.Height() - 1)) // store post fork block associated with summary - innerBlk := &snowman.TestBlock{ + innerBlk := &snowmantest.Block{ BytesV: []byte{1}, ParentV: ids.GenerateTestID(), HeightV: innerSummary.Height(), @@ -337,7 +338,7 @@ func TestStateSyncGetStateSummary(t *testing.T) { require.NoError(vm.SetForkHeight(innerSummary.Height() - 1)) // store post fork block associated with summary - innerBlk := &snowman.TestBlock{ + innerBlk := &snowmantest.Block{ BytesV: []byte{1}, ParentV: ids.GenerateTestID(), HeightV: innerSummary.Height(), @@ -409,7 +410,7 @@ func TestParseStateSummary(t *testing.T) { require.NoError(vm.SetForkHeight(innerSummary.Height() - 1)) // store post fork block associated with summary - innerBlk := &snowman.TestBlock{ + innerBlk := &snowmantest.Block{ BytesV: []byte{1}, ParentV: ids.GenerateTestID(), HeightV: innerSummary.Height(), @@ -467,7 +468,7 @@ func TestStateSummaryAccept(t *testing.T) { require.NoError(vm.SetForkHeight(innerSummary.Height() - 1)) // store post fork block associated with summary - innerBlk := &snowman.TestBlock{ + innerBlk := &snowmantest.Block{ BytesV: []byte{1}, ParentV: ids.GenerateTestID(), HeightV: innerSummary.Height(), @@ -538,7 +539,7 @@ func TestStateSummaryAcceptOlderBlock(t *testing.T) { vm.lastAcceptedHeight = innerSummary.Height() + 1 // store post fork block associated with summary - innerBlk := &snowman.TestBlock{ + innerBlk := &snowmantest.Block{ BytesV: []byte{1}, ParentV: ids.GenerateTestID(), HeightV: innerSummary.Height(), diff --git a/vms/proposervm/tree/tree_test.go b/vms/proposervm/tree/tree_test.go index 1e826e418c21..7bfdf2c51c88 100644 --- a/vms/proposervm/tree/tree_test.go +++ b/vms/proposervm/tree/tree_test.go @@ -9,32 +9,16 @@ import ( "github.com/stretchr/testify/require" - "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/snow/choices" - "github.com/ava-labs/avalanchego/snow/consensus/snowman" -) - -var ( - GenesisID = ids.GenerateTestID() - Genesis = &snowman.TestBlock{TestDecidable: choices.TestDecidable{ - IDV: GenesisID, - StatusV: choices.Accepted, - }} + "github.com/ava-labs/avalanchego/snow/consensus/snowman/snowmantest" ) func TestAcceptSingleBlock(t *testing.T) { require := require.New(t) - block := &snowman.TestBlock{ - TestDecidable: choices.TestDecidable{ - IDV: ids.GenerateTestID(), - StatusV: choices.Processing, - }, - ParentV: Genesis.ID(), - } - tr := New() + block := snowmantest.BuildChildBlock(snowmantest.Genesis) _, contains := tr.Get(block) require.False(contains) @@ -53,24 +37,11 @@ func TestAcceptSingleBlock(t *testing.T) { func TestAcceptBlockConflict(t *testing.T) { require := require.New(t) - blockToAccept := &snowman.TestBlock{ - TestDecidable: choices.TestDecidable{ - IDV: ids.GenerateTestID(), - StatusV: choices.Processing, - }, - ParentV: Genesis.ID(), - } - - blockToReject := &snowman.TestBlock{ - TestDecidable: choices.TestDecidable{ - IDV: ids.GenerateTestID(), - StatusV: choices.Processing, - }, - ParentV: Genesis.ID(), - } - tr := New() + blockToAccept := snowmantest.BuildChildBlock(snowmantest.Genesis) + blockToReject := snowmantest.BuildChildBlock(snowmantest.Genesis) + // add conflicting blocks tr.Add(blockToAccept) _, contains := tr.Get(blockToAccept) @@ -96,32 +67,12 @@ func TestAcceptBlockConflict(t *testing.T) { func TestAcceptChainConflict(t *testing.T) { require := require.New(t) - blockToAccept := &snowman.TestBlock{ - TestDecidable: choices.TestDecidable{ - IDV: ids.GenerateTestID(), - StatusV: choices.Processing, - }, - ParentV: Genesis.ID(), - } - - blockToReject := &snowman.TestBlock{ - TestDecidable: choices.TestDecidable{ - IDV: ids.GenerateTestID(), - StatusV: choices.Processing, - }, - ParentV: Genesis.ID(), - } - - blockToRejectChild := &snowman.TestBlock{ - TestDecidable: choices.TestDecidable{ - IDV: ids.GenerateTestID(), - StatusV: choices.Processing, - }, - ParentV: blockToReject.ID(), - } - tr := New() + blockToAccept := snowmantest.BuildChildBlock(snowmantest.Genesis) + blockToReject := snowmantest.BuildChildBlock(snowmantest.Genesis) + blockToRejectChild := snowmantest.BuildChildBlock(blockToReject) + // add conflicting blocks. tr.Add(blockToAccept) _, contains := tr.Get(blockToAccept) diff --git a/vms/proposervm/vm_byzantine_test.go b/vms/proposervm/vm_byzantine_test.go index c9ad1b98c79b..e145570c2ffd 100644 --- a/vms/proposervm/vm_byzantine_test.go +++ b/vms/proposervm/vm_byzantine_test.go @@ -16,6 +16,7 @@ import ( "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/snow/choices" "github.com/ava-labs/avalanchego/snow/consensus/snowman" + "github.com/ava-labs/avalanchego/snow/consensus/snowman/snowmantest" "github.com/ava-labs/avalanchego/snow/validators" "github.com/ava-labs/avalanchego/vms/proposervm/block" ) @@ -41,7 +42,7 @@ func TestInvalidByzantineProposerParent(t *testing.T) { require.NoError(proVM.Shutdown(context.Background())) }() - xBlock := &snowman.TestBlock{ + xBlock := &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.GenerateTestID(), StatusV: choices.Processing, @@ -63,7 +64,7 @@ func TestInvalidByzantineProposerParent(t *testing.T) { require.NoError(aBlock.Accept(context.Background())) yBlockBytes := []byte{2} - yBlock := &snowman.TestBlock{ + yBlock := &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.GenerateTestID(), StatusV: choices.Processing, @@ -115,7 +116,7 @@ func TestInvalidByzantineProposerOracleParent(t *testing.T) { xBlockID := ids.GenerateTestID() xBlock := &TestOptionsBlock{ - TestBlock: snowman.TestBlock{ + Block: snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: xBlockID, StatusV: choices.Processing, @@ -124,7 +125,7 @@ func TestInvalidByzantineProposerOracleParent(t *testing.T) { ParentV: coreGenBlk.ID(), }, opts: [2]snowman.Block{ - &snowman.TestBlock{ + &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.GenerateTestID(), StatusV: choices.Processing, @@ -132,7 +133,7 @@ func TestInvalidByzantineProposerOracleParent(t *testing.T) { BytesV: []byte{2}, ParentV: xBlockID, }, - &snowman.TestBlock{ + &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.GenerateTestID(), StatusV: choices.Processing, @@ -221,7 +222,7 @@ func TestInvalidByzantineProposerPreForkParent(t *testing.T) { require.NoError(proVM.Shutdown(context.Background())) }() - xBlock := &snowman.TestBlock{ + xBlock := &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.GenerateTestID(), StatusV: choices.Processing, @@ -235,7 +236,7 @@ func TestInvalidByzantineProposerPreForkParent(t *testing.T) { } yBlockBytes := []byte{2} - yBlock := &snowman.TestBlock{ + yBlock := &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.GenerateTestID(), StatusV: choices.Processing, @@ -313,7 +314,7 @@ func TestBlockVerify_PostForkOption_FaultyParent(t *testing.T) { }() xBlock := &TestOptionsBlock{ - TestBlock: snowman.TestBlock{ + Block: snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.GenerateTestID(), StatusV: choices.Processing, @@ -322,7 +323,7 @@ func TestBlockVerify_PostForkOption_FaultyParent(t *testing.T) { ParentV: coreGenBlk.ID(), }, opts: [2]snowman.Block{ - &snowman.TestBlock{ + &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.GenerateTestID(), StatusV: choices.Processing, @@ -330,7 +331,7 @@ func TestBlockVerify_PostForkOption_FaultyParent(t *testing.T) { BytesV: []byte{2}, ParentV: coreGenBlk.ID(), // valid block should reference xBlock }, - &snowman.TestBlock{ + &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.GenerateTestID(), StatusV: choices.Processing, @@ -415,7 +416,7 @@ func TestBlockVerify_InvalidPostForkOption(t *testing.T) { // create an Oracle pre-fork block X xBlockID := ids.GenerateTestID() xBlock := &TestOptionsBlock{ - TestBlock: snowman.TestBlock{ + Block: snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: xBlockID, StatusV: choices.Processing, @@ -424,7 +425,7 @@ func TestBlockVerify_InvalidPostForkOption(t *testing.T) { ParentV: coreGenBlk.ID(), }, opts: [2]snowman.Block{ - &snowman.TestBlock{ + &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.GenerateTestID(), StatusV: choices.Processing, @@ -432,7 +433,7 @@ func TestBlockVerify_InvalidPostForkOption(t *testing.T) { BytesV: []byte{2}, ParentV: xBlockID, }, - &snowman.TestBlock{ + &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.GenerateTestID(), StatusV: choices.Processing, @@ -448,7 +449,7 @@ func TestBlockVerify_InvalidPostForkOption(t *testing.T) { xInnerOption := xInnerOptions[0] // create a non-Oracle pre-fork block Y - yBlock := &snowman.TestBlock{ + yBlock := &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.GenerateTestID(), StatusV: choices.Processing, @@ -527,7 +528,7 @@ func TestBlockVerify_InvalidPostForkOption(t *testing.T) { // create post-fork block B from Y zBlockID := ids.GenerateTestID() zBlock := &TestOptionsBlock{ - TestBlock: snowman.TestBlock{ + Block: snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: zBlockID, StatusV: choices.Processing, @@ -536,7 +537,7 @@ func TestBlockVerify_InvalidPostForkOption(t *testing.T) { ParentV: coreGenBlk.ID(), }, opts: [2]snowman.Block{ - &snowman.TestBlock{ + &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.GenerateTestID(), StatusV: choices.Processing, @@ -544,7 +545,7 @@ func TestBlockVerify_InvalidPostForkOption(t *testing.T) { BytesV: []byte{2}, ParentV: zBlockID, }, - &snowman.TestBlock{ + &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.GenerateTestID(), StatusV: choices.Processing, @@ -608,7 +609,7 @@ func TestGetBlock_MutatedSignature(t *testing.T) { proVM.Set(coreGenBlk.Timestamp()) // Create valid core blocks to build our chain on. - coreBlk0 := &snowman.TestBlock{ + coreBlk0 := &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.Empty.Prefix(1111), StatusV: choices.Processing, @@ -618,7 +619,7 @@ func TestGetBlock_MutatedSignature(t *testing.T) { HeightV: coreGenBlk.Height() + 1, } - coreBlk1 := &snowman.TestBlock{ + coreBlk1 := &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.Empty.Prefix(2222), StatusV: choices.Processing, diff --git a/vms/proposervm/vm_test.go b/vms/proposervm/vm_test.go index eb40426c17c2..67585fe2a8c8 100644 --- a/vms/proposervm/vm_test.go +++ b/vms/proposervm/vm_test.go @@ -83,12 +83,12 @@ func initTestProposerVM( *fullVM, *validators.TestState, *VM, - *snowman.TestBlock, + *snowmantest.Block, database.Database, ) { require := require.New(t) - coreGenBlk := &snowman.TestBlock{ + coreGenBlk := &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.GenerateTestID(), StatusV: choices.Accepted, @@ -259,7 +259,7 @@ func TestBuildBlockTimestampAreRoundedToSeconds(t *testing.T) { skewedTimestamp := time.Now().Truncate(time.Second).Add(time.Millisecond) proVM.Set(skewedTimestamp) - coreBlk := &snowman.TestBlock{ + coreBlk := &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.Empty.Prefix(111), StatusV: choices.Processing, @@ -292,7 +292,7 @@ func TestBuildBlockIsIdempotent(t *testing.T) { require.NoError(proVM.Shutdown(context.Background())) }() - coreBlk := &snowman.TestBlock{ + coreBlk := &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.Empty.Prefix(111), StatusV: choices.Processing, @@ -330,7 +330,7 @@ func TestFirstProposerBlockIsBuiltOnTopOfGenesis(t *testing.T) { require.NoError(proVM.Shutdown(context.Background())) }() - coreBlk := &snowman.TestBlock{ + coreBlk := &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.Empty.Prefix(111), StatusV: choices.Processing, @@ -368,7 +368,7 @@ func TestProposerBlocksAreBuiltOnPreferredProBlock(t *testing.T) { }() // add two proBlks... - coreBlk1 := &snowman.TestBlock{ + coreBlk1 := &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.Empty.Prefix(111), StatusV: choices.Processing, @@ -383,7 +383,7 @@ func TestProposerBlocksAreBuiltOnPreferredProBlock(t *testing.T) { proBlk1, err := proVM.BuildBlock(context.Background()) require.NoError(err) - coreBlk2 := &snowman.TestBlock{ + coreBlk2 := &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.Empty.Prefix(222), StatusV: choices.Processing, @@ -401,7 +401,7 @@ func TestProposerBlocksAreBuiltOnPreferredProBlock(t *testing.T) { require.NoError(proBlk2.Verify(context.Background())) // ...and set one as preferred - var prefcoreBlk *snowman.TestBlock + var prefcoreBlk *snowmantest.Block coreVM.SetPreferenceF = func(_ context.Context, prefID ids.ID) error { switch prefID { case coreBlk1.ID(): @@ -430,7 +430,7 @@ func TestProposerBlocksAreBuiltOnPreferredProBlock(t *testing.T) { require.NoError(proVM.SetPreference(context.Background(), proBlk2.ID())) // build block... - coreBlk3 := &snowman.TestBlock{ + coreBlk3 := &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.Empty.Prefix(333), StatusV: choices.Processing, @@ -463,7 +463,7 @@ func TestCoreBlocksMustBeBuiltOnPreferredCoreBlock(t *testing.T) { require.NoError(proVM.Shutdown(context.Background())) }() - coreBlk1 := &snowman.TestBlock{ + coreBlk1 := &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.Empty.Prefix(111), StatusV: choices.Processing, @@ -478,7 +478,7 @@ func TestCoreBlocksMustBeBuiltOnPreferredCoreBlock(t *testing.T) { proBlk1, err := proVM.BuildBlock(context.Background()) require.NoError(err) - coreBlk2 := &snowman.TestBlock{ + coreBlk2 := &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.Empty.Prefix(222), StatusV: choices.Processing, @@ -497,7 +497,7 @@ func TestCoreBlocksMustBeBuiltOnPreferredCoreBlock(t *testing.T) { require.NoError(proBlk2.Verify(context.Background())) // ...and set one as preferred - var wronglyPreferredcoreBlk *snowman.TestBlock + var wronglyPreferredcoreBlk *snowmantest.Block coreVM.SetPreferenceF = func(_ context.Context, prefID ids.ID) error { switch prefID { case coreBlk1.ID(): @@ -526,7 +526,7 @@ func TestCoreBlocksMustBeBuiltOnPreferredCoreBlock(t *testing.T) { require.NoError(proVM.SetPreference(context.Background(), proBlk2.ID())) // build block... - coreBlk3 := &snowman.TestBlock{ + coreBlk3 := &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.Empty.Prefix(333), StatusV: choices.Processing, @@ -560,7 +560,7 @@ func TestCoreBlockFailureCauseProposerBlockParseFailure(t *testing.T) { require.NoError(proVM.Shutdown(context.Background())) }() - innerBlk := &snowman.TestBlock{ + innerBlk := &snowmantest.Block{ BytesV: []byte{1}, } coreVM.ParseBlockF = func(context.Context, []byte) (snowman.Block, error) { @@ -603,7 +603,7 @@ func TestTwoProBlocksWrappingSameCoreBlockCanBeParsed(t *testing.T) { }() // create two Proposer blocks at the same height - innerBlk := &snowman.TestBlock{ + innerBlk := &snowmantest.Block{ BytesV: []byte{1}, ParentV: gencoreBlk.ID(), HeightV: gencoreBlk.Height() + 1, @@ -679,7 +679,7 @@ func TestTwoProBlocksWithSameParentCanBothVerify(t *testing.T) { }() // one block is built from this proVM - localcoreBlk := &snowman.TestBlock{ + localcoreBlk := &snowmantest.Block{ BytesV: []byte{111}, ParentV: coreGenBlk.ID(), HeightV: coreGenBlk.Height() + 1, @@ -693,7 +693,7 @@ func TestTwoProBlocksWithSameParentCanBothVerify(t *testing.T) { require.NoError(builtBlk.Verify(context.Background())) // another block with same parent comes from network and is parsed - netcoreBlk := &snowman.TestBlock{ + netcoreBlk := &snowmantest.Block{ BytesV: []byte{222}, ParentV: coreGenBlk.ID(), HeightV: coreGenBlk.Height() + 1, @@ -771,7 +771,7 @@ func TestPreFork_BuildBlock(t *testing.T) { require.NoError(proVM.Shutdown(context.Background())) }() - coreBlk := &snowman.TestBlock{ + coreBlk := &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.Empty.Prefix(333), StatusV: choices.Processing, @@ -812,7 +812,7 @@ func TestPreFork_ParseBlock(t *testing.T) { require.NoError(proVM.Shutdown(context.Background())) }() - coreBlk := &snowman.TestBlock{ + coreBlk := &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.Empty.Prefix(2021), }, @@ -851,7 +851,7 @@ func TestPreFork_SetPreference(t *testing.T) { require.NoError(proVM.Shutdown(context.Background())) }() - coreBlk0 := &snowman.TestBlock{ + coreBlk0 := &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.Empty.Prefix(333), StatusV: choices.Processing, @@ -889,7 +889,7 @@ func TestPreFork_SetPreference(t *testing.T) { } require.NoError(proVM.SetPreference(context.Background(), builtBlk.ID())) - coreBlk1 := &snowman.TestBlock{ + coreBlk1 := &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.Empty.Prefix(444), StatusV: choices.Processing, @@ -910,7 +910,7 @@ func TestPreFork_SetPreference(t *testing.T) { func TestExpiredBuildBlock(t *testing.T) { require := require.New(t) - coreGenBlk := &snowman.TestBlock{ + coreGenBlk := &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.GenerateTestID(), StatusV: choices.Accepted, @@ -1026,7 +1026,7 @@ func TestExpiredBuildBlock(t *testing.T) { // Before calling BuildBlock, verify a remote block and set it as the // preferred block. - coreBlk := &snowman.TestBlock{ + coreBlk := &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.GenerateTestID(), StatusV: choices.Processing, @@ -1124,7 +1124,7 @@ func TestInnerBlockDeduplication(t *testing.T) { require.NoError(proVM.Shutdown(context.Background())) }() - coreBlk := &snowman.TestBlock{ + coreBlk := &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.GenerateTestID(), StatusV: choices.Processing, @@ -1217,7 +1217,7 @@ func TestInnerBlockDeduplication(t *testing.T) { func TestInnerVMRollback(t *testing.T) { require := require.New(t) - coreGenBlk := &snowman.TestBlock{ + coreGenBlk := &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.GenerateTestID(), StatusV: choices.Accepted, @@ -1314,7 +1314,7 @@ func TestInnerVMRollback(t *testing.T) { require.NoError(proVM.SetState(context.Background(), snow.NormalOp)) require.NoError(proVM.SetPreference(context.Background(), coreGenBlk.IDV)) - coreBlk := &snowman.TestBlock{ + coreBlk := &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.GenerateTestID(), StatusV: choices.Processing, @@ -1433,7 +1433,7 @@ func TestBuildBlockDuringWindow(t *testing.T) { }, nil } - coreBlk0 := &snowman.TestBlock{ + coreBlk0 := &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.GenerateTestID(), StatusV: choices.Processing, @@ -1442,7 +1442,7 @@ func TestBuildBlockDuringWindow(t *testing.T) { ParentV: coreGenBlk.ID(), HeightV: coreGenBlk.Height() + 1, } - coreBlk1 := &snowman.TestBlock{ + coreBlk1 := &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.GenerateTestID(), StatusV: choices.Processing, @@ -1530,7 +1530,7 @@ func TestTwoForks_OneIsAccepted(t *testing.T) { }() // create pre-fork block X and post-fork block A - xBlock := &snowman.TestBlock{ + xBlock := &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.GenerateTestID(), StatusV: choices.Processing, @@ -1549,7 +1549,7 @@ func TestTwoForks_OneIsAccepted(t *testing.T) { require.NoError(aBlock.Verify(context.Background())) // use a different way to construct pre-fork block Y and post-fork block B - yBlock := &snowman.TestBlock{ + yBlock := &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.GenerateTestID(), StatusV: choices.Processing, @@ -1579,7 +1579,7 @@ func TestTwoForks_OneIsAccepted(t *testing.T) { require.NoError(bBlock.Verify(context.Background())) // append Z/C to Y/B - zBlock := &snowman.TestBlock{ + zBlock := &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.GenerateTestID(), StatusV: choices.Processing, @@ -1626,7 +1626,7 @@ func TestTooFarAdvanced(t *testing.T) { require.NoError(proVM.Shutdown(context.Background())) }() - xBlock := &snowman.TestBlock{ + xBlock := &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.GenerateTestID(), StatusV: choices.Processing, @@ -1637,7 +1637,7 @@ func TestTooFarAdvanced(t *testing.T) { TimestampV: gBlock.Timestamp(), } - yBlock := &snowman.TestBlock{ + yBlock := &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.GenerateTestID(), StatusV: choices.Processing, @@ -1722,7 +1722,7 @@ func TestTwoOptions_OneIsAccepted(t *testing.T) { xBlockID := ids.GenerateTestID() xBlock := &TestOptionsBlock{ - TestBlock: snowman.TestBlock{ + Block: snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: xBlockID, StatusV: choices.Processing, @@ -1732,7 +1732,7 @@ func TestTwoOptions_OneIsAccepted(t *testing.T) { TimestampV: coreGenBlk.Timestamp(), }, opts: [2]snowman.Block{ - &snowman.TestBlock{ + &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.GenerateTestID(), StatusV: choices.Processing, @@ -1741,7 +1741,7 @@ func TestTwoOptions_OneIsAccepted(t *testing.T) { ParentV: xBlockID, TimestampV: coreGenBlk.Timestamp(), }, - &snowman.TestBlock{ + &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.GenerateTestID(), StatusV: choices.Processing, @@ -1798,7 +1798,7 @@ func TestLaggedPChainHeight(t *testing.T) { require.NoError(proVM.Shutdown(context.Background())) }() - innerBlock := &snowman.TestBlock{ + innerBlock := &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.GenerateTestID(), StatusV: choices.Processing, @@ -1826,7 +1826,7 @@ func TestLaggedPChainHeight(t *testing.T) { func TestRejectedHeightNotIndexed(t *testing.T) { require := require.New(t) - coreGenBlk := &snowman.TestBlock{ + coreGenBlk := &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.GenerateTestID(), StatusV: choices.Accepted, @@ -1953,7 +1953,7 @@ func TestRejectedHeightNotIndexed(t *testing.T) { require.NoError(proVM.SetPreference(context.Background(), coreGenBlk.IDV)) // create inner block X and outer block A - xBlock := &snowman.TestBlock{ + xBlock := &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.GenerateTestID(), StatusV: choices.Processing, @@ -1974,7 +1974,7 @@ func TestRejectedHeightNotIndexed(t *testing.T) { require.NoError(aBlock.Verify(context.Background())) // use a different way to construct inner block Y and outer block B - yBlock := &snowman.TestBlock{ + yBlock := &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.GenerateTestID(), StatusV: choices.Processing, @@ -2025,7 +2025,7 @@ func TestRejectedHeightNotIndexed(t *testing.T) { func TestRejectedOptionHeightNotIndexed(t *testing.T) { require := require.New(t) - coreGenBlk := &snowman.TestBlock{ + coreGenBlk := &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.GenerateTestID(), StatusV: choices.Accepted, @@ -2153,7 +2153,7 @@ func TestRejectedOptionHeightNotIndexed(t *testing.T) { xBlockID := ids.GenerateTestID() xBlock := &TestOptionsBlock{ - TestBlock: snowman.TestBlock{ + Block: snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: xBlockID, StatusV: choices.Processing, @@ -2163,7 +2163,7 @@ func TestRejectedOptionHeightNotIndexed(t *testing.T) { TimestampV: coreGenBlk.Timestamp(), }, opts: [2]snowman.Block{ - &snowman.TestBlock{ + &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.GenerateTestID(), StatusV: choices.Processing, @@ -2172,7 +2172,7 @@ func TestRejectedOptionHeightNotIndexed(t *testing.T) { ParentV: xBlockID, TimestampV: coreGenBlk.Timestamp(), }, - &snowman.TestBlock{ + &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.GenerateTestID(), StatusV: choices.Processing, @@ -2347,7 +2347,7 @@ func TestVMInnerBlkCacheDeduplicationRegression(t *testing.T) { }() // create pre-fork block X and post-fork block A - xBlock := &snowman.TestBlock{ + xBlock := &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.GenerateTestID(), StatusV: choices.Processing, @@ -2373,7 +2373,7 @@ func TestVMInnerBlkCacheDeduplicationRegression(t *testing.T) { ) require.NoError(err) - xBlockCopy := &snowman.TestBlock{ + xBlockCopy := &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: xBlock.IDV, StatusV: choices.Processing, @@ -2426,7 +2426,7 @@ func TestVMInnerBlkMarkedAcceptedRegression(t *testing.T) { }() // create an inner block and wrap it in an postForkBlock. - innerBlock := &snowman.TestBlock{ + innerBlock := &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.GenerateTestID(), StatusV: choices.Processing, @@ -2616,7 +2616,7 @@ func TestVM_VerifyBlockWithContext(t *testing.T) { func TestHistoricalBlockDeletion(t *testing.T) { require := require.New(t) - coreGenBlk := &snowman.TestBlock{ + coreGenBlk := &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.GenerateTestID(), StatusV: choices.Accepted, @@ -2714,7 +2714,7 @@ func TestHistoricalBlockDeletion(t *testing.T) { issueBlock := func() { lastAcceptedBlock := acceptedBlocks[currentHeight] - innerBlock := &snowman.TestBlock{ + innerBlock := &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.GenerateTestID(), StatusV: choices.Processing, diff --git a/vms/rpcchainvm/state_syncable_vm_test.go b/vms/rpcchainvm/state_syncable_vm_test.go index 3b71aaa8b4c7..504f628fc90a 100644 --- a/vms/rpcchainvm/state_syncable_vm_test.go +++ b/vms/rpcchainvm/state_syncable_vm_test.go @@ -17,7 +17,7 @@ import ( "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/snow" "github.com/ava-labs/avalanchego/snow/choices" - "github.com/ava-labs/avalanchego/snow/consensus/snowman" + "github.com/ava-labs/avalanchego/snow/consensus/snowman/snowmantest" "github.com/ava-labs/avalanchego/snow/engine/snowman/block" "github.com/ava-labs/avalanchego/snow/snowtest" "github.com/ava-labs/avalanchego/utils/logging" @@ -41,7 +41,7 @@ var ( } // last accepted blocks data before and after summary is accepted - preSummaryBlk = &snowman.TestBlock{ + preSummaryBlk = &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.ID{'f', 'i', 'r', 's', 't', 'B', 'l', 'K'}, StatusV: choices.Accepted, @@ -50,7 +50,7 @@ var ( ParentV: ids.ID{'p', 'a', 'r', 'e', 'n', 't', 'B', 'l', 'k'}, } - summaryBlk = &snowman.TestBlock{ + summaryBlk = &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: ids.ID{'s', 'u', 'm', 'm', 'a', 'r', 'y', 'B', 'l', 'K'}, StatusV: choices.Accepted, From bc36f79ebbeb6c4ee66013b4f758bc0b2a5875cc Mon Sep 17 00:00:00 2001 From: Stephen Buttolph Date: Fri, 26 Apr 2024 16:34:55 -0400 Subject: [PATCH 05/24] Remove old test --- snow/consensus/snowman/test_block.go | 54 ---------------------------- 1 file changed, 54 deletions(-) delete mode 100644 snow/consensus/snowman/test_block.go diff --git a/snow/consensus/snowman/test_block.go b/snow/consensus/snowman/test_block.go deleted file mode 100644 index a32872adbb96..000000000000 --- a/snow/consensus/snowman/test_block.go +++ /dev/null @@ -1,54 +0,0 @@ -// Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. -// See the file LICENSE for licensing terms. - -package snowman - -import ( - "cmp" - "context" - "time" - - "github.com/ava-labs/avalanchego/ids" - "github.com/ava-labs/avalanchego/snow/choices" - "github.com/ava-labs/avalanchego/utils" -) - -var ( - _ Block = (*TestBlock)(nil) - _ utils.Sortable[*TestBlock] = (*TestBlock)(nil) -) - -// TestBlock is a useful test block -type TestBlock struct { - choices.TestDecidable - - ParentV ids.ID - HeightV uint64 - TimestampV time.Time - VerifyV error - BytesV []byte -} - -func (b *TestBlock) Parent() ids.ID { - return b.ParentV -} - -func (b *TestBlock) Height() uint64 { - return b.HeightV -} - -func (b *TestBlock) Timestamp() time.Time { - return b.TimestampV -} - -func (b *TestBlock) Verify(context.Context) error { - return b.VerifyV -} - -func (b *TestBlock) Bytes() []byte { - return b.BytesV -} - -func (b *TestBlock) Compare(other *TestBlock) int { - return cmp.Compare(b.HeightV, other.HeightV) -} From 5c46f609e994e43b4bb2a84877b3b4e548273c16 Mon Sep 17 00:00:00 2001 From: Stephen Buttolph Date: Fri, 26 Apr 2024 16:41:49 -0400 Subject: [PATCH 06/24] Remove old genesis ID --- snow/engine/snowman/transitive_test.go | 141 ++++++++++++------------- 1 file changed, 70 insertions(+), 71 deletions(-) diff --git a/snow/engine/snowman/transitive_test.go b/snow/engine/snowman/transitive_test.go index fb158dbed287..d8443c7e05ad 100644 --- a/snow/engine/snowman/transitive_test.go +++ b/snow/engine/snowman/transitive_test.go @@ -39,11 +39,10 @@ var ( errUnexpectedCall = errors.New("unexpected call") errTest = errors.New("non-nil test") - GenesisID = ids.GenerateTestID() GenesisBytes = utils.RandomBytes(32) Genesis = &snowmantest.Block{ TestDecidable: choices.TestDecidable{ - IDV: GenesisID, + IDV: snowmantest.GenesisID, StatusV: choices.Accepted, }, BytesV: GenesisBytes, @@ -124,12 +123,12 @@ func setup(t *testing.T, config Config) (ids.NodeID, validators.Manager, *common vm.CantSetPreference = false vm.LastAcceptedF = func(context.Context) (ids.ID, error) { - return GenesisID, nil + return snowmantest.GenesisID, nil } vm.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { switch blkID { - case GenesisID: + case snowmantest.GenesisID: return Genesis, nil default: return nil, errUnknownBlock @@ -170,7 +169,7 @@ func TestEngineDropsAttemptToIssueBlockAfterFailedRequest(t *testing.T) { } vm.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { switch blkID { - case GenesisID: + case snowmantest.GenesisID: return Genesis, nil default: return nil, errUnknownBlock @@ -208,9 +207,9 @@ func TestEngineQuery(t *testing.T) { require.False(sendChitsCalled) sendChitsCalled = true require.Equal(uint32(15), requestID) - require.Equal(GenesisID, preferredID) - require.Equal(GenesisID, preferredIDByHeight) - require.Equal(GenesisID, accepted) + require.Equal(snowmantest.GenesisID, preferredID) + require.Equal(snowmantest.GenesisID, preferredIDByHeight) + require.Equal(snowmantest.GenesisID, accepted) } var getBlockCalled bool @@ -218,7 +217,7 @@ func TestEngineQuery(t *testing.T) { getBlockCalled = true switch blkID { - case GenesisID: + case snowmantest.GenesisID: return Genesis, nil default: return nil, errUnknownBlock @@ -235,7 +234,7 @@ func TestEngineQuery(t *testing.T) { require.Equal(peerID, nodeID) require.Contains([]ids.ID{ parent.ID(), - GenesisID, + snowmantest.GenesisID, }, blkID) } @@ -370,10 +369,10 @@ func TestEngineMultipleQuery(t *testing.T) { vm.CantSetPreference = false vm.LastAcceptedF = func(context.Context) (ids.ID, error) { - return GenesisID, nil + return snowmantest.GenesisID, nil } vm.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { - require.Equal(GenesisID, blkID) + require.Equal(snowmantest.GenesisID, blkID) return Genesis, nil } @@ -403,7 +402,7 @@ func TestEngineMultipleQuery(t *testing.T) { vm.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { switch blkID { - case GenesisID: + case snowmantest.GenesisID: return Genesis, nil default: return nil, errUnknownBlock @@ -420,7 +419,7 @@ func TestEngineMultipleQuery(t *testing.T) { vm.GetBlockF = func(_ context.Context, id ids.ID) (snowman.Block, error) { switch id { - case GenesisID: + case snowmantest.GenesisID: return Genesis, nil case blk0.ID(): return blk0, nil @@ -492,7 +491,7 @@ func TestEngineBlockedIssue(t *testing.T) { sender.SendGetF = func(context.Context, ids.NodeID, uint32, ids.ID) {} vm.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { switch blkID { - case GenesisID: + case snowmantest.GenesisID: return Genesis, nil case blk0.ID(): return blk0, nil @@ -528,7 +527,7 @@ func TestEngineRespondsToGetRequest(t *testing.T) { sender.Default(false) vm.GetBlockF = func(_ context.Context, id ids.ID) (snowman.Block, error) { - require.Equal(GenesisID, id) + require.Equal(snowmantest.GenesisID, id) return Genesis, nil } @@ -542,7 +541,7 @@ func TestEngineRespondsToGetRequest(t *testing.T) { require.Equal(GenesisBytes, blk) } - require.NoError(te.Get(context.Background(), vdr, 123, GenesisID)) + require.NoError(te.Get(context.Background(), vdr, 123, snowmantest.GenesisID)) require.True(sentPut) } @@ -565,7 +564,7 @@ func TestEnginePushQuery(t *testing.T) { vm.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { switch blkID { - case GenesisID: + case snowmantest.GenesisID: return Genesis, nil case blk.ID(): return blk, nil @@ -580,9 +579,9 @@ func TestEnginePushQuery(t *testing.T) { *chitted = true require.Equal(vdr, inVdr) require.Equal(uint32(20), requestID) - require.Equal(GenesisID, preferredID) - require.Equal(GenesisID, preferredIDByHeight) - require.Equal(GenesisID, acceptedID) + require.Equal(snowmantest.GenesisID, preferredID) + require.Equal(snowmantest.GenesisID, preferredIDByHeight) + require.Equal(snowmantest.GenesisID, acceptedID) } queried := new(bool) @@ -613,7 +612,7 @@ func TestEngineBuildBlock(t *testing.T) { vm.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { switch blkID { - case GenesisID: + case snowmantest.GenesisID: return Genesis, nil default: return nil, errUnknownBlock @@ -698,10 +697,10 @@ func TestVoteCanceling(t *testing.T) { vm.CantSetPreference = false vm.LastAcceptedF = func(context.Context) (ids.ID, error) { - return GenesisID, nil + return snowmantest.GenesisID, nil } vm.GetBlockF = func(_ context.Context, id ids.ID) (snowman.Block, error) { - require.Equal(GenesisID, id) + require.Equal(snowmantest.GenesisID, id) return Genesis, nil } @@ -762,11 +761,11 @@ func TestEngineNoQuery(t *testing.T) { vm := &block.TestVM{} vm.T = t vm.LastAcceptedF = func(context.Context) (ids.ID, error) { - return GenesisID, nil + return snowmantest.GenesisID, nil } vm.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { - if blkID == GenesisID { + if blkID == snowmantest.GenesisID { return Genesis, nil } return nil, errUnknownBlock @@ -803,11 +802,11 @@ func TestEngineNoRepollQuery(t *testing.T) { vm := &block.TestVM{} vm.T = t vm.LastAcceptedF = func(context.Context) (ids.ID, error) { - return GenesisID, nil + return snowmantest.GenesisID, nil } vm.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { - if blkID == GenesisID { + if blkID == snowmantest.GenesisID { return Genesis, nil } return nil, errUnknownBlock @@ -865,7 +864,7 @@ func TestEngineAbandonChit(t *testing.T) { vm.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { switch blkID { - case GenesisID: + case snowmantest.GenesisID: return Genesis, nil case blk.ID(): return nil, errUnknownBlock @@ -919,7 +918,7 @@ func TestEngineAbandonChitWithUnexpectedPutBlock(t *testing.T) { vm.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { switch blkID { - case GenesisID: + case snowmantest.GenesisID: return Genesis, nil case blk.ID(): return nil, errUnknownBlock @@ -982,7 +981,7 @@ func TestEngineBlockingChitRequest(t *testing.T) { vm.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { switch blkID { - case GenesisID: + case snowmantest.GenesisID: return Genesis, nil case blockingBlk.ID(): return blockingBlk, nil @@ -1043,7 +1042,7 @@ func TestEngineBlockingChitResponse(t *testing.T) { vm.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { switch blkID { - case GenesisID: + case snowmantest.GenesisID: return Genesis, nil case issuedBlk.ID(): return issuedBlk, nil @@ -1138,7 +1137,7 @@ func TestEngineBlockingChitResponse(t *testing.T) { vm.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { switch blkID { - case GenesisID: + case snowmantest.GenesisID: return Genesis, nil case issuedBlk.ID(): return issuedBlk, nil @@ -1226,7 +1225,7 @@ func TestEngineUndeclaredDependencyDeadlock(t *testing.T) { vm.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { switch blkID { - case GenesisID: + case snowmantest.GenesisID: return Genesis, nil case validBlk.ID(): return validBlk, nil @@ -1262,10 +1261,10 @@ func TestEngineGossip(t *testing.T) { nodeID, _, sender, vm, te := setup(t, DefaultConfig(t)) vm.LastAcceptedF = func(context.Context) (ids.ID, error) { - return GenesisID, nil + return snowmantest.GenesisID, nil } vm.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { - require.Equal(GenesisID, blkID) + require.Equal(snowmantest.GenesisID, blkID) return Genesis, nil } @@ -1305,7 +1304,7 @@ func TestEngineInvalidBlockIgnoredFromUnexpectedPeer(t *testing.T) { vm.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { switch blkID { - case GenesisID: + case snowmantest.GenesisID: return Genesis, nil case pendingBlk.ID(): if !*parsed { @@ -1339,7 +1338,7 @@ func TestEngineInvalidBlockIgnoredFromUnexpectedPeer(t *testing.T) { } vm.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { switch blkID { - case GenesisID: + case snowmantest.GenesisID: return Genesis, nil case missingBlk.ID(): if !*parsed { @@ -1379,7 +1378,7 @@ func TestEnginePushQueryRequestIDConflict(t *testing.T) { vm.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { switch blkID { - case GenesisID: + case snowmantest.GenesisID: return Genesis, nil case pendingBlk.ID(): if !*parsed { @@ -1416,7 +1415,7 @@ func TestEnginePushQueryRequestIDConflict(t *testing.T) { } vm.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { switch blkID { - case GenesisID: + case snowmantest.GenesisID: return Genesis, nil case missingBlk.ID(): if !*parsed { @@ -1460,10 +1459,10 @@ func TestEngineAggressivePolling(t *testing.T) { vm.CantSetPreference = false vm.LastAcceptedF = func(context.Context) (ids.ID, error) { - return GenesisID, nil + return snowmantest.GenesisID, nil } vm.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { - require.Equal(GenesisID, blkID) + require.Equal(snowmantest.GenesisID, blkID) return Genesis, nil } @@ -1489,7 +1488,7 @@ func TestEngineAggressivePolling(t *testing.T) { vm.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { switch blkID { - case GenesisID: + case snowmantest.GenesisID: return Genesis, nil case pendingBlk.ID(): if !*parsed { @@ -1549,10 +1548,10 @@ func TestEngineDoubleChit(t *testing.T) { vm.CantSetPreference = false vm.LastAcceptedF = func(context.Context) (ids.ID, error) { - return GenesisID, nil + return snowmantest.GenesisID, nil } vm.GetBlockF = func(_ context.Context, id ids.ID) (snowman.Block, error) { - require.Equal(GenesisID, id) + require.Equal(snowmantest.GenesisID, id) return Genesis, nil } @@ -1587,7 +1586,7 @@ func TestEngineDoubleChit(t *testing.T) { vm.GetBlockF = func(_ context.Context, id ids.ID) (snowman.Block, error) { switch id { - case GenesisID: + case snowmantest.GenesisID: return Genesis, nil case blk.ID(): return blk, nil @@ -1636,10 +1635,10 @@ func TestEngineBuildBlockLimit(t *testing.T) { vm.CantSetPreference = false vm.LastAcceptedF = func(context.Context) (ids.ID, error) { - return GenesisID, nil + return snowmantest.GenesisID, nil } vm.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { - require.Equal(GenesisID, blkID) + require.Equal(snowmantest.GenesisID, blkID) return Genesis, nil } @@ -1668,7 +1667,7 @@ func TestEngineBuildBlockLimit(t *testing.T) { vm.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { switch blkID { - case GenesisID: + case snowmantest.GenesisID: return Genesis, nil default: return nil, errUnknownBlock @@ -1693,7 +1692,7 @@ func TestEngineBuildBlockLimit(t *testing.T) { vm.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { switch blkID { - case GenesisID: + case snowmantest.GenesisID: return Genesis, nil case blk0.ID(): return blk0, nil @@ -1735,7 +1734,7 @@ func TestEngineReceiveNewRejectedBlock(t *testing.T) { vm.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { switch blkID { - case GenesisID: + case snowmantest.GenesisID: return Genesis, nil case acceptedBlk.ID(): return acceptedBlk, nil @@ -1806,7 +1805,7 @@ func TestEngineRejectionAmplification(t *testing.T) { vm.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { switch blkID { - case GenesisID: + case snowmantest.GenesisID: return Genesis, nil case acceptedBlk.ID(): return acceptedBlk, nil @@ -1830,7 +1829,7 @@ func TestEngineRejectionAmplification(t *testing.T) { vm.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { switch blkID { - case GenesisID: + case snowmantest.GenesisID: return Genesis, nil case acceptedBlk.ID(): return acceptedBlk, nil @@ -1896,7 +1895,7 @@ func TestEngineTransitiveRejectionAmplificationDueToRejectedParent(t *testing.T) vm.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { switch blkID { - case GenesisID: + case snowmantest.GenesisID: return Genesis, nil case acceptedBlk.ID(): return acceptedBlk, nil @@ -1963,7 +1962,7 @@ func TestEngineTransitiveRejectionAmplificationDueToInvalidParent(t *testing.T) vm.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { switch blkID { - case GenesisID: + case snowmantest.GenesisID: return Genesis, nil default: return nil, errUnknownBlock @@ -1984,7 +1983,7 @@ func TestEngineTransitiveRejectionAmplificationDueToInvalidParent(t *testing.T) vm.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { switch blkID { - case GenesisID: + case snowmantest.GenesisID: return Genesis, nil case rejectedBlk.ID(): return rejectedBlk, nil @@ -2028,7 +2027,7 @@ func TestEngineNonPreferredAmplification(t *testing.T) { vm.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { switch blkID { - case GenesisID: + case snowmantest.GenesisID: return Genesis, nil default: return nil, errUnknownBlock @@ -2091,7 +2090,7 @@ func TestEngineBubbleVotesThroughInvalidBlock(t *testing.T) { // in the following tests vm.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { switch blkID { - case GenesisID: + case snowmantest.GenesisID: return Genesis, nil default: return nil, errUnknownBlock @@ -2140,7 +2139,7 @@ func TestEngineBubbleVotesThroughInvalidBlock(t *testing.T) { // now [blk1] is verified, vm can return it vm.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { switch blkID { - case GenesisID: + case snowmantest.GenesisID: return Genesis, nil case blk1.ID(): return blk1, nil @@ -2176,7 +2175,7 @@ func TestEngineBubbleVotesThroughInvalidBlock(t *testing.T) { blk2.VerifyV = nil vm.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { switch blkID { - case GenesisID: + case snowmantest.GenesisID: return Genesis, nil case blk1.ID(): return blk1, nil @@ -2252,7 +2251,7 @@ func TestEngineBubbleVotesThroughInvalidChain(t *testing.T) { // The VM should be able to retrieve [Genesis] and [blk1] from storage vm.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { switch blkID { - case GenesisID: + case snowmantest.GenesisID: return Genesis, nil case blk1.ID(): return blk1, nil @@ -2367,7 +2366,7 @@ func TestEngineBuildBlockWithCachedNonVerifiedParent(t *testing.T) { vm.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { switch blkID { - case GenesisID: + case snowmantest.GenesisID: return Genesis, nil case grandParentBlk.IDV: return grandParentBlk, nil @@ -2403,7 +2402,7 @@ func TestEngineBuildBlockWithCachedNonVerifiedParent(t *testing.T) { vm.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { switch blkID { - case GenesisID: + case snowmantest.GenesisID: return Genesis, nil case grandParentBlk.IDV: return grandParentBlk, nil @@ -2487,10 +2486,10 @@ func TestEngineApplyAcceptedFrontierInQueryFailed(t *testing.T) { vm.CantSetPreference = false vm.LastAcceptedF = func(context.Context) (ids.ID, error) { - return GenesisID, nil + return snowmantest.GenesisID, nil } vm.GetBlockF = func(_ context.Context, id ids.ID) (snowman.Block, error) { - require.Equal(GenesisID, id) + require.Equal(snowmantest.GenesisID, id) return Genesis, nil } @@ -2521,7 +2520,7 @@ func TestEngineApplyAcceptedFrontierInQueryFailed(t *testing.T) { vm.GetBlockF = func(_ context.Context, id ids.ID) (snowman.Block, error) { switch id { - case GenesisID: + case snowmantest.GenesisID: return Genesis, nil case blk.ID(): return blk, nil @@ -2582,10 +2581,10 @@ func TestEngineRepollsMisconfiguredSubnet(t *testing.T) { vm.CantSetPreference = false vm.LastAcceptedF = func(context.Context) (ids.ID, error) { - return GenesisID, nil + return snowmantest.GenesisID, nil } vm.GetBlockF = func(_ context.Context, id ids.ID) (snowman.Block, error) { - require.Equal(GenesisID, id) + require.Equal(snowmantest.GenesisID, id) return Genesis, nil } @@ -2634,7 +2633,7 @@ func TestEngineRepollsMisconfiguredSubnet(t *testing.T) { vm.GetBlockF = func(_ context.Context, id ids.ID) (snowman.Block, error) { switch id { - case GenesisID: + case snowmantest.GenesisID: return Genesis, nil case blk.ID(): return blk, nil @@ -2934,7 +2933,7 @@ func TestGetProcessingAncestor(t *testing.T) { require.NoError(t, c.Initialize( ctx, snowball.DefaultParameters, - GenesisID, + snowmantest.GenesisID, 0, time.Now(), )) @@ -2973,7 +2972,7 @@ func TestGetProcessingAncestor(t *testing.T) { pending: map[ids.ID]snowman.Block{}, nonVerifiedCache: &cache.Empty[ids.ID, snowman.Block]{}, }, - initialVote: GenesisID, + initialVote: snowmantest.GenesisID, expectedAncestor: ids.Empty, expectedFound: false, }, From 92935cbd8db5a5d77835b440ff1cf77a94c51029 Mon Sep 17 00:00:00 2001 From: Stephen Buttolph Date: Fri, 26 Apr 2024 16:42:24 -0400 Subject: [PATCH 07/24] Remove old genesis bytes --- snow/engine/snowman/transitive_test.go | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/snow/engine/snowman/transitive_test.go b/snow/engine/snowman/transitive_test.go index d8443c7e05ad..da592fbc8bf9 100644 --- a/snow/engine/snowman/transitive_test.go +++ b/snow/engine/snowman/transitive_test.go @@ -27,7 +27,6 @@ import ( "github.com/ava-labs/avalanchego/snow/engine/snowman/getter" "github.com/ava-labs/avalanchego/snow/snowtest" "github.com/ava-labs/avalanchego/snow/validators" - "github.com/ava-labs/avalanchego/utils" "github.com/ava-labs/avalanchego/utils/set" "github.com/ava-labs/avalanchego/version" ) @@ -39,13 +38,12 @@ var ( errUnexpectedCall = errors.New("unexpected call") errTest = errors.New("non-nil test") - GenesisBytes = utils.RandomBytes(32) - Genesis = &snowmantest.Block{ + Genesis = &snowmantest.Block{ TestDecidable: choices.TestDecidable{ IDV: snowmantest.GenesisID, StatusV: choices.Accepted, }, - BytesV: GenesisBytes, + BytesV: snowmantest.GenesisBytes, } ) @@ -538,7 +536,7 @@ func TestEngineRespondsToGetRequest(t *testing.T) { require.Equal(vdr, nodeID) require.Equal(uint32(123), requestID) - require.Equal(GenesisBytes, blk) + require.Equal(snowmantest.GenesisBytes, blk) } require.NoError(te.Get(context.Background(), vdr, 123, snowmantest.GenesisID)) @@ -957,13 +955,13 @@ func TestEngineAbandonChitWithUnexpectedPutBlock(t *testing.T) { sender.CantSendPullQuery = false vm.ParseBlockF = func(_ context.Context, b []byte) (snowman.Block, error) { - require.Equal(GenesisBytes, b) + require.Equal(snowmantest.GenesisBytes, b) return Genesis, nil } // Respond with an unexpected block and verify that the request is correctly // cleared. - require.NoError(te.Put(context.Background(), vdr, reqID, GenesisBytes)) + require.NoError(te.Put(context.Background(), vdr, reqID, snowmantest.GenesisBytes)) require.Empty(te.blocked) } @@ -1054,7 +1052,7 @@ func TestEngineBlockingChitResponse(t *testing.T) { } vm.ParseBlockF = func(_ context.Context, blkBytes []byte) (snowman.Block, error) { switch { - case bytes.Equal(GenesisBytes, blkBytes): + case bytes.Equal(snowmantest.GenesisBytes, blkBytes): return Genesis, nil case bytes.Equal(issuedBlk.Bytes(), blkBytes): return issuedBlk, nil From 15b00301839f0b3fcea6711d19b5b65d07d913c1 Mon Sep 17 00:00:00 2001 From: Stephen Buttolph Date: Fri, 26 Apr 2024 16:47:17 -0400 Subject: [PATCH 08/24] Remove old genesis --- snow/engine/snowman/transitive_test.go | 202 ++++++++++++------------- 1 file changed, 97 insertions(+), 105 deletions(-) diff --git a/snow/engine/snowman/transitive_test.go b/snow/engine/snowman/transitive_test.go index da592fbc8bf9..2746765b76c0 100644 --- a/snow/engine/snowman/transitive_test.go +++ b/snow/engine/snowman/transitive_test.go @@ -37,14 +37,6 @@ var ( errInvalid = errors.New("invalid") errUnexpectedCall = errors.New("unexpected call") errTest = errors.New("non-nil test") - - Genesis = &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: snowmantest.GenesisID, - StatusV: choices.Accepted, - }, - BytesV: snowmantest.GenesisBytes, - } ) func MakeGetBlockF(blks ...[]*snowmantest.Block) func(context.Context, ids.ID) (snowman.Block, error) { @@ -127,7 +119,7 @@ func setup(t *testing.T, config Config) (ids.NodeID, validators.Manager, *common vm.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { switch blkID { case snowmantest.GenesisID: - return Genesis, nil + return snowmantest.Genesis, nil default: return nil, errUnknownBlock } @@ -148,7 +140,7 @@ func TestEngineDropsAttemptToIssueBlockAfterFailedRequest(t *testing.T) { peerID, _, sender, vm, engine := setup(t, DefaultConfig(t)) - blks := snowmantest.BuildChain(Genesis, 2) + blks := snowmantest.BuildChain(snowmantest.Genesis, 2) parent := blks[0] child := blks[1] @@ -168,7 +160,7 @@ func TestEngineDropsAttemptToIssueBlockAfterFailedRequest(t *testing.T) { vm.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { switch blkID { case snowmantest.GenesisID: - return Genesis, nil + return snowmantest.Genesis, nil default: return nil, errUnknownBlock } @@ -196,7 +188,7 @@ func TestEngineQuery(t *testing.T) { peerID, _, sender, vm, engine := setup(t, DefaultConfig(t)) - blks := snowmantest.BuildChain(Genesis, 2) + blks := snowmantest.BuildChain(snowmantest.Genesis, 2) parent := blks[0] child := blks[1] @@ -216,7 +208,7 @@ func TestEngineQuery(t *testing.T) { switch blkID { case snowmantest.GenesisID: - return Genesis, nil + return snowmantest.Genesis, nil default: return nil, errUnknownBlock } @@ -371,7 +363,7 @@ func TestEngineMultipleQuery(t *testing.T) { } vm.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { require.Equal(snowmantest.GenesisID, blkID) - return Genesis, nil + return snowmantest.Genesis, nil } te, err := New(engCfg) @@ -382,7 +374,7 @@ func TestEngineMultipleQuery(t *testing.T) { vm.GetBlockF = nil vm.LastAcceptedF = nil - blks := snowmantest.BuildChain(Genesis, 2) + blks := snowmantest.BuildChain(snowmantest.Genesis, 2) blk0 := blks[0] blk1 := blks[1] @@ -401,7 +393,7 @@ func TestEngineMultipleQuery(t *testing.T) { vm.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { switch blkID { case snowmantest.GenesisID: - return Genesis, nil + return snowmantest.Genesis, nil default: return nil, errUnknownBlock } @@ -418,7 +410,7 @@ func TestEngineMultipleQuery(t *testing.T) { vm.GetBlockF = func(_ context.Context, id ids.ID) (snowman.Block, error) { switch id { case snowmantest.GenesisID: - return Genesis, nil + return snowmantest.Genesis, nil case blk0.ID(): return blk0, nil case blk1.ID(): @@ -482,7 +474,7 @@ func TestEngineBlockedIssue(t *testing.T) { sender.Default(false) - blks := snowmantest.BuildChain(Genesis, 2) + blks := snowmantest.BuildChain(snowmantest.Genesis, 2) blk0 := blks[0] blk1 := blks[1] @@ -490,7 +482,7 @@ func TestEngineBlockedIssue(t *testing.T) { vm.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { switch blkID { case snowmantest.GenesisID: - return Genesis, nil + return snowmantest.Genesis, nil case blk0.ID(): return blk0, nil default: @@ -526,7 +518,7 @@ func TestEngineRespondsToGetRequest(t *testing.T) { vm.GetBlockF = func(_ context.Context, id ids.ID) (snowman.Block, error) { require.Equal(snowmantest.GenesisID, id) - return Genesis, nil + return snowmantest.Genesis, nil } var sentPut bool @@ -550,7 +542,7 @@ func TestEnginePushQuery(t *testing.T) { sender.Default(true) - blks := snowmantest.BuildChain(Genesis, 1) + blks := snowmantest.BuildChain(snowmantest.Genesis, 1) blk := blks[0] vm.ParseBlockF = func(_ context.Context, b []byte) (snowman.Block, error) { @@ -563,7 +555,7 @@ func TestEnginePushQuery(t *testing.T) { vm.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { switch blkID { case snowmantest.GenesisID: - return Genesis, nil + return snowmantest.Genesis, nil case blk.ID(): return blk, nil default: @@ -605,13 +597,13 @@ func TestEngineBuildBlock(t *testing.T) { sender.Default(true) - blks := snowmantest.BuildChain(Genesis, 1) + blks := snowmantest.BuildChain(snowmantest.Genesis, 1) blk := blks[0] vm.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { switch blkID { case snowmantest.GenesisID: - return Genesis, nil + return snowmantest.Genesis, nil default: return nil, errUnknownBlock } @@ -699,7 +691,7 @@ func TestVoteCanceling(t *testing.T) { } vm.GetBlockF = func(_ context.Context, id ids.ID) (snowman.Block, error) { require.Equal(snowmantest.GenesisID, id) - return Genesis, nil + return snowmantest.Genesis, nil } te, err := New(engCfg) @@ -709,7 +701,7 @@ func TestVoteCanceling(t *testing.T) { vm.LastAcceptedF = nil - blks := snowmantest.BuildChain(Genesis, 1) + blks := snowmantest.BuildChain(snowmantest.Genesis, 1) blk := blks[0] queried := new(bool) @@ -764,7 +756,7 @@ func TestEngineNoQuery(t *testing.T) { vm.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { if blkID == snowmantest.GenesisID { - return Genesis, nil + return snowmantest.Genesis, nil } return nil, errUnknownBlock } @@ -776,7 +768,7 @@ func TestEngineNoQuery(t *testing.T) { require.NoError(te.Start(context.Background(), 0)) - blks := snowmantest.BuildChain(Genesis, 1) + blks := snowmantest.BuildChain(snowmantest.Genesis, 1) blk := blks[0] require.NoError(te.issue( @@ -805,7 +797,7 @@ func TestEngineNoRepollQuery(t *testing.T) { vm.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { if blkID == snowmantest.GenesisID { - return Genesis, nil + return snowmantest.Genesis, nil } return nil, errUnknownBlock } @@ -857,13 +849,13 @@ func TestEngineAbandonChit(t *testing.T) { sender.Default(true) - blks := snowmantest.BuildChain(Genesis, 1) + blks := snowmantest.BuildChain(snowmantest.Genesis, 1) blk := blks[0] vm.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { switch blkID { case snowmantest.GenesisID: - return Genesis, nil + return snowmantest.Genesis, nil case blk.ID(): return nil, errUnknownBlock } @@ -911,13 +903,13 @@ func TestEngineAbandonChitWithUnexpectedPutBlock(t *testing.T) { sender.Default(true) - blks := snowmantest.BuildChain(Genesis, 1) + blks := snowmantest.BuildChain(snowmantest.Genesis, 1) blk := blks[0] vm.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { switch blkID { case snowmantest.GenesisID: - return Genesis, nil + return snowmantest.Genesis, nil case blk.ID(): return nil, errUnknownBlock } @@ -956,7 +948,7 @@ func TestEngineAbandonChitWithUnexpectedPutBlock(t *testing.T) { vm.ParseBlockF = func(_ context.Context, b []byte) (snowman.Block, error) { require.Equal(snowmantest.GenesisBytes, b) - return Genesis, nil + return snowmantest.Genesis, nil } // Respond with an unexpected block and verify that the request is correctly @@ -972,7 +964,7 @@ func TestEngineBlockingChitRequest(t *testing.T) { sender.Default(true) - blks := snowmantest.BuildChain(Genesis, 3) + blks := snowmantest.BuildChain(snowmantest.Genesis, 3) missingBlk := blks[0] parentBlk := blks[1] blockingBlk := blks[2] @@ -980,7 +972,7 @@ func TestEngineBlockingChitRequest(t *testing.T) { vm.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { switch blkID { case snowmantest.GenesisID: - return Genesis, nil + return snowmantest.Genesis, nil case blockingBlk.ID(): return blockingBlk, nil default: @@ -1031,17 +1023,17 @@ func TestEngineBlockingChitResponse(t *testing.T) { sender.Default(true) - issuedBlks := snowmantest.BuildChain(Genesis, 1) + issuedBlks := snowmantest.BuildChain(snowmantest.Genesis, 1) issuedBlk := issuedBlks[0] - blockingBlks := snowmantest.BuildChain(Genesis, 2) + blockingBlks := snowmantest.BuildChain(snowmantest.Genesis, 2) missingBlk := blockingBlks[0] blockingBlk := blockingBlks[1] vm.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { switch blkID { case snowmantest.GenesisID: - return Genesis, nil + return snowmantest.Genesis, nil case issuedBlk.ID(): return issuedBlk, nil case blockingBlk.ID(): @@ -1053,7 +1045,7 @@ func TestEngineBlockingChitResponse(t *testing.T) { vm.ParseBlockF = func(_ context.Context, blkBytes []byte) (snowman.Block, error) { switch { case bytes.Equal(snowmantest.GenesisBytes, blkBytes): - return Genesis, nil + return snowmantest.Genesis, nil case bytes.Equal(issuedBlk.Bytes(), blkBytes): return issuedBlk, nil case bytes.Equal(missingBlk.Bytes(), blkBytes): @@ -1136,7 +1128,7 @@ func TestEngineBlockingChitResponse(t *testing.T) { vm.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { switch blkID { case snowmantest.GenesisID: - return Genesis, nil + return snowmantest.Genesis, nil case issuedBlk.ID(): return issuedBlk, nil case missingBlk.ID(): @@ -1168,7 +1160,7 @@ func TestEngineRetryFetch(t *testing.T) { sender.Default(true) - blks := snowmantest.BuildChain(Genesis, 1) + blks := snowmantest.BuildChain(snowmantest.Genesis, 1) missingBlk := blks[0] vm.CantGetBlock = false @@ -1208,7 +1200,7 @@ func TestEngineUndeclaredDependencyDeadlock(t *testing.T) { sender.Default(true) - blks := snowmantest.BuildChain(Genesis, 2) + blks := snowmantest.BuildChain(snowmantest.Genesis, 2) validBlk := blks[0] invalidBlk := blks[1] @@ -1224,7 +1216,7 @@ func TestEngineUndeclaredDependencyDeadlock(t *testing.T) { vm.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { switch blkID { case snowmantest.GenesisID: - return Genesis, nil + return snowmantest.Genesis, nil case validBlk.ID(): return validBlk, nil case invalidBlk.ID(): @@ -1263,7 +1255,7 @@ func TestEngineGossip(t *testing.T) { } vm.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { require.Equal(snowmantest.GenesisID, blkID) - return Genesis, nil + return snowmantest.Genesis, nil } var calledSendPullQuery bool @@ -1287,7 +1279,7 @@ func TestEngineInvalidBlockIgnoredFromUnexpectedPeer(t *testing.T) { sender.Default(true) - blks := snowmantest.BuildChain(Genesis, 2) + blks := snowmantest.BuildChain(snowmantest.Genesis, 2) missingBlk := blks[0] pendingBlk := blks[1] @@ -1303,7 +1295,7 @@ func TestEngineInvalidBlockIgnoredFromUnexpectedPeer(t *testing.T) { vm.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { switch blkID { case snowmantest.GenesisID: - return Genesis, nil + return snowmantest.Genesis, nil case pendingBlk.ID(): if !*parsed { return nil, errUnknownBlock @@ -1337,7 +1329,7 @@ func TestEngineInvalidBlockIgnoredFromUnexpectedPeer(t *testing.T) { vm.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { switch blkID { case snowmantest.GenesisID: - return Genesis, nil + return snowmantest.Genesis, nil case missingBlk.ID(): if !*parsed { return nil, errUnknownBlock @@ -1361,7 +1353,7 @@ func TestEnginePushQueryRequestIDConflict(t *testing.T) { sender.Default(true) - blks := snowmantest.BuildChain(Genesis, 2) + blks := snowmantest.BuildChain(snowmantest.Genesis, 2) missingBlk := blks[0] pendingBlk := blks[1] @@ -1377,7 +1369,7 @@ func TestEnginePushQueryRequestIDConflict(t *testing.T) { vm.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { switch blkID { case snowmantest.GenesisID: - return Genesis, nil + return snowmantest.Genesis, nil case pendingBlk.ID(): if !*parsed { return nil, errUnknownBlock @@ -1414,7 +1406,7 @@ func TestEnginePushQueryRequestIDConflict(t *testing.T) { vm.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { switch blkID { case snowmantest.GenesisID: - return Genesis, nil + return snowmantest.Genesis, nil case missingBlk.ID(): if !*parsed { return nil, errUnknownBlock @@ -1461,7 +1453,7 @@ func TestEngineAggressivePolling(t *testing.T) { } vm.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { require.Equal(snowmantest.GenesisID, blkID) - return Genesis, nil + return snowmantest.Genesis, nil } te, err := New(engCfg) @@ -1472,7 +1464,7 @@ func TestEngineAggressivePolling(t *testing.T) { vm.GetBlockF = nil vm.LastAcceptedF = nil - blks := snowmantest.BuildChain(Genesis, 1) + blks := snowmantest.BuildChain(snowmantest.Genesis, 1) pendingBlk := blks[0] parsed := new(bool) @@ -1487,7 +1479,7 @@ func TestEngineAggressivePolling(t *testing.T) { vm.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { switch blkID { case snowmantest.GenesisID: - return Genesis, nil + return snowmantest.Genesis, nil case pendingBlk.ID(): if !*parsed { return nil, errUnknownBlock @@ -1550,7 +1542,7 @@ func TestEngineDoubleChit(t *testing.T) { } vm.GetBlockF = func(_ context.Context, id ids.ID) (snowman.Block, error) { require.Equal(snowmantest.GenesisID, id) - return Genesis, nil + return snowmantest.Genesis, nil } te, err := New(engCfg) @@ -1560,7 +1552,7 @@ func TestEngineDoubleChit(t *testing.T) { vm.LastAcceptedF = nil - blks := snowmantest.BuildChain(Genesis, 1) + blks := snowmantest.BuildChain(snowmantest.Genesis, 1) blk := blks[0] queried := new(bool) @@ -1585,7 +1577,7 @@ func TestEngineDoubleChit(t *testing.T) { vm.GetBlockF = func(_ context.Context, id ids.ID) (snowman.Block, error) { switch id { case snowmantest.GenesisID: - return Genesis, nil + return snowmantest.Genesis, nil case blk.ID(): return blk, nil } @@ -1637,7 +1629,7 @@ func TestEngineBuildBlockLimit(t *testing.T) { } vm.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { require.Equal(snowmantest.GenesisID, blkID) - return Genesis, nil + return snowmantest.Genesis, nil } te, err := New(engCfg) @@ -1648,7 +1640,7 @@ func TestEngineBuildBlockLimit(t *testing.T) { vm.GetBlockF = nil vm.LastAcceptedF = nil - blks := snowmantest.BuildChain(Genesis, 2) + blks := snowmantest.BuildChain(snowmantest.Genesis, 2) blk0 := blks[0] var ( @@ -1666,7 +1658,7 @@ func TestEngineBuildBlockLimit(t *testing.T) { vm.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { switch blkID { case snowmantest.GenesisID: - return Genesis, nil + return snowmantest.Genesis, nil default: return nil, errUnknownBlock } @@ -1691,7 +1683,7 @@ func TestEngineBuildBlockLimit(t *testing.T) { vm.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { switch blkID { case snowmantest.GenesisID: - return Genesis, nil + return snowmantest.Genesis, nil case blk0.ID(): return blk0, nil default: @@ -1709,10 +1701,10 @@ func TestEngineReceiveNewRejectedBlock(t *testing.T) { vdr, _, sender, vm, te := setup(t, DefaultConfig(t)) - acceptedBlks := snowmantest.BuildChain(Genesis, 1) + acceptedBlks := snowmantest.BuildChain(snowmantest.Genesis, 1) acceptedBlk := acceptedBlks[0] - rejectedBlks := snowmantest.BuildChain(Genesis, 2) + rejectedBlks := snowmantest.BuildChain(snowmantest.Genesis, 2) rejectedBlk := rejectedBlks[0] pendingBlk := rejectedBlks[1] @@ -1733,7 +1725,7 @@ func TestEngineReceiveNewRejectedBlock(t *testing.T) { vm.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { switch blkID { case snowmantest.GenesisID: - return Genesis, nil + return snowmantest.Genesis, nil case acceptedBlk.ID(): return acceptedBlk, nil default: @@ -1780,10 +1772,10 @@ func TestEngineRejectionAmplification(t *testing.T) { vdr, _, sender, vm, te := setup(t, DefaultConfig(t)) - acceptedBlks := snowmantest.BuildChain(Genesis, 1) + acceptedBlks := snowmantest.BuildChain(snowmantest.Genesis, 1) acceptedBlk := acceptedBlks[0] - rejectedBlks := snowmantest.BuildChain(Genesis, 2) + rejectedBlks := snowmantest.BuildChain(snowmantest.Genesis, 2) rejectedBlk := rejectedBlks[0] pendingBlk := rejectedBlks[1] @@ -1804,7 +1796,7 @@ func TestEngineRejectionAmplification(t *testing.T) { vm.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { switch blkID { case snowmantest.GenesisID: - return Genesis, nil + return snowmantest.Genesis, nil case acceptedBlk.ID(): return acceptedBlk, nil default: @@ -1828,7 +1820,7 @@ func TestEngineRejectionAmplification(t *testing.T) { vm.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { switch blkID { case snowmantest.GenesisID: - return Genesis, nil + return snowmantest.Genesis, nil case acceptedBlk.ID(): return acceptedBlk, nil default: @@ -1869,10 +1861,10 @@ func TestEngineTransitiveRejectionAmplificationDueToRejectedParent(t *testing.T) vdr, _, sender, vm, te := setup(t, DefaultConfig(t)) - acceptedBlks := snowmantest.BuildChain(Genesis, 1) + acceptedBlks := snowmantest.BuildChain(snowmantest.Genesis, 1) acceptedBlk := acceptedBlks[0] - rejectedBlks := snowmantest.BuildChain(Genesis, 2) + rejectedBlks := snowmantest.BuildChain(snowmantest.Genesis, 2) rejectedBlk := rejectedBlks[0] pendingBlk := rejectedBlks[1] pendingBlk.RejectV = errUnexpectedCall @@ -1894,7 +1886,7 @@ func TestEngineTransitiveRejectionAmplificationDueToRejectedParent(t *testing.T) vm.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { switch blkID { case snowmantest.GenesisID: - return Genesis, nil + return snowmantest.Genesis, nil case acceptedBlk.ID(): return acceptedBlk, nil case rejectedBlk.ID(): @@ -1935,10 +1927,10 @@ func TestEngineTransitiveRejectionAmplificationDueToInvalidParent(t *testing.T) vdr, _, sender, vm, te := setup(t, DefaultConfig(t)) - acceptedBlks := snowmantest.BuildChain(Genesis, 1) + acceptedBlks := snowmantest.BuildChain(snowmantest.Genesis, 1) acceptedBlk := acceptedBlks[0] - rejectedBlks := snowmantest.BuildChain(Genesis, 2) + rejectedBlks := snowmantest.BuildChain(snowmantest.Genesis, 2) rejectedBlk := rejectedBlks[0] rejectedBlk.VerifyV = errUnexpectedCall pendingBlk := rejectedBlks[1] @@ -1961,7 +1953,7 @@ func TestEngineTransitiveRejectionAmplificationDueToInvalidParent(t *testing.T) vm.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { switch blkID { case snowmantest.GenesisID: - return Genesis, nil + return snowmantest.Genesis, nil default: return nil, errUnknownBlock } @@ -1982,7 +1974,7 @@ func TestEngineTransitiveRejectionAmplificationDueToInvalidParent(t *testing.T) vm.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { switch blkID { case snowmantest.GenesisID: - return Genesis, nil + return snowmantest.Genesis, nil case rejectedBlk.ID(): return rejectedBlk, nil case acceptedBlk.ID(): @@ -2005,10 +1997,10 @@ func TestEngineNonPreferredAmplification(t *testing.T) { vdr, _, sender, vm, te := setup(t, DefaultConfig(t)) - preferredBlks := snowmantest.BuildChain(Genesis, 1) + preferredBlks := snowmantest.BuildChain(snowmantest.Genesis, 1) preferredBlk := preferredBlks[0] - nonPreferredBlks := snowmantest.BuildChain(Genesis, 1) + nonPreferredBlks := snowmantest.BuildChain(snowmantest.Genesis, 1) nonPreferredBlk := nonPreferredBlks[0] vm.ParseBlockF = func(_ context.Context, b []byte) (snowman.Block, error) { @@ -2026,7 +2018,7 @@ func TestEngineNonPreferredAmplification(t *testing.T) { vm.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { switch blkID { case snowmantest.GenesisID: - return Genesis, nil + return snowmantest.Genesis, nil default: return nil, errUnknownBlock } @@ -2063,7 +2055,7 @@ func TestEngineBubbleVotesThroughInvalidBlock(t *testing.T) { vdr, _, sender, vm, te := setup(t, DefaultConfig(t)) expectedVdrSet := set.Of(vdr) - blks := snowmantest.BuildChain(Genesis, 2) + blks := snowmantest.BuildChain(snowmantest.Genesis, 2) blk1 := blks[0] // blk2 cannot pass verification until [blk1] has been marked as accepted. @@ -2089,7 +2081,7 @@ func TestEngineBubbleVotesThroughInvalidBlock(t *testing.T) { vm.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { switch blkID { case snowmantest.GenesisID: - return Genesis, nil + return snowmantest.Genesis, nil default: return nil, errUnknownBlock } @@ -2138,7 +2130,7 @@ func TestEngineBubbleVotesThroughInvalidBlock(t *testing.T) { vm.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { switch blkID { case snowmantest.GenesisID: - return Genesis, nil + return snowmantest.Genesis, nil case blk1.ID(): return blk1, nil default: @@ -2174,7 +2166,7 @@ func TestEngineBubbleVotesThroughInvalidBlock(t *testing.T) { vm.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { switch blkID { case snowmantest.GenesisID: - return Genesis, nil + return snowmantest.Genesis, nil case blk1.ID(): return blk1, nil case blk2.ID(): @@ -2222,7 +2214,7 @@ func TestEngineBubbleVotesThroughInvalidChain(t *testing.T) { vdr, _, sender, vm, te := setup(t, DefaultConfig(t)) expectedVdrSet := set.Of(vdr) - blks := snowmantest.BuildChain(Genesis, 3) + blks := snowmantest.BuildChain(snowmantest.Genesis, 3) blk1 := blks[0] // blk2 cannot pass verification until [blk1] has been marked as accepted. @@ -2250,7 +2242,7 @@ func TestEngineBubbleVotesThroughInvalidChain(t *testing.T) { vm.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { switch blkID { case snowmantest.GenesisID: - return Genesis, nil + return snowmantest.Genesis, nil case blk1.ID(): return blk1, nil default: @@ -2336,7 +2328,7 @@ func TestEngineBuildBlockWithCachedNonVerifiedParent(t *testing.T) { sender.Default(true) - blks := snowmantest.BuildChain(Genesis, 3) + blks := snowmantest.BuildChain(snowmantest.Genesis, 3) grandParentBlk := blks[0] parentBlkA := blks[1] @@ -2365,7 +2357,7 @@ func TestEngineBuildBlockWithCachedNonVerifiedParent(t *testing.T) { vm.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { switch blkID { case snowmantest.GenesisID: - return Genesis, nil + return snowmantest.Genesis, nil case grandParentBlk.IDV: return grandParentBlk, nil default: @@ -2401,7 +2393,7 @@ func TestEngineBuildBlockWithCachedNonVerifiedParent(t *testing.T) { vm.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { switch blkID { case snowmantest.GenesisID: - return Genesis, nil + return snowmantest.Genesis, nil case grandParentBlk.IDV: return grandParentBlk, nil case parentBlkB.IDV: @@ -2488,7 +2480,7 @@ func TestEngineApplyAcceptedFrontierInQueryFailed(t *testing.T) { } vm.GetBlockF = func(_ context.Context, id ids.ID) (snowman.Block, error) { require.Equal(snowmantest.GenesisID, id) - return Genesis, nil + return snowmantest.Genesis, nil } te, err := New(engCfg) @@ -2497,7 +2489,7 @@ func TestEngineApplyAcceptedFrontierInQueryFailed(t *testing.T) { vm.LastAcceptedF = nil - blks := snowmantest.BuildChain(Genesis, 1) + blks := snowmantest.BuildChain(snowmantest.Genesis, 1) blk := blks[0] queryRequestID := new(uint32) @@ -2519,7 +2511,7 @@ func TestEngineApplyAcceptedFrontierInQueryFailed(t *testing.T) { vm.GetBlockF = func(_ context.Context, id ids.ID) (snowman.Block, error) { switch id { case snowmantest.GenesisID: - return Genesis, nil + return snowmantest.Genesis, nil case blk.ID(): return blk, nil } @@ -2583,7 +2575,7 @@ func TestEngineRepollsMisconfiguredSubnet(t *testing.T) { } vm.GetBlockF = func(_ context.Context, id ids.ID) (snowman.Block, error) { require.Equal(snowmantest.GenesisID, id) - return Genesis, nil + return snowmantest.Genesis, nil } te, err := New(engCfg) @@ -2592,7 +2584,7 @@ func TestEngineRepollsMisconfiguredSubnet(t *testing.T) { vm.LastAcceptedF = nil - blks := snowmantest.BuildChain(Genesis, 1) + blks := snowmantest.BuildChain(snowmantest.Genesis, 1) blk := blks[0] // Issue the block. This shouldn't call the sender, because creating the @@ -2632,7 +2624,7 @@ func TestEngineRepollsMisconfiguredSubnet(t *testing.T) { vm.GetBlockF = func(_ context.Context, id ids.ID) (snowman.Block, error) { switch id { case snowmantest.GenesisID: - return Genesis, nil + return snowmantest.Genesis, nil case blk.ID(): return blk, nil } @@ -2712,8 +2704,8 @@ func TestEngineVoteStallRegression(t *testing.T) { sender.Default(true) config.Sender = sender - acceptedChain := snowmantest.BuildChain(Genesis, 3) - rejectedChain := snowmantest.BuildChain(Genesis, 2) + acceptedChain := snowmantest.BuildChain(snowmantest.Genesis, 3) + rejectedChain := snowmantest.BuildChain(snowmantest.Genesis, 2) vm := &block.TestVM{ TestVM: common.TestVM{ @@ -2736,19 +2728,19 @@ func TestEngineVoteStallRegression(t *testing.T) { }, }, ParseBlockF: MakeParseBlockF( - []*snowmantest.Block{Genesis}, + []*snowmantest.Block{snowmantest.Genesis}, acceptedChain, rejectedChain, ), GetBlockF: MakeGetBlockF( - []*snowmantest.Block{Genesis}, + []*snowmantest.Block{snowmantest.Genesis}, acceptedChain, ), SetPreferenceF: func(context.Context, ids.ID) error { return nil }, LastAcceptedF: MakeLastAcceptedBlockF( - Genesis, + snowmantest.Genesis, acceptedChain, ), } @@ -2880,7 +2872,7 @@ func TestEngineVoteStallRegression(t *testing.T) { // accepted, block 4 will be dropped. // Then poll 1 should terminate because block 4 was dropped. vm.GetBlockF = MakeGetBlockF( - []*snowmantest.Block{Genesis}, + []*snowmantest.Block{snowmantest.Genesis}, acceptedChain, rejectedChain, ) @@ -2920,7 +2912,7 @@ func TestGetProcessingAncestor(t *testing.T) { ctx = snowtest.ConsensusContext( snowtest.Context(t, snowtest.PChainID), ) - issuedChain = snowmantest.BuildChain(Genesis, 1) + issuedChain = snowmantest.BuildChain(snowmantest.Genesis, 1) unissuedOnIssuedChain = snowmantest.BuildChain(issuedChain[0], 1) ) @@ -2960,7 +2952,7 @@ func TestGetProcessingAncestor(t *testing.T) { T: t, }, GetBlockF: MakeGetBlockF( - []*snowmantest.Block{Genesis}, + []*snowmantest.Block{snowmantest.Genesis}, ), }, Consensus: c, @@ -2984,7 +2976,7 @@ func TestGetProcessingAncestor(t *testing.T) { T: t, }, GetBlockF: MakeGetBlockF( - []*snowmantest.Block{Genesis}, + []*snowmantest.Block{snowmantest.Genesis}, ), }, Consensus: c, @@ -3008,7 +3000,7 @@ func TestGetProcessingAncestor(t *testing.T) { T: t, }, GetBlockF: MakeGetBlockF( - []*snowmantest.Block{Genesis}, + []*snowmantest.Block{snowmantest.Genesis}, ), }, Consensus: c, @@ -3032,7 +3024,7 @@ func TestGetProcessingAncestor(t *testing.T) { T: t, }, GetBlockF: MakeGetBlockF( - []*snowmantest.Block{Genesis}, + []*snowmantest.Block{snowmantest.Genesis}, ), }, Consensus: c, @@ -3056,7 +3048,7 @@ func TestGetProcessingAncestor(t *testing.T) { T: t, }, GetBlockF: MakeGetBlockF( - []*snowmantest.Block{Genesis}, + []*snowmantest.Block{snowmantest.Genesis}, ), }, Consensus: c, From 6769a2d28d2c005f55b56801bfa657a130f51cf5 Mon Sep 17 00:00:00 2001 From: Stephen Buttolph Date: Fri, 26 Apr 2024 17:14:23 -0400 Subject: [PATCH 09/24] cleanup snow package --- snow/consensus/snowman/consensus_test.go | 92 ++++++++-------- snow/consensus/snowman/snowmantest/block.go | 33 +++--- .../snowman/bootstrap/bootstrapper_test.go | 100 ++++-------------- snow/engine/snowman/bootstrap/storage_test.go | 9 +- snow/engine/snowman/getter/getter_test.go | 38 +++---- snow/engine/snowman/transitive_test.go | 78 +++++++------- vms/proposervm/tree/tree_test.go | 12 +-- 7 files changed, 153 insertions(+), 209 deletions(-) diff --git a/snow/consensus/snowman/consensus_test.go b/snow/consensus/snowman/consensus_test.go index 43d24a6d6e9a..d52e76759512 100644 --- a/snow/consensus/snowman/consensus_test.go +++ b/snow/consensus/snowman/consensus_test.go @@ -134,7 +134,7 @@ func NumProcessingTest(t *testing.T, factory Factory) { snowmantest.GenesisTimestamp, )) - block := snowmantest.BuildChildBlock(snowmantest.Genesis) + block := snowmantest.BuildChild(snowmantest.Genesis) require.Zero(sm.NumProcessing()) @@ -173,7 +173,7 @@ func AddToTailTest(t *testing.T, factory Factory) { snowmantest.GenesisTimestamp, )) - block := snowmantest.BuildChildBlock(snowmantest.Genesis) + block := snowmantest.BuildChild(snowmantest.Genesis) // Adding to the previous preference will update the preference require.NoError(sm.Add(context.Background(), block)) @@ -211,8 +211,8 @@ func AddToNonTailTest(t *testing.T, factory Factory) { snowmantest.GenesisTimestamp, )) - firstBlock := snowmantest.BuildChildBlock(snowmantest.Genesis) - secondBlock := snowmantest.BuildChildBlock(snowmantest.Genesis) + firstBlock := snowmantest.BuildChild(snowmantest.Genesis) + secondBlock := snowmantest.BuildChild(snowmantest.Genesis) // Adding to the previous preference will update the preference require.NoError(sm.Add(context.Background(), firstBlock)) @@ -327,7 +327,7 @@ func StatusOrProcessingPreviouslyRejectedTest(t *testing.T, factory Factory) { snowmantest.GenesisTimestamp, )) - block := snowmantest.BuildChildBlock(snowmantest.Genesis) + block := snowmantest.BuildChild(snowmantest.Genesis) require.NoError(block.Reject(context.Background())) require.Equal(choices.Rejected, block.Status()) @@ -364,7 +364,7 @@ func StatusOrProcessingUnissuedTest(t *testing.T, factory Factory) { snowmantest.GenesisTimestamp, )) - block := snowmantest.BuildChildBlock(snowmantest.Genesis) + block := snowmantest.BuildChild(snowmantest.Genesis) require.Equal(choices.Processing, block.Status()) require.False(sm.Processing(block.ID())) @@ -400,7 +400,7 @@ func StatusOrProcessingIssuedTest(t *testing.T, factory Factory) { snowmantest.GenesisTimestamp, )) - block := snowmantest.BuildChildBlock(snowmantest.Genesis) + block := snowmantest.BuildChild(snowmantest.Genesis) require.NoError(sm.Add(context.Background(), block)) require.Equal(choices.Processing, block.Status()) @@ -438,7 +438,7 @@ func RecordPollAcceptSingleBlockTest(t *testing.T, factory Factory) { snowmantest.GenesisTimestamp, )) - block := snowmantest.BuildChildBlock(snowmantest.Genesis) + block := snowmantest.BuildChild(snowmantest.Genesis) require.NoError(sm.Add(context.Background(), block)) @@ -479,8 +479,8 @@ func RecordPollAcceptAndRejectTest(t *testing.T, factory Factory) { snowmantest.GenesisTimestamp, )) - firstBlock := snowmantest.BuildChildBlock(snowmantest.Genesis) - secondBlock := snowmantest.BuildChildBlock(snowmantest.Genesis) + firstBlock := snowmantest.BuildChild(snowmantest.Genesis) + secondBlock := snowmantest.BuildChild(snowmantest.Genesis) require.NoError(sm.Add(context.Background(), firstBlock)) require.NoError(sm.Add(context.Background(), secondBlock)) @@ -527,8 +527,8 @@ func RecordPollSplitVoteNoChangeTest(t *testing.T, factory Factory) { snowmantest.GenesisTimestamp, )) - firstBlock := snowmantest.BuildChildBlock(snowmantest.Genesis) - secondBlock := snowmantest.BuildChildBlock(snowmantest.Genesis) + firstBlock := snowmantest.BuildChild(snowmantest.Genesis) + secondBlock := snowmantest.BuildChild(snowmantest.Genesis) require.NoError(sm.Add(context.Background(), firstBlock)) require.NoError(sm.Add(context.Background(), secondBlock)) @@ -610,9 +610,9 @@ func RecordPollRejectTransitivelyTest(t *testing.T, factory Factory) { snowmantest.GenesisTimestamp, )) - block0 := snowmantest.BuildChildBlock(snowmantest.Genesis) - block1 := snowmantest.BuildChildBlock(snowmantest.Genesis) - block2 := snowmantest.BuildChildBlock(block1) + block0 := snowmantest.BuildChild(snowmantest.Genesis) + block1 := snowmantest.BuildChild(snowmantest.Genesis) + block2 := snowmantest.BuildChild(block1) require.NoError(sm.Add(context.Background(), block0)) require.NoError(sm.Add(context.Background(), block1)) @@ -665,10 +665,10 @@ func RecordPollTransitivelyResetConfidenceTest(t *testing.T, factory Factory) { snowmantest.GenesisTimestamp, )) - block0 := snowmantest.BuildChildBlock(snowmantest.Genesis) - block1 := snowmantest.BuildChildBlock(snowmantest.Genesis) - block2 := snowmantest.BuildChildBlock(block1) - block3 := snowmantest.BuildChildBlock(block1) + block0 := snowmantest.BuildChild(snowmantest.Genesis) + block1 := snowmantest.BuildChild(snowmantest.Genesis) + block2 := snowmantest.BuildChild(block1) + block3 := snowmantest.BuildChild(block1) require.NoError(sm.Add(context.Background(), block0)) require.NoError(sm.Add(context.Background(), block1)) @@ -735,7 +735,7 @@ func RecordPollInvalidVoteTest(t *testing.T, factory Factory) { snowmantest.GenesisTimestamp, )) - block := snowmantest.BuildChildBlock(snowmantest.Genesis) + block := snowmantest.BuildChild(snowmantest.Genesis) unknownBlockID := ids.GenerateTestID() require.NoError(sm.Add(context.Background(), block)) @@ -775,11 +775,11 @@ func RecordPollTransitiveVotingTest(t *testing.T, factory Factory) { snowmantest.GenesisTimestamp, )) - block0 := snowmantest.BuildChildBlock(snowmantest.Genesis) - block1 := snowmantest.BuildChildBlock(block0) - block2 := snowmantest.BuildChildBlock(block1) - block3 := snowmantest.BuildChildBlock(block0) - block4 := snowmantest.BuildChildBlock(block3) + block0 := snowmantest.BuildChild(snowmantest.Genesis) + block1 := snowmantest.BuildChild(block0) + block2 := snowmantest.BuildChild(block1) + block3 := snowmantest.BuildChild(block0) + block4 := snowmantest.BuildChild(block3) require.NoError(sm.Add(context.Background(), block0)) require.NoError(sm.Add(context.Background(), block1)) @@ -880,7 +880,7 @@ func RecordPollDivergedVotingWithNoConflictingBitTest(t *testing.T, factory Fact ParentV: snowmantest.GenesisID, HeightV: snowmantest.GenesisHeight + 1, } - block3 := snowmantest.BuildChildBlock(block2) + block3 := snowmantest.BuildChild(block2) require.NoError(sm.Add(context.Background(), block0)) require.NoError(sm.Add(context.Background(), block1)) @@ -959,10 +959,10 @@ func RecordPollChangePreferredChainTest(t *testing.T, factory Factory) { snowmantest.GenesisTimestamp, )) - a1Block := snowmantest.BuildChildBlock(snowmantest.Genesis) - b1Block := snowmantest.BuildChildBlock(snowmantest.Genesis) - a2Block := snowmantest.BuildChildBlock(a1Block) - b2Block := snowmantest.BuildChildBlock(b1Block) + a1Block := snowmantest.BuildChild(snowmantest.Genesis) + b1Block := snowmantest.BuildChild(snowmantest.Genesis) + a2Block := snowmantest.BuildChild(a1Block) + b2Block := snowmantest.BuildChild(b1Block) require.NoError(sm.Add(context.Background(), a1Block)) require.NoError(sm.Add(context.Background(), a2Block)) @@ -1044,10 +1044,10 @@ func LastAcceptedTest(t *testing.T, factory Factory) { snowmantest.GenesisTimestamp, )) - block0 := snowmantest.BuildChildBlock(snowmantest.Genesis) - block1 := snowmantest.BuildChildBlock(block0) - block2 := snowmantest.BuildChildBlock(block1) - block1Conflict := snowmantest.BuildChildBlock(block0) + block0 := snowmantest.BuildChild(snowmantest.Genesis) + block1 := snowmantest.BuildChild(block0) + block2 := snowmantest.BuildChild(block1) + block1Conflict := snowmantest.BuildChild(block0) lastAcceptedID, lastAcceptedHeight := sm.LastAccepted() require.Equal(snowmantest.GenesisID, lastAcceptedID) @@ -1261,7 +1261,7 @@ func ErrorOnAcceptTest(t *testing.T, factory Factory) { snowmantest.GenesisTimestamp, )) - block := snowmantest.BuildChildBlock(snowmantest.Genesis) + block := snowmantest.BuildChild(snowmantest.Genesis) block.AcceptV = errTest require.NoError(sm.Add(context.Background(), block)) @@ -1297,8 +1297,8 @@ func ErrorOnRejectSiblingTest(t *testing.T, factory Factory) { snowmantest.GenesisTimestamp, )) - block0 := snowmantest.BuildChildBlock(snowmantest.Genesis) - block1 := snowmantest.BuildChildBlock(snowmantest.Genesis) + block0 := snowmantest.BuildChild(snowmantest.Genesis) + block1 := snowmantest.BuildChild(snowmantest.Genesis) block1.RejectV = errTest require.NoError(sm.Add(context.Background(), block0)) @@ -1335,9 +1335,9 @@ func ErrorOnTransitiveRejectionTest(t *testing.T, factory Factory) { snowmantest.GenesisTimestamp, )) - block0 := snowmantest.BuildChildBlock(snowmantest.Genesis) - block1 := snowmantest.BuildChildBlock(snowmantest.Genesis) - block2 := snowmantest.BuildChildBlock(block1) + block0 := snowmantest.BuildChild(snowmantest.Genesis) + block1 := snowmantest.BuildChild(snowmantest.Genesis) + block2 := snowmantest.BuildChild(block1) block2.RejectV = errTest require.NoError(sm.Add(context.Background(), block0)) @@ -1408,7 +1408,7 @@ func ErrorOnAddDecidedBlockTest(t *testing.T, factory Factory) { snowmantest.GenesisTimestamp, )) - block := snowmantest.BuildChildBlock(snowmantest.Genesis) + block := snowmantest.BuildChild(snowmantest.Genesis) require.NoError(block.Accept(context.Background())) err := sm.Add(context.Background(), block) @@ -1455,8 +1455,8 @@ func RecordPollWithDefaultParameters(t *testing.T, factory Factory) { )) // "blk1" and "blk2" are in conflict - blk1 := snowmantest.BuildChildBlock(snowmantest.Genesis) - blk2 := snowmantest.BuildChildBlock(snowmantest.Genesis) + blk1 := snowmantest.BuildChild(snowmantest.Genesis) + blk2 := snowmantest.BuildChild(snowmantest.Genesis) require.NoError(sm.Add(context.Background(), blk1)) require.NoError(sm.Add(context.Background(), blk2)) @@ -1500,9 +1500,9 @@ func RecordPollRegressionCalculateInDegreeIndegreeCalculation(t *testing.T, fact snowmantest.GenesisTimestamp, )) - blk1 := snowmantest.BuildChildBlock(snowmantest.Genesis) - blk2 := snowmantest.BuildChildBlock(blk1) - blk3 := snowmantest.BuildChildBlock(blk2) + blk1 := snowmantest.BuildChild(snowmantest.Genesis) + blk2 := snowmantest.BuildChild(blk1) + blk3 := snowmantest.BuildChild(blk2) require.NoError(sm.Add(context.Background(), blk1)) require.NoError(sm.Add(context.Background(), blk2)) diff --git a/snow/consensus/snowman/snowmantest/block.go b/snow/consensus/snowman/snowmantest/block.go index e81b6bddaca3..badf8f68ad0d 100644 --- a/snow/consensus/snowman/snowmantest/block.go +++ b/snow/consensus/snowman/snowmantest/block.go @@ -21,18 +21,10 @@ var ( GenesisID = ids.GenerateTestID() GenesisTimestamp = time.Unix(1, 0) GenesisBytes = GenesisID[:] - Genesis = &Block{ - TestDecidable: choices.TestDecidable{ - IDV: GenesisID, - StatusV: choices.Accepted, - }, - HeightV: GenesisHeight, - TimestampV: GenesisTimestamp, - BytesV: GenesisBytes, - } + Genesis = BuildChain(1)[0] ) -func BuildChildBlock(parent *Block) *Block { +func BuildChild(parent *Block) *Block { blkID := ids.GenerateTestID() return &Block{ TestDecidable: choices.TestDecidable{ @@ -46,10 +38,27 @@ func BuildChildBlock(parent *Block) *Block { } } -func BuildChain(parent *Block, length int) []*Block { +func BuildChain(length int) []*Block { + if length == 0 { + return nil + } + + genesis := &Block{ + TestDecidable: choices.TestDecidable{ + IDV: GenesisID, + StatusV: choices.Accepted, + }, + HeightV: GenesisHeight, + TimestampV: GenesisTimestamp, + BytesV: GenesisBytes, + } + return append([]*Block{genesis}, BuildDescendants(genesis, length-1)...) +} + +func BuildDescendants(parent *Block, length int) []*Block { chain := make([]*Block, length) for i := range chain { - parent = BuildChildBlock(parent) + parent = BuildChild(parent) chain[i] = parent } return chain diff --git a/snow/engine/snowman/bootstrap/bootstrapper_test.go b/snow/engine/snowman/bootstrap/bootstrapper_test.go index f03ec1d4a913..159fc98fb581 100644 --- a/snow/engine/snowman/bootstrap/bootstrapper_test.go +++ b/snow/engine/snowman/bootstrap/bootstrapper_test.go @@ -6,7 +6,6 @@ package bootstrap import ( "bytes" "context" - "encoding/binary" "errors" "testing" "time" @@ -29,7 +28,6 @@ import ( "github.com/ava-labs/avalanchego/snow/engine/snowman/getter" "github.com/ava-labs/avalanchego/snow/snowtest" "github.com/ava-labs/avalanchego/snow/validators" - "github.com/ava-labs/avalanchego/utils" "github.com/ava-labs/avalanchego/utils/set" "github.com/ava-labs/avalanchego/version" @@ -156,23 +154,13 @@ func TestBootstrapperStartsOnlyIfEnoughStakeIsConnected(t *testing.T) { VM: vm, } - blkID0 := ids.Empty.Prefix(0) - blkBytes0 := []byte{0} - blk0 := &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: blkID0, - StatusV: choices.Accepted, - }, - HeightV: 0, - BytesV: blkBytes0, - } vm.CantLastAccepted = false vm.LastAcceptedF = func(context.Context) (ids.ID, error) { - return blk0.ID(), nil + return snowmantest.GenesisID, nil } vm.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { - require.Equal(blk0.ID(), blkID) - return blk0, nil + require.Equal(snowmantest.GenesisID, blkID) + return snowmantest.Genesis, nil } // create bootstrapper @@ -227,7 +215,7 @@ func TestBootstrapperSingleFrontier(t *testing.T) { config, _, _, vm := newConfig(t) - blks := generateBlockchain(1) + blks := snowmantest.BuildChain(1) initializeVMWithBlockchain(vm, blks) bs, err := New( @@ -255,7 +243,7 @@ func TestBootstrapperUnknownByzantineResponse(t *testing.T) { config, peerID, sender, vm := newConfig(t) - blks := generateBlockchain(2) + blks := snowmantest.BuildChain(2) initializeVMWithBlockchain(vm, blks) bs, err := New( @@ -300,7 +288,7 @@ func TestBootstrapperPartialFetch(t *testing.T) { config, peerID, sender, vm := newConfig(t) - blks := generateBlockchain(4) + blks := snowmantest.BuildChain(4) initializeVMWithBlockchain(vm, blks) bs, err := New( @@ -350,7 +338,7 @@ func TestBootstrapperEmptyResponse(t *testing.T) { config, peerID, sender, vm := newConfig(t) - blks := generateBlockchain(2) + blks := snowmantest.BuildChain(2) initializeVMWithBlockchain(vm, blks) bs, err := New( @@ -398,7 +386,7 @@ func TestBootstrapperAncestors(t *testing.T) { config, peerID, sender, vm := newConfig(t) - blks := generateBlockchain(4) + blks := snowmantest.BuildChain(4) initializeVMWithBlockchain(vm, blks) bs, err := New( @@ -443,7 +431,7 @@ func TestBootstrapperFinalized(t *testing.T) { config, peerID, sender, vm := newConfig(t) - blks := generateBlockchain(3) + blks := snowmantest.BuildChain(3) initializeVMWithBlockchain(vm, blks) bs, err := New( @@ -485,7 +473,7 @@ func TestRestartBootstrapping(t *testing.T) { config, peerID, sender, vm := newConfig(t) - blks := generateBlockchain(5) + blks := snowmantest.BuildChain(5) initializeVMWithBlockchain(vm, blks) bs, err := New( @@ -546,10 +534,10 @@ func TestBootstrapOldBlockAfterStateSync(t *testing.T) { config, peerID, sender, vm := newConfig(t) - blks := generateBlockchain(2) + blks := snowmantest.BuildChain(2) initializeVMWithBlockchain(vm, blks) - blks[0].(*snowmantest.Block).StatusV = choices.Processing + blks[0].StatusV = choices.Processing require.NoError(blks[1].Accept(context.Background())) bs, err := New( @@ -589,7 +577,7 @@ func TestBootstrapContinueAfterHalt(t *testing.T) { config, _, _, vm := newConfig(t) - blks := generateBlockchain(2) + blks := snowmantest.BuildChain(2) initializeVMWithBlockchain(vm, blks) bs, err := New( @@ -657,28 +645,11 @@ func TestBootstrapNoParseOnNew(t *testing.T) { snowGetHandler, err := getter.New(vm, sender, ctx.Log, time.Second, 2000, ctx.Registerer) require.NoError(err) - blk0 := &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.GenerateTestID(), - StatusV: choices.Accepted, - }, - HeightV: 0, - BytesV: utils.RandomBytes(32), - } - - blk1 := &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.GenerateTestID(), - StatusV: choices.Processing, - }, - ParentV: blk0.ID(), - HeightV: 1, - BytesV: utils.RandomBytes(32), - } + blk1 := snowmantest.BuildChild(snowmantest.Genesis) vm.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { - require.Equal(blk0.ID(), blkID) - return blk0, nil + require.Equal(snowmantest.GenesisID, blkID) + return snowmantest.Genesis, nil } intervalDB := memdb.New() @@ -733,7 +704,7 @@ func TestBootstrapperReceiveStaleAncestorsMessage(t *testing.T) { config, peerID, sender, vm := newConfig(t) - blks := generateBlockchain(3) + blks := snowmantest.BuildChain(3) initializeVMWithBlockchain(vm, blks) bs, err := New( @@ -771,36 +742,7 @@ func TestBootstrapperReceiveStaleAncestorsMessage(t *testing.T) { require.Equal(snow.Bootstrapping, config.Ctx.State.Get().State) } -func generateBlockchain(length uint64) []snowman.Block { - if length == 0 { - return nil - } - - blocks := make([]snowman.Block, length) - blocks[0] = &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.GenerateTestID(), - StatusV: choices.Accepted, - }, - ParentV: ids.Empty, - HeightV: 0, - BytesV: binary.AppendUvarint(nil, 0), - } - for height := uint64(1); height < length; height++ { - blocks[height] = &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.GenerateTestID(), - StatusV: choices.Processing, - }, - ParentV: blocks[height-1].ID(), - HeightV: height, - BytesV: binary.AppendUvarint(nil, height), - } - } - return blocks -} - -func initializeVMWithBlockchain(vm *block.TestVM, blocks []snowman.Block) { +func initializeVMWithBlockchain(vm *block.TestVM, blocks []*snowmantest.Block) { vm.CantSetState = false vm.LastAcceptedF = func(context.Context) (ids.ID, error) { var ( @@ -834,13 +776,13 @@ func initializeVMWithBlockchain(vm *block.TestVM, blocks []snowman.Block) { } } -func requireStatusIs(require *require.Assertions, blocks []snowman.Block, status choices.Status) { +func requireStatusIs(require *require.Assertions, blocks []*snowmantest.Block, status choices.Status) { for i, blk := range blocks { require.Equal(status, blk.Status(), i) } } -func blocksToIDs(blocks []snowman.Block) []ids.ID { +func blocksToIDs(blocks []*snowmantest.Block) []ids.ID { blkIDs := make([]ids.ID, len(blocks)) for i, blk := range blocks { blkIDs[i] = blk.ID() @@ -848,7 +790,7 @@ func blocksToIDs(blocks []snowman.Block) []ids.ID { return blkIDs } -func blocksToBytes(blocks []snowman.Block) [][]byte { +func blocksToBytes(blocks []*snowmantest.Block) [][]byte { numBlocks := len(blocks) blkBytes := make([][]byte, numBlocks) for i, blk := range blocks { diff --git a/snow/engine/snowman/bootstrap/storage_test.go b/snow/engine/snowman/bootstrap/storage_test.go index 6ac2761f8cd7..a4373f3bbfdf 100644 --- a/snow/engine/snowman/bootstrap/storage_test.go +++ b/snow/engine/snowman/bootstrap/storage_test.go @@ -15,6 +15,7 @@ import ( "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/snow/choices" "github.com/ava-labs/avalanchego/snow/consensus/snowman" + "github.com/ava-labs/avalanchego/snow/consensus/snowman/snowmantest" "github.com/ava-labs/avalanchego/snow/engine/common" "github.com/ava-labs/avalanchego/snow/engine/snowman/block" "github.com/ava-labs/avalanchego/snow/engine/snowman/bootstrap/interval" @@ -25,7 +26,7 @@ import ( var _ block.Parser = testParser(nil) func TestGetMissingBlockIDs(t *testing.T) { - blocks := generateBlockchain(7) + blocks := snowmantest.BuildChain(7) parser := makeParser(blocks) tests := []struct { @@ -103,7 +104,7 @@ func TestGetMissingBlockIDs(t *testing.T) { } func TestProcess(t *testing.T) { - blocks := generateBlockchain(7) + blocks := snowmantest.BuildChain(7) tests := []struct { name string @@ -259,7 +260,7 @@ func TestExecute(t *testing.T) { tree, err := interval.NewTree(db) require.NoError(err) - blocks := generateBlockchain(numBlocks) + blocks := snowmantest.BuildChain(numBlocks) parser := makeParser(blocks) for _, blk := range blocks { _, err := interval.Add(db, tree, 0, blk.Height(), blk.Bytes()) @@ -299,7 +300,7 @@ func (f testParser) ParseBlock(ctx context.Context, bytes []byte) (snowman.Block return f(ctx, bytes) } -func makeParser(blocks []snowman.Block) block.Parser { +func makeParser(blocks []*snowmantest.Block) block.Parser { return testParser(func(_ context.Context, b []byte) (snowman.Block, error) { for _, block := range blocks { if bytes.Equal(b, block.Bytes()) { diff --git a/snow/engine/snowman/getter/getter_test.go b/snow/engine/snowman/getter/getter_test.go index d7a95048e8a6..cf58841b9581 100644 --- a/snow/engine/snowman/getter/getter_test.go +++ b/snow/engine/snowman/getter/getter_test.go @@ -14,7 +14,6 @@ import ( "go.uber.org/mock/gomock" "github.com/ava-labs/avalanchego/ids" - "github.com/ava-labs/avalanchego/snow/choices" "github.com/ava-labs/avalanchego/snow/consensus/snowman" "github.com/ava-labs/avalanchego/snow/consensus/snowman/snowmantest" "github.com/ava-labs/avalanchego/snow/engine/common" @@ -78,30 +77,23 @@ func TestFilterAccepted(t *testing.T) { require := require.New(t) bs, vm, sender := newTest(t) - blkID0 := ids.GenerateTestID() - blkID1 := ids.GenerateTestID() - blkID2 := ids.GenerateTestID() + acceptedBlk := snowmantest.BuildChild(snowmantest.Genesis) + require.NoError(acceptedBlk.Accept(context.Background())) - blk0 := &snowmantest.Block{TestDecidable: choices.TestDecidable{ - IDV: blkID0, - StatusV: choices.Accepted, - }} - blk1 := &snowmantest.Block{TestDecidable: choices.TestDecidable{ - IDV: blkID1, - StatusV: choices.Accepted, - }} + unknownBlkID := ids.GenerateTestID() vm.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { switch blkID { - case blkID0: - return blk0, nil - case blkID1: - return blk1, nil - case blkID2: + case snowmantest.GenesisID: + return snowmantest.Genesis, nil + case acceptedBlk.ID(): + return acceptedBlk, nil + case unknownBlkID: + return nil, errUnknownBlock + default: + require.FailNow(errUnknownBlock.Error()) return nil, errUnknownBlock } - require.FailNow(errUnknownBlock.Error()) - return nil, errUnknownBlock } var accepted []ids.ID @@ -109,11 +101,11 @@ func TestFilterAccepted(t *testing.T) { accepted = frontier } - blkIDs := set.Of(blkID0, blkID1, blkID2) + blkIDs := set.Of(snowmantest.GenesisID, acceptedBlk.ID(), unknownBlkID) require.NoError(bs.GetAccepted(context.Background(), ids.EmptyNodeID, 0, blkIDs)) require.Len(accepted, 2) - require.Contains(accepted, blkID0) - require.Contains(accepted, blkID1) - require.NotContains(accepted, blkID2) + require.Contains(accepted, snowmantest.GenesisID) + require.Contains(accepted, acceptedBlk.ID()) + require.NotContains(accepted, unknownBlkID) } diff --git a/snow/engine/snowman/transitive_test.go b/snow/engine/snowman/transitive_test.go index 2746765b76c0..da2631bef188 100644 --- a/snow/engine/snowman/transitive_test.go +++ b/snow/engine/snowman/transitive_test.go @@ -140,7 +140,7 @@ func TestEngineDropsAttemptToIssueBlockAfterFailedRequest(t *testing.T) { peerID, _, sender, vm, engine := setup(t, DefaultConfig(t)) - blks := snowmantest.BuildChain(snowmantest.Genesis, 2) + blks := snowmantest.BuildDescendants(snowmantest.Genesis, 2) parent := blks[0] child := blks[1] @@ -188,7 +188,7 @@ func TestEngineQuery(t *testing.T) { peerID, _, sender, vm, engine := setup(t, DefaultConfig(t)) - blks := snowmantest.BuildChain(snowmantest.Genesis, 2) + blks := snowmantest.BuildDescendants(snowmantest.Genesis, 2) parent := blks[0] child := blks[1] @@ -374,7 +374,7 @@ func TestEngineMultipleQuery(t *testing.T) { vm.GetBlockF = nil vm.LastAcceptedF = nil - blks := snowmantest.BuildChain(snowmantest.Genesis, 2) + blks := snowmantest.BuildDescendants(snowmantest.Genesis, 2) blk0 := blks[0] blk1 := blks[1] @@ -474,7 +474,7 @@ func TestEngineBlockedIssue(t *testing.T) { sender.Default(false) - blks := snowmantest.BuildChain(snowmantest.Genesis, 2) + blks := snowmantest.BuildDescendants(snowmantest.Genesis, 2) blk0 := blks[0] blk1 := blks[1] @@ -542,7 +542,7 @@ func TestEnginePushQuery(t *testing.T) { sender.Default(true) - blks := snowmantest.BuildChain(snowmantest.Genesis, 1) + blks := snowmantest.BuildDescendants(snowmantest.Genesis, 1) blk := blks[0] vm.ParseBlockF = func(_ context.Context, b []byte) (snowman.Block, error) { @@ -597,7 +597,7 @@ func TestEngineBuildBlock(t *testing.T) { sender.Default(true) - blks := snowmantest.BuildChain(snowmantest.Genesis, 1) + blks := snowmantest.BuildDescendants(snowmantest.Genesis, 1) blk := blks[0] vm.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { @@ -701,7 +701,7 @@ func TestVoteCanceling(t *testing.T) { vm.LastAcceptedF = nil - blks := snowmantest.BuildChain(snowmantest.Genesis, 1) + blks := snowmantest.BuildDescendants(snowmantest.Genesis, 1) blk := blks[0] queried := new(bool) @@ -768,7 +768,7 @@ func TestEngineNoQuery(t *testing.T) { require.NoError(te.Start(context.Background(), 0)) - blks := snowmantest.BuildChain(snowmantest.Genesis, 1) + blks := snowmantest.BuildDescendants(snowmantest.Genesis, 1) blk := blks[0] require.NoError(te.issue( @@ -849,7 +849,7 @@ func TestEngineAbandonChit(t *testing.T) { sender.Default(true) - blks := snowmantest.BuildChain(snowmantest.Genesis, 1) + blks := snowmantest.BuildDescendants(snowmantest.Genesis, 1) blk := blks[0] vm.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { @@ -903,7 +903,7 @@ func TestEngineAbandonChitWithUnexpectedPutBlock(t *testing.T) { sender.Default(true) - blks := snowmantest.BuildChain(snowmantest.Genesis, 1) + blks := snowmantest.BuildDescendants(snowmantest.Genesis, 1) blk := blks[0] vm.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { @@ -964,7 +964,7 @@ func TestEngineBlockingChitRequest(t *testing.T) { sender.Default(true) - blks := snowmantest.BuildChain(snowmantest.Genesis, 3) + blks := snowmantest.BuildDescendants(snowmantest.Genesis, 3) missingBlk := blks[0] parentBlk := blks[1] blockingBlk := blks[2] @@ -1023,10 +1023,10 @@ func TestEngineBlockingChitResponse(t *testing.T) { sender.Default(true) - issuedBlks := snowmantest.BuildChain(snowmantest.Genesis, 1) + issuedBlks := snowmantest.BuildDescendants(snowmantest.Genesis, 1) issuedBlk := issuedBlks[0] - blockingBlks := snowmantest.BuildChain(snowmantest.Genesis, 2) + blockingBlks := snowmantest.BuildDescendants(snowmantest.Genesis, 2) missingBlk := blockingBlks[0] blockingBlk := blockingBlks[1] @@ -1160,7 +1160,7 @@ func TestEngineRetryFetch(t *testing.T) { sender.Default(true) - blks := snowmantest.BuildChain(snowmantest.Genesis, 1) + blks := snowmantest.BuildDescendants(snowmantest.Genesis, 1) missingBlk := blks[0] vm.CantGetBlock = false @@ -1200,7 +1200,7 @@ func TestEngineUndeclaredDependencyDeadlock(t *testing.T) { sender.Default(true) - blks := snowmantest.BuildChain(snowmantest.Genesis, 2) + blks := snowmantest.BuildDescendants(snowmantest.Genesis, 2) validBlk := blks[0] invalidBlk := blks[1] @@ -1279,7 +1279,7 @@ func TestEngineInvalidBlockIgnoredFromUnexpectedPeer(t *testing.T) { sender.Default(true) - blks := snowmantest.BuildChain(snowmantest.Genesis, 2) + blks := snowmantest.BuildDescendants(snowmantest.Genesis, 2) missingBlk := blks[0] pendingBlk := blks[1] @@ -1353,7 +1353,7 @@ func TestEnginePushQueryRequestIDConflict(t *testing.T) { sender.Default(true) - blks := snowmantest.BuildChain(snowmantest.Genesis, 2) + blks := snowmantest.BuildDescendants(snowmantest.Genesis, 2) missingBlk := blks[0] pendingBlk := blks[1] @@ -1464,7 +1464,7 @@ func TestEngineAggressivePolling(t *testing.T) { vm.GetBlockF = nil vm.LastAcceptedF = nil - blks := snowmantest.BuildChain(snowmantest.Genesis, 1) + blks := snowmantest.BuildDescendants(snowmantest.Genesis, 1) pendingBlk := blks[0] parsed := new(bool) @@ -1552,7 +1552,7 @@ func TestEngineDoubleChit(t *testing.T) { vm.LastAcceptedF = nil - blks := snowmantest.BuildChain(snowmantest.Genesis, 1) + blks := snowmantest.BuildDescendants(snowmantest.Genesis, 1) blk := blks[0] queried := new(bool) @@ -1640,7 +1640,7 @@ func TestEngineBuildBlockLimit(t *testing.T) { vm.GetBlockF = nil vm.LastAcceptedF = nil - blks := snowmantest.BuildChain(snowmantest.Genesis, 2) + blks := snowmantest.BuildDescendants(snowmantest.Genesis, 2) blk0 := blks[0] var ( @@ -1701,10 +1701,10 @@ func TestEngineReceiveNewRejectedBlock(t *testing.T) { vdr, _, sender, vm, te := setup(t, DefaultConfig(t)) - acceptedBlks := snowmantest.BuildChain(snowmantest.Genesis, 1) + acceptedBlks := snowmantest.BuildDescendants(snowmantest.Genesis, 1) acceptedBlk := acceptedBlks[0] - rejectedBlks := snowmantest.BuildChain(snowmantest.Genesis, 2) + rejectedBlks := snowmantest.BuildDescendants(snowmantest.Genesis, 2) rejectedBlk := rejectedBlks[0] pendingBlk := rejectedBlks[1] @@ -1772,10 +1772,10 @@ func TestEngineRejectionAmplification(t *testing.T) { vdr, _, sender, vm, te := setup(t, DefaultConfig(t)) - acceptedBlks := snowmantest.BuildChain(snowmantest.Genesis, 1) + acceptedBlks := snowmantest.BuildDescendants(snowmantest.Genesis, 1) acceptedBlk := acceptedBlks[0] - rejectedBlks := snowmantest.BuildChain(snowmantest.Genesis, 2) + rejectedBlks := snowmantest.BuildDescendants(snowmantest.Genesis, 2) rejectedBlk := rejectedBlks[0] pendingBlk := rejectedBlks[1] @@ -1861,10 +1861,10 @@ func TestEngineTransitiveRejectionAmplificationDueToRejectedParent(t *testing.T) vdr, _, sender, vm, te := setup(t, DefaultConfig(t)) - acceptedBlks := snowmantest.BuildChain(snowmantest.Genesis, 1) + acceptedBlks := snowmantest.BuildDescendants(snowmantest.Genesis, 1) acceptedBlk := acceptedBlks[0] - rejectedBlks := snowmantest.BuildChain(snowmantest.Genesis, 2) + rejectedBlks := snowmantest.BuildDescendants(snowmantest.Genesis, 2) rejectedBlk := rejectedBlks[0] pendingBlk := rejectedBlks[1] pendingBlk.RejectV = errUnexpectedCall @@ -1927,10 +1927,10 @@ func TestEngineTransitiveRejectionAmplificationDueToInvalidParent(t *testing.T) vdr, _, sender, vm, te := setup(t, DefaultConfig(t)) - acceptedBlks := snowmantest.BuildChain(snowmantest.Genesis, 1) + acceptedBlks := snowmantest.BuildDescendants(snowmantest.Genesis, 1) acceptedBlk := acceptedBlks[0] - rejectedBlks := snowmantest.BuildChain(snowmantest.Genesis, 2) + rejectedBlks := snowmantest.BuildDescendants(snowmantest.Genesis, 2) rejectedBlk := rejectedBlks[0] rejectedBlk.VerifyV = errUnexpectedCall pendingBlk := rejectedBlks[1] @@ -1997,10 +1997,10 @@ func TestEngineNonPreferredAmplification(t *testing.T) { vdr, _, sender, vm, te := setup(t, DefaultConfig(t)) - preferredBlks := snowmantest.BuildChain(snowmantest.Genesis, 1) + preferredBlks := snowmantest.BuildDescendants(snowmantest.Genesis, 1) preferredBlk := preferredBlks[0] - nonPreferredBlks := snowmantest.BuildChain(snowmantest.Genesis, 1) + nonPreferredBlks := snowmantest.BuildDescendants(snowmantest.Genesis, 1) nonPreferredBlk := nonPreferredBlks[0] vm.ParseBlockF = func(_ context.Context, b []byte) (snowman.Block, error) { @@ -2055,7 +2055,7 @@ func TestEngineBubbleVotesThroughInvalidBlock(t *testing.T) { vdr, _, sender, vm, te := setup(t, DefaultConfig(t)) expectedVdrSet := set.Of(vdr) - blks := snowmantest.BuildChain(snowmantest.Genesis, 2) + blks := snowmantest.BuildDescendants(snowmantest.Genesis, 2) blk1 := blks[0] // blk2 cannot pass verification until [blk1] has been marked as accepted. @@ -2214,7 +2214,7 @@ func TestEngineBubbleVotesThroughInvalidChain(t *testing.T) { vdr, _, sender, vm, te := setup(t, DefaultConfig(t)) expectedVdrSet := set.Of(vdr) - blks := snowmantest.BuildChain(snowmantest.Genesis, 3) + blks := snowmantest.BuildDescendants(snowmantest.Genesis, 3) blk1 := blks[0] // blk2 cannot pass verification until [blk1] has been marked as accepted. @@ -2328,7 +2328,7 @@ func TestEngineBuildBlockWithCachedNonVerifiedParent(t *testing.T) { sender.Default(true) - blks := snowmantest.BuildChain(snowmantest.Genesis, 3) + blks := snowmantest.BuildDescendants(snowmantest.Genesis, 3) grandParentBlk := blks[0] parentBlkA := blks[1] @@ -2489,7 +2489,7 @@ func TestEngineApplyAcceptedFrontierInQueryFailed(t *testing.T) { vm.LastAcceptedF = nil - blks := snowmantest.BuildChain(snowmantest.Genesis, 1) + blks := snowmantest.BuildDescendants(snowmantest.Genesis, 1) blk := blks[0] queryRequestID := new(uint32) @@ -2584,7 +2584,7 @@ func TestEngineRepollsMisconfiguredSubnet(t *testing.T) { vm.LastAcceptedF = nil - blks := snowmantest.BuildChain(snowmantest.Genesis, 1) + blks := snowmantest.BuildDescendants(snowmantest.Genesis, 1) blk := blks[0] // Issue the block. This shouldn't call the sender, because creating the @@ -2704,8 +2704,8 @@ func TestEngineVoteStallRegression(t *testing.T) { sender.Default(true) config.Sender = sender - acceptedChain := snowmantest.BuildChain(snowmantest.Genesis, 3) - rejectedChain := snowmantest.BuildChain(snowmantest.Genesis, 2) + acceptedChain := snowmantest.BuildDescendants(snowmantest.Genesis, 3) + rejectedChain := snowmantest.BuildDescendants(snowmantest.Genesis, 2) vm := &block.TestVM{ TestVM: common.TestVM{ @@ -2912,8 +2912,8 @@ func TestGetProcessingAncestor(t *testing.T) { ctx = snowtest.ConsensusContext( snowtest.Context(t, snowtest.PChainID), ) - issuedChain = snowmantest.BuildChain(snowmantest.Genesis, 1) - unissuedOnIssuedChain = snowmantest.BuildChain(issuedChain[0], 1) + issuedChain = snowmantest.BuildDescendants(snowmantest.Genesis, 1) + unissuedOnIssuedChain = snowmantest.BuildDescendants(issuedChain[0], 1) ) metrics, err := newMetrics("", prometheus.NewRegistry()) diff --git a/vms/proposervm/tree/tree_test.go b/vms/proposervm/tree/tree_test.go index 7bfdf2c51c88..48095a40f638 100644 --- a/vms/proposervm/tree/tree_test.go +++ b/vms/proposervm/tree/tree_test.go @@ -18,7 +18,7 @@ func TestAcceptSingleBlock(t *testing.T) { tr := New() - block := snowmantest.BuildChildBlock(snowmantest.Genesis) + block := snowmantest.BuildChild(snowmantest.Genesis) _, contains := tr.Get(block) require.False(contains) @@ -39,8 +39,8 @@ func TestAcceptBlockConflict(t *testing.T) { tr := New() - blockToAccept := snowmantest.BuildChildBlock(snowmantest.Genesis) - blockToReject := snowmantest.BuildChildBlock(snowmantest.Genesis) + blockToAccept := snowmantest.BuildChild(snowmantest.Genesis) + blockToReject := snowmantest.BuildChild(snowmantest.Genesis) // add conflicting blocks tr.Add(blockToAccept) @@ -69,9 +69,9 @@ func TestAcceptChainConflict(t *testing.T) { tr := New() - blockToAccept := snowmantest.BuildChildBlock(snowmantest.Genesis) - blockToReject := snowmantest.BuildChildBlock(snowmantest.Genesis) - blockToRejectChild := snowmantest.BuildChildBlock(blockToReject) + blockToAccept := snowmantest.BuildChild(snowmantest.Genesis) + blockToReject := snowmantest.BuildChild(snowmantest.Genesis) + blockToRejectChild := snowmantest.BuildChild(blockToReject) // add conflicting blocks. tr.Add(blockToAccept) From 8b2fd425c439ab29a05a372539355d3d6b238774 Mon Sep 17 00:00:00 2001 From: Stephen Buttolph Date: Fri, 26 Apr 2024 17:21:30 -0400 Subject: [PATCH 10/24] Combine genesis timestamp constant --- snow/consensus/snowman/snowmantest/block.go | 7 +++++-- vms/proposervm/batched_vm_test.go | 2 +- vms/proposervm/pre_fork_block_test.go | 12 ++++++------ vms/proposervm/vm_test.go | 15 ++++++--------- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/snow/consensus/snowman/snowmantest/block.go b/snow/consensus/snowman/snowmantest/block.go index badf8f68ad0d..c103f30d77ed 100644 --- a/snow/consensus/snowman/snowmantest/block.go +++ b/snow/consensus/snowman/snowmantest/block.go @@ -13,13 +13,16 @@ import ( "github.com/ava-labs/avalanchego/utils" ) -const GenesisHeight uint64 = 0 +const ( + GenesisHeight uint64 = 0 + GenesisUnixTimestamp int64 = 1 +) var ( _ utils.Sortable[*Block] = (*Block)(nil) GenesisID = ids.GenerateTestID() - GenesisTimestamp = time.Unix(1, 0) + GenesisTimestamp = time.Unix(GenesisUnixTimestamp, 0) GenesisBytes = GenesisID[:] Genesis = BuildChain(1)[0] ) diff --git a/vms/proposervm/batched_vm_test.go b/vms/proposervm/batched_vm_test.go index f0714b732363..24e1eb753b9b 100644 --- a/vms/proposervm/batched_vm_test.go +++ b/vms/proposervm/batched_vm_test.go @@ -988,7 +988,7 @@ func initTestRemoteProposerVM( StatusV: choices.Accepted, }, HeightV: 0, - TimestampV: genesisTimestamp, + TimestampV: snowmantest.GenesisTimestamp, BytesV: []byte{0}, } diff --git a/vms/proposervm/pre_fork_block_test.go b/vms/proposervm/pre_fork_block_test.go index 9dc8fa2e3c44..5266e9488c0c 100644 --- a/vms/proposervm/pre_fork_block_test.go +++ b/vms/proposervm/pre_fork_block_test.go @@ -144,7 +144,7 @@ func TestOracle_PostForkBlkCanBuiltOnPreForkOption(t *testing.T) { require := require.New(t) var ( - activationTime = genesisTimestamp.Add(10 * time.Second) + activationTime = snowmantest.GenesisTimestamp.Add(10 * time.Second) durangoTime = activationTime ) coreVM, _, proVM, coreGenBlk, _ := initTestProposerVM(t, activationTime, durangoTime, 0) @@ -241,7 +241,7 @@ func TestBlockVerify_PreFork_ParentChecks(t *testing.T) { require := require.New(t) var ( - activationTime = genesisTimestamp.Add(10 * time.Second) + activationTime = snowmantest.GenesisTimestamp.Add(10 * time.Second) durangoTime = activationTime ) coreVM, _, proVM, coreGenBlk, _ := initTestProposerVM(t, activationTime, durangoTime, 0) @@ -320,7 +320,7 @@ func TestBlockVerify_BlocksBuiltOnPreForkGenesis(t *testing.T) { require := require.New(t) var ( - activationTime = genesisTimestamp.Add(10 * time.Second) + activationTime = snowmantest.GenesisTimestamp.Add(10 * time.Second) durangoTime = activationTime ) coreVM, _, proVM, coreGenBlk, _ := initTestProposerVM(t, activationTime, durangoTime, 0) @@ -454,7 +454,7 @@ func TestBlockVerify_BlocksBuiltOnPostForkGenesis(t *testing.T) { require := require.New(t) var ( - activationTime = genesisTimestamp.Add(-1 * time.Second) + activationTime = snowmantest.GenesisTimestamp.Add(-1 * time.Second) durangoTime = activationTime ) coreVM, _, proVM, coreGenBlk, _ := initTestProposerVM(t, activationTime, durangoTime, 0) @@ -596,7 +596,7 @@ func TestBlockVerify_ForkBlockIsOracleBlock(t *testing.T) { require := require.New(t) var ( - activationTime = genesisTimestamp.Add(10 * time.Second) + activationTime = snowmantest.GenesisTimestamp.Add(10 * time.Second) durangoTime = activationTime ) coreVM, _, proVM, coreGenBlk, _ := initTestProposerVM(t, activationTime, durangoTime, 0) @@ -690,7 +690,7 @@ func TestBlockVerify_ForkBlockIsOracleBlockButChildrenAreSigned(t *testing.T) { require := require.New(t) var ( - activationTime = genesisTimestamp.Add(10 * time.Second) + activationTime = snowmantest.GenesisTimestamp.Add(10 * time.Second) durangoTime = activationTime ) coreVM, _, proVM, coreGenBlk, _ := initTestProposerVM(t, activationTime, durangoTime, 0) diff --git a/vms/proposervm/vm_test.go b/vms/proposervm/vm_test.go index 67585fe2a8c8..5177727c56be 100644 --- a/vms/proposervm/vm_test.go +++ b/vms/proposervm/vm_test.go @@ -50,9 +50,6 @@ var ( pTestSigner crypto.Signer pTestCert *staking.Certificate - genesisUnixTimestamp int64 = 1000 - genesisTimestamp = time.Unix(genesisUnixTimestamp, 0) - defaultPChainHeight uint64 = 2000 errUnknownBlock = errors.New("unknown block") @@ -94,7 +91,7 @@ func initTestProposerVM( StatusV: choices.Accepted, }, HeightV: 0, - TimestampV: genesisTimestamp, + TimestampV: snowmantest.GenesisTimestamp, BytesV: []byte{0}, } @@ -916,7 +913,7 @@ func TestExpiredBuildBlock(t *testing.T) { StatusV: choices.Accepted, }, HeightV: 0, - TimestampV: genesisTimestamp, + TimestampV: snowmantest.GenesisTimestamp, BytesV: []byte{0}, } @@ -1223,7 +1220,7 @@ func TestInnerVMRollback(t *testing.T) { StatusV: choices.Accepted, }, HeightV: 0, - TimestampV: genesisTimestamp, + TimestampV: snowmantest.GenesisTimestamp, BytesV: []byte{0}, } @@ -1832,7 +1829,7 @@ func TestRejectedHeightNotIndexed(t *testing.T) { StatusV: choices.Accepted, }, HeightV: 0, - TimestampV: genesisTimestamp, + TimestampV: snowmantest.GenesisTimestamp, BytesV: []byte{0}, } @@ -2031,7 +2028,7 @@ func TestRejectedOptionHeightNotIndexed(t *testing.T) { StatusV: choices.Accepted, }, HeightV: 0, - TimestampV: genesisTimestamp, + TimestampV: snowmantest.GenesisTimestamp, BytesV: []byte{0}, } @@ -2622,7 +2619,7 @@ func TestHistoricalBlockDeletion(t *testing.T) { StatusV: choices.Accepted, }, HeightV: 0, - TimestampV: genesisTimestamp, + TimestampV: snowmantest.GenesisTimestamp, BytesV: utils.RandomBytes(1024), } acceptedBlocks := []snowman.Block{coreGenBlk} From 4bb373b2f2f087d0ef27d35ba5f98dcea4bfec8b Mon Sep 17 00:00:00 2001 From: Stephen Buttolph Date: Fri, 26 Apr 2024 17:25:36 -0400 Subject: [PATCH 11/24] Union genesis --- vms/proposervm/batched_vm_test.go | 69 +++++++++++++------------------ 1 file changed, 29 insertions(+), 40 deletions(-) diff --git a/vms/proposervm/batched_vm_test.go b/vms/proposervm/batched_vm_test.go index 24e1eb753b9b..e7344ddab9e1 100644 --- a/vms/proposervm/batched_vm_test.go +++ b/vms/proposervm/batched_vm_test.go @@ -62,7 +62,7 @@ func TestGetAncestorsPreForkOnly(t *testing.T) { activationTime = mockable.MaxTime durangoTime = activationTime ) - coreVM, proRemoteVM, coreGenBlk := initTestRemoteProposerVM(t, activationTime, durangoTime) + coreVM, proRemoteVM := initTestRemoteProposerVM(t, activationTime, durangoTime) defer func() { require.NoError(proRemoteVM.Shutdown(context.Background())) }() @@ -74,9 +74,9 @@ func TestGetAncestorsPreForkOnly(t *testing.T) { StatusV: choices.Processing, }, BytesV: []byte{1}, - ParentV: coreGenBlk.ID(), - HeightV: coreGenBlk.Height() + 1, - TimestampV: coreGenBlk.Timestamp(), + ParentV: snowmantest.GenesisID, + HeightV: snowmantest.GenesisHeight + 1, + TimestampV: snowmantest.GenesisTimestamp, } coreVM.BuildBlockF = func(context.Context) (snowman.Block, error) { return coreBlk1, nil @@ -212,7 +212,7 @@ func TestGetAncestorsPostForkOnly(t *testing.T) { activationTime = time.Unix(0, 0) durangoTime = activationTime ) - coreVM, proRemoteVM, coreGenBlk := initTestRemoteProposerVM(t, activationTime, durangoTime) + coreVM, proRemoteVM := initTestRemoteProposerVM(t, activationTime, durangoTime) defer func() { require.NoError(proRemoteVM.Shutdown(context.Background())) }() @@ -224,8 +224,8 @@ func TestGetAncestorsPostForkOnly(t *testing.T) { StatusV: choices.Processing, }, BytesV: []byte{1}, - ParentV: coreGenBlk.ID(), - HeightV: coreGenBlk.Height() + 1, + ParentV: snowmantest.GenesisID, + HeightV: snowmantest.GenesisHeight + 1, } coreVM.BuildBlockF = func(context.Context) (snowman.Block, error) { return coreBlk1, nil @@ -301,8 +301,8 @@ func TestGetAncestorsPostForkOnly(t *testing.T) { coreVM.ParseBlockF = func(_ context.Context, b []byte) (snowman.Block, error) { switch { - case bytes.Equal(b, coreGenBlk.Bytes()): - return coreGenBlk, nil + case bytes.Equal(b, snowmantest.GenesisBytes): + return snowmantest.Genesis, nil case bytes.Equal(b, coreBlk1.Bytes()): return coreBlk1, nil case bytes.Equal(b, coreBlk2.Bytes()): @@ -372,7 +372,7 @@ func TestGetAncestorsAtSnomanPlusPlusFork(t *testing.T) { ) // enable ProBlks in next future - coreVM, proRemoteVM, coreGenBlk := initTestRemoteProposerVM(t, forkTime, durangoTime) + coreVM, proRemoteVM := initTestRemoteProposerVM(t, forkTime, durangoTime) defer func() { require.NoError(proRemoteVM.Shutdown(context.Background())) }() @@ -385,8 +385,8 @@ func TestGetAncestorsAtSnomanPlusPlusFork(t *testing.T) { StatusV: choices.Processing, }, BytesV: []byte{1}, - ParentV: coreGenBlk.ID(), - HeightV: coreGenBlk.Height() + 1, + ParentV: snowmantest.GenesisID, + HeightV: snowmantest.GenesisHeight + 1, TimestampV: preForkTime, } coreVM.BuildBlockF = func(context.Context) (snowman.Block, error) { @@ -574,7 +574,7 @@ func TestBatchedParseBlockPreForkOnly(t *testing.T) { activationTime = mockable.MaxTime durangoTime = activationTime ) - coreVM, proRemoteVM, coreGenBlk := initTestRemoteProposerVM(t, activationTime, durangoTime) + coreVM, proRemoteVM := initTestRemoteProposerVM(t, activationTime, durangoTime) defer func() { require.NoError(proRemoteVM.Shutdown(context.Background())) }() @@ -586,8 +586,8 @@ func TestBatchedParseBlockPreForkOnly(t *testing.T) { StatusV: choices.Processing, }, BytesV: []byte{1}, - ParentV: coreGenBlk.ID(), - HeightV: coreGenBlk.Height() + 1, + ParentV: snowmantest.GenesisID, + HeightV: snowmantest.GenesisHeight + 1, } coreVM.BuildBlockF = func(context.Context) (snowman.Block, error) { return coreBlk1, nil @@ -696,7 +696,7 @@ func TestBatchedParseBlockPostForkOnly(t *testing.T) { activationTime = time.Unix(0, 0) durangoTime = activationTime ) - coreVM, proRemoteVM, coreGenBlk := initTestRemoteProposerVM(t, activationTime, durangoTime) + coreVM, proRemoteVM := initTestRemoteProposerVM(t, activationTime, durangoTime) defer func() { require.NoError(proRemoteVM.Shutdown(context.Background())) }() @@ -708,8 +708,8 @@ func TestBatchedParseBlockPostForkOnly(t *testing.T) { StatusV: choices.Processing, }, BytesV: []byte{1}, - ParentV: coreGenBlk.ID(), - HeightV: coreGenBlk.Height() + 1, + ParentV: snowmantest.GenesisID, + HeightV: snowmantest.GenesisHeight + 1, } coreVM.BuildBlockF = func(context.Context) (snowman.Block, error) { return coreBlk1, nil @@ -813,7 +813,7 @@ func TestBatchedParseBlockAtSnomanPlusPlusFork(t *testing.T) { ) // enable ProBlks in next future - coreVM, proRemoteVM, coreGenBlk := initTestRemoteProposerVM(t, forkTime, durangoTime) + coreVM, proRemoteVM := initTestRemoteProposerVM(t, forkTime, durangoTime) defer func() { require.NoError(proRemoteVM.Shutdown(context.Background())) }() @@ -826,8 +826,8 @@ func TestBatchedParseBlockAtSnomanPlusPlusFork(t *testing.T) { StatusV: choices.Processing, }, BytesV: []byte{1}, - ParentV: coreGenBlk.ID(), - HeightV: coreGenBlk.Height() + 1, + ParentV: snowmantest.GenesisID, + HeightV: snowmantest.GenesisHeight + 1, TimestampV: preForkTime, } coreVM.BuildBlockF = func(context.Context) (snowman.Block, error) { @@ -978,20 +978,9 @@ func initTestRemoteProposerVM( ) ( TestRemoteProposerVM, *VM, - *snowmantest.Block, ) { require := require.New(t) - coreGenBlk := &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.GenerateTestID(), - StatusV: choices.Accepted, - }, - HeightV: 0, - TimestampV: snowmantest.GenesisTimestamp, - BytesV: []byte{0}, - } - initialState := []byte("genesis state") coreVM := TestRemoteProposerVM{ TestVM: &block.TestVM{}, @@ -1014,20 +1003,20 @@ func initTestRemoteProposerVM( return nil } coreVM.LastAcceptedF = func(context.Context) (ids.ID, error) { - return coreGenBlk.ID(), nil + return snowmantest.GenesisID, nil } coreVM.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { switch { - case blkID == coreGenBlk.ID(): - return coreGenBlk, nil + case blkID == snowmantest.GenesisID: + return snowmantest.Genesis, nil default: return nil, errUnknownBlock } } coreVM.ParseBlockF = func(_ context.Context, b []byte) (snowman.Block, error) { switch { - case bytes.Equal(b, coreGenBlk.Bytes()): - return coreGenBlk, nil + case bytes.Equal(b, snowmantest.GenesisBytes): + return snowmantest.Genesis, nil default: return nil, errUnknownBlock } @@ -1050,7 +1039,7 @@ func initTestRemoteProposerVM( T: t, } valState.GetMinimumHeightF = func(context.Context) (uint64, error) { - return coreGenBlk.Height(), nil + return snowmantest.GenesisHeight, nil } valState.GetCurrentHeightF = func(context.Context) (uint64, error) { return defaultPChainHeight, nil @@ -1102,6 +1091,6 @@ func initTestRemoteProposerVM( coreVM.InitializeF = nil require.NoError(proVM.SetState(context.Background(), snow.NormalOp)) - require.NoError(proVM.SetPreference(context.Background(), coreGenBlk.IDV)) - return coreVM, proVM, coreGenBlk + require.NoError(proVM.SetPreference(context.Background(), snowmantest.GenesisID)) + return coreVM, proVM } From 5d3c814458a31450da32a2559a0b1562938ed2b6 Mon Sep 17 00:00:00 2001 From: Stephen Buttolph Date: Fri, 26 Apr 2024 18:02:07 -0400 Subject: [PATCH 12/24] Use common genesis --- vms/proposervm/batched_vm_test.go | 2 +- vms/proposervm/block_test.go | 28 +-- vms/proposervm/post_fork_block_test.go | 148 ++++++++-------- vms/proposervm/post_fork_option_test.go | 100 +++++------ vms/proposervm/pre_fork_block_test.go | 102 +++++------ vms/proposervm/vm_byzantine_test.go | 84 ++++----- vms/proposervm/vm_test.go | 225 +++++++++++------------- 7 files changed, 339 insertions(+), 350 deletions(-) diff --git a/vms/proposervm/batched_vm_test.go b/vms/proposervm/batched_vm_test.go index e7344ddab9e1..33e586cd378b 100644 --- a/vms/proposervm/batched_vm_test.go +++ b/vms/proposervm/batched_vm_test.go @@ -33,7 +33,7 @@ func TestCoreVMNotRemote(t *testing.T) { activationTime = time.Unix(0, 0) durangoTime = activationTime ) - _, _, proVM, _, _ := initTestProposerVM(t, activationTime, durangoTime, 0) + _, _, proVM, _ := initTestProposerVM(t, activationTime, durangoTime, 0) defer func() { require.NoError(proVM.Shutdown(context.Background())) }() diff --git a/vms/proposervm/block_test.go b/vms/proposervm/block_test.go index 9ddce10c7a3e..5e4790137f61 100644 --- a/vms/proposervm/block_test.go +++ b/vms/proposervm/block_test.go @@ -110,7 +110,7 @@ func TestPreDurangoValidatorNodeBlockBuiltDelaysTests(t *testing.T) { activationTime = time.Unix(0, 0) durangoTime = mockable.MaxTime ) - coreVM, valState, proVM, coreGenBlk, _ := initTestProposerVM(t, activationTime, durangoTime, 0) + coreVM, valState, proVM, _ := initTestProposerVM(t, activationTime, durangoTime, 0) defer func() { require.NoError(proVM.Shutdown(ctx)) }() @@ -125,8 +125,8 @@ func TestPreDurangoValidatorNodeBlockBuiltDelaysTests(t *testing.T) { StatusV: choices.Processing, }, BytesV: []byte{1}, - ParentV: coreGenBlk.ID(), - HeightV: coreGenBlk.Height() + 1, + ParentV: snowmantest.GenesisID, + HeightV: snowmantest.GenesisHeight + 1, } coreVM.BuildBlockF = func(context.Context) (snowman.Block, error) { return coreParentBlk, nil @@ -135,8 +135,8 @@ func TestPreDurangoValidatorNodeBlockBuiltDelaysTests(t *testing.T) { switch { case blkID == coreParentBlk.ID(): return coreParentBlk, nil - case blkID == coreGenBlk.ID(): - return coreGenBlk, nil + case blkID == snowmantest.GenesisID: + return snowmantest.Genesis, nil default: return nil, errUnknownBlock } @@ -145,8 +145,8 @@ func TestPreDurangoValidatorNodeBlockBuiltDelaysTests(t *testing.T) { switch { case bytes.Equal(b, coreParentBlk.Bytes()): return coreParentBlk, nil - case bytes.Equal(b, coreGenBlk.Bytes()): - return coreGenBlk, nil + case bytes.Equal(b, snowmantest.GenesisBytes): + return snowmantest.Genesis, nil default: return nil, errUnknownBlock } @@ -247,7 +247,7 @@ func TestPreDurangoNonValidatorNodeBlockBuiltDelaysTests(t *testing.T) { activationTime = time.Unix(0, 0) durangoTime = mockable.MaxTime ) - coreVM, valState, proVM, coreGenBlk, _ := initTestProposerVM(t, activationTime, durangoTime, 0) + coreVM, valState, proVM, _ := initTestProposerVM(t, activationTime, durangoTime, 0) defer func() { require.NoError(proVM.Shutdown(ctx)) }() @@ -262,8 +262,8 @@ func TestPreDurangoNonValidatorNodeBlockBuiltDelaysTests(t *testing.T) { StatusV: choices.Processing, }, BytesV: []byte{1}, - ParentV: coreGenBlk.ID(), - HeightV: coreGenBlk.Height() + 1, + ParentV: snowmantest.GenesisID, + HeightV: snowmantest.GenesisHeight + 1, } coreVM.BuildBlockF = func(context.Context) (snowman.Block, error) { return coreParentBlk, nil @@ -272,8 +272,8 @@ func TestPreDurangoNonValidatorNodeBlockBuiltDelaysTests(t *testing.T) { switch { case blkID == coreParentBlk.ID(): return coreParentBlk, nil - case blkID == coreGenBlk.ID(): - return coreGenBlk, nil + case blkID == snowmantest.GenesisID: + return snowmantest.Genesis, nil default: return nil, errUnknownBlock } @@ -282,8 +282,8 @@ func TestPreDurangoNonValidatorNodeBlockBuiltDelaysTests(t *testing.T) { switch { case bytes.Equal(b, coreParentBlk.Bytes()): return coreParentBlk, nil - case bytes.Equal(b, coreGenBlk.Bytes()): - return coreGenBlk, nil + case bytes.Equal(b, snowmantest.GenesisBytes): + return snowmantest.Genesis, nil default: return nil, errUnknownBlock } diff --git a/vms/proposervm/post_fork_block_test.go b/vms/proposervm/post_fork_block_test.go index a949f137269a..4b1b478fe48c 100644 --- a/vms/proposervm/post_fork_block_test.go +++ b/vms/proposervm/post_fork_block_test.go @@ -45,7 +45,7 @@ func TestOracle_PostForkBlock_ImplementsInterface(t *testing.T) { activationTime = time.Unix(0, 0) durangoTime = activationTime ) - _, _, proVM, _, _ := initTestProposerVM(t, activationTime, durangoTime, 0) + _, _, proVM, _ := initTestProposerVM(t, activationTime, durangoTime, 0) defer func() { require.NoError(proVM.Shutdown(context.Background())) }() @@ -105,7 +105,7 @@ func TestBlockVerify_PostForkBlock_PreDurango_ParentChecks(t *testing.T) { activationTime = time.Unix(0, 0) durangoTime = mockable.MaxTime // pre Durango ) - coreVM, valState, proVM, coreGenBlk, _ := initTestProposerVM(t, activationTime, durangoTime, 0) + coreVM, valState, proVM, _ := initTestProposerVM(t, activationTime, durangoTime, 0) defer func() { require.NoError(proVM.Shutdown(context.Background())) }() @@ -122,16 +122,16 @@ func TestBlockVerify_PostForkBlock_PreDurango_ParentChecks(t *testing.T) { StatusV: choices.Processing, }, BytesV: []byte{1}, - ParentV: coreGenBlk.ID(), - HeightV: coreGenBlk.Height() + 1, + ParentV: snowmantest.GenesisID, + HeightV: snowmantest.GenesisHeight + 1, } coreVM.BuildBlockF = func(context.Context) (snowman.Block, error) { return parentCoreBlk, nil } coreVM.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { switch blkID { - case coreGenBlk.ID(): - return coreGenBlk, nil + case snowmantest.GenesisID: + return snowmantest.Genesis, nil case parentCoreBlk.ID(): return parentCoreBlk, nil default: @@ -140,8 +140,8 @@ func TestBlockVerify_PostForkBlock_PreDurango_ParentChecks(t *testing.T) { } coreVM.ParseBlockF = func(_ context.Context, b []byte) (snowman.Block, error) { switch { - case bytes.Equal(b, coreGenBlk.Bytes()): - return coreGenBlk, nil + case bytes.Equal(b, snowmantest.GenesisBytes): + return snowmantest.Genesis, nil case bytes.Equal(b, parentCoreBlk.Bytes()): return parentCoreBlk, nil default: @@ -209,7 +209,7 @@ func TestBlockVerify_PostForkBlock_PostDurango_ParentChecks(t *testing.T) { activationTime = time.Unix(0, 0) durangoTime = activationTime // post Durango ) - coreVM, valState, proVM, coreGenBlk, _ := initTestProposerVM(t, activationTime, durangoTime, 0) + coreVM, valState, proVM, _ := initTestProposerVM(t, activationTime, durangoTime, 0) defer func() { require.NoError(proVM.Shutdown(context.Background())) }() @@ -225,16 +225,16 @@ func TestBlockVerify_PostForkBlock_PostDurango_ParentChecks(t *testing.T) { StatusV: choices.Processing, }, BytesV: []byte{1}, - ParentV: coreGenBlk.ID(), - HeightV: coreGenBlk.Height() + 1, + ParentV: snowmantest.GenesisID, + HeightV: snowmantest.GenesisHeight + 1, } coreVM.BuildBlockF = func(context.Context) (snowman.Block, error) { return parentCoreBlk, nil } coreVM.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { switch blkID { - case coreGenBlk.ID(): - return coreGenBlk, nil + case snowmantest.GenesisID: + return snowmantest.Genesis, nil case parentCoreBlk.ID(): return parentCoreBlk, nil default: @@ -243,8 +243,8 @@ func TestBlockVerify_PostForkBlock_PostDurango_ParentChecks(t *testing.T) { } coreVM.ParseBlockF = func(_ context.Context, b []byte) (snowman.Block, error) { switch { - case bytes.Equal(b, coreGenBlk.Bytes()): - return coreGenBlk, nil + case bytes.Equal(b, snowmantest.GenesisBytes): + return snowmantest.Genesis, nil case bytes.Equal(b, parentCoreBlk.Bytes()): return parentCoreBlk, nil default: @@ -318,7 +318,7 @@ func TestBlockVerify_PostForkBlock_TimestampChecks(t *testing.T) { activationTime = time.Unix(0, 0) durangoTime = mockable.MaxTime ) - coreVM, valState, proVM, coreGenBlk, _ := initTestProposerVM(t, activationTime, durangoTime, 0) + coreVM, valState, proVM, _ := initTestProposerVM(t, activationTime, durangoTime, 0) defer func() { require.NoError(proVM.Shutdown(context.Background())) }() @@ -354,16 +354,16 @@ func TestBlockVerify_PostForkBlock_TimestampChecks(t *testing.T) { StatusV: choices.Processing, }, BytesV: []byte{1}, - ParentV: coreGenBlk.ID(), - HeightV: coreGenBlk.Height() + 1, + ParentV: snowmantest.GenesisID, + HeightV: snowmantest.GenesisHeight + 1, } coreVM.BuildBlockF = func(context.Context) (snowman.Block, error) { return parentCoreBlk, nil } coreVM.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { switch blkID { - case coreGenBlk.ID(): - return coreGenBlk, nil + case snowmantest.GenesisID: + return snowmantest.Genesis, nil case parentCoreBlk.ID(): return parentCoreBlk, nil default: @@ -372,8 +372,8 @@ func TestBlockVerify_PostForkBlock_TimestampChecks(t *testing.T) { } coreVM.ParseBlockF = func(_ context.Context, b []byte) (snowman.Block, error) { switch { - case bytes.Equal(b, coreGenBlk.Bytes()): - return coreGenBlk, nil + case bytes.Equal(b, snowmantest.GenesisBytes): + return snowmantest.Genesis, nil case bytes.Equal(b, parentCoreBlk.Bytes()): return parentCoreBlk, nil default: @@ -539,7 +539,7 @@ func TestBlockVerify_PostForkBlock_PChainHeightChecks(t *testing.T) { activationTime = time.Unix(0, 0) durangoTime = activationTime ) - coreVM, valState, proVM, coreGenBlk, _ := initTestProposerVM(t, activationTime, durangoTime, 0) + coreVM, valState, proVM, _ := initTestProposerVM(t, activationTime, durangoTime, 0) defer func() { require.NoError(proVM.Shutdown(context.Background())) }() @@ -559,16 +559,16 @@ func TestBlockVerify_PostForkBlock_PChainHeightChecks(t *testing.T) { StatusV: choices.Processing, }, BytesV: []byte{1}, - ParentV: coreGenBlk.ID(), - HeightV: coreGenBlk.Height() + 1, + ParentV: snowmantest.GenesisID, + HeightV: snowmantest.GenesisHeight + 1, } coreVM.BuildBlockF = func(context.Context) (snowman.Block, error) { return parentCoreBlk, nil } coreVM.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { switch blkID { - case coreGenBlk.ID(): - return coreGenBlk, nil + case snowmantest.GenesisID: + return snowmantest.Genesis, nil case parentCoreBlk.ID(): return parentCoreBlk, nil default: @@ -577,8 +577,8 @@ func TestBlockVerify_PostForkBlock_PChainHeightChecks(t *testing.T) { } coreVM.ParseBlockF = func(_ context.Context, b []byte) (snowman.Block, error) { switch { - case bytes.Equal(b, coreGenBlk.Bytes()): - return coreGenBlk, nil + case bytes.Equal(b, snowmantest.GenesisBytes): + return snowmantest.Genesis, nil case bytes.Equal(b, parentCoreBlk.Bytes()): return parentCoreBlk, nil default: @@ -710,7 +710,7 @@ func TestBlockVerify_PostForkBlockBuiltOnOption_PChainHeightChecks(t *testing.T) activationTime = time.Unix(0, 0) durangoTime = mockable.MaxTime ) - coreVM, valState, proVM, coreGenBlk, _ := initTestProposerVM(t, activationTime, durangoTime, 0) + coreVM, valState, proVM, _ := initTestProposerVM(t, activationTime, durangoTime, 0) defer func() { require.NoError(proVM.Shutdown(context.Background())) }() @@ -731,8 +731,8 @@ func TestBlockVerify_PostForkBlockBuiltOnOption_PChainHeightChecks(t *testing.T) StatusV: choices.Processing, }, BytesV: []byte{1}, - ParentV: coreGenBlk.ID(), - HeightV: coreGenBlk.Height() + 1, + ParentV: snowmantest.GenesisID, + HeightV: snowmantest.GenesisHeight + 1, }, } oracleCoreBlk.opts = [2]snowman.Block{ @@ -761,8 +761,8 @@ func TestBlockVerify_PostForkBlockBuiltOnOption_PChainHeightChecks(t *testing.T) } coreVM.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { switch blkID { - case coreGenBlk.ID(): - return coreGenBlk, nil + case snowmantest.GenesisID: + return snowmantest.Genesis, nil case oracleCoreBlk.ID(): return oracleCoreBlk, nil case oracleCoreBlk.opts[0].ID(): @@ -775,8 +775,8 @@ func TestBlockVerify_PostForkBlockBuiltOnOption_PChainHeightChecks(t *testing.T) } coreVM.ParseBlockF = func(_ context.Context, b []byte) (snowman.Block, error) { switch { - case bytes.Equal(b, coreGenBlk.Bytes()): - return coreGenBlk, nil + case bytes.Equal(b, snowmantest.GenesisBytes): + return snowmantest.Genesis, nil case bytes.Equal(b, oracleCoreBlk.Bytes()): return oracleCoreBlk, nil case bytes.Equal(b, oracleCoreBlk.opts[0].Bytes()): @@ -910,7 +910,7 @@ func TestBlockVerify_PostForkBlock_CoreBlockVerifyIsCalledOnce(t *testing.T) { activationTime = time.Unix(0, 0) durangoTime = activationTime ) - coreVM, valState, proVM, coreGenBlk, _ := initTestProposerVM(t, activationTime, durangoTime, 0) + coreVM, valState, proVM, _ := initTestProposerVM(t, activationTime, durangoTime, 0) defer func() { require.NoError(proVM.Shutdown(context.Background())) }() @@ -926,16 +926,16 @@ func TestBlockVerify_PostForkBlock_CoreBlockVerifyIsCalledOnce(t *testing.T) { StatusV: choices.Processing, }, BytesV: []byte{1}, - ParentV: coreGenBlk.ID(), - HeightV: coreGenBlk.Height() + 1, + ParentV: snowmantest.GenesisID, + HeightV: snowmantest.GenesisHeight + 1, } coreVM.BuildBlockF = func(context.Context) (snowman.Block, error) { return coreBlk, nil } coreVM.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { switch blkID { - case coreGenBlk.ID(): - return coreGenBlk, nil + case snowmantest.GenesisID: + return snowmantest.Genesis, nil case coreBlk.ID(): return coreBlk, nil default: @@ -944,8 +944,8 @@ func TestBlockVerify_PostForkBlock_CoreBlockVerifyIsCalledOnce(t *testing.T) { } coreVM.ParseBlockF = func(_ context.Context, b []byte) (snowman.Block, error) { switch { - case bytes.Equal(b, coreGenBlk.Bytes()): - return coreGenBlk, nil + case bytes.Equal(b, snowmantest.GenesisBytes): + return snowmantest.Genesis, nil case bytes.Equal(b, coreBlk.Bytes()): return coreBlk, nil default: @@ -977,7 +977,7 @@ func TestBlockAccept_PostForkBlock_SetsLastAcceptedBlock(t *testing.T) { activationTime = time.Unix(0, 0) durangoTime = activationTime ) - coreVM, valState, proVM, coreGenBlk, _ := initTestProposerVM(t, activationTime, durangoTime, 0) + coreVM, valState, proVM, _ := initTestProposerVM(t, activationTime, durangoTime, 0) defer func() { require.NoError(proVM.Shutdown(context.Background())) }() @@ -993,16 +993,16 @@ func TestBlockAccept_PostForkBlock_SetsLastAcceptedBlock(t *testing.T) { StatusV: choices.Processing, }, BytesV: []byte{1}, - ParentV: coreGenBlk.ID(), - HeightV: coreGenBlk.Height() + 1, + ParentV: snowmantest.GenesisID, + HeightV: snowmantest.GenesisHeight + 1, } coreVM.BuildBlockF = func(context.Context) (snowman.Block, error) { return coreBlk, nil } coreVM.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { switch blkID { - case coreGenBlk.ID(): - return coreGenBlk, nil + case snowmantest.GenesisID: + return snowmantest.Genesis, nil case coreBlk.ID(): return coreBlk, nil default: @@ -1011,8 +1011,8 @@ func TestBlockAccept_PostForkBlock_SetsLastAcceptedBlock(t *testing.T) { } coreVM.ParseBlockF = func(_ context.Context, b []byte) (snowman.Block, error) { switch { - case bytes.Equal(b, coreGenBlk.Bytes()): - return coreGenBlk, nil + case bytes.Equal(b, snowmantest.GenesisBytes): + return snowmantest.Genesis, nil case bytes.Equal(b, coreBlk.Bytes()): return coreBlk, nil default: @@ -1030,7 +1030,7 @@ func TestBlockAccept_PostForkBlock_SetsLastAcceptedBlock(t *testing.T) { if coreBlk.Status() == choices.Accepted { return coreBlk.ID(), nil } - return coreGenBlk.ID(), nil + return snowmantest.GenesisID, nil } acceptedID, err := proVM.LastAccepted(context.Background()) require.NoError(err) @@ -1044,7 +1044,7 @@ func TestBlockAccept_PostForkBlock_TwoProBlocksWithSameCoreBlock_OneIsAccepted(t activationTime = time.Unix(0, 0) durangoTime = activationTime ) - coreVM, valState, proVM, coreGenBlk, _ := initTestProposerVM(t, activationTime, durangoTime, 0) + coreVM, valState, proVM, _ := initTestProposerVM(t, activationTime, durangoTime, 0) defer func() { require.NoError(proVM.Shutdown(context.Background())) }() @@ -1061,14 +1061,14 @@ func TestBlockAccept_PostForkBlock_TwoProBlocksWithSameCoreBlock_OneIsAccepted(t StatusV: choices.Processing, }, BytesV: []byte{1}, - ParentV: coreGenBlk.ID(), - HeightV: coreGenBlk.Height() + 1, + ParentV: snowmantest.GenesisID, + HeightV: snowmantest.GenesisHeight + 1, } coreVM.BuildBlockF = func(context.Context) (snowman.Block, error) { return coreBlk, nil } - minimumHeight = coreGenBlk.Height() + minimumHeight = snowmantest.GenesisHeight proBlk1, err := proVM.BuildBlock(context.Background()) require.NoError(err) @@ -1095,7 +1095,7 @@ func TestBlockReject_PostForkBlock_InnerBlockIsNotRejected(t *testing.T) { activationTime = time.Unix(0, 0) durangoTime = activationTime ) - coreVM, _, proVM, coreGenBlk, _ := initTestProposerVM(t, activationTime, durangoTime, 0) + coreVM, _, proVM, _ := initTestProposerVM(t, activationTime, durangoTime, 0) defer func() { require.NoError(proVM.Shutdown(context.Background())) }() @@ -1106,8 +1106,8 @@ func TestBlockReject_PostForkBlock_InnerBlockIsNotRejected(t *testing.T) { StatusV: choices.Processing, }, BytesV: []byte{1}, - ParentV: coreGenBlk.ID(), - HeightV: coreGenBlk.Height() + 1, + ParentV: snowmantest.GenesisID, + HeightV: snowmantest.GenesisHeight + 1, } coreVM.BuildBlockF = func(context.Context) (snowman.Block, error) { return coreBlk, nil @@ -1131,7 +1131,7 @@ func TestBlockVerify_PostForkBlock_ShouldBePostForkOption(t *testing.T) { activationTime = time.Unix(0, 0) durangoTime = activationTime ) - coreVM, _, proVM, coreGenBlk, _ := initTestProposerVM(t, activationTime, durangoTime, 0) + coreVM, _, proVM, _ := initTestProposerVM(t, activationTime, durangoTime, 0) defer func() { require.NoError(proVM.Shutdown(context.Background())) }() @@ -1144,8 +1144,8 @@ func TestBlockVerify_PostForkBlock_ShouldBePostForkOption(t *testing.T) { StatusV: choices.Processing, }, BytesV: []byte{1}, - ParentV: coreGenBlk.ID(), - HeightV: coreGenBlk.Height() + 1, + ParentV: snowmantest.GenesisID, + HeightV: snowmantest.GenesisHeight + 1, }, } coreOpt0 := &snowmantest.Block{ @@ -1176,8 +1176,8 @@ func TestBlockVerify_PostForkBlock_ShouldBePostForkOption(t *testing.T) { } coreVM.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { switch blkID { - case coreGenBlk.ID(): - return coreGenBlk, nil + case snowmantest.GenesisID: + return snowmantest.Genesis, nil case oracleCoreBlk.ID(): return oracleCoreBlk, nil case oracleCoreBlk.opts[0].ID(): @@ -1190,8 +1190,8 @@ func TestBlockVerify_PostForkBlock_ShouldBePostForkOption(t *testing.T) { } coreVM.ParseBlockF = func(_ context.Context, b []byte) (snowman.Block, error) { switch { - case bytes.Equal(b, coreGenBlk.Bytes()): - return coreGenBlk, nil + case bytes.Equal(b, snowmantest.GenesisBytes): + return snowmantest.Genesis, nil case bytes.Equal(b, oracleCoreBlk.Bytes()): return oracleCoreBlk, nil case bytes.Equal(b, oracleCoreBlk.opts[0].Bytes()): @@ -1249,7 +1249,7 @@ func TestBlockVerify_PostForkBlock_PChainTooLow(t *testing.T) { activationTime = time.Unix(0, 0) durangoTime = activationTime ) - coreVM, _, proVM, coreGenBlk, _ := initTestProposerVM(t, activationTime, durangoTime, 5) + coreVM, _, proVM, _ := initTestProposerVM(t, activationTime, durangoTime, 5) defer func() { require.NoError(proVM.Shutdown(context.Background())) }() @@ -1260,14 +1260,14 @@ func TestBlockVerify_PostForkBlock_PChainTooLow(t *testing.T) { StatusV: choices.Processing, }, BytesV: []byte{1}, - ParentV: coreGenBlk.ID(), - HeightV: coreGenBlk.Height() + 1, + ParentV: snowmantest.GenesisID, + HeightV: snowmantest.GenesisHeight + 1, } coreVM.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { switch blkID { - case coreGenBlk.ID(): - return coreGenBlk, nil + case snowmantest.GenesisID: + return snowmantest.Genesis, nil case coreBlk.ID(): return coreBlk, nil default: @@ -1276,8 +1276,8 @@ func TestBlockVerify_PostForkBlock_PChainTooLow(t *testing.T) { } coreVM.ParseBlockF = func(_ context.Context, b []byte) (snowman.Block, error) { switch { - case bytes.Equal(b, coreGenBlk.Bytes()): - return coreGenBlk, nil + case bytes.Equal(b, snowmantest.GenesisBytes): + return snowmantest.Genesis, nil case bytes.Equal(b, coreBlk.Bytes()): return coreBlk, nil default: @@ -1286,8 +1286,8 @@ func TestBlockVerify_PostForkBlock_PChainTooLow(t *testing.T) { } statelessChild, err := block.BuildUnsigned( - coreGenBlk.ID(), - coreGenBlk.Timestamp(), + snowmantest.GenesisID, + snowmantest.GenesisTimestamp, 4, coreBlk.Bytes(), ) diff --git a/vms/proposervm/post_fork_option_test.go b/vms/proposervm/post_fork_option_test.go index d81218580fc7..a299cfa95401 100644 --- a/vms/proposervm/post_fork_option_test.go +++ b/vms/proposervm/post_fork_option_test.go @@ -41,7 +41,7 @@ func TestBlockVerify_PostForkOption_ParentChecks(t *testing.T) { activationTime = time.Unix(0, 0) durangoTime = activationTime ) - coreVM, _, proVM, coreGenBlk, _ := initTestProposerVM(t, activationTime, durangoTime, 0) + coreVM, _, proVM, _ := initTestProposerVM(t, activationTime, durangoTime, 0) defer func() { require.NoError(proVM.Shutdown(context.Background())) }() @@ -54,8 +54,8 @@ func TestBlockVerify_PostForkOption_ParentChecks(t *testing.T) { StatusV: choices.Processing, }, BytesV: []byte{1}, - ParentV: coreGenBlk.ID(), - HeightV: coreGenBlk.Height() + 1, + ParentV: snowmantest.GenesisID, + HeightV: snowmantest.GenesisHeight + 1, }, } oracleCoreBlk.opts = [2]snowman.Block{ @@ -84,8 +84,8 @@ func TestBlockVerify_PostForkOption_ParentChecks(t *testing.T) { } coreVM.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { switch blkID { - case coreGenBlk.ID(): - return coreGenBlk, nil + case snowmantest.GenesisID: + return snowmantest.Genesis, nil case oracleCoreBlk.ID(): return oracleCoreBlk, nil case oracleCoreBlk.opts[0].ID(): @@ -98,8 +98,8 @@ func TestBlockVerify_PostForkOption_ParentChecks(t *testing.T) { } coreVM.ParseBlockF = func(_ context.Context, b []byte) (snowman.Block, error) { switch { - case bytes.Equal(b, coreGenBlk.Bytes()): - return coreGenBlk, nil + case bytes.Equal(b, snowmantest.GenesisBytes): + return snowmantest.Genesis, nil case bytes.Equal(b, oracleCoreBlk.Bytes()): return oracleCoreBlk, nil case bytes.Equal(b, oracleCoreBlk.opts[0].Bytes()): @@ -160,7 +160,7 @@ func TestBlockVerify_PostForkOption_CoreBlockVerifyIsCalledOnce(t *testing.T) { activationTime = time.Unix(0, 0) durangoTime = activationTime ) - coreVM, _, proVM, coreGenBlk, _ := initTestProposerVM(t, activationTime, durangoTime, 0) + coreVM, _, proVM, _ := initTestProposerVM(t, activationTime, durangoTime, 0) defer func() { require.NoError(proVM.Shutdown(context.Background())) }() @@ -173,8 +173,8 @@ func TestBlockVerify_PostForkOption_CoreBlockVerifyIsCalledOnce(t *testing.T) { StatusV: choices.Processing, }, BytesV: []byte{1}, - ParentV: coreGenBlk.ID(), - HeightV: coreGenBlk.Height() + 1, + ParentV: snowmantest.GenesisID, + HeightV: snowmantest.GenesisHeight + 1, }, } coreOpt0 := &snowmantest.Block{ @@ -205,8 +205,8 @@ func TestBlockVerify_PostForkOption_CoreBlockVerifyIsCalledOnce(t *testing.T) { } coreVM.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { switch blkID { - case coreGenBlk.ID(): - return coreGenBlk, nil + case snowmantest.GenesisID: + return snowmantest.Genesis, nil case oracleCoreBlk.ID(): return oracleCoreBlk, nil case oracleCoreBlk.opts[0].ID(): @@ -219,8 +219,8 @@ func TestBlockVerify_PostForkOption_CoreBlockVerifyIsCalledOnce(t *testing.T) { } coreVM.ParseBlockF = func(_ context.Context, b []byte) (snowman.Block, error) { switch { - case bytes.Equal(b, coreGenBlk.Bytes()): - return coreGenBlk, nil + case bytes.Equal(b, snowmantest.GenesisBytes): + return snowmantest.Genesis, nil case bytes.Equal(b, oracleCoreBlk.Bytes()): return oracleCoreBlk, nil case bytes.Equal(b, oracleCoreBlk.opts[0].Bytes()): @@ -265,7 +265,7 @@ func TestBlockAccept_PostForkOption_SetsLastAcceptedBlock(t *testing.T) { activationTime = time.Unix(0, 0) durangoTime = activationTime ) - coreVM, _, proVM, coreGenBlk, _ := initTestProposerVM(t, activationTime, durangoTime, 0) + coreVM, _, proVM, _ := initTestProposerVM(t, activationTime, durangoTime, 0) defer func() { require.NoError(proVM.Shutdown(context.Background())) }() @@ -278,8 +278,8 @@ func TestBlockAccept_PostForkOption_SetsLastAcceptedBlock(t *testing.T) { StatusV: choices.Processing, }, BytesV: []byte{1}, - ParentV: coreGenBlk.ID(), - HeightV: coreGenBlk.Height() + 1, + ParentV: snowmantest.GenesisID, + HeightV: snowmantest.GenesisHeight + 1, }, } oracleCoreBlk.opts = [2]snowman.Block{ @@ -308,8 +308,8 @@ func TestBlockAccept_PostForkOption_SetsLastAcceptedBlock(t *testing.T) { } coreVM.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { switch blkID { - case coreGenBlk.ID(): - return coreGenBlk, nil + case snowmantest.GenesisID: + return snowmantest.Genesis, nil case oracleCoreBlk.ID(): return oracleCoreBlk, nil case oracleCoreBlk.opts[0].ID(): @@ -322,8 +322,8 @@ func TestBlockAccept_PostForkOption_SetsLastAcceptedBlock(t *testing.T) { } coreVM.ParseBlockF = func(_ context.Context, b []byte) (snowman.Block, error) { switch { - case bytes.Equal(b, coreGenBlk.Bytes()): - return coreGenBlk, nil + case bytes.Equal(b, snowmantest.GenesisBytes): + return snowmantest.Genesis, nil case bytes.Equal(b, oracleCoreBlk.Bytes()): return oracleCoreBlk, nil case bytes.Equal(b, oracleCoreBlk.opts[0].Bytes()): @@ -345,7 +345,7 @@ func TestBlockAccept_PostForkOption_SetsLastAcceptedBlock(t *testing.T) { if oracleCoreBlk.Status() == choices.Accepted { return oracleCoreBlk.ID(), nil } - return coreGenBlk.ID(), nil + return snowmantest.GenesisID, nil } acceptedID, err := proVM.LastAccepted(context.Background()) require.NoError(err) @@ -378,7 +378,7 @@ func TestBlockReject_InnerBlockIsNotRejected(t *testing.T) { activationTime = time.Unix(0, 0) durangoTime = activationTime ) - coreVM, _, proVM, coreGenBlk, _ := initTestProposerVM(t, activationTime, durangoTime, 0) + coreVM, _, proVM, _ := initTestProposerVM(t, activationTime, durangoTime, 0) defer func() { require.NoError(proVM.Shutdown(context.Background())) }() @@ -391,8 +391,8 @@ func TestBlockReject_InnerBlockIsNotRejected(t *testing.T) { StatusV: choices.Processing, }, BytesV: []byte{1}, - ParentV: coreGenBlk.ID(), - HeightV: coreGenBlk.Height() + 1, + ParentV: snowmantest.GenesisID, + HeightV: snowmantest.GenesisHeight + 1, }, } oracleCoreBlk.opts = [2]snowman.Block{ @@ -421,8 +421,8 @@ func TestBlockReject_InnerBlockIsNotRejected(t *testing.T) { } coreVM.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { switch blkID { - case coreGenBlk.ID(): - return coreGenBlk, nil + case snowmantest.GenesisID: + return snowmantest.Genesis, nil case oracleCoreBlk.ID(): return oracleCoreBlk, nil case oracleCoreBlk.opts[0].ID(): @@ -435,8 +435,8 @@ func TestBlockReject_InnerBlockIsNotRejected(t *testing.T) { } coreVM.ParseBlockF = func(_ context.Context, b []byte) (snowman.Block, error) { switch { - case bytes.Equal(b, coreGenBlk.Bytes()): - return coreGenBlk, nil + case bytes.Equal(b, snowmantest.GenesisBytes): + return snowmantest.Genesis, nil case bytes.Equal(b, oracleCoreBlk.Bytes()): return oracleCoreBlk, nil case bytes.Equal(b, oracleCoreBlk.opts[0].Bytes()): @@ -483,7 +483,7 @@ func TestBlockVerify_PostForkOption_ParentIsNotOracleWithError(t *testing.T) { activationTime = time.Unix(0, 0) durangoTime = activationTime ) - coreVM, _, proVM, coreGenBlk, _ := initTestProposerVM(t, activationTime, durangoTime, 0) + coreVM, _, proVM, _ := initTestProposerVM(t, activationTime, durangoTime, 0) defer func() { require.NoError(proVM.Shutdown(context.Background())) }() @@ -495,8 +495,8 @@ func TestBlockVerify_PostForkOption_ParentIsNotOracleWithError(t *testing.T) { StatusV: choices.Processing, }, BytesV: []byte{1}, - ParentV: coreGenBlk.ID(), - HeightV: coreGenBlk.Height() + 1, + ParentV: snowmantest.GenesisID, + HeightV: snowmantest.GenesisHeight + 1, }, optsErr: snowman.ErrNotOracle, } @@ -516,8 +516,8 @@ func TestBlockVerify_PostForkOption_ParentIsNotOracleWithError(t *testing.T) { } coreVM.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { switch blkID { - case coreGenBlk.ID(): - return coreGenBlk, nil + case snowmantest.GenesisID: + return snowmantest.Genesis, nil case coreBlk.ID(): return coreBlk, nil case coreChildBlk.ID(): @@ -528,8 +528,8 @@ func TestBlockVerify_PostForkOption_ParentIsNotOracleWithError(t *testing.T) { } coreVM.ParseBlockF = func(_ context.Context, b []byte) (snowman.Block, error) { switch { - case bytes.Equal(b, coreGenBlk.Bytes()): - return coreGenBlk, nil + case bytes.Equal(b, snowmantest.GenesisBytes): + return snowmantest.Genesis, nil case bytes.Equal(b, coreBlk.Bytes()): return coreBlk, nil case bytes.Equal(b, coreChildBlk.Bytes()): @@ -571,7 +571,7 @@ func TestOptionTimestampValidity(t *testing.T) { activationTime = time.Unix(0, 0) durangoTime = activationTime ) - coreVM, _, proVM, coreGenBlk, db := initTestProposerVM(t, activationTime, durangoTime, 0) + coreVM, _, proVM, db := initTestProposerVM(t, activationTime, durangoTime, 0) coreOracleBlkID := ids.GenerateTestID() coreOracleBlk := &TestOptionsBlock{ @@ -581,8 +581,8 @@ func TestOptionTimestampValidity(t *testing.T) { StatusV: choices.Processing, }, BytesV: []byte{1}, - ParentV: coreGenBlk.ID(), - HeightV: coreGenBlk.Height() + 1, + ParentV: snowmantest.GenesisID, + HeightV: snowmantest.GenesisHeight + 1, }, opts: [2]snowman.Block{ &snowmantest.Block{ @@ -592,7 +592,7 @@ func TestOptionTimestampValidity(t *testing.T) { }, BytesV: []byte{2}, ParentV: coreOracleBlkID, - HeightV: coreGenBlk.Height() + 2, + HeightV: snowmantest.GenesisHeight + 2, }, &snowmantest.Block{ TestDecidable: choices.TestDecidable{ @@ -601,14 +601,14 @@ func TestOptionTimestampValidity(t *testing.T) { }, BytesV: []byte{3}, ParentV: coreOracleBlkID, - HeightV: coreGenBlk.Height() + 2, + HeightV: snowmantest.GenesisHeight + 2, }, }, } oracleBlkTime := proVM.Time().Truncate(time.Second) statelessBlock, err := block.BuildUnsigned( - coreGenBlk.ID(), + snowmantest.GenesisID, oracleBlkTime, 0, coreOracleBlk.Bytes(), @@ -617,8 +617,8 @@ func TestOptionTimestampValidity(t *testing.T) { coreVM.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { switch blkID { - case coreGenBlk.ID(): - return coreGenBlk, nil + case snowmantest.GenesisID: + return snowmantest.Genesis, nil case coreOracleBlk.ID(): return coreOracleBlk, nil case coreOracleBlk.opts[0].ID(): @@ -631,8 +631,8 @@ func TestOptionTimestampValidity(t *testing.T) { } coreVM.ParseBlockF = func(_ context.Context, b []byte) (snowman.Block, error) { switch { - case bytes.Equal(b, coreGenBlk.Bytes()): - return coreGenBlk, nil + case bytes.Equal(b, snowmantest.GenesisBytes): + return snowmantest.Genesis, nil case bytes.Equal(b, coreOracleBlk.Bytes()): return coreOracleBlk, nil case bytes.Equal(b, coreOracleBlk.opts[0].Bytes()): @@ -708,8 +708,8 @@ func TestOptionTimestampValidity(t *testing.T) { coreVM.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { switch blkID { - case coreGenBlk.ID(): - return coreGenBlk, nil + case snowmantest.GenesisID: + return snowmantest.Genesis, nil case coreOracleBlk.ID(): return coreOracleBlk, nil case coreOracleBlk.opts[0].ID(): @@ -722,8 +722,8 @@ func TestOptionTimestampValidity(t *testing.T) { } coreVM.ParseBlockF = func(_ context.Context, b []byte) (snowman.Block, error) { switch { - case bytes.Equal(b, coreGenBlk.Bytes()): - return coreGenBlk, nil + case bytes.Equal(b, snowmantest.GenesisBytes): + return snowmantest.Genesis, nil case bytes.Equal(b, coreOracleBlk.Bytes()): return coreOracleBlk, nil case bytes.Equal(b, coreOracleBlk.opts[0].Bytes()): diff --git a/vms/proposervm/pre_fork_block_test.go b/vms/proposervm/pre_fork_block_test.go index 5266e9488c0c..f22e6b299084 100644 --- a/vms/proposervm/pre_fork_block_test.go +++ b/vms/proposervm/pre_fork_block_test.go @@ -55,7 +55,7 @@ func TestOracle_PreForkBlkCanBuiltOnPreForkOption(t *testing.T) { activationTime = mockable.MaxTime durangoTime = activationTime ) - coreVM, _, proVM, coreGenBlk, _ := initTestProposerVM(t, activationTime, durangoTime, 0) + coreVM, _, proVM, _ := initTestProposerVM(t, activationTime, durangoTime, 0) defer func() { require.NoError(proVM.Shutdown(context.Background())) }() @@ -68,7 +68,7 @@ func TestOracle_PreForkBlkCanBuiltOnPreForkOption(t *testing.T) { StatusV: choices.Processing, }, BytesV: []byte{1}, - ParentV: coreGenBlk.ID(), + ParentV: snowmantest.GenesisID, }, } oracleCoreBlk.opts = [2]snowman.Block{ @@ -95,8 +95,8 @@ func TestOracle_PreForkBlkCanBuiltOnPreForkOption(t *testing.T) { } coreVM.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { switch blkID { - case coreGenBlk.ID(): - return coreGenBlk, nil + case snowmantest.GenesisID: + return snowmantest.Genesis, nil case oracleCoreBlk.ID(): return oracleCoreBlk, nil case oracleCoreBlk.opts[0].ID(): @@ -147,7 +147,7 @@ func TestOracle_PostForkBlkCanBuiltOnPreForkOption(t *testing.T) { activationTime = snowmantest.GenesisTimestamp.Add(10 * time.Second) durangoTime = activationTime ) - coreVM, _, proVM, coreGenBlk, _ := initTestProposerVM(t, activationTime, durangoTime, 0) + coreVM, _, proVM, _ := initTestProposerVM(t, activationTime, durangoTime, 0) defer func() { require.NoError(proVM.Shutdown(context.Background())) }() @@ -160,7 +160,7 @@ func TestOracle_PostForkBlkCanBuiltOnPreForkOption(t *testing.T) { StatusV: choices.Processing, }, BytesV: []byte{1}, - ParentV: coreGenBlk.ID(), + ParentV: snowmantest.GenesisID, TimestampV: activationTime.Add(-1 * time.Second), }, } @@ -192,8 +192,8 @@ func TestOracle_PostForkBlkCanBuiltOnPreForkOption(t *testing.T) { } coreVM.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { switch blkID { - case coreGenBlk.ID(): - return coreGenBlk, nil + case snowmantest.GenesisID: + return snowmantest.Genesis, nil case oracleCoreBlk.ID(): return oracleCoreBlk, nil case oracleCoreBlk.opts[0].ID(): @@ -244,12 +244,12 @@ func TestBlockVerify_PreFork_ParentChecks(t *testing.T) { activationTime = snowmantest.GenesisTimestamp.Add(10 * time.Second) durangoTime = activationTime ) - coreVM, _, proVM, coreGenBlk, _ := initTestProposerVM(t, activationTime, durangoTime, 0) + coreVM, _, proVM, _ := initTestProposerVM(t, activationTime, durangoTime, 0) defer func() { require.NoError(proVM.Shutdown(context.Background())) }() - require.True(coreGenBlk.Timestamp().Before(activationTime)) + require.True(snowmantest.GenesisTimestamp.Before(activationTime)) // create parent block ... parentCoreBlk := &snowmantest.Block{ @@ -258,16 +258,16 @@ func TestBlockVerify_PreFork_ParentChecks(t *testing.T) { StatusV: choices.Processing, }, BytesV: []byte{1}, - ParentV: coreGenBlk.ID(), - TimestampV: coreGenBlk.Timestamp(), + ParentV: snowmantest.GenesisID, + TimestampV: snowmantest.GenesisTimestamp, } coreVM.BuildBlockF = func(context.Context) (snowman.Block, error) { return parentCoreBlk, nil } coreVM.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { switch blkID { - case coreGenBlk.ID(): - return coreGenBlk, nil + case snowmantest.GenesisID: + return snowmantest.Genesis, nil case parentCoreBlk.ID(): return parentCoreBlk, nil default: @@ -276,8 +276,8 @@ func TestBlockVerify_PreFork_ParentChecks(t *testing.T) { } coreVM.ParseBlockF = func(_ context.Context, b []byte) (snowman.Block, error) { switch { - case bytes.Equal(b, coreGenBlk.Bytes()): - return coreGenBlk, nil + case bytes.Equal(b, snowmantest.GenesisBytes): + return snowmantest.Genesis, nil case bytes.Equal(b, parentCoreBlk.Bytes()): return parentCoreBlk, nil default: @@ -323,12 +323,12 @@ func TestBlockVerify_BlocksBuiltOnPreForkGenesis(t *testing.T) { activationTime = snowmantest.GenesisTimestamp.Add(10 * time.Second) durangoTime = activationTime ) - coreVM, _, proVM, coreGenBlk, _ := initTestProposerVM(t, activationTime, durangoTime, 0) + coreVM, _, proVM, _ := initTestProposerVM(t, activationTime, durangoTime, 0) defer func() { require.NoError(proVM.Shutdown(context.Background())) }() - require.True(coreGenBlk.Timestamp().Before(activationTime)) + require.True(snowmantest.GenesisTimestamp.Before(activationTime)) preActivationTime := activationTime.Add(-1 * time.Second) proVM.Set(preActivationTime) @@ -338,7 +338,7 @@ func TestBlockVerify_BlocksBuiltOnPreForkGenesis(t *testing.T) { StatusV: choices.Processing, }, BytesV: []byte{1}, - ParentV: coreGenBlk.ID(), + ParentV: snowmantest.GenesisID, TimestampV: preActivationTime, VerifyV: nil, } @@ -355,7 +355,7 @@ func TestBlockVerify_BlocksBuiltOnPreForkGenesis(t *testing.T) { // postFork block does NOT verify if parent is before fork activation time postForkStatelessChild, err := statelessblock.Build( - coreGenBlk.ID(), + snowmantest.GenesisID, coreBlk.Timestamp(), 0, // pChainHeight proVM.StakingCertLeaf, @@ -400,8 +400,8 @@ func TestBlockVerify_BlocksBuiltOnPreForkGenesis(t *testing.T) { } coreVM.GetBlockF = func(_ context.Context, id ids.ID) (snowman.Block, error) { switch id { - case coreGenBlk.ID(): - return coreGenBlk, nil + case snowmantest.GenesisID: + return snowmantest.Genesis, nil case coreBlk.ID(): return coreBlk, nil default: @@ -431,8 +431,8 @@ func TestBlockVerify_BlocksBuiltOnPreForkGenesis(t *testing.T) { } coreVM.GetBlockF = func(_ context.Context, id ids.ID) (snowman.Block, error) { switch id { - case coreGenBlk.ID(): - return coreGenBlk, nil + case snowmantest.GenesisID: + return snowmantest.Genesis, nil case coreBlk.ID(): return coreBlk, nil case secondCoreBlk.ID(): @@ -457,7 +457,7 @@ func TestBlockVerify_BlocksBuiltOnPostForkGenesis(t *testing.T) { activationTime = snowmantest.GenesisTimestamp.Add(-1 * time.Second) durangoTime = activationTime ) - coreVM, _, proVM, coreGenBlk, _ := initTestProposerVM(t, activationTime, durangoTime, 0) + coreVM, _, proVM, _ := initTestProposerVM(t, activationTime, durangoTime, 0) proVM.Set(activationTime) defer func() { require.NoError(proVM.Shutdown(context.Background())) @@ -470,8 +470,8 @@ func TestBlockVerify_BlocksBuiltOnPostForkGenesis(t *testing.T) { StatusV: choices.Processing, }, BytesV: []byte{1}, - ParentV: coreGenBlk.ID(), - TimestampV: coreGenBlk.Timestamp(), + ParentV: snowmantest.GenesisID, + TimestampV: snowmantest.GenesisTimestamp, VerifyV: nil, } coreVM.BuildBlockF = func(context.Context) (snowman.Block, error) { @@ -502,7 +502,7 @@ func TestBlockAccept_PreFork_SetsLastAcceptedBlock(t *testing.T) { activationTime = mockable.MaxTime durangoTime = activationTime ) - coreVM, _, proVM, coreGenBlk, _ := initTestProposerVM(t, activationTime, durangoTime, 0) + coreVM, _, proVM, _ := initTestProposerVM(t, activationTime, durangoTime, 0) defer func() { require.NoError(proVM.Shutdown(context.Background())) }() @@ -513,15 +513,15 @@ func TestBlockAccept_PreFork_SetsLastAcceptedBlock(t *testing.T) { StatusV: choices.Processing, }, BytesV: []byte{1}, - ParentV: coreGenBlk.ID(), + ParentV: snowmantest.GenesisID, } coreVM.BuildBlockF = func(context.Context) (snowman.Block, error) { return coreBlk, nil } coreVM.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { switch blkID { - case coreGenBlk.ID(): - return coreGenBlk, nil + case snowmantest.GenesisID: + return snowmantest.Genesis, nil case coreBlk.ID(): return coreBlk, nil default: @@ -530,8 +530,8 @@ func TestBlockAccept_PreFork_SetsLastAcceptedBlock(t *testing.T) { } coreVM.ParseBlockF = func(_ context.Context, b []byte) (snowman.Block, error) { switch { - case bytes.Equal(b, coreGenBlk.Bytes()): - return coreGenBlk, nil + case bytes.Equal(b, snowmantest.GenesisBytes): + return snowmantest.Genesis, nil case bytes.Equal(b, coreBlk.Bytes()): return coreBlk, nil default: @@ -549,7 +549,7 @@ func TestBlockAccept_PreFork_SetsLastAcceptedBlock(t *testing.T) { if coreBlk.Status() == choices.Accepted { return coreBlk.ID(), nil } - return coreGenBlk.ID(), nil + return snowmantest.GenesisID, nil } acceptedID, err := proVM.LastAccepted(context.Background()) require.NoError(err) @@ -564,7 +564,7 @@ func TestBlockReject_PreForkBlock_InnerBlockIsRejected(t *testing.T) { activationTime = mockable.MaxTime durangoTime = activationTime ) - coreVM, _, proVM, coreGenBlk, _ := initTestProposerVM(t, activationTime, durangoTime, 0) + coreVM, _, proVM, _ := initTestProposerVM(t, activationTime, durangoTime, 0) defer func() { require.NoError(proVM.Shutdown(context.Background())) }() @@ -575,8 +575,8 @@ func TestBlockReject_PreForkBlock_InnerBlockIsRejected(t *testing.T) { StatusV: choices.Processing, }, BytesV: []byte{1}, - ParentV: coreGenBlk.ID(), - HeightV: coreGenBlk.Height() + 1, + ParentV: snowmantest.GenesisID, + HeightV: snowmantest.GenesisHeight + 1, } coreVM.BuildBlockF = func(context.Context) (snowman.Block, error) { return coreBlk, nil @@ -599,12 +599,12 @@ func TestBlockVerify_ForkBlockIsOracleBlock(t *testing.T) { activationTime = snowmantest.GenesisTimestamp.Add(10 * time.Second) durangoTime = activationTime ) - coreVM, _, proVM, coreGenBlk, _ := initTestProposerVM(t, activationTime, durangoTime, 0) + coreVM, _, proVM, _ := initTestProposerVM(t, activationTime, durangoTime, 0) defer func() { require.NoError(proVM.Shutdown(context.Background())) }() - require.True(coreGenBlk.Timestamp().Before(activationTime)) + require.True(snowmantest.GenesisTimestamp.Before(activationTime)) postActivationTime := activationTime.Add(time.Second) proVM.Set(postActivationTime) @@ -616,7 +616,7 @@ func TestBlockVerify_ForkBlockIsOracleBlock(t *testing.T) { StatusV: choices.Processing, }, BytesV: []byte{1}, - ParentV: coreGenBlk.ID(), + ParentV: snowmantest.GenesisID, TimestampV: postActivationTime, }, opts: [2]snowman.Block{ @@ -643,8 +643,8 @@ func TestBlockVerify_ForkBlockIsOracleBlock(t *testing.T) { coreVM.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { switch blkID { - case coreGenBlk.ID(): - return coreGenBlk, nil + case snowmantest.GenesisID: + return snowmantest.Genesis, nil case coreBlk.ID(): return coreBlk, nil case coreBlk.opts[0].ID(): @@ -657,8 +657,8 @@ func TestBlockVerify_ForkBlockIsOracleBlock(t *testing.T) { } coreVM.ParseBlockF = func(_ context.Context, b []byte) (snowman.Block, error) { switch { - case bytes.Equal(b, coreGenBlk.Bytes()): - return coreGenBlk, nil + case bytes.Equal(b, snowmantest.GenesisBytes): + return snowmantest.Genesis, nil case bytes.Equal(b, coreBlk.Bytes()): return coreBlk, nil case bytes.Equal(b, coreBlk.opts[0].Bytes()): @@ -693,12 +693,12 @@ func TestBlockVerify_ForkBlockIsOracleBlockButChildrenAreSigned(t *testing.T) { activationTime = snowmantest.GenesisTimestamp.Add(10 * time.Second) durangoTime = activationTime ) - coreVM, _, proVM, coreGenBlk, _ := initTestProposerVM(t, activationTime, durangoTime, 0) + coreVM, _, proVM, _ := initTestProposerVM(t, activationTime, durangoTime, 0) defer func() { require.NoError(proVM.Shutdown(context.Background())) }() - require.True(coreGenBlk.Timestamp().Before(activationTime)) + require.True(snowmantest.GenesisTimestamp.Before(activationTime)) postActivationTime := activationTime.Add(time.Second) proVM.Set(postActivationTime) @@ -710,7 +710,7 @@ func TestBlockVerify_ForkBlockIsOracleBlockButChildrenAreSigned(t *testing.T) { StatusV: choices.Processing, }, BytesV: []byte{1}, - ParentV: coreGenBlk.ID(), + ParentV: snowmantest.GenesisID, TimestampV: postActivationTime, }, opts: [2]snowman.Block{ @@ -737,8 +737,8 @@ func TestBlockVerify_ForkBlockIsOracleBlockButChildrenAreSigned(t *testing.T) { coreVM.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { switch blkID { - case coreGenBlk.ID(): - return coreGenBlk, nil + case snowmantest.GenesisID: + return snowmantest.Genesis, nil case coreBlk.ID(): return coreBlk, nil case coreBlk.opts[0].ID(): @@ -751,8 +751,8 @@ func TestBlockVerify_ForkBlockIsOracleBlockButChildrenAreSigned(t *testing.T) { } coreVM.ParseBlockF = func(_ context.Context, b []byte) (snowman.Block, error) { switch { - case bytes.Equal(b, coreGenBlk.Bytes()): - return coreGenBlk, nil + case bytes.Equal(b, snowmantest.GenesisBytes): + return snowmantest.Genesis, nil case bytes.Equal(b, coreBlk.Bytes()): return coreBlk, nil case bytes.Equal(b, coreBlk.opts[0].Bytes()): diff --git a/vms/proposervm/vm_byzantine_test.go b/vms/proposervm/vm_byzantine_test.go index e145570c2ffd..a80338c35c86 100644 --- a/vms/proposervm/vm_byzantine_test.go +++ b/vms/proposervm/vm_byzantine_test.go @@ -37,7 +37,7 @@ func TestInvalidByzantineProposerParent(t *testing.T) { activationTime = time.Unix(0, 0) durangoTime = activationTime ) - coreVM, _, proVM, gBlock, _ := initTestProposerVM(t, activationTime, durangoTime, 0) + coreVM, _, proVM, _ := initTestProposerVM(t, activationTime, durangoTime, 0) defer func() { require.NoError(proVM.Shutdown(context.Background())) }() @@ -48,8 +48,8 @@ func TestInvalidByzantineProposerParent(t *testing.T) { StatusV: choices.Processing, }, BytesV: []byte{1}, - ParentV: gBlock.ID(), - HeightV: gBlock.Height() + 1, + ParentV: snowmantest.GenesisID, + HeightV: snowmantest.GenesisHeight + 1, } coreVM.BuildBlockF = func(context.Context) (snowman.Block, error) { return xBlock, nil @@ -108,8 +108,8 @@ func TestInvalidByzantineProposerOracleParent(t *testing.T) { activationTime = time.Unix(0, 0) durangoTime = activationTime ) - coreVM, _, proVM, coreGenBlk, _ := initTestProposerVM(t, activationTime, durangoTime, 0) - proVM.Set(coreGenBlk.Timestamp()) + coreVM, _, proVM, _ := initTestProposerVM(t, activationTime, durangoTime, 0) + proVM.Set(snowmantest.GenesisTimestamp) defer func() { require.NoError(proVM.Shutdown(context.Background())) }() @@ -122,7 +122,7 @@ func TestInvalidByzantineProposerOracleParent(t *testing.T) { StatusV: choices.Processing, }, BytesV: []byte{1}, - ParentV: coreGenBlk.ID(), + ParentV: snowmantest.GenesisID, }, opts: [2]snowman.Block{ &snowmantest.Block{ @@ -149,8 +149,8 @@ func TestInvalidByzantineProposerOracleParent(t *testing.T) { } coreVM.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { switch blkID { - case coreGenBlk.ID(): - return coreGenBlk, nil + case snowmantest.GenesisID: + return snowmantest.Genesis, nil case xBlock.ID(): return xBlock, nil case xBlock.opts[0].ID(): @@ -163,8 +163,8 @@ func TestInvalidByzantineProposerOracleParent(t *testing.T) { } coreVM.ParseBlockF = func(_ context.Context, b []byte) (snowman.Block, error) { switch { - case bytes.Equal(b, coreGenBlk.Bytes()): - return coreGenBlk, nil + case bytes.Equal(b, snowmantest.GenesisBytes): + return snowmantest.Genesis, nil case bytes.Equal(b, xBlock.Bytes()): return xBlock, nil case bytes.Equal(b, xBlock.opts[0].Bytes()): @@ -217,7 +217,7 @@ func TestInvalidByzantineProposerPreForkParent(t *testing.T) { activationTime = time.Unix(0, 0) durangoTime = activationTime ) - coreVM, _, proVM, gBlock, _ := initTestProposerVM(t, activationTime, durangoTime, 0) + coreVM, _, proVM, _ := initTestProposerVM(t, activationTime, durangoTime, 0) defer func() { require.NoError(proVM.Shutdown(context.Background())) }() @@ -228,8 +228,8 @@ func TestInvalidByzantineProposerPreForkParent(t *testing.T) { StatusV: choices.Processing, }, BytesV: []byte{1}, - ParentV: gBlock.ID(), - HeightV: gBlock.Height() + 1, + ParentV: snowmantest.GenesisID, + HeightV: snowmantest.GenesisHeight + 1, } coreVM.BuildBlockF = func(context.Context) (snowman.Block, error) { return xBlock, nil @@ -248,8 +248,8 @@ func TestInvalidByzantineProposerPreForkParent(t *testing.T) { coreVM.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { switch blkID { - case gBlock.ID(): - return gBlock, nil + case snowmantest.GenesisID: + return snowmantest.Genesis, nil case xBlock.ID(): return xBlock, nil case yBlock.ID(): @@ -260,8 +260,8 @@ func TestInvalidByzantineProposerPreForkParent(t *testing.T) { } coreVM.ParseBlockF = func(_ context.Context, blockBytes []byte) (snowman.Block, error) { switch { - case bytes.Equal(blockBytes, gBlock.Bytes()): - return gBlock, nil + case bytes.Equal(blockBytes, snowmantest.GenesisBytes): + return snowmantest.Genesis, nil case bytes.Equal(blockBytes, xBlock.Bytes()): return xBlock, nil case bytes.Equal(blockBytes, yBlock.Bytes()): @@ -307,8 +307,8 @@ func TestBlockVerify_PostForkOption_FaultyParent(t *testing.T) { activationTime = time.Unix(0, 0) durangoTime = activationTime ) - coreVM, _, proVM, coreGenBlk, _ := initTestProposerVM(t, activationTime, durangoTime, 0) - proVM.Set(coreGenBlk.Timestamp()) + coreVM, _, proVM, _ := initTestProposerVM(t, activationTime, durangoTime, 0) + proVM.Set(snowmantest.GenesisTimestamp) defer func() { require.NoError(proVM.Shutdown(context.Background())) }() @@ -320,7 +320,7 @@ func TestBlockVerify_PostForkOption_FaultyParent(t *testing.T) { StatusV: choices.Processing, }, BytesV: []byte{1}, - ParentV: coreGenBlk.ID(), + ParentV: snowmantest.GenesisID, }, opts: [2]snowman.Block{ &snowmantest.Block{ @@ -329,7 +329,7 @@ func TestBlockVerify_PostForkOption_FaultyParent(t *testing.T) { StatusV: choices.Processing, }, BytesV: []byte{2}, - ParentV: coreGenBlk.ID(), // valid block should reference xBlock + ParentV: snowmantest.GenesisID, // valid block should reference xBlock }, &snowmantest.Block{ TestDecidable: choices.TestDecidable{ @@ -337,7 +337,7 @@ func TestBlockVerify_PostForkOption_FaultyParent(t *testing.T) { StatusV: choices.Processing, }, BytesV: []byte{3}, - ParentV: coreGenBlk.ID(), // valid block should reference xBlock + ParentV: snowmantest.GenesisID, // valid block should reference xBlock }, }, } @@ -347,8 +347,8 @@ func TestBlockVerify_PostForkOption_FaultyParent(t *testing.T) { } coreVM.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { switch blkID { - case coreGenBlk.ID(): - return coreGenBlk, nil + case snowmantest.GenesisID: + return snowmantest.Genesis, nil case xBlock.ID(): return xBlock, nil case xBlock.opts[0].ID(): @@ -361,8 +361,8 @@ func TestBlockVerify_PostForkOption_FaultyParent(t *testing.T) { } coreVM.ParseBlockF = func(_ context.Context, b []byte) (snowman.Block, error) { switch { - case bytes.Equal(b, coreGenBlk.Bytes()): - return coreGenBlk, nil + case bytes.Equal(b, snowmantest.GenesisBytes): + return snowmantest.Genesis, nil case bytes.Equal(b, xBlock.Bytes()): return xBlock, nil case bytes.Equal(b, xBlock.opts[0].Bytes()): @@ -407,8 +407,8 @@ func TestBlockVerify_InvalidPostForkOption(t *testing.T) { activationTime = time.Unix(0, 0) durangoTime = activationTime ) - coreVM, _, proVM, coreGenBlk, _ := initTestProposerVM(t, activationTime, durangoTime, 0) - proVM.Set(coreGenBlk.Timestamp()) + coreVM, _, proVM, _ := initTestProposerVM(t, activationTime, durangoTime, 0) + proVM.Set(snowmantest.GenesisTimestamp) defer func() { require.NoError(proVM.Shutdown(context.Background())) }() @@ -422,7 +422,7 @@ func TestBlockVerify_InvalidPostForkOption(t *testing.T) { StatusV: choices.Processing, }, BytesV: []byte{1}, - ParentV: coreGenBlk.ID(), + ParentV: snowmantest.GenesisID, }, opts: [2]snowman.Block{ &snowmantest.Block{ @@ -455,13 +455,13 @@ func TestBlockVerify_InvalidPostForkOption(t *testing.T) { StatusV: choices.Processing, }, BytesV: []byte{1}, - ParentV: coreGenBlk.ID(), - HeightV: coreGenBlk.Height() + 1, + ParentV: snowmantest.GenesisID, + HeightV: snowmantest.GenesisHeight + 1, } ySlb, err := block.BuildUnsigned( - coreGenBlk.ID(), - coreGenBlk.Timestamp(), + snowmantest.GenesisID, + snowmantest.GenesisTimestamp, uint64(2000), yBlock.Bytes(), ) @@ -534,7 +534,7 @@ func TestBlockVerify_InvalidPostForkOption(t *testing.T) { StatusV: choices.Processing, }, BytesV: []byte{1}, - ParentV: coreGenBlk.ID(), + ParentV: snowmantest.GenesisID, }, opts: [2]snowman.Block{ &snowmantest.Block{ @@ -591,7 +591,7 @@ func TestGetBlock_MutatedSignature(t *testing.T) { activationTime = time.Unix(0, 0) durangoTime = activationTime ) - coreVM, valState, proVM, coreGenBlk, _ := initTestProposerVM(t, activationTime, durangoTime, 0) + coreVM, valState, proVM, _ := initTestProposerVM(t, activationTime, durangoTime, 0) defer func() { require.NoError(proVM.Shutdown(context.Background())) }() @@ -606,7 +606,7 @@ func TestGetBlock_MutatedSignature(t *testing.T) { }, nil } - proVM.Set(coreGenBlk.Timestamp()) + proVM.Set(snowmantest.GenesisTimestamp) // Create valid core blocks to build our chain on. coreBlk0 := &snowmantest.Block{ @@ -615,8 +615,8 @@ func TestGetBlock_MutatedSignature(t *testing.T) { StatusV: choices.Processing, }, BytesV: []byte{1}, - ParentV: coreGenBlk.ID(), - HeightV: coreGenBlk.Height() + 1, + ParentV: snowmantest.GenesisID, + HeightV: snowmantest.GenesisHeight + 1, } coreBlk1 := &snowmantest.Block{ @@ -631,8 +631,8 @@ func TestGetBlock_MutatedSignature(t *testing.T) { coreVM.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { switch blkID { - case coreGenBlk.ID(): - return coreGenBlk, nil + case snowmantest.GenesisID: + return snowmantest.Genesis, nil case coreBlk0.ID(): return coreBlk0, nil case coreBlk1.ID(): @@ -643,8 +643,8 @@ func TestGetBlock_MutatedSignature(t *testing.T) { } coreVM.ParseBlockF = func(_ context.Context, b []byte) (snowman.Block, error) { switch { - case bytes.Equal(b, coreGenBlk.Bytes()): - return coreGenBlk, nil + case bytes.Equal(b, snowmantest.GenesisBytes): + return snowmantest.Genesis, nil case bytes.Equal(b, coreBlk0.Bytes()): return coreBlk0, nil case bytes.Equal(b, coreBlk1.Bytes()): diff --git a/vms/proposervm/vm_test.go b/vms/proposervm/vm_test.go index 5177727c56be..0f835813f38a 100644 --- a/vms/proposervm/vm_test.go +++ b/vms/proposervm/vm_test.go @@ -80,21 +80,10 @@ func initTestProposerVM( *fullVM, *validators.TestState, *VM, - *snowmantest.Block, database.Database, ) { require := require.New(t) - coreGenBlk := &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.GenerateTestID(), - StatusV: choices.Accepted, - }, - HeightV: 0, - TimestampV: snowmantest.GenesisTimestamp, - BytesV: []byte{0}, - } - initialState := []byte("genesis state") coreVM := &fullVM{ TestVM: &block.TestVM{ @@ -114,20 +103,20 @@ func initTestProposerVM( return nil } coreVM.LastAcceptedF = func(context.Context) (ids.ID, error) { - return coreGenBlk.ID(), nil + return snowmantest.GenesisID, nil } coreVM.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { switch { - case blkID == coreGenBlk.ID(): - return coreGenBlk, nil + case blkID == snowmantest.GenesisID: + return snowmantest.Genesis, nil default: return nil, errUnknownBlock } } coreVM.ParseBlockF = func(_ context.Context, b []byte) (snowman.Block, error) { switch { - case bytes.Equal(b, coreGenBlk.Bytes()): - return coreGenBlk, nil + case bytes.Equal(b, snowmantest.GenesisBytes): + return snowmantest.Genesis, nil default: return nil, errUnknownBlock } @@ -150,7 +139,7 @@ func initTestProposerVM( T: t, } valState.GetMinimumHeightF = func(context.Context) (uint64, error) { - return coreGenBlk.HeightV, nil + return snowmantest.GenesisHeight, nil } valState.GetCurrentHeightF = func(context.Context) (uint64, error) { return defaultPChainHeight, nil @@ -204,11 +193,11 @@ func initTestProposerVM( coreVM.InitializeF = nil require.NoError(proVM.SetState(context.Background(), snow.NormalOp)) - require.NoError(proVM.SetPreference(context.Background(), coreGenBlk.IDV)) + require.NoError(proVM.SetPreference(context.Background(), snowmantest.GenesisID)) - proVM.Set(coreGenBlk.Timestamp()) + proVM.Set(snowmantest.GenesisTimestamp) - return coreVM, valState, proVM, coreGenBlk, db + return coreVM, valState, proVM, db } func waitForProposerWindow(vm *VM, chainTip snowman.Block, pchainHeight uint64) error { @@ -248,7 +237,7 @@ func TestBuildBlockTimestampAreRoundedToSeconds(t *testing.T) { activationTime = time.Unix(0, 0) durangoTime = activationTime ) - coreVM, _, proVM, coreGenBlk, _ := initTestProposerVM(t, activationTime, durangoTime, 0) + coreVM, _, proVM, _ := initTestProposerVM(t, activationTime, durangoTime, 0) defer func() { require.NoError(proVM.Shutdown(context.Background())) }() @@ -262,8 +251,8 @@ func TestBuildBlockTimestampAreRoundedToSeconds(t *testing.T) { StatusV: choices.Processing, }, BytesV: []byte{1}, - ParentV: coreGenBlk.ID(), - HeightV: coreGenBlk.Height() + 1, + ParentV: snowmantest.GenesisID, + HeightV: snowmantest.GenesisHeight + 1, } coreVM.BuildBlockF = func(context.Context) (snowman.Block, error) { return coreBlk, nil @@ -284,7 +273,7 @@ func TestBuildBlockIsIdempotent(t *testing.T) { activationTime = time.Unix(0, 0) durangoTime = activationTime ) - coreVM, _, proVM, coreGenBlk, _ := initTestProposerVM(t, activationTime, durangoTime, 0) + coreVM, _, proVM, _ := initTestProposerVM(t, activationTime, durangoTime, 0) defer func() { require.NoError(proVM.Shutdown(context.Background())) }() @@ -295,8 +284,8 @@ func TestBuildBlockIsIdempotent(t *testing.T) { StatusV: choices.Processing, }, BytesV: []byte{1}, - ParentV: coreGenBlk.ID(), - HeightV: coreGenBlk.Height() + 1, + ParentV: snowmantest.GenesisID, + HeightV: snowmantest.GenesisHeight + 1, } coreVM.BuildBlockF = func(context.Context) (snowman.Block, error) { return coreBlk, nil @@ -322,7 +311,7 @@ func TestFirstProposerBlockIsBuiltOnTopOfGenesis(t *testing.T) { activationTime = time.Unix(0, 0) durangoTime = activationTime ) - coreVM, _, proVM, coreGenBlk, _ := initTestProposerVM(t, activationTime, durangoTime, 0) + coreVM, _, proVM, _ := initTestProposerVM(t, activationTime, durangoTime, 0) defer func() { require.NoError(proVM.Shutdown(context.Background())) }() @@ -333,8 +322,8 @@ func TestFirstProposerBlockIsBuiltOnTopOfGenesis(t *testing.T) { StatusV: choices.Processing, }, BytesV: []byte{1}, - ParentV: coreGenBlk.ID(), - HeightV: coreGenBlk.Height() + 1, + ParentV: snowmantest.GenesisID, + HeightV: snowmantest.GenesisHeight + 1, } coreVM.BuildBlockF = func(context.Context) (snowman.Block, error) { return coreBlk, nil @@ -359,7 +348,7 @@ func TestProposerBlocksAreBuiltOnPreferredProBlock(t *testing.T) { activationTime = time.Unix(0, 0) durangoTime = activationTime ) - coreVM, _, proVM, coreGenBlk, _ := initTestProposerVM(t, activationTime, durangoTime, 0) + coreVM, _, proVM, _ := initTestProposerVM(t, activationTime, durangoTime, 0) defer func() { require.NoError(proVM.Shutdown(context.Background())) }() @@ -371,8 +360,8 @@ func TestProposerBlocksAreBuiltOnPreferredProBlock(t *testing.T) { StatusV: choices.Processing, }, BytesV: []byte{1}, - ParentV: coreGenBlk.ID(), - HeightV: coreGenBlk.Height() + 1, + ParentV: snowmantest.GenesisID, + HeightV: snowmantest.GenesisHeight + 1, } coreVM.BuildBlockF = func(context.Context) (snowman.Block, error) { return coreBlk1, nil @@ -386,8 +375,8 @@ func TestProposerBlocksAreBuiltOnPreferredProBlock(t *testing.T) { StatusV: choices.Processing, }, BytesV: []byte{2}, - ParentV: coreGenBlk.ID(), - HeightV: coreGenBlk.Height() + 1, + ParentV: snowmantest.GenesisID, + HeightV: snowmantest.GenesisHeight + 1, } coreVM.BuildBlockF = func(context.Context) (snowman.Block, error) { return coreBlk2, nil @@ -455,7 +444,7 @@ func TestCoreBlocksMustBeBuiltOnPreferredCoreBlock(t *testing.T) { activationTime = time.Unix(0, 0) durangoTime = activationTime ) - coreVM, _, proVM, coreGenBlk, _ := initTestProposerVM(t, activationTime, durangoTime, 0) + coreVM, _, proVM, _ := initTestProposerVM(t, activationTime, durangoTime, 0) defer func() { require.NoError(proVM.Shutdown(context.Background())) }() @@ -466,8 +455,8 @@ func TestCoreBlocksMustBeBuiltOnPreferredCoreBlock(t *testing.T) { StatusV: choices.Processing, }, BytesV: []byte{1}, - ParentV: coreGenBlk.ID(), - HeightV: coreGenBlk.Height() + 1, + ParentV: snowmantest.GenesisID, + HeightV: snowmantest.GenesisHeight + 1, } coreVM.BuildBlockF = func(context.Context) (snowman.Block, error) { return coreBlk1, nil @@ -481,8 +470,8 @@ func TestCoreBlocksMustBeBuiltOnPreferredCoreBlock(t *testing.T) { StatusV: choices.Processing, }, BytesV: []byte{2}, - ParentV: coreGenBlk.ID(), - HeightV: coreGenBlk.Height() + 1, + ParentV: snowmantest.GenesisID, + HeightV: snowmantest.GenesisHeight + 1, } coreVM.BuildBlockF = func(context.Context) (snowman.Block, error) { return coreBlk2, nil @@ -552,7 +541,7 @@ func TestCoreBlockFailureCauseProposerBlockParseFailure(t *testing.T) { activationTime = time.Unix(0, 0) durangoTime = activationTime ) - coreVM, _, proVM, _, _ := initTestProposerVM(t, activationTime, durangoTime, 0) + coreVM, _, proVM, _ := initTestProposerVM(t, activationTime, durangoTime, 0) defer func() { require.NoError(proVM.Shutdown(context.Background())) }() @@ -594,7 +583,7 @@ func TestTwoProBlocksWrappingSameCoreBlockCanBeParsed(t *testing.T) { activationTime = time.Unix(0, 0) durangoTime = activationTime ) - coreVM, _, proVM, gencoreBlk, _ := initTestProposerVM(t, activationTime, durangoTime, 0) + coreVM, _, proVM, _ := initTestProposerVM(t, activationTime, durangoTime, 0) defer func() { require.NoError(proVM.Shutdown(context.Background())) }() @@ -602,8 +591,8 @@ func TestTwoProBlocksWrappingSameCoreBlockCanBeParsed(t *testing.T) { // create two Proposer blocks at the same height innerBlk := &snowmantest.Block{ BytesV: []byte{1}, - ParentV: gencoreBlk.ID(), - HeightV: gencoreBlk.Height() + 1, + ParentV: snowmantest.GenesisID, + HeightV: snowmantest.GenesisHeight + 1, } coreVM.ParseBlockF = func(_ context.Context, b []byte) (snowman.Block, error) { require.Equal(innerBlk.Bytes(), b) @@ -670,7 +659,7 @@ func TestTwoProBlocksWithSameParentCanBothVerify(t *testing.T) { activationTime = time.Unix(0, 0) durangoTime = activationTime ) - coreVM, _, proVM, coreGenBlk, _ := initTestProposerVM(t, activationTime, durangoTime, 0) + coreVM, _, proVM, _ := initTestProposerVM(t, activationTime, durangoTime, 0) defer func() { require.NoError(proVM.Shutdown(context.Background())) }() @@ -678,8 +667,8 @@ func TestTwoProBlocksWithSameParentCanBothVerify(t *testing.T) { // one block is built from this proVM localcoreBlk := &snowmantest.Block{ BytesV: []byte{111}, - ParentV: coreGenBlk.ID(), - HeightV: coreGenBlk.Height() + 1, + ParentV: snowmantest.GenesisID, + HeightV: snowmantest.GenesisHeight + 1, } coreVM.BuildBlockF = func(context.Context) (snowman.Block, error) { return localcoreBlk, nil @@ -692,13 +681,13 @@ func TestTwoProBlocksWithSameParentCanBothVerify(t *testing.T) { // another block with same parent comes from network and is parsed netcoreBlk := &snowmantest.Block{ BytesV: []byte{222}, - ParentV: coreGenBlk.ID(), - HeightV: coreGenBlk.Height() + 1, + ParentV: snowmantest.GenesisID, + HeightV: snowmantest.GenesisHeight + 1, } coreVM.ParseBlockF = func(_ context.Context, b []byte) (snowman.Block, error) { switch { - case bytes.Equal(b, coreGenBlk.Bytes()): - return coreGenBlk, nil + case bytes.Equal(b, snowmantest.GenesisBytes): + return snowmantest.Genesis, nil case bytes.Equal(b, localcoreBlk.Bytes()): return localcoreBlk, nil case bytes.Equal(b, netcoreBlk.Bytes()): @@ -740,7 +729,7 @@ func TestPreFork_Initialize(t *testing.T) { activationTime = mockable.MaxTime durangoTime = activationTime ) - _, _, proVM, coreGenBlk, _ := initTestProposerVM(t, activationTime, durangoTime, 0) + _, _, proVM, _ := initTestProposerVM(t, activationTime, durangoTime, 0) defer func() { require.NoError(proVM.Shutdown(context.Background())) }() @@ -753,7 +742,7 @@ func TestPreFork_Initialize(t *testing.T) { require.NoError(err) require.IsType(&preForkBlock{}, rtvdBlk) - require.Equal(coreGenBlk.Bytes(), rtvdBlk.Bytes()) + require.Equal(snowmantest.GenesisBytes, rtvdBlk.Bytes()) } func TestPreFork_BuildBlock(t *testing.T) { @@ -763,7 +752,7 @@ func TestPreFork_BuildBlock(t *testing.T) { activationTime = mockable.MaxTime durangoTime = activationTime ) - coreVM, _, proVM, coreGenBlk, _ := initTestProposerVM(t, activationTime, durangoTime, 0) + coreVM, _, proVM, _ := initTestProposerVM(t, activationTime, durangoTime, 0) defer func() { require.NoError(proVM.Shutdown(context.Background())) }() @@ -774,8 +763,8 @@ func TestPreFork_BuildBlock(t *testing.T) { StatusV: choices.Processing, }, BytesV: []byte{3}, - ParentV: coreGenBlk.ID(), - HeightV: coreGenBlk.Height() + 1, + ParentV: snowmantest.GenesisID, + HeightV: snowmantest.GenesisHeight + 1, } coreVM.BuildBlockF = func(context.Context) (snowman.Block, error) { return coreBlk, nil @@ -804,7 +793,7 @@ func TestPreFork_ParseBlock(t *testing.T) { activationTime = mockable.MaxTime durangoTime = activationTime ) - coreVM, _, proVM, _, _ := initTestProposerVM(t, activationTime, durangoTime, 0) + coreVM, _, proVM, _ := initTestProposerVM(t, activationTime, durangoTime, 0) defer func() { require.NoError(proVM.Shutdown(context.Background())) }() @@ -843,7 +832,7 @@ func TestPreFork_SetPreference(t *testing.T) { activationTime = mockable.MaxTime durangoTime = activationTime ) - coreVM, _, proVM, coreGenBlk, _ := initTestProposerVM(t, activationTime, durangoTime, 0) + coreVM, _, proVM, _ := initTestProposerVM(t, activationTime, durangoTime, 0) defer func() { require.NoError(proVM.Shutdown(context.Background())) }() @@ -854,9 +843,9 @@ func TestPreFork_SetPreference(t *testing.T) { StatusV: choices.Processing, }, BytesV: []byte{3}, - ParentV: coreGenBlk.ID(), - HeightV: coreGenBlk.Height() + 1, - TimestampV: coreGenBlk.Timestamp(), + ParentV: snowmantest.GenesisID, + HeightV: snowmantest.GenesisHeight + 1, + TimestampV: snowmantest.GenesisTimestamp, } coreVM.BuildBlockF = func(context.Context) (snowman.Block, error) { return coreBlk0, nil @@ -866,8 +855,8 @@ func TestPreFork_SetPreference(t *testing.T) { coreVM.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { switch blkID { - case coreGenBlk.ID(): - return coreGenBlk, nil + case snowmantest.GenesisID: + return snowmantest.Genesis, nil case coreBlk0.ID(): return coreBlk0, nil default: @@ -876,8 +865,8 @@ func TestPreFork_SetPreference(t *testing.T) { } coreVM.ParseBlockF = func(_ context.Context, b []byte) (snowman.Block, error) { switch { - case bytes.Equal(b, coreGenBlk.Bytes()): - return coreGenBlk, nil + case bytes.Equal(b, snowmantest.GenesisBytes): + return snowmantest.Genesis, nil case bytes.Equal(b, coreBlk0.Bytes()): return coreBlk0, nil default: @@ -1116,7 +1105,7 @@ func TestInnerBlockDeduplication(t *testing.T) { activationTime = time.Unix(0, 0) durangoTime = activationTime ) - coreVM, _, proVM, coreGenBlk, _ := initTestProposerVM(t, activationTime, durangoTime, 0) + coreVM, _, proVM, _ := initTestProposerVM(t, activationTime, durangoTime, 0) defer func() { require.NoError(proVM.Shutdown(context.Background())) }() @@ -1127,9 +1116,9 @@ func TestInnerBlockDeduplication(t *testing.T) { StatusV: choices.Processing, }, BytesV: []byte{1}, - ParentV: coreGenBlk.ID(), - HeightV: coreGenBlk.Height() + 1, - TimestampV: coreGenBlk.Timestamp(), + ParentV: snowmantest.GenesisID, + HeightV: snowmantest.GenesisHeight + 1, + TimestampV: snowmantest.GenesisTimestamp, } coreBlk0 := &wrappedBlock{ Block: coreBlk, @@ -1138,14 +1127,14 @@ func TestInnerBlockDeduplication(t *testing.T) { Block: coreBlk, } statelessBlock0, err := statelessblock.BuildUnsigned( - coreGenBlk.ID(), + snowmantest.GenesisID, coreBlk.Timestamp(), 0, coreBlk.Bytes(), ) require.NoError(err) statelessBlock1, err := statelessblock.BuildUnsigned( - coreGenBlk.ID(), + snowmantest.GenesisID, coreBlk.Timestamp(), 1, coreBlk.Bytes(), @@ -1154,8 +1143,8 @@ func TestInnerBlockDeduplication(t *testing.T) { coreVM.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { switch blkID { - case coreGenBlk.ID(): - return coreGenBlk, nil + case snowmantest.GenesisID: + return snowmantest.Genesis, nil case coreBlk0.ID(): return coreBlk0, nil default: @@ -1164,8 +1153,8 @@ func TestInnerBlockDeduplication(t *testing.T) { } coreVM.ParseBlockF = func(_ context.Context, b []byte) (snowman.Block, error) { switch { - case bytes.Equal(b, coreGenBlk.Bytes()): - return coreGenBlk, nil + case bytes.Equal(b, snowmantest.GenesisBytes): + return snowmantest.Genesis, nil case bytes.Equal(b, coreBlk0.Bytes()): return coreBlk0, nil default: @@ -1182,8 +1171,8 @@ func TestInnerBlockDeduplication(t *testing.T) { coreVM.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { switch blkID { - case coreGenBlk.ID(): - return coreGenBlk, nil + case snowmantest.GenesisID: + return snowmantest.Genesis, nil case coreBlk1.ID(): return coreBlk1, nil default: @@ -1192,8 +1181,8 @@ func TestInnerBlockDeduplication(t *testing.T) { } coreVM.ParseBlockF = func(_ context.Context, b []byte) (snowman.Block, error) { switch { - case bytes.Equal(b, coreGenBlk.Bytes()): - return coreGenBlk, nil + case bytes.Equal(b, snowmantest.GenesisBytes): + return snowmantest.Genesis, nil case bytes.Equal(b, coreBlk1.Bytes()): return coreBlk1, nil default: @@ -1416,7 +1405,7 @@ func TestBuildBlockDuringWindow(t *testing.T) { activationTime = time.Unix(0, 0) durangoTime = mockable.MaxTime ) - coreVM, valState, proVM, coreGenBlk, _ := initTestProposerVM(t, activationTime, durangoTime, 0) + coreVM, valState, proVM, _ := initTestProposerVM(t, activationTime, durangoTime, 0) defer func() { require.NoError(proVM.Shutdown(context.Background())) }() @@ -1436,8 +1425,8 @@ func TestBuildBlockDuringWindow(t *testing.T) { StatusV: choices.Processing, }, BytesV: []byte{1}, - ParentV: coreGenBlk.ID(), - HeightV: coreGenBlk.Height() + 1, + ParentV: snowmantest.GenesisID, + HeightV: snowmantest.GenesisHeight + 1, } coreBlk1 := &snowmantest.Block{ TestDecidable: choices.TestDecidable{ @@ -1449,7 +1438,7 @@ func TestBuildBlockDuringWindow(t *testing.T) { HeightV: coreBlk0.Height() + 1, } statelessBlock0, err := statelessblock.BuildUnsigned( - coreGenBlk.ID(), + snowmantest.GenesisID, proVM.Time(), 0, coreBlk0.Bytes(), @@ -1458,8 +1447,8 @@ func TestBuildBlockDuringWindow(t *testing.T) { coreVM.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { switch blkID { - case coreGenBlk.ID(): - return coreGenBlk, nil + case snowmantest.GenesisID: + return snowmantest.Genesis, nil case coreBlk0.ID(): return coreBlk0, nil case coreBlk1.ID(): @@ -1470,8 +1459,8 @@ func TestBuildBlockDuringWindow(t *testing.T) { } coreVM.ParseBlockF = func(_ context.Context, b []byte) (snowman.Block, error) { switch { - case bytes.Equal(b, coreGenBlk.Bytes()): - return coreGenBlk, nil + case bytes.Equal(b, snowmantest.GenesisBytes): + return snowmantest.Genesis, nil case bytes.Equal(b, coreBlk0.Bytes()): return coreBlk0, nil case bytes.Equal(b, coreBlk1.Bytes()): @@ -1521,7 +1510,7 @@ func TestTwoForks_OneIsAccepted(t *testing.T) { activationTime = time.Unix(0, 0) durangoTime = mockable.MaxTime ) - coreVM, _, proVM, gBlock, _ := initTestProposerVM(t, activationTime, durangoTime, 0) + coreVM, _, proVM, _ := initTestProposerVM(t, activationTime, durangoTime, 0) defer func() { require.NoError(proVM.Shutdown(context.Background())) }() @@ -1533,8 +1522,8 @@ func TestTwoForks_OneIsAccepted(t *testing.T) { StatusV: choices.Processing, }, BytesV: []byte{1}, - ParentV: gBlock.ID(), - HeightV: gBlock.Height() + 1, + ParentV: snowmantest.GenesisID, + HeightV: snowmantest.GenesisHeight + 1, } coreVM.BuildBlockF = func(context.Context) (snowman.Block, error) { @@ -1552,12 +1541,12 @@ func TestTwoForks_OneIsAccepted(t *testing.T) { StatusV: choices.Processing, }, BytesV: []byte{2}, - ParentV: gBlock.ID(), - HeightV: gBlock.Height() + 1, + ParentV: snowmantest.GenesisID, + HeightV: snowmantest.GenesisHeight + 1, } ySlb, err := statelessblock.BuildUnsigned( - gBlock.ID(), + snowmantest.GenesisID, proVM.Time(), defaultPChainHeight, yBlock.Bytes(), @@ -1618,7 +1607,7 @@ func TestTooFarAdvanced(t *testing.T) { activationTime = time.Unix(0, 0) durangoTime = mockable.MaxTime ) - coreVM, _, proVM, gBlock, _ := initTestProposerVM(t, activationTime, durangoTime, 0) + coreVM, _, proVM, _ := initTestProposerVM(t, activationTime, durangoTime, 0) defer func() { require.NoError(proVM.Shutdown(context.Background())) }() @@ -1629,9 +1618,9 @@ func TestTooFarAdvanced(t *testing.T) { StatusV: choices.Processing, }, BytesV: []byte{1}, - ParentV: gBlock.ID(), - HeightV: gBlock.Height() + 1, - TimestampV: gBlock.Timestamp(), + ParentV: snowmantest.GenesisID, + HeightV: snowmantest.GenesisHeight + 1, + TimestampV: snowmantest.GenesisTimestamp, } yBlock := &snowmantest.Block{ @@ -1712,7 +1701,7 @@ func TestTwoOptions_OneIsAccepted(t *testing.T) { activationTime = time.Unix(0, 0) durangoTime = mockable.MaxTime ) - coreVM, _, proVM, coreGenBlk, _ := initTestProposerVM(t, activationTime, durangoTime, 0) + coreVM, _, proVM, _ := initTestProposerVM(t, activationTime, durangoTime, 0) defer func() { require.NoError(proVM.Shutdown(context.Background())) }() @@ -1725,8 +1714,8 @@ func TestTwoOptions_OneIsAccepted(t *testing.T) { StatusV: choices.Processing, }, BytesV: []byte{1}, - ParentV: coreGenBlk.ID(), - TimestampV: coreGenBlk.Timestamp(), + ParentV: snowmantest.GenesisID, + TimestampV: snowmantest.GenesisTimestamp, }, opts: [2]snowman.Block{ &snowmantest.Block{ @@ -1736,7 +1725,7 @@ func TestTwoOptions_OneIsAccepted(t *testing.T) { }, BytesV: []byte{2}, ParentV: xBlockID, - TimestampV: coreGenBlk.Timestamp(), + TimestampV: snowmantest.GenesisTimestamp, }, &snowmantest.Block{ TestDecidable: choices.TestDecidable{ @@ -1745,7 +1734,7 @@ func TestTwoOptions_OneIsAccepted(t *testing.T) { }, BytesV: []byte{3}, ParentV: xBlockID, - TimestampV: coreGenBlk.Timestamp(), + TimestampV: snowmantest.GenesisTimestamp, }, }, } @@ -1790,7 +1779,7 @@ func TestLaggedPChainHeight(t *testing.T) { activationTime = time.Unix(0, 0) durangoTime = activationTime ) - coreVM, _, proVM, coreGenBlk, _ := initTestProposerVM(t, activationTime, durangoTime, 0) + coreVM, _, proVM, _ := initTestProposerVM(t, activationTime, durangoTime, 0) defer func() { require.NoError(proVM.Shutdown(context.Background())) }() @@ -1801,8 +1790,8 @@ func TestLaggedPChainHeight(t *testing.T) { StatusV: choices.Processing, }, BytesV: []byte{1}, - ParentV: coreGenBlk.ID(), - TimestampV: coreGenBlk.Timestamp(), + ParentV: snowmantest.GenesisID, + TimestampV: snowmantest.GenesisTimestamp, } coreVM.BuildBlockF = func(context.Context) (snowman.Block, error) { @@ -1815,7 +1804,7 @@ func TestLaggedPChainHeight(t *testing.T) { block := blockIntf.(*postForkBlock) pChainHeight := block.PChainHeight() - require.Equal(pChainHeight, coreGenBlk.Height()) + require.Equal(pChainHeight, snowmantest.GenesisHeight) } // Ensure that rejecting a block does not modify the accepted block ID for the @@ -2338,7 +2327,7 @@ func TestVMInnerBlkCacheDeduplicationRegression(t *testing.T) { activationTime = time.Unix(0, 0) durangoTime = activationTime ) - coreVM, _, proVM, gBlock, _ := initTestProposerVM(t, activationTime, durangoTime, 0) + coreVM, _, proVM, _ := initTestProposerVM(t, activationTime, durangoTime, 0) defer func() { require.NoError(proVM.Shutdown(context.Background())) }() @@ -2350,9 +2339,9 @@ func TestVMInnerBlkCacheDeduplicationRegression(t *testing.T) { StatusV: choices.Processing, }, BytesV: []byte{1}, - ParentV: gBlock.ID(), - HeightV: gBlock.Height() + 1, - TimestampV: gBlock.Timestamp(), + ParentV: snowmantest.GenesisID, + HeightV: snowmantest.GenesisHeight + 1, + TimestampV: snowmantest.GenesisTimestamp, } coreVM.BuildBlockF = func(context.Context) (snowman.Block, error) { @@ -2363,8 +2352,8 @@ func TestVMInnerBlkCacheDeduplicationRegression(t *testing.T) { coreVM.BuildBlockF = nil bStatelessBlock, err := statelessblock.BuildUnsigned( - gBlock.ID(), - gBlock.Timestamp(), + snowmantest.GenesisID, + snowmantest.GenesisTimestamp, defaultPChainHeight, xBlock.Bytes(), ) @@ -2376,9 +2365,9 @@ func TestVMInnerBlkCacheDeduplicationRegression(t *testing.T) { StatusV: choices.Processing, }, BytesV: []byte{1}, - ParentV: gBlock.ID(), - HeightV: gBlock.Height() + 1, - TimestampV: gBlock.Timestamp(), + ParentV: snowmantest.GenesisID, + HeightV: snowmantest.GenesisHeight + 1, + TimestampV: snowmantest.GenesisTimestamp, } coreVM.ParseBlockF = func(context.Context, []byte) (snowman.Block, error) { return xBlockCopy, nil @@ -2417,7 +2406,7 @@ func TestVMInnerBlkMarkedAcceptedRegression(t *testing.T) { activationTime = time.Unix(0, 0) durangoTime = activationTime ) - coreVM, _, proVM, gBlock, _ := initTestProposerVM(t, activationTime, durangoTime, 0) + coreVM, _, proVM, _ := initTestProposerVM(t, activationTime, durangoTime, 0) defer func() { require.NoError(proVM.Shutdown(context.Background())) }() @@ -2429,9 +2418,9 @@ func TestVMInnerBlkMarkedAcceptedRegression(t *testing.T) { StatusV: choices.Processing, }, BytesV: []byte{1}, - ParentV: gBlock.ID(), - HeightV: gBlock.Height() + 1, - TimestampV: gBlock.Timestamp(), + ParentV: snowmantest.GenesisID, + HeightV: snowmantest.GenesisHeight + 1, + TimestampV: snowmantest.GenesisTimestamp, } coreVM.BuildBlockF = func(context.Context) (snowman.Block, error) { From 1f6ed5dd89b51f5cb8fe81769ebbd43aed278655 Mon Sep 17 00:00:00 2001 From: Stephen Buttolph Date: Fri, 26 Apr 2024 18:03:13 -0400 Subject: [PATCH 13/24] nit --- snow/consensus/snowman/snowmantest/block.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snow/consensus/snowman/snowmantest/block.go b/snow/consensus/snowman/snowmantest/block.go index c103f30d77ed..d77ee9759136 100644 --- a/snow/consensus/snowman/snowmantest/block.go +++ b/snow/consensus/snowman/snowmantest/block.go @@ -36,7 +36,7 @@ func BuildChild(parent *Block) *Block { }, ParentV: parent.ID(), HeightV: parent.Height() + 1, - TimestampV: parent.Timestamp().Add(time.Second), + TimestampV: parent.Timestamp(), BytesV: blkID[:], } } From 30a21c8b4e8c1f8141828749d2e35fff987c000f Mon Sep 17 00:00:00 2001 From: Stephen Buttolph Date: Fri, 26 Apr 2024 18:27:20 -0400 Subject: [PATCH 14/24] Use builder helpers --- vms/proposervm/batched_vm_test.go | 224 ++++--------------------- vms/proposervm/block_test.go | 41 +---- vms/proposervm/post_fork_block_test.go | 224 ++++--------------------- 3 files changed, 63 insertions(+), 426 deletions(-) diff --git a/vms/proposervm/batched_vm_test.go b/vms/proposervm/batched_vm_test.go index 33e586cd378b..215d886c1876 100644 --- a/vms/proposervm/batched_vm_test.go +++ b/vms/proposervm/batched_vm_test.go @@ -16,7 +16,6 @@ import ( "github.com/ava-labs/avalanchego/database/prefixdb" "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/snow" - "github.com/ava-labs/avalanchego/snow/choices" "github.com/ava-labs/avalanchego/snow/consensus/snowman" "github.com/ava-labs/avalanchego/snow/consensus/snowman/snowmantest" "github.com/ava-labs/avalanchego/snow/engine/common" @@ -68,16 +67,7 @@ func TestGetAncestorsPreForkOnly(t *testing.T) { }() // Build some prefork blocks.... - coreBlk1 := &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.GenerateTestID(), - StatusV: choices.Processing, - }, - BytesV: []byte{1}, - ParentV: snowmantest.GenesisID, - HeightV: snowmantest.GenesisHeight + 1, - TimestampV: snowmantest.GenesisTimestamp, - } + coreBlk1 := snowmantest.BuildChild(snowmantest.Genesis) coreVM.BuildBlockF = func(context.Context) (snowman.Block, error) { return coreBlk1, nil } @@ -87,24 +77,15 @@ func TestGetAncestorsPreForkOnly(t *testing.T) { // prepare build of next block require.NoError(proRemoteVM.SetPreference(context.Background(), builtBlk1.ID())) coreVM.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { - switch { - case blkID == coreBlk1.ID(): + switch blkID { + case coreBlk1.ID(): return coreBlk1, nil default: return nil, errUnknownBlock } } - coreBlk2 := &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.GenerateTestID(), - StatusV: choices.Processing, - }, - BytesV: []byte{2}, - ParentV: coreBlk1.ID(), - HeightV: coreBlk1.Height() + 1, - TimestampV: coreBlk1.Timestamp(), - } + coreBlk2 := snowmantest.BuildChild(coreBlk1) coreVM.BuildBlockF = func(context.Context) (snowman.Block, error) { return coreBlk2, nil } @@ -114,24 +95,15 @@ func TestGetAncestorsPreForkOnly(t *testing.T) { // prepare build of next block require.NoError(proRemoteVM.SetPreference(context.Background(), builtBlk2.ID())) coreVM.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { - switch { - case blkID == coreBlk2.ID(): + switch blkID { + case coreBlk2.ID(): return coreBlk2, nil default: return nil, errUnknownBlock } } - coreBlk3 := &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.GenerateTestID(), - StatusV: choices.Processing, - }, - BytesV: []byte{3}, - ParentV: coreBlk2.ID(), - HeightV: coreBlk2.Height() + 1, - TimestampV: coreBlk2.Timestamp(), - } + coreBlk3 := snowmantest.BuildChild(coreBlk2) coreVM.BuildBlockF = func(context.Context) (snowman.Block, error) { return coreBlk3, nil } @@ -218,15 +190,7 @@ func TestGetAncestorsPostForkOnly(t *testing.T) { }() // Build some post-Fork blocks.... - coreBlk1 := &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.GenerateTestID(), - StatusV: choices.Processing, - }, - BytesV: []byte{1}, - ParentV: snowmantest.GenesisID, - HeightV: snowmantest.GenesisHeight + 1, - } + coreBlk1 := snowmantest.BuildChild(snowmantest.Genesis) coreVM.BuildBlockF = func(context.Context) (snowman.Block, error) { return coreBlk1, nil } @@ -238,15 +202,7 @@ func TestGetAncestorsPostForkOnly(t *testing.T) { require.NoError(proRemoteVM.SetPreference(context.Background(), builtBlk1.ID())) require.NoError(waitForProposerWindow(proRemoteVM, builtBlk1, 0)) - coreBlk2 := &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.GenerateTestID(), - StatusV: choices.Processing, - }, - BytesV: []byte{2}, - ParentV: coreBlk1.ID(), - HeightV: coreBlk1.Height() + 1, - } + coreBlk2 := snowmantest.BuildChild(coreBlk1) coreVM.BuildBlockF = func(context.Context) (snowman.Block, error) { return coreBlk2, nil } @@ -258,15 +214,7 @@ func TestGetAncestorsPostForkOnly(t *testing.T) { require.NoError(proRemoteVM.SetPreference(context.Background(), builtBlk2.ID())) require.NoError(waitForProposerWindow(proRemoteVM, builtBlk2, 0)) - coreBlk3 := &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.GenerateTestID(), - StatusV: choices.Processing, - }, - BytesV: []byte{3}, - ParentV: coreBlk2.ID(), - HeightV: coreBlk2.Height() + 1, - } + coreBlk3 := snowmantest.BuildChild(coreBlk2) coreVM.BuildBlockF = func(context.Context) (snowman.Block, error) { return coreBlk3, nil } @@ -379,16 +327,8 @@ func TestGetAncestorsAtSnomanPlusPlusFork(t *testing.T) { // Build some prefork blocks.... proRemoteVM.Set(preForkTime) - coreBlk1 := &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.GenerateTestID(), - StatusV: choices.Processing, - }, - BytesV: []byte{1}, - ParentV: snowmantest.GenesisID, - HeightV: snowmantest.GenesisHeight + 1, - TimestampV: preForkTime, - } + coreBlk1 := snowmantest.BuildChild(snowmantest.Genesis) + coreBlk1.TimestampV = preForkTime coreVM.BuildBlockF = func(context.Context) (snowman.Block, error) { return coreBlk1, nil } @@ -407,16 +347,8 @@ func TestGetAncestorsAtSnomanPlusPlusFork(t *testing.T) { } } - coreBlk2 := &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.GenerateTestID(), - StatusV: choices.Processing, - }, - BytesV: []byte{2}, - ParentV: coreBlk1.ID(), - HeightV: coreBlk1.Height() + 1, - TimestampV: postForkTime, - } + coreBlk2 := snowmantest.BuildChild(coreBlk1) + coreBlk2.TimestampV = postForkTime coreVM.BuildBlockF = func(context.Context) (snowman.Block, error) { return coreBlk2, nil } @@ -437,15 +369,7 @@ func TestGetAncestorsAtSnomanPlusPlusFork(t *testing.T) { // .. and some post-fork proRemoteVM.Set(postForkTime) - coreBlk3 := &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.GenerateTestID(), - StatusV: choices.Processing, - }, - BytesV: []byte{3}, - ParentV: coreBlk2.ID(), - HeightV: coreBlk2.Height() + 1, - } + coreBlk3 := snowmantest.BuildChild(coreBlk2) coreVM.BuildBlockF = func(context.Context) (snowman.Block, error) { return coreBlk3, nil } @@ -458,15 +382,7 @@ func TestGetAncestorsAtSnomanPlusPlusFork(t *testing.T) { require.NoError(proRemoteVM.SetPreference(context.Background(), builtBlk3.ID())) require.NoError(waitForProposerWindow(proRemoteVM, builtBlk3, builtBlk3.(*postForkBlock).PChainHeight())) - coreBlk4 := &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.GenerateTestID(), - StatusV: choices.Processing, - }, - BytesV: []byte{4}, - ParentV: coreBlk3.ID(), - HeightV: coreBlk3.Height() + 1, - } + coreBlk4 := snowmantest.BuildChild(coreBlk3) coreVM.BuildBlockF = func(context.Context) (snowman.Block, error) { return coreBlk4, nil } @@ -580,15 +496,7 @@ func TestBatchedParseBlockPreForkOnly(t *testing.T) { }() // Build some prefork blocks.... - coreBlk1 := &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.GenerateTestID(), - StatusV: choices.Processing, - }, - BytesV: []byte{1}, - ParentV: snowmantest.GenesisID, - HeightV: snowmantest.GenesisHeight + 1, - } + coreBlk1 := snowmantest.BuildChild(snowmantest.Genesis) coreVM.BuildBlockF = func(context.Context) (snowman.Block, error) { return coreBlk1, nil } @@ -598,23 +506,15 @@ func TestBatchedParseBlockPreForkOnly(t *testing.T) { // prepare build of next block require.NoError(proRemoteVM.SetPreference(context.Background(), builtBlk1.ID())) coreVM.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { - switch { - case blkID == coreBlk1.ID(): + switch blkID { + case coreBlk1.ID(): return coreBlk1, nil default: return nil, errUnknownBlock } } - coreBlk2 := &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.GenerateTestID(), - StatusV: choices.Processing, - }, - BytesV: []byte{2}, - ParentV: coreBlk1.ID(), - HeightV: coreBlk1.Height() + 1, - } + coreBlk2 := snowmantest.BuildChild(coreBlk1) coreVM.BuildBlockF = func(context.Context) (snowman.Block, error) { return coreBlk2, nil } @@ -632,15 +532,7 @@ func TestBatchedParseBlockPreForkOnly(t *testing.T) { } } - coreBlk3 := &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.GenerateTestID(), - StatusV: choices.Processing, - }, - BytesV: []byte{3}, - ParentV: coreBlk2.ID(), - HeightV: coreBlk2.Height() + 1, - } + coreBlk3 := snowmantest.BuildChild(coreBlk2) coreVM.BuildBlockF = func(context.Context) (snowman.Block, error) { return coreBlk3, nil } @@ -702,15 +594,7 @@ func TestBatchedParseBlockPostForkOnly(t *testing.T) { }() // Build some post-Fork blocks.... - coreBlk1 := &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.GenerateTestID(), - StatusV: choices.Processing, - }, - BytesV: []byte{1}, - ParentV: snowmantest.GenesisID, - HeightV: snowmantest.GenesisHeight + 1, - } + coreBlk1 := snowmantest.BuildChild(snowmantest.Genesis) coreVM.BuildBlockF = func(context.Context) (snowman.Block, error) { return coreBlk1, nil } @@ -722,15 +606,7 @@ func TestBatchedParseBlockPostForkOnly(t *testing.T) { require.NoError(proRemoteVM.SetPreference(context.Background(), builtBlk1.ID())) require.NoError(waitForProposerWindow(proRemoteVM, builtBlk1, 0)) - coreBlk2 := &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.GenerateTestID(), - StatusV: choices.Processing, - }, - BytesV: []byte{2}, - ParentV: coreBlk1.ID(), - HeightV: coreBlk1.Height() + 1, - } + coreBlk2 := snowmantest.BuildChild(coreBlk1) coreVM.BuildBlockF = func(context.Context) (snowman.Block, error) { return coreBlk2, nil } @@ -742,15 +618,7 @@ func TestBatchedParseBlockPostForkOnly(t *testing.T) { require.NoError(proRemoteVM.SetPreference(context.Background(), builtBlk2.ID())) require.NoError(waitForProposerWindow(proRemoteVM, builtBlk2, builtBlk2.(*postForkBlock).PChainHeight())) - coreBlk3 := &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.GenerateTestID(), - StatusV: choices.Processing, - }, - BytesV: []byte{3}, - ParentV: coreBlk2.ID(), - HeightV: coreBlk2.Height() + 1, - } + coreBlk3 := snowmantest.BuildChild(coreBlk2) coreVM.BuildBlockF = func(context.Context) (snowman.Block, error) { return coreBlk3, nil } @@ -820,16 +688,8 @@ func TestBatchedParseBlockAtSnomanPlusPlusFork(t *testing.T) { // Build some prefork blocks.... proRemoteVM.Set(preForkTime) - coreBlk1 := &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.GenerateTestID(), - StatusV: choices.Processing, - }, - BytesV: []byte{1}, - ParentV: snowmantest.GenesisID, - HeightV: snowmantest.GenesisHeight + 1, - TimestampV: preForkTime, - } + coreBlk1 := snowmantest.BuildChild(snowmantest.Genesis) + coreBlk1.TimestampV = preForkTime coreVM.BuildBlockF = func(context.Context) (snowman.Block, error) { return coreBlk1, nil } @@ -848,16 +708,8 @@ func TestBatchedParseBlockAtSnomanPlusPlusFork(t *testing.T) { } } - coreBlk2 := &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.GenerateTestID(), - StatusV: choices.Processing, - }, - BytesV: []byte{2}, - ParentV: coreBlk1.ID(), - HeightV: coreBlk1.Height() + 1, - TimestampV: postForkTime, - } + coreBlk2 := snowmantest.BuildChild(coreBlk1) + coreBlk2.TimestampV = postForkTime coreVM.BuildBlockF = func(context.Context) (snowman.Block, error) { return coreBlk2, nil } @@ -878,15 +730,7 @@ func TestBatchedParseBlockAtSnomanPlusPlusFork(t *testing.T) { // .. and some post-fork proRemoteVM.Set(postForkTime) - coreBlk3 := &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.GenerateTestID(), - StatusV: choices.Processing, - }, - BytesV: []byte{3}, - ParentV: coreBlk2.ID(), - HeightV: coreBlk2.Height() + 1, - } + coreBlk3 := snowmantest.BuildChild(coreBlk2) coreVM.BuildBlockF = func(context.Context) (snowman.Block, error) { return coreBlk3, nil } @@ -899,15 +743,7 @@ func TestBatchedParseBlockAtSnomanPlusPlusFork(t *testing.T) { require.NoError(proRemoteVM.SetPreference(context.Background(), builtBlk3.ID())) require.NoError(waitForProposerWindow(proRemoteVM, builtBlk3, builtBlk3.(*postForkBlock).PChainHeight())) - coreBlk4 := &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.GenerateTestID(), - StatusV: choices.Processing, - }, - BytesV: []byte{4}, - ParentV: coreBlk3.ID(), - HeightV: coreBlk3.Height() + 1, - } + coreBlk4 := snowmantest.BuildChild(coreBlk3) coreVM.BuildBlockF = func(context.Context) (snowman.Block, error) { return coreBlk4, nil } diff --git a/vms/proposervm/block_test.go b/vms/proposervm/block_test.go index 5e4790137f61..0163c0586738 100644 --- a/vms/proposervm/block_test.go +++ b/vms/proposervm/block_test.go @@ -17,7 +17,6 @@ import ( "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/snow" - "github.com/ava-labs/avalanchego/snow/choices" "github.com/ava-labs/avalanchego/snow/consensus/snowman" "github.com/ava-labs/avalanchego/snow/consensus/snowman/snowmantest" "github.com/ava-labs/avalanchego/snow/engine/snowman/block" @@ -119,15 +118,7 @@ func TestPreDurangoValidatorNodeBlockBuiltDelaysTests(t *testing.T) { parentTime := time.Now().Truncate(time.Second) proVM.Set(parentTime) - coreParentBlk := &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.GenerateTestID(), - StatusV: choices.Processing, - }, - BytesV: []byte{1}, - ParentV: snowmantest.GenesisID, - HeightV: snowmantest.GenesisHeight + 1, - } + coreParentBlk := snowmantest.BuildChild(snowmantest.Genesis) coreVM.BuildBlockF = func(context.Context) (snowman.Block, error) { return coreParentBlk, nil } @@ -177,15 +168,7 @@ func TestPreDurangoValidatorNodeBlockBuiltDelaysTests(t *testing.T) { }, nil } - coreChildBlk := &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.GenerateTestID(), - StatusV: choices.Processing, - }, - BytesV: []byte{2}, - ParentV: coreParentBlk.ID(), - HeightV: coreParentBlk.Height() + 1, - } + coreChildBlk := snowmantest.BuildChild(coreParentBlk) coreVM.BuildBlockF = func(context.Context) (snowman.Block, error) { return coreChildBlk, nil } @@ -256,15 +239,7 @@ func TestPreDurangoNonValidatorNodeBlockBuiltDelaysTests(t *testing.T) { parentTime := time.Now().Truncate(time.Second) proVM.Set(parentTime) - coreParentBlk := &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.GenerateTestID(), - StatusV: choices.Processing, - }, - BytesV: []byte{1}, - ParentV: snowmantest.GenesisID, - HeightV: snowmantest.GenesisHeight + 1, - } + coreParentBlk := snowmantest.BuildChild(snowmantest.Genesis) coreVM.BuildBlockF = func(context.Context) (snowman.Block, error) { return coreParentBlk, nil } @@ -316,15 +291,7 @@ func TestPreDurangoNonValidatorNodeBlockBuiltDelaysTests(t *testing.T) { }, nil } - coreChildBlk := &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.GenerateTestID(), - StatusV: choices.Processing, - }, - BytesV: []byte{2}, - ParentV: coreParentBlk.ID(), - HeightV: coreParentBlk.Height() + 1, - } + coreChildBlk := snowmantest.BuildChild(coreParentBlk) coreVM.BuildBlockF = func(context.Context) (snowman.Block, error) { return coreChildBlk, nil } diff --git a/vms/proposervm/post_fork_block_test.go b/vms/proposervm/post_fork_block_test.go index 4b1b478fe48c..416fc087b101 100644 --- a/vms/proposervm/post_fork_block_test.go +++ b/vms/proposervm/post_fork_block_test.go @@ -32,7 +32,7 @@ func TestOracle_PostForkBlock_ImplementsInterface(t *testing.T) { // setup proBlk := postForkBlock{ postForkCommonComponents: postForkCommonComponents{ - innerBlk: &snowmantest.Block{}, + innerBlk: snowmantest.BuildChild(snowmantest.Genesis), }, } @@ -50,26 +50,12 @@ func TestOracle_PostForkBlock_ImplementsInterface(t *testing.T) { require.NoError(proVM.Shutdown(context.Background())) }() + innerTestBlock := snowmantest.BuildChild(snowmantest.Genesis) innerOracleBlk := &TestOptionsBlock{ - Block: snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.Empty.Prefix(1111), - }, - BytesV: []byte{1}, - }, + Block: *innerTestBlock, opts: [2]snowman.Block{ - &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.Empty.Prefix(2222), - }, - BytesV: []byte{2}, - }, - &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.Empty.Prefix(3333), - }, - BytesV: []byte{3}, - }, + snowmantest.BuildChild(innerTestBlock), + snowmantest.BuildChild(innerTestBlock), }, } @@ -116,15 +102,7 @@ func TestBlockVerify_PostForkBlock_PreDurango_ParentChecks(t *testing.T) { } // create parent block ... - parentCoreBlk := &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.Empty.Prefix(1111), - StatusV: choices.Processing, - }, - BytesV: []byte{1}, - ParentV: snowmantest.GenesisID, - HeightV: snowmantest.GenesisHeight + 1, - } + parentCoreBlk := snowmantest.BuildChild(snowmantest.Genesis) coreVM.BuildBlockF = func(context.Context) (snowman.Block, error) { return parentCoreBlk, nil } @@ -156,11 +134,7 @@ func TestBlockVerify_PostForkBlock_PreDurango_ParentChecks(t *testing.T) { require.NoError(proVM.SetPreference(context.Background(), parentBlk.ID())) // .. create child block ... - childCoreBlk := &snowmantest.Block{ - ParentV: parentCoreBlk.ID(), - BytesV: []byte{2}, - HeightV: parentCoreBlk.Height() + 1, - } + childCoreBlk := snowmantest.BuildChild(parentCoreBlk) childBlk := postForkBlock{ postForkCommonComponents: postForkCommonComponents{ vm: proVM, @@ -219,15 +193,7 @@ func TestBlockVerify_PostForkBlock_PostDurango_ParentChecks(t *testing.T) { return pChainHeight, nil } - parentCoreBlk := &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.Empty.Prefix(1111), - StatusV: choices.Processing, - }, - BytesV: []byte{1}, - ParentV: snowmantest.GenesisID, - HeightV: snowmantest.GenesisHeight + 1, - } + parentCoreBlk := snowmantest.BuildChild(snowmantest.Genesis) coreVM.BuildBlockF = func(context.Context) (snowman.Block, error) { return parentCoreBlk, nil } @@ -258,11 +224,7 @@ func TestBlockVerify_PostForkBlock_PostDurango_ParentChecks(t *testing.T) { require.NoError(parentBlk.Verify(context.Background())) require.NoError(proVM.SetPreference(context.Background(), parentBlk.ID())) - childCoreBlk := &snowmantest.Block{ - ParentV: parentCoreBlk.ID(), - BytesV: []byte{2}, - HeightV: parentCoreBlk.Height() + 1, - } + childCoreBlk := snowmantest.BuildChild(parentCoreBlk) childBlk := postForkBlock{ postForkCommonComponents: postForkCommonComponents{ vm: proVM, @@ -348,15 +310,7 @@ func TestBlockVerify_PostForkBlock_TimestampChecks(t *testing.T) { } // create parent block ... - parentCoreBlk := &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.Empty.Prefix(1111), - StatusV: choices.Processing, - }, - BytesV: []byte{1}, - ParentV: snowmantest.GenesisID, - HeightV: snowmantest.GenesisHeight + 1, - } + parentCoreBlk := snowmantest.BuildChild(snowmantest.Genesis) coreVM.BuildBlockF = func(context.Context) (snowman.Block, error) { return parentCoreBlk, nil } @@ -392,15 +346,7 @@ func TestBlockVerify_PostForkBlock_TimestampChecks(t *testing.T) { parentPChainHeight = parentBlk.(*postForkBlock).PChainHeight() ) - childCoreBlk := &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.Empty.Prefix(2222), - StatusV: choices.Processing, - }, - ParentV: parentCoreBlk.ID(), - HeightV: parentCoreBlk.Height() + 1, - BytesV: []byte{2}, - } + childCoreBlk := snowmantest.BuildChild(parentCoreBlk) childBlk := postForkBlock{ postForkCommonComponents: postForkCommonComponents{ vm: proVM, @@ -553,15 +499,7 @@ func TestBlockVerify_PostForkBlock_PChainHeightChecks(t *testing.T) { } // create parent block ... - parentCoreBlk := &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.Empty.Prefix(1111), - StatusV: choices.Processing, - }, - BytesV: []byte{1}, - ParentV: snowmantest.GenesisID, - HeightV: snowmantest.GenesisHeight + 1, - } + parentCoreBlk := snowmantest.BuildChild(snowmantest.Genesis) coreVM.BuildBlockF = func(context.Context) (snowman.Block, error) { return parentCoreBlk, nil } @@ -597,15 +535,7 @@ func TestBlockVerify_PostForkBlock_PChainHeightChecks(t *testing.T) { parentBlkPChainHeight := parentBlk.(*postForkBlock).PChainHeight() require.NoError(waitForProposerWindow(proVM, parentBlk, parentBlkPChainHeight)) - childCoreBlk := &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.Empty.Prefix(2222), - StatusV: choices.Processing, - }, - ParentV: parentCoreBlk.ID(), - HeightV: parentBlk.Height() + 1, - BytesV: []byte{2}, - } + childCoreBlk := snowmantest.BuildChild(parentCoreBlk) childBlk := postForkBlock{ postForkCommonComponents: postForkCommonComponents{ vm: proVM, @@ -724,36 +654,14 @@ func TestBlockVerify_PostForkBlockBuiltOnOption_PChainHeightChecks(t *testing.T) } // create post fork oracle block ... + innerTestBlock := snowmantest.BuildChild(snowmantest.Genesis) oracleCoreBlk := &TestOptionsBlock{ - Block: snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.Empty.Prefix(1111), - StatusV: choices.Processing, - }, - BytesV: []byte{1}, - ParentV: snowmantest.GenesisID, - HeightV: snowmantest.GenesisHeight + 1, - }, + Block: *innerTestBlock, } + preferredOracleBlkChild := snowmantest.BuildChild(innerTestBlock) oracleCoreBlk.opts = [2]snowman.Block{ - &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.Empty.Prefix(2222), - StatusV: choices.Processing, - }, - BytesV: []byte{2}, - ParentV: oracleCoreBlk.ID(), - HeightV: oracleCoreBlk.Height() + 1, - }, - &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.Empty.Prefix(3333), - StatusV: choices.Processing, - }, - BytesV: []byte{3}, - ParentV: oracleCoreBlk.ID(), - HeightV: oracleCoreBlk.Height() + 1, - }, + preferredOracleBlkChild, + snowmantest.BuildChild(innerTestBlock), } coreVM.BuildBlockF = func(context.Context) (snowman.Block, error) { @@ -811,15 +719,7 @@ func TestBlockVerify_PostForkBlockBuiltOnOption_PChainHeightChecks(t *testing.T) parentBlkPChainHeight := postForkOracleBlk.PChainHeight() // option takes proposal blocks' Pchain height - childCoreBlk := &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.Empty.Prefix(2222), - StatusV: choices.Processing, - }, - ParentV: oracleCoreBlk.opts[0].ID(), - BytesV: []byte{2}, - HeightV: oracleCoreBlk.opts[0].Height() + 1, - } + childCoreBlk := snowmantest.BuildChild(preferredOracleBlkChild) childBlk := postForkBlock{ postForkCommonComponents: postForkCommonComponents{ vm: proVM, @@ -920,15 +820,7 @@ func TestBlockVerify_PostForkBlock_CoreBlockVerifyIsCalledOnce(t *testing.T) { return pChainHeight, nil } - coreBlk := &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.Empty.Prefix(1111), - StatusV: choices.Processing, - }, - BytesV: []byte{1}, - ParentV: snowmantest.GenesisID, - HeightV: snowmantest.GenesisHeight + 1, - } + coreBlk := snowmantest.BuildChild(snowmantest.Genesis) coreVM.BuildBlockF = func(context.Context) (snowman.Block, error) { return coreBlk, nil } @@ -987,15 +879,7 @@ func TestBlockAccept_PostForkBlock_SetsLastAcceptedBlock(t *testing.T) { return pChainHeight, nil } - coreBlk := &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.Empty.Prefix(1111), - StatusV: choices.Processing, - }, - BytesV: []byte{1}, - ParentV: snowmantest.GenesisID, - HeightV: snowmantest.GenesisHeight + 1, - } + coreBlk := snowmantest.BuildChild(snowmantest.Genesis) coreVM.BuildBlockF = func(context.Context) (snowman.Block, error) { return coreBlk, nil } @@ -1055,15 +939,7 @@ func TestBlockAccept_PostForkBlock_TwoProBlocksWithSameCoreBlock_OneIsAccepted(t } // generate two blocks with the same core block and store them - coreBlk := &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.Empty.Prefix(111), - StatusV: choices.Processing, - }, - BytesV: []byte{1}, - ParentV: snowmantest.GenesisID, - HeightV: snowmantest.GenesisHeight + 1, - } + coreBlk := snowmantest.BuildChild(snowmantest.Genesis) coreVM.BuildBlockF = func(context.Context) (snowman.Block, error) { return coreBlk, nil } @@ -1100,15 +976,7 @@ func TestBlockReject_PostForkBlock_InnerBlockIsNotRejected(t *testing.T) { require.NoError(proVM.Shutdown(context.Background())) }() - coreBlk := &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.Empty.Prefix(111), - StatusV: choices.Processing, - }, - BytesV: []byte{1}, - ParentV: snowmantest.GenesisID, - HeightV: snowmantest.GenesisHeight + 1, - } + coreBlk := snowmantest.BuildChild(snowmantest.Genesis) coreVM.BuildBlockF = func(context.Context) (snowman.Block, error) { return coreBlk, nil } @@ -1137,38 +1005,13 @@ func TestBlockVerify_PostForkBlock_ShouldBePostForkOption(t *testing.T) { }() // create post fork oracle block ... + coreTestBlk := snowmantest.BuildChild(snowmantest.Genesis) oracleCoreBlk := &TestOptionsBlock{ - Block: snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.Empty.Prefix(1111), - StatusV: choices.Processing, - }, - BytesV: []byte{1}, - ParentV: snowmantest.GenesisID, - HeightV: snowmantest.GenesisHeight + 1, - }, - } - coreOpt0 := &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.Empty.Prefix(2222), - StatusV: choices.Processing, - }, - BytesV: []byte{2}, - ParentV: oracleCoreBlk.ID(), - HeightV: oracleCoreBlk.Height() + 1, - } - coreOpt1 := &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.Empty.Prefix(3333), - StatusV: choices.Processing, + Block: *coreTestBlk, + opts: [2]snowman.Block{ + snowmantest.BuildChild(coreTestBlk), + snowmantest.BuildChild(coreTestBlk), }, - BytesV: []byte{3}, - ParentV: oracleCoreBlk.ID(), - HeightV: oracleCoreBlk.Height() + 1, - } - oracleCoreBlk.opts = [2]snowman.Block{ - coreOpt0, - coreOpt1, } coreVM.BuildBlockF = func(context.Context) (snowman.Block, error) { @@ -1254,16 +1097,7 @@ func TestBlockVerify_PostForkBlock_PChainTooLow(t *testing.T) { require.NoError(proVM.Shutdown(context.Background())) }() - coreBlk := &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.GenerateTestID(), - StatusV: choices.Processing, - }, - BytesV: []byte{1}, - ParentV: snowmantest.GenesisID, - HeightV: snowmantest.GenesisHeight + 1, - } - + coreBlk := snowmantest.BuildChild(snowmantest.Genesis) coreVM.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { switch blkID { case snowmantest.GenesisID: From d1b2b1930f7ac1c46766a110014fb7d90dc262aa Mon Sep 17 00:00:00 2001 From: Stephen Buttolph Date: Fri, 26 Apr 2024 18:50:37 -0400 Subject: [PATCH 15/24] wip --- vms/proposervm/post_fork_option_test.go | 200 ++++-------------------- vms/proposervm/pre_fork_block_test.go | 42 +---- 2 files changed, 39 insertions(+), 203 deletions(-) diff --git a/vms/proposervm/post_fork_option_test.go b/vms/proposervm/post_fork_option_test.go index a299cfa95401..39c6434dddf6 100644 --- a/vms/proposervm/post_fork_option_test.go +++ b/vms/proposervm/post_fork_option_test.go @@ -47,35 +47,13 @@ func TestBlockVerify_PostForkOption_ParentChecks(t *testing.T) { }() // create post fork oracle block ... + coreTestBlk := snowmantest.BuildChild(snowmantest.Genesis) + preferredBlk := snowmantest.BuildChild(coreTestBlk) oracleCoreBlk := &TestOptionsBlock{ - Block: snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.Empty.Prefix(1111), - StatusV: choices.Processing, - }, - BytesV: []byte{1}, - ParentV: snowmantest.GenesisID, - HeightV: snowmantest.GenesisHeight + 1, - }, - } - oracleCoreBlk.opts = [2]snowman.Block{ - &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.Empty.Prefix(2222), - StatusV: choices.Processing, - }, - BytesV: []byte{2}, - ParentV: oracleCoreBlk.ID(), - HeightV: oracleCoreBlk.Height() + 1, - }, - &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.Empty.Prefix(3333), - StatusV: choices.Processing, - }, - BytesV: []byte{3}, - ParentV: oracleCoreBlk.ID(), - HeightV: oracleCoreBlk.Height() + 1, + Block: *coreTestBlk, + opts: [2]snowman.Block{ + preferredBlk, + snowmantest.BuildChild(coreTestBlk), }, } @@ -131,15 +109,7 @@ func TestBlockVerify_PostForkOption_ParentChecks(t *testing.T) { // show we can build on options require.NoError(proVM.SetPreference(context.Background(), opts[0].ID())) - childCoreBlk := &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.Empty.Prefix(4444), - StatusV: choices.Processing, - }, - ParentV: oracleCoreBlk.opts[0].ID(), - BytesV: []byte{4}, - HeightV: oracleCoreBlk.opts[0].Height() + 1, - } + childCoreBlk := snowmantest.BuildChild(preferredBlk) coreVM.BuildBlockF = func(context.Context) (snowman.Block, error) { return childCoreBlk, nil } @@ -166,38 +136,15 @@ func TestBlockVerify_PostForkOption_CoreBlockVerifyIsCalledOnce(t *testing.T) { }() // create post fork oracle block ... + coreTestBlk := snowmantest.BuildChild(snowmantest.Genesis) + coreOpt0 := snowmantest.BuildChild(coreTestBlk) + coreOpt1 := snowmantest.BuildChild(coreTestBlk) oracleCoreBlk := &TestOptionsBlock{ - Block: snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.Empty.Prefix(1111), - StatusV: choices.Processing, - }, - BytesV: []byte{1}, - ParentV: snowmantest.GenesisID, - HeightV: snowmantest.GenesisHeight + 1, - }, - } - coreOpt0 := &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.Empty.Prefix(2222), - StatusV: choices.Processing, - }, - BytesV: []byte{2}, - ParentV: oracleCoreBlk.ID(), - HeightV: oracleCoreBlk.Height() + 1, - } - coreOpt1 := &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.Empty.Prefix(3333), - StatusV: choices.Processing, + Block: *coreTestBlk, + opts: [2]snowman.Block{ + coreOpt0, + coreOpt1, }, - BytesV: []byte{3}, - ParentV: oracleCoreBlk.ID(), - HeightV: oracleCoreBlk.Height() + 1, - } - oracleCoreBlk.opts = [2]snowman.Block{ - coreOpt0, - coreOpt1, } coreVM.BuildBlockF = func(context.Context) (snowman.Block, error) { @@ -271,35 +218,12 @@ func TestBlockAccept_PostForkOption_SetsLastAcceptedBlock(t *testing.T) { }() // create post fork oracle block ... + coreTestBlk := snowmantest.BuildChild(snowmantest.Genesis) oracleCoreBlk := &TestOptionsBlock{ - Block: snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.Empty.Prefix(1111), - StatusV: choices.Processing, - }, - BytesV: []byte{1}, - ParentV: snowmantest.GenesisID, - HeightV: snowmantest.GenesisHeight + 1, - }, - } - oracleCoreBlk.opts = [2]snowman.Block{ - &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.Empty.Prefix(2222), - StatusV: choices.Processing, - }, - BytesV: []byte{2}, - ParentV: oracleCoreBlk.ID(), - HeightV: oracleCoreBlk.Height() + 1, - }, - &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.Empty.Prefix(3333), - StatusV: choices.Processing, - }, - BytesV: []byte{3}, - ParentV: oracleCoreBlk.ID(), - HeightV: oracleCoreBlk.Height() + 1, + Block: *coreTestBlk, + opts: [2]snowman.Block{ + snowmantest.BuildChild(coreTestBlk), + snowmantest.BuildChild(coreTestBlk), }, } @@ -384,35 +308,12 @@ func TestBlockReject_InnerBlockIsNotRejected(t *testing.T) { }() // create post fork oracle block ... + coreTestBlk := snowmantest.BuildChild(snowmantest.Genesis) oracleCoreBlk := &TestOptionsBlock{ - Block: snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.Empty.Prefix(1111), - StatusV: choices.Processing, - }, - BytesV: []byte{1}, - ParentV: snowmantest.GenesisID, - HeightV: snowmantest.GenesisHeight + 1, - }, - } - oracleCoreBlk.opts = [2]snowman.Block{ - &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.Empty.Prefix(2222), - StatusV: choices.Processing, - }, - BytesV: []byte{2}, - ParentV: oracleCoreBlk.ID(), - HeightV: oracleCoreBlk.Height() + 1, - }, - &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.Empty.Prefix(3333), - StatusV: choices.Processing, - }, - BytesV: []byte{3}, - ParentV: oracleCoreBlk.ID(), - HeightV: oracleCoreBlk.Height() + 1, + Block: *coreTestBlk, + opts: [2]snowman.Block{ + snowmantest.BuildChild(coreTestBlk), + snowmantest.BuildChild(coreTestBlk), }, } @@ -488,28 +389,13 @@ func TestBlockVerify_PostForkOption_ParentIsNotOracleWithError(t *testing.T) { require.NoError(proVM.Shutdown(context.Background())) }() + coreTestBlk := snowmantest.BuildChild(snowmantest.Genesis) coreBlk := &TestOptionsBlock{ - Block: snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.GenerateTestID(), - StatusV: choices.Processing, - }, - BytesV: []byte{1}, - ParentV: snowmantest.GenesisID, - HeightV: snowmantest.GenesisHeight + 1, - }, + Block: *coreTestBlk, optsErr: snowman.ErrNotOracle, } - coreChildBlk := &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.GenerateTestID(), - StatusV: choices.Processing, - }, - BytesV: []byte{2}, - ParentV: coreBlk.ID(), - HeightV: coreBlk.Height() + 1, - } + coreChildBlk := snowmantest.BuildChild(coreTestBlk) coreVM.BuildBlockF = func(context.Context) (snowman.Block, error) { return coreBlk, nil @@ -573,36 +459,12 @@ func TestOptionTimestampValidity(t *testing.T) { ) coreVM, _, proVM, db := initTestProposerVM(t, activationTime, durangoTime, 0) - coreOracleBlkID := ids.GenerateTestID() + coreTestBlk := snowmantest.BuildChild(snowmantest.Genesis) coreOracleBlk := &TestOptionsBlock{ - Block: snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: coreOracleBlkID, - StatusV: choices.Processing, - }, - BytesV: []byte{1}, - ParentV: snowmantest.GenesisID, - HeightV: snowmantest.GenesisHeight + 1, - }, + Block: *coreTestBlk, opts: [2]snowman.Block{ - &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.GenerateTestID(), - StatusV: choices.Processing, - }, - BytesV: []byte{2}, - ParentV: coreOracleBlkID, - HeightV: snowmantest.GenesisHeight + 2, - }, - &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.GenerateTestID(), - StatusV: choices.Processing, - }, - BytesV: []byte{3}, - ParentV: coreOracleBlkID, - HeightV: snowmantest.GenesisHeight + 2, - }, + snowmantest.BuildChild(coreTestBlk), + snowmantest.BuildChild(coreTestBlk), }, } diff --git a/vms/proposervm/pre_fork_block_test.go b/vms/proposervm/pre_fork_block_test.go index f22e6b299084..864a967beee1 100644 --- a/vms/proposervm/pre_fork_block_test.go +++ b/vms/proposervm/pre_fork_block_test.go @@ -31,7 +31,7 @@ func TestOracle_PreForkBlkImplementsInterface(t *testing.T) { // setup proBlk := preForkBlock{ - Block: &snowmantest.Block{}, + Block: snowmantest.BuildChild(snowmantest.Genesis), } // test @@ -61,32 +61,13 @@ func TestOracle_PreForkBlkCanBuiltOnPreForkOption(t *testing.T) { }() // create pre fork oracle block ... + coreTestBlk := snowmantest.BuildChild(snowmantest.Genesis) + preferredTestBlk := snowmantest.BuildChild(coreTestBlk) oracleCoreBlk := &TestOptionsBlock{ - Block: snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.Empty.Prefix(1111), - StatusV: choices.Processing, - }, - BytesV: []byte{1}, - ParentV: snowmantest.GenesisID, - }, - } - oracleCoreBlk.opts = [2]snowman.Block{ - &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.Empty.Prefix(2222), - StatusV: choices.Processing, - }, - BytesV: []byte{2}, - ParentV: oracleCoreBlk.ID(), - }, - &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.Empty.Prefix(3333), - StatusV: choices.Processing, - }, - BytesV: []byte{3}, - ParentV: oracleCoreBlk.ID(), + Block: *coreTestBlk, + opts: [2]snowman.Block{ + preferredTestBlk, + snowmantest.BuildChild(coreTestBlk), }, } @@ -122,14 +103,7 @@ func TestOracle_PreForkBlkCanBuiltOnPreForkOption(t *testing.T) { require.NoError(proVM.SetPreference(context.Background(), opts[0].ID())) lastCoreBlk := &TestOptionsBlock{ - Block: snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.Empty.Prefix(4444), - StatusV: choices.Processing, - }, - BytesV: []byte{4}, - ParentV: oracleCoreBlk.opts[0].ID(), - }, + Block: *snowmantest.BuildChild(preferredTestBlk), } coreVM.BuildBlockF = func(context.Context) (snowman.Block, error) { return lastCoreBlk, nil From 0d801d1eba210f42f12fc049103b06a0497b245c Mon Sep 17 00:00:00 2001 From: Stephen Buttolph Date: Fri, 26 Apr 2024 18:56:17 -0400 Subject: [PATCH 16/24] lint --- vms/proposervm/vm_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vms/proposervm/vm_test.go b/vms/proposervm/vm_test.go index 0f835813f38a..03e81741524b 100644 --- a/vms/proposervm/vm_test.go +++ b/vms/proposervm/vm_test.go @@ -1804,7 +1804,7 @@ func TestLaggedPChainHeight(t *testing.T) { block := blockIntf.(*postForkBlock) pChainHeight := block.PChainHeight() - require.Equal(pChainHeight, snowmantest.GenesisHeight) + require.Equal(snowmantest.GenesisHeight, pChainHeight) } // Ensure that rejecting a block does not modify the accepted block ID for the From ed6d05bc03c9946026237193020476124ef4184f Mon Sep 17 00:00:00 2001 From: Stephen Buttolph Date: Sat, 27 Apr 2024 14:16:42 -0400 Subject: [PATCH 17/24] use helper --- vms/proposervm/pre_fork_block_test.go | 199 +++++--------------------- 1 file changed, 34 insertions(+), 165 deletions(-) diff --git a/vms/proposervm/pre_fork_block_test.go b/vms/proposervm/pre_fork_block_test.go index 864a967beee1..56c588dbc956 100644 --- a/vms/proposervm/pre_fork_block_test.go +++ b/vms/proposervm/pre_fork_block_test.go @@ -127,37 +127,21 @@ func TestOracle_PostForkBlkCanBuiltOnPreForkOption(t *testing.T) { }() // create pre fork oracle block pre activation time... - oracleCoreBlk := &TestOptionsBlock{ - Block: snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.Empty.Prefix(1111), - StatusV: choices.Processing, - }, - BytesV: []byte{1}, - ParentV: snowmantest.GenesisID, - TimestampV: activationTime.Add(-1 * time.Second), - }, - } + coreTestBlk := snowmantest.BuildChild(snowmantest.Genesis) + coreTestBlk.TimestampV = activationTime.Add(-1 * time.Second) // ... whose options are post activation time - oracleCoreBlk.opts = [2]snowman.Block{ - &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.Empty.Prefix(2222), - StatusV: choices.Processing, - }, - BytesV: []byte{2}, - ParentV: oracleCoreBlk.ID(), - TimestampV: activationTime.Add(time.Second), - }, - &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.Empty.Prefix(3333), - StatusV: choices.Processing, - }, - BytesV: []byte{3}, - ParentV: oracleCoreBlk.ID(), - TimestampV: activationTime.Add(time.Second), + preferredBlk := snowmantest.BuildChild(coreTestBlk) + preferredBlk.TimestampV = activationTime.Add(time.Second) + + unpreferredBlk := snowmantest.BuildChild(coreTestBlk) + unpreferredBlk.TimestampV = activationTime.Add(time.Second) + + oracleCoreBlk := &TestOptionsBlock{ + Block: *coreTestBlk, + opts: [2]snowman.Block{ + preferredBlk, + unpreferredBlk, }, } @@ -193,14 +177,7 @@ func TestOracle_PostForkBlkCanBuiltOnPreForkOption(t *testing.T) { require.NoError(proVM.SetPreference(context.Background(), opts[0].ID())) lastCoreBlk := &TestOptionsBlock{ - Block: snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.Empty.Prefix(4444), - StatusV: choices.Processing, - }, - BytesV: []byte{4}, - ParentV: oracleCoreBlk.opts[0].ID(), - }, + Block: *snowmantest.BuildChild(preferredBlk), } coreVM.BuildBlockF = func(context.Context) (snowman.Block, error) { return lastCoreBlk, nil @@ -226,15 +203,7 @@ func TestBlockVerify_PreFork_ParentChecks(t *testing.T) { require.True(snowmantest.GenesisTimestamp.Before(activationTime)) // create parent block ... - parentCoreBlk := &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.Empty.Prefix(1111), - StatusV: choices.Processing, - }, - BytesV: []byte{1}, - ParentV: snowmantest.GenesisID, - TimestampV: snowmantest.GenesisTimestamp, - } + parentCoreBlk := snowmantest.BuildChild(snowmantest.Genesis) coreVM.BuildBlockF = func(context.Context) (snowman.Block, error) { return parentCoreBlk, nil } @@ -263,14 +232,7 @@ func TestBlockVerify_PreFork_ParentChecks(t *testing.T) { require.NoError(err) // .. create child block ... - childCoreBlk := &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.GenerateTestID(), - StatusV: choices.Processing, - }, - BytesV: []byte{2}, - TimestampV: parentCoreBlk.Timestamp(), - } + childCoreBlk := snowmantest.BuildChild(parentCoreBlk) childBlk := preForkBlock{ Block: childCoreBlk, vm: proVM, @@ -306,16 +268,8 @@ func TestBlockVerify_BlocksBuiltOnPreForkGenesis(t *testing.T) { preActivationTime := activationTime.Add(-1 * time.Second) proVM.Set(preActivationTime) - coreBlk := &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.Empty.Prefix(1111), - StatusV: choices.Processing, - }, - BytesV: []byte{1}, - ParentV: snowmantest.GenesisID, - TimestampV: preActivationTime, - VerifyV: nil, - } + coreBlk := snowmantest.BuildChild(snowmantest.Genesis) + coreBlk.TimestampV = preActivationTime coreVM.BuildBlockF = func(context.Context) (snowman.Block, error) { return coreBlk, nil } @@ -360,15 +314,8 @@ func TestBlockVerify_BlocksBuiltOnPreForkGenesis(t *testing.T) { } require.NoError(proVM.SetPreference(context.Background(), preForkChild.ID())) - secondCoreBlk := &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.Empty.Prefix(2222), - }, - BytesV: []byte{2}, - ParentV: coreBlk.ID(), - TimestampV: postActivationTime, - VerifyV: nil, - } + secondCoreBlk := snowmantest.BuildChild(coreBlk) + secondCoreBlk.TimestampV = postActivationTime coreVM.BuildBlockF = func(context.Context) (snowman.Block, error) { return secondCoreBlk, nil } @@ -391,15 +338,7 @@ func TestBlockVerify_BlocksBuiltOnPreForkGenesis(t *testing.T) { require.NoError(lastPreForkBlk.Verify(context.Background())) require.NoError(proVM.SetPreference(context.Background(), lastPreForkBlk.ID())) - thirdCoreBlk := &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.Empty.Prefix(333), - }, - BytesV: []byte{3}, - ParentV: secondCoreBlk.ID(), - TimestampV: postActivationTime, - VerifyV: nil, - } + thirdCoreBlk := snowmantest.BuildChild(secondCoreBlk) coreVM.BuildBlockF = func(context.Context) (snowman.Block, error) { return thirdCoreBlk, nil } @@ -438,16 +377,7 @@ func TestBlockVerify_BlocksBuiltOnPostForkGenesis(t *testing.T) { }() // build parent block after fork activation time ... - coreBlock := &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.Empty.Prefix(1111), - StatusV: choices.Processing, - }, - BytesV: []byte{1}, - ParentV: snowmantest.GenesisID, - TimestampV: snowmantest.GenesisTimestamp, - VerifyV: nil, - } + coreBlock := snowmantest.BuildChild(snowmantest.Genesis) coreVM.BuildBlockF = func(context.Context) (snowman.Block, error) { return coreBlock, nil } @@ -481,14 +411,7 @@ func TestBlockAccept_PreFork_SetsLastAcceptedBlock(t *testing.T) { require.NoError(proVM.Shutdown(context.Background())) }() - coreBlk := &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.Empty.Prefix(1111), - StatusV: choices.Processing, - }, - BytesV: []byte{1}, - ParentV: snowmantest.GenesisID, - } + coreBlk := snowmantest.BuildChild(snowmantest.Genesis) coreVM.BuildBlockF = func(context.Context) (snowman.Block, error) { return coreBlk, nil } @@ -543,15 +466,7 @@ func TestBlockReject_PreForkBlock_InnerBlockIsRejected(t *testing.T) { require.NoError(proVM.Shutdown(context.Background())) }() - coreBlk := &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.Empty.Prefix(111), - StatusV: choices.Processing, - }, - BytesV: []byte{1}, - ParentV: snowmantest.GenesisID, - HeightV: snowmantest.GenesisHeight + 1, - } + coreBlk := snowmantest.BuildChild(snowmantest.Genesis) coreVM.BuildBlockF = func(context.Context) (snowman.Block, error) { return coreBlk, nil } @@ -582,36 +497,13 @@ func TestBlockVerify_ForkBlockIsOracleBlock(t *testing.T) { postActivationTime := activationTime.Add(time.Second) proVM.Set(postActivationTime) - coreBlkID := ids.GenerateTestID() + coreTestBlk := snowmantest.BuildChild(snowmantest.Genesis) + coreTestBlk.TimestampV = postActivationTime coreBlk := &TestOptionsBlock{ - Block: snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: coreBlkID, - StatusV: choices.Processing, - }, - BytesV: []byte{1}, - ParentV: snowmantest.GenesisID, - TimestampV: postActivationTime, - }, + Block: *coreTestBlk, opts: [2]snowman.Block{ - &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.GenerateTestID(), - StatusV: choices.Processing, - }, - BytesV: []byte{2}, - ParentV: coreBlkID, - TimestampV: postActivationTime, - }, - &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.GenerateTestID(), - StatusV: choices.Processing, - }, - BytesV: []byte{3}, - ParentV: coreBlkID, - TimestampV: postActivationTime, - }, + snowmantest.BuildChild(coreTestBlk), + snowmantest.BuildChild(coreTestBlk), }, } @@ -676,36 +568,13 @@ func TestBlockVerify_ForkBlockIsOracleBlockButChildrenAreSigned(t *testing.T) { postActivationTime := activationTime.Add(time.Second) proVM.Set(postActivationTime) - coreBlkID := ids.GenerateTestID() + coreTestBlk := snowmantest.BuildChild(snowmantest.Genesis) + coreTestBlk.TimestampV = postActivationTime coreBlk := &TestOptionsBlock{ - Block: snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: coreBlkID, - StatusV: choices.Processing, - }, - BytesV: []byte{1}, - ParentV: snowmantest.GenesisID, - TimestampV: postActivationTime, - }, + Block: *coreTestBlk, opts: [2]snowman.Block{ - &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.GenerateTestID(), - StatusV: choices.Processing, - }, - BytesV: []byte{2}, - ParentV: coreBlkID, - TimestampV: postActivationTime, - }, - &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.GenerateTestID(), - StatusV: choices.Processing, - }, - BytesV: []byte{3}, - ParentV: coreBlkID, - TimestampV: postActivationTime, - }, + snowmantest.BuildChild(coreTestBlk), + snowmantest.BuildChild(coreTestBlk), }, } From 4735e218a3faa8c90c42a38293446b383298af23 Mon Sep 17 00:00:00 2001 From: Stephen Buttolph Date: Sat, 27 Apr 2024 14:35:16 -0400 Subject: [PATCH 18/24] use helpers --- vms/proposervm/state_syncable_vm_test.go | 13 +- vms/proposervm/vm_byzantine_test.go | 197 +++-------------------- 2 files changed, 28 insertions(+), 182 deletions(-) diff --git a/vms/proposervm/state_syncable_vm_test.go b/vms/proposervm/state_syncable_vm_test.go index 45093fb67a06..4f44adc0bf74 100644 --- a/vms/proposervm/state_syncable_vm_test.go +++ b/vms/proposervm/state_syncable_vm_test.go @@ -41,13 +41,6 @@ func helperBuildStateSyncTestObjects(t *testing.T) (*fullVM, *VM) { } // load innerVM expectations - innerGenesisBlk := &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.ID{'i', 'n', 'n', 'e', 'r', 'G', 'e', 'n', 'e', 's', 'i', 's', 'I', 'D'}, - }, - HeightV: 0, - BytesV: []byte("genesis state"), - } innerVM.InitializeF = func(context.Context, *snow.Context, database.Database, []byte, []byte, []byte, chan<- common.Message, []*common.Fx, common.AppSender, @@ -55,10 +48,10 @@ func helperBuildStateSyncTestObjects(t *testing.T) (*fullVM, *VM) { return nil } innerVM.LastAcceptedF = func(context.Context) (ids.ID, error) { - return innerGenesisBlk.ID(), nil + return snowmantest.GenesisID, nil } innerVM.GetBlockF = func(context.Context, ids.ID) (snowman.Block, error) { - return innerGenesisBlk, nil + return snowmantest.Genesis, nil } // create the VM @@ -82,7 +75,7 @@ func helperBuildStateSyncTestObjects(t *testing.T) (*fullVM, *VM) { context.Background(), ctx, prefixdb.New([]byte{}, memdb.New()), - innerGenesisBlk.Bytes(), + snowmantest.GenesisBytes, nil, nil, nil, diff --git a/vms/proposervm/vm_byzantine_test.go b/vms/proposervm/vm_byzantine_test.go index a80338c35c86..d4997781cdd4 100644 --- a/vms/proposervm/vm_byzantine_test.go +++ b/vms/proposervm/vm_byzantine_test.go @@ -42,15 +42,7 @@ func TestInvalidByzantineProposerParent(t *testing.T) { require.NoError(proVM.Shutdown(context.Background())) }() - xBlock := &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.GenerateTestID(), - StatusV: choices.Processing, - }, - BytesV: []byte{1}, - ParentV: snowmantest.GenesisID, - HeightV: snowmantest.GenesisHeight + 1, - } + xBlock := snowmantest.BuildChild(snowmantest.Genesis) coreVM.BuildBlockF = func(context.Context) (snowman.Block, error) { return xBlock, nil } @@ -63,25 +55,15 @@ func TestInvalidByzantineProposerParent(t *testing.T) { require.NoError(aBlock.Verify(context.Background())) require.NoError(aBlock.Accept(context.Background())) - yBlockBytes := []byte{2} - yBlock := &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.GenerateTestID(), - StatusV: choices.Processing, - }, - BytesV: yBlockBytes, - ParentV: xBlock.ID(), - HeightV: xBlock.Height() + 1, - } - + yBlock := snowmantest.BuildChild(xBlock) coreVM.ParseBlockF = func(_ context.Context, blockBytes []byte) (snowman.Block, error) { - if !bytes.Equal(blockBytes, yBlockBytes) { + if !bytes.Equal(blockBytes, yBlock.Bytes()) { return nil, errUnknownBlock } return yBlock, nil } - parsedBlock, err := proVM.ParseBlock(context.Background(), yBlockBytes) + parsedBlock, err := proVM.ParseBlock(context.Background(), yBlock.Bytes()) if err != nil { // If there was an error parsing, then this is fine. return @@ -114,33 +96,12 @@ func TestInvalidByzantineProposerOracleParent(t *testing.T) { require.NoError(proVM.Shutdown(context.Background())) }() - xBlockID := ids.GenerateTestID() + xTestBlock := snowmantest.BuildChild(snowmantest.Genesis) xBlock := &TestOptionsBlock{ - Block: snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: xBlockID, - StatusV: choices.Processing, - }, - BytesV: []byte{1}, - ParentV: snowmantest.GenesisID, - }, + Block: *xTestBlock, opts: [2]snowman.Block{ - &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.GenerateTestID(), - StatusV: choices.Processing, - }, - BytesV: []byte{2}, - ParentV: xBlockID, - }, - &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.GenerateTestID(), - StatusV: choices.Processing, - }, - BytesV: []byte{3}, - ParentV: xBlockID, - }, + snowmantest.BuildChild(xTestBlock), + snowmantest.BuildChild(xTestBlock), }, } @@ -222,30 +183,12 @@ func TestInvalidByzantineProposerPreForkParent(t *testing.T) { require.NoError(proVM.Shutdown(context.Background())) }() - xBlock := &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.GenerateTestID(), - StatusV: choices.Processing, - }, - BytesV: []byte{1}, - ParentV: snowmantest.GenesisID, - HeightV: snowmantest.GenesisHeight + 1, - } + xBlock := snowmantest.BuildChild(snowmantest.Genesis) coreVM.BuildBlockF = func(context.Context) (snowman.Block, error) { return xBlock, nil } - yBlockBytes := []byte{2} - yBlock := &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.GenerateTestID(), - StatusV: choices.Processing, - }, - BytesV: yBlockBytes, - ParentV: xBlock.ID(), - HeightV: xBlock.Height() + 1, - } - + yBlock := snowmantest.BuildChild(xBlock) coreVM.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { switch blkID { case snowmantest.GenesisID: @@ -314,31 +257,10 @@ func TestBlockVerify_PostForkOption_FaultyParent(t *testing.T) { }() xBlock := &TestOptionsBlock{ - Block: snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.GenerateTestID(), - StatusV: choices.Processing, - }, - BytesV: []byte{1}, - ParentV: snowmantest.GenesisID, - }, - opts: [2]snowman.Block{ - &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.GenerateTestID(), - StatusV: choices.Processing, - }, - BytesV: []byte{2}, - ParentV: snowmantest.GenesisID, // valid block should reference xBlock - }, - &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.GenerateTestID(), - StatusV: choices.Processing, - }, - BytesV: []byte{3}, - ParentV: snowmantest.GenesisID, // valid block should reference xBlock - }, + Block: *snowmantest.BuildChild(snowmantest.Genesis), + opts: [2]snowman.Block{ // valid blocks should reference xBlock + snowmantest.BuildChild(snowmantest.Genesis), + snowmantest.BuildChild(snowmantest.Genesis), }, } @@ -414,33 +336,12 @@ func TestBlockVerify_InvalidPostForkOption(t *testing.T) { }() // create an Oracle pre-fork block X - xBlockID := ids.GenerateTestID() + xTestBlock := snowmantest.BuildChild(snowmantest.Genesis) xBlock := &TestOptionsBlock{ - Block: snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: xBlockID, - StatusV: choices.Processing, - }, - BytesV: []byte{1}, - ParentV: snowmantest.GenesisID, - }, + Block: *xTestBlock, opts: [2]snowman.Block{ - &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.GenerateTestID(), - StatusV: choices.Processing, - }, - BytesV: []byte{2}, - ParentV: xBlockID, - }, - &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.GenerateTestID(), - StatusV: choices.Processing, - }, - BytesV: []byte{3}, - ParentV: xBlockID, - }, + snowmantest.BuildChild(xTestBlock), + snowmantest.BuildChild(xTestBlock), }, } @@ -449,16 +350,7 @@ func TestBlockVerify_InvalidPostForkOption(t *testing.T) { xInnerOption := xInnerOptions[0] // create a non-Oracle pre-fork block Y - yBlock := &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.GenerateTestID(), - StatusV: choices.Processing, - }, - BytesV: []byte{1}, - ParentV: snowmantest.GenesisID, - HeightV: snowmantest.GenesisHeight + 1, - } - + yBlock := snowmantest.BuildChild(snowmantest.Genesis) ySlb, err := block.BuildUnsigned( snowmantest.GenesisID, snowmantest.GenesisTimestamp, @@ -526,33 +418,12 @@ func TestBlockVerify_InvalidPostForkOption(t *testing.T) { // create an Oracle pre-fork block Z // create post-fork block B from Y - zBlockID := ids.GenerateTestID() + zTestBlock := snowmantest.BuildChild(snowmantest.Genesis) zBlock := &TestOptionsBlock{ - Block: snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: zBlockID, - StatusV: choices.Processing, - }, - BytesV: []byte{1}, - ParentV: snowmantest.GenesisID, - }, + Block: *zTestBlock, opts: [2]snowman.Block{ - &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.GenerateTestID(), - StatusV: choices.Processing, - }, - BytesV: []byte{2}, - ParentV: zBlockID, - }, - &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.GenerateTestID(), - StatusV: choices.Processing, - }, - BytesV: []byte{3}, - ParentV: zBlockID, - }, + snowmantest.BuildChild(zTestBlock), + snowmantest.BuildChild(zTestBlock), }, } @@ -609,26 +480,8 @@ func TestGetBlock_MutatedSignature(t *testing.T) { proVM.Set(snowmantest.GenesisTimestamp) // Create valid core blocks to build our chain on. - coreBlk0 := &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.Empty.Prefix(1111), - StatusV: choices.Processing, - }, - BytesV: []byte{1}, - ParentV: snowmantest.GenesisID, - HeightV: snowmantest.GenesisHeight + 1, - } - - coreBlk1 := &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.Empty.Prefix(2222), - StatusV: choices.Processing, - }, - BytesV: []byte{2}, - ParentV: coreBlk0.ID(), - HeightV: coreBlk0.Height() + 1, - } - + coreBlk0 := snowmantest.BuildChild(snowmantest.Genesis) + coreBlk1 := snowmantest.BuildChild(coreBlk0) coreVM.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { switch blkID { case snowmantest.GenesisID: From a6a9790a55b70a968ea4316cb9e123d9e03e6661 Mon Sep 17 00:00:00 2001 From: Stephen Buttolph Date: Sat, 27 Apr 2024 15:19:34 -0400 Subject: [PATCH 19/24] use helpers --- vms/proposervm/vm_test.go | 542 +++++++------------------------------- 1 file changed, 90 insertions(+), 452 deletions(-) diff --git a/vms/proposervm/vm_test.go b/vms/proposervm/vm_test.go index 03e81741524b..390cb5a1e1ba 100644 --- a/vms/proposervm/vm_test.go +++ b/vms/proposervm/vm_test.go @@ -245,15 +245,7 @@ func TestBuildBlockTimestampAreRoundedToSeconds(t *testing.T) { skewedTimestamp := time.Now().Truncate(time.Second).Add(time.Millisecond) proVM.Set(skewedTimestamp) - coreBlk := &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.Empty.Prefix(111), - StatusV: choices.Processing, - }, - BytesV: []byte{1}, - ParentV: snowmantest.GenesisID, - HeightV: snowmantest.GenesisHeight + 1, - } + coreBlk := snowmantest.BuildChild(snowmantest.Genesis) coreVM.BuildBlockF = func(context.Context) (snowman.Block, error) { return coreBlk, nil } @@ -278,15 +270,7 @@ func TestBuildBlockIsIdempotent(t *testing.T) { require.NoError(proVM.Shutdown(context.Background())) }() - coreBlk := &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.Empty.Prefix(111), - StatusV: choices.Processing, - }, - BytesV: []byte{1}, - ParentV: snowmantest.GenesisID, - HeightV: snowmantest.GenesisHeight + 1, - } + coreBlk := snowmantest.BuildChild(snowmantest.Genesis) coreVM.BuildBlockF = func(context.Context) (snowman.Block, error) { return coreBlk, nil } @@ -316,15 +300,7 @@ func TestFirstProposerBlockIsBuiltOnTopOfGenesis(t *testing.T) { require.NoError(proVM.Shutdown(context.Background())) }() - coreBlk := &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.Empty.Prefix(111), - StatusV: choices.Processing, - }, - BytesV: []byte{1}, - ParentV: snowmantest.GenesisID, - HeightV: snowmantest.GenesisHeight + 1, - } + coreBlk := snowmantest.BuildChild(snowmantest.Genesis) coreVM.BuildBlockF = func(context.Context) (snowman.Block, error) { return coreBlk, nil } @@ -354,30 +330,14 @@ func TestProposerBlocksAreBuiltOnPreferredProBlock(t *testing.T) { }() // add two proBlks... - coreBlk1 := &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.Empty.Prefix(111), - StatusV: choices.Processing, - }, - BytesV: []byte{1}, - ParentV: snowmantest.GenesisID, - HeightV: snowmantest.GenesisHeight + 1, - } + coreBlk1 := snowmantest.BuildChild(snowmantest.Genesis) coreVM.BuildBlockF = func(context.Context) (snowman.Block, error) { return coreBlk1, nil } proBlk1, err := proVM.BuildBlock(context.Background()) require.NoError(err) - coreBlk2 := &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.Empty.Prefix(222), - StatusV: choices.Processing, - }, - BytesV: []byte{2}, - ParentV: snowmantest.GenesisID, - HeightV: snowmantest.GenesisHeight + 1, - } + coreBlk2 := snowmantest.BuildChild(snowmantest.Genesis) coreVM.BuildBlockF = func(context.Context) (snowman.Block, error) { return coreBlk2, nil } @@ -416,15 +376,7 @@ func TestProposerBlocksAreBuiltOnPreferredProBlock(t *testing.T) { require.NoError(proVM.SetPreference(context.Background(), proBlk2.ID())) // build block... - coreBlk3 := &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.Empty.Prefix(333), - StatusV: choices.Processing, - }, - BytesV: []byte{3}, - ParentV: prefcoreBlk.ID(), - HeightV: prefcoreBlk.Height() + 1, - } + coreBlk3 := snowmantest.BuildChild(prefcoreBlk) coreVM.BuildBlockF = func(context.Context) (snowman.Block, error) { return coreBlk3, nil } @@ -449,30 +401,14 @@ func TestCoreBlocksMustBeBuiltOnPreferredCoreBlock(t *testing.T) { require.NoError(proVM.Shutdown(context.Background())) }() - coreBlk1 := &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.Empty.Prefix(111), - StatusV: choices.Processing, - }, - BytesV: []byte{1}, - ParentV: snowmantest.GenesisID, - HeightV: snowmantest.GenesisHeight + 1, - } + coreBlk1 := snowmantest.BuildChild(snowmantest.Genesis) coreVM.BuildBlockF = func(context.Context) (snowman.Block, error) { return coreBlk1, nil } proBlk1, err := proVM.BuildBlock(context.Background()) require.NoError(err) - coreBlk2 := &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.Empty.Prefix(222), - StatusV: choices.Processing, - }, - BytesV: []byte{2}, - ParentV: snowmantest.GenesisID, - HeightV: snowmantest.GenesisHeight + 1, - } + coreBlk2 := snowmantest.BuildChild(snowmantest.Genesis) coreVM.BuildBlockF = func(context.Context) (snowman.Block, error) { return coreBlk2, nil } @@ -512,15 +448,7 @@ func TestCoreBlocksMustBeBuiltOnPreferredCoreBlock(t *testing.T) { require.NoError(proVM.SetPreference(context.Background(), proBlk2.ID())) // build block... - coreBlk3 := &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.Empty.Prefix(333), - StatusV: choices.Processing, - }, - BytesV: []byte{3}, - ParentV: wronglyPreferredcoreBlk.ID(), - HeightV: wronglyPreferredcoreBlk.Height() + 1, - } + coreBlk3 := snowmantest.BuildChild(wronglyPreferredcoreBlk) coreVM.BuildBlockF = func(context.Context) (snowman.Block, error) { return coreBlk3, nil } @@ -546,12 +474,11 @@ func TestCoreBlockFailureCauseProposerBlockParseFailure(t *testing.T) { require.NoError(proVM.Shutdown(context.Background())) }() - innerBlk := &snowmantest.Block{ - BytesV: []byte{1}, - } coreVM.ParseBlockF = func(context.Context, []byte) (snowman.Block, error) { return nil, errMarshallingFailed } + + innerBlk := snowmantest.BuildChild(snowmantest.Genesis) slb, err := statelessblock.Build( proVM.preferred, proVM.Time(), @@ -589,11 +516,7 @@ func TestTwoProBlocksWrappingSameCoreBlockCanBeParsed(t *testing.T) { }() // create two Proposer blocks at the same height - innerBlk := &snowmantest.Block{ - BytesV: []byte{1}, - ParentV: snowmantest.GenesisID, - HeightV: snowmantest.GenesisHeight + 1, - } + innerBlk := snowmantest.BuildChild(snowmantest.Genesis) coreVM.ParseBlockF = func(_ context.Context, b []byte) (snowman.Block, error) { require.Equal(innerBlk.Bytes(), b) return innerBlk, nil @@ -665,11 +588,7 @@ func TestTwoProBlocksWithSameParentCanBothVerify(t *testing.T) { }() // one block is built from this proVM - localcoreBlk := &snowmantest.Block{ - BytesV: []byte{111}, - ParentV: snowmantest.GenesisID, - HeightV: snowmantest.GenesisHeight + 1, - } + localcoreBlk := snowmantest.BuildChild(snowmantest.Genesis) coreVM.BuildBlockF = func(context.Context) (snowman.Block, error) { return localcoreBlk, nil } @@ -679,11 +598,7 @@ func TestTwoProBlocksWithSameParentCanBothVerify(t *testing.T) { require.NoError(builtBlk.Verify(context.Background())) // another block with same parent comes from network and is parsed - netcoreBlk := &snowmantest.Block{ - BytesV: []byte{222}, - ParentV: snowmantest.GenesisID, - HeightV: snowmantest.GenesisHeight + 1, - } + netcoreBlk := snowmantest.BuildChild(snowmantest.Genesis) coreVM.ParseBlockF = func(_ context.Context, b []byte) (snowman.Block, error) { switch { case bytes.Equal(b, snowmantest.GenesisBytes): @@ -757,15 +672,7 @@ func TestPreFork_BuildBlock(t *testing.T) { require.NoError(proVM.Shutdown(context.Background())) }() - coreBlk := &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.Empty.Prefix(333), - StatusV: choices.Processing, - }, - BytesV: []byte{3}, - ParentV: snowmantest.GenesisID, - HeightV: snowmantest.GenesisHeight + 1, - } + coreBlk := snowmantest.BuildChild(snowmantest.Genesis) coreVM.BuildBlockF = func(context.Context) (snowman.Block, error) { return coreBlk, nil } @@ -798,13 +705,7 @@ func TestPreFork_ParseBlock(t *testing.T) { require.NoError(proVM.Shutdown(context.Background())) }() - coreBlk := &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.Empty.Prefix(2021), - }, - BytesV: []byte{1}, - } - + coreBlk := snowmantest.BuildChild(snowmantest.Genesis) coreVM.ParseBlockF = func(_ context.Context, b []byte) (snowman.Block, error) { require.Equal(coreBlk.Bytes(), b) return coreBlk, nil @@ -837,16 +738,7 @@ func TestPreFork_SetPreference(t *testing.T) { require.NoError(proVM.Shutdown(context.Background())) }() - coreBlk0 := &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.Empty.Prefix(333), - StatusV: choices.Processing, - }, - BytesV: []byte{3}, - ParentV: snowmantest.GenesisID, - HeightV: snowmantest.GenesisHeight + 1, - TimestampV: snowmantest.GenesisTimestamp, - } + coreBlk0 := snowmantest.BuildChild(snowmantest.Genesis) coreVM.BuildBlockF = func(context.Context) (snowman.Block, error) { return coreBlk0, nil } @@ -875,16 +767,7 @@ func TestPreFork_SetPreference(t *testing.T) { } require.NoError(proVM.SetPreference(context.Background(), builtBlk.ID())) - coreBlk1 := &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.Empty.Prefix(444), - StatusV: choices.Processing, - }, - BytesV: []byte{3}, - ParentV: coreBlk0.ID(), - HeightV: coreBlk0.Height() + 1, - TimestampV: coreBlk0.Timestamp(), - } + coreBlk1 := snowmantest.BuildChild(coreBlk0) coreVM.BuildBlockF = func(context.Context) (snowman.Block, error) { return coreBlk1, nil } @@ -896,34 +779,24 @@ func TestPreFork_SetPreference(t *testing.T) { func TestExpiredBuildBlock(t *testing.T) { require := require.New(t) - coreGenBlk := &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.GenerateTestID(), - StatusV: choices.Accepted, - }, - HeightV: 0, - TimestampV: snowmantest.GenesisTimestamp, - BytesV: []byte{0}, - } - coreVM := &block.TestVM{} coreVM.T = t coreVM.LastAcceptedF = func(context.Context) (ids.ID, error) { - return coreGenBlk.ID(), nil + return snowmantest.GenesisID, nil } coreVM.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { switch blkID { - case coreGenBlk.ID(): - return coreGenBlk, nil + case snowmantest.GenesisID: + return snowmantest.Genesis, nil default: return nil, errUnknownBlock } } coreVM.ParseBlockF = func(_ context.Context, b []byte) (snowman.Block, error) { switch { - case bytes.Equal(b, coreGenBlk.Bytes()): - return coreGenBlk, nil + case bytes.Equal(b, snowmantest.GenesisBytes): + return snowmantest.Genesis, nil default: return nil, errUnknownBlock } @@ -946,7 +819,7 @@ func TestExpiredBuildBlock(t *testing.T) { T: t, } valState.GetMinimumHeightF = func(context.Context) (uint64, error) { - return coreGenBlk.Height(), nil + return snowmantest.GenesisHeight, nil } valState.GetCurrentHeightF = func(context.Context) (uint64, error) { return defaultPChainHeight, nil @@ -1003,7 +876,7 @@ func TestExpiredBuildBlock(t *testing.T) { coreVM.InitializeF = nil require.NoError(proVM.SetState(context.Background(), snow.NormalOp)) - require.NoError(proVM.SetPreference(context.Background(), coreGenBlk.IDV)) + require.NoError(proVM.SetPreference(context.Background(), snowmantest.GenesisID)) // Notify the proposer VM of a new block on the inner block side toScheduler <- common.PendingTxs @@ -1012,17 +885,9 @@ func TestExpiredBuildBlock(t *testing.T) { // Before calling BuildBlock, verify a remote block and set it as the // preferred block. - coreBlk := &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.GenerateTestID(), - StatusV: choices.Processing, - }, - BytesV: []byte{1}, - ParentV: coreGenBlk.ID(), - HeightV: coreGenBlk.Height() + 1, - } + coreBlk := snowmantest.BuildChild(snowmantest.Genesis) statelessBlock, err := statelessblock.BuildUnsigned( - coreGenBlk.ID(), + snowmantest.GenesisID, proVM.Time(), 0, coreBlk.Bytes(), @@ -1031,8 +896,8 @@ func TestExpiredBuildBlock(t *testing.T) { coreVM.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { switch blkID { - case coreGenBlk.ID(): - return coreGenBlk, nil + case snowmantest.GenesisID: + return snowmantest.Genesis, nil case coreBlk.ID(): return coreBlk, nil default: @@ -1041,8 +906,8 @@ func TestExpiredBuildBlock(t *testing.T) { } coreVM.ParseBlockF = func(_ context.Context, b []byte) (snowman.Block, error) { switch { - case bytes.Equal(b, coreGenBlk.Bytes()): - return coreGenBlk, nil + case bytes.Equal(b, snowmantest.GenesisBytes): + return snowmantest.Genesis, nil case bytes.Equal(b, coreBlk.Bytes()): return coreBlk, nil default: @@ -1110,16 +975,7 @@ func TestInnerBlockDeduplication(t *testing.T) { require.NoError(proVM.Shutdown(context.Background())) }() - coreBlk := &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.GenerateTestID(), - StatusV: choices.Processing, - }, - BytesV: []byte{1}, - ParentV: snowmantest.GenesisID, - HeightV: snowmantest.GenesisHeight + 1, - TimestampV: snowmantest.GenesisTimestamp, - } + coreBlk := snowmantest.BuildChild(snowmantest.Genesis) coreBlk0 := &wrappedBlock{ Block: coreBlk, } @@ -1203,16 +1059,6 @@ func TestInnerBlockDeduplication(t *testing.T) { func TestInnerVMRollback(t *testing.T) { require := require.New(t) - coreGenBlk := &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.GenerateTestID(), - StatusV: choices.Accepted, - }, - HeightV: 0, - TimestampV: snowmantest.GenesisTimestamp, - BytesV: []byte{0}, - } - valState := &validators.TestState{ T: t, } @@ -1233,20 +1079,20 @@ func TestInnerVMRollback(t *testing.T) { coreVM.T = t coreVM.LastAcceptedF = func(context.Context) (ids.ID, error) { - return coreGenBlk.ID(), nil + return snowmantest.GenesisID, nil } coreVM.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { switch blkID { - case coreGenBlk.ID(): - return coreGenBlk, nil + case snowmantest.GenesisID: + return snowmantest.Genesis, nil default: return nil, errUnknownBlock } } coreVM.ParseBlockF = func(_ context.Context, b []byte) (snowman.Block, error) { switch { - case bytes.Equal(b, coreGenBlk.Bytes()): - return coreGenBlk, nil + case bytes.Equal(b, snowmantest.GenesisBytes): + return snowmantest.Genesis, nil default: return nil, errUnknownBlock } @@ -1298,20 +1144,11 @@ func TestInnerVMRollback(t *testing.T) { )) require.NoError(proVM.SetState(context.Background(), snow.NormalOp)) - require.NoError(proVM.SetPreference(context.Background(), coreGenBlk.IDV)) + require.NoError(proVM.SetPreference(context.Background(), snowmantest.GenesisID)) - coreBlk := &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.GenerateTestID(), - StatusV: choices.Processing, - }, - BytesV: []byte{1}, - ParentV: coreGenBlk.ID(), - HeightV: coreGenBlk.Height() + 1, - TimestampV: coreGenBlk.Timestamp(), - } + coreBlk := snowmantest.BuildChild(snowmantest.Genesis) statelessBlock, err := statelessblock.BuildUnsigned( - coreGenBlk.ID(), + snowmantest.GenesisID, coreBlk.Timestamp(), 0, coreBlk.Bytes(), @@ -1320,8 +1157,8 @@ func TestInnerVMRollback(t *testing.T) { coreVM.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { switch blkID { - case coreGenBlk.ID(): - return coreGenBlk, nil + case snowmantest.GenesisID: + return snowmantest.Genesis, nil case coreBlk.ID(): return coreBlk, nil default: @@ -1330,8 +1167,8 @@ func TestInnerVMRollback(t *testing.T) { } coreVM.ParseBlockF = func(_ context.Context, b []byte) (snowman.Block, error) { switch { - case bytes.Equal(b, coreGenBlk.Bytes()): - return coreGenBlk, nil + case bytes.Equal(b, snowmantest.GenesisBytes): + return snowmantest.Genesis, nil case bytes.Equal(b, coreBlk.Bytes()): return coreBlk, nil default: @@ -1390,7 +1227,7 @@ func TestInnerVMRollback(t *testing.T) { lastAcceptedID, err := proVM.LastAccepted(context.Background()) require.NoError(err) - require.Equal(coreGenBlk.IDV, lastAcceptedID) + require.Equal(snowmantest.GenesisID, lastAcceptedID) parsedBlock, err = proVM.ParseBlock(context.Background(), statelessBlock.Bytes()) require.NoError(err) @@ -1419,24 +1256,8 @@ func TestBuildBlockDuringWindow(t *testing.T) { }, nil } - coreBlk0 := &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.GenerateTestID(), - StatusV: choices.Processing, - }, - BytesV: []byte{1}, - ParentV: snowmantest.GenesisID, - HeightV: snowmantest.GenesisHeight + 1, - } - coreBlk1 := &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.GenerateTestID(), - StatusV: choices.Processing, - }, - BytesV: []byte{2}, - ParentV: coreBlk0.ID(), - HeightV: coreBlk0.Height() + 1, - } + coreBlk0 := snowmantest.BuildChild(snowmantest.Genesis) + coreBlk1 := snowmantest.BuildChild(coreBlk0) statelessBlock0, err := statelessblock.BuildUnsigned( snowmantest.GenesisID, proVM.Time(), @@ -1516,15 +1337,7 @@ func TestTwoForks_OneIsAccepted(t *testing.T) { }() // create pre-fork block X and post-fork block A - xBlock := &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.GenerateTestID(), - StatusV: choices.Processing, - }, - BytesV: []byte{1}, - ParentV: snowmantest.GenesisID, - HeightV: snowmantest.GenesisHeight + 1, - } + xBlock := snowmantest.BuildChild(snowmantest.Genesis) coreVM.BuildBlockF = func(context.Context) (snowman.Block, error) { return xBlock, nil @@ -1535,15 +1348,7 @@ func TestTwoForks_OneIsAccepted(t *testing.T) { require.NoError(aBlock.Verify(context.Background())) // use a different way to construct pre-fork block Y and post-fork block B - yBlock := &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.GenerateTestID(), - StatusV: choices.Processing, - }, - BytesV: []byte{2}, - ParentV: snowmantest.GenesisID, - HeightV: snowmantest.GenesisHeight + 1, - } + yBlock := snowmantest.BuildChild(snowmantest.Genesis) ySlb, err := statelessblock.BuildUnsigned( snowmantest.GenesisID, @@ -1565,15 +1370,7 @@ func TestTwoForks_OneIsAccepted(t *testing.T) { require.NoError(bBlock.Verify(context.Background())) // append Z/C to Y/B - zBlock := &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.GenerateTestID(), - StatusV: choices.Processing, - }, - BytesV: []byte{3}, - ParentV: yBlock.ID(), - HeightV: yBlock.Height() + 1, - } + zBlock := snowmantest.BuildChild(yBlock) coreVM.BuildBlockF = func(context.Context) (snowman.Block, error) { return zBlock, nil @@ -1612,27 +1409,8 @@ func TestTooFarAdvanced(t *testing.T) { require.NoError(proVM.Shutdown(context.Background())) }() - xBlock := &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.GenerateTestID(), - StatusV: choices.Processing, - }, - BytesV: []byte{1}, - ParentV: snowmantest.GenesisID, - HeightV: snowmantest.GenesisHeight + 1, - TimestampV: snowmantest.GenesisTimestamp, - } - - yBlock := &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.GenerateTestID(), - StatusV: choices.Processing, - }, - BytesV: []byte{2}, - ParentV: xBlock.ID(), - HeightV: xBlock.Height() + 1, - TimestampV: xBlock.Timestamp(), - } + xBlock := snowmantest.BuildChild(snowmantest.Genesis) + yBlock := snowmantest.BuildChild(xBlock) coreVM.BuildBlockF = func(context.Context) (snowman.Block, error) { return xBlock, nil @@ -1706,36 +1484,12 @@ func TestTwoOptions_OneIsAccepted(t *testing.T) { require.NoError(proVM.Shutdown(context.Background())) }() - xBlockID := ids.GenerateTestID() + xTestBlock := snowmantest.BuildChild(snowmantest.Genesis) xBlock := &TestOptionsBlock{ - Block: snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: xBlockID, - StatusV: choices.Processing, - }, - BytesV: []byte{1}, - ParentV: snowmantest.GenesisID, - TimestampV: snowmantest.GenesisTimestamp, - }, + Block: *xTestBlock, opts: [2]snowman.Block{ - &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.GenerateTestID(), - StatusV: choices.Processing, - }, - BytesV: []byte{2}, - ParentV: xBlockID, - TimestampV: snowmantest.GenesisTimestamp, - }, - &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.GenerateTestID(), - StatusV: choices.Processing, - }, - BytesV: []byte{3}, - ParentV: xBlockID, - TimestampV: snowmantest.GenesisTimestamp, - }, + snowmantest.BuildChild(xTestBlock), + snowmantest.BuildChild(xTestBlock), }, } @@ -1784,16 +1538,7 @@ func TestLaggedPChainHeight(t *testing.T) { require.NoError(proVM.Shutdown(context.Background())) }() - innerBlock := &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.GenerateTestID(), - StatusV: choices.Processing, - }, - BytesV: []byte{1}, - ParentV: snowmantest.GenesisID, - TimestampV: snowmantest.GenesisTimestamp, - } - + innerBlock := snowmantest.BuildChild(snowmantest.Genesis) coreVM.BuildBlockF = func(context.Context) (snowman.Block, error) { return innerBlock, nil } @@ -1812,17 +1557,7 @@ func TestLaggedPChainHeight(t *testing.T) { func TestRejectedHeightNotIndexed(t *testing.T) { require := require.New(t) - coreGenBlk := &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.GenerateTestID(), - StatusV: choices.Accepted, - }, - HeightV: 0, - TimestampV: snowmantest.GenesisTimestamp, - BytesV: []byte{0}, - } - - coreHeights := []ids.ID{coreGenBlk.ID()} + coreHeights := []ids.ID{snowmantest.GenesisID} initialState := []byte("genesis state") coreVM := &block.TestVM{ @@ -1844,20 +1579,20 @@ func TestRejectedHeightNotIndexed(t *testing.T) { return nil } coreVM.LastAcceptedF = func(context.Context) (ids.ID, error) { - return coreGenBlk.ID(), nil + return snowmantest.GenesisID, nil } coreVM.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { - switch { - case blkID == coreGenBlk.ID(): - return coreGenBlk, nil + switch blkID { + case snowmantest.GenesisID: + return snowmantest.Genesis, nil default: return nil, errUnknownBlock } } coreVM.ParseBlockF = func(_ context.Context, b []byte) (snowman.Block, error) { switch { - case bytes.Equal(b, coreGenBlk.Bytes()): - return coreGenBlk, nil + case bytes.Equal(b, snowmantest.GenesisBytes): + return snowmantest.Genesis, nil default: return nil, errUnknownBlock } @@ -1880,7 +1615,7 @@ func TestRejectedHeightNotIndexed(t *testing.T) { T: t, } valState.GetMinimumHeightF = func(context.Context) (uint64, error) { - return coreGenBlk.HeightV, nil + return snowmantest.GenesisHeight, nil } valState.GetCurrentHeightF = func(context.Context) (uint64, error) { return defaultPChainHeight, nil @@ -1936,19 +1671,10 @@ func TestRejectedHeightNotIndexed(t *testing.T) { require.NoError(proVM.SetState(context.Background(), snow.NormalOp)) - require.NoError(proVM.SetPreference(context.Background(), coreGenBlk.IDV)) + require.NoError(proVM.SetPreference(context.Background(), snowmantest.GenesisID)) // create inner block X and outer block A - xBlock := &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.GenerateTestID(), - StatusV: choices.Processing, - }, - BytesV: []byte{1}, - ParentV: coreGenBlk.ID(), - HeightV: coreGenBlk.Height() + 1, - TimestampV: coreGenBlk.Timestamp(), - } + xBlock := snowmantest.BuildChild(snowmantest.Genesis) coreVM.BuildBlockF = func(context.Context) (snowman.Block, error) { return xBlock, nil @@ -1960,20 +1686,11 @@ func TestRejectedHeightNotIndexed(t *testing.T) { require.NoError(aBlock.Verify(context.Background())) // use a different way to construct inner block Y and outer block B - yBlock := &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.GenerateTestID(), - StatusV: choices.Processing, - }, - BytesV: []byte{2}, - ParentV: coreGenBlk.ID(), - HeightV: coreGenBlk.Height() + 1, - TimestampV: coreGenBlk.Timestamp(), - } + yBlock := snowmantest.BuildChild(snowmantest.Genesis) ySlb, err := statelessblock.BuildUnsigned( - coreGenBlk.ID(), - coreGenBlk.Timestamp(), + snowmantest.GenesisID, + snowmantest.GenesisTimestamp, defaultPChainHeight, yBlock.Bytes(), ) @@ -2011,17 +1728,7 @@ func TestRejectedHeightNotIndexed(t *testing.T) { func TestRejectedOptionHeightNotIndexed(t *testing.T) { require := require.New(t) - coreGenBlk := &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.GenerateTestID(), - StatusV: choices.Accepted, - }, - HeightV: 0, - TimestampV: snowmantest.GenesisTimestamp, - BytesV: []byte{0}, - } - - coreHeights := []ids.ID{coreGenBlk.ID()} + coreHeights := []ids.ID{snowmantest.GenesisID} initialState := []byte("genesis state") coreVM := &block.TestVM{ @@ -2043,20 +1750,20 @@ func TestRejectedOptionHeightNotIndexed(t *testing.T) { return nil } coreVM.LastAcceptedF = func(context.Context) (ids.ID, error) { - return coreGenBlk.ID(), nil + return snowmantest.GenesisID, nil } coreVM.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { - switch { - case blkID == coreGenBlk.ID(): - return coreGenBlk, nil + switch blkID { + case snowmantest.GenesisID: + return snowmantest.Genesis, nil default: return nil, errUnknownBlock } } coreVM.ParseBlockF = func(_ context.Context, b []byte) (snowman.Block, error) { switch { - case bytes.Equal(b, coreGenBlk.Bytes()): - return coreGenBlk, nil + case bytes.Equal(b, snowmantest.GenesisBytes): + return snowmantest.Genesis, nil default: return nil, errUnknownBlock } @@ -2079,7 +1786,7 @@ func TestRejectedOptionHeightNotIndexed(t *testing.T) { T: t, } valState.GetMinimumHeightF = func(context.Context) (uint64, error) { - return coreGenBlk.HeightV, nil + return snowmantest.GenesisHeight, nil } valState.GetCurrentHeightF = func(context.Context) (uint64, error) { return defaultPChainHeight, nil @@ -2135,38 +1842,14 @@ func TestRejectedOptionHeightNotIndexed(t *testing.T) { require.NoError(proVM.SetState(context.Background(), snow.NormalOp)) - require.NoError(proVM.SetPreference(context.Background(), coreGenBlk.IDV)) + require.NoError(proVM.SetPreference(context.Background(), snowmantest.GenesisID)) - xBlockID := ids.GenerateTestID() + xTestBlock := snowmantest.BuildChild(snowmantest.Genesis) xBlock := &TestOptionsBlock{ - Block: snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: xBlockID, - StatusV: choices.Processing, - }, - BytesV: []byte{1}, - ParentV: coreGenBlk.ID(), - TimestampV: coreGenBlk.Timestamp(), - }, + Block: *xTestBlock, opts: [2]snowman.Block{ - &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.GenerateTestID(), - StatusV: choices.Processing, - }, - BytesV: []byte{2}, - ParentV: xBlockID, - TimestampV: coreGenBlk.Timestamp(), - }, - &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.GenerateTestID(), - StatusV: choices.Processing, - }, - BytesV: []byte{3}, - ParentV: xBlockID, - TimestampV: coreGenBlk.Timestamp(), - }, + snowmantest.BuildChild(xTestBlock), + snowmantest.BuildChild(xTestBlock), }, } @@ -2333,16 +2016,7 @@ func TestVMInnerBlkCacheDeduplicationRegression(t *testing.T) { }() // create pre-fork block X and post-fork block A - xBlock := &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.GenerateTestID(), - StatusV: choices.Processing, - }, - BytesV: []byte{1}, - ParentV: snowmantest.GenesisID, - HeightV: snowmantest.GenesisHeight + 1, - TimestampV: snowmantest.GenesisTimestamp, - } + xBlock := snowmantest.BuildChild(snowmantest.Genesis) coreVM.BuildBlockF = func(context.Context) (snowman.Block, error) { return xBlock, nil @@ -2359,18 +2033,9 @@ func TestVMInnerBlkCacheDeduplicationRegression(t *testing.T) { ) require.NoError(err) - xBlockCopy := &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: xBlock.IDV, - StatusV: choices.Processing, - }, - BytesV: []byte{1}, - ParentV: snowmantest.GenesisID, - HeightV: snowmantest.GenesisHeight + 1, - TimestampV: snowmantest.GenesisTimestamp, - } + xBlockCopy := *xBlock coreVM.ParseBlockF = func(context.Context, []byte) (snowman.Block, error) { - return xBlockCopy, nil + return &xBlockCopy, nil } bBlockBytes := bStatelessBlock.Bytes() @@ -2412,16 +2077,7 @@ func TestVMInnerBlkMarkedAcceptedRegression(t *testing.T) { }() // create an inner block and wrap it in an postForkBlock. - innerBlock := &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.GenerateTestID(), - StatusV: choices.Processing, - }, - BytesV: []byte{1}, - ParentV: snowmantest.GenesisID, - HeightV: snowmantest.GenesisHeight + 1, - TimestampV: snowmantest.GenesisTimestamp, - } + innerBlock := snowmantest.BuildChild(snowmantest.Genesis) coreVM.BuildBlockF = func(context.Context) (snowman.Block, error) { return innerBlock, nil @@ -2602,16 +2258,7 @@ func TestVM_VerifyBlockWithContext(t *testing.T) { func TestHistoricalBlockDeletion(t *testing.T) { require := require.New(t) - coreGenBlk := &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.GenerateTestID(), - StatusV: choices.Accepted, - }, - HeightV: 0, - TimestampV: snowmantest.GenesisTimestamp, - BytesV: utils.RandomBytes(1024), - } - acceptedBlocks := []snowman.Block{coreGenBlk} + acceptedBlocks := []*snowmantest.Block{snowmantest.Genesis} currentHeight := uint64(0) initialState := []byte("genesis state") @@ -2654,7 +2301,7 @@ func TestHistoricalBlockDeletion(t *testing.T) { ctx.ValidatorState = &validators.TestState{ T: t, GetMinimumHeightF: func(context.Context) (uint64, error) { - return coreGenBlk.HeightV, nil + return snowmantest.GenesisHeight, nil }, GetCurrentHeightF: func(context.Context) (uint64, error) { return defaultPChainHeight, nil @@ -2700,16 +2347,7 @@ func TestHistoricalBlockDeletion(t *testing.T) { issueBlock := func() { lastAcceptedBlock := acceptedBlocks[currentHeight] - innerBlock := &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: ids.GenerateTestID(), - StatusV: choices.Processing, - }, - ParentV: lastAcceptedBlock.ID(), - HeightV: lastAcceptedBlock.Height() + 1, - TimestampV: lastAcceptedBlock.Timestamp(), - BytesV: utils.RandomBytes(1024), - } + innerBlock := snowmantest.BuildChild(lastAcceptedBlock) coreVM.BuildBlockF = func(context.Context) (snowman.Block, error) { return innerBlock, nil From 61354bf3ff51e8f9e7365f0bcbbb4089034631ae Mon Sep 17 00:00:00 2001 From: Stephen Buttolph Date: Sat, 27 Apr 2024 15:33:12 -0400 Subject: [PATCH 20/24] cleanup chain components --- snow/choices/test_decidable.go | 4 + vms/components/chain/state_test.go | 121 +++++++++-------------------- 2 files changed, 39 insertions(+), 86 deletions(-) diff --git a/snow/choices/test_decidable.go b/snow/choices/test_decidable.go index 39e8ed67b7c1..e750c2465f91 100644 --- a/snow/choices/test_decidable.go +++ b/snow/choices/test_decidable.go @@ -48,3 +48,7 @@ func (d *TestDecidable) Reject(context.Context) error { func (d *TestDecidable) Status() Status { return d.StatusV } + +func (d *TestDecidable) SetStatus(status Status) { + d.StatusV = status +} diff --git a/vms/components/chain/state_test.go b/vms/components/chain/state_test.go index c67e344295ee..d1a71beedf63 100644 --- a/vms/components/chain/state_test.go +++ b/vms/components/chain/state_test.go @@ -22,8 +22,6 @@ import ( ) var ( - _ Block = (*TestBlock)(nil) - errCantBuildBlock = errors.New("can't build new block") errVerify = errors.New("verify failed") errAccept = errors.New("accept failed") @@ -31,36 +29,25 @@ var ( errUnexpectedBlockBytes = errors.New("unexpected block bytes") ) -type TestBlock struct { - *snowmantest.Block -} - -// SetStatus sets the status of the Block. -func (b *TestBlock) SetStatus(status choices.Status) { - b.Block.TestDecidable.StatusV = status -} - // NewTestBlock returns a new test block with height, bytes, and ID derived from [i] // and using [parentID] as the parent block ID -func NewTestBlock(i uint64, parentID ids.ID) *TestBlock { +func NewTestBlock(i uint64, parentID ids.ID) *snowmantest.Block { b := []byte{byte(i)} id := hashing.ComputeHash256Array(b) - return &TestBlock{ - Block: &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: id, - StatusV: choices.Unknown, - }, - HeightV: i, - ParentV: parentID, - BytesV: b, + return &snowmantest.Block{ + TestDecidable: choices.TestDecidable{ + IDV: id, + StatusV: choices.Unknown, }, + HeightV: i, + ParentV: parentID, + BytesV: b, } } // NewTestBlocks generates [numBlocks] consecutive blocks -func NewTestBlocks(numBlocks uint64) []*TestBlock { - blks := make([]*TestBlock, 0, numBlocks) +func NewTestBlocks(numBlocks uint64) []*snowmantest.Block { + blks := make([]*snowmantest.Block, 0, numBlocks) parentID := ids.Empty for i := uint64(0); i < numBlocks; i++ { blks = append(blks, NewTestBlock(i, parentID)) @@ -71,18 +58,17 @@ func NewTestBlocks(numBlocks uint64) []*TestBlock { return blks } -func createInternalBlockFuncs(t *testing.T, blks []*TestBlock) ( +func createInternalBlockFuncs(blks []*snowmantest.Block) ( func(ctx context.Context, blkID ids.ID) (snowman.Block, error), func(ctx context.Context, b []byte) (snowman.Block, error), func(ctx context.Context, height uint64) (ids.ID, error), ) { - blkMap := make(map[ids.ID]*TestBlock) - blkByteMap := make(map[byte]*TestBlock) + blkMap := make(map[ids.ID]*snowmantest.Block) + blkBytesMap := make(map[string]*snowmantest.Block) for _, blk := range blks { blkMap[blk.ID()] = blk blkBytes := blk.Bytes() - require.Len(t, blkBytes, 1) - blkByteMap[blkBytes[0]] = blk + blkBytesMap[string(blkBytes)] = blk } getBlock := func(_ context.Context, id ids.ID) (snowman.Block, error) { @@ -95,11 +81,7 @@ func createInternalBlockFuncs(t *testing.T, blks []*TestBlock) ( } parseBlk := func(_ context.Context, b []byte) (snowman.Block, error) { - if len(b) != 1 { - return nil, fmt.Errorf("expected block bytes to be length 1, but found %d", len(b)) - } - - blk, ok := blkByteMap[b[0]] + blk, ok := blkBytesMap[string(b)] if !ok { return nil, fmt.Errorf("%w: %x", errUnexpectedBlockBytes, b) } @@ -197,22 +179,10 @@ func TestState(t *testing.T) { blk2 := testBlks[2] // Need to create a block with a different bytes and hash here // to generate a conflict with blk2 - blk3Bytes := []byte{byte(3)} - blk3ID := hashing.ComputeHash256Array(blk3Bytes) - blk3 := &TestBlock{ - Block: &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: blk3ID, - StatusV: choices.Processing, - }, - HeightV: uint64(2), - BytesV: blk3Bytes, - ParentV: blk1.IDV, - }, - } + blk3 := snowmantest.BuildChild(blk1) testBlks = append(testBlks, blk3) - getBlock, parseBlock, getCanonicalBlockID := createInternalBlockFuncs(t, testBlks) + getBlock, parseBlock, getCanonicalBlockID := createInternalBlockFuncs(testBlks) chainState := NewState(&Config{ DecidedCacheSize: 2, MissingCacheSize: 2, @@ -291,7 +261,7 @@ func TestBuildBlock(t *testing.T) { genesisBlock.SetStatus(choices.Accepted) blk1 := testBlks[1] - getBlock, parseBlock, getCanonicalBlockID := createInternalBlockFuncs(t, testBlks) + getBlock, parseBlock, getCanonicalBlockID := createInternalBlockFuncs(testBlks) buildBlock := func(context.Context) (snowman.Block, error) { // Once the block is built, mark it as processing blk1.SetStatus(choices.Processing) @@ -336,7 +306,7 @@ func TestStateDecideBlock(t *testing.T) { badVerifyBlk.VerifyV = errVerify badRejectBlk := testBlks[3] badRejectBlk.RejectV = errReject - getBlock, parseBlock, getCanonicalBlockID := createInternalBlockFuncs(t, testBlks) + getBlock, parseBlock, getCanonicalBlockID := createInternalBlockFuncs(testBlks) chainState := NewState(&Config{ DecidedCacheSize: 2, MissingCacheSize: 2, @@ -389,7 +359,7 @@ func TestStateParent(t *testing.T) { blk1 := testBlks[1] blk2 := testBlks[2] - getBlock, parseBlock, getCanonicalBlockID := createInternalBlockFuncs(t, testBlks) + getBlock, parseBlock, getCanonicalBlockID := createInternalBlockFuncs(testBlks) chainState := NewState(&Config{ DecidedCacheSize: 2, MissingCacheSize: 2, @@ -430,7 +400,7 @@ func TestGetBlockInternal(t *testing.T) { genesisBlock := testBlks[0] genesisBlock.SetStatus(choices.Accepted) - getBlock, parseBlock, getCanonicalBlockID := createInternalBlockFuncs(t, testBlks) + getBlock, parseBlock, getCanonicalBlockID := createInternalBlockFuncs(testBlks) chainState := NewState(&Config{ DecidedCacheSize: 2, MissingCacheSize: 2, @@ -444,13 +414,13 @@ func TestGetBlockInternal(t *testing.T) { }) genesisBlockInternal := chainState.LastAcceptedBlockInternal() - require.IsType(&TestBlock{}, genesisBlockInternal) + require.IsType(&snowmantest.Block{}, genesisBlockInternal) require.Equal(genesisBlock.ID(), genesisBlockInternal.ID()) blk, err := chainState.GetBlockInternal(context.Background(), genesisBlock.ID()) require.NoError(err) - require.IsType(&TestBlock{}, blk) + require.IsType(&snowmantest.Block{}, blk) require.Equal(genesisBlock.ID(), blk.ID()) } @@ -462,7 +432,7 @@ func TestGetBlockError(t *testing.T) { genesisBlock.SetStatus(choices.Accepted) blk1 := testBlks[1] - getBlock, parseBlock, getCanonicalBlockID := createInternalBlockFuncs(t, testBlks) + getBlock, parseBlock, getCanonicalBlockID := createInternalBlockFuncs(testBlks) wrappedGetBlock := func(ctx context.Context, id ids.ID) (snowman.Block, error) { blk, err := getBlock(ctx, id) if err != nil { @@ -499,7 +469,7 @@ func TestParseBlockError(t *testing.T) { genesisBlock := testBlks[0] genesisBlock.SetStatus(choices.Accepted) - getBlock, parseBlock, getCanonicalBlockID := createInternalBlockFuncs(t, testBlks) + getBlock, parseBlock, getCanonicalBlockID := createInternalBlockFuncs(testBlks) chainState := NewState(&Config{ DecidedCacheSize: 2, MissingCacheSize: 2, @@ -521,7 +491,7 @@ func TestBuildBlockError(t *testing.T) { genesisBlock := testBlks[0] genesisBlock.SetStatus(choices.Accepted) - getBlock, parseBlock, getCanonicalBlockID := createInternalBlockFuncs(t, testBlks) + getBlock, parseBlock, getCanonicalBlockID := createInternalBlockFuncs(testBlks) chainState := NewState(&Config{ DecidedCacheSize: 2, MissingCacheSize: 2, @@ -547,7 +517,7 @@ func TestMeteredCache(t *testing.T) { genesisBlock := testBlks[0] genesisBlock.SetStatus(choices.Accepted) - getBlock, parseBlock, getCanonicalBlockID := createInternalBlockFuncs(t, testBlks) + getBlock, parseBlock, getCanonicalBlockID := createInternalBlockFuncs(testBlks) config := &Config{ DecidedCacheSize: 2, MissingCacheSize: 2, @@ -575,7 +545,7 @@ func TestStateBytesToIDCache(t *testing.T) { blk1 := testBlks[1] blk2 := testBlks[2] - getBlock, parseBlock, getCanonicalBlockID := createInternalBlockFuncs(t, testBlks) + getBlock, parseBlock, getCanonicalBlockID := createInternalBlockFuncs(testBlks) buildBlock := func(context.Context) (snowman.Block, error) { require.FailNow("shouldn't have been called") return nil, nil @@ -628,34 +598,13 @@ func TestSetLastAcceptedBlock(t *testing.T) { genesisBlock.SetStatus(choices.Accepted) postSetBlk1ParentID := hashing.ComputeHash256Array([]byte{byte(199)}) - postSetBlk1Bytes := []byte{byte(200)} - postSetBlk2Bytes := []byte{byte(201)} - postSetBlk1 := &TestBlock{ - Block: &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: hashing.ComputeHash256Array(postSetBlk1Bytes), - StatusV: choices.Accepted, - }, - HeightV: uint64(200), - BytesV: postSetBlk1Bytes, - ParentV: postSetBlk1ParentID, - }, - } - postSetBlk2 := &TestBlock{ - Block: &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: hashing.ComputeHash256Array(postSetBlk2Bytes), - StatusV: choices.Processing, - }, - HeightV: uint64(201), - BytesV: postSetBlk2Bytes, - ParentV: postSetBlk1.IDV, - }, - } + postSetBlk1 := NewTestBlock(200, postSetBlk1ParentID) + postSetBlk2 := NewTestBlock(201, postSetBlk1.ID()) + // note we do not need to parse postSetBlk1 so it is omitted here testBlks = append(testBlks, postSetBlk2) - getBlock, parseBlock, getCanonicalBlockID := createInternalBlockFuncs(t, testBlks) + getBlock, parseBlock, getCanonicalBlockID := createInternalBlockFuncs(testBlks) chainState := NewState(&Config{ LastAcceptedBlock: genesisBlock, GetBlock: getBlock, @@ -696,7 +645,7 @@ func TestSetLastAcceptedBlockWithProcessingBlocksErrors(t *testing.T) { blk1 := testBlks[1] resetBlk := testBlks[4] - getBlock, parseBlock, getCanonicalBlockID := createInternalBlockFuncs(t, testBlks) + getBlock, parseBlock, getCanonicalBlockID := createInternalBlockFuncs(testBlks) buildBlock := func(context.Context) (snowman.Block, error) { // Once the block is built, mark it as processing blk1.SetStatus(choices.Processing) @@ -738,7 +687,7 @@ func TestStateParseTransitivelyAcceptedBlock(t *testing.T) { blk2 := testBlks[2] blk2.SetStatus(choices.Accepted) - getBlock, parseBlock, getCanonicalBlockID := createInternalBlockFuncs(t, testBlks) + getBlock, parseBlock, getCanonicalBlockID := createInternalBlockFuncs(testBlks) chainState := NewState(&Config{ DecidedCacheSize: 2, MissingCacheSize: 2, @@ -764,7 +713,7 @@ func TestIsProcessing(t *testing.T) { genesisBlock.SetStatus(choices.Accepted) blk1 := testBlks[1] - getBlock, parseBlock, getCanonicalBlockID := createInternalBlockFuncs(t, testBlks) + getBlock, parseBlock, getCanonicalBlockID := createInternalBlockFuncs(testBlks) chainState := NewState(&Config{ DecidedCacheSize: 2, MissingCacheSize: 2, From 54d39270af1a64fda4c263fa43da18779cef2792 Mon Sep 17 00:00:00 2001 From: Stephen Buttolph Date: Sat, 27 Apr 2024 19:02:46 -0400 Subject: [PATCH 21/24] nits --- snow/engine/snowman/transitive_test.go | 190 +++++++++---------------- 1 file changed, 69 insertions(+), 121 deletions(-) diff --git a/snow/engine/snowman/transitive_test.go b/snow/engine/snowman/transitive_test.go index da2631bef188..a6a3728fa39f 100644 --- a/snow/engine/snowman/transitive_test.go +++ b/snow/engine/snowman/transitive_test.go @@ -140,9 +140,8 @@ func TestEngineDropsAttemptToIssueBlockAfterFailedRequest(t *testing.T) { peerID, _, sender, vm, engine := setup(t, DefaultConfig(t)) - blks := snowmantest.BuildDescendants(snowmantest.Genesis, 2) - parent := blks[0] - child := blks[1] + parent := snowmantest.BuildChild(snowmantest.Genesis) + child := snowmantest.BuildChild(parent) var request *common.Request sender.SendGetF = func(_ context.Context, nodeID ids.NodeID, requestID uint32, blkID ids.ID) { @@ -188,9 +187,8 @@ func TestEngineQuery(t *testing.T) { peerID, _, sender, vm, engine := setup(t, DefaultConfig(t)) - blks := snowmantest.BuildDescendants(snowmantest.Genesis, 2) - parent := blks[0] - child := blks[1] + parent := snowmantest.BuildChild(snowmantest.Genesis) + child := snowmantest.BuildChild(parent) var sendChitsCalled bool sender.SendChitsF = func(_ context.Context, _ ids.NodeID, requestID uint32, preferredID ids.ID, preferredIDByHeight ids.ID, accepted ids.ID) { @@ -374,9 +372,8 @@ func TestEngineMultipleQuery(t *testing.T) { vm.GetBlockF = nil vm.LastAcceptedF = nil - blks := snowmantest.BuildDescendants(snowmantest.Genesis, 2) - blk0 := blks[0] - blk1 := blks[1] + blk0 := snowmantest.BuildChild(snowmantest.Genesis) + blk1 := snowmantest.BuildChild(blk0) queried := new(bool) queryRequestID := new(uint32) @@ -474,9 +471,8 @@ func TestEngineBlockedIssue(t *testing.T) { sender.Default(false) - blks := snowmantest.BuildDescendants(snowmantest.Genesis, 2) - blk0 := blks[0] - blk1 := blks[1] + blk0 := snowmantest.BuildChild(snowmantest.Genesis) + blk1 := snowmantest.BuildChild(blk0) sender.SendGetF = func(context.Context, ids.NodeID, uint32, ids.ID) {} vm.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { @@ -542,8 +538,7 @@ func TestEnginePushQuery(t *testing.T) { sender.Default(true) - blks := snowmantest.BuildDescendants(snowmantest.Genesis, 1) - blk := blks[0] + blk := snowmantest.BuildChild(snowmantest.Genesis) vm.ParseBlockF = func(_ context.Context, b []byte) (snowman.Block, error) { if bytes.Equal(b, blk.Bytes()) { @@ -597,8 +592,7 @@ func TestEngineBuildBlock(t *testing.T) { sender.Default(true) - blks := snowmantest.BuildDescendants(snowmantest.Genesis, 1) - blk := blks[0] + blk := snowmantest.BuildChild(snowmantest.Genesis) vm.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { switch blkID { @@ -701,8 +695,7 @@ func TestVoteCanceling(t *testing.T) { vm.LastAcceptedF = nil - blks := snowmantest.BuildDescendants(snowmantest.Genesis, 1) - blk := blks[0] + blk := snowmantest.BuildChild(snowmantest.Genesis) queried := new(bool) queryRequestID := new(uint32) @@ -768,8 +761,7 @@ func TestEngineNoQuery(t *testing.T) { require.NoError(te.Start(context.Background(), 0)) - blks := snowmantest.BuildDescendants(snowmantest.Genesis, 1) - blk := blks[0] + blk := snowmantest.BuildChild(snowmantest.Genesis) require.NoError(te.issue( context.Background(), @@ -849,8 +841,7 @@ func TestEngineAbandonChit(t *testing.T) { sender.Default(true) - blks := snowmantest.BuildDescendants(snowmantest.Genesis, 1) - blk := blks[0] + blk := snowmantest.BuildChild(snowmantest.Genesis) vm.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { switch blkID { @@ -903,8 +894,7 @@ func TestEngineAbandonChitWithUnexpectedPutBlock(t *testing.T) { sender.Default(true) - blks := snowmantest.BuildDescendants(snowmantest.Genesis, 1) - blk := blks[0] + blk := snowmantest.BuildChild(snowmantest.Genesis) vm.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { switch blkID { @@ -964,10 +954,9 @@ func TestEngineBlockingChitRequest(t *testing.T) { sender.Default(true) - blks := snowmantest.BuildDescendants(snowmantest.Genesis, 3) - missingBlk := blks[0] - parentBlk := blks[1] - blockingBlk := blks[2] + missingBlk := snowmantest.BuildChild(snowmantest.Genesis) + parentBlk := snowmantest.BuildChild(missingBlk) + blockingBlk := snowmantest.BuildChild(parentBlk) vm.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { switch blkID { @@ -1023,12 +1012,10 @@ func TestEngineBlockingChitResponse(t *testing.T) { sender.Default(true) - issuedBlks := snowmantest.BuildDescendants(snowmantest.Genesis, 1) - issuedBlk := issuedBlks[0] + issuedBlk := snowmantest.BuildChild(snowmantest.Genesis) - blockingBlks := snowmantest.BuildDescendants(snowmantest.Genesis, 2) - missingBlk := blockingBlks[0] - blockingBlk := blockingBlks[1] + missingBlk := snowmantest.BuildChild(snowmantest.Genesis) + blockingBlk := snowmantest.BuildChild(missingBlk) vm.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { switch blkID { @@ -1160,8 +1147,7 @@ func TestEngineRetryFetch(t *testing.T) { sender.Default(true) - blks := snowmantest.BuildDescendants(snowmantest.Genesis, 1) - missingBlk := blks[0] + missingBlk := snowmantest.BuildChild(snowmantest.Genesis) vm.CantGetBlock = false @@ -1200,10 +1186,8 @@ func TestEngineUndeclaredDependencyDeadlock(t *testing.T) { sender.Default(true) - blks := snowmantest.BuildDescendants(snowmantest.Genesis, 2) - validBlk := blks[0] - - invalidBlk := blks[1] + validBlk := snowmantest.BuildChild(snowmantest.Genesis) + invalidBlk := snowmantest.BuildChild(validBlk) invalidBlk.VerifyV = errTest invalidBlkID := invalidBlk.ID() @@ -1279,9 +1263,8 @@ func TestEngineInvalidBlockIgnoredFromUnexpectedPeer(t *testing.T) { sender.Default(true) - blks := snowmantest.BuildDescendants(snowmantest.Genesis, 2) - missingBlk := blks[0] - pendingBlk := blks[1] + missingBlk := snowmantest.BuildChild(snowmantest.Genesis) + pendingBlk := snowmantest.BuildChild(missingBlk) parsed := new(bool) vm.ParseBlockF = func(_ context.Context, b []byte) (snowman.Block, error) { @@ -1353,9 +1336,8 @@ func TestEnginePushQueryRequestIDConflict(t *testing.T) { sender.Default(true) - blks := snowmantest.BuildDescendants(snowmantest.Genesis, 2) - missingBlk := blks[0] - pendingBlk := blks[1] + missingBlk := snowmantest.BuildChild(snowmantest.Genesis) + pendingBlk := snowmantest.BuildChild(missingBlk) parsed := new(bool) vm.ParseBlockF = func(_ context.Context, b []byte) (snowman.Block, error) { @@ -1464,8 +1446,7 @@ func TestEngineAggressivePolling(t *testing.T) { vm.GetBlockF = nil vm.LastAcceptedF = nil - blks := snowmantest.BuildDescendants(snowmantest.Genesis, 1) - pendingBlk := blks[0] + pendingBlk := snowmantest.BuildChild(snowmantest.Genesis) parsed := new(bool) vm.ParseBlockF = func(_ context.Context, b []byte) (snowman.Block, error) { @@ -1552,8 +1533,7 @@ func TestEngineDoubleChit(t *testing.T) { vm.LastAcceptedF = nil - blks := snowmantest.BuildDescendants(snowmantest.Genesis, 1) - blk := blks[0] + blk := snowmantest.BuildChild(snowmantest.Genesis) queried := new(bool) queryRequestID := new(uint32) @@ -1701,12 +1681,9 @@ func TestEngineReceiveNewRejectedBlock(t *testing.T) { vdr, _, sender, vm, te := setup(t, DefaultConfig(t)) - acceptedBlks := snowmantest.BuildDescendants(snowmantest.Genesis, 1) - acceptedBlk := acceptedBlks[0] - - rejectedBlks := snowmantest.BuildDescendants(snowmantest.Genesis, 2) - rejectedBlk := rejectedBlks[0] - pendingBlk := rejectedBlks[1] + acceptedBlk := snowmantest.BuildChild(snowmantest.Genesis) + rejectedBlk := snowmantest.BuildChild(snowmantest.Genesis) + pendingBlk := snowmantest.BuildChild(rejectedBlk) vm.ParseBlockF = func(_ context.Context, b []byte) (snowman.Block, error) { switch { @@ -1772,12 +1749,9 @@ func TestEngineRejectionAmplification(t *testing.T) { vdr, _, sender, vm, te := setup(t, DefaultConfig(t)) - acceptedBlks := snowmantest.BuildDescendants(snowmantest.Genesis, 1) - acceptedBlk := acceptedBlks[0] - - rejectedBlks := snowmantest.BuildDescendants(snowmantest.Genesis, 2) - rejectedBlk := rejectedBlks[0] - pendingBlk := rejectedBlks[1] + acceptedBlk := snowmantest.BuildChild(snowmantest.Genesis) + rejectedBlk := snowmantest.BuildChild(snowmantest.Genesis) + pendingBlk := snowmantest.BuildChild(rejectedBlk) vm.ParseBlockF = func(_ context.Context, b []byte) (snowman.Block, error) { switch { @@ -1861,12 +1835,9 @@ func TestEngineTransitiveRejectionAmplificationDueToRejectedParent(t *testing.T) vdr, _, sender, vm, te := setup(t, DefaultConfig(t)) - acceptedBlks := snowmantest.BuildDescendants(snowmantest.Genesis, 1) - acceptedBlk := acceptedBlks[0] - - rejectedBlks := snowmantest.BuildDescendants(snowmantest.Genesis, 2) - rejectedBlk := rejectedBlks[0] - pendingBlk := rejectedBlks[1] + acceptedBlk := snowmantest.BuildChild(snowmantest.Genesis) + rejectedBlk := snowmantest.BuildChild(snowmantest.Genesis) + pendingBlk := snowmantest.BuildChild(rejectedBlk) pendingBlk.RejectV = errUnexpectedCall vm.ParseBlockF = func(_ context.Context, b []byte) (snowman.Block, error) { @@ -1927,14 +1898,11 @@ func TestEngineTransitiveRejectionAmplificationDueToInvalidParent(t *testing.T) vdr, _, sender, vm, te := setup(t, DefaultConfig(t)) - acceptedBlks := snowmantest.BuildDescendants(snowmantest.Genesis, 1) - acceptedBlk := acceptedBlks[0] - - rejectedBlks := snowmantest.BuildDescendants(snowmantest.Genesis, 2) - rejectedBlk := rejectedBlks[0] + acceptedBlk := snowmantest.BuildChild(snowmantest.Genesis) + rejectedBlk := snowmantest.BuildChild(snowmantest.Genesis) rejectedBlk.VerifyV = errUnexpectedCall - pendingBlk := rejectedBlks[1] - pendingBlk.RejectV = errUnexpectedCall + pendingBlk := snowmantest.BuildChild(rejectedBlk) + pendingBlk.VerifyV = errUnexpectedCall vm.ParseBlockF = func(_ context.Context, b []byte) (snowman.Block, error) { switch { @@ -1997,11 +1965,8 @@ func TestEngineNonPreferredAmplification(t *testing.T) { vdr, _, sender, vm, te := setup(t, DefaultConfig(t)) - preferredBlks := snowmantest.BuildDescendants(snowmantest.Genesis, 1) - preferredBlk := preferredBlks[0] - - nonPreferredBlks := snowmantest.BuildDescendants(snowmantest.Genesis, 1) - nonPreferredBlk := nonPreferredBlks[0] + preferredBlk := snowmantest.BuildChild(snowmantest.Genesis) + nonPreferredBlk := snowmantest.BuildChild(snowmantest.Genesis) vm.ParseBlockF = func(_ context.Context, b []byte) (snowman.Block, error) { switch { @@ -2055,11 +2020,9 @@ func TestEngineBubbleVotesThroughInvalidBlock(t *testing.T) { vdr, _, sender, vm, te := setup(t, DefaultConfig(t)) expectedVdrSet := set.Of(vdr) - blks := snowmantest.BuildDescendants(snowmantest.Genesis, 2) - blk1 := blks[0] - + blk1 := snowmantest.BuildChild(snowmantest.Genesis) + blk2 := snowmantest.BuildChild(blk1) // blk2 cannot pass verification until [blk1] has been marked as accepted. - blk2 := blks[1] blk2.VerifyV = errInvalid // The VM should be able to parse [blk1] and [blk2] @@ -2214,14 +2177,11 @@ func TestEngineBubbleVotesThroughInvalidChain(t *testing.T) { vdr, _, sender, vm, te := setup(t, DefaultConfig(t)) expectedVdrSet := set.Of(vdr) - blks := snowmantest.BuildDescendants(snowmantest.Genesis, 3) - blk1 := blks[0] - + blk1 := snowmantest.BuildChild(snowmantest.Genesis) // blk2 cannot pass verification until [blk1] has been marked as accepted. - blk2 := blks[1] + blk2 := snowmantest.BuildChild(blk1) blk2.VerifyV = errInvalid - - blk3 := blks[2] + blk3 := snowmantest.BuildChild(blk2) // The VM should be able to parse [blk1], [blk2], and [blk3] vm.ParseBlockF = func(_ context.Context, b []byte) (snowman.Block, error) { @@ -2328,26 +2288,18 @@ func TestEngineBuildBlockWithCachedNonVerifiedParent(t *testing.T) { sender.Default(true) - blks := snowmantest.BuildDescendants(snowmantest.Genesis, 3) - grandParentBlk := blks[0] + grandParentBlk := snowmantest.BuildChild(snowmantest.Genesis) - parentBlkA := blks[1] + parentBlkA := snowmantest.BuildChild(grandParentBlk) parentBlkA.VerifyV = errInvalid // Note that [parentBlkB] has the same [ID()] as [parentBlkA]; // it's a different instantiation of the same block. - parentBlkB := &snowmantest.Block{ - TestDecidable: choices.TestDecidable{ - IDV: parentBlkA.IDV, - StatusV: parentBlkA.StatusV, - }, - ParentV: parentBlkA.ParentV, - HeightV: parentBlkA.HeightV, - BytesV: parentBlkA.BytesV, - } + parentBlkB := *parentBlkA + parentBlkB.VerifyV = nil // Child of [parentBlkA]/[parentBlkB] - childBlk := blks[2] + childBlk := snowmantest.BuildChild(parentBlkA) vm.ParseBlockF = func(_ context.Context, b []byte) (snowman.Block, error) { require.Equal(grandParentBlk.BytesV, b) @@ -2387,7 +2339,7 @@ func TestEngineBuildBlockWithCachedNonVerifiedParent(t *testing.T) { vm.ParseBlockF = func(_ context.Context, b []byte) (snowman.Block, error) { require.Equal(parentBlkB.BytesV, b) - return parentBlkB, nil + return &parentBlkB, nil } vm.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { @@ -2397,7 +2349,7 @@ func TestEngineBuildBlockWithCachedNonVerifiedParent(t *testing.T) { case grandParentBlk.IDV: return grandParentBlk, nil case parentBlkB.IDV: - return parentBlkB, nil + return &parentBlkB, nil default: return nil, errUnknownBlock } @@ -2489,8 +2441,7 @@ func TestEngineApplyAcceptedFrontierInQueryFailed(t *testing.T) { vm.LastAcceptedF = nil - blks := snowmantest.BuildDescendants(snowmantest.Genesis, 1) - blk := blks[0] + blk := snowmantest.BuildChild(snowmantest.Genesis) queryRequestID := new(uint32) sender.SendPushQueryF = func(_ context.Context, inVdrs set.Set[ids.NodeID], requestID uint32, blkBytes []byte, requestedHeight uint64) { @@ -2584,8 +2535,7 @@ func TestEngineRepollsMisconfiguredSubnet(t *testing.T) { vm.LastAcceptedF = nil - blks := snowmantest.BuildDescendants(snowmantest.Genesis, 1) - blk := blks[0] + blk := snowmantest.BuildChild(snowmantest.Genesis) // Issue the block. This shouldn't call the sender, because creating the // poll should fail. @@ -2912,8 +2862,8 @@ func TestGetProcessingAncestor(t *testing.T) { ctx = snowtest.ConsensusContext( snowtest.Context(t, snowtest.PChainID), ) - issuedChain = snowmantest.BuildDescendants(snowmantest.Genesis, 1) - unissuedOnIssuedChain = snowmantest.BuildDescendants(issuedChain[0], 1) + issuedBlock = snowmantest.BuildChild(snowmantest.Genesis) + unissuedBlock = snowmantest.BuildChild(issuedBlock) ) metrics, err := newMetrics("", prometheus.NewRegistry()) @@ -2928,12 +2878,10 @@ func TestGetProcessingAncestor(t *testing.T) { time.Now(), )) - for _, blk := range issuedChain { - require.NoError(t, c.Add(context.Background(), blk)) - } + require.NoError(t, c.Add(context.Background(), issuedBlock)) nonVerifiedAncestors := ancestor.NewTree() - nonVerifiedAncestors.Add(unissuedOnIssuedChain[0].ID(), unissuedOnIssuedChain[0].Parent()) + nonVerifiedAncestors.Add(unissuedBlock.ID(), unissuedBlock.Parent()) tests := []struct { name string @@ -2986,8 +2934,8 @@ func TestGetProcessingAncestor(t *testing.T) { pending: map[ids.ID]snowman.Block{}, nonVerifiedCache: &cache.Empty[ids.ID, snowman.Block]{}, }, - initialVote: issuedChain[0].ID(), - expectedAncestor: issuedChain[0].ID(), + initialVote: issuedBlock.ID(), + expectedAncestor: issuedBlock.ID(), expectedFound: true, }, { @@ -3034,8 +2982,8 @@ func TestGetProcessingAncestor(t *testing.T) { pending: map[ids.ID]snowman.Block{}, nonVerifiedCache: &cache.Empty[ids.ID, snowman.Block]{}, }, - initialVote: unissuedOnIssuedChain[0].ID(), - expectedAncestor: issuedChain[0].ID(), + initialVote: unissuedBlock.ID(), + expectedAncestor: issuedBlock.ID(), expectedFound: true, }, { @@ -3056,12 +3004,12 @@ func TestGetProcessingAncestor(t *testing.T) { metrics: metrics, nonVerifieds: ancestor.NewTree(), pending: map[ids.ID]snowman.Block{ - unissuedOnIssuedChain[0].ID(): unissuedOnIssuedChain[0], + unissuedBlock.ID(): unissuedBlock, }, nonVerifiedCache: &cache.Empty[ids.ID, snowman.Block]{}, }, - initialVote: unissuedOnIssuedChain[0].ID(), - expectedAncestor: issuedChain[0].ID(), + initialVote: unissuedBlock.ID(), + expectedAncestor: issuedBlock.ID(), expectedFound: true, }, } From 7e1b16d28978de49b9873783c8f15e2968e37c84 Mon Sep 17 00:00:00 2001 From: Stephen Buttolph Date: Sat, 27 Apr 2024 19:06:54 -0400 Subject: [PATCH 22/24] reduce diff --- snow/engine/snowman/transitive_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snow/engine/snowman/transitive_test.go b/snow/engine/snowman/transitive_test.go index a6a3728fa39f..75040d9a1f53 100644 --- a/snow/engine/snowman/transitive_test.go +++ b/snow/engine/snowman/transitive_test.go @@ -2021,8 +2021,8 @@ func TestEngineBubbleVotesThroughInvalidBlock(t *testing.T) { expectedVdrSet := set.Of(vdr) blk1 := snowmantest.BuildChild(snowmantest.Genesis) - blk2 := snowmantest.BuildChild(blk1) // blk2 cannot pass verification until [blk1] has been marked as accepted. + blk2 := snowmantest.BuildChild(blk1) blk2.VerifyV = errInvalid // The VM should be able to parse [blk1] and [blk2] From 5ed4c293ebdb186e5454fe1d844afbd0967d7bec Mon Sep 17 00:00:00 2001 From: Stephen Buttolph Date: Sat, 27 Apr 2024 19:14:59 -0400 Subject: [PATCH 23/24] nit --- vms/proposervm/batched_vm_test.go | 4 ++-- vms/proposervm/block_test.go | 12 ++++++------ vms/proposervm/vm_test.go | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/vms/proposervm/batched_vm_test.go b/vms/proposervm/batched_vm_test.go index 215d886c1876..a6e9ffb2b1d6 100644 --- a/vms/proposervm/batched_vm_test.go +++ b/vms/proposervm/batched_vm_test.go @@ -842,8 +842,8 @@ func initTestRemoteProposerVM( return snowmantest.GenesisID, nil } coreVM.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { - switch { - case blkID == snowmantest.GenesisID: + switch blkID { + case snowmantest.GenesisID: return snowmantest.Genesis, nil default: return nil, errUnknownBlock diff --git a/vms/proposervm/block_test.go b/vms/proposervm/block_test.go index 0163c0586738..1d16222f0124 100644 --- a/vms/proposervm/block_test.go +++ b/vms/proposervm/block_test.go @@ -123,10 +123,10 @@ func TestPreDurangoValidatorNodeBlockBuiltDelaysTests(t *testing.T) { return coreParentBlk, nil } coreVM.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { - switch { - case blkID == coreParentBlk.ID(): + switch blkID { + case coreParentBlk.ID(): return coreParentBlk, nil - case blkID == snowmantest.GenesisID: + case snowmantest.GenesisID: return snowmantest.Genesis, nil default: return nil, errUnknownBlock @@ -244,10 +244,10 @@ func TestPreDurangoNonValidatorNodeBlockBuiltDelaysTests(t *testing.T) { return coreParentBlk, nil } coreVM.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { - switch { - case blkID == coreParentBlk.ID(): + switch blkID { + case coreParentBlk.ID(): return coreParentBlk, nil - case blkID == snowmantest.GenesisID: + case snowmantest.GenesisID: return snowmantest.Genesis, nil default: return nil, errUnknownBlock diff --git a/vms/proposervm/vm_test.go b/vms/proposervm/vm_test.go index 390cb5a1e1ba..fb717c203f7f 100644 --- a/vms/proposervm/vm_test.go +++ b/vms/proposervm/vm_test.go @@ -106,8 +106,8 @@ func initTestProposerVM( return snowmantest.GenesisID, nil } coreVM.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) { - switch { - case blkID == snowmantest.GenesisID: + switch blkID { + case snowmantest.GenesisID: return snowmantest.Genesis, nil default: return nil, errUnknownBlock From e13928c4e04eb5f4f57172f2dbe0bcb19cdce363 Mon Sep 17 00:00:00 2001 From: Stephen Buttolph Date: Sat, 27 Apr 2024 19:23:11 -0400 Subject: [PATCH 24/24] nit --- vms/proposervm/pre_fork_block_test.go | 5 ----- 1 file changed, 5 deletions(-) diff --git a/vms/proposervm/pre_fork_block_test.go b/vms/proposervm/pre_fork_block_test.go index 56c588dbc956..892209781e8c 100644 --- a/vms/proposervm/pre_fork_block_test.go +++ b/vms/proposervm/pre_fork_block_test.go @@ -200,8 +200,6 @@ func TestBlockVerify_PreFork_ParentChecks(t *testing.T) { require.NoError(proVM.Shutdown(context.Background())) }() - require.True(snowmantest.GenesisTimestamp.Before(activationTime)) - // create parent block ... parentCoreBlk := snowmantest.BuildChild(snowmantest.Genesis) coreVM.BuildBlockF = func(context.Context) (snowman.Block, error) { @@ -264,7 +262,6 @@ func TestBlockVerify_BlocksBuiltOnPreForkGenesis(t *testing.T) { require.NoError(proVM.Shutdown(context.Background())) }() - require.True(snowmantest.GenesisTimestamp.Before(activationTime)) preActivationTime := activationTime.Add(-1 * time.Second) proVM.Set(preActivationTime) @@ -493,7 +490,6 @@ func TestBlockVerify_ForkBlockIsOracleBlock(t *testing.T) { require.NoError(proVM.Shutdown(context.Background())) }() - require.True(snowmantest.GenesisTimestamp.Before(activationTime)) postActivationTime := activationTime.Add(time.Second) proVM.Set(postActivationTime) @@ -564,7 +560,6 @@ func TestBlockVerify_ForkBlockIsOracleBlockButChildrenAreSigned(t *testing.T) { require.NoError(proVM.Shutdown(context.Background())) }() - require.True(snowmantest.GenesisTimestamp.Before(activationTime)) postActivationTime := activationTime.Add(time.Second) proVM.Set(postActivationTime)