Skip to content

Commit

Permalink
Fix incorrect checks in db tests; Return error using %w to pass error…
Browse files Browse the repository at this point in the history
… type.
  • Loading branch information
cabrador committed Jul 19, 2024
1 parent 85aa142 commit 25ac740
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 8 deletions.
9 changes: 7 additions & 2 deletions db/code_db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package db

import (
"bytes"
"errors"
"fmt"
"testing"

Expand Down Expand Up @@ -82,8 +83,12 @@ func TestCodeDB_DeleteCode(t *testing.T) {
}

code, err := db.GetCode(hash)
if err != nil {
t.Fatalf("get code returned error; %v", err)
if err == nil {
t.Fatal("get code must fail")
}

if got, want := err, leveldb.ErrNotFound; !errors.Is(got, want) {
t.Fatalf("unexpected err, got: %v, want: %v", got, want)
}

if code != nil {
Expand Down
9 changes: 7 additions & 2 deletions db/substate_db_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package db

import (
"errors"
"fmt"
"math/big"
"testing"
Expand Down Expand Up @@ -98,8 +99,12 @@ func TestSubstateDB_DeleteSubstate(t *testing.T) {
}

ss, err := db.GetSubstate(37_534_834, 1)
if err != nil {
t.Fatalf("get substate returned error; %v", err)
if err == nil {
t.Fatal("get substate must fail")
}

if got, want := err, leveldb.ErrNotFound; !errors.Is(got, want) {
t.Fatalf("unexpected err, got: %v, want: %v", got, want)
}

if ss != nil {
Expand Down
4 changes: 2 additions & 2 deletions db/update_db.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func (db *updateDB) GetUpdateSet(block uint64) (*updateset.UpdateSet, error) {
key := UpdateDBKey(block)
value, err := db.Get(key)
if err != nil {
return nil, fmt.Errorf("cannot get updateset block: %v, key %v; %v", block, key, err)
return nil, fmt.Errorf("cannot get updateset block: %v, key %v; %w", block, key, err)
}

if value == nil {
Expand All @@ -130,7 +130,7 @@ func (db *updateDB) GetUpdateSet(block uint64) (*updateset.UpdateSet, error) {
// decode value
var updateSetRLP updateset.UpdateSetRLP
if err = trlp.DecodeBytes(value, &updateSetRLP); err != nil {
return nil, fmt.Errorf("cannot decode update-set rlp block: %v, key %v; %v", block, key, err)
return nil, fmt.Errorf("cannot decode update-set rlp block: %v, key %v; %w", block, key, err)
}

return updateSetRLP.ToWorldState(db.GetCode, block)
Expand Down
9 changes: 7 additions & 2 deletions db/update_db_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package db

import (
"errors"
"fmt"
"math/big"
"testing"
Expand Down Expand Up @@ -98,8 +99,12 @@ func TestUpdateDB_DeleteUpdateSet(t *testing.T) {
}

us, err := db.GetUpdateSet(testUpdateSet.Block)
if err != nil {
t.Fatalf("get update=set returned error; %v", err)
if err == nil {
t.Fatal("get update-set must fail")
}

if got, want := err, leveldb.ErrNotFound; !errors.Is(got, want) {
t.Fatalf("unexpected err, got: %v, want: %v", got, want)
}

if us != nil {
Expand Down

0 comments on commit 25ac740

Please sign in to comment.