Skip to content

Commit 102ddce

Browse files
authored
chore(dot/state): newTestStorageState does not take tries argument (#2804)
1 parent 1e38c35 commit 102ddce

File tree

7 files changed

+38
-39
lines changed

7 files changed

+38
-39
lines changed

dot/state/block_data_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
)
1515

1616
func TestGetSet_ReceiptMessageQueue_Justification(t *testing.T) {
17-
s := newTestBlockState(t, nil, newTriesEmpty())
17+
s := newTestBlockState(t, newTriesEmpty())
1818

1919
var genesisHeader = &types.Header{
2020
Number: 0,

dot/state/block_finalisation_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
)
1515

1616
func TestHighestRoundAndSetID(t *testing.T) {
17-
bs := newTestBlockState(t, testGenesisHeader, newTriesEmpty())
17+
bs := newTestBlockState(t, newTriesEmpty())
1818
round, setID, err := bs.GetHighestRoundAndSetID()
1919
require.NoError(t, err)
2020
require.Equal(t, uint64(0), round)
@@ -62,7 +62,7 @@ func TestHighestRoundAndSetID(t *testing.T) {
6262
}
6363

6464
func TestBlockState_SetFinalisedHash(t *testing.T) {
65-
bs := newTestBlockState(t, testGenesisHeader, newTriesEmpty())
65+
bs := newTestBlockState(t, newTriesEmpty())
6666
h, err := bs.GetFinalisedHash(0, 0)
6767
require.NoError(t, err)
6868
require.Equal(t, testGenesisHeader.Hash(), h)
@@ -104,7 +104,7 @@ func TestBlockState_SetFinalisedHash(t *testing.T) {
104104
}
105105

106106
func TestSetFinalisedHash_setFirstSlotOnFinalisation(t *testing.T) {
107-
bs := newTestBlockState(t, testGenesisHeader, newTriesEmpty())
107+
bs := newTestBlockState(t, newTriesEmpty())
108108
firstSlot := uint64(42069)
109109

110110
digest := types.NewDigest()

dot/state/block_notify_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616
var testMessageTimeout = time.Second * 3
1717

1818
func TestImportChannel(t *testing.T) {
19-
bs := newTestBlockState(t, testGenesisHeader, newTriesEmpty())
19+
bs := newTestBlockState(t, newTriesEmpty())
2020
ch := bs.GetImportedBlockNotifierChannel()
2121

2222
defer bs.FreeImportedBlockNotifierChannel(ch)
@@ -33,7 +33,7 @@ func TestImportChannel(t *testing.T) {
3333
}
3434

3535
func TestFreeImportedBlockNotifierChannel(t *testing.T) {
36-
bs := newTestBlockState(t, testGenesisHeader, newTriesEmpty())
36+
bs := newTestBlockState(t, newTriesEmpty())
3737
ch := bs.GetImportedBlockNotifierChannel()
3838
require.Equal(t, 1, len(bs.imported))
3939

@@ -42,7 +42,7 @@ func TestFreeImportedBlockNotifierChannel(t *testing.T) {
4242
}
4343

4444
func TestFinalizedChannel(t *testing.T) {
45-
bs := newTestBlockState(t, testGenesisHeader, newTriesEmpty())
45+
bs := newTestBlockState(t, newTriesEmpty())
4646

4747
ch := bs.GetFinalisedNotifierChannel()
4848

@@ -64,7 +64,7 @@ func TestFinalizedChannel(t *testing.T) {
6464
}
6565

6666
func TestImportChannel_Multi(t *testing.T) {
67-
bs := newTestBlockState(t, testGenesisHeader, newTriesEmpty())
67+
bs := newTestBlockState(t, newTriesEmpty())
6868

6969
num := 5
7070
chs := make([]chan *types.Block, num)
@@ -96,7 +96,7 @@ func TestImportChannel_Multi(t *testing.T) {
9696
}
9797

9898
func TestFinalizedChannel_Multi(t *testing.T) {
99-
bs := newTestBlockState(t, testGenesisHeader, newTriesEmpty())
99+
bs := newTestBlockState(t, newTriesEmpty())
100100

101101
num := 5
102102
chs := make([]chan *types.FinalisationInfo, num)
@@ -133,7 +133,7 @@ func TestFinalizedChannel_Multi(t *testing.T) {
133133
}
134134

135135
func TestService_RegisterUnRegisterRuntimeUpdatedChannel(t *testing.T) {
136-
bs := newTestBlockState(t, testGenesisHeader, newTriesEmpty())
136+
bs := newTestBlockState(t, newTriesEmpty())
137137
ch := make(chan<- runtime.Version)
138138
chID, err := bs.RegisterRuntimeUpdatedChannel(ch)
139139
require.NoError(t, err)
@@ -144,7 +144,7 @@ func TestService_RegisterUnRegisterRuntimeUpdatedChannel(t *testing.T) {
144144
}
145145

146146
func TestService_RegisterUnRegisterConcurrentCalls(t *testing.T) {
147-
bs := newTestBlockState(t, testGenesisHeader, newTriesEmpty())
147+
bs := newTestBlockState(t, newTriesEmpty())
148148

149149
go func() {
150150
for i := 0; i < 100; i++ {

dot/state/block_test.go

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,13 @@ var testGenesisHeader = &types.Header{
2424
Digest: types.NewDigest(),
2525
}
2626

27-
func newTestBlockState(t *testing.T, header *types.Header, tries *Tries) *BlockState {
27+
func newTestBlockState(t *testing.T, tries *Tries) *BlockState {
2828
ctrl := gomock.NewController(t)
2929
telemetryMock := NewMockClient(ctrl)
3030
telemetryMock.EXPECT().SendMessage(gomock.Any()).AnyTimes()
3131

3232
db := NewInMemoryDB(t)
33-
if header == nil {
34-
header = testGenesisHeader
35-
}
33+
header := testGenesisHeader
3634

3735
bs, err := NewBlockStateFromGenesis(db, tries, header, telemetryMock)
3836
require.NoError(t, err)
@@ -48,7 +46,7 @@ func newTestBlockState(t *testing.T, header *types.Header, tries *Tries) *BlockS
4846
}
4947

5048
func TestSetAndGetHeader(t *testing.T) {
51-
bs := newTestBlockState(t, nil, newTriesEmpty())
49+
bs := newTestBlockState(t, newTriesEmpty())
5250

5351
header := &types.Header{
5452
Number: 0,
@@ -65,7 +63,7 @@ func TestSetAndGetHeader(t *testing.T) {
6563
}
6664

6765
func TestHasHeader(t *testing.T) {
68-
bs := newTestBlockState(t, nil, newTriesEmpty())
66+
bs := newTestBlockState(t, newTriesEmpty())
6967

7068
header := &types.Header{
7169
Number: 0,
@@ -82,7 +80,7 @@ func TestHasHeader(t *testing.T) {
8280
}
8381

8482
func TestGetBlockByNumber(t *testing.T) {
85-
bs := newTestBlockState(t, testGenesisHeader, newTriesEmpty())
83+
bs := newTestBlockState(t, newTriesEmpty())
8684

8785
blockHeader := &types.Header{
8886
ParentHash: testGenesisHeader.Hash(),
@@ -104,7 +102,7 @@ func TestGetBlockByNumber(t *testing.T) {
104102
}
105103

106104
func TestAddBlock(t *testing.T) {
107-
bs := newTestBlockState(t, testGenesisHeader, newTriesEmpty())
105+
bs := newTestBlockState(t, newTriesEmpty())
108106

109107
// Create header
110108
header0 := &types.Header{
@@ -167,7 +165,7 @@ func TestAddBlock(t *testing.T) {
167165
}
168166

169167
func TestGetSlotForBlock(t *testing.T) {
170-
bs := newTestBlockState(t, testGenesisHeader, newTriesEmpty())
168+
bs := newTestBlockState(t, newTriesEmpty())
171169
expectedSlot := uint64(77)
172170

173171
babeHeader := types.NewBabeDigest()
@@ -198,7 +196,7 @@ func TestGetSlotForBlock(t *testing.T) {
198196
}
199197

200198
func TestIsBlockOnCurrentChain(t *testing.T) {
201-
bs := newTestBlockState(t, testGenesisHeader, newTriesEmpty())
199+
bs := newTestBlockState(t, newTriesEmpty())
202200
currChain, branchChains := AddBlocksToState(t, bs, 3, false)
203201

204202
for _, header := range currChain {
@@ -221,7 +219,7 @@ func TestIsBlockOnCurrentChain(t *testing.T) {
221219
}
222220

223221
func TestAddBlock_BlockNumberToHash(t *testing.T) {
224-
bs := newTestBlockState(t, testGenesisHeader, newTriesEmpty())
222+
bs := newTestBlockState(t, newTriesEmpty())
225223
currChain, branchChains := AddBlocksToState(t, bs, 8, false)
226224

227225
bestHash := bs.BestBlockHash()
@@ -269,7 +267,7 @@ func TestAddBlock_BlockNumberToHash(t *testing.T) {
269267
}
270268

271269
func TestFinalization_DeleteBlock(t *testing.T) {
272-
bs := newTestBlockState(t, testGenesisHeader, newTriesEmpty())
270+
bs := newTestBlockState(t, newTriesEmpty())
273271
AddBlocksToState(t, bs, 5, false)
274272

275273
btBefore := bs.bt.DeepCopy()
@@ -324,7 +322,7 @@ func TestFinalization_DeleteBlock(t *testing.T) {
324322
}
325323

326324
func TestGetHashByNumber(t *testing.T) {
327-
bs := newTestBlockState(t, testGenesisHeader, newTriesEmpty())
325+
bs := newTestBlockState(t, newTriesEmpty())
328326

329327
res, err := bs.GetHashByNumber(0)
330328
require.NoError(t, err)
@@ -351,7 +349,7 @@ func TestGetHashByNumber(t *testing.T) {
351349

352350
func TestAddBlock_WithReOrg(t *testing.T) {
353351
t.Skip() // TODO: this should be fixed after state refactor PR
354-
bs := newTestBlockState(t, testGenesisHeader, newTriesEmpty())
352+
bs := newTestBlockState(t, newTriesEmpty())
355353

356354
header1a := &types.Header{
357355
Number: 1,
@@ -460,7 +458,7 @@ func TestAddBlock_WithReOrg(t *testing.T) {
460458
}
461459

462460
func TestAddBlockToBlockTree(t *testing.T) {
463-
bs := newTestBlockState(t, testGenesisHeader, newTriesEmpty())
461+
bs := newTestBlockState(t, newTriesEmpty())
464462

465463
header := &types.Header{
466464
Number: 1,
@@ -482,7 +480,7 @@ func TestAddBlockToBlockTree(t *testing.T) {
482480
func TestNumberIsFinalised(t *testing.T) {
483481
tries := newTriesEmpty()
484482

485-
bs := newTestBlockState(t, testGenesisHeader, tries)
483+
bs := newTestBlockState(t, tries)
486484
fin, err := bs.NumberIsFinalised(0)
487485
require.NoError(t, err)
488486
require.True(t, fin)

dot/state/epoch_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ var genesisBABEConfig = &types.BabeConfiguration{
2929

3030
func newEpochStateFromGenesis(t *testing.T) *EpochState {
3131
db := NewInMemoryDB(t)
32-
blockState := newTestBlockState(t, nil, newTriesEmpty())
32+
blockState := newTestBlockState(t, newTriesEmpty())
3333
s, err := NewEpochStateFromGenesis(db, blockState, genesisBABEConfig)
3434
require.NoError(t, err)
3535
return s
@@ -183,7 +183,7 @@ func TestEpochState_SetAndGetSlotDuration(t *testing.T) {
183183

184184
func TestEpochState_GetEpochFromTime(t *testing.T) {
185185
s := newEpochStateFromGenesis(t)
186-
s.blockState = newTestBlockState(t, testGenesisHeader, newTriesEmpty())
186+
s.blockState = newTestBlockState(t, newTriesEmpty())
187187

188188
epochDuration, err := time.ParseDuration(
189189
fmt.Sprintf("%dms",

dot/state/storage_notify_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818
)
1919

2020
func TestStorageState_RegisterStorageObserver(t *testing.T) {
21-
ss := newTestStorageState(t, newTriesEmpty())
21+
ss := newTestStorageState(t)
2222

2323
ts, err := ss.TrieState(nil)
2424
require.NoError(t, err)
@@ -57,7 +57,7 @@ func TestStorageState_RegisterStorageObserver(t *testing.T) {
5757
}
5858

5959
func TestStorageState_RegisterStorageObserver_Multi(t *testing.T) {
60-
ss := newTestStorageState(t, newTriesEmpty())
60+
ss := newTestStorageState(t)
6161
ts, err := ss.TrieState(nil)
6262
require.NoError(t, err)
6363

@@ -95,7 +95,7 @@ func TestStorageState_RegisterStorageObserver_Multi(t *testing.T) {
9595

9696
func TestStorageState_RegisterStorageObserver_Multi_Filter(t *testing.T) {
9797
t.Skip() // this seems to fail often on CI
98-
ss := newTestStorageState(t, newTriesEmpty())
98+
ss := newTestStorageState(t)
9999
ts, err := ss.TrieState(nil)
100100
require.NoError(t, err)
101101

dot/state/storage_test.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,19 @@ import (
2020
"github.com/stretchr/testify/require"
2121
)
2222

23-
func newTestStorageState(t *testing.T, tries *Tries) *StorageState {
23+
func newTestStorageState(t *testing.T) *StorageState {
2424
db := NewInMemoryDB(t)
2525

26-
bs := newTestBlockState(t, testGenesisHeader, tries)
26+
tries := newTriesEmpty()
27+
bs := newTestBlockState(t, tries)
2728

2829
s, err := NewStorageState(db, bs, tries, pruner.Config{})
2930
require.NoError(t, err)
3031
return s
3132
}
3233

3334
func TestStorage_StoreAndLoadTrie(t *testing.T) {
34-
storage := newTestStorageState(t, newTriesEmpty())
35+
storage := newTestStorageState(t)
3536
ts, err := storage.TrieState(&trie.EmptyHash)
3637
require.NoError(t, err)
3738

@@ -50,7 +51,7 @@ func TestStorage_StoreAndLoadTrie(t *testing.T) {
5051
}
5152

5253
func TestStorage_GetStorageByBlockHash(t *testing.T) {
53-
storage := newTestStorageState(t, newTriesEmpty())
54+
storage := newTestStorageState(t)
5455
ts, err := storage.TrieState(&trie.EmptyHash)
5556
require.NoError(t, err)
5657

@@ -85,7 +86,7 @@ func TestStorage_GetStorageByBlockHash(t *testing.T) {
8586
}
8687

8788
func TestStorage_TrieState(t *testing.T) {
88-
storage := newTestStorageState(t, newTriesEmpty())
89+
storage := newTestStorageState(t)
8990
ts, err := storage.TrieState(&trie.EmptyHash)
9091
require.NoError(t, err)
9192
ts.Set([]byte("noot"), []byte("washere"))
@@ -105,7 +106,7 @@ func TestStorage_TrieState(t *testing.T) {
105106
}
106107

107108
func TestStorage_LoadFromDB(t *testing.T) {
108-
storage := newTestStorageState(t, newTriesEmpty())
109+
storage := newTestStorageState(t)
109110
ts, err := storage.TrieState(&trie.EmptyHash)
110111
require.NoError(t, err)
111112

@@ -150,7 +151,7 @@ func TestStorage_LoadFromDB(t *testing.T) {
150151
}
151152

152153
func TestStorage_StoreTrie_NotSyncing(t *testing.T) {
153-
storage := newTestStorageState(t, newTriesEmpty())
154+
storage := newTestStorageState(t)
154155
ts, err := storage.TrieState(&trie.EmptyHash)
155156
require.NoError(t, err)
156157

0 commit comments

Comments
 (0)