Skip to content

Commit

Permalink
Minor select test database setup simplify
Browse files Browse the repository at this point in the history
- Use in memory database when amount is not big (`TestTrieDiff`)
- Do not create unneeded `trie` table in `lib/trie`'s `newTestDB`
- `dot/state`: use `t.TempDir()` as data dir directly
  • Loading branch information
qdm12 committed Jan 9, 2023
1 parent 948fac0 commit ad9eafb
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 18 deletions.
5 changes: 1 addition & 4 deletions dot/state/storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
package state

import (
"path/filepath"
"testing"
"time"

Expand Down Expand Up @@ -167,10 +166,8 @@ func TestStorage_StoreTrie_NotSyncing(t *testing.T) {
}

func TestGetStorageChildAndGetStorageFromChild(t *testing.T) {
// initialise database using data directory
basepath := t.TempDir()
db, err := chaindb.NewBadgerDB(&chaindb.Config{
DataDir: filepath.Join(basepath, "db"),
DataDir: t.TempDir(),
})
require.NoError(t, err)
t.Cleanup(func() {
Expand Down
2 changes: 1 addition & 1 deletion lib/trie/database_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func newTestDB(t *testing.T) chaindb.Database {
err := database.Close()
require.NoError(t, err)
})
return chaindb.NewTable(database, "trie")
return database
}

func Test_Trie_Store_Load(t *testing.T) {
Expand Down
16 changes: 3 additions & 13 deletions lib/trie/trie_endtoend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,23 +267,13 @@ func TestDeleteOddKeyLengths(t *testing.T) {
}

func TestTrieDiff(t *testing.T) {
cfg := &chaindb.Config{
DataDir: t.TempDir(),
}

db, err := chaindb.NewBadgerDB(cfg)
require.NoError(t, err)

db := newTestDB(t)
t.Cleanup(func() {
err = db.Close()
err := db.Close()
require.NoError(t, err)
})

storageDB := chaindb.NewTable(db, "storage")
t.Cleanup(func() {
err := storageDB.Close()
require.NoError(t, err)
})

trie := NewEmptyTrie()

Expand All @@ -300,7 +290,7 @@ func TestTrieDiff(t *testing.T) {
}

newTrie := trie.Snapshot()
err = trie.WriteDirty(storageDB)
err := trie.WriteDirty(storageDB)
require.NoError(t, err)

tests = []keyValues{
Expand Down

0 comments on commit ad9eafb

Please sign in to comment.