From 102ddce1464ec29f5336185edf4edcd5097a8418 Mon Sep 17 00:00:00 2001 From: Quentin McGaw Date: Tue, 20 Sep 2022 15:42:06 -0400 Subject: [PATCH] chore(dot/state): `newTestStorageState` does not take `tries` argument (#2804) --- dot/state/block_data_test.go | 2 +- dot/state/block_finalisation_test.go | 6 +++--- dot/state/block_notify_test.go | 14 ++++++------- dot/state/block_test.go | 30 +++++++++++++--------------- dot/state/epoch_test.go | 4 ++-- dot/state/storage_notify_test.go | 6 +++--- dot/state/storage_test.go | 15 +++++++------- 7 files changed, 38 insertions(+), 39 deletions(-) diff --git a/dot/state/block_data_test.go b/dot/state/block_data_test.go index a07606bb05..370282850b 100644 --- a/dot/state/block_data_test.go +++ b/dot/state/block_data_test.go @@ -14,7 +14,7 @@ import ( ) func TestGetSet_ReceiptMessageQueue_Justification(t *testing.T) { - s := newTestBlockState(t, nil, newTriesEmpty()) + s := newTestBlockState(t, newTriesEmpty()) var genesisHeader = &types.Header{ Number: 0, diff --git a/dot/state/block_finalisation_test.go b/dot/state/block_finalisation_test.go index 2cc0afb980..aa62f591a4 100644 --- a/dot/state/block_finalisation_test.go +++ b/dot/state/block_finalisation_test.go @@ -14,7 +14,7 @@ import ( ) func TestHighestRoundAndSetID(t *testing.T) { - bs := newTestBlockState(t, testGenesisHeader, newTriesEmpty()) + bs := newTestBlockState(t, newTriesEmpty()) round, setID, err := bs.GetHighestRoundAndSetID() require.NoError(t, err) require.Equal(t, uint64(0), round) @@ -62,7 +62,7 @@ func TestHighestRoundAndSetID(t *testing.T) { } func TestBlockState_SetFinalisedHash(t *testing.T) { - bs := newTestBlockState(t, testGenesisHeader, newTriesEmpty()) + bs := newTestBlockState(t, newTriesEmpty()) h, err := bs.GetFinalisedHash(0, 0) require.NoError(t, err) require.Equal(t, testGenesisHeader.Hash(), h) @@ -104,7 +104,7 @@ func TestBlockState_SetFinalisedHash(t *testing.T) { } func TestSetFinalisedHash_setFirstSlotOnFinalisation(t *testing.T) { - bs := newTestBlockState(t, testGenesisHeader, newTriesEmpty()) + bs := newTestBlockState(t, newTriesEmpty()) firstSlot := uint64(42069) digest := types.NewDigest() diff --git a/dot/state/block_notify_test.go b/dot/state/block_notify_test.go index 2b7b827af7..a8bf3c639c 100644 --- a/dot/state/block_notify_test.go +++ b/dot/state/block_notify_test.go @@ -16,7 +16,7 @@ import ( var testMessageTimeout = time.Second * 3 func TestImportChannel(t *testing.T) { - bs := newTestBlockState(t, testGenesisHeader, newTriesEmpty()) + bs := newTestBlockState(t, newTriesEmpty()) ch := bs.GetImportedBlockNotifierChannel() defer bs.FreeImportedBlockNotifierChannel(ch) @@ -33,7 +33,7 @@ func TestImportChannel(t *testing.T) { } func TestFreeImportedBlockNotifierChannel(t *testing.T) { - bs := newTestBlockState(t, testGenesisHeader, newTriesEmpty()) + bs := newTestBlockState(t, newTriesEmpty()) ch := bs.GetImportedBlockNotifierChannel() require.Equal(t, 1, len(bs.imported)) @@ -42,7 +42,7 @@ func TestFreeImportedBlockNotifierChannel(t *testing.T) { } func TestFinalizedChannel(t *testing.T) { - bs := newTestBlockState(t, testGenesisHeader, newTriesEmpty()) + bs := newTestBlockState(t, newTriesEmpty()) ch := bs.GetFinalisedNotifierChannel() @@ -64,7 +64,7 @@ func TestFinalizedChannel(t *testing.T) { } func TestImportChannel_Multi(t *testing.T) { - bs := newTestBlockState(t, testGenesisHeader, newTriesEmpty()) + bs := newTestBlockState(t, newTriesEmpty()) num := 5 chs := make([]chan *types.Block, num) @@ -96,7 +96,7 @@ func TestImportChannel_Multi(t *testing.T) { } func TestFinalizedChannel_Multi(t *testing.T) { - bs := newTestBlockState(t, testGenesisHeader, newTriesEmpty()) + bs := newTestBlockState(t, newTriesEmpty()) num := 5 chs := make([]chan *types.FinalisationInfo, num) @@ -133,7 +133,7 @@ func TestFinalizedChannel_Multi(t *testing.T) { } func TestService_RegisterUnRegisterRuntimeUpdatedChannel(t *testing.T) { - bs := newTestBlockState(t, testGenesisHeader, newTriesEmpty()) + bs := newTestBlockState(t, newTriesEmpty()) ch := make(chan<- runtime.Version) chID, err := bs.RegisterRuntimeUpdatedChannel(ch) require.NoError(t, err) @@ -144,7 +144,7 @@ func TestService_RegisterUnRegisterRuntimeUpdatedChannel(t *testing.T) { } func TestService_RegisterUnRegisterConcurrentCalls(t *testing.T) { - bs := newTestBlockState(t, testGenesisHeader, newTriesEmpty()) + bs := newTestBlockState(t, newTriesEmpty()) go func() { for i := 0; i < 100; i++ { diff --git a/dot/state/block_test.go b/dot/state/block_test.go index e665c8cdea..e437a674b2 100644 --- a/dot/state/block_test.go +++ b/dot/state/block_test.go @@ -24,15 +24,13 @@ var testGenesisHeader = &types.Header{ Digest: types.NewDigest(), } -func newTestBlockState(t *testing.T, header *types.Header, tries *Tries) *BlockState { +func newTestBlockState(t *testing.T, tries *Tries) *BlockState { ctrl := gomock.NewController(t) telemetryMock := NewMockClient(ctrl) telemetryMock.EXPECT().SendMessage(gomock.Any()).AnyTimes() db := NewInMemoryDB(t) - if header == nil { - header = testGenesisHeader - } + header := testGenesisHeader bs, err := NewBlockStateFromGenesis(db, tries, header, telemetryMock) require.NoError(t, err) @@ -48,7 +46,7 @@ func newTestBlockState(t *testing.T, header *types.Header, tries *Tries) *BlockS } func TestSetAndGetHeader(t *testing.T) { - bs := newTestBlockState(t, nil, newTriesEmpty()) + bs := newTestBlockState(t, newTriesEmpty()) header := &types.Header{ Number: 0, @@ -65,7 +63,7 @@ func TestSetAndGetHeader(t *testing.T) { } func TestHasHeader(t *testing.T) { - bs := newTestBlockState(t, nil, newTriesEmpty()) + bs := newTestBlockState(t, newTriesEmpty()) header := &types.Header{ Number: 0, @@ -82,7 +80,7 @@ func TestHasHeader(t *testing.T) { } func TestGetBlockByNumber(t *testing.T) { - bs := newTestBlockState(t, testGenesisHeader, newTriesEmpty()) + bs := newTestBlockState(t, newTriesEmpty()) blockHeader := &types.Header{ ParentHash: testGenesisHeader.Hash(), @@ -104,7 +102,7 @@ func TestGetBlockByNumber(t *testing.T) { } func TestAddBlock(t *testing.T) { - bs := newTestBlockState(t, testGenesisHeader, newTriesEmpty()) + bs := newTestBlockState(t, newTriesEmpty()) // Create header header0 := &types.Header{ @@ -167,7 +165,7 @@ func TestAddBlock(t *testing.T) { } func TestGetSlotForBlock(t *testing.T) { - bs := newTestBlockState(t, testGenesisHeader, newTriesEmpty()) + bs := newTestBlockState(t, newTriesEmpty()) expectedSlot := uint64(77) babeHeader := types.NewBabeDigest() @@ -198,7 +196,7 @@ func TestGetSlotForBlock(t *testing.T) { } func TestIsBlockOnCurrentChain(t *testing.T) { - bs := newTestBlockState(t, testGenesisHeader, newTriesEmpty()) + bs := newTestBlockState(t, newTriesEmpty()) currChain, branchChains := AddBlocksToState(t, bs, 3, false) for _, header := range currChain { @@ -221,7 +219,7 @@ func TestIsBlockOnCurrentChain(t *testing.T) { } func TestAddBlock_BlockNumberToHash(t *testing.T) { - bs := newTestBlockState(t, testGenesisHeader, newTriesEmpty()) + bs := newTestBlockState(t, newTriesEmpty()) currChain, branchChains := AddBlocksToState(t, bs, 8, false) bestHash := bs.BestBlockHash() @@ -269,7 +267,7 @@ func TestAddBlock_BlockNumberToHash(t *testing.T) { } func TestFinalization_DeleteBlock(t *testing.T) { - bs := newTestBlockState(t, testGenesisHeader, newTriesEmpty()) + bs := newTestBlockState(t, newTriesEmpty()) AddBlocksToState(t, bs, 5, false) btBefore := bs.bt.DeepCopy() @@ -324,7 +322,7 @@ func TestFinalization_DeleteBlock(t *testing.T) { } func TestGetHashByNumber(t *testing.T) { - bs := newTestBlockState(t, testGenesisHeader, newTriesEmpty()) + bs := newTestBlockState(t, newTriesEmpty()) res, err := bs.GetHashByNumber(0) require.NoError(t, err) @@ -351,7 +349,7 @@ func TestGetHashByNumber(t *testing.T) { func TestAddBlock_WithReOrg(t *testing.T) { t.Skip() // TODO: this should be fixed after state refactor PR - bs := newTestBlockState(t, testGenesisHeader, newTriesEmpty()) + bs := newTestBlockState(t, newTriesEmpty()) header1a := &types.Header{ Number: 1, @@ -460,7 +458,7 @@ func TestAddBlock_WithReOrg(t *testing.T) { } func TestAddBlockToBlockTree(t *testing.T) { - bs := newTestBlockState(t, testGenesisHeader, newTriesEmpty()) + bs := newTestBlockState(t, newTriesEmpty()) header := &types.Header{ Number: 1, @@ -482,7 +480,7 @@ func TestAddBlockToBlockTree(t *testing.T) { func TestNumberIsFinalised(t *testing.T) { tries := newTriesEmpty() - bs := newTestBlockState(t, testGenesisHeader, tries) + bs := newTestBlockState(t, tries) fin, err := bs.NumberIsFinalised(0) require.NoError(t, err) require.True(t, fin) diff --git a/dot/state/epoch_test.go b/dot/state/epoch_test.go index 75b4736560..aa0a0903e5 100644 --- a/dot/state/epoch_test.go +++ b/dot/state/epoch_test.go @@ -29,7 +29,7 @@ var genesisBABEConfig = &types.BabeConfiguration{ func newEpochStateFromGenesis(t *testing.T) *EpochState { db := NewInMemoryDB(t) - blockState := newTestBlockState(t, nil, newTriesEmpty()) + blockState := newTestBlockState(t, newTriesEmpty()) s, err := NewEpochStateFromGenesis(db, blockState, genesisBABEConfig) require.NoError(t, err) return s @@ -183,7 +183,7 @@ func TestEpochState_SetAndGetSlotDuration(t *testing.T) { func TestEpochState_GetEpochFromTime(t *testing.T) { s := newEpochStateFromGenesis(t) - s.blockState = newTestBlockState(t, testGenesisHeader, newTriesEmpty()) + s.blockState = newTestBlockState(t, newTriesEmpty()) epochDuration, err := time.ParseDuration( fmt.Sprintf("%dms", diff --git a/dot/state/storage_notify_test.go b/dot/state/storage_notify_test.go index cd065d79df..39cf2dbd6b 100644 --- a/dot/state/storage_notify_test.go +++ b/dot/state/storage_notify_test.go @@ -18,7 +18,7 @@ import ( ) func TestStorageState_RegisterStorageObserver(t *testing.T) { - ss := newTestStorageState(t, newTriesEmpty()) + ss := newTestStorageState(t) ts, err := ss.TrieState(nil) require.NoError(t, err) @@ -57,7 +57,7 @@ func TestStorageState_RegisterStorageObserver(t *testing.T) { } func TestStorageState_RegisterStorageObserver_Multi(t *testing.T) { - ss := newTestStorageState(t, newTriesEmpty()) + ss := newTestStorageState(t) ts, err := ss.TrieState(nil) require.NoError(t, err) @@ -95,7 +95,7 @@ func TestStorageState_RegisterStorageObserver_Multi(t *testing.T) { func TestStorageState_RegisterStorageObserver_Multi_Filter(t *testing.T) { t.Skip() // this seems to fail often on CI - ss := newTestStorageState(t, newTriesEmpty()) + ss := newTestStorageState(t) ts, err := ss.TrieState(nil) require.NoError(t, err) diff --git a/dot/state/storage_test.go b/dot/state/storage_test.go index f78bc4f96e..79060371c2 100644 --- a/dot/state/storage_test.go +++ b/dot/state/storage_test.go @@ -20,10 +20,11 @@ import ( "github.com/stretchr/testify/require" ) -func newTestStorageState(t *testing.T, tries *Tries) *StorageState { +func newTestStorageState(t *testing.T) *StorageState { db := NewInMemoryDB(t) - bs := newTestBlockState(t, testGenesisHeader, tries) + tries := newTriesEmpty() + bs := newTestBlockState(t, tries) s, err := NewStorageState(db, bs, tries, pruner.Config{}) require.NoError(t, err) @@ -31,7 +32,7 @@ func newTestStorageState(t *testing.T, tries *Tries) *StorageState { } func TestStorage_StoreAndLoadTrie(t *testing.T) { - storage := newTestStorageState(t, newTriesEmpty()) + storage := newTestStorageState(t) ts, err := storage.TrieState(&trie.EmptyHash) require.NoError(t, err) @@ -50,7 +51,7 @@ func TestStorage_StoreAndLoadTrie(t *testing.T) { } func TestStorage_GetStorageByBlockHash(t *testing.T) { - storage := newTestStorageState(t, newTriesEmpty()) + storage := newTestStorageState(t) ts, err := storage.TrieState(&trie.EmptyHash) require.NoError(t, err) @@ -85,7 +86,7 @@ func TestStorage_GetStorageByBlockHash(t *testing.T) { } func TestStorage_TrieState(t *testing.T) { - storage := newTestStorageState(t, newTriesEmpty()) + storage := newTestStorageState(t) ts, err := storage.TrieState(&trie.EmptyHash) require.NoError(t, err) ts.Set([]byte("noot"), []byte("washere")) @@ -105,7 +106,7 @@ func TestStorage_TrieState(t *testing.T) { } func TestStorage_LoadFromDB(t *testing.T) { - storage := newTestStorageState(t, newTriesEmpty()) + storage := newTestStorageState(t) ts, err := storage.TrieState(&trie.EmptyHash) require.NoError(t, err) @@ -150,7 +151,7 @@ func TestStorage_LoadFromDB(t *testing.T) { } func TestStorage_StoreTrie_NotSyncing(t *testing.T) { - storage := newTestStorageState(t, newTriesEmpty()) + storage := newTestStorageState(t) ts, err := storage.TrieState(&trie.EmptyHash) require.NoError(t, err)