Skip to content

Commit

Permalink
chore(dot/state): newTestStorageState does not take tries argument (
Browse files Browse the repository at this point in the history
  • Loading branch information
qdm12 authored Sep 20, 2022
1 parent 1e38c35 commit 102ddce
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 39 deletions.
2 changes: 1 addition & 1 deletion dot/state/block_data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions dot/state/block_finalisation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand Down
14 changes: 7 additions & 7 deletions dot/state/block_notify_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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))

Expand All @@ -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()

Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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++ {
Expand Down
30 changes: 14 additions & 16 deletions dot/state/block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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(),
Expand All @@ -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{
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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 {
Expand All @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions dot/state/epoch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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",
Expand Down
6 changes: 3 additions & 3 deletions dot/state/storage_notify_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand Down
15 changes: 8 additions & 7 deletions dot/state/storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,19 @@ 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)
return s
}

func TestStorage_StoreAndLoadTrie(t *testing.T) {
storage := newTestStorageState(t, newTriesEmpty())
storage := newTestStorageState(t)
ts, err := storage.TrieState(&trie.EmptyHash)
require.NoError(t, err)

Expand All @@ -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)

Expand Down Expand Up @@ -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"))
Expand All @@ -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)

Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit 102ddce

Please sign in to comment.