forked from irinazheltisheva/powergate
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchainsync_test.go
More file actions
47 lines (39 loc) · 922 Bytes
/
chainsync_test.go
File metadata and controls
47 lines (39 loc) · 922 Bytes
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
package chainsync
import (
"context"
"os"
"testing"
"github.com/filecoin-project/lotus/chain/types"
logging "github.com/ipfs/go-log/v2"
"github.com/textileio/fil-tools/tests"
)
func TestMain(m *testing.M) {
logging.SetAllLoggers(logging.LevelError)
os.Exit(m.Run())
}
func TestPrecede(t *testing.T) {
dnet, _, _, close := tests.CreateLocalDevnet(t, 1)
defer close()
ctx := context.Background()
h, err := dnet.Client.ChainHead(ctx)
checkErr(t, err)
csync := New(dnet.Client)
head := h.Key()
prevhead := types.NewTipSetKey(h.Blocks()[0].Parents...)
yes, err := csync.Precedes(ctx, prevhead, head)
checkErr(t, err)
if !yes {
t.Fatal("parent of head should precedes head")
}
yes, err = csync.Precedes(ctx, head, prevhead)
checkErr(t, err)
if yes {
t.Fatal("head shouldn't preced parent of head")
}
}
func checkErr(t *testing.T, err error) {
t.Helper()
if err != nil {
t.Fatal(err)
}
}