Skip to content

Commit

Permalink
test(lib/runtime/storage): use require.NoError instead of require.Nil…
Browse files Browse the repository at this point in the history
… for errors (#3977)

Co-authored-by: Diego <[email protected]>
  • Loading branch information
EmilGeorgiev and dimartiro authored Jun 12, 2024
1 parent 59363f3 commit 64bf408
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion dot/sync/syncer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ func Test_Service_HandleBlockAnnounceHandshake(t *testing.T) {
}

err := service.HandleBlockAnnounceHandshake(peer.ID("peer"), message)
require.Nil(t, err)
require.NoError(t, err)
}

func TestService_IsSynced(t *testing.T) {
Expand Down
34 changes: 17 additions & 17 deletions lib/runtime/storage/trie_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func TestTrieState_WithAndWithoutTransactions(t *testing.T) {
require.Nil(t, val)

if isTransactionRunning {
require.Nil(t, err)
require.NoError(t, err)
} else {
require.ErrorContains(t, err, "child trie does not exist at key")
}
Expand All @@ -133,7 +133,7 @@ func TestTrieState_WithAndWithoutTransactions(t *testing.T) {
},
checks: func(t *testing.T, ts *TrieState, _ bool) {
err := ts.DeleteChild(keyToChild)
require.Nil(t, err)
require.NoError(t, err)

root, err := ts.GetChildStorage(keyToChild, prefixedKeys[0])
require.NotNil(t, err)
Expand All @@ -144,12 +144,12 @@ func TestTrieState_WithAndWithoutTransactions(t *testing.T) {
changes: func(t *testing.T, ts *TrieState) {
for i, key := range prefixedKeys {
err := ts.Put(key, []byte{byte(i)})
require.Nil(t, err)
require.NoError(t, err)
}
},
checks: func(t *testing.T, ts *TrieState, _ bool) {
err := ts.ClearPrefix([]byte("noo"))
require.Nil(t, err)
require.NoError(t, err)

for i, key := range prefixedKeys {
val := ts.Get(key)
Expand All @@ -165,12 +165,12 @@ func TestTrieState_WithAndWithoutTransactions(t *testing.T) {
changes: func(t *testing.T, ts *TrieState) {
for i, key := range prefixedKeys {
err := ts.Put(key, []byte{byte(i)})
require.Nil(t, err)
require.NoError(t, err)
}
},
checks: func(t *testing.T, ts *TrieState, isTransactionRunning bool) {
deleted, allDeleted, err := ts.ClearPrefixLimit([]byte("noo"), uint32(1))
require.Nil(t, err)
require.NoError(t, err)

if isTransactionRunning {
// New keys are not considered towards the limit
Expand Down Expand Up @@ -229,7 +229,7 @@ func TestTrieState_WithAndWithoutTransactions(t *testing.T) {
changes: func(t *testing.T, ts *TrieState) {
for i, key := range sortedKeys {
err := ts.SetChildStorage(keyToChild, key, []byte{byte(i)})
require.Nil(t, err)
require.NoError(t, err)
}
},
checks: func(t *testing.T, ts *TrieState, isTransactionRunning bool) {
Expand All @@ -249,7 +249,7 @@ func TestTrieState_WithAndWithoutTransactions(t *testing.T) {
changes: func(t *testing.T, ts *TrieState) {
for i, key := range sortedKeys {
err := ts.SetChildStorage(keyToChild, key, []byte{byte(i)})
require.Nil(t, err)
require.NoError(t, err)
}
},
checks: func(t *testing.T, ts *TrieState, isTransactionRunning bool) {
Expand All @@ -273,13 +273,13 @@ func TestTrieState_WithAndWithoutTransactions(t *testing.T) {
changes: func(t *testing.T, ts *TrieState) {
for i, key := range sortedKeys {
err := ts.SetChildStorage(keyToChild, key, []byte{byte(i)})
require.Nil(t, err)
require.NoError(t, err)
}
},
checks: func(t *testing.T, ts *TrieState, isTransactionRunning bool) {
deleted, all, err := ts.DeleteChildLimit(keyToChild, nil)

require.Nil(t, err)
require.NoError(t, err)
require.Equal(t, uint32(3), deleted)
require.Equal(t, true, all)
},
Expand All @@ -288,7 +288,7 @@ func TestTrieState_WithAndWithoutTransactions(t *testing.T) {
changes: func(t *testing.T, ts *TrieState) {
for i, tc := range sortedKeys {
err := ts.Put(tc, sortedValues[i])
require.Nil(t, err)
require.NoError(t, err)
}
},
checks: func(t *testing.T, ts *TrieState, _ bool) {
Expand All @@ -306,13 +306,13 @@ func TestTrieState_WithAndWithoutTransactions(t *testing.T) {
changes: func(t *testing.T, ts *TrieState) {
for i, tc := range sortedKeys {
err := ts.SetChildStorage(keyToChild, tc, sortedValues[i])
require.Nil(t, err)
require.NoError(t, err)
}
},
checks: func(t *testing.T, ts *TrieState, _ bool) {
for i, tc := range sortedKeys {
next, err := ts.GetChildNextKey(keyToChild, tc)
require.Nil(t, err)
require.NoError(t, err)

if i == len(sortedKeys)-1 {
require.Nil(t, next)
Expand All @@ -326,7 +326,7 @@ func TestTrieState_WithAndWithoutTransactions(t *testing.T) {
changes: func(t *testing.T, ts *TrieState) {
for i, tc := range testCases {
err := ts.Put([]byte(tc), sortedValues[i])
require.Nil(t, err)
require.NoError(t, err)
}
},
checks: func(t *testing.T, ts *TrieState, _ bool) {
Expand All @@ -342,13 +342,13 @@ func TestTrieState_WithAndWithoutTransactions(t *testing.T) {
changes: func(t *testing.T, ts *TrieState) {
for i, tc := range prefixedKeys {
err := ts.SetChildStorage(keyToChild, tc, sortedValues[i])
require.Nil(t, err)
require.NoError(t, err)
}
},
checks: func(t *testing.T, ts *TrieState, _ bool) {
values, err := ts.GetKeysWithPrefixFromChild(keyToChild, []byte("noo"))

require.Nil(t, err)
require.NoError(t, err)
require.Len(t, values, 2)
require.Contains(t, values, []byte("noot"))
require.Contains(t, values, []byte("noodle"))
Expand Down Expand Up @@ -412,7 +412,7 @@ func TestTrieState_ChildRoot(t *testing.T) {
}

root, err := ts.GetChildRoot(keyToChild)
require.Nil(t, err)
require.NoError(t, err)
require.NotNil(t, root)
}

Expand Down

0 comments on commit 64bf408

Please sign in to comment.