forked from celestiaorg/celestia-node
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fetcher_test.go
39 lines (33 loc) · 1.08 KB
/
fetcher_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
package core
import (
"context"
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestBlockFetcher_GetBlock_and_SubscribeNewBlockEvent(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
t.Cleanup(cancel)
client := StartTestNode(t).Client
fetcher := NewBlockFetcher(client)
// generate some blocks
newBlockChan, err := fetcher.SubscribeNewBlockEvent(ctx)
require.NoError(t, err)
for i := 1; i < 3; i++ {
select {
case newBlockFromChan := <-newBlockChan:
h := newBlockFromChan.Header.Height
block, err := fetcher.GetSignedBlock(ctx, &h)
require.NoError(t, err)
assert.Equal(t, newBlockFromChan.Data, block.Data)
assert.Equal(t, newBlockFromChan.Header, block.Header)
assert.Equal(t, newBlockFromChan.Commit, block.Commit)
assert.Equal(t, newBlockFromChan.ValidatorSet, block.ValidatorSet)
require.GreaterOrEqual(t, newBlockFromChan.Header.Height, int64(i))
case <-ctx.Done():
require.NoError(t, ctx.Err())
}
}
require.NoError(t, fetcher.UnsubscribeNewBlockEvent(ctx))
}