-
Notifications
You must be signed in to change notification settings - Fork 179
/
testing.go
46 lines (40 loc) · 1.95 KB
/
testing.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package util
import (
"os"
"path/filepath"
"testing"
"github.com/dgraph-io/badger/v2"
"github.com/stretchr/testify/require"
"github.com/onflow/flow-go/module/metrics"
storage "github.com/onflow/flow-go/storage/badger"
"github.com/onflow/flow-go/utils/unittest"
)
func StorageLayer(t testing.TB, db *badger.DB) (*storage.Headers, *storage.Guarantees, *storage.Seals, *storage.Index, *storage.Payloads, *storage.Blocks, *storage.EpochSetups, *storage.EpochCommits, *storage.EpochStatuses, *storage.ExecutionResults) {
metrics := metrics.NewNoopCollector()
headers := storage.NewHeaders(metrics, db)
guarantees := storage.NewGuarantees(metrics, db, storage.DefaultCacheSize)
seals := storage.NewSeals(metrics, db)
results := storage.NewExecutionResults(metrics, db)
receipts := storage.NewExecutionReceipts(metrics, db, results, storage.DefaultCacheSize)
index := storage.NewIndex(metrics, db)
payloads := storage.NewPayloads(db, index, guarantees, seals, receipts, results)
blocks := storage.NewBlocks(db, headers, payloads)
setups := storage.NewEpochSetups(metrics, db)
commits := storage.NewEpochCommits(metrics, db)
statuses := storage.NewEpochStatuses(metrics, db)
return headers, guarantees, seals, index, payloads, blocks, setups, commits, statuses, results
}
func RunWithStorageLayer(t testing.TB, f func(*badger.DB, *storage.Headers, *storage.Guarantees, *storage.Seals, *storage.Index, *storage.Payloads, *storage.Blocks, *storage.EpochSetups, *storage.EpochCommits, *storage.EpochStatuses)) {
unittest.RunWithBadgerDB(t, func(db *badger.DB) {
headers, guarantees, seals, index, payloads, blocks, setups, commits, statuses, _ := StorageLayer(t, db)
f(db, headers, guarantees, seals, index, payloads, blocks, setups, commits, statuses)
})
}
func CreateFiles(t *testing.T, dir string, names ...string) {
for _, name := range names {
file, err := os.Create(filepath.Join(dir, name))
require.NoError(t, err)
err = file.Close()
require.NoError(t, err)
}
}