forked from streamingfast/firehose-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
storage_test.go
49 lines (45 loc) · 1.1 KB
/
storage_test.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
47
48
49
package firecore
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func Test_searchBlockNum(t *testing.T) {
tests := []struct {
name string
startBlockNum uint64
lastBlockNum *uint64
expect int
expectErr bool
}{
{"golden path", 1_690_600, uptr(208_853_300), 208_853_300, false},
{"no block file found", 1_690_600, nil, 1_690_600, false},
{"block file greater then start block", 0, uptr(100), 100, false},
{"block file less then start block", 200, uptr(100), 200, false},
{"golden path 2", 0, uptr(17821900), 17821900, false},
}
for _, tt := range tests {
t.Run("", func(t *testing.T) {
dstoreOpt := 0
v, err := searchBlockNum(tt.startBlockNum, func(i uint64) (bool, error) {
dstoreOpt++
if tt.lastBlockNum == nil {
return false, nil
}
if i > *tt.lastBlockNum {
return false, nil
}
return true, nil
})
if tt.expectErr {
require.Error(t, err)
} else {
require.NoError(t, err)
assert.Equal(t, tt.expect, int(v))
}
})
}
}
func uptr(v uint64) *uint64 {
return &v
}