forked from celestiaorg/celestia-node
-
Notifications
You must be signed in to change notification settings - Fork 0
/
client_test.go
43 lines (36 loc) · 1.13 KB
/
client_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
package core
import (
"context"
"testing"
"time"
"github.com/stretchr/testify/require"
"github.com/tendermint/tendermint/types"
)
func TestRemoteClient_Status(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
t.Cleanup(cancel)
client := StartTestNode(t).Client
status, err := client.Status(ctx)
require.NoError(t, err)
require.NotNil(t, status)
}
func TestRemoteClient_StartBlockSubscription_And_GetBlock(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
t.Cleanup(cancel)
client := StartTestNode(t).Client
eventChan, err := client.Subscribe(ctx, newBlockSubscriber, newDataSignedBlockQuery)
require.NoError(t, err)
for i := 1; i <= 3; i++ {
select {
case evt := <-eventChan:
h := evt.Data.(types.EventDataSignedBlock).Header.Height
block, err := client.Block(ctx, &h)
require.NoError(t, err)
require.GreaterOrEqual(t, block.Block.Height, int64(i))
case <-ctx.Done():
require.NoError(t, ctx.Err())
}
}
// unsubscribe to event channel
require.NoError(t, client.Unsubscribe(ctx, newBlockSubscriber, newDataSignedBlockQuery))
}