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
52 lines (44 loc) · 1.07 KB
/
chainsync_test.go
File metadata and controls
52 lines (44 loc) · 1.07 KB
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
50
51
52
package chainsync
import (
"context"
"os"
"testing"
"time"
"github.com/filecoin-project/lotus/chain/types"
logging "github.com/ipfs/go-log/v2"
"github.com/stretchr/testify/require"
"github.com/textileio/powergate/tests"
)
func TestMain(m *testing.M) {
logging.SetAllLoggers(logging.LevelError)
os.Exit(m.Run())
}
func TestPrecede(t *testing.T) {
clientBuilder, _, _ := tests.CreateLocalDevnet(t, 1)
time.Sleep(time.Second * 5) // Give time for at least 1 block to be mined.
ctx := context.Background()
c, cls, err := clientBuilder()
require.NoError(t, err)
defer cls()
h, err := c.ChainHead(ctx)
checkErr(t, err)
csync := New(clientBuilder)
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)
}
}